[cfe-commits] r78213 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaTemplateInstantiateExpr.cpp test/CodeGenCXX/constructor-default-arg.cpp
Fariborz Jahanian
fjahanian at apple.com
Wed Aug 5 10:04:34 PDT 2009
Author: fjahanian
Date: Wed Aug 5 12:03:54 2009
New Revision: 78213
URL: http://llvm.org/viewvc/llvm-project?rev=78213&view=rev
Log:
Patch to improve ir-gen for constructors with default argument
expressions and a test case.
Added:
cfe/trunk/test/CodeGenCXX/constructor-default-arg.cpp
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=78213&r1=78212&r2=78213&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Aug 5 12:03:54 2009
@@ -1672,6 +1672,14 @@
CXXConstructorDecl *Constructor,
QualType DeclInitType,
Expr **Exprs, unsigned NumExprs);
+
+ /// BuildCXXConstructExpr - Creates a complete call to a constructor,
+ /// including handling of its default argument expressions.
+ Expr * BuildCXXConstructExpr(ASTContext &C,
+ QualType DeclInitType,
+ CXXConstructorDecl *Constructor,
+ bool Elidable,
+ Expr **Exprs, unsigned NumExprs);
/// FinalizeVarWithDestructor - Prepare for calling destructor on the
/// constructed variable.
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=78213&r1=78212&r2=78213&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Aug 5 12:03:54 2009
@@ -2356,13 +2356,16 @@
CopyConstructor->setUsed();
}
-void Sema::InitializeVarWithConstructor(VarDecl *VD,
- CXXConstructorDecl *Constructor,
- QualType DeclInitType,
- Expr **Exprs, unsigned NumExprs) {
- CXXConstructExpr *Temp = CXXConstructExpr::Create(Context, DeclInitType,
+/// BuildCXXConstructExpr - Creates a complete call to a constructor,
+/// including handling of its default argument expressions.
+Expr *Sema::BuildCXXConstructExpr(ASTContext &C,
+ QualType DeclInitType,
+ CXXConstructorDecl *Constructor,
+ bool Elidable,
+ Expr **Exprs, unsigned NumExprs) {
+ CXXConstructExpr *Temp = CXXConstructExpr::Create(C, DeclInitType,
Constructor,
- false, Exprs, NumExprs);
+ Elidable, Exprs, NumExprs);
// default arguments must be added to constructor call expression.
FunctionDecl *FDecl = cast<FunctionDecl>(Constructor);
unsigned NumArgsInProto = FDecl->param_size();
@@ -2379,10 +2382,19 @@
for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I)
ExprTemporaries.push_back(E->getTemporary(I));
}
- Expr *Arg = new (Context) CXXDefaultArgExpr(FDecl->getParamDecl(j));
+ Expr *Arg = new (C) CXXDefaultArgExpr(FDecl->getParamDecl(j));
Temp->setArg(j, Arg);
}
-
+ return Temp;
+}
+
+void Sema::InitializeVarWithConstructor(VarDecl *VD,
+ CXXConstructorDecl *Constructor,
+ QualType DeclInitType,
+ Expr **Exprs, unsigned NumExprs) {
+ Expr *Temp = BuildCXXConstructExpr(Context,
+ DeclInitType, Constructor,
+ false, Exprs, NumExprs);
MarkDeclarationReferenced(VD->getLocation(), Constructor);
VD->setInit(Context, Temp);
}
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=78213&r1=78212&r2=78213&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Aug 5 12:03:54 2009
@@ -911,8 +911,8 @@
assert(!ToType->isReferenceType());
// FIXME: Keep track of whether the copy constructor is elidable or not.
- From = CXXConstructExpr::Create(Context, ToType,
- SCS.CopyConstructor, false, &From, 1);
+ From = BuildCXXConstructExpr(Context,
+ ToType, SCS.CopyConstructor, false, &From, 1);
return false;
}
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=78213&r1=78212&r2=78213&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Aug 5 12:03:54 2009
@@ -177,8 +177,8 @@
if (!Constructor)
return true;
- Init = CXXConstructExpr::Create(Context, DeclType, Constructor, false,
- &Init, 1);
+ Init = BuildCXXConstructExpr(Context,
+ DeclType, Constructor, false, &Init, 1);
return false;
}
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=78213&r1=78212&r2=78213&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Wed Aug 5 12:03:54 2009
@@ -1073,11 +1073,11 @@
Args.push_back(ArgInst.takeAs<Expr>());
}
- return SemaRef.Owned(CXXConstructExpr::Create(SemaRef.Context, T,
- E->getConstructor(),
- E->isElidable(),
- Args.takeAs<Expr>(),
- Args.size()));
+ return SemaRef.Owned(SemaRef.BuildCXXConstructExpr(SemaRef.Context, T,
+ E->getConstructor(),
+ E->isElidable(),
+ Args.takeAs<Expr>(),
+ Args.size()));
}
Sema::OwningExprResult
Added: cfe/trunk/test/CodeGenCXX/constructor-default-arg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/constructor-default-arg.cpp?rev=78213&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/constructor-default-arg.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/constructor-default-arg.cpp Wed Aug 5 12:03:54 2009
@@ -0,0 +1,30 @@
+// RUN: clang-cc %s -emit-llvm -o %t &&
+// RUN: grep 'call void @_ZN1XC1ERK1Xiii' %t | count 3
+
+extern "C" int printf(...);
+
+
+struct C {
+ C() : iC(6) {}
+ int iC;
+};
+
+int foo() {
+ return 6;
+};
+
+class X { // ...
+public:
+ X(int) {}
+ X(const X&, int i = 1, int j = 2, int k = foo()) {
+ printf("X(const X&, %d, %d, %d)\n", i, j, k);
+ }
+};
+
+int main()
+{
+ X a(1);
+ X b(a, 2);
+ X c = b;
+ X d(a, 5, 6);
+}
More information about the cfe-commits
mailing list