[clang] [clang-tools-extra] [lldb] [clang] Reland: Instantiate alias templates with sugar (PR #101858)

2024-08-08 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> From past conversations with IWYU maintainer, this was desirable, since IWYU 
> rolls its own resugarer, which is faulty and difficult to maintain.

I just want to mention that, actually, IWYU doesn't probably need any resugarer 
at all. A type template argument as-written is needed just to decide whether 
its canonical type should be reported for `#include`ing or not (e.g. because 
the `typedef` author has provided it already). Another way to do it is to 
collect a list of types blocked for reporting before scanning the instantiated 
template. I started rewriting IWYU in that direction some time ago.

https://github.com/llvm/llvm-project/pull/101858
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [lldb] [clang] Reland: Instantiate alias templates with sugar (PR #101858)

2024-08-05 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> One possibility here is that if you have the type, then you will have a 
> template specialization type for the template alias, and that gives you the 
> template arguments used to specialize the alias. Which should answer this 
> need.

This can probably go, thank you!

https://github.com/llvm/llvm-project/pull/101858
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [lldb] [clang] Reland: Instantiate alias templates with sugar (PR #101858)

2024-08-05 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

No, IWYU has some complex logic to figure out which type components the type 
alias author intends to provide, and which should be `#include`d at the use 
site. Of course, substituted template type arguments are the user 
responsibility, not the alias author's one, hence this information is important.

https://github.com/llvm/llvm-project/pull/101858
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [lldb] [clang] Reland: Instantiate alias templates with sugar (PR #101858)

2024-08-05 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

When instantiating such an alias:
```cpp
template 
using Identity = T;
```
before the patch:
```
TemplateSpecializationType 0x676f0a60 'Identity' sugar alias
|-name: 'Identity' qualified
| `-TypeAliasTemplateDecl 0x676c91d8  Identity
|-TemplateArgument type 'IndirectClass'
| `-ElaboratedType 0x676c9250 'IndirectClass' sugar
|   `-RecordType 0x676c8430 'class IndirectClass'
| `-CXXRecord 0x676c8398 'IndirectClass'
`-SubstTemplateTypeParmType 0x676f0a20 'class IndirectClass' sugar typename 
depth 0 index 0 T
  |-TypeAliasTemplate 0x676c91d8 'Identity'
  `-RecordType 0x676c8430 'class IndirectClass'
`-CXXRecord 0x676c8398 'IndirectClass'
```
After the patch:
```
TemplateSpecializationType 0x676f0a30 'Identity' sugar alias
|-name: 'Identity' qualified
| `-TypeAliasTemplateDecl 0x676c91d8  Identity
|-TemplateArgument type 'IndirectClass'
| `-ElaboratedType 0x676c9250 'IndirectClass' sugar
|   `-RecordType 0x676c8430 'class IndirectClass'
| `-CXXRecord 0x676c8398 'IndirectClass'
`-ElaboratedType 0x676c9250 'IndirectClass' sugar
  `-RecordType 0x676c8430 'class IndirectClass'
`-CXXRecord 0x676c8398 'IndirectClass'
```
@mizvekov, do you have any idea how to get back the lost 
`SubstTemplateTypeParmType`? It plays an important role in the IWYU tool 
analysis. Thanks!

https://github.com/llvm/llvm-project/pull/101858
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Adds a pseudonym to clang"s windows mangler... (PR #97792)

2024-07-14 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

LGTM, but I don't have the commit access, hence cannot merge your PR. Someone 
closely related to the community should take a look.

https://github.com/llvm/llvm-project/pull/97792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Adds a pseudonym to clang"s windows mangler... (PR #97792)

2024-07-09 Thread Andrey Ali Khan Bolshakov via cfe-commits




bolshakov-a wrote:

I'd prefer something simpler like:
```cpp
struct A { int* pi; };
template  void TplFn();
int i;
void Fn() {
  TplFn();
}
```
with checking of the full mangled name.

https://github.com/llvm/llvm-project/pull/97792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Adds a pseudonym to clang"s windows mangler... (PR #97792)

2024-07-09 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -1938,12 +1946,23 @@ void 
MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T,
 mangleNumber(V.getLValueOffset().getQuantity());
   } else if (!V.hasLValuePath()) {
 // FIXME: This can only happen as an extension. Invent a mangling.
-break;
+DiagnosticsEngine &Diags = Context.getDiags();
+unsigned DiagID =
+Diags.getCustomDiagID(DiagnosticsEngine::Error,
+  "cannot mangle this template argument yet "
+  "(non-null base with null lvalue path)");

bolshakov-a wrote:

I think that "lvalue base" and "lvalue path" are clang internal terms. Not sure 
whether they are worth appearing in diagnostics.

https://github.com/llvm/llvm-project/pull/97792
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Ok, got it. Thanks!

https://github.com/llvm/llvm-project/pull/85837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@efriedma-quic ping.

https://github.com/llvm/llvm-project/pull/85837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -1265,13 +1238,62 @@ class TemplateDiff {
 IsNullPtr = true;
 return;
   case TemplateArgument::Expression:
-// TODO: Sometimes, the desugared template argument Expr differs from
-// the sugared template argument Expr.  It may be useful in the future
-// but for now, it is just discarded.
-if (!E)
-  E = TA.getAsExpr();
-return;
+E = Iter->getAsExpr();
+break;
+  case TemplateArgument::Null:
+  case TemplateArgument::Type:
+  case TemplateArgument::Template:
+  case TemplateArgument::TemplateExpansion:
+llvm_unreachable("TemplateArgument kind is not expected for NTTP");
+  case TemplateArgument::Pack:
+llvm_unreachable("TemplateArgument kind handled elsewhere");

bolshakov-a wrote:

Nit: "... _should be_ handled ..."?

https://github.com/llvm/llvm-project/pull/93265
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a approved this pull request.

One question about the version of the C++ standard under testing, otherwise 
LGTM, thanks!

https://github.com/llvm/llvm-project/pull/93265
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a edited 
https://github.com/llvm/llvm-project/pull/93265
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Avoid crash due to unimplemented StructuralValue support in the template differ (PR #93265)

2024-05-24 Thread Andrey Ali Khan Bolshakov via cfe-commits




bolshakov-a wrote:

I don't see any C++26-specific stuff here, only C++20.

https://github.com/llvm/llvm-project/pull/93265
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-05-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/85837

>From 61abd7b6089ecb87eaf6886e251969d4db87e223 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 19 Mar 2024 19:05:36 +0300
Subject: [PATCH 1/2] [clang][c++20] Fix code coverage mapping crash with
 generalized NTTPs

Introduced in #78041, originally reported as #79957 and fixed partially
in #80050.

`OpaqueValueExpr` used with `TemplateArgument::StructuralValue` has no
corresponding source expression.

A test case with subobject-referring NTTP added.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 3 ++-
 clang/test/CoverageMapping/templates.cpp | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index cc8ab7a5b4369..48896fa03d9ff 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2187,7 +2187,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-Visit(OVE->getSourceExpr());
+if (const Expr *SE = OVE->getSourceExpr())
+  Visit(SE);
   }
 };
 
diff --git a/clang/test/CoverageMapping/templates.cpp 
b/clang/test/CoverageMapping/templates.cpp
index 143e566a33cb8..7e7f2208f1145 100644
--- a/clang/test/CoverageMapping/templates.cpp
+++ b/clang/test/CoverageMapping/templates.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
 
 template
 void unused(T x) {
@@ -30,5 +30,6 @@ namespace structural_value_crash {
 
   void test() {
 tpl_fn();
+tpl_fn<&arr[1]>();
   }
 }

>From 9684fed244607e3c7923c0a3118945c559e2d5d5 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Thu, 16 May 2024 12:18:17 +0300
Subject: [PATCH 2/2] Fix up: check `isUnique` instead of source expr presence

---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 48896fa03d9ff..5f62d2ae46bdb 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2187,8 +2187,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-if (const Expr *SE = OVE->getSourceExpr())
-  Visit(SE);
+if (OVE->isUnique())
+  Visit(OVE->getSourceExpr());
   }
 };
 

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


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-05-15 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Thanks!

https://github.com/llvm/llvm-project/pull/1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-05-15 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Could you please merge both of these?

https://github.com/llvm/llvm-project/pull/1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-05-13 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

This looks like supporting my words:
https://github.com/llvm/llvm-project/blob/llvmorg-19-init/clang/lib/CodeGen/CodeGenPGO.cpp#L935-L936

https://github.com/llvm/llvm-project/pull/1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-05-13 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@efriedma-quic ping. CC @AaronBallman

https://github.com/llvm/llvm-project/pull/1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-04-22 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@efriedma-quic, would it be OK to add "subexpression" visitation with a comment 
that I'm not sure that it is actually needed?

https://github.com/llvm/llvm-project/pull/1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-04-18 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> But anyway, I think we end up doing the right thing automatically if you 
> ignore non-unique OpaqueValueExprs.

The problem is that there is no initializing "common expression" in the AST 
besides non-unique `OpaqueValueExpr`, hence some code handling 
`ArrayInitLoopExpr` should be written so as not to lose it at all.

@chapuni, @gulfemsavrun, @evodius96, @vedantk, please clarify: should or should 
not the implicit stuff be traversed here, particularly for array element 
initialization?

https://github.com/llvm/llvm-project/pull/1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][NFC] Avoid visiting non-unique `OpaqueValueExpr` (PR #88910)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> Please turn off [Keep my email addresses 
> private](https://github.com/settings/emails) setting in your account.

Done.

https://github.com/llvm/llvm-project/pull/88910
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/1

>From a025b2a45c2a66595c111262dd43c0890f0d54b6 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 16 Apr 2024 14:21:40 +0300
Subject: [PATCH 1/2] [Coverage] Handle array decomposition correctly

`ArrayInitLoopExpr` AST node has two occurences of its as-written
initializing expression in its subexpressions through a non-unique
`OpaqueValueExpr`. It causes double-visiting of the initializing
expression if not handled explicitly, as discussed in #85837.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp |  4 
 clang/test/CoverageMapping/decomposition.cpp | 15 +++
 2 files changed, 19 insertions(+)
 create mode 100644 clang/test/CoverageMapping/decomposition.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d0..569fd489dc8baa 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2171,6 +2171,10 @@ struct CounterCoverageMappingBuilder
 // propagate counts into them.
   }
 
+  void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *AILE) {
+Visit(AILE->getCommonExpr()->getSourceExpr());
+  }
+
   void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
 // Just visit syntatic expression as this is what users actually write.
 VisitStmt(POE->getSyntacticForm());
diff --git a/clang/test/CoverageMapping/decomposition.cpp 
b/clang/test/CoverageMapping/decomposition.cpp
new file mode 100644
index 00..31bd6cae2c4dec
--- /dev/null
+++ b/clang/test/CoverageMapping/decomposition.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   _Z19array_decompositioni:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+8]]:20 -> [[@LINE+8]]:25 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+7]]:20 -> [[@LINE+7]]:25 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+6]]:27 -> [[@LINE+6]]:28 = #1
+// CHECK-NEXT:  File 0, [[@LINE+5]]:28 -> [[@LINE+5]]:29 = #1
+// CHECK-NEXT:  File 0, [[@LINE+4]]:32 -> [[@LINE+4]]:33 = (#0 - #1)
+int array_decomposition(int i) {
+  int a[] = {1, 2, 3};
+  int b[] = {4, 5, 6};
+  auto [x, y, z] = i > 0 ? a : b;
+  return x + y + z;
+}

>From 2936ef132db8908fa65293ceba6884f80c871c93 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Wed, 17 Apr 2024 07:10:25 +0300
Subject: [PATCH 2/2] Fix up running test on Windows

---
 clang/test/CoverageMapping/decomposition.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CoverageMapping/decomposition.cpp 
b/clang/test/CoverageMapping/decomposition.cpp
index 31bd6cae2c4dec..601ea630faeec9 100644
--- a/clang/test/CoverageMapping/decomposition.cpp
+++ b/clang/test/CoverageMapping/decomposition.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -triple 
%itanium_abi_triple -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
 
 // CHECK-LABEL:   _Z19array_decompositioni:
 // CHECK-NEXT:  File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0

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


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

I don't see any difference on your example (with `main()` and function 
definitions added) with and without my patch neither in the dumped coverage 
mapping nor in the output of `llvm-cov show ... --show-branches=count 
--show-expansions -show-line-counts-or-regions` command. If the coverage 
mapping works with code regions, it looks quite natural that an implicit code 
(`foo()` call inside `f()` in the sample) has no corresponding region and hence 
no mapping (except macro expansions).

Maybe, @hyp can clarify?

https://github.com/llvm/llvm-project/pull/1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][NFC] Avoid visiting non-unique `OpaqueValueExpr` (PR #88910)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Could you merge it please?

https://github.com/llvm/llvm-project/pull/88910
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Honestly, I'm not very familiar with code coverage technique, but it seems to 
me that only explicitly written code is relevant for that. "Common expression" 
is exactly the explicitly written part. "Subexpression" is an implicitly 
generated per-element initializer which refers to the "common expression" 
(hence, without this patch, the counters for the conditional operator from the 
test are duplicated despite it is executed only once per function call). Which 
observable drawbacks do you expect from not visiting the implicit parts of the 
initializer?

https://github.com/llvm/llvm-project/pull/1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -2177,7 +2177,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-Visit(OVE->getSourceExpr());
+if (const Expr *SE = OVE->getSourceExpr())

bolshakov-a wrote:

Makes sense, thanks! Moreover, I've really found a couple of bugs when some 
expressions referred by `OpaqueValueExpr` are handled more than once (#1 
and #88898). Regarding `BinaryConditionalOperator`, I've decided to refactor it 
[in a separate PR](https://github.com/llvm/llvm-project/pull/88910) and then to 
introduce the `isUnique()` check in this PR, hoping that there will be no more 
regressions.

https://github.com/llvm/llvm-project/pull/85837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage][NFC] Avoid visiting non-unique `OpaqueValueExpr` (PR #88910)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a created 
https://github.com/llvm/llvm-project/pull/88910

Only unique `OpaqueValueExpr`s should be handled in the mapping builder, as 
[discussed](https://github.com/llvm/llvm-project/pull/85837#discussion_r1542056451)
 in #85837. However, `getCond()` returns non-unique `OpaqueValueExpr` for 
`BinaryConditionalOperator` (because it is also used as the "true" branch 
expression). Use `getCommon()` instead so as to bypass the `OpaqueValueExpr`.

@efriedma-quic 

>From da7a72d3a9918f83e112a55f7ce60da5f015c56c Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 16 Apr 2024 18:13:49 +0300
Subject: [PATCH] [Coverage][NFC] Avoid visiting non-unique `OpaqueValueExpr`

Only unique `OpaqueValueExpr`s should be handled in the mapping
builder, as discussed in #85837. However, `getCond()` returns
non-unique `OpaqueValueExpr` for `BinaryConditionalOperator` (because
it is also used as the "true" branch expression). Use `getCommon()`
instead so as to bypass the `OpaqueValueExpr`.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d0..64c39c5de351c7 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2011,11 +2011,13 @@ struct CounterCoverageMappingBuilder
 Counter TrueCount = llvm::EnableSingleByteCoverage
 ? getRegionCounter(E->getTrueExpr())
 : getRegionCounter(E);
-
-propagateCounts(ParentCount, E->getCond());
 Counter OutCount;
 
-if (!isa(E)) {
+if (const auto *BCO = dyn_cast(E)) {
+  propagateCounts(ParentCount, BCO->getCommon());
+  OutCount = TrueCount;
+} else {
+  propagateCounts(ParentCount, E->getCond());
   // The 'then' count applies to the area immediately after the condition.
   auto Gap =
   findGapAreaBetween(E->getQuestionLoc(), getStart(E->getTrueExpr()));
@@ -2024,8 +2026,6 @@ struct CounterCoverageMappingBuilder
 
   extendRegion(E->getTrueExpr());
   OutCount = propagateCounts(TrueCount, E->getTrueExpr());
-} else {
-  OutCount = TrueCount;
 }
 
 extendRegion(E->getFalseExpr());

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


[clang] [Coverage] Handle `CoroutineSuspendExpr` correctly (PR #88898)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a created 
https://github.com/llvm/llvm-project/pull/88898

This avoids visiting `co_await` or `co_yield` operand 5 times (it is repeated 
under transformed awaiter subexpression, and under `await_ready`, 
`await_suspend`, and `await_resume` generated call subexpressions).

@efriedma-quic, @lxfind 

>From aa96d89ff52c1082d97a39767eb32a78654c0bff Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 16 Apr 2024 16:14:04 +0300
Subject: [PATCH] [Coverage] Handle `CoroutineSuspendExpr` correctly

This avoids visiting `co_await` or `co_yield` operand 5 times (it is
repeated under transformed awaiter subexpression, and under
`await_ready`, `await_suspend`, and `await_resume` generated call
subexpressions).
---
 clang/lib/CodeGen/CoverageMappingGen.cpp |  4 
 clang/test/CoverageMapping/coroutine.cpp | 19 +++
 2 files changed, 23 insertions(+)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d0..51556729d550ab 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1437,6 +1437,10 @@ struct CounterCoverageMappingBuilder
 terminateRegion(S);
   }
 
+  void VisitCoroutineSuspendExpr(const CoroutineSuspendExpr *E) {
+Visit(E->getOperand());
+  }
+
   void VisitCXXThrowExpr(const CXXThrowExpr *E) {
 extendRegion(E);
 if (E->getSubExpr())
diff --git a/clang/test/CoverageMapping/coroutine.cpp 
b/clang/test/CoverageMapping/coroutine.cpp
index 0105005d198a1c..d322bc351a7276 100644
--- a/clang/test/CoverageMapping/coroutine.cpp
+++ b/clang/test/CoverageMapping/coroutine.cpp
@@ -32,6 +32,7 @@ struct std::coroutine_traits {
 suspend_always final_suspend() noexcept;
 void unhandled_exception() noexcept;
 void return_value(int);
+suspend_always yield_value(int);
   };
 };
 
@@ -45,3 +46,21 @@ int f1(int x) {   // CHECK-NEXT: File 0, [[@LINE]]:15 -> 
[[@LINE+8]]:2 = #0
   }   // CHECK-NEXT: File 0, [[@LINE-2]]:10 -> [[@LINE]]:4 = 
(#0 - #1)
   co_return x;// CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE]]:3 
= #1
 } // CHECK-NEXT: File 0, [[@LINE-1]]:3 -> [[@LINE-1]]:14 = #1
+
+// CHECK-LABEL: _Z2f2i:
+// CHECK-NEXT: File 0, [[@LINE+1]]:15 -> [[@LINE+15]]:2 = #0
+int f2(int x) {
+// CHECK-NEXT: File 0, [[@LINE+5]]:13 -> [[@LINE+5]]:18 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE+4]]:13 -> [[@LINE+4]]:18 = #1, (#0 - #1)
+// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:20 -> [[@LINE+3]]:21 = #1
+// CHECK-NEXT: File 0, [[@LINE+2]]:21 -> [[@LINE+2]]:37 = #1
+// CHECK-NEXT: File 0, [[@LINE+1]]:40 -> [[@LINE+1]]:56 = (#0 - #1)
+  co_await (x > 0 ? suspend_always{} : suspend_always{});
+// CHECK-NEXT: File 0, [[@LINE+5]]:12 -> [[@LINE+5]]:17 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE+4]]:12 -> [[@LINE+4]]:17 = #2, (#0 - #2)
+// CHECK-NEXT: Gap,File 0, [[@LINE+3]]:19 -> [[@LINE+3]]:20 = #2
+// CHECK-NEXT: File 0, [[@LINE+2]]:20 -> [[@LINE+2]]:21 = #2
+// CHECK-NEXT: File 0, [[@LINE+1]]:24 -> [[@LINE+1]]:25 = (#0 - #2)
+  co_yield x > 0 ? 1 : 2;
+  co_return 0;
+}

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


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a edited 
https://github.com/llvm/llvm-project/pull/1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Handle array decomposition correctly (PR #88881)

2024-04-16 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a created 
https://github.com/llvm/llvm-project/pull/1

`ArrayInitLoopExpr` AST node has two occurences of its as-written initializing 
expression in its subexpressions through a non-unique `OpaqueValueExpr`. It 
causes double-visiting of the initializing expression if not handled 
explicitly, as discussed in #85837.

@efriedma-quic 

>From a025b2a45c2a66595c111262dd43c0890f0d54b6 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 16 Apr 2024 14:21:40 +0300
Subject: [PATCH] [Coverage] Handle array decomposition correctly

`ArrayInitLoopExpr` AST node has two occurences of its as-written
initializing expression in its subexpressions through a non-unique
`OpaqueValueExpr`. It causes double-visiting of the initializing
expression if not handled explicitly, as discussed in #85837.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp |  4 
 clang/test/CoverageMapping/decomposition.cpp | 15 +++
 2 files changed, 19 insertions(+)
 create mode 100644 clang/test/CoverageMapping/decomposition.cpp

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d0..569fd489dc8baa 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2171,6 +2171,10 @@ struct CounterCoverageMappingBuilder
 // propagate counts into them.
   }
 
+  void VisitArrayInitLoopExpr(const ArrayInitLoopExpr *AILE) {
+Visit(AILE->getCommonExpr()->getSourceExpr());
+  }
+
   void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
 // Just visit syntatic expression as this is what users actually write.
 VisitStmt(POE->getSyntacticForm());
diff --git a/clang/test/CoverageMapping/decomposition.cpp 
b/clang/test/CoverageMapping/decomposition.cpp
new file mode 100644
index 00..31bd6cae2c4dec
--- /dev/null
+++ b/clang/test/CoverageMapping/decomposition.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only %s | FileCheck %s
+
+// CHECK-LABEL:   _Z19array_decompositioni:
+// CHECK-NEXT:  File 0, [[@LINE+6]]:32 -> {{[0-9]+}}:2 = #0
+// CHECK-NEXT:  File 0, [[@LINE+8]]:20 -> [[@LINE+8]]:25 = #0
+// CHECK-NEXT:  Branch,File 0, [[@LINE+7]]:20 -> [[@LINE+7]]:25 = #1, 
(#0 - #1)
+// CHECK-NEXT:  Gap,File 0, [[@LINE+6]]:27 -> [[@LINE+6]]:28 = #1
+// CHECK-NEXT:  File 0, [[@LINE+5]]:28 -> [[@LINE+5]]:29 = #1
+// CHECK-NEXT:  File 0, [[@LINE+4]]:32 -> [[@LINE+4]]:33 = (#0 - #1)
+int array_decomposition(int i) {
+  int a[] = {1, 2, 3};
+  int b[] = {4, 5, 6};
+  auto [x, y, z] = i > 0 ? a : b;
+  return x + y + z;
+}

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


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-04-09 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a edited 
https://github.com/llvm/llvm-project/pull/85837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-04-09 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -2177,7 +2177,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-Visit(OVE->getSourceExpr());
+if (const Expr *SE = OVE->getSourceExpr())

bolshakov-a wrote:

> If I'm following correctly, you end up visiting the condition twice

No, the "true" branch visitation (`propagateCounts`) is performed only when it 
is the ordinary `ConditionalOperator` 
(https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CoverageMappingGen.cpp#L2018).

Do you think it should be rewritten first? It's just the first case found by me 
where a non-unique OVE has a source expression which is visited. There may be 
more cases.

https://github.com/llvm/llvm-project/pull/85837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-04-08 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@erichkeane, @cor3ntin, @Endilll, @efriedma-quic ping.

https://github.com/llvm/llvm-project/pull/85837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-03-28 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -2177,7 +2177,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-Visit(OVE->getSourceExpr());
+if (const Expr *SE = OVE->getSourceExpr())

bolshakov-a wrote:

Not all `OpaqueValueExpr`s having a source expression are marked as "unique". 
Checking `isUnique()` instead of `getSourceExpr()` breaks at least handling of 
the GNU extension of the `?:` operator:
```
1|  1|int main() {
2|  1|int i = 1;
3|  1|return (i ? 1 : 0)
  ^0<-- disappears if isUnique() is used
  --
  |  Branch (3:12): [True: 1, False: 0]
  |  Branch (3:13): [True: 1, False: 0] <-- disappears if isUnique() is used
  --
4|  1|?: 10;
 ^0
5|  1|}
```

https://github.com/llvm/llvm-project/pull/85837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][c++20] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-03-19 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a edited 
https://github.com/llvm/llvm-project/pull/85837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-03-19 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/85837

>From 398ad87c1e9669223def3561f4cdd72af11857c3 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 19 Mar 2024 19:05:36 +0300
Subject: [PATCH] [clang][c++20] Fix code coverage mapping crash with
 generalized NTTPs

Introduced in #78041, originally reported as #79957 and fixed partially
in #80050.

`OpaqueValueExpr` used with `TemplateArgument::StructuralValue` has no
corresponding source expression.

A test case with subobject-referring NTTP added.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 3 ++-
 clang/test/CoverageMapping/templates.cpp | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d0..3a87f935470673 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2177,7 +2177,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-Visit(OVE->getSourceExpr());
+if (const Expr *SE = OVE->getSourceExpr())
+  Visit(SE);
   }
 };
 
diff --git a/clang/test/CoverageMapping/templates.cpp 
b/clang/test/CoverageMapping/templates.cpp
index 143e566a33cb85..7e7f2208f1145f 100644
--- a/clang/test/CoverageMapping/templates.cpp
+++ b/clang/test/CoverageMapping/templates.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
 
 template
 void unused(T x) {
@@ -30,5 +30,6 @@ namespace structural_value_crash {
 
   void test() {
 tpl_fn();
+tpl_fn<&arr[1]>();
   }
 }

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


[clang] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-03-19 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s

bolshakov-a wrote:

Maybe, separate launch mode should be added instead of changing existing one? 
OTOH, it was irrelevant to any specific C++ standard.

https://github.com/llvm/llvm-project/pull/85837
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix code coverage mapping crash with generalized NTTPs (PR #85837)

2024-03-19 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a created 
https://github.com/llvm/llvm-project/pull/85837

Introduced in #78041, originally reported as #79957 and fixed partially in 
#80050.

`OpaqueValueExpr` used with `TemplateArgument::StructuralValue` has no 
corresponding source expression.

A test case with subobject-referring NTTP added.

@erichkeane, @cor3ntin, @Endilll

>From ec923eedb0b43050e7ce5e6648711a12adb1cebe Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 19 Mar 2024 19:05:36 +0300
Subject: [PATCH] Fix code coverage mapping crash with generalized NTTPs

Introduced in #78041, originally reported as #79957 and fixed partially
in #80050.

`OpaqueValueExpr` used with `TemplateArgument::StructuralValue` has no
corresponding source expression.

A test case with subobject-referring NTTP added.
---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 3 ++-
 clang/test/CoverageMapping/templates.cpp | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 71215da362d3d0..3a87f935470673 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2177,7 +2177,8 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitOpaqueValueExpr(const OpaqueValueExpr* OVE) {
-Visit(OVE->getSourceExpr());
+if (const Expr *SE = OVE->getSourceExpr())
+  Visit(SE);
   }
 };
 
diff --git a/clang/test/CoverageMapping/templates.cpp 
b/clang/test/CoverageMapping/templates.cpp
index 143e566a33cb85..7e7f2208f1145f 100644
--- a/clang/test/CoverageMapping/templates.cpp
+++ b/clang/test/CoverageMapping/templates.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++20 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -main-file-name templates.cpp %s | FileCheck %s
 
 template
 void unused(T x) {
@@ -30,5 +30,6 @@ namespace structural_value_crash {
 
   void test() {
 tpl_fn();
+tpl_fn<&arr[1]>();
   }
 }

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


[clang] [clang-tools-extra] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-02-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -5401,6 +5409,8 @@ std::string CGDebugInfo::GetName(const Decl *D, bool 
Qualified) const {
 // feasible some day.
 return TA.getAsIntegral().getBitWidth() <= 64 &&
IsReconstitutableType(TA.getIntegralType());
+  case TemplateArgument::StructuralValue:
+return false;

bolshakov-a wrote:

Thanks for clarifying! Probably, I'll come back to this some day to extend the 
backend, but I'm not sure.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Represent array refs as `TemplateArgument::Declaration` (PR #80050)

2024-01-31 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> Please do!

#80150. I don't know, maybe, some more actions should be done. I cannot add 
"release:backport" label, at least.

https://github.com/llvm/llvm-project/pull/80050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Represent array refs as `TemplateArgument::Declaration` (PR #80050)

2024-01-31 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Thanks! Should I open an issue to backport this to RC?

https://github.com/llvm/llvm-project/pull/80050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Represent array refs as `TemplateArgument::Declaration` (PR #80050)

2024-01-31 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@cor3ntin, @erichkeane, could you merge it please?

https://github.com/llvm/llvm-project/pull/80050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Represent array refs as `TemplateArgument::Declaration` (PR #80050)

2024-01-31 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> what a proper fix would look like

Probably, some more `OpaqueValueExpr` handlers should be rewritten correctly.

https://github.com/llvm/llvm-project/pull/80050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Represent array refs as `TemplateArgument::Declaration` (PR #80050)

2024-01-31 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

I think the problem is that the generalized NTTP feature is still raw. It 
should not break already working features, namely array reference NTTPs, hence 
they are swithed back to the old `TemplateArgument::Declaration`, as they 
worked prior to #78041, from the new `StructuralValue`.

https://github.com/llvm/llvm-project/pull/80050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Represent array refs as `TemplateArgument::Declaration` (PR #80050)

2024-01-31 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@jeremiahar, thanks for reporting! Added a coverage mapping test case.

https://github.com/llvm/llvm-project/pull/80050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Represent array refs as `TemplateArgument::Declaration` (PR #80050)

2024-01-31 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/80050

>From ae4b26cbd22a52a932464dfe5c529b296bbf96dd Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 30 Jan 2024 21:33:34 +0300
Subject: [PATCH] [clang] Represent array refs as
 `TemplateArgument::Declaration`

This returns (probably temporarily) array-referring NTTP behavior
to which was prior to #78041 to avoid regressions.
---
 clang/lib/Sema/SemaTemplate.cpp  | 44 +---
 clang/test/CoverageMapping/templates.cpp | 13 +++
 2 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 3f33ecb89502e..9e8d058041f04 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -7417,9 +7417,9 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
 if (ArgResult.isInvalid())
   return ExprError();
 
-// Prior to C++20, enforce restrictions on possible template argument
-// values.
-if (!getLangOpts().CPlusPlus20 && Value.isLValue()) {
+if (Value.isLValue()) {
+  APValue::LValueBase Base = Value.getLValueBase();
+  auto *VD = const_cast(Base.dyn_cast());
   //   For a non-type template-parameter of pointer or reference type,
   //   the value of the constant expression shall not refer to
   assert(ParamType->isPointerType() || ParamType->isReferenceType() ||
@@ -7428,8 +7428,6 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
   // -- a string literal
   // -- the result of a typeid expression, or
   // -- a predefined __func__ variable
-  APValue::LValueBase Base = Value.getLValueBase();
-  auto *VD = const_cast(Base.dyn_cast());
   if (Base &&
   (!VD ||
isa(VD))) 
{
@@ -7437,24 +7435,30 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
 << Arg->getSourceRange();
 return ExprError();
   }
-  // -- a subobject [until C++20]
-  if (Value.hasLValuePath() && Value.getLValuePath().size() == 1 &&
-  VD && VD->getType()->isArrayType() &&
+
+  if (Value.hasLValuePath() && Value.getLValuePath().size() == 1 && VD &&
+  VD->getType()->isArrayType() &&
   Value.getLValuePath()[0].getAsArrayIndex() == 0 &&
   !Value.isLValueOnePastTheEnd() && ParamType->isPointerType()) {
-// Per defect report (no number yet):
-//   ... other than a pointer to the first element of a complete array
-//   object.
-  } else if (!Value.hasLValuePath() || Value.getLValuePath().size() ||
- Value.isLValueOnePastTheEnd()) {
-Diag(StartLoc, diag::err_non_type_template_arg_subobject)
-  << Value.getAsString(Context, ParamType);
-return ExprError();
+SugaredConverted = TemplateArgument(VD, ParamType);
+CanonicalConverted = TemplateArgument(
+cast(VD->getCanonicalDecl()), CanonParamType);
+return ArgResult.get();
+  }
+
+  // -- a subobject [until C++20]
+  if (!getLangOpts().CPlusPlus20) {
+if (!Value.hasLValuePath() || Value.getLValuePath().size() ||
+Value.isLValueOnePastTheEnd()) {
+  Diag(StartLoc, diag::err_non_type_template_arg_subobject)
+  << Value.getAsString(Context, ParamType);
+  return ExprError();
+}
+assert((VD || !ParamType->isReferenceType()) &&
+   "null reference should not be a constant expression");
+assert((!VD || !ParamType->isNullPtrType()) &&
+   "non-null value of type nullptr_t?");
   }
-  assert((VD || !ParamType->isReferenceType()) &&
- "null reference should not be a constant expression");
-  assert((!VD || !ParamType->isNullPtrType()) &&
- "non-null value of type nullptr_t?");
 }
 
 if (Value.isAddrLabelDiff())
diff --git a/clang/test/CoverageMapping/templates.cpp 
b/clang/test/CoverageMapping/templates.cpp
index 7010edbc32c34..143e566a33cb8 100644
--- a/clang/test/CoverageMapping/templates.cpp
+++ b/clang/test/CoverageMapping/templates.cpp
@@ -19,3 +19,16 @@ int main() {
   func(true);
   return 0;
 }
+
+namespace structural_value_crash {
+  template 
+  void tpl_fn() {
+(void)p;
+  }
+
+  int arr[] = {1, 2, 3};
+
+  void test() {
+tpl_fn();
+  }
+}

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


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-30 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

#80050 opened. Nevertheless, a reproducer for future work would be appreciated.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Represent array refs as `TemplateArgument::Declaration` (PR #80050)

2024-01-30 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@erichkeane, @cor3ntin

https://github.com/llvm/llvm-project/pull/80050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Represent array refs as `TemplateArgument::Declaration` (PR #80050)

2024-01-30 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a created 
https://github.com/llvm/llvm-project/pull/80050

This returns (probably temporarily) array-referring NTTP behavior to which was 
prior to #78041 because ~~I'm fed up~~ have no time to fix regressions.

>From 0ccf1c9eeec7641dfdca9f8a06499512f98ba6da Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Tue, 30 Jan 2024 21:33:34 +0300
Subject: [PATCH] [clang] Represent array refs as
 `TemplateArgument::Declaration`

This returns (probably temporarily) array-referring NTTP behavior
to which was prior to #78041 to avoid regressions.
---
 clang/lib/Sema/SemaTemplate.cpp | 44 ++---
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 3f33ecb89502e..9e8d058041f04 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -7417,9 +7417,9 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
 if (ArgResult.isInvalid())
   return ExprError();
 
-// Prior to C++20, enforce restrictions on possible template argument
-// values.
-if (!getLangOpts().CPlusPlus20 && Value.isLValue()) {
+if (Value.isLValue()) {
+  APValue::LValueBase Base = Value.getLValueBase();
+  auto *VD = const_cast(Base.dyn_cast());
   //   For a non-type template-parameter of pointer or reference type,
   //   the value of the constant expression shall not refer to
   assert(ParamType->isPointerType() || ParamType->isReferenceType() ||
@@ -7428,8 +7428,6 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
   // -- a string literal
   // -- the result of a typeid expression, or
   // -- a predefined __func__ variable
-  APValue::LValueBase Base = Value.getLValueBase();
-  auto *VD = const_cast(Base.dyn_cast());
   if (Base &&
   (!VD ||
isa(VD))) 
{
@@ -7437,24 +7435,30 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
 << Arg->getSourceRange();
 return ExprError();
   }
-  // -- a subobject [until C++20]
-  if (Value.hasLValuePath() && Value.getLValuePath().size() == 1 &&
-  VD && VD->getType()->isArrayType() &&
+
+  if (Value.hasLValuePath() && Value.getLValuePath().size() == 1 && VD &&
+  VD->getType()->isArrayType() &&
   Value.getLValuePath()[0].getAsArrayIndex() == 0 &&
   !Value.isLValueOnePastTheEnd() && ParamType->isPointerType()) {
-// Per defect report (no number yet):
-//   ... other than a pointer to the first element of a complete array
-//   object.
-  } else if (!Value.hasLValuePath() || Value.getLValuePath().size() ||
- Value.isLValueOnePastTheEnd()) {
-Diag(StartLoc, diag::err_non_type_template_arg_subobject)
-  << Value.getAsString(Context, ParamType);
-return ExprError();
+SugaredConverted = TemplateArgument(VD, ParamType);
+CanonicalConverted = TemplateArgument(
+cast(VD->getCanonicalDecl()), CanonParamType);
+return ArgResult.get();
+  }
+
+  // -- a subobject [until C++20]
+  if (!getLangOpts().CPlusPlus20) {
+if (!Value.hasLValuePath() || Value.getLValuePath().size() ||
+Value.isLValueOnePastTheEnd()) {
+  Diag(StartLoc, diag::err_non_type_template_arg_subobject)
+  << Value.getAsString(Context, ParamType);
+  return ExprError();
+}
+assert((VD || !ParamType->isReferenceType()) &&
+   "null reference should not be a constant expression");
+assert((!VD || !ParamType->isNullPtrType()) &&
+   "non-null value of type nullptr_t?");
   }
-  assert((VD || !ParamType->isReferenceType()) &&
- "null reference should not be a constant expression");
-  assert((!VD || !ParamType->isNullPtrType()) &&
- "non-null value of type nullptr_t?");
 }
 
 if (Value.isAddrLabelDiff())

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


[clang-tools-extra] [clang] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-30 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@eaeltsin, could you try out [that 
branch](https://github.com/bolshakov-a/llvm-project/tree/avoid_regressions)?

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-30 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Thanks!

https://github.com/llvm/llvm-project/pull/79764
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-30 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

I'm just waiting for someone who would do it instead of me... I don't have 
commit access.

https://github.com/llvm/llvm-project/pull/79764
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-29 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/79764

>From b3debeb88fdc3d50f257be56f3e60ae7bf83cc07 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Sun, 28 Jan 2024 21:12:10 +0300
Subject: [PATCH] Fix crashes on 'StructuralValue'

`OpaqueValueExpr` doesn't necessarily contain a source expression.
Particularly, after #78041, it is used to carry the type and the value
kind of a non-type template argument of floating-point type or referring
to a subobject (those are so called `StructuralValue` arguments).

This fixes #79575.
---
 clang/lib/Sema/SemaDecl.cpp |  3 ++-
 clang/lib/StaticAnalyzer/Core/Environment.cpp   |  8 +---
 clang/test/Analysis/templates.cpp   | 13 +
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp | 17 +
 4 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e725e187fc9ea0..9bf1e9dd084331 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12753,7 +12753,8 @@ namespace {
   }
 
   if (OpaqueValueExpr *OVE = dyn_cast(E)) {
-HandleValue(OVE->getSourceExpr());
+if (Expr *SE = OVE->getSourceExpr())
+  HandleValue(SE);
 return;
   }
 
diff --git a/clang/lib/StaticAnalyzer/Core/Environment.cpp 
b/clang/lib/StaticAnalyzer/Core/Environment.cpp
index 4f989ed59bee38..427f51109853bd 100644
--- a/clang/lib/StaticAnalyzer/Core/Environment.cpp
+++ b/clang/lib/StaticAnalyzer/Core/Environment.cpp
@@ -40,8 +40,11 @@ static const Expr *ignoreTransparentExprs(const Expr *E) {
 
   switch (E->getStmtClass()) {
   case Stmt::OpaqueValueExprClass:
-E = cast(E)->getSourceExpr();
-break;
+if (const Expr *SE = cast(E)->getSourceExpr()) {
+  E = SE;
+  break;
+}
+return E;
   case Stmt::ExprWithCleanupsClass:
 E = cast(E)->getSubExpr();
 break;
@@ -98,7 +101,6 @@ SVal Environment::getSVal(const EnvironmentEntry &Entry,
   case Stmt::CXXBindTemporaryExprClass:
   case Stmt::ExprWithCleanupsClass:
   case Stmt::GenericSelectionExprClass:
-  case Stmt::OpaqueValueExprClass:
   case Stmt::ConstantExprClass:
   case Stmt::ParenExprClass:
   case Stmt::SubstNonTypeTemplateParmExprClass:
diff --git a/clang/test/Analysis/templates.cpp 
b/clang/test/Analysis/templates.cpp
index 061c19fe7e0445..6da1821b70f26f 100644
--- a/clang/test/Analysis/templates.cpp
+++ b/clang/test/Analysis/templates.cpp
@@ -68,3 +68,16 @@ namespace rdar13954714 {
   // force instantiation
   template void blockWithStatic();
 }
+
+namespace structural_value_crash {
+  constexpr char abc[] = "abc";
+
+  template 
+  void use_template_param() {
+const char *p = in;
+  }
+
+  void force_instantiate() {
+use_template_param();
+  }
+}
diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
index 834174cdf6a32d..ad73daa8e214c3 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -354,3 +354,20 @@ namespace ReportedRegression1 {
 return dummy.exit_code();
   }
 }
+
+namespace ReportedRegression2 {
+  const char str[] = "dummy";
+
+  struct S {
+S operator+(const char*) const;
+  };
+
+  template 
+  void fn() {
+auto s = S{} + in;
+  }
+
+  void use() {
+fn();
+  }
+}

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


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-29 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@zmodem, thanks! Added the fix to #79764.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-29 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/79764

>From 474f86604c35bea7041bcf3e6f8e2103d180902f Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Sun, 28 Jan 2024 21:12:10 +0300
Subject: [PATCH] Fix crashes on 'StructuralValue'

`OpaqueValueExpr` doesn't necessarily contain a source expression.
Particularly, after #78041, it is used to carry the type and the value
kind of a non-type template argument of floating-point type or referring
to a subobject (those are so called `StructuralValue` arguments).

This fixes #79575.
---
 clang/lib/Sema/SemaDecl.cpp   |  3 ++-
 clang/lib/StaticAnalyzer/Core/Environment.cpp |  8 +---
 clang/test/Analysis/templates.cpp | 13 +
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e725e187fc9ea08..9bf1e9dd084331f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -12753,7 +12753,8 @@ namespace {
   }
 
   if (OpaqueValueExpr *OVE = dyn_cast(E)) {
-HandleValue(OVE->getSourceExpr());
+if (Expr *SE = OVE->getSourceExpr())
+  HandleValue(SE);
 return;
   }
 
diff --git a/clang/lib/StaticAnalyzer/Core/Environment.cpp 
b/clang/lib/StaticAnalyzer/Core/Environment.cpp
index 4f989ed59bee38c..427f51109853bda 100644
--- a/clang/lib/StaticAnalyzer/Core/Environment.cpp
+++ b/clang/lib/StaticAnalyzer/Core/Environment.cpp
@@ -40,8 +40,11 @@ static const Expr *ignoreTransparentExprs(const Expr *E) {
 
   switch (E->getStmtClass()) {
   case Stmt::OpaqueValueExprClass:
-E = cast(E)->getSourceExpr();
-break;
+if (const Expr *SE = cast(E)->getSourceExpr()) {
+  E = SE;
+  break;
+}
+return E;
   case Stmt::ExprWithCleanupsClass:
 E = cast(E)->getSubExpr();
 break;
@@ -98,7 +101,6 @@ SVal Environment::getSVal(const EnvironmentEntry &Entry,
   case Stmt::CXXBindTemporaryExprClass:
   case Stmt::ExprWithCleanupsClass:
   case Stmt::GenericSelectionExprClass:
-  case Stmt::OpaqueValueExprClass:
   case Stmt::ConstantExprClass:
   case Stmt::ParenExprClass:
   case Stmt::SubstNonTypeTemplateParmExprClass:
diff --git a/clang/test/Analysis/templates.cpp 
b/clang/test/Analysis/templates.cpp
index 061c19fe7e04451..6da1821b70f26fa 100644
--- a/clang/test/Analysis/templates.cpp
+++ b/clang/test/Analysis/templates.cpp
@@ -68,3 +68,16 @@ namespace rdar13954714 {
   // force instantiation
   template void blockWithStatic();
 }
+
+namespace structural_value_crash {
+  constexpr char abc[] = "abc";
+
+  template 
+  void use_template_param() {
+const char *p = in;
+  }
+
+  void force_instantiate() {
+use_template_param();
+  }
+}

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


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-29 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -40,8 +40,12 @@ static const Expr *ignoreTransparentExprs(const Expr *E) {
 
   switch (E->getStmtClass()) {
   case Stmt::OpaqueValueExprClass:
-E = cast(E)->getSourceExpr();
-break;
+if (const clang::Expr *SE = cast(E)->getSourceExpr()) {
+  E = SE;
+  break;
+} else {
+  return E;
+}

bolshakov-a wrote:

Thanks! `else` doesn't make sense, indeed.

But it should be noted that `SE` refers to the result of `->getSourceExpr()` 
and not to the result of `cast(E)`, hence its type is not a 
pointer to `OpaqueValueExpr`. Doesn't LLVM policy insist on the explicit type 
in such cases? Nevertheless, `clang::` qualification is redundant.

https://github.com/llvm/llvm-project/pull/79764
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-28 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@steakhal, @cor3ntin, @erichkeane

https://github.com/llvm/llvm-project/pull/79764
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-28 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a created 
https://github.com/llvm/llvm-project/pull/79764

`OpaqueValueExpr` doesn't necessarily contain a source expression. 
Particularly, after #78041, it is used to carry the type and the value kind of 
a non-type template argument of floating-point type or referring to a subobject 
(those are so called `StructuralValue` arguments).

This fixes #79575.

>From 2a0a46f9242e99a18670d38f638a649fe808e4dc Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Sun, 28 Jan 2024 21:12:10 +0300
Subject: [PATCH] Fix analyzer crash on 'StructuralValue'

`OpaqueValueExpr` doesn't necessarily contain a source expression.
Particularly, after #78041, it is used to carry the type and the value
kind of a non-type template argument of floating-point type or referring
to a subobject (those are so called `StructuralValue` arguments).

This fixes #79575.
---
 clang/lib/StaticAnalyzer/Core/Environment.cpp |  9 ++---
 clang/test/Analysis/templates.cpp | 13 +
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/Environment.cpp 
b/clang/lib/StaticAnalyzer/Core/Environment.cpp
index 4f989ed59bee38c..c77b28bc48fd674 100644
--- a/clang/lib/StaticAnalyzer/Core/Environment.cpp
+++ b/clang/lib/StaticAnalyzer/Core/Environment.cpp
@@ -40,8 +40,12 @@ static const Expr *ignoreTransparentExprs(const Expr *E) {
 
   switch (E->getStmtClass()) {
   case Stmt::OpaqueValueExprClass:
-E = cast(E)->getSourceExpr();
-break;
+if (const clang::Expr *SE = cast(E)->getSourceExpr()) {
+  E = SE;
+  break;
+} else {
+  return E;
+}
   case Stmt::ExprWithCleanupsClass:
 E = cast(E)->getSubExpr();
 break;
@@ -98,7 +102,6 @@ SVal Environment::getSVal(const EnvironmentEntry &Entry,
   case Stmt::CXXBindTemporaryExprClass:
   case Stmt::ExprWithCleanupsClass:
   case Stmt::GenericSelectionExprClass:
-  case Stmt::OpaqueValueExprClass:
   case Stmt::ConstantExprClass:
   case Stmt::ParenExprClass:
   case Stmt::SubstNonTypeTemplateParmExprClass:
diff --git a/clang/test/Analysis/templates.cpp 
b/clang/test/Analysis/templates.cpp
index 061c19fe7e04451..6da1821b70f26fa 100644
--- a/clang/test/Analysis/templates.cpp
+++ b/clang/test/Analysis/templates.cpp
@@ -68,3 +68,16 @@ namespace rdar13954714 {
   // force instantiation
   template void blockWithStatic();
 }
+
+namespace structural_value_crash {
+  constexpr char abc[] = "abc";
+
+  template 
+  void use_template_param() {
+const char *p = in;
+  }
+
+  void force_instantiate() {
+use_template_param();
+  }
+}

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


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-26 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -8129,29 +8067,133 @@ 
Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
 else
   Kind = CharacterLiteralKind::Ascii;
 
-E = new (Context) CharacterLiteral(Arg.getAsIntegral().getZExtValue(),
-   Kind, T, Loc);
+E = new (S.Context) CharacterLiteral(Int.getZExtValue(), Kind, T, Loc);
   } else if (T->isBooleanType()) {
-E = CXXBoolLiteralExpr::Create(Context, Arg.getAsIntegral().getBoolValue(),
-   T, Loc);
-  } else if (T->isNullPtrType()) {
-E = new (Context) CXXNullPtrLiteralExpr(Context.NullPtrTy, Loc);
+E = CXXBoolLiteralExpr::Create(S.Context, Int.getBoolValue(), T, Loc);
   } else {
-E = IntegerLiteral::Create(Context, Arg.getAsIntegral(), T, Loc);
+E = IntegerLiteral::Create(S.Context, Int, T, Loc);
   }
 
   if (OrigT->isEnumeralType()) {
 // FIXME: This is a hack. We need a better way to handle substituted
 // non-type template parameters.
-E = CStyleCastExpr::Create(Context, OrigT, VK_PRValue, CK_IntegralCast, E,
-   nullptr, CurFPFeatureOverrides(),
-   Context.getTrivialTypeSourceInfo(OrigT, Loc),
+E = CStyleCastExpr::Create(S.Context, OrigT, VK_PRValue, CK_IntegralCast, 
E,
+   nullptr, S.CurFPFeatureOverrides(),
+   S.Context.getTrivialTypeSourceInfo(OrigT, Loc),
Loc, Loc);
   }
 
   return E;
 }
 
+static Expr *BuildExpressionFromNonTypeTemplateArgumentValue(
+Sema &S, QualType T, const APValue &Val, SourceLocation Loc) {
+  auto MakeInitList = [&](ArrayRef Elts) -> Expr * {
+auto *ILE = new (S.Context) InitListExpr(S.Context, Loc, Elts, Loc);
+ILE->setType(T);
+return ILE;
+  };
+
+  switch (Val.getKind()) {
+  case APValue::AddrLabelDiff:
+// This cannot occur in a template argument at all.
+  case APValue::Array:
+  case APValue::Struct:
+  case APValue::Union:
+// These can only occur within a template parameter object, which is
+// represented as a TemplateArgument::Declaration.
+llvm_unreachable("unexpected template argument value");
+
+  case APValue::Int:
+return BuildExpressionFromIntegralTemplateArgumentValue(S, T, Val.getInt(),
+Loc);
+
+  case APValue::Float:
+return FloatingLiteral::Create(S.Context, Val.getFloat(), /*IsExact=*/true,
+   T, Loc);
+
+  case APValue::FixedPoint:
+return FixedPointLiteral::CreateFromRawInt(
+S.Context, Val.getFixedPoint().getValue(), T, Loc,
+Val.getFixedPoint().getScale());
+
+  case APValue::ComplexInt: {
+QualType ElemT = T->castAs()->getElementType();
+return MakeInitList({BuildExpressionFromIntegralTemplateArgumentValue(
+ S, ElemT, Val.getComplexIntReal(), Loc),
+ BuildExpressionFromIntegralTemplateArgumentValue(
+ S, ElemT, Val.getComplexIntImag(), Loc)});
+  }
+
+  case APValue::ComplexFloat: {
+QualType ElemT = T->castAs()->getElementType();
+return MakeInitList(
+{FloatingLiteral::Create(S.Context, Val.getComplexFloatReal(), true,
+ ElemT, Loc),
+ FloatingLiteral::Create(S.Context, Val.getComplexFloatImag(), true,
+ ElemT, Loc)});
+  }
+
+  case APValue::Vector: {
+QualType ElemT = T->castAs()->getElementType();
+llvm::SmallVector Elts;
+for (unsigned I = 0, N = Val.getVectorLength(); I != N; ++I)
+  Elts.push_back(BuildExpressionFromNonTypeTemplateArgumentValue(
+  S, ElemT, Val.getVectorElt(I), Loc));
+return MakeInitList(Elts);
+  }
+
+  case APValue::None:
+  case APValue::Indeterminate:
+llvm_unreachable("Unexpected APValue kind.");
+  case APValue::LValue:
+  case APValue::MemberPointer:
+// There isn't necessarily a valid equivalent source-level syntax for
+// these; in particular, a naive lowering might violate access control.
+// So for now we lower to a ConstantExpr holding the value, wrapped around
+// an OpaqueValueExpr.
+// FIXME: We should have a better representation for this.
+ExprValueKind VK = VK_PRValue;
+if (T->isReferenceType()) {
+  T = T->getPointeeType();
+  VK = VK_LValue;
+}
+auto *OVE = new (S.Context) OpaqueValueExpr(Loc, T, VK);

bolshakov-a wrote:

Right, I didn't. But the clang codebase is pretty well designed if every class 
can be considered as fully initialized after calling its constructor!

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-26 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -8129,29 +8067,133 @@ 
Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
 else
   Kind = CharacterLiteralKind::Ascii;
 
-E = new (Context) CharacterLiteral(Arg.getAsIntegral().getZExtValue(),
-   Kind, T, Loc);
+E = new (S.Context) CharacterLiteral(Int.getZExtValue(), Kind, T, Loc);
   } else if (T->isBooleanType()) {
-E = CXXBoolLiteralExpr::Create(Context, Arg.getAsIntegral().getBoolValue(),
-   T, Loc);
-  } else if (T->isNullPtrType()) {
-E = new (Context) CXXNullPtrLiteralExpr(Context.NullPtrTy, Loc);
+E = CXXBoolLiteralExpr::Create(S.Context, Int.getBoolValue(), T, Loc);
   } else {
-E = IntegerLiteral::Create(Context, Arg.getAsIntegral(), T, Loc);
+E = IntegerLiteral::Create(S.Context, Int, T, Loc);
   }
 
   if (OrigT->isEnumeralType()) {
 // FIXME: This is a hack. We need a better way to handle substituted
 // non-type template parameters.
-E = CStyleCastExpr::Create(Context, OrigT, VK_PRValue, CK_IntegralCast, E,
-   nullptr, CurFPFeatureOverrides(),
-   Context.getTrivialTypeSourceInfo(OrigT, Loc),
+E = CStyleCastExpr::Create(S.Context, OrigT, VK_PRValue, CK_IntegralCast, 
E,
+   nullptr, S.CurFPFeatureOverrides(),
+   S.Context.getTrivialTypeSourceInfo(OrigT, Loc),
Loc, Loc);
   }
 
   return E;
 }
 
+static Expr *BuildExpressionFromNonTypeTemplateArgumentValue(
+Sema &S, QualType T, const APValue &Val, SourceLocation Loc) {
+  auto MakeInitList = [&](ArrayRef Elts) -> Expr * {
+auto *ILE = new (S.Context) InitListExpr(S.Context, Loc, Elts, Loc);
+ILE->setType(T);
+return ILE;
+  };
+
+  switch (Val.getKind()) {
+  case APValue::AddrLabelDiff:
+// This cannot occur in a template argument at all.
+  case APValue::Array:
+  case APValue::Struct:
+  case APValue::Union:
+// These can only occur within a template parameter object, which is
+// represented as a TemplateArgument::Declaration.
+llvm_unreachable("unexpected template argument value");
+
+  case APValue::Int:
+return BuildExpressionFromIntegralTemplateArgumentValue(S, T, Val.getInt(),
+Loc);
+
+  case APValue::Float:
+return FloatingLiteral::Create(S.Context, Val.getFloat(), /*IsExact=*/true,
+   T, Loc);
+
+  case APValue::FixedPoint:
+return FixedPointLiteral::CreateFromRawInt(
+S.Context, Val.getFixedPoint().getValue(), T, Loc,
+Val.getFixedPoint().getScale());
+
+  case APValue::ComplexInt: {
+QualType ElemT = T->castAs()->getElementType();
+return MakeInitList({BuildExpressionFromIntegralTemplateArgumentValue(
+ S, ElemT, Val.getComplexIntReal(), Loc),
+ BuildExpressionFromIntegralTemplateArgumentValue(
+ S, ElemT, Val.getComplexIntImag(), Loc)});
+  }
+
+  case APValue::ComplexFloat: {
+QualType ElemT = T->castAs()->getElementType();
+return MakeInitList(
+{FloatingLiteral::Create(S.Context, Val.getComplexFloatReal(), true,
+ ElemT, Loc),
+ FloatingLiteral::Create(S.Context, Val.getComplexFloatImag(), true,
+ ElemT, Loc)});
+  }
+
+  case APValue::Vector: {
+QualType ElemT = T->castAs()->getElementType();
+llvm::SmallVector Elts;
+for (unsigned I = 0, N = Val.getVectorLength(); I != N; ++I)
+  Elts.push_back(BuildExpressionFromNonTypeTemplateArgumentValue(
+  S, ElemT, Val.getVectorElt(I), Loc));
+return MakeInitList(Elts);
+  }
+
+  case APValue::None:
+  case APValue::Indeterminate:
+llvm_unreachable("Unexpected APValue kind.");
+  case APValue::LValue:
+  case APValue::MemberPointer:
+// There isn't necessarily a valid equivalent source-level syntax for
+// these; in particular, a naive lowering might violate access control.
+// So for now we lower to a ConstantExpr holding the value, wrapped around
+// an OpaqueValueExpr.
+// FIXME: We should have a better representation for this.
+ExprValueKind VK = VK_PRValue;
+if (T->isReferenceType()) {
+  T = T->getPointeeType();
+  VK = VK_LValue;
+}
+auto *OVE = new (S.Context) OpaqueValueExpr(Loc, T, VK);

bolshakov-a wrote:

I agree. (It _becomes_ wrong after this PR)

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-26 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Prior to this PR, arrays in NTTP were represented as `Declaration`s and now as 
`StructuralValue`s referring to their first element. @steakhal, please note 
[here](https://github.com/llvm/llvm-project/pull/78041/files#diff-2f25fdb80b1a63f2e0a5a7c7a7c061b494b430ee8f5759b48022a86a149030bbR8162)
 how the corresponding `OpaqueValueExpr` is constructed. The is no 
subexpression inside it. Maybe, it will help. I'll probably have a chance to 
look into it deeper after several hours or tomorrow.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

The tests are passed.
Maybe, someone else could write a test and commit? I'm slightly busy.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@erichkeane, @cor3ntin, argument types 
[here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaTemplateDeduction.cpp#L3022)
 occurs to be different with sugar added to one of them. This patch fixes the 
problem:
```
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -450,7 +450,7 @@ bool TemplateArgument::structurallyEquals(const 
TemplateArgument &Other) const {
getAsIntegral() == Other.getAsIntegral();
 
   case StructuralValue: {
-if (getStructuralValueType() != Other.getStructuralValueType())
+if (getStructuralValueType().getCanonicalType() != 
Other.getStructuralValueType().getCanonicalType())
   return false;
 
 llvm::FoldingSetNodeID A, B;
```
Not sure if it is correct. Running tests...

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

I suspect the reason is in the array-to-pointer conversion in `StructuralValue` 
argument. Maybe this will help someone to invent a fix quickly...

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-24 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Thanks! I'll probably take a look in my spare time. Feel free to revert this.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Thank you all, especially to @zygoloid for allowing me to steal its thunder!

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> Do you need me to merge that for you?

Yes, please. I don't have commit access.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/78041

>From 6cc472d5a1214e847b7f3a5dce28d6bed86121ed Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Sun, 21 Jan 2024 16:19:51 +0300
Subject: [PATCH] [c++20] P1907R1: Support for generalized non-type template
 arguments of scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith, with some
minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch
in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup
in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC
ver. 19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when
the corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates
in `warn-bool-conversion` test;
in C++17 and C++20 mode, array reference used as a template argument
of pointer type produces template argument of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  86 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   5 -
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   3 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  36 ++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  67 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  10 +
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |  10 +-
 clang/lib/Sema/SemaTemplate.cpp   | 218 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 +++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/test/CXX/drs/dr18xx.cpp |   4 +-
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/CodeGenCXX/template-arguments.cpp  | 113 +
 .../Index/USR/structural-value-tpl-arg.cpp|  23 ++
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp  |   3 +
 47

[clang] [clang-tools-extra] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-21 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/78041

>From e2fa0ec1fbb77a521b92f2a17f45879ca01cd304 Mon Sep 17 00:00:00 2001
From: Andrey Ali Khan Bolshakov 
Date: Sun, 6 Aug 2023 19:38:23 +0300
Subject: [PATCH] [c++20] P1907R1: Support for generalized non-type template
 arguments of scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith, with some
minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch
in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup
in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC
ver. 19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when
the corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates
in `warn-bool-conversion` test;
in C++17 and C++20 mode, array reference used as a template argument
of pointer type produces template argument of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  86 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   5 -
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   3 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  36 ++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  67 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  10 +
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |  10 +-
 clang/lib/Sema/SemaTemplate.cpp   | 218 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 +++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/test/CXX/drs/dr18xx.cpp |   4 +-
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/CodeGenCXX/template-arguments.cpp  | 113 +
 .../Index/USR/structural-value-tpl-arg.cpp|  23 ++
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp  

[clang] [clang-tools-extra] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-20 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/78041

>From 7abb30826263ad69d529dd6af585bf3bce40f979 Mon Sep 17 00:00:00 2001
From: Andrey Ali Khan Bolshakov 
Date: Sun, 6 Aug 2023 19:38:23 +0300
Subject: [PATCH] [c++20] P1907R1: Support for generalized non-type template
 arguments of scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith, with some
minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch
in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup
in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC
ver. 19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when
the corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates
in `warn-bool-conversion` test;
in C++17 and C++20 mode, array reference used as a template argument
of pointer type produces template argument of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  86 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   5 -
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   3 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  36 ++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  67 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  10 +
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |  10 +-
 clang/lib/Sema/SemaTemplate.cpp   | 218 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 +++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/test/CXX/drs/dr18xx.cpp |   4 +-
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/CodeGenCXX/template-arguments.cpp  | 113 +
 .../Index/USR/structural-value-tpl-arg.cpp|  23 ++
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp  

[clang] [clang-tools-extra] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-20 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/78041

>From 35e5e87d5c6f250f9f7a6cf5e5aeaebe5929f155 Mon Sep 17 00:00:00 2001
From: Andrey Ali Khan Bolshakov 
Date: Sun, 6 Aug 2023 19:38:23 +0300
Subject: [PATCH] [c++20] P1907R1: Support for generalized non-type template
 arguments of scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith, with some
minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch
in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup
in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC
ver. 19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when
the corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates
in `warn-bool-conversion` test;
in C++17 and C++20 mode, array reference used as a template argument
of pointer type produces template argument of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  86 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   5 -
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   3 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  36 ++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  67 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  10 +
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |  10 +-
 clang/lib/Sema/SemaTemplate.cpp   | 218 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 +++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/test/CXX/drs/dr18xx.cpp |   4 +-
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/CodeGenCXX/template-arguments.cpp  | 113 +
 .../Index/USR/structural-value-tpl-arg.cpp|  23 ++
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp  

[clang-tools-extra] [clang] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-20 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/78041

>From 9bef9d5dd970f1af653d5b10d0a062d96a69ad01 Mon Sep 17 00:00:00 2001
From: Andrey Ali Khan Bolshakov 
Date: Sun, 6 Aug 2023 19:38:23 +0300
Subject: [PATCH] [c++20] P1907R1: Support for generalized non-type template
 arguments of scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith, with some
minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch
in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup
in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC
ver. 19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when
the corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates
in `warn-bool-conversion` test;
in C++17 and C++20 mode, array reference used as a template argument
of pointer type produces template argument of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  86 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   5 -
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   3 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  36 ++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  67 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  10 +
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |  10 +-
 clang/lib/Sema/SemaTemplate.cpp   | 218 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 +++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/test/CXX/drs/dr18xx.cpp |   4 +-
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/CodeGenCXX/template-arguments.cpp  | 113 +
 .../Index/USR/structural-value-tpl-arg.cpp|  23 ++
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp  

[clang-tools-extra] [clang] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-20 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -6472,7 +6494,20 @@ void CXXNameMangler::mangleValueInTemplateArg(QualType 
T, const APValue &V,
   Out << "plcvPcad";
   Kind = Offset;
 } else {
-  if (!V.getLValuePath().empty() || V.isLValueOnePastTheEnd()) {
+  // Clang 11 and before mangled an array subject to array-to-pointer decay
+  // as if it were the declaration itself.
+  bool IsArrayToPointerDecayMangledAsDecl = false;
+  if (TopLevel && Ctx.getLangOpts().getClangABICompat() <=
+  LangOptions::ClangABI::Ver11) {
+QualType BType = B.getType();
+IsArrayToPointerDecayMangledAsDecl =
+BType->isArrayType() && V.getLValuePath().size() == 1 &&
+V.getLValuePath()[0].getAsArrayIndex() == 0 &&
+Ctx.hasSimilarType(T, Ctx.getDecayedType(BType));
+  }
+

bolshakov-a wrote:

This concerns ABI changes which are actually present in Clang since ver. 12. I 
think, they have been introduced 
[here](https://github.com/llvm/llvm-project/commit/6c365cd31e323d2d075573edd927e4f7fb5ec01c#diff-8a63be2ffd0742a4ce78d229b1bad68c62dd0b95e39d7f9a378bb52ad3f4a0b7R5011).
 The changes in this PR are to avoid regression. The test 
`CodeGenCXX/clang-abi-compat.cpp` fails if they are removed.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [lldb] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-20 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -4833,9 +4833,26 @@ void CXXNameMangler::mangleExpression(const Expr *E, 
unsigned Arity,
 E = cast(E)->getSubExpr();
 goto recurse;
 
-  case Expr::SubstNonTypeTemplateParmExprClass:
+  case Expr::SubstNonTypeTemplateParmExprClass: {
+// Mangle a substituted parameter the same way we mangle the template
+// argument.
+auto *SNTTPE = cast(E);
+if (auto *CE = dyn_cast(SNTTPE->getReplacement())) {
+  // Pull out the constant value and mangle it as a template argument.
+  QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
+  if (CE->hasAPValueResult())
+mangleValueInTemplateArg(ParamType, CE->getResultAsAPValue(), false,
+ /*NeedExactType=*/true);
+  else
+mangleValueInTemplateArg(ParamType, CE->getAPValueResult(), false,
+ /*NeedExactType=*/true);

bolshakov-a wrote:

> `hasAPValueResult()` is looking at the `APValueKind` bitfield while 
> `getResultAsAPValue()` is checking the `ResultKind` bitfield.

Good catch, thanks!

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -14,6 +14,11 @@
 
 #include "clang/AST/ODRHash.h"
 
+#include "clang/AST/APValue.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/CharUnits.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"

bolshakov-a wrote:

Removed.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -25,10 +25,13 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/NSAPI.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/LLVM.h"

bolshakov-a wrote:

Ok, removed.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/78041

>From 459f2c778d42fd5132bf69695537dc5f5a26b160 Mon Sep 17 00:00:00 2001
From: Andrey Ali Khan Bolshakov 
Date: Sun, 6 Aug 2023 19:38:23 +0300
Subject: [PATCH] [c++20] P1907R1: Support for generalized non-type template
 arguments of scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith, with some
minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch
in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup
in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC
ver. 19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when
the corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates
in `warn-bool-conversion` test;
in C++17 and C++20 mode, array reference used as a template argument
of pointer type produces template argument of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  86 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   5 -
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   3 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  39 +++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  67 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  10 +
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |  10 +-
 clang/lib/Sema/SemaTemplate.cpp   | 218 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 +++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/test/CXX/drs/dr18xx.cpp |   4 +-
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/CodeGenCXX/template-arguments.cpp  | 113 +
 .../Index/USR/structural-value-tpl-arg.cpp|  23 ++
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp 

[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -12,6 +12,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclVisitor.h"
+#include "clang/AST/ODRHash.h"

bolshakov-a wrote:

Just to clarify: do you insist that `#include` set added in a PR should be 
minimal for compilability?

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Btw, I have a local branch with a few distinct commits. I could temporarily 
push it to simplify review process, and then squash them before merging.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> Should we add a couple of PCH tests ?

[clang/test/Modules/odr_hash.cpp](https://github.com/llvm/llvm-project/pull/78041/files#diff-b0662120e3a8a2bf3ccd95b9e8943640816b457c00e662ebfdd648632e383314)
 should cover AST serialization/deserialization. But I could missing something, 
of course. What is your concern?

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -628,6 +628,10 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
 return IsStructurallyEquivalent(Context, Arg1.getAsExpr(),
 Arg2.getAsExpr());
 
+  case TemplateArgument::StructuralValue:
+// FIXME: Do we need to customize the comparison?

bolshakov-a wrote:

I agree that it seems like it should work. Dropped the comment.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/78041

>From b178deb9479e86d2899466c521ebfb28a08d27cb Mon Sep 17 00:00:00 2001
From: Andrey Ali Khan Bolshakov 
Date: Sun, 6 Aug 2023 19:38:23 +0300
Subject: [PATCH] [c++20] P1907R1: Support for generalized non-type template
 arguments of scalar type.

Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and
reverted because a dependency commit was reverted, then committed again
as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because
"dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was
reverted. But it doesn't seem that 5a391d38ac6c was a real dependency
for this.

This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and
18e093faf726d15f210ab4917142beec51848258 by Richard Smith, with some
minor fixes, most notably:

- `UncommonValue` renamed to `StructuralValue`

- `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and
member pointer handling branch
in `BuildExpressionFromNonTypeTemplateArgumentValue`;

- handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`;

- filling in `SugaredConverted` along with `CanonicalConverted`
parameter in `Sema::CheckTemplateArgument`;

- minor cleanup
in `TemplateInstantiator::transformNonTypeTemplateParmRef`;

- `TemplateArgument` constructors refactored;

- `ODRHash` calculation for `UncommonValue`;

- USR generation for `UncommonValue`;

- more correct MS compatibility mangling algorithm (tested on MSVC
ver. 19.35; toolset ver. 143);

- IR emitting fixed on using a subobject as a template argument when
the corresponding template parameter is used in an lvalue context;

- `noundef` attribute and opaque pointers in `template-arguments` test;

- analysis for C++17 mode is turned off for templates
in `warn-bool-conversion` test;
in C++17 and C++20 mode, array reference used as a template argument
of pointer type produces template argument of UncommonValue type, and
`BuildExpressionFromNonTypeTemplateArgumentValue` makes
`OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see
through it; despite of "These cases should not warn" comment, I'm not
sure about correct behavior; I'd expect a suggestion to replace `if` by
`if constexpr`;

- `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
---
 clang-tools-extra/clangd/DumpAST.cpp  |   1 +
 clang-tools-extra/clangd/FindTarget.cpp   |   1 +
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/ODRHash.h |   3 +
 clang/include/clang/AST/PropertiesBase.td |  14 ++
 clang/include/clang/AST/RecursiveASTVisitor.h |   2 +
 .../clang/AST/TemplateArgumentVisitor.h   |   2 +
 clang/include/clang/AST/TemplateBase.h|  86 ---
 .../clang/Basic/DiagnosticSemaKinds.td|   5 -
 clang/include/clang/Sema/Sema.h   |   4 +-
 clang/lib/AST/ASTContext.cpp  |   5 +
 clang/lib/AST/ASTImporter.cpp |  13 ++
 clang/lib/AST/ASTStructuralEquivalence.cpp|   3 +
 clang/lib/AST/Decl.cpp|   4 +
 clang/lib/AST/ItaniumMangle.cpp   |  39 +++-
 clang/lib/AST/MicrosoftMangle.cpp |  78 +--
 clang/lib/AST/ODRHash.cpp |  72 ++
 clang/lib/AST/StmtProfile.cpp |   6 +
 clang/lib/AST/TemplateBase.cpp| 113 -
 clang/lib/AST/TypeLoc.cpp |   1 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  10 +
 clang/lib/CodeGen/CGExpr.cpp  |  15 +-
 clang/lib/Index/USRGeneration.cpp |  10 +
 clang/lib/Sema/SemaLookup.cpp |   1 +
 clang/lib/Sema/SemaOverload.cpp   |  10 +-
 clang/lib/Sema/SemaTemplate.cpp   | 218 +++---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  64 +++--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  14 +-
 clang/lib/Sema/SemaTemplateVariadic.cpp   |   2 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 clang/lib/Serialization/ASTReader.cpp |   1 +
 clang/lib/Serialization/ASTWriter.cpp |   1 +
 clang/test/CXX/drs/dr18xx.cpp |   4 +-
 .../CXX/temp/temp.arg/temp.arg.nontype/p1.cpp |   4 +-
 clang/test/CodeGenCXX/mangle-ms-templates.cpp |  48 
 clang/test/CodeGenCXX/mangle-template.cpp |  40 +++-
 clang/test/CodeGenCXX/template-arguments.cpp  | 113 +
 .../Index/USR/structural-value-tpl-arg.cpp|  23 ++
 clang/test/Modules/odr_hash.cpp   | 193 +++-
 clang/test/SemaCXX/warn-bool-conversion.cpp   |   2 +
 .../SemaTemplate/temp_arg_nontype_cxx1z.cpp   |  40 ++--
 .../SemaTemplate/temp_arg_nontype_cxx20.cpp   |  40 ++--
 clang/tools/libclang/CIndex.cpp   |   5 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 clang/www/cxx_status.html |  18 +-
 lldb/include/lldb/lldb-enumerations.h |   1 +
 .../TypeSystem/Clang/TypeSystemClang.cpp 

[lldb] [clang] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a edited 
https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -14,6 +14,11 @@
 
 #include "clang/AST/ODRHash.h"
 
+#include "clang/AST/APValue.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/CharUnits.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"

bolshakov-a wrote:

Types from all of them are used inside `AddStructuralValue` function 
(`ASTContext` and `CharUnits` implicitly, as intermediate return types inside 
`D->getASTContext().getMemberPointerPathAdjustment(Value).getQuantity())` 
expression.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -12,6 +12,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclVisitor.h"
+#include "clang/AST/ODRHash.h"

bolshakov-a wrote:

`ODRHash` is used inside the newly added code. Btw, what do you mean by 
"necessary"? I think one should not rely on transitive `#include`s in general. 
(I'm just an active contributor of [the IWYU 
project](https://github.com/include-what-you-use/include-what-you-use/). 
~~Trust me!~~)

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -25,10 +25,13 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/NSAPI.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
+#include "clang/Basic/LLVM.h"

bolshakov-a wrote:

`FullExpr` is defined in `Expr.h`, `QualType` is in `Type.h`, and `LLVM.h` 
pulls `isa` function into `clang` namespace with `using llvm::isa;`. All of 
this is needed for `getConstantExprReferredType` function.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lldb] [clang-tools-extra] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -80,6 +81,13 @@ class TemplateArgument {
 /// that was provided for an integral non-type template parameter.
 Integral,
 
+/// The template argument is a non-type template argument that can't be
+/// represented by the special-case Declaration, NullPtr, or Integral
+/// forms. These values are only ever produced by constant evaluation,
+/// so cannot be dependent.
+/// TODO: merge Declaration, NullPtr and Integral into this?

bolshakov-a wrote:

Honestly, no. Not in the near future, at least.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [lldb] [clang] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@cor3ntin, #78041.

https://github.com/llvm/llvm-project/pull/77428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -5401,6 +5409,8 @@ std::string CGDebugInfo::GetName(const Decl *D, bool 
Qualified) const {
 // feasible some day.
 return TA.getAsIntegral().getBitWidth() <= 64 &&
IsReconstitutableType(TA.getIntegralType());
+  case TemplateArgument::StructuralValue:
+return false;

bolshakov-a wrote:

@dwblaikie, could you verify please? Maybe, non-type template arguments of 
floating point types are reconstitutable though?

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-13 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -25,7 +25,7 @@ template  struct S {}; // #dr1801-S
 S V; // #dr1801-S-i
 // cxx98-14-error@-1 {{non-type template argument does not refer to any 
declaration}}
 //   cxx98-14-note@#dr1801-S {{template parameter is declared here}}
-// since-cxx17-error@#dr1801-S-i {{non-type template argument refers to 
subobject '.i'}}
+// cxx17-error@#dr1801-S-i {{non-type template argument refers to subobject 
'.i'}}

bolshakov-a wrote:

I'm not sure about this. 
[Here](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1801) it 
is stated that this should be ill-formed, with a reference to 
[N4268](https://open-std.org/JTC1/SC22/WG21/docs/papers/2014/n4268.html). But 
it seems that it is not actual after P1907R1.

https://github.com/llvm/llvm-project/pull/78041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [lldb] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-09 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Seems like I should ping reviewers more actively... Ok, thanks, I'll probably 
proceed at the weekend.

https://github.com/llvm/llvm-project/pull/77428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang] [clang-tools-extra] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-09 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Have I understood correctly that I should open my own PR to proceed working on 
this?

https://github.com/llvm/llvm-project/pull/77428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2024-01-09 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

Thanks!

https://github.com/llvm/llvm-project/pull/71077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [clang-tools-extra] [clang] [Clang] [c++20] P1907R1: Support for generalized non-type template ar… (PR #77428)

2024-01-09 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

@cor3ntin, thank you! Could you please take a look and probably merge #71077? 
This depends on that PR.

https://github.com/llvm/llvm-project/pull/77428
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2024-01-09 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/71077

>From 4435d1ed5ed4785be7df35c129332359d89f132b Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Thu, 2 Nov 2023 19:20:27 +0300
Subject: [PATCH] [clang] Improve bit-field in ref NTTP diagnostic

Prior to this, attempts to bind a bit-field to an NTTP of reference type
produced an error because references to subobjects in NTTPs are
disallowed. But C++20 allows references to subobjects in NTTPs generally
(see P1907R1). Without this change, implementing P1907R1 would cause
a bug allowing bit-fields to be bound to reference template arguments.

Extracted from https://reviews.llvm.org/D140996
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticSemaKinds.td   |  2 ++
 clang/lib/Sema/SemaOverload.cpp| 10 ++
 clang/test/CXX/drs/dr12xx.cpp  |  2 +-
 clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp |  6 ++
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c89488e54ef494..ddeb1186d65ac8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -520,6 +520,8 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses narrowing conversions involving const references.
   (`#63151: `_).
 - Clang now diagnoses unexpanded packs within the template argument lists of 
function template specializations.
+- Clang now diagnoses attempts to bind a bitfield to an NTTP of a reference 
type as erroneous
+  converted constant expression and not as a reference to subobject.
 
 
 Improvements to Clang's time-trace
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a97182cad5d513..3884dca59e2f3b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2253,6 +2253,8 @@ def warn_cxx17_compat_aggregate_init_paren_list : Warning<
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "
   "bit-field%select{| %1}2">;
+def err_reference_bind_to_bitfield_in_cce : Error<
+  "reference cannot bind to bit-field in converted constant expression">;
 def err_reference_bind_to_vector_element : Error<
   "%select{non-const|volatile}0 reference cannot bind to vector element">;
 def err_reference_bind_to_matrix_element : Error<
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index e6c267bb79e60b..64bc3851980272 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6056,6 +6056,16 @@ static ExprResult BuildConvertedConstantExpression(Sema 
&S, Expr *From,
   diag::err_typecheck_converted_constant_expression_indirect)
<< From->getType() << From->getSourceRange() << T;
   }
+  // 'TryCopyInitialization' returns incorrect info for attempts to bind
+  // a reference to a bit-field due to C++ [over.ics.ref]p4. Namely,
+  // 'SCS->DirectBinding' occurs to be set to 'true' despite it is not
+  // the direct binding according to C++ [dcl.init.ref]p5. Hence, check this
+  // case explicitly.
+  if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) {
+return S.Diag(From->getBeginLoc(),
+  diag::err_reference_bind_to_bitfield_in_cce)
+   << From->getSourceRange();
+  }
 
   // Usually we can simply apply the ImplicitConversionSequence we formed
   // earlier, but that's not guaranteed to work when initializing an object of
diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp
index adf7f56711c451..cb4cc5aef17371 100644
--- a/clang/test/CXX/drs/dr12xx.cpp
+++ b/clang/test/CXX/drs/dr12xx.cpp
@@ -154,7 +154,7 @@ namespace dr1295 { // dr1295: 4
   Y y; // #dr1295-y
   // cxx98-14-error@-1 {{non-type template argument does not refer to any 
declaration}}
   //   cxx98-14-note@#dr1295-Y {{template parameter is declared here}}
-  // since-cxx17-error@#dr1295-y {{non-type template argument refers to 
subobject 'x.bitfield'}}
+  // since-cxx17-error@#dr1295-y {{reference cannot bind to bit-field in 
converted constant expression}}
 
 #if __cplusplus >= 201103L
   const unsigned other = 0;
diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
index 792dc78464b2a8..982f6ec2215708 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -93,6 +93,12 @@ namespace ConvertedConstant {
   template  struct X {};
   void f(X<1.0f>) {}
   void g(X<2>) {}
+
+  struct {
+int i : 2;
+  } b;
+  template  struct Y {};
+  void f(Y) {} // expected-error {{reference cannot bind to bit-field in 
converted constant expression}}
 }
 
 namespace CopyCounting {

_

[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-04 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/71077

>From e5ad8f5b00a297ef745e1b9341df32b80a7c6b77 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Thu, 2 Nov 2023 19:20:27 +0300
Subject: [PATCH] [clang] Improve bit-field in ref NTTP diagnostic

Prior to this, attempts to bind a bit-field to an NTTP of reference type
produced an error because references to subobjects in NTTPs are
disallowed. But C++20 allows references to subobjects in NTTPs generally
(see P1907R1). Without this change, implementing P1907R1 would cause
a bug allowing bit-fields to be bound to reference template arguments.

Extracted from https://reviews.llvm.org/D140996
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticSemaKinds.td   |  2 ++
 clang/lib/Sema/SemaOverload.cpp| 10 ++
 clang/test/CXX/drs/dr12xx.cpp  |  2 +-
 clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp |  6 ++
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7a948fd3fae5..01a927b2bc17e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -503,6 +503,8 @@ Improvements to Clang's diagnostics
48 | static_assert(1 << 4 == 15);
   |   ~~~^
 
+- Clang now diagnoses attempts to bind a bitfield to an NTTP of a reference 
type as erroneous
+  converted constant expression and not as a reference to subobject.
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6dfb2d7195203..b95d2bea00a5e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2251,6 +2251,8 @@ def warn_cxx17_compat_aggregate_init_paren_list : Warning<
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "
   "bit-field%select{| %1}2">;
+def err_reference_bind_to_bitfield_in_cce : Error<
+  "reference cannot bind to bit-field in converted constant expression">;
 def err_reference_bind_to_vector_element : Error<
   "%select{non-const|volatile}0 reference cannot bind to vector element">;
 def err_reference_bind_to_matrix_element : Error<
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5026e1d603e5e..ebbd4f48b57f8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6056,6 +6056,16 @@ static ExprResult BuildConvertedConstantExpression(Sema 
&S, Expr *From,
   diag::err_typecheck_converted_constant_expression_indirect)
<< From->getType() << From->getSourceRange() << T;
   }
+  // 'TryCopyInitialization' returns incorrect info for attempts to bind
+  // a reference to a bit-field due to C++ [over.ics.ref]p4. Namely,
+  // 'SCS->DirectBinding' occurs to be set to 'true' despite it is not
+  // the direct binding according to C++ [dcl.init.ref]p5. Hence, check this
+  // case explicitly.
+  if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) {
+return S.Diag(From->getBeginLoc(),
+  diag::err_reference_bind_to_bitfield_in_cce)
+   << From->getSourceRange();
+  }
 
   // Usually we can simply apply the ImplicitConversionSequence we formed
   // earlier, but that's not guaranteed to work when initializing an object of
diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp
index c23a515ba56cb..81c113d4c1c5a 100644
--- a/clang/test/CXX/drs/dr12xx.cpp
+++ b/clang/test/CXX/drs/dr12xx.cpp
@@ -138,7 +138,7 @@ namespace dr1295 { // dr1295: 4
 #if __cplusplus <= 201402L
   // expected-error@-2 {{does not refer to any declaration}} expected-note@-3 
{{here}}
 #else
-  // expected-error@-4 {{refers to subobject}}
+  // expected-error@-4 {{reference cannot bind to bit-field in converted 
constant expression}}
 #endif
 
 #if __cplusplus >= 201103L
diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
index 792dc78464b2a..982f6ec221570 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -93,6 +93,12 @@ namespace ConvertedConstant {
   template  struct X {};
   void f(X<1.0f>) {}
   void g(X<2>) {}
+
+  struct {
+int i : 2;
+  } b;
+  template  struct Y {};
+  void f(Y) {} // expected-error {{reference cannot bind to bit-field in 
converted constant expression}}
 }
 
 namespace CopyCounting {

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


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-04 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

I want just note that it is probably not an improvement from the user's point 
of view, just a change of wording.

https://github.com/llvm/llvm-project/pull/71077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread Andrey Ali Khan Bolshakov via cfe-commits

https://github.com/bolshakov-a updated 
https://github.com/llvm/llvm-project/pull/71077

>From ff1b0d96e7beef51a082d59548c49b9c02d79eb0 Mon Sep 17 00:00:00 2001
From: Bolshakov 
Date: Thu, 2 Nov 2023 19:20:27 +0300
Subject: [PATCH] [clang] Improve bit-field in ref NTTP diagnostic

Prior to this, attempts to bind a bit-field to an NTTP of reference type
produced an error because references to subobjects in NTTPs are
disallowed. But C++20 allows references to subobjects in NTTPs generally
(see P1907R1). Without this change, implementing P1907R1 would cause
a bug allowing bit-fields to be bound to reference template arguments.

Extracted from https://reviews.llvm.org/D140996
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td   |  2 ++
 clang/lib/Sema/SemaOverload.cpp| 10 ++
 clang/test/CXX/drs/dr12xx.cpp  |  2 +-
 clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp |  6 ++
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6dfb2d7195203..b95d2bea00a5e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2251,6 +2251,8 @@ def warn_cxx17_compat_aggregate_init_paren_list : Warning<
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "
   "bit-field%select{| %1}2">;
+def err_reference_bind_to_bitfield_in_cce : Error<
+  "reference cannot bind to bit-field in converted constant expression">;
 def err_reference_bind_to_vector_element : Error<
   "%select{non-const|volatile}0 reference cannot bind to vector element">;
 def err_reference_bind_to_matrix_element : Error<
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 5026e1d603e5e..ebbd4f48b57f8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6056,6 +6056,16 @@ static ExprResult BuildConvertedConstantExpression(Sema 
&S, Expr *From,
   diag::err_typecheck_converted_constant_expression_indirect)
<< From->getType() << From->getSourceRange() << T;
   }
+  // 'TryCopyInitialization' returns incorrect info for attempts to bind
+  // a reference to a bit-field due to C++ [over.ics.ref]p4. Namely,
+  // 'SCS->DirectBinding' occurs to be set to 'true' despite it is not
+  // the direct binding according to C++ [dcl.init.ref]p5. Hence, check this
+  // case explicitly.
+  if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) {
+return S.Diag(From->getBeginLoc(),
+  diag::err_reference_bind_to_bitfield_in_cce)
+   << From->getSourceRange();
+  }
 
   // Usually we can simply apply the ImplicitConversionSequence we formed
   // earlier, but that's not guaranteed to work when initializing an object of
diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp
index c23a515ba56cb..81c113d4c1c5a 100644
--- a/clang/test/CXX/drs/dr12xx.cpp
+++ b/clang/test/CXX/drs/dr12xx.cpp
@@ -138,7 +138,7 @@ namespace dr1295 { // dr1295: 4
 #if __cplusplus <= 201402L
   // expected-error@-2 {{does not refer to any declaration}} expected-note@-3 
{{here}}
 #else
-  // expected-error@-4 {{refers to subobject}}
+  // expected-error@-4 {{reference cannot bind to bit-field in converted 
constant expression}}
 #endif
 
 #if __cplusplus >= 201103L
diff --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
index 792dc78464b2a..982f6ec221570 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
@@ -93,6 +93,12 @@ namespace ConvertedConstant {
   template  struct X {};
   void f(X<1.0f>) {}
   void g(X<2>) {}
+
+  struct {
+int i : 2;
+  } b;
+  template  struct Y {};
+  void f(Y) {} // expected-error {{reference cannot bind to bit-field in 
converted constant expression}}
 }
 
 namespace CopyCounting {

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


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread Andrey Ali Khan Bolshakov via cfe-commits


@@ -5992,6 +5992,15 @@ static ExprResult BuildConvertedConstantExpression(Sema 
&S, Expr *From,
   /*InOverloadResolution=*/false,
   /*AllowObjCWritebackConversion=*/false,
   /*AllowExplicit=*/false);
+
+  // TryCopyInitialization returns incorrect info for attempts to bind 
reference
+  // to bit-field due to C++ [over.ics.ref]p4, so check it here.
+  if (From->refersToBitField() && T.getTypePtr()->isReferenceType()) {
+return S.Diag(From->getBeginLoc(),
+  diag::err_reference_bind_to_bitfield_in_cce)
+   << From->getSourceRange();
+  }

bolshakov-a wrote:

This citation is already present here. I've moved the new code closer to the 
last cited piece.

https://github.com/llvm/llvm-project/pull/71077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve bit-field in ref NTTP diagnostic (PR #71077)

2023-12-03 Thread Andrey Ali Khan Bolshakov via cfe-commits

bolshakov-a wrote:

> Can you add a release note?

Do you think this small diagnostic wording change is worth noting in relnotes?

> Do we need more tests in other contexts where a converted constant expression 
> is used?

Seems like constant expressions converted to references may currently only 
appear in non-type template arguments. Added a case into 
`SemaTemplate/temp_arg_nontype_cxx20.cpp`.

https://github.com/llvm/llvm-project/pull/71077
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >