This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix typos in member initializers
ClosedPublic

Authored by kadircet on Jan 20 2023, 1:02 AM.

Details

Summary

This was regressed in ca619613801233ef2def8c3cc7d311d5ed0033cb. As we
attached InitExprs as-is to the AST, without performing transformations.

Diff Detail

Event Timeline

kadircet created this revision.Jan 20 2023, 1:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2023, 1:02 AM
kadircet requested review of this revision.Jan 20 2023, 1:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2023, 1:02 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Randomly chiming in here.
I never had a good model of where CorrectDelayedTyposInExpr, but wanted to note that ActOnFullExpr also calls it. This may be fine, I just wanted to mention it as it stood out.

clang/lib/Sema/SemaDeclCXX.cpp
4101–4105

Should we pass FD here to avoid correcting to itself?

Randomly chiming in here.
I never had a good model of where CorrectDelayedTyposInExpr, but wanted to note that ActOnFullExpr also calls it. This may be fine, I just wanted to mention it as it stood out.

+1, we seem to call CorrectDelayedTyposInExpr in an ad-hoc way.

The fix looks good to me, but I will leave the final stamp to @aaron.ballman, @cor3ntin.

clang/test/PCH/typo3.cpp
7

IIUC, the issue is that, we have a dangling TypoExpr under the FieldDecl in the final AST, which violates the contract of TypoExpr.

aaron.ballman added inline comments.Jan 20 2023, 5:14 AM
clang/lib/Sema/SemaDeclCXX.cpp
4103

Should we be checking for Init.isUsable() before calling .get()?

kadircet marked 3 inline comments as done.Jan 20 2023, 5:24 AM
kadircet added inline comments.
clang/lib/Sema/SemaDeclCXX.cpp
4101–4105

unfortunately the interface requires a VarDecl, hence we can't pass a FieldDecl.

4103

because InitExpr is never null here (we bail out early), and because we're converting any leftover TypoExprs to RecoveryExpr Init should always be Usable here. adding an assert.

clang/test/PCH/typo3.cpp
7

yes

kadircet updated this revision to Diff 490793.Jan 20 2023, 5:24 AM
kadircet marked 3 inline comments as done.

assert on usability of initializer

This revision is now accepted and ready to land.Jan 20 2023, 5:38 AM
This revision was landed with ongoing or failed builds.Jan 20 2023, 6:20 AM
This revision was automatically updated to reflect the committed changes.
ilya-biryukov added inline comments.Jan 20 2023, 7:43 AM
clang/lib/Sema/SemaDeclCXX.cpp
4101–4105

Ah, it also does not seem to suggest any FieldDecls for typo correction. Nevermind then, sorry for the noise.