[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D128113#3753565 , @davrec wrote:

> 2: After thinking about it further I don't think the pack index provides 
> sufficiently useful info in any case, since packs will always be expanded in 
> full, in order: when you find the first `SubstTemplateTypeParmType` expanded 
> from a pack, the rest are sure to be right behind.  IIUC I see how including 
> the pack index makes resugaring more straightforward: the substitution of the 
> sugared info for the non-sugared info occurs via a TreeTransform (see 
> clang/lib/Sema/SemaTemplate.cpp in https://reviews.llvm.org/D127695), and by 
> storing the pack index Matheus can simply override 
> `TransformSubstTemplateTypeParmType` to make use of the pack index to easily 
> fetch the corresponding sugared info.  But since the pack indices are 
> predictable given a bird's eye view of the AST, maybe state info can be 
> stored in the TreeTransform to allow the pack index to be inferred in each 
> call to `TransformSubstTemplateTypeParmType`?

Packs are expanded from patterns, which is an arbitrary type that will 
reference one or more parameter pack anywhere within. So going back from an 
expanded pack back to a pattern + number of expansions will take more effort 
and we may need to add new markings to the AST to help with that.

Check this example out: https://godbolt.org/z/rsGsM6GrM

  template  struct A {
template  struct B {
using type1 = void ((void (*...fps)(Ts, Us)));
};
  };
  using type2 = A::B::type1;

  TypeAliasDecl 0x55ffe8b45368  col:7 type2 'A::B::type1':'void ((void (*)(int, short), void (*)(char, 
bool)))'
`-ElaboratedType 0x55ffe8b452f0 'A::B::type1' sugar
  `-TypedefType 0x55ffe8b452d0 'A::B::type1' sugar
|-TypeAlias 0x55ffe8b45258 'type1'
`-FunctionProtoType 0x55ffe8b451e0 'void ((void (*)(int, short), void 
(*)(char, bool)))' cdecl
  |-ParenType 0x55ffe8b12150 'void' sugar
  | `-BuiltinType 0x55ffe8ac6370 'void'
  |-PointerType 0x55ffe8b44550 'void (*)(int, short)'
  | `-ParenType 0x55ffe8b444f0 'void (int, short)' sugar
  |   `-FunctionProtoType 0x55ffe8b444b0 'void (int, short)' cdecl
  | |-BuiltinType 0x55ffe8ac6370 'void'
  | |-SubstTemplateTypeParmType 0x55ffe8b44310 'int' sugar
  | | |-TemplateTypeParmType 0x55ffe8b11440 'Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
  | | | `-TemplateTypeParm 0x55ffe8b113c0 'Ts'
  | | `-BuiltinType 0x55ffe8ac6410 'int'
  | `-SubstTemplateTypeParmType 0x55ffe8b443c0 'short' sugar
  |   |-TemplateTypeParmType 0x55ffe8b11960 'Us' dependent 
contains_unexpanded_pack depth 1 index 0 pack
  |   | `-TemplateTypeParm 0x55ffe8b118d8 'Us'
  |   `-BuiltinType 0x55ffe8ac63f0 'short'
  `-PointerType 0x55ffe8b450c0 'void (*)(char, bool)'
`-ParenType 0x55ffe8b45060 'void (char, bool)' sugar
  `-FunctionProtoType 0x55ffe8b447d0 'void (char, bool)' cdecl
|-BuiltinType 0x55ffe8ac6370 'void'
|-SubstTemplateTypeParmType 0x55ffe8b44630 'char' sugar
| |-TemplateTypeParmType 0x55ffe8b11440 'Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| | `-TemplateTypeParm 0x55ffe8b113c0 'Ts'
| `-BuiltinType 0x55ffe8ac63b0 'char'
`-SubstTemplateTypeParmType 0x55ffe8b446e0 'bool' sugar
  |-TemplateTypeParmType 0x55ffe8b11960 'Us' dependent 
contains_unexpanded_pack depth 1 index 0 pack
  | `-TemplateTypeParm 0x55ffe8b118d8 'Us'
  `-BuiltinType 0x55ffe8ac6390 'bool'

And in fact, a given parameter pack might be referenced more than one time in a 
given pack expansion pattern:

  template  struct A {
template  struct B {
using type1 = void ((void (*...fps)(Ts, Ts, Us)));
};
  };

Ie those two Ts are referencing the same argument within the pack, we can't 
confuse that with an expansion.

So think also about a case like the above, but where you are performing the 
expansion just one time. It doesn't look like to me you can figure that out 
from what Clang leaves behind in the AST at the moment.
We may need to create a new AST node, which is like a Subst variant of a 
PackExpansionType, at the expansion loci.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D128113#3753624 , @davrec wrote:

> Or just `SubstTemplateTypeParmType` could store this number in addition to 
> its `TemplateTypeParmType`?  (E.g. the first Ts in an expansion is 0, the 
> second Ts in the same expansion is 1, etc. - but it resets for the next 
> expansion.)

Well that number is just the pack_index, as implemented in this current patch :)

I like the idea obviously, this patch is so simple, and simple solutions are 
the best when they are good enough.

I am not completely sold that this solution is not good enough, it's hard to 
make the case that the reproducer is a reasonable program, but at the same time 
it's obvious that packs where designed to deal very cheaply with very large 
number of arguments.

And this patch does not make the worst case worse: If all arguments are 
different types in all expansions, then a different pack_index will not cause 
an extra uniquing because the underlying types will be different as well anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D128113#3753656 , @davrec wrote:

> If I'm missing something and it is substantially more complex than that, then 
> you're right that storing the pack index might end up the best solution - we 
> don't want to e.g. have to do considerable Sema logic in the Resugarer just 
> to infer the pack index.

Having a new Subst-like node that wraps the whole expanded pattern seems to 
simplify the case where we need to take the type apart, such as deductions, 
leaving you without the 'birds-eye' view. Otherwise we would need to dig into 
the type to figure out what pack indexes we need to preserve in the resulting 
type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D128113#3753662 , @davrec wrote:

> Thanks for your work on this, and for explaining these complexities.

TBH I still don't know what to do here from the project perspective. I have a 
new deadline now that runs until November.

It seems that sitting down, figuring out a solution and coming up with a 
review-ready patch would take a considerable portion of that time. And then the 
review could take a year.

Meanwhile there is still considerable work remaining on the resugarer, in terms 
of addressing performance and getting everything into a reviewable state.

So I might try leaving this problem aside and not handle packs, for now. This 
would make us not able to resugar tuples for example, which is very unfortunate.

But in the unlikely case there was someone else interested in solving this 
problem, this could be parallelized.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

llvm-compile-time-tracker stats for this patch: 
http://llvm-compile-time-tracker.com/compare.php?from=f7a33090a91015836497c75f173775392ab0304d&to=771076b836b331f50f8a852fba1353aa60865e30&stat=instructions

For the next one on the stack, which hooks the new mechanism here to more 
places: 
http://llvm-compile-time-tracker.com/compare.php?from=771076b836b331f50f8a852fba1353aa60865e30&to=56a1894e70ff387d0b7791564a12a5879655c86f&stat=instructions

For the one after that, which extends this mechanism to cover sugar nodes: 
http://llvm-compile-time-tracker.com/compare.php?from=56a1894e70ff387d0b7791564a12a5879655c86f&to=96a13ce3e1776de824585182603f01258332d2c8&stat=instructions

They all look to be within what you would expect from noise alone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

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


[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

llvm-compile-time-tracker stats for this patch: 
http://llvm-compile-time-tracker.com/compare.php?from=de872a323c8eb1c90d740fc739c8781d41743ead&to=c5cdd76e99ced02ba433e899fb6075fe214a84fd&stat=instructions

The difference looks like noise.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 456196.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

Files:
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/SemaCXX/deduced-return-void.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaTemplate/deduction.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D111283
Index: clang/test/SemaTemplate/deduction.cpp
===
--- clang/test/SemaTemplate/deduction.cpp
+++ clang/test/SemaTemplate/deduction.cpp
@@ -162,6 +162,15 @@
 
 } // namespace test4
 
+namespace test5 {
+
+template  class a {};
+template  void c(b, b);
+template  void c(a, a);
+void d() { c(a(), a()); }
+
+} // namespace test5
+
 // Verify that we can deduce enum-typed arguments correctly.
 namespace test14 {
   enum E { E0, E1 };
Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -1,4 +1,12 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20
+// RUN: %clang_cc1 -fsyntax-only -verify -xobjective-c++ %s -std=c++20 -fms-extensions -fblocks -fobjc-arc -fobjc-runtime-has-weak -fenable-matrix -Wno-dynamic-exception-spec -Wno-c++17-compat-mangling
+// RUN: %clang_cc1 -fsyntax-only -verify -xobjective-c++ %s -std=c++14 -fms-extensions -fblocks -fobjc-arc -fobjc-runtime-has-weak -fenable-matrix -Wno-dynamic-exception-spec -Wno-c++17-compat-mangling
+
+namespace std {
+template struct initializer_list {
+  const T *begin, *end;
+  initializer_list();
+};
+} // namespace std
 
 enum class N {};
 
@@ -9,6 +17,26 @@
 using Man = Animal;
 using Dog = Animal;
 
+using ManPtr = Man *;
+using DogPtr = Dog *;
+
+using SocratesPtr = ManPtr;
+
+using ConstMan = const Man;
+using ConstDog = const Dog;
+
+using Virus = void;
+using SARS = Virus;
+using Ebola = Virus;
+
+using Bacteria = float;
+using Bacilli = Bacteria;
+using Vibrio = Bacteria;
+
+struct Plant;
+using Gymnosperm = Plant;
+using Angiosperm = Plant;
+
 namespace variable {
 
 auto x1 = Animal();
@@ -25,6 +53,9 @@
 N t4 = x4; // expected-error {{lvalue of type 'Man' (aka 'int')}}
 N t5 = x5; // expected-error {{lvalue of type 'Dog' (aka 'int')}}
 
+auto x6 = { Man(), Dog() };
+N t6 = x6; // expected-error {{from 'std::initializer_list' (aka 'initializer_list')}}
+
 } // namespace variable
 
 namespace function_basic {
@@ -41,3 +72,160 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace function_multiple_basic {
+
+N t1 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Man();
+  return Dog();
+}();
+
+N t2 = []() -> decltype(auto) { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Man();
+  return Dog();
+}();
+
+N t3 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Dog();
+  auto x = Man();
+  return x;
+}();
+
+N t4 = [] { // expected-error {{rvalue of type 'int'}}
+  if (true)
+return Dog();
+  return 1;
+}();
+
+N t5 = [] { // expected-error {{rvalue of type 'Virus' (aka 'void')}}
+  if (true)
+return Ebola();
+  return SARS();
+}();
+
+N t6 = [] { // expected-error {{rvalue of type 'void'}}
+  if (true)
+return SARS();
+  return;
+}();
+
+} // namespace function_multiple_basic
+
+#define TEST_AUTO(X, A, B) \
+  static_assert(__is_same(A, B), ""); \
+  auto X(A a, B b) {   \
+if (0) \
+  return a;\
+if (0) \
+  return b;\
+return N();\
+  }
+#define TEST_DAUTO(X, A, B) \
+  static_assert(__is_same(A, B), ""); \
+  decltype(auto) X(A a, B b) {  \
+if (0)  \
+  return static_cast(a); \
+if (0)  \
+  return static_cast(b); \
+return N(); \
+  }
+
+namespace misc {
+
+TEST_AUTO(t1, ManPtr, DogPtr)  // expected-error {{but deduced as 'Animal *' (aka 'int *')}}
+TEST_AUTO(t2, ManPtr, int *)   // expected-error {{but deduced as 'int *'}}
+TEST_AUTO(t3, SocratesPtr, ManPtr) // expected-error {{but deduced as 'ManPtr' (aka 'int *')}}
+
+TEST_AUTO(t4, _Atomic(Man), _Atomic(Dog)) // expected

[PATCH] D111509: [clang] use getCommonSugar in an assortment of places

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 456197.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111509

Files:
  clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-fpfeatures.cpp
  clang/test/CodeGen/compound-assign-overflow.c
  clang/test/Sema/matrix-type-operators.c
  clang/test/Sema/nullability.c
  clang/test/Sema/sugar-common-types.c
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaObjC/format-strings-objc.m
  compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
  compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
  libcxx/DELETE.ME
  lldb/test/API/commands/expression/rdar42038760/main.c
  lldb/test/API/commands/expression/rdar44436068/main.c

Index: lldb/test/API/commands/expression/rdar44436068/main.c
===
--- lldb/test/API/commands/expression/rdar44436068/main.c
+++ lldb/test/API/commands/expression/rdar44436068/main.c
@@ -3,6 +3,6 @@
 __int128_t n = 1;
 n = n + n;
 return n; //%self.expect("p n", substrs=['(__int128_t) $0 = 2'])
-  //%self.expect("p n + 6", substrs=['(__int128) $1 = 8'])
-  //%self.expect("p n + n", substrs=['(__int128) $2 = 4'])
+  //%self.expect("p n + 6", substrs=['(__int128_t) $1 = 8'])
+  //%self.expect("p n + n", substrs=['(__int128_t) $2 = 4'])
 }
Index: lldb/test/API/commands/expression/rdar42038760/main.c
===
--- lldb/test/API/commands/expression/rdar42038760/main.c
+++ lldb/test/API/commands/expression/rdar42038760/main.c
@@ -10,7 +10,7 @@
   struct S0 l_19;
   l_19.f2 = 419;
   uint32_t l_4037 = 4294967295UL;
-  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(unsigned int) $0 = 358717883'])
+  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(uint32_t) $0 = 358717883'])
 }
 int main()
 {
Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1 +1,2 @@
 D111283
+D111509
Index: compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
@@ -12,12 +12,12 @@
 
 #ifdef SUB_I32
   (void)(uint32_t(1) - uint32_t(2));
-  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int'
+  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 #endif
 
 #ifdef SUB_I64
   (void)(uint64_t(800ll) - uint64_t(900ll));
-  // CHECK-SUB_I64: 800 - 900 cannot be represented in type 'unsigned {{long( long)?}}'
+  // CHECK-SUB_I64: 800 - 900 cannot be represented in type '{{uint64_t|unsigned long( long)?}}'
 #endif
 
 #ifdef SUB_I128
@@ -26,6 +26,6 @@
 # else
   puts("__int128 not supported\n");
 # endif
-  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type 'unsigned __int128'|__int128 not supported}}
+  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type '__uint128_t'|__int128 not supported}}
 #endif
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
@@ -13,7 +13,7 @@
   (void)(uint16_t(0x) * uint16_t(0x8001));
 
   (void)(uint32_t(0x) * uint32_t(0x2));
-  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type 'unsigned int'
+  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 
   return 0;
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
=

[PATCH] D130308: [clang] extend getCommonSugaredType to merge sugar nodes

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 456198.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130308

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,2 +1,3 @@
 D111283
 D111509
+D130308
Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix -triple i686-pc-win32
 
 enum class N {};
 
@@ -38,3 +38,77 @@
 N t7 = X4() + Y4(); // expected-error {{rvalue of type 'B4'}}
 N t8 = X4() * Y4(); // expected-error {{rvalue of type 'B4'}}
 N t9 = X5() * Y5(); // expected-error {{rvalue of type 'A4 __attribute__((matrix_type(3, 3)))'}}
+
+template  struct S1 {
+  template  struct S2 {};
+};
+
+N t10 = 0 ? S1() : S1(); // expected-error {{from 'S1' (aka 'S1')}}
+N t11 = 0 ? S1::S2() : S1::S2(); // expected-error {{from 'S1::S2' (aka 'S2')}}
+
+template  using Al = S1;
+
+N t12 = 0 ? Al() : Al(); // expected-error {{from 'Al' (aka 'S1')}}
+
+#define AS1 __attribute__((address_space(1)))
+#define AS2 __attribute__((address_space(1)))
+using AS1X1 = AS1 B1;
+using AS1Y1 = AS1 B1;
+using AS2Y1 = AS2 B1;
+N t13 = 0 ? (AS1X1){} : (AS1Y1){}; // expected-error {{rvalue of type 'AS1 B1' (aka '__attribute__((address_space(1))) int')}}
+N t14 = 0 ? (AS1X1){} : (AS2Y1){}; // expected-error {{rvalue of type '__attribute__((address_space(1))) B1' (aka '__attribute__((address_space(1))) int')}}
+
+using FX1 = X1 ();
+using FY1 = Y1 ();
+N t15 = 0 ? (FX1*){} : (FY1*){}; // expected-error {{rvalue of type 'B1 (*)()' (aka 'int (*)()')}}
+
+struct SS1 {};
+using SB1 = SS1;
+using SX1 = SB1;
+using SY1 = SB1;
+
+using MFX1 = X1 SX1::*();
+using MFY1 = Y1 SY1::*();
+
+N t16 = 0 ? (MFX1*){} : (MFY1*){}; // expected-error {{rvalue of type 'B1 SB1::*(*)()'}}
+
+N t17 = 0 ? (FX1 SX1::*){} : (FY1 SY1::*){}; // expected-error {{rvalue of type 'B1 (SB1::*)() __attribute__((thiscall))'}}
+
+N t18 = 0 ? (__typeof(X1*)){} : (__typeof(Y1*)){}; // expected-error {{rvalue of type 'typeof(B1 *)' (aka 'int *')}}
+
+struct Enums {
+  enum X : B1;
+  enum Y : ::B1;
+};
+using EnumsB = Enums;
+using EnumsX = EnumsB;
+using EnumsY = EnumsB;
+
+N t19 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::Y)){};
+// expected-error@-1 {{rvalue of type 'B1' (aka 'int')}}
+
+N t20 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::X)){};
+// expected-error@-1 {{rvalue of type '__underlying_type(Enums::X)' (aka 'int')}}
+
+using SBTF1 = SS1 [[clang::btf_type_tag("1")]];
+using SBTF2 = ::SS1 [[clang::btf_type_tag("1")]];
+using SBTF3 = ::SS1 [[clang::btf_type_tag("2")]];
+
+N t21 = 0 ? (SBTF1){} : (SBTF3){}; // expected-error {{from 'SS1'}}
+N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 btf_type_tag(1)' (aka 'SS1')}}
+
+using QX = const SB1 *;
+using QY = const ::SB1 *;
+N t23 = 0 ? (QX){} : (QY){}; // expected-error {{rvalue of type 'const SB1 *' (aka 'const SS1 *')}}
+
+template  using Alias = short;
+N t24 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'Alias' (aka 'short')}}
+N t25 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'short'}}
+
+template  concept C1 = true;
+template  concept C2 = true;
+C1 auto t26_1 = (SB1){};
+C1 auto t26_2 = (::SB1){};
+C2 auto t26_3 = (::SB1){};
+N t26 = 0 ? t26_1 : t26_2; // expected-error {{from 'SB1' (aka 'SS1')}}
+N t27 = 0 ? t26_1 : t26_3; // expected-error {{from 'SB1' (aka 'SS1')}}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3822,13 +3822,11 @@
 //   - If A is an array type, the pointer type produced by the
 // array-to-pointer standard conversion (4.2) is used in place of
 // A for type deduction; otherwise,
-if (ArgType->isArrayType())
-  ArgType = S.Context.getArrayDecayedType(ArgType);
 //   - If A is a function type, the pointer type produced by the
 // function-to-pointer standard conversion (4.3) is used in place
 // of A for type deduction; otherwise,
-else if (ArgType->isFunctionType())
-  ArgType = S.Context.getPointerType(ArgType);
+if (ArgType->canDecayToPointerType())
+  ArgType = S.Context.getDecayedType(ArgType);
 else {
   // - If A is a cv-qualified type, the top level cv-qualifiers of A's
   //   type are ignored for type 

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 456199.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,3 +1,4 @@
 D111283
 D111509
 D130308
+D131858
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -156,9 +156,8 @@
 // CHECK:   |-BuiltinType {{.*}} 'int'
 // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack
 // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
-// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack
-// CHECK: |-TemplateTypeParmType {{.*}} 'U' dependent contains_unexpanded_pack depth 1 index 0 pack
-// CHECK: | `-TemplateTypeParm {{.*}} 'U'
+// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack typename depth 1 index 0 ... U
+// CHECK: |-TypeAliasTemplate {{.*}} 'B'
 // CHECK: `-TemplateArgument pack
 // CHECK:   |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NOT: Subst
Index: clang/test/AST/deduction-guides.cpp
===
--- clang/test/AST/deduction-guides.cpp
+++ clang/test/AST/deduction-guides.cpp
@@ -67,9 +67,8 @@
 // CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived::type_alias' sugar
 // CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base::type_alias' sugar
 // CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
-// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
-// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
+// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar class depth 0 index 0 A
+// CHECK-NEXT: ClassTemplateSpecialization {{.*}} 'Base'
 // CHECK-NEXT: BuiltinType {{.*}} 'int'
 
 // CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (Derived &&, const typename Derived::type_alias &) -> Derived'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -120,12 +120,12 @@
 // CHECK-NEXT: TemplateArgument type 'void'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent depth 0 index 0
-// CHECK-NEXT: TemplateTypeParm 0x{{[^ ]*}} 'U'
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent depth 0 index 0
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T
+// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
+// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'
 } // namespace PR55886
 
 namespace PR56099 {
@@ -136,14 +136,14 @@
 };
 using t1 = foo::bind;
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypePar

[PATCH] D130308: [clang] extend getCommonSugaredType to merge sugar nodes

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 456201.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130308

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,2 +1,3 @@
 D111283
 D111509
+D130308
Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix -triple i686-pc-win32
 
 enum class N {};
 
@@ -38,3 +38,77 @@
 N t7 = X4() + Y4(); // expected-error {{rvalue of type 'B4'}}
 N t8 = X4() * Y4(); // expected-error {{rvalue of type 'B4'}}
 N t9 = X5() * Y5(); // expected-error {{rvalue of type 'A4 __attribute__((matrix_type(3, 3)))'}}
+
+template  struct S1 {
+  template  struct S2 {};
+};
+
+N t10 = 0 ? S1() : S1(); // expected-error {{from 'S1' (aka 'S1')}}
+N t11 = 0 ? S1::S2() : S1::S2(); // expected-error {{from 'S1::S2' (aka 'S2')}}
+
+template  using Al = S1;
+
+N t12 = 0 ? Al() : Al(); // expected-error {{from 'Al' (aka 'S1')}}
+
+#define AS1 __attribute__((address_space(1)))
+#define AS2 __attribute__((address_space(1)))
+using AS1X1 = AS1 B1;
+using AS1Y1 = AS1 B1;
+using AS2Y1 = AS2 B1;
+N t13 = 0 ? (AS1X1){} : (AS1Y1){}; // expected-error {{rvalue of type 'AS1 B1' (aka '__attribute__((address_space(1))) int')}}
+N t14 = 0 ? (AS1X1){} : (AS2Y1){}; // expected-error {{rvalue of type '__attribute__((address_space(1))) B1' (aka '__attribute__((address_space(1))) int')}}
+
+using FX1 = X1 ();
+using FY1 = Y1 ();
+N t15 = 0 ? (FX1*){} : (FY1*){}; // expected-error {{rvalue of type 'B1 (*)()' (aka 'int (*)()')}}
+
+struct SS1 {};
+using SB1 = SS1;
+using SX1 = SB1;
+using SY1 = SB1;
+
+using MFX1 = X1 SX1::*();
+using MFY1 = Y1 SY1::*();
+
+N t16 = 0 ? (MFX1*){} : (MFY1*){}; // expected-error {{rvalue of type 'B1 SB1::*(*)()'}}
+
+N t17 = 0 ? (FX1 SX1::*){} : (FY1 SY1::*){}; // expected-error {{rvalue of type 'B1 (SB1::*)() __attribute__((thiscall))'}}
+
+N t18 = 0 ? (__typeof(X1*)){} : (__typeof(Y1*)){}; // expected-error {{rvalue of type 'typeof(B1 *)' (aka 'int *')}}
+
+struct Enums {
+  enum X : B1;
+  enum Y : ::B1;
+};
+using EnumsB = Enums;
+using EnumsX = EnumsB;
+using EnumsY = EnumsB;
+
+N t19 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::Y)){};
+// expected-error@-1 {{rvalue of type 'B1' (aka 'int')}}
+
+N t20 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::X)){};
+// expected-error@-1 {{rvalue of type '__underlying_type(Enums::X)' (aka 'int')}}
+
+using SBTF1 = SS1 [[clang::btf_type_tag("1")]];
+using SBTF2 = ::SS1 [[clang::btf_type_tag("1")]];
+using SBTF3 = ::SS1 [[clang::btf_type_tag("2")]];
+
+N t21 = 0 ? (SBTF1){} : (SBTF3){}; // expected-error {{from 'SS1'}}
+N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 btf_type_tag(1)' (aka 'SS1')}}
+
+using QX = const SB1 *;
+using QY = const ::SB1 *;
+N t23 = 0 ? (QX){} : (QY){}; // expected-error {{rvalue of type 'const SB1 *' (aka 'const SS1 *')}}
+
+template  using Alias = short;
+N t24 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'Alias' (aka 'short')}}
+N t25 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'short'}}
+
+template  concept C1 = true;
+template  concept C2 = true;
+C1 auto t26_1 = (SB1){};
+C1 auto t26_2 = (::SB1){};
+C2 auto t26_3 = (::SB1){};
+N t26 = 0 ? t26_1 : t26_2; // expected-error {{from 'SB1' (aka 'SS1')}}
+N t27 = 0 ? t26_1 : t26_3; // expected-error {{from 'SB1' (aka 'SS1')}}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3822,13 +3822,11 @@
 //   - If A is an array type, the pointer type produced by the
 // array-to-pointer standard conversion (4.2) is used in place of
 // A for type deduction; otherwise,
-if (ArgType->isArrayType())
-  ArgType = S.Context.getArrayDecayedType(ArgType);
 //   - If A is a function type, the pointer type produced by the
 // function-to-pointer standard conversion (4.3) is used in place
 // of A for type deduction; otherwise,
-else if (ArgType->isFunctionType())
-  ArgType = S.Context.getPointerType(ArgType);
+if (ArgType->canDecayToPointerType())
+  ArgType = S.Context.getDecayedType(ArgType);
 else {
   // - If A is a cv-qualified type, the top level cv-qualifiers

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 456202.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,3 +1,4 @@
 D111283
 D111509
 D130308
+D131858
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -156,9 +156,8 @@
 // CHECK:   |-BuiltinType {{.*}} 'int'
 // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack
 // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
-// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack
-// CHECK: |-TemplateTypeParmType {{.*}} 'U' dependent contains_unexpanded_pack depth 1 index 0 pack
-// CHECK: | `-TemplateTypeParm {{.*}} 'U'
+// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack typename depth 1 index 0 ... U
+// CHECK: |-TypeAliasTemplate {{.*}} 'B'
 // CHECK: `-TemplateArgument pack
 // CHECK:   |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NOT: Subst
Index: clang/test/AST/deduction-guides.cpp
===
--- clang/test/AST/deduction-guides.cpp
+++ clang/test/AST/deduction-guides.cpp
@@ -67,9 +67,8 @@
 // CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived::type_alias' sugar
 // CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base::type_alias' sugar
 // CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
-// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
-// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
+// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar class depth 0 index 0 A
+// CHECK-NEXT: ClassTemplateSpecialization {{.*}} 'Base'
 // CHECK-NEXT: BuiltinType {{.*}} 'int'
 
 // CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (Derived &&, const typename Derived::type_alias &) -> Derived'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -120,12 +120,12 @@
 // CHECK-NEXT: TemplateArgument type 'void'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent depth 0 index 0
-// CHECK-NEXT: TemplateTypeParm 0x{{[^ ]*}} 'U'
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent depth 0 index 0
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T
+// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
+// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'
 } // namespace PR55886
 
 namespace PR56099 {
@@ -136,14 +136,14 @@
 };
 using t1 = foo::bind;
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypePar

[PATCH] D128095: [clang] Improve diagnostics for expansion length mismatch

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128095

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


[PATCH] D126172: [clang] Fix comparison of TemplateArgument when they are of template kind

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

Hello, @roberteg16, are you still interested in working on this patch?

I might need a fix for this myself, and also it happened recently that someone 
else attempted a fix for the same bug.

If you are not abandoning it, please let us know!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126172

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


[PATCH] D132816: [clang] AST: SubstTemplateTypeParmType support for non-canonical underlying type.

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends on D130308 

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132816

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Type.cpp

Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3718,6 +3718,11 @@
 : Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
Replacement->getDependence()),
   ReplacedDecl(ReplacedDecl) {
+  SubstTemplateTypeParmTypeBits.hasNonCanonicalUnderlyingType =
+  Replacement != getCanonicalTypeInternal();
+  if (SubstTemplateTypeParmTypeBits.hasNonCanonicalUnderlyingType)
+*getTrailingObjects() = Replacement;
+
   SubstTemplateTypeParmTypeBits.Index = Index;
   assert(ReplacedDecl != nullptr);
   assert(getReplacedParameter() != nullptr);
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4752,9 +4752,6 @@
 QualType ASTContext::getSubstTemplateTypeParmType(QualType Replacement,
   Decl *ReplacedDecl,
   unsigned Index) const {
-  assert(Replacement.isCanonical()
- && "replacement types must always be canonical");
-
   llvm::FoldingSetNodeID ID;
   SubstTemplateTypeParmType::Profile(ID, Replacement, ReplacedDecl, Index);
   void *InsertPos = nullptr;
@@ -4762,8 +4759,11 @@
   SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
 
   if (!SubstParm) {
-SubstParm = new (*this, TypeAlignment)
-SubstTemplateTypeParmType(Replacement, ReplacedDecl, Index);
+void *Mem = Allocate(SubstTemplateTypeParmType::totalSizeToAlloc(
+ !Replacement.isCanonical()),
+ TypeAlignment);
+SubstParm =
+new (Mem) SubstTemplateTypeParmType(Replacement, ReplacedDecl, Index);
 Types.push_back(SubstParm);
 SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
   }
Index: clang/include/clang/AST/TypeProperties.td
===
--- clang/include/clang/AST/TypeProperties.td
+++ clang/include/clang/AST/TypeProperties.td
@@ -741,7 +741,7 @@
   // The call to getCanonicalType here existed in ASTReader.cpp, too.
   def : Creator<[{
 return ctx.getSubstTemplateTypeParmType(
-ctx.getCanonicalType(replacementType), replacedDecl, Index);
+replacementType, replacedDecl, Index);
   }]>;
 }
 
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -1798,8 +1798,10 @@
 
 unsigned : NumTypeBits;
 
+unsigned hasNonCanonicalUnderlyingType : 1;
+
 // The index of the template parameter this substitution represents.
-unsigned Index;
+unsigned Index : 16;
   };
 
   class SubstTemplateTypeParmPackTypeBitfields {
@@ -4981,8 +4983,12 @@
 /// been replaced with these.  They are used solely to record that a
 /// type was originally written as a template type parameter;
 /// therefore they are never canonical.
-class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
+class SubstTemplateTypeParmType final
+: public Type,
+  public llvm::FoldingSetNode,
+  private llvm::TrailingObjects {
   friend class ASTContext;
+  friend class llvm::TrailingObjects;
 
   Decl *ReplacedDecl;
 
@@ -4992,7 +4998,11 @@
 public:
   /// Gets the type that was substituted for the template
   /// parameter.
-  QualType getReplacementType() const { return getCanonicalTypeInternal(); }
+  QualType getReplacementType() const {
+return SubstTemplateTypeParmTypeBits.hasNonCanonicalUnderlyingType
+   ? *getTrailingObjects()
+   : getCanonicalTypeInternal();
+  }
 
   /// Gets the templated entity that was substituted.
   Decl *getReplacedDecl() const { return ReplacedDecl; }
@@ -5011,7 +5021,7 @@
   static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement,
   const Decl *ReplacedDecl, unsigned Index) {
 ID.AddPointer(ReplacedDecl);
-ID.AddPointer(Replacement.getAsOpaquePtr());
+Replacement.Profile(ID);
 ID.AddInteger(Index);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 456213.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,3 +1,4 @@
 D111283
 D111509
 D130308
+D131858
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -156,9 +156,8 @@
 // CHECK:   |-BuiltinType {{.*}} 'int'
 // CHECK:   |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack
 // CHECK:   | `-TemplateTypeParm {{.*}} 'T'
-// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack
-// CHECK: |-TemplateTypeParmType {{.*}} 'U' dependent contains_unexpanded_pack depth 1 index 0 pack
-// CHECK: | `-TemplateTypeParm {{.*}} 'U'
+// CHECK:   `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack typename depth 1 index 0 ... U
+// CHECK: |-TypeAliasTemplate {{.*}} 'B'
 // CHECK: `-TemplateArgument pack
 // CHECK:   |-TemplateArgument type 'type-parameter-0-1'
 // CHECK-NOT: Subst
Index: clang/test/AST/deduction-guides.cpp
===
--- clang/test/AST/deduction-guides.cpp
+++ clang/test/AST/deduction-guides.cpp
@@ -67,9 +67,8 @@
 // CHECK-NEXT: ElaboratedType {{.*}} 'typename Derived::type_alias' sugar
 // CHECK-NEXT: TypedefType {{.*}} 'PR48177::Base::type_alias' sugar
 // CHECK-NEXT: TypeAlias {{.*}} 'type_alias'
-// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType {{.*}} 'A'
-// CHECK-NEXT: TemplateTypeParm {{.*}} 'A'
+// CHECK-NEXT: SubstTemplateTypeParmType {{.*}} 'int' sugar class depth 0 index 0 A
+// CHECK-NEXT: ClassTemplateSpecialization {{.*}} 'Base'
 // CHECK-NEXT: BuiltinType {{.*}} 'int'
 
 // CHECK: CXXDeductionGuideDecl {{.*}} implicit  'auto (Derived &&, const typename Derived::type_alias &) -> Derived'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -120,12 +120,12 @@
 // CHECK-NEXT: TemplateArgument type 'void'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
 // CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent depth 0 index 0
-// CHECK-NEXT: TemplateTypeParm 0x{{[^ ]*}} 'U'
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar class depth 0 index 0 U
+// CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'type1'
 // CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
-// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
-// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent depth 0 index 0
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar class depth 0 index 0 T
+// CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'C'
+// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'int'
 } // namespace PR55886
 
 namespace PR56099 {
@@ -136,14 +136,14 @@
 };
 using t1 = foo::bind;
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypePar

[PATCH] D132816: [clang] AST: SubstTemplateTypeParmType support for non-canonical underlying type.

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 456216.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132816

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Type.cpp

Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3718,6 +3718,11 @@
 : Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
Replacement->getDependence()),
   ReplacedDecl(ReplacedDecl) {
+  SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType =
+  Replacement != getCanonicalTypeInternal();
+  if (SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType)
+*getTrailingObjects() = Replacement;
+
   SubstTemplateTypeParmTypeBits.Index = Index;
   assert(ReplacedDecl != nullptr);
   assert(getReplacedParameter() != nullptr);
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1529,8 +1529,7 @@
 return ToReplacementTypeOrErr.takeError();
 
   return Importer.getToContext().getSubstTemplateTypeParmType(
-  ToReplacementTypeOrErr->getCanonicalType(), *ReplacedOrErr,
-  T->getIndex());
+  *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex());
 }
 
 ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4752,9 +4752,6 @@
 QualType ASTContext::getSubstTemplateTypeParmType(QualType Replacement,
   Decl *ReplacedDecl,
   unsigned Index) const {
-  assert(Replacement.isCanonical()
- && "replacement types must always be canonical");
-
   llvm::FoldingSetNodeID ID;
   SubstTemplateTypeParmType::Profile(ID, Replacement, ReplacedDecl, Index);
   void *InsertPos = nullptr;
@@ -4762,8 +4759,11 @@
   SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
 
   if (!SubstParm) {
-SubstParm = new (*this, TypeAlignment)
-SubstTemplateTypeParmType(Replacement, ReplacedDecl, Index);
+void *Mem = Allocate(SubstTemplateTypeParmType::totalSizeToAlloc(
+ !Replacement.isCanonical()),
+ TypeAlignment);
+SubstParm =
+new (Mem) SubstTemplateTypeParmType(Replacement, ReplacedDecl, Index);
 Types.push_back(SubstParm);
 SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
   }
Index: clang/include/clang/AST/TypeProperties.td
===
--- clang/include/clang/AST/TypeProperties.td
+++ clang/include/clang/AST/TypeProperties.td
@@ -741,7 +741,7 @@
   // The call to getCanonicalType here existed in ASTReader.cpp, too.
   def : Creator<[{
 return ctx.getSubstTemplateTypeParmType(
-ctx.getCanonicalType(replacementType), replacedDecl, Index);
+replacementType, replacedDecl, Index);
   }]>;
 }
 
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -1798,8 +1798,10 @@
 
 unsigned : NumTypeBits;
 
+unsigned HasNonCanonicalUnderlyingType : 1;
+
 // The index of the template parameter this substitution represents.
-unsigned Index;
+unsigned Index : 16;
   };
 
   class SubstTemplateTypeParmPackTypeBitfields {
@@ -4981,8 +4983,12 @@
 /// been replaced with these.  They are used solely to record that a
 /// type was originally written as a template type parameter;
 /// therefore they are never canonical.
-class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
+class SubstTemplateTypeParmType final
+: public Type,
+  public llvm::FoldingSetNode,
+  private llvm::TrailingObjects {
   friend class ASTContext;
+  friend class llvm::TrailingObjects;
 
   Decl *ReplacedDecl;
 
@@ -4992,7 +4998,11 @@
 public:
   /// Gets the type that was substituted for the template
   /// parameter.
-  QualType getReplacementType() const { return getCanonicalTypeInternal(); }
+  QualType getReplacementType() const {
+return SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType
+   ? *getTrailingObjects()
+   : getCanonicalTypeInternal();
+  }
 
   /// Gets the templated entity that was substituted.
   Decl *getReplacedDecl() const { return ReplacedDecl; }
@@ -5011,7 +5021,7 @@
   static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement

[PATCH] D132816: [clang] AST: SubstTemplateTypeParmType support for non-canonical underlying type

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov retitled this revision from "[clang] AST: SubstTemplateTypeParmType 
support for non-canonical underlying type." to "[clang] AST: 
SubstTemplateTypeParmType support for non-canonical underlying type".
mizvekov updated this revision to Diff 456217.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132816

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Type.cpp

Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3718,6 +3718,11 @@
 : Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
Replacement->getDependence()),
   ReplacedDecl(ReplacedDecl) {
+  SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType =
+  Replacement != getCanonicalTypeInternal();
+  if (SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType)
+*getTrailingObjects() = Replacement;
+
   SubstTemplateTypeParmTypeBits.Index = Index;
   assert(ReplacedDecl != nullptr);
   assert(getReplacedParameter() != nullptr);
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1529,8 +1529,7 @@
 return ToReplacementTypeOrErr.takeError();
 
   return Importer.getToContext().getSubstTemplateTypeParmType(
-  ToReplacementTypeOrErr->getCanonicalType(), *ReplacedOrErr,
-  T->getIndex());
+  *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex());
 }
 
 ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4752,9 +4752,6 @@
 QualType ASTContext::getSubstTemplateTypeParmType(QualType Replacement,
   Decl *ReplacedDecl,
   unsigned Index) const {
-  assert(Replacement.isCanonical()
- && "replacement types must always be canonical");
-
   llvm::FoldingSetNodeID ID;
   SubstTemplateTypeParmType::Profile(ID, Replacement, ReplacedDecl, Index);
   void *InsertPos = nullptr;
@@ -4762,8 +4759,11 @@
   SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
 
   if (!SubstParm) {
-SubstParm = new (*this, TypeAlignment)
-SubstTemplateTypeParmType(Replacement, ReplacedDecl, Index);
+void *Mem = Allocate(SubstTemplateTypeParmType::totalSizeToAlloc(
+ !Replacement.isCanonical()),
+ TypeAlignment);
+SubstParm =
+new (Mem) SubstTemplateTypeParmType(Replacement, ReplacedDecl, Index);
 Types.push_back(SubstParm);
 SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
   }
Index: clang/include/clang/AST/TypeProperties.td
===
--- clang/include/clang/AST/TypeProperties.td
+++ clang/include/clang/AST/TypeProperties.td
@@ -741,7 +741,7 @@
   // The call to getCanonicalType here existed in ASTReader.cpp, too.
   def : Creator<[{
 return ctx.getSubstTemplateTypeParmType(
-ctx.getCanonicalType(replacementType), replacedDecl, Index);
+replacementType, replacedDecl, Index);
   }]>;
 }
 
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -1798,8 +1798,10 @@
 
 unsigned : NumTypeBits;
 
+unsigned HasNonCanonicalUnderlyingType : 1;
+
 // The index of the template parameter this substitution represents.
-unsigned Index;
+unsigned Index : 16;
   };
 
   class SubstTemplateTypeParmPackTypeBitfields {
@@ -4981,8 +4983,12 @@
 /// been replaced with these.  They are used solely to record that a
 /// type was originally written as a template type parameter;
 /// therefore they are never canonical.
-class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
+class SubstTemplateTypeParmType final
+: public Type,
+  public llvm::FoldingSetNode,
+  private llvm::TrailingObjects {
   friend class ASTContext;
+  friend class llvm::TrailingObjects;
 
   Decl *ReplacedDecl;
 
@@ -4992,7 +4998,11 @@
 public:
   /// Gets the type that was substituted for the template
   /// parameter.
-  QualType getReplacementType() const { return getCanonicalTypeInternal(); }
+  QualType getReplacementType() const {
+return SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType
+   ? *getTrailingObjects()
+   : getCanonicalTypeInternal();
+  }
 
   /// Gets the templated entity that was substituted.
   Decl *getReplacedDecl() const { return ReplacedDecl; 

[PATCH] D128113: WIP: Clang: fix AST representation of expanded template arguments.

2022-08-28 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov retitled this revision from "Clang: fix AST representation of expanded 
template arguments." to "WIP: Clang: fix AST representation of expanded 
template arguments.".
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 456220.
mizvekov planned changes to this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/ast-dump-template-decls.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4793,6 +4793,44 @@
   ToD2->getDeclContext(), ToD2->getTemplateParameters()->getParam(0)));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportSubstTemplateTypeParmType) {
+  constexpr auto Code = R"(
+template  struct A {
+  using B = A1(A2...);
+};
+template struct A;
+)";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cpp");
+  auto *FromClass = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+
+  auto testType = [&](ASTContext &Ctx, const char *Name,
+  llvm::Optional PackIndex) {
+const auto *Subst = selectFirst(
+"sttp", match(substTemplateTypeParmType(
+  hasReplacementType(hasCanonicalType(asString(Name
+  .bind("sttp"),
+  Ctx));
+const char *ExpectedTemplateParamName = PackIndex ? "A2" : "A1";
+ASSERT_TRUE(Subst);
+ASSERT_EQ(Subst->getReplacedParameter()->getIdentifier()->getName(),
+  ExpectedTemplateParamName);
+ASSERT_EQ(Subst->getPackIndex(), PackIndex);
+  };
+  auto tests = [&](ASTContext &Ctx) {
+testType(Ctx, "void", None);
+testType(Ctx, "char", 0);
+testType(Ctx, "float", 1);
+testType(Ctx, "int", 2);
+testType(Ctx, "short", 3);
+  };
+
+  tests(FromTU->getASTContext());
+
+  ClassTemplateSpecializationDecl *ToClass = Import(FromClass, Lang_CXX11);
+  tests(ToClass->getASTContext());
+}
+
 const AstTypeMatcher
 substTemplateTypeParmPackType;
 
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -136,13 +136,13 @@
 };
 using t1 = foo::bind;
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename depth 0 index 0 ... Bs
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename depth 0 index 0 ... Bs pack_index 0
 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... Bs
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... Bs pack_index 1
 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... Bs
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... Bs pack_index 2
 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename depth 0 index 0 ... Bs
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar typename depth 0 index 0 ... Bs pack_index 3
 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'Z'
 
 template  struct D {
@@ -152,13 +152,13 @@
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'B' sugar alias B
 // CHECK:  FunctionProtoType 0x{{[^ ]*}} 'int (int (*)(float, int), int (*)(char, short))' cdecl
 // CHECK:  FunctionProtoType 0x{{[^ ]*}} 'int (float, int)' cdecl
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... T
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar typename depth 0 index 0 ... T pack_index 0
 // CHECK-NEXT: ClassTemplateSpecialization 0x{{[^ ]*}} 'D'
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... U
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar typename depth 0 index 0 ... U pack_index 0
 // CHECK-NEXT: TypeAliasTemplate 0x{{[^ ]*}} 'B'
 // CHECK:  FunctionProtoType 0x{{[^ ]*}} 'int (char, short)' cdecl
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar typename dep

[PATCH] D128095: [clang] Improve diagnostics for expansion length mismatch

2022-08-29 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplateVariadic.cpp:103-106
+VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *E) 
{
+  Unexpanded.push_back({E, E->getParameterPackLocation()});
+  return true;
+}

aaron.ballman wrote:
> Do we need to handle `FunctionParmPackExpr` as well?
Right, that and SubstTemplateTemplateParmPack are the two missing cases we 
could handle here, and perhaps that would allow us to get rid of that 'from 
outer parameter packs' diagnostics completely.

Would you prefer to handle everything in one patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128095

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


[PATCH] D128095: WIP: [clang] Improve diagnostics for expansion length mismatch

2022-08-29 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov retitled this revision from "[clang] Improve diagnostics for expansion 
length mismatch" to "WIP: [clang] Improve diagnostics for expansion length 
mismatch".
mizvekov updated this revision to Diff 456494.
mizvekov planned changes to this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128095

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaInternal.h
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
  clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
  clang/test/SemaTemplate/pack-deduction.cpp

Index: clang/test/SemaTemplate/pack-deduction.cpp
===
--- clang/test/SemaTemplate/pack-deduction.cpp
+++ clang/test/SemaTemplate/pack-deduction.cpp
@@ -134,14 +134,14 @@
   template struct tuple {};
   template struct A {
 template static pair, tuple> f(pair ...p);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 3)}}
 // expected-note@-2 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (at least 3 vs. 2) from outer parameter packs}}
 
 template static pair, tuple> g(pair ...p, ...);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 3)}}
 
 template static tuple h(tuple..., pair>);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 1) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 1)}}
   };
 
   pair, tuple> k1 = A().f(pair(), pair());
Index: clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
===
--- clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
+++ clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
@@ -97,7 +97,7 @@
   template  struct Constant {};
 
   template  struct Sum {
-template  using type = Constant<((Is + Js) + ... + 0)>; // expected-error {{pack expansion contains parameter pack 'Js' that has a different length (1 vs. 2) from outer parameter packs}}
+template  using type = Constant<((Is + Js) + ... + 0)>; // expected-error {{pack expansion contains parameter packs 'Is' and 'Js' that have different lengths (1 vs. 2)}}
   };
 
   Sum<1>::type<1, 2> x; // expected-note {{instantiation of}}
Index: clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -473,7 +473,7 @@
 namespace pr56094 {
 template  struct D {
   template  using B = int(int (*...p)(T, U));
-  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  // expected-error@-1 {{pack expansion contains parameter packs 'T' and 'U' that have different lengths (1 vs. 2)}}
   template  D(B *);
   // expected-note@-1 {{in instantiation of template type alias 'B' requested here}}
 };
@@ -484,7 +484,7 @@
 template  struct G {};
 template  struct E {
   template  using B = G...>;
-  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  // expected-error@-1 {{pack expansion contains parameter packs 'I' and 'U' that have different lengths (1 vs. 2)}}
   template  E(B *);
   // expected-note@-1 {{in instantiation of template type alias 'B' requested here}}
 };
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -88,6 +88,23 @@
   return true;
 }
 
+bool
+VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc TL) {
+  Unexpanded.push_back({TL.getTypePtr(), TL.getNameLoc()});
+  return true;
+}
+
+bool VisitSubstTemplateTypeParmPackType(SubstTemplateTypeParmPackType *T) {
+  Unexpanded.push_back({T, SourceLocation()});
+  return true;
+}
+
+bool
+VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *E) {
+  Unexpanded.push_back({E, E->getParameterPackLocation()});
+  return true;
+}
+
 /// Record occurrences of function a

[PATCH] D128095: [clang] Improve diagnostics for expansion length mismatch

2022-08-29 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov retitled this revision from "WIP: [clang] Improve diagnostics for 
expansion length mismatch" to "[clang] Improve diagnostics for expansion length 
mismatch".
mizvekov updated this revision to Diff 456495.
mizvekov marked 5 inline comments as done.
mizvekov requested review of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128095

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaInternal.h
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
  clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
  clang/test/SemaTemplate/pack-deduction.cpp

Index: clang/test/SemaTemplate/pack-deduction.cpp
===
--- clang/test/SemaTemplate/pack-deduction.cpp
+++ clang/test/SemaTemplate/pack-deduction.cpp
@@ -134,14 +134,14 @@
   template struct tuple {};
   template struct A {
 template static pair, tuple> f(pair ...p);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 3)}}
 // expected-note@-2 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (at least 3 vs. 2) from outer parameter packs}}
 
 template static pair, tuple> g(pair ...p, ...);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 3)}}
 
 template static tuple h(tuple..., pair>);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 1) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 1)}}
   };
 
   pair, tuple> k1 = A().f(pair(), pair());
Index: clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
===
--- clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
+++ clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
@@ -97,7 +97,7 @@
   template  struct Constant {};
 
   template  struct Sum {
-template  using type = Constant<((Is + Js) + ... + 0)>; // expected-error {{pack expansion contains parameter pack 'Js' that has a different length (1 vs. 2) from outer parameter packs}}
+template  using type = Constant<((Is + Js) + ... + 0)>; // expected-error {{pack expansion contains parameter packs 'Is' and 'Js' that have different lengths (1 vs. 2)}}
   };
 
   Sum<1>::type<1, 2> x; // expected-note {{instantiation of}}
Index: clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -473,7 +473,7 @@
 namespace pr56094 {
 template  struct D {
   template  using B = int(int (*...p)(T, U));
-  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  // expected-error@-1 {{pack expansion contains parameter packs 'T' and 'U' that have different lengths (1 vs. 2)}}
   template  D(B *);
   // expected-note@-1 {{in instantiation of template type alias 'B' requested here}}
 };
@@ -484,7 +484,7 @@
 template  struct G {};
 template  struct E {
   template  using B = G...>;
-  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  // expected-error@-1 {{pack expansion contains parameter packs 'I' and 'U' that have different lengths (1 vs. 2)}}
   template  E(B *);
   // expected-note@-1 {{in instantiation of template type alias 'B' requested here}}
 };
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -88,6 +88,23 @@
   return true;
 }
 
+bool
+VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc TL) {
+  Unexpanded.push_back({TL.getTypePtr(), TL.getNameLoc()});
+  return true;
+}
+
+bool VisitSubstTemplateTypeParmPackType(SubstTemplateTypeParmPackType *T) {
+  Unexpanded.push_back({T, SourceLocation()});
+  return true;
+}
+
+bool
+VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *E) {
+  Unexpanded.push_back({E, E->getParameterPackLocation()});
+  return true;
+}

[PATCH] D128095: [clang] Improve diagnostics for expansion length mismatch

2022-08-29 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplateVariadic.cpp:860
+} else if (const auto *ND = Unexpanded[I].first.get();
+   isa(ND)) {
+  // Function parameter pack or init-capture pack.

erichkeane wrote:
> This pattern with the init + condition is a little awkward here... any reason 
> to not just use the cast around the 'ND" and just use the VD in the use 
> below? or is there a good reason to split it up like this?
> 
> Same with the above case.
No very strong reason than that just from my different perception this looked 
fine :)

Minor advantage that we don't make the variable a VarDecl pointer if we don't 
need to access it as such.

But no strong preference here, I can have another look tomorrow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128095

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


[PATCH] D128095: [clang] Improve diagnostics for expansion length mismatch

2022-08-30 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 456682.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128095

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaInternal.h
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
  clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
  clang/test/SemaTemplate/pack-deduction.cpp

Index: clang/test/SemaTemplate/pack-deduction.cpp
===
--- clang/test/SemaTemplate/pack-deduction.cpp
+++ clang/test/SemaTemplate/pack-deduction.cpp
@@ -134,14 +134,14 @@
   template struct tuple {};
   template struct A {
 template static pair, tuple> f(pair ...p);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 3)}}
 // expected-note@-2 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (at least 3 vs. 2) from outer parameter packs}}
 
 template static pair, tuple> g(pair ...p, ...);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 3)}}
 
 template static tuple h(tuple..., pair>);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 1) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 1)}}
   };
 
   pair, tuple> k1 = A().f(pair(), pair());
Index: clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
===
--- clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
+++ clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
@@ -97,7 +97,7 @@
   template  struct Constant {};
 
   template  struct Sum {
-template  using type = Constant<((Is + Js) + ... + 0)>; // expected-error {{pack expansion contains parameter pack 'Js' that has a different length (1 vs. 2) from outer parameter packs}}
+template  using type = Constant<((Is + Js) + ... + 0)>; // expected-error {{pack expansion contains parameter packs 'Is' and 'Js' that have different lengths (1 vs. 2)}}
   };
 
   Sum<1>::type<1, 2> x; // expected-note {{instantiation of}}
Index: clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -473,7 +473,7 @@
 namespace pr56094 {
 template  struct D {
   template  using B = int(int (*...p)(T, U));
-  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  // expected-error@-1 {{pack expansion contains parameter packs 'T' and 'U' that have different lengths (1 vs. 2)}}
   template  D(B *);
   // expected-note@-1 {{in instantiation of template type alias 'B' requested here}}
 };
@@ -484,7 +484,7 @@
 template  struct G {};
 template  struct E {
   template  using B = G...>;
-  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  // expected-error@-1 {{pack expansion contains parameter packs 'I' and 'U' that have different lengths (1 vs. 2)}}
   template  E(B *);
   // expected-note@-1 {{in instantiation of template type alias 'B' requested here}}
 };
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -88,6 +88,23 @@
   return true;
 }
 
+bool
+VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc TL) {
+  Unexpanded.push_back({TL.getTypePtr(), TL.getNameLoc()});
+  return true;
+}
+
+bool VisitSubstTemplateTypeParmPackType(SubstTemplateTypeParmPackType *T) {
+  Unexpanded.push_back({T, SourceLocation()});
+  return true;
+}
+
+bool
+VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *E) {
+  Unexpanded.push_back({E, E->getParameterPackLocation()});
+  return true;
+}
+
 /// Record occurrences of function and non-type template
 /// parameter packs in an expression.
 bool VisitDeclRefExpr(DeclRefExpr *E) {
@@ -306,7 +323,8 @@
   auto *TTPD = dyn_cast(LocalPack);
   return TTPD && TTPD->getTy

[PATCH] D128095: [clang] Improve diagnostics for expansion length mismatch

2022-08-30 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplateVariadic.cpp:860
+} else if (const auto *ND = Unexpanded[I].first.get();
+   isa(ND)) {
+  // Function parameter pack or init-capture pack.

mizvekov wrote:
> erichkeane wrote:
> > This pattern with the init + condition is a little awkward here... any 
> > reason to not just use the cast around the 'ND" and just use the VD in the 
> > use below? or is there a good reason to split it up like this?
> > 
> > Same with the above case.
> No very strong reason than that just from my different perception this looked 
> fine :)
> 
> Minor advantage that we don't make the variable a VarDecl pointer if we don't 
> need to access it as such.
> 
> But no strong preference here, I can have another look tomorrow.
I played a little bit with this change.

I think one thing that makes that pattern of adding separate ND and VD a bit 
confusing is that at a glance it almost looks like these are different cases in 
the PointerUnion variant. You have to do a double take to see that, since the 
nested cast is a bit subtle. This can become even subtler as we add more cases 
in the next patch.

Or we could stop using PointerUnion on the next patch, since it's so 
unergonomic with so many variants.

Anyway, I did some other refactorings and I think in general this will be much 
clearer to read on my next push.

With this refactoring, on this part here that problem goes away since we make 
this section produce a NamedDecl.

On the second part, below, I tidied up the code so much that I think that 
nested else isn't almost invisible anymore, since the other blocks become about 
the same size.

Otherwise, let me know what you think.

I also added to this first part here a FIXME comment describing a pre-existing 
problem where if we get a canonical TTP, the diagnostics fail to point to the 
relevant parameter since we won't have it's identifier.

Will try to add a repro and fix for that on the next patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128095

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


[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-08-30 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

Just a first glance at the patch, will try to do a more comprehensive review 
later.




Comment at: clang/lib/Sema/SemaConcept.cpp:823
+  //
+  // Using the pattern is suffice because the partial ordering rules guarantee
+  // the template paramaters are equivalent.





Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:1838
 
-QualType Replacement = Arg.getAsType();
 

I think this change could be masking a bug.

The arguments to an instantiation should always be canonical.

We could implement one day instantiation with non-canonical args, but this 
would not be the only change required to get this to work.

And regardless it should be done in separate patch with proper test cases :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

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


[PATCH] D128095: [clang] Improve diagnostics for expansion length mismatch

2022-08-30 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a0309c53674: [clang] Improve diagnostics for expansion 
length mismatch (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128095

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaInternal.h
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
  clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
  clang/test/SemaTemplate/pack-deduction.cpp

Index: clang/test/SemaTemplate/pack-deduction.cpp
===
--- clang/test/SemaTemplate/pack-deduction.cpp
+++ clang/test/SemaTemplate/pack-deduction.cpp
@@ -134,14 +134,14 @@
   template struct tuple {};
   template struct A {
 template static pair, tuple> f(pair ...p);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 3)}}
 // expected-note@-2 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (at least 3 vs. 2) from outer parameter packs}}
 
 template static pair, tuple> g(pair ...p, ...);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 3)}}
 
 template static tuple h(tuple..., pair>);
-// expected-note@-1 {{[with U = ]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 1) from outer parameter packs}}
+// expected-note@-1 {{[with U = ]: pack expansion contains parameter packs 'T' and 'U' that have different lengths (2 vs. 1)}}
   };
 
   pair, tuple> k1 = A().f(pair(), pair());
Index: clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
===
--- clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
+++ clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
@@ -97,7 +97,7 @@
   template  struct Constant {};
 
   template  struct Sum {
-template  using type = Constant<((Is + Js) + ... + 0)>; // expected-error {{pack expansion contains parameter pack 'Js' that has a different length (1 vs. 2) from outer parameter packs}}
+template  using type = Constant<((Is + Js) + ... + 0)>; // expected-error {{pack expansion contains parameter packs 'Is' and 'Js' that have different lengths (1 vs. 2)}}
   };
 
   Sum<1>::type<1, 2> x; // expected-note {{instantiation of}}
Index: clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -473,7 +473,7 @@
 namespace pr56094 {
 template  struct D {
   template  using B = int(int (*...p)(T, U));
-  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  // expected-error@-1 {{pack expansion contains parameter packs 'T' and 'U' that have different lengths (1 vs. 2)}}
   template  D(B *);
   // expected-note@-1 {{in instantiation of template type alias 'B' requested here}}
 };
@@ -484,7 +484,7 @@
 template  struct G {};
 template  struct E {
   template  using B = G...>;
-  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  // expected-error@-1 {{pack expansion contains parameter packs 'I' and 'U' that have different lengths (1 vs. 2)}}
   template  E(B *);
   // expected-note@-1 {{in instantiation of template type alias 'B' requested here}}
 };
Index: clang/lib/Sema/SemaTemplateVariadic.cpp
===
--- clang/lib/Sema/SemaTemplateVariadic.cpp
+++ clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -88,6 +88,23 @@
   return true;
 }
 
+bool
+VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc TL) {
+  Unexpanded.push_back({TL.getTypePtr(), TL.getNameLoc()});
+  return true;
+}
+
+bool VisitSubstTemplateTypeParmPackType(SubstTemplateTypeParmPackType *T) {
+  Unexpanded.push_back({T, SourceLocation()});
+  return true;
+}
+
+bool
+VisitSubstNonTypeTemplateParmPackExpr(SubstNonTypeTemplateParmPackExpr *E) {
+  Unexpanded.push_back({E, E->getParameterPackLocation()});
+  return true;
+}
+
 /// Record occurrences of function and non-type template
 /// parameter packs in an expression.

[PATCH] D128095: [clang] Improve diagnostics for expansion length mismatch

2022-08-30 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked 2 inline comments as done.
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplateVariadic.cpp:860
+} else if (const auto *ND = Unexpanded[I].first.get();
+   isa(ND)) {
+  // Function parameter pack or init-capture pack.

erichkeane wrote:
> mizvekov wrote:
> > mizvekov wrote:
> > > erichkeane wrote:
> > > > This pattern with the init + condition is a little awkward here... any 
> > > > reason to not just use the cast around the 'ND" and just use the VD in 
> > > > the use below? or is there a good reason to split it up like this?
> > > > 
> > > > Same with the above case.
> > > No very strong reason than that just from my different perception this 
> > > looked fine :)
> > > 
> > > Minor advantage that we don't make the variable a VarDecl pointer if we 
> > > don't need to access it as such.
> > > 
> > > But no strong preference here, I can have another look tomorrow.
> > I played a little bit with this change.
> > 
> > I think one thing that makes that pattern of adding separate ND and VD a 
> > bit confusing is that at a glance it almost looks like these are different 
> > cases in the PointerUnion variant. You have to do a double take to see 
> > that, since the nested cast is a bit subtle. This can become even subtler 
> > as we add more cases in the next patch.
> > 
> > Or we could stop using PointerUnion on the next patch, since it's so 
> > unergonomic with so many variants.
> > 
> > Anyway, I did some other refactorings and I think in general this will be 
> > much clearer to read on my next push.
> > 
> > With this refactoring, on this part here that problem goes away since we 
> > make this section produce a NamedDecl.
> > 
> > On the second part, below, I tidied up the code so much that I think that 
> > nested else isn't almost invisible anymore, since the other blocks become 
> > about the same size.
> > 
> > Otherwise, let me know what you think.
> > 
> > I also added to this first part here a FIXME comment describing a 
> > pre-existing problem where if we get a canonical TTP, the diagnostics fail 
> > to point to the relevant parameter since we won't have it's identifier.
> > 
> > Will try to add a repro and fix for that on the next patch.
> Thanks for spending time on this... the nested conditionals on the var-decl 
> was hiding 90%+ of what was going on in the branch, and at least this top one 
> is BETTER enough than before.  I too hate the pointer union (note BTW, that 
> _4_ is the maximum number of elements thanks to 32 bit platforms, that'll 
> burn you :)).
> 
> 
Thanks, true about the maximum size :)

Some of the cases could be unified as we have two types and two expressions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128095

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


[PATCH] D127695: WIP: clang: Implement Template Specialization Resugaring

2022-08-30 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: libcxx/utils/ci/buildkite-pipeline.yml:377
+CFLAGS: "-fcrash-diagnostics-dir=crash_diagnostics_dir"
+CXXFLAGS: "-fcrash-diagnostics-dir=crash_diagnostics_dir"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"

Mordante wrote:
> I actually think this change would be nice for libc++ in general. I've has 
> several assertion failures in the bootstrapping CI. Especially with the 
> symbolizer available the crash reports become a lot better.
> 
> I'm not convinced the way you used the `CXXFLAGS` in the CMakeLists.txt is 
> the best way, maybe @ldionne has a better suggestion.
Ah, this is just an idea at this point, this is not even working for crashes in 
lit-tests, the `LIBCXX_TEST_COMPILER_FLAGS` setting below did not seem to work.

I would really appreciate suggestions, but meanwhile I'll try to get something 
minimally working here and spin a separate DR.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127695

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


[PATCH] D132952: [Sema] disable -Wvla for function array parameters

2022-08-30 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D132952#3759731 , @efriedma wrote:

> As a practical matter, there isn't any reason to force variably modified 
> parameters to make a function variably modified.  The types of parameters 
> aren't visible in the caller of a function; we only check the compatibility 
> for calls.
>
> Trying to treat `void (*)(int, int *)` as variably modified would have 
> additional complications, in that clang would internally need to have two 
> canonical types for `void (*)(int, int *)`: one variably modified, one not 
> variably modified.

I have been thinking about this problem for different reasons.

I wonder if the right solution here is to just change AdjustedType so that it 
desugars to the OriginalType instead of the AdjustedType, but keep the latter 
as the canonical type.
And not bother storing a separate QualType fot the AdjustedType.

That way, after a decay, the as-written type could be VM, but not the canonical 
type.

Similarly with `AttributedType` vis EquivalentType and ModifiedType.

We would lose though the nice property that a single step desugar always 
produces the same type.

I wonder how radical a change this would be for the users.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132952

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


[PATCH] D132990: [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()

2022-08-31 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a reviewer: mizvekov.
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:1534-1538
+  if (TInfo->getType()->getContainedAutoType()) {
 Diag(D.getIdentifierLoc(),
  diag::warn_cxx14_compat_template_nontype_parm_auto_type)
   << QualType(TInfo->getType()->getContainedAutoType(), 0);
   }

I think checking that the deduced type is undeduced was really unnecessary 
though, as I don't think we update the type source infos after deduction in any 
case.



Comment at: clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp:7
+
+template  // ok, no diagnostic expected
+void func() {}

I think this should have a new diagnostic per above, as this is not compatible 
with C++17.


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

https://reviews.llvm.org/D132990

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


[PATCH] D132990: [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()

2022-08-31 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp:1
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 -Wpre-c++17-compat %s
+

One thing we could do is to run this test also in std=c++17 mode, with a 
different expectancy, as a kind of sanity check that the warning is in sync.


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

https://reviews.llvm.org/D132990

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


[PATCH] D133072: WIP: [clang] fix profiling of template arguments of template and declaration kind

2022-08-31 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added projects: clang, libc++, All.
Herald added subscribers: libcxx-commits, cfe-commits.
Herald added a reviewer: libc++.
mizvekov requested review of this revision.

Template arguments of template and declaration kind were being profiled
only by their canonical properties, which would cause incorrect
uniquing of constrained AutoTypes, leading to a crash in some cases.

This exposed some places in CheckTemplateArguments where non-canonical
arguments where being pushed into the resulting converted list.

We also throw in some asserts to catch early and explain the crashes.

Note that the fix for the 'declaration' kind is untestable at this point,
because there should be no cases right now in the AST where we try
to unique a non-canonical converted template argument.

This fixes GH55567.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133072

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/concepts.cpp
  libcxx/DELETE.ME

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -256,3 +256,9 @@
 C auto **&j2 = g();  // expected-error {{deduced type 'int' does not satisfy 'C'}}
 C auto **&&j3 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}
 }
+
+namespace GH55567 {
+template class> concept C = true;
+template  struct S {};
+void f(C auto);
+} // namespace GH55567
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5643,7 +5643,8 @@
 if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
   return true;
 
-Converted.push_back(Arg.getArgument());
+Converted.push_back(
+Context.getCanonicalTemplateArgument(Arg.getArgument()));
 break;
 
   case TemplateArgument::Expression:
@@ -5813,13 +5814,14 @@
 if (!ArgumentPack.empty()) {
   // If we were part way through filling in an expanded parameter pack,
   // fall back to just producing individual arguments.
-  Converted.insert(Converted.end(),
-   ArgumentPack.begin(), ArgumentPack.end());
+  for (const TemplateArgument &I : ArgumentPack)
+Converted.push_back(Context.getCanonicalTemplateArgument(I));
   ArgumentPack.clear();
 }
 
 while (ArgIdx < NumArgs) {
-  Converted.push_back(NewArgs[ArgIdx].getArgument());
+  Converted.push_back(Context.getCanonicalTemplateArgument(
+  NewArgs[ArgIdx].getArgument()));
   ++ArgIdx;
 }
 
@@ -5952,7 +5954,8 @@
   if (ArgIdx < NumArgs && CurrentInstantiationScope &&
   CurrentInstantiationScope->getPartiallySubstitutedPack()) {
 while (ArgIdx < NumArgs && NewArgs[ArgIdx].getArgument().isPackExpansion())
-  Converted.push_back(NewArgs[ArgIdx++].getArgument());
+  Converted.push_back(Context.getCanonicalTemplateArgument(
+  NewArgs[ArgIdx++].getArgument()));
   }
 
   // If we have any leftover arguments, then there were too many arguments.
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -321,26 +321,15 @@
 
   case Declaration:
 getParamTypeForDecl().Profile(ID);
-ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr);
+ID.AddPointer(getAsDecl());
 break;
 
+  case TemplateExpansion:
+ID.AddInteger(TemplateArg.NumExpansions);
+LLVM_FALLTHROUGH;
   case Template:
-  case TemplateExpansion: {
-TemplateName Template = getAsTemplateOrTemplatePattern();
-if (TemplateTemplateParmDecl *TTP
-  = dyn_cast_or_null(
-Template.getAsTemplateDecl())) {
-  ID.AddBoolean(true);
-  ID.AddInteger(TTP->getDepth());
-  ID.AddInteger(TTP->getPosition());
-  ID.AddBoolean(TTP->isParameterPack());
-} else {
-  ID.AddBoolean(false);
-  ID.AddPointer(Context.getCanonicalTemplateName(Template)
-  .getAsVoidPointer());
-}
+getAsTemplateOrTemplatePattern().Profile(ID);
 break;
-  }
 
   case Integral:
 getAsIntegral().Profile(ID);
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5116,7 +5116,9 @@
CanonArgs);
 
 // Find the insert position again.
-DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
+[[maybe_unused]] auto *Nothing =
+DependentTemplateSpecializationTy

[PATCH] D133082: WIP: [clang] Implement setting crash_diagnostics_dir through env variable

2022-08-31 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added subscribers: libcxx-commits, cfe-commits, arichardson.
Herald added projects: clang, libc++, All.
Herald added a reviewer: libc++.
mizvekov requested review of this revision.
Herald added a subscriber: MaskRay.

This implements setting the equivalent of `-fcrash-diagnostics-dir`
through the environment variable `CLANG_CRASH_DIAGNOSTICS_DIR`.
If present, the flag still takes precedence.

This helps integration with test frameworks and pipelines.

With this feature, we change the libcxx bootstrapping build
pipeline to produce clang crash reproducers as artifacts.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133082

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/crash-diagnostics-dir-3.c
  libcxx/test/libcxx/crash.sh.cpp
  libcxx/utils/ci/buildkite-pipeline.yml


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: libcxx/test/libcxx/crash.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/crash.sh.cpp
@@ -0,0 +1,15 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Test that we produce the crash artifacts in the pipeline
+// For exposition only
+// FIXME: Delete this file
+
+// RUN: %{cxx} %{flags} %{compile_flags} -fsyntax-only %s
+
+#pragma clang __debug parser_crash
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | 
FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: 
{{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5422,15 +5422,17 @@
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
+  const char *CrashDirectory = CCGenDiagnostics && A
+   ? A->getValue()
+   : 
std::getenv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {
 if (!getVFS().exists(CrashDirectory))
   llvm::sys::fs::create_directories(CrashDirectory);
-llvm::sys::path::append(CrashDirectory, Prefix);
+SmallString<128> Path(CrashDirectory);
+llvm::sys::path::append(Path, Prefix);
 const char *Middle = !Suffix.empty() ? "-%%." : "-%%";
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-CrashDirectory + Middle + Suffix, TmpName);
-if (EC) {
+if (std::error_code EC =
+llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) {
   Diag(clang::diag::err_unable_to_make_temp) << EC.message();
   return "";
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -137,6 +137,10 @@
 
 New Compiler Flags
 --
+- It's now possible to set the crash diagnostics directory through
+  the environment variable 'CLANG_CRASH_DIAGNOSTICS_DIR'.
+  The '-fcrash-diagnostics-dir' flag takes precedence.
+
 
 Deprecated Compiler Flags
 -


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD

[PATCH] D133082: WIP: [clang] Implement setting crash_diagnostics_dir through env variable

2022-08-31 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 457159.
mizvekov planned changes to this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/crash-diagnostics-dir-3.c
  libcxx/test/libcxx/crash.sh.cpp
  libcxx/utils/ci/buildkite-pipeline.yml


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: libcxx/test/libcxx/crash.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/crash.sh.cpp
@@ -0,0 +1,15 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Test that we produce the crash artifacts in the pipeline
+// For exposition only
+// FIXME: Delete this file
+
+// RUN: not %{cxx} %{flags} %{compile_flags} -fsyntax-only %s
+
+#pragma clang __debug parser_crash
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | 
FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: 
{{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5422,15 +5422,17 @@
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
+  const char *CrashDirectory = CCGenDiagnostics && A
+   ? A->getValue()
+   : 
std::getenv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {
 if (!getVFS().exists(CrashDirectory))
   llvm::sys::fs::create_directories(CrashDirectory);
-llvm::sys::path::append(CrashDirectory, Prefix);
+SmallString<128> Path(CrashDirectory);
+llvm::sys::path::append(Path, Prefix);
 const char *Middle = !Suffix.empty() ? "-%%." : "-%%";
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-CrashDirectory + Middle + Suffix, TmpName);
-if (EC) {
+if (std::error_code EC =
+llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) {
   Diag(clang::diag::err_unable_to_make_temp) << EC.message();
   return "";
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -137,6 +137,10 @@
 
 New Compiler Flags
 --
+- It's now possible to set the crash diagnostics directory through
+  the environment variable 'CLANG_CRASH_DIAGNOSTICS_DIR'.
+  The '-fcrash-diagnostics-dir' flag takes precedence.
+
 
 Deprecated Compiler Flags
 -


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: libcxx/test/libcxx/crash.sh.cpp
===
--- /dev/null
+++ libcxx/test/libcxx/crash.sh.cpp
@@ -0,0 +1,15 @@
+//===--===//
+//
+// Part of th

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:3748-3751
+  // If it is a template, import all related things.
+  if (Error Err = ImportTemplateInformation(D, ToFunction))
+return std::move(Err);
+

martong wrote:
> What's the reason of moving this hunk?
All the changes here to the ASTImporter revolve around the need to import the 
template bits before the type, as now the type itself can depend on the 
templated declaration, and this would cause a cycle otherwise.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D133072: [clang] fix profiling of template arguments of template and declaration kind

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:5119
 // Find the insert position again.
-DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
+[[maybe_unused]] auto *Nothing =
+DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, 
InsertPos);

erichkeane wrote:
> Instead of `maybe_unused` put this and the assert inside of a `#if NDEBUG` so 
> we don't do the `Nothing` work.  Same below.
We still need to do the `FindNodeOrInsertPos` bit, to refresh the insert 
position.
So I think this would end up too noisy to add two sets of blocks.



Comment at: clang/lib/Sema/SemaTemplate.cpp:5817
   // fall back to just producing individual arguments.
-  Converted.insert(Converted.end(),
-   ArgumentPack.begin(), ArgumentPack.end());
+  for (const TemplateArgument &I : ArgumentPack)
+Converted.push_back(Context.getCanonicalTemplateArgument(I));

erichkeane wrote:
> Ooh, thats a transform!  
> 
> `llvm::transform(ArgumentPack, std::back_inserter(Converted), [](const auto 
> &I) { return Context.getCanonicalTemplateArgument(I));`
That is true, though unless we can come up with a clearer spelling for that, it 
looks less readable to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133072

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


[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D131858#3763851 , @erichkeane 
wrote:

> Just did a quick scroll through this (as it is quite large!), but the general 
> idea seems like a fine one to me.  I AM concerned about how it interacts with 
> the deferred concepts instantiation that I've been working on 
> (https://reviews.llvm.org/D126907), particularly around the MLTAL work.

I think I did rebase it on top of that at one point, thought it was short lived 
as it was reverted if I am not mistaken.
But I can certainly do it again if you merge yours first, and I am available 
any time to help if it happens the other way around.

But the gist of the change is simple, you will simply have to pass in the 
templated declaration for every level that you push into the MLTAL.
I think that should be the only change that affects you, besides possibly churn 
in AST tests if you plan to have any.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D133072: [clang] fix profiling of template arguments of template and declaration kind

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:5817
   // fall back to just producing individual arguments.
-  Converted.insert(Converted.end(),
-   ArgumentPack.begin(), ArgumentPack.end());
+  for (const TemplateArgument &I : ArgumentPack)
+Converted.push_back(Context.getCanonicalTemplateArgument(I));

erichkeane wrote:
> mizvekov wrote:
> > erichkeane wrote:
> > > Ooh, thats a transform!  
> > > 
> > > `llvm::transform(ArgumentPack, std::back_inserter(Converted), [](const 
> > > auto &I) { return Context.getCanonicalTemplateArgument(I));`
> > That is true, though unless we can come up with a clearer spelling for 
> > that, it looks less readable to me.
> But I like transform :(
I will think of something, even if we have to add a new helper :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133072

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


[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D131858#3763892 , @erichkeane 
wrote:

> In D131858#3763878 , @mizvekov 
> wrote:
>
>> In D131858#3763851 , @erichkeane 
>> wrote:
>>
>>> Just did a quick scroll through this (as it is quite large!), but the 
>>> general idea seems like a fine one to me.  I AM concerned about how it 
>>> interacts with the deferred concepts instantiation that I've been working 
>>> on (https://reviews.llvm.org/D126907), particularly around the MLTAL work.
>>
>> I think I did rebase it on top of that at one point, thought it was short 
>> lived as it was reverted if I am not mistaken.
>> But I can certainly do it again if you merge yours first, and I am available 
>> any time to help if it happens the other way around.
>>
>> But the gist of the change is simple, you will simply have to pass in the 
>> templated declaration for every level that you push into the MLTAL.
>> I think that should be the only change that affects you, besides possibly 
>> churn in AST tests if you plan to have any.
>
> Part of the problem is that the concepts instantiation needs to reform the 
> MLTAL AFTER the fact using `Sema::getTemplateInstantiationArgs` and 
> `addInstantiatedParametersToScope`.  BUT I don't se the corresponding changes 
> on quick look here.
>
> As far as which goes first, I obviously have my preference, since I'm about 
> 10 months into that patch now :/  I'm still working through a couple of 
> issues though.

`getTemplateInstantiationArgs` is updated in this patch to build the MLTAL with 
the new information.

I don' have any changes to `addInstantiatedParametersToScope`, as that doesn't 
modify MLTAL, it just forwards it to SubstType.

No worries about who merges first, you are racing @rsmith here, you will win 
easily :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:5425
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
+  const char *CrashDirectory = CCGenDiagnostics && A
+   ? A->getValue()

erichkeane wrote:
> `StringRef` would be better here instead, which should mean you don't have to 
> create the SmallString below, and could just work in `Twine`s for everything.
It seems that `llvm::sys::path::append` takes twine as inputs, but it only 
outputs to a SmallVectorImpl.
Unless there is something else I could use?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:5425
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
+  const char *CrashDirectory = CCGenDiagnostics && A
+   ? A->getValue()

erichkeane wrote:
> mizvekov wrote:
> > erichkeane wrote:
> > > `StringRef` would be better here instead, which should mean you don't 
> > > have to create the SmallString below, and could just work in `Twine`s for 
> > > everything.
> > It seems that `llvm::sys::path::append` takes twine as inputs, but it only 
> > outputs to a SmallVectorImpl.
> > Unless there is something else I could use?
> Ah, yikes, I  missed that was what was happening :/  THAT is still necessary. 
>  A Twine can be created from a stringref (and I'd still prefer one anyway), 
> but you DO still have to make that SmallString unfortunately.
The Twine also can't take a nullptr (such as the case no flag passed and no env 
variable), so we would have to use something like `std::optional`, and 
make the needed conversions here.

And the Twine to SmallString copy looks unergonomic as well.

So it seems we would need to make some little changes out of scope of this MR 
to get that to look nicely.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:5425
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
+  const char *CrashDirectory = CCGenDiagnostics && A
+   ? A->getValue()

erichkeane wrote:
> mizvekov wrote:
> > erichkeane wrote:
> > > mizvekov wrote:
> > > > erichkeane wrote:
> > > > > `StringRef` would be better here instead, which should mean you don't 
> > > > > have to create the SmallString below, and could just work in `Twine`s 
> > > > > for everything.
> > > > It seems that `llvm::sys::path::append` takes twine as inputs, but it 
> > > > only outputs to a SmallVectorImpl.
> > > > Unless there is something else I could use?
> > > Ah, yikes, I  missed that was what was happening :/  THAT is still 
> > > necessary.  A Twine can be created from a stringref (and I'd still prefer 
> > > one anyway), but you DO still have to make that SmallString unfortunately.
> > The Twine also can't take a nullptr (such as the case no flag passed and no 
> > env variable), so we would have to use something like 
> > `std::optional`, and make the needed conversions here.
> > 
> > And the Twine to SmallString copy looks unergonomic as well.
> > 
> > So it seems we would need to make some little changes out of scope of this 
> > MR to get that to look nicely.
> I guess i don't get the concern here?  I'm suggesting just changing this from 
> `const char*` to `StringRef` (which should work).  Everything else below 
> should 'just work' AFAIK.
Oh okay I misunderstood you! Thought you meant to make CrashDirectory a Twine.

Yeah with `StringRef` we only need to change the test:

```
if (CrashDirectory) {
```
--->
```
if (CrashDirectory.data() != nullptr) {
```

Everything else stays the same. It doesn't look cleaner, but would address your 
concerns about avoiding storing a char pointer variable?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:5425
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
+  const char *CrashDirectory = CCGenDiagnostics && A
+   ? A->getValue()

mizvekov wrote:
> erichkeane wrote:
> > mizvekov wrote:
> > > erichkeane wrote:
> > > > mizvekov wrote:
> > > > > erichkeane wrote:
> > > > > > `StringRef` would be better here instead, which should mean you 
> > > > > > don't have to create the SmallString below, and could just work in 
> > > > > > `Twine`s for everything.
> > > > > It seems that `llvm::sys::path::append` takes twine as inputs, but it 
> > > > > only outputs to a SmallVectorImpl.
> > > > > Unless there is something else I could use?
> > > > Ah, yikes, I  missed that was what was happening :/  THAT is still 
> > > > necessary.  A Twine can be created from a stringref (and I'd still 
> > > > prefer one anyway), but you DO still have to make that SmallString 
> > > > unfortunately.
> > > The Twine also can't take a nullptr (such as the case no flag passed and 
> > > no env variable), so we would have to use something like 
> > > `std::optional`, and make the needed conversions here.
> > > 
> > > And the Twine to SmallString copy looks unergonomic as well.
> > > 
> > > So it seems we would need to make some little changes out of scope of 
> > > this MR to get that to look nicely.
> > I guess i don't get the concern here?  I'm suggesting just changing this 
> > from `const char*` to `StringRef` (which should work).  Everything else 
> > below should 'just work' AFAIK.
> Oh okay I misunderstood you! Thought you meant to make CrashDirectory a Twine.
> 
> Yeah with `StringRef` we only need to change the test:
> 
> ```
> if (CrashDirectory) {
> ```
> --->
> ```
> if (CrashDirectory.data() != nullptr) {
> ```
> 
> Everything else stays the same. It doesn't look cleaner, but would address 
> your concerns about avoiding storing a char pointer variable?
We could add a bool conversion to StringRef, but perhaps folks could find the 
meaning confusing between empty and null pointer?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:5425
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
+  const char *CrashDirectory = CCGenDiagnostics && A
+   ? A->getValue()

erichkeane wrote:
> mizvekov wrote:
> > mizvekov wrote:
> > > erichkeane wrote:
> > > > mizvekov wrote:
> > > > > erichkeane wrote:
> > > > > > mizvekov wrote:
> > > > > > > erichkeane wrote:
> > > > > > > > `StringRef` would be better here instead, which should mean you 
> > > > > > > > don't have to create the SmallString below, and could just work 
> > > > > > > > in `Twine`s for everything.
> > > > > > > It seems that `llvm::sys::path::append` takes twine as inputs, 
> > > > > > > but it only outputs to a SmallVectorImpl.
> > > > > > > Unless there is something else I could use?
> > > > > > Ah, yikes, I  missed that was what was happening :/  THAT is still 
> > > > > > necessary.  A Twine can be created from a stringref (and I'd still 
> > > > > > prefer one anyway), but you DO still have to make that SmallString 
> > > > > > unfortunately.
> > > > > The Twine also can't take a nullptr (such as the case no flag passed 
> > > > > and no env variable), so we would have to use something like 
> > > > > `std::optional`, and make the needed conversions here.
> > > > > 
> > > > > And the Twine to SmallString copy looks unergonomic as well.
> > > > > 
> > > > > So it seems we would need to make some little changes out of scope of 
> > > > > this MR to get that to look nicely.
> > > > I guess i don't get the concern here?  I'm suggesting just changing 
> > > > this from `const char*` to `StringRef` (which should work).  Everything 
> > > > else below should 'just work' AFAIK.
> > > Oh okay I misunderstood you! Thought you meant to make CrashDirectory a 
> > > Twine.
> > > 
> > > Yeah with `StringRef` we only need to change the test:
> > > 
> > > ```
> > > if (CrashDirectory) {
> > > ```
> > > --->
> > > ```
> > > if (CrashDirectory.data() != nullptr) {
> > > ```
> > > 
> > > Everything else stays the same. It doesn't look cleaner, but would 
> > > address your concerns about avoiding storing a char pointer variable?
> > We could add a bool conversion to StringRef, but perhaps folks could find 
> > the meaning confusing between empty and null pointer?
> Hrm... do we actually have meaning here to 'empty' for these files?  I guess 
> we allow it already hrm... Ok, disregard the suggestion, and thanks for 
> thinking this through with me.
Thanks for the review and suggestions!

Yeah right, I didn't want to change the behavior vs empty here, but I think if 
we did some change, it would make more sense to create some specific error for 
it, instead of treating empty the same as no argument passed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D133082#3764256 , @aaron.ballman 
wrote:

> We use environment variables in several other places within the driver, but I 
> am a bit skittish about adding new ones to correspond to feature flags as 
> that seems to be somewhat novel. I think it'd be a good idea to get more 
> buy-in with an RFC on Discourse for more broad awareness.
>
> If we go this route, we definitely need user-facing documentation that 
> explains what's going on. I don't think we have anything corresponding to 
> https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html, but having 
> such a page for Clang would be a good idea (even if the page is incomplete).

Okay, fair!

We will have an RFC about this.




Comment at: clang/lib/Driver/Driver.cpp:5427
+   ? A->getValue()
+   : 
std::getenv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {

aaron.ballman wrote:
> This should use `llvm::sys::Process::GetEnv()` so it properly handles text 
> encodings. CC @tahonermann @cor3ntin for text encoding awareness.
Okay, makes sense. But be aware that we have multiple places in the llvm 
project where we are using std::getenv to retrieve a filesystem path variable. 
There is another one within clang itself as well (`CLANG_MODULE_CACHE_PATH`, 
which is where I took inspiration from).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: libcxx/test/libcxx/crash.sh.cpp:15
+
+#pragma clang __debug parser_crash

Mordante wrote:
> The libc++ build seems to be green. I assume it was intended to be red so we 
> can validate the artifact is available in the CI.
If I made it red, this test would fail in one the jobs from the early group, 
and we would never run the bootstraping job :(

But making it green does not stop it from exporting the artifact, you can go in 
there in the build results and have a look!



Comment at: libcxx/utils/ci/buildkite-pipeline.yml:377
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:

Mordante wrote:
> Are relative directories allowed?
Yes, it already worked with the flag.

You can check that it's working, even though the bootstrapping pipeline is 
green, it still exports the artifacts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 457327.
mizvekov marked 10 inline comments as done.
mizvekov requested review of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/crash-diagnostics-dir-3.c
  libcxx/utils/ci/buildkite-pipeline.yml


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | 
FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: 
{{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5417,15 +5417,18 @@
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
-if (!getVFS().exists(CrashDirectory))
-  llvm::sys::fs::create_directories(CrashDirectory);
-llvm::sys::path::append(CrashDirectory, Prefix);
+  Optional CrashDirectory =
+  CCGenDiagnostics && A
+  ? std::string(A->getValue())
+  : llvm::sys::Process::GetEnv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {
+if (!getVFS().exists(*CrashDirectory))
+  llvm::sys::fs::create_directories(*CrashDirectory);
+SmallString<128> Path(*CrashDirectory);
+llvm::sys::path::append(Path, Prefix);
 const char *Middle = !Suffix.empty() ? "-%%." : "-%%";
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-CrashDirectory + Middle + Suffix, TmpName);
-if (EC) {
+if (std::error_code EC =
+llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) {
   Diag(clang::diag::err_unable_to_make_temp) << EC.message();
   return "";
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -137,6 +137,10 @@
 
 New Compiler Flags
 --
+- It's now possible to set the crash diagnostics directory through
+  the environment variable ``CLANG_CRASH_DIAGNOSTICS_DIR``.
+  The ``-fcrash-diagnostics-dir`` flag takes precedence.
+
 
 Deprecated Compiler Flags
 -


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: {{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5417,15 +5417,18 @@
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue())

[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 457462.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/crash-diagnostics-dir-3.c
  libcxx/utils/ci/buildkite-pipeline.yml

Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: {{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5417,15 +5417,18 @@
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
-if (!getVFS().exists(CrashDirectory))
-  llvm::sys::fs::create_directories(CrashDirectory);
-llvm::sys::path::append(CrashDirectory, Prefix);
+  Optional CrashDirectory =
+  CCGenDiagnostics && A
+  ? std::string(A->getValue())
+  : llvm::sys::Process::GetEnv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {
+if (!getVFS().exists(*CrashDirectory))
+  llvm::sys::fs::create_directories(*CrashDirectory);
+SmallString<128> Path(*CrashDirectory);
+llvm::sys::path::append(Path, Prefix);
 const char *Middle = !Suffix.empty() ? "-%%." : "-%%";
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-CrashDirectory + Middle + Suffix, TmpName);
-if (EC) {
+if (std::error_code EC =
+llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) {
   Diag(clang::diag::err_unable_to_make_temp) << EC.message();
   return "";
 }
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -687,6 +687,11 @@
   Specify where to write the crash diagnostics files; defaults to the
   usual location for temporary files.
 
+.. envvar:: CLANG_CRASH_DIAGNOSTICS_DIR
+
+   Like :option:`-fcrash-diagnostics-dir=`, specifies where to write the
+   crash diagnostics files, but with lower precedence than the option.
+
 Clang is also capable of generating preprocessed source file(s) and associated
 run script(s) even without a crash. This is specially useful when trying to
 generate a reproducer for warnings or errors while using modules.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -134,6 +134,9 @@
 
 Non-comprehensive list of changes in this release
 -
+- It's now possible to set the crash diagnostics directory through
+  the environment variable ``CLANG_CRASH_DIAGNOSTICS_DIR``.
+  The ``-fcrash-diagnostics-dir`` flag takes precedence.
 
 New Compiler Flags
 --
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -895,6 +895,10 @@
 
 Put crash-report files in 
 
+.. envvar:: CLANG_CRASH_DIAGNOSTICS_DIR=
+
+Put crash-report files in , with a lower precedence than :option:`-fcrash-diagnostics-dir=`
+
 .. option:: -fcrash-diagnostics=, -fcrash-diagnostics (equivalent to -fcrash-diagnostics=compiler)
 
 Set level of crash diagnostic reporting, (option: off, compiler, all)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D133082#3764256 , @aaron.ballman 
wrote:

> If we go this route, we definitely need user-facing documentation that 
> explains what's going on. I don't think we have anything corresponding to 
> https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html, but having 
> such a page for Clang would be a good idea (even if the page is incomplete).

I took an attempt at this on the latest diff.
I am suggesting we put the variables close to command line flags, in the same 
document, as I think it makes sense to have these options that interact with 
each other close together.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 457468.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/crash-diagnostics-dir-3.c
  libcxx/utils/ci/buildkite-pipeline.yml

Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: {{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5417,15 +5417,18 @@
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
-if (!getVFS().exists(CrashDirectory))
-  llvm::sys::fs::create_directories(CrashDirectory);
-llvm::sys::path::append(CrashDirectory, Prefix);
+  Optional CrashDirectory =
+  CCGenDiagnostics && A
+  ? std::string(A->getValue())
+  : llvm::sys::Process::GetEnv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {
+if (!getVFS().exists(*CrashDirectory))
+  llvm::sys::fs::create_directories(*CrashDirectory);
+SmallString<128> Path(*CrashDirectory);
+llvm::sys::path::append(Path, Prefix);
 const char *Middle = !Suffix.empty() ? "-%%." : "-%%";
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-CrashDirectory + Middle + Suffix, TmpName);
-if (EC) {
+if (std::error_code EC =
+llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) {
   Diag(clang::diag::err_unable_to_make_temp) << EC.message();
   return "";
 }
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -687,6 +687,11 @@
   Specify where to write the crash diagnostics files; defaults to the
   usual location for temporary files.
 
+.. envvar:: CLANG_CRASH_DIAGNOSTICS_DIR=
+
+   Like :option:`-fcrash-diagnostics-dir=`, specifies where to write the
+   crash diagnostics files, but with lower precedence than the option.
+
 Clang is also capable of generating preprocessed source file(s) and associated
 run script(s) even without a crash. This is specially useful when trying to
 generate a reproducer for warnings or errors while using modules.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -134,6 +134,9 @@
 
 Non-comprehensive list of changes in this release
 -
+- It's now possible to set the crash diagnostics directory through
+  the environment variable ``CLANG_CRASH_DIAGNOSTICS_DIR``.
+  The ``-fcrash-diagnostics-dir`` flag takes precedence.
 
 New Compiler Flags
 --
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -895,6 +895,10 @@
 
 Put crash-report files in 
 
+.. envvar:: CLANG_CRASH_DIAGNOSTICS_DIR=
+
+Put crash-report files in , with a lower precedence than :option:`-fcrash-diagnostics-dir=`
+
 .. option:: -fcrash-diagnostics=, -fcrash-diagnostics (equivalent to -fcrash-diagnostics=compiler)
 
 Set level of crash diagnostic reporting, (option: off, compiler, all)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132990: [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:1534-1538
+  if (TInfo->getType()->getContainedAutoType()) {
 Diag(D.getIdentifierLoc(),
  diag::warn_cxx14_compat_template_nontype_parm_auto_type)
   << QualType(TInfo->getType()->getContainedAutoType(), 0);
   }

shafik wrote:
> shafik wrote:
> > mizvekov wrote:
> > > I think checking that the deduced type is undeduced was really 
> > > unnecessary though, as I don't think we update the type source infos 
> > > after deduction in any case.
> > I am not sure about the `DeducedTemplateSpecializationType` I was looking 
> > at the change that brought in that type and it is not clear to me what a 
> > good test would be. I believe outside of C++17 mode they would be hard 
> > errors.  Can you provide an example that would work outside of C++17 mode?
> The `DeducedTemplateSpecializationType` also feels a bit outside the bug I am 
> fixing so I might just choose to address it in a follow-up.
Well the bit on your test below, which you marked with no diagnostic expected, 
is an example.

This is something that works on C++20 but not on C++17, which is what this 
warning is supposed to warn, right?


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

https://reviews.llvm.org/D132990

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:2819-2823
+  // For two canonically equal types, return a type which has
+  // the common sugar between them. If Unqualified is true,
+  // both types need only be the same unqualified type.
+  // The result will drop the qualifiers which do not occur
+  // in both types.

ChuanqiXu wrote:
> For this comment, I want to know what if `X`and `Y` is not equal. Is there an 
> assertion failure or special type returned?
Assertion failure, the function is supposed to handle only the case where 
`hasSame[Unqualified]Type(X, Y) == true`.

It will always return a type `R` for which `hasSame[Unqualified]Type(R, Y) == 
true` also holds, so there are no special return values.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

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


[PATCH] D130308: [clang] extend getCommonSugaredType to merge sugar nodes

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:1369
   }
+  QualType getDecayedType(QualType T, QualType Decayed) const;
 

ChuanqiXu wrote:
> Maybe we need a comment for this. The signature looks not straight forward 
> and I can't relate this to the above comment.
I think I wanted to make this an internal variant, since we will probably never 
need this outside of ASTContext anyway, but there is the friendship situation 
between Type and ASTContext. Maybe making this private would be for the best.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130308

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


[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:623-626
+  VisitDeclaratorDecl(D);
+  Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
+  Record.push_back(D->getIdentifierNamespace());
+

ChuanqiXu wrote:
> I still don't get the reason for the move. What's the benefit? Or why is it 
> necessary?
Yeah, now the type can reference the template decl, so without moving this, it 
can happen during import of the type that we try to read this function template 
bits without having imported them yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D130308: [clang] extend getCommonSugaredType to merge sugar nodes

2022-09-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:1369
   }
+  QualType getDecayedType(QualType T, QualType Decayed) const;
 

ChuanqiXu wrote:
> mizvekov wrote:
> > ChuanqiXu wrote:
> > > Maybe we need a comment for this. The signature looks not straight 
> > > forward and I can't relate this to the above comment.
> > I think I wanted to make this an internal variant, since we will probably 
> > never need this outside of ASTContext anyway, but there is the friendship 
> > situation between Type and ASTContext. Maybe making this private would be 
> > for the best.
> Yeah, the signature confused me as well... as long as the second parameter is 
> `Decayed` already, why we need to get the decayed type again? I guess 
> `Underlying` may be a better name.
Ah I see, but this confusion already existed. See the definition of DecayedType 
in Type.h, where you have the `QualType getDecayedType()` member. This is what 
this Decayed parameter represents, what we will put in there to be returned by 
that method.

For DecayedType / AdjustedType / AttributedType there exists this confusion 
where they have two child nodes, which arbitrarily picking one of them to be 
called the `UnderlyingType` could be controversial. You could make the case 
that it should be the same one we use for implementing `desugar`, but there are 
arguments there for the other case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130308

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


[PATCH] D133209: [clang] Document environment variables used by the driver

2022-09-02 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We also mention limitations with regards to character encoding support.

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133209

Files:
  clang/docs/ClangCommandLineReference.rst

Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -5,7 +5,7 @@
   ---
 
 =
-Clang command line argument reference
+Clang command line reference
 =
 .. contents::
:local:
@@ -13,7 +13,7 @@
 Introduction
 
 
-This page lists the command line arguments currently supported by the
+This page lists the command line arguments and environment variables currently supported by the
 GCC-compatible ``clang`` and ``clang++`` drivers.
 
 
@@ -22,6 +22,11 @@
 
 Search $prefix$file for executables, libraries, and data files. If $prefix is a directory, search $prefix/$file
 
+.. envvar:: COMPILER_PATH=
+
+Search $paths for executables, libraries, and data files. The value is a list of paths separated by a system standard
+separator. On Windows and Unix, this separator should be colon, just like ``PATH``.
+
 .. option:: -F
 
 Add directory to framework include search path
@@ -349,8 +354,51 @@
 
 Run the migrator
 
+.. option:: -mmacosx-version-min=
+
+Sets the deployment target version (macOS only)
+
+.. evnvar:: MACOSX_DEPLOYMENT_TARGET
+
+Sets the deployment target version (macOS only).
+This variable might not correctly handle non-ASCII characters in some hosts.
+
 .. option:: -mios-simulator-version-min=, -miphonesimulator-version-min=
 
+Sets the deployment target version (iOS only)
+
+.. evnvar:: IPHONEOS_DEPLOYMENT_TARGET
+
+Sets the deployment target version (iOS only).
+This variable might not correctly handle non-ASCII characters in some hosts.
+
+.. option:: -mtvos-version-min=
+
+Sets the deployment target version (tvOS only)
+
+.. evnvar:: TVOS_DEPLOYMENT_TARGET
+
+Sets the deployment target version (tvOS only).
+This variable might not correctly handle non-ASCII characters in some hosts.
+
+.. option:: -mwatchos-version-min=
+
+Sets the deployment target version (watchOS only)
+
+.. evnvar:: WATCHOS_DEPLOYMENT_TARGET
+
+Sets the deployment target version (watchOS only).
+This variable might not correctly handle non-ASCII characters in some hosts.
+
+.. option:: -mdriverkit-version-min=
+
+Sets the deployment target version (DriverKit only)
+
+.. evnvar:: DRIVERKIT_DEPLOYMENT_TARGET
+
+Sets the deployment target version (DriverKit only).
+This variable might not correctly handle non-ASCII characters in some hosts.
+
 .. option:: -mlinker-version=
 
 .. option:: -mlittle-endian, -EL
@@ -1166,6 +1214,14 @@
 paths, for example if also specified with -isystem, the -I option
 will be ignored
 
+.. envvar:: CPATH=
+
+Takes a list of paths to add to the include search path, like :option:`-I`.
+The value is a list of paths separated by a system standard separator.
+On Windows and Unix, this separator should be colon, just like ``PATH``.
+
+This variable might not correctly handle non-ASCII characters in some hosts.
+
 .. option:: -I-, --include-barrier
 
 Restrict all prior -I flags to double-quoted inclusion and remove current directory from include path
@@ -1182,10 +1238,6 @@
 
 CUDA installation path
 
-.. option:: -cxx-isystem
-
-Add directory to the C++ SYSTEM include search path
-
 .. option:: -fbuild-session-file=
 
 Use the last modification time of  as the build session timestamp
@@ -1202,6 +1254,12 @@
 
 Specify the module cache path
 
+.. envvar:: CLANG_MODULE_CACHE_PATH=
+
+Specify the module cache path.
+Will be used as a fallback if ::option::`-fmodules-cache-path=` is not specified.
+This variable might not correctly handle non-ASCII characters in some hosts.
+
 .. option:: -fmodules-disable-diagnostic-validation
 
 Disable validation of the diagnostic options when loading the module
@@ -1270,6 +1328,31 @@
 
 Set the system root directory (usually /)
 
+.. envvar:: SDKROOT=
+
+Set the system root directory, with a lower precedence than :option:`-isysroot` (Darwin only).
+This variable might not correctly handle non-ASCII characters in some hosts.
+
+.. envvar:: RC_DEBUG_OPTIONS=
+
+Sets DWARF debug flag if $val is not empty (Darwin only).
+This variable might not correctly handle non-ASCII characters in some hosts.
+
+.. envvar:: RC_DEBUG_PREFIX_MAP=
+
+Sets debug path remapping (Darwin only).
+This variable might not correctly handle non-ASCII characters in some hosts.
+
+.. envvar:: SCE_ORBIS_SDK_DIR=
+
+Determine where to find the libraries (PS4 only).
+This variable might not correctly handle no

[PATCH] D133209: [clang] Document environment variables used by the driver

2022-09-02 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/docs/ClangCommandLineReference.rst:2-5
   ---
   NOTE: This file is automatically generated by running clang-tblgen
   -gen-opt-docs. Do not edit this file by hand!!
   ---

aaron.ballman wrote:
> I think you might have missed this bit. ;-)
> 
> @jansvoboda11 -- do you know of an ergonomic way for people to associate 
> extra documentation along with the command line reference to support adding 
> documentation like this? This is the second time in the past hour I've seen 
> people adding documentation directly to this file and the docs would be kind 
> of onerous to put in `HelpText<>` directly. I'm wondering if the FE options 
> can support something along the lines of AttrDocs.td where we can specify 
> some out-of-line documentation in another .td for things that are nontrivial 
> to document?
Ooops!

Why do we even commit this file then? :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133209

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


[PATCH] D126172: [clang] Fix comparison of TemplateArgument when they are of template kind

2022-09-02 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D126172#3767188 , @roberteg16 
wrote:

> Hey @mizvekov! Sorry for the late response.
>
> Yes, I am still interested and I am working on this. I'll let you know ASAP 
> if I find something that resembles a valid fix.
>
> I would be very grateful if you could give me some tips for debuging better 
> clang or if you could point me towards documents, links, whatever that could 
> give me nice information about how to reason about the code of the 
> parser/sema of clang.
>
> If you are in a hurry and need to fix it yourself and it happens that you 
> finish the path first, please @ me so I can get to see how an error like this 
> would be fixed, thanks!

Hello! Yeah you were just a bit too late, I have a patch that is accepted and 
should go in soon: https://reviews.llvm.org/D133072
I had run into this problem while making changes around 
CheckTemplateArgumentList, and I have this big patch which I am trying to 
offload into smaller chunks to expedite review.

I don't have any documents to recommend besides the obvious things, like the 
Clang docs auto-generated from the source code.
If you do want to get started, I can only recommend what worked for me, which 
is to try fixing bugs first, much like you tried here.
Though perhaps it's not very productive to get stuck in any one for a very long 
time, instead just ask for help or move on :)

I think that if you want to implement something new or a more substantial 
change, being able to debug quickly certainly helps.
There is no way you are going to be able to understand what is going on early 
on, so you will make a big mess, break hundreds of tests and so on, and being 
able to quickly go over and understand what is going on with them is important.
Invest in isolating bugs before working on them, it always pays off.

When fixing stuff, beware of changing assertions, most of the times the 
assertion is correct.
Also, if a bug fix is too local and seems easy, it's always worth spending some 
extra time to be sure.

And lots and lots and lots of free time, patience and being able to work 
without distractions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126172

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-02 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 457685.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/crash-diagnostics-dir-3.c
  libcxx/utils/ci/buildkite-pipeline.yml


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | 
FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: 
{{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5413,15 +5413,18 @@
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
-if (!getVFS().exists(CrashDirectory))
-  llvm::sys::fs::create_directories(CrashDirectory);
-llvm::sys::path::append(CrashDirectory, Prefix);
+  Optional CrashDirectory =
+  CCGenDiagnostics && A
+  ? std::string(A->getValue())
+  : llvm::sys::Process::GetEnv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {
+if (!getVFS().exists(*CrashDirectory))
+  llvm::sys::fs::create_directories(*CrashDirectory);
+SmallString<128> Path(*CrashDirectory);
+llvm::sys::path::append(Path, Prefix);
 const char *Middle = !Suffix.empty() ? "-%%." : "-%%";
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-CrashDirectory + Middle + Suffix, TmpName);
-if (EC) {
+if (std::error_code EC =
+llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) {
   Diag(clang::diag::err_unable_to_make_temp) << EC.message();
   return "";
 }
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -687,6 +687,11 @@
   Specify where to write the crash diagnostics files; defaults to the
   usual location for temporary files.
 
+.. envvar:: CLANG_CRASH_DIAGNOSTICS_DIR=
+
+   Like :option:`-fcrash-diagnostics-dir=`, specifies where to write the
+   crash diagnostics files, but with lower precedence than the option.
+
 Clang is also capable of generating preprocessed source file(s) and associated
 run script(s) even without a crash. This is specially useful when trying to
 generate a reproducer for warnings or errors while using modules.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -133,6 +133,9 @@
 
 Non-comprehensive list of changes in this release
 -
+- It's now possible to set the crash diagnostics directory through
+  the environment variable ``CLANG_CRASH_DIAGNOSTICS_DIR``.
+  The ``-fcrash-diagnostics-dir`` flag takes precedence.
 
 New Compiler Flags
 --


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH

[PATCH] D132990: [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()

2022-09-02 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:1534-1538
+  if (const auto *T = TInfo->getType()->getContainedDeducedType())
+if (isa(T))
+  Diag(D.getIdentifierLoc(),
+   diag::warn_cxx14_compat_template_nontype_parm_auto_type)
+  << QualType(TInfo->getType()->getContainedAutoType(), 0);

aaron.ballman wrote:
> Let's get fancy!
You would use `getContainedDeducedType` if you expected to handle DeducedTypes 
in general, not just AutoTypes.

So if you only want to handle AutoTypes, there is no point in using 
`getContainedDeducedType`.



Comment at: clang/test/SemaTemplate/temp_arg_nontype_diagnostic_cxx1z.cpp:3-8
+namespace GH57362 {
+template  // expected-warning {{non-type template parameters declared 
with 'auto' are incompatible with C++ standards before C++17}}
+struct A{};
+
+template  // expected-warning {{non-type template parameters 
declared with 'decltype(auto)' are incompatible with C++ standards before 
C++17}}
+struct B{};

I don't understand why these cases are grouped under GH57362 issue, they are 
cases that worked fine without this patch, we just didn't have tests for them.


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

https://reviews.llvm.org/D132990

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


[PATCH] D132990: [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()

2022-09-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp:310-316
+namespace GH57362 {
+template 
+class TemplateClass {};
+
+template  // ok, no diagnostic expected
+void func() {}
+}

I think the issue might not be tested in this file since we do not run it with 
the `-Wpre-c++17-compat` flag


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

https://reviews.llvm.org/D132990

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


[PATCH] D133261: NFC: [clang] add template substitution AST test for make_integer_seq

2022-09-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends on D133072 

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133261

Files:
  clang/test/SemaTemplate/make_integer_seq.cpp


Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -ast-dump -xc++ < %s | FileCheck %s
+
+template  struct A {};
+
+using test1 = __make_integer_seq;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 
test1 '__make_integer_seq':'A'
+// CHECK-NEXT: | `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar
+// CHECK-NEXT: |   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 
'__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT: | |-TemplateArgument template A
+// CHECK-NEXT: | |-TemplateArgument type 'int'
+// CHECK-NEXT: | | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: | |-TemplateArgument expr
+// CHECK-NEXT: | | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT: | |   |-value: Int 1
+// CHECK-NEXT: | |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
+// CHECK-NEXT: | `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: |   `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
+
+template  using B = __make_integer_seq;
+using test2 = B;
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 
test2 'B':'A'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} 'B' sugar
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'B' 
sugar alias B
+// CHECK-NEXT:   |-TemplateArgument type 'int'
+// CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   |   |-value: Int 1
+// CHECK-NEXT:   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} 
'__make_integer_seq' sugar
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 
'__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT:   |-TemplateArgument template A
+// CHECK-NEXT:   |-TemplateArgument type 'int':'int'
+// CHECK-NEXT:   | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 
'int' sugar
+// CHECK-NEXT:   |   |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'B1' 
dependent depth 0 index 0
+// CHECK-NEXT:   |   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'B1'
+// CHECK-NEXT:   |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   |   |-value: Int 1
+// CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}} 
 'int'
+// CHECK-NEXT:   | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}} 
 col:24 referenced 'B1' depth 0 index 1 B2
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  
'int' 1
+// CHECK-NEXT:   `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'


Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -ast-dump -xc++ < %s | FileCheck %s
+
+template  struct A {};
+
+using test1 = __make_integer_seq;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test1 '__make_integer_seq':'A'
+// CHECK-NEXT: | `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar
+// CHECK-NEXT: |   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT: | |-TemplateArgument template A
+// CHECK-NEXT: | |-TemplateArgument type 'int'
+// CHECK-NEXT: | | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: | |-TemplateArgument expr
+// CHECK-NEXT: | | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT: | |   |-value: Int 1
+// CHECK-NEXT: | |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
+// CHECK-NEXT: | `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: |   `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
+
+template  using B = __make_integer_seq;
+using test2 = B;
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} 'B' sugar
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'B' sugar alias B
+// CHECK-NEXT:   |-TemplateArgument type 'int'
+// CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: 

[PATCH] D133262: [clang] Represent __make_integer_seq as alias template in the AST

2022-09-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a subscriber: jeroen.dobbelaere.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We change the template specialization of __make_integer_seq to
be an alias to a synthesized template specialization type of the
underlying template, making the resulting type correctly represent
the template arguments used to specialize the underlying template.

When performing member access on the resulting type, it's now
possible to map from a Subst* node to the template argument
as-written used in a regular fashion, without special casing.

Depends on D133261 

Signed-off-by: Matheus Izvekov 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133262

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp

Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -5,7 +5,7 @@
 using test1 = __make_integer_seq;
 //  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test1 '__make_integer_seq':'A'
 // CHECK-NEXT: | `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar
-// CHECK-NEXT: |   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT: |   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar alias __make_integer_seq
 // CHECK-NEXT: | |-TemplateArgument template A
 // CHECK-NEXT: | |-TemplateArgument type 'int'
 // CHECK-NEXT: | | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
@@ -13,12 +13,22 @@
 // CHECK-NEXT: | | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT: | |   |-value: Int 1
 // CHECK-NEXT: | |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
-// CHECK-NEXT: | `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
-// CHECK-NEXT: |   `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: | `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
+// CHECK-NEXT: |   |-TemplateArgument type 'int':'int'
+// CHECK-NEXT: |   | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
+// CHECK-NEXT: |   |   |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
+// CHECK-NEXT: |   |   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT: |   |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: |   |-TemplateArgument expr
+// CHECK-NEXT: |   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT: |   |   |-value: Int 0
+// CHECK-NEXT: |   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
+// CHECK-NEXT: |   `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: | `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
 
 template  using B = __make_integer_seq;
 using test2 = B;
-//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} 'B' sugar
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'B' sugar alias B
 // CHECK-NEXT:   |-TemplateArgument type 'int'
@@ -28,7 +38,7 @@
 // CHECK-NEXT:   |   |-value: Int 1
 // CHECK-NEXT:   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar
-// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template A
 // CHECK-NEXT:   |-TemplateArgument type 'int':'int'
 // CHECK-NEXT:   | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
@@ -36,10 +46,20 @@
 // CHECK-NEXT:   |   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'B1'
 // CHECK-NEXT:   |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT:   |   |-value: Int 1
 // CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT:   | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}}  col:24 referenced 'B1' depth 0 index 1 B2
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
-// CHECK-NEXT:   `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
-// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}

[PATCH] D133262: [clang] Represent __make_integer_seq as alias template in the AST

2022-09-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 457816.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1 +1,2 @@
 D133072
+D133262
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -5,7 +5,7 @@
 using test1 = __make_integer_seq;
 //  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test1 '__make_integer_seq':'A'
 // CHECK-NEXT: | `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar
-// CHECK-NEXT: |   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT: |   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar alias __make_integer_seq
 // CHECK-NEXT: | |-TemplateArgument template A
 // CHECK-NEXT: | |-TemplateArgument type 'int'
 // CHECK-NEXT: | | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
@@ -13,12 +13,22 @@
 // CHECK-NEXT: | | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT: | |   |-value: Int 1
 // CHECK-NEXT: | |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
-// CHECK-NEXT: | `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
-// CHECK-NEXT: |   `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: | `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
+// CHECK-NEXT: |   |-TemplateArgument type 'int':'int'
+// CHECK-NEXT: |   | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
+// CHECK-NEXT: |   |   |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
+// CHECK-NEXT: |   |   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT: |   |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: |   |-TemplateArgument expr
+// CHECK-NEXT: |   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT: |   |   |-value: Int 0
+// CHECK-NEXT: |   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
+// CHECK-NEXT: |   `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: | `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
 
 template  using B = __make_integer_seq;
 using test2 = B;
-//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} 'B' sugar
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'B' sugar alias B
 // CHECK-NEXT:   |-TemplateArgument type 'int'
@@ -28,7 +38,7 @@
 // CHECK-NEXT:   |   |-value: Int 1
 // CHECK-NEXT:   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar
-// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template A
 // CHECK-NEXT:   |-TemplateArgument type 'int':'int'
 // CHECK-NEXT:   | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
@@ -36,10 +46,20 @@
 // CHECK-NEXT:   |   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'B1'
 // CHECK-NEXT:   |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT:   |   |-value: Int 1
 // CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT:   | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}}  col:24 referenced 'B1' depth 0 index 1 B2
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
-// CHECK-NEXT:   `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
-// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
+// CHECK-NEXT: |-TemplateArgument type 'int':'int'
+// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
+// CHECK-NEXT: |   |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1

[PATCH] D133262: [clang] Represent __make_integer_seq as alias template in the AST

2022-09-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 457817.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1 +1,2 @@
 D133072
+D133262
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- clang/test/SemaTemplate/make_integer_seq.cpp
+++ clang/test/SemaTemplate/make_integer_seq.cpp
@@ -5,7 +5,7 @@
 using test1 = __make_integer_seq;
 //  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test1 '__make_integer_seq':'A'
 // CHECK-NEXT: | `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar
-// CHECK-NEXT: |   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT: |   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar alias __make_integer_seq
 // CHECK-NEXT: | |-TemplateArgument template A
 // CHECK-NEXT: | |-TemplateArgument type 'int'
 // CHECK-NEXT: | | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
@@ -13,12 +13,22 @@
 // CHECK-NEXT: | | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT: | |   |-value: Int 1
 // CHECK-NEXT: | |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
-// CHECK-NEXT: | `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
-// CHECK-NEXT: |   `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: | `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
+// CHECK-NEXT: |   |-TemplateArgument type 'int':'int'
+// CHECK-NEXT: |   | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
+// CHECK-NEXT: |   |   |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
+// CHECK-NEXT: |   |   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT: |   |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT: |   |-TemplateArgument expr
+// CHECK-NEXT: |   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT: |   |   |-value: Int 0
+// CHECK-NEXT: |   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
+// CHECK-NEXT: |   `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT: | `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
 
 template  using B = __make_integer_seq;
 using test2 = B;
-//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:7 test2 'B':'A'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} 'B' sugar
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'B' sugar alias B
 // CHECK-NEXT:   |-TemplateArgument type 'int'
@@ -28,7 +38,7 @@
 // CHECK-NEXT:   |   |-value: Int 1
 // CHECK-NEXT:   |   `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar
-// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar __make_integer_seq
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__make_integer_seq' sugar alias __make_integer_seq
 // CHECK-NEXT:   |-TemplateArgument template A
 // CHECK-NEXT:   |-TemplateArgument type 'int':'int'
 // CHECK-NEXT:   | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
@@ -36,10 +46,20 @@
 // CHECK-NEXT:   |   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'B1'
 // CHECK-NEXT:   |   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 // CHECK-NEXT:   |-TemplateArgument expr
-// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT:   |   |-value: Int 1
 // CHECK-NEXT:   |   `-SubstNonTypeTemplateParmExpr 0x{{[0-9A-Fa-f]+}}  'int'
 // CHECK-NEXT:   | |-NonTypeTemplateParmDecl 0x{{[0-9A-Fa-f]+}}  col:24 referenced 'B1' depth 0 index 1 B2
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 1
-// CHECK-NEXT:   `-RecordType 0x{{[0-9A-Fa-f]+}} 'A'
-// CHECK-NEXT: `-ClassTemplateSpecialization 0x{{[0-9A-Fa-f]+}} 'A'
+// CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} 'A' sugar A
+// CHECK-NEXT: |-TemplateArgument type 'int':'int'
+// CHECK-NEXT: | `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
+// CHECK-NEXT: |   |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
+// CHECK-NEXT: |   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT: |   `

[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 457818.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/crash-diagnostics-dir-3.c
  libcxx/utils/ci/buildkite-pipeline.yml


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | 
FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: 
{{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5413,15 +5413,18 @@
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
-if (!getVFS().exists(CrashDirectory))
-  llvm::sys::fs::create_directories(CrashDirectory);
-llvm::sys::path::append(CrashDirectory, Prefix);
+  Optional CrashDirectory =
+  CCGenDiagnostics && A
+  ? std::string(A->getValue())
+  : llvm::sys::Process::GetEnv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {
+if (!getVFS().exists(*CrashDirectory))
+  llvm::sys::fs::create_directories(*CrashDirectory);
+SmallString<128> Path(*CrashDirectory);
+llvm::sys::path::append(Path, Prefix);
 const char *Middle = !Suffix.empty() ? "-%%." : "-%%";
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-CrashDirectory + Middle + Suffix, TmpName);
-if (EC) {
+if (std::error_code EC =
+llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) {
   Diag(clang::diag::err_unable_to_make_temp) << EC.message();
   return "";
 }
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -687,6 +687,11 @@
   Specify where to write the crash diagnostics files; defaults to the
   usual location for temporary files.
 
+.. envvar:: CLANG_CRASH_DIAGNOSTICS_DIR=
+
+   Like :option:`-fcrash-diagnostics-dir=`, specifies where to write the
+   crash diagnostics files, but with lower precedence than the option.
+
 Clang is also capable of generating preprocessed source file(s) and associated
 run script(s) even without a crash. This is specially useful when trying to
 generate a reproducer for warnings or errors while using modules.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -135,6 +135,9 @@
 
 Non-comprehensive list of changes in this release
 -
+- It's now possible to set the crash diagnostics directory through
+  the environment variable ``CLANG_CRASH_DIAGNOSTICS_DIR``.
+  The ``-fcrash-diagnostics-dir`` flag takes precedence.
 
 New Compiler Flags
 --


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH

[PATCH] D133072: [clang] fix profiling of template arguments of template and declaration kind

2022-09-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 457819.
mizvekov marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133072

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/concepts.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D133072
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -256,3 +256,9 @@
 C auto **&j2 = g();  // expected-error {{deduced type 'int' does not satisfy 'C'}}
 C auto **&&j3 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}
 }
+
+namespace GH55567 {
+template class> concept C = true;
+template  struct S {};
+void f(C auto);
+} // namespace GH55567
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5643,7 +5643,8 @@
 if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
   return true;
 
-Converted.push_back(Arg.getArgument());
+Converted.push_back(
+Context.getCanonicalTemplateArgument(Arg.getArgument()));
 break;
 
   case TemplateArgument::Expression:
@@ -5813,13 +5814,14 @@
 if (!ArgumentPack.empty()) {
   // If we were part way through filling in an expanded parameter pack,
   // fall back to just producing individual arguments.
-  Converted.insert(Converted.end(),
-   ArgumentPack.begin(), ArgumentPack.end());
+  for (const TemplateArgument &I : ArgumentPack)
+Converted.push_back(Context.getCanonicalTemplateArgument(I));
   ArgumentPack.clear();
 }
 
 while (ArgIdx < NumArgs) {
-  Converted.push_back(NewArgs[ArgIdx].getArgument());
+  Converted.push_back(Context.getCanonicalTemplateArgument(
+  NewArgs[ArgIdx].getArgument()));
   ++ArgIdx;
 }
 
@@ -5952,7 +5954,8 @@
   if (ArgIdx < NumArgs && CurrentInstantiationScope &&
   CurrentInstantiationScope->getPartiallySubstitutedPack()) {
 while (ArgIdx < NumArgs && NewArgs[ArgIdx].getArgument().isPackExpansion())
-  Converted.push_back(NewArgs[ArgIdx++].getArgument());
+  Converted.push_back(Context.getCanonicalTemplateArgument(
+  NewArgs[ArgIdx++].getArgument()));
   }
 
   // If we have any leftover arguments, then there were too many arguments.
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -321,26 +321,15 @@
 
   case Declaration:
 getParamTypeForDecl().Profile(ID);
-ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr);
+ID.AddPointer(getAsDecl());
 break;
 
+  case TemplateExpansion:
+ID.AddInteger(TemplateArg.NumExpansions);
+LLVM_FALLTHROUGH;
   case Template:
-  case TemplateExpansion: {
-TemplateName Template = getAsTemplateOrTemplatePattern();
-if (TemplateTemplateParmDecl *TTP
-  = dyn_cast_or_null(
-Template.getAsTemplateDecl())) {
-  ID.AddBoolean(true);
-  ID.AddInteger(TTP->getDepth());
-  ID.AddInteger(TTP->getPosition());
-  ID.AddBoolean(TTP->isParameterPack());
-} else {
-  ID.AddBoolean(false);
-  ID.AddPointer(Context.getCanonicalTemplateName(Template)
-  .getAsVoidPointer());
-}
+getAsTemplateOrTemplatePattern().Profile(ID);
 break;
-  }
 
   case Integral:
 getAsIntegral().Profile(ID);
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5116,7 +5116,9 @@
CanonArgs);
 
 // Find the insert position again.
-DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
+[[maybe_unused]] auto *Nothing =
+DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
+assert(!Nothing && "canonical type broken");
   }
 
   void *Mem = Allocate((sizeof(DependentTemplateSpecializationType) +
@@ -5731,7 +5733,9 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+[[maybe_unused]] auto *Nothing =
+AutoTypes.FindNode

[PATCH] D133262: [clang] Represent __make_integer_seq as alias template in the AST

2022-09-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D133262#3768883 , @royjacobson 
wrote:

> There are some known bugs about how we handle this built-in in the AST- 
> #42102, #51928, #54993. Is it possible that your patch solves them? It would 
> be great if it does, I hit one of them in the wild a while back.

I think not, these look like deduction problems, and what is done in this patch 
should not affect deduction.

The TemplateSpecializationTypes we are changing in this patch are all sugar, 
and these should not affect it.

Dependence can create canonical TST, which does affect it, but 
`checkBuiltinTemplateIdType` is not even called if there is any dependence.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

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


[PATCH] D133249: [libc++] Documents details of the pre-commit CI.

2022-09-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: libcxx/docs/Contributing.rst:164-165
+
+  When this buld fails with an LLVM assertion, the crash diagnostics are
+  available as an artifact.
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133249

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


[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-09-04 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/include/clang/Sema/SemaConcept.h:48-52
+  if (ArgA.getKind() == TemplateArgument::Expression &&
+  ArgB.getKind() == TemplateArgument::Expression &&
+  ArgA.getAsExpr()->getType()->isUndeducedAutoType() &&
+  ArgB.getAsExpr()->getType()->isUndeducedAutoType())
+continue;

Why are looking at only the type of the expression?
The expression can be arbitrarily different, but as long as they are both 
undeduced auto, that is okay?



Comment at: clang/include/clang/Sema/SemaConcept.h:54-68
+  if (ArgA.getKind() == TemplateArgument::Type &&
+  ArgB.getKind() == TemplateArgument::Type)
+if (const auto *SubstA =
+ArgA.getAsType()->getAs())
+  if (const auto *SubstB =
+  ArgB.getAsType()->getAs()) {
+QualType ReplacementA = SubstA->getReplacementType();

It's a bit odd to find `SubstTemplateTypeParmType` necessary to implement the 
semantics of this change.

This is just type sugar we leave behind in the template instantiator to mark 
where type replacement happened.

There are several potential issues here:
1) This could be marking a substitution that happened at any template depth. Ie 
this could be marking a substitution from an outer template. Does the level not 
matter here at all? 
2) If the level does matter, you won't be able to reconstitute that easily 
without further improvements. See 
https://github.com/llvm/llvm-project/issues/55886 for example.
3) A substitution can replace a dependent type for another one, and when that 
other gets replaced, we lose track of that because `SubstTemplateTypeParmType` 
only holds a canonical underlying type.



Leaving that aside, I get the impression you are trying to work around the fact 
that when an expression appears in a canonical type, presumably because that 
expression is dependent on an NTTP, we can't rely on uniquing anymore to 
compare if they are the same type, as we lack in Clang the equivalent concept 
of canonicalization for expressions.

But this however is a bit hard to implement. Are we sure the standard requires 
this, or can we simply consider these types always different?



Comment at: clang/lib/AST/ASTContext.cpp:5149-5151
+Expr *E = new (*this)
+DeclRefExpr(*this, NTTP, /*enclosing*/ false, T,
+Expr::getValueKindForType(NTTPType), NTTP->getLocation());





Comment at: clang/lib/AST/ASTContext.cpp:5154-5156
+  E = new (*this) PackExpansionExpr(
+  NTTPType->isUndeducedAutoType() ? NTTPType : DependentTy, E,
+  NTTP->getLocation(), None);

I don't know if this change is necessary for this patch, as this looks part of 
the workaround in `SemaConcept.h`,
but I think a better way to preserve the type here might be to always use 
`NTTPType`, but then add an additional `Dependent` parameter to 
`PackExpansionExpr` which can be used to force the expression to be dependent.



Comment at: clang/lib/Sema/SemaConcept.cpp:827
+assert(FoldE->isRightFold() && FoldE->getOperator() == BO_LAnd);
+E = FoldE->getPattern();
+  }

If you need to dig down into the pattern, then I think the pattern might also 
contain casts and parenthesis which you would need to keep ignoring for the 
rest of the code to work.

I would consider adding a test for that.



Comment at: clang/lib/Sema/SemaOverload.cpp:9675-9676
-  // when comparing template functions. 
-  if (Cand1.Function && Cand2.Function && Cand1.Function->hasPrototype() &&
-  Cand2.Function->hasPrototype()) {
 auto *PT1 = cast(Cand1.Function->getFunctionType());

Why are these `hasPrototype` checks not needed anymore?

I don't see other changes which would obliviate the need for it. Presumably the 
code below is assuming we have them when we perform that `FunctionProtoType` 
cast.

Maybe this was either not possible, or we simply never added tests for it.



Comment at: clang/lib/Sema/SemaTemplate.cpp:1267
   BuildDeclRefExpr(NTTP, NTTP->getType(), VK_PRValue, NTTP->getLocation());
-  if (!Ref)
-return true;
+  assert(Ref);
   ExprResult ImmediatelyDeclaredConstraint = formImmediatelyDeclaredConstraint(

I don't think the `assert` is even necessary TBH, the function can't return 
nullptr.



Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5247-5248
+  for (unsigned i = 0; i < NumParams1; ++i)
+if (FD1->getParamDecl(i)->getType().getCanonicalType() !=
+FD2->getParamDecl(i)->getType().getCanonicalType())
+  return nullptr;





Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:5256-5257
+  //   than the other.
+  if (TPOC == TPOC_Conversion && FD1->getReturnType().getCanonicalType() !=
+   

[PATCH] D133072: [clang] fix profiling of template arguments of template and declaration kind

2022-09-06 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:5817
   // fall back to just producing individual arguments.
-  Converted.insert(Converted.end(),
-   ArgumentPack.begin(), ArgumentPack.end());
+  for (const TemplateArgument &I : ArgumentPack)
+Converted.push_back(Context.getCanonicalTemplateArgument(I));

mizvekov wrote:
> erichkeane wrote:
> > mizvekov wrote:
> > > erichkeane wrote:
> > > > Ooh, thats a transform!  
> > > > 
> > > > `llvm::transform(ArgumentPack, std::back_inserter(Converted), [](const 
> > > > auto &I) { return Context.getCanonicalTemplateArgument(I));`
> > > That is true, though unless we can come up with a clearer spelling for 
> > > that, it looks less readable to me.
> > But I like transform :(
> I will think of something, even if we have to add a new helper :)
I'll try to address this concern, about having a helper which returns a 
transformed copy of a container, in a way that reads better than the pure 
transform as suggested, in a follow up patch. Meanwhile I'll offload this 
patch, as my stack is too big right now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133072

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


[PATCH] D133072: [clang] fix profiling of template arguments of template and declaration kind

2022-09-06 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGacb767f5cda5: [clang] fix profiling of template arguments of 
template and declaration kind (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D133072?vs=457819&id=458191#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133072

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -256,3 +256,9 @@
 C auto **&j2 = g();  // expected-error {{deduced type 'int' does not satisfy 'C'}}
 C auto **&&j3 = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}
 }
+
+namespace GH55567 {
+template class> concept C = true;
+template  struct S {};
+void f(C auto);
+} // namespace GH55567
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -5643,7 +5643,8 @@
 if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
   return true;
 
-Converted.push_back(Arg.getArgument());
+Converted.push_back(
+Context.getCanonicalTemplateArgument(Arg.getArgument()));
 break;
 
   case TemplateArgument::Expression:
@@ -5813,13 +5814,14 @@
 if (!ArgumentPack.empty()) {
   // If we were part way through filling in an expanded parameter pack,
   // fall back to just producing individual arguments.
-  Converted.insert(Converted.end(),
-   ArgumentPack.begin(), ArgumentPack.end());
+  for (const TemplateArgument &I : ArgumentPack)
+Converted.push_back(Context.getCanonicalTemplateArgument(I));
   ArgumentPack.clear();
 }
 
 while (ArgIdx < NumArgs) {
-  Converted.push_back(NewArgs[ArgIdx].getArgument());
+  Converted.push_back(Context.getCanonicalTemplateArgument(
+  NewArgs[ArgIdx].getArgument()));
   ++ArgIdx;
 }
 
@@ -5952,7 +5954,8 @@
   if (ArgIdx < NumArgs && CurrentInstantiationScope &&
   CurrentInstantiationScope->getPartiallySubstitutedPack()) {
 while (ArgIdx < NumArgs && NewArgs[ArgIdx].getArgument().isPackExpansion())
-  Converted.push_back(NewArgs[ArgIdx++].getArgument());
+  Converted.push_back(Context.getCanonicalTemplateArgument(
+  NewArgs[ArgIdx++].getArgument()));
   }
 
   // If we have any leftover arguments, then there were too many arguments.
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -321,26 +321,15 @@
 
   case Declaration:
 getParamTypeForDecl().Profile(ID);
-ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr);
+ID.AddPointer(getAsDecl());
 break;
 
+  case TemplateExpansion:
+ID.AddInteger(TemplateArg.NumExpansions);
+LLVM_FALLTHROUGH;
   case Template:
-  case TemplateExpansion: {
-TemplateName Template = getAsTemplateOrTemplatePattern();
-if (TemplateTemplateParmDecl *TTP
-  = dyn_cast_or_null(
-Template.getAsTemplateDecl())) {
-  ID.AddBoolean(true);
-  ID.AddInteger(TTP->getDepth());
-  ID.AddInteger(TTP->getPosition());
-  ID.AddBoolean(TTP->isParameterPack());
-} else {
-  ID.AddBoolean(false);
-  ID.AddPointer(Context.getCanonicalTemplateName(Template)
-  .getAsVoidPointer());
-}
+getAsTemplateOrTemplatePattern().Profile(ID);
 break;
-  }
 
   case Integral:
 getAsIntegral().Profile(ID);
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -5116,7 +5116,9 @@
CanonArgs);
 
 // Find the insert position again.
-DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
+[[maybe_unused]] auto *Nothing =
+DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
+assert(!Nothing && "canonical type broken");
   }
 
   void *Mem = Allocate((sizeof(DependentTemplateSpecializationType) +
@@ -5731,7 +5733,9 @@
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+

[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-06 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

@aaron.ballman I think all of your concerns are addressed now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

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


[PATCH] D133082: [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-06 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG94c6dfbaebbd: [clang] Implement setting 
crash_diagnostics_dir through env variable (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133082

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/crash-diagnostics-dir-3.c
  libcxx/utils/ci/buildkite-pipeline.yml


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | 
FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: 
{{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -5413,15 +5413,18 @@
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
-if (!getVFS().exists(CrashDirectory))
-  llvm::sys::fs::create_directories(CrashDirectory);
-llvm::sys::path::append(CrashDirectory, Prefix);
+  Optional CrashDirectory =
+  CCGenDiagnostics && A
+  ? std::string(A->getValue())
+  : llvm::sys::Process::GetEnv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {
+if (!getVFS().exists(*CrashDirectory))
+  llvm::sys::fs::create_directories(*CrashDirectory);
+SmallString<128> Path(*CrashDirectory);
+llvm::sys::path::append(Path, Prefix);
 const char *Middle = !Suffix.empty() ? "-%%." : "-%%";
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-CrashDirectory + Middle + Suffix, TmpName);
-if (EC) {
+if (std::error_code EC =
+llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) {
   Diag(clang::diag::err_unable_to_make_temp) << EC.message();
   return "";
 }
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -687,6 +687,11 @@
   Specify where to write the crash diagnostics files; defaults to the
   usual location for temporary files.
 
+.. envvar:: CLANG_CRASH_DIAGNOSTICS_DIR=
+
+   Like :option:`-fcrash-diagnostics-dir=`, specifies where to write the
+   crash diagnostics files, but with lower precedence than the option.
+
 Clang is also capable of generating preprocessed source file(s) and associated
 run script(s) even without a crash. This is specially useful when trying to
 generate a reproducer for warnings or errors while using modules.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -135,6 +135,9 @@
 
 Non-comprehensive list of changes in this release
 -
+- It's now possible to set the crash diagnostics directory through
+  the environment variable ``CLANG_CRASH_DIAGNOSTICS_DIR``.
+  The ``-fcrash-diagnostics-dir`` flag takes precedence.
 
 New Compiler Flags
 --


Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-symbolizer-${LLVM_HEAD_VERSION}"
+CLANG_CRASH_DIAGNOSTICS_DIR: "crash_diagnostics"
 agents:
   queue: "libcxx-builders"
   os: "linux"
Index: clang/test/Driver/crash-diagnostics-dir-3.c
===

[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-09-06 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

Hello, thanks, I appreciate that you found it helpful!

It's pretty late for me now, I will give this another look tomorrow.




Comment at: clang/include/clang/Sema/SemaConcept.h:48-52
+  if (ArgA.getKind() == TemplateArgument::Expression &&
+  ArgB.getKind() == TemplateArgument::Expression &&
+  ArgA.getAsExpr()->getType()->isUndeducedAutoType() &&
+  ArgB.getAsExpr()->getType()->isUndeducedAutoType())
+continue;

ychen wrote:
> mizvekov wrote:
> > Why are looking at only the type of the expression?
> > The expression can be arbitrarily different, but as long as they are both 
> > undeduced auto, that is okay?
> In the partial ordering context, the expression is the same explicit template 
> argument. So we could treat two undeduced autos as equal. 
> 
> This code is to deal with the fact that, `AuoType` is currently being uniqued 
> on type constrained, which goes against the spirit of P2113R0 which considers 
> type constraints only when the two types are equivalent.
> 
> I think the more neat way is to unique auto template parameter with the kind 
> of placeholder type (`auto`, `auto*`, `auto&`, `decltype(auto)`, ...), and 
> its template parameter depth/index. Then we don't need the workaround here 
> and I could simplify the code in `SemaTemplateDeduction.cpp` too. WDYT?
If you mean a change so that constraints are not part of the canonical type of 
undeduced AutoType, that is worth a try.
I can't think right now of a reason why they should be part of it in the first 
place.



Comment at: clang/include/clang/Sema/SemaConcept.h:54-68
+  if (ArgA.getKind() == TemplateArgument::Type &&
+  ArgB.getKind() == TemplateArgument::Type)
+if (const auto *SubstA =
+ArgA.getAsType()->getAs())
+  if (const auto *SubstB =
+  ArgB.getAsType()->getAs()) {
+QualType ReplacementA = SubstA->getReplacementType();

ychen wrote:
> mizvekov wrote:
> > It's a bit odd to find `SubstTemplateTypeParmType` necessary to implement 
> > the semantics of this change.
> > 
> > This is just type sugar we leave behind in the template instantiator to 
> > mark where type replacement happened.
> > 
> > There are several potential issues here:
> > 1) This could be marking a substitution that happened at any template 
> > depth. Ie this could be marking a substitution from an outer template. Does 
> > the level not matter here at all? 
> > 2) If the level does matter, you won't be able to reconstitute that easily 
> > without further improvements. See 
> > https://github.com/llvm/llvm-project/issues/55886 for example.
> > 3) A substitution can replace a dependent type for another one, and when 
> > that other gets replaced, we lose track of that because 
> > `SubstTemplateTypeParmType` only holds a canonical underlying type.
> > 
> > 
> > 
> > Leaving that aside, I get the impression you are trying to work around the 
> > fact that when an expression appears in a canonical type, presumably 
> > because that expression is dependent on an NTTP, we can't rely on uniquing 
> > anymore to compare if they are the same type, as we lack in Clang the 
> > equivalent concept of canonicalization for expressions.
> > 
> > But this however is a bit hard to implement. Are we sure the standard 
> > requires this, or can we simply consider these types always different?
> > It's a bit odd to find SubstTemplateTypeParmType necessary to implement the 
> > semantics of this change.
> 
> Odd indeed. 
> 
> > Leaving that aside, I get the impression you are trying to work around the 
> > fact that when an expression appears in a canonical type, presumably 
> > because that expression is dependent on an NTTP, we can't rely on uniquing 
> > anymore to compare if they are the same type, as we lack in Clang the 
> > equivalent concept of canonicalization for expressions.
> 
> Yeah, sort of . This workaround is to deal with the fact that `DecltypeType` 
> is not uniqued. However, the injected template argument for `t` of 
> `template` is `decltype(t)` (which on a side note, might be wrong 
> since `auto` means using template arg deduct rules; `decltype(auto)` means 
> using `decltype(expr)` type, let's keep it this way now since this code path 
> is still needed when Clang starts to support `decltype(auto)` as NTTP type) 
> and concepts partial ordering rules need to compare these concept template 
> arguments (https://eel.is/c++draft/temp.constr#atomic-1). 
> 
> Looking at the motivation why `DecltypeType` is not uniqued 
> (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ASTContext.cpp#L5637-L5640),
>  I think maybe we should unique decltype on the expr to deal with concepts 
> cleanly. Thoughts?
I see, there should be no problem with a change to unique a DecltypeType, but 
it might not help you, because expressions typically have source location 
inf

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Serialization/ASTWriterDecl.cpp:623-626
+  VisitDeclaratorDecl(D);
+  Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
+  Record.push_back(D->getIdentifierNamespace());
+

ChuanqiXu wrote:
> ChuanqiXu wrote:
> > ChuanqiXu wrote:
> > > mizvekov wrote:
> > > > ChuanqiXu wrote:
> > > > > I still don't get the reason for the move. What's the benefit? Or why 
> > > > > is it necessary?
> > > > Yeah, now the type can reference the template decl, so without moving 
> > > > this, it can happen during import of the type that we try to read this 
> > > > function template bits without having imported them yet.
> > > Oh, I guess I met the problem before (D129748 ) and I made a workaround 
> > > for it (https://reviews.llvm.org/D130331). If I understood right, the 
> > > patch will solve that problem. I'll check it out later.
> > > 
> > > (This kind of code move looks dangerous you know and I'll take a double 
> > > check)
> > After looking into the detailed change for the serialization part, I feel 
> > it is a not-so-good workaround indeed.. It looks like we need a better 
> > method to delay reading the type in the serializer. And I'm looking at it. 
> > @mizvekov would you like to rebase the series of patches to the main branch 
> > so that I can test it actually.
> Or would it be simpler to rebase and squash them into a draft revision?
I had given this some thought, and it made sense to me that we should deal with 
the template bits first, since these are closer to the introducer for these 
declarations, and so that it would be harder to have a dependence the other way 
around.

But I would like to hear your thoughts on this after you have taken a better 
look.
I am working on a bunch of things right now, I should be able to rebase this on 
the next few days, but otherwise
I last rebased about 4 days ago, so you can also check that out at 
https://github.com/mizvekov/llvm-project/tree/resugar
That link has the whole stack, you probably should check out just the commit 
for this patch, as you are probably going to encounter issues with the 
resugarer if you try it on substantial code bases.
It will carry other changes with it, but I think those should be safe.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D133261: NFC: [clang] add template AST test for make_integer_seq and type_pack_element

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov retitled this revision from "NFC: [clang] add template substitution 
AST test for make_integer_seq" to "NFC: [clang] add template AST test for 
make_integer_seq and type_pack_element".
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 458540.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133261

Files:
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp

Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -ast-dump -verify -xc++ < %s | FileCheck %s
+
+using test1 = __type_pack_element<0, int>;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <:3:1, col:41> col:7 test1 '__type_pack_element<0, int>':'int'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long long'
+// CHECK-NEXT:   |   |-value: Int 0
+// CHECK-NEXT:   |   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long long' 
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
+// CHECK-NEXT:   |-TemplateArgument type 'int'
+// CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+
+template struct A {
+  using test2 = __type_pack_element;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long long' 
+// CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
+// CHECK-NEXT:   `-TemplateArgument type 'Ts...'
+// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
+// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
+// CHECK-NEXT: `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+
+  using test3 = __type_pack_element<0, Ts...>;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, Ts...>'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' dependent __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long long'
+// CHECK-NEXT:   |   |-value: Int 0
+// CHECK-NEXT:   |   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long long' 
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
+// CHECK-NEXT:   `-TemplateArgument type 'Ts...'
+// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
+// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
+// CHECK-NEXT: `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+
+  using test4 = __type_pack_element;
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long long' 
+// CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
+// CHECK-NEXT:   `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+};
+
+// FIXME: builtin templates should not participate in deduction
+template  struct B; // expected-note {{template is declared here}}
+template  struct B> {};
+template struct B; // expected-error {{explicit instantiation of undefined template}}
+
+template  struct C; // expected-note {{template is declared here}}
+template  struct C> {};
+template struct C; // expected-error {{explicit instantiation of undefined template}}
+
+template  struct D;
+template  struct D<__type_pack_element<0, T, U>> {};
+template  struct D<__type_pack_ele

[PATCH] D133262: [clang] Fixes how we represent / emulate builtin templates

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov retitled this revision from "[clang] Represent __make_integer_seq as 
alias template in the AST" to "[clang] Fixes how we represent / emulate builtin 
templates".
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 458541.
mizvekov marked 3 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D133262
Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- clang/test/SemaTemplate/type_pack_element.cpp
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -3,7 +3,7 @@
 using test1 = __type_pack_element<0, int>;
 //  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <:3:1, col:41> col:7 test1 '__type_pack_element<0, int>':'int'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar
-// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar __type_pack_element
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
 // CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long long'
 // CHECK-NEXT:   |   |-value: Int 0
@@ -11,59 +11,89 @@
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT:   |-TemplateArgument type 'int'
 // CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
-// CHECK-NEXT:   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
+// CHECK-NEXT: |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
+// CHECK-NEXT: | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 
 template struct A {
   using test2 = __type_pack_element;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
-// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
 // CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long long' 
 // CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
-// CHECK-NEXT:   `-TemplateArgument type 'Ts...'
-// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
-// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
-// CHECK-NEXT: `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+// CHECK-NEXT:   |-TemplateArgument type 'Ts...'
+// CHECK-NEXT:   | `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
+// CHECK-NEXT:   |   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
+// CHECK-NEXT:   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+// CHECK-NEXT:   `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT: |-TemplateArgument expr
+// CHECK-NEXT: | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long long' 
+// CHECK-NEXT: |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
+// CHECK-NEXT: `-TemplateArgument pack
+// CHECK-NEXT:   `-TemplateArgument type 'type-parameter-0-1...'
+// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1...' dependent
+// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test3 = __type_pack_element<0, Ts...>;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, Ts...>'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-

[PATCH] D133262: [clang] Fixes how we represent / emulate builtin templates

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/AST/DeclTemplate.cpp:262
+  }
+  default:;
+  };

erichkeane wrote:
> The semicolon after default is bizarre/unnecessary.  That said, I'd suggest 
> just making the 'default' case be 'return false'.
This is just a workaround for some versions of GCC and/or MSVC which warn on 
control flow reaching the end of the function, even in cases such as a switch 
which returns in all paths.
Also we prefer to emit a warning on unhandled cases when omitting the default 
case.

So this is a compact way of avoiding those issues without having to add a 
`llvm_unreachable("control flow should never get here");` at the end.

Have we gotten rid of the old versions of those toolchains which had this 
problem?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

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


[PATCH] D133262: [clang] Fixes how we represent / emulate builtin templates

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D133262#3768883 , @royjacobson 
wrote:

> There are some known bugs about how we handle this built-in in the AST- 
> #42102, #51928, #54993. Is it possible that your patch solves them? It would 
> be great if it does, I hit one of them in the wild a while back.

@royjacobson I decided to do a complete job here and fix those issues as well. 
Can you confirm?

I also applied the same idea to `type_pack_element` as I saw a crash related to 
that in the wild.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

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


[PATCH] D133261: NFC: [clang] add template AST test for make_integer_seq and type_pack_element

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 458552.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133261

Files:
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp

Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -triple x86_64-linux-gnu -ast-dump -verify -xc++ < %s | FileCheck %s
+
+using test1 = __type_pack_element<0, int>;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}} <:3:1, col:41> col:7 test1 '__type_pack_element<0, int>':'int'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, int>' sugar __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long'
+// CHECK-NEXT:   |   |-value: Int 0
+// CHECK-NEXT:   |   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
+// CHECK-NEXT:   |-TemplateArgument type 'int'
+// CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+// CHECK-NEXT:   `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+
+template struct A {
+  using test2 = __type_pack_element;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
+// CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
+// CHECK-NEXT:   `-TemplateArgument type 'Ts...'
+// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
+// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
+// CHECK-NEXT: `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+
+  using test3 = __type_pack_element<0, Ts...>;
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, Ts...>'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' dependent __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ConstantExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long'
+// CHECK-NEXT:   |   |-value: Int 0
+// CHECK-NEXT:   |   `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
+// CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
+// CHECK-NEXT:   `-TemplateArgument type 'Ts...'
+// CHECK-NEXT: `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
+// CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
+// CHECK-NEXT: `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
+
+  using test4 = __type_pack_element;
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
+// CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
+// CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' dependent __type_pack_element
+// CHECK-NEXT:   |-TemplateArgument expr
+// CHECK-NEXT:   | `-ImplicitCastExpr 0x{{[0-9A-Fa-f]+}}  'unsigned long' 
+// CHECK-NEXT:   |   `-DeclRefExpr 0x{{[0-9A-Fa-f]+}}  'int' NonTypeTemplateParm 0x{{[0-9A-Fa-f]+}} 'N' 'int'
+// CHECK-NEXT:   `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
+};
+
+template  struct B; // expected-note {{template is declared here}}
+template  struct B> {};
+template struct B; // expected-error {{explicit instantiation of undefined template}}
+
+template  struct C; // expected-note {{template is declared here}}
+template  struct C> {};
+template struct C; // expected-error {{explicit instantiation of undefined template}}
+
+template  struct D;
+template  struct D<__type_pack_element<0, T, U>> {};
+template  struct D<__type_pack_element<0, U, T>> {};
+
+template  struct E;
+template  struct E<__type_pack_element<0, T>> {};
+template  struct E<__type_pack_element<0, T, U>> {};
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/m

[PATCH] D133262: [clang] Fixes how we represent / emulate builtin templates

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 458553.
Herald added subscribers: mstorsjo, arichardson.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp
  libcxx/DELETE.ME
  libcxx/utils/ci/buildkite-pipeline.yml

Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -59,310 +59,6 @@
   limit: 2
 timeout_in_minutes: 120
 
-  - label: "Documentation"
-command: "libcxx/utils/ci/run-buildbot documentation"
-artifact_paths:
-  - "**/test-results.xml"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  #
-  # General testing with the default configuration, under all the supported
-  # Standard modes, with Clang and GCC. This catches most issues upfront.
-  # The goal of this step is to catch most issues while being very fast.
-  #
-  - wait
-
-  - label: "C++2b"
-command: "libcxx/utils/ci/run-buildbot generic-cxx2b"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++11"
-command: "libcxx/utils/ci/run-buildbot generic-cxx11"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++03"
-command: "libcxx/utils/ci/run-buildbot generic-cxx03"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "Modular build"
-command: "libcxx/utils/ci/run-buildbot generic-modules"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "GCC ${GCC_STABLE_VERSION} / C++latest"
-command: "libcxx/utils/ci/run-buildbot generic-gcc"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "gcc-${GCC_STABLE_VERSION}"
-CXX: "g++-${GCC_STABLE_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  #
-  # All other supported configurations of libc++.
-  #
-  - wait
-
-  - label: "C++20"
-command: "libcxx/utils/ci/run-buildbot generic-cxx20"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++17"
-command: "libcxx/utils/ci/run-buildbot generic-cxx17"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-# TODO (mordante) use head
-#CC: "clang-${LLVM_HEAD_VERSION}"
-#CXX: "clang++-${LLVM_HEAD_VERSION}"
-CC: "clang-15"
-CXX: "clang++-15"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++14"
-command: "libcxx/utils/ci/run-buildbot generic-cxx14"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-  

[PATCH] D133262: [clang] Fixes how we represent / emulate builtin templates

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 458559.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp
  libcxx/DELETE.ME
  libcxx/utils/ci/buildkite-pipeline.yml

Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -59,310 +59,6 @@
   limit: 2
 timeout_in_minutes: 120
 
-  - label: "Documentation"
-command: "libcxx/utils/ci/run-buildbot documentation"
-artifact_paths:
-  - "**/test-results.xml"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  #
-  # General testing with the default configuration, under all the supported
-  # Standard modes, with Clang and GCC. This catches most issues upfront.
-  # The goal of this step is to catch most issues while being very fast.
-  #
-  - wait
-
-  - label: "C++2b"
-command: "libcxx/utils/ci/run-buildbot generic-cxx2b"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++11"
-command: "libcxx/utils/ci/run-buildbot generic-cxx11"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++03"
-command: "libcxx/utils/ci/run-buildbot generic-cxx03"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "Modular build"
-command: "libcxx/utils/ci/run-buildbot generic-modules"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "GCC ${GCC_STABLE_VERSION} / C++latest"
-command: "libcxx/utils/ci/run-buildbot generic-gcc"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "gcc-${GCC_STABLE_VERSION}"
-CXX: "g++-${GCC_STABLE_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  #
-  # All other supported configurations of libc++.
-  #
-  - wait
-
-  - label: "C++20"
-command: "libcxx/utils/ci/run-buildbot generic-cxx20"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++17"
-command: "libcxx/utils/ci/run-buildbot generic-cxx17"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-# TODO (mordante) use head
-#CC: "clang-${LLVM_HEAD_VERSION}"
-#CXX: "clang++-${LLVM_HEAD_VERSION}"
-CC: "clang-15"
-CXX: "clang++-15"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++14"
-command: "libcxx/utils/ci/run-buildbot generic-cxx14"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-C

[PATCH] D133262: [clang] Fixes how we represent / emulate builtin templates

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 458586.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp
  libcxx/DELETE.ME
  libcxx/utils/ci/buildkite-pipeline.yml

Index: libcxx/utils/ci/buildkite-pipeline.yml
===
--- libcxx/utils/ci/buildkite-pipeline.yml
+++ libcxx/utils/ci/buildkite-pipeline.yml
@@ -59,310 +59,6 @@
   limit: 2
 timeout_in_minutes: 120
 
-  - label: "Documentation"
-command: "libcxx/utils/ci/run-buildbot documentation"
-artifact_paths:
-  - "**/test-results.xml"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  #
-  # General testing with the default configuration, under all the supported
-  # Standard modes, with Clang and GCC. This catches most issues upfront.
-  # The goal of this step is to catch most issues while being very fast.
-  #
-  - wait
-
-  - label: "C++2b"
-command: "libcxx/utils/ci/run-buildbot generic-cxx2b"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++11"
-command: "libcxx/utils/ci/run-buildbot generic-cxx11"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++03"
-command: "libcxx/utils/ci/run-buildbot generic-cxx03"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "Modular build"
-command: "libcxx/utils/ci/run-buildbot generic-modules"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "GCC ${GCC_STABLE_VERSION} / C++latest"
-command: "libcxx/utils/ci/run-buildbot generic-gcc"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "gcc-${GCC_STABLE_VERSION}"
-CXX: "g++-${GCC_STABLE_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  #
-  # All other supported configurations of libc++.
-  #
-  - wait
-
-  - label: "C++20"
-command: "libcxx/utils/ci/run-buildbot generic-cxx20"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: "clang++-${LLVM_HEAD_VERSION}"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++17"
-command: "libcxx/utils/ci/run-buildbot generic-cxx17"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-# TODO (mordante) use head
-#CC: "clang-${LLVM_HEAD_VERSION}"
-#CXX: "clang++-${LLVM_HEAD_VERSION}"
-CC: "clang-15"
-CXX: "clang++-15"
-agents:
-  queue: "libcxx-builders"
-  os: "linux"
-retry:
-  automatic:
-- exit_status: -1  # Agent was lost
-  limit: 2
-timeout_in_minutes: 120
-
-  - label: "C++14"
-command: "libcxx/utils/ci/run-buildbot generic-cxx14"
-artifact_paths:
-  - "**/test-results.xml"
-  - "**/*.abilist"
-env:
-CC: "clang-${LLVM_HEAD_VERSION}"
-CXX: 

[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 458587.
mizvekov marked 5 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

Files:
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/SemaCXX/deduced-return-void.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaTemplate/deduction.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1 +1,2 @@
 D133262
+D111283
Index: clang/test/SemaTemplate/deduction.cpp
===
--- clang/test/SemaTemplate/deduction.cpp
+++ clang/test/SemaTemplate/deduction.cpp
@@ -162,6 +162,15 @@
 
 } // namespace test4
 
+namespace test5 {
+
+template  class a {};
+template  void c(b, b);
+template  void c(a, a);
+void d() { c(a(), a()); }
+
+} // namespace test5
+
 // Verify that we can deduce enum-typed arguments correctly.
 namespace test14 {
   enum E { E0, E1 };
Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -1,4 +1,12 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20
+// RUN: %clang_cc1 -fsyntax-only -verify -xobjective-c++ %s -std=c++20 -fms-extensions -fblocks -fobjc-arc -fobjc-runtime-has-weak -fenable-matrix -Wno-dynamic-exception-spec -Wno-c++17-compat-mangling
+// RUN: %clang_cc1 -fsyntax-only -verify -xobjective-c++ %s -std=c++14 -fms-extensions -fblocks -fobjc-arc -fobjc-runtime-has-weak -fenable-matrix -Wno-dynamic-exception-spec -Wno-c++17-compat-mangling
+
+namespace std {
+template struct initializer_list {
+  const T *begin, *end;
+  initializer_list();
+};
+} // namespace std
 
 enum class N {};
 
@@ -9,6 +17,26 @@
 using Man = Animal;
 using Dog = Animal;
 
+using ManPtr = Man *;
+using DogPtr = Dog *;
+
+using SocratesPtr = ManPtr;
+
+using ConstMan = const Man;
+using ConstDog = const Dog;
+
+using Virus = void;
+using SARS = Virus;
+using Ebola = Virus;
+
+using Bacteria = float;
+using Bacilli = Bacteria;
+using Vibrio = Bacteria;
+
+struct Plant;
+using Gymnosperm = Plant;
+using Angiosperm = Plant;
+
 namespace variable {
 
 auto x1 = Animal();
@@ -25,6 +53,9 @@
 N t4 = x4; // expected-error {{lvalue of type 'Man' (aka 'int')}}
 N t5 = x5; // expected-error {{lvalue of type 'Dog' (aka 'int')}}
 
+auto x6 = { Man(), Dog() };
+N t6 = x6; // expected-error {{from 'std::initializer_list' (aka 'initializer_list')}}
+
 } // namespace variable
 
 namespace function_basic {
@@ -41,3 +72,160 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace function_multiple_basic {
+
+N t1 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Man();
+  return Dog();
+}();
+
+N t2 = []() -> decltype(auto) { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Man();
+  return Dog();
+}();
+
+N t3 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Dog();
+  auto x = Man();
+  return x;
+}();
+
+N t4 = [] { // expected-error {{rvalue of type 'int'}}
+  if (true)
+return Dog();
+  return 1;
+}();
+
+N t5 = [] { // expected-error {{rvalue of type 'Virus' (aka 'void')}}
+  if (true)
+return Ebola();
+  return SARS();
+}();
+
+N t6 = [] { // expected-error {{rvalue of type 'void'}}
+  if (true)
+return SARS();
+  return;
+}();
+
+} // namespace function_multiple_basic
+
+#define TEST_AUTO(X, A, B) \
+  static_assert(__is_same(A, B), ""); \
+  auto X(A a, B b) {   \
+if (0) \
+  return a;\
+if (0) \
+  return b;\
+return N();\
+  }
+#define TEST_DAUTO(X, A, B) \
+  static_assert(__is_same(A, B), ""); \
+  decltype(auto) X(A a, B b) {  \
+if (0)  \
+  return static_cast(a); \
+if (0)  \
+  return static_cast(b); \
+return N(); \
+  }
+
+namespace misc {
+
+TEST_AUTO(t1, ManPtr, DogPtr)  // expected-error {{but deduced as 'Animal *' (aka 'int *')}}
+TEST_AUTO(t2, ManPtr, int *)   // expected-error {{but deduced as 'int *'}}
+TEST_AUTO(t3, SocratesPtr, ManPtr) // expected

[PATCH] D133262: [clang] Fixes how we represent / emulate builtin templates

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked an inline comment as done.
mizvekov added inline comments.



Comment at: clang/lib/AST/DeclTemplate.cpp:262
+  }
+  default:;
+  };

mizvekov wrote:
> erichkeane wrote:
> > The semicolon after default is bizarre/unnecessary.  That said, I'd suggest 
> > just making the 'default' case be 'return false'.
> This is just a workaround for some versions of GCC and/or MSVC which warn on 
> control flow reaching the end of the function, even in cases such as a switch 
> which returns in all paths.
> Also we prefer to emit a warning on unhandled cases when omitting the default 
> case.
> 
> So this is a compact way of avoiding those issues without having to add a 
> `llvm_unreachable("control flow should never get here");` at the end.
> 
> Have we gotten rid of the old versions of those toolchains which had this 
> problem?
Removed as I just confirmed we don't need it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133262

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked an inline comment as done.
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:12139
+return X;
+  assert(declaresSameEntity(X, Y));
+  for (const Decl *DX : X->redecls()) {

erichkeane wrote:
> As a nit, I'd prefer this assert above the 'if' above, that way it catches 
> Nulls in that case. It seems that the 'contract' for this function is no null 
> values, so we want to catch this ASAP.
Actually we want to handle the case they are both null, in which case we return 
null as well.
This case would trip the assert below, as `declaresSameEntity` considers that 
not the same entity.

For example, unconstrained AutoType will have null ConceptDecl.

In the D130308 patch, we add another variant, `getCommonDeclChecked, which 
requires non-null inputs, which can be used in places where non-null is 
required.

I went ahead and moved the introduction of `getCommonDeclChecked` to this 
patch, even though there is only one use of it.



Comment at: clang/lib/AST/ASTContext.cpp:12154
+T *getCommonDecl(T *X, T *Y) {
+  return cast_or_null(
+  getCommonDecl(const_cast(cast_or_null(X)),

erichkeane wrote:
> Do we REALLY need to tolerate  'null' here as well?  It seems we should do a 
> normal cast and have the cast assert.
Yes, as above.



Comment at: clang/lib/AST/ASTContext.cpp:12172
+
+static auto getCommonTypeArray(ASTContext &Ctx, ArrayRef Xs,
+   ArrayRef Ys,

erichkeane wrote:
> Please comment these functions, it isn't clear on read through what you mean 
> by 'Array' here.  You probably mean for this to be something like 
> `getCommonTypes`.
Yeah that name works as well.



Comment at: clang/lib/AST/ASTContext.cpp:12241
+
+template  static auto *getCommonSizeExpr(T *X, T *Y) {
+  assert(X->getSizeExpr() == Y->getSizeExpr());

erichkeane wrote:
> I guess I don't see the po int of the next 3 functions?  There is no sugaring 
> or anything, AND they already assume they are the same 
> expression/element/etc? 
Well the point is to not repeat the assert in all use sites.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D111283#3771900 , @erichkeane 
wrote:

> Thanks for your patience, this was a sizable review that it took a while to 
> be able to make time for.  A handful of non-functional reviews, but the 
> functionality looks fine.

Thanks, I appreciate the effort!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

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


[PATCH] D111509: [clang] use getCommonSugar in an assortment of places

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 458608.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111509

Files:
  clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-fpfeatures.cpp
  clang/test/CodeGen/compound-assign-overflow.c
  clang/test/Sema/matrix-type-operators.c
  clang/test/Sema/nullability.c
  clang/test/Sema/sugar-common-types.c
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaObjC/format-strings-objc.m
  compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
  compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
  libcxx/DELETE.ME
  lldb/test/API/commands/expression/rdar42038760/main.c
  lldb/test/API/commands/expression/rdar44436068/main.c

Index: lldb/test/API/commands/expression/rdar44436068/main.c
===
--- lldb/test/API/commands/expression/rdar44436068/main.c
+++ lldb/test/API/commands/expression/rdar44436068/main.c
@@ -3,6 +3,6 @@
 __int128_t n = 1;
 n = n + n;
 return n; //%self.expect("p n", substrs=['(__int128_t) $0 = 2'])
-  //%self.expect("p n + 6", substrs=['(__int128) $1 = 8'])
-  //%self.expect("p n + n", substrs=['(__int128) $2 = 4'])
+  //%self.expect("p n + 6", substrs=['(__int128_t) $1 = 8'])
+  //%self.expect("p n + n", substrs=['(__int128_t) $2 = 4'])
 }
Index: lldb/test/API/commands/expression/rdar42038760/main.c
===
--- lldb/test/API/commands/expression/rdar42038760/main.c
+++ lldb/test/API/commands/expression/rdar42038760/main.c
@@ -10,7 +10,7 @@
   struct S0 l_19;
   l_19.f2 = 419;
   uint32_t l_4037 = 4294967295UL;
-  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(unsigned int) $0 = 358717883'])
+  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(uint32_t) $0 = 358717883'])
 }
 int main()
 {
Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,2 +1,3 @@
 D133262
 D111283
+D111509
Index: compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
@@ -12,12 +12,12 @@
 
 #ifdef SUB_I32
   (void)(uint32_t(1) - uint32_t(2));
-  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int'
+  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 #endif
 
 #ifdef SUB_I64
   (void)(uint64_t(800ll) - uint64_t(900ll));
-  // CHECK-SUB_I64: 800 - 900 cannot be represented in type 'unsigned {{long( long)?}}'
+  // CHECK-SUB_I64: 800 - 900 cannot be represented in type '{{uint64_t|unsigned long( long)?}}'
 #endif
 
 #ifdef SUB_I128
@@ -26,6 +26,6 @@
 # else
   puts("__int128 not supported\n");
 # endif
-  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type 'unsigned __int128'|__int128 not supported}}
+  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type '__uint128_t'|__int128 not supported}}
 #endif
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
@@ -13,7 +13,7 @@
   (void)(uint16_t(0x) * uint16_t(0x8001));
 
   (void)(uint32_t(0x) * uint32_t(0x2));
-  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type 'unsigned int'
+  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 
   return 0;
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
==

[PATCH] D130308: [clang] extend getCommonSugaredType to merge sugar nodes

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked 4 inline comments as done.
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:12141
 static Decl *getCommonDecl(Decl *X, Decl *Y) {
-  if (X == Y)
-return X;
-  assert(declaresSameEntity(X, Y));
+  if (!declaresSameEntity(X, Y))
+return nullptr;

erichkeane wrote:
> same concerns about null here.  I find myself wondering if this 'getCommonX' 
> should take/return references when possible.
Null is a valid input on this one. We change this function to now accept 
unrelated decls, and return null in that case as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130308

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


[PATCH] D130308: [clang] extend getCommonSugaredType to merge sugar nodes

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 458613.
mizvekov marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130308

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -1,3 +1,4 @@
 D133262
 D111283
 D111509
+D130308
Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix -triple i686-pc-win32
 
 enum class N {};
 
@@ -38,3 +38,77 @@
 N t7 = X4() + Y4(); // expected-error {{rvalue of type 'B4'}}
 N t8 = X4() * Y4(); // expected-error {{rvalue of type 'B4'}}
 N t9 = X5() * Y5(); // expected-error {{rvalue of type 'A4 __attribute__((matrix_type(3, 3)))'}}
+
+template  struct S1 {
+  template  struct S2 {};
+};
+
+N t10 = 0 ? S1() : S1(); // expected-error {{from 'S1' (aka 'S1')}}
+N t11 = 0 ? S1::S2() : S1::S2(); // expected-error {{from 'S1::S2' (aka 'S2')}}
+
+template  using Al = S1;
+
+N t12 = 0 ? Al() : Al(); // expected-error {{from 'Al' (aka 'S1')}}
+
+#define AS1 __attribute__((address_space(1)))
+#define AS2 __attribute__((address_space(1)))
+using AS1X1 = AS1 B1;
+using AS1Y1 = AS1 B1;
+using AS2Y1 = AS2 B1;
+N t13 = 0 ? (AS1X1){} : (AS1Y1){}; // expected-error {{rvalue of type 'AS1 B1' (aka '__attribute__((address_space(1))) int')}}
+N t14 = 0 ? (AS1X1){} : (AS2Y1){}; // expected-error {{rvalue of type '__attribute__((address_space(1))) B1' (aka '__attribute__((address_space(1))) int')}}
+
+using FX1 = X1 ();
+using FY1 = Y1 ();
+N t15 = 0 ? (FX1*){} : (FY1*){}; // expected-error {{rvalue of type 'B1 (*)()' (aka 'int (*)()')}}
+
+struct SS1 {};
+using SB1 = SS1;
+using SX1 = SB1;
+using SY1 = SB1;
+
+using MFX1 = X1 SX1::*();
+using MFY1 = Y1 SY1::*();
+
+N t16 = 0 ? (MFX1*){} : (MFY1*){}; // expected-error {{rvalue of type 'B1 SB1::*(*)()'}}
+
+N t17 = 0 ? (FX1 SX1::*){} : (FY1 SY1::*){}; // expected-error {{rvalue of type 'B1 (SB1::*)() __attribute__((thiscall))'}}
+
+N t18 = 0 ? (__typeof(X1*)){} : (__typeof(Y1*)){}; // expected-error {{rvalue of type 'typeof(B1 *)' (aka 'int *')}}
+
+struct Enums {
+  enum X : B1;
+  enum Y : ::B1;
+};
+using EnumsB = Enums;
+using EnumsX = EnumsB;
+using EnumsY = EnumsB;
+
+N t19 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::Y)){};
+// expected-error@-1 {{rvalue of type 'B1' (aka 'int')}}
+
+N t20 = 0 ? (__underlying_type(EnumsX::X)){} : (__underlying_type(EnumsY::X)){};
+// expected-error@-1 {{rvalue of type '__underlying_type(Enums::X)' (aka 'int')}}
+
+using SBTF1 = SS1 [[clang::btf_type_tag("1")]];
+using SBTF2 = ::SS1 [[clang::btf_type_tag("1")]];
+using SBTF3 = ::SS1 [[clang::btf_type_tag("2")]];
+
+N t21 = 0 ? (SBTF1){} : (SBTF3){}; // expected-error {{from 'SS1'}}
+N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 btf_type_tag(1)' (aka 'SS1')}}
+
+using QX = const SB1 *;
+using QY = const ::SB1 *;
+N t23 = 0 ? (QX){} : (QY){}; // expected-error {{rvalue of type 'const SB1 *' (aka 'const SS1 *')}}
+
+template  using Alias = short;
+N t24 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'Alias' (aka 'short')}}
+N t25 = 0 ? (Alias){} : (Alias){}; // expected-error {{rvalue of type 'short'}}
+
+template  concept C1 = true;
+template  concept C2 = true;
+C1 auto t26_1 = (SB1){};
+C1 auto t26_2 = (::SB1){};
+C2 auto t26_3 = (::SB1){};
+N t26 = 0 ? t26_1 : t26_2; // expected-error {{from 'SB1' (aka 'SS1')}}
+N t27 = 0 ? t26_1 : t26_3; // expected-error {{from 'SB1' (aka 'SS1')}}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3841,13 +3841,11 @@
 //   - If A is an array type, the pointer type produced by the
 // array-to-pointer standard conversion (4.2) is used in place of
 // A for type deduction; otherwise,
-if (ArgType->isArrayType())
-  ArgType = S.Context.getArrayDecayedType(ArgType);
 //   - If A is a function type, the pointer type produced by the
 // function-to-pointer standard conversion (4.3) is used in place
 // of A for type deduction; otherwise,
-else if (ArgType->isFunctionType())
-  ArgType = S.Context.getPointerType(ArgType);
+if (ArgType->canDecayToPointerType())
+  ArgType = S.Context.getDecayedType(ArgType);
 else {
   // - If A is a cv-qualified type, the top level cv-qual

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 458621.
mizvekov marked 6 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- libcxx/DELETE.ME
+++ libcxx/DELETE.ME
@@ -2,3 +2,4 @@
 D111283
 D111509
 D130308
+D131858
Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- clang/test/SemaTemplate/type_pack_element.cpp
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -11,14 +11,13 @@
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT:   |-TemplateArgument type 'int'
 // CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
-// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
-// CHECK-NEXT: |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
-// CHECK-NEXT: | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1 ...
+// CHECK-NEXT: |-BuiltinTemplate 0x{{[0-9A-Fa-f]+}} '__type_pack_element'
 // CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 
 template struct A {
   using test2 = __type_pack_element;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -38,7 +37,7 @@
 // CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test3 = __type_pack_element<0, Ts...>;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'type-parameter-0-1...'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'type-parameter-0-1...'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -50,14 +49,13 @@
 // CHECK-NEXT:   | `-PackExpansionType 0x{{[0-9A-Fa-f]+}} 'Ts...' dependent
 // CHECK-NEXT:   |   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
 // CHECK-NEXT:   | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} 'Ts'
-// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1...' sugar dependent
-// CHECK-NEXT: |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
-// CHECK-NEXT: | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1...' sugar dependent typename depth 0 index 1 ...
+// CHECK-NEXT: |-BuiltinTemplate 0x{{[0-9A-Fa-f]+}} '__type_pack_element'
 // CHECK-NEXT: `-PackExpansionType 0x{{

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:1618
+  QualType getSubstTemplateTypeParmType(QualType Replacement,
+Decl *ReplacedDecl,
+unsigned Index) const;

davrec wrote:
> ReplacedDecl -> ReplacedParamParent (see below)
We need a more apt name.

How about `ReplacedTemplateLikeEntityDecl`?



Comment at: clang/include/clang/AST/Type.h:4998
+  /// Gets the templated entity that was substituted.
+  Decl *getReplacedDecl() const { return ReplacedDecl; }
+

davrec wrote:
> To reiterate an earlier comment which may have been overlooked: I think this 
> needs a clearer name and documentation (so long as I do not misunderstand 
> what kinds of decls it may be - see other inline comment).  
> 
> Given that we have `getReplacedParameter()`, I think something like 
> `getReplacedParamParent()` makes the most sense.
> 
> And the documentation should suggest the relationship between 
> `getReplacedParameter` and this (i.e. `getReplacedParamParent()` + 
> `getIndex()` -> `getReplacedParameter()`).  
> 
> Plus, add back in the original documentation for `getReplacedParameter()`, 
> and a brief line of documentation for `getIndex()` (and do same for the Pack 
> version below too).
> 
Yeah like I said, we can't suggest a relationship very much, I don't think we 
should try to explain how to obtain the parameter from the main entity, that 
would be exposing too much guts.

We just offer a method to get it, and hope for the best.

The name for this method, whatever we pick, will probably be a bit vague 
sounding, because in Clang a template is a very vague concept (in the 
philosophical sense and in the C++20 sense).



Comment at: clang/lib/AST/Type.cpp:3709
+unsigned Index) {
+  if (const auto *TTP = dyn_cast(D))
+return TTP;

davrec wrote:
> Will this cast ever succeed?  I.e. are there still places 
> `Context.getSubstTemplateTypeParmType(...)` is called with a TTPD as the 
> `ReplacedDecl`?  That would make `getReplacedDecl()` much more 
> complicated/less understandable - can we change any such places to always 
> pass the parent template/templated entity as the ReplacedDecl, for 
> consistency (and so that we can rename ReplacedDecl to ReplacedParamParent)?
Yeah, there is this one place related to concepts where we invent a 
substitution and there is actually no associated declaration at all, besides 
just the invented template parameter, so in this case the TTP is the parent and 
parameter.

So that is why I picked such a vaguely named acessor... because there is no 
order here, anarchy reigns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

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


[PATCH] D132816: [clang] AST: SubstTemplateTypeParmType support for non-canonical underlying type

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 458623.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132816

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaTemplate.cpp

Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -3506,8 +3506,8 @@
 
   // Wrap the type in substitution sugar.
   auto getSubstType = [&](unsigned IndexReplaced, QualType Replacement) {
-return SemaRef.Context.getSubstTemplateTypeParmType(
-Replacement.getCanonicalType(), BTD, IndexReplaced);
+return SemaRef.Context.getSubstTemplateTypeParmType(Replacement, BTD,
+IndexReplaced);
   };
 
   switch (BTD->getBuiltinTemplateKind()) {
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3718,6 +3718,11 @@
 : Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
Replacement->getDependence()),
   ReplacedDecl(ReplacedDecl) {
+  SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType =
+  Replacement != getCanonicalTypeInternal();
+  if (SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType)
+*getTrailingObjects() = Replacement;
+
   SubstTemplateTypeParmTypeBits.Index = Index;
   assert(ReplacedDecl != nullptr);
   assert(getReplacedParameter() != nullptr);
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1529,8 +1529,7 @@
 return ToReplacementTypeOrErr.takeError();
 
   return Importer.getToContext().getSubstTemplateTypeParmType(
-  ToReplacementTypeOrErr->getCanonicalType(), *ReplacedOrErr,
-  T->getIndex());
+  *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex());
 }
 
 ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4752,9 +4752,6 @@
 QualType ASTContext::getSubstTemplateTypeParmType(QualType Replacement,
   Decl *ReplacedDecl,
   unsigned Index) const {
-  assert(Replacement.isCanonical()
- && "replacement types must always be canonical");
-
   llvm::FoldingSetNodeID ID;
   SubstTemplateTypeParmType::Profile(ID, Replacement, ReplacedDecl, Index);
   void *InsertPos = nullptr;
@@ -4762,8 +4759,11 @@
   SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
 
   if (!SubstParm) {
-SubstParm = new (*this, TypeAlignment)
-SubstTemplateTypeParmType(Replacement, ReplacedDecl, Index);
+void *Mem = Allocate(SubstTemplateTypeParmType::totalSizeToAlloc(
+ !Replacement.isCanonical()),
+ TypeAlignment);
+SubstParm =
+new (Mem) SubstTemplateTypeParmType(Replacement, ReplacedDecl, Index);
 Types.push_back(SubstParm);
 SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
   }
Index: clang/include/clang/AST/TypeProperties.td
===
--- clang/include/clang/AST/TypeProperties.td
+++ clang/include/clang/AST/TypeProperties.td
@@ -741,7 +741,7 @@
   // The call to getCanonicalType here existed in ASTReader.cpp, too.
   def : Creator<[{
 return ctx.getSubstTemplateTypeParmType(
-ctx.getCanonicalType(replacementType), replacedDecl, Index);
+replacementType, replacedDecl, Index);
   }]>;
 }
 
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -1798,8 +1798,10 @@
 
 unsigned : NumTypeBits;
 
+unsigned HasNonCanonicalUnderlyingType : 1;
+
 // The index of the template parameter this substitution represents.
-unsigned Index;
+unsigned Index : 16;
   };
 
   class SubstTemplateTypeParmPackTypeBitfields {
@@ -4981,8 +4983,12 @@
 /// been replaced with these.  They are used solely to record that a
 /// type was originally written as a template type parameter;
 /// therefore they are never canonical.
-class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
+class SubstTemplateTypeParmType final
+: public Type,
+  public llvm::FoldingSetNode,
+  private llvm::TrailingObjects {
   friend class ASTContext;
+  friend class llvm::TrailingObjects;
 
   Decl *ReplacedDecl;
 
@@ -4992,7 +4998,11 @@
 public:
   /// 

[PATCH] D133468: [clang] Implement divergence for TypedefType and UsingType

2022-09-07 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov created this revision.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.
Herald added a project: All.
mizvekov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

With this patch, TypedefTypes and UsingTypes can have an
underlying type which diverges from their corresponding
declarations.

For the TypedefType case, this can be seen when getting
the common sugared type between two redeclarations with
different sugar.

For both cases, this will become important as resugaring
is implemented, as this will allow us to resugar these
when they were dependent before instantiation.

Depends on D132816 

Signed-off-by: Matheus Izvekov 

Depends on D132816 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133468

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/sugar-common-types.cpp

Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -112,3 +112,22 @@
 C2 auto t26_3 = (::SB1){};
 N t26 = 0 ? t26_1 : t26_2; // expected-error {{from 'SB1' (aka 'SS1')}}
 N t27 = 0 ? t26_1 : t26_3; // expected-error {{from 'SB1' (aka 'SS1')}}
+
+using RPB1 = X1*;
+using RPX1 = RPB1;
+using RPB1 = Y1*; // redeclared
+using RPY1 = RPB1;
+N t28 = *(RPB1){}; // expected-error {{lvalue of type 'Y1' (aka 'int')}}
+auto t29 = 0 ? (RPX1){} : (RPY1){};
+N t30 = t29;  // expected-error {{lvalue of type 'RPB1' (aka 'int *')}}
+N t31 = *t29; // expected-error {{lvalue of type 'B1' (aka 'int')}}
+
+namespace A { using type1 = X1*; };
+namespace C { using A::type1; };
+using UPX1 = C::type1;
+namespace A { using type1 = Y1*; };  // redeclared
+namespace C { using A::type1; }; // redeclared
+using UPY1 = C::type1;
+auto t32 = 0 ? (UPX1){} : (UPY1){};
+N t33 = t32;  // expected-error {{lvalue of type 'C::type1' (aka 'int *')}}
+N t34 = *t32; // expected-error {{lvalue of type 'B1' (aka 'int')}}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3434,25 +3434,34 @@
 }
 
 TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D,
- QualType underlying, QualType can)
-: Type(tc, can, toSemanticDependence(underlying->getDependence())),
+ QualType Underlying, QualType can)
+: Type(tc, can, toSemanticDependence(can->getDependence())),
   Decl(const_cast(D)) {
   assert(!isa(can) && "Invalid canonical type");
+  TypedefBits.isDivergent = !Underlying.isNull();
+  if (isDivergent())
+*reinterpret_cast(this + 1) = Underlying;
 }
 
 QualType TypedefType::desugar() const {
-  return getDecl()->getUnderlyingType();
+  return isDivergent() ? *getTrailingObjects()
+   : Decl->getUnderlyingType();
 }
 
 UsingType::UsingType(const UsingShadowDecl *Found, QualType Underlying,
  QualType Canon)
-: Type(Using, Canon, toSemanticDependence(Underlying->getDependence())),
+: Type(Using, Canon, toSemanticDependence(Canon->getDependence())),
   Found(const_cast(Found)) {
-  assert(Underlying == getUnderlyingType());
+  UsingBits.isDivergent = !Underlying.isNull();
+  if (isDivergent())
+*reinterpret_cast(this + 1) = Underlying;
 }
 
 QualType UsingType::getUnderlyingType() const {
-  return QualType(cast(Found->getTargetDecl())->getTypeForDecl(), 0);
+  return isDivergent()
+ ? *getTrailingObjects()
+ : QualType(
+   cast(Found->getTargetDecl())->getTypeForDecl(), 0);
 }
 
 QualType MacroQualifiedType::desugar() const { return getUnderlyingType(); }
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1543,10 +1543,14 @@
 
 void TextNodeDumper::VisitUsingType(const UsingType *T) {
   dumpDeclRef(T->getFoundDecl());
+  if (T->isDivergent())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitTypedefType(const TypedefType *T) {
   dumpDeclRef(T->getDecl());
+  if (T->isDivergent())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) {
Index: clang/lib/AST/JSONNodeDumper.cpp
===
--- clang/lib/AST/JSONNodeDumper.cpp
+++ clang/lib/AST/JSONNodeDumper.cpp
@@ -531,6 +531,14 @@
 
 void JSONNodeDumper::VisitTy

[PATCH] D127695: WIP: clang: Implement Template Specialization Resugaring

2022-09-08 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov marked 2 inline comments as done.
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:534-540
+  QualType TransformSubstTemplateTypeParmType(TypeLocBuilder &TLB,
+  SubstTemplateTypeParmTypeLoc TL) 
{
+QualType QT = TL.getType();
+const SubstTemplateTypeParmType *T = TL.getTypePtr();
+Decl *ReplacedDecl = T->getReplacedDecl();
+
+Optional PackIndex = T->getPackIndex();

davrec wrote:
> davrec wrote:
> > Haven't thought this through fully, but: would the following make D128113 
> > (storing the pack index in the STTPT or introducing a new sugar type) 
> > unnecessary?
> > ```
> > map, Optional> CurPackIndices;
> > QualType TransformSubstTemplateTypeParmType(TypeLocBuilder &TLB,
> >   SubstTemplateTypeParmTypeLoc 
> > TL) {
> >QualType QT = TL.getType();
> >const SubstTemplateTypeParmType *T = TL.getTypePtr();
> >Decl *ReplacedDecl = T->getReplacedDecl();
> >
> >Optional &PackIndex = CurPackIndices[{ReplacedDecl, 
> > T->getIndex()}];
> >if (!PackIndex && T->getReplacedParameter()->isParameterPack())
> >  PackIndex = 0;
> > 
> >...
> > 
> >if (PackIndex)
> >  ++PackIndex;
> >  // ^ maybe reset to zero if > pack size, if we might be resugaring 
> > multiple expansions
> >return QT;
> > }
> > ```
> Disregard above - upon further thought this does not improve the things; 
> there still isn't enough info about the substitutions.  I.e. the issue is 
> with substitutions, not the parameter declarations for which they are 
> substituted.  So a sugar node wrapping the STTPTs to represent each expansion 
> instance really is needed.  Then when we have that I think we could map from 
> those to their current pack indices per the above to infer the pack indices.
> 
> For this sugar node, maybe we could just modify 
> `SubstTemplateTypeParmPackType` so it is not just canonical, but can also be 
> sugar wrapping substituted STTPTs, as opposed to introducing a new Subst* 
> type class?
I will reply to this on https://reviews.llvm.org/D128113.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127695

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


[PATCH] D128113: WIP: Clang: fix AST representation of expanded template arguments.

2022-09-08 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

@davrec  @alexfh

I finally managed to have a talk to @rsmith about this.

He thinks that, even if we can't come up with a better solution in time, the 
benefits of this patch justify the costs observed, as those substitution nodes 
are pretty useless without a way to index the pack, and having a rich AST is 
one of Clang's main goals.

But he also came up with this nifty idea that this high cost is perhaps coming 
because we are reindexing the whole pack every time that repro recurses on that 
disjunction and we consume the first element in the deduction.
And that a good solution for this might be to just index the pack backwards, so 
that 0 is the last element.

I will try that sometime soon. Even if I don't see an improvement, any further 
objections we just re-merge this?

PS: That does not disregard the other ideas to further improve this in the 
future. Another thing he noted that would be important is to also be able to 
represent in the resulting AST a pack that expanded 0 times.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D111283: [clang] template / auto deduction deduces common sugar

2022-09-08 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd200db386378: [clang] template / auto deduction deduces 
common sugar (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D111283?vs=458587&id=458786#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111283

Files:
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
  clang/test/SemaCXX/deduced-return-void.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaTemplate/deduction.cpp

Index: clang/test/SemaTemplate/deduction.cpp
===
--- clang/test/SemaTemplate/deduction.cpp
+++ clang/test/SemaTemplate/deduction.cpp
@@ -162,6 +162,15 @@
 
 } // namespace test4
 
+namespace test5 {
+
+template  class a {};
+template  void c(b, b);
+template  void c(a, a);
+void d() { c(a(), a()); }
+
+} // namespace test5
+
 // Verify that we can deduce enum-typed arguments correctly.
 namespace test14 {
   enum E { E0, E1 };
Index: clang/test/SemaCXX/sugared-auto.cpp
===
--- clang/test/SemaCXX/sugared-auto.cpp
+++ clang/test/SemaCXX/sugared-auto.cpp
@@ -1,4 +1,12 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20
+// RUN: %clang_cc1 -fsyntax-only -verify -xobjective-c++ %s -std=c++20 -fms-extensions -fblocks -fobjc-arc -fobjc-runtime-has-weak -fenable-matrix -Wno-dynamic-exception-spec -Wno-c++17-compat-mangling
+// RUN: %clang_cc1 -fsyntax-only -verify -xobjective-c++ %s -std=c++14 -fms-extensions -fblocks -fobjc-arc -fobjc-runtime-has-weak -fenable-matrix -Wno-dynamic-exception-spec -Wno-c++17-compat-mangling
+
+namespace std {
+template struct initializer_list {
+  const T *begin, *end;
+  initializer_list();
+};
+} // namespace std
 
 enum class N {};
 
@@ -9,6 +17,26 @@
 using Man = Animal;
 using Dog = Animal;
 
+using ManPtr = Man *;
+using DogPtr = Dog *;
+
+using SocratesPtr = ManPtr;
+
+using ConstMan = const Man;
+using ConstDog = const Dog;
+
+using Virus = void;
+using SARS = Virus;
+using Ebola = Virus;
+
+using Bacteria = float;
+using Bacilli = Bacteria;
+using Vibrio = Bacteria;
+
+struct Plant;
+using Gymnosperm = Plant;
+using Angiosperm = Plant;
+
 namespace variable {
 
 auto x1 = Animal();
@@ -25,6 +53,9 @@
 N t4 = x4; // expected-error {{lvalue of type 'Man' (aka 'int')}}
 N t5 = x5; // expected-error {{lvalue of type 'Dog' (aka 'int')}}
 
+auto x6 = { Man(), Dog() };
+N t6 = x6; // expected-error {{from 'std::initializer_list' (aka 'initializer_list')}}
+
 } // namespace variable
 
 namespace function_basic {
@@ -41,3 +72,160 @@
 N t3 = x3; // expected-error {{lvalue of type 'Animal' (aka 'int')}}
 
 } // namespace function_basic
+
+namespace function_multiple_basic {
+
+N t1 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Man();
+  return Dog();
+}();
+
+N t2 = []() -> decltype(auto) { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Man();
+  return Dog();
+}();
+
+N t3 = [] { // expected-error {{rvalue of type 'Animal' (aka 'int')}}
+  if (true)
+return Dog();
+  auto x = Man();
+  return x;
+}();
+
+N t4 = [] { // expected-error {{rvalue of type 'int'}}
+  if (true)
+return Dog();
+  return 1;
+}();
+
+N t5 = [] { // expected-error {{rvalue of type 'Virus' (aka 'void')}}
+  if (true)
+return Ebola();
+  return SARS();
+}();
+
+N t6 = [] { // expected-error {{rvalue of type 'void'}}
+  if (true)
+return SARS();
+  return;
+}();
+
+} // namespace function_multiple_basic
+
+#define TEST_AUTO(X, A, B) \
+  static_assert(__is_same(A, B), ""); \
+  auto X(A a, B b) {   \
+if (0) \
+  return a;\
+if (0) \
+  return b;\
+return N();\
+  }
+#define TEST_DAUTO(X, A, B) \
+  static_assert(__is_same(A, B), ""); \
+  decltype(auto) X(A a, B b) {  \
+if (0)  \
+  return static_cast(a); \
+if (0)  \
+  return static_cast(b); \
+return N(); \
+  }
+
+namespace misc {
+
+TEST_AUTO(t1, ManPtr, DogPtr)  // expected-error {{but deduced as 'Animal *' (aka 'int *')}}
+TEST_AUTO(t2, ManPtr, int *)   // expected-error {{but deduced as 'int *'}}
+TEST_AUTO(t3

[PATCH] D111509: [clang] use getCommonSugar in an assortment of places

2022-09-08 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd42122cd5db0: [clang] use getCommonSugar in an assortment of 
places (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D111509?vs=458608&id=458787#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111509

Files:
  clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/AST/ast-dump-fpfeatures.cpp
  clang/test/CodeGen/compound-assign-overflow.c
  clang/test/Sema/matrix-type-operators.c
  clang/test/Sema/nullability.c
  clang/test/Sema/sugar-common-types.c
  clang/test/SemaCXX/matrix-type-operators.cpp
  clang/test/SemaCXX/sugar-common-types.cpp
  clang/test/SemaCXX/sugared-auto.cpp
  clang/test/SemaObjC/format-strings-objc.m
  compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
  compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
  compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
  lldb/test/API/commands/expression/rdar42038760/main.c
  lldb/test/API/commands/expression/rdar44436068/main.c

Index: lldb/test/API/commands/expression/rdar44436068/main.c
===
--- lldb/test/API/commands/expression/rdar44436068/main.c
+++ lldb/test/API/commands/expression/rdar44436068/main.c
@@ -3,6 +3,6 @@
 __int128_t n = 1;
 n = n + n;
 return n; //%self.expect("p n", substrs=['(__int128_t) $0 = 2'])
-  //%self.expect("p n + 6", substrs=['(__int128) $1 = 8'])
-  //%self.expect("p n + n", substrs=['(__int128) $2 = 4'])
+  //%self.expect("p n + 6", substrs=['(__int128_t) $1 = 8'])
+  //%self.expect("p n + n", substrs=['(__int128_t) $2 = 4'])
 }
Index: lldb/test/API/commands/expression/rdar42038760/main.c
===
--- lldb/test/API/commands/expression/rdar42038760/main.c
+++ lldb/test/API/commands/expression/rdar42038760/main.c
@@ -10,7 +10,7 @@
   struct S0 l_19;
   l_19.f2 = 419;
   uint32_t l_4037 = 4294967295UL;
-  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(unsigned int) $0 = 358717883'])
+  l_19.f2 = g_463; //%self.expect("expr ((l_4037 % (-(g_463))) | l_19.f2)", substrs=['(uint32_t) $0 = 358717883'])
 }
 int main()
 {
Index: compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
@@ -12,12 +12,12 @@
 
 #ifdef SUB_I32
   (void)(uint32_t(1) - uint32_t(2));
-  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type 'unsigned int'
+  // CHECK-SUB_I32: usub-overflow.cpp:[[@LINE-1]]:22: runtime error: unsigned integer overflow: 1 - 2 cannot be represented in type '{{uint32_t|unsigned int}}'
 #endif
 
 #ifdef SUB_I64
   (void)(uint64_t(800ll) - uint64_t(900ll));
-  // CHECK-SUB_I64: 800 - 900 cannot be represented in type 'unsigned {{long( long)?}}'
+  // CHECK-SUB_I64: 800 - 900 cannot be represented in type '{{uint64_t|unsigned long( long)?}}'
 #endif
 
 #ifdef SUB_I128
@@ -26,6 +26,6 @@
 # else
   puts("__int128 not supported\n");
 # endif
-  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type 'unsigned __int128'|__int128 not supported}}
+  // CHECK-SUB_I128: {{0x4000 - 0x8000 cannot be represented in type '__uint128_t'|__int128 not supported}}
 #endif
 }
Index: compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
@@ -13,7 +13,7 @@
   (void)(uint16_t(0x) * uint16_t(0x8001));
 
   (void)(uint32_t(0x) * uint32_t(0x2));
-  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type 'unsigned int'
+  // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in 

  1   2   3   4   5   6   7   8   9   10   >