Page MenuHomePhabricator

[clang] Implement ElaboratedType sugaring for types written bare
Needs ReviewPublic

Authored by mizvekov on Oct 23 2021, 5:34 PM.

Details

Reviewers
shafik
jdoerfert
Group Reviewers
Restricted Project
Summary

Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.

The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.

An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.

Depends on D111509

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
mizvekov edited the summary of this revision. (Show Details)Oct 26 2021, 2:30 PM
rsmith added a subscriber: rsmith.Oct 27 2021, 12:28 PM
rsmith added inline comments.
clang/lib/Sema/SemaDecl.cpp
278

Maybe buildNamedType given that this also covers the non-nested case now?

291

It'd be useful to add a comment such as "These can never be qualified so an ElaboratedType node would carry no additional meaning."

296
548

Can we add these to the switch above and unconditionally call buildNestedType?

clang/lib/Sema/SemaDeclCXX.cpp
10913–10914

... maybe? I don't think any of the other kinds of adjustment can ever happen here, though, so either way seems correct.

mizvekov edited the summary of this revision. (Show Details)Nov 1 2021, 4:28 AM
mizvekov marked 5 inline comments as done.Wed, Nov 10, 3:09 PM
mizvekov added inline comments.
clang/lib/Sema/SemaDecl.cpp
291

Sure. But even then, in the current implementation of the type printer, adding this node would not be a no-op, it would incorrectly change meaning as we would suppress printing the scope of not just the type under the Elaborated node, but for any children of that as well. So for example a template parameter which is sugar for a CXXRecordDecl would be printed with scope suppressed.

mizvekov marked an inline comment as done.Wed, Nov 10, 5:50 PM
mizvekov updated this revision to Diff 387661.Tue, Nov 16, 8:32 AM
  • Run libcxx CI.
mizvekov published this revision for review.Tue, Nov 16, 10:40 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript
mizvekov updated this revision to Diff 387699.Tue, Nov 16, 10:43 AM
mizvekov retitled this revision from [clang] WIP: Implement ElaboratedType sugaring for types written bare to [clang] Implement ElaboratedType sugaring for types written bare.
mizvekov edited the summary of this revision. (Show Details)

rebase

martong removed a subscriber: martong.Thu, Nov 18, 2:41 AM
mizvekov updated this revision to Diff 389298.Tue, Nov 23, 1:11 PM
mizvekov edited the summary of this revision. (Show Details)
  • Avoid using any storage for an empty ElaboratedTYpeLoc.
    • But we still require pointer alignment for it, due to pre-existing bugs.
Herald added a project: Restricted Project. · View Herald TranscriptTue, Nov 23, 1:11 PM
mizvekov updated this revision to Diff 389352.Tue, Nov 23, 4:28 PM
  • fix IntrospectionTests.