https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/236752
>From 8bbc579f9eb320c5a88edc2651f0ce26599c19eb Mon Sep 17 00:00:00 2001 From: Ben Shi <[email protected]> Date: Thu, 29 Oct 2026 20:15:02 +0800 Subject: [PATCH 1/3] [clang][CodeGen] Fix a crash caused by inconsistent addrspace fixes https://github.com/llvm/llvm-project/issues/236285 --- clang/lib/CodeGen/CGCXX.cpp | 8 +++++--- clang/test/CodeGen/avr/issue-236285.cpp | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGen/avr/issue-236285.cpp 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..ebb8968dd3716c --- /dev/null +++ b/clang/test/CodeGen/avr/issue-236285.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple avr -target-cpu atmega328 -emit-llvm -x c++ < %s | FileCheck --allow-empty %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 >From 50594a5297fddb511bc4f8da3013d616da99276a Mon Sep 17 00:00:00 2001 From: Ben Shi <[email protected]> Date: Fri, 30 Oct 2026 10:35:23 +0800 Subject: [PATCH 2/3] imporve --- clang/docs/ReleaseNotes.md | 2 ++ clang/lib/CodeGen/CGCXX.cpp | 6 +++--- clang/test/CodeGen/avr/issue-236285.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index db2237c495ffdb..421b07c4f49b29 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1204,6 +1204,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 different 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 94b625036b99fd..9b998268c63e54 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -178,9 +178,9 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) { return true; // 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()); + auto *Alias = llvm::GlobalAlias::create( + AliasValueType, getDataLayout().getProgramAddressSpace(), 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 index ebb8968dd3716c..ad68dceb44010a 100644 --- a/clang/test/CodeGen/avr/issue-236285.cpp +++ b/clang/test/CodeGen/avr/issue-236285.cpp @@ -1,8 +1,9 @@ -// RUN: %clang_cc1 -triple avr -target-cpu atmega328 -emit-llvm -x c++ < %s | FileCheck --allow-empty %s +// 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(); }; @@ -15,4 +16,5 @@ struct C : B { C::~C() {} -// CHECK: {{.*}} alias void (ptr), ptr +// CHECK: {{.*}} alias void (ptr), ptr addrspace(1) +// CHECK: {{.*}} alias void (ptr), ptr addrspace(1) >From 8c39b4f1c55d3896c543eb6a736fb04b48cba183 Mon Sep 17 00:00:00 2001 From: Ben Shi <[email protected]> Date: Fri, 30 Oct 2026 14:29:24 +0800 Subject: [PATCH 3/3] fix --- clang/lib/CodeGen/CGCXX.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index 9b998268c63e54..94b625036b99fd 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -178,9 +178,9 @@ bool CodeGenModule::TryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) { return true; // Create the alias with no name, in the same address space as the aliasee. - auto *Alias = llvm::GlobalAlias::create( - AliasValueType, getDataLayout().getProgramAddressSpace(), Linkage, "", - Aliasee, &getModule()); + auto *Alias = + llvm::GlobalAlias::create(AliasValueType, Aliasee->getAddressSpace(), + Linkage, "", Aliasee, &getModule()); // Destructors are always unnamed_addr. Alias->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
