зеркало из https://github.com/microsoft/clang.git
Codegen CXXConstructExprs with trivial constructors as constants.
Eliminates a lot of spurious global initializers, fixing PR6205. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95077 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
2e13db8bc6
Коммит
fb8b69aef3
|
@ -668,6 +668,29 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
llvm::Constant *VisitCXXConstructExpr(CXXConstructExpr *E) {
|
||||
if (!E->getConstructor()->isTrivial())
|
||||
return 0;
|
||||
|
||||
// Only copy and default constructors can be trivial.
|
||||
|
||||
QualType Ty = E->getType();
|
||||
|
||||
if (E->getNumArgs()) {
|
||||
assert(E->getNumArgs() == 1 && "trivial ctor with > 1 argument");
|
||||
assert(E->getConstructor()->isCopyConstructor() &&
|
||||
"trivial ctor has argument but isn't a copy ctor");
|
||||
|
||||
Expr *Arg = E->getArg(0);
|
||||
assert(CGM.getContext().hasSameUnqualifiedType(Ty, Arg->getType()) &&
|
||||
"argument to copy ctor is of wrong type");
|
||||
|
||||
return Visit(E->getArg(0));
|
||||
}
|
||||
|
||||
return CGM.EmitNullConstant(Ty);
|
||||
}
|
||||
|
||||
llvm::Constant *VisitStringLiteral(StringLiteral *E) {
|
||||
assert(!E->getType()->isPointerType() && "Strings are always arrays");
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@ struct A {
|
|||
|
||||
struct B { B(); ~B(); };
|
||||
|
||||
struct C { void *field; };
|
||||
|
||||
// CHECK: @c = global %struct.C zeroinitializer, align 8
|
||||
|
||||
// CHECK: call void @_ZN1AC1Ev(%struct.A* @a)
|
||||
// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1AD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @a, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*))
|
||||
A a;
|
||||
|
@ -14,3 +18,9 @@ A a;
|
|||
// CHECK: call void @_ZN1BC1Ev(%struct.A* @b)
|
||||
// CHECK: call i32 @__cxa_atexit(void (i8*)* bitcast (void (%struct.A*)* @_ZN1BD1Ev to void (i8*)*), i8* getelementptr inbounds (%struct.A* @b, i32 0, i32 0), i8* bitcast (i8** @__dso_handle to i8*))
|
||||
B b;
|
||||
|
||||
// PR6205: this should not require a global initializer
|
||||
// CHECK-NOT: call void @_ZN1CC1Ev(%struct.C* @c)
|
||||
C c;
|
||||
|
||||
// CHECK: define internal void @__cxx_global_initialization() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче