This is an archive of the discontinued LLVM Phabricator instance.

[clang][Sema] Fix uninitialized `SourceLocation` for types with multiple attributes and macros.
ClosedPublic

Authored by vsapsai on Jan 10 2023, 12:55 PM.

Details

Summary

Some TypeLocs are considered "sugar" and we go past them in
GetTypeSourceInfoForDeclarator. The problem is that we peel off only
the same kind of TypeLoc at the time which makes it impossible to
handle mixed sequences like
AttributedTypeLoc - MacroQualifiedTypeLoc - AttributedTypeLoc - PointerTypeLoc

In this situation, as shown in the added test, we don't get to
PointerTypeLoc and don't set its starLoc leaving it uninitialized.

Address FIXME and peel off "sugar" TypeLocs regardless of their order.

rdar://102149264

Diff Detail

Event Timeline

vsapsai created this revision.Jan 10 2023, 12:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2023, 12:55 PM
Herald added a subscriber: ributzka. · View Herald Transcript
vsapsai requested review of this revision.Jan 10 2023, 12:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 10 2023, 12:55 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
vsapsai updated this revision to Diff 487959.Jan 10 2023, 12:58 PM

clang-format the change.

Want to note that originally the issue was noticed with the modules because we serialize and deserialize PointerTypeLoc::starLoc and on deserialization we assert if the value is too big. With uninitialized memory the value can be too big sometimes and clang was failing intermittently. For testing don't use modules anymore and call PointerTypeLoc::getStarLoc directly to make it simpler and more reliable.

clang/lib/Sema/SemaType.cpp
6513–6516

Didn't move AtomicTypeLoc into the switch because it is peeled off only once and not in the while loop unlike other TypeLocs.

vsapsai updated this revision to Diff 490003.Jan 17 2023, 5:51 PM

Rebase the patch and trigger pre-commit checks.

yonghong-song accepted this revision.Jan 17 2023, 8:46 PM

LGTM. Thanks!

This revision is now accepted and ready to land.Jan 17 2023, 8:46 PM

Thanks for the review!

This revision was landed with ongoing or failed builds.Jan 18 2023, 2:16 PM
This revision was automatically updated to reflect the committed changes.