r212764 - PR20256: don't accidentally instantiate non-dependent default-initialization as
Richard Smith
richard-llvm at metafoo.co.uk
Thu Jul 10 13:53:43 PDT 2014
Author: rsmith
Date: Thu Jul 10 15:53:43 2014
New Revision: 212764
URL: http://llvm.org/viewvc/llvm-project?rev=212764&view=rev
Log:
PR20256: don't accidentally instantiate non-dependent default-initialization as
value-initialization.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/test/CodeGenCXX/value-init.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=212764&r1=212763&r2=212764&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Jul 10 15:53:43 2014
@@ -3679,8 +3679,9 @@ void Sema::InstantiateVariableInitialize
bool TypeMayContainAuto = true;
Expr *InitExpr = Init.get();
- if (Var->hasAttr<DLLImportAttr>() && InitExpr &&
- !InitExpr->isConstantInitializer(getASTContext(), false)) {
+ if (Var->hasAttr<DLLImportAttr>() &&
+ (!InitExpr ||
+ !InitExpr->isConstantInitializer(getASTContext(), false))) {
// Do not dynamically initialize dllimport variables.
} else if (InitExpr) {
bool DirectInit = OldVar->isDirectInit();
Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=212764&r1=212763&r2=212764&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Thu Jul 10 15:53:43 2014
@@ -2891,6 +2891,13 @@ ExprResult TreeTransform<Derived>::Trans
// Build a ParenListExpr to represent anything else.
SourceRange Parens = Construct->getParenOrBraceRange();
+ if (Parens.isInvalid()) {
+ // This was a variable declaration's initialization for which no initializer
+ // was specified.
+ assert(NewArgs.empty() &&
+ "no parens or braces but have direct init with arguments?");
+ return ExprEmpty();
+ }
return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
Parens.getEnd());
}
Modified: cfe/trunk/test/CodeGenCXX/value-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/value-init.cpp?rev=212764&r1=212763&r2=212764&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/value-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/value-init.cpp Thu Jul 10 15:53:43 2014
@@ -262,6 +262,59 @@ namespace PR11124 {
void r170806_a(bool b = bool());
void r170806_b() { r170806_a(); }
+namespace PR20256 {
+ struct data { int i; };
+
+ template<typename T = int>
+ data g() {
+ data d; // not value-init
+ return d;
+ }
+ template data g();
+ // CHECK-LABEL: define {{.*}} @_ZN7PR202561gIiEENS_4dataEv(
+ // CHECK-NOT: store
+ // CHECK-NOT: memset
+ // CHECK: }
+
+ template<typename ...T>
+ data h(T ...t) {
+ data d(t...); // value-init
+ return d;
+ }
+ template data h();
+ // CHECK-LABEL: define {{.*}} @_ZN7PR202561hIJEEENS_4dataEDpT_(
+ // CHECK: call void @llvm.memset
+ // CHECK: }
+
+
+ template<typename T = int>
+ data j() {
+ data d = {}; // value-init
+ return d;
+ }
+ template data j();
+ // CHECK-LABEL: define {{.*}} @_ZN7PR202561jIiEENS_4dataEv(
+ // CHECK: call void @llvm.memset
+ // CHECK: }
+
+ data f() {
+ data d; // not value-init
+ return d;
+ }
+ // CHECK-LABEL: define {{.*}} @_ZN7PR202561fEv(
+ // CHECK-NOT: store
+ // CHECK-NOT: memset
+ // CHECK: }
+
+ data i() {
+ data d = {}; // value-init
+ return d;
+ }
+ // CHECK-LABEL: define {{.*}} @_ZN7PR202561iEv(
+ // CHECK: call void @llvm.memset
+ // CHECK: }
+}
+
// CHECK-LABEL: define linkonce_odr void @_ZN8zeroinit2X3IiEC2Ev(%"struct.zeroinit::X3"* %this) unnamed_addr
// CHECK: call void @llvm.memset.p0i8.i64
// CHECK-NEXT: call void @_ZN8zeroinit2X2IiEC2Ev
More information about the cfe-commits
mailing list