This is an archive of the discontinued LLVM Phabricator instance.

Treat qualifiers on elaborated types for qualtypenames appropriately.
ClosedPublic

Authored by saugustine on May 6 2016, 4:20 PM.

Details

Reviewers
bkramer
rnk
rsmith
Summary

Treat qualifiers on elaborated types for qualtypenames appropriately.

Diff Detail

Event Timeline

saugustine updated this revision to Diff 56480.May 6 2016, 4:20 PM
saugustine retitled this revision from to Treat qualifiers on elaborated types for qualtypenames appropriately..
saugustine updated this object.
saugustine added a reviewer: rnk.
saugustine added a subscriber: cfe-commits.
rsmith added a subscriber: rsmith.May 9 2016, 11:17 AM
rsmith added inline comments.
lib/Tooling/Core/QualTypeNames.cpp
386–390

Qualtype -> QualType

393–394

Maybe add an assert that QT is unqualified here?

401–402

I find the way this code ensures that we preserve the qualifiers to be a little subtle. It's not obvious to me that this does the right thing for a case like

struct X;
void f(const ::X x) {}

... where we have an ElaboratedType with no keyword, and for which we will generate an empty Prefix -- it looks like we would lose the const on line 392 and never add it back.

Can you remove and re-add the qualifiers unconditionally? (That is, move this removal of qualifiers from QT to after line 389, and move line 419 outside the if.) I think that'll make the logic clearer.

409–411

With the change suggested above, you should be able to delete the handling of qualifiers here.

dblaikie added inline comments.
unittests/Tooling/QualTypeNamesTest.cpp
91

What does this produce without your change? (what's the change causing to happen?)

saugustine updated this revision to Diff 56634.May 9 2016, 2:31 PM
saugustine marked an inline comment as done.
  • Handle elaborated types even more cleanly.

Thanks for the reviews. I believe I have addressed all issues. Take another look when you get the chance.

lib/Tooling/Core/QualTypeNames.cpp
401–402

We can remove and put them back unconditionally, but we still need to condition getting a new elaborated type, because an assertion prevents creating an elaborated type without a prefix of an empty keyword.

I'm not sure what you expect on the new example, but I have added it as a test case (as a pointer because the struct is incomplete). The result we produce in this case is "const X *", which I think is correct.

unittests/Tooling/QualTypeNamesTest.cpp
91

Without the change, we get "A::B::Class0 *" with no "const".

rsmith accepted this revision.May 9 2016, 2:51 PM
rsmith added a reviewer: rsmith.

LGTM with a couple of minor tweaks, thanks!

lib/Tooling/Core/QualTypeNames.cpp
401–402

Please move this up to immediately after line 389, so that we have a single point where we split QT into a type pointer and qualifiers.

401–402

Sure, building the elaborated type should still be conditional on there being one to build :)

const X * looks correct to me for your new example (I think with the old code we'd have got just X *).

407

Maybe pont -> point while you're here :)

411

QT = QualType(TypePtr, 0); would be fine here.

This revision is now accepted and ready to land.May 9 2016, 2:51 PM
saugustine updated this revision to Diff 56643.May 9 2016, 3:18 PM
saugustine marked 4 inline comments as done.
saugustine edited edge metadata.
  • Address remaining nits from review.

Thanks again. I've addressed the last little bits. Mind checking this in for me?

rsmith closed this revision.May 9 2016, 4:12 PM

Committed as rL268988.