[cfe-commits] r41545 - in /cfe/trunk: Sema/SemaType.cpp include/clang/Basic/DiagnosticKinds.def test/Sema/c89.c

Chris Lattner sabre at nondot.org
Tue Aug 28 09:54:00 PDT 2007


Author: lattner
Date: Tue Aug 28 11:54:00 2007
New Revision: 41545

URL: http://llvm.org/viewvc/llvm-project?rev=41545&view=rev
Log:
extwarn about VLAs in C89 mode.

Modified:
    cfe/trunk/Sema/SemaType.cpp
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/test/Sema/c89.c

Modified: cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaType.cpp?rev=41545&r1=41544&r2=41545&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Tue Aug 28 11:54:00 2007
@@ -165,6 +165,7 @@
       break;
     case DeclaratorChunk::Array: {
       const DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
+      Expr *ArraySize = static_cast<Expr*>(ATI.NumElts);
       ArrayType::ArraySizeModifier ASM;
       if (ATI.isStar)
         ASM = ArrayType::Star;
@@ -201,8 +202,13 @@
           D.setInvalidType(true);
         }
       }
-      T = Context.getArrayType(T, ASM, ATI.TypeQuals, 
-                               static_cast<Expr *>(ATI.NumElts));
+      T = Context.getArrayType(T, ASM, ATI.TypeQuals, ArraySize);
+      
+      // If this is not C99, extwarn about VLA's and C99 array size modifiers.
+      if (!getLangOptions().C99 && 
+          (ASM != ArrayType::Normal ||
+           (ArraySize && !ArraySize->isIntegerConstantExpr(Context))))
+        Diag(D.getIdentifierLoc(), diag::ext_vla);
       break;
     }
     case DeclaratorChunk::Function:

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=41545&r1=41544&r2=41545&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Aug 28 11:54:00 2007
@@ -448,6 +448,8 @@
      "ISO C requires a named argument before '...'")
 DIAG(err_unspecified_vla_size_with_static, ERROR,
      "'static' may not be used with an unspecified variable length array size")
+DIAG(ext_vla, EXTENSION,
+     "variable length arrays are a C99 feature, accepted as an extension")
 DIAG(err_invalid_storage_class_in_func_decl, ERROR,
      "invalid storage class specifier in function declarator")
 DIAG(err_invalid_reference_qualifier_application, ERROR,

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

==============================================================================
--- cfe/trunk/test/Sema/c89.c (original)
+++ cfe/trunk/test/Sema/c89.c Tue Aug 28 11:54:00 2007
@@ -1,6 +1,6 @@
 /* RUN: clang %s -std=c89 -pedantic -parse-ast-check
  */
-void foo() {
+void test1() {
   {
     int i;
     i = i + 1;
@@ -18,5 +18,9 @@
   }
 }
 
-long long x;   /* expected-warning {{extension}} */
+long long test2;   /* expected-warning {{extension}} */
 
+
+void test3(int i) {
+  int A[i];        /* expected-warning {{variable length array}} */
+}





More information about the cfe-commits mailing list