https://github.com/lijinpei-amd updated 
https://github.com/llvm/llvm-project/pull/200873

>From 38f79eb3acd6e16628459517ae285d177fed46f3 Mon Sep 17 00:00:00 2001
From: Li Jinpei <[email protected]>
Date: Tue, 2 Jun 2026 00:55:37 +0800
Subject: [PATCH 1/2] [Sema] Fix assertion crash on section conflict with a
 non-identifier decl

NamedDecl::getName() asserts the name is a simple identifier, so
UnifySection crashed when the conflicting section decl had a special
name such as a lambda's call operator.

Drop the argument: `note_declared_at` has no format placeholder,
so it was dead code. The error already prints the section decl.

Fixes https://github.com/llvm/llvm-project/issues/192264
---
 clang/lib/Sema/SemaAttr.cpp         |  6 ++----
 clang/test/SemaCXX/attr-section.cpp | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index ffd546138008a..67573c9f1c72a 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -853,8 +853,7 @@ bool Sema::UnifySection(StringRef SectionName, int 
SectionFlags,
     return false;
   Diag(Decl->getLocation(), diag::err_section_conflict) << Decl << Section;
   if (Section.Decl)
-    Diag(Section.Decl->getLocation(), diag::note_declared_at)
-        << Section.Decl->getName();
+    Diag(Section.Decl->getLocation(), diag::note_declared_at);
   if (PragmaLocation.isValid())
     Diag(PragmaLocation, diag::note_pragma_entered_here);
   if (Section.PragmaSectionLocation.isValid())
@@ -874,8 +873,7 @@ bool Sema::UnifySection(StringRef SectionName,
       Diag(PragmaSectionLocation, diag::err_section_conflict)
           << "this" << Section;
       if (Section.Decl)
-        Diag(Section.Decl->getLocation(), diag::note_declared_at)
-            << Section.Decl->getName();
+        Diag(Section.Decl->getLocation(), diag::note_declared_at);
       if (Section.PragmaSectionLocation.isValid())
         Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
       return true;
diff --git a/clang/test/SemaCXX/attr-section.cpp 
b/clang/test/SemaCXX/attr-section.cpp
index 1c07e3dd8bba2..35d38ec6e2be0 100644
--- a/clang/test/SemaCXX/attr-section.cpp
+++ b/clang/test/SemaCXX/attr-section.cpp
@@ -69,3 +69,18 @@ __attribute__((section("non_trivial_ctor"))) const t1 v1; // 
expected-note {{dec
 extern const t1 v2;
 __attribute__((section("non_trivial_ctor"))) const t1 v2{3}; // expected-error 
{{'v2' causes a section type conflict with 'v1'}}
 } // namespace non_trivial_ctor
+
+// Check that a section conflict with a decl whose name is not a simple
+// identifier (here, a lambda's call operator) is diagnosed without crashing.
+namespace lambda_call_operator {
+auto lambda = [](int val) __attribute__((section("lambda_op"))) { return val; 
}; // expected-note {{declared here}}
+__attribute__((section("lambda_op"))) int i{}; // expected-error {{'i' causes 
a section type conflict with 'operator()'}}
+} // namespace lambda_call_operator
+
+// Check that a section conflict with a decl whose name is not a simple
+// identifier (here, a lambda's call operator) is diagnosed without crashing.
+namespace lambda_call_operator_pragma {
+auto lambda = [](int val) __attribute__((section("lambda_op_pragma"))) { 
return val; }; // expected-note {{declared here}}
+#pragma clang section bss="lambda_op_pragma" // expected-error {{this causes a 
section type conflict with 'operator()'}}
+#pragma clang section bss=""
+} // namespace lambda_call_operator_pragma

>From c6a548b2a66b3d37ab8a2667451176f4718411a4 Mon Sep 17 00:00:00 2001
From: lijinpei-amd <[email protected]>
Date: Tue, 2 Jun 2026 16:58:04 +0800
Subject: [PATCH 2/2] Update clang/test/SemaCXX/attr-section.cpp

Co-authored-by: Corentin Jabot <[email protected]>
---
 clang/test/SemaCXX/attr-section.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/attr-section.cpp 
b/clang/test/SemaCXX/attr-section.cpp
index 35d38ec6e2be0..7252ef7694b27 100644
--- a/clang/test/SemaCXX/attr-section.cpp
+++ b/clang/test/SemaCXX/attr-section.cpp
@@ -72,7 +72,7 @@ __attribute__((section("non_trivial_ctor"))) const t1 v2{3}; 
// expected-error {
 
 // Check that a section conflict with a decl whose name is not a simple
 // identifier (here, a lambda's call operator) is diagnosed without crashing.
-namespace lambda_call_operator {
+namespace GH192264 {
 auto lambda = [](int val) __attribute__((section("lambda_op"))) { return val; 
}; // expected-note {{declared here}}
 __attribute__((section("lambda_op"))) int i{}; // expected-error {{'i' causes 
a section type conflict with 'operator()'}}
 } // namespace lambda_call_operator

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to