diff options
| author | John McCall <rjmccall@apple.com> | 2010-01-19 22:33:45 +0000 |
|---|---|---|
| committer | John McCall <rjmccall@apple.com> | 2010-01-19 22:33:45 +0000 |
| commit | 5d7aa7fa0ae5154c8ca7fe8851b0cafcf8d61700 (patch) | |
| tree | 38f87da151f3ebb955b1ae4bf818aa60ef74f66f | |
| parent | 8d67d2f5f8fcf8eeb269ab33315a848f4acfba06 (diff) | |
| download | bcm5719-llvm-5d7aa7fa0ae5154c8ca7fe8851b0cafcf8d61700.tar.gz bcm5719-llvm-5d7aa7fa0ae5154c8ca7fe8851b0cafcf8d61700.zip | |
The type of a compound literal expression is not necessarily the same as the
type which was syntactically written. Fixes PR 6080.
llvm-svn: 93933
| -rw-r--r-- | clang/include/clang/AST/Expr.h | 7 | ||||
| -rw-r--r-- | clang/lib/Frontend/RewriteObjC.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/TreeTransform.h | 4 | ||||
| -rw-r--r-- | clang/test/Sema/compound-literal.c | 3 |
5 files changed, 18 insertions, 8 deletions
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 2852c197442..25278176716 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1462,14 +1462,17 @@ class CompoundLiteralExpr : public Expr { /// compound literal like "(int){4}". This can be null if this is a /// synthesized compound expression. SourceLocation LParenLoc; + + /// The type as written. This can be an incomplete array type, in + /// which case the actual expression type will be different. TypeSourceInfo *TInfo; Stmt *Init; bool FileScope; public: // FIXME: Can compound literals be value-dependent? CompoundLiteralExpr(SourceLocation lparenloc, TypeSourceInfo *tinfo, - Expr *init, bool fileScope) - : Expr(CompoundLiteralExprClass, tinfo->getType(), + QualType T, Expr *init, bool fileScope) + : Expr(CompoundLiteralExprClass, T, tinfo->getType()->isDependentType(), false), LParenLoc(lparenloc), TInfo(tinfo), Init(init), FileScope(fileScope) {} diff --git a/clang/lib/Frontend/RewriteObjC.cpp b/clang/lib/Frontend/RewriteObjC.cpp index 2e101f402b7..c0ad799c5a9 100644 --- a/clang/lib/Frontend/RewriteObjC.cpp +++ b/clang/lib/Frontend/RewriteObjC.cpp @@ -2516,8 +2516,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp) { SourceLocation()); TypeSourceInfo *superTInfo = Context->getTrivialTypeSourceInfo(superType); - SuperRep = new (Context) CompoundLiteralExpr(SourceLocation(), - superTInfo, ILE, false); + SuperRep = new (Context) CompoundLiteralExpr(SourceLocation(), superTInfo, + superType, ILE, false); // struct objc_super * SuperRep = new (Context) UnaryOperator(SuperRep, UnaryOperator::AddrOf, Context->getPointerType(SuperRep->getType()), @@ -2601,8 +2601,8 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp) { SourceLocation()); TypeSourceInfo *superTInfo = Context->getTrivialTypeSourceInfo(superType); - SuperRep = new (Context) CompoundLiteralExpr(SourceLocation(), - superTInfo, ILE, false); + SuperRep = new (Context) CompoundLiteralExpr(SourceLocation(), superTInfo, + superType, ILE, false); } MsgExprs.push_back(SuperRep); } else { diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index f8f3e05f56e..8c740dd1dbf 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3707,7 +3707,7 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, Result.release(); - return Owned(new (Context) CompoundLiteralExpr(LParenLoc, TInfo, + return Owned(new (Context) CompoundLiteralExpr(LParenLoc, TInfo, literalType, literalExpr, isFileScope)); } @@ -4718,7 +4718,7 @@ static void ConstructTransparentUnion(ASTContext &C, Expr *&E, // Build a compound literal constructing a value of the transparent // union type from this initializer list. TypeSourceInfo *unionTInfo = C.getTrivialTypeSourceInfo(UnionType); - E = new (C) CompoundLiteralExpr(SourceLocation(), unionTInfo, + E = new (C) CompoundLiteralExpr(SourceLocation(), unionTInfo, UnionType, Initializer, false); } diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 587c93d1ad5..b2102afdfc4 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -3867,6 +3867,10 @@ TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { Init.get() == E->getInitializer()) return SemaRef.Owned(E->Retain()); + // Note: the expression type doesn't necessarily match the + // type-as-written, but that's okay, because it should always be + // derivable from the initializer. + return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, /*FIXME:*/E->getInitializer()->getLocEnd(), move(Init)); diff --git a/clang/test/Sema/compound-literal.c b/clang/test/Sema/compound-literal.c index a650d12de97..0c8ddd42d0c 100644 --- a/clang/test/Sema/compound-literal.c +++ b/clang/test/Sema/compound-literal.c @@ -31,3 +31,6 @@ void IncompleteFunc(unsigned x) { (void){1,2,3}; // -expected-error {{variable has incomplete type}} (void(void)) { 0 }; // -expected-error{{illegal initializer type 'void (void)'}} } + +// PR6080 +int array[(sizeof(int[3]) == sizeof( (int[]) {0,1,2} )) ? 1 : -1]; |

