[PATCH] D158006: [Clang][WIP]Experimental implementation of data member packs in dependent context.

2023-08-17 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao added inline comments.



Comment at: clang/test/CodeGenCXX/data_member_packs.cpp:73
+  // CHECK: i32 @_Z3sumIJiiEEDaDpT_(i32 noundef %ts, i32 noundef %ts1)
+  sum_pack2(s6);
+  // Check instantiation of sum(int, long, float, double)

cjdb wrote:
> This needs to be passed to one of the sum functions and checked that it's 
> generating the correct code.
It's passed to `sum` and generation of `sum(int, int)` is checked.



Comment at: clang/test/CodeGenCXX/data_member_packs.cpp:76
+  // CHECK: double @_Z3sumIJilfdEEDaDpT_(i32 noundef %ts, i64 noundef %ts1, 
float noundef %ts3, double noundef %ts5)
+  S4{}.sum_pack(s7);
+  return 0;

denik wrote:
> This is a good test case!
> I would also add a test for the partial expansion of the member pack. And 
> also checking the right order of the fields. Something like:
> ```
> template constexpr auto foo(T t) { return t; }
> template constexpr auto foo(T t, Ts ... ts) { 
> return t + 2 * foo(ts...); }
> 
> S1 s = {1,2,3};
> static_assert(foo(s.ts...) == 17);
> ```
> 
We can't check the runtime state in LLVM/Clang tests. I added a test case for 
partial expansion and checked the IR. The order of fields can be checked by 
looking at the order of types in the instantiation of `sum`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158006

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


[PATCH] D158006: [Clang][WIP]Experimental implementation of data member packs in dependent context.

2023-08-17 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 551348.
SlaterLatiao marked an inline comment as done.
SlaterLatiao added a comment.

- Added test case for partial expansion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158006

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- clang/test/CodeGenCXX/data_member_packs.cpp
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -10,6 +10,11 @@
 Ts... ts;
 };
 
+template struct S3 {
+T t;
+Ts... ts;
+};
+
 // CHECK: %struct.S1 = type { i32 }
 S1 s1;
 // CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
@@ -28,3 +33,58 @@
 // CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
 S1 s6;
 
+S1 s7;
+
+template auto sum(Ts... ts) {
+  return (ts + ...);
+}
+
+template auto partial_sum(T t, Ts... ts) {
+  return sum(ts...);
+}
+
+template auto partial_sum(S1 s) {
+  return partial_sum(s.ts...);
+}
+
+auto take_empty() {
+  return 0;
+}
+
+template auto sum_pack(S1 s) {
+  return sum(s.ts...);
+}
+// Test template arg + expansion.
+template auto sum_pack2(S1 s) {
+  return sum(s.ts...);
+}
+// Test empty expansion.
+template auto take_empty(S3 s) {
+  return take_empty(s.ts...);
+}
+// Test nested template args and multiple expansions.
+template struct S4 {
+  template auto sum_pack(S1 s) {
+return sum(s.ts...);
+  }
+};
+
+int main() {
+  // Check calling take_empty()
+  // CHECK: %call = call noundef i32 @_Z10take_emptyv()
+  take_empty(S3{});
+  // Check instantiation of sum(int, float, double)
+  // CHECK: double @_Z3sumIJifdEEDaDpT_(i32 noundef %ts, float noundef %ts1, double noundef %ts3)
+  sum_pack(s2);
+  // Check instantiation of sum(int, int)
+  // CHECK: i32 @_Z3sumIJiiEEDaDpT_(i32 noundef %ts, i32 noundef %ts1)
+  sum_pack2(s6);
+  // Check instantiation of sum(int, long, float, double)
+  // CHECK: double @_Z3sumIJilfdEEDaDpT_(i32 noundef %ts, i64 noundef %ts1, float noundef %ts3, double noundef %ts5)
+  S4{}.sum_pack(s7);
+  // Check instantiation of sum(long, float, double)
+  // CHECK: double @_Z3sumIJlfdEEDaDpT_(i64 noundef %ts, float noundef %ts1, double noundef %ts3)
+  partial_sum(s7);
+  return 0;
+}
+
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4150,11 +4150,67 @@
Parens.getEnd());
 }
 
+template 
+bool TransformExprsOnMemberPack(Derived , Sema ,
+   bool *ArgChanged,
+   SmallVectorImpl ,
+   const CXXDependentScopeMemberExpr *MemberExpr) {
+  if (ArgChanged)
+*ArgChanged = true;
+  assert(MemberExpr->isMemberPackAccess() &&
+ "trying to expand non-pack member access");
+  std::string UnExpandedNameStr =
+  MemberExpr->getMemberNameInfo().getName().getAsString();
+
+  ExprResult Base = DerivedRef.TransformExpr(MemberExpr->getBase());
+  if (Base.isInvalid())
+return true;
+  QualType BaseType = ((Expr *)Base.get())->getType();
+  if (MemberExpr->isArrow()) {
+assert(BaseType->isPointerType());
+BaseType = BaseType->castAs()->getPointeeType();
+  }
+
+  unsigned Arg = 0;
+  while (true) {
+Twine ExpandedNameStr = Twine(UnExpandedNameStr) + "@" + Twine(Arg);
+// Transform unexpanded field name and create a new member
+// expression.
+DeclarationName ExpandedName =
+(ExpandedNameStr.str());
+// Construct name info with new name and keep other members the same.
+DeclarationNameInfo ExpandedNameInfo = DeclarationNameInfo(
+ExpandedName, MemberExpr->getMemberNameInfo().getLoc(),
+MemberExpr->getMemberNameInfo().getInfo());
+TemplateArgumentListInfo TemplateArgs = TemplateArgumentListInfo();
+MemberExpr->copyTemplateArgumentsInto(TemplateArgs);
+auto *ExpandedMemberExpr = CXXDependentScopeMemberExpr::Create(
+SemaRef.Context, MemberExpr->getBase(), MemberExpr->getBaseType(),
+MemberExpr->isArrow(), MemberExpr->getOperatorLoc(),
+MemberExpr->getQualifierLoc(), MemberExpr->getTemplateKeywordLoc(),
+MemberExpr->getFirstQualifierFoundInScope(), ExpandedNameInfo,
+, MemberExpr->isMemberPackAccess());
+
+Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, Arg);
+ExprResult Out = DerivedRef.TransformExpr(ExpandedMemberExpr);
+if (Out.isInvalid())
+  return true;
+// An empty expression is returned when name lookup fails in accessing
+// member packs. This means the last field in member pack has been
+// 

[PATCH] D158006: [Clang][WIP]Experimental implementation of data member packs in dependent context.

2023-08-17 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao marked 4 inline comments as done.
SlaterLatiao added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:4171
 
+  if (CXXDependentScopeMemberExpr *MemberExpr =
+  dyn_cast(Pattern)) {

dblaikie wrote:
> Might be worth pulling out this new code as a separate function - the 
> `continue` at the end is many lines away from the start or end of the loop, 
> making control flow a bit hard to follow (probably the existing code could do 
> with some of this massaging even before/regardless of the new code you're 
> adding here)
Made the logic a separate function and added a comment to explain the 
`continue`. 



Comment at: clang/lib/Sema/TreeTransform.h:4198-4199
+  MemberExpr->getMemberNameInfo().getInfo());
+  TemplateArgumentListInfo TemplateArgs = TemplateArgumentListInfo();
+  MemberExpr->copyTemplateArgumentsInto(TemplateArgs);
+  auto *ExpandedMemberExpr = CXXDependentScopeMemberExpr::Create(

denik wrote:
> Why is this in a loop?
Each field need to have its own `MemberAccessExpression`. This loop iterates 
through the expanded fields.



Comment at: clang/lib/Sema/TreeTransform.h:4208
+
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), Arg);
+  ExprResult Out = getDerived().TransformExpr(ExpandedMemberExpr);

denik wrote:
> Can we add a check that Arg never exceeds the number of arguments in the full 
> expansion (is it Expansion->getNumExpansions()?)
`Expansion->getNumExpansions()` returns the number of expansions only when we 
know it. In this case it returns `std::nullopt`.
A more legit way to check `Arg` is to search for the specialization of  the 
struct based on the template args of the current context, but I didn't find a 
proper way to achieve that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158006

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


[PATCH] D158006: [Clang][WIP]Experimental implementation of data member packs in dependent context.

2023-08-17 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 551342.
SlaterLatiao added a comment.

- Make transforming expressions for member packs a separate function.
- Minor edits based on review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158006

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- clang/test/CodeGenCXX/data_member_packs.cpp
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -10,6 +10,11 @@
 Ts... ts;
 };
 
+template struct S3 {
+T t;
+Ts... ts;
+};
+
 // CHECK: %struct.S1 = type { i32 }
 S1 s1;
 // CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
@@ -28,3 +33,47 @@
 // CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
 S1 s6;
 
+S1 s7;
+
+template auto sum(Ts... ts) {
+  return (ts + ...);
+}
+
+auto take_empty() {
+  return 0;
+}
+
+template auto sum_pack(S1 s) {
+  return sum(s.ts...);
+}
+// Test template arg + expansion.
+template auto sum_pack2(S1 s) {
+  return sum(s.ts...);
+}
+// Test empty expansion.
+template auto take_empty(S3 s) {
+  return take_empty(s.ts...);
+}
+// Test nested template args and multiple expansions.
+template struct S4 {
+  template auto sum_pack(S1 s) {
+return sum(s.ts...);
+  }
+};
+
+int main() {
+  // Check calling take_empty()
+  // CHECK: %call = call noundef i32 @_Z10take_emptyv()
+  take_empty(S3{});
+  // Check instantiation of sum(int, float, double)
+  // CHECK: double @_Z3sumIJifdEEDaDpT_(i32 noundef %ts, float noundef %ts1, double noundef %ts3)
+  sum_pack(s2);
+  // Check instantiation of sum(int, int)
+  // CHECK: i32 @_Z3sumIJiiEEDaDpT_(i32 noundef %ts, i32 noundef %ts1)
+  sum_pack2(s6);
+  // Check instantiation of sum(int, long, float, double)
+  // CHECK: double @_Z3sumIJilfdEEDaDpT_(i32 noundef %ts, i64 noundef %ts1, float noundef %ts3, double noundef %ts5)
+  S4{}.sum_pack(s7);
+  return 0;
+}
+
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4150,11 +4150,67 @@
Parens.getEnd());
 }
 
+template 
+bool TransformExprsOnMemberPack(Derived , Sema ,
+   bool *ArgChanged,
+   SmallVectorImpl ,
+   const CXXDependentScopeMemberExpr *MemberExpr) {
+  if (ArgChanged)
+*ArgChanged = true;
+  assert(MemberExpr->isMemberPackAccess() &&
+ "trying to expand non-pack member access");
+  std::string UnExpandedNameStr =
+  MemberExpr->getMemberNameInfo().getName().getAsString();
+
+  ExprResult Base = DerivedRef.TransformExpr(MemberExpr->getBase());
+  if (Base.isInvalid())
+return true;
+  QualType BaseType = ((Expr *)Base.get())->getType();
+  if (MemberExpr->isArrow()) {
+assert(BaseType->isPointerType());
+BaseType = BaseType->castAs()->getPointeeType();
+  }
+
+  unsigned Arg = 0;
+  while (true) {
+Twine ExpandedNameStr = Twine(UnExpandedNameStr) + "@" + Twine(Arg);
+// Transform unexpanded field name and create a new member
+// expression.
+DeclarationName ExpandedName =
+(ExpandedNameStr.str());
+// Construct name info with new name and keep other members the same.
+DeclarationNameInfo ExpandedNameInfo = DeclarationNameInfo(
+ExpandedName, MemberExpr->getMemberNameInfo().getLoc(),
+MemberExpr->getMemberNameInfo().getInfo());
+TemplateArgumentListInfo TemplateArgs = TemplateArgumentListInfo();
+MemberExpr->copyTemplateArgumentsInto(TemplateArgs);
+auto *ExpandedMemberExpr = CXXDependentScopeMemberExpr::Create(
+SemaRef.Context, MemberExpr->getBase(), MemberExpr->getBaseType(),
+MemberExpr->isArrow(), MemberExpr->getOperatorLoc(),
+MemberExpr->getQualifierLoc(), MemberExpr->getTemplateKeywordLoc(),
+MemberExpr->getFirstQualifierFoundInScope(), ExpandedNameInfo,
+, MemberExpr->isMemberPackAccess());
+
+Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, Arg);
+ExprResult Out = DerivedRef.TransformExpr(ExpandedMemberExpr);
+if (Out.isInvalid())
+  return true;
+// An empty expression is returned when name lookup fails in accessing
+// member packs. This means the last field in member pack has been
+// processd and time to exit the loop.
+if (Out.isUnset())
+  break;
+Outputs.push_back(Out.get());
+++Arg;
+  }
+  return false;
+}
+
 template
 bool TreeTransform::TransformExprs(Expr *const *Inputs,
 unsigned NumInputs,
 

[PATCH] D158006: [Clang][WIP]Experimental implementation of data member packs in dependent context.

2023-08-17 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 551337.
SlaterLatiao added a comment.

- Minor fix on comment.
- Replace string '+' with Twine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158006

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- clang/test/CodeGenCXX/data_member_packs.cpp
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -10,6 +10,11 @@
 Ts... ts;
 };
 
+template struct S3 {
+T t;
+Ts... ts;
+};
+
 // CHECK: %struct.S1 = type { i32 }
 S1 s1;
 // CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
@@ -28,3 +33,47 @@
 // CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
 S1 s6;
 
+S1 s7;
+
+template auto sum(Ts... ts) {
+  return (ts + ...);
+}
+
+auto take_empty() {
+  return 0;
+}
+
+template auto sum_pack(S1 s) {
+  return sum(s.ts...);
+}
+// Test template arg + expansion.
+template auto sum_pack2(S1 s) {
+  return sum(s.ts...);
+}
+// Test empty expansion.
+template auto take_empty(S3 s) {
+  return take_empty(s.ts...);
+}
+// Test nested template args and multiple expansions.
+template struct S4 {
+  template auto sum_pack(S1 s) {
+return sum(s.ts...);
+  }
+};
+
+int main() {
+  // Check calling take_empty()
+  // CHECK: %call = call noundef i32 @_Z10take_emptyv()
+  take_empty(S3{});
+  // Check instantiation of sum(int, float, double)
+  // CHECK: double @_Z3sumIJifdEEDaDpT_(i32 noundef %ts, float noundef %ts1, double noundef %ts3)
+  sum_pack(s2);
+  // Check instantiation of sum(int, int)
+  // CHECK: i32 @_Z3sumIJiiEEDaDpT_(i32 noundef %ts, i32 noundef %ts1)
+  sum_pack2(s6);
+  // Check instantiation of sum(int, long, float, double)
+  // CHECK: double @_Z3sumIJilfdEEDaDpT_(i32 noundef %ts, i64 noundef %ts1, float noundef %ts3, double noundef %ts5)
+  S4{}.sum_pack(s7);
+  return 0;
+}
+
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4168,6 +4168,60 @@
 if (PackExpansionExpr *Expansion = dyn_cast(Inputs[I])) {
   Expr *Pattern = Expansion->getPattern();
 
+  if (CXXDependentScopeMemberExpr *MemberExpr =
+  dyn_cast(Pattern)) {
+if (ArgChanged)
+  *ArgChanged = true;
+assert(MemberExpr->isMemberPackAccess() &&
+   "trying to expand non-pack member access");
+std::string UnExpanedNameStr =
+MemberExpr->getMemberNameInfo().getName().getAsString();
+
+ExprResult Base = getDerived().TransformExpr(MemberExpr->getBase());
+if (Base.isInvalid())
+  return true;
+QualType BaseType = ((Expr *)Base.get())->getType();
+if (MemberExpr->isArrow()) {
+  assert(BaseType->isPointerType());
+  BaseType = BaseType->castAs()->getPointeeType();
+}
+
+unsigned Arg = 0;
+while (true) {
+  Twine ExpandedNameStr = Twine(UnExpanedNameStr) + "@" + Twine(Arg);
+  // Transform unexpanded field name and create a new member
+  // expression.
+  DeclarationName ExpandedName =
+  (ExpandedNameStr.str());
+  // Construct name info with new name and keep other members the same.
+  DeclarationNameInfo ExpandedNameInfo = DeclarationNameInfo(
+  ExpandedName, MemberExpr->getMemberNameInfo().getLoc(),
+  MemberExpr->getMemberNameInfo().getInfo());
+  TemplateArgumentListInfo TemplateArgs = TemplateArgumentListInfo();
+  MemberExpr->copyTemplateArgumentsInto(TemplateArgs);
+  auto *ExpandedMemberExpr = CXXDependentScopeMemberExpr::Create(
+  SemaRef.Context, MemberExpr->getBase(), MemberExpr->getBaseType(),
+  MemberExpr->isArrow(), MemberExpr->getOperatorLoc(),
+  MemberExpr->getQualifierLoc(),
+  MemberExpr->getTemplateKeywordLoc(),
+  MemberExpr->getFirstQualifierFoundInScope(), ExpandedNameInfo,
+  , MemberExpr->isMemberPackAccess());
+
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), Arg);
+  ExprResult Out = getDerived().TransformExpr(ExpandedMemberExpr);
+  if (Out.isInvalid())
+return true;
+  // An empty expression is returned when name lookup fails in accessing
+  // member packs. This means the last field in member pack has been
+  // processd and time to exit the loop.
+  if (Out.isUnset())
+break;
+  Outputs.push_back(Out.get());
+  Arg++;
+}
+continue;
+  }
+
   

[PATCH] D158006: [Clang][WIP]Experimental implementation of data member packs in dependent context.

2023-08-17 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 551253.
SlaterLatiao marked 2 inline comments as done.
SlaterLatiao added a comment.

Remove changes in D156546  which doesn't 
belong to this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158006

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- clang/test/CodeGenCXX/data_member_packs.cpp
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -10,6 +10,11 @@
 Ts... ts;
 };
 
+template struct S3 {
+T t;
+Ts... ts;
+};
+
 // CHECK: %struct.S1 = type { i32 }
 S1 s1;
 // CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
@@ -28,3 +33,47 @@
 // CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
 S1 s6;
 
+S1 s7;
+
+template auto sum(Ts... ts) {
+  return (ts + ...);
+}
+
+auto take_empty() {
+  return 0;
+}
+
+template auto sum_pack(S1 s) {
+  return sum(s.ts...);
+}
+// Test template arg + expansion.
+template auto sum_pack2(S1 s) {
+  return sum(s.ts...);
+}
+// Test empty expansion.
+template auto take_empty(S3 s) {
+  return take_empty(s.ts...);
+}
+// Test nested template args and multiple expansions.
+template struct S4 {
+  template auto sum_pack(S1 s) {
+return sum(s.ts...);
+  }
+};
+
+int main() {
+  // Check calling take_empty()
+  // CHECK: %call = call noundef i32 @_Z10take_emptyv()
+  take_empty(S3{});
+  // Check instantiation of sum(int, float, double)
+  // CHECK: double @_Z3sumIJifdEEDaDpT_(i32 noundef %ts, float noundef %ts1, double noundef %ts3)
+  sum_pack(s2);
+  // Check instantiation of sum(int, int)
+  // CHECK: i32 @_Z3sumIJiiEEDaDpT_(i32 noundef %ts, i32 noundef %ts1)
+  sum_pack2(s6);
+  // Check instantiation of sum(int, long, float, double)
+  // CHECK: double @_Z3sumIJilfdEEDaDpT_(i32 noundef %ts, i64 noundef %ts1, float noundef %ts3, double noundef %ts5)
+  S4{}.sum_pack(s7);
+  return 0;
+}
+
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4168,6 +4168,58 @@
 if (PackExpansionExpr *Expansion = dyn_cast(Inputs[I])) {
   Expr *Pattern = Expansion->getPattern();
 
+  if (CXXDependentScopeMemberExpr *MemberExpr =
+  dyn_cast(Pattern)) {
+if (ArgChanged)
+  *ArgChanged = true;
+assert(MemberExpr->isMemberPackAccess() &&
+   "trying to expand non-pack member access");
+std::string UnExpanedNameStr =
+MemberExpr->getMemberNameInfo().getName().getAsString();
+
+ExprResult Base = getDerived().TransformExpr(MemberExpr->getBase());
+if (Base.isInvalid())
+  return true;
+QualType BaseType = ((Expr *)Base.get())->getType();
+if (MemberExpr->isArrow()) {
+  assert(BaseType->isPointerType());
+  BaseType = BaseType->castAs()->getPointeeType();
+}
+
+unsigned Arg = 0;
+while (true) {
+  // Transform unexpanded field name and create a new member expression.
+  DeclarationName ExpandedName = (
+  UnExpanedNameStr + "@" + std::to_string(Arg));
+  // Construct name info with new name and keep other members the same.
+  DeclarationNameInfo ExpandedNameInfo = DeclarationNameInfo(
+  ExpandedName, MemberExpr->getMemberNameInfo().getLoc(),
+  MemberExpr->getMemberNameInfo().getInfo());
+  TemplateArgumentListInfo TemplateArgs = TemplateArgumentListInfo();
+  MemberExpr->copyTemplateArgumentsInto(TemplateArgs);
+  auto *ExpandedMemberExpr = CXXDependentScopeMemberExpr::Create(
+  SemaRef.Context, MemberExpr->getBase(), MemberExpr->getBaseType(),
+  MemberExpr->isArrow(), MemberExpr->getOperatorLoc(),
+  MemberExpr->getQualifierLoc(),
+  MemberExpr->getTemplateKeywordLoc(),
+  MemberExpr->getFirstQualifierFoundInScope(), ExpandedNameInfo,
+  , MemberExpr->isMemberPackAccess());
+
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), Arg);
+  ExprResult Out = getDerived().TransformExpr(ExpandedMemberExpr);
+  if (Out.isInvalid())
+return true;
+  // An empty expression is returned when name lookup fails in accessing
+  // member packs. This means the last field in member pack has been
+  // processd and time to exit the loop.
+  if (Out.isUnset())
+break;
+  Outputs.push_back(Out.get());
+  Arg++;
+}
+continue;
+  }

[PATCH] D158006: [Clang][WIP]Experimental implementation of data member packs in dependent context.

2023-08-17 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao marked 6 inline comments as done.
SlaterLatiao added inline comments.



Comment at: clang/lib/Sema/SemaExprMember.cpp:523-524
+  auto *TD = TST->getTemplateName().getAsTemplateDecl();
+  assert(isa(TD) &&
+ "template decl in member access is not ClassTemplateDecl");
+  for (FieldDecl *Field :

dblaikie wrote:
> No need for the assert if you're immediately going to `cast` anyway, it'll 
> assert. Though perhaps the custom assert here gives you a chance to make it 
> more explicit that this is intentional.
Removed the assert.



Comment at: clang/lib/Sema/SemaExprMember.cpp:525-527
+  for (FieldDecl *Field :
+   cast(TD)->getTemplatedDecl()->fields()) {
+if (Field->getDeclName() == NameInfo.getName()) {

dblaikie wrote:
> This could be `llvm::find_if`, maybe? Not sure if it'd be tidier, but maybe 
> more legible
Rewrote with `llvm::find_if`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158006

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


[PATCH] D158006: [Clang][WIP]Experimental implementation of data member packs in dependent context.

2023-08-17 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 551249.
SlaterLatiao added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158006

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 --std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefixes=CHECK
+
+// Tests declaration data member packs.
+template struct S1 {
+Ts... ts;
+};
+
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+
+template struct S3 {
+T t;
+Ts... ts;
+};
+
+// CHECK: %struct.S1 = type { i32 }
+S1 s1;
+// CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
+S1 s2;
+// Test template args as the last arg.
+// CHECK-NEXT: %struct.S2 = type { [2 x i32], float, double }
+S2 s3;
+// Test nested template args.
+// CHECK-NEXT: %struct.S1.1 = type { i32, float, %struct.S1.2 }
+// CHECK-NEXT: %struct.S1.2 = type { double, double }
+S1> s4;
+// Test empty template arg.
+// CHECK-NEXT: %struct.S1.3 = type { i8 }
+S1<> s5;
+// Test duplicate types in template args.
+// CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
+S1 s6;
+
+S1 s7;
+
+template auto sum(Ts... ts) {
+  return (ts + ...);
+}
+
+auto take_empty() {
+  return 0;
+}
+
+template auto sum_pack(S1 s) {
+  return sum(s.ts...);
+}
+// Test template arg + expansion.
+template auto sum_pack2(S1 s) {
+  return sum(s.ts...);
+}
+// Test empty expansion.
+template auto take_empty(S3 s) {
+  return take_empty(s.ts...);
+}
+// Test nested template args and multiple expansions.
+template struct S4 {
+  template auto sum_pack(S1 s) {
+return sum(s.ts...);
+  }
+};
+
+int main() {
+  // Check calling take_empty()
+  // CHECK: %call = call noundef i32 @_Z10take_emptyv()
+  take_empty(S3{});
+  // Check instantiation of sum(int, float, double)
+  // CHECK: double @_Z3sumIJifdEEDaDpT_(i32 noundef %ts, float noundef %ts1, double noundef %ts3)
+  sum_pack(s2);
+  // Check instantiation of sum(int, int)
+  // CHECK: i32 @_Z3sumIJiiEEDaDpT_(i32 noundef %ts, i32 noundef %ts1)
+  sum_pack2(s6);
+  // Check instantiation of sum(int, long, float, double)
+  // CHECK: double @_Z3sumIJilfdEEDaDpT_(i32 noundef %ts, i64 noundef %ts1, float noundef %ts3, double noundef %ts5)
+  S4{}.sum_pack(s7);
+  return 0;
+}
+
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4168,6 +4168,58 @@
 if (PackExpansionExpr *Expansion = dyn_cast(Inputs[I])) {
   Expr *Pattern = Expansion->getPattern();
 
+  if (CXXDependentScopeMemberExpr *MemberExpr =
+  dyn_cast(Pattern)) {
+if (ArgChanged)
+  *ArgChanged = true;
+assert(MemberExpr->isMemberPackAccess() &&
+   "trying to expand non-pack member access");
+std::string UnExpanedNameStr =
+MemberExpr->getMemberNameInfo().getName().getAsString();
+
+ExprResult Base = getDerived().TransformExpr(MemberExpr->getBase());
+if (Base.isInvalid())
+  return true;
+QualType BaseType = ((Expr *)Base.get())->getType();
+if (MemberExpr->isArrow()) {
+  assert(BaseType->isPointerType());
+  BaseType = BaseType->castAs()->getPointeeType();
+}
+
+unsigned Arg = 0;
+while (true) {
+  // Transform unexpanded field name and create a new member expression.
+  DeclarationName ExpandedName = (
+  UnExpanedNameStr + "@" + std::to_string(Arg));
+  // Construct name info with new name and keep other members the same.
+  DeclarationNameInfo ExpandedNameInfo = DeclarationNameInfo(
+  ExpandedName, MemberExpr->getMemberNameInfo().getLoc(),
+  MemberExpr->getMemberNameInfo().getInfo());
+  TemplateArgumentListInfo TemplateArgs = TemplateArgumentListInfo();
+  MemberExpr->copyTemplateArgumentsInto(TemplateArgs);
+  auto *ExpandedMemberExpr = CXXDependentScopeMemberExpr::Create(
+  SemaRef.Context, MemberExpr->getBase(), MemberExpr->getBaseType(),
+  MemberExpr->isArrow(), MemberExpr->getOperatorLoc(),
+  MemberExpr->getQualifierLoc(),
+  MemberExpr->getTemplateKeywordLoc(),
+  MemberExpr->getFirstQualifierFoundInScope(), ExpandedNameInfo,
+  , MemberExpr->isMemberPackAccess());
+
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), Arg);
+ 

[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-08-16 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 550927.
SlaterLatiao added a comment.

- Refactor instantiating members into 2 functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 --std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefixes=CHECK
+
+// Tests declaration data member packs.
+template struct S1 {
+Ts... ts;
+};
+
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+
+// CHECK: %struct.S1 = type { i32 }
+S1 s1;
+// CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
+S1 s2;
+// Test template args as the last arg.
+// CHECK-NEXT: %struct.S2 = type { [2 x i32], float, double }
+S2 s3;
+// Test nested template args.
+// CHECK-NEXT: %struct.S1.1 = type { i32, float, %struct.S1.2 }
+// CHECK-NEXT: %struct.S1.2 = type { double, double }
+S1> s4;
+// Test empty template arg.
+// CHECK-NEXT: %struct.S1.3 = type { i8 }
+S1<> s5;
+// Test duplicate types in template args.
+// CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
+S1 s6;
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5927,6 +5927,9 @@
  /*ExpectPackInType=*/false);
   }
   break;
+case DeclaratorContext::Member:
+  // Expand for data member packs.
+  // https://discourse.llvm.org/t/adding-support-for-data-member-packs/71333
 case DeclaratorContext::TemplateParam:
   // C++0x [temp.param]p15:
   //   If a template-parameter is a [...] is a parameter-declaration that
@@ -5954,7 +5957,6 @@
 case DeclaratorContext::CXXNew:
 case DeclaratorContext::AliasDecl:
 case DeclaratorContext::AliasTemplate:
-case DeclaratorContext::Member:
 case DeclaratorContext::Block:
 case DeclaratorContext::ForInit:
 case DeclaratorContext::SelectionInit:
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3135,6 +3135,93 @@
   }
 }
 
+/// Instantiate the member pack of a class.
+void InstantiateMemberPack(Sema , CXXRecordDecl *Instantiation,
+   const MultiLevelTemplateArgumentList ,
+   FieldDecl *Field, SmallVector ,
+   TemplateDeclInstantiator ) {
+  QualType PatternType =
+  Field->getType()->castAs()->getPattern();
+  std::optional NumArgumentsInExpansion =
+  S.getNumArgumentsInExpansion(Field->getType(), TemplateArgs);
+  assert(NumArgumentsInExpansion &&
+ "should not see unknown template argument here");
+  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
+// Generate a new field from PackExpansion field.
+if (Decl *NewMember = Instantiator.Visit(Field)) {
+  FieldDecl *PackedField = cast(NewMember);
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(S, Arg);
+  QualType T =
+  S.SubstType(PatternType, TemplateArgs, PackedField->getLocation(),
+  PackedField->getDeclName());
+  PackedField->setType(T);
+  Fields.push_back(PackedField);
+  if (NewMember->isInvalidDecl()) {
+// When `NewMember` has type of `PackExpansionType`, it escapes
+// validation checks in `Visit`. Handling of such cases
+// will be implemented in a future commit.
+// Currently this branch should never be reached.
+assert(false && "not implemented");
+Instantiation->setInvalidDecl();
+  }
+} else {
+  // FIXME: This is the same situation of InstantiateMember, when handling
+  // non-pack members.
+  continue;
+}
+  }
+}
+
+/// Instantiate the non-pack members of a class.
+///
+/// \returns true if need to bail out the member instantiation ,loop, false otherwise.
+bool InstantiateMember(Sema , SourceLocation ,
+   CXXRecordDecl *Instantiation, Decl *Member,
+   TemplateSpecializationKind TSK,
+   SmallVector ,
+   TemplateDeclInstantiator ,
+   bool ) {
+  Decl *NewMember = Instantiator.Visit(Member);
+  if (NewMember) {
+if (FieldDecl *Field = dyn_cast(NewMember)) {
+  Fields.push_back(Field);
+} else if (EnumDecl *Enum = dyn_cast(NewMember)) {
+  // C++11 [temp.inst]p1: The implicit instantiation of a class template
+  // specialization causes the implicit instantiation of the definitions
+ 

[PATCH] D158006: Member pack access in dependent context.

2023-08-15 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao created this revision.
Herald added a project: All.
SlaterLatiao 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/D158006

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- clang/test/CodeGenCXX/data_member_packs.cpp
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -10,6 +10,11 @@
 Ts... ts;
 };
 
+template struct S3 {
+T t;
+Ts... ts;
+};
+
 // CHECK: %struct.S1 = type { i32 }
 S1 s1;
 // CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
@@ -28,3 +33,47 @@
 // CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
 S1 s6;
 
+S1 s7;
+
+template auto sum(Ts... ts) {
+  return (ts + ...);
+}
+
+auto take_empty() {
+  return 0;
+}
+
+template auto sum_pack(S1 s) {
+  return sum(s.ts...);
+}
+// Test template arg + expansion.
+template auto sum_pack2(S1 s) {
+  return sum(s.ts...);
+}
+// Test empty expansion.
+template auto take_empty(S3 s) {
+  return take_empty(s.ts...);
+}
+// Test nested template args and multiple expansions.
+template struct S4 {
+  template auto sum_pack(S1 s) {
+return sum(s.ts...);
+  }
+};
+
+int main() {
+  // Check calling take_empty()
+  // CHECK: %call = call noundef i32 @_Z10take_emptyv()
+  take_empty(S3{});
+  // Check instantiation of sum(int, float, double)
+  // CHECK: double @_Z3sumIJifdEEDaDpT_(i32 noundef %ts, float noundef %ts1, double noundef %ts3)
+  sum_pack(s2);
+  // Check instantiation of sum(int, int)
+  // CHECK: i32 @_Z3sumIJiiEEDaDpT_(i32 noundef %ts, i32 noundef %ts1)
+  sum_pack2(s6);
+  // Check instantiation of sum(int, long, float, double)
+  // CHECK: double @_Z3sumIJilfdEEDaDpT_(i32 noundef %ts, i64 noundef %ts1, float noundef %ts3, double noundef %ts5)
+  S4{}.sum_pack(s7);
+  return 0;
+}
+
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4168,6 +4168,58 @@
 if (PackExpansionExpr *Expansion = dyn_cast(Inputs[I])) {
   Expr *Pattern = Expansion->getPattern();
 
+  if (CXXDependentScopeMemberExpr *MemberExpr =
+  dyn_cast(Pattern)) {
+if (ArgChanged)
+  *ArgChanged = true;
+assert(MemberExpr->isMemberPackAccess() &&
+   "trying to expand non-pack member access");
+std::string UnExpanedNameStr =
+MemberExpr->getMemberNameInfo().getName().getAsString();
+
+ExprResult Base = getDerived().TransformExpr(MemberExpr->getBase());
+if (Base.isInvalid())
+  return true;
+QualType BaseType = ((Expr *)Base.get())->getType();
+if (MemberExpr->isArrow()) {
+  assert(BaseType->isPointerType());
+  BaseType = BaseType->castAs()->getPointeeType();
+}
+
+unsigned Arg = 0;
+while (true) {
+  // Transform unexpanded field name and create a new member expression.
+  DeclarationName ExpandedName = (
+  UnExpanedNameStr + "@" + std::to_string(Arg));
+  // Construct name info with new name and keep other members the same.
+  DeclarationNameInfo ExpandedNameInfo = DeclarationNameInfo(
+  ExpandedName, MemberExpr->getMemberNameInfo().getLoc(),
+  MemberExpr->getMemberNameInfo().getInfo());
+  TemplateArgumentListInfo TemplateArgs = TemplateArgumentListInfo();
+  MemberExpr->copyTemplateArgumentsInto(TemplateArgs);
+  auto *ExpandedMemberExpr = CXXDependentScopeMemberExpr::Create(
+  SemaRef.Context, MemberExpr->getBase(), MemberExpr->getBaseType(),
+  MemberExpr->isArrow(), MemberExpr->getOperatorLoc(),
+  MemberExpr->getQualifierLoc(),
+  MemberExpr->getTemplateKeywordLoc(),
+  MemberExpr->getFirstQualifierFoundInScope(), ExpandedNameInfo,
+  , MemberExpr->isMemberPackAccess());
+
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), Arg);
+  ExprResult Out = getDerived().TransformExpr(ExpandedMemberExpr);
+  if (Out.isInvalid())
+return true;
+  // An empty expression is returned when name lookup fails in accessing
+  // member packs. This means the last field in member pack has been
+  // processd and time to exit the loop.
+  if (Out.isUnset())
+break;
+  Outputs.push_back(Out.get());
+  Arg++;
+}
+continue;
+  }
+
   SmallVector Unexpanded;
   getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
   

[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-08-01 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao marked an inline comment as done.
SlaterLatiao added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:3289-3290
+  Fields.push_back(PackedField);
+  if (NewMember->isInvalidDecl())
+Instantiation->setInvalidDecl();
+} else {

dblaikie wrote:
> Is this codepath tested?
Some checks in `Visit` need to be implemented for this branch. I elaborated in 
the comment and will implement in a future differential.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:3292-3295
+  // FIXME: Eventually, a NULL return will mean that one of the
+  // instantiations was a semantic disaster, and we'll want to mark
+  // the declaration invalid. For now, we expect to skip some members
+  // that we can't yet handle.

SlaterLatiao wrote:
> dblaikie wrote:
> > Worth having a test case showing that/what's broken here?
> It's copied from the handling of non-pack members and possibly a duplicate 
> that should be avoided. I'm not sure which case could trigger this branch. 
> Will look into it.
We Traced back and could not find a test case associated with this block.  I 
added a cross reference of this to the FIXME below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

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


[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-08-01 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 546257.
SlaterLatiao added a comment.

- Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 --std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefixes=CHECK
+
+// Tests declaration data member packs.
+template struct S1 {
+Ts... ts;
+};
+
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+
+// CHECK: %struct.S1 = type { i32 }
+S1 s1;
+// CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
+S1 s2;
+// Test template args as the last arg.
+// CHECK-NEXT: %struct.S2 = type { [2 x i32], float, double }
+S2 s3;
+// Test nested template args.
+// CHECK-NEXT: %struct.S1.1 = type { i32, float, %struct.S1.2 }
+// CHECK-NEXT: %struct.S1.2 = type { double, double }
+S1> s4;
+// Test empty template arg.
+// CHECK-NEXT: %struct.S1.3 = type { i8 }
+S1<> s5;
+// Test duplicate types in template args.
+// CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
+S1 s6;
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5927,6 +5927,9 @@
  /*ExpectPackInType=*/false);
   }
   break;
+case DeclaratorContext::Member:
+  // Expand for data member packs.
+  // https://discourse.llvm.org/t/adding-support-for-data-member-packs/71333
 case DeclaratorContext::TemplateParam:
   // C++0x [temp.param]p15:
   //   If a template-parameter is a [...] is a parameter-declaration that
@@ -5954,7 +5957,6 @@
 case DeclaratorContext::CXXNew:
 case DeclaratorContext::AliasDecl:
 case DeclaratorContext::AliasTemplate:
-case DeclaratorContext::Member:
 case DeclaratorContext::Block:
 case DeclaratorContext::ForInit:
 case DeclaratorContext::SelectionInit:
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3267,42 +3267,81 @@
   continue;
 }
 
-Decl *NewMember = Instantiator.Visit(Member);
-if (NewMember) {
-  if (FieldDecl *Field = dyn_cast(NewMember)) {
-Fields.push_back(Field);
-  } else if (EnumDecl *Enum = dyn_cast(NewMember)) {
-// C++11 [temp.inst]p1: The implicit instantiation of a class template
-// specialization causes the implicit instantiation of the definitions
-// of unscoped member enumerations.
-// Record a point of instantiation for this implicit instantiation.
-if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
-Enum->isCompleteDefinition()) {
-  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
-  assert(MSInfo && "no spec info for member enum specialization");
-  MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
-  MSInfo->setPointOfInstantiation(PointOfInstantiation);
-}
-  } else if (StaticAssertDecl *SA = dyn_cast(NewMember)) {
-if (SA->isFailed()) {
-  // A static_assert failed. Bail out; instantiating this
-  // class is probably not meaningful.
-  Instantiation->setInvalidDecl();
-  break;
+// Instantiate packed data members.
+if (FieldDecl *Field = dyn_cast(Member);
+Field && isa(Field->getType().getTypePtr())) {
+  QualType PatternType = Field->getType()
+ ->castAs()
+ ->getPattern();
+  std::optional NumArgumentsInExpansion =
+  getNumArgumentsInExpansion(Field->getType(), TemplateArgs);
+  assert(NumArgumentsInExpansion && "should not see unknown template argument here");
+  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
+// Generate a new field from PackExpansion field.
+if (Decl *NewMember = Instantiator.Visit(Member)) {
+  FieldDecl *PackedField = cast(NewMember);
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, Arg);
+  QualType T =
+  SubstType(PatternType, TemplateArgs, PackedField->getLocation(),
+PackedField->getDeclName());
+  PackedField->setType(T);
+  Fields.push_back(PackedField);
+  if (NewMember->isInvalidDecl()) {
+// When `NewMember` has type of `PackExpansionType`, it escapes
+// validation checks in `Visit`. Handling of such cases
+

[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-07-31 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao marked an inline comment as done.
SlaterLatiao added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:3292-3295
+  // FIXME: Eventually, a NULL return will mean that one of the
+  // instantiations was a semantic disaster, and we'll want to mark
+  // the declaration invalid. For now, we expect to skip some members
+  // that we can't yet handle.

dblaikie wrote:
> Worth having a test case showing that/what's broken here?
It's copied from the handling of non-pack members and possibly a duplicate that 
should be avoided. I'm not sure which case could trigger this branch. Will look 
into it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

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


[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-07-31 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 545804.
SlaterLatiao added a comment.

Fix code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 --std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefixes=CHECK
+
+// Tests declaration data member packs.
+template struct S1 {
+Ts... ts;
+};
+
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+
+// CHECK: %struct.S1 = type { i32 }
+S1 s1;
+// CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
+S1 s2;
+// Test template args as the last arg.
+// CHECK-NEXT: %struct.S2 = type { [2 x i32], float, double }
+S2 s3;
+// Test nested template args.
+// CHECK-NEXT: %struct.S1.1 = type { i32, float, %struct.S1.2 }
+// CHECK-NEXT: %struct.S1.2 = type { double, double }
+S1> s4;
+// Test empty template arg.
+// CHECK-NEXT: %struct.S1.3 = type { i8 }
+S1<> s5;
+// Test duplicate types in template args.
+// CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
+S1 s6;
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5927,6 +5927,8 @@
  /*ExpectPackInType=*/false);
   }
   break;
+case DeclaratorContext::Member:
+  // Expand for packed data members.
 case DeclaratorContext::TemplateParam:
   // C++0x [temp.param]p15:
   //   If a template-parameter is a [...] is a parameter-declaration that
@@ -5954,7 +5956,6 @@
 case DeclaratorContext::CXXNew:
 case DeclaratorContext::AliasDecl:
 case DeclaratorContext::AliasTemplate:
-case DeclaratorContext::Member:
 case DeclaratorContext::Block:
 case DeclaratorContext::ForInit:
 case DeclaratorContext::SelectionInit:
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3267,42 +3267,74 @@
   continue;
 }
 
-Decl *NewMember = Instantiator.Visit(Member);
-if (NewMember) {
-  if (FieldDecl *Field = dyn_cast(NewMember)) {
-Fields.push_back(Field);
-  } else if (EnumDecl *Enum = dyn_cast(NewMember)) {
-// C++11 [temp.inst]p1: The implicit instantiation of a class template
-// specialization causes the implicit instantiation of the definitions
-// of unscoped member enumerations.
-// Record a point of instantiation for this implicit instantiation.
-if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
-Enum->isCompleteDefinition()) {
-  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
-  assert(MSInfo && "no spec info for member enum specialization");
-  MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
-  MSInfo->setPointOfInstantiation(PointOfInstantiation);
-}
-  } else if (StaticAssertDecl *SA = dyn_cast(NewMember)) {
-if (SA->isFailed()) {
-  // A static_assert failed. Bail out; instantiating this
-  // class is probably not meaningful.
-  Instantiation->setInvalidDecl();
-  break;
+// Instantiate packed data members.
+if (FieldDecl *Field = dyn_cast(Member);
+Field && isa(Field->getType().getTypePtr())) {
+  QualType PatternType = Field->getType()
+ ->castAs()
+ ->getPattern();
+  std::optional NumArgumentsInExpansion =
+  getNumArgumentsInExpansion(Field->getType(), TemplateArgs);
+  assert(NumArgumentsInExpansion && "should not see unknown template argument here");
+  for (unsigned Arg = 0; Arg < *NumArgumentsInExpansion; ++Arg) {
+// Generate a new field from PackExpansion field.
+if (Decl *NewMember = Instantiator.Visit(Member)) {
+  FieldDecl *PackedField = cast(NewMember);
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, Arg);
+  QualType T =
+  SubstType(PatternType, TemplateArgs, PackedField->getLocation(),
+PackedField->getDeclName());
+  PackedField->setType(T);
+  Fields.push_back(PackedField);
+  if (NewMember->isInvalidDecl())
+Instantiation->setInvalidDecl();
+} else {
+  // FIXME: Eventually, a NULL return will mean that one of the
+  // instantiations was a semantic disaster, and we'll want to mark
+  // the declaration 

[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-07-28 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao added inline comments.



Comment at: clang/test/CodeGenCXX/packed_data_member.cpp:8-12
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+

dblaikie wrote:
> Did this test case come out of any particular bug discovered during 
> implementation?
No. I just wanted to test the case when the packed parameter is not the only 
parameter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

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


[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-07-28 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao added a comment.

In D156546#4543697 , @dblaikie wrote:

> (just a side note about the title of this patch: I got "packed data members" 
> confused and thought this was referring to struct packing 
> `__attribute__((packed))` - so perhaps something more like "data member 
> packs" would be a more clear term here?)

I changed the name to "data member packs" in description and in the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

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


[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-07-28 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 545297.
SlaterLatiao added a comment.

Address comments.

- Added test case of duplicate types in template arguments.
- Added ending new line to test case file.
- Renamed "packed data members" -> "data member packs"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 --std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefixes=CHECK
+
+// Tests declaration data member packs.
+template struct S1 {
+Ts... ts;
+};
+
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+
+// CHECK: %struct.S1 = type { i32 }
+S1 s1;
+// CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
+S1 s2;
+// Test template args as the last arg.
+// CHECK-NEXT: %struct.S2 = type { [2 x i32], float, double }
+S2 s3;
+// Test nested template args.
+// CHECK-NEXT: %struct.S1.1 = type { i32, float, %struct.S1.2 }
+// CHECK-NEXT: %struct.S1.2 = type { double, double }
+S1> s4;
+// Test empty template arg.
+// CHECK-NEXT: %struct.S1.3 = type { i8 }
+S1<> s5;
+// Test duplicate types in template args.
+// CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
+S1 s6;
+
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5927,6 +5927,8 @@
  /*ExpectPackInType=*/false);
   }
   break;
+case DeclaratorContext::Member:
+  // Expand for packed data members.
 case DeclaratorContext::TemplateParam:
   // C++0x [temp.param]p15:
   //   If a template-parameter is a [...] is a parameter-declaration that
@@ -5954,7 +5956,6 @@
 case DeclaratorContext::CXXNew:
 case DeclaratorContext::AliasDecl:
 case DeclaratorContext::AliasTemplate:
-case DeclaratorContext::Member:
 case DeclaratorContext::Block:
 case DeclaratorContext::ForInit:
 case DeclaratorContext::SelectionInit:
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3267,42 +3267,74 @@
   continue;
 }
 
-Decl *NewMember = Instantiator.Visit(Member);
-if (NewMember) {
-  if (FieldDecl *Field = dyn_cast(NewMember)) {
-Fields.push_back(Field);
-  } else if (EnumDecl *Enum = dyn_cast(NewMember)) {
-// C++11 [temp.inst]p1: The implicit instantiation of a class template
-// specialization causes the implicit instantiation of the definitions
-// of unscoped member enumerations.
-// Record a point of instantiation for this implicit instantiation.
-if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
-Enum->isCompleteDefinition()) {
-  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
-  assert(MSInfo && "no spec info for member enum specialization");
-  MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
-  MSInfo->setPointOfInstantiation(PointOfInstantiation);
-}
-  } else if (StaticAssertDecl *SA = dyn_cast(NewMember)) {
-if (SA->isFailed()) {
-  // A static_assert failed. Bail out; instantiating this
-  // class is probably not meaningful.
-  Instantiation->setInvalidDecl();
-  break;
+// Instantiate packed data members.
+if (FieldDecl *Field = dyn_cast(Member);
+Field && isa(Field->getType().getTypePtr())) {
+  QualType PatternType = Field->getType()
+ ->castAs()
+ ->getPattern();
+  std::optional NumArgumentsInExpansion =
+  getNumArgumentsInExpansion(Field->getType(), TemplateArgs);
+  assert(NumArgumentsInExpansion && "should not see unknown template argument here");
+  for (unsigned Arg = 0; Arg < NumArgumentsInExpansion; ++Arg) {
+// Generate a new field from PackExpansion field.
+if (Decl *NewMember = Instantiator.Visit(Member)) {
+  FieldDecl *PackedField = cast(NewMember);
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, Arg);
+  QualType T =
+  SubstType(PatternType, TemplateArgs, PackedField->getLocation(),
+PackedField->getDeclName());
+  PackedField->setType(T);
+  Fields.push_back(PackedField);
+  if (NewMember->isInvalidDecl())
+Instantiation->setInvalidDecl();
+} else {
+  // 

[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-07-28 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 545291.
SlaterLatiao marked 2 inline comments as done.
SlaterLatiao added a comment.

Revert last commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/packed_data_member.cpp

Index: clang/test/CodeGenCXX/packed_data_member.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/packed_data_member.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 --std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefixes=CHECK
+
+// Tests declaration of packed data members.
+template struct S1 {
+Ts... ts;
+};
+
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+
+// CHECK: %struct.S1 = type { i32 }
+S1 s1;
+// CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
+S1 s2;
+// Test template args as the last arg.
+// CHECK-NEXT: %struct.S2 = type { [2 x i32], float, double }
+S2 s3;
+// Test nested template args.
+// CHECK-NEXT: %struct.S1.1 = type { i32, float, %struct.S1.2 }
+// CHECK-NEXT: %struct.S1.2 = type { double, double }
+S1> s4;
+// Test empty template arg.
+// CHECK-NEXT: %struct.S1.3 = type { i8 }
+S1<> s5;
\ No newline at end of file
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5927,6 +5927,8 @@
  /*ExpectPackInType=*/false);
   }
   break;
+case DeclaratorContext::Member:
+  // Expand for packed data members.
 case DeclaratorContext::TemplateParam:
   // C++0x [temp.param]p15:
   //   If a template-parameter is a [...] is a parameter-declaration that
@@ -5944,7 +5946,6 @@
  ? diag::warn_cxx98_compat_variadic_templates
  : diag::ext_variadic_templates);
   break;
-
 case DeclaratorContext::File:
 case DeclaratorContext::KNRTypeList:
 case DeclaratorContext::ObjCParameter: // FIXME: special diagnostic here?
@@ -5954,7 +5955,6 @@
 case DeclaratorContext::CXXNew:
 case DeclaratorContext::AliasDecl:
 case DeclaratorContext::AliasTemplate:
-case DeclaratorContext::Member:
 case DeclaratorContext::Block:
 case DeclaratorContext::ForInit:
 case DeclaratorContext::SelectionInit:
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3267,42 +3267,75 @@
   continue;
 }
 
-Decl *NewMember = Instantiator.Visit(Member);
-if (NewMember) {
-  if (FieldDecl *Field = dyn_cast(NewMember)) {
-Fields.push_back(Field);
-  } else if (EnumDecl *Enum = dyn_cast(NewMember)) {
-// C++11 [temp.inst]p1: The implicit instantiation of a class template
-// specialization causes the implicit instantiation of the definitions
-// of unscoped member enumerations.
-// Record a point of instantiation for this implicit instantiation.
-if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
-Enum->isCompleteDefinition()) {
-  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
-  assert(MSInfo && "no spec info for member enum specialization");
-  MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
-  MSInfo->setPointOfInstantiation(PointOfInstantiation);
-}
-  } else if (StaticAssertDecl *SA = dyn_cast(NewMember)) {
-if (SA->isFailed()) {
-  // A static_assert failed. Bail out; instantiating this
-  // class is probably not meaningful.
-  Instantiation->setInvalidDecl();
-  break;
+// Instantiate packed data members.
+if (FieldDecl *Field = dyn_cast(Member);
+Field && isa(Field->getType().getTypePtr())) {
+  QualType PatternType = Field->getType()
+ ->castAs()
+ ->getPattern();
+  std::optional NumArgumentsInExpansion =
+  getNumArgumentsInExpansion(Field->getType(), TemplateArgs);
+  assert(NumArgumentsInExpansion && "should not see unknown template argument here");
+  for (unsigned Arg = 0; Arg < NumArgumentsInExpansion; ++Arg) {
+// Generate a new field from PackExpansion field.
+Decl *NewMember = Instantiator.Visit(Member);
+if (NewMember) {
+  FieldDecl *PackedField = dyn_cast(NewMember);
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, Arg);
+  QualType T =
+  SubstType(PatternType, TemplateArgs, PackedField->getLocation(),
+PackedField->getDeclName());
+  PackedField->setType(T);
+  

[PATCH] D156546: [Clang][WIP]Experimental implementation of data member packs declarations

2023-07-28 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 545286.
SlaterLatiao added a comment.

- Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156546

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/ast-print-method-decl.cpp
  clang/test/CodeGenCXX/data_member_packs.cpp

Index: clang/test/CodeGenCXX/data_member_packs.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/data_member_packs.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 --std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefixes=CHECK
+
+// Tests declaration data member packs.
+template struct S1 {
+Ts... ts;
+};
+
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+
+// CHECK: %struct.S1 = type { i32 }
+S1 s1;
+// CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
+S1 s2;
+// Test template args as the last arg.
+// CHECK-NEXT: %struct.S2 = type { [2 x i32], float, double }
+S2 s3;
+// Test nested template args.
+// CHECK-NEXT: %struct.S1.1 = type { i32, float, %struct.S1.2 }
+// CHECK-NEXT: %struct.S1.2 = type { double, double }
+S1> s4;
+// Test empty template arg.
+// CHECK-NEXT: %struct.S1.3 = type { i8 }
+S1<> s5;
+// Test duplicate types in template args.
+// CHECK-NEXT: %struct.S1.4 = type { i32, i32 }
+S1 s6;
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/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5927,6 +5927,8 @@
  /*ExpectPackInType=*/false);
   }
   break;
+case DeclaratorContext::Member:
+  // Expand for packed data members.
 case DeclaratorContext::TemplateParam:
   // C++0x [temp.param]p15:
   //   If a template-parameter is a [...] is a parameter-declaration that
@@ -5944,7 +5946,7 @@
  ? diag::warn_cxx98_compat_variadic_templates
  : diag::ext_variadic_templates);
   break;
-
+  
 case DeclaratorContext::File:
 case DeclaratorContext::KNRTypeList:
 case DeclaratorContext::ObjCParameter: // FIXME: special diagnostic here?
@@ -5954,7 +5956,6 @@
 case DeclaratorContext::CXXNew:
 case DeclaratorContext::AliasDecl:
 case DeclaratorContext::AliasTemplate:
-case DeclaratorContext::Member:
 case DeclaratorContext::Block:
 case DeclaratorContext::ForInit:
 case DeclaratorContext::SelectionInit:
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3267,42 +3267,74 @@
   continue;
 }
 
-Decl *NewMember = Instantiator.Visit(Member);
-if (NewMember) {
-  if (FieldDecl *Field = dyn_cast(NewMember)) {
-Fields.push_back(Field);
-  } else if (EnumDecl *Enum = dyn_cast(NewMember)) {
-// C++11 [temp.inst]p1: The implicit instantiation of a class template
-// specialization causes the implicit instantiation of the definitions
-// of unscoped member enumerations.
-// Record a point of instantiation for this implicit instantiation.
-if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
-Enum->isCompleteDefinition()) {
-  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
-  assert(MSInfo && "no spec info for member enum specialization");
-  MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
-  MSInfo->setPointOfInstantiation(PointOfInstantiation);
-}
-  } else if (StaticAssertDecl *SA = dyn_cast(NewMember)) {
-if (SA->isFailed()) {
-  // A static_assert failed. Bail out; instantiating this
-  // class is probably not meaningful.
-  Instantiation->setInvalidDecl();
-  break;
+// Instantiate packed data members.
+if (FieldDecl *Field = dyn_cast(Member);
+Field && isa(Field->getType().getTypePtr())) {
+  QualType PatternType = Field->getType()
+ ->castAs()
+ ->getPattern();
+  

[PATCH] D156546: Experimental implementation of packed data member declaration

2023-07-28 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao created this revision.
Herald added a project: All.
SlaterLatiao 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/D156546

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/packed_data_member.cpp

Index: clang/test/CodeGenCXX/packed_data_member.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/packed_data_member.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 --std=c++20 %s -emit-llvm -o - -triple x86_64-linux | FileCheck %s --check-prefixes=CHECK
+
+// Tests declaration of packed data members.
+template struct S1 {
+Ts... ts;
+};
+
+template struct S2 {
+T t[2];
+Ts... ts;
+};
+
+// CHECK: %struct.S1 = type { i32 }
+S1 s1;
+// CHECK-NEXT: %struct.S1.0 = type { i32, float, double }
+S1 s2;
+// Test template args as the last arg.
+// CHECK-NEXT: %struct.S2 = type { [2 x i32], float, double }
+S2 s3;
+// Test nested template args.
+// CHECK-NEXT: %struct.S1.1 = type { i32, float, %struct.S1.2 }
+// CHECK-NEXT: %struct.S1.2 = type { double, double }
+S1> s4;
+// Test empty template arg.
+// CHECK-NEXT: %struct.S1.3 = type { i8 }
+S1<> s5;
\ No newline at end of file
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5927,6 +5927,8 @@
  /*ExpectPackInType=*/false);
   }
   break;
+case DeclaratorContext::Member:
+  // Expand for packed data members.
 case DeclaratorContext::TemplateParam:
   // C++0x [temp.param]p15:
   //   If a template-parameter is a [...] is a parameter-declaration that
@@ -5944,7 +5946,6 @@
  ? diag::warn_cxx98_compat_variadic_templates
  : diag::ext_variadic_templates);
   break;
-
 case DeclaratorContext::File:
 case DeclaratorContext::KNRTypeList:
 case DeclaratorContext::ObjCParameter: // FIXME: special diagnostic here?
@@ -5954,7 +5955,6 @@
 case DeclaratorContext::CXXNew:
 case DeclaratorContext::AliasDecl:
 case DeclaratorContext::AliasTemplate:
-case DeclaratorContext::Member:
 case DeclaratorContext::Block:
 case DeclaratorContext::ForInit:
 case DeclaratorContext::SelectionInit:
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3267,42 +3267,75 @@
   continue;
 }
 
-Decl *NewMember = Instantiator.Visit(Member);
-if (NewMember) {
-  if (FieldDecl *Field = dyn_cast(NewMember)) {
-Fields.push_back(Field);
-  } else if (EnumDecl *Enum = dyn_cast(NewMember)) {
-// C++11 [temp.inst]p1: The implicit instantiation of a class template
-// specialization causes the implicit instantiation of the definitions
-// of unscoped member enumerations.
-// Record a point of instantiation for this implicit instantiation.
-if (TSK == TSK_ImplicitInstantiation && !Enum->isScoped() &&
-Enum->isCompleteDefinition()) {
-  MemberSpecializationInfo *MSInfo =Enum->getMemberSpecializationInfo();
-  assert(MSInfo && "no spec info for member enum specialization");
-  MSInfo->setTemplateSpecializationKind(TSK_ImplicitInstantiation);
-  MSInfo->setPointOfInstantiation(PointOfInstantiation);
-}
-  } else if (StaticAssertDecl *SA = dyn_cast(NewMember)) {
-if (SA->isFailed()) {
-  // A static_assert failed. Bail out; instantiating this
-  // class is probably not meaningful.
-  Instantiation->setInvalidDecl();
-  break;
+// Instantiate packed data members.
+if (FieldDecl *Field = dyn_cast(Member);
+Field && isa(Field->getType().getTypePtr())) {
+  QualType PatternType = Field->getType()
+ ->castAs()
+ ->getPattern();
+  std::optional NumArgumentsInExpansion =
+  getNumArgumentsInExpansion(Field->getType(), TemplateArgs);
+  assert(NumArgumentsInExpansion && "should not see unknown template argument here");
+  for (unsigned Arg = 0; Arg < NumArgumentsInExpansion; ++Arg) {
+// Generate a new field from PackExpansion field.
+Decl *NewMember = Instantiator.Visit(Member);
+if (NewMember) {
+  FieldDecl *PackedField = dyn_cast(NewMember);
+  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, Arg);
+  QualType T =
+  SubstType(PatternType, TemplateArgs, PackedField->getLocation(),
+PackedField->getDeclName());
+  PackedField->setType(T);
+  Fields.push_back(PackedField);
+   

[PATCH] D151575: [clang][diagnostics] Always show include stacks on errors

2023-07-07 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 538197.
SlaterLatiao added a comment.

- Emit include stack on all top-level diagnostics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151575

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Frontend/DiagnosticRenderer.cpp
  clang/test/Misc/Inputs/include-stack-on-error-1.h
  clang/test/Misc/Inputs/include-stack-on-error-2.h
  clang/test/Misc/Inputs/include-stack-on-error-3.h
  clang/test/Misc/include-stack-on-error-1.cpp
  clang/test/Misc/include-stack-on-error-2.cpp

Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// This include should be skipped due to duplicate include location.
+// NOTESTACK-NOT:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/include-stack-on-error-1.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-1.cpp
@@ -0,0 +1,24 @@
+// Test duplicate include stacks on a new error are not skipped.
+// RUN: not %clang_cc1 -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=STACK
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-2.h"
+
+// STACK:  In file included from
+// STACK: error: no matching function for call to 'b1'
+// STACK-NOT:  In file included from
+// STACK: note: candidate function not viable
+// STACK:  In file included from
+// STACK: error: invalid operands to binary expression
+// STACK-NOT:  In file included from
+// STACK: note: in instantiation of function template specialization
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// NOTESTACK:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/Inputs/include-stack-on-error-3.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-3.h
@@ -0,0 +1,5 @@
+void b1();
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-2.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-2.h
@@ -0,0 +1,4 @@
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-1.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-1.h
@@ -0,0 +1,2 @@
+void b1();
+template  void b2(T x, T y) { x + y; }
Index: clang/lib/Frontend/DiagnosticRenderer.cpp
===
--- clang/lib/Frontend/DiagnosticRenderer.cpp
+++ clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -167,8 +167,8 @@
   PLoc.isInvalid() ? FullSourceLoc()
: FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
 
-  // Skip redundant include stacks altogether.
-  if (LastIncludeLoc == IncludeLoc)
+  // Skip redundant include stacks altogether on non-top-level.
+  if (Level < DiagnosticsEngine::Warning && LastIncludeLoc == IncludeLoc)
 return;
 
   LastIncludeLoc = IncludeLoc;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -359,6 +359,9 @@
 - The Fix-It emitted for unused labels used to expand to the next line, which caused
   visual oddities now that Clang shows more than one line of code snippet. This has
   been fixed and the Fix-It now only spans to the end of the ``:``.
+- Clang now does not skip the include stack on top-level diagnostics when it's a 
+  duplicate of the previous include stack.
+  (`#62001 `_)
 
 Bug Fixes in This Version
 

[PATCH] D151575: [clang][diagnostics] Always show include stacks on errors

2023-06-15 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 531885.
SlaterLatiao added a comment.

Remove unnecessary condition and assignment in implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151575

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Frontend/DiagnosticRenderer.cpp
  clang/test/Misc/Inputs/include-stack-on-error-1.h
  clang/test/Misc/Inputs/include-stack-on-error-2.h
  clang/test/Misc/Inputs/include-stack-on-error-3.h
  clang/test/Misc/include-stack-on-error-1.cpp
  clang/test/Misc/include-stack-on-error-2.cpp

Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// This include should be skipped due to duplicate include location.
+// NOTESTACK-NOT:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/include-stack-on-error-1.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-1.cpp
@@ -0,0 +1,24 @@
+// Test duplicate include stacks on a new error are not skipped.
+// RUN: not %clang_cc1 -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=STACK
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-2.h"
+
+// STACK:  In file included from
+// STACK: error: no matching function for call to 'b1'
+// STACK-NOT:  In file included from
+// STACK: note: candidate function not viable
+// STACK:  In file included from
+// STACK: error: invalid operands to binary expression
+// STACK-NOT:  In file included from
+// STACK: note: in instantiation of function template specialization
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// NOTESTACK:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/Inputs/include-stack-on-error-3.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-3.h
@@ -0,0 +1,5 @@
+void b1();
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-2.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-2.h
@@ -0,0 +1,4 @@
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-1.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-1.h
@@ -0,0 +1,2 @@
+void b1();
+template  void b2(T x, T y) { x + y; }
Index: clang/lib/Frontend/DiagnosticRenderer.cpp
===
--- clang/lib/Frontend/DiagnosticRenderer.cpp
+++ clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -167,8 +167,8 @@
   PLoc.isInvalid() ? FullSourceLoc()
: FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
 
-  // Skip redundant include stacks altogether.
-  if (LastIncludeLoc == IncludeLoc)
+  // Skip redundant include stacks altogether on non-top-level.
+  if (Level != DiagnosticsEngine::Error && LastIncludeLoc == IncludeLoc)
 return;
 
   LastIncludeLoc = IncludeLoc;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -319,6 +319,9 @@
   ``-fno-diagnostics-show-line-numbers``. At the same time, the maximum
   number of code lines it prints has been increased from 1 to 16. This
   can be controlled using ``-fcaret-diagnostics-max-lines=``.
+- Clang now does not skip the include stack on an error when it's a duplicate of 
+  the previous include stack.
+  (`#62001 `_)
 
 Bug Fixes in This Version
 -

[PATCH] D153068: Remove unnecessary condition and assignment.

2023-06-15 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao created this revision.
Herald added a project: All.
SlaterLatiao 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/D153068

Files:
  clang/lib/Frontend/DiagnosticRenderer.cpp


Index: clang/lib/Frontend/DiagnosticRenderer.cpp
===
--- clang/lib/Frontend/DiagnosticRenderer.cpp
+++ clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -167,12 +167,8 @@
   PLoc.isInvalid() ? FullSourceLoc()
: FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
 
-  // Reset `LastIncludeLoc` on a new error so that the include stacks are
-  // not skipped.
-  if (Level == DiagnosticsEngine::Error)
-LastIncludeLoc = SourceLocation();
-  // Skip redundant include stacks altogether.
-  if (LastIncludeLoc == IncludeLoc)
+  // Skip redundant include stacks altogether on non-top-level.
+  if (Level != DiagnosticsEngine::Error && LastIncludeLoc == IncludeLoc)
 return;
 
   LastIncludeLoc = IncludeLoc;


Index: clang/lib/Frontend/DiagnosticRenderer.cpp
===
--- clang/lib/Frontend/DiagnosticRenderer.cpp
+++ clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -167,12 +167,8 @@
   PLoc.isInvalid() ? FullSourceLoc()
: FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
 
-  // Reset `LastIncludeLoc` on a new error so that the include stacks are
-  // not skipped.
-  if (Level == DiagnosticsEngine::Error)
-LastIncludeLoc = SourceLocation();
-  // Skip redundant include stacks altogether.
-  if (LastIncludeLoc == IncludeLoc)
+  // Skip redundant include stacks altogether on non-top-level.
+  if (Level != DiagnosticsEngine::Error && LastIncludeLoc == IncludeLoc)
 return;
 
   LastIncludeLoc = IncludeLoc;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151575: [clang][diagnostics] Always show include stacks on errors

2023-05-30 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 526717.
SlaterLatiao added a comment.

- Added release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151575

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Frontend/DiagnosticRenderer.cpp
  clang/test/Misc/Inputs/include-stack-on-error-1.h
  clang/test/Misc/Inputs/include-stack-on-error-2.h
  clang/test/Misc/Inputs/include-stack-on-error-3.h
  clang/test/Misc/include-stack-on-error-1.cpp
  clang/test/Misc/include-stack-on-error-2.cpp

Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// This include should be skipped due to duplicate include location.
+// NOTESTACK-NOT:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/include-stack-on-error-1.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-1.cpp
@@ -0,0 +1,24 @@
+// Test duplicate include stacks on a new error are not skipped.
+// RUN: not %clang_cc1 -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=STACK
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-2.h"
+
+// STACK:  In file included from
+// STACK: error: no matching function for call to 'b1'
+// STACK-NOT:  In file included from
+// STACK: note: candidate function not viable
+// STACK:  In file included from
+// STACK: error: invalid operands to binary expression
+// STACK-NOT:  In file included from
+// STACK: note: in instantiation of function template specialization
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// NOTESTACK:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/Inputs/include-stack-on-error-3.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-3.h
@@ -0,0 +1,5 @@
+void b1();
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-2.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-2.h
@@ -0,0 +1,4 @@
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-1.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-1.h
@@ -0,0 +1,2 @@
+void b1();
+template  void b2(T x, T y) { x + y; }
Index: clang/lib/Frontend/DiagnosticRenderer.cpp
===
--- clang/lib/Frontend/DiagnosticRenderer.cpp
+++ clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -167,6 +167,10 @@
   PLoc.isInvalid() ? FullSourceLoc()
: FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
 
+  // Reset `LastIncludeLoc` on a new error so that the include stacks are
+  // not skipped.
+  if (Level == DiagnosticsEngine::Error)
+LastIncludeLoc = SourceLocation();
   // Skip redundant include stacks altogether.
   if (LastIncludeLoc == IncludeLoc)
 return;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -307,6 +307,9 @@
   (`#62850: `_).
 - Clang now warns when any predefined macro is undefined or redefined, instead
   of only some of them.
+- Clang now does not skip the include stack on an error when it's a duplicate of 
+  the previous include stack.
+  (`#62001 `_)
 
 Bug Fixes in This Version
 -
___
cfe-commits mailing list

[PATCH] D151575: [clang][diagnostics] Always show include stacks on errors

2023-05-26 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 526144.
SlaterLatiao added a comment.

- Add newline to end of file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151575

Files:
  clang/lib/Frontend/DiagnosticRenderer.cpp
  clang/test/Misc/Inputs/include-stack-on-error-1.h
  clang/test/Misc/Inputs/include-stack-on-error-2.h
  clang/test/Misc/Inputs/include-stack-on-error-3.h
  clang/test/Misc/include-stack-on-error-1.cpp
  clang/test/Misc/include-stack-on-error-2.cpp


Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I 
%S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// This include should be skipped due to duplicate include location.
+// NOTESTACK-NOT:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/include-stack-on-error-1.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-1.cpp
@@ -0,0 +1,24 @@
+// Test duplicate include stacks on a new error are not skipped.
+// RUN: not %clang_cc1 -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s 
-check-prefix=STACK
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I 
%S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-2.h"
+
+// STACK:  In file included from
+// STACK: error: no matching function for call to 'b1'
+// STACK-NOT:  In file included from
+// STACK: note: candidate function not viable
+// STACK:  In file included from
+// STACK: error: invalid operands to binary expression
+// STACK-NOT:  In file included from
+// STACK: note: in instantiation of function template specialization
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// NOTESTACK:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
Index: clang/test/Misc/Inputs/include-stack-on-error-3.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-3.h
@@ -0,0 +1,5 @@
+void b1();
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-2.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-2.h
@@ -0,0 +1,4 @@
+void c() {
+b1(0);
+b2("0", "0");
+}
Index: clang/test/Misc/Inputs/include-stack-on-error-1.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-1.h
@@ -0,0 +1,2 @@
+void b1();
+template  void b2(T x, T y) { x + y; }
Index: clang/lib/Frontend/DiagnosticRenderer.cpp
===
--- clang/lib/Frontend/DiagnosticRenderer.cpp
+++ clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -167,6 +167,10 @@
   PLoc.isInvalid() ? FullSourceLoc()
: FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
 
+  // Reset `LastIncludeLoc` on a new error so that the include stacks are
+  // not skipped.
+  if (Level == DiagnosticsEngine::Error)
+LastIncludeLoc = SourceLocation();
   // Skip redundant include stacks altogether.
   if (LastIncludeLoc == IncludeLoc)
 return;


Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// This include should be skipped due to duplicate include location.
+// NOTESTACK-NOT:  In file included from
+// 

[PATCH] D151575: [clang][diagnostics] Always show include stacks on errors

2023-05-26 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao created this revision.
Herald added a project: All.
SlaterLatiao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Fixes PR#62001.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151575

Files:
  clang/lib/Frontend/DiagnosticRenderer.cpp
  clang/test/Misc/Inputs/include-stack-on-error-1.h
  clang/test/Misc/Inputs/include-stack-on-error-2.h
  clang/test/Misc/Inputs/include-stack-on-error-3.h
  clang/test/Misc/include-stack-on-error-1.cpp
  clang/test/Misc/include-stack-on-error-2.cpp


Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I 
%S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// This include should be skipped due to duplicate include location.
+// NOTESTACK-NOT:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
\ No newline at end of file
Index: clang/test/Misc/include-stack-on-error-1.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-1.cpp
@@ -0,0 +1,25 @@
+// Test duplicate include stacks on a new error are not skipped.
+// RUN: not %clang_cc1 -fsyntax-only -I %S/Inputs %s 2>&1 | FileCheck %s 
-check-prefix=STACK
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I 
%S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-2.h"
+
+// STACK:  In file included from
+// STACK: error: no matching function for call to 'b1'
+// STACK-NOT:  In file included from
+// STACK: note: candidate function not viable
+// STACK:  In file included from
+// STACK: error: invalid operands to binary expression
+// STACK-NOT:  In file included from
+// STACK: note: in instantiation of function template specialization
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching function for call to 'b1'
+// NOTESTACK:  In file included from
+// NOTESTACK: note: candidate function not viable
+// NOTESTACK:  In file included from
+// NOTESTACK: error: invalid operands to binary expression
+// NOTESTACK:  In file included from
+// NOTESTACK: note: in instantiation of function template specialization
+
Index: clang/test/Misc/Inputs/include-stack-on-error-3.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-3.h
@@ -0,0 +1,5 @@
+void b1();
+void c() {
+b1(0);
+b2("0", "0");
+}
\ No newline at end of file
Index: clang/test/Misc/Inputs/include-stack-on-error-2.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-2.h
@@ -0,0 +1,4 @@
+void c() {
+b1(0);
+b2("0", "0");
+}
\ No newline at end of file
Index: clang/test/Misc/Inputs/include-stack-on-error-1.h
===
--- /dev/null
+++ clang/test/Misc/Inputs/include-stack-on-error-1.h
@@ -0,0 +1,2 @@
+void b1();
+template  void b2(T x, T y) { x + y; }
\ No newline at end of file
Index: clang/lib/Frontend/DiagnosticRenderer.cpp
===
--- clang/lib/Frontend/DiagnosticRenderer.cpp
+++ clang/lib/Frontend/DiagnosticRenderer.cpp
@@ -167,6 +167,10 @@
   PLoc.isInvalid() ? FullSourceLoc()
: FullSourceLoc(PLoc.getIncludeLoc(), Loc.getManager());
 
+  // Reset `LastIncludeLoc` on a new error so that the include stacks are
+  // not skipped.
+  if (Level == DiagnosticsEngine::Error)
+LastIncludeLoc = SourceLocation();
   // Skip redundant include stacks altogether.
   if (LastIncludeLoc == IncludeLoc)
 return;


Index: clang/test/Misc/include-stack-on-error-2.cpp
===
--- /dev/null
+++ clang/test/Misc/include-stack-on-error-2.cpp
@@ -0,0 +1,15 @@
+// Test duplicate include stacks that are not on a new error are skipped.
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-show-note-include-stack -I %S/Inputs %s 2>&1 | FileCheck %s -check-prefix=NOTESTACK
+
+#include "include-stack-on-error-1.h"
+#include "include-stack-on-error-3.h"
+
+// NOTESTACK:  In file included from
+// NOTESTACK: error: no matching 

[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-25 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 525744.
SlaterLatiao added a comment.

Adding back the `-triple` flag

- The padding size can be different on different architectures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151162

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
  clang/test/CodeGenCXX/warn-padded-packed.cpp
  clang/test/Misc/warning-wall.c


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
===
--- clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
+++ clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
@@ -1,5 +1,10 @@
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,top %s -emit-llvm-only
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is 
unnecessary" warnings.
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -verify=top %s 
-emit-llvm-only
+// -Wall should not emit the "packed attribute is unnecessary" warnings 
without -Wpacked.
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wall -verify=top %s 
-emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -282,6 +282,8 @@
   Clang ABI >= 15.
   (`#62353: `_,
   fallout from the non-POD packing ABI fix in LLVM 15).
+- ``-Wpacked-non-pod`` is now included in ``-Wall``.
+  (`#60832: `_)
 
 
 Bug Fixes in This Version


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
===
--- clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
+++ clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
@@ -1,5 +1,10 @@
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is unnecessary" warnings.
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -verify=top %s -emit-llvm-only
+// -Wall should not emit the "packed attribute is unnecessary" warnings without -Wpacked.
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wall -verify=top %s -emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -282,6 +282,8 @@
  

[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-25 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao added a comment.

I shouldn't remove `-triple=x86_64-none-none` in the test case. I'll add it 
back.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151162

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


[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-25 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao added a comment.

In D151162#4373027 , @aaron.ballman 
wrote:

> LGTM! Do you need someone to commit on your behalf? If so, what name and 
> email address would you like us to use for patch attribution?

Thank you, Aaron! Please use Zenong Zhang and slaterlat...@gmail.com for the 
commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151162

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


[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-25 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 525654.
SlaterLatiao added a comment.

- Fix missing parenthesis.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151162

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
  clang/test/CodeGenCXX/warn-padded-packed.cpp
  clang/test/Misc/warning-wall.c


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
===
--- clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
+++ clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,top %s -emit-llvm-only
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,abi15 
-fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is 
unnecessary" warnings.
+// RUN: %clang_cc1 -Wpacked-non-pod -verify=top %s -emit-llvm-only
+// -Wall should not emit the "packed attribute is unnecessary" warnings 
without -Wpacked.
+// RUN: %clang_cc1 -Wall -verify=top %s -emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -282,6 +282,8 @@
   Clang ABI >= 15.
   (`#62353: `_,
   fallout from the non-POD packing ABI fix in LLVM 15).
+- ``-Wpacked-non-pod`` is now included in ``-Wall``.
+  (`#60832: `_)
 
 
 Bug Fixes in This Version


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
===
--- clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
+++ clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is unnecessary" warnings.
+// RUN: %clang_cc1 -Wpacked-non-pod -verify=top %s -emit-llvm-only
+// -Wall should not emit the "packed attribute is unnecessary" warnings without -Wpacked.
+// RUN: %clang_cc1 -Wall -verify=top %s -emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, 

[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-25 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 525653.
SlaterLatiao added a comment.

- Test behavior of `-Wpacked-non-pod` in `-Wall` and update test case name.
- Update release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151162

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
  clang/test/CodeGenCXX/warn-padded-packed.cpp
  clang/test/Misc/warning-wall.c


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
===
--- clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
+++ clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,top %s -emit-llvm-only
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,abi15 
-fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is 
unnecessary" warnings.
+// RUN: %clang_cc1 -Wpacked-non-pod -verify=top %s -emit-llvm-only
+// -Wall should not emit the "packed attribute is unnecessary" warnings 
without -Wpacked.
+// RUN: %clang_cc1 -Wall -verify=top %s -emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -282,6 +282,8 @@
   Clang ABI >= 15.
   (`#62353: `_,
   fallout from the non-POD packing ABI fix in LLVM 15).
+- ``-Wpacked-non-pod`` is now included in ``-Wall``.
+  (`#60832: `_
 
 
 Bug Fixes in This Version


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
===
--- clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
+++ clang/test/CodeGenCXX/warn-all-padded-packed-packed-non-pod.cpp
@@ -1,5 +1,10 @@
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is unnecessary" warnings.
+// RUN: %clang_cc1 -Wpacked-non-pod -verify=top %s -emit-llvm-only
+// -Wall should not emit the "packed attribute is unnecessary" warnings without -Wpacked.
+// RUN: %clang_cc1 -Wall -verify=top %s -emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // 

[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-24 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao added a comment.

In D151162#4369584 , @aaron.ballman 
wrote:

> Please be sure to add a release note for the change, and it'd probably be 
> good to have a test case that shows this triggers under `-Wall` (the modified 
> test case explicitly names the diagnostic).

Thank you, Aaron. I'll add the test case. Should this change go under 
`Improvements to Clang’s diagnostics` in the release note?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151162

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


[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-24 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao added inline comments.



Comment at: clang/test/CodeGenCXX/warn-padded-packed.cpp:5
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -verify=top %s 
-emit-llvm-only
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod 
-fclang-abi-compat=15 %s -emit-llvm-only
+

denik wrote:
> Probably we don't need this one. But I'm not sure if there is any impact of 
> the abi on`packed-non-pod`. According to the original test it checks only 
> `-Wpacked` `packed attribute is unnecessary` warning.
I added this line to make sure all the `packed attribute is unnecessary` 
warnings in the existing test of  `-Wpacked` are not reported by  
`-Wpacked-non-pod`. Yeah if the abi doesn't have any impact on 
`-Wpacked-non-pod` this test is unnecessary. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151162

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


[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-24 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 525280.
SlaterLatiao added a comment.

- Removed the -triple flag from warn-padded-packed testcase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151162

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/CodeGenCXX/warn-padded-packed.cpp
  clang/test/Misc/warning-wall.c


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-padded-packed.cpp
===
--- clang/test/CodeGenCXX/warn-padded-packed.cpp
+++ clang/test/CodeGenCXX/warn-padded-packed.cpp
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,top %s -emit-llvm-only
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,abi15 
-fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is 
unnecessary" warnings.
+// RUN: %clang_cc1 -Wpacked-non-pod -verify=top %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpacked-non-pod -fclang-abi-compat=15 %s -emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-padded-packed.cpp
===
--- clang/test/CodeGenCXX/warn-padded-packed.cpp
+++ clang/test/CodeGenCXX/warn-padded-packed.cpp
@@ -1,5 +1,9 @@
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
-// RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is unnecessary" warnings.
+// RUN: %clang_cc1 -Wpacked-non-pod -verify=top %s -emit-llvm-only
+// RUN: %clang_cc1 -Wpacked-non-pod -fclang-abi-compat=15 %s -emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-23 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao updated this revision to Diff 524909.
SlaterLatiao added a comment.

Test -packed-non-pod not omitting warnings of "packed attribute is unnecessary".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151162

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/CodeGenCXX/warn-padded-packed.cpp
  clang/test/Misc/warning-wall.c


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-padded-packed.cpp
===
--- clang/test/CodeGenCXX/warn-padded-packed.cpp
+++ clang/test/CodeGenCXX/warn-padded-packed.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,top %s -emit-llvm-only
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is 
unnecessary" warnings.
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -verify=top %s 
-emit-llvm-only
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod 
-fclang-abi-compat=15 %s -emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/test/CodeGenCXX/warn-padded-packed.cpp
===
--- clang/test/CodeGenCXX/warn-padded-packed.cpp
+++ clang/test/CodeGenCXX/warn-padded-packed.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is unnecessary" warnings.
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -verify=top %s -emit-llvm-only
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -fclang-abi-compat=15 %s -emit-llvm-only
+
 
 struct S1 {
   char c;
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151264: Test -Wpacked-non-pod does not emit warnings of "packed attribute is unnecessary"

2023-05-23 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao created this revision.
Herald added a project: All.
SlaterLatiao 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/D151264

Files:
  clang/test/CodeGenCXX/warn-padded-packed.cpp


Index: clang/test/CodeGenCXX/warn-padded-packed.cpp
===
--- clang/test/CodeGenCXX/warn-padded-packed.cpp
+++ clang/test/CodeGenCXX/warn-padded-packed.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,top %s -emit-llvm-only
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked 
-verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is 
unnecessary" warnings.
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -verify=top %s 
-emit-llvm-only
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod 
-fclang-abi-compat=15 %s -emit-llvm-only
+
 
 struct S1 {
   char c;


Index: clang/test/CodeGenCXX/warn-padded-packed.cpp
===
--- clang/test/CodeGenCXX/warn-padded-packed.cpp
+++ clang/test/CodeGenCXX/warn-padded-packed.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,top %s -emit-llvm-only
 // RUN: %clang_cc1 -triple=x86_64-none-none -Wpadded -Wpacked -verify=expected,abi15 -fclang-abi-compat=15 %s -emit-llvm-only
+// -Wpacked-non-pod itself should not emit the "packed attribute is unnecessary" warnings.
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -verify=top %s -emit-llvm-only
+// RUN: %clang_cc1 -triple=x86_64-none-none -Wpacked-non-pod -fclang-abi-compat=15 %s -emit-llvm-only
+
 
 struct S1 {
   char c;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151162: Add -Wpacked-non-pod to -Wall

2023-05-22 Thread Zenong Zhang via Phabricator via cfe-commits
SlaterLatiao created this revision.
Herald added a project: All.
SlaterLatiao 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/D151162

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/test/Misc/warning-wall.c


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;


Index: clang/test/Misc/warning-wall.c
===
--- clang/test/Misc/warning-wall.c
+++ clang/test/Misc/warning-wall.c
@@ -99,6 +99,7 @@
 CHECK-NEXT:  -Wswitch
 CHECK-NEXT:  -Wswitch-bool
 CHECK-NEXT:  -Wmisleading-indentation
+CHECK-NEXT:  -Wpacked-non-pod
 
 
 CHECK-NOT:-W
Index: clang/include/clang/Basic/DiagnosticGroups.td
===
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1060,7 +1060,7 @@
 // warning should be active _only_ when -Wall is passed in, mark it as
 // DefaultIgnore in addition to putting it here.
 def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
-MisleadingIndentation]>;
+MisleadingIndentation, PackedNonPod]>;
 
 // Warnings that should be in clang-cl /w4.
 def : DiagGroup<"CL4", [All, Extra]>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits