Skip to content

Commit

Permalink
[UniqueLinkageName] Use exsiting GlobalDecl object instead of reconst…
Browse files Browse the repository at this point in the history
…ructing one.

C++ constructors/destructors need to go through a different constructor to construct a GlobalDecl object in order to retrieve their linkage type. This causes an assert failure in the default constructor of GlobalDecl. I'm chaning it to using the exsiting GlobalDecl object.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D102356
  • Loading branch information
htyu committed Jun 28, 2021
1 parent 1fa7023 commit 633ca3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGCall.cpp
Expand Up @@ -2174,7 +2174,8 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
// functions with -funique-internal-linkage-names.
if (TargetDecl && CodeGenOpts.UniqueInternalLinkageNames) {
if (auto *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
if (this->getFunctionLinkage(Fn) == llvm::GlobalValue::InternalLinkage)
if (this->getFunctionLinkage(CalleeInfo.getCalleeDecl()) ==
llvm::GlobalValue::InternalLinkage)
FuncAttrs.addAttribute("sample-profile-suffix-elision-policy",
"selected");
}
Expand Down
16 changes: 16 additions & 0 deletions clang/test/CodeGen/unique-internal-linkage-names.cpp
Expand Up @@ -42,12 +42,26 @@ int mver_call() {
return mver();
}

namespace {
class A {
public:
A() {}
~A() {}
};
}

void test() {
A a;
}

// PLAIN: @_ZL4glob = internal global
// PLAIN: @_ZZ8retAnonMvE5fGlob = internal global
// PLAIN: @_ZN12_GLOBAL__N_16anon_mE = internal global
// PLAIN: define internal i32 @_ZL3foov()
// PLAIN: define internal i32 @_ZN12_GLOBAL__N_14getMEv
// PLAIN: define weak_odr i32 ()* @_ZL4mverv.resolver()
// PLAIN: define internal void @_ZN12_GLOBAL__N_11AC1Ev
// PLAIN: define internal void @_ZN12_GLOBAL__N_11AD1Ev
// PLAIN: define internal i32 @_ZL4mverv()
// PLAIN: define internal i32 @_ZL4mverv.sse4.2()
// PLAIN-NOT: "sample-profile-suffix-elision-policy"
Expand All @@ -57,6 +71,8 @@ int mver_call() {
// UNIQUE: define internal i32 @_ZL3foov.[[MODHASH:__uniq.[0-9]+]]() #[[#ATTR:]] {
// UNIQUE: define internal i32 @_ZN12_GLOBAL__N_14getMEv.[[MODHASH]]
// UNIQUE: define weak_odr i32 ()* @_ZL4mverv.[[MODHASH]].resolver()
// UNIQUE: define internal void @_ZN12_GLOBAL__N_11AC1Ev.__uniq.68358509610070717889884130747296293671
// UNIQUE: define internal void @_ZN12_GLOBAL__N_11AD1Ev.__uniq.68358509610070717889884130747296293671
// UNIQUE: define internal i32 @_ZL4mverv.[[MODHASH]]()
// UNIQUE: define internal i32 @_ZL4mverv.[[MODHASH]].sse4.2
// UNIQUE: attributes #[[#ATTR]] = { {{.*}}"sample-profile-suffix-elision-policy"{{.*}} }

0 comments on commit 633ca3f

Please sign in to comment.