diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -817,8 +817,10 @@ CurFn->getName().bytes_begin(), CurFn->getName().bytes_end()); auto Group = crc32(FuncName) % FuncGroups; if (Group != CGM.getCodeGenOpts().XRaySelectedFunctionGroup && - !AlwaysXRayAttr) + !AlwaysXRayAttr) { + Fn->removeFnAttr("xray-instruction-threshold"); Fn->addFnAttr("function-instrument", "xray-never"); + } } } diff --git a/llvm/lib/CodeGen/XRayInstrumentation.cpp b/llvm/lib/CodeGen/XRayInstrumentation.cpp --- a/llvm/lib/CodeGen/XRayInstrumentation.cpp +++ b/llvm/lib/CodeGen/XRayInstrumentation.cpp @@ -145,6 +145,10 @@ bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) { auto &F = MF.getFunction(); auto InstrAttr = F.getFnAttribute("function-instrument"); + bool NeverInstrument = InstrAttr.isStringAttribute() && + InstrAttr.getValueAsString() == "xray-never"; + if (NeverInstrument) + return false; bool AlwaysInstrument = InstrAttr.isStringAttribute() && InstrAttr.getValueAsString() == "xray-always"; auto ThresholdAttr = F.getFnAttribute("xray-instruction-threshold");