[cfe-commits] r41524 - in /cfe/trunk: Sema/SemaStmt.cpp include/clang/Basic/DiagnosticKinds.def test/Sema/for.c
Chris Lattner
sabre at nondot.org
Mon Aug 27 22:03:08 PDT 2007
Author: lattner
Date: Tue Aug 28 00:03:08 2007
New Revision: 41524
URL: http://llvm.org/viewvc/llvm-project?rev=41524&view=rev
Log:
now that all the infrastructure is in place, enforce C99 6.8.5p3.
Note the FIXME: we need some way to mark a decl erroneous :)
Added:
cfe/trunk/test/Sema/for.c
Modified:
cfe/trunk/Sema/SemaStmt.cpp
cfe/trunk/include/clang/Basic/DiagnosticKinds.def
Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=41524&r1=41523&r2=41524&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Tue Aug 28 00:03:08 2007
@@ -453,10 +453,17 @@
Expr *Third = static_cast<Expr*>(third);
Stmt *Body = static_cast<Stmt*>(body);
- if (First) {
- // C99 6.8.5p3: FIXME. Need to hack Parser::ParseForStatement() and
- // declaration support to create a DeclStmt node. Once this is done,
- // we can test for DeclStmt vs. Expr (already a sub-class of Stmt).
+ if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
+ // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
+ // identifiers for objects having storage class 'auto' or 'register'.
+ for (Decl *D = DS->getDecl(); D; D = D->getNextDeclarator()) {
+ BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(D);
+ if (BVD && !BVD->hasLocalStorage())
+ BVD = 0;
+ if (BVD == 0)
+ Diag(D->getLocation(), diag::err_non_variable_decl_in_for);
+ // FIXME: mark decl erroneous!
+ }
}
if (Second) {
DefaultFunctionArrayConversion(Second);
Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=41524&r1=41523&r2=41524&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Tue Aug 28 00:03:08 2007
@@ -367,6 +367,8 @@
"expected ';' after expression")
DIAG(err_expected_semi_for, ERROR,
"expected ';' in 'for' statement specifier")
+DIAG(err_non_variable_decl_in_for, ERROR,
+ "declaration of non-local variable in 'for' loop")
DIAG(err_expected_colon_after, ERROR,
"expected ':' after %0")
DIAG(err_label_end_of_compound_statement, ERROR,
Added: cfe/trunk/test/Sema/for.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/for.c?rev=41524&view=auto
==============================================================================
--- cfe/trunk/test/Sema/for.c (added)
+++ cfe/trunk/test/Sema/for.c Tue Aug 28 00:03:08 2007
@@ -0,0 +1,7 @@
+// RUN: clang -parse-ast-check %s
+
+// Check C99 6.8.5p3
+void b1 (void) { for (void (*f) (void);;); }
+void b2 (void) { for (void f (void);;); } // expected-error {{declaration of non-local variable}}
+void b3 (void) { for (static int f;;); } // expected-error {{declaration of non-local variable}}
+void b4 (void) { for (typedef int f;;); } // expected-error {{declaration of non-local variable}}
More information about the cfe-commits
mailing list