This is an archive of the discontinued LLVM Phabricator instance.

[clang][AST] Fix crash when printing error
ClosedPublic

Authored by ellis on Dec 28 2021, 1:24 PM.

Details

Summary

Clang will crash if it tries to compile the following code. This commit
fixes it.

$ cat foo.c
void foo(_Nullable int *ptr) {
    __auto_type _Nonnull a = ptr;
};
$ clang foo.c -c -Wnullable-to-nonnull-conversion

Diff Detail

Event Timeline

ellis created this revision.Dec 28 2021, 1:24 PM
ellis published this revision for review.Dec 28 2021, 1:32 PM
ellis added inline comments.
clang/lib/AST/TypePrinter.cpp
242

Hi @dblaikie, I'm not familiar with this code but I'm wondering if these uses of T should actually be UnderlyingType. Will this cause a crash similar to what I found?

Herald added a project: Restricted Project. · View Herald TranscriptDec 28 2021, 1:32 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sammccall accepted this revision.Jan 1 2022, 8:18 PM
sammccall added inline comments.
clang/lib/AST/TypePrinter.cpp
242

There's no functional difference - these helpers all start with getAs<SomeTypeClass> so they'll see through the sugar on T.

Potentially UnderlyingType does a bit less work (since there's less sugar to look through) while T is marginally more obvious (to me at least). I wouldn't change it, I doubt this matters at all.

This revision is now accepted and ready to land.Jan 1 2022, 8:18 PM
This revision was landed with ongoing or failed builds.Jan 2 2022, 6:03 PM
This revision was automatically updated to reflect the committed changes.