diff options
| author | Chris Lattner <sabre@nondot.org> | 2011-02-18 21:16:39 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2011-02-18 21:16:39 +0000 |
| commit | 9ba479bd2c2c102559c8416d6a08c996c16b6ebc (patch) | |
| tree | 4bb894fc8f1b6c6422444978caf80b98d5f69be9 /clang | |
| parent | d1fd6963f5116816933cf76010ab25d086ba82ce (diff) | |
| download | bcm5719-llvm-9ba479bd2c2c102559c8416d6a08c996c16b6ebc.tar.gz bcm5719-llvm-9ba479bd2c2c102559c8416d6a08c996c16b6ebc.zip | |
fix rdar://9024687, a crash on invalid that we used to silently ignore.
llvm-svn: 125962
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticParseKinds.td | 2 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 5 | ||||
| -rw-r--r-- | clang/test/Sema/scope-check.c | 3 |
4 files changed, 11 insertions, 2 deletions
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index ad673f8198e..9d7ec9d4544 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -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; diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index 84d77300eb2..616c251583f 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -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()); diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 789f9c9f4ff..b4946cf8d6d 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -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); diff --git a/clang/test/Sema/scope-check.c b/clang/test/Sema/scope-check.c index 1a2fc2b3608..a9494d3e3fb 100644 --- a/clang/test/Sema/scope-check.c +++ b/clang/test/Sema/scope-check.c @@ -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}} |

