Author: Ben Shi
Date: 2026-10-31T17:06:51+08:00
New Revision: ac9879eef5db5a4d6bb104d6e94272e8a1905355

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

LOG: [clang][CodeGen] Fix a crash caused by inconsistent addrspace (#236752)

fixes https://github.com/llvm/llvm-project/issues/236285

Added: 
    clang/test/CodeGen/avr/issue-236285.cpp

Modified: 
    clang/docs/ReleaseNotes.md
    clang/lib/CodeGen/CGCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 39aa1bf0a5f433..d8762f8a8d54d5 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1220,6 +1220,8 @@ documentation](CIR/index.md) for more information 
regarding ClangIR's status and
   parameter substituted through an alias template is used as the base of an
   unresolved name, such as `TT<T>::value` in a non-type template parameter's
   type. (#GH88592)
+- Fixed an assertion when emitting base destructor as alias on targets (such
+  as AVR) which have 
diff erent address spaces for code and data. (#GH236285)
 
 ### OpenACC Specific Changes
 

diff  --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp
index 8112783850bad3..94b625036b99fd 100644
--- a/clang/lib/CodeGen/CGCXX.cpp
+++ b/clang/lib/CodeGen/CGCXX.cpp
@@ -176,9 +176,11 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const 
CXXDestructorDecl *D) {
   // requires explicit comdat support in the IL.
   if (llvm::GlobalValue::isWeakForLinker(TargetLinkage))
     return true;
-  // Create the alias with no name.
-  auto *Alias = llvm::GlobalAlias::create(AliasValueType, 0, Linkage, "",
-                                          Aliasee, &getModule());
+
+  // Create the alias with no name, in the same address space as the aliasee.
+  auto *Alias =
+      llvm::GlobalAlias::create(AliasValueType, Aliasee->getAddressSpace(),
+                                Linkage, "", Aliasee, &getModule());
 
   // Destructors are always unnamed_addr.
   Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);

diff  --git a/clang/test/CodeGen/avr/issue-236285.cpp 
b/clang/test/CodeGen/avr/issue-236285.cpp
new file mode 100644
index 00000000000000..ad68dceb44010a
--- /dev/null
+++ b/clang/test/CodeGen/avr/issue-236285.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple avr -mconstructor-aliases -emit-llvm -o - %s | 
FileCheck %s
+
+// This test case verifies https://github.com/llvm/llvm-project/issues/236285 .
+
+struct A {};
+
+struct B : A {
+  ~B();
+};
+
+B::~B() {}
+
+struct C : B {
+  ~C();
+};
+
+C::~C() {}
+
+// CHECK: {{.*}} alias void (ptr), ptr addrspace(1)
+// CHECK: {{.*}} alias void (ptr), ptr addrspace(1)


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

Reply via email to