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

Chris Lattner sabre at nondot.org
Wed Dec 17 22:50:15 PST 2008


Author: lattner
Date: Thu Dec 18 00:50:14 2008
New Revision: 61197

URL: http://llvm.org/viewvc/llvm-project?rev=61197&view=rev
Log:
Clean up the C89/C++ warnings about C99 array features to not 
emit duplicate diags (some in parser and some in sema) and to
warn about use of typequals in array sizes.  This implements 
PR2759.

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

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Thu Dec 18 00:50:14 2008
@@ -310,7 +310,7 @@
 DIAG(ext_ident_list_in_param, EXTENSION,
      "type-less parameter names in function declaration")
 DIAG(ext_c99_array_usage, EXTENSION,
-     "use of C99-specific array features")
+     "use of C99-specific array features, accepted as an extension")
 DIAG(ext_c99_variable_decl_in_for_loop, EXTENSION,
      "variable declaration in for loop is a C99-specific feature")
 DIAG(ext_c99_compound_literal, EXTENSION,

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=61197&r1=61196&r2=61197&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Dec 18 00:50:14 2008
@@ -1283,7 +1283,7 @@
       DS.AddAttributes(ParseAttributes());
       continue; // do *not* consume the next token!
     }
-    
+
     // If the specifier combination wasn't legal, issue a diagnostic.
     if (isInvalid) {
       assert(PrevSpec && "Method did not return previous specifier!");
@@ -1943,6 +1943,7 @@
     StaticLoc = ConsumeToken();
   
   // If there is a type-qualifier-list, read it now.
+  // Type qualifiers in an array subscript are a C99 feature.
   DeclSpec DS;
   ParseTypeQualifierListOpt(DS);
   
@@ -1962,9 +1963,10 @@
   if (Tok.is(tok::star) && GetLookAheadToken(1).is(tok::r_square)) {
     ConsumeToken();  // Eat the '*'.
 
-    if (StaticLoc.isValid())
+    if (StaticLoc.isValid()) {
       Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
-    StaticLoc = SourceLocation();  // Drop the static.
+      StaticLoc = SourceLocation();  // Drop the static.
+    }
     isStar = true;
   } else if (Tok.isNot(tok::r_square)) {
     // Parse the assignment-expression now.
@@ -1980,15 +1982,6 @@
   
   MatchRHSPunctuation(tok::r_square, StartLoc);
     
-  // If C99 isn't enabled, emit an ext-warn if the arg list wasn't empty and if
-  // it was not a constant expression.
-  if (!getLang().C99) {
-    // TODO: check C90 array constant exprness.
-    if (isStar || StaticLoc.isValid() ||
-        0/*TODO: NumElts is not a C90 constantexpr */)
-      Diag(StartLoc, diag::ext_c99_array_usage);
-  }
-
   // Remember that we parsed a pointer type, and remember the type-quals.
   D.AddTypeInfo(DeclaratorChunk::getArray(DS.getTypeQualifiers(),
                                           StaticLoc.isValid(), isStar,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Dec 18 00:50:14 2008
@@ -416,11 +416,13 @@
         T = Context.getConstantArrayType(T, ConstVal, ASM, ATI.TypeQuals);
       }
       // If this is not C99, extwarn about VLA's and C99 array size modifiers.
-      if (!getLangOptions().C99 &&
-          (ASM != ArrayType::Normal ||
-           (ArraySize && !ArraySize->isValueDependent() && 
-            !ArraySize->isIntegerConstantExpr(Context))))
-        Diag(D.getIdentifierLoc(), diag::ext_vla);
+      if (!getLangOptions().C99) {
+        if (ArraySize && !ArraySize->isValueDependent() && 
+            !ArraySize->isIntegerConstantExpr(Context))
+          Diag(D.getIdentifierLoc(), diag::ext_vla);
+        else if (ASM != ArrayType::Normal || ATI.TypeQuals != 0)
+          Diag(D.getIdentifierLoc(), diag::ext_c99_array_usage);
+      }
       break;
     }
     case DeclaratorChunk::Function:

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

==============================================================================
--- cfe/trunk/test/Sema/c89.c (original)
+++ cfe/trunk/test/Sema/c89.c Thu Dec 18 00:50:14 2008
@@ -60,3 +60,10 @@
 
 void foo(void) {}
 
+/* PR2759 */
+void test10 (int x[*]); /* expected-warning {{use of C99-specific array features}} */
+void test11 (int x[static 4]); /* expected-warning {{use of C99-specific array features}} */
+
+void test12 (int x[const 4]) { /* expected-warning {{use of C99-specific array features}} */
+  int Y[x[1]]; /* expected-warning {{variable length arrays are a C99 feature, accepted as an extension}} */
+}





More information about the cfe-commits mailing list