This is an archive of the discontinued LLVM Phabricator instance.

[AST] Use RecoveryExpr to model a DeclRefExpr which refers to an invalid Decl.
ClosedPublic

Authored by hokein on Mar 2 2022, 6:42 AM.

Details

Summary

Previously, we didin't build a DeclRefExpr which refers to an invalid declaration.

In this patch, we handle this case by building an empty RecoveryExpr,
which will preserve more broken code (AST parent nodes that contain the
RecoveryExpr is preserved in the AST).

Diff Detail

Event Timeline

hokein created this revision.Mar 2 2022, 6:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 6:42 AM
hokein requested review of this revision.Mar 2 2022, 6:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 6:42 AM
hokein added inline comments.Mar 2 2022, 6:44 AM
clang/test/SemaCXX/copy-assignment.cpp
117

This is a bogus diagnostic "accidentally" caused by this change, this is an existing problem in clang where we discard ill-formed base specifier.

sammccall accepted this revision.Mar 2 2022, 7:03 AM

Very nice! I thought we had considered and rejected this in the past, but I think it was rather allowing lookup to find invalid decls in cases where it doesn't today.

clang/test/SemaCXX/constructor-initializer.cpp
252

update the other expected-error to to say what it refers to, too?

This revision is now accepted and ready to land.Mar 2 2022, 7:03 AM
hokein added a comment.Mar 3 2022, 1:32 AM

Very nice! I thought we had considered and rejected this in the past, but I think it was rather allowing lookup to find invalid decls in cases where it doesn't today.

Yeah, in the past (https://reviews.llvm.org/D76831), we tried to build the DeclRefExpr even for an invalid ref decl, it made the diagnostics much worse (as we don't know the type of the invalid decl, the fallback int type is not suitable for every cases).

We use a different approach in this approach (build RecoveryExpr instead), a sad bit is that we are not able to retrieve the ref decl from the RecoveryExpr.

This revision was landed with ongoing or failed builds.Mar 3 2022, 1:34 AM
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.

To preserve the decl, we could consider as a next step building a recoveryexpr wrapping a declrefexpr pointing at the invalid decl.

This was discussed in the patch you linked, but I don't think it was tried?