This is an archive of the discontinued LLVM Phabricator instance.

[AST] Fix crashes on decltype(recovery-expr).
ClosedPublic

Authored by hokein on Mar 30 2020, 12:33 AM.

Details

Summary

We mark these decls as invalid.

Diff Detail

Event Timeline

hokein created this revision.Mar 30 2020, 12:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2020, 12:33 AM
sammccall added inline comments.Mar 30 2020, 2:20 AM
clang/include/clang/AST/Type.h
2144

Why is this called isErrorType when the expr version is containsErrors?

clang/lib/Parse/ParseExprCXX.cpp
3109

Add a comment for what the null case means? (When do we actually hit this?)

clang/lib/Sema/SemaType.cpp
1591

we've added the ability to represent types containing errors, but now we're dropping the type.
Is marking the declarator as invalid sufficient?

hokein updated this revision to Diff 253537.Mar 30 2020, 3:11 AM
hokein marked 3 inline comments as done.

address review comments.

clang/lib/Parse/ParseExprCXX.cpp
3109

yeah, the [CompleteTest](https://github.com/llvm/llvm-project/blob/master/clang/unittests/Sema/CodeCompleteTest.cpp#L490) hits the assertion after this patch.

the assertion seems incorrect -- IIUC, the assertion is for the isInvalidType() sanity check on Line 3090, however
In ActOnTypeName, DeclaratorInfo could be modified (by GetTypeForDeclarator) before calling isInvalidType.

btw, I think for the CodeCompleteTest, would be nicer to make ActOnTypeName return decltype(<recovery-expr>(bar)), rather than the null type, but I'm not sure changing the ActOnTypeName behavior has any side effect.

sammccall accepted this revision.Mar 30 2020, 4:14 AM
sammccall added inline comments.
clang/lib/Parse/ParseExprCXX.cpp
3109

the assertion seems incorrect -- IIUC, the assertion is for the isInvalidType() sanity check on Line 3090, however

What you say makes sense, but I think it's worth probing why it's not currently hit (e.g. by int x(auto);, where GetDeclSpecTypeForDeclarator marks the decl as invalid because auto isn't allowed in a prototype).

btw, I think for the CodeCompleteTest, would be nicer to make ActOnTypeName return decltype(<recovery-expr>(bar)), rather than the null type

Definitely. I think "invalid" on a type-concept is stronger than what we're looking for - since we're not tracking errors in decls, we'd want to use "haserrors" on type-concepts and then promote to "invalid" on decl-concepts.

Ugh, the design of "Declarator" makes this difficult, because there's no distinction between "type of this declarator is invalid" and "type of this declarator makes the declarator invalid".

I'd suggest leaving a FIXME on the changes in SemaType, saying something like "we want resulting declarations to be marked invalid, but claiming the type is invalid is too strong - e.g. it causes ActOnTypeName to return a null type."

clang/lib/Sema/SemaType.cpp
1594

are you sure you want this in the individual cases, rather than once at the end of this function?

This revision is now accepted and ready to land.Mar 30 2020, 4:14 AM
hokein updated this revision to Diff 253567.Mar 30 2020, 5:44 AM
hokein marked 4 inline comments as done.

address comments.

clang/lib/Parse/ParseExprCXX.cpp
3109

What you say makes sense, but I think it's worth probing why it's not currently hit (e.g. by int x(auto);, where GetDeclSpecTypeForDeclarator marks the decl as invalid because auto isn't allowed in a prototype).

I believe the issue exists even before this patch, it was just not caught by tests. Added one.

clang/lib/Sema/SemaType.cpp
1594

ah, good point, moved the end of the switch statement.

This revision was automatically updated to reflect the committed changes.