This is an archive of the discontinued LLVM Phabricator instance.

[Parser] Fix the assertion crash in ActOnStartOfSwitch stmt.
ClosedPublic

Authored by hokein on Mar 23 2020, 12:38 AM.

Details

Summary

After we parse the switch condition, we don't do the type check for
type-dependent expr (e.g. TypoExpr) (in Sema::CheckSwitchCondition), then the
TypoExpr is corrected to an invalid-type expr (in Sema::MakeFullExpr) and passed
to the ActOnStartOfSwitchStmt, which triggers the assertion.

Fix https://github.com/clangd/clangd/issues/311

Diff Detail

Event Timeline

hokein created this revision.Mar 23 2020, 12:38 AM
sammccall added inline comments.Mar 23 2020, 6:41 PM
clang/lib/Sema/SemaStmt.cpp
709

How do we know Cond is a TypoExpr directly rather than containing one?

I think the usual strategy when code can't deal with typo correction being delayed further is to call CorrectDelayedTyposInExpr.

hokein marked an inline comment as done.Mar 24 2020, 3:05 AM
hokein added inline comments.
clang/lib/Sema/SemaStmt.cpp
709

no sure whether we should consider the containing-typo Cond, we might still want to keep the typo correction? thinking a case like switch(return_int(typo-expr)) {}.

Do you suggest that we use the CorrectDelayedTyposInExpr to check the whether Cond is/has a TypoExpr? CorrectDelayedTyposInExpr has a side effect of emitting the typo-suggestion diagnostic.

hokein updated this revision to Diff 252280.Mar 24 2020, 5:12 AM

adjust the assertion based on the offline discussion.

hokein updated this revision to Diff 252281.Mar 24 2020, 5:14 AM

fix a typo.

sammccall accepted this revision.Mar 24 2020, 5:31 AM
This revision is now accepted and ready to land.Mar 24 2020, 5:31 AM
This revision was automatically updated to reflect the committed changes.