Author: lijinpei-amd
Date: 2026-06-05T08:50:40-04:00
New Revision: ddfa5eb8ae2e0cdd1c0542fff9c6671b8b3ff85c

URL: 
https://github.com/llvm/llvm-project/commit/ddfa5eb8ae2e0cdd1c0542fff9c6671b8b3ff85c
DIFF: 
https://github.com/llvm/llvm-project/commit/ddfa5eb8ae2e0cdd1c0542fff9c6671b8b3ff85c.diff

LOG: [Sema] Fix assertion crash on section conflict with a non-identifier decl 
(#200873)

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

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaAttr.cpp
    clang/test/SemaCXX/attr-section.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index da72bd17a484d..77f801e6f7d67 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -680,6 +680,9 @@ Bug Fixes to Attribute Support
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Fixed a behavioral discrepancy between deleted functions and private members 
when checking the ``enable_if`` attribute. (#GH175895)
 - Fixed ``init_priority`` attribute by delaying type checks until after the 
type is deduced.
+- Fixed a crash when a ``section`` attribute or ``#pragma clang section`` 
caused a
+  section type conflict with a declaration whose name is not a simple 
identifier,
+  such as a lambda's call operator. (#GH192264)
 
 Bug Fixes to C++ Support
 ^^^^^^^^^^^^^^^^^^^^^^^^

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..95d4fc53ebe6c 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 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 GH192264
+
+// 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


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

Reply via email to