forked from OSchip/llvm-project
PR13941: Mark all virtual functions as unnamed_addr. It's not possible to
observe their addresses (taking their address gives the vtable slot) so we are free to merge their definitions. llvm-svn: 164864
This commit is contained in:
parent
538fe8f35b
commit
b555a767ba
|
@ -588,6 +588,10 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
|
|||
if (isa<CXXConstructorDecl>(D) || isa<CXXDestructorDecl>(D))
|
||||
F->setUnnamedAddr(true);
|
||||
|
||||
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D))
|
||||
if (MD->isVirtual())
|
||||
F->setUnnamedAddr(true);
|
||||
|
||||
if (LangOpts.getStackProtector() == LangOptions::SSPOn)
|
||||
F->addFnAttr(llvm::Attribute::StackProtect);
|
||||
else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
|
||||
|
|
|
@ -10,17 +10,21 @@ class C {
|
|||
virtual void bar1() __attribute__((aligned(1)));
|
||||
virtual void bar2() __attribute__((aligned(2)));
|
||||
virtual void bar3() __attribute__((aligned(1024)));
|
||||
void bar4() __attribute__((aligned(1024)));
|
||||
} c;
|
||||
|
||||
// CHECK: define void @_ZN1C4bar1Ev(%class.C* %this) nounwind align 2
|
||||
// CHECK: define void @_ZN1C4bar1Ev(%class.C* %this) unnamed_addr nounwind align 2
|
||||
void C::bar1() { }
|
||||
|
||||
// CHECK: define void @_ZN1C4bar2Ev(%class.C* %this) nounwind align 2
|
||||
// CHECK: define void @_ZN1C4bar2Ev(%class.C* %this) unnamed_addr nounwind align 2
|
||||
void C::bar2() { }
|
||||
|
||||
// CHECK: define void @_ZN1C4bar3Ev(%class.C* %this) nounwind align 1024
|
||||
// CHECK: define void @_ZN1C4bar3Ev(%class.C* %this) unnamed_addr nounwind align 1024
|
||||
void C::bar3() { }
|
||||
|
||||
// CHECK: define void @_ZN1C4bar4Ev(%class.C* %this) nounwind align 1024
|
||||
void C::bar4() { }
|
||||
|
||||
// PR6635
|
||||
// CHECK: define i32 @_Z5test1v()
|
||||
int test1() { return 10; }
|
||||
|
|
|
@ -35,6 +35,9 @@ struct S {
|
|||
static void g() { }
|
||||
|
||||
static void f();
|
||||
|
||||
// RUN: grep "define linkonce_odr void @_ZN1S1vEv.*unnamed_addr" %t
|
||||
virtual void v() {}
|
||||
};
|
||||
|
||||
// RUN: grep "define void @_ZN1S1fEv" %t
|
||||
|
|
Loading…
Reference in New Issue