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

2026-02-04 Thread Justin Stitt via cfe-commits


@@ -6064,13 +6064,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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. Track
+  // inline/static calls for the heuristic fallback when debug info is not
+  // available. This heuristic is conservative and best-effort since static or
+  // inline-annotated functions are still not guaranteed to be inlined.
+  if (TargetDecl) {
+bool NeedSrcLoc = TargetDecl->hasAttr();
+if (!NeedSrcLoc) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->hasAttr() ||
+ FD->getStorageClass() == SC_Static ||
+ FD->isInAnonymousNamespace();

JustinStitt wrote:

Interesting. Can you expand on where to store Line information? I need the 
information to persist during inlining optimizations. I don't think I can get 
away with any sort of AST fields, etc.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-30 Thread Justin Stitt via cfe-commits

https://github.com/JustinStitt edited 
https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-30 Thread Justin Stitt via cfe-commits

https://github.com/JustinStitt edited 
https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-30 Thread Justin Stitt via cfe-commits


@@ -6064,13 +6064,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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. Track
+  // inline/static calls for the heuristic fallback when debug info is not
+  // available. This heuristic is conservative and best-effort since static or
+  // inline-annotated functions are still not guaranteed to be inlined.
+  if (TargetDecl) {
+bool NeedSrcLoc = TargetDecl->hasAttr();
+if (!NeedSrcLoc) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->hasAttr() ||
+ FD->getStorageClass() == SC_Static ||
+ FD->isInAnonymousNamespace();

JustinStitt wrote:

@efriedma-quic 
> I think I'd like to see peak memory usage numbers for some C++ code.

I ran some benchmarks and saw the following results, note that each block is 10 
runs building some clang Sema code. 

```
peak memory usage building Sema/SemaExpr.cpp

┌─┬──┬──┬──┐
 
│ Config  │Blk 1 │Blk 2 │   Overhead   │
 
├─┼──┼──┼──┤
 
│ Vanilla │  1013.9 MB   │  1013.4 MB   │  -   │
 
│ Heuristic   │  1031.2 MB   │  1031.0 MB   │   +1.7%  │
 
│ Debug   │  1353.9 MB   │  1355.8 MB   │  +33.7%  │
└─┴──┴──┴──┘ 
```

I am not exactly sure how representative `SemaExpr.cpp` is of C++ code in the 
wild but we probably shouldn't be pushing 2% memory overhead too frequently, 
especially for simple diagnostic changes. 

I wanted to hide all of this behind a flag but as you can see early on in this 
PR we opted to not do that. What are other options here? Can we drop the 
heuristic mode entirely and just let users build with `-g1` if they are 
debugging a `error/warning`-annotated stack?

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-29 Thread Justin Stitt via cfe-commits


@@ -484,8 +484,27 @@ void llvm::diagnoseDontCall(const CallInst &CI) {
   if (MDNode *MD = CI.getMetadata("srcloc"))
 LocCookie =
 mdconst::extract(MD->getOperand(0))->getZExtValue();
+  MDNode *InlinedFromMD = CI.getMetadata("inlined.from");
   DiagnosticInfoDontCall D(F->getName(), A.getValueAsString(), Sev,
-   LocCookie);
+   LocCookie, InlinedFromMD);
+
+  if (const DebugLoc &DL = CI.getDebugLoc()) {
+SmallVector DebugChain;
+auto AddLocation = [&](const DILocation *Loc) {
+  if (auto *Scope = Loc->getScope())
+if (auto *SP = Scope->getSubprogram())
+  DebugChain.push_back({SP->getName(), Loc->getFilename(),
+Loc->getLine(), Loc->getColumn()});
+};
+if (const DILocation *Loc = DL.get()) {

JustinStitt wrote:

Makes sense. I wasn't sure if `.get()` could still return null here somehow. I 
removed the redundant check with 269a85772dbb43d16b88100da1760e8110d3f111

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-29 Thread Justin Stitt via cfe-commits

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

>From 401a61f5fbc9a65560a6419621a7abb46e126a8e Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 6 Jan 2026 15:36:33 -0800
Subject: [PATCH 1/4] [Clang] Implement inlining hints for
 __attribute__((warnning/error))

When functions marked with __attribute__((warning/error)) are called
through inlined functions, Clang now shows the inlining chain that led
to the call.

The two modes are:

- ``heuristic`` tries to guess which functions will be inlined to
  minimize the amount of source locations kept in memory and visible in
  LLVM IR.

- ``debug`` leverages minimal debug directive tracking infrastructure to
  get more reliable source locations over the heuristic mode while
  having more compile-time overhead.

``debug`` mode is enabled when debug information
``-gline-directives-only`` (implied by ``-g1`` or higher) is available.
If this debug information is not available, the ``heuristic`` mode is
used which represents a best-effort approach towards accurate inline
hints. When the heuristic fails and we cannot show an accurate source
location for one or more hints, the source location of the initial
warning is used -- completely wrong locations are never used.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1571
Based-on: https://github.com/llvm/llvm-project/pull/73552
Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |   9 ++
 clang/include/clang/Basic/AttrDocs.td |   9 ++
 .../clang/Basic/DiagnosticFrontendKinds.td|   6 +
 clang/include/clang/Options/Options.td|  10 +-
 clang/lib/CodeGen/CGCall.cpp  |  24 ++--
 clang/lib/CodeGen/CodeGenAction.cpp   |  38 ++
 clang/test/CodeGen/attr-nomerge.cpp   |   6 +-
 clang/test/CodeGenCXX/builtin-invoke.cpp  |   4 +-
 .../inheriting-constructor-cleanup.cpp|   2 +-
 .../test/CodeGenCXX/type-aware-allocators.cpp |   2 +-
 .../coro-await-resume-eh.cpp  |   2 +-
 clang/test/DebugInfo/CXX/member-call.cpp  |   4 +-
 .../backend-attribute-inlining-cross-tu.c |  67 +++
 ...-attribute-inlining-debug-vs-heuristic.cpp |  92 ++
 .../backend-attribute-inlining-modes.c|  32 +
 .../Frontend/backend-attribute-inlining.c | 112 ++
 ...ibute_parallel_for_num_threads_codegen.cpp |   8 +-
 ..._parallel_for_simd_num_threads_codegen.cpp |  12 +-
 clang/test/OpenMP/scope_codegen.cpp   |   8 +-
 clang/test/OpenMP/single_codegen.cpp  |  12 +-
 ...ibute_parallel_for_num_threads_codegen.cpp |   4 +-
 ..._parallel_for_simd_num_threads_codegen.cpp |   6 +-
 clang/test/OpenMP/threadprivate_codegen.cpp   |  42 +++
 .../Inputs/basic-cplusplus.cpp.expected   |  41 +--
 ...plicit-template-instantiation.cpp.expected |  20 ++--
 llvm/include/llvm/IR/DiagnosticInfo.h |  26 +++-
 llvm/lib/IR/DiagnosticInfo.cpp|  38 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  44 +++
 28 files changed, 588 insertions(+), 92 deletions(-)
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-cross-tu.c
 create mode 100644 
clang/test/Frontend/backend-attribute-inlining-debug-vs-heuristic.cpp
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-modes.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 489a91d439133..17aa673296d13 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -187,6 +187,15 @@ Improvements to Clang's diagnostics
 int* p(int *in [[clang::noescape]]) { return in; }
  ^~
 
+- ``[[gnu::warning]]`` and ``[[gnu::error]]`` diagnostics now have notes
+  describing inlining locations. When a function with these attributes is
+  called from an inlined context, Clang can now show which functions were
+  inlined to reach the call. When debug info is available
+  (``-gline-directives-only`` (implicitly enabled at ``-g1``) or higher),
+  accurate source locations are used; otherwise, a heuristic fallback is used
+  with a note suggesting how to enable debug info for better accuracy.
+
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 6e2c73f924352..0d72688d80c50 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8411,6 +8411,15 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the inlining chain that led to
+the call is shown. This helps identify which call site triggered the diagnostic
+when the attributed function is called from multiple locations through inline
+functi

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

2026-01-29 Thread Justin Stitt via cfe-commits

https://github.com/JustinStitt edited 
https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-29 Thread Justin Stitt via cfe-commits


@@ -6064,13 +6064,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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. Track
+  // inline/static calls for the heuristic fallback when debug info is not
+  // available. This heuristic is conservative and best-effort since static or
+  // inline-annotated functions are still not guaranteed to be inlined.
+  if (TargetDecl) {
+bool NeedSrcLoc = TargetDecl->hasAttr();
+if (!NeedSrcLoc) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->hasAttr() ||
+ FD->getStorageClass() == SC_Static ||
+ FD->isInAnonymousNamespace();

JustinStitt wrote:

> This is imposing a non-zero cost on all code, whether or not it uses 
> ErrorAttr. Imposing a cost on everyone for the sake of the Linux kernel isn't 
> great.

The cost is a dyn_cast-check and some short-circuitable trivial checks. The 
most expensive check after the dynamic cast is probably the `hasAttr` check. I 
don't see how I can avoid it :(

> How much does this cost? Do we expect diagnostics that are relevant outside 
> the Linux kernel to use this?

I put some benchmarks I ran a couple of weeks ago in the PR description.



https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-29 Thread Justin Stitt via cfe-commits

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

>From 401a61f5fbc9a65560a6419621a7abb46e126a8e Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 6 Jan 2026 15:36:33 -0800
Subject: [PATCH 1/3] [Clang] Implement inlining hints for
 __attribute__((warnning/error))

When functions marked with __attribute__((warning/error)) are called
through inlined functions, Clang now shows the inlining chain that led
to the call.

The two modes are:

- ``heuristic`` tries to guess which functions will be inlined to
  minimize the amount of source locations kept in memory and visible in
  LLVM IR.

- ``debug`` leverages minimal debug directive tracking infrastructure to
  get more reliable source locations over the heuristic mode while
  having more compile-time overhead.

``debug`` mode is enabled when debug information
``-gline-directives-only`` (implied by ``-g1`` or higher) is available.
If this debug information is not available, the ``heuristic`` mode is
used which represents a best-effort approach towards accurate inline
hints. When the heuristic fails and we cannot show an accurate source
location for one or more hints, the source location of the initial
warning is used -- completely wrong locations are never used.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1571
Based-on: https://github.com/llvm/llvm-project/pull/73552
Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |   9 ++
 clang/include/clang/Basic/AttrDocs.td |   9 ++
 .../clang/Basic/DiagnosticFrontendKinds.td|   6 +
 clang/include/clang/Options/Options.td|  10 +-
 clang/lib/CodeGen/CGCall.cpp  |  24 ++--
 clang/lib/CodeGen/CodeGenAction.cpp   |  38 ++
 clang/test/CodeGen/attr-nomerge.cpp   |   6 +-
 clang/test/CodeGenCXX/builtin-invoke.cpp  |   4 +-
 .../inheriting-constructor-cleanup.cpp|   2 +-
 .../test/CodeGenCXX/type-aware-allocators.cpp |   2 +-
 .../coro-await-resume-eh.cpp  |   2 +-
 clang/test/DebugInfo/CXX/member-call.cpp  |   4 +-
 .../backend-attribute-inlining-cross-tu.c |  67 +++
 ...-attribute-inlining-debug-vs-heuristic.cpp |  92 ++
 .../backend-attribute-inlining-modes.c|  32 +
 .../Frontend/backend-attribute-inlining.c | 112 ++
 ...ibute_parallel_for_num_threads_codegen.cpp |   8 +-
 ..._parallel_for_simd_num_threads_codegen.cpp |  12 +-
 clang/test/OpenMP/scope_codegen.cpp   |   8 +-
 clang/test/OpenMP/single_codegen.cpp  |  12 +-
 ...ibute_parallel_for_num_threads_codegen.cpp |   4 +-
 ..._parallel_for_simd_num_threads_codegen.cpp |   6 +-
 clang/test/OpenMP/threadprivate_codegen.cpp   |  42 +++
 .../Inputs/basic-cplusplus.cpp.expected   |  41 +--
 ...plicit-template-instantiation.cpp.expected |  20 ++--
 llvm/include/llvm/IR/DiagnosticInfo.h |  26 +++-
 llvm/lib/IR/DiagnosticInfo.cpp|  38 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  44 +++
 28 files changed, 588 insertions(+), 92 deletions(-)
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-cross-tu.c
 create mode 100644 
clang/test/Frontend/backend-attribute-inlining-debug-vs-heuristic.cpp
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-modes.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 489a91d439133..17aa673296d13 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -187,6 +187,15 @@ Improvements to Clang's diagnostics
 int* p(int *in [[clang::noescape]]) { return in; }
  ^~
 
+- ``[[gnu::warning]]`` and ``[[gnu::error]]`` diagnostics now have notes
+  describing inlining locations. When a function with these attributes is
+  called from an inlined context, Clang can now show which functions were
+  inlined to reach the call. When debug info is available
+  (``-gline-directives-only`` (implicitly enabled at ``-g1``) or higher),
+  accurate source locations are used; otherwise, a heuristic fallback is used
+  with a note suggesting how to enable debug info for better accuracy.
+
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 6e2c73f924352..0d72688d80c50 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8411,6 +8411,15 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the inlining chain that led to
+the call is shown. This helps identify which call site triggered the diagnostic
+when the attributed function is called from multiple locations through inline
+functi

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

2026-01-29 Thread Aaron Ballman via cfe-commits


@@ -8397,6 +8397,18 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the
+``-fdiagnostics-show-inlining-chain`` option can be used to show the
+inlining chain that led to the call. This helps identify which call site
+triggered the diagnostic when the attributed function is called from
+multiple locations through inline functions.
+
+When enabled, this option automatically uses debug info for accurate source
+locations if available (``-gline-directives-only`` (implicitly enabled at
+``-g1``) or higher), or falls back to a heuristic based on metadata tracking.

AaronBallman wrote:

The parens seem a bit odd to me because "or higher" seems like it should be 
grouped with `-g1` and not `-gline-directives-only` (what does "higher" mean 
with "line-directives-only"?).

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-29 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Clang bits LGTM but I'd appreciate some more eyes on the codegen and LLVM parts 
before landing.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-29 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-22 Thread Fabrice de Gans via cfe-commits

Steelskin wrote:

> Should I apply the diff [the bot is talking 
> about](https://github.com/llvm/llvm-project/pull/174892#issuecomment-3740884157)?
>  Note that I didn't touch those files.

I opened #177344 to land these changes.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-21 Thread Bill Wendling via cfe-commits


@@ -92,10 +92,10 @@ void something_else_again() {
 // CHECK: call void @_ZN1AC1Ev({{.*}}) #[[ATTR0]]
 // CHECK: call void @_ZN1A1fEv({{.*}}) #[[ATTR0]]
 // CHECK: call void @_ZN1A1gEv({{.*}}) #[[ATTR0]]
-// CHECK: call void @_ZN1A2f1Ev() #[[ATTR0]]
-// CHECK: call void @_ZN1BC1Ev({{.*}}){{$}}
+// CHECK: call void @_ZN1A2f1Ev(){{.*}}#[[ATTR0]]
+// CHECK: call void @_ZN1BC1Ev({{.*}}){{.*}}{{$}}

bwendling wrote:

Never mind. Sorry for the spam.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-21 Thread Bill Wendling via cfe-commits


@@ -47,8 +47,8 @@ extern "C" void call_memptr(std::reference_wrapper 
wrapper) {
   // CHECK-EMPTY:
   // CHECK-NEXT: memptr.virtual:
   // CHECK-NEXT:   %vtable = load ptr, ptr %0, align 8
-  // CHECK-NEXT:   %1 = getelementptr i8, ptr %vtable, i64 sub (i64 ptrtoint 
(ptr @_ZN8Callable4funcEv to i64), i64 1), !nosanitize !2
-  // CHECK-NEXT:   %memptr.virtualfn = load ptr, ptr %1, align 8, !nosanitize 
!2
+  // CHECK-NEXT:   %1 = getelementptr i8, ptr %vtable, i64 sub (i64 ptrtoint 
(ptr @_ZN8Callable4funcEv to i64), i64 1), !nosanitize !
+  // CHECK-NEXT:   %memptr.virtualfn = load ptr, ptr %1, align 8, !nosanitize !

bwendling wrote:

Never mind. :-)

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-21 Thread Bill Wendling via cfe-commits


@@ -37,7 +37,7 @@ void f() {
   // EXCEPTIONS: %[[TMP1:.*]] = alloca %struct.S1
   // EXCEPTIONS: %[[TMP2:.*]] = alloca %struct.S2
   // EXCEPTIONS: invoke void (ptr, ptr, ptr, ptr, ...) 
@_ZN4BaseC2ERK2S1RK2S2PKcz(ptr {{.*}}, ptr noundef nonnull align 1 
dereferenceable(1) %[[TMP1]], ptr noundef nonnull align 1 dereferenceable(1) 
%[[TMP2]], ptr {{.*}})
-  // EXCEPTIONS-NEXT: to label %[[CONT:.*]] unwind label %[[LPAD:.*]]
+  // EXCEPTIONS-NEXT: to label %[[CONT:.*]] unwind label %[[LPAD:.*]], !srcloc

bwendling wrote:

Never mind. :-)

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-21 Thread Bill Wendling via cfe-commits


@@ -37,7 +37,7 @@ void f() {
   // EXCEPTIONS: %[[TMP1:.*]] = alloca %struct.S1
   // EXCEPTIONS: %[[TMP2:.*]] = alloca %struct.S2
   // EXCEPTIONS: invoke void (ptr, ptr, ptr, ptr, ...) 
@_ZN4BaseC2ERK2S1RK2S2PKcz(ptr {{.*}}, ptr noundef nonnull align 1 
dereferenceable(1) %[[TMP1]], ptr noundef nonnull align 1 dereferenceable(1) 
%[[TMP2]], ptr {{.*}})
-  // EXCEPTIONS-NEXT: to label %[[CONT:.*]] unwind label %[[LPAD:.*]]
+  // EXCEPTIONS-NEXT: to label %[[CONT:.*]] unwind label %[[LPAD:.*]], !srcloc

bwendling wrote:

Is `!srcloc` part of your changes? If not, then this and the other tests with 
similar changes, could be reverted.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-21 Thread Bill Wendling via cfe-commits


@@ -47,8 +47,8 @@ extern "C" void call_memptr(std::reference_wrapper 
wrapper) {
   // CHECK-EMPTY:
   // CHECK-NEXT: memptr.virtual:
   // CHECK-NEXT:   %vtable = load ptr, ptr %0, align 8
-  // CHECK-NEXT:   %1 = getelementptr i8, ptr %vtable, i64 sub (i64 ptrtoint 
(ptr @_ZN8Callable4funcEv to i64), i64 1), !nosanitize !2
-  // CHECK-NEXT:   %memptr.virtualfn = load ptr, ptr %1, align 8, !nosanitize 
!2
+  // CHECK-NEXT:   %1 = getelementptr i8, ptr %vtable, i64 sub (i64 ptrtoint 
(ptr @_ZN8Callable4funcEv to i64), i64 1), !nosanitize !
+  // CHECK-NEXT:   %memptr.virtualfn = load ptr, ptr %1, align 8, !nosanitize !

bwendling wrote:

This also looks extraneous.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-21 Thread Fabrice de Gans via cfe-commits

Steelskin wrote:

> > Should I apply the diff [the bot is talking 
> > about](https://github.com/llvm/llvm-project/pull/174892#issuecomment-3740884157)?
> >  Note that I didn't touch those files.
> 
> I would ignore the bot, that seems like a false positive; CC @tstellar 
> @petrhosek as infra folks

This is not a false positive in the sense that these headers are included by 
the header you are modifying `llvm/include/llvm/IR/DiagnosticInfo.h` and are 
missing the annotations. However, your PR did not cause the issue so feel free 
to ignore it. I will land the fix separately, thanks for tagging me!

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-21 Thread Tom Stellard via cfe-commits

tstellar wrote:

> > Should I apply the diff [the bot is talking 
> > about](https://github.com/llvm/llvm-project/pull/174892#issuecomment-3740884157)?
> >  Note that I didn't touch those files.
> 
> I would ignore the bot, that seems like a false positive; CC @tstellar 
> @petrhosek as infra folks

That is fine to ignore.  fyi @Steelskin 

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-21 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Should I apply the diff [the bot is talking 
> about](https://github.com/llvm/llvm-project/pull/174892#issuecomment-3740884157)?
>  Note that I didn't touch those files.

I would ignore the bot, that seems like a false positive; CC @tstellar 
@petrhosek as infra folks 

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-20 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> @AaronBallman
> 
> > That's what I was envisioning as well
> 
> After removing the flag and running the tests, I'm wondering if we should 
> keep the flag but just have it on by default. This is because there's a bunch 
> of clang tests that are not expecting to see my `srcloc` metadata and I'd 
> like to specify `-fno-diagnostics-show-inlining-chain` on those tests.
> 
> I guess the two options are:
> 
> 1. update all 16 of the tests, or
> 
> 2. add `-fno-diagnostics-show-inlining-chain` to them
> 
> 
> Thoughts?
> 
> edit: I have a patch altering all the tests and it wasn't too bad, still want 
> to know opinions on this though.
> FWIW, here's the stat from fixing stale tests.
> 
> ```
>  clang/test/CodeGen/attr-nomerge.cpp  
>   |  6 +++---
>  clang/test/CodeGenCXX/builtin-invoke.cpp 
>   |  4 ++--
>  clang/test/CodeGenCXX/inheriting-constructor-cleanup.cpp 
>   |  2 +-
>  clang/test/CodeGenCXX/type-aware-allocators.cpp  
>   |  2 +-
>  clang/test/CodeGenCoroutines/coro-await-resume-eh.cpp
>   |  2 +-
>  clang/test/DebugInfo/CXX/member-call.cpp 
>   |  4 ++--
>  clang/test/Frontend/backend-attribute-inlining-modes.c   
>   | 26 --
>  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
>   |  8 
>  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp   
>   | 12 ++--
>  clang/test/OpenMP/scope_codegen.cpp  
>   |  8 
>  clang/test/OpenMP/single_codegen.cpp 
>   | 12 ++--
>  clang/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp  
>   |  4 ++--
>  clang/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp 
>   |  6 +++---
>  clang/test/OpenMP/threadprivate_codegen.cpp  
>   | 42 +-
>  clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected   
>   | 41 +
>  
> clang/test/utils/update_cc_test_checks/Inputs/explicit-template-instantiation.cpp.expected
>  | 20 ++--
>  16 files changed, 103 insertions(+), 96 deletions(-)
> ```

For 16 tests, I'd say it's better to fix the tests.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-16 Thread Justin Stitt via cfe-commits

JustinStitt wrote:

@AaronBallman 
> That's what I was envisioning as well


After removing the flag and running the test I now believe that we should keep 
the flag but just have it on by default. This is because there's a WHOLE BUNCH 
of llvm IR tests that are not expecting to see my `srcloc` metadata and I'd 
love to specify ``-fno-diagnostics-show-inlining-chain`` on those tests.

I guess the two options are 1) update all the tests, 2) add `-fno...` to them

Thoughts?

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-15 Thread Justin Stitt via cfe-commits

JustinStitt wrote:

@nickdesaulniers Are you suggesting removing the flag 
`-fdiagnostics-show-inlining-chain` **as well as** the heuristic mode and just 
have `-gline-directives-only` enable these hints (With a meta hint about -g1 or 
greater on the WarningAttr itself)?

I am all for removing the flag but the accuracy of the heuristic mode seems to 
be pretty good and judging from my benchmarking it has no impact on build 
times. I know some folks have complained about the memory usage of full LLVM 
builds so perhaps I should benchmark to see if there is a measurable memory 
usage increase. I imagine the peak memory usage occurs during linking and all 
the `srcloc` is gone by then so I don't forsee any increase in peak memory 
usage.

I reckon we can remove the flag `-fdiagnostics-show-inlining-chain` and have 
the heuristic mode on by default with the meta hint about 
`-gline-directives-only` which, if enabled, would turn some better tracking 
utilizing the debug info.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-15 Thread Kees Cook via cfe-commits

kees wrote:

I may be misunderstanding what you're saying about 
-fdiagnostics-show-inlining-chain. Do you mean enable its functionality by 
default so it is not necessary to specify the flag, or do you mean remove its 
functionality entirely and only have the reporting provided by 
-gline-directives-only?

For Linux I want a behavior that always gives us the inlining report with 
minimal build time/size changes. The intention is to universally enable this 
behavior by default on all Linux builds so we can finally close the diagnostic 
gap between GCC and Clang. FORTIFY is not the only place this happens; it's 
just the one I see most often. This cannot be a two step "enable more 
diagnostics" thing: it needs to be visible during the Linux build, always, just 
as we already see from GCC.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-13 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> Previously @AaronBallman has expressed that diagnostics should not differ 
> between optimization levels. I think there's a subtle difference here; for 
> backend diagnostics, encouraging the user to enable debug info can add 
> additional/helpful notes, in this case for potentially stopping buffer 
> overflows known at compile time (for the Linux kernel's implementation of 
> FORTIFY_SOURCE) for which clang is currently strictly worse than GCC here.

The notion of diagnosing buffer overflows at compile-time sounds great, but 
doing it in the backend has practical problems... among other issues, we've had 
multiple bug reports that boiled down to "a false-positive diagnostic triggered 
because of a missed optimization" . Anyway, that's only indirectly related to 
this patch.

I don't think modifying the text of the notes based on information we have 
available will cause any practical issues.  The consistency issue is mostly 
about whether the primary diagnostic is consistent.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-13 Thread Nick Desaulniers via cfe-commits

nickdesaulniers wrote:

I think @dwblaikie also expressed similar sentiments (or perhaps I'm mixing up 
a conversation I had with David with Aaron, IDK). Anyways, all feedback welcome 
here.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-13 Thread Nick Desaulniers via cfe-commits

nickdesaulniers wrote:

I'd be curious @AaronBallman 's thoughts on having note diagnostics like this 
where the note encourages you to enable debug info for better (more precise) 
diagnostics. I don't think there's _any_ prior art in Clang here.

If @AaronBallman is cool with the idea, then towards the goal of improved 
ergonomics, I'd be curious if we could push further and not even have/add 
`-fdiagnostics-show-inlining-chain` at all; attach the note on instances of 
`-Werror`/`-Wwarning` that `-gline-directives-only` (and higher) can give you 
additional info (hopefully the presence of debug info doesn't change inlining 
decisions :P).

If @AaronBallman is not cool with the idea, then I think this PR has to be 
scuttled.

Previously @AaronBallman has expressed that diagnostics should not differ 
between optimization levels.  I think there's a subtle difference here; for 
_backend_ diagnostics, encouraging the user to enable debug info can add 
additional/helpful notes, in this case for potentially stopping buffer 
overflows _known at compile time_ (for the Linux kernel's implementation of 
FORTIFY_SOURCE) for which clang is currently _strictly worse than GCC here_.

@AaronBallman what are your thoughts here?

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-13 Thread Justin Stitt via cfe-commits

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

>From 9bf61d2ef2ae81d6aa4c5f5bd7e0aa062298f0e0 Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 6 Jan 2026 15:36:33 -0800
Subject: [PATCH 1/6] [Clang] Add -fdiagnostics-show-inlining-chain for
 warning/error attributes

When functions marked with __attribute__((warning/error)) are called
through inlined functions, Clang now optionally shows the inlining chain
that led to the call.

Three modes are supported:

- ``none`` is the default and results in no inline notes being shown
  (matches the behavior before this change).

- ``heuristic`` tries to guess which functions will be inlined to
  minimize the amount of source locations kept in memory and visible in
  LLVM IR.

- ``debug`` leverages minimal debug directive tracking infrastructure to
  get more reliable source locations over the heuristic mode while
  having more compile-time overhead.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1571
Based-on: https://github.com/llvm/llvm-project/pull/73552
Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |  15 +++
 clang/include/clang/Basic/AttrDocs.td |   7 ++
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   8 ++
 .../clang/Basic/DiagnosticFrontendKinds.td|   6 +
 clang/include/clang/Options/Options.td|  15 +++
 clang/lib/CodeGen/CGCall.cpp  |  23 ++--
 clang/lib/CodeGen/CodeGenAction.cpp   |  31 +
 clang/lib/Driver/ToolChains/Clang.cpp |   7 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../backend-attribute-inlining-cross-tu.c |  64 ++
 ...nd-attribute-inlining-debug-vs-heuristic.c |  28 +
 .../backend-attribute-inlining-modes.c|  47 
 .../Frontend/backend-attribute-inlining.c | 109 ++
 llvm/include/llvm/IR/DiagnosticInfo.h |  26 -
 llvm/lib/IR/DiagnosticInfo.cpp|  38 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  44 +++
 17 files changed, 468 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-cross-tu.c
 create mode 100644 
clang/test/Frontend/backend-attribute-inlining-debug-vs-heuristic.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-modes.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b91d99647855c..2723ff61ef022 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -90,6 +90,21 @@ Non-comprehensive list of changes in this release
 
 New Compiler Flags
 --
+- New option ``-fno-sanitize-debug-trap-reasons`` added to disable emitting 
trap reasons into the debug info when compiling with trapping UBSan (e.g. 
``-fsanitize-trap=undefined``).
+- New option ``-fsanitize-debug-trap-reasons=`` added to control emitting trap 
reasons into the debug info when compiling with trapping UBSan (e.g. 
``-fsanitize-trap=undefined``).
+- New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
+- The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
+- New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain=`` added to show inlining 
chain
+  notes for ``__attribute__((warning))`` and ``__attribute__((error))``
+  diagnostics. When a function with these attributes is called from an inlined
+  context, Clang can now show which functions were inlined to reach the call.
+  Modes: ``none`` (default), ``heuristic`` (uses metadata tracking), ``debug``
+  (uses debug info for accurate source locations).
+
+Lanai Support
+^^
+- The option ``-mcmodel={small,medium,large}`` is supported again.
 
 Deprecated Compiler Flags
 -
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 812b48058d189..97331b1175cc9 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8397,6 +8397,13 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the
+``-fdiagnostics-show-inlining-chain=`` option can be used to show the
+inlining chain that led to the call. This helps identify which call site
+triggered the diagnostic when the attributed function is called from
+multiple locations through inline functions. See ``clang --help`` for
+available modes.
   }];
 }
 
diff --git a/clang/include/clang/

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

2026-01-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: LLVM ABI annotation checker, ids-check found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git diff origin/main HEAD -- 'llvm/include/llvm/**/*.h' 
'llvm/include/llvm-c/**/*.h' 'llvm/include/llvm/Demangle/**/*.h'
Then run idt on the changed files with appropriate --export-macro and 
--include-header flags.
``

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:





View the diff from ids-check here.


``diff
diff --git a/llvm/include/llvm/IR/User.h b/llvm/include/llvm/IR/User.h
index da886a508..d68414c89 100644
--- a/llvm/include/llvm/IR/User.h
+++ b/llvm/include/llvm/IR/User.h
@@ -18,6 +18,7 @@
 #ifndef LLVM_IR_USER_H
 #define LLVM_IR_USER_H
 
+#include "llvm/include/llvm/Support/Compiler.h"
 #include "llvm/ADT/iterator.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/IR/Use.h"
@@ -142,7 +143,7 @@ protected:
 
 protected:
   // Use deleteValue() to delete a generic User.
-  ~User();
+  LLVM_ABI ~User();
 
 public:
   User(const User &) = delete;
diff --git a/llvm/include/llvm/Support/BranchProbability.h 
b/llvm/include/llvm/Support/BranchProbability.h
index 61a032813..55c26b119 100644
--- a/llvm/include/llvm/Support/BranchProbability.h
+++ b/llvm/include/llvm/Support/BranchProbability.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_SUPPORT_BRANCHPROBABILITY_H
 #define LLVM_SUPPORT_BRANCHPROBABILITY_H
 
+#include "llvm/include/llvm/Support/Compiler.h"
 #include "llvm/ADT/ADL.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/DataTypes.h"
@@ -101,7 +102,7 @@ public:
   LLVM_ABI uint64_t scaleByInverse(uint64_t Num) const;
 
   /// Compute pow(Probability, N).
-  BranchProbability pow(unsigned N) const;
+  LLVM_ABI BranchProbability pow(unsigned N) const;
 
   BranchProbability &operator+=(BranchProbability RHS) {
 assert(N != UnknownN && RHS.N != UnknownN &&
diff --git a/llvm/include/llvm/Support/SourceMgr.h 
b/llvm/include/llvm/Support/SourceMgr.h
index 43f7e27c2..a7ff4b1d2 100644
--- a/llvm/include/llvm/Support/SourceMgr.h
+++ b/llvm/include/llvm/Support/SourceMgr.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_SUPPORT_SOURCEMGR_H
 #define LLVM_SUPPORT_SOURCEMGR_H
 
+#include "llvm/include/llvm/Support/Compiler.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
@@ -106,14 +107,14 @@ public:
   LLVM_ABI SourceMgr();
   /// Create new source manager with the capability of finding include files
   /// via the provided file system.
-  explicit SourceMgr(IntrusiveRefCntPtr FS);
+  LLVM_ABI explicit SourceMgr(IntrusiveRefCntPtr FS);
   SourceMgr(const SourceMgr &) = delete;
   SourceMgr &operator=(const SourceMgr &) = delete;
-  SourceMgr(SourceMgr &&);
-  SourceMgr &operator=(SourceMgr &&);
+  LLVM_ABI SourceMgr(SourceMgr &&);
+  LLVM_ABI SourceMgr &operator=(SourceMgr &&);
   LLVM_ABI ~SourceMgr();
 
-  IntrusiveRefCntPtr getVirtualFileSystem() const;
+  LLVM_ABI IntrusiveRefCntPtr getVirtualFileSystem() const;
   LLVM_ABI void setVirtualFileSystem(IntrusiveRefCntPtr FS);
 
   /// Return the include directories of this source manager.

``




https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-12 Thread Justin Stitt via cfe-commits

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

>From 6e61f3b8d09284d2f03389827e65b4da2c79e1f3 Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 6 Jan 2026 15:36:33 -0800
Subject: [PATCH 1/6] [Clang] Add -fdiagnostics-show-inlining-chain for
 warning/error attributes

When functions marked with __attribute__((warning/error)) are called
through inlined functions, Clang now optionally shows the inlining chain
that led to the call.

Three modes are supported:

- ``none`` is the default and results in no inline notes being shown
  (matches the behavior before this change).

- ``heuristic`` tries to guess which functions will be inlined to
  minimize the amount of source locations kept in memory and visible in
  LLVM IR.

- ``debug`` leverages minimal debug directive tracking infrastructure to
  get more reliable source locations over the heuristic mode while
  having more compile-time overhead.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1571
Based-on: https://github.com/llvm/llvm-project/pull/73552
Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |   6 +
 clang/include/clang/Basic/AttrDocs.td |   7 ++
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   8 ++
 .../clang/Basic/DiagnosticFrontendKinds.td|   6 +
 clang/include/clang/Options/Options.td|  15 +++
 clang/lib/CodeGen/CGCall.cpp  |  23 ++--
 clang/lib/CodeGen/CodeGenAction.cpp   |  31 +
 clang/lib/Driver/ToolChains/Clang.cpp |   7 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../backend-attribute-inlining-cross-tu.c |  64 ++
 ...nd-attribute-inlining-debug-vs-heuristic.c |  28 +
 .../backend-attribute-inlining-modes.c|  47 
 .../Frontend/backend-attribute-inlining.c | 109 ++
 llvm/include/llvm/IR/DiagnosticInfo.h |  26 -
 llvm/lib/IR/DiagnosticInfo.cpp|  38 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  44 +++
 17 files changed, 459 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-cross-tu.c
 create mode 100644 
clang/test/Frontend/backend-attribute-inlining-debug-vs-heuristic.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-modes.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c56d2015f7a3f..e90adfb50dd27 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -363,6 +363,12 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain=`` added to show inlining 
chain
+  notes for ``__attribute__((warning))`` and ``__attribute__((error))``
+  diagnostics. When a function with these attributes is called from an inlined
+  context, Clang can now show which functions were inlined to reach the call.
+  Modes: ``none`` (default), ``heuristic`` (uses metadata tracking), ``debug``
+  (uses debug info for accurate source locations).
 
 Lanai Support
 ^^
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 812b48058d189..97331b1175cc9 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8397,6 +8397,13 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the
+``-fdiagnostics-show-inlining-chain=`` option can be used to show the
+inlining chain that led to the call. This helps identify which call site
+triggered the diagnostic when the attributed function is called from
+multiple locations through inline functions. See ``clang --help`` for
+available modes.
   }];
 }
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index baf8b093c10e6..59f12a821fa53 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -76,6 +76,8 @@ CODEGENOPT(CallGraphSection, 1, 0, Benign) ///< Emit a call 
graph section into t
///< object file.
 CODEGENOPT(EmitCallSiteInfo, 1, 0, Benign) ///< Emit call site info only in 
the case of
///< '-g' + 'O>0' level.
+/// Tracking inlining chai

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

2026-01-09 Thread Justin Stitt via cfe-commits

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

>From ea02427b27288e70acaf87b0c2ad53d897f13e80 Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 6 Jan 2026 15:36:33 -0800
Subject: [PATCH 1/6] [Clang] Add -fdiagnostics-show-inlining-chain for
 warning/error attributes

When functions marked with __attribute__((warning/error)) are called
through inlined functions, Clang now optionally shows the inlining chain
that led to the call.

Three modes are supported:

- ``none`` is the default and results in no inline notes being shown
  (matches the behavior before this change).

- ``heuristic`` tries to guess which functions will be inlined to
  minimize the amount of source locations kept in memory and visible in
  LLVM IR.

- ``debug`` leverages minimal debug directive tracking infrastructure to
  get more reliable source locations over the heuristic mode while
  having more compile-time overhead.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1571
Based-on: https://github.com/llvm/llvm-project/pull/73552
Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |   6 +
 clang/include/clang/Basic/AttrDocs.td |   7 ++
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   8 ++
 .../clang/Basic/DiagnosticFrontendKinds.td|   6 +
 clang/include/clang/Options/Options.td|  15 +++
 clang/lib/CodeGen/CGCall.cpp  |  23 ++--
 clang/lib/CodeGen/CodeGenAction.cpp   |  31 +
 clang/lib/Driver/ToolChains/Clang.cpp |   7 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../backend-attribute-inlining-cross-tu.c |  64 ++
 ...nd-attribute-inlining-debug-vs-heuristic.c |  28 +
 .../backend-attribute-inlining-modes.c|  47 
 .../Frontend/backend-attribute-inlining.c | 109 ++
 llvm/include/llvm/IR/DiagnosticInfo.h |  26 -
 llvm/lib/IR/DiagnosticInfo.cpp|  38 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  44 +++
 17 files changed, 459 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-cross-tu.c
 create mode 100644 
clang/test/Frontend/backend-attribute-inlining-debug-vs-heuristic.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-modes.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8ef6564bd80e6..cf17f8a052cbb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,12 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain=`` added to show inlining 
chain
+  notes for ``__attribute__((warning))`` and ``__attribute__((error))``
+  diagnostics. When a function with these attributes is called from an inlined
+  context, Clang can now show which functions were inlined to reach the call.
+  Modes: ``none`` (default), ``heuristic`` (uses metadata tracking), ``debug``
+  (uses debug info for accurate source locations).
 
 Lanai Support
 ^^
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 812b48058d189..97331b1175cc9 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8397,6 +8397,13 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the
+``-fdiagnostics-show-inlining-chain=`` option can be used to show the
+inlining chain that led to the call. This helps identify which call site
+triggered the diagnostic when the attributed function is called from
+multiple locations through inline functions. See ``clang --help`` for
+available modes.
   }];
 }
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 3784844ef1028..223e803a22c6c 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -76,6 +76,8 @@ CODEGENOPT(CallGraphSection, 1, 0, Benign) ///< Emit a call 
graph section into t
///< object file.
 CODEGENOPT(EmitCallSiteInfo, 1, 0, Benign) ///< Emit call site info only in 
the case of
///< '-g' + 'O>0' level.
+/// Tracking inlining chai

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

2026-01-08 Thread via cfe-commits

github-actions[bot] wrote:


# :window: Windows x64 Test Results

* 129269 tests passed
* 2852 tests skipped
* 1 test failed

## Failed Tests
(click on a test name to see its output)

### Clang

Clang.Frontend/backend-attribute-inlining-debug-vs-heuristic.cpp

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
c:\_work\llvm-project\llvm-project\build\bin\clang.exe -cc1 -internal-isystem 
C:\_work\llvm-project\llvm-project\build\lib\clang\22\include -nostdsysteminc 
-O2 -emit-obj -fdiagnostics-show-inlining-chain 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp
 -o /dev/null 2>&1 | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp
 --check-prefix=HEURISTIC
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\clang.exe' 
-cc1 -internal-isystem 
'C:\_work\llvm-project\llvm-project\build\lib\clang\22\include' -nostdsysteminc 
-O2 -emit-obj -fdiagnostics-show-inlining-chain 
'C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp'
 -o /dev/null
# note: command had no output on stdout or stderr
# executed command: 
'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 
'C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp'
 --check-prefix=HEURISTIC
# .---command stderr
# | 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp:27:15:
 error: HEURISTIC: expected string not found in input
# | // HEURISTIC: :16:{{.*}}: warning: call to 'dangerous()'
# |   ^
# | :1:1: note: scanning from here
# | 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp:16:5:
 warning: call to 'void __cdecl dangerous(void)' declared with 'warning' 
attribute: dangerous function [-Wattribute-warning]
# | ^
# | :1:104: note: possible intended match here
# | 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp:16:5:
 warning: call to 'void __cdecl dangerous(void)' declared with 'warning' 
attribute: dangerous function [-Wattribute-warning]
# | 
   ^
# | 
# | Input file: 
# | Check file: 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# | 1: 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp:16:5:
 warning: call to 'void __cdecl dangerous(void)' declared with 'warning' 
attribute: dangerous function [-Wattribute-warning] 
# | check:27'0 
X~~
 error: no match found
# | check:27'1  
  ? 

   possible intended match
# | 2:  16 | dangerous(); 
# | check:27'0 ~~~
# | 3:  | ^ 
# | check:27'0 ~
# | 4: 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp:16:5:
 warning: call to 'void __cdecl dangerous(void)' declared with 'warning' 
attribute: dangerous function [-Wattribute-warning] 
# | check:27'0 
~~~
# | 5: 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp:16:5:
 note: called by function 'void __cdecl wrapper(void)' 
# | check:27'0 
~
# | 6: 
C:\_work\llvm-project\llvm-project\clang\test\Frontend\backend-attribute-inlining-debug-vs-heuristic.cpp:16:5:
 note: inlined by function 'void __cdecl middle(void)' 
# | check:27'0 
~
# | .
# | .
# | .
# | >>
# `-
# error: command failed

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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -6048,13 +6048,22 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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 __attribute__((error/warning)) diagnostics.
+  // In heuristic mode, also track inline/static calls for inlining chain.
+  if (TargetDecl) {
+bool NeedSrcLoc = TargetDecl->hasAttr();
+if (!NeedSrcLoc && CGM.getCodeGenOpts().getInliningChain() ==
+   CodeGenOptions::Inlining_Heuristic) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->isInlineSpecified() ||
+ FD->hasAttr() ||
+ FD->getStorageClass() == SC_Static;

JustinStitt wrote:

Done with [`1a22581` 
(#174892)](https://github.com/llvm/llvm-project/pull/174892/commits/1a2258184323622af390946c70b63afb12762276)

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -348,6 +348,13 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain`` added to show inlining chain
+  notes for ``[[gnu::warning]]`` and ``[[gnu::error]]`` diagnostics. When a
+  function with these attributes is called from an inlined context, Clang can
+  now show which functions were inlined to reach the call. When debug info is
+  available (``-gline-directives-only`` (implicitly enabled at ``-g1``) or

JustinStitt wrote:

Done in [`1a22581` 
(#174892)](https://github.com/llvm/llvm-project/pull/174892/commits/1a2258184323622af390946c70b63afb12762276).
 I also added the note to the diagnostic note that gets emitted when in 
heuristic mode.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -6048,13 +6048,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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();
+if (!NeedSrcLoc && CGM.getCodeGenOpts().ShowInliningChain) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->isInlineSpecified() ||

JustinStitt wrote:

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

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits

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

>From ea02427b27288e70acaf87b0c2ad53d897f13e80 Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 6 Jan 2026 15:36:33 -0800
Subject: [PATCH 1/5] [Clang] Add -fdiagnostics-show-inlining-chain for
 warning/error attributes

When functions marked with __attribute__((warning/error)) are called
through inlined functions, Clang now optionally shows the inlining chain
that led to the call.

Three modes are supported:

- ``none`` is the default and results in no inline notes being shown
  (matches the behavior before this change).

- ``heuristic`` tries to guess which functions will be inlined to
  minimize the amount of source locations kept in memory and visible in
  LLVM IR.

- ``debug`` leverages minimal debug directive tracking infrastructure to
  get more reliable source locations over the heuristic mode while
  having more compile-time overhead.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1571
Based-on: https://github.com/llvm/llvm-project/pull/73552
Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |   6 +
 clang/include/clang/Basic/AttrDocs.td |   7 ++
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   8 ++
 .../clang/Basic/DiagnosticFrontendKinds.td|   6 +
 clang/include/clang/Options/Options.td|  15 +++
 clang/lib/CodeGen/CGCall.cpp  |  23 ++--
 clang/lib/CodeGen/CodeGenAction.cpp   |  31 +
 clang/lib/Driver/ToolChains/Clang.cpp |   7 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../backend-attribute-inlining-cross-tu.c |  64 ++
 ...nd-attribute-inlining-debug-vs-heuristic.c |  28 +
 .../backend-attribute-inlining-modes.c|  47 
 .../Frontend/backend-attribute-inlining.c | 109 ++
 llvm/include/llvm/IR/DiagnosticInfo.h |  26 -
 llvm/lib/IR/DiagnosticInfo.cpp|  38 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  44 +++
 17 files changed, 459 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-cross-tu.c
 create mode 100644 
clang/test/Frontend/backend-attribute-inlining-debug-vs-heuristic.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-modes.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8ef6564bd80e6..cf17f8a052cbb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,12 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain=`` added to show inlining 
chain
+  notes for ``__attribute__((warning))`` and ``__attribute__((error))``
+  diagnostics. When a function with these attributes is called from an inlined
+  context, Clang can now show which functions were inlined to reach the call.
+  Modes: ``none`` (default), ``heuristic`` (uses metadata tracking), ``debug``
+  (uses debug info for accurate source locations).
 
 Lanai Support
 ^^
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 812b48058d189..97331b1175cc9 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8397,6 +8397,13 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the
+``-fdiagnostics-show-inlining-chain=`` option can be used to show the
+inlining chain that led to the call. This helps identify which call site
+triggered the diagnostic when the attributed function is called from
+multiple locations through inline functions. See ``clang --help`` for
+available modes.
   }];
 }
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 3784844ef1028..223e803a22c6c 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -76,6 +76,8 @@ CODEGENOPT(CallGraphSection, 1, 0, Benign) ///< Emit a call 
graph section into t
///< object file.
 CODEGENOPT(EmitCallSiteInfo, 1, 0, Benign) ///< Emit call site info only in 
the case of
///< '-g' + 'O>0' level.
+/// Tracking inlining chai

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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -6048,13 +6048,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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.

JustinStitt wrote:

Do you like the note as written in 38e8f6dade4a72c05106a46fbe7df6ed3b311fe6?

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -348,6 +348,13 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain`` added to show inlining chain
+  notes for ``[[gnu::warning]]`` and ``[[gnu::error]]`` diagnostics. When a
+  function with these attributes is called from an inlined context, Clang can
+  now show which functions were inlined to reach the call. When debug info is
+  available (``-gline-directives-only`` or higher), accurate source locations

JustinStitt wrote:

Good suggestion, I took it in 38e8f6dade4a72c05106a46fbe7df6ed3b311fe6 but 
dropped the extraneous paren. thanks

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits

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

>From ea02427b27288e70acaf87b0c2ad53d897f13e80 Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 6 Jan 2026 15:36:33 -0800
Subject: [PATCH 1/3] [Clang] Add -fdiagnostics-show-inlining-chain for
 warning/error attributes

When functions marked with __attribute__((warning/error)) are called
through inlined functions, Clang now optionally shows the inlining chain
that led to the call.

Three modes are supported:

- ``none`` is the default and results in no inline notes being shown
  (matches the behavior before this change).

- ``heuristic`` tries to guess which functions will be inlined to
  minimize the amount of source locations kept in memory and visible in
  LLVM IR.

- ``debug`` leverages minimal debug directive tracking infrastructure to
  get more reliable source locations over the heuristic mode while
  having more compile-time overhead.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1571
Based-on: https://github.com/llvm/llvm-project/pull/73552
Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |   6 +
 clang/include/clang/Basic/AttrDocs.td |   7 ++
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   8 ++
 .../clang/Basic/DiagnosticFrontendKinds.td|   6 +
 clang/include/clang/Options/Options.td|  15 +++
 clang/lib/CodeGen/CGCall.cpp  |  23 ++--
 clang/lib/CodeGen/CodeGenAction.cpp   |  31 +
 clang/lib/Driver/ToolChains/Clang.cpp |   7 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../backend-attribute-inlining-cross-tu.c |  64 ++
 ...nd-attribute-inlining-debug-vs-heuristic.c |  28 +
 .../backend-attribute-inlining-modes.c|  47 
 .../Frontend/backend-attribute-inlining.c | 109 ++
 llvm/include/llvm/IR/DiagnosticInfo.h |  26 -
 llvm/lib/IR/DiagnosticInfo.cpp|  38 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  44 +++
 17 files changed, 459 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-cross-tu.c
 create mode 100644 
clang/test/Frontend/backend-attribute-inlining-debug-vs-heuristic.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-modes.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8ef6564bd80e6..cf17f8a052cbb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,12 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain=`` added to show inlining 
chain
+  notes for ``__attribute__((warning))`` and ``__attribute__((error))``
+  diagnostics. When a function with these attributes is called from an inlined
+  context, Clang can now show which functions were inlined to reach the call.
+  Modes: ``none`` (default), ``heuristic`` (uses metadata tracking), ``debug``
+  (uses debug info for accurate source locations).
 
 Lanai Support
 ^^
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 812b48058d189..97331b1175cc9 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8397,6 +8397,13 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the
+``-fdiagnostics-show-inlining-chain=`` option can be used to show the
+inlining chain that led to the call. This helps identify which call site
+triggered the diagnostic when the attributed function is called from
+multiple locations through inline functions. See ``clang --help`` for
+available modes.
   }];
 }
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 3784844ef1028..223e803a22c6c 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -76,6 +76,8 @@ CODEGENOPT(CallGraphSection, 1, 0, Benign) ///< Emit a call 
graph section into t
///< object file.
 CODEGENOPT(EmitCallSiteInfo, 1, 0, Benign) ///< Emit call site info only in 
the case of
///< '-g' + 'O>0' level.
+/// Tracking inlining chai

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

2026-01-08 Thread Justin Stitt via cfe-commits

https://github.com/JustinStitt edited 
https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -6048,13 +6048,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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();
+if (!NeedSrcLoc && CGM.getCodeGenOpts().ShowInliningChain) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->isInlineSpecified() ||

JustinStitt wrote:

You mean when compared to `isInlineSpecified`? I think `isInlined` is a broader 
check encompassing `isInlineSpecified` (which checks for explicit inline 
keyword) and other criteria likely to result in a method being inlined. I put 
both here because I don't know the difference and I got better results 
(especially with C++ code) with both included in the heuristic.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -6048,13 +6048,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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();

JustinStitt wrote:

AFAICT, `ErrorAttr` holds information about whether it is a warning or an 
error, two modes of the same attr.

Attrs.inc:5179

```c
class CLANG_ABI ErrorAttr : public InheritableAttr {
unsigned userDiagnosticLength;
char *userDiagnostic;

public:
  enum Spelling {
GNU_error = 0,
CXX11_gnu_error = 1,
C23_gnu_error = 2,
GNU_warning = 3,
CXX11_gnu_warning = 4,
C23_gnu_warning = 5,
SpellingNotCalculated = 15
...
``` 

and it can look into these spellings with 

```c
  bool isWarning() const { return getAttributeSpellingListIndex() == 3 ||
getAttributeSpellingListIndex() == 4 ||
getAttributeSpellingListIndex() == 5; }
```

I can't find a `WarningAttr` proper

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Nick Desaulniers via cfe-commits

https://github.com/nickdesaulniers edited 
https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Nick Desaulniers via cfe-commits


@@ -2253,6 +2253,14 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   Opts.getDebugInfo() == llvm::codegenoptions::NoDebugInfo)
 Opts.setDebugInfo(llvm::codegenoptions::LocTrackingOnly);
 
+  // Debug mode for inlining chain diagnostics requires at least
+  // -gline-directives-only to track inlining locations via DILocation.
+  if (Opts.getInliningChain() == CodeGenOptions::Inlining_Debug &&
+  Opts.getDebugInfo() < llvm::codegenoptions::DebugDirectivesOnly) {
+Diags.Report(diag::warn_fe_inlining_debug_requires_g);
+Opts.setInliningChain(CodeGenOptions::Inlining_Heuristic);
+  }

nickdesaulniers wrote:

> it can get a bit noisy when there are multiple diagnostics.

I'm ok with that. If your code emits multiple instances of _any_ diagnostic 
that additionally has a note attached, clang generally doesn't dedup the notes 
IIRC, so that's in line with the status quo.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Nick Desaulniers via cfe-commits


@@ -6048,13 +6048,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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();
+if (!NeedSrcLoc && CGM.getCodeGenOpts().ShowInliningChain) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->isInlineSpecified() ||

nickdesaulniers wrote:

Just curious, what does `isInlined` _mean_ for a `FunctionDecl`?

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Nick Desaulniers via cfe-commits


@@ -6048,13 +6048,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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.

nickdesaulniers wrote:

It may be worth noting in this comment that this is conservative; just because 
the function is marked static or always_inline does not 100% guaruntee inline 
substitution _will_ be performed by the middle end.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Nick Desaulniers via cfe-commits


@@ -6048,13 +6048,23 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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();

nickdesaulniers wrote:

Do we need to check `WarningAttr`, too?

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Nick Desaulniers via cfe-commits


@@ -348,6 +348,13 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain`` added to show inlining chain
+  notes for ``[[gnu::warning]]`` and ``[[gnu::error]]`` diagnostics. When a
+  function with these attributes is called from an inlined context, Clang can
+  now show which functions were inlined to reach the call. When debug info is
+  available (``-gline-directives-only`` or higher), accurate source locations

nickdesaulniers wrote:

If you use `diagtool tree`, you'll get a printout of the hierarchy of 
diagnostic group flags from clang. I assume that `-gline-directives-only` is 
implicitly enabled at `-g1` (and higher).  Verify that assumption; if it holds, 
it might be worth adding:

```suggestion
  available (``-gline-directives-only`` (implicitly enabled at ``-O1``)) or 
higher), accurate source locations
```

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Nick Desaulniers via cfe-commits


@@ -6048,13 +6048,22 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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 __attribute__((error/warning)) diagnostics.
+  // In heuristic mode, also track inline/static calls for inlining chain.
+  if (TargetDecl) {
+bool NeedSrcLoc = TargetDecl->hasAttr();
+if (!NeedSrcLoc && CGM.getCodeGenOpts().getInliningChain() ==
+   CodeGenOptions::Inlining_Heuristic) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->isInlineSpecified() ||
+ FD->hasAttr() ||
+ FD->getStorageClass() == SC_Static;

nickdesaulniers wrote:

Please add a .cpp file unit test testing the behavior of callees declared in 
anonymous namespaces, to prove to reviewers this works as intended in C++ mode.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits

https://github.com/JustinStitt edited 
https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits

JustinStitt wrote:

@nickdesaulniers 
> Hmm...I think we can improve the ergonomics here a little bit. I feel like it 
> should be possible to have 2 modes instead of three. Like in CGCall if 
> `-gline-directives-only` or higher is set, then we can elide the `srcloc`. 
> Then when a dontcall is triggered we scan for (possibly absent) debug info. 
> If that doesn't exist, fall back to looking for `srcloc`. idk, something just 
> feels off about a ternary flag, with a second flag required to use one of the 
> the three states. Most flags are binary, and perhaps the tacked on note 
> diagnostic that says "enable debug info for additional information" is 
> palatable and simpler for users?

I've changed over to a binary flag in e866945f1c61774e745ec3a793629104ef473fee 
wherein we use debug info if it exists and otherwise we use the heuristic with 
manual srcloc annotations. How does it look?


https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -120,6 +120,14 @@ class CodeGenOptions : public CodeGenOptionsBase {
 Embed_Marker// Embed a marker as a placeholder for bitcode.
   };
 
+  /// Inlining chain tracking __attribute__((warning)) or 
__attribute__((error))
+  /// diagnostics
+  enum InliningChainKind {

JustinStitt wrote:

Sounds good to me. PTAL e866945f1c61774e745ec3a793629104ef473fee

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -6048,13 +6048,22 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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 __attribute__((error/warning)) diagnostics.
+  // In heuristic mode, also track inline/static calls for inlining chain.
+  if (TargetDecl) {
+bool NeedSrcLoc = TargetDecl->hasAttr();
+if (!NeedSrcLoc && CGM.getCodeGenOpts().getInliningChain() ==
+   CodeGenOptions::Inlining_Heuristic) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->isInlineSpecified() ||
+ FD->hasAttr() ||
+ FD->getStorageClass() == SC_Static;

JustinStitt wrote:

Since methods inside of an anonymous namespace are pretty likely to be inlined 
at -O2 I've added them to the heuristic in 
e866945f1c61774e745ec3a793629104ef473fee. thanks

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -348,6 +348,12 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain=`` added to show inlining 
chain
+  notes for ``__attribute__((warning))`` and ``__attribute__((error))``

JustinStitt wrote:

Changed all the instances in e866945f1c61774e745ec3a793629104ef473fee. 
Hopefully I didn't miss anywhere

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -2253,6 +2253,14 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   Opts.getDebugInfo() == llvm::codegenoptions::NoDebugInfo)
 Opts.setDebugInfo(llvm::codegenoptions::LocTrackingOnly);
 
+  // Debug mode for inlining chain diagnostics requires at least
+  // -gline-directives-only to track inlining locations via DILocation.
+  if (Opts.getInliningChain() == CodeGenOptions::Inlining_Debug &&
+  Opts.getDebugInfo() < llvm::codegenoptions::DebugDirectivesOnly) {
+Diags.Report(diag::warn_fe_inlining_debug_requires_g);
+Opts.setInliningChain(CodeGenOptions::Inlining_Heuristic);
+  }

JustinStitt wrote:

Ok done with [`e866945` 
(#174892)](https://github.com/llvm/llvm-project/pull/174892/commits/e866945f1c61774e745ec3a793629104ef473fee)
 although it can get a bit noisy when there are multiple diagnostics. Should I 
try to engineer some EmitOnce or does something like that already exist?

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits


@@ -8397,6 +8397,13 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the
+``-fdiagnostics-show-inlining-chain=`` option can be used to show the
+inlining chain that led to the call. This helps identify which call site
+triggered the diagnostic when the attributed function is called from
+multiple locations through inline functions. See ``clang --help`` for
+available modes.

JustinStitt wrote:

Makes sense :)

fixed with [`e866945` 
(#174892)](https://github.com/llvm/llvm-project/pull/174892/commits/e866945f1c61774e745ec3a793629104ef473fee)

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-08 Thread Justin Stitt via cfe-commits

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

>From ea02427b27288e70acaf87b0c2ad53d897f13e80 Mon Sep 17 00:00:00 2001
From: Justin Stitt 
Date: Tue, 6 Jan 2026 15:36:33 -0800
Subject: [PATCH 1/2] [Clang] Add -fdiagnostics-show-inlining-chain for
 warning/error attributes

When functions marked with __attribute__((warning/error)) are called
through inlined functions, Clang now optionally shows the inlining chain
that led to the call.

Three modes are supported:

- ``none`` is the default and results in no inline notes being shown
  (matches the behavior before this change).

- ``heuristic`` tries to guess which functions will be inlined to
  minimize the amount of source locations kept in memory and visible in
  LLVM IR.

- ``debug`` leverages minimal debug directive tracking infrastructure to
  get more reliable source locations over the heuristic mode while
  having more compile-time overhead.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1571
Based-on: https://github.com/llvm/llvm-project/pull/73552
Signed-off-by: Justin Stitt 
---
 clang/docs/ReleaseNotes.rst   |   6 +
 clang/include/clang/Basic/AttrDocs.td |   7 ++
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   8 ++
 .../clang/Basic/DiagnosticFrontendKinds.td|   6 +
 clang/include/clang/Options/Options.td|  15 +++
 clang/lib/CodeGen/CGCall.cpp  |  23 ++--
 clang/lib/CodeGen/CodeGenAction.cpp   |  31 +
 clang/lib/Driver/ToolChains/Clang.cpp |   7 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   8 ++
 .../backend-attribute-inlining-cross-tu.c |  64 ++
 ...nd-attribute-inlining-debug-vs-heuristic.c |  28 +
 .../backend-attribute-inlining-modes.c|  47 
 .../Frontend/backend-attribute-inlining.c | 109 ++
 llvm/include/llvm/IR/DiagnosticInfo.h |  26 -
 llvm/lib/IR/DiagnosticInfo.cpp|  38 +-
 llvm/lib/Transforms/Utils/InlineFunction.cpp  |  44 +++
 17 files changed, 459 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-cross-tu.c
 create mode 100644 
clang/test/Frontend/backend-attribute-inlining-debug-vs-heuristic.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining-modes.c
 create mode 100644 clang/test/Frontend/backend-attribute-inlining.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8ef6564bd80e6..cf17f8a052cbb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,12 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain=`` added to show inlining 
chain
+  notes for ``__attribute__((warning))`` and ``__attribute__((error))``
+  diagnostics. When a function with these attributes is called from an inlined
+  context, Clang can now show which functions were inlined to reach the call.
+  Modes: ``none`` (default), ``heuristic`` (uses metadata tracking), ``debug``
+  (uses debug info for accurate source locations).
 
 Lanai Support
 ^^
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 812b48058d189..97331b1175cc9 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8397,6 +8397,13 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the
+``-fdiagnostics-show-inlining-chain=`` option can be used to show the
+inlining chain that led to the call. This helps identify which call site
+triggered the diagnostic when the attributed function is called from
+multiple locations through inline functions. See ``clang --help`` for
+available modes.
   }];
 }
 
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 3784844ef1028..223e803a22c6c 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -76,6 +76,8 @@ CODEGENOPT(CallGraphSection, 1, 0, Benign) ///< Emit a call 
graph section into t
///< object file.
 CODEGENOPT(EmitCallSiteInfo, 1, 0, Benign) ///< Emit call site info only in 
the case of
///< '-g' + 'O>0' level.
+/// Tracking inlining chai

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

2026-01-07 Thread Nick Desaulniers via cfe-commits

https://github.com/nickdesaulniers edited 
https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-07 Thread Nick Desaulniers via cfe-commits


@@ -8397,6 +8397,13 @@ pointing to precise locations of the call site in the 
source.
   dontcall(); // No Warning
 sizeof(dontcall()); // No Warning
   }
+
+When the call occurs through inlined functions, the
+``-fdiagnostics-show-inlining-chain=`` option can be used to show the
+inlining chain that led to the call. This helps identify which call site
+triggered the diagnostic when the attributed function is called from
+multiple locations through inline functions. See ``clang --help`` for
+available modes.

nickdesaulniers wrote:

I don't think we want our HTML docs to say "run `clang --help` for the 
options."  This is our official docs, spell them out!!!

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-07 Thread Nick Desaulniers via cfe-commits


@@ -2253,6 +2253,14 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   Opts.getDebugInfo() == llvm::codegenoptions::NoDebugInfo)
 Opts.setDebugInfo(llvm::codegenoptions::LocTrackingOnly);
 
+  // Debug mode for inlining chain diagnostics requires at least
+  // -gline-directives-only to track inlining locations via DILocation.
+  if (Opts.getInliningChain() == CodeGenOptions::Inlining_Debug &&
+  Opts.getDebugInfo() < llvm::codegenoptions::DebugDirectivesOnly) {
+Diags.Report(diag::warn_fe_inlining_debug_requires_g);
+Opts.setInliningChain(CodeGenOptions::Inlining_Heuristic);
+  }

nickdesaulniers wrote:

Maybe it would be better to emit a Note diagnostic on the -Wwarning diagnostics 
if `FD->getStorageClass() == SC_Static` that enabling `-gline-directives-only` 
(or higher level debug flags) can provide additional info?

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-07 Thread Nick Desaulniers via cfe-commits

https://github.com/nickdesaulniers commented:

> Q) Why have three modes?
A) Fully re-purposing the debug info architecture for inline tracing requires 
at least -gline-directives-only (I believe.) which is probably not something 
everyone wants by default. A heuristic approach is the middle ground and of 
course none matches the current clang behavior without this PR.

Hmm...I think we can improve the ergonomics here a little bit.  I feel like it 
should be possible to have 2 modes instead of three.  Like in CGCall if 
`-gline-directives-only` or higher is set, then we can elide the `srcloc`. Then 
when a dontcall is triggered we scan for (possibly absent) debug info. If that 
doesn't exist, fall back to looking for `srcloc`.  idk, something just feels 
off about a ternary flag, with a second flag required to use of the the three 
states.  Most flags are binary, and perhaps the tacked on note binary that says 
"enable debug info for additional information" is palatable and simpler for 
users?

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-07 Thread Nick Desaulniers via cfe-commits


@@ -6048,13 +6048,22 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (getDebugInfo() && TargetDecl && TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
 
-  // Add metadata if calling an __attribute__((error(""))) or warning fn.
-  if (TargetDecl && TargetDecl->hasAttr()) {
-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 __attribute__((error/warning)) diagnostics.
+  // In heuristic mode, also track inline/static calls for inlining chain.
+  if (TargetDecl) {
+bool NeedSrcLoc = TargetDecl->hasAttr();
+if (!NeedSrcLoc && CGM.getCodeGenOpts().getInliningChain() ==
+   CodeGenOptions::Inlining_Heuristic) {
+  if (const auto *FD = dyn_cast(TargetDecl))
+NeedSrcLoc = FD->isInlined() || FD->isInlineSpecified() ||
+ FD->hasAttr() ||
+ FD->getStorageClass() == SC_Static;

nickdesaulniers wrote:

`FD->getStorageClass() == SC_Static` makes me wonder about functions defined in 
C++ anonymous namespaces.

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-07 Thread Nick Desaulniers via cfe-commits


@@ -348,6 +348,12 @@ New Compiler Flags
 - New options for enabling allocation token instrumentation: 
``-fsanitize=alloc-token``, ``-falloc-token-max=``, 
``-fsanitize-alloc-token-fast-abi``, ``-fsanitize-alloc-token-extended``.
 - The ``-resource-dir`` option is now displayed in the list of options shown 
by ``--help``.
 - New option ``-fmatrix-memory-layout`` added to control the memory layout of 
Clang matrix types. (e.g. ``-fmatrix-memory-layout=column-major`` or 
``-fmatrix-memory-layout=row-major``).
+- New option ``-fdiagnostics-show-inlining-chain=`` added to show inlining 
chain
+  notes for ``__attribute__((warning))`` and ``__attribute__((error))``

nickdesaulniers wrote:

Man, C23 standardized the C++20 syntax for attributes, which uses `[[]]`. Let's 
use the standard syntax, throughout this PR? `[[gnu::warning]]`

https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2026-01-07 Thread Nick Desaulniers via cfe-commits

https://github.com/nickdesaulniers edited 
https://github.com/llvm/llvm-project/pull/174892
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits