[cfe-commits] r125962 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseExpr.cpp lib/Sema/SemaLookup.cpp test/Sema/scope-check.c

Chris Lattner sabre at nondot.org
Fri Feb 18 13:16:39 PST 2011


Author: lattner
Date: Fri Feb 18 15:16:39 2011
New Revision: 125962

URL: http://llvm.org/viewvc/llvm-project?rev=125962&view=rev
Log:
fix rdar://9024687, a crash on invalid that we used to silently ignore.


Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/Sema/scope-check.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=125962&r1=125961&r2=125962&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Feb 18 15:16:39 2011
@@ -148,6 +148,8 @@
 def err_expected_colon_after : Error<"expected ':' after %0">;
 def err_label_end_of_compound_statement : Error<
   "label at end of compound statement: expected statement">;
+def err_address_of_label_outside_fn : Error<
+  "use of address-of-label extension outside of a function body">;
 def err_expected_string_literal : Error<"expected string literal">;
 def err_expected_asm_operand : Error<
   "expected string literal or '[' for asm operand">, CatInlineAsm;

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=125962&r1=125961&r2=125962&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri Feb 18 15:16:39 2011
@@ -794,6 +794,9 @@
     if (Tok.isNot(tok::identifier))
       return ExprError(Diag(Tok, diag::err_expected_ident));
 
+    if (getCurScope()->getFnParent() == 0)
+      return ExprError(Diag(Tok, diag::err_address_of_label_outside_fn));
+    
     Diag(AmpAmpLoc, diag::ext_gnu_address_of_label);
     LabelDecl *LD = Actions.LookupOrCreateLabel(Tok.getIdentifierInfo(),
                                                 Tok.getLocation());

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=125962&r1=125961&r2=125962&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Fri Feb 18 15:16:39 2011
@@ -2780,8 +2780,9 @@
   if (Res == 0) {
     // If not forward referenced or defined already, create the backing decl.
     Res = LabelDecl::Create(Context, CurContext, Loc, II);
-    PushOnScopeChains(Res, isLocalLabel ? CurScope : CurScope->getFnParent(),
-                      true);
+    Scope *S = isLocalLabel ? CurScope : CurScope->getFnParent();
+    assert(S && "Not in a function?");
+    PushOnScopeChains(Res, S, true);
   }
   
   return cast<LabelDecl>(Res);

Modified: cfe/trunk/test/Sema/scope-check.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/scope-check.c?rev=125962&r1=125961&r2=125962&view=diff
==============================================================================
--- cfe/trunk/test/Sema/scope-check.c (original)
+++ cfe/trunk/test/Sema/scope-check.c Fri Feb 18 15:16:39 2011
@@ -229,3 +229,6 @@
     vla[0] = 'a';
   }
 }
+
+// rdar://9024687
+int test16(int [sizeof &&z]); // expected-error {{use of address-of-label extension outside of a function body}}





More information about the cfe-commits mailing list