]> granicus.if.org Git - clang/commitdiff
fix rdar://9024687, a crash on invalid that we used to silently ignore.
authorChris Lattner <sabre@nondot.org>
Fri, 18 Feb 2011 21:16:39 +0000 (21:16 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 18 Feb 2011 21:16:39 +0000 (21:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125962 91177308-0d34-0410-b5e6-96231b3b80d8

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

index ad673f8198eaffdc1cd05e65157565d4c8da17f9..9d7ec9d4544723316ad300612459e143089366fc 100644 (file)
@@ -148,6 +148,8 @@ def err_expected_semi_for : Error<"expected ';' in 'for' statement specifier">;
 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;
index 84d77300eb2afb1ef50a7584ea1dc8f2d725ea5e..616c251583fb85b453834e2019e725dfb78e4b6b 100644 (file)
@@ -794,6 +794,9 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
     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());
index 789f9c9f4ff389ac909f144da6f96cac2d4d2261..b4946cf8d6d21a2df9fa7c3a6a33b239e718b528 100644 (file)
@@ -2780,8 +2780,9 @@ LabelDecl *Sema::LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc,
   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);
index 1a2fc2b3608fe8e0e5e12eecbaa31cdc0fa1800d..a9494d3e3fb4add2f2b6fbff0b685ff4eada1c77 100644 (file)
@@ -229,3 +229,6 @@ void test15(int n, void *pc) {
     vla[0] = 'a';
   }
 }
+
+// rdar://9024687
+int test16(int [sizeof &&z]); // expected-error {{use of address-of-label extension outside of a function body}}