[cfe-commits] r72575 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/Sema/vla.c

Mike Stump mrs at apple.com
Fri May 29 09:34:15 PDT 2009


Author: mrs
Date: Fri May 29 11:34:15 2009
New Revision: 72575

URL: http://llvm.org/viewvc/llvm-project?rev=72575&view=rev
Log:
Avoid dumping during semantic analysis when checking array types when
a vla is used.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/Sema/vla.c

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri May 29 11:34:15 2009
@@ -97,21 +97,22 @@
     return;
   }
   
-  const ConstantArrayType *CAT = cast<ConstantArrayType>(AT);
-  
-  // C99 6.7.8p14. We have an array of character type with known size.  However,
-  // the size may be smaller or larger than the string we are initializing.
-  // FIXME: Avoid truncation for 64-bit length strings.
-  if (StrLength-1 > CAT->getSize().getZExtValue())
-    S.Diag(Str->getSourceRange().getBegin(),
-           diag::warn_initializer_string_for_char_array_too_long)
-      << Str->getSourceRange();
-  
-  // Set the type to the actual size that we are initializing.  If we have
-  // something like:
-  //   char x[1] = "foo";
-  // then this will set the string literal's type to char[1].
-  Str->setType(DeclT);
+  if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) {
+    // C99 6.7.8p14. We have an array of character type with known size.
+    // However, the size may be smaller or larger than the string we are
+    // initializing.
+    // FIXME: Avoid truncation for 64-bit length strings.
+    if (StrLength-1 > CAT->getSize().getZExtValue())
+      S.Diag(Str->getSourceRange().getBegin(),
+             diag::warn_initializer_string_for_char_array_too_long)
+        << Str->getSourceRange();
+
+    // Set the type to the actual size that we are initializing.  If we have
+    // something like:
+    //   char x[1] = "foo";
+    // then this will set the string literal's type to char[1].
+    Str->setType(DeclT);
+  }
 }
 
 bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,

Modified: cfe/trunk/test/Sema/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vla.c?rev=72575&r1=72574&r2=72575&view=diff

==============================================================================
--- cfe/trunk/test/Sema/vla.c (original)
+++ cfe/trunk/test/Sema/vla.c Fri May 29 11:34:15 2009
@@ -51,3 +51,6 @@
 int pr2044(int b) {int (*c(void))[b];**c() = 2;} // expected-error {{variably modified type}}
 int pr2044b;
 int (*pr2044c(void))[pr2044b]; // expected-error {{variably modified type}}
+
+const int f5_ci = 1;
+void f5() { char a[][f5_ci] = {""}; }





More information about the cfe-commits mailing list