[clang] [llvm] [Clang] Show inlining hints for __attribute__((warning/error)) (PR #174892)

Justin Stitt via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 8 16:53:30 PST 2026


================
@@ -6048,13 +6048,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr<MSAllocatorAttr>())
     getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr<ErrorAttr>()) {
-    llvm::ConstantInt *Line =
-        llvm::ConstantInt::get(Int64Ty, Loc.getRawEncoding());
-    llvm::ConstantAsMetadata *MD = llvm::ConstantAsMetadata::get(Line);
-    llvm::MDTuple *MDT = llvm::MDNode::get(getLLVMContext(), {MD});
-    CI->setMetadata("srcloc", MDT);
+  // Add srcloc metadata for [[gnu::error/warning]] diagnostics.
+  // When ShowInliningChain is enabled, also track inline/static calls for the
+  // heuristic fallback when debug info is not available.
+  if (TargetDecl) {
+    bool NeedSrcLoc = TargetDecl->hasAttr<ErrorAttr>();
+    if (!NeedSrcLoc && CGM.getCodeGenOpts().ShowInliningChain) {
+      if (const auto *FD = dyn_cast<FunctionDecl>(TargetDecl))
+        NeedSrcLoc = FD->isInlined() || FD->isInlineSpecified() ||
----------------
JustinStitt wrote:

After some testing, both are _not_ necessary but we do need `FD->hasAttr<AlwaysInlineAttr>()`. I added a test for this case.

https://github.com/llvm/llvm-project/pull/174892


More information about the llvm-commits mailing list