[PATCH] D158265: [clang][AST] TextNodeDumper learned to output refers_to_enclosing_variable_or_capture flag for DeclRefExpr

2023-08-18 Thread Timo Stripf via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd34e97c8a117: [clang][AST] TextNodeDumper learned to output… 
(authored by strimo378).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158265

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-lambda.cpp
  clang/test/AST/ast-dump-openmp-distribute-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-distribute-parallel-for.c
  clang/test/AST/ast-dump-openmp-distribute-simd.c
  clang/test/AST/ast-dump-openmp-distribute.c
  clang/test/AST/ast-dump-openmp-for-simd.c
  clang/test/AST/ast-dump-openmp-for.c
  clang/test/AST/ast-dump-openmp-ordered.c
  clang/test/AST/ast-dump-openmp-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-parallel-for.c
  clang/test/AST/ast-dump-openmp-simd.c
  clang/test/AST/ast-dump-openmp-target-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-target-parallel-for.c
  clang/test/AST/ast-dump-openmp-target-simd.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute-parallel-for.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute-simd.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute.c
  clang/test/AST/ast-dump-openmp-taskloop-simd.c
  clang/test/AST/ast-dump-openmp-taskloop.c
  clang/test/AST/ast-dump-openmp-teams-distribute-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-teams-distribute-parallel-for.c
  clang/test/AST/ast-dump-openmp-teams-distribute-simd.c
  clang/test/AST/ast-dump-openmp-teams-distribute.c

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158242: [Clang][Attribute] Introduce linkage attribute to specify the exact LLVM linkage type for functions or variables

2023-08-18 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

> I'm wary of exposing internal LLVM implementation details through a 
> user-facing attribute like this.

@aaron.ballman That means you would be more open to an attribute like 
`__attribute__((onedefinitionrule))` because it is part of the C++ standard?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158242

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158265: [clang][AST] TextNodeDumper learned to output refers_to_enclosing_variable_or_capture flag for DeclRefExpr

2023-08-18 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

It is not that easy. It is an important flag for lambdas and it took me quite a 
while analyzing codegen to find it. In general, it is very seldom useful. 
OpenMP seems to have to good test coverage of ast-dump test cases. I think it 
is also used for nested C function that can access the scope of the parent 
function.

Consider the following example:

  void func(int x) {
  x;
  
  [x]() { return x; };
  }

The outer DeclRefExpr #189 to x does not have the flag, the inner has the flag 
DeclRefExpr #195 .

  FunctionDecl #187 0x20ddd29c760 lc 0x20ddb844ed8 
 line:2:6
  |-Decl: ParmVar 0x20ddd2520f0 #185 'x' 'int'#7 func 'void (int)'#186
  |-Decl: CXXRecord 0x20ddd29c950 #192 ''
  |-ParmVarDecl #185 0x20ddd2520f0 lc 0x20ddd29c760  col:15 
used x 'int'#7
  `-CompoundStmt 0x20ddd29cfe0 
|-DeclRefExpr #189 0x20ddd29c860  'int'#7 lvalue ParmVar 
0x20ddd2520f0 #185 'x' 'int'#7**
`-LambdaExpr #207 0x20ddd29ce50  '(lambda at 
D:\emmtrix\git\llvm2\test_clang_ccode\test74_lambda04_capture1_value1.cpp:5:2)'#193
  |-CXXRecordDecl #192 0x20ddd29c950 lc 0x20ddd29c760  col:2 
implicit class definition '(lambda at 
D:\emmtrix\git\llvm2\test_clang_ccode\test74_lambda04_capture1_value1.cpp:5:2)'#193
  | |-DefinitionData lambda pass_in_registers standard_layout 
trivially_copyable can_const_default_init
  | | |-DefaultConstructor
  | | |-CopyConstructor simple trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveConstructor exists simple trivial needs_implicit
  | | |-CopyAssignment trivial has_const_param needs_implicit 
implicit_has_const_param
  | | |-MoveAssignment
  | | `-Destructor simple irrelevant trivial
  | |-CXXMethodDecl #194 0x20ddd29ca98 lc 0x20ddd29c950  
col:2 operator() 'int () const'#202 typeloc 'auto () const'#191 inline
  | | `-CompoundStmt 0x20ddd29cd50 
  | |   `-ReturnStmt 0x20ddd29cd40 
  | | `-ImplicitCastExpr #203 0x20ddd29cd20  'int'#7 

  | |   `-DeclRefExpr #195 0x20ddd29cb50  'const int'#7 lvalue 
ParmVar 0x20ddd2520f0 #185 'x' 'int'#7 refers_to_enclosing_variable_or_capture
  | `-FieldDecl #206 0x20ddd29cdc8 lc 0x20ddd29c950  col:3 implicit 
'int'#7
  |-ImplicitCastExpr #205 0x20ddd29cd90  'int'#7 
  | `-DeclRefExpr #204 0x20ddd29cd68  'int'#7 lvalue ParmVar 
0x20ddd2520f0 #185 'x' 'int'#7
  `-CompoundStmt 0x20ddd29cd50 
`-ReturnStmt 0x20ddd29cd40 
  `-ImplicitCastExpr #203 0x20ddd29cd20  'int'#7 

`-DeclRefExpr #195 0x20ddd29cb50  'const int'#7 lvalue 
ParmVar 0x20ddd2520f0 #185 'x' 'int'#7 refers_to_enclosing_variable_or_capture


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158265

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158267: [clang][CodeGen] Avoid emitting unnecessary memcpy of records without content

2023-08-18 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang codegen emits an unnecessary memcpy for C++ class without content. This 
patch fixes the issue.

See https://github.com/llvm/llvm-project/issues/59336

Please let me know if the patch is going into the right direction that it can 
be accepted. If yes, I'll finish it with test cases and also extend it to C. 
Currently, check-clang is not showing an error...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158267

Files:
  clang/lib/CodeGen/CGExprAgg.cpp


Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -2099,6 +2099,34 @@
   return AggValueSlot::MayOverlap;
 }
 
+static bool hasSomethingToCopy(const ASTContext , QualType Ty) {
+  if (const RecordType *RT = Ty->getAs()) {
+CXXRecordDecl *Record = cast(RT->getDecl());
+
+if (Record->isEmpty())
+  return false;
+if (Record->isDynamicClass())
+  return true;
+
+for (auto *Field : Record->fields()) {
+  if (Field->isZeroLengthBitField(Ctx))
+continue;
+
+  if (hasSomethingToCopy(Ctx, Field->getType()))
+return true;
+}
+
+for (auto  : Record->bases()) {
+  if (hasSomethingToCopy(Ctx, Base.getType()))
+return true;
+}
+
+return false;
+  } else {
+return true;
+  }
+}
+
 void CodeGenFunction::EmitAggregateCopy(LValue Dest, LValue Src, QualType Ty,
 AggValueSlot::Overlap_t MayOverlap,
 bool isVolatile) {
@@ -2118,7 +2146,7 @@
  "Trying to aggregate-copy a type without a trivial copy/move "
  "constructor or assignment operator");
   // Ignore empty classes in C++.
-  if (Record->isEmpty())
+  if (!hasSomethingToCopy(getContext(), Ty))
 return;
 }
   }


Index: clang/lib/CodeGen/CGExprAgg.cpp
===
--- clang/lib/CodeGen/CGExprAgg.cpp
+++ clang/lib/CodeGen/CGExprAgg.cpp
@@ -2099,6 +2099,34 @@
   return AggValueSlot::MayOverlap;
 }
 
+static bool hasSomethingToCopy(const ASTContext , QualType Ty) {
+  if (const RecordType *RT = Ty->getAs()) {
+CXXRecordDecl *Record = cast(RT->getDecl());
+
+if (Record->isEmpty())
+  return false;
+if (Record->isDynamicClass())
+  return true;
+
+for (auto *Field : Record->fields()) {
+  if (Field->isZeroLengthBitField(Ctx))
+continue;
+
+  if (hasSomethingToCopy(Ctx, Field->getType()))
+return true;
+}
+
+for (auto  : Record->bases()) {
+  if (hasSomethingToCopy(Ctx, Base.getType()))
+return true;
+}
+
+return false;
+  } else {
+return true;
+  }
+}
+
 void CodeGenFunction::EmitAggregateCopy(LValue Dest, LValue Src, QualType Ty,
 AggValueSlot::Overlap_t MayOverlap,
 bool isVolatile) {
@@ -2118,7 +2146,7 @@
  "Trying to aggregate-copy a type without a trivial copy/move "
  "constructor or assignment operator");
   // Ignore empty classes in C++.
-  if (Record->isEmpty())
+  if (!hasSomethingToCopy(getContext(), Ty))
 return;
 }
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158265: [clang][AST] TextNodeDumper learned to output refers_to_enclosing_variable_or_capture flag for DeclRefExpr

2023-08-18 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158265

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-lambda.cpp
  clang/test/AST/ast-dump-openmp-distribute-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-distribute-parallel-for.c
  clang/test/AST/ast-dump-openmp-distribute-simd.c
  clang/test/AST/ast-dump-openmp-distribute.c
  clang/test/AST/ast-dump-openmp-for-simd.c
  clang/test/AST/ast-dump-openmp-for.c
  clang/test/AST/ast-dump-openmp-ordered.c
  clang/test/AST/ast-dump-openmp-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-parallel-for.c
  clang/test/AST/ast-dump-openmp-simd.c
  clang/test/AST/ast-dump-openmp-target-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-target-parallel-for.c
  clang/test/AST/ast-dump-openmp-target-simd.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute-parallel-for.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute-simd.c
  clang/test/AST/ast-dump-openmp-target-teams-distribute.c
  clang/test/AST/ast-dump-openmp-taskloop-simd.c
  clang/test/AST/ast-dump-openmp-taskloop.c
  clang/test/AST/ast-dump-openmp-teams-distribute-parallel-for-simd.c
  clang/test/AST/ast-dump-openmp-teams-distribute-parallel-for.c
  clang/test/AST/ast-dump-openmp-teams-distribute-simd.c
  clang/test/AST/ast-dump-openmp-teams-distribute.c

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158242: [Clang][Attribute] Introduce linkage attribute to specify the exact LLVM linkage type for functions or variables

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158242

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-linkage.c

Index: clang/test/CodeGen/attr-linkage.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-linkage.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -emit-llvm -Wno-gcc-compat -O1 -disable-llvm-passes -o - %s | FileCheck %s
+
+int v01 __attribute__((linkage("external")));
+int v02 __attribute__((linkage("available_externally")));
+int v03 __attribute__((linkage("linkonce")));
+int v04 __attribute__((linkage("linkonce_odr")));
+int v05 __attribute__((linkage("weak")));
+int v06 __attribute__((linkage("weak_odr")));
+int v07[3] __attribute__((linkage("appending")));
+int v08 __attribute__((linkage("internal")));
+int v09 __attribute__((linkage("private")));
+int v10 __attribute__((linkage("external_weak")));
+int v11 __attribute__((linkage("common")));
+
+// CHECK: @v01 = global i32 0
+// CHECK: @v02 = available_externally global i32 0
+// CHECK: @v03 = linkonce global i32 0
+// CHECK: @v04 = linkonce_odr global i32 0
+// CHECK: @v05 = weak global i32 0
+// CHECK: @v06 = weak_odr global i32 0
+// CHECK: @v07 = appending global [3 x i32] zeroinitializer
+// CHECK: @v08 = internal global i32 0
+// CHECK: @v09 = private global i32 0
+// CHECK: @v10 = extern_weak global i32 0
+// CHECK: @v11 = common global i32 0
+
+void f01(void) __attribute__((linkage("external"))) {};
+void f02(void) __attribute__((linkage("available_externally"))) {};
+void f03(void) __attribute__((linkage("linkonce"))) {};
+void f04(void) __attribute__((linkage("linkonce_odr"))) {};
+void f05(void) __attribute__((linkage("weak"))) {};
+void f06(void) __attribute__((linkage("weak_odr"))) {};
+// appending is only applicable to variables
+void f08(void) __attribute__((linkage("internal"))) {};
+void f09(void) __attribute__((linkage("private"))) {};
+void f10(void) __attribute__((linkage("external_weak"))) {};
+// common is only applicable to variables
+
+// CHECK: define dso_local void @f01()
+// CHECK: define available_externally void @f02()
+// CHECK: define linkonce void @f03()
+// CHECK: define linkonce_odr void @f04()
+// CHECK: define weak void @f05()
+// CHECK: define weak_odr void @f06()
+// CHECK: define internal void @f08()
+// CHECK: define private void @f09()
+// CHECK: define extern_weak void @f10()
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -2365,6 +2365,29 @@
   D->addAttr(::new (S.Context) ConstructorAttr(S.Context, AL, priority));
 }
 
+static void handleLinkageAttr(Sema , Decl *D, const ParsedAttr ) {
+  // Linkage attributes don't mean anything on a typedef.
+  if (isa(D)) {
+S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
+return;
+  }
+
+  // Check that the argument is a string literal.
+  StringRef TypeStr;
+  SourceLocation LiteralLoc;
+  if (!S.checkStringLiteralArgumentAttr(AL, 0, TypeStr, ))
+return;
+
+  LinkageAttr::LinkageType type;
+  if (!LinkageAttr::ConvertStrToLinkageType(TypeStr, type)) {
+S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported)
+<< AL << TypeStr;
+return;
+  }
+
+  D->addAttr(::new (S.Context) LinkageAttr(S.Context, AL, type));
+}
+
 static void handleDestructorAttr(Sema , Decl *D, const ParsedAttr ) {
   uint32_t priority = DestructorAttr::DefaultPriority;
   if (AL.getNumArgs() &&
@@ -8878,6 +8901,9 @@
 S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl)
 << AL << AL.isRegularKeywordAttribute() << D->getLocation();
 break;
+  case ParsedAttr::AT_Linkage:
+handleLinkageAttr(S, D, AL);
+break;
   case ParsedAttr::AT_Interrupt:
 handleInterruptAttr(S, D, AL);
 break;
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -5413,6 +5413,36 @@
 llvm::GlobalValue::LinkageTypes
 CodeGenModule::getLLVMLinkageForDeclarator(const DeclaratorDecl *D,
GVALinkage Linkage) {
+
+  if (const auto *A = D->getAttr()) {
+switch (A->getLinkage()) {
+case LinkageAttr::Private:
+  return llvm::GlobalValue::PrivateLinkage;
+case LinkageAttr::Internal:
+  return llvm::GlobalValue::InternalLinkage;
+case LinkageAttr::WeakAny:
+  return llvm::GlobalValue::WeakAnyLinkage;
+case LinkageAttr::WeakODR:
+  return llvm::GlobalValue::WeakODRLinkage;
+case LinkageAttr::LinkOnceAny:
+  return 

[PATCH] D158188: [clang][AST] TextNodeDumper learned to output friend information for functions

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG110d141f12b7: [clang][AST] TextNodeDumper learned to output 
friend information for functions (authored by strimo378).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158188

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/CXX/class/class.friend/p7-cxx20.cpp


Index: clang/test/CXX/class/class.friend/p7-cxx20.cpp
===
--- clang/test/CXX/class/class.friend/p7-cxx20.cpp
+++ clang/test/CXX/class/class.friend/p7-cxx20.cpp
@@ -19,7 +19,7 @@
 // CHECK-NM: `-CXXRecordDecl {{.*}}  line:2:7 
class X definition
 // CHECK-NM:   |-CXXRecordDecl {{.*}}  col:7 implicit class X
 // CHECK-NM-NEXT: `-FriendDecl {{.*}}  col:15
-// CHECK-NM-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 x 
'void ()' implicit-inline
+// CHECK-NM-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
friend_undeclared x 'void ()' implicit-inline
 
 //--- header-unit.h
 
@@ -30,7 +30,7 @@
 // CHECK-HU: `-CXXRecordDecl {{.*}} <./header-unit.h:2:1, line:4:1> line:2:7 
class Y definition
 // CHECK-HU: |-CXXRecordDecl {{.*}}  col:7 implicit class Y
 // CHECK-HU-NEXT: `-FriendDecl {{.*}}  col:15
-// CHECK-HU-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 y 
'void ()' implicit-inline
+// CHECK-HU-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
friend_undeclared y 'void ()' implicit-inline
 
 // A textually-included header
 //--- header.h
@@ -51,9 +51,9 @@
 // CHECK-MOD: |-CXXRecordDecl {{.*}} <./header.h:2:1, line:4:1> line:2:7 in 
M. hidden class A definition
 // CHECK-MOD: | |-CXXRecordDecl {{.*}}  col:7 in M. 
hidden implicit class A
 // CHECK-MOD-NEXT: | `-FriendDecl {{.*}}  col:15 in 
M.
-// CHECK-MOD-NEXT: |   `-FunctionDecl {{.*}} parent {{.*}}  
col:15 in M. hidden a 'void ()' implicit-inline
+// CHECK-MOD-NEXT: |   `-FunctionDecl {{.*}} parent {{.*}}  
col:15 in M. hidden friend_undeclared a 'void ()' implicit-inline
 
 // CHECK-MOD: `-CXXRecordDecl {{.*}}  line:6:7 in M 
hidden class Z{{( ReachableWhenImported)?}} definition
 // CHECK-MOD: |-CXXRecordDecl {{.*}}  col:7 in M hidden implicit 
class Z{{( ReachableWhenImported)?}}
 // CHECK-MOD-NEXT: `-FriendDecl {{.*}}  col:15 in M{{( 
ReachableWhenImported)?}}
-// CHECK-MOD-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
in M hidden z 'void ()'{{( ReachableWhenImported)?}}
+// CHECK-MOD-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
in M hidden friend_undeclared z 'void ()'{{( ReachableWhenImported)?}}
Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -525,7 +525,7 @@
   // CHECK-NEXT: | | `-Destructor simple irrelevant trivial needs_implicit{{$}}
   // CHECK-NEXT: | |-CXXRecordDecl 0x{{.+}}  col:31 implicit 
class TestClassTemplate{{$}}
   // CHECK-NEXT: | `-FriendDecl 0x{{.+}}  
col:40{{$}}
-  // CHECK-NEXT: |   `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}}  col:40 TestClassTemplate{{$}}
+  // CHECK-NEXT: |   `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}}  col:40 friend_undeclared TestClassTemplate{{$}}
   // CHECK-NEXT: | |-TemplateTypeParmDecl 0x{{.+}}  col:23 
typename depth 1 index 0 T2{{$}}
   // CHECK-NEXT: | `-CXXRecordDecl 0x{{.+}} parent 0x{{.+}}  col:40 class TestClassTemplate{{$}}
   // CHECK-NEXT: `-ClassTemplateSpecializationDecl 0x{{.+}} 
 line:[[@LINE-19]]:31 class 
TestClassTemplate definition implicit_instantiation{{$}}
@@ -541,7 +541,7 @@
   // CHECK-NEXT:   |   `-CXXRecord 0x{{.+}} 'A'{{$}}
   // CHECK-NEXT:   |-CXXRecordDecl 0x{{.+}}  col:31 implicit 
class TestClassTemplate{{$}}
   // CHECK-NEXT:   |-FriendDecl 0x{{.+}}  
col:40{{$}}
-  // CHECK-NEXT:   | `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}} prev 
0x{{.+}}  col:40 TestClassTemplate{{$}}
+  // CHECK-NEXT:   | `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}} prev 
0x{{.+}}  col:40 friend TestClassTemplate{{$}}
   // CHECK-NEXT:   |   |-TemplateTypeParmDecl 0x{{.+}}  col:23 
typename depth 0 index 0 T2{{$}}
   // CHECK-NEXT:   |   |-CXXRecordDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} 
 col:40 class TestClassTemplate{{$}}
   // CHECK-NEXT:   |   `-ClassTemplateSpecialization 0x{{.+}} 
'TestClassTemplate'{{$}}
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -300,6 +300,17 @@
 }
   }
 
+  switch (D->getFriendObjectKind()) {
+  case Decl::FOK_None:
+break;
+  case Decl::FOK_Declared:
+OS << " friend";
+break;
+  case Decl::FOK_Undeclared:
+OS << " friend_undeclared";
+break;
+  }
+
   ConstDeclVisitor::Visit(D);
 }
 


Index: clang/test/CXX/class/class.friend/p7-cxx20.cpp

[PATCH] D158055: [clang][AST] Added some missing setter methods

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 abandoned this revision.
strimo378 added a comment.

Alright, thank you for the review...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158055

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158188: [clang][AST] TextNodeDumper learned to output friend information for functions

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158188

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/CXX/class/class.friend/p7-cxx20.cpp


Index: clang/test/CXX/class/class.friend/p7-cxx20.cpp
===
--- clang/test/CXX/class/class.friend/p7-cxx20.cpp
+++ clang/test/CXX/class/class.friend/p7-cxx20.cpp
@@ -19,7 +19,7 @@
 // CHECK-NM: `-CXXRecordDecl {{.*}}  line:2:7 
class X definition
 // CHECK-NM:   |-CXXRecordDecl {{.*}}  col:7 implicit class X
 // CHECK-NM-NEXT: `-FriendDecl {{.*}}  col:15
-// CHECK-NM-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 x 
'void ()' implicit-inline
+// CHECK-NM-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
friend_undeclared x 'void ()' implicit-inline
 
 //--- header-unit.h
 
@@ -30,7 +30,7 @@
 // CHECK-HU: `-CXXRecordDecl {{.*}} <./header-unit.h:2:1, line:4:1> line:2:7 
class Y definition
 // CHECK-HU: |-CXXRecordDecl {{.*}}  col:7 implicit class Y
 // CHECK-HU-NEXT: `-FriendDecl {{.*}}  col:15
-// CHECK-HU-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 y 
'void ()' implicit-inline
+// CHECK-HU-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
friend_undeclared y 'void ()' implicit-inline
 
 // A textually-included header
 //--- header.h
@@ -51,9 +51,9 @@
 // CHECK-MOD: |-CXXRecordDecl {{.*}} <./header.h:2:1, line:4:1> line:2:7 in 
M. hidden class A definition
 // CHECK-MOD: | |-CXXRecordDecl {{.*}}  col:7 in M. 
hidden implicit class A
 // CHECK-MOD-NEXT: | `-FriendDecl {{.*}}  col:15 in 
M.
-// CHECK-MOD-NEXT: |   `-FunctionDecl {{.*}} parent {{.*}}  
col:15 in M. hidden a 'void ()' implicit-inline
+// CHECK-MOD-NEXT: |   `-FunctionDecl {{.*}} parent {{.*}}  
col:15 in M. hidden friend_undeclared a 'void ()' implicit-inline
 
 // CHECK-MOD: `-CXXRecordDecl {{.*}}  line:6:7 in M 
hidden class Z{{( ReachableWhenImported)?}} definition
 // CHECK-MOD: |-CXXRecordDecl {{.*}}  col:7 in M hidden implicit 
class Z{{( ReachableWhenImported)?}}
 // CHECK-MOD-NEXT: `-FriendDecl {{.*}}  col:15 in M{{( 
ReachableWhenImported)?}}
-// CHECK-MOD-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
in M hidden z 'void ()'{{( ReachableWhenImported)?}}
+// CHECK-MOD-NEXT: `-FunctionDecl {{.*}} parent {{.*}}  col:15 
in M hidden friend_undeclared z 'void ()'{{( ReachableWhenImported)?}}
Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -525,7 +525,7 @@
   // CHECK-NEXT: | | `-Destructor simple irrelevant trivial needs_implicit{{$}}
   // CHECK-NEXT: | |-CXXRecordDecl 0x{{.+}}  col:31 implicit 
class TestClassTemplate{{$}}
   // CHECK-NEXT: | `-FriendDecl 0x{{.+}}  
col:40{{$}}
-  // CHECK-NEXT: |   `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}}  col:40 TestClassTemplate{{$}}
+  // CHECK-NEXT: |   `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}}  col:40 friend_undeclared TestClassTemplate{{$}}
   // CHECK-NEXT: | |-TemplateTypeParmDecl 0x{{.+}}  col:23 
typename depth 1 index 0 T2{{$}}
   // CHECK-NEXT: | `-CXXRecordDecl 0x{{.+}} parent 0x{{.+}}  col:40 class TestClassTemplate{{$}}
   // CHECK-NEXT: `-ClassTemplateSpecializationDecl 0x{{.+}} 
 line:[[@LINE-19]]:31 class 
TestClassTemplate definition implicit_instantiation{{$}}
@@ -541,7 +541,7 @@
   // CHECK-NEXT:   |   `-CXXRecord 0x{{.+}} 'A'{{$}}
   // CHECK-NEXT:   |-CXXRecordDecl 0x{{.+}}  col:31 implicit 
class TestClassTemplate{{$}}
   // CHECK-NEXT:   |-FriendDecl 0x{{.+}}  
col:40{{$}}
-  // CHECK-NEXT:   | `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}} prev 
0x{{.+}}  col:40 TestClassTemplate{{$}}
+  // CHECK-NEXT:   | `-ClassTemplateDecl 0x{{.+}} parent 0x{{.+}} prev 
0x{{.+}}  col:40 friend TestClassTemplate{{$}}
   // CHECK-NEXT:   |   |-TemplateTypeParmDecl 0x{{.+}}  col:23 
typename depth 0 index 0 T2{{$}}
   // CHECK-NEXT:   |   |-CXXRecordDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}} 
 col:40 class TestClassTemplate{{$}}
   // CHECK-NEXT:   |   `-ClassTemplateSpecialization 0x{{.+}} 
'TestClassTemplate'{{$}}
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -300,6 +300,17 @@
 }
   }
 
+  switch (D->getFriendObjectKind()) {
+  case Decl::FOK_None:
+break;
+  case Decl::FOK_Declared:
+OS << " friend";
+break;
+  case Decl::FOK_Undeclared:
+OS << " friend_undeclared";
+break;
+  }
+
   ConstDeclVisitor::Visit(D);
 }
 


Index: clang/test/CXX/class/class.friend/p7-cxx20.cpp
===
--- clang/test/CXX/class/class.friend/p7-cxx20.cpp
+++ 

[PATCH] D158165: [clang][AST] TextNodeDumper learned to output instantiated_from information

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd7f7fb6c1d97: [clang][AST] TextNodeDumper learned to output 
instantiated_from information (authored by strimo378).

Changed prior to commit:
  https://reviews.llvm.org/D158165?vs=551068=551124#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158165

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp

Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -316,173 +316,173 @@
   template class TT> struct TestTemplateTemplateDefaultType { };
 }
 
-// CHECK:   ClassTemplateDecl 0x{{.+}} <{{.+}}:[[@LINE-40]]:3, line:[[@LINE-34]]:3> line:[[@LINE-40]]:30 TestClassTemplate
-// CHECK-NEXT:  |-TemplateTypeParmDecl 0x{{.+}}  col:21 typename depth 0 index 0 T
-// CHECK-NEXT:  |-CXXRecordDecl 0x{{.+}}  line:[[@LINE-42]]:30 class TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit referenced class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  col:5 TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  col:5 ~TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 j 'int ()'
-// CHECK-NEXT:  | `-FieldDecl 0x{{.+}}  col:9 i 'int'
-// CHECK-NEXT:  |-ClassTemplateSpecializationDecl 0x{{.+}}  line:[[@LINE-56]]:30 class TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor non_trivial user_declared
-// CHECK-NEXT:  | |-TemplateArgument type 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | | `-RecordType 0{{.+}} 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | |   `-CXXRecord 0x{{.+}} 'A'
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  col:5 used TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  col:5 used ~TestClassTemplate 'void () noexcept'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 j 'int ()'
-// CHECK-NEXT:  | |-FieldDecl 0x{{.+}}  col:9 i 'int'
-// CHECK-NEXT:  | `-CXXConstructorDecl 0x{{.+}}  col:30 implicit constexpr TestClassTemplate 'void (const TestClassTemplate &)' inline default trivial noexcept-unevaluated 0x{{.+}}
-// CHECK-NEXT:  |   `-ParmVarDecl 0x{{.+}}  col:30 'const TestClassTemplate &'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  `-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-
-// CHECK:   ClassTemplateSpecializationDecl 0x{{.+}} <{{.+}}:[[@LINE-67]]:3, line:[[@LINE-65]]:3> line:[[@LINE-67]]:20 class TestClassTemplate definition
-// CHECK-NEXT:  |-DefinitionData pass_in_registers standard_layout trivially_copyable trivial literal
-// CHECK-NEXT:  | |-DefaultConstructor exists trivial needs_implicit
-// CHECK-NEXT:  | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | |-MoveConstructor exists simple trivial needs_implicit
-// CHECK-NEXT:  | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | |-MoveAssignment exists simple trivial needs_implicit
-// CHECK-NEXT:  | `-Destructor simple irrelevant trivial needs_implicit
-// CHECK-NEXT:  |-TemplateArgument type 'testClassTemplateDecl::B'
-// CHECK-NEXT:  | `-RecordType 0{{.+}} 'testClassTemplateDecl::B'
-// CHECK-NEXT:  |   `-CXXRecord 0x{{.+}} 'B'
-// CHECK-NEXT:  |-CXXRecordDecl 0x{{.+}}  col:20 implicit class TestClassTemplate
-// CHECK-NEXT:  `-FieldDecl 0x{{.+}}  col:9 j 'int'
-
-// CHECK:   ClassTemplateSpecializationDecl 0x{{.+}} <{{.+}}:{{.*}}:3, col:44> col:25 class 

[PATCH] D158165: [clang][AST] TextNodeDumper learned to output instantiated_from information

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158165

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp

Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -316,173 +316,173 @@
   template class TT> struct TestTemplateTemplateDefaultType { };
 }
 
-// CHECK:   ClassTemplateDecl 0x{{.+}} <{{.+}}:[[@LINE-40]]:3, line:[[@LINE-34]]:3> line:[[@LINE-40]]:30 TestClassTemplate
-// CHECK-NEXT:  |-TemplateTypeParmDecl 0x{{.+}}  col:21 typename depth 0 index 0 T
-// CHECK-NEXT:  |-CXXRecordDecl 0x{{.+}}  line:[[@LINE-42]]:30 class TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit referenced class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  col:5 TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  col:5 ~TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 j 'int ()'
-// CHECK-NEXT:  | `-FieldDecl 0x{{.+}}  col:9 i 'int'
-// CHECK-NEXT:  |-ClassTemplateSpecializationDecl 0x{{.+}}  line:[[@LINE-56]]:30 class TestClassTemplate definition
-// CHECK-NEXT:  | |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | | |-DefaultConstructor exists non_trivial user_provided
-// CHECK-NEXT:  | | |-CopyConstructor simple trivial has_const_param implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveConstructor
-// CHECK-NEXT:  | | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | | |-MoveAssignment
-// CHECK-NEXT:  | | `-Destructor non_trivial user_declared
-// CHECK-NEXT:  | |-TemplateArgument type 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | | `-RecordType 0{{.+}} 'testClassTemplateDecl::A'
-// CHECK-NEXT:  | |   `-CXXRecord 0x{{.+}} 'A'
-// CHECK-NEXT:  | |-CXXRecordDecl 0x{{.+}}  col:30 implicit class TestClassTemplate
-// CHECK-NEXT:  | |-AccessSpecDecl 0x{{.+}}  col:3 public
-// CHECK-NEXT:  | |-CXXConstructorDecl 0x{{.+}}  col:5 used TestClassTemplate 'void ()'
-// CHECK-NEXT:  | |-CXXDestructorDecl 0x{{.+}}  col:5 used ~TestClassTemplate 'void () noexcept'
-// CHECK-NEXT:  | |-CXXMethodDecl 0x{{.+}}  col:9 j 'int ()'
-// CHECK-NEXT:  | |-FieldDecl 0x{{.+}}  col:9 i 'int'
-// CHECK-NEXT:  | `-CXXConstructorDecl 0x{{.+}}  col:30 implicit constexpr TestClassTemplate 'void (const TestClassTemplate &)' inline default trivial noexcept-unevaluated 0x{{.+}}
-// CHECK-NEXT:  |   `-ParmVarDecl 0x{{.+}}  col:30 'const TestClassTemplate &'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  |-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-// CHECK-NEXT:  `-ClassTemplateSpecialization 0x{{.+}} 'TestClassTemplate'
-
-// CHECK:   ClassTemplateSpecializationDecl 0x{{.+}} <{{.+}}:[[@LINE-67]]:3, line:[[@LINE-65]]:3> line:[[@LINE-67]]:20 class TestClassTemplate definition
-// CHECK-NEXT:  |-DefinitionData pass_in_registers standard_layout trivially_copyable trivial literal
-// CHECK-NEXT:  | |-DefaultConstructor exists trivial needs_implicit
-// CHECK-NEXT:  | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | |-MoveConstructor exists simple trivial needs_implicit
-// CHECK-NEXT:  | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:  | |-MoveAssignment exists simple trivial needs_implicit
-// CHECK-NEXT:  | `-Destructor simple irrelevant trivial needs_implicit
-// CHECK-NEXT:  |-TemplateArgument type 'testClassTemplateDecl::B'
-// CHECK-NEXT:  | `-RecordType 0{{.+}} 'testClassTemplateDecl::B'
-// CHECK-NEXT:  |   `-CXXRecord 0x{{.+}} 'B'
-// CHECK-NEXT:  |-CXXRecordDecl 0x{{.+}}  col:20 implicit class TestClassTemplate
-// CHECK-NEXT:  `-FieldDecl 0x{{.+}}  col:9 j 'int'
-
-// CHECK:   ClassTemplateSpecializationDecl 0x{{.+}} <{{.+}}:{{.*}}:3, col:44> col:25 class TestClassTemplate definition
-// CHECK-NEXT:  |-DefinitionData standard_layout has_user_declared_ctor can_const_default_init
-// CHECK-NEXT:  | 

[PATCH] D158055: [clang][AST] Added some missing setter methods

2023-08-17 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

Yes, I have a need for these setters :) but I cannot decide if the LLVM project 
in general or other people could profit from it.

I am working on a C++-to-C transpiler based on clang. Other clang-based tool 
typically modify the intput file based on FileLocation information. In 
contrast, I follow a constructive approach with AST print. The transpiler is 
organized in many small passes that transform the clang AST until at the end I 
can output the C code via AST print. Some notable passes are

- Remove unused AST decls (simplifies AST for non-trivial input)
- Resolve templates (is also useful standalone to remove templates from a C++ 
program)
- Resolve namespaces
- Move nested records
- Convert methods to functions
- etc.

For transforming the AST, I often need to replace Types and regenerate the 
corresponding TypeLoc. I tried for over one year to recreate AST nodes when a 
setter methods that was missing but that caused a lot of work and instabilities 
for maintaining cross references. For that reason, I now insert a new setter 
method when needed and until now surprising less setter methods are missing.

For me it takes 5-10 min per version upgrade to port the changes, so it is not 
a big deal for me if you refuse them. I have some other AST modification in 
place for removing templates information but nothing complex...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158055

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158055: [clang][AST] Added some missing setter methods

2023-08-16 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

I added some missing (simple) setter methods to Decl and Expr classes. I did 
not comment them since typically simple setter methods are uncommented.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158055

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158055: [clang][AST] Added some missing setter methods

2023-08-16 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158055

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/Expr.h


Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1199,6 +1199,8 @@
   /// place.
   Expr *getSourceExpr() const { return SourceExpr; }
 
+  void setSourceExpr(Expr *E) { SourceExpr = E; }
+
   void setIsUnique(bool V) {
 assert((!V || SourceExpr) &&
"unique OVEs are expected to have source expressions");
@@ -1332,6 +1334,11 @@
 return *getTrailingObjects();
   }
 
+  void setQualifierLoc(NestedNameSpecifierLoc QL) {
+assert(hasQualifier());
+*getTrailingObjects() = QL;
+  }
+
   /// If the name was qualified, retrieves the nested-name-specifier
   /// that precedes the name. Otherwise, returns NULL.
   NestedNameSpecifier *getQualifier() const {
@@ -1354,6 +1361,11 @@
 return hasFoundDecl() ? *getTrailingObjects() : D;
   }
 
+  void setFoundDecl(NamedDecl *ND) {
+assert(hasFoundDecl());
+*getTrailingObjects() = ND;
+  }
+
   bool hasTemplateKWAndArgsInfo() const {
 return DeclRefExprBits.HasTemplateKWAndArgsInfo;
   }
@@ -3296,6 +3308,11 @@
 return getTrailingObjects()->QualifierLoc;
   }
 
+  void setQualifierLoc(NestedNameSpecifierLoc QL) {
+assert(hasQualifierOrFoundDecl());
+getTrailingObjects()->QualifierLoc = QL;
+  }
+
   /// If the member name was qualified, retrieves the
   /// nested-name-specifier that precedes the member name. Otherwise, returns
   /// NULL.
@@ -3370,6 +3387,10 @@
MemberLoc, MemberDNLoc);
   }
 
+  void setMemberDeclNameLoc(const DeclarationNameLoc ) {
+MemberDNLoc = Loc;
+  }
+
   SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; }
 
   bool isArrow() const { return MemberExprBits.IsArrow; }
Index: clang/include/clang/AST/Decl.h
===
--- clang/include/clang/AST/Decl.h
+++ clang/include/clang/AST/Decl.h
@@ -2118,6 +2118,8 @@
 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
   }
 
+  void setDeclNameLoc(const DeclarationNameLoc ) { DNLoc = Loc; }
+
   void getNameForDiagnostic(raw_ostream , const PrintingPolicy ,
 bool Qualified) const override;
 
@@ -3046,6 +3048,8 @@
   /// Determines whether this field is mutable (C++ only).
   bool isMutable() const { return Mutable; }
 
+  void setMutable(bool Mutable) { this->Mutable = Mutable; }
+
   /// Determines whether this field is a bitfield.
   bool isBitField() const { return BitField; }
 


Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -1199,6 +1199,8 @@
   /// place.
   Expr *getSourceExpr() const { return SourceExpr; }
 
+  void setSourceExpr(Expr *E) { SourceExpr = E; }
+
   void setIsUnique(bool V) {
 assert((!V || SourceExpr) &&
"unique OVEs are expected to have source expressions");
@@ -1332,6 +1334,11 @@
 return *getTrailingObjects();
   }
 
+  void setQualifierLoc(NestedNameSpecifierLoc QL) {
+assert(hasQualifier());
+*getTrailingObjects() = QL;
+  }
+
   /// If the name was qualified, retrieves the nested-name-specifier
   /// that precedes the name. Otherwise, returns NULL.
   NestedNameSpecifier *getQualifier() const {
@@ -1354,6 +1361,11 @@
 return hasFoundDecl() ? *getTrailingObjects() : D;
   }
 
+  void setFoundDecl(NamedDecl *ND) {
+assert(hasFoundDecl());
+*getTrailingObjects() = ND;
+  }
+
   bool hasTemplateKWAndArgsInfo() const {
 return DeclRefExprBits.HasTemplateKWAndArgsInfo;
   }
@@ -3296,6 +3308,11 @@
 return getTrailingObjects()->QualifierLoc;
   }
 
+  void setQualifierLoc(NestedNameSpecifierLoc QL) {
+assert(hasQualifierOrFoundDecl());
+getTrailingObjects()->QualifierLoc = QL;
+  }
+
   /// If the member name was qualified, retrieves the
   /// nested-name-specifier that precedes the member name. Otherwise, returns
   /// NULL.
@@ -3370,6 +3387,10 @@
MemberLoc, MemberDNLoc);
   }
 
+  void setMemberDeclNameLoc(const DeclarationNameLoc ) {
+MemberDNLoc = Loc;
+  }
+
   SourceLocation getOperatorLoc() const { return MemberExprBits.OperatorLoc; }
 
   bool isArrow() const { return MemberExprBits.IsArrow; }
Index: clang/include/clang/AST/Decl.h
===
--- clang/include/clang/AST/Decl.h
+++ clang/include/clang/AST/Decl.h
@@ -2118,6 +2118,8 @@
 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
   }
 
+  void setDeclNameLoc(const 

[PATCH] D158047: [clang][ASTImporter] Add import of 'BitIntType'

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

I think the ASTImporter class has in general a completion problem. What do you 
think about rewriting it that any missing Visit* function for Type, Decl and 
Stmt produces an compiler error?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158047

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158047: [clang][ASTImporter] Add import of 'BitIntType'

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158047

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -583,6 +583,13 @@
   functionDecl(hasDescendant(typedefDecl(has(atomicType());
 }
 
+TEST_P(ImportType, ImportBitIntType) {
+  MatchVerifier Verifier;
+  testImport("void declToImport() { typedef _BitInt(10) bit_int; }", 
Lang_CXX11,
+ "", Lang_CXX11, Verifier,
+ functionDecl(hasDescendant(typedefDecl(has(bitIntType());
+}
+
 TEST_P(ImportType, ImportUsingType) {
   MatchVerifier Verifier;
   testImport("struct C {};"
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -419,6 +419,7 @@
 ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T);
 ExpectedType VisitObjCObjectType(const ObjCObjectType *T);
 ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T);
+ExpectedType VisitBitIntType(const BitIntType *T);
 
 // Importing declarations
 Error ImportDeclParts(NamedDecl *D, DeclarationName , NamedDecl *,
@@ -1701,6 +1702,11 @@
   return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
 }
 
+ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
+  return Importer.getToContext().getBitIntType(T->isUnsigned(),
+   T->getNumBits());
+}
+
 //
 // Import Declarations
 //
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7025,6 +7025,16 @@
 AST_TYPELOC_TRAVERSE_MATCHER_DECL(hasValueType, getValue,
   AST_POLYMORPHIC_SUPPORTED_TYPES(AtomicType));
 
+/// Matches bitint types.
+///
+/// Given
+/// \code
+///   _BitInt(10) i;
+/// \endcode
+/// bitIntType()
+///   matches "_BitInt(10) i"
+extern const AstTypeMatcher bitIntType;
+
 /// Matches types nodes representing C++11 auto types.
 ///
 /// Given:


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -583,6 +583,13 @@
   functionDecl(hasDescendant(typedefDecl(has(atomicType());
 }
 
+TEST_P(ImportType, ImportBitIntType) {
+  MatchVerifier Verifier;
+  testImport("void declToImport() { typedef _BitInt(10) bit_int; }", Lang_CXX11,
+ "", Lang_CXX11, Verifier,
+ functionDecl(hasDescendant(typedefDecl(has(bitIntType());
+}
+
 TEST_P(ImportType, ImportUsingType) {
   MatchVerifier Verifier;
   testImport("struct C {};"
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -419,6 +419,7 @@
 ExpectedType VisitObjCInterfaceType(const ObjCInterfaceType *T);
 ExpectedType VisitObjCObjectType(const ObjCObjectType *T);
 ExpectedType VisitObjCObjectPointerType(const ObjCObjectPointerType *T);
+ExpectedType VisitBitIntType(const BitIntType *T);
 
 // Importing declarations
 Error ImportDeclParts(NamedDecl *D, DeclarationName , NamedDecl *,
@@ -1701,6 +1702,11 @@
   return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
 }
 
+ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
+  return Importer.getToContext().getBitIntType(T->isUnsigned(),
+   T->getNumBits());
+}
+
 //
 // Import Declarations
 //
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7025,6 +7025,16 @@
 AST_TYPELOC_TRAVERSE_MATCHER_DECL(hasValueType, getValue,
   

[PATCH] D157681: [clang][AST] TextNodeDumper learned to dump qualifiers (NestedNameSpecifier)

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcad3130a23da: [clang][AST] TextNodeDumper learned to dump 
qualifiers (NestedNameSpecifier) (authored by strimo378).

Changed prior to commit:
  https://reviews.llvm.org/D157681?vs=549273=550387#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157681

Files:
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
  clang/test/AST/ast-dump-using.cpp

Index: clang/test/AST/ast-dump-using.cpp
===
--- clang/test/AST/ast-dump-using.cpp
+++ clang/test/AST/ast-dump-using.cpp
@@ -6,6 +6,7 @@
 namespace b {
 using a::S;
 // CHECK:  UsingDecl {{.*}} a::S
+// CHECK-NEXT: | `-NestedNameSpecifier NamespaceNamespace {{.*}} 'a'
 // CHECK-NEXT: UsingShadowDecl {{.*}} implicit CXXRecord {{.*}} 'S'
 // CHECK-NEXT: `-RecordType {{.*}} 'a::S'
 typedef S f; // to dump the introduced type
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
===
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
@@ -114,10 +114,12 @@
 // CHECK-NEXT: |   | |-CallExpr [[ADDR_47:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   | | `-ImplicitCastExpr [[ADDR_48:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: |   | |   `-DeclRefExpr [[ADDR_49:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_1]] 'foo' 'int ({{.*}})'
+// CHECK-NEXT: |   | |   `-NestedNameSpecifier NamespaceNamespace [[ADDR_0]] 'A'
 // CHECK-NEXT: |   | `-PseudoObjectExpr [[ADDR_50:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   |   |-CallExpr [[ADDR_51:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   |   | `-ImplicitCastExpr [[ADDR_52:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: |   |   |   `-DeclRefExpr [[ADDR_53:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_6]] 'bar' 'int ({{.*}})'
+// CHECK-NEXT: |   |   |   `-NestedNameSpecifier NamespaceNamespace [[ADDR_31]] 'B'
 // CHECK-NEXT: |   |   `-CallExpr [[ADDR_54:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   | `-ImplicitCastExpr [[ADDR_55:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: |   |   `-DeclRefExpr [[ADDR_11]]  'int ({{.*}})' Function [[ADDR_12]] 'bar[implementation={vendor(llvm)}]' 'int ({{.*}})'
@@ -125,6 +127,7 @@
 // CHECK-NEXT: | |-CallExpr [[ADDR_57:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: | | `-ImplicitCastExpr [[ADDR_58:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_59:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_14]] 'baz' 'int ({{.*}})'
+// CHECK-NEXT: | |   `-NestedNameSpecifier NamespaceNamespace [[ADDR_13]] 'C'
 // CHECK-NEXT: | `-CallExpr [[ADDR_60:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   `-ImplicitCastExpr [[ADDR_61:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: | `-DeclRefExpr [[ADDR_19]]  'int ({{.*}})' Function [[ADDR_20]] 'baz[implementation={vendor(llvm)}]' 'int ({{.*}})'
Index: clang/test/AST/ast-dump-expr.cpp
===
--- clang/test/AST/ast-dump-expr.cpp
+++ clang/test/AST/ast-dump-expr.cpp
@@ -224,6 +224,8 @@
   p->::S::~S();
   // CHECK: CXXMemberCallExpr 0x{{[^ ]*}}  'void'
   // CHECK-NEXT: MemberExpr 0x{{[^ ]*}}  '' ->~S 0x{{[^ ]*}}
+  // CHECK-NEXT: NestedNameSpecifier TypeSpec 'S'
+  // CHECK-NEXT: NestedNameSpecifier Global
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'S *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'S *'
 
@@ -231,6 +233,7 @@
   r->template U::~U();
   // CHECK: CXXMemberCallExpr 0x{{[^ ]*}}  'void'
   // CHECK-NEXT: MemberExpr 0x{{[^ ]*}}  '' ->~U 0x{{[^ ]*}}
+  // CHECK-NEXT: NestedNameSpecifier TypeSpecWithTemplate 'U':'U'
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'U *' lvalue ParmVar 0x{{[^ ]*}} 'r' 'U *'
 
Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -614,24 +614,27 @@
   // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}}  col:25 referenced typename depth 0 index 0 T
   // CHECK-NEXT: |-VarDecl 0x{{.+}}  col:43 TestVarTemplate 'const T' static
   // CHECK-NEXT: |-VarTemplateSpecializationDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}}  col:14 referenced TestVarTemplate 'const int':'const int' implicit_instantiation cinit
+  // CHECK-NEXT: | |-NestedNameSpecifier TypeSpec 'testCanonicalTemplate::S'
   // CHECK-NEXT: | |-TemplateArgument type 'int'
   // CHECK-NEXT: | | `-BuiltinType 0x{{.+}} 'int'
   // 

[PATCH] D157687: [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeda9d27a91e6: [clang][AST] TextNodeDumper learned to dump 
NRVO candidates of return stmts (authored by strimo378).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157687

Files:
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp


Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -25,12 +25,17 @@
 
 namespace testVarDeclNRVO {
   class A { };
-  A foo() {
+  A TestFuncNRVO() {
 A TestVarDeclNRVO;
 return TestVarDeclNRVO;
   }
 }
-// CHECK: VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo
+// CHECK:  FunctionDecl{{.*}} TestFuncNRVO 'A ()'
+// CHECK-NEXT: `-CompoundStmt
+// CHECK-NEXT: |-DeclStmt
+// CHECK-NEXT: | `-VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo 
callinit
+// CHECK-NEXT: |   `-CXXConstructExpr
+// CHECK-NEXT: `-ReturnStmt{{.*}} nrvo_candidate(Var {{.*}} 'TestVarDeclNRVO' 
'A':'testVarDeclNRVO::A')
 
 void testParmVarDeclInit(int TestParmVarDeclInit = 0);
 // CHECK:  ParmVarDecl{{.*}} TestParmVarDeclInit 'int'
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1015,6 +1015,14 @@
 OS << " gnu_range";
 }
 
+void clang::TextNodeDumper::VisitReturnStmt(const ReturnStmt *Node) {
+  if (const VarDecl *Cand = Node->getNRVOCandidate()) {
+OS << " nrvo_candidate(";
+dumpBareDeclRef(Cand);
+OS << ")";
+  }
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
Index: clang/include/clang/AST/TextNodeDumper.h
===
--- clang/include/clang/AST/TextNodeDumper.h
+++ clang/include/clang/AST/TextNodeDumper.h
@@ -247,6 +247,7 @@
   void VisitLabelStmt(const LabelStmt *Node);
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
+  void VisitReturnStmt(const ReturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);


Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -25,12 +25,17 @@
 
 namespace testVarDeclNRVO {
   class A { };
-  A foo() {
+  A TestFuncNRVO() {
 A TestVarDeclNRVO;
 return TestVarDeclNRVO;
   }
 }
-// CHECK: VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo
+// CHECK:  FunctionDecl{{.*}} TestFuncNRVO 'A ()'
+// CHECK-NEXT: `-CompoundStmt
+// CHECK-NEXT: |-DeclStmt
+// CHECK-NEXT: | `-VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo callinit
+// CHECK-NEXT: |   `-CXXConstructExpr
+// CHECK-NEXT: `-ReturnStmt{{.*}} nrvo_candidate(Var {{.*}} 'TestVarDeclNRVO' 'A':'testVarDeclNRVO::A')
 
 void testParmVarDeclInit(int TestParmVarDeclInit = 0);
 // CHECK:  ParmVarDecl{{.*}} TestParmVarDeclInit 'int'
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1015,6 +1015,14 @@
 OS << " gnu_range";
 }
 
+void clang::TextNodeDumper::VisitReturnStmt(const ReturnStmt *Node) {
+  if (const VarDecl *Cand = Node->getNRVOCandidate()) {
+OS << " nrvo_candidate(";
+dumpBareDeclRef(Cand);
+OS << ")";
+  }
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
Index: clang/include/clang/AST/TextNodeDumper.h
===
--- clang/include/clang/AST/TextNodeDumper.h
+++ clang/include/clang/AST/TextNodeDumper.h
@@ -247,6 +247,7 @@
   void VisitLabelStmt(const LabelStmt *Node);
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
+  void VisitReturnStmt(const ReturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157705: [clang][AST] TextNodeDumper learned to output template specialization kind

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3bfafc4f2287: [clang][AST] TextNodeDumper learned to output 
template specialization kind (authored by strimo378).

Changed prior to commit:
  https://reviews.llvm.org/D157705?vs=549346=550354#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157705

Files:
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/HLSL/this-reference-template.hlsl
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/SemaCXX/lambda-conversion-op-cc.cpp
  clang/test/SemaOpenCLCXX/address-space-deduction.clcpp

Index: clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
===
--- clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
+++ clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
@@ -6,7 +6,7 @@
 constexpr int foo = 0;
 
 //CHECK: |-VarDecl {{.*}} foo1 'T' cinit
-//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' cinit
+//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' implicit_instantiation cinit
 template 
 T foo1 = 0;
 
Index: clang/test/SemaCXX/lambda-conversion-op-cc.cpp
===
--- clang/test/SemaCXX/lambda-conversion-op-cc.cpp
+++ clang/test/SemaCXX/lambda-conversion-op-cc.cpp
@@ -67,11 +67,11 @@
   //
   // CHECK: FunctionTemplateDecl {{.*}} operator()
   // LIN64: CXXMethodDecl {{.*}} operator() 'auto (auto) const' inline
-  // LIN64: CXXMethodDecl {{.*}} operator() 'void (char) const' inline
-  // LIN64: CXXMethodDecl {{.*}} operator() 'void (int) const' inline
+  // LIN64: CXXMethodDecl {{.*}} operator() 'void (char) const' implicit_instantiation inline
+  // LIN64: CXXMethodDecl {{.*}} operator() 'void (int) const' implicit_instantiation inline
   // WIN32: CXXMethodDecl {{.*}} operator() 'auto (auto) __attribute__((thiscall)) const' inline
-  // WIN32: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((thiscall)) const' inline
-  // WIN32: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((thiscall)) const' inline
+  // WIN32: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((thiscall)) const' implicit_instantiation inline
+  // WIN32: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((thiscall)) const' implicit_instantiation inline
   //
   // NODEF: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0)
   // VECDEF: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall))
@@ -108,8 +108,8 @@
   // CHECK: LambdaExpr
   // CHECK: FunctionTemplateDecl {{.*}} operator()
   // CHECK: CXXMethodDecl {{.*}} operator() 'auto (auto) __attribute__((vectorcall)) const' inline
-  // CHECK: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((vectorcall)) const' inline
-  // CHECK: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((vectorcall)) const' inline
+  // CHECK: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((vectorcall)) const' implicit_instantiation inline
+  // CHECK: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((vectorcall)) const' implicit_instantiation inline
   // CHECK: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall))
   // LIN64: CXXConversionDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall)) 'auto (*() const noexcept)(auto) __attribute__((vectorcall))'
   // LIN64: CXXConversionDecl {{.*}} operator auto (*)(char) __attribute__((vectorcall)) 'void (*() const noexcept)(char) __attribute__((vectorcall))'
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
===
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -184,7 +184,7 @@
 // CHECK-NEXT: | |   `-ReturnStmt [[ADDR_39:0x[a-z0-9]*]] 
 // CHECK-NEXT: | | `-CXXStaticCastExpr [[ADDR_40:0x[a-z0-9]*]]  '_Up':'typename remove_reference<_Tp>::type' xvalue static_cast<_Up &&> 
 // CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_41:0x[a-z0-9]*]]  '_Tp' {{.*}}ParmVar [[ADDR_34]] '__t' '_Tp &&'
-// CHECK-NEXT: | |-FunctionDecl [[ADDR_42:0x[a-z0-9]*]]  line:11:1 used move 'typename remove_reference::type &&(float &)' inline
+// CHECK-NEXT: | |-FunctionDecl [[ADDR_42:0x[a-z0-9]*]]  line:11:1 used move 'typename remove_reference::type &&(float &)' implicit_instantiation inline
 // CHECK-NEXT: | | |-TemplateArgument type 'float &'
 // CHECK-NEXT: | | | `-LValueReferenceType [[ADDR_7]] 'float &'
 // CHECK-NEXT: | | |   `-BuiltinType [[ADDR_8]] 'float'
@@ -201,7 +201,7 @@
 // CHECK-NEXT: | |   `-ReturnStmt 

[PATCH] D157687: [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

@aaron.ballman Alright ... I managed to extend an existing test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157687

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157687: [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts

2023-08-15 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 550319.
strimo378 added a comment.

Added test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157687

Files:
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp


Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -25,12 +25,17 @@
 
 namespace testVarDeclNRVO {
   class A { };
-  A foo() {
+  A TestFuncNRVO() {
 A TestVarDeclNRVO;
 return TestVarDeclNRVO;
   }
 }
-// CHECK: VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo
+// CHECK:  FunctionDecl{{.*}} TestFuncNRVO 'A ()'
+// CHECK-NEXT: `-CompoundStmt
+// CHECK-NEXT: |-DeclStmt
+// CHECK-NEXT: | `-VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo 
callinit
+// CHECK-NEXT: |   `-CXXConstructExpr
+// CHECK-NEXT: `-ReturnStmt{{.*}} nrvo_candidate(Var {{.*}} 'TestVarDeclNRVO' 
'A':'testVarDeclNRVO::A')
 
 void testParmVarDeclInit(int TestParmVarDeclInit = 0);
 // CHECK:  ParmVarDecl{{.*}} TestParmVarDeclInit 'int'
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -995,6 +995,14 @@
 OS << " gnu_range";
 }
 
+void clang::TextNodeDumper::VisitReturnStmt(const ReturnStmt *Node) {
+  if (const VarDecl *Cand = Node->getNRVOCandidate()) {
+OS << " nrvo_candidate(";
+dumpBareDeclRef(Cand);
+OS << ")";
+  }
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
Index: clang/include/clang/AST/TextNodeDumper.h
===
--- clang/include/clang/AST/TextNodeDumper.h
+++ clang/include/clang/AST/TextNodeDumper.h
@@ -246,6 +246,7 @@
   void VisitLabelStmt(const LabelStmt *Node);
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
+  void VisitReturnStmt(const ReturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);


Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -25,12 +25,17 @@
 
 namespace testVarDeclNRVO {
   class A { };
-  A foo() {
+  A TestFuncNRVO() {
 A TestVarDeclNRVO;
 return TestVarDeclNRVO;
   }
 }
-// CHECK: VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo
+// CHECK:  FunctionDecl{{.*}} TestFuncNRVO 'A ()'
+// CHECK-NEXT: `-CompoundStmt
+// CHECK-NEXT: |-DeclStmt
+// CHECK-NEXT: | `-VarDecl{{.*}} TestVarDeclNRVO 'A':'testVarDeclNRVO::A' nrvo callinit
+// CHECK-NEXT: |   `-CXXConstructExpr
+// CHECK-NEXT: `-ReturnStmt{{.*}} nrvo_candidate(Var {{.*}} 'TestVarDeclNRVO' 'A':'testVarDeclNRVO::A')
 
 void testParmVarDeclInit(int TestParmVarDeclInit = 0);
 // CHECK:  ParmVarDecl{{.*}} TestParmVarDeclInit 'int'
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -995,6 +995,14 @@
 OS << " gnu_range";
 }
 
+void clang::TextNodeDumper::VisitReturnStmt(const ReturnStmt *Node) {
+  if (const VarDecl *Cand = Node->getNRVOCandidate()) {
+OS << " nrvo_candidate(";
+dumpBareDeclRef(Cand);
+OS << ")";
+  }
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
Index: clang/include/clang/AST/TextNodeDumper.h
===
--- clang/include/clang/AST/TextNodeDumper.h
+++ clang/include/clang/AST/TextNodeDumper.h
@@ -246,6 +246,7 @@
   void VisitLabelStmt(const LabelStmt *Node);
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
+  void VisitReturnStmt(const ReturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141714: Fix ast print of variables with attributes

2023-08-11 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

@aaron.ballman I had today a teams meeting with @giulianobelinassi and we 
discussed both patches as well as that we want to work together in improving 
AST print. Both patches are fine for us since they improve the attribute 
printing. The features of the respective other patch can be easily integrated 
with minimal changes in a subsequent smaller patch. We further think that there 
are a lot more cases of attributes that we need to consider that we do not know 
atm.

I think we should go one with patch that has the higher probability to get 
landed soon. Since this branch had a lot more reviews, I suggest we go further 
with this patch. I further suggest to keep it simple and remove the tblgen part 
and add it in an subsequent patch once we know all cases and requirements. What 
do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141714

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157705: [clang][AST] TestNodeDumper learned to output template specialization kind

2023-08-11 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157705

Files:
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/HLSL/this-reference-template.hlsl
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/SemaCXX/lambda-conversion-op-cc.cpp
  clang/test/SemaOpenCLCXX/address-space-deduction.clcpp

Index: clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
===
--- clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
+++ clang/test/SemaOpenCLCXX/address-space-deduction.clcpp
@@ -6,7 +6,7 @@
 constexpr int foo = 0;
 
 //CHECK: |-VarDecl {{.*}} foo1 'T' cinit
-//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' cinit
+//CHECK: `-VarTemplateSpecializationDecl {{.*}} used foo1 '__global long':'__global long' implicit_instantiation cinit
 template 
 T foo1 = 0;
 
Index: clang/test/SemaCXX/lambda-conversion-op-cc.cpp
===
--- clang/test/SemaCXX/lambda-conversion-op-cc.cpp
+++ clang/test/SemaCXX/lambda-conversion-op-cc.cpp
@@ -67,11 +67,11 @@
   //
   // CHECK: FunctionTemplateDecl {{.*}} operator()
   // LIN64: CXXMethodDecl {{.*}} operator() 'auto (auto) const' inline
-  // LIN64: CXXMethodDecl {{.*}} operator() 'void (char) const' inline
-  // LIN64: CXXMethodDecl {{.*}} operator() 'void (int) const' inline
+  // LIN64: CXXMethodDecl {{.*}} operator() 'void (char) const' implicit_instantiation inline
+  // LIN64: CXXMethodDecl {{.*}} operator() 'void (int) const' implicit_instantiation inline
   // WIN32: CXXMethodDecl {{.*}} operator() 'auto (auto) __attribute__((thiscall)) const' inline
-  // WIN32: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((thiscall)) const' inline
-  // WIN32: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((thiscall)) const' inline
+  // WIN32: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((thiscall)) const' implicit_instantiation inline
+  // WIN32: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((thiscall)) const' implicit_instantiation inline
   //
   // NODEF: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0)
   // VECDEF: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall))
@@ -108,8 +108,8 @@
   // CHECK: LambdaExpr
   // CHECK: FunctionTemplateDecl {{.*}} operator()
   // CHECK: CXXMethodDecl {{.*}} operator() 'auto (auto) __attribute__((vectorcall)) const' inline
-  // CHECK: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((vectorcall)) const' inline
-  // CHECK: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((vectorcall)) const' inline
+  // CHECK: CXXMethodDecl {{.*}} operator() 'void (char) __attribute__((vectorcall)) const' implicit_instantiation inline
+  // CHECK: CXXMethodDecl {{.*}} operator() 'void (int) __attribute__((vectorcall)) const' implicit_instantiation inline
   // CHECK: FunctionTemplateDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall))
   // LIN64: CXXConversionDecl {{.*}} operator auto (*)(type-parameter-0-0) __attribute__((vectorcall)) 'auto (*() const noexcept)(auto) __attribute__((vectorcall))'
   // LIN64: CXXConversionDecl {{.*}} operator auto (*)(char) __attribute__((vectorcall)) 'void (*() const noexcept)(char) __attribute__((vectorcall))'
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
===
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
@@ -184,7 +184,7 @@
 // CHECK-NEXT: | |   `-ReturnStmt [[ADDR_39:0x[a-z0-9]*]] 
 // CHECK-NEXT: | | `-CXXStaticCastExpr [[ADDR_40:0x[a-z0-9]*]]  '_Up':'typename remove_reference<_Tp>::type' xvalue static_cast<_Up &&> 
 // CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_41:0x[a-z0-9]*]]  '_Tp' {{.*}}ParmVar [[ADDR_34]] '__t' '_Tp &&'
-// CHECK-NEXT: | |-FunctionDecl [[ADDR_42:0x[a-z0-9]*]]  line:11:1 used move 'typename remove_reference::type &&(float &)' inline
+// CHECK-NEXT: | |-FunctionDecl [[ADDR_42:0x[a-z0-9]*]]  line:11:1 used move 'typename remove_reference::type &&(float &)' implicit_instantiation inline
 // CHECK-NEXT: | | |-TemplateArgument type 'float &'
 // CHECK-NEXT: | | | `-LValueReferenceType [[ADDR_7]] 'float &'
 // CHECK-NEXT: | | |   `-BuiltinType [[ADDR_8]] 'float'
@@ -201,7 +201,7 @@
 // CHECK-NEXT: | |   `-ReturnStmt [[ADDR_49:0x[a-z0-9]*]] 
 // CHECK-NEXT: | | `-CXXStaticCastExpr [[ADDR_50:0x[a-z0-9]*]]  '_Up':'float' xvalue static_cast<_Up &&> 
 // 

[PATCH] D157687: [clang][AST] TextNodeDumper learned to dump NRVO candidates of return stmts

2023-08-11 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157687

Files:
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/TextNodeDumper.cpp


Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -995,6 +995,14 @@
 OS << " gnu_range";
 }
 
+void clang::TextNodeDumper::VisitReturnStmt(const ReturnStmt *Node) {
+  if (const VarDecl *Cand = Node->getNRVOCandidate()) {
+OS << " nrvo_candidate(";
+dumpBareDeclRef(Cand);
+OS << ")";
+  }
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
Index: clang/include/clang/AST/TextNodeDumper.h
===
--- clang/include/clang/AST/TextNodeDumper.h
+++ clang/include/clang/AST/TextNodeDumper.h
@@ -246,6 +246,7 @@
   void VisitLabelStmt(const LabelStmt *Node);
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
+  void VisitReturnStmt(const ReturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);


Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -995,6 +995,14 @@
 OS << " gnu_range";
 }
 
+void clang::TextNodeDumper::VisitReturnStmt(const ReturnStmt *Node) {
+  if (const VarDecl *Cand = Node->getNRVOCandidate()) {
+OS << " nrvo_candidate(";
+dumpBareDeclRef(Cand);
+OS << ")";
+  }
+}
+
 void TextNodeDumper::VisitConstantExpr(const ConstantExpr *Node) {
   if (Node->hasAPValueResult())
 AddChild("value",
Index: clang/include/clang/AST/TextNodeDumper.h
===
--- clang/include/clang/AST/TextNodeDumper.h
+++ clang/include/clang/AST/TextNodeDumper.h
@@ -246,6 +246,7 @@
   void VisitLabelStmt(const LabelStmt *Node);
   void VisitGotoStmt(const GotoStmt *Node);
   void VisitCaseStmt(const CaseStmt *Node);
+  void VisitReturnStmt(const ReturnStmt *Node);
   void VisitCompoundStmt(const CompoundStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157681: [clang][AST] TextNodeDumper learned to dump qualifiers (NestedNameSpecifier)

2023-08-11 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157681

Files:
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/AST/ast-dump-expr.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
  clang/test/AST/ast-dump-using.cpp

Index: clang/test/AST/ast-dump-using.cpp
===
--- clang/test/AST/ast-dump-using.cpp
+++ clang/test/AST/ast-dump-using.cpp
@@ -6,6 +6,7 @@
 namespace b {
 using a::S;
 // CHECK:  UsingDecl {{.*}} a::S
+// CHECK-NEXT: | `-NestedNameSpecifier NamespaceNamespace {{.*}} 'a'
 // CHECK-NEXT: UsingShadowDecl {{.*}} implicit CXXRecord {{.*}} 'S'
 // CHECK-NEXT: `-RecordType {{.*}} 'a::S'
 typedef S f; // to dump the introduced type
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
===
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_namespace_1.cpp
@@ -114,10 +114,12 @@
 // CHECK-NEXT: |   | |-CallExpr [[ADDR_47:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   | | `-ImplicitCastExpr [[ADDR_48:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: |   | |   `-DeclRefExpr [[ADDR_49:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_1]] 'foo' 'int ({{.*}})'
+// CHECK-NEXT: |   | |   `-NestedNameSpecifier NamespaceNamespace [[ADDR_0]] 'A'
 // CHECK-NEXT: |   | `-PseudoObjectExpr [[ADDR_50:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   |   |-CallExpr [[ADDR_51:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   |   | `-ImplicitCastExpr [[ADDR_52:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: |   |   |   `-DeclRefExpr [[ADDR_53:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_6]] 'bar' 'int ({{.*}})'
+// CHECK-NEXT: |   |   |   `-NestedNameSpecifier NamespaceNamespace [[ADDR_31]] 'B'
 // CHECK-NEXT: |   |   `-CallExpr [[ADDR_54:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   | `-ImplicitCastExpr [[ADDR_55:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: |   |   `-DeclRefExpr [[ADDR_11]]  'int ({{.*}})' Function [[ADDR_12]] 'bar[implementation={vendor(llvm)}]' 'int ({{.*}})'
@@ -125,6 +127,7 @@
 // CHECK-NEXT: | |-CallExpr [[ADDR_57:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: | | `-ImplicitCastExpr [[ADDR_58:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: | |   `-DeclRefExpr [[ADDR_59:0x[a-z0-9]*]]  'int ({{.*}})' {{.*}}Function [[ADDR_14]] 'baz' 'int ({{.*}})'
+// CHECK-NEXT: | |   `-NestedNameSpecifier NamespaceNamespace [[ADDR_13]] 'C'
 // CHECK-NEXT: | `-CallExpr [[ADDR_60:0x[a-z0-9]*]]  'int'
 // CHECK-NEXT: |   `-ImplicitCastExpr [[ADDR_61:0x[a-z0-9]*]]  'int (*)({{.*}})' 
 // CHECK-NEXT: | `-DeclRefExpr [[ADDR_19]]  'int ({{.*}})' Function [[ADDR_20]] 'baz[implementation={vendor(llvm)}]' 'int ({{.*}})'
Index: clang/test/AST/ast-dump-expr.cpp
===
--- clang/test/AST/ast-dump-expr.cpp
+++ clang/test/AST/ast-dump-expr.cpp
@@ -224,6 +224,8 @@
   p->::S::~S();
   // CHECK: CXXMemberCallExpr 0x{{[^ ]*}}  'void'
   // CHECK-NEXT: MemberExpr 0x{{[^ ]*}}  '' ->~S 0x{{[^ ]*}}
+  // CHECK-NEXT: NestedNameSpecifier TypeSpec 'S'
+  // CHECK-NEXT: NestedNameSpecifier Global
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'S *' lvalue ParmVar 0x{{[^ ]*}} 'p' 'S *'
 
@@ -231,6 +233,7 @@
   r->template U::~U();
   // CHECK: CXXMemberCallExpr 0x{{[^ ]*}}  'void'
   // CHECK-NEXT: MemberExpr 0x{{[^ ]*}}  '' ->~U 0x{{[^ ]*}}
+  // CHECK-NEXT: NestedNameSpecifier TypeSpecWithTemplate 'U':'U'
   // CHECK-NEXT: ImplicitCastExpr
   // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'U *' lvalue ParmVar 0x{{[^ ]*}} 'r' 'U *'
 
Index: clang/test/AST/ast-dump-decl.cpp
===
--- clang/test/AST/ast-dump-decl.cpp
+++ clang/test/AST/ast-dump-decl.cpp
@@ -609,24 +609,27 @@
   // CHECK-NEXT: |-TemplateTypeParmDecl 0x{{.+}}  col:25 referenced typename depth 0 index 0 T
   // CHECK-NEXT: |-VarDecl 0x{{.+}}  col:43 TestVarTemplate 'const T' static
   // CHECK-NEXT: |-VarTemplateSpecializationDecl 0x{{.+}} parent 0x{{.+}} prev 0x{{.+}}  col:14 referenced TestVarTemplate 'const int':'const int' cinit
+  // CHECK-NEXT: | |-NestedNameSpecifier TypeSpec 'testCanonicalTemplate::S'
   // CHECK-NEXT: | |-TemplateArgument type 'int'
   // CHECK-NEXT: | | `-BuiltinType 0x{{.+}} 'int'
   // CHECK-NEXT: | `-InitListExpr 0x{{.+}}  'int':'int'
-  // CHECK-NEXT: `-VarTemplateSpecializationDecl 0x{{.+}}  col:43 referenced TestVarTemplate 'const int':'const int' static
+  // CHECK-NEXT: 

[PATCH] D155383: [clang][AST] TextNodeDumper learned to output exception specifications

2023-08-10 Thread Timo Stripf via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7fc6fa97edb6: [clang][AST] TextNodeDumper learned to output 
exception specifications (authored by strimo378).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155383

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-functionprototype.cpp


Index: clang/test/AST/ast-dump-functionprototype.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-functionprototype.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 
-Wno-dynamic-exception-spec -ast-dump %s | FileCheck -strict-whitespace %s
+
+struct A {};
+struct B {};
+
+typedef void (type1)() noexcept(10 > 5);
+
+// CHECK:  TypedefDecl {{.*}} type1 'void () noexcept(10 > 5)':'void () 
noexcept(10 > 5)'
+// CHECK-NEXT: `-ParenType {{.*}}
+// CHECK-NEXT:   `-FunctionProtoType {{.*}} 'void () noexcept(10 > 5)' 
exceptionspec_noexcept_true cdecl
+// CHECK-NEXT: |-NoexceptExpr: ConstantExpr {{.*}} 'bool'
+// CHECK-NEXT: | `-value: Int 1
+// CHECK-NEXT: `-BuiltinType {{.*}} 'void'
+
+typedef void (type2)() throw(A, B);
+
+// CHECK:  TypedefDecl {{.*}} type2 'void () throw(A, B)':'void () 
throw(A, B)'
+// CHECK-NEXT: `-ParenType {{.*}}
+// CHECK-NEXT:   `-FunctionProtoType {{.*}} 'void () throw(A, B)' 
exceptionspec_dynamic cdecl
+// CHECK-NEXT: |-Exceptions: 'A':'A', 'B':'B'
+// CHECK-NEXT: `-BuiltinType {{.*}} 'void'
+
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1541,7 +1541,64 @@
 OS << " &&";
 break;
   }
-  // FIXME: Exception specification.
+
+  switch (EPI.ExceptionSpec.Type) {
+  case EST_None:
+break;
+  case EST_DynamicNone:
+OS << " exceptionspec_dynamic_none";
+break;
+  case EST_Dynamic:
+OS << " exceptionspec_dynamic";
+break;
+  case EST_MSAny:
+OS << " exceptionspec_ms_any";
+break;
+  case EST_NoThrow:
+OS << " exceptionspec_nothrow";
+break;
+  case EST_BasicNoexcept:
+OS << " exceptionspec_basic_noexcept";
+break;
+  case EST_DependentNoexcept:
+OS << " exceptionspec_dependent_noexcept";
+break;
+  case EST_NoexceptFalse:
+OS << " exceptionspec_noexcept_false";
+break;
+  case EST_NoexceptTrue:
+OS << " exceptionspec_noexcept_true";
+break;
+  case EST_Unevaluated:
+OS << " exceptionspec_unevaluated";
+break;
+  case EST_Uninstantiated:
+OS << " exceptionspec_uninstantiated";
+break;
+  case EST_Unparsed:
+OS << " exceptionspec_unparsed";
+break;
+  }
+  if (!EPI.ExceptionSpec.Exceptions.empty()) {
+AddChild([=] {
+  OS << "Exceptions:";
+  for (unsigned I = 0, N = EPI.ExceptionSpec.Exceptions.size(); I != N;
+   ++I) {
+if (I)
+  OS << ",";
+dumpType(EPI.ExceptionSpec.Exceptions[I]);
+  }
+});
+  }
+  if (EPI.ExceptionSpec.NoexceptExpr) {
+AddChild([=] {
+  OS << "NoexceptExpr: ";
+  Visit(EPI.ExceptionSpec.NoexceptExpr);
+});
+  }
+  dumpDeclRef(EPI.ExceptionSpec.SourceDecl, "ExceptionSourceDecl");
+  dumpDeclRef(EPI.ExceptionSpec.SourceTemplate, "ExceptionSourceTemplate");
+
   // FIXME: Consumed parameters.
   VisitFunctionType(T);
 }


Index: clang/test/AST/ast-dump-functionprototype.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-functionprototype.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -Wno-dynamic-exception-spec -ast-dump %s | FileCheck -strict-whitespace %s
+
+struct A {};
+struct B {};
+
+typedef void (type1)() noexcept(10 > 5);
+
+// CHECK:  TypedefDecl {{.*}} type1 'void () noexcept(10 > 5)':'void () noexcept(10 > 5)'
+// CHECK-NEXT: `-ParenType {{.*}}
+// CHECK-NEXT:   `-FunctionProtoType {{.*}} 'void () noexcept(10 > 5)' exceptionspec_noexcept_true cdecl
+// CHECK-NEXT: |-NoexceptExpr: ConstantExpr {{.*}} 'bool'
+// CHECK-NEXT: | `-value: Int 1
+// CHECK-NEXT: `-BuiltinType {{.*}} 'void'
+
+typedef void (type2)() throw(A, B);
+
+// CHECK:  TypedefDecl {{.*}} type2 'void () throw(A, B)':'void () throw(A, B)'
+// CHECK-NEXT: `-ParenType {{.*}}
+// CHECK-NEXT:   `-FunctionProtoType {{.*}} 'void () throw(A, B)' exceptionspec_dynamic cdecl
+// CHECK-NEXT: |-Exceptions: 'A':'A', 'B':'B'
+// CHECK-NEXT: `-BuiltinType {{.*}} 'void'
+
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1541,7 +1541,64 @@
 OS << " &&";
 break;
   }
-  // FIXME: Exception specification.
+
+  switch (EPI.ExceptionSpec.Type) {
+  case EST_None:
+break;
+  case 

[PATCH] D155383: [clang][AST] TextNodeDumper learned to output exception specifications

2023-08-10 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

I added a test case for demonstrating `NoexceptExpr` and `Exceptions` output. I 
don't know how to produce a FunctionProtoType output with ExceptionSourceDecl 
and ExceptionSourceTemplate. typedef/using is the only way I know to output 
types for the current AST dump and all my attempts failed to produce an 
uninstantiated exception information within a typedef.

Here is an example from my (slightly extended) AST dump where I output every 
type stored within ASTContext:

  FunctionProtoType #267 0x20c10fd58a0 'void ()' (canonical FunctionProtoType 
#210 0x20c10fd6580) exceptionspec_uninstantiated
  |-ExceptionSourceDecl CXXConstructor 0x20c10fd5798 #266 'e' 'void () 
noexcept(b<__is_same(d<>, d<>)>::c && b<__is_same(d<>, d<>)>::c)'#286 cdecl
  |-ExceptionSourceTemplate CXXConstructor 0x20c10fd6608 #212 'e' 'void () 
noexcept(b<__is_same(d<>, d<>)>::c && b<__is_same(d<>, d)>::c)'#251
  `-BuiltinType #2 0x20c0f5bf7f0 'void'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155383

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155383: [clang][AST] TextNodeDumper learned to output exception specifications

2023-08-10 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 548964.
strimo378 added a comment.

Added test cases and applied review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155383

Files:
  clang/lib/AST/TextNodeDumper.cpp
  clang/test/AST/ast-dump-functionprototype.cpp


Index: clang/test/AST/ast-dump-functionprototype.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-functionprototype.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 
-Wno-dynamic-exception-spec -ast-dump %s | FileCheck -strict-whitespace %s
+
+struct A {};
+struct B {};
+
+typedef void (type1)() noexcept(10 > 5);
+
+// CHECK:  TypedefDecl {{.*}} type1 'void () noexcept(10 > 5)':'void () 
noexcept(10 > 5)'
+// CHECK-NEXT: `-ParenType {{.*}}
+// CHECK-NEXT:   `-FunctionProtoType {{.*}} 'void () noexcept(10 > 5)' 
exceptionspec_noexcept_true cdecl
+// CHECK-NEXT: |-NoexceptExpr: ConstantExpr {{.*}} 'bool'
+// CHECK-NEXT: | `-value: Int 1
+// CHECK-NEXT: `-BuiltinType {{.*}} 'void'
+
+typedef void (type2)() throw(A, B);
+
+// CHECK:  TypedefDecl {{.*}} type2 'void () throw(A, B)':'void () 
throw(A, B)'
+// CHECK-NEXT: `-ParenType {{.*}}
+// CHECK-NEXT:   `-FunctionProtoType {{.*}} 'void () throw(A, B)' 
exceptionspec_dynamic cdecl
+// CHECK-NEXT: |-Exceptions: 'A':'A', 'B':'B'
+// CHECK-NEXT: `-BuiltinType {{.*}} 'void'
+
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1541,7 +1541,64 @@
 OS << " &&";
 break;
   }
-  // FIXME: Exception specification.
+
+  switch (EPI.ExceptionSpec.Type) {
+  case EST_None:
+break;
+  case EST_DynamicNone:
+OS << " exceptionspec_dynamic_none";
+break;
+  case EST_Dynamic:
+OS << " exceptionspec_dynamic";
+break;
+  case EST_MSAny:
+OS << " exceptionspec_ms_any";
+break;
+  case EST_NoThrow:
+OS << " exceptionspec_nothrow";
+break;
+  case EST_BasicNoexcept:
+OS << " exceptionspec_basic_noexcept";
+break;
+  case EST_DependentNoexcept:
+OS << " exceptionspec_dependent_noexcept";
+break;
+  case EST_NoexceptFalse:
+OS << " exceptionspec_noexcept_false";
+break;
+  case EST_NoexceptTrue:
+OS << " exceptionspec_noexcept_true";
+break;
+  case EST_Unevaluated:
+OS << " exceptionspec_unevaluated";
+break;
+  case EST_Uninstantiated:
+OS << " exceptionspec_uninstantiated";
+break;
+  case EST_Unparsed:
+OS << " exceptionspec_unparsed";
+break;
+  }
+  if (!EPI.ExceptionSpec.Exceptions.empty()) {
+AddChild([=] {
+  OS << "Exceptions:";
+  for (unsigned I = 0, N = EPI.ExceptionSpec.Exceptions.size(); I != N;
+   ++I) {
+if (I)
+  OS << ",";
+dumpType(EPI.ExceptionSpec.Exceptions[I]);
+  }
+});
+  }
+  if (EPI.ExceptionSpec.NoexceptExpr) {
+AddChild([=] {
+  OS << "NoexceptExpr: ";
+  Visit(EPI.ExceptionSpec.NoexceptExpr);
+});
+  }
+  dumpDeclRef(EPI.ExceptionSpec.SourceDecl, "ExceptionSourceDecl");
+  dumpDeclRef(EPI.ExceptionSpec.SourceTemplate, "ExceptionSourceTemplate");
+
   // FIXME: Consumed parameters.
   VisitFunctionType(T);
 }


Index: clang/test/AST/ast-dump-functionprototype.cpp
===
--- /dev/null
+++ clang/test/AST/ast-dump-functionprototype.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -Wno-dynamic-exception-spec -ast-dump %s | FileCheck -strict-whitespace %s
+
+struct A {};
+struct B {};
+
+typedef void (type1)() noexcept(10 > 5);
+
+// CHECK:  TypedefDecl {{.*}} type1 'void () noexcept(10 > 5)':'void () noexcept(10 > 5)'
+// CHECK-NEXT: `-ParenType {{.*}}
+// CHECK-NEXT:   `-FunctionProtoType {{.*}} 'void () noexcept(10 > 5)' exceptionspec_noexcept_true cdecl
+// CHECK-NEXT: |-NoexceptExpr: ConstantExpr {{.*}} 'bool'
+// CHECK-NEXT: | `-value: Int 1
+// CHECK-NEXT: `-BuiltinType {{.*}} 'void'
+
+typedef void (type2)() throw(A, B);
+
+// CHECK:  TypedefDecl {{.*}} type2 'void () throw(A, B)':'void () throw(A, B)'
+// CHECK-NEXT: `-ParenType {{.*}}
+// CHECK-NEXT:   `-FunctionProtoType {{.*}} 'void () throw(A, B)' exceptionspec_dynamic cdecl
+// CHECK-NEXT: |-Exceptions: 'A':'A', 'B':'B'
+// CHECK-NEXT: `-BuiltinType {{.*}} 'void'
+
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1541,7 +1541,64 @@
 OS << " &&";
 break;
   }
-  // FIXME: Exception specification.
+
+  switch (EPI.ExceptionSpec.Type) {
+  case EST_None:
+break;
+  case EST_DynamicNone:
+OS << " exceptionspec_dynamic_none";
+break;
+  case EST_Dynamic:

[PATCH] D157394: [clang][DeclPrinter] Improve AST print of function attributes

2023-08-10 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added inline comments.



Comment at: clang/lib/AST/DeclPrinter.cpp:267
+// C2x/C++11-style attributes must appear before the declarator.
+if (S == Attr::AS_CXX11 || S == Attr::AS_C2x)
+  return AttrLocation::BeforeDecl;

strimo378 wrote:
> giulianobelinassi wrote:
> > You can use A->isStandardAttributeSyntax()
> Yes, ok
I checked isStandardAttributeSyntax(). I cannot use it since it also includes 
the alignas keyword for some strange reason.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157394

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157394: [clang][DeclPrinter] Improve AST print of function attributes

2023-08-10 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 548916.
strimo378 added a comment.

Added more test cases and considering __declspec


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157394

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp
  clang/test/AST/ast-print-no-sanitize.cpp
  clang/test/OpenMP/assumes_codegen.cpp
  clang/test/OpenMP/assumes_print.cpp
  clang/test/OpenMP/assumes_template_print.cpp
  clang/test/OpenMP/declare_simd_ast_print.cpp
  clang/test/SemaCXX/attr-no-sanitize.cpp
  clang/test/SemaCXX/cxx11-attr-print.cpp

Index: clang/test/SemaCXX/cxx11-attr-print.cpp
===
--- clang/test/SemaCXX/cxx11-attr-print.cpp
+++ clang/test/SemaCXX/cxx11-attr-print.cpp
@@ -42,21 +42,21 @@
 // CHECK: int f1() __attribute__((warn_unused_result("")));
 int f1() __attribute__((warn_unused_result));
 
-// CHECK: {{\[}}[clang::warn_unused_result("")]];
+// CHECK: {{\[}}[clang::warn_unused_result("")]]
 int f2 [[clang::warn_unused_result]] ();
 
-// CHECK: {{\[}}[gnu::warn_unused_result("")]];
+// CHECK: {{\[}}[gnu::warn_unused_result("")]]
 int f3 [[gnu::warn_unused_result]] ();
 
 // FIXME: ast-print need to print C++11
 // attribute after function declare-id.
-// CHECK: {{\[}}[noreturn]];
+// CHECK: {{\[}}[noreturn]]
 void f4 [[noreturn]] ();
 
 // CHECK: __attribute__((gnu_inline));
 inline void f6() __attribute__((gnu_inline));
 
-// CHECK: {{\[}}[gnu::gnu_inline]];
+// CHECK: {{\[}}[gnu::gnu_inline]]
 inline void f7 [[gnu::gnu_inline]] ();
 
 // arguments printing
@@ -66,8 +66,8 @@
 // CHECK: int m __attribute__((aligned(4
 // CHECK: int n alignas(4
 // CHECK: int p alignas(int
-// CHECK: static int f() __attribute__((pure))
-// CHECK: static int g() {{\[}}[gnu::pure]]
+// CHECK: __attribute__((pure)) static int f()
+// CHECK: {{\[}}[gnu::pure]] static int g()
 template  struct S {
   __attribute__((aligned(4))) int m;
   alignas(4) int n;
@@ -82,8 +82,8 @@
 
 // CHECK: int m __attribute__((aligned(4
 // CHECK: int n alignas(4
-// CHECK: static int f() __attribute__((pure))
-// CHECK: static int g() {{\[}}[gnu::pure]]
+// CHECK: __attribute__((pure)) static int f()
+// CHECK: {{\[}}[gnu::pure]] static int g()
 template struct S;
 
 // CHECK: using Small2 {{\[}}[gnu::mode(byte)]] = int;
Index: clang/test/SemaCXX/attr-no-sanitize.cpp
===
--- clang/test/SemaCXX/attr-no-sanitize.cpp
+++ clang/test/SemaCXX/attr-no-sanitize.cpp
@@ -16,12 +16,12 @@
 
 // DUMP-LABEL: FunctionDecl {{.*}} f4
 // DUMP: NoSanitizeAttr {{.*}} thread
-// PRINT: int f4() {{\[\[}}clang::no_sanitize("thread")]]
+// PRINT: {{\[\[}}clang::no_sanitize("thread")]] int f4()
 [[clang::no_sanitize("thread")]] int f4();
 
 // DUMP-LABEL: FunctionDecl {{.*}} f4
 // DUMP: NoSanitizeAttr {{.*}} hwaddress
-// PRINT: int f4() {{\[\[}}clang::no_sanitize("hwaddress")]]
+// PRINT: {{\[\[}}clang::no_sanitize("hwaddress")]] int f4()
 [[clang::no_sanitize("hwaddress")]] int f4();
 
 // DUMP-LABEL: FunctionDecl {{.*}} f5
@@ -36,5 +36,5 @@
 
 // DUMP-LABEL: FunctionDecl {{.*}} f7
 // DUMP: NoSanitizeAttr {{.*}} memtag
-// PRINT: int f7() {{\[\[}}clang::no_sanitize("memtag")]]
+// PRINT: {{\[\[}}clang::no_sanitize("memtag")]] int f7()
 [[clang::no_sanitize("memtag")]] int f7();
Index: clang/test/OpenMP/declare_simd_ast_print.cpp
===
--- clang/test/OpenMP/declare_simd_ast_print.cpp
+++ clang/test/OpenMP/declare_simd_ast_print.cpp
@@ -60,7 +60,7 @@
 
 class VV {
   // CHECK: #pragma omp declare simd uniform(this, a) linear(val(b): a)
-  // CHECK-NEXT: int add(int a, int b) __attribute__((cold)){
+  // CHECK-NEXT: __attribute__((cold)) int add(int a, int b)  {
   // CHECK-NEXT: return a + b;
   // CHECK-NEXT: }
   #pragma omp declare simd uniform(this, a) linear(val(b): a)
Index: clang/test/OpenMP/assumes_template_print.cpp
===
--- clang/test/OpenMP/assumes_template_print.cpp
+++ clang/test/OpenMP/assumes_template_print.cpp
@@ -17,7 +17,7 @@
 struct S {
   int a;
 // CHECK: template  struct S {
-// CHECK: void foo() __attribute__((assume("ompx_global_assumption"))) {
+// CHECK: __attribute__((assume("ompx_global_assumption")))  void foo()   {
   void foo() {
 #pragma omp parallel
 {}
@@ -25,15 +25,15 @@
 };
 
 // CHECK: template<> struct S {
-// CHECK: void foo() __attribute__((assume("ompx_global_assumption"))) {
+// CHECK: __attribute__((assume("ompx_global_assumption")))  void foo(){
 
 #pragma omp begin assumes no_openmp
-// CHECK: void S_with_assumes_no_call() __attribute__((assume("omp_no_openmp"))) __attribute__((assume("ompx_global_assumption"))) {
+// CHECK: __attribute__((assume("omp_no_openmp"))) __attribute__((assume("ompx_global_assumption"))) void 

[PATCH] D157394: [clang][DeclPrinter] Improve AST print of function attributes

2023-08-09 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

In D157394#4572777 , 
@giulianobelinassi wrote:

> This patch do not address attributes in variables nor the __declspec case, as 
> D141714  do. His patch looks cleaner and I 
> can surely coordinate with @strimo378 to also fix those cases, but I want an 
> answer to the tblgen question first to see if we decide to drop the tblgen 
> solution or not.

The patch is intended to only address function attributes to keep it simple and 
the test cases focused. Most important is that the AttrLocation is introduced 
and functionality can be easily extended to other decl types in subsequent 
patches. I did some work to address variable and record attributes but I think 
that I did not consider all cases for variables as you did.

`__declspec` should be always placed left?




Comment at: clang/lib/AST/DeclPrinter.cpp:259
+case attr::Final:
+case attr::Override:
+  return AttrLocation::AfterDecl;

giulianobelinassi wrote:
> aaron.ballman wrote:
> > giulianobelinassi wrote:
> > > @aaron.ballman @erichkeane 
> > > 
> > > Is this enough to describe the position of the attribute kind, or should 
> > > it go for a tblgen approach, as I did in D141714? This here looks much 
> > > cleaner than the tblgen IMHO.
> > Oofda, I forgot that we model those as keyword attributes. `override` and 
> > `final` (and other keyword attributes) are a bit trickier than just 
> > "before" or "after" because there's a very particular order in which those 
> > can be parsed grammatically, especially for functions: 
> > https://godbolt.org/z/ad5qecbrj
> > 
> > Thinking out loud: perhaps an approach to solving this is to sort the 
> > attributes by source location. So all the before attributes are written in 
> > the same order as they were in source, as are all of the after attributes. 
> > So long as we're skipping over implicit attributes, this seems like it 
> > should keep the order of the attributes correct.
> > 
> > A different alternative that's possibly more work than it's worth: the decl 
> > printer could dispatch to a table-genned function to ask the attribute "do 
> > you want to be printed now?" based on what part of the declaration we've 
> > already printed. This would require the decl printer to know e.g., "I've 
> > finished printing the parameter list but haven't yet printed cv qualifiers" 
> > and pass that information along to the attribute; individual attributes 
> > with special rules could supply special logic in Attr.td to say "the 
> > attribute should be printed after the function parameter list and after the 
> > cv and ref qualifiers, but before the override/final keywords" while most 
> > attributes can hopefully get away with whatever the default behavior is 
> > coming out of tablegen.
> > Oofda, I forgot that we model those as keyword attributes. `override` and 
> > `final` (and other keyword attributes) are a bit trickier than just 
> > "before" or "after" because there's a very particular order in which those 
> > can be parsed grammatically, especially for functions: 
> > https://godbolt.org/z/ad5qecbrj
> > 
> > Thinking out loud: perhaps an approach to solving this is to sort the 
> > attributes by source location. So all the before attributes are written in 
> > the same order as they were in source, as are all of the after attributes. 
> > So long as we're skipping over implicit attributes, this seems like it 
> > should keep the order of the attributes correct.
> 
> This may work in cases where clang is able to find the SourceLocation of the 
> Decl. My concern is when clang is *not* able to do it. When analyzing Linux 
> sourcecode there are cases where this happen, and I have to fallback to AST 
> dumping. The only way I see this working is by changing the parser for it to 
> mark the attribute and its position. This may be something for the future, 
> but the presented fix solves the issue for the cases we have already found. 
>  
> > A different alternative that's possibly more work than it's worth: the decl 
> > printer could dispatch to a table-genned function to ask the attribute "do 
> > you want to be printed now?" based on what part of the declaration we've 
> > already printed. This would require the decl printer to know e.g., "I've 
> > finished printing the parameter list but haven't yet printed cv qualifiers" 
> > and pass that information along to the attribute; individual attributes 
> > with special rules could supply special logic in Attr.td to say "the 
> > attribute should be printed after the function parameter list and after the 
> > cv and ref qualifiers, but before the override/final keywords" while most 
> > attributes can hopefully get away with whatever the default behavior is 
> > coming out of tablegen.
> 
> Sounds a lot of work :). Wouldn't my previous suggestion be simpler?
> 
Currently, I would not go for a tblgen approach 

[PATCH] D141714: Fix ast print of variables with attributes

2023-08-09 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

@giulianobelinassi I provided a similar patch as you addressed here, see 
https://reviews.llvm.org/D157394 . It looks like we have the same requirement 
that we both need compilable ast-print code. Are you interested in a teams 
meeting to discuss the topic and align our effort? If yes please write me an 
mail to timo.str...@emmtrix.com .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141714

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157384: [clang] Added Attr::getVariety function

2023-08-09 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 abandoned this revision.
strimo378 added a comment.

Unnecessary


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157384

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157384: [clang] Added Attr::getVariety function

2023-08-09 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 548482.
strimo378 added a comment.

Using Attr::getSyntax (instead of unnecessary added Attr::getVariety)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157384

Files:
  clang/include/clang/AST/Attr.h
  clang/utils/TableGen/ClangAttrEmitter.cpp


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1498,6 +1498,30 @@
   OS << "}\n\n";
 }
 
+static void writeGetVarietyFunction(const Record , raw_ostream ) {
+  std::vector Spellings = GetFlattenedSpellings(R);
+
+  OS << "Attr::Variety " << R.getName() << "Attr::getVariety() const {\n";
+  if (Spellings.empty()) {
+OS << "  return Variety::None;\n}\n\n";
+return;
+  }
+
+  OS << "  switch (getAttributeSpellingListIndex()) {\n"
+"  default:\n"
+"llvm_unreachable(\"Unknown attribute spelling!\");\n"
+"return Variety::None;\n";
+
+  for (unsigned I = 0; I < Spellings.size(); ++I) {
+OS << "  case " << I << ":\n";
+OS << "return Variety::" << Spellings[I].variety() << ";\n";
+  }
+  // End of the switch statement.
+  OS << "  }\n";
+  // End of the getVariety function.
+  OS << "}\n\n";
+}
+
 static void
 writePrettyPrintFunction(const Record ,
  const std::vector> ,
@@ -2798,6 +2822,7 @@
   OS << "  void printPretty(raw_ostream ,\n"
  << "   const PrintingPolicy ) const;\n";
   OS << "  const char *getSpelling() const;\n";
+  OS << "  Variety getVariety() const;\n";
 }
 
 if (!ElideSpelling) {
@@ -2872,6 +2897,7 @@
 
   writePrettyPrintFunction(R, Args, OS);
   writeGetSpellingFunction(R, OS);
+  writeGetVarietyFunction(R, OS);
 }
   }
 }
@@ -2919,6 +2945,9 @@
   OS << "Attr *Attr::clone(ASTContext ) const {\n";
   EmitFunc("clone(C)");
 
+  OS << "Attr::Variety Attr::getVariety() const {\n";
+  EmitFunc("getVariety()");
+
   OS << "void Attr::printPretty(raw_ostream , "
 "const PrintingPolicy ) const {\n";
   EmitFunc("printPretty(OS, Policy)");
Index: clang/include/clang/AST/Attr.h
===
--- clang/include/clang/AST/Attr.h
+++ clang/include/clang/AST/Attr.h
@@ -84,6 +84,20 @@
   }
   const char *getSpelling() const;
 
+  enum class Variety {
+None,
+GNU,  // __attribute__((...))
+Declspec, // __declspec(...)
+Microsoft,// [...]
+CXX11,// [[...]]
+C2x,  // [[...]]
+Keyword,  // e.g. _Noreturn, final, __fastcall, etc.
+Pragma,   // #pragma ...
+HLSLSemantic, // :...
+  };
+
+  Variety getVariety() const;
+
   SourceLocation getLocation() const { return getRange().getBegin(); }
 
   bool isInherited() const { return Inherited; }


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1498,6 +1498,30 @@
   OS << "}\n\n";
 }
 
+static void writeGetVarietyFunction(const Record , raw_ostream ) {
+  std::vector Spellings = GetFlattenedSpellings(R);
+
+  OS << "Attr::Variety " << R.getName() << "Attr::getVariety() const {\n";
+  if (Spellings.empty()) {
+OS << "  return Variety::None;\n}\n\n";
+return;
+  }
+
+  OS << "  switch (getAttributeSpellingListIndex()) {\n"
+"  default:\n"
+"llvm_unreachable(\"Unknown attribute spelling!\");\n"
+"return Variety::None;\n";
+
+  for (unsigned I = 0; I < Spellings.size(); ++I) {
+OS << "  case " << I << ":\n";
+OS << "return Variety::" << Spellings[I].variety() << ";\n";
+  }
+  // End of the switch statement.
+  OS << "  }\n";
+  // End of the getVariety function.
+  OS << "}\n\n";
+}
+
 static void
 writePrettyPrintFunction(const Record ,
  const std::vector> ,
@@ -2798,6 +2822,7 @@
   OS << "  void printPretty(raw_ostream ,\n"
  << "   const PrintingPolicy ) const;\n";
   OS << "  const char *getSpelling() const;\n";
+  OS << "  Variety getVariety() const;\n";
 }
 
 if (!ElideSpelling) {
@@ -2872,6 +2897,7 @@
 
   writePrettyPrintFunction(R, Args, OS);
   writeGetSpellingFunction(R, OS);
+  writeGetVarietyFunction(R, OS);
 }
   }
 }
@@ -2919,6 +2945,9 @@
   OS << "Attr *Attr::clone(ASTContext ) const {\n";
   EmitFunc("clone(C)");
 
+  OS << "Attr::Variety Attr::getVariety() const {\n";
+  EmitFunc("getVariety()");
+
   OS << "void Attr::printPretty(raw_ostream , "
 "const PrintingPolicy ) const {\n";
   EmitFunc("printPretty(OS, Policy)");
Index: clang/include/clang/AST/Attr.h
===
--- 

[PATCH] D157394: [clang][DeclPrinter] Improve AST print of function attributes

2023-08-09 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 548487.
strimo378 edited the summary of this revision.
strimo378 added a comment.

Using Attr::getSyntax function (instead of unnecessarly added Attr::getVariety 
function)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157394

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp
  clang/test/AST/ast-print-no-sanitize.cpp
  clang/test/OpenMP/assumes_codegen.cpp
  clang/test/OpenMP/assumes_print.cpp
  clang/test/OpenMP/assumes_template_print.cpp
  clang/test/OpenMP/declare_simd_ast_print.cpp
  clang/test/SemaCXX/attr-no-sanitize.cpp
  clang/test/SemaCXX/cxx11-attr-print.cpp

Index: clang/test/SemaCXX/cxx11-attr-print.cpp
===
--- clang/test/SemaCXX/cxx11-attr-print.cpp
+++ clang/test/SemaCXX/cxx11-attr-print.cpp
@@ -42,21 +42,21 @@
 // CHECK: int f1() __attribute__((warn_unused_result("")));
 int f1() __attribute__((warn_unused_result));
 
-// CHECK: {{\[}}[clang::warn_unused_result("")]];
+// CHECK: {{\[}}[clang::warn_unused_result("")]]
 int f2 [[clang::warn_unused_result]] ();
 
-// CHECK: {{\[}}[gnu::warn_unused_result("")]];
+// CHECK: {{\[}}[gnu::warn_unused_result("")]]
 int f3 [[gnu::warn_unused_result]] ();
 
 // FIXME: ast-print need to print C++11
 // attribute after function declare-id.
-// CHECK: {{\[}}[noreturn]];
+// CHECK: {{\[}}[noreturn]]
 void f4 [[noreturn]] ();
 
 // CHECK: __attribute__((gnu_inline));
 inline void f6() __attribute__((gnu_inline));
 
-// CHECK: {{\[}}[gnu::gnu_inline]];
+// CHECK: {{\[}}[gnu::gnu_inline]]
 inline void f7 [[gnu::gnu_inline]] ();
 
 // arguments printing
@@ -66,8 +66,8 @@
 // CHECK: int m __attribute__((aligned(4
 // CHECK: int n alignas(4
 // CHECK: int p alignas(int
-// CHECK: static int f() __attribute__((pure))
-// CHECK: static int g() {{\[}}[gnu::pure]]
+// CHECK: __attribute__((pure)) static int f()
+// CHECK: {{\[}}[gnu::pure]] static int g()
 template  struct S {
   __attribute__((aligned(4))) int m;
   alignas(4) int n;
@@ -82,8 +82,8 @@
 
 // CHECK: int m __attribute__((aligned(4
 // CHECK: int n alignas(4
-// CHECK: static int f() __attribute__((pure))
-// CHECK: static int g() {{\[}}[gnu::pure]]
+// CHECK: __attribute__((pure)) static int f()
+// CHECK: {{\[}}[gnu::pure]] static int g()
 template struct S;
 
 // CHECK: using Small2 {{\[}}[gnu::mode(byte)]] = int;
Index: clang/test/SemaCXX/attr-no-sanitize.cpp
===
--- clang/test/SemaCXX/attr-no-sanitize.cpp
+++ clang/test/SemaCXX/attr-no-sanitize.cpp
@@ -16,12 +16,12 @@
 
 // DUMP-LABEL: FunctionDecl {{.*}} f4
 // DUMP: NoSanitizeAttr {{.*}} thread
-// PRINT: int f4() {{\[\[}}clang::no_sanitize("thread")]]
+// PRINT: {{\[\[}}clang::no_sanitize("thread")]] int f4()
 [[clang::no_sanitize("thread")]] int f4();
 
 // DUMP-LABEL: FunctionDecl {{.*}} f4
 // DUMP: NoSanitizeAttr {{.*}} hwaddress
-// PRINT: int f4() {{\[\[}}clang::no_sanitize("hwaddress")]]
+// PRINT: {{\[\[}}clang::no_sanitize("hwaddress")]] int f4()
 [[clang::no_sanitize("hwaddress")]] int f4();
 
 // DUMP-LABEL: FunctionDecl {{.*}} f5
@@ -36,5 +36,5 @@
 
 // DUMP-LABEL: FunctionDecl {{.*}} f7
 // DUMP: NoSanitizeAttr {{.*}} memtag
-// PRINT: int f7() {{\[\[}}clang::no_sanitize("memtag")]]
+// PRINT: {{\[\[}}clang::no_sanitize("memtag")]] int f7()
 [[clang::no_sanitize("memtag")]] int f7();
Index: clang/test/OpenMP/declare_simd_ast_print.cpp
===
--- clang/test/OpenMP/declare_simd_ast_print.cpp
+++ clang/test/OpenMP/declare_simd_ast_print.cpp
@@ -60,7 +60,7 @@
 
 class VV {
   // CHECK: #pragma omp declare simd uniform(this, a) linear(val(b): a)
-  // CHECK-NEXT: int add(int a, int b) __attribute__((cold)){
+  // CHECK-NEXT: __attribute__((cold)) int add(int a, int b)  {
   // CHECK-NEXT: return a + b;
   // CHECK-NEXT: }
   #pragma omp declare simd uniform(this, a) linear(val(b): a)
Index: clang/test/OpenMP/assumes_template_print.cpp
===
--- clang/test/OpenMP/assumes_template_print.cpp
+++ clang/test/OpenMP/assumes_template_print.cpp
@@ -17,7 +17,7 @@
 struct S {
   int a;
 // CHECK: template  struct S {
-// CHECK: void foo() __attribute__((assume("ompx_global_assumption"))) {
+// CHECK: __attribute__((assume("ompx_global_assumption")))  void foo()   {
   void foo() {
 #pragma omp parallel
 {}
@@ -25,15 +25,15 @@
 };
 
 // CHECK: template<> struct S {
-// CHECK: void foo() __attribute__((assume("ompx_global_assumption"))) {
+// CHECK: __attribute__((assume("ompx_global_assumption")))  void foo(){
 
 #pragma omp begin assumes no_openmp
-// CHECK: void S_with_assumes_no_call() __attribute__((assume("omp_no_openmp"))) __attribute__((assume("ompx_global_assumption"))) {
+// CHECK: 

[PATCH] D157384: [clang] Added Attr::getVariety function

2023-08-08 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 abandoned this revision.
strimo378 added a comment.

@aaron.ballman Thank you for the information. Strange that I missed that ... I 
even used the function somewhere else o_O


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157384

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157394: [clang][DeclPrinter] Improved AST print of function attributes

2023-08-08 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, wangpc, jplehr, sstefan1.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157394

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-no-sanitize.cpp
  clang/test/OpenMP/assumes_codegen.cpp
  clang/test/OpenMP/assumes_print.cpp
  clang/test/OpenMP/assumes_template_print.cpp
  clang/test/OpenMP/declare_simd_ast_print.cpp
  clang/test/SemaCXX/attr-no-sanitize.cpp
  clang/test/SemaCXX/cxx11-attr-print.cpp

Index: clang/test/SemaCXX/cxx11-attr-print.cpp
===
--- clang/test/SemaCXX/cxx11-attr-print.cpp
+++ clang/test/SemaCXX/cxx11-attr-print.cpp
@@ -42,21 +42,21 @@
 // CHECK: int f1() __attribute__((warn_unused_result("")));
 int f1() __attribute__((warn_unused_result));
 
-// CHECK: {{\[}}[clang::warn_unused_result("")]];
+// CHECK: {{\[}}[clang::warn_unused_result("")]]
 int f2 [[clang::warn_unused_result]] ();
 
-// CHECK: {{\[}}[gnu::warn_unused_result("")]];
+// CHECK: {{\[}}[gnu::warn_unused_result("")]]
 int f3 [[gnu::warn_unused_result]] ();
 
 // FIXME: ast-print need to print C++11
 // attribute after function declare-id.
-// CHECK: {{\[}}[noreturn]];
+// CHECK: {{\[}}[noreturn]]
 void f4 [[noreturn]] ();
 
 // CHECK: __attribute__((gnu_inline));
 inline void f6() __attribute__((gnu_inline));
 
-// CHECK: {{\[}}[gnu::gnu_inline]];
+// CHECK: {{\[}}[gnu::gnu_inline]]
 inline void f7 [[gnu::gnu_inline]] ();
 
 // arguments printing
@@ -66,8 +66,8 @@
 // CHECK: int m __attribute__((aligned(4
 // CHECK: int n alignas(4
 // CHECK: int p alignas(int
-// CHECK: static int f() __attribute__((pure))
-// CHECK: static int g() {{\[}}[gnu::pure]]
+// CHECK: __attribute__((pure)) static int f()
+// CHECK: {{\[}}[gnu::pure]] static int g()
 template  struct S {
   __attribute__((aligned(4))) int m;
   alignas(4) int n;
@@ -82,8 +82,8 @@
 
 // CHECK: int m __attribute__((aligned(4
 // CHECK: int n alignas(4
-// CHECK: static int f() __attribute__((pure))
-// CHECK: static int g() {{\[}}[gnu::pure]]
+// CHECK: __attribute__((pure)) static int f()
+// CHECK: {{\[}}[gnu::pure]] static int g()
 template struct S;
 
 // CHECK: using Small2 {{\[}}[gnu::mode(byte)]] = int;
Index: clang/test/SemaCXX/attr-no-sanitize.cpp
===
--- clang/test/SemaCXX/attr-no-sanitize.cpp
+++ clang/test/SemaCXX/attr-no-sanitize.cpp
@@ -16,12 +16,12 @@
 
 // DUMP-LABEL: FunctionDecl {{.*}} f4
 // DUMP: NoSanitizeAttr {{.*}} thread
-// PRINT: int f4() {{\[\[}}clang::no_sanitize("thread")]]
+// PRINT: {{\[\[}}clang::no_sanitize("thread")]] int f4()
 [[clang::no_sanitize("thread")]] int f4();
 
 // DUMP-LABEL: FunctionDecl {{.*}} f4
 // DUMP: NoSanitizeAttr {{.*}} hwaddress
-// PRINT: int f4() {{\[\[}}clang::no_sanitize("hwaddress")]]
+// PRINT: {{\[\[}}clang::no_sanitize("hwaddress")]] int f4()
 [[clang::no_sanitize("hwaddress")]] int f4();
 
 // DUMP-LABEL: FunctionDecl {{.*}} f5
@@ -36,5 +36,5 @@
 
 // DUMP-LABEL: FunctionDecl {{.*}} f7
 // DUMP: NoSanitizeAttr {{.*}} memtag
-// PRINT: int f7() {{\[\[}}clang::no_sanitize("memtag")]]
+// PRINT: {{\[\[}}clang::no_sanitize("memtag")]] int f7()
 [[clang::no_sanitize("memtag")]] int f7();
Index: clang/test/OpenMP/declare_simd_ast_print.cpp
===
--- clang/test/OpenMP/declare_simd_ast_print.cpp
+++ clang/test/OpenMP/declare_simd_ast_print.cpp
@@ -60,7 +60,7 @@
 
 class VV {
   // CHECK: #pragma omp declare simd uniform(this, a) linear(val(b): a)
-  // CHECK-NEXT: int add(int a, int b) __attribute__((cold)){
+  // CHECK-NEXT: __attribute__((cold)) int add(int a, int b)  {
   // CHECK-NEXT: return a + b;
   // CHECK-NEXT: }
   #pragma omp declare simd uniform(this, a) linear(val(b): a)
Index: clang/test/OpenMP/assumes_template_print.cpp
===
--- clang/test/OpenMP/assumes_template_print.cpp
+++ clang/test/OpenMP/assumes_template_print.cpp
@@ -17,7 +17,7 @@
 struct S {
   int a;
 // CHECK: template  struct S {
-// CHECK: void foo() __attribute__((assume("ompx_global_assumption"))) {
+// CHECK: __attribute__((assume("ompx_global_assumption")))  void foo()   {
   void foo() {
 #pragma omp parallel
 {}
@@ -25,15 +25,15 @@
 };
 
 // CHECK: template<> struct S {
-// CHECK: void foo() __attribute__((assume("ompx_global_assumption"))) {
+// CHECK: __attribute__((assume("ompx_global_assumption")))  void foo(){
 
 #pragma omp begin assumes no_openmp
-// CHECK: void S_with_assumes_no_call() __attribute__((assume("omp_no_openmp"))) __attribute__((assume("ompx_global_assumption"))) {
+// CHECK: __attribute__((assume("omp_no_openmp"))) __attribute__((assume("ompx_global_assumption"))) void 

[PATCH] D157384: [clang] Added Attr::getVariety function

2023-08-08 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The commit extends ClangAttrEmitter of tablegen to generate Attr*::getVariety() 
function. The function returns the variety of the attribute as an enum. I'll 
use the function in a follow up commit to improve the output of function 
attributes for ast-print.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157384

Files:
  clang/include/clang/AST/Attr.h
  clang/utils/TableGen/ClangAttrEmitter.cpp


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1498,6 +1498,30 @@
   OS << "}\n\n";
 }
 
+static void writeGetVarietyFunction(const Record , raw_ostream ) {
+  std::vector Spellings = GetFlattenedSpellings(R);
+
+  OS << "Attr::Variety " << R.getName() << "Attr::getVariety() const {\n";
+  if (Spellings.empty()) {
+OS << "  return Variety::None;\n}\n\n";
+return;
+  }
+
+  OS << "  switch (getAttributeSpellingListIndex()) {\n"
+"  default:\n"
+"llvm_unreachable(\"Unknown attribute spelling!\");\n"
+"return Variety::None;\n";
+
+  for (unsigned I = 0; I < Spellings.size(); ++I) {
+OS << "  case " << I << ":\n";
+OS << "return Variety::" << Spellings[I].variety() << ";\n";
+  }
+  // End of the switch statement.
+  OS << "  }\n";
+  // End of the getVariety function.
+  OS << "}\n\n";
+}
+
 static void
 writePrettyPrintFunction(const Record ,
  const std::vector> ,
@@ -2798,6 +2822,7 @@
   OS << "  void printPretty(raw_ostream ,\n"
  << "   const PrintingPolicy ) const;\n";
   OS << "  const char *getSpelling() const;\n";
+  OS << "  Variety getVariety() const;\n";
 }
 
 if (!ElideSpelling) {
@@ -2872,6 +2897,7 @@
 
   writePrettyPrintFunction(R, Args, OS);
   writeGetSpellingFunction(R, OS);
+  writeGetVarietyFunction(R, OS);
 }
   }
 }
@@ -2919,6 +2945,9 @@
   OS << "Attr *Attr::clone(ASTContext ) const {\n";
   EmitFunc("clone(C)");
 
+  OS << "Attr::Variety Attr::getVariety() const {\n";
+  EmitFunc("getVariety()");
+
   OS << "void Attr::printPretty(raw_ostream , "
 "const PrintingPolicy ) const {\n";
   EmitFunc("printPretty(OS, Policy)");
Index: clang/include/clang/AST/Attr.h
===
--- clang/include/clang/AST/Attr.h
+++ clang/include/clang/AST/Attr.h
@@ -84,6 +84,20 @@
   }
   const char *getSpelling() const;
 
+  enum class Variety {
+None,
+GNU,  // __attribute__((...))
+Declspec, // __declspec(...)
+Microsoft,// [...]
+CXX11,// [[...]]
+C2x,  // [[...]]
+Keyword,  // e.g. _Noreturn, final, __fastcall, etc.
+Pragma,   // #pragma ...
+HLSLSemantic, // :...
+  };
+
+  Variety getVariety() const;
+
   SourceLocation getLocation() const { return getRange().getBegin(); }
 
   bool isInherited() const { return Inherited; }


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1498,6 +1498,30 @@
   OS << "}\n\n";
 }
 
+static void writeGetVarietyFunction(const Record , raw_ostream ) {
+  std::vector Spellings = GetFlattenedSpellings(R);
+
+  OS << "Attr::Variety " << R.getName() << "Attr::getVariety() const {\n";
+  if (Spellings.empty()) {
+OS << "  return Variety::None;\n}\n\n";
+return;
+  }
+
+  OS << "  switch (getAttributeSpellingListIndex()) {\n"
+"  default:\n"
+"llvm_unreachable(\"Unknown attribute spelling!\");\n"
+"return Variety::None;\n";
+
+  for (unsigned I = 0; I < Spellings.size(); ++I) {
+OS << "  case " << I << ":\n";
+OS << "return Variety::" << Spellings[I].variety() << ";\n";
+  }
+  // End of the switch statement.
+  OS << "  }\n";
+  // End of the getVariety function.
+  OS << "}\n\n";
+}
+
 static void
 writePrettyPrintFunction(const Record ,
  const std::vector> ,
@@ -2798,6 +2822,7 @@
   OS << "  void printPretty(raw_ostream ,\n"
  << "   const PrintingPolicy ) const;\n";
   OS << "  const char *getSpelling() const;\n";
+  OS << "  Variety getVariety() const;\n";
 }
 
 if (!ElideSpelling) {
@@ -2872,6 +2897,7 @@
 
   writePrettyPrintFunction(R, Args, OS);
   writeGetSpellingFunction(R, OS);
+  writeGetVarietyFunction(R, OS);
 }
   }
 }
@@ -2919,6 +2945,9 @@
   OS << "Attr *Attr::clone(ASTContext ) const {\n";
   EmitFunc("clone(C)");
 
+  OS << "Attr::Variety Attr::getVariety() const {\n";
+  EmitFunc("getVariety()");

[PATCH] D156523: [clang][DeclPrinter] Fix AST print to suppress output of implicit (non-written) constructor initializers

2023-08-07 Thread Timo Stripf via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG291eb2589fdc: [clang][DeclPrinter] Fix AST print to suppress 
output of implicit (non-written)… (authored by strimo378).

Changed prior to commit:
  https://reviews.llvm.org/D156523?vs=545102=547988#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156523

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -100,3 +100,26 @@
 
   // CHECK-NEXT: };
 };
+
+
+//  Check that implict (non-written) constructor initializers are not 
output
+
+struct ImplicitCtorInit1 {
+  int a;
+};
+
+// CHECK: struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+
+  // CHECK-NEXT: ImplicitCtorInit2(int *) {
+  ImplicitCtorInit2(int *) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -309,6 +309,8 @@
   for (const auto *BMInitializer : CDecl->inits()) {
 if (BMInitializer->isInClassMemberInitializer())
   continue;
+if (!BMInitializer->isWritten())
+  continue;
 
 if (!HasInitializerList) {
   Proto += " : ";


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -100,3 +100,26 @@
 
   // CHECK-NEXT: };
 };
+
+
+//  Check that implict (non-written) constructor initializers are not output
+
+struct ImplicitCtorInit1 {
+  int a;
+};
+
+// CHECK: struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+
+  // CHECK-NEXT: ImplicitCtorInit2(int *) {
+  ImplicitCtorInit2(int *) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -309,6 +309,8 @@
   for (const auto *BMInitializer : CDecl->inits()) {
 if (BMInitializer->isInClassMemberInitializer())
   continue;
+if (!BMInitializer->isWritten())
+  continue;
 
 if (!HasInitializerList) {
   Proto += " : ";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156533: [clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body

2023-07-28 Thread Timo Stripf via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa3da6284c23a: [clang][DeclPrinter] Fix missing semicolon in 
AST print for methods that are… (authored by strimo378).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156533

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,18 @@
 
   // CHECK-NEXT: };
 };
+
+
+// CHECK: struct DefMethodsWithoutBody {
+struct DefMethodsWithoutBody {
+  // CHECK-NEXT: DefMethodsWithoutBody() = delete;
+  DefMethodsWithoutBody() = delete;
+
+  // CHECK-NEXT: DefMethodsWithoutBody() = default;
+  ~DefMethodsWithoutBody() = default;
+
+  // CHECK-NEXT: void m1() __attribute__((alias("X")));
+  void m1() __attribute__((alias("X")));
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -463,12 +463,12 @@
 else if (isa(*D) && cast(*D)->hasBody())
   Terminator = nullptr;
 else if (auto FD = dyn_cast(*D)) {
-  if (FD->isThisDeclarationADefinition())
+  if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
 Terminator = nullptr;
   else
 Terminator = ";";
 } else if (auto TD = dyn_cast(*D)) {
-  if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
+  if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
 Terminator = nullptr;
   else
 Terminator = ";";


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,18 @@
 
   // CHECK-NEXT: };
 };
+
+
+// CHECK: struct DefMethodsWithoutBody {
+struct DefMethodsWithoutBody {
+  // CHECK-NEXT: DefMethodsWithoutBody() = delete;
+  DefMethodsWithoutBody() = delete;
+
+  // CHECK-NEXT: DefMethodsWithoutBody() = default;
+  ~DefMethodsWithoutBody() = default;
+
+  // CHECK-NEXT: void m1() __attribute__((alias("X")));
+  void m1() __attribute__((alias("X")));
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -463,12 +463,12 @@
 else if (isa(*D) && cast(*D)->hasBody())
   Terminator = nullptr;
 else if (auto FD = dyn_cast(*D)) {
-  if (FD->isThisDeclarationADefinition())
+  if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
 Terminator = nullptr;
   else
 Terminator = ";";
 } else if (auto TD = dyn_cast(*D)) {
-  if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
+  if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
 Terminator = nullptr;
   else
 Terminator = ";";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156533: [clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body

2023-07-28 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

https://github.com/llvm/llvm-project/issues/62996


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156533

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156533: [clang][DeclPrinter] Fix missing semicolon in AST print for methods that are definitions without having a body

2023-07-28 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

DeclPrinter used FunctionDecl::isThisDeclarationADefinition to decide if the 
decl requires a semicolon at the end. However, there are several methods 
without body (that require a semicolon) that are definitions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156533

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,18 @@
 
   // CHECK-NEXT: };
 };
+
+
+// CHECK: struct DefMethodsWithoutBody {
+struct DefMethodsWithoutBody {
+  // CHECK-NEXT: DefMethodsWithoutBody() = delete;
+  DefMethodsWithoutBody() = delete;
+
+  // CHECK-NEXT: DefMethodsWithoutBody() = default;
+  ~DefMethodsWithoutBody() = default;
+
+  // CHECK-NEXT: void m1() __attribute__((alias("X")));
+  void m1() __attribute__((alias("X")));
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -463,12 +463,12 @@
 else if (isa(*D) && cast(*D)->hasBody())
   Terminator = nullptr;
 else if (auto FD = dyn_cast(*D)) {
-  if (FD->isThisDeclarationADefinition())
+  if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
 Terminator = nullptr;
   else
 Terminator = ";";
 } else if (auto TD = dyn_cast(*D)) {
-  if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
+  if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
 Terminator = nullptr;
   else
 Terminator = ";";


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,18 @@
 
   // CHECK-NEXT: };
 };
+
+
+// CHECK: struct DefMethodsWithoutBody {
+struct DefMethodsWithoutBody {
+  // CHECK-NEXT: DefMethodsWithoutBody() = delete;
+  DefMethodsWithoutBody() = delete;
+
+  // CHECK-NEXT: DefMethodsWithoutBody() = default;
+  ~DefMethodsWithoutBody() = default;
+
+  // CHECK-NEXT: void m1() __attribute__((alias("X")));
+  void m1() __attribute__((alias("X")));
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -463,12 +463,12 @@
 else if (isa(*D) && cast(*D)->hasBody())
   Terminator = nullptr;
 else if (auto FD = dyn_cast(*D)) {
-  if (FD->isThisDeclarationADefinition())
+  if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
 Terminator = nullptr;
   else
 Terminator = ";";
 } else if (auto TD = dyn_cast(*D)) {
-  if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
+  if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
 Terminator = nullptr;
   else
 Terminator = ";";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156523: [clang][DeclPrinter] Fix AST print to suppress output of implicit (non-written) constructor initializers

2023-07-28 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

The current output of the test case can be shown here: 
https://godbolt.org/z/95ToPbqrP


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156523

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156523: [clang][DeclPrinter] Fix AST print to suppress output of implicit (non-written) constructor initializers

2023-07-28 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

DeclPrinter::PrintConstructorInitializers did output non-written constructor 
initiaizers. In particular, implicit constructor initializers of base classes 
were output.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156523

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,28 @@
 
   // CHECK-NEXT: };
 };
+
+
+
+//  Check that implict (non-written) constructor initializers are not 
output
+
+struct ImplicitCtorInit1 {
+  int a;
+};
+
+// CHECK: struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+
+  // CHECK-NEXT: ImplicitCtorInit2(int *) {
+  ImplicitCtorInit2(int *) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  // CHECK-NEXT: }
+  }
+
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -309,6 +309,8 @@
   for (const auto *BMInitializer : CDecl->inits()) {
 if (BMInitializer->isInClassMemberInitializer())
   continue;
+if (!BMInitializer->isWritten())
+  continue;
 
 if (!HasInitializerList) {
   Proto += " : ";


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -85,3 +85,28 @@
 
   // CHECK-NEXT: };
 };
+
+
+
+//  Check that implict (non-written) constructor initializers are not output
+
+struct ImplicitCtorInit1 {
+  int a;
+};
+
+// CHECK: struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+struct ImplicitCtorInit2 : ImplicitCtorInit1 {
+
+  // CHECK-NEXT: ImplicitCtorInit2(int *) {
+  ImplicitCtorInit2(int *) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  ImplicitCtorInit2(int **) : ImplicitCtorInit1() {
+  // CHECK-NEXT: }
+  }
+
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -309,6 +309,8 @@
   for (const auto *BMInitializer : CDecl->inits()) {
 if (BMInitializer->isInClassMemberInitializer())
   continue;
+if (!BMInitializer->isWritten())
+  continue;
 
 if (!HasInitializerList) {
   Proto += " : ";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156307: [clang][DeclPrinter] Fix AST print of curly constructor initializers

2023-07-27 Thread Timo Stripf via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e4c5cc56c14: [clang][DeclPrinter] Fix AST print of curly 
constructor initializers (authored by strimo378).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156307

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp

Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
 
-// CHECK: struct A {
-struct A {
-  // CHECK-NEXT: A();
-  A();
+// CHECK: struct DelegatingCtor1 {
+struct DelegatingCtor1 {
+  // CHECK-NEXT: DelegatingCtor1();
+  DelegatingCtor1();
 
-  // CHECK-NEXT: A(int) : A() {
-  A(int) : A() {
+  // CHECK-NEXT: DelegatingCtor1(int) : DelegatingCtor1() {
+  DelegatingCtor1(int) : DelegatingCtor1() {
 // CHECK-NEXT: }
   }
 
@@ -14,33 +14,72 @@
 };
 
 
-// CHECK: struct B {
-struct B {
-  // CHECK-NEXT: template  B(Ty);
-  template  B(Ty);
+// CHECK: struct DelegatingCtor2 {
+struct DelegatingCtor2 {
+  // CHECK-NEXT: template  DelegatingCtor2(Ty);
+  template  DelegatingCtor2(Ty);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK-NEXT: template<> B(float);
+  // CHECK-NEXT: template<> DelegatingCtor2(float);
 
-  // CHECK-NEXT: B(int X) : B((float)X) {
-  B(int X) : B((float)X) {
+  // CHECK-NEXT: DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
+  DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
   // CHECK-NEXT: }
   }
 
   // CHECK-NEXT: };
 };
 
-// CHECK: struct C {
-struct C {
+// CHECK: struct DelegatingCtor3 {
+struct DelegatingCtor3 {
   // FIXME: template <> should not be output
-  // CHECK: template <> C(auto);
-  C(auto);
+  // CHECK: template <> DelegatingCtor3(auto);
+  DelegatingCtor3(auto);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK: template<> C(const char *);
+  // CHECK: template<> DelegatingCtor3(const char *);
 
-  // CHECK: C(int) : C("") {
-  C(int) : C("") {
+  // CHECK: DelegatingCtor3(int) : DelegatingCtor3("") {
+  DelegatingCtor3(int) : DelegatingCtor3("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct CurlyCtorInit {
+struct CurlyCtorInit {
+  // CHECK-NEXT: struct A {
+  struct A {
+// CHECK-NEXT: int x;
+int x;
+  // CHECK-NEXT: };
+  };
+
+  // CHECK-NEXT: A a;
+  A a;
+  // CHECK-NEXT: int i;
+  int i;
+
+  // FIXME: /*implicit*/(int)0 should not be output
+  // CHECK-NEXT: CurlyCtorInit(int *) : a(), i(/*implicit*/(int)0) {
+  CurlyCtorInit(int *) : a(), i() {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: CurlyCtorInit(int **) : a{}, i{} {
+  CurlyCtorInit(int **) : a{}, i{} {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: CurlyCtorInit(int ***) : a({}), i(0) {
+  CurlyCtorInit(int ***) : a({}), i(0) {
+  // CHECK-NEXT: }
+  }
+
+  // FIXME: Implicit this should not be output
+  // CHECK-NEXT: CurlyCtorInit(int ) : a({.x = 0}), i(this->a.x) {
+  CurlyCtorInit(int ) : a({.x = 0}), i(a.x) {
   // CHECK-NEXT: }
   }
 
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -327,11 +327,12 @@
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
 
-Out << "(";
-if (!BMInitializer->getInit()) {
-  // Nothing to print
-} else {
-  Expr *Init = BMInitializer->getInit();
+if (Expr *Init = BMInitializer->getInit()) {
+  bool OutParens = !isa(Init);
+
+  if (OutParens)
+Out << "(";
+
   if (ExprWithCleanups *Tmp = dyn_cast(Init))
 Init = Tmp->getSubExpr();
 
@@ -365,8 +366,13 @@
);
 }
   }
+
+  if (OutParens)
+Out << ")";
+} else {
+  Out << "()";
 }
-Out << ")";
+
 if (BMInitializer->isPackExpansion())
   Out << "...";
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156307: [clang][DeclPrinter] Fix AST print of curly constructor initializers

2023-07-26 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 544566.
strimo378 added a comment.

Added additional ctor variants as suggested by the reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156307

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp

Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
 
-// CHECK: struct A {
-struct A {
-  // CHECK-NEXT: A();
-  A();
+// CHECK: struct DelegatingCtor1 {
+struct DelegatingCtor1 {
+  // CHECK-NEXT: DelegatingCtor1();
+  DelegatingCtor1();
 
-  // CHECK-NEXT: A(int) : A() {
-  A(int) : A() {
+  // CHECK-NEXT: DelegatingCtor1(int) : DelegatingCtor1() {
+  DelegatingCtor1(int) : DelegatingCtor1() {
 // CHECK-NEXT: }
   }
 
@@ -14,33 +14,72 @@
 };
 
 
-// CHECK: struct B {
-struct B {
-  // CHECK-NEXT: template  B(Ty);
-  template  B(Ty);
+// CHECK: struct DelegatingCtor2 {
+struct DelegatingCtor2 {
+  // CHECK-NEXT: template  DelegatingCtor2(Ty);
+  template  DelegatingCtor2(Ty);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK-NEXT: template<> B(float);
+  // CHECK-NEXT: template<> DelegatingCtor2(float);
 
-  // CHECK-NEXT: B(int X) : B((float)X) {
-  B(int X) : B((float)X) {
+  // CHECK-NEXT: DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
+  DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
   // CHECK-NEXT: }
   }
 
   // CHECK-NEXT: };
 };
 
-// CHECK: struct C {
-struct C {
+// CHECK: struct DelegatingCtor3 {
+struct DelegatingCtor3 {
   // FIXME: template <> should not be output
-  // CHECK: template <> C(auto);
-  C(auto);
+  // CHECK: template <> DelegatingCtor3(auto);
+  DelegatingCtor3(auto);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK: template<> C(const char *);
+  // CHECK: template<> DelegatingCtor3(const char *);
 
-  // CHECK: C(int) : C("") {
-  C(int) : C("") {
+  // CHECK: DelegatingCtor3(int) : DelegatingCtor3("") {
+  DelegatingCtor3(int) : DelegatingCtor3("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct CurlyCtorInit {
+struct CurlyCtorInit {
+  // CHECK-NEXT: struct A {
+  struct A {
+// CHECK-NEXT: int x;
+int x;
+  // CHECK-NEXT: };
+  };
+
+  // CHECK-NEXT: A a;
+  A a;
+  // CHECK-NEXT: int i;
+  int i;
+
+  // FIXME: /*implicit*/(int)0 should not be output
+  // CHECK-NEXT: CurlyCtorInit(int *) : a(), i(/*implicit*/(int)0) {
+  CurlyCtorInit(int *) : a(), i() {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: CurlyCtorInit(int **) : a{}, i{} {
+  CurlyCtorInit(int **) : a{}, i{} {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: CurlyCtorInit(int ***) : a({}), i(0) {
+  CurlyCtorInit(int ***) : a({}), i(0) {
+  // CHECK-NEXT: }
+  }
+
+  // FIXME: Implicit this should not be output
+  // CHECK-NEXT: CurlyCtorInit(int ) : a({.x = 0}), i(this->a.x) {
+  CurlyCtorInit(int ) : a({.x = 0}), i(a.x) {
   // CHECK-NEXT: }
   }
 
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -327,11 +327,12 @@
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
 
-Out << "(";
-if (!BMInitializer->getInit()) {
-  // Nothing to print
-} else {
-  Expr *Init = BMInitializer->getInit();
+if (Expr *Init = BMInitializer->getInit()) {
+  bool OutParens = !isa(Init);
+
+  if (OutParens)
+Out << "(";
+
   if (ExprWithCleanups *Tmp = dyn_cast(Init))
 Init = Tmp->getSubExpr();
 
@@ -365,8 +366,13 @@
);
 }
   }
+
+  if (OutParens)
+Out << ")";
+} else {
+  Out << "()";
 }
-Out << ")";
+
 if (BMInitializer->isPackExpansion())
   Out << "...";
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156307: [clang][DeclPrinter] Fix AST print of curly constructor initializers

2023-07-26 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156307

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp

Index: clang/test/AST/ast-print-method-decl.cpp
===
--- clang/test/AST/ast-print-method-decl.cpp
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
 
-// CHECK: struct A {
-struct A {
-  // CHECK-NEXT: A();
-  A();
+// CHECK: struct DelegatingCtor1 {
+struct DelegatingCtor1 {
+  // CHECK-NEXT: DelegatingCtor1();
+  DelegatingCtor1();
 
-  // CHECK-NEXT: A(int) : A() {
-  A(int) : A() {
+  // CHECK-NEXT: DelegatingCtor1(int) : DelegatingCtor1() {
+  DelegatingCtor1(int) : DelegatingCtor1() {
 // CHECK-NEXT: }
   }
 
@@ -14,35 +14,58 @@
 };
 
 
-// CHECK: struct B {
-struct B {
-  // CHECK-NEXT: template  B(Ty);
-  template  B(Ty);
+// CHECK: struct DelegatingCtor2 {
+struct DelegatingCtor2 {
+  // CHECK-NEXT: template  DelegatingCtor2(Ty);
+  template  DelegatingCtor2(Ty);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK-NEXT: template<> B(float);
+  // CHECK-NEXT: template<> DelegatingCtor2(float);
 
-  // CHECK-NEXT: B(int X) : B((float)X) {
-  B(int X) : B((float)X) {
+  // CHECK-NEXT: DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
+  DelegatingCtor2(int X) : DelegatingCtor2((float)X) {
   // CHECK-NEXT: }
   }
 
   // CHECK-NEXT: };
 };
 
-// CHECK: struct C {
-struct C {
+// CHECK: struct DelegatingCtor3 {
+struct DelegatingCtor3 {
   // FIXME: template <> should not be output
-  // CHECK: template <> C(auto);
-  C(auto);
+  // CHECK: template <> DelegatingCtor3(auto);
+  DelegatingCtor3(auto);
 
   // FIXME: Implicitly specialized method should not be output
-  // CHECK: template<> C(const char *);
+  // CHECK: template<> DelegatingCtor3(const char *);
 
-  // CHECK: C(int) : C("") {
-  C(int) : C("") {
+  // CHECK: DelegatingCtor3(int) : DelegatingCtor3("") {
+  DelegatingCtor3(int) : DelegatingCtor3("") {
   // CHECK-NEXT: }
   }
 
   // CHECK-NEXT: };
 };
+
+// CHECK: struct CurlyCtorInit {
+struct CurlyCtorInit {
+  // CHECK-NEXT: struct A {
+  struct A {
+  // CHECK-NEXT: };
+  };
+
+  // CHECK-NEXT: A a1;
+  A a1;
+  // CHECK-NEXT: A a2;
+  A a2;
+  // CHECK-NEXT: int b;
+  int b;
+
+  // CHECK-NEXT: CurlyCtorInit() : a1({}), a2{}, b{} {
+  CurlyCtorInit() : a1({}), a2{}, b{} {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -327,11 +327,12 @@
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
 
-Out << "(";
-if (!BMInitializer->getInit()) {
-  // Nothing to print
-} else {
-  Expr *Init = BMInitializer->getInit();
+if (Expr *Init = BMInitializer->getInit()) {
+  bool OutParens = !isa(Init);
+
+  if (OutParens)
+Out << "(";
+
   if (ExprWithCleanups *Tmp = dyn_cast(Init))
 Init = Tmp->getSubExpr();
 
@@ -365,8 +366,13 @@
);
 }
   }
+
+  if (OutParens)
+Out << ")";
+} else {
+  Out << "()";
 }
-Out << ")";
+
 if (BMInitializer->isPackExpansion())
   Out << "...";
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-26 Thread Timo Stripf via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2ca74162258b: [clang][DeclPrinter] Fix AST print of 
delegating constructors (authored by strimo378).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154186

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+
+// CHECK: struct B {
+struct B {
+  // CHECK-NEXT: template  B(Ty);
+  template  B(Ty);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK-NEXT: template<> B(float);
+
+  // CHECK-NEXT: B(int X) : B((float)X) {
+  B(int X) : B((float)X) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct C {
+struct C {
+  // FIXME: template <> should not be output
+  // CHECK: template <> C(auto);
+  C(auto);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK: template<> C(const char *);
+
+  // CHECK: C(int) : C("") {
+  C(int) : C("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+
+// CHECK: struct B {
+struct B {
+  // CHECK-NEXT: template  B(Ty);
+  template  B(Ty);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK-NEXT: template<> B(float);
+
+  // CHECK-NEXT: B(int X) : B((float)X) {
+  B(int X) : B((float)X) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct C {
+struct C {
+  // FIXME: template <> should not be output
+  // CHECK: template <> C(auto);
+  C(auto);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK: template<> C(const char *);
+
+  // CHECK: C(int) : C("") {
+  C(int) : C("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-25 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

I plan around half a dozen patches only for ast-print functionality. I would 
love to land it myself and will asked for commit privileges.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154186

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-20 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 marked 3 inline comments as done.
strimo378 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154186

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139267: Supporting tbaa.struct metadata generation for bitfields

2023-07-20 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.
Herald added a subscriber: wangpc.

Ping


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

https://reviews.llvm.org/D139267

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155383: [clang][AST] TextNodeDumper learned to output exception specifications

2023-07-17 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

There are many ast-dump tests about decls but there are nearly no other type 
tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155383

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155383: [clang][AST] TextNodeDumper learned to output exception specifications

2023-07-15 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added reviewers: aaron.ballman, hazohelet, stephenkelly.
strimo378 added a project: clang.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a subscriber: cfe-commits.

Extended TextNodeDumper::VisitFunctionProtoType to output exception 
specifications


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155383

Files:
  clang/lib/AST/TextNodeDumper.cpp


Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1541,7 +1541,64 @@
 OS << " &&";
 break;
   }
-  // FIXME: Exception specification.
+
+  switch (EPI.ExceptionSpec.Type) {
+  case EST_None:
+break;
+  case EST_DynamicNone:
+OS << " exceptionspec_dynamicnone";
+break;
+  case EST_Dynamic:
+OS << " exceptionspec_dynamic";
+break;
+  case EST_MSAny:
+OS << " exceptionspec_msany";
+break;
+  case EST_NoThrow:
+OS << " exceptionspec_nothrow";
+break;
+  case EST_BasicNoexcept:
+OS << " exceptionspec_basicnoexcept";
+break;
+  case EST_DependentNoexcept:
+OS << " exceptionspec_dependentnoexcept";
+break;
+  case EST_NoexceptFalse:
+OS << " exceptionspec_noexceptfalse";
+break;
+  case EST_NoexceptTrue:
+OS << " exceptionspec_noexcepttrue";
+break;
+  case EST_Unevaluated:
+OS << " exceptionspec_unevaluated";
+break;
+  case EST_Uninstantiated:
+OS << " exceptionspec_uninstantiated";
+break;
+  case EST_Unparsed:
+OS << " exceptionspec_unparsed";
+break;
+  }
+  if (!EPI.ExceptionSpec.Exceptions.empty()) {
+AddChild([=] {
+  OS << "Exceptions:";
+  for (unsigned I = 0, N = EPI.ExceptionSpec.Exceptions.size(); I != N;
+   ++I) {
+if (I)
+  OS << ",";
+dumpType(EPI.ExceptionSpec.Exceptions[I]);
+  }
+});
+  }
+  if (EPI.ExceptionSpec.NoexceptExpr) {
+AddChild([=] {
+  OS << "NoexceptExpr: ";
+  Visit(EPI.ExceptionSpec.NoexceptExpr);
+});
+  }
+  dumpDeclRef(EPI.ExceptionSpec.SourceDecl, "ExceptionSourceDecl");
+  dumpDeclRef(EPI.ExceptionSpec.SourceTemplate, "ExceptionSourceTemplate");
+
   // FIXME: Consumed parameters.
   VisitFunctionType(T);
 }


Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1541,7 +1541,64 @@
 OS << " &&";
 break;
   }
-  // FIXME: Exception specification.
+
+  switch (EPI.ExceptionSpec.Type) {
+  case EST_None:
+break;
+  case EST_DynamicNone:
+OS << " exceptionspec_dynamicnone";
+break;
+  case EST_Dynamic:
+OS << " exceptionspec_dynamic";
+break;
+  case EST_MSAny:
+OS << " exceptionspec_msany";
+break;
+  case EST_NoThrow:
+OS << " exceptionspec_nothrow";
+break;
+  case EST_BasicNoexcept:
+OS << " exceptionspec_basicnoexcept";
+break;
+  case EST_DependentNoexcept:
+OS << " exceptionspec_dependentnoexcept";
+break;
+  case EST_NoexceptFalse:
+OS << " exceptionspec_noexceptfalse";
+break;
+  case EST_NoexceptTrue:
+OS << " exceptionspec_noexcepttrue";
+break;
+  case EST_Unevaluated:
+OS << " exceptionspec_unevaluated";
+break;
+  case EST_Uninstantiated:
+OS << " exceptionspec_uninstantiated";
+break;
+  case EST_Unparsed:
+OS << " exceptionspec_unparsed";
+break;
+  }
+  if (!EPI.ExceptionSpec.Exceptions.empty()) {
+AddChild([=] {
+  OS << "Exceptions:";
+  for (unsigned I = 0, N = EPI.ExceptionSpec.Exceptions.size(); I != N;
+   ++I) {
+if (I)
+  OS << ",";
+dumpType(EPI.ExceptionSpec.Exceptions[I]);
+  }
+});
+  }
+  if (EPI.ExceptionSpec.NoexceptExpr) {
+AddChild([=] {
+  OS << "NoexceptExpr: ";
+  Visit(EPI.ExceptionSpec.NoexceptExpr);
+});
+  }
+  dumpDeclRef(EPI.ExceptionSpec.SourceDecl, "ExceptionSourceDecl");
+  dumpDeclRef(EPI.ExceptionSpec.SourceTemplate, "ExceptionSourceTemplate");
+
   // FIXME: Consumed parameters.
   VisitFunctionType(T);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-14 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 540627.
strimo378 added a comment.

Updated test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154186

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+
+// CHECK: struct B {
+struct B {
+  // CHECK-NEXT: template  B(Ty);
+  template  B(Ty);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK-NEXT: template<> B(float);
+
+  // CHECK-NEXT: B(int X) : B((float)X) {
+  B(int X) : B((float)X) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct C {
+struct C {
+  // FIXME: template <> should not be output
+  // CHECK: template <> C(auto);
+  C(auto);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK: template<> C(const char *);
+
+  // CHECK: C(int) : C("") {
+  C(int) : C("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -ast-print %s -o - -std=c++20 | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+
+// CHECK: struct B {
+struct B {
+  // CHECK-NEXT: template  B(Ty);
+  template  B(Ty);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK-NEXT: template<> B(float);
+
+  // CHECK-NEXT: B(int X) : B((float)X) {
+  B(int X) : B((float)X) {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
+
+// CHECK: struct C {
+struct C {
+  // FIXME: template <> should not be output
+  // CHECK: template <> C(auto);
+  C(auto);
+
+  // FIXME: Implicitly specialized method should not be output
+  // CHECK: template<> C(const char *);
+
+  // CHECK: C(int) : C("") {
+  C(int) : C("") {
+  // CHECK-NEXT: }
+  }
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-11 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added inline comments.



Comment at: clang/test/AST/ast-print-method-decl.cpp:15
+  // CHECK-NEXT: };
+};

aaron.ballman wrote:
> I'd also like to see test cases along the lines of:
> ```
> struct B {
>   template 
>   B(Ty);
>   B(int X) : B((float)X) {}
> };
> 
> struct C {
>   C(auto);
>   C(int) : C("") {}
> };
> ```
I fully agree to you that these test cases should also work but that goes 
beyond the scope of a "simple" delegating ctor output fix.

In the current implementation all implicitly specialized templates are output 
and therefore the generated code is not correct C++ anymore, see 
https://godbolt.org/z/34xaoYW5n . I think it is not a good idea to check for 
incorrect C++ code in a test case...

I am currently focusing to get non-templated C++ code output correctly. For 
methods e.g. there are many problems with the correct position of attributes. I 
will address that in one of my next merge request and I want to put all method 
related tests into ast-print-method-decl.cpp . Therefore, I would like to keep 
the name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154186

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-06-30 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a reviewer: aaron.ballman.
strimo378 added a project: clang.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a subscriber: cfe-commits.

DeclPrinter::PrintConstructorInitializers did not consider delegating 
initializers. As result, the output contained an "NULL TYPE" for delegating 
constructors.

I chose a generic test case name (ast-print-method-decl.cpp). The plan is to 
add there other method related test cases for fixes I have in my local branch.

Please use "Timo Stripf" and timo.str...@emmtrix.com for commit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154186

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-method-decl.cpp


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }


Index: clang/test/AST/ast-print-method-decl.cpp
===
--- /dev/null
+++ clang/test/AST/ast-print-method-decl.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -ast-print %s -o - | FileCheck %s
+
+// CHECK: struct A {
+struct A {
+  // CHECK-NEXT: A();
+  A();
+
+  // CHECK-NEXT: A(int) : A() {
+  A(int) : A() {
+// CHECK-NEXT: }
+  }
+
+
+  // CHECK-NEXT: };
+};
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -321,6 +321,8 @@
 if (BMInitializer->isAnyMemberInitializer()) {
   FieldDecl *FD = BMInitializer->getAnyMember();
   Out << *FD;
+} else if (BMInitializer->isDelegatingInitializer()) {
+  Out << CDecl->getNameAsString();
 } else {
   Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139267: Supporting tbaa.struct metadata generation for bitfields

2023-06-30 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

Ping


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

https://reviews.llvm.org/D139267

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151528: [clang][DeclPrinter] Fix AST print of out-of-line record definitions

2023-06-06 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.

Please use "Timo Stripf" and timo.str...@emmtrix.com

Thank you for your review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151528

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139267: Supporting tbaa.struct metadata generation for bitfields

2023-05-24 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 updated this revision to Diff 525387.
strimo378 added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

- Updated a test case
- Supporting correct output for -new-struct-path-tbaa
- Added a paragraph to LangRef.rst (see 
https://discourse.llvm.org/t/rfc-clearify-tbaa-struct-requirements-within-language-reference/70835
 )


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

https://reviews.llvm.org/D139267

Files:
  clang/lib/CodeGen/CodeGenTBAA.cpp
  clang/lib/CodeGen/CodeGenTBAA.h
  clang/test/CodeGen/tbaa-struct.cpp
  llvm/docs/LangRef.rst

Index: llvm/docs/LangRef.rst
===
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -6406,6 +6406,11 @@
 4 byte gap between the two fields. This gap represents padding which
 does not carry useful data and need not be preserved.
 
+The order of the fields is unspecified. The byte range
+[offset, offset + size) of two fields must not overlap. The size
+of one field might be greater than the size of its TBAA tag (e.g. in
+case of arrays) or might be smaller (e.g. in case of bitfields).
+
 '``noalias``' and '``alias.scope``' Metadata
 
 
Index: clang/test/CodeGen/tbaa-struct.cpp
===
--- clang/test/CodeGen/tbaa-struct.cpp
+++ clang/test/CodeGen/tbaa-struct.cpp
@@ -102,6 +102,32 @@
   *a1 = *a2;
 }
 
+struct E {
+  int : 8;
+  int a1 : 8;
+  int : 8;
+  int a2 : 8;
+  
+  int b1 : 9;
+  int : (32-9-9);
+  int b2 : 9;
+
+  int c1 : 15;
+  int c2 : 1;
+  int c3 : 1;
+  int : (32-15-1-1);
+  
+  char dummy[4];
+};
+
+void copy8(E *e1, E *e2) {
+// CHECK-LABEL: _Z5copy8P1ES0_
+// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %{{.*}}, ptr noundef nonnull align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false)
+// CHECK-OLD-SAME: !tbaa.struct [[TS6:!.*]]
+// CHECK-NEW-SAME: !tbaa [[TAG_E:![0-9]*]]
+  *e1 = *e2;
+}
+
 // CHECK-OLD: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}}
 // CHECK-OLD: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}}
 // CHECK-OLD: [[TAG_INT:!.*]] = !{[[INT:!.*]], [[INT]], i64 0}
@@ -113,6 +139,7 @@
 // CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}}
 // CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]}
 // CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]}
+// CHECK-OLD: [[TS6]] = !{i64 1, i64 1, [[TAG_INT]], i64 3, i64 1, [[TAG_INT]], i64 4, i64 2, [[TAG_INT]], i64 6, i64 2, [[TAG_INT]], i64 8, i64 2, [[TAG_INT]], i64 10, i64 1, [[TAG_INT]], i64 12, i64 4, [[TAG_CHAR]]}
 
 // CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"}
 // CHECK-NEW-DAG: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0, i64 0}
@@ -127,3 +154,5 @@
 // CHECK-NEW-DAG: [[TAG_C]] = !{[[TYPE_C]], [[TYPE_C]], i64 0, i64 3}
 // CHECK-NEW-DAG: [[TYPE_D:!.*]] = !{[[TYPE_char]], i64 6, !"_ZTS1D", [[TYPE_char]], i64 0, i64 1, [[TYPE_char]], i64 4, i64 1, [[TYPE_char]], i64 5, i64 1}
 // CHECK-NEW-DAG: [[TAG_D]] = !{[[TYPE_D]], [[TYPE_D]], i64 0, i64 6}
+// CHECK-NEW-DAG: [[TYPE_E:!.*]] = !{[[TYPE_char]], i64 16, !"_ZTS1E", [[TYPE_int]], i64 1, i64 1, [[TYPE_int]], i64 3, i64 1, [[TYPE_int]], i64 4, i64 2, [[TYPE_int]], i64 6, i64 2, [[TYPE_int]], i64 8, i64 2, [[TYPE_int]], i64 9, i64 1, [[TYPE_int]], i64 10, i64 1, [[TYPE_char]], i64 12, i64 4}
+// CHECK-NEW-DAG: [[TAG_E]] = !{[[TYPE_E]], [[TYPE_E]], i64 0, i64 16}
Index: clang/lib/CodeGen/CodeGenTBAA.h
===
--- clang/lib/CodeGen/CodeGenTBAA.h
+++ clang/lib/CodeGen/CodeGenTBAA.h
@@ -146,6 +146,12 @@
   /// considered to be equivalent to it.
   llvm::MDNode *getChar();
 
+  /// AddCollectedField - Add one collected field to Fields vector
+  void
+  AddCollectedField(SmallVectorImpl ,
+uint64_t Offset, uint64_t Size, QualType QTy, bool MayAlias,
+bool FuseOverlapping);
+
   /// CollectFields - Collect information about the fields of a type for
   /// !tbaa.struct metadata formation. Return false for an unsupported type.
   bool CollectFields(uint64_t BaseOffset,
Index: clang/lib/CodeGen/CodeGenTBAA.cpp
===
--- clang/lib/CodeGen/CodeGenTBAA.cpp
+++ clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -272,13 +272,44 @@
 Size);
 }
 
+void CodeGenTBAA::AddCollectedField(
+SmallVectorImpl , uint64_t Offset,
+uint64_t Size, QualType QTy, bool MayAlias, bool FuseOverlapping) {
+
+  // Fuse fields that overlap in their byte position (e.g. caused by bitfields)
+  if (FuseOverlapping && !Fields.empty() && Fields.back().Offset <= Offset &&
+  Offset < 

[PATCH] D139267: Supporting tbaa.struct metadata generation for bitfields

2022-12-03 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 created this revision.
strimo378 added a project: clang.
Herald added subscribers: jeroen.dobbelaere, kosarev.
Herald added a project: All.
strimo378 requested review of this revision.
Herald added a subscriber: cfe-commits.

Hi all,

this is my first contribution to the LLVM project.

The patch adds support for generating the tbaa.struct metadata for structs 
containing bitfields. The current implementation does not support bitfields and 
even generates wrong tbaa.struct metadata ... see 
https://github.com/llvm/llvm-project/issues/59328 .

The patch is not yet finished. I need some help to create an appropriate test 
case. My first test case looks like that

  struct a {
int : 8;
int b1 : 4;
int b2 : 8;
  };
  a i1,i2;
  void c() { i1 = i2; }

and should generate the following metadata

call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 bitcast (%struct.a* @i1 to 
i8*), i8* align 4 bitcast (%struct.a* @i2 to i8*), i64 4, i1 false), 
!tbaa.struct !3
  ...
!3 = !{i64 1, i64 2, !4}

Furthermore, I am unsure what Type should be used for adding bitfields to 
tbaa.struct. The original type or char? The current implementation uses the 
original type (if not alias).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139267

Files:
  clang/lib/CodeGen/CodeGenTBAA.cpp
  clang/lib/CodeGen/CodeGenTBAA.h


Index: clang/lib/CodeGen/CodeGenTBAA.h
===
--- clang/lib/CodeGen/CodeGenTBAA.h
+++ clang/lib/CodeGen/CodeGenTBAA.h
@@ -146,6 +146,12 @@
   /// considered to be equivalent to it.
   llvm::MDNode *getChar();
 
+  /// AddCollectedField - Add one collected field to Fields vector
+  void
+  AddCollectedField(SmallVectorImpl ,
+uint64_t Offset, uint64_t Size, QualType QTy, bool 
MayAlias,
+bool FuseOverlapping);
+
   /// CollectFields - Collect information about the fields of a type for
   /// !tbaa.struct metadata formation. Return false for an unsupported type.
   bool CollectFields(uint64_t BaseOffset,
Index: clang/lib/CodeGen/CodeGenTBAA.cpp
===
--- clang/lib/CodeGen/CodeGenTBAA.cpp
+++ clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -272,13 +272,28 @@
 Size);
 }
 
+void CodeGenTBAA::AddCollectedField(
+SmallVectorImpl , uint64_t Offset,
+uint64_t Size, QualType QTy, bool MayAlias, bool FuseOverlapping) {
+
+  // Fuse fields that overlap in their byte position (e.g. caused by bitfields)
+  if (FuseOverlapping && !Fields.empty() && Offset < Fields.back().Offset + 
Fields.back().Size) {
+Fields.back().Size = Fields.back().Offset - Offset + Size;
+return;
+  }
+
+  llvm::MDNode *TBAAType = MayAlias ? getChar() : getTypeInfo(QTy);
+  llvm::MDNode *TBAATag = getAccessTagInfo(TBAAAccessInfo(TBAAType, Size));
+  Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
+}
+
 bool
 CodeGenTBAA::CollectFields(uint64_t BaseOffset,
QualType QTy,
SmallVectorImpl &
  Fields,
bool MayAlias) {
-  /* Things not handled yet include: C++ base classes, bitfields, */
+  /* Things not handled yet include: C++ base classes */
 
   if (const RecordType *TTy = QTy->getAs()) {
 const RecordDecl *RD = TTy->getDecl()->getDefinition();
@@ -300,19 +315,25 @@
   uint64_t Offset = BaseOffset +
 Layout.getFieldOffset(idx) / Context.getCharWidth();
   QualType FieldQTy = i->getType();
-  if (!CollectFields(Offset, FieldQTy, Fields,
- MayAlias || TypeHasMayAlias(FieldQTy)))
-return false;
+  bool FieldMayAlias = MayAlias || TypeHasMayAlias(FieldQTy);
+  if ((*i)->isBitField()) {
+uint64_t EndOffset =
+BaseOffset +
+(Layout.getFieldOffset(idx) + (*i)->getBitWidthValue(Context) - 1) 
/
+Context.getCharWidth();
+
+AddCollectedField(Fields, Offset, EndOffset - Offset + 1, QTy, 
FieldMayAlias, true);
+  } else {
+if (!CollectFields(Offset, FieldQTy, Fields, FieldMayAlias))
+  return false;
+  }
 }
 return true;
   }
 
   /* Otherwise, treat whatever it is as a field. */
-  uint64_t Offset = BaseOffset;
   uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity();
-  llvm::MDNode *TBAAType = MayAlias ? getChar() : getTypeInfo(QTy);
-  llvm::MDNode *TBAATag = getAccessTagInfo(TBAAAccessInfo(TBAAType, Size));
-  Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
+  AddCollectedField(Fields, BaseOffset, Size, QTy, MayAlias, false);
   return true;
 }
 


Index: clang/lib/CodeGen/CodeGenTBAA.h
===
--- clang/lib/CodeGen/CodeGenTBAA.h
+++ clang/lib/CodeGen/CodeGenTBAA.h
@@ -146,6 +146,12 @@
   /// considered to be equivalent to it.