[cfe-commits] r93933 - in /cfe/trunk: include/clang/AST/Expr.h lib/Frontend/RewriteObjC.cpp lib/Sema/SemaExpr.cpp lib/Sema/TreeTransform.h test/Sema/compound-literal.c

John McCall rjmccall at apple.com
Tue Jan 19 14:33:46 PST 2010


Author: rjmccall
Date: Tue Jan 19 16:33:45 2010
New Revision: 93933

URL: http://llvm.org/viewvc/llvm-project?rev=93933&view=rev
Log:
The type of a compound literal expression is not necessarily the same as the
type which was syntactically written.  Fixes PR 6080.


Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/Frontend/RewriteObjC.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/Sema/compound-literal.c

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=93933&r1=93932&r2=93933&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Jan 19 16:33:45 2010
@@ -1462,14 +1462,17 @@
   /// 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) {}
 

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=93933&r1=93932&r2=93933&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Tue Jan 19 16:33:45 2010
@@ -2516,8 +2516,8 @@
                                              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 @@
                                              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 {

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=93933&r1=93932&r2=93933&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan 19 16:33:45 2010
@@ -3707,7 +3707,7 @@
 
   Result.release();
   
-  return Owned(new (Context) CompoundLiteralExpr(LParenLoc, TInfo,
+  return Owned(new (Context) CompoundLiteralExpr(LParenLoc, TInfo, literalType,
                                                  literalExpr, isFileScope));
 }
 
@@ -4718,7 +4718,7 @@
   // 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);
 }
 

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=93933&r1=93932&r2=93933&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Tue Jan 19 16:33:45 2010
@@ -3867,6 +3867,10 @@
       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));

Modified: cfe/trunk/test/Sema/compound-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compound-literal.c?rev=93933&r1=93932&r2=93933&view=diff

==============================================================================
--- cfe/trunk/test/Sema/compound-literal.c (original)
+++ cfe/trunk/test/Sema/compound-literal.c Tue Jan 19 16:33:45 2010
@@ -31,3 +31,6 @@
   (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];





More information about the cfe-commits mailing list