[cfe-commits] r51300 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/compound-literal.c

Eli Friedman eli.friedman at gmail.com
Mon May 19 22:22:08 PDT 2008


Author: efriedma
Date: Tue May 20 00:22:08 2008
New Revision: 51300

URL: http://llvm.org/viewvc/llvm-project?rev=51300&view=rev
Log:
Add some more checking for compound literals.


Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/compound-literal.c

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue May 20 00:22:08 2008
@@ -738,7 +738,20 @@
   //assert((InitExpr != 0) && "ActOnCompoundLiteral(): missing expression");
   Expr *literalExpr = static_cast<Expr*>(InitExpr);
 
-  // FIXME: add more semantic analysis (C99 6.5.2.5).
+  if (literalType->isArrayType()) {
+    if (literalType->getAsVariableArrayType())
+      return Diag(LParenLoc,
+                  diag::err_variable_object_no_init,
+                  SourceRange(LParenLoc,
+                              literalExpr->getSourceRange().getEnd()));
+  } else if (literalType->isIncompleteType()) {
+    return Diag(LParenLoc,
+                diag::err_typecheck_decl_incomplete_type,
+                literalType.getAsString(),
+                SourceRange(LParenLoc,
+                            literalExpr->getSourceRange().getEnd()));
+  }
+
   if (CheckInitializerTypes(literalExpr, literalType))
     return true;
 

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

==============================================================================
--- cfe/trunk/test/Sema/compound-literal.c (original)
+++ cfe/trunk/test/Sema/compound-literal.c Tue May 20 00:22:08 2008
@@ -21,4 +21,8 @@
  fooFunc(&(struct foo){ 1, 2 });
 }
 
-
+struct Incomplete;
+struct Incomplete* I1 = &(struct Incomplete){1, 2, 3}; // -expected-error {{variable has incomplete type}}
+void IncompleteFunc(unsigned x) {
+  struct Incomplete* I2 = (struct foo[x]){1, 2, 3}; // -expected-error {{variable-sized object may not be initialized}}
+}





More information about the cfe-commits mailing list