Skip to content

Commit ee210d3

Browse files
committed
[CIR][CIRGen] Fix some alias issues under -O1 and above
Note that there are still missing pieces, which will be incrementally addressed.
1 parent 94b4d89 commit ee210d3

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

clang/lib/CIR/CodeGen/CIRGenCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ bool CIRGenModule::tryEmitBaseDestructorAsAlias(const CXXDestructorDecl *D) {
174174
llvm_unreachable("NYI");
175175

176176
// Create the alias with no name.
177-
buildAliasForGlobal("", Entry, AliasDecl, Aliasee, Linkage);
177+
buildAliasForGlobal(MangledName, Entry, AliasDecl, Aliasee, Linkage);
178178
return false;
179179
}
180180

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,9 +2139,15 @@ void CIRGenModule::buildAliasForGlobal(StringRef mangledName,
21392139
mlir::cir::GlobalLinkageKind linkage) {
21402140
auto *aliasFD = dyn_cast<FunctionDecl>(aliasGD.getDecl());
21412141
assert(aliasFD && "expected FunctionDecl");
2142-
auto alias =
2143-
createCIRFunction(getLoc(aliasGD.getDecl()->getSourceRange()),
2144-
mangledName, aliasee.getFunctionType(), aliasFD);
2142+
2143+
// The aliasee function type is different from the alias one, this difference
2144+
// is specific to CIR because in LLVM the ptr types are already erased at this
2145+
// point.
2146+
auto &fnInfo = getTypes().arrangeCXXStructorDeclaration(aliasGD);
2147+
auto fnType = getTypes().GetFunctionType(fnInfo);
2148+
2149+
auto alias = createCIRFunction(getLoc(aliasGD.getDecl()->getSourceRange()),
2150+
mangledName, fnType, aliasFD);
21452151
alias.setAliasee(aliasee.getName());
21462152
alias.setLinkage(linkage);
21472153
// Declarations cannot have public MLIR visibility, just mark them private

clang/test/CIR/CodeGen/virtual-destructor-calls.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -std=c++20 -mconstructor-aliases -O0 -fclangir -emit-cir %s -o %t.cir
33
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
4+
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -std=c++20 -mconstructor-aliases -O1 -fclangir -emit-cir %s -o %t-o1.cir
5+
// RUN: FileCheck --check-prefix=CIR_O1 --input-file=%t-o1.cir %s
46
// RUN: %clang_cc1 -triple aarch64-none-linux-android21 -std=c++20 -mconstructor-aliases -O0 -fclangir -emit-llvm -fno-clangir-call-conv-lowering %s -o %t.ll
57
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
68

@@ -38,8 +40,11 @@ struct B : A {
3840
// LLVM: call void @_ZdlPv
3941

4042
// (aliases from C)
41-
// FIXME: this should be an alias declaration.
43+
// FIXME: this should be an alias declaration even in -O0
4244
// CIR: cir.func @_ZN1CD2Ev(%arg0: !cir.ptr<!ty_C>{{.*}})) {{.*}} {
45+
// CIR_O1-NOT: cir.func @_ZN1CD2Ev(%arg0: !cir.ptr<!ty_C>{{.*}})) {{.*}} {
46+
// CIR_O1: cir.func private @_ZN1CD2Ev(!cir.ptr<!ty_C>) alias(@_ZN1BD2Ev)
47+
4348
// CIR: cir.func private @_ZN1CD1Ev(!cir.ptr<!ty_C>) alias(@_ZN1CD2Ev)
4449

4550
// FIXME: LLVM output should be: @_ZN1CD2Ev ={{.*}} unnamed_addr alias {{.*}} @_ZN1BD2Ev

0 commit comments

Comments
 (0)