[PATCH] D112374: [clang] Implement ElaboratedType sugaring for types written bare

Kim Gräsman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 16 08:05:19 PDT 2022


kimgr added a comment.

It's a little confusing, because it now looks like _every_ `Type` in the AST is wrapped in an `ElaboratedTypeLoc` + `ElaboratedType`. IWYU's debug AST dump shows this (excerpt):

  tests/cxx/sizeof_reference.cc:51:8: (1) [ VarDecl ] size_t s2                                                                                                                                                      
  tests/cxx/sizeof_reference.cc:51:1: (2) [ ElaboratedTypeLoc ] size_t                                                                                                                                               
  tests/cxx/sizeof_reference.cc:51:1: (2) [ ElaboratedType ] size_t                                                                                                                                                  
  tests/cxx/sizeof_reference.cc:51:1: (3) [ TypedefTypeLoc ] size_t                                                                                                                                                  
  tests/cxx/sizeof_reference.cc:51:1: (3) [ TypedefType ] size_t                                                                                                                                                     
  Marked full-info use of decl size_t (from /home/kimgr/code/iwyu/out/main/lib/clang/15.0.0/include/stddef.h:46:23) at tests/cxx/sizeof_reference.cc:51:1
  tests/cxx/sizeof_reference.cc:51:13: (2) [ UnaryExprOrTypeTraitExpr ] UnaryExprOrTypeTraitExpr 0x5589fd2a4230 'unsigned long' sizeof 'IndirectTemplateStruct<IndirectClass> &'                                     
                                                                                                                                                                                                                     
  (For type IndirectTemplateStruct<IndirectClass>):                                                                                                                                                                  
  Marked full-info use of decl IndirectTemplateStruct (from tests/cxx/sizeof_reference.cc:18:30) at tests/cxx/sizeof_reference.cc:51:20                                                                              
  tests/cxx/sizeof_reference.cc:51:20: (3) [ LValueReferenceTypeLoc ] IndirectTemplateStruct<IndirectClass> &                                                                                                        
  tests/cxx/sizeof_reference.cc:51:20: (3) [ LValueReferenceType ] IndirectTemplateStruct<IndirectClass> &                                                                                                           
  tests/cxx/sizeof_reference.cc:51:20: (4) [ ElaboratedTypeLoc ] IndirectTemplateStruct<IndirectClass>                                                                                                               
  tests/cxx/sizeof_reference.cc:51:20: (4) [ ElaboratedType ] IndirectTemplateStruct<IndirectClass>                                                                                                                  
  tests/cxx/sizeof_reference.cc:51:20: (5) [ TemplateSpecializationTypeLoc ] IndirectTemplateStruct<IndirectClass>                                                                                                   
  tests/cxx/sizeof_reference.cc:51:20: (5) [ TemplateSpecializationType ] IndirectTemplateStruct<IndirectClass>                                                                                                      
  Marked fwd-decl use of decl IndirectTemplateStruct (from tests/cxx/sizeof_reference.cc:18:30) at tests/cxx/sizeof_reference.cc:51:20                                                                               
  tests/cxx/sizeof_reference.cc:51:20: (6, fwd decl) [ TemplateName ] IndirectTemplateStruct                                                                                                                         
  tests/cxx/sizeof_reference.cc:51:43: (6, fwd decl) [ TemplateArgumentLoc ] <IndirectClass>                                                                                                                         
  tests/cxx/sizeof_reference.cc:51:43: (7, fwd decl) [ ElaboratedTypeLoc ] IndirectClass                                                                                                                             
  tests/cxx/sizeof_reference.cc:51:43: (7, fwd decl) [ ElaboratedType ] IndirectClass                                                                                                                                
  tests/cxx/sizeof_reference.cc:51:43: (8, fwd decl) [ RecordTypeLoc ] class IndirectClass                                                                                                                           
  tests/cxx/sizeof_reference.cc:51:43: (8, fwd decl) [ RecordType ] class IndirectClass                                                                                                                              
  Marked fwd-decl use of decl IndirectClass (from tests/cxx/indirect.h:18:7) at tests/cxx/sizeof_reference.cc:51:43                                                                                                  
  tests/cxx/sizeof_reference.cc:55:8: (1) [ VarDecl ] size_t s3                                                                                                                                                      
  tests/cxx/sizeof_reference.cc:55:1: (2) [ ElaboratedTypeLoc ] size_t                                                                                                                                               
  tests/cxx/sizeof_reference.cc:55:1: (2) [ ElaboratedType ] size_t                                                                                                                                                  
  tests/cxx/sizeof_reference.cc:55:1: (3) [ TypedefTypeLoc ] size_t                                                                                                                                                  
  tests/cxx/sizeof_reference.cc:55:1: (3) [ TypedefType ] size_t                                                                                                                                                     
  Marked full-info use of decl size_t (from /home/kimgr/code/iwyu/out/main/lib/clang/15.0.0/include/stddef.h:46:23) at tests/cxx/sizeof_reference.cc:55:1                                                            
  tests/cxx/sizeof_reference.cc:55:13: (2) [ UnaryExprOrTypeTraitExpr ] UnaryExprOrTypeTraitExpr 0x5589fd2a4760 'unsigned long' sizeof 'IndirectTemplateStruct<IndirectClass &>':'struct IndirectTemplateStruct<class
   IndirectClass &>'                                                          

for this line of code:

  size_t s2 = sizeof(IndirectTemplateStruct<IndirectClass>&); 

I'm not sure I understand why the elaborated type nodes are necessary even when they don't seem to add any additional information?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112374/new/

https://reviews.llvm.org/D112374



More information about the llvm-commits mailing list