]> granicus.if.org Git - clang/commitdiff
extwarn about VLAs in C89 mode.
authorChris Lattner <sabre@nondot.org>
Tue, 28 Aug 2007 16:54:00 +0000 (16:54 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 28 Aug 2007 16:54:00 +0000 (16:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41545 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaType.cpp
include/clang/Basic/DiagnosticKinds.def
test/Sema/c89.c

index 5582c5a89b0e10819e70b86670aa3d70f15e8a2f..04264a3e514db236d3a6c8e3c5e43667467c4cb7 100644 (file)
@@ -165,6 +165,7 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
       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 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
           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:
index dbf1b270a093b0bdf3c2c7d44f839d7b54303a5b..f2437d6554b170b69d17e1cb985a32af338224db 100644 (file)
@@ -448,6 +448,8 @@ DIAG(err_ellipsis_first_arg, ERROR,
      "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,
index a78472222a8c918012770a9fc37550e7de894491..a5855b21d00340f42f4359a382715b363e7153d8 100644 (file)
@@ -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 @@ void foo() {
   }
 }
 
-long long x;   /* expected-warning {{extension}} */
+long long test2;   /* expected-warning {{extension}} */
 
+
+void test3(int i) {
+  int A[i];        /* expected-warning {{variable length array}} */
+}