This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Centralize type "desugaring" logic in ClangASTContext
ClosedPublic

Authored by labath on Dec 9 2019, 8:27 AM.

Details

Summary

A *lot* of ClangASTContext functions contained repetitive code for
"desugaring" certain kinds of clang types. This patch creates a utility
function for performing this task.

Right now it handles four types (auto, elaborated, paren and typedef),
as these are the types that were handled everywhere. There are probably
other kinds of types that could/should be added here too (TypeOf,
decltype, ...), but I'm leaving that for a separate patch as doing that
would not be NFC (though I'm pretty sure that adding them will not hurt,
and it may in fact fix some bugs).

In another patch I'd like to add "atomic" type to this list to properly
display atomic structs.

Since sometimes one may want to handle a certain kind of type specially
(right now we have code which does that with typedefs), the Desugar
function takes a "mask" argument, which can supress desugaring of
certain kinds of types.

Diff Detail

Event Timeline

labath created this revision.Dec 9 2019, 8:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2019, 8:27 AM
Herald added a subscriber: jfb. · View Herald Transcript
teemperor accepted this revision.Dec 9 2019, 8:59 AM

I think this can be further simplified, but we can also do the move to QualType::getDesugaredType in a follow-up commit to unblock your atomic struct patch.

lldb/source/Symbol/ClangASTContext.cpp
2489

QualType already has a getDesugaredType implementation that does the same (but handles more cases, so you still need the switch statement but you can unify all the case bodies if you want to keep this NFC).

This revision is now accepted and ready to land.Dec 9 2019, 8:59 AM
labath marked an inline comment as done.Dec 10 2019, 4:59 AM
labath added inline comments.
lldb/source/Symbol/ClangASTContext.cpp
2489

Good idea. I should have checked clang for similar functionality. Though, the right function here seems to be getLocallyUnqualifiedSingleStepDesugaredType. "SingleStep" because we want to avoid desugaring all the way if the caller has asked us to stop at typedefs. And "LocallyUnqualified" because: a) that's what the current code does; b) the non-locally unqualified version requires a ClangASTContext, which is not available in all callers.

That said, I think that the LocallyUnqualified thing should be fixed as it's probably the cause of some subtle bugs.

This revision was automatically updated to reflect the committed changes.