This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Avoid crashes when parsing using enum declarations
ClosedPublic

Authored by shafik on Aug 25 2022, 12:01 PM.

Details

Summary

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

Diff Detail

Event Timeline

shafik created this revision.Aug 25 2022, 12:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2022, 12:01 PM
shafik requested review of this revision.Aug 25 2022, 12:01 PM
erichkeane accepted this revision.Aug 25 2022, 12:09 PM

Changes seem correct enough, and the tests all look like we're just removing incorrect diagnostics, so LGTM.

This revision is now accepted and ready to land.Aug 25 2022, 12:09 PM
aaron.ballman accepted this revision.Aug 26 2022, 4:43 AM

Thanks, this looks like it cleans up some needlessly chatty diagnostics! Just had a question that you can fix when landing if you agree, otherwise LGTM as well.

clang/lib/Parse/ParseDecl.cpp
4652

Shouldn't this be lifted out of the if statement into the parent one where we issue the error diagnostic?

shafik updated this revision to Diff 456128.Aug 27 2022, 9:30 AM
shafik marked an inline comment as done.
  • Move DS.SetTypeSpecError() outside the if so that it is always called when the diagnostic is triggered.
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 27 2022, 3:42 PM