aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/Expr.h7
-rw-r--r--lib/Frontend/RewriteObjC.cpp8
-rw-r--r--lib/Sema/SemaExpr.cpp4
-rw-r--r--lib/Sema/TreeTransform.h4
-rw-r--r--test/Sema/compound-literal.c3
5 files changed, 18 insertions, 8 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 2852c19744..2527817671 100644
--- a/include/clang/AST/Expr.h
+++ b/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/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp
index 2e101f402b..c0ad799c5a 100644
--- a/lib/Frontend/RewriteObjC.cpp
+++ b/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/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index f8f3e05f56..8c740dd1db 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/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/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 587c93d1ad..b2102afdfc 100644
--- a/lib/Sema/TreeTransform.h
+++ b/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/test/Sema/compound-literal.c b/test/Sema/compound-literal.c
index a650d12de9..0c8ddd42d0 100644
--- a/test/Sema/compound-literal.c
+++ b/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];