aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorShafik Yaghmour <shafik.yaghmour@intel.com>2022-08-27 15:18:36 -0700
committerShafik Yaghmour <shafik.yaghmour@intel.com>2022-08-27 15:18:36 -0700
commitaa7ce60536a642e825d26d89b4a4347a36b63360 (patch)
tree6de1e3eb120d77af6ff41a0cbf846e6fd97f9ca9 /clang/lib/Parse/ParseDecl.cpp
parent44a06b51b2ce2c75ec327902b7ddd1172e54bc8f (diff)
downloadllvm-aa7ce60536a642e825d26d89b4a4347a36b63360.zip
llvm-aa7ce60536a642e825d26d89b4a4347a36b63360.tar.gz
llvm-aa7ce60536a642e825d26d89b4a4347a36b63360.tar.bz2
[Clang] Avoid crashes when parsing using enum declarations
In Parser::ParseUsingDeclaration(...) when we call ParseEnumSpecifier(...) it is not calling SetTypeSpecError() on DS when it detects an error. That means that DS is left set to TST_unspecified. When we then pass DS into Sema::ActOnUsingEnumDeclaration(...) we hit an llvm_unreachable(...) since it expects it to be one of three states TST_error, TST_enum or TST_typename. This fixes https://github.com/llvm/llvm-project/issues/57347 Differential Revision: https://reviews.llvm.org/D132695
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 97a856a..c502fc5 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4647,6 +4647,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
if (Spec.isSet() && Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected) << tok::identifier;
+ DS.SetTypeSpecError();
if (Tok.isNot(tok::l_brace)) {
// Has no name and is not a definition.
// Skip the rest of this declarator, up until the comma or semicolon.
@@ -4663,6 +4664,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
Tok.isNot(tok::colon)) {
Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
+ DS.SetTypeSpecError();
// Skip the rest of this declarator, up until the comma or semicolon.
SkipUntil(tok::comma, StopAtSemi);
return;
@@ -4838,6 +4840,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
if (!Name && TUK != Sema::TUK_Definition) {
Diag(Tok, diag::err_enumerator_unnamed_no_def);
+ DS.SetTypeSpecError();
// Skip the rest of this declarator, up until the comma or semicolon.
SkipUntil(tok::comma, StopAtSemi);
return;