Skip to content

Commit 7866c40

Browse files
authored
Fix crash with invalid member function param list (llvm#139595)
We cannot consume annotation tokens with ConsumeToken(), so any pragmas present in an invalid initializer would previously crash. Now we handle annotation tokens more generally and avoid the crash. Fixes llvm#113722
1 parent 91f3cdb commit 7866c40

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ Bug Fixes in This Version
582582
``#include`` directive. (#GH138094)
583583
- Fixed a crash during constant evaluation involving invalid lambda captures
584584
(#GH138832)
585+
- Fixed a crash with an invalid member function parameter list with a default
586+
argument which contains a pragma. (#GH113722)
585587
- Fixed assertion failures when generating name lookup table in modules. (#GH61065, #GH134739)
586588

587589
Bug Fixes to Compiler Builtins

clang/lib/Parse/ParseCXXInlineMethods.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,10 +1272,6 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks,
12721272
goto consume_token;
12731273

12741274
case tok::eof:
1275-
case tok::annot_module_begin:
1276-
case tok::annot_module_end:
1277-
case tok::annot_module_include:
1278-
case tok::annot_repl_input_end:
12791275
// Ran out of tokens.
12801276
return false;
12811277

@@ -1411,6 +1407,11 @@ bool Parser::ConsumeAndStoreInitializer(CachedTokens &Toks,
14111407
[[fallthrough]];
14121408
default:
14131409
consume_token:
1410+
// If it's an annotation token, then we've run out of tokens and should
1411+
// bail out. Otherwise, cache the token and consume it.
1412+
if (Tok.isAnnotation())
1413+
return false;
1414+
14141415
Toks.push_back(Tok);
14151416
ConsumeToken();
14161417
break;

clang/test/Parser/cxx-invalid-function-decl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ struct S : public Base1<int>, public Base2<float> {
4040
// All initializers are correct, nothing to skip, diagnose 2 missing commas.
4141
S(const S &) : Base1<int>(0) ::Base2<float>(1.0) x(2) {} // expected-error2{{missing ',' between base or member initializers}}
4242
};
43+
44+
namespace GH113722 {
45+
struct S {
46+
void m(int x = 0; // expected-error {{unexpected end of default argument expression}} \
47+
expected-note {{to match this '('}}
48+
#pragma unused(x) // expected-error {{expected ')'}} \
49+
expected-error {{expected ';' at end of declaration list}}
50+
} // expected-error {{expected ';' after struct}}
51+
};
52+
} // expected-error {{extraneous closing brace ('}')}}

0 commit comments

Comments
 (0)