https://github.com/benshi001 created https://github.com/llvm/llvm-project/pull/236752
fixes https://github.com/llvm/llvm-project/issues/236285 >From 27ee322a70c638822cb03ff38a7f3375e4357349 Mon Sep 17 00:00:00 2001 From: Ben Shi <[email protected]> Date: Thu, 29 Oct 2026 20:15:02 +0800 Subject: [PATCH] [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 | 19 +++++++++++++++++++ 2 files changed, 24 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..2c0e3d86c54fd4 --- /dev/null +++ b/clang/test/CodeGen/avr/issue-236285.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -triple avr -target-cpu atmega328 -emit-llvm -x c++ < %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
