[PATCH] D120874: [C++20] [Modules] Use '-' as the separator of partitions when searching in filesystems

2022-03-03 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu created this revision.
ChuanqiXu added reviewers: urnathan, iains.
ChuanqiXu added a project: clang.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

It is simpler to search for module unit by `-fprebuilt-module-path` option. 
However, the separator ':' of partitions is not friendly. According to the 
discussion in https://reviews.llvm.org/D118586, I think we get consensus to use 
'-' as the separator instead. The '-' is the choice of GCC too.

Previously I thought it would be better to add an option. But I feel it is 
over-engineering now. Another reason here is that there are too many options 
for modules (for clang module mainly) now. Given it is not bad to use '-' when 
searching, I think it is acceptable to not add an option.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120874

Files:
  clang/lib/Lex/HeaderSearch.cpp
  clang/test/Modules/search-partitions.cppm


Index: clang/test/Modules/search-partitions.cppm
===
--- /dev/null
+++ clang/test/Modules/search-partitions.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition1.cpp \
+// RUN:  -o %t/A-Part1.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition2.cpp \
+// RUN:  -o %t/A-Part2.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition3.cpp \
+// RUN:  -o %t/A-Part3.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/moduleA.cpp \
+// RUN:  -fprebuilt-module-path=%t
+
+// expected-no-diagnostics
+
+//--- partition1.cpp
+export module A : Part1;
+
+int part1();
+
+//--- partition2.cpp
+
+export module A : Part2;
+
+int part2();
+
+//--- partition3.cpp
+
+export module A : Part3;
+
+int part3();
+
+//--- moduleA.cpp
+
+export module A;
+
+import : Part1;
+export import : Part2;
+import : Part3;
+
+int foo();
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -194,10 +194,20 @@
   for (const std::string &Dir : HSOpts->PrebuiltModulePaths) {
 SmallString<256> Result(Dir);
 llvm::sys::fs::make_absolute(Result);
-llvm::sys::path::append(Result, ModuleName + ".pcm");
+if (ModuleName.contains(':'))
+  // The separator of C++20 modules partitions (':') is not good for file
+  // systems, here we choose '-' by default since it is not a valid
+  // character of C++ indentifiers. So we could avoid conflicts. BTW, '-' 
is
+  // the choice of GCC too.
+  llvm::sys::path::append(Result, ModuleName.split(':').first + "-" +
+  ModuleName.split(':').second +
+  ".pcm");
+else
+  llvm::sys::path::append(Result, ModuleName + ".pcm");
 if (getFileMgr().getFile(Result.str()))
   return std::string(Result);
   }
+
   return {};
 }
 


Index: clang/test/Modules/search-partitions.cppm
===
--- /dev/null
+++ clang/test/Modules/search-partitions.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition1.cpp \
+// RUN:  -o %t/A-Part1.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition2.cpp \
+// RUN:  -o %t/A-Part2.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/partition3.cpp \
+// RUN:  -o %t/A-Part3.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/moduleA.cpp \
+// RUN:  -fprebuilt-module-path=%t
+
+// expected-no-diagnostics
+
+//--- partition1.cpp
+export module A : Part1;
+
+int part1();
+
+//--- partition2.cpp
+
+export module A : Part2;
+
+int part2();
+
+//--- partition3.cpp
+
+export module A : Part3;
+
+int part3();
+
+//--- moduleA.cpp
+
+export module A;
+
+import : Part1;
+export import : Part2;
+import : Part3;
+
+int foo();
Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -194,10 +194,20 @@
   for (const std::string &Dir : HSOpts->PrebuiltModulePaths) {
 SmallString<256> Result(Dir);
 llvm::sys::fs::make_absolute(Result);
-llvm::sys::path::append(Result, ModuleName + ".pcm");
+if (ModuleName.contains(':'))
+  // The separator of C++20 modules partitions (':') is not good for file
+  // systems, here we choose '-' by default since it is not a valid
+  // character of C++ indentifiers. So we could avoid conflicts. BTW, '-' is
+  // the choice of GCC too.
+  llvm::sys::path::append(Result, ModuleName.split(':').first + "-" +
+  ModuleName.split(':').second +
+

[PATCH] D120395: [X86] Prohibit arithmetic operations on type `__bfloat16`

2022-03-03 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Thanks @andrew.w.kaylor ! You are totally correct about the intention and 
current implementations.

> Concretely, what are the semantics that we want for the BF16 types and 
> intrinsics? Unlike the other floating-point types, there's no standard to 
> guide this, so it's even more important to clearly specify how these types 
> are to be used, instead of having an ad-hoc semantics of whatever someone 
> happens to implement.

Good question! This is actually the scope of ABI. Unfortunately, we don't have 
the BF16 ABI at the present. We can't assume what are the physical registers 
the arguments been passed and returned before we have such a hardware. For 
example, ARM has soft FP ABI that supports FP arithmetic operations and passes 
and returns arguments by integer registers. When we enabling some ISA set whose 
type doesn't have ABI representation, e.g., F16C, we borrowed such conception. 
And as a trade off, we used integer rather than introducing a new IR type, 
since we don't need to support the arithmetic operations.
This patch as well as D120411  are trying to 
follow what we are doing on F16C. The difference is we are supporting scalar 
type too. That's why I put them into two patches.
Back to the question:

1. There's no BF16 type and its semantics before ABI ready on X86.
2. All intrinsics take BF16 as integer type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120395

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


[PATCH] D120874: [C++20] [Modules] Use '-' as the separator of partitions when searching in filesystems

2022-03-03 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a subscriber: MyDeveloperDay.
ChuanqiXu added inline comments.



Comment at: clang/test/Modules/search-partitions.cppm:20
+//--- partition1.cpp
+export module A : Part1;
+

@MyDeveloperDay hi, I remember the support for partitions in clang-format is 
done in https://reviews.llvm.org/D114151. I think I did something wrong. I 
format my code with the following command in the root directory of llvm project:
```
git diff -U0 --no-color --relative HEAD^ | 
clang/tools/clang-format/clang-format-diff.py -p1 -i
```

Would it use an out-dated clang-format? If yes, how should I use the proper 
one. Or if is it possible that the `.clang-format` files is not updated 
correctly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120874

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


[PATCH] D120875: [Driver] Split up huge aarch64-cpus.c test.

2022-03-03 Thread Florian Hahn via Phabricator via cfe-commits
fhahn created this revision.
fhahn added reviewers: simon_tatham, dmgreen, tmatheson, tyb0807.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a project: clang.

This test file has grown to the point where it takes a huge amount of
time to run. At the moment, this test seems to consistently time out
when running in the pre-commit checks in Phabricator with a 10 minute
timeout. For example see
https://reviews.llvm.org/harbormaster/unit/view/2832723/

While splitting up the test file is not ideal, it is even more
undesirable to have huge test files that time out in common settings.

This patch splits up the test file roughly in the middle.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120875

Files:
  clang/test/Driver/aarch64-cpus-1.c
  clang/test/Driver/aarch64-cpus-2.c
  clang/test/Driver/aarch64-cpus.c

Index: clang/test/Driver/aarch64-cpus-2.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-cpus-2.c
@@ -0,0 +1,434 @@
+// Check target CPUs are correctly passed. Continuation of aarch64-cpus-1.c.
+// NOTE: The tests are split across multiple files, to avoid excessive test
+// times for large single test files.
+
+// RUN: %clang -target aarch64 -### -c %s 2>&1 | FileCheck -check-prefix=GENERIC-V8A %s
+// RUN: %clang -target aarch64 -march=armv8-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERIC-V8A %s
+// GENERIC-V8A: "-cc1"{{.*}} "-triple" "aarch64{{(--)?}}"{{.*}} "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a"
+
+// RUN: %clang -target aarch64 -march=armv8-r -### -c %s 2>&1 | FileCheck -check-prefix=GENERIC-V8R %s
+// GENERIC-V8R: "-cc1"{{.*}} "-triple" "aarch64{{(--)?}}"{{.*}} "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8r"
+
+// RUN: %clang -target aarch64 -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A %s
+// RUN: %clang -target aarch64 -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A %s
+// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A %s
+// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A %s
+// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A %s
+// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A %s
+// GENERICV81A: "-cc1"{{.*}} "-triple" "aarch64{{(--)?}}"{{.*}} "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.1a"
+
+// RUN: %clang -target arm64 -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-GENERICV81A %s
+// RUN: %clang -target arm64 -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-GENERICV81A %s
+// RUN: %clang -target arm64 -mlittle-endian -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-GENERICV81A %s
+// RUN: %clang -target arm64 -mlittle-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=ARM64-GENERICV81A %s
+// ARM64-GENERICV81A: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.1a"
+
+// RUN: %clang -target aarch64_be -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s
+// RUN: %clang -target aarch64_be -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s
+// RUN: %clang -target aarch64 -mbig-endian -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s
+// RUN: %clang -target aarch64 -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s
+// RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s
+// RUN: %clang -target aarch64_be -mbig-endian -march=armv8.1-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV81A-BE %s
+
+// RUN: %clang -target aarch64 -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s
+// RUN: %clang -target aarch64 -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s
+// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s
+// RUN: %clang -target aarch64 -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s
+// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s
+// RUN: %clang -target aarch64_be -mlittle-endian -march=armv8.2-a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A %s
+// GENERICV82A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8.2a"
+
+// RUN: %clang -target aarch64_be -march=armv8.2a -### -c %s 2>&1 | FileCheck -check-prefix=GENERICV82A-BE %s
+// 

[PATCH] D117860: [RISCV] Remove experimental prefix from rvv-related extensions.

2022-03-03 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.
Herald added a subscriber: pcwang-thead.
Herald added a project: All.

Unfortunately some of the intrinsics tests have grown so large the the 
consistently hit the 10 minute timeout in the Phabricator precommit tests, e.g. 
see https://reviews.llvm.org/harbormaster/unit/152224/

Some of those files need to be split up, as those test failures in the 
pre-commit tests impact everyone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117860

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


[PATCH] D117860: [RISCV] Remove experimental prefix from rvv-related extensions.

2022-03-03 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

Also see https://github.com/llvm/llvm-project/issues/54168


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117860

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


[PATCH] D120876: [Driver] Split up huge arm-cortex-cpus.c test.

2022-03-03 Thread Florian Hahn via Phabricator via cfe-commits
fhahn created this revision.
fhahn added reviewers: simon_tatham, dmgreen, tmatheson, tyb0807.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This test file has grown to the point where it takes a huge amount of
time to run. At the moment, this test seems to consistently time out
when running in the pre-commit checks in Phabricator with a 10 minute
timeout. For example see
https://reviews.llvm.org/harbormaster/unit/view/2832724/

While splitting up the test file is not ideal, it is even more
undesirable to have huge test files that time out in common settings.

This patch splits up the test file roughly in the middle.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120876

Files:
  clang/test/Driver/arm-cortex-cpus-1.c
  clang/test/Driver/arm-cortex-cpus-2.c
  clang/test/Driver/arm-cortex-cpus.c

Index: clang/test/Driver/arm-cortex-cpus-2.c
===
--- clang/test/Driver/arm-cortex-cpus-2.c
+++ clang/test/Driver/arm-cortex-cpus-2.c
@@ -1,445 +1,7 @@
-// == Check default CPU on each major architecture
-// RUN: %clang -target arm -mcpu=generic -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-GENERIC %s
-// CHECK-GENERIC: "-cc1"{{.*}} "-triple" "armv4t-{{.*}} "-target-cpu" "generic"
-
-// RUN: %clang -target armeb -mcpu=generic -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-BE-GENERIC %s
-// CHECK-BE-GENERIC: "-cc1"{{.*}} "-triple" "armebv4t-{{.*}} "-target-cpu" "generic"
-
-// RUN: %clang -target arm -mthumb -mcpu=generic -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-GENERIC-THUMB %s
-// CHECK-GENERIC-THUMB: "-cc1"{{.*}} "-triple" "thumbv4t-{{.*}} "-target-cpu" "generic"
-
-// RUN: %clang -target armeb -mthumb -mcpu=generic -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-BE-GENERIC-THUMB %s
-// CHECK-BE-GENERIC-THUMB: "-cc1"{{.*}} "-triple" "thumbebv4t-{{.*}} "-target-cpu" "generic"
-
-// RUN: %clang -target armv4t -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V4T %s
-// RUN: %clang -target arm -march=armv4t -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V4T %s
-// CHECK-V4T: "-cc1"{{.*}} "-triple" "armv4t-{{.*}} "-target-cpu" "arm7tdmi"
-
-// RUN: %clang -target armv4t -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V4T-THUMB %s
-// RUN: %clang -target arm -mthumb -march=armv4t -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V4T-THUMB %s
-// CHECK-V4T-THUMB: "-cc1"{{.*}} "-triple" "thumbv4t-{{.*}} "-target-cpu" "arm7tdmi"
-
-// RUN: %clang -target armv5 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5 %s
-// RUN: %clang -target arm -march=armv5 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5 %s
-// RUN: %clang -target armv5t -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5 %s
-// RUN: %clang -target arm -march=armv5t -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5 %s
-// CHECK-V5: "-cc1"{{.*}} "-triple" "armv5-{{.*}} "-target-cpu" "arm10tdmi"
-
-// RUN: %clang -target armv5 -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5-THUMB %s
-// RUN: %clang -target arm -march=armv5 -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5-THUMB %s
-// RUN: %clang -target armv5t -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5-THUMB %s
-// CHECK-V5-THUMB: "-cc1"{{.*}} "-triple" "thumbv5-{{.*}} "-target-cpu" "arm10tdmi"
-
-// RUN: %clang -target armv5e -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5E %s
-// RUN: %clang -target arm -march=armv5e -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5E %s
-// CHECK-V5E: "-cc1"{{.*}} "-triple" "armv5e-{{.*}} "-target-cpu" "arm1022e"
-
-// RUN: %clang -target armv5e -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5E-THUMB %s
-// RUN: %clang -target arm -march=armv5e -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5E-THUMB %s
-// CHECK-V5E-THUMB: "-cc1"{{.*}} "-triple" "thumbv5e-{{.*}} "-target-cpu" "arm1022e"
-
-// FIXME %clang -target armv5tej -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5TEJ %s
-// RUN: %clang -target arm -march=armv5tej -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5TEJ %s
-// CHECK-V5TEJ: "-cc1"{{.*}} "-triple" "armv5e-{{.*}} "-target-cpu" "arm926ej-s"
-
-// FIXME %clang -target armv5tej -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5TEJ-THUMB %s
-// RUN: %clang -target arm -march=armv5tej -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V5TEJ-THUMB %s
-// CHECK-V5TEJ-THUMB: "-cc1"{{.*}} "-triple" "thumbv5e-{{.*}} "-target-cpu" "arm926ej-s"
-
-// RUN: %clang -target armv6 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V6 %s
-// RUN: %clang -target arm -march=armv6 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V6 %s
-// CHECK-V6: "-cc1"{{.*}} "-triple" "armv6-{{.*}} "-target-cpu" "arm1136jf-s"
-
-// RUN: %clang -target armv6 -mthumb -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-V6-THUMB %s
-// RUN: %clang -target arm -march=armv6 -mthumb -

[PATCH] D120875: [Driver] Split up huge aarch64-cpus.c test.

2022-03-03 Thread Son Tuan Vu via Phabricator via cfe-commits
tyb0807 added a comment.

Thanks for making this change. However, I think a better split would be

- List Item

`aarch64-cpus.c` which contains cpu-specific test cases (usually with `-mcpu` 
flag). Roughly this is until line 515, plus some last test cases from line 926 
to end.
`aarch64-archs.c` which contains architecture-specific test cases (with 
`-march` flag).

Or better yet, we can further break down the `aarch64-archs.c`, with 
feature-specific test cases going into a feature-specific file, just as what we 
are doing with new features (`aarch64-hbc.c`, `aarch64-mops.c`, ...). I can 
submit a separate patch for this if you prefer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120875

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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2022-03-03 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

> I just pushed 6cb42cd6669785f3b611106e1b6b38bbe65733a9 
>  to 
> hopefully fix this.

Thank you Craig! That fixed it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[PATCH] D120875: [Driver] Split up huge aarch64-cpus.c test.

2022-03-03 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham added a comment.

> While splitting up the test file is not ideal [...]

Actually I'm not so sure. I'd almost rather go further, and split it up into 
lots of //much// smaller files, each with some kind of reasonable theme, like 
"all the basically v8.1-A stuff" or "all the v8M".

The advantage of that is that it sets an obvious pattern for the next developer 
to follow – they look at the existing tests, notice there are lots of separate 
files, and make a fresh one rather than extending an existing one. Doing it 
this way, all that will happen is that one of the -1 and -2 files gets too big 
again in a year or two's time :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120875

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


[PATCH] D120812: [AST] Use RecoveryExpr to model a DeclRefExpr which refers to an invalid Decl.

2022-03-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D120812#3354308 , @sammccall wrote:

> Very nice! I thought we had considered and rejected this in the past, but I 
> think it was rather allowing lookup to find invalid decls in cases where it 
> doesn't today.

Yeah, in the past (https://reviews.llvm.org/D76831), we tried to build the 
`DeclRefExpr` even for an invalid ref decl, it made the diagnostics much worse 
(as we don't know the type of the invalid decl, the fallback int type is not 
suitable for every cases).

We use a different approach in this approach (build RecoveryExpr instead), a 
sad bit is that we are not able to retrieve the ref decl from the 
`RecoveryExpr`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120812

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


[clang] ba6c71b - [AST] Use RecoveryExpr to model a DeclRefExpr which refers to an invalid Decl.

2022-03-03 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-03-03T10:33:40+01:00
New Revision: ba6c71b1377e8c99b62b2115a8519df74465f53c

URL: 
https://github.com/llvm/llvm-project/commit/ba6c71b1377e8c99b62b2115a8519df74465f53c
DIFF: 
https://github.com/llvm/llvm-project/commit/ba6c71b1377e8c99b62b2115a8519df74465f53c.diff

LOG: [AST] Use RecoveryExpr to model a DeclRefExpr which refers to an invalid 
Decl.

Previously, we didin't build a DeclRefExpr which refers to an invalid 
declaration.

In this patch, we handle this case by building an empty RecoveryExpr,
which will preserve more broken code (AST parent nodes that contain the
RecoveryExpr is preserved in the AST).

Differential Revision: https://reviews.llvm.org/D120812

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/Sema/ms-inline-asm.c
clang/test/SemaCXX/constructor-initializer.cpp
clang/test/SemaCXX/copy-assignment.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index bd7110d0315d9..ca5e206f8933d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3228,8 +3228,12 @@ ExprResult Sema::BuildDeclarationNameExpr(
  "Cannot refer unambiguously to a function template");
 
   SourceLocation Loc = NameInfo.getLoc();
-  if (CheckDeclInExpr(*this, Loc, D))
-return ExprError();
+  if (CheckDeclInExpr(*this, Loc, D)) {
+// Recovery from invalid cases (e.g. D is an invalid Decl).
+// We use the dependent type for the RecoveryExpr to prevent bogus 
follow-up
+// diagnostics, as invalid decls use int as a fallback type.
+return CreateRecoveryExpr(NameInfo.getBeginLoc(), NameInfo.getEndLoc(), 
{});
+  }
 
   if (TemplateDecl *Template = dyn_cast(D)) {
 // Specifically diagnose references to class templates that are missing

diff  --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index 0bdd726ab3ce4..f2aca6a78fb02 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -401,3 +401,13 @@ void returnInitListFromVoid() {
   // CHECK-NEXT:   |-IntegerLiteral {{.*}} 'int' 7
   // CHECK-NEXT:   `-IntegerLiteral {{.*}} 'int' 8
 }
+
+void RecoveryExprForInvalidDecls(Unknown InvalidDecl) {
+  InvalidDecl + 1;
+  // CHECK:  BinaryOperator {{.*}}
+  // CHECK-NEXT: |-RecoveryExpr {{.*}} ''
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+  InvalidDecl();
+  // CHECK:  CallExpr {{.*}}
+  // CHECK-NEXT: `-RecoveryExpr {{.*}} ''
+}

diff  --git a/clang/test/Sema/ms-inline-asm.c b/clang/test/Sema/ms-inline-asm.c
index 896c74c546d06..fc2a6c294b5c9 100644
--- a/clang/test/Sema/ms-inline-asm.c
+++ b/clang/test/Sema/ms-inline-asm.c
@@ -78,7 +78,6 @@ void t3(void) {
   __asm { mov eax, [eax] UndeclaredId } // expected-error {{unknown token in 
expression}} expected-error {{use of undeclared label 'UndeclaredId'}}
 
   // FIXME: Only emit one diagnostic here.
-  // expected-error@+3 {{use of undeclared label 'A'}}
   // expected-error@+2 {{unexpected type name 'A': expected expression}}
   // expected-error@+1 {{unknown token in expression}}
   __asm { mov eax, [eax] A }

diff  --git a/clang/test/SemaCXX/constructor-initializer.cpp 
b/clang/test/SemaCXX/constructor-initializer.cpp
index 874682944bb85..010f90b59cb07 100644
--- a/clang/test/SemaCXX/constructor-initializer.cpp
+++ b/clang/test/SemaCXX/constructor-initializer.cpp
@@ -249,7 +249,9 @@ namespace test3 {
   class B : public A {
   public:
 B(const String& s, int e=0) // expected-error {{unknown type name}} 
-  : A(e), m_String(s) , m_ErrorStr(__null) {} // expected-error {{no 
matching constructor}} expected-error {{does not name}}
+  : A(e), m_String(s) , m_ErrorStr(__null) {} // expected-error {{no 
matching constructor}} \
+  expected-error {{member initializer 'm_String' does not name}} \
+  expected-error {{member initializer 'm_ErrorStr' does not name}}
 B(const B& e)
   : A(e), m_String(e.m_String), m_ErrorStr(__null) { // expected-error 
2{{does not name}} \
   // expected-error {{no member named 'm_String' in 'test3::B'}}

diff  --git a/clang/test/SemaCXX/copy-assignment.cpp 
b/clang/test/SemaCXX/copy-assignment.cpp
index d6ad6577895fe..1dbd1037f5b54 100644
--- a/clang/test/SemaCXX/copy-assignment.cpp
+++ b/clang/test/SemaCXX/copy-assignment.cpp
@@ -114,6 +114,7 @@ void test() {
 namespace test1 {
   template class A : public unknown::X { // expected-error 
{{undeclared identifier 'unknown'}} expected-error {{expected class name}}
 A(UndeclaredType n) : X(n) {} // expected-error {{unknown type name 
'UndeclaredType'}}
+// expected-error@-1 {{member initializer 'X' does not name a non-static 
data member or base class}}
   };
   template class B : public A {
 virtual void foo() {}



___
cfe-commits mailing list

[PATCH] D120812: [AST] Use RecoveryExpr to model a DeclRefExpr which refers to an invalid Decl.

2022-03-03 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rGba6c71b1377e: [AST] Use RecoveryExpr to model a DeclRefExpr 
which refers to an invalid Decl. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D120812?vs=412400&id=412632#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120812

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/Sema/ms-inline-asm.c
  clang/test/SemaCXX/constructor-initializer.cpp
  clang/test/SemaCXX/copy-assignment.cpp


Index: clang/test/SemaCXX/copy-assignment.cpp
===
--- clang/test/SemaCXX/copy-assignment.cpp
+++ clang/test/SemaCXX/copy-assignment.cpp
@@ -114,6 +114,7 @@
 namespace test1 {
   template class A : public unknown::X { // expected-error 
{{undeclared identifier 'unknown'}} expected-error {{expected class name}}
 A(UndeclaredType n) : X(n) {} // expected-error {{unknown type name 
'UndeclaredType'}}
+// expected-error@-1 {{member initializer 'X' does not name a non-static 
data member or base class}}
   };
   template class B : public A {
 virtual void foo() {}
Index: clang/test/SemaCXX/constructor-initializer.cpp
===
--- clang/test/SemaCXX/constructor-initializer.cpp
+++ clang/test/SemaCXX/constructor-initializer.cpp
@@ -249,7 +249,9 @@
   class B : public A {
   public:
 B(const String& s, int e=0) // expected-error {{unknown type name}} 
-  : A(e), m_String(s) , m_ErrorStr(__null) {} // expected-error {{no 
matching constructor}} expected-error {{does not name}}
+  : A(e), m_String(s) , m_ErrorStr(__null) {} // expected-error {{no 
matching constructor}} \
+  expected-error {{member initializer 'm_String' does not name}} \
+  expected-error {{member initializer 'm_ErrorStr' does not name}}
 B(const B& e)
   : A(e), m_String(e.m_String), m_ErrorStr(__null) { // expected-error 
2{{does not name}} \
   // expected-error {{no member named 'm_String' in 'test3::B'}}
Index: clang/test/Sema/ms-inline-asm.c
===
--- clang/test/Sema/ms-inline-asm.c
+++ clang/test/Sema/ms-inline-asm.c
@@ -78,7 +78,6 @@
   __asm { mov eax, [eax] UndeclaredId } // expected-error {{unknown token in 
expression}} expected-error {{use of undeclared label 'UndeclaredId'}}
 
   // FIXME: Only emit one diagnostic here.
-  // expected-error@+3 {{use of undeclared label 'A'}}
   // expected-error@+2 {{unexpected type name 'A': expected expression}}
   // expected-error@+1 {{unknown token in expression}}
   __asm { mov eax, [eax] A }
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -401,3 +401,13 @@
   // CHECK-NEXT:   |-IntegerLiteral {{.*}} 'int' 7
   // CHECK-NEXT:   `-IntegerLiteral {{.*}} 'int' 8
 }
+
+void RecoveryExprForInvalidDecls(Unknown InvalidDecl) {
+  InvalidDecl + 1;
+  // CHECK:  BinaryOperator {{.*}}
+  // CHECK-NEXT: |-RecoveryExpr {{.*}} ''
+  // CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
+  InvalidDecl();
+  // CHECK:  CallExpr {{.*}}
+  // CHECK-NEXT: `-RecoveryExpr {{.*}} ''
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -3228,8 +3228,12 @@
  "Cannot refer unambiguously to a function template");
 
   SourceLocation Loc = NameInfo.getLoc();
-  if (CheckDeclInExpr(*this, Loc, D))
-return ExprError();
+  if (CheckDeclInExpr(*this, Loc, D)) {
+// Recovery from invalid cases (e.g. D is an invalid Decl).
+// We use the dependent type for the RecoveryExpr to prevent bogus 
follow-up
+// diagnostics, as invalid decls use int as a fallback type.
+return CreateRecoveryExpr(NameInfo.getBeginLoc(), NameInfo.getEndLoc(), 
{});
+  }
 
   if (TemplateDecl *Template = dyn_cast(D)) {
 // Specifically diagnose references to class templates that are missing


Index: clang/test/SemaCXX/copy-assignment.cpp
===
--- clang/test/SemaCXX/copy-assignment.cpp
+++ clang/test/SemaCXX/copy-assignment.cpp
@@ -114,6 +114,7 @@
 namespace test1 {
   template class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}}
 A(UndeclaredType n) : X(n) {} // expected-error {{unknown type name 'UndeclaredType'}}
+// expected-error@-1 {{member initializer 'X' does not name a non-static data member or base class}}
   };
   template class B : public A {
 virtual vo

[PATCH] D120875: [Driver] Split up huge aarch64-cpus.c test.

2022-03-03 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D120875#3356432 , @simon_tatham 
wrote:

>> While splitting up the test file is not ideal [...]
>
> Actually I'm not so sure. I'd almost rather go further, and split it up into 
> lots of //much// smaller files, each with some kind of reasonable theme, like 
> "all the basically v8.1-A stuff" or "all the v8M".
>
> The advantage of that is that it sets an obvious pattern for the next 
> developer to follow – they look at the existing tests, notice there are lots 
> of separate files, and make a fresh one rather than extending an existing 
> one. Doing it this way, all that will happen is that one of the -1 and -2 
> files gets too big again in a year or two's time :-)

Agreed, more fine-grained splitting would be ideal, but unfortunately I am not 
familiar enough with all the intricacies of the test to perform more 
fine-grained splitting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120875

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


[PATCH] D120873: [clang-format] Handle wrapped else for RemoveBracesLLVM

2022-03-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120873

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


[PATCH] D120812: [AST] Use RecoveryExpr to model a DeclRefExpr which refers to an invalid Decl.

2022-03-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

To preserve the decl, we could consider as a next step building a recoveryexpr 
wrapping a declrefexpr pointing at the invalid decl.

This was discussed in the patch you linked, but I don't think it was tried?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120812

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


[PATCH] D120449: [RISCV][RVV] Add strict vfcvt intrinsics that have side effects for dynamically-set rounding mode

2022-03-03 Thread ShihPo Hung via Phabricator via cfe-commits
arcbbb added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVISelLowering.cpp:4683
+Ops.push_back(VL);
+Ops.push_back(DAG.getUNDEF(XLenVT)); // Policy
+  }

kito-cheng wrote:
> Is this operand for tail policy? if so why this is `UNDEF`? I guess this 
> should be `TAIL_AGNOSTIC` rather than `UNDEF`?
Because unmasked pseudos doesn't have a policy operand,
TA/TU is distinguished by checking if passthru is undef. I think it is proper 
to leave undef here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120449

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


[PATCH] D118370: [clang-tidy] bugprone-signal-handler: Message improvement and code refactoring.

2022-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.
Herald added a project: All.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:159-160
Itr != ItrE; ++Itr) {
 const auto *CallF = dyn_cast((*Itr)->getDecl());
-if (CallF && !isFunctionAsyncSafe(CallF)) {
-  assert(Itr.getPathLength() >= 2);
-  reportBug(CallF, findCallExpr(Itr.getPath(Itr.getPathLength() - 2), 
*Itr),
-/*DirectHandler=*/false);
-  reportHandlerCommon(Itr, SignalCall, HandlerDecl, HandlerExpr);
+if (CallF) {
+  unsigned int PathL = Itr.getPathLength();

whisperity wrote:
> 
Is this code not too long to put in the condition section?



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:165-171
+  if (checkFunction(CallF, CallOrRef))
+reportHandlerChain(Itr, HandlerExpr);
 }
   }
 }
 
+bool SignalHandlerCheck::checkFunction(const FunctionDecl *FD,

whisperity wrote:
> What does the return value of `checkFunction` signal to the user, and the 
> `if`?
This has a description in the header file.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c:14
   printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be 
asynchronous-safe; calling it from a signal handler may be dangerous 
[bugprone-signal-handler]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: system call 'printf' may not be 
asynchronous-safe; calling it from a signal handler may be dangerous 
[bugprone-signal-handler]
 }

whisperity wrote:
> I'm not exactly sure we should call `printf` (and `memcpy`) a "system call". 
> As far as I can see, in this patch, `isSystemCall()` boils down to 
> //"declaration in file included as system header"//
Call it "standard function"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118370

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


[clang] d832078 - [analyzer] Improve NoOwnershipChangeVisitor's understanding of deallocators

2022-03-03 Thread Kristóf Umann via cfe-commits

Author: Kristóf Umann
Date: 2022-03-03T11:27:56+01:00
New Revision: d832078904c6e1d26648236b9f724f699dafb201

URL: 
https://github.com/llvm/llvm-project/commit/d832078904c6e1d26648236b9f724f699dafb201
DIFF: 
https://github.com/llvm/llvm-project/commit/d832078904c6e1d26648236b9f724f699dafb201.diff

LOG: [analyzer] Improve NoOwnershipChangeVisitor's understanding of deallocators

The problem with leak bug reports is that the most interesting event in the code
is likely the one that did not happen -- lack of ownership change and lack of
deallocation, which is often present within the same function that the analyzer
inlined anyway, but not on the path of execution on which the bug occured. We
struggle to understand that a function was responsible for freeing the memory,
but failed.

D105819 added a new visitor to improve memory leak bug reports. In addition to
inspecting the ExplodedNodes of the bug pat, the visitor tries to guess whether
the function was supposed to free memory, but failed to. Initially (in D108753),
this was done by checking whether a CXXDeleteExpr is present in the function. If
so, we assume that the function was at least party responsible, and prevent the
analyzer from pruning bug report notes in it. This patch improves this heuristic
by recognizing all deallocator functions that MallocChecker itself recognizes,
by reusing MallocChecker::isFreeingCall.

Differential Revision: https://reviews.llvm.org/D118880

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/test/Analysis/NewDeleteLeaks.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 63194d69d6363..238022d1253b9 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -398,6 +398,9 @@ class MallocChecker
   };
 
   bool isFreeingCall(const CallEvent &Call) const;
+  static bool isFreeingOwnershipAttrCall(const FunctionDecl *Func);
+
+  friend class NoOwnershipChangeVisitor;
 
   CallDescriptionMap AllocatingMemFnMap{
   {{"alloca", 1}, &MallocChecker::checkAlloca},
@@ -742,7 +745,9 @@ class MallocChecker
 
 namespace {
 class NoOwnershipChangeVisitor final : public NoStateChangeFuncVisitor {
+  // The symbol whose (lack of) ownership change we are interested in.
   SymbolRef Sym;
+  const MallocChecker &Checker;
   using OwnerSet = llvm::SmallPtrSet;
 
   // Collect which entities point to the allocated memory, and could be
@@ -794,6 +799,29 @@ class NoOwnershipChangeVisitor final : public 
NoStateChangeFuncVisitor {
 return "";
   }
 
+  /// Syntactically checks whether the callee is a deallocating function. Since
+  /// we have no path-sensitive information on this call (we would need a
+  /// CallEvent instead of a CallExpr for that), its possible that a
+  /// deallocation function was called indirectly through a function pointer,
+  /// but we are not able to tell, so this is a best effort analysis.
+  /// See namespace `memory_passed_to_fn_call_free_through_fn_ptr` in
+  /// clang/test/Analysis/NewDeleteLeaks.cpp.
+  bool isFreeingCallAsWritten(const CallExpr &Call) const {
+if (Checker.FreeingMemFnMap.lookupAsWritten(Call) ||
+Checker.ReallocatingMemFnMap.lookupAsWritten(Call))
+  return true;
+
+if (const auto *Func =
+llvm::dyn_cast_or_null(Call.getCalleeDecl()))
+  return MallocChecker::isFreeingOwnershipAttrCall(Func);
+
+return false;
+  }
+
+  /// Heuristically guess whether the callee intended to free memory. This is
+  /// done syntactically, because we are trying to argue about alternative
+  /// paths of execution, and as a consequence we don't have path-sensitive
+  /// information.
   bool doesFnIntendToHandleOwnership(const Decl *Callee, ASTContext &ACtx) {
 using namespace clang::ast_matchers;
 const FunctionDecl *FD = dyn_cast(Callee);
@@ -807,13 +835,21 @@ class NoOwnershipChangeVisitor final : public 
NoStateChangeFuncVisitor {
 if (!FD || !FD->hasBody())
   return false;
 
-// TODO: Operator delete is hardly the only deallocator -- Can we reuse
-// isFreeingCall() or something thats already here?
-auto Deallocations = match(
-stmt(hasDescendant(cxxDeleteExpr().bind("delete"))
- ), *FD->getBody(), ACtx);
-// TODO: Ownership my change with an attempt to store the allocated memory.
-return !Deallocations.empty();
+auto Matches = match(findAll(stmt(anyOf(cxxDeleteExpr().bind("delete"),
+callExpr().bind("call",
+ *FD->getBody(), ACtx);
+for (BoundNodes Match : Matches) {
+  if (Match.getNodeAs("delete"))
+return true;
+
+  if (const auto *Call = Match.getNodeAs("call"))
+if (isFreeingCallAsWritten(*Call))
+  return true;

[PATCH] D118880: [analyzer] Improve NoOwnershipChangeVisitor's understanding of deallocators

2022-03-03 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd832078904c6: [analyzer] Improve 
NoOwnershipChangeVisitor's understanding of deallocators (authored by 
Szelethus).
Herald added a project: All.

Changed prior to commit:
  https://reviews.llvm.org/D118880?vs=407121&id=412644#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118880

Files:
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/test/Analysis/NewDeleteLeaks.cpp

Index: clang/test/Analysis/NewDeleteLeaks.cpp
===
--- clang/test/Analysis/NewDeleteLeaks.cpp
+++ clang/test/Analysis/NewDeleteLeaks.cpp
@@ -35,7 +35,9 @@
 
 } // namespace memory_allocated_in_fn_call
 
-namespace memory_passed_to_fn_call {
+// Realize that sink() intends to deallocate memory, assume that it should've
+// taken care of the leaked object as well.
+namespace memory_passed_to_fn_call_delete {
 
 void sink(int *P) {
   if (coin()) // ownership-note {{Assuming the condition is false}}
@@ -50,7 +52,41 @@
 } // expected-warning {{Potential leak of memory pointed to by 'ptr' [cplusplus.NewDeleteLeaks]}}
 // expected-note@-1 {{Potential leak}}
 
-} // namespace memory_passed_to_fn_call
+} // namespace memory_passed_to_fn_call_delete
+
+namespace memory_passed_to_fn_call_free {
+
+void sink(int *P) {
+  if (coin()) // ownership-note {{Assuming the condition is false}}
+  // ownership-note@-1 {{Taking false branch}}
+free(P);
+} // ownership-note {{Returning without deallocating memory or storing the pointer for later deallocation}}
+
+void foo() {
+  int *ptr = (int *)malloc(sizeof(int)); // expected-note {{Memory is allocated}}
+  sink(ptr); // ownership-note {{Calling 'sink'}}
+ // ownership-note@-1 {{Returning from 'sink'}}
+} // expected-warning {{Potential leak of memory pointed to by 'ptr' [unix.Malloc]}}
+// expected-note@-1 {{Potential leak}}
+
+} // namespace memory_passed_to_fn_call_free
+
+// Function pointers cannot be resolved syntactically.
+namespace memory_passed_to_fn_call_free_through_fn_ptr {
+void (*freeFn)(void *) = free;
+
+void sink(int *P) {
+  if (coin())
+freeFn(P);
+}
+
+void foo() {
+  int *ptr = (int *)malloc(sizeof(int)); // expected-note {{Memory is allocated}}
+  sink(ptr);
+} // expected-warning {{Potential leak of memory pointed to by 'ptr' [unix.Malloc]}}
+// expected-note@-1 {{Potential leak}}
+
+} // namespace memory_passed_to_fn_call_free_through_fn_ptr
 
 namespace memory_shared_with_ptr_of_shorter_lifetime {
 
@@ -123,6 +159,24 @@
 
 } // namespace memory_passed_into_fn_that_doesnt_intend_to_free
 
+namespace memory_passed_into_fn_that_doesnt_intend_to_free2 {
+
+void bar();
+
+void sink(int *P) {
+  // Correctly realize that calling bar() doesn't mean that this function would
+  // like to deallocate anything.
+  bar();
+}
+
+void foo() {
+  int *ptr = new int(5); // expected-note {{Memory is allocated}}
+  sink(ptr);
+} // expected-warning {{Potential leak of memory pointed to by 'ptr' [cplusplus.NewDeleteLeaks]}}
+// expected-note@-1 {{Potential leak}}
+
+} // namespace memory_passed_into_fn_that_doesnt_intend_to_free2
+
 namespace refkind_from_unoallocated_to_allocated {
 
 // RefKind of the symbol changed from nothing to Allocated. We don't want to
Index: clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -398,6 +398,9 @@
   };
 
   bool isFreeingCall(const CallEvent &Call) const;
+  static bool isFreeingOwnershipAttrCall(const FunctionDecl *Func);
+
+  friend class NoOwnershipChangeVisitor;
 
   CallDescriptionMap AllocatingMemFnMap{
   {{"alloca", 1}, &MallocChecker::checkAlloca},
@@ -742,7 +745,9 @@
 
 namespace {
 class NoOwnershipChangeVisitor final : public NoStateChangeFuncVisitor {
+  // The symbol whose (lack of) ownership change we are interested in.
   SymbolRef Sym;
+  const MallocChecker &Checker;
   using OwnerSet = llvm::SmallPtrSet;
 
   // Collect which entities point to the allocated memory, and could be
@@ -794,6 +799,29 @@
 return "";
   }
 
+  /// Syntactically checks whether the callee is a deallocating function. Since
+  /// we have no path-sensitive information on this call (we would need a
+  /// CallEvent instead of a CallExpr for that), its possible that a
+  /// deallocation function was called indirectly through a function pointer,
+  /// but we are not able to tell, so this is a best effort analysis.
+  /// See namespace `memory_passed_to_fn_call_free_through_fn_ptr` in
+  /// clang/test/Analysis/NewDeleteLeaks.cpp.
+  bool isFreeingCallAsWritten(const CallExpr &Call) const {
+if (Checker.FreeingMemFnMap.lookupAsWritten(Call) ||

[PATCH] D120881: [Clang] Diagnose invalid member variable with template parameters

2022-03-03 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/54151


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120881

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/class.cpp


Index: clang/test/SemaCXX/class.cpp
===
--- clang/test/SemaCXX/class.cpp
+++ clang/test/SemaCXX/class.cpp
@@ -208,6 +208,22 @@
 }
 }
 
-struct PR9989 { 
-  static int const PR9989_Member = sizeof PR9989_Member; 
+struct PR9989 {
+  static int const PR9989_Member = sizeof PR9989_Member;
 };
+
+
+namespace GH54151 {
+
+struct S {
+  int i<0>; //expected-error  {{member 'i' cannot have template arguments}}
+  int j; //expected-error  {{member 'j' cannot have template arguments}}
+};
+
+template 
+struct U {
+  int i; //expected-error {{member 'i' cannot have template arguments}}
+  int j; //expected-error {{member 'j' cannot have template arguments}}
+};
+
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3395,6 +3395,13 @@
   return nullptr;
 }
 
+if(isInstField && D.getName().getKind() == 
UnqualifiedIdKind::IK_TemplateId) {
+Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)
+<< II
+<< SourceRange(D.getName().TemplateId->LAngleLoc, 
D.getName().TemplateId->RAngleLoc)
+<< D.getName().TemplateId->LAngleLoc;
+}
+
 if (SS.isSet() && !SS.isInvalid()) {
   // The user provided a superfluous scope specifier inside a class
   // definition:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4790,6 +4790,7 @@
 def err_template_variable_noparams : Error<
   "extraneous 'template<>' in declaration of variable %0">;
 def err_template_member : Error<"member %0 declared as a template">;
+def err_member_with_template_arguments : Error<"member %0 cannot have template 
arguments">;
 def err_template_member_noparams : Error<
   "extraneous 'template<>' in declaration of member %0">;
 def err_template_tag_noparams : Error<


Index: clang/test/SemaCXX/class.cpp
===
--- clang/test/SemaCXX/class.cpp
+++ clang/test/SemaCXX/class.cpp
@@ -208,6 +208,22 @@
 }
 }
 
-struct PR9989 { 
-  static int const PR9989_Member = sizeof PR9989_Member; 
+struct PR9989 {
+  static int const PR9989_Member = sizeof PR9989_Member;
 };
+
+
+namespace GH54151 {
+
+struct S {
+  int i<0>; //expected-error  {{member 'i' cannot have template arguments}}
+  int j; //expected-error  {{member 'j' cannot have template arguments}}
+};
+
+template 
+struct U {
+  int i; //expected-error {{member 'i' cannot have template arguments}}
+  int j; //expected-error {{member 'j' cannot have template arguments}}
+};
+
+}
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3395,6 +3395,13 @@
   return nullptr;
 }
 
+if(isInstField && D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
+Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)
+<< II
+<< SourceRange(D.getName().TemplateId->LAngleLoc, D.getName().TemplateId->RAngleLoc)
+<< D.getName().TemplateId->LAngleLoc;
+}
+
 if (SS.isSet() && !SS.isInvalid()) {
   // The user provided a superfluous scope specifier inside a class
   // definition:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4790,6 +4790,7 @@
 def err_template_variable_noparams : Error<
   "extraneous 'template<>' in declaration of variable %0">;
 def err_template_member : Error<"member %0 declared as a template">;
+def err_member_with_template_arguments : Error<"member %0 cannot have template arguments">;
 def err_template_member_noparams : Error<
   "extraneous 'template<>' in declaration of member %0">;
 def err_template_tag_noparams : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk created this revision.
kwk added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius.
Herald added a project: All.
kwk requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It was requested here (https://reviews.llvm.org/D120398#3353053) to make
the underlying type of all enums in `FormatStyle` an `int8_t`.

Originally the type was changed in https://reviews.llvm.org/D93758.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120884

Files:
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -62,7 +62,7 @@
   int AccessModifierOffset;
 
   /// Different styles for aligning after open brackets.
-  enum BracketAlignmentStyle : unsigned char {
+  enum BracketAlignmentStyle : int8_t {
 /// Align parameters on the open bracket, e.g.:
 /// \code
 ///   someLongFunction(argument1,
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : int8_t {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -140,7 +140,7 @@
   /// ``AlignConsecutiveBitFields``), names in declarations (see
   /// ``AlignConsecutiveDeclarations``) or macro definitions (see
   /// ``AlignConsecutiveMacros``).
-  enum AlignConsecutiveStyle {
+  enum AlignConsecutiveStyle : int8_t {
 ACS_None,
 ACS_Consecutive,
 ACS_AcrossEmptyLines,
@@ -429,7 +429,7 @@
   AlignConsecutiveStyle AlignConsecutiveDeclarations;
 
   /// Different styles for aligning escaped newlines.
-  enum EscapedNewlineAlignmentStyle : unsigned char {
+  enum EscapedNewlineAlignmentStyle : int8_t {
 /// Don't align escaped newlines.
 /// \code
 ///   #define A \
@@ -464,7 +464,7 @@
   EscapedNewlineAlignmentStyle AlignEscapedNewlines;
 
   /// Different styles for aligning operands.
-  enum OperandAlignmentStyle : unsigned char {
+  enum OperandAlignmentStyle : int8_t {
 /// Do not align operands of binary and ternary expressions.
 /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
 /// the start of the line.
@@ -567,7 +567,7 @@
 
   /// Different styles for merging short blocks containing at most one
   /// statement.
-  enum ShortBlockStyle : unsigned char {
+  enum ShortBlockStyle : int8_t {
 /// Never merge blocks into a single line.
 /// \code
 ///   while (true) {
@@ -614,7 +614,7 @@
 
   /// Different styles for merging short functions containing at most one
   /// statement.
-  enum ShortFunctionStyle : unsigned char {
+  enum ShortFunctionStyle : int8_t {
 /// Never merge functions into a single line.
 SFS_None,
 /// Only merge functions defined inside a class. Same as "inline",
@@ -666,7 +666,7 @@
   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
 
   /// Different styles for handling short if statements.
-  enum ShortIfStyle : unsigned char {
+  enum ShortIfStyle : int8_t {
 /// Never put short ifs on the same line.
 /// \code
 ///   if (a)
@@ -738,7 +738,7 @@
 
   /// Different styles for merging short lambdas containing at most one
   /// statement.
-  enum ShortLambdaStyle : unsigned char {
+  enum ShortLambdaStyle : int8_t {
 /// Never merge lambdas into a single line.
 SLS_None,
 /// Only merge empty lambdas.
@@ -777,7 +777,7 @@
 
   /// Different ways to break after the function definition return type.
   /// This option is **deprecated** and is retained for backwards compatibility.
-  enum DefinitionReturnTypeBreakingStyle : unsigned char {
+  enum DefinitionReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 DRTBS_None,
@@ -789,7 +789,7 @@
 
   /// Different ways to break after the function definition or
   /// declaration return type.
-  enum ReturnTypeBreakingStyle : unsigned char {
+  enum ReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 /// \code
@@ -883,7 +883,7 @@
   bool AlwaysBreakBeforeMultilineStrings;
 
   /// Different ways to break after the template declaration.
-  enum BreakTemplateDeclarationsStyle : unsigned char {
+  enum BreakTemplateDeclarationsStyle : int8_t {
 /// Do not force break before declaration.
 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
 /// \code
@@ -961,7 +961,7 @@
   bool BinPackArguments;
 
   /// The style of inserting trailing commas into container literals.
-  enum TrailingCommaStyle : unsigned char {
+  enum TrailingCommaStyle : int8_t {
 /// Do not insert trailing commas.
 TCS_None,
 /// Inse

[PATCH] D120398: [format] follow up: Use unsigned char as the base of all enums in FormatStyle

2022-03-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk abandoned this revision.
kwk added a comment.

I abandon this revision in favor of https://reviews.llvm.org/D120884.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120398

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


[PATCH] D120881: [Clang] Diagnose invalid member variable with template parameters

2022-03-03 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 412654.
cor3ntin added a comment.

Fix Formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120881

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/class.cpp


Index: clang/test/SemaCXX/class.cpp
===
--- clang/test/SemaCXX/class.cpp
+++ clang/test/SemaCXX/class.cpp
@@ -208,6 +208,22 @@
 }
 }
 
-struct PR9989 { 
-  static int const PR9989_Member = sizeof PR9989_Member; 
+struct PR9989 {
+  static int const PR9989_Member = sizeof PR9989_Member;
 };
+
+
+namespace GH54151 {
+
+struct S {
+  int i<0>;   // expected-error  {{member 'i' cannot have template arguments}}
+  int j; // expected-error  {{member 'j' cannot have template arguments}}
+};
+
+template 
+struct U {
+  int i; // expected-error {{member 'i' cannot have template arguments}}
+  int j; // expected-error {{member 'j' cannot have template arguments}}
+};
+
+} // namespace GH54151
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3395,6 +3395,15 @@
   return nullptr;
 }
 
+if (isInstField &&
+D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)
+  << II
+  << SourceRange(D.getName().TemplateId->LAngleLoc,
+ D.getName().TemplateId->RAngleLoc)
+  << D.getName().TemplateId->LAngleLoc;
+}
+
 if (SS.isSet() && !SS.isInvalid()) {
   // The user provided a superfluous scope specifier inside a class
   // definition:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4790,6 +4790,7 @@
 def err_template_variable_noparams : Error<
   "extraneous 'template<>' in declaration of variable %0">;
 def err_template_member : Error<"member %0 declared as a template">;
+def err_member_with_template_arguments : Error<"member %0 cannot have template 
arguments">;
 def err_template_member_noparams : Error<
   "extraneous 'template<>' in declaration of member %0">;
 def err_template_tag_noparams : Error<


Index: clang/test/SemaCXX/class.cpp
===
--- clang/test/SemaCXX/class.cpp
+++ clang/test/SemaCXX/class.cpp
@@ -208,6 +208,22 @@
 }
 }
 
-struct PR9989 { 
-  static int const PR9989_Member = sizeof PR9989_Member; 
+struct PR9989 {
+  static int const PR9989_Member = sizeof PR9989_Member;
 };
+
+
+namespace GH54151 {
+
+struct S {
+  int i<0>;   // expected-error  {{member 'i' cannot have template arguments}}
+  int j; // expected-error  {{member 'j' cannot have template arguments}}
+};
+
+template 
+struct U {
+  int i; // expected-error {{member 'i' cannot have template arguments}}
+  int j; // expected-error {{member 'j' cannot have template arguments}}
+};
+
+} // namespace GH54151
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3395,6 +3395,15 @@
   return nullptr;
 }
 
+if (isInstField &&
+D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)
+  << II
+  << SourceRange(D.getName().TemplateId->LAngleLoc,
+ D.getName().TemplateId->RAngleLoc)
+  << D.getName().TemplateId->LAngleLoc;
+}
+
 if (SS.isSet() && !SS.isInvalid()) {
   // The user provided a superfluous scope specifier inside a class
   // definition:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4790,6 +4790,7 @@
 def err_template_variable_noparams : Error<
   "extraneous 'template<>' in declaration of variable %0">;
 def err_template_member : Error<"member %0 declared as a template">;
+def err_member_with_template_arguments : Error<"member %0 cannot have template arguments">;
 def err_template_member_noparams : Error<
   "extraneous 'template<>' in declaration of member %0">;
 def err_template_tag_noparams : Error<
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113545: [C++20] [Module] Support reachable definition initially/partially

2022-03-03 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 412657.
ChuanqiXu added a comment.

Rebase and update tests.


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

https://reviews.llvm.org/D113545

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Basic/Module.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  
clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/Inputs/Friend-in-reachable-class.cppm
  
clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4-friend-in-reachable-class.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
  clang/test/CXX/module/module.interface/Inputs/p7.cppm
  clang/test/CXX/module/module.interface/p2.cpp
  clang/test/CXX/module/module.interface/p7.cpp
  clang/test/CXX/module/module.reach/Inputs/p4/bar.cppm
  clang/test/CXX/module/module.reach/Inputs/p4/foo.cppm
  clang/test/CXX/module/module.reach/Inputs/p5-A.cppm
  clang/test/CXX/module/module.reach/p4/TransitiveImport.cpp
  clang/test/CXX/module/module.reach/p5.cpp
  clang/test/CXX/module/module.unit/p7/t6.cpp
  clang/test/Modules/Inputs/Reachability-Private/Private.cppm
  clang/test/Modules/Inputs/Reachability-func-default-arg/func_default_arg.cppm
  clang/test/Modules/Inputs/Reachability-func-ret/func_ret.cppm
  
clang/test/Modules/Inputs/Reachability-template-default-arg/template_default_arg.cppm
  clang/test/Modules/Inputs/Reachability-template-instantiation/Templ.cppm
  clang/test/Modules/Inputs/Reachability-template-instantiation/Templ.h
  clang/test/Modules/Inputs/Reachability-template-instantiation/Use.cppm
  clang/test/Modules/Inputs/Reachability-using-templates/mod-templates.cppm
  clang/test/Modules/Inputs/Reachability-using/mod.cppm
  clang/test/Modules/Inputs/derived_class/bar.h
  clang/test/Modules/Inputs/derived_class/foo.cppm
  clang/test/Modules/Inputs/explicitly-specialized-template/X.cppm
  clang/test/Modules/Inputs/explicitly-specialized-template/foo.h
  clang/test/Modules/Inputs/template-function-specialization/foo.cppm
  clang/test/Modules/Inputs/template_default_argument/B.cppm
  clang/test/Modules/Inputs/template_default_argument/templ.h
  clang/test/Modules/Reachability-Private.cpp
  clang/test/Modules/Reachability-func-default-arg.cpp
  clang/test/Modules/Reachability-func-ret.cpp
  clang/test/Modules/Reachability-template-default-arg.cpp
  clang/test/Modules/Reachability-template-instantiation.cpp
  clang/test/Modules/Reachability-using-templates.cpp
  clang/test/Modules/Reachability-using.cpp
  clang/test/Modules/cxx20-10-1-ex2.cpp
  clang/test/Modules/derived_class.cpp
  clang/test/Modules/explicitly-specialized-template.cpp
  clang/test/Modules/template-function-specialization.cpp
  clang/test/Modules/template_default_argument.cpp

Index: clang/test/Modules/template_default_argument.cpp
===
--- /dev/null
+++ clang/test/Modules/template_default_argument.cpp
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/template_default_argument/B.cppm --precompile -o %t/B.pcm
+// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -c -o -
+// expected-no-diagnostics
+import B;
+auto foo() {
+  return bar();
+}
Index: clang/test/Modules/template-function-specialization.cpp
===
--- /dev/null
+++ clang/test/Modules/template-function-specialization.cpp
@@ -0,0 +1,18 @@
+// RUN: rm -fr %t
+// RUN: mkdir %t
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %S/Inputs/template-function-specialization/foo.cppm -o %t/foo.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %s -verify -fsyntax-only
+import foo;
+void use() {
+  foo();
+  foo();
+  foo2(); // expected-error {{missing '#include'; 'foo2' must be declared before it is used}}
+ // expected-note@* {{declaration here is not visible}}
+  foo2();   // expected-error {{missing '#include'; 'foo2' must be declared before it is used}}
+ // expected-note@* {{declaration here is not visible}}
+  foo3();
+  foo3();
+
+  foo4();
+  foo4();
+}
Index: clang/test/Modules/explicitly-specialized-template.cpp
===
--- /dev/null
+++ clang/test/Modules/explicitly-specialized-template.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/explicitly-specialized-template/X.cppm --precompile -o %t/X.pcm
+// RUN: %clang -std=c++20 -fprebuilt-module-path=%t %s -fsyntax-only -Xclang -verify -o -
+
+import X;
+foo f; // expected-error {{'foo' must be declared before it 

[PATCH] D120888: [clang] Stop dragging a EndLoc around when parsing attributes

2022-03-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added a reviewer: aaron.ballman.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I noticed that this is basically always unused. And if it is needed, the end of 
the attribute range can be used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120888

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTentative.cpp

Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -1913,7 +1913,7 @@
   /*OuterMightBeMessageSend*/true))
   return TPResult::True;
 
-ParsedAttributes attrs(AttrFactory);
+ParsedAttributesWithRange attrs(AttrFactory);
 MaybeParseMicrosoftAttributes(attrs);
 
 // decl-specifier-seq
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -106,7 +106,7 @@
   // at the start of the statement. Thus, we're not using MaybeParseAttributes
   // here because we don't want to allow arbitrary orderings.
   ParsedAttributesWithRange Attrs(AttrFactory);
-  MaybeParseCXX11Attributes(Attrs, nullptr, /*MightBeObjCMessageSend*/ true);
+  MaybeParseCXX11Attributes(Attrs, /*MightBeObjCMessageSend*/ true);
   if (getLangOpts().OpenCL)
 MaybeParseGNUAttributes(Attrs);
 
@@ -1119,7 +1119,7 @@
 ConsumeToken();
 
   ParsedAttributesWithRange attrs(AttrFactory);
-  MaybeParseCXX11Attributes(attrs, nullptr,
+  MaybeParseCXX11Attributes(attrs,
 /*MightBeObjCMessageSend*/ true);
 
   // If this is the start of a declaration, parse it as such.
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1252,7 +1252,7 @@
   TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
   Actions.PushLambdaScope();
 
-  ParsedAttributes Attr(AttrFactory);
+  ParsedAttributesWithRange Attr(AttrFactory);
   if (getLangOpts().CUDA) {
 // In CUDA code, GNU attributes are allowed to appear immediately after the
 // "[...]", even if there is no "(...)" before the lambda body.
@@ -1355,7 +1355,8 @@
   DeclEndLoc = ESpecRange.getEnd();
 
 // Parse attribute-specifier[opt].
-MaybeParseCXX11Attributes(Attr, &DeclEndLoc);
+if (MaybeParseCXX11Attributes(Attr))
+  DeclEndLoc = Attr.Range.getEnd();
 
 // Parse OpenCL addr space attribute.
 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -4513,19 +4513,17 @@
 ///
 /// attribute-specifier-seq:
 ///   attribute-specifier-seq[opt] attribute-specifier
-void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
-  SourceLocation *endLoc) {
+void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs) {
   assert(standardAttributesAllowed());
 
-  SourceLocation StartLoc = Tok.getLocation(), Loc;
-  if (!endLoc)
-endLoc = &Loc;
+  SourceLocation StartLoc = Tok.getLocation();
+  SourceLocation EndLoc = StartLoc;
 
   do {
-ParseCXX11AttributeSpecifier(attrs, endLoc);
+ParseCXX11AttributeSpecifier(attrs, &EndLoc);
   } while (isCXX11AttributeSpecifier());
 
-  attrs.Range = SourceRange(StartLoc, *endLoc);
+  attrs.Range = SourceRange(StartLoc, EndLoc);
 }
 
 void Parser::DiagnoseAndSkipCXX11Attributes() {
@@ -4658,9 +4656,10 @@
 /// [MS] ms-attribute-seq:
 /// ms-attribute[opt]
 /// ms-attribute ms-attribute-seq
-void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs,
-  SourceLocation *endLoc) {
+void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs) {
   assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list");
+  // FIXME: ParseMicrosoftAttributes() does not support
+  // ParsedAttributesWithRange.
 
   do {
 // FIXME: If this is actually a C++11 attribute, parse it as one.
@@ -4687,8 +4686,6 @@
 }
 
 T.consumeClose();
-if (endLoc)
-  *endLoc = T.getCloseLocation();
   } while (Tok.is(tok::l_square));
 }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -105,7 +105,6 @@
 
 void Parser::ParseAttribute

[PATCH] D120774: [clang-format] Handle builtins in constraint expression

2022-03-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks updated this revision to Diff 412664.
HazardyKnusperkeks added a comment.

More Traits.


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

https://reviews.llvm.org/D120774

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23743,6 +23743,15 @@
   verifyFormat("template \n"
"concept Node = std::is_object_v;");
 
+  verifyFormat("template \n"
+   "concept integral = __is_integral(T);");
+
+  verifyFormat("template \n"
+   "concept is2D = __array_extent(T, 1) == 2;");
+
+  verifyFormat("template \n"
+   "concept isRhs = __is_rvalue_expr(std::declval() + 2)");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3085,6 +3085,13 @@
 return;
   break;
 
+// Get the type traits tokens. Let them behave like any other identifier (which
+// may also be a type trait).
+#define TYPE_TRAIT(N, I, K) case tok::kw_##I:
+#define ARRAY_TYPE_TRAIT(I, E, K) case tok::kw_##I:
+#define EXPRESSION_TRAIT(I, E, K) case tok::kw_##I:
+#include "clang/Basic/TokenKinds.def"
+
 case tok::identifier:
   // We need to differentiate identifiers for a template deduction guide,
   // variables, or function return types (the constraint expression has


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23743,6 +23743,15 @@
   verifyFormat("template \n"
"concept Node = std::is_object_v;");
 
+  verifyFormat("template \n"
+   "concept integral = __is_integral(T);");
+
+  verifyFormat("template \n"
+   "concept is2D = __array_extent(T, 1) == 2;");
+
+  verifyFormat("template \n"
+   "concept isRhs = __is_rvalue_expr(std::declval() + 2)");
+
   auto Style = getLLVMStyle();
   Style.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Allowed;
 
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3085,6 +3085,13 @@
 return;
   break;
 
+// Get the type traits tokens. Let them behave like any other identifier (which
+// may also be a type trait).
+#define TYPE_TRAIT(N, I, K) case tok::kw_##I:
+#define ARRAY_TYPE_TRAIT(I, E, K) case tok::kw_##I:
+#define EXPRESSION_TRAIT(I, E, K) case tok::kw_##I:
+#include "clang/Basic/TokenKinds.def"
+
 case tok::identifier:
   // We need to differentiate identifiers for a template deduction guide,
   // variables, or function return types (the constraint expression has
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120774: [clang-format] Handle builtins in constraint expression

2022-03-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks marked an inline comment as done.
HazardyKnusperkeks added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:23747
+  verifyFormat("template \n"
+   "concept integral = __is_integral(T);");
+

HazardyKnusperkeks wrote:
> curdeius wrote:
> > curdeius wrote:
> > > How about other kinds?
> > > This doesn't seem to work for at least ARRAY_TYPE_TRAIT (e.g. `concept 
> > > OneDimensionalArray = __array_rank(T) == 1;`  and EXPRESSION_TRAIT.
> > > 
> > > Is there a way to be more generic and treat all identifier-like entities 
> > > like identifiers?
> > I'd like to see a test for ALIASes as well, e.g. `__is_same_as`.
> > How about other kinds?
> > This doesn't seem to work for at least ARRAY_TYPE_TRAIT (e.g. `concept 
> > OneDimensionalArray = __array_rank(T) == 1;`  and EXPRESSION_TRAIT.
> 
> I was conservative, since I don't know what these kind of traits are. But 
> sure can add.
> 
> > Is there a way to be more generic and treat all identifier-like entities 
> > like identifiers?
> Not that I know of. There is no such function in `TokenKind.h`.
I have no idea how to handle the aliases, since there are many, and most are no 
traits, not correct here. We could add __is_same_as, as it seems to be the only 
trait alias, directly.


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

https://reviews.llvm.org/D120774

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


[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-03 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Please use the clang-format tag.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120884

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


[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D120884#3356746 , 
@HazardyKnusperkeks wrote:

> Please use the clang-format tag.

Yes, sorry that I forgot it again. And thank you for approving. Shall I wait 
for the others to approve this or land the patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120884

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


[PATCH] D120774: [clang-format] Handle builtins in constraint expression

2022-03-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

Thanks for handling other traits! LGTM % alias test.




Comment at: clang/unittests/Format/FormatTest.cpp:23747
+  verifyFormat("template \n"
+   "concept integral = __is_integral(T);");
+

HazardyKnusperkeks wrote:
> HazardyKnusperkeks wrote:
> > curdeius wrote:
> > > curdeius wrote:
> > > > How about other kinds?
> > > > This doesn't seem to work for at least ARRAY_TYPE_TRAIT (e.g. `concept 
> > > > OneDimensionalArray = __array_rank(T) == 1;`  and EXPRESSION_TRAIT.
> > > > 
> > > > Is there a way to be more generic and treat all identifier-like 
> > > > entities like identifiers?
> > > I'd like to see a test for ALIASes as well, e.g. `__is_same_as`.
> > > How about other kinds?
> > > This doesn't seem to work for at least ARRAY_TYPE_TRAIT (e.g. `concept 
> > > OneDimensionalArray = __array_rank(T) == 1;`  and EXPRESSION_TRAIT.
> > 
> > I was conservative, since I don't know what these kind of traits are. But 
> > sure can add.
> > 
> > > Is there a way to be more generic and treat all identifier-like entities 
> > > like identifiers?
> > Not that I know of. There is no such function in `TokenKind.h`.
> I have no idea how to handle the aliases, since there are many, and most are 
> no traits, not correct here. We could add __is_same_as, as it seems to be the 
> only trait alias, directly.
I don't think you need to treat them specially, they should behave as their 
aliased entity actually. But please test at least one.


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

https://reviews.llvm.org/D120774

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


[PATCH] D120824: [clang][ASTImporter] Fix a bug when importing CXXDefaultInitExpr.

2022-03-03 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 412665.
balazske added a comment.

Improved the test to fix failure on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120824

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/test/Analysis/Inputs/ctu-cxxdefaultinitexpr-import.cpp
  
clang/test/Analysis/Inputs/ctu-cxxdefaultinitexpr-import.cpp.externalDefMap.ast-dump.txt
  clang/test/Analysis/ctu-cxxdefaultinitexpr.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -530,6 +530,21 @@
has(floatLiteral(equals(1.0);
 }
 
+const internal::VariadicDynCastAllOfMatcher
+cxxDefaultInitExpr;
+
+TEST_P(ImportExpr, ImportCXXDefaultInitExpr) {
+  MatchVerifier Verifier;
+  testImport("class declToImport { int DefInit = 5; }; declToImport X;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ cxxRecordDecl(hasDescendant(cxxConstructorDecl(
+ hasAnyConstructorInitializer(cxxCtorInitializer(
+ withInitializer(cxxDefaultInitExpr(;
+  testImport(
+  "struct X { int A = 5; }; X declToImport{};", Lang_CXX17, "", Lang_CXX17,
+  Verifier,
+  varDecl(hasInitializer(initListExpr(hasInit(0, cxxDefaultInitExpr());
+}
 
 const internal::VariadicDynCastAllOfMatcher vaArgExpr;
 
Index: clang/test/Analysis/ctu-cxxdefaultinitexpr.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-cxxdefaultinitexpr.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -std=c++17 \
+// RUN:   -emit-pch -o %t/ctudir/ctu-cxxdefaultinitexpr-import.cpp.ast %S/Inputs/ctu-cxxdefaultinitexpr-import.cpp
+// RUN: cp %S/Inputs/ctu-cxxdefaultinitexpr-import.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -std=c++17 -analyze \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -verify %s
+
+// Check that importing this code does not cause crash.
+// expected-no-diagnostics
+
+namespace QHashPrivate {
+template  int b;
+struct Data;
+} // namespace QHashPrivate
+
+struct QDomNodePrivate {};
+template  struct QMultiHash {
+  QHashPrivate::Data *d = nullptr;
+};
+
+struct QDomNamedNodeMapPrivate {
+  QMultiHash<> map;
+};
+struct QDomElementPrivate : QDomNodePrivate {
+  QDomElementPrivate();
+  void importee();
+  QMultiHash<> *m_attr = nullptr;
+};
+// - common part end -
+
+void importer(QDomElementPrivate x) { x.importee(); }
Index: clang/test/Analysis/Inputs/ctu-cxxdefaultinitexpr-import.cpp.externalDefMap.ast-dump.txt
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-cxxdefaultinitexpr-import.cpp.externalDefMap.ast-dump.txt
@@ -0,0 +1,4 @@
+c:@S@foo@value ctu-cxxdefaultinitexpr-import.cpp.ast
+c:@S@QDomElementPrivate@F@importee# ctu-cxxdefaultinitexpr-import.cpp.ast
+c:@S@QDomElementPrivate@F@QDomElementPrivate# ctu-cxxdefaultinitexpr-import.cpp.ast
+c:@S@QDomNodePrivate@F@QDomNodePrivate# ctu-cxxdefaultinitexpr-import.cpp.ast
Index: clang/test/Analysis/Inputs/ctu-cxxdefaultinitexpr-import.cpp
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-cxxdefaultinitexpr-import.cpp
@@ -0,0 +1,26 @@
+namespace QHashPrivate {
+template  int b;
+struct Data;
+} // namespace QHashPrivate
+
+struct QDomNodePrivate {};
+template  struct QMultiHash {
+  QHashPrivate::Data *d = nullptr;
+};
+
+struct QDomNamedNodeMapPrivate {
+  QMultiHash<> map;
+};
+struct QDomElementPrivate : QDomNodePrivate {
+  QDomElementPrivate();
+  void importee();
+  QMultiHash<> *m_attr = nullptr;
+};
+// - common part end -
+
+QDomElementPrivate::QDomElementPrivate() : m_attr{new QMultiHash<>} {}
+void QDomElementPrivate::importee() { (void)QMultiHash<>{}; }
+struct foo {
+  QDomElementPrivate m = {};
+  static const int value = (QHashPrivate::b, 22);
+};
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3646,19 +3646,23 @@
 // initializer of a FieldDecl might not had been instantiated in the
 // "To" context.  However, the "From" context might instantiated that,
 // thus we have to merge that.
+// Note: `hasInClassInitializer()` is not the same as non-null
+// `getInClassInitializer()` value.
 if (Expr *FromInitializer = D->getInClassInitializer()) {
-

[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: sgatev.
Herald added subscribers: tschuett, steakhal, mgrang, mgorny.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

This patch adds a simpe lattice used to collect source loctions. An intended 
application is to track errors found in code during an analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120890

Files:
  clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp
@@ -0,0 +1,68 @@
+//===- unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/SourceLocationsLattice.h"
+
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Basic/SourceLocation.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace dataflow {
+namespace {
+
+TEST(SourceLocationsLatticeTest, Comparison) {
+  const SourceLocationsLattice Bottom;
+  const SourceLocationsLattice NonBottom(
+  {clang::SourceLocation::getFromRawEncoding(0)});
+
+  EXPECT_TRUE(Bottom == Bottom);
+  EXPECT_FALSE(Bottom == NonBottom);
+  EXPECT_FALSE(NonBottom == Bottom);
+  EXPECT_TRUE(NonBottom == NonBottom);
+
+  EXPECT_FALSE(Bottom != Bottom);
+  EXPECT_TRUE(Bottom != NonBottom);
+  EXPECT_TRUE(NonBottom != Bottom);
+  EXPECT_FALSE(NonBottom != NonBottom);
+}
+
+TEST(SourceLocationsLatticeTest, Join) {
+  const SourceLocationsLattice Bottom;
+  const SourceLocationsLattice NonBottom(
+  {clang::SourceLocation::getFromRawEncoding(0)});
+  {
+SourceLocationsLattice LHS = Bottom;
+const SourceLocationsLattice RHS = Bottom;
+EXPECT_EQ(LHS.join(RHS), clang::dataflow::LatticeJoinEffect::Unchanged);
+EXPECT_EQ(LHS, Bottom);
+  }
+  {
+SourceLocationsLattice LHS = NonBottom;
+const SourceLocationsLattice RHS = Bottom;
+EXPECT_EQ(LHS.join(RHS), clang::dataflow::LatticeJoinEffect::Unchanged);
+EXPECT_EQ(LHS, NonBottom);
+  }
+  {
+SourceLocationsLattice LHS = Bottom;
+const SourceLocationsLattice RHS = NonBottom;
+EXPECT_EQ(LHS.join(RHS), clang::dataflow::LatticeJoinEffect::Changed);
+EXPECT_EQ(LHS, NonBottom);
+  }
+  {
+SourceLocationsLattice LHS = NonBottom;
+const SourceLocationsLattice RHS = NonBottom;
+EXPECT_EQ(LHS.join(RHS), clang::dataflow::LatticeJoinEffect::Unchanged);
+EXPECT_EQ(LHS, NonBottom);
+  }
+}
+
+} // namespace
+} // namespace dataflow
+} // namespace clang
Index: clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
===
--- clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
+++ clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
@@ -9,6 +9,7 @@
   MapLatticeTest.cpp
   MultiVarConstantPropagationTest.cpp
   SingleVarConstantPropagationTest.cpp
+  SourceLocationsLatticeTest.cpp
   TestingSupport.cpp
   TestingSupportTest.cpp
   TransferTest.cpp
Index: clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
===
--- /dev/null
+++ clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
@@ -0,0 +1,51 @@
+//===- SourceLocationsLattice.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file implements a lattice that collects source locations of interest.
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/SourceLocationsLattice.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace dataflow {
+
+LatticeJoinEffect
+SourceLocationsLattice::join(const SourceLocationsLattice &Other) {
+  auto SizeBefore = Locs.size();
+  Locs.insert(Other.Locs.begin(), Other.Locs.end());
+  ret

[PATCH] D118352: [clang][ABI] New c++20 modules mangling scheme

2022-03-03 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan updated this revision to Diff 412669.
urnathan added a comment.
Herald added a project: All.

Updated to new partitions API


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

https://reviews.llvm.org/D118352

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cpp
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/module.cppm
  clang/test/CXX/modules-ts/basic/basic.def.odr/p4/user.cpp
  clang/test/CXX/modules-ts/basic/basic.link/p3.cppm
  clang/test/CXX/modules-ts/codegen-basics.cppm
  clang/test/CodeGenCXX/Inputs/cxx20-module-impl-1a.cpp
  clang/test/CodeGenCXX/Inputs/cxx20-module-std-subst-2a.cpp
  clang/test/CodeGenCXX/cxx20-module-decomp-1.cpp
  clang/test/CodeGenCXX/cxx20-module-extern-1.cppm
  clang/test/CodeGenCXX/cxx20-module-impl-1a.cpp
  clang/test/CodeGenCXX/cxx20-module-nested-1.cppm
  clang/test/CodeGenCXX/cxx20-module-nested-2.cppm
  clang/test/CodeGenCXX/cxx20-module-std-subst-1.cppm
  clang/test/CodeGenCXX/cxx20-module-std-subst-2b.cpp
  clang/test/CodeGenCXX/cxx20-module-std-subst-2c.cpp
  clang/test/CodeGenCXX/cxx20-module-sub-1a.cppm
  clang/test/CodeGenCXX/cxx20-module-sub-1b.cppm
  clang/test/CodeGenCXX/cxx20-module-tmpl-1.cppm

Index: clang/test/CodeGenCXX/cxx20-module-tmpl-1.cppm
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-tmpl-1.cppm
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s
+
+export module FOO;
+
+class One;
+class Two;
+
+export template struct TPL
+{
+void M (T *);
+template void N (T *, U*);
+};
+
+template
+void TPL::M (T *) {}
+
+template template void TPL::N (T *, U*) {}
+
+// CHECK-DAG: void @_ZNW3FOO3TPLIS_3OneE1MEPS1_(
+template void TPL::M (One *);
+// CHECK-DAG: void @_ZNW3FOO3TPLIS_3OneE1NIS_3TwoEEvPS1_PT_(
+template void TPL::N (One *, Two *);
+
+namespace NMS {
+class One;
+class Two;
+
+export template struct TPL
+{
+void M (T *);
+template void N (T *, U*);
+};
+
+template
+void TPL::M (T *) {}
+
+template template void TPL::N (T *, U*) {}
+
+// CHECK-DAG: void @_ZN3NMSW3FOO3TPLINS_S0_3OneEE1MEPS2_(
+template void TPL::M (One *);
+// CHECK-DAG: void @_ZN3NMSW3FOO3TPLINS_S0_3OneEE1NINS_S0_3TwoEEEvPS2_PT_
+template void TPL::N (One *, Two *);
+}
Index: clang/test/CodeGenCXX/cxx20-module-sub-1b.cppm
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-sub-1b.cppm
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 %S/cxx20-module-sub-1a.cppm -triple %itanium_abi_triple -emit-module-interface -o %t
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s
+
+export module FOO.BAZ;
+import FOO.BAR;
+
+namespace Bob {
+
+// CHECK-DAG: void @_ZN3BobW3FOOW3BAZ3FooEPS0_W3BAR1APNS_S2_1BE(
+void Foo (A *, B*) {
+}
+}
+
+// CHECK-DAG: void @_ZW3FOOW3BAZ3BarPS_W3BAR1APN3BobS1_1BE(
+void Bar (A *, Bob::B*) {
+}
Index: clang/test/CodeGenCXX/cxx20-module-sub-1a.cppm
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-sub-1a.cppm
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %s
+
+export module FOO.BAR;
+export class A;
+namespace Bob {
+export class B;
+
+// CHECK-DAG: void @_ZN3BobW3FOOW3BAR3BarEPS1_1APNS_S1_1BE(
+export void Bar (A *, B*) {
+}
+}
+
+// CHECK-DAG: void @_ZW3FOOW3BAR3FooPS0_1APN3BobS0_1BE(
+export void Foo (A *, Bob::B*) {
+}
Index: clang/test/CodeGenCXX/cxx20-module-std-subst-2c.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-std-subst-2c.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++20 %S/Inputs/cxx20-module-std-subst-2a.cpp -triple %itanium_abi_triple -emit-module-interface -o %t
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s
+module;
+# 5 __FILE__ 1
+namespace std {
+template  struct char_traits {};
+} // namespace std
+# 9 "" 2
+export module Bar;
+import RenameString;
+
+// Use Sb as this is global-module std::char_traits
+// CHECK-DAG: void @_ZW3Bar1gRSs(
+void g(str> &s) {
+}
Index: clang/test/CodeGenCXX/cxx20-module-std-subst-2b.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx20-module-std-subst-2b.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++20 %S/Inputs/cxx20-module-std-subst-2a.cpp -triple %itanium_abi_triple -emit-module-interface -o %t
+// RUN: %clang_cc1 -std=c++20 %s -triple %itanium_abi_triple -fmodule-file=%t -emit-llvm -o - | FileCheck %s
+
+export module Foo;
+import RenameString;
+
+namespace std {
+template  struct char_traits {};
+} // namespace std
+
+// use Sb mangling, not Ss as this is not global-module std::char

[PATCH] D120723: [pseudo] Fix an out-of-bound error in LRTable::find.

2022-03-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.
Herald added a subscriber: alextsao1999.

I'm seeing debug failures again on Windows after this.

  FAIL: Clang :: Syntax/lr-build-conflicts.test (14728 of 14729)
   TEST 'Clang :: Syntax/lr-build-conflicts.test' FAILED 

  Script:
  --
  : 'RUN: at line 5';   clang-pseudo -grammar 
F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test -print-graph | 
f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test 
--check-prefix=GRAPH
  : 'RUN: at line 30';   clang-pseudo -grammar 
F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test -print-table | 
f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test 
--check-prefix=TABLE
  --
  Exit Code: 2
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 5"
  $ "clang-pseudo" "-grammar" 
"F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" 
"-print-graph"
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
"F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" 
"--check-prefix=GRAPH"
  $ ":" "RUN: at line 30"
  $ "clang-pseudo" "-grammar" 
"F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" 
"-print-table"
  note: command had no output on stdout or stderr
  error: command failed with exit status: 3221226505
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
"F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" 
"--check-prefix=TABLE"
  # command stderr:
  FileCheck error: '' is empty.
  FileCheck command line:  
f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test 
--check-prefix=TABLE
  
  error: command failed with exit status: 2
  
  --
  
  
  Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
  FAIL: Clang :: Syntax/lr-build-basic.test (14729 of 14729)
   TEST 'Clang :: Syntax/lr-build-basic.test' FAILED 

  Script:
  --
  : 'RUN: at line 5';   clang-pseudo -grammar 
F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test -print-graph | 
f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test 
--check-prefix=GRAPH
  : 'RUN: at line 18';   clang-pseudo -grammar 
F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test -print-table | 
f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test 
--check-prefix=TABLE
  --
  Exit Code: 2
  
  Command Output (stdout):
  --
  $ ":" "RUN: at line 5"
  $ "clang-pseudo" "-grammar" 
"F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "-print-graph"
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
"F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" 
"--check-prefix=GRAPH"
  $ ":" "RUN: at line 18"
  $ "clang-pseudo" "-grammar" 
"F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "-print-table"
  note: command had no output on stdout or stderr
  error: command failed with exit status: 3221226505
  $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
"F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" 
"--check-prefix=TABLE"
  # command stderr:
  FileCheck error: '' is empty.
  FileCheck command line:  
f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test 
--check-prefix=TABLE
  
  error: command failed with exit status: 2
  
  --
  
  
  Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
  
  Failed Tests (2):
Clang :: Syntax/lr-build-basic.test
Clang :: Syntax/lr-build-conflicts.test
  
  
  Testing Time: 336.94s
Unsupported  :  1727
Passed   : 12972
Expectedly Failed:28
Failed   : 2

It looks to be another index out of bounds assert with the MSVC STL debug 
iterators. Can you fix or revert?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120723

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


[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev accepted this revision.
sgatev added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h:13
+
+#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SOURCELOCATIONS_LATTICE_H_
+#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_SOURCELOCATIONS_LATTICE_H_

Remove the last `_` for consistency with the other headers.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h:46
+
+  llvm::DenseSet &getSourceLocations() { return Locs; }
+  const llvm::DenseSet &getSourceLocations() const {

Add an empty line after this member to separate it from the next?



Comment at: clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp:45
+  std::string result;
+  llvm::raw_string_ostream Os(result);
+  llvm::interleaveComma(Locations, Os);

Call this `OS`? It seems to be common.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120890

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


[PATCH] D120824: [clang][ASTImporter] Fix a bug when importing CXXDefaultInitExpr.

2022-03-03 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Looks good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120824

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


[PATCH] D120774: [clang-format] Handle builtins in constraint expression

2022-03-03 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:3090-3093
+#define TYPE_TRAIT(N, I, K) case tok::kw_##I:
+#define ARRAY_TYPE_TRAIT(I, E, K) case tok::kw_##I:
+#define EXPRESSION_TRAIT(I, E, K) case tok::kw_##I:
+#include "clang/Basic/TokenKinds.def"

Instead, you can fold `case tok::identifier:` below into `default:` like this:
```
default:
  if (!FormatTok->Tok.getIdentifierInfo())
return;

  // We need to differentiate identifiers for a template deduction guide,
  ...
```


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

https://reviews.llvm.org/D120774

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


[clang] 1aa608a - [clang-format] Handle wrapped else for RemoveBracesLLVM

2022-03-03 Thread via cfe-commits

Author: owenca
Date: 2022-03-03T04:53:15-08:00
New Revision: 1aa608a0208bc6a6945550a2071285ab51d899f1

URL: 
https://github.com/llvm/llvm-project/commit/1aa608a0208bc6a6945550a2071285ab51d899f1
DIFF: 
https://github.com/llvm/llvm-project/commit/1aa608a0208bc6a6945550a2071285ab51d899f1.diff

LOG: [clang-format] Handle wrapped else for RemoveBracesLLVM

Removes the newline before the right brace that's followed by an
else on the next line.

Differential Revision: https://reviews.llvm.org/D120873

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c12096dc93ba8..497ebb414384f 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1812,9 +1812,12 @@ class BracesRemover : public TokenAnalyzer {
 if (!Token->Optional)
   continue;
 assert(Token->isOneOf(tok::l_brace, tok::r_brace));
-const auto Start = Token == Line->Last
-   ? Token->WhitespaceRange.getBegin()
-   : Token->Tok.getLocation();
+assert(Token->Next || Token == Line->Last);
+const auto Start =
+Token == Line->Last || (Token->Next->is(tok::kw_else) &&
+Token->Next->NewlinesBefore > 0)
+? Token->WhitespaceRange.getBegin()
+: Token->Tok.getLocation();
 const auto Range =
 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
 cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 94f6dea1a2ed4..6c2b00b97ed3c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24974,6 +24974,20 @@ TEST_F(FormatTest, RemoveBraces) {
"};",
Style);
 
+  verifyFormat("if (a)\n"
+   "  foo();\n"
+   "else\n"
+   "  bar();",
+   "if (a)\n"
+   "{\n"
+   "  foo();\n"
+   "}\n"
+   "else\n"
+   "{\n"
+   "  bar();\n"
+   "}",
+   Style);
+
   // FIXME: See https://github.com/llvm/llvm-project/issues/53543.
 #if 0
   Style.ColumnLimit = 65;



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


[PATCH] D120873: [clang-format] Handle wrapped else for RemoveBracesLLVM

2022-03-03 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1aa608a0208b: [clang-format] Handle wrapped else for 
RemoveBracesLLVM (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120873

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24974,6 +24974,20 @@
"};",
Style);
 
+  verifyFormat("if (a)\n"
+   "  foo();\n"
+   "else\n"
+   "  bar();",
+   "if (a)\n"
+   "{\n"
+   "  foo();\n"
+   "}\n"
+   "else\n"
+   "{\n"
+   "  bar();\n"
+   "}",
+   Style);
+
   // FIXME: See https://github.com/llvm/llvm-project/issues/53543.
 #if 0
   Style.ColumnLimit = 65;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1812,9 +1812,12 @@
 if (!Token->Optional)
   continue;
 assert(Token->isOneOf(tok::l_brace, tok::r_brace));
-const auto Start = Token == Line->Last
-   ? Token->WhitespaceRange.getBegin()
-   : Token->Tok.getLocation();
+assert(Token->Next || Token == Line->Last);
+const auto Start =
+Token == Line->Last || (Token->Next->is(tok::kw_else) &&
+Token->Next->NewlinesBefore > 0)
+? Token->WhitespaceRange.getBegin()
+: Token->Tok.getLocation();
 const auto Range =
 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
 cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24974,6 +24974,20 @@
"};",
Style);
 
+  verifyFormat("if (a)\n"
+   "  foo();\n"
+   "else\n"
+   "  bar();",
+   "if (a)\n"
+   "{\n"
+   "  foo();\n"
+   "}\n"
+   "else\n"
+   "{\n"
+   "  bar();\n"
+   "}",
+   Style);
+
   // FIXME: See https://github.com/llvm/llvm-project/issues/53543.
 #if 0
   Style.ColumnLimit = 65;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1812,9 +1812,12 @@
 if (!Token->Optional)
   continue;
 assert(Token->isOneOf(tok::l_brace, tok::r_brace));
-const auto Start = Token == Line->Last
-   ? Token->WhitespaceRange.getBegin()
-   : Token->Tok.getLocation();
+assert(Token->Next || Token == Line->Last);
+const auto Start =
+Token == Line->Last || (Token->Next->is(tok::kw_else) &&
+Token->Next->NewlinesBefore > 0)
+? Token->WhitespaceRange.getBegin()
+: Token->Tok.getLocation();
 const auto Range =
 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
 cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120874: [C++20] [Modules] Use '-' as the separator of partitions when searching in filesystems

2022-03-03 Thread Iain Sandoe via Phabricator via cfe-commits
iains added inline comments.



Comment at: clang/test/Modules/search-partitions.cppm:20
+//--- partition1.cpp
+export module A : Part1;
+

ChuanqiXu wrote:
> @MyDeveloperDay hi, I remember the support for partitions in clang-format is 
> done in https://reviews.llvm.org/D114151. I think I did something wrong. I 
> format my code with the following command in the root directory of llvm 
> project:
> ```
> git diff -U0 --no-color --relative HEAD^ | 
> clang/tools/clang-format/clang-format-diff.py -p1 -i
> ```
> 
> Would it use an out-dated clang-format? If yes, how should I use the proper 
> one. Or if is it possible that the `.clang-format` files is not updated 
> correctly?
FWIW, I have been using `git clang-format  ` with llvm-14 clang-format in 
my PATH and it seems to work OK there - but not for llvm <= 13 (on macOS 10.15).



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120874

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


[PATCH] D119609: [Clang][Sema] Don't act on ReturnStmt when parsing the lambda declarator.

2022-03-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D119609#3355878 , @junaire wrote:

> Frankly speaking, this is really a randomly written patch, and I have never 
> thought it would raise so much concern. But I believe I can handle it if you 
> guys can give me some trust and little guidance! <3

We're happy to help!

> In D119609#3355409 , @aaron.ballman 
> wrote:
>
>> Thank you for looking into this! I'm not certain this is the correct 
>> approach, however. The comment on the function is:
>>
>>   /// ActOnCapScopeReturnStmt - Utility routine to type-check return 
>> statements
>>   /// for capturing scopes.
>>
>> however, there's not a capture scope in the test case -- the GNU expression 
>> statement is within the parameter list, which can't capture anything: 
>> https://godbolt.org/z/3KrEx8hEW. I think the issue might be whatever causes 
>> us to call `ActOnCapScopeReturnStmt()`  in the first place.
>
> Yes, you're correct. From the call stack we can see:
>
>   clang::Sema::ActOnCapScopeReturnStmt
>   clang::Sema::BuildReturnStmt // bad things happened here :(
>   clang::Sema::ActOnReturnStmt
>   
>   clang::Parser::ParseStatementOrDeclarationAfterAttributes
>   clang::Parser::ParseStatementOrDeclaration
>   clang::Parser::ParseCompoundStatementBody
>   clang::Parser::ParseCompoundStatement
>   clang::Parser::ParseParenExpression
>   clang::Parser::ParseCastExpression
>   clang::Parser::ParseCastExpression
>   clang::Parser::ParseAssignmentExpression
>   clang::Parser::ParseParameterDeclarationClause
>   
>   clang::Parser::ParseLambdaExpressionAfterIntroducer
>
> When clang is parsing a lambda and hit a `ReturnStmt`,  it will do something 
> like:
>
>   if (isa(getCurFunction()))
> return ActOnCapScopeReturnStmt(ReturnLoc, RetValExp, NRInfo,
>SupressSimplerImplicitMoves);
>
> However, in this case, though what `getCurFunction()` returns is a 
> `CapturingScopeInfo`, we're not finished building the lambda! so clang will 
> crash when we try to use its `CallOperator`:
>
>   bool HasDeducedReturnType =
>   CurLambda && hasDeducedReturnType(CurLambda->CallOperator);
>
> So my original patch is to add an extra check when we decide to jump into 
> `ActOnCapScopeReturnStmt`, however, I can't pass all the tests. Then I 
> discovered that `CurLambda` can be `nullptr`, and we still need to call 
> `ActOnCapScopeReurnStmt`, so I changed my patch. I'm not really sure why this 
> would happen, maybe I need to dig into the code more.

Thanks for the explanation! Looking at `BuildReturnStmt()`, I now see why we're 
getting into this capturing return statement.

>> But there's a design question there as to whether expression statements in a 
>> lambda default parameter value makes sense *at all*, because the lambda is 
>> an object that can be passed around to others to call. e.g., 
>> https://godbolt.org/z/3Edeqv9qv
>
> Not sure about this, but at least gcc accepts code below:
>
>   void g() {
> auto whatever = [=](int foo = ({ return;5; })) {};
>   }
>
> I agree to listen to what gcc folks think about it.

I'm not certain they intended this to work as they give some interesting 
diagnostics before crashing: https://godbolt.org/z/nWTGEc1dW. I added that 
information to the bug report, but it seems to be gaining steam for rejecting 
the use of a statement expression in a lambda's default argument.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119609

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


[PATCH] D120723: [pseudo] Fix an out-of-bound error in LRTable::find.

2022-03-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D120723#3356831 , @aaron.ballman 
wrote:

> I'm seeing debug failures again on Windows after this.
>
>   FAIL: Clang :: Syntax/lr-build-conflicts.test (14728 of 14729)
>    TEST 'Clang :: Syntax/lr-build-conflicts.test' FAILED 
> 
>   Script:
>   --
>   : 'RUN: at line 5';   clang-pseudo -grammar 
> F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test -print-graph 
> | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
> F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test 
> --check-prefix=GRAPH
>   : 'RUN: at line 30';   clang-pseudo -grammar 
> F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test -print-table 
> | f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
> F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test 
> --check-prefix=TABLE
>   --
>   Exit Code: 2
>   
>   Command Output (stdout):
>   --
>   $ ":" "RUN: at line 5"
>   $ "clang-pseudo" "-grammar" 
> "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" 
> "-print-graph"
>   $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
> "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" 
> "--check-prefix=GRAPH"
>   $ ":" "RUN: at line 30"
>   $ "clang-pseudo" "-grammar" 
> "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" 
> "-print-table"
>   note: command had no output on stdout or stderr
>   error: command failed with exit status: 3221226505
>   $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
> "F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test" 
> "--check-prefix=TABLE"
>   # command stderr:
>   FileCheck error: '' is empty.
>   FileCheck command line:  
> f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
> F:\source\llvm-project\clang\test\Syntax\lr-build-conflicts.test 
> --check-prefix=TABLE
>   
>   error: command failed with exit status: 2
>   
>   --
>   
>   
>   Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
>   FAIL: Clang :: Syntax/lr-build-basic.test (14729 of 14729)
>    TEST 'Clang :: Syntax/lr-build-basic.test' FAILED 
> 
>   Script:
>   --
>   : 'RUN: at line 5';   clang-pseudo -grammar 
> F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test -print-graph | 
> f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
> F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test 
> --check-prefix=GRAPH
>   : 'RUN: at line 18';   clang-pseudo -grammar 
> F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test -print-table | 
> f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
> F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test 
> --check-prefix=TABLE
>   --
>   Exit Code: 2
>   
>   Command Output (stdout):
>   --
>   $ ":" "RUN: at line 5"
>   $ "clang-pseudo" "-grammar" 
> "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "-print-graph"
>   $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
> "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" 
> "--check-prefix=GRAPH"
>   $ ":" "RUN: at line 18"
>   $ "clang-pseudo" "-grammar" 
> "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" "-print-table"
>   note: command had no output on stdout or stderr
>   error: command failed with exit status: 3221226505
>   $ "f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe" 
> "F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test" 
> "--check-prefix=TABLE"
>   # command stderr:
>   FileCheck error: '' is empty.
>   FileCheck command line:  
> f:\source\llvm-project\llvm\out\build\x64-debug\bin\filecheck.exe 
> F:\source\llvm-project\clang\test\Syntax\lr-build-basic.test 
> --check-prefix=TABLE
>   
>   error: command failed with exit status: 2
>   
>   --
>   
>   
>   Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
>   
>   Failed Tests (2):
> Clang :: Syntax/lr-build-basic.test
> Clang :: Syntax/lr-build-conflicts.test
>   
>   
>   Testing Time: 336.94s
> Unsupported  :  1727
> Passed   : 12972
> Expectedly Failed:28
> Failed   : 2
>
> It looks to be another index out of bounds assert with the MSVC STL debug 
> iterators. Can you fix or revert?

oops.. sorry. Looking at it now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120723

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


[PATCH] D120881: [Clang] Diagnose invalid member variable with template parameters

2022-03-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for looking into this, that's a rather amusing bug.




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:3398-3399
 
+if (isInstField &&
+D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)

No need to look at `isInstField`, it's already tested above on line 3365.



Comment at: clang/test/SemaCXX/class.cpp:219
+struct S {
+  int i<0>;   // expected-error  {{member 'i' cannot have template arguments}}
+  int j; // expected-error  {{member 'j' cannot have template arguments}}

Can you also add test cases for:
```
static int k<12>;
void f<12>();
```
To make sure we diagnose it the same way, both in a non-template class and 
within a templated class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120881

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


[clang] 28ccf32 - [pseudo] Fix an out-of-bound access for LRTable::Actions.

2022-03-03 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-03-03T14:27:44+01:00
New Revision: 28ccf326725d0fea8648834c8acdbdfe3aa40d7a

URL: 
https://github.com/llvm/llvm-project/commit/28ccf326725d0fea8648834c8acdbdfe3aa40d7a
DIFF: 
https://github.com/llvm/llvm-project/commit/28ccf326725d0fea8648834c8acdbdfe3aa40d7a.diff

LOG: [pseudo] Fix an out-of-bound access for LRTable::Actions.

Without this patch, when End == Start, we access Actions[Actions.end()]
though we return an empty result.
This fixes an assertion failure in MSVC STL debug build.

Added: 


Modified: 
clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp 
b/clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp
index 4f1494fff277d..957d17a503cf0 100644
--- a/clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp
+++ b/clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp
@@ -112,6 +112,8 @@ llvm::ArrayRef LRTable::find(StateID Src, 
SymbolID ID) const {
  "subrange of the StateIdx should be sorted!");
   const LRTable::StateID *Start = llvm::partition_point(
   TargetedStates, [&Src](LRTable::StateID S) { return S < Src; });
+  if (Start == TargetedStates.end())
+return {};
   const LRTable::StateID *End = Start;
   while (End != TargetedStates.end() && *End == Src)
 ++End;



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


[PATCH] D120723: [pseudo] Fix an out-of-bound error in LRTable::find.

2022-03-03 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Fixed in 28ccf326725d0fea8648834c8acdbdfe3aa40d7a 
.




Comment at: clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp:115
   TargetedStates, [&Src](LRTable::StateID S) { return S < Src; });
-  if (It == TargetedStates.end())
+  if (Start == TargetedStates.end())
 return {};

sammccall wrote:
> I think this check is no longer needed
sorry, should have thought more carefully on this comment, we need this check 
to make sure we don't access `Actions[Actions.end()]` on Line120 below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120723

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


[PATCH] D114235: [clang] Extend ParsedAttr to allow custom handling for type attributes

2022-03-03 Thread Martin Böhme via Phabricator via cfe-commits
mboehme abandoned this revision.
mboehme added a comment.
Herald added a project: All.

Thanks for all of the input!

Rather than going deeper into the discussion of the attribute here (on an only 
vaguely related change), I think it would be better to continue the discussion 
on the forum.

I'm currently in the process of writing up an RFC and will add a link here once 
I've published it. That RFC will also contain a link to a second RFC that 
describes our intended use case for the attribute in detail.

As I have come to the conclusion that I'd like to pursue a proposal for a new 
attribute rather than extending `ParsedAttr to allow custom handling for type 
attributes` (which is what this change is about), I'll retract this change from 
review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114235

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


[PATCH] D120881: [Clang] Diagnose invalid member variable with template parameters

2022-03-03 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 412689.
cor3ntin added a comment.

- Fix redundant check
- move test to p17.cpp which seems more approriate
- add a couple of tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120881

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp


Index: clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
===
--- clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
+++ clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
@@ -32,3 +32,23 @@
   template <> int AB::foo = 0; // expected-error{{extraneous 'template<>'}}
   int AB::bar = 1;
 }
+
+namespace GH54151 {
+
+struct S {
+  int i<0>;   // expected-error  {{member 'i' cannot have template arguments}}
+  int j; // expected-error  {{member 'j' cannot have template arguments}}
+
+  static int k<12>; // expected-error {{template specialization requires 
'template<>'}} \
+   expected-error{{no variable template matches 
specialization}}
+  void f<12>(); // expected-error {{template specialization requires 
'template<>'}} \
+// expected-error {{no function template matches function 
template specialization 'f'}}
+};
+
+template 
+struct U {
+  int i; // expected-error {{member 'i' cannot have template arguments}}
+  int j; // expected-error {{member 'j' cannot have template arguments}}
+};
+
+} // namespace GH54151
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3395,6 +3395,14 @@
   return nullptr;
 }
 
+if (D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)
+  << II
+  << SourceRange(D.getName().TemplateId->LAngleLoc,
+ D.getName().TemplateId->RAngleLoc)
+  << D.getName().TemplateId->LAngleLoc;
+}
+
 if (SS.isSet() && !SS.isInvalid()) {
   // The user provided a superfluous scope specifier inside a class
   // definition:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4790,6 +4790,7 @@
 def err_template_variable_noparams : Error<
   "extraneous 'template<>' in declaration of variable %0">;
 def err_template_member : Error<"member %0 declared as a template">;
+def err_member_with_template_arguments : Error<"member %0 cannot have template 
arguments">;
 def err_template_member_noparams : Error<
   "extraneous 'template<>' in declaration of member %0">;
 def err_template_tag_noparams : Error<


Index: clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
===
--- clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
+++ clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
@@ -32,3 +32,23 @@
   template <> int AB::foo = 0; // expected-error{{extraneous 'template<>'}}
   int AB::bar = 1;
 }
+
+namespace GH54151 {
+
+struct S {
+  int i<0>;   // expected-error  {{member 'i' cannot have template arguments}}
+  int j; // expected-error  {{member 'j' cannot have template arguments}}
+
+  static int k<12>; // expected-error {{template specialization requires 'template<>'}} \
+   expected-error{{no variable template matches specialization}}
+  void f<12>(); // expected-error {{template specialization requires 'template<>'}} \
+// expected-error {{no function template matches function template specialization 'f'}}
+};
+
+template 
+struct U {
+  int i; // expected-error {{member 'i' cannot have template arguments}}
+  int j; // expected-error {{member 'j' cannot have template arguments}}
+};
+
+} // namespace GH54151
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3395,6 +3395,14 @@
   return nullptr;
 }
 
+if (D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)
+  << II
+  << SourceRange(D.getName().TemplateId->LAngleLoc,
+ D.getName().TemplateId->RAngleLoc)
+  << D.getName().TemplateId->LAngleLoc;
+}
+
 if (SS.isSet() && !SS.isInvalid()) {
   // The user provided a superfluous scope specifier inside a class
   // definition:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSema

[PATCH] D120900: [clang][dataflow] Add `MatchSwitch` utility library.

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added reviewers: sgatev, gribozavr2.
Herald added subscribers: tschuett, steakhal, mgorny.
Herald added a project: All.
ymandel requested review of this revision.
Herald added a project: clang.

Adds `MatchSwitch`, a library for simplifying implementation of transfer
functions. `MatchSwitch` supports constructing a "switch" statement, where each
case of the switch is defined by an AST matcher. The cases are considered in
order, like pattern matching in functional languages.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120900

Files:
  clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
@@ -0,0 +1,188 @@
+//===- unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a simplistic version of Constant Propagation as an example
+//  of a forward, monotonic dataflow analysis. The analysis tracks all
+//  variables in the scope, but lacks escape analysis.
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
+#include "TestingSupport.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/MapLattice.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang;
+using namespace dataflow;
+
+namespace {
+using ::testing::Pair;
+using ::testing::UnorderedElementsAre;
+
+class BooleanLattice {
+public:
+  BooleanLattice() : Value(false) {}
+  explicit BooleanLattice(bool B) : Value(B) {}
+
+  static BooleanLattice bottom() { return BooleanLattice(false); }
+
+  static BooleanLattice top() { return BooleanLattice(true); }
+
+  LatticeJoinEffect join(BooleanLattice Other) {
+auto Prev = Value;
+Value = Value || Other.Value;
+return Prev == Value ? LatticeJoinEffect::Unchanged
+ : LatticeJoinEffect::Changed;
+  }
+
+  friend bool operator==(BooleanLattice LHS, BooleanLattice RHS) {
+return LHS.Value == RHS.Value;
+  }
+
+  friend std::ostream &operator<<(std::ostream &Os, const BooleanLattice &B) {
+Os << B.Value;
+return Os;
+  }
+
+  bool value() const { return Value; }
+
+private:
+  bool Value;
+};
+} // namespace
+
+MATCHER_P(Holds, m,
+  ((negation ? "doesn't hold" : "holds") +
+   llvm::StringRef(" a lattice element that ") +
+   ::testing::DescribeMatcher(m, negation))
+  .str()) {
+  return ExplainMatchResult(m, arg.Lattice, result_listener);
+}
+
+void TransferFound(const Expr *, TransferState &State) {
+  State.Lattice = BooleanLattice(true);
+}
+
+class TestAnalysis : public DataflowAnalysis {
+  MatchSwitch> TransferSwitch;
+
+public:
+  explicit TestAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {
+using namespace ast_matchers;
+TransferSwitch =
+MatchSwitchBuilder>()
+.CaseOf(declRefExpr(to(varDecl(hasName("X", TransferFound)
+.CaseOf(callExpr(callee(functionDecl(hasName("Foo",
+TransferFound)
+.Build();
+  }
+
+  static BooleanLattice initialElement() { return BooleanLattice::bottom(); }
+
+  void transfer(const Stmt *S, BooleanLattice &L, Environment &Env) {
+ASTContext &Context = getASTContext();
+TransferState State(Context, L, Env);
+TransferSwitch(*S, Context, State);
+  }
+};
+
+class MatchSwitchTest : public ::testing::Test {
+protected:
+  template 
+  void RunDataflow(llvm::StringRef Code, Matcher Expectations) {
+ASSERT_THAT_ERROR(
+test::checkDataflow(
+Code, "fun",
+[](ASTContext &C, Environment &) { return TestAnalysis(C); },
+  

[PATCH] D120255: [Concepts] Check constraints for explicit template instantiations

2022-03-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Do you have push rights, or do you need someone to push for you?  If you need 
someone to push for you, please post the name and email address you'd like the 
commit under.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120255

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


[PATCH] D120900: [clang][dataflow] Add `MatchSwitch` utility library.

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 412693.
ymandel added a comment.

Adjust tests to use two different handlers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120900

Files:
  clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
@@ -0,0 +1,203 @@
+//===- unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a simplistic version of Constant Propagation as an example
+//  of a forward, monotonic dataflow analysis. The analysis tracks all
+//  variables in the scope, but lacks escape analysis.
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
+#include "TestingSupport.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/MapLattice.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang;
+using namespace dataflow;
+
+namespace {
+using ::testing::Pair;
+using ::testing::UnorderedElementsAre;
+
+class BooleanLattice {
+public:
+  BooleanLattice() : Value(false) {}
+  explicit BooleanLattice(bool B) : Value(B) {}
+
+  static BooleanLattice bottom() { return BooleanLattice(false); }
+
+  static BooleanLattice top() { return BooleanLattice(true); }
+
+  LatticeJoinEffect join(BooleanLattice Other) {
+auto Prev = Value;
+Value = Value || Other.Value;
+return Prev == Value ? LatticeJoinEffect::Unchanged
+ : LatticeJoinEffect::Changed;
+  }
+
+  friend bool operator==(BooleanLattice LHS, BooleanLattice RHS) {
+return LHS.Value == RHS.Value;
+  }
+
+  friend std::ostream &operator<<(std::ostream &Os, const BooleanLattice &B) {
+Os << B.Value;
+return Os;
+  }
+
+  bool value() const { return Value; }
+
+private:
+  bool Value;
+};
+} // namespace
+
+MATCHER_P(Holds, m,
+  ((negation ? "doesn't hold" : "holds") +
+   llvm::StringRef(" a lattice element that ") +
+   ::testing::DescribeMatcher(m, negation))
+  .str()) {
+  return ExplainMatchResult(m, arg.Lattice, result_listener);
+}
+
+void TransferSetTrue(const DeclRefExpr *,
+ TransferState &State) {
+  State.Lattice = BooleanLattice(true);
+}
+
+void TransferSetFalse(const Expr *, TransferState &State) {
+  State.Lattice = BooleanLattice(false);
+}
+
+class TestAnalysis : public DataflowAnalysis {
+  MatchSwitch> TransferSwitch;
+
+public:
+  explicit TestAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {
+using namespace ast_matchers;
+TransferSwitch =
+MatchSwitchBuilder>()
+.CaseOf(declRefExpr(to(varDecl(hasName("X", TransferSetTrue)
+.CaseOf(callExpr(callee(functionDecl(hasName("Foo",
+TransferSetFalse)
+.Build();
+  }
+
+  static BooleanLattice initialElement() { return BooleanLattice::bottom(); }
+
+  void transfer(const Stmt *S, BooleanLattice &L, Environment &Env) {
+ASTContext &Context = getASTContext();
+TransferState State(Context, L, Env);
+TransferSwitch(*S, Context, State);
+  }
+};
+
+class MatchSwitchTest : public ::testing::Test {
+protected:
+  template 
+  void RunDataflow(llvm::StringRef Code, Matcher Expectations) {
+ASSERT_THAT_ERROR(
+test::checkDataflow(
+Code, "fun",
+[](ASTContext &C, Environment &) { return TestAnalysis(C); },
+[&Expectations](
+llvm::ArrayRef>>
+Results,
+ASTContext &) { EXPECT_THAT(Results, Expectations); },
+{"-fsyntax-only", "-std

[PATCH] D120255: [Concepts] Check constraints for explicit template instantiations

2022-03-03 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D120255#3357007 , @erichkeane 
wrote:

> Do you have push rights, or do you need someone to push for you?  If you need 
> someone to push for you, please post the name and email address you'd like 
> the commit under.

Thanks a lot! I don't have push rights, so please push this with Roy Jacobson 

(not a typo, the email has different spelling)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120255

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


[PATCH] D120881: [Clang] Diagnose invalid member variable with template parameters

2022-03-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Do we have a test somewhere to check the variable template specialization case 
to make sure that didn't break?  Otherwise LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120881

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


[PATCH] D120723: [pseudo] Fix an out-of-bound error in LRTable::find.

2022-03-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D120723#3356925 , @hokein wrote:

> Fixed in 28ccf326725d0fea8648834c8acdbdfe3aa40d7a 
> .

Thanks! I can confirm this is fixed on my end now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120723

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


[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h:26
+
+// Lattice for dataflow analysis that keeps track of a set of source locations.
+//

Doc comments start with `///`.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h:55
+
+// Returns a string that represents the source locations of the lattice.
+std::string DebugString(const SourceLocationsLattice &Lattice,

Doc comments start with `///`.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h:56
+// Returns a string that represents the source locations of the lattice.
+std::string DebugString(const SourceLocationsLattice &Lattice,
+const ASTContext &Context);

Can you please add tests for this too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120890

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


[PATCH] D120881: [Clang] Diagnose invalid member variable with template parameters

2022-03-03 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

In D120881#3357015 , @erichkeane 
wrote:

> Do we have a test somewhere to check the variable template specialization 
> case to make sure that didn't break?  Otherwise LGTM.

Thanks for the review.
It seems fairly well covered in 
`clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120881

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


[PATCH] D112774: [RISCV] Support k-ext clang intrinsics

2022-03-03 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence updated this revision to Diff 412698.
achieveartificialintelligence marked 7 inline comments as done.
achieveartificialintelligence added a comment.

Address @craig.topper's comments. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112774

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkx.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkc.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkx.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv32-zksh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknd.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zkne.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zknh.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zksed.c
  clang/test/CodeGen/RISCV/rvk-intrinsics/riscv64-zksh.c
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c

Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -31,6 +31,17 @@
 // CHECK-NOT: __riscv_zfh
 // CHECK-NOT: __riscv_v
 // CHECK-NOT: __riscv_vector
+// CHECK-NOT: __riscv_zbkc
+// CHECK-NOT: __riscv_zbkx
+// CHECK-NOT: __riscv_zbkb
+// CHECK-NOT: __riscv_zkne
+// CHECK-NOT: __riscv_zknd
+// CHECK-NOT: __riscv_zknh
+// CHECK-NOT: __riscv_zksh
+// CHECK-NOT: __riscv_zksed
+// CHECK-NOT: __riscv_zkr
+// CHECK-NOT: __riscv_zkt
+// CHECK-NOT: __riscv_zk
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
@@ -343,3 +354,58 @@
 // CHECK-ZVE32X-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32X-EXT: __riscv_vector 1
 // CHECK-ZVE32X-EXT: __riscv_zve32x 100{{$}}
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkc1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKC-EXT %s
+// CHECK-ZBKC-EXT: __riscv_zbkc
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkx1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKX-EXT %s
+// CHECK-ZBKX-EXT: __riscv_zbkx
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izbkb1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZBKB-EXT %s
+// CHECK-ZBKB-EXT: __riscv_zbkb
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknd1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKND-EXT %s
+// CHECK-ZKND-EXT: __riscv_zknd
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkne1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNE-EXT %s
+// CHECK-ZKNE-EXT: __riscv_zkne
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izknh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKNH-EXT %s
+// CHECK-ZKNH-EXT: __riscv_zknh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksh1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSH-EXT %s
+// CHECK-ZKSH-EXT: __riscv_zksh
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izksed1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKSED-EXT %s
+// CHECK-ZKSED-EXT: __riscv_zksed
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkr1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKR-EXT %s
+// CHECK-ZKR-EXT: __riscv_zkr
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izkt1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZKT-EXT %s
+// CHECK-ZKT-EXT: __riscv_zkt
+
+// RUN: %clang -target riscv64-unknown-linux-gnu \
+// RUN: -march=rv64izk1p0 -x c -E -dM %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ZK-EXT %s
+// CHECK-ZK-EXT: __riscv_zk
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -414,3 +414,47 @@
 // RUN: %clang -target riscv32-unknown-elf -march=rv32iv1p0_zvl32b1p0 -### %s -c 2>&1 | \
 // RUN:   FileCheck -check-prefix=RV32-ZVL-GOODVERS %s
 // RV32-ZVL-GOODVERS: "-target-feature" "+zvl32b"
+
+// RUN: %clang -target riscv32

[clang] 5aeaabf - [Concepts] Check constraints for explicit template instantiations

2022-03-03 Thread Erich Keane via cfe-commits

Author: Roy Jacobson
Date: 2022-03-03T06:33:49-08:00
New Revision: 5aeaabf35eaddf9e5bfb05c0ec901a8aecfaa36a

URL: 
https://github.com/llvm/llvm-project/commit/5aeaabf35eaddf9e5bfb05c0ec901a8aecfaa36a
DIFF: 
https://github.com/llvm/llvm-project/commit/5aeaabf35eaddf9e5bfb05c0ec901a8aecfaa36a.diff

LOG: [Concepts] Check constraints for explicit template instantiations

The standard requires[0] member function constraints to be checked when
explicitly instantiating classes. This patch adds this constraints
check.

This issue is tracked as #46029 [1].

Note that there's an related open CWG issue (2421[2]) about what to do when
multiple candidates have satisfied constraints. This is particularly an
issue because mangling doesn't contain function constraints, and so the
following code still ICEs with definition with same mangled name
'_ZN1BIiE1fEv' as another definition:

template
struct B {
  int f() requires std::same_as {
return 0;
  }
  int f() requires (std::same_as &&
!std::same_as) {
return 1;
  }
};

template struct B;

Also note that the constraints checking while instantiating *functions*
is still not implemented. I started looking at it but It's a bit more
complicated. I believe in such a case we have to consider the partial
constraints order and potentially choose the best candidate out of the
set of multiple valid ones.

[0]: https://eel.is/c++draft/temp.explicit#10
[1]: https://github.com/llvm/llvm-project/issues/46029
[2]: https://cplusplus.github.io/CWG/issues/2421.html

Differential Revision: https://reviews.llvm.org/D120255

Added: 
clang/test/AST/constraints-explicit-instantiation.cpp

Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 2675665202971..46da97968a937 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3230,6 +3230,14 @@ Sema::InstantiateClassMembers(SourceLocation 
PointOfInstantiation,
   if (FunctionDecl *Pattern =
   Function->getInstantiatedFromMemberFunction()) {
 
+if (Function->getTrailingRequiresClause()) {
+  ConstraintSatisfaction Satisfaction;
+  if (CheckFunctionConstraints(Function, Satisfaction) ||
+  !Satisfaction.IsSatisfied) {
+continue;
+  }
+}
+
 if (Function->hasAttr())
   continue;
 

diff  --git a/clang/test/AST/constraints-explicit-instantiation.cpp 
b/clang/test/AST/constraints-explicit-instantiation.cpp
new file mode 100644
index 0..10b6432f2db8c
--- /dev/null
+++ b/clang/test/AST/constraints-explicit-instantiation.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++20 -ast-dump %s | FileCheck %s
+
+namespace PR46029 {
+
+template 
+void canary1();
+template 
+void canary2();
+
+template 
+struct A {
+  void f() requires(N == 1) {
+static_assert(N == 1);
+canary1();
+  }
+  void f() requires(N == 2) {
+static_assert(N == 2);
+canary2();
+  }
+};
+
+// This checks that `canary1<1>` and `canaray2<2>` are instantiated, thus
+// indirectly validating that the correct candidates of `A::f` were really
+// instantiated each time. 
+// The `static_assert`s validate we don't instantiate wrong candidates.
+
+// CHECK:{{.*}}FunctionTemplateDecl {{.*}} canary1
+// CHECK:  {{.*}}TemplateArgument integral
+// CHECK-SAME: {{1$}}
+template struct A<1>;
+
+// CHECK:  {{.*}}FunctionTemplateDecl {{.*}} canary2
+// CHECK:  {{.*}}TemplateArgument integral
+// CHECK-SAME: {{2$}}
+template struct A<2>;
+
+template struct A<3>;
+}



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


[PATCH] D120255: [Concepts] Check constraints for explicit template instantiations

2022-03-03 Thread Erich Keane via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5aeaabf35ead: [Concepts] Check constraints for explicit 
template instantiations (authored by royjacobson, committed by erichkeane).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120255

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/AST/constraints-explicit-instantiation.cpp


Index: clang/test/AST/constraints-explicit-instantiation.cpp
===
--- /dev/null
+++ clang/test/AST/constraints-explicit-instantiation.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++20 -ast-dump %s | FileCheck %s
+
+namespace PR46029 {
+
+template 
+void canary1();
+template 
+void canary2();
+
+template 
+struct A {
+  void f() requires(N == 1) {
+static_assert(N == 1);
+canary1();
+  }
+  void f() requires(N == 2) {
+static_assert(N == 2);
+canary2();
+  }
+};
+
+// This checks that `canary1<1>` and `canaray2<2>` are instantiated, thus
+// indirectly validating that the correct candidates of `A::f` were really
+// instantiated each time. 
+// The `static_assert`s validate we don't instantiate wrong candidates.
+
+// CHECK:{{.*}}FunctionTemplateDecl {{.*}} canary1
+// CHECK:  {{.*}}TemplateArgument integral
+// CHECK-SAME: {{1$}}
+template struct A<1>;
+
+// CHECK:  {{.*}}FunctionTemplateDecl {{.*}} canary2
+// CHECK:  {{.*}}TemplateArgument integral
+// CHECK-SAME: {{2$}}
+template struct A<2>;
+
+template struct A<3>;
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3230,6 +3230,14 @@
   if (FunctionDecl *Pattern =
   Function->getInstantiatedFromMemberFunction()) {
 
+if (Function->getTrailingRequiresClause()) {
+  ConstraintSatisfaction Satisfaction;
+  if (CheckFunctionConstraints(Function, Satisfaction) ||
+  !Satisfaction.IsSatisfied) {
+continue;
+  }
+}
+
 if (Function->hasAttr())
   continue;
 


Index: clang/test/AST/constraints-explicit-instantiation.cpp
===
--- /dev/null
+++ clang/test/AST/constraints-explicit-instantiation.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++20 -ast-dump %s | FileCheck %s
+
+namespace PR46029 {
+
+template 
+void canary1();
+template 
+void canary2();
+
+template 
+struct A {
+  void f() requires(N == 1) {
+static_assert(N == 1);
+canary1();
+  }
+  void f() requires(N == 2) {
+static_assert(N == 2);
+canary2();
+  }
+};
+
+// This checks that `canary1<1>` and `canaray2<2>` are instantiated, thus
+// indirectly validating that the correct candidates of `A::f` were really
+// instantiated each time. 
+// The `static_assert`s validate we don't instantiate wrong candidates.
+
+// CHECK:{{.*}}FunctionTemplateDecl {{.*}} canary1
+// CHECK:  {{.*}}TemplateArgument integral
+// CHECK-SAME: {{1$}}
+template struct A<1>;
+
+// CHECK:  {{.*}}FunctionTemplateDecl {{.*}} canary2
+// CHECK:  {{.*}}TemplateArgument integral
+// CHECK-SAME: {{2$}}
+template struct A<2>;
+
+template struct A<3>;
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3230,6 +3230,14 @@
   if (FunctionDecl *Pattern =
   Function->getInstantiatedFromMemberFunction()) {
 
+if (Function->getTrailingRequiresClause()) {
+  ConstraintSatisfaction Satisfaction;
+  if (CheckFunctionConstraints(Function, Satisfaction) ||
+  !Satisfaction.IsSatisfied) {
+continue;
+  }
+}
+
 if (Function->hasAttr())
   continue;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120397: [C++20] [Modules] Make the linkage consistent for template and its specialization

2022-03-03 Thread Nathan Sidwell via Phabricator via cfe-commits
urnathan added inline comments.
Herald added a project: All.



Comment at: clang/test/Modules/inconsist-export-template.cpp:19-23
+// FIXME: We should reject following specialization,
+// since it tries to export a name which is already introduced.
+export template <>
+void f1() {
+

ChuanqiXu wrote:
> iains wrote:
> > iains wrote:
> > > ChuanqiXu wrote:
> > > > urnathan wrote:
> > > > > I don't think we should be testing for ill-formed code here.  We want 
> > > > > to verify that explicit instantiations, explicit specializations and 
> > > > > implicit instantiations all get the expected linkage -- both external 
> > > > > linkage on exported entities, module linkage on non-exported 
> > > > > module-purview entities.
> > > > I think it could add an `expected-error` once we complete the check in 
> > > > compiler so I added the FIXME here.
> > > would it be possible to find a suitable place in the source for the FIXME?
> > > I would be concerned that it could get forgotten in the test-case.
> > or maybe just file a PR for accepts invalid code?
> I would like to send an issue after the patch to remind me not forgetting it. 
> The issue is needed after the patch since it would crash too. I prefer to 
> remain the FIXME here so that it would look like a pre-commit test case, 
> which should be good.
The way to not forget about this is to file a bug and assign it to yourself.  
Not add a known-wrong testcase.


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

https://reviews.llvm.org/D120397

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


[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 412701.
ymandel added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120890

Files:
  clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp
@@ -0,0 +1,68 @@
+//===- unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/SourceLocationsLattice.h"
+
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Basic/SourceLocation.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace dataflow {
+namespace {
+
+TEST(SourceLocationsLatticeTest, Comparison) {
+  const SourceLocationsLattice Bottom;
+  const SourceLocationsLattice NonBottom(
+  {SourceLocation::getFromRawEncoding(0)});
+
+  EXPECT_TRUE(Bottom == Bottom);
+  EXPECT_FALSE(Bottom == NonBottom);
+  EXPECT_FALSE(NonBottom == Bottom);
+  EXPECT_TRUE(NonBottom == NonBottom);
+
+  EXPECT_FALSE(Bottom != Bottom);
+  EXPECT_TRUE(Bottom != NonBottom);
+  EXPECT_TRUE(NonBottom != Bottom);
+  EXPECT_FALSE(NonBottom != NonBottom);
+}
+
+TEST(SourceLocationsLatticeTest, Join) {
+  const SourceLocationsLattice Bottom;
+  const SourceLocationsLattice NonBottom(
+  {SourceLocation::getFromRawEncoding(0)});
+  {
+SourceLocationsLattice LHS = Bottom;
+const SourceLocationsLattice RHS = Bottom;
+EXPECT_EQ(LHS.join(RHS), LatticeJoinEffect::Unchanged);
+EXPECT_EQ(LHS, Bottom);
+  }
+  {
+SourceLocationsLattice LHS = NonBottom;
+const SourceLocationsLattice RHS = Bottom;
+EXPECT_EQ(LHS.join(RHS), LatticeJoinEffect::Unchanged);
+EXPECT_EQ(LHS, NonBottom);
+  }
+  {
+SourceLocationsLattice LHS = Bottom;
+const SourceLocationsLattice RHS = NonBottom;
+EXPECT_EQ(LHS.join(RHS), LatticeJoinEffect::Changed);
+EXPECT_EQ(LHS, NonBottom);
+  }
+  {
+SourceLocationsLattice LHS = NonBottom;
+const SourceLocationsLattice RHS = NonBottom;
+EXPECT_EQ(LHS.join(RHS), LatticeJoinEffect::Unchanged);
+EXPECT_EQ(LHS, NonBottom);
+  }
+}
+
+} // namespace
+} // namespace dataflow
+} // namespace clang
Index: clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
===
--- clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
+++ clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
@@ -9,6 +9,7 @@
   MapLatticeTest.cpp
   MultiVarConstantPropagationTest.cpp
   SingleVarConstantPropagationTest.cpp
+  SourceLocationsLatticeTest.cpp
   TestingSupport.cpp
   TestingSupportTest.cpp
   TransferTest.cpp
Index: clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
===
--- /dev/null
+++ clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
@@ -0,0 +1,51 @@
+//===- SourceLocationsLattice.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file implements a lattice that collects source locations of interest.
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/SourceLocationsLattice.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace dataflow {
+
+LatticeJoinEffect
+SourceLocationsLattice::join(const SourceLocationsLattice &Other) {
+  auto SizeBefore = Locs.size();
+  Locs.insert(Other.Locs.begin(), Other.Locs.end());
+  return SizeBefore == Locs.size() ? LatticeJoinEffect::Unchanged
+   : LatticeJoinEffect::Changed;
+}
+
+std::string DebugString(const SourceLocationsLattice &Lattice,
+const ASTContext &Context) {
+  if (Lattice.getSourceLocations().empty())
+

[PATCH] D120902: [clang-format] Fix assertion failure/crash with `AllowShortFunctionsOnASingleLine: Inline/InlineOnly`.

2022-03-03 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
Herald added a project: All.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/54147.

When handling `AllowShortFunctionsOnASingleLine`, we were searching for the 
last line with a smaller level than the current line. The search was incorrect 
when the first line had the same level as the current one. This led to an 
unsatisfied assumption about the existence of a brace (non-comment token).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120902

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12639,6 +12639,13 @@
"};",
MergeInlineOnly);
   verifyFormat("int f() {}", MergeInlineOnly);
+  // https://llvm.org/PR54147
+  verifyFormat("auto lambda = []() {\n"
+   "  // comment\n"
+   "  f();\n"
+   "  g();\n"
+   "};",
+   MergeInlineOnly);
 
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -310,6 +310,8 @@
   for (; J != AnnotatedLines.begin(); --J)
 if ((*J)->Level < TheLine->Level)
   break;
+  if ((*J)->Level == TheLine->Level)
+return false;
 
   // Check if the found line starts a record.
   const FormatToken *LastNonComment = (*J)->Last;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12639,6 +12639,13 @@
"};",
MergeInlineOnly);
   verifyFormat("int f() {}", MergeInlineOnly);
+  // https://llvm.org/PR54147
+  verifyFormat("auto lambda = []() {\n"
+   "  // comment\n"
+   "  f();\n"
+   "  g();\n"
+   "};",
+   MergeInlineOnly);
 
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -310,6 +310,8 @@
   for (; J != AnnotatedLines.begin(); --J)
 if ((*J)->Level < TheLine->Level)
   break;
+  if ((*J)->Level == TheLine->Level)
+return false;
 
   // Check if the found line starts a record.
   const FormatToken *LastNonComment = (*J)->Last;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked 5 inline comments as done.
ymandel added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h:56
+// Returns a string that represents the source locations of the lattice.
+std::string DebugString(const SourceLocationsLattice &Lattice,
+const ASTContext &Context);

sgatev wrote:
> Can you please add tests for this too?
I'm not sure what I would test, since it (intentionally) has no guaranteed API. 
Do you have something particular in mind? I generally avoid testing things like 
DebugString because we don't want users to rely on them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120890

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


[PATCH] D120881: [Clang] Diagnose invalid member variable with template parameters

2022-03-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM (I'm a bit sad about the diagnostic differences, but I understand why 
they're different a bit better now, so this is fine.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120881

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


[clang] 942c039 - [Clang] Diagnose invalid member variable with template parameters

2022-03-03 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-03-03T15:51:46+01:00
New Revision: 942c03910aef43de1cd2c733a82370fd3e2c9981

URL: 
https://github.com/llvm/llvm-project/commit/942c03910aef43de1cd2c733a82370fd3e2c9981
DIFF: 
https://github.com/llvm/llvm-project/commit/942c03910aef43de1cd2c733a82370fd3e2c9981.diff

LOG: [Clang] Diagnose invalid member variable with template parameters

Fixes https://github.com/llvm/llvm-project/issues/54151

Reviewed By: erichkeane, aaron.ballman

Differential Revision: https://reviews.llvm.org/D120881

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 945d4e2976503..0468370536fc0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4811,6 +4811,7 @@ def warn_cxx11_compat_variable_template : Warning<
 def err_template_variable_noparams : Error<
   "extraneous 'template<>' in declaration of variable %0">;
 def err_template_member : Error<"member %0 declared as a template">;
+def err_member_with_template_arguments : Error<"member %0 cannot have template 
arguments">;
 def err_template_member_noparams : Error<
   "extraneous 'template<>' in declaration of member %0">;
 def err_template_tag_noparams : Error<

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 90a1cf514eb6e..a845d60f6d880 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -3395,6 +3395,14 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier 
AS, Declarator &D,
   return nullptr;
 }
 
+if (D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)
+  << II
+  << SourceRange(D.getName().TemplateId->LAngleLoc,
+ D.getName().TemplateId->RAngleLoc)
+  << D.getName().TemplateId->LAngleLoc;
+}
+
 if (SS.isSet() && !SS.isInvalid()) {
   // The user provided a superfluous scope specifier inside a class
   // definition:

diff  --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp 
b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
index 56231e2f725f6..1b039627a1d3a 100644
--- a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
+++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
@@ -32,3 +32,23 @@ namespace test1 {
   template <> int AB::foo = 0; // expected-error{{extraneous 'template<>'}}
   int AB::bar = 1;
 }
+
+namespace GH54151 {
+
+struct S {
+  int i<0>;   // expected-error  {{member 'i' cannot have template arguments}}
+  int j; // expected-error  {{member 'j' cannot have template arguments}}
+
+  static int k<12>; // expected-error {{template specialization requires 
'template<>'}} \
+   expected-error{{no variable template matches 
specialization}}
+  void f<12>(); // expected-error {{template specialization requires 
'template<>'}} \
+// expected-error {{no function template matches function 
template specialization 'f'}}
+};
+
+template 
+struct U {
+  int i; // expected-error {{member 'i' cannot have template arguments}}
+  int j; // expected-error {{member 'j' cannot have template arguments}}
+};
+
+} // namespace GH54151



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


[PATCH] D120881: [Clang] Diagnose invalid member variable with template parameters

2022-03-03 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG942c03910aef: [Clang] Diagnose invalid member variable with 
template parameters (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120881

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp


Index: clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
===
--- clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
+++ clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
@@ -32,3 +32,23 @@
   template <> int AB::foo = 0; // expected-error{{extraneous 'template<>'}}
   int AB::bar = 1;
 }
+
+namespace GH54151 {
+
+struct S {
+  int i<0>;   // expected-error  {{member 'i' cannot have template arguments}}
+  int j; // expected-error  {{member 'j' cannot have template arguments}}
+
+  static int k<12>; // expected-error {{template specialization requires 
'template<>'}} \
+   expected-error{{no variable template matches 
specialization}}
+  void f<12>(); // expected-error {{template specialization requires 
'template<>'}} \
+// expected-error {{no function template matches function 
template specialization 'f'}}
+};
+
+template 
+struct U {
+  int i; // expected-error {{member 'i' cannot have template arguments}}
+  int j; // expected-error {{member 'j' cannot have template arguments}}
+};
+
+} // namespace GH54151
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3395,6 +3395,14 @@
   return nullptr;
 }
 
+if (D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)
+  << II
+  << SourceRange(D.getName().TemplateId->LAngleLoc,
+ D.getName().TemplateId->RAngleLoc)
+  << D.getName().TemplateId->LAngleLoc;
+}
+
 if (SS.isSet() && !SS.isInvalid()) {
   // The user provided a superfluous scope specifier inside a class
   // definition:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4811,6 +4811,7 @@
 def err_template_variable_noparams : Error<
   "extraneous 'template<>' in declaration of variable %0">;
 def err_template_member : Error<"member %0 declared as a template">;
+def err_member_with_template_arguments : Error<"member %0 cannot have template 
arguments">;
 def err_template_member_noparams : Error<
   "extraneous 'template<>' in declaration of member %0">;
 def err_template_tag_noparams : Error<


Index: clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
===
--- clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
+++ clang/test/CXX/temp/temp.spec/temp.expl.spec/p17.cpp
@@ -32,3 +32,23 @@
   template <> int AB::foo = 0; // expected-error{{extraneous 'template<>'}}
   int AB::bar = 1;
 }
+
+namespace GH54151 {
+
+struct S {
+  int i<0>;   // expected-error  {{member 'i' cannot have template arguments}}
+  int j; // expected-error  {{member 'j' cannot have template arguments}}
+
+  static int k<12>; // expected-error {{template specialization requires 'template<>'}} \
+   expected-error{{no variable template matches specialization}}
+  void f<12>(); // expected-error {{template specialization requires 'template<>'}} \
+// expected-error {{no function template matches function template specialization 'f'}}
+};
+
+template 
+struct U {
+  int i; // expected-error {{member 'i' cannot have template arguments}}
+  int j; // expected-error {{member 'j' cannot have template arguments}}
+};
+
+} // namespace GH54151
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3395,6 +3395,14 @@
   return nullptr;
 }
 
+if (D.getName().getKind() == UnqualifiedIdKind::IK_TemplateId) {
+  Diag(D.getIdentifierLoc(), diag::err_member_with_template_arguments)
+  << II
+  << SourceRange(D.getName().TemplateId->LAngleLoc,
+ D.getName().TemplateId->RAngleLoc)
+  << D.getName().TemplateId->LAngleLoc;
+}
+
 if (SS.isSet() && !SS.isInvalid()) {
   // The user provided a superfluous scope specifier inside a class
   // definition:
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
==

[PATCH] D120907: [docs] Add PowerPC release notes for LLVM 14

2022-03-03 Thread Lei Huang via Phabricator via cfe-commits
lei created this revision.
lei added reviewers: hubert.reinterpretcast, nemanjai, jsji.
Herald added a subscriber: shchenz.
Herald added a project: All.
lei requested review of this revision.
Herald added projects: clang, libc++, LLVM.
Herald added subscribers: llvm-commits, libcxx-commits, cfe-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120907

Files:
  clang/docs/ReleaseNotes.rst
  libcxx/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst

Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -100,12 +100,36 @@
 Changes to the Hexagon Target
 -
 
-* ...
+During this release ...
 
 Changes to the PowerPC Target
 -
 
-During this release ...
+Linux improvements:
+* Provided a number of builtins for compatibility with the XL compiler.
+* Allow MMA builtin types in pre-P10 compilation units.
+* Add support for Return Oriented Programming (ROP) protection for 32 bit.
+* Refactored code to use more inclusive language.
+* Switched to LLD as the default linker for pre-built Linux binaries.
+* Enabled IEEE quad long double on Linux via ``PPC_LINUX_DEFAULT_IEEELONGDOUBLE``
+  in cmake config.
+  * Added ``__ibm128`` type to represent IBM double-double format, also available
+as ``__attribute__((mode(IF)))``.
+  * ``-mfloat128`` can now be used in Linux subtargets with VSX enabled.
+* Added quadword atomic load/store support in codegen; not enabled by default.
+* Codegen improvements for splat load, byval parameter, stack lowering, etc.
+* Implemented P10 instruction scheduling model.
+* Implemented P10 instruction fusion pairs.
+* Improved handling of ``#pragma clang loop unroll_and_jam``.
+* Various bug fixes.
+
+AIX Support/improvements:
+* variadic (ellipsis) functions with C complex types are now supported.
+* Added toc-data support for AIX 64-bit.
+* Added toc-data support for read-only globals.
+* Updated default target on AIX from pwr4 to pwr7.
+* AIX 64-bit now use fast-isel for O0.
+* Added DWARF support for 32-bit XCOFF.
 
 Changes to the X86 Target
 -
@@ -224,6 +248,13 @@
 * llvm-readobj now supports several dump styles (``--needed-libs, --relocs, --syms``) for XCOFF.
 * llvm-symbolizer now supports `--debuginfod `.
   (`D113717 `_)
+* ``llvm-cov`` now accepts "allowlist" spelling for ``-name-allowlist``.
+* ``llvm-nm`` now supports XCOFF object files.
+* Added ``--needed-libs``, aux header, and symbols support in ``llvm-readobj``.
+* Added ``--symbolize-operands`` support in ``llvm-objdump``.
+* Tools that read archive files now support reading AIX big format archive files.
+* Added dump section support in ``obj2yaml``.
+* Added ``yaml2obj`` support for 64-bit XCOFF.
 
 Changes to LLDB
 -
Index: libcxx/docs/ReleaseNotes.rst
===
--- libcxx/docs/ReleaseNotes.rst
+++ libcxx/docs/ReleaseNotes.rst
@@ -77,6 +77,9 @@
 - More C++2b features have been implemented. :doc:`Status/Cxx2b` has the full
   overview of libc++'s C++2b implementation status.
 
+- 16-bit ``wchar_t`` handling added for ``codecvt_utf8``, ``codecvt_utf16`` and
+  ``codecvt_utf8_utf16``.
+
 API Changes
 ---
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -51,7 +51,19 @@
   For more details refer to :ref:`the SPIR-V support section `.
 - Completed support of OpenCL C 3.0 and C++ for OpenCL 2021 at experimental
   state.
--  ...
+
+- Prebuilt AIX7.2 TL5 SP3+ binary available with following notes and
+  limitations:
+  - C++ driver modes use the system libc++ headers. These headers are included
+in the optional ``libc++.adt.include`` fileset on AIX.
+  - LTO, although not disabled, is not recommended.
+  - Shared libraries builds (``-shared``) must use explicit symbol export
+options and/or export lists (e.g., with ``-bE:``) on the link step. Clang
+currently will not automatically generate symbol export lists as implicit
+linker inputs.
+
+- ``float.h`` now exposes (in hosted mode) extensions made available from the
+  AIX system header.
 
 Improvements to Clang's diagnostics
 ^^^
@@ -79,6 +91,9 @@
 - The ``-E -P`` preprocessor output now always omits blank lines, matching
   gcc behaviour. Previously, up to 8 consecutive blank lines could appear
   in the output.
+- AIX platform-related predefined macros added:
+  ``_ARCH_PPC64``, ``__HOS_AIX__``, ``__PPC``, ``__THW_BIG_ENDIAN__``,
+  ``__THW_PPC__``, and ``__powerpc``
 
 New Compiler Flags
 --
@@ -103,6 +118,8 @@
   for `ccache 

[PATCH] D120907: [docs] Add PowerPC release notes for LLVM 14

2022-03-03 Thread Lei Huang via Phabricator via cfe-commits
lei updated this revision to Diff 412710.
lei added a comment.

remove unintented change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120907

Files:
  clang/docs/ReleaseNotes.rst
  libcxx/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst

Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -105,7 +105,31 @@
 Changes to the PowerPC Target
 -
 
-During this release ...
+Linux improvements:
+* Provided a number of builtins for compatibility with the XL compiler.
+* Allow MMA builtin types in pre-P10 compilation units.
+* Add support for Return Oriented Programming (ROP) protection for 32 bit.
+* Refactored code to use more inclusive language.
+* Switched to LLD as the default linker for pre-built Linux binaries.
+* Enabled IEEE quad long double on Linux via ``PPC_LINUX_DEFAULT_IEEELONGDOUBLE``
+  in cmake config.
+  * Added ``__ibm128`` type to represent IBM double-double format, also available
+as ``__attribute__((mode(IF)))``.
+  * ``-mfloat128`` can now be used in Linux subtargets with VSX enabled.
+* Added quadword atomic load/store support in codegen; not enabled by default.
+* Codegen improvements for splat load, byval parameter, stack lowering, etc.
+* Implemented P10 instruction scheduling model.
+* Implemented P10 instruction fusion pairs.
+* Improved handling of ``#pragma clang loop unroll_and_jam``.
+* Various bug fixes.
+
+AIX Support/improvements:
+* variadic (ellipsis) functions with C complex types are now supported.
+* Added toc-data support for AIX 64-bit.
+* Added toc-data support for read-only globals.
+* Updated default target on AIX from pwr4 to pwr7.
+* AIX 64-bit now use fast-isel for O0.
+* Added DWARF support for 32-bit XCOFF.
 
 Changes to the X86 Target
 -
@@ -224,6 +248,13 @@
 * llvm-readobj now supports several dump styles (``--needed-libs, --relocs, --syms``) for XCOFF.
 * llvm-symbolizer now supports `--debuginfod `.
   (`D113717 `_)
+* ``llvm-cov`` now accepts "allowlist" spelling for ``-name-allowlist``.
+* ``llvm-nm`` now supports XCOFF object files.
+* Added ``--needed-libs``, aux header, and symbols support in ``llvm-readobj``.
+* Added ``--symbolize-operands`` support in ``llvm-objdump``.
+* Tools that read archive files now support reading AIX big format archive files.
+* Added dump section support in ``obj2yaml``.
+* Added ``yaml2obj`` support for 64-bit XCOFF.
 
 Changes to LLDB
 -
Index: libcxx/docs/ReleaseNotes.rst
===
--- libcxx/docs/ReleaseNotes.rst
+++ libcxx/docs/ReleaseNotes.rst
@@ -77,6 +77,9 @@
 - More C++2b features have been implemented. :doc:`Status/Cxx2b` has the full
   overview of libc++'s C++2b implementation status.
 
+- 16-bit ``wchar_t`` handling added for ``codecvt_utf8``, ``codecvt_utf16`` and
+  ``codecvt_utf8_utf16``.
+
 API Changes
 ---
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -51,7 +51,19 @@
   For more details refer to :ref:`the SPIR-V support section `.
 - Completed support of OpenCL C 3.0 and C++ for OpenCL 2021 at experimental
   state.
--  ...
+
+- Prebuilt AIX7.2 TL5 SP3+ binary available with following notes and
+  limitations:
+  - C++ driver modes use the system libc++ headers. These headers are included
+in the optional ``libc++.adt.include`` fileset on AIX.
+  - LTO, although not disabled, is not recommended.
+  - Shared libraries builds (``-shared``) must use explicit symbol export
+options and/or export lists (e.g., with ``-bE:``) on the link step. Clang
+currently will not automatically generate symbol export lists as implicit
+linker inputs.
+
+- ``float.h`` now exposes (in hosted mode) extensions made available from the
+  AIX system header.
 
 Improvements to Clang's diagnostics
 ^^^
@@ -79,6 +91,9 @@
 - The ``-E -P`` preprocessor output now always omits blank lines, matching
   gcc behaviour. Previously, up to 8 consecutive blank lines could appear
   in the output.
+- AIX platform-related predefined macros added:
+  ``_ARCH_PPC64``, ``__HOS_AIX__``, ``__PPC``, ``__THW_BIG_ENDIAN__``,
+  ``__THW_PPC__``, and ``__powerpc``
 
 New Compiler Flags
 --
@@ -103,6 +118,8 @@
   for `ccache `_ and
   `sccache `_ are under review.
 
+- Clang now accepts "allowlist" spelling for ``-objcmt-allowlist-dir-path``.
+
 Deprecated Compiler Flags
 -
 
@@ -169,6 +186,8 @@
   attributes, but will no

[PATCH] D120907: [docs] Add PowerPC release notes for LLVM 14

2022-03-03 Thread Jinsong Ji via Phabricator via cfe-commits
jsji accepted this revision.
jsji added a comment.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120907

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


[PATCH] D120888: [clang] Stop dragging a EndLoc around when parsing attributes

2022-03-03 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 412714.

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

https://reviews.llvm.org/D120888

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/ParseTentative.cpp

Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -1913,7 +1913,7 @@
   /*OuterMightBeMessageSend*/true))
   return TPResult::True;
 
-ParsedAttributes attrs(AttrFactory);
+ParsedAttributesWithRange attrs(AttrFactory);
 MaybeParseMicrosoftAttributes(attrs);
 
 // decl-specifier-seq
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -106,7 +106,7 @@
   // at the start of the statement. Thus, we're not using MaybeParseAttributes
   // here because we don't want to allow arbitrary orderings.
   ParsedAttributesWithRange Attrs(AttrFactory);
-  MaybeParseCXX11Attributes(Attrs, nullptr, /*MightBeObjCMessageSend*/ true);
+  MaybeParseCXX11Attributes(Attrs, /*MightBeObjCMessageSend*/ true);
   if (getLangOpts().OpenCL)
 MaybeParseGNUAttributes(Attrs);
 
@@ -1119,7 +1119,7 @@
 ConsumeToken();
 
   ParsedAttributesWithRange attrs(AttrFactory);
-  MaybeParseCXX11Attributes(attrs, nullptr,
+  MaybeParseCXX11Attributes(attrs,
 /*MightBeObjCMessageSend*/ true);
 
   // If this is the start of a declaration, parse it as such.
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1252,7 +1252,7 @@
   TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
   Actions.PushLambdaScope();
 
-  ParsedAttributes Attr(AttrFactory);
+  ParsedAttributesWithRange Attr(AttrFactory);
   if (getLangOpts().CUDA) {
 // In CUDA code, GNU attributes are allowed to appear immediately after the
 // "[...]", even if there is no "(...)" before the lambda body.
@@ -1355,7 +1355,8 @@
   DeclEndLoc = ESpecRange.getEnd();
 
 // Parse attribute-specifier[opt].
-MaybeParseCXX11Attributes(Attr, &DeclEndLoc);
+if (MaybeParseCXX11Attributes(Attr))
+  DeclEndLoc = Attr.Range.getEnd();
 
 // Parse OpenCL addr space attribute.
 if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
Index: clang/lib/Parse/ParseDeclCXX.cpp
===
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -4513,19 +4513,17 @@
 ///
 /// attribute-specifier-seq:
 ///   attribute-specifier-seq[opt] attribute-specifier
-void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
-  SourceLocation *endLoc) {
+void Parser::ParseCXX11Attributes(ParsedAttributesWithRange &attrs) {
   assert(standardAttributesAllowed());
 
-  SourceLocation StartLoc = Tok.getLocation(), Loc;
-  if (!endLoc)
-endLoc = &Loc;
+  SourceLocation StartLoc = Tok.getLocation();
+  SourceLocation EndLoc = StartLoc;
 
   do {
-ParseCXX11AttributeSpecifier(attrs, endLoc);
+ParseCXX11AttributeSpecifier(attrs, &EndLoc);
   } while (isCXX11AttributeSpecifier());
 
-  attrs.Range = SourceRange(StartLoc, *endLoc);
+  attrs.Range = SourceRange(StartLoc, EndLoc);
 }
 
 void Parser::DiagnoseAndSkipCXX11Attributes() {
@@ -4658,9 +4656,10 @@
 /// [MS] ms-attribute-seq:
 /// ms-attribute[opt]
 /// ms-attribute ms-attribute-seq
-void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs,
-  SourceLocation *endLoc) {
+void Parser::ParseMicrosoftAttributes(ParsedAttributes &attrs) {
   assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list");
+  // FIXME: ParseMicrosoftAttributes() does not support
+  // ParsedAttributesWithRange.
 
   do {
 // FIXME: If this is actually a C++11 attribute, parse it as one.
@@ -4687,8 +4686,6 @@
 }
 
 T.consumeClose();
-if (endLoc)
-  *endLoc = T.getCloseLocation();
   } while (Tok.is(tok::l_square));
 }
 
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -105,7 +105,6 @@
 
 void Parser::ParseAttributes(unsigned WhichAttrKinds,
  ParsedAttributesWithRange &Attrs,
- SourceLocation *End,
  LateParsedAttrList *LateAttrs) {
   bool MoreToParse;
   do {
@@ -113,11 +112,11 @@
 

[PATCH] D120723: [pseudo] Fix an out-of-bound error in LRTable::find.

2022-03-03 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/Tooling/Syntax/Pseudo/LRTable.cpp:115
   TargetedStates, [&Src](LRTable::StateID S) { return S < Src; });
-  if (It == TargetedStates.end())
+  if (Start == TargetedStates.end())
 return {};

hokein wrote:
> sammccall wrote:
> > I think this check is no longer needed
> sorry, should have thought more carefully on this comment, we need this check 
> to make sure we don't access `Actions[Actions.end()]` on Line120 below.
Sorry about that.

You're right, we formally do &*Actions[Actions.size()], which is invalid.

However we don't actually need a runtime check, just a change of syntax to 
avoid the dereference:

`return llvm::makeArrayRef(Actions.data() + (Start - States.data()), End - 
Start);`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120723

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


[PATCH] D120910: [HIP] Fix job action offloading kind for mixed HIP/C++ compilation

2022-03-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a project: All.
yaxunl requested review of this revision.

When both HIP and C++ programs are input files to clang
with -c, clang treats C++ programs as HIP programs,
which is incorrect.

This is due to action builder does not set correct
offloading kind for job actions for C++ programs.


https://reviews.llvm.org/D120910

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/Inputs/empty.cpp
  clang/test/Driver/Inputs/empty.hip
  clang/test/Driver/hip-phases.hip


Index: clang/test/Driver/hip-phases.hip
===
--- clang/test/Driver/hip-phases.hip
+++ clang/test/Driver/hip-phases.hip
@@ -338,7 +338,7 @@
 // RL2-NB-NOT: linker
 // RL2-NB-NOT: offload
 
-// NL2-DAG: [[P4:[0-9]+]]: linker, {[[P0]], [[P2]]}, image, (host-[[T:hip]])
+// NL2-DAG: [[P4:[0-9]+]]: linker, {[[P0]], [[P2]]}, image
 // RL2-EM-DAG: [[P4:[0-9]+]]: linker, {[[P1]], [[P3]], [[P9]]}, image, 
(host-[[T]])
 // RL2-DEV-NOT: linker
 
@@ -455,3 +455,21 @@
 // PPELLVM2-DAG: [[P9:[0-9]+]]: offload, "device-[[T]] 
(amdgcn-amd-amdhsa:[[ARCH2]])" {[[P8]]}, ir
 // PPELLVM2-DAG: [[P10:[0-9]+]]: clang-offload-bundler, {[[P4]], [[P9]]}, ir, 
(device-hip, )
 // PPELLVM2-NOT: host
+
+// Test mixed HIP and C++ compilation. HIP program should have HIP offload 
kind.
+// C++ program should have no offload kind.
+
+// RUN: %clang -target x86_64-unknown-linux-gnu \
+// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN: -c %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck 
-check-prefixes=MIXED %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu \
+// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN: -c %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck 
-check-prefixes=MIXED-NEG %s
+
+// MIXED-DAG: input, "{{.*}}empty.hip", hip, (host-hip)
+// MIXED-DAG: input, "{{.*}}empty.hip", hip, (device-hip, gfx803)
+// MIXED-DAG: input, "{{.*}}empty.hip", hip, (device-hip, gfx900)
+// MIXED-DAG: input, "{{.*}}empty.cpp", c++
+// MIXED-NEG-NOT: input, "{{.*}}empty.cpp", c++, (host-hip)
+// MIXED-NEG-NOT: input, "{{.*}}empty.cpp", c++, (device-hip
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2692,6 +2692,7 @@
   UA->registerDependentActionInfo(ToolChains[0], Arch,
   AssociatedOffloadKind);
 }
+IsActive = true;
 return ABRT_Success;
   }
 
@@ -3038,6 +3039,9 @@
 getDeviceDependences(OffloadAction::DeviceDependences &DA,
  phases::ID CurPhase, phases::ID FinalPhase,
  PhasesTy &Phases) override {
+  if (!IsActive)
+return ABRT_Inactive;
+
   // amdgcn does not support linking of object files, therefore we skip
   // backend and assemble phases to output LLVM IR. Except for generating
   // non-relocatable device coee, where we generate fat binary for device


Index: clang/test/Driver/hip-phases.hip
===
--- clang/test/Driver/hip-phases.hip
+++ clang/test/Driver/hip-phases.hip
@@ -338,7 +338,7 @@
 // RL2-NB-NOT: linker
 // RL2-NB-NOT: offload
 
-// NL2-DAG: [[P4:[0-9]+]]: linker, {[[P0]], [[P2]]}, image, (host-[[T:hip]])
+// NL2-DAG: [[P4:[0-9]+]]: linker, {[[P0]], [[P2]]}, image
 // RL2-EM-DAG: [[P4:[0-9]+]]: linker, {[[P1]], [[P3]], [[P9]]}, image, (host-[[T]])
 // RL2-DEV-NOT: linker
 
@@ -455,3 +455,21 @@
 // PPELLVM2-DAG: [[P9:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa:[[ARCH2]])" {[[P8]]}, ir
 // PPELLVM2-DAG: [[P10:[0-9]+]]: clang-offload-bundler, {[[P4]], [[P9]]}, ir, (device-hip, )
 // PPELLVM2-NOT: host
+
+// Test mixed HIP and C++ compilation. HIP program should have HIP offload kind.
+// C++ program should have no offload kind.
+
+// RUN: %clang -target x86_64-unknown-linux-gnu \
+// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN: -c %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu \
+// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN: -c %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED-NEG %s
+
+// MIXED-DAG: input, "{{.*}}empty.hip", hip, (host-hip)
+// MIXED-DAG: input, "{{.*}}empty.hip", hip, (device-hip, gfx803)
+// MIXED-DAG: input, "{{.*}}empty.hip", hip, (device-hip, gfx900)
+// MIXED-DAG: input, "{{.*}}empty.cpp", c++
+// MIXED-NEG-NOT: input, "{{.*}}empty.cpp", c++, (host-hip)
+// MIXED-NEG-NOT: input, "{{.*}}empty.cpp", c++, (device-hip
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2692,6 +2692,7 @@
 

[PATCH] D120911: [CUDA][HIP] Fix offloading kind for linking C++ programs

2022-03-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a subscriber: carlosgalvezp.
Herald added a project: All.
yaxunl requested review of this revision.

When both CUDA or HIP programs and C++ programs are passed
to clang driver without `-c`, C++ programs are treated as CUDA
or HIP program, which is incorrect.

This is because action builder sets the offloading kind of input
job actions to the linking action to be the union of offloading
kind of the input job actions, i.e. if there is one HIP or CUDA
input to the linker, then all the input to the linker is marked
as HIP or CUDA.

To fix this issue, the offload action builder tracks the originating
input argument of each host action, which allows it to determine
the active offload kind of each host action. Then the offload
kind of each input action to the linker can be determined
individually.


https://reviews.llvm.org/D120911

Files:
  clang/include/clang/Driver/Action.h
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/hip-phases.hip

Index: clang/test/Driver/hip-phases.hip
===
--- clang/test/Driver/hip-phases.hip
+++ clang/test/Driver/hip-phases.hip
@@ -463,10 +463,26 @@
 // RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
 // RUN: -c %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED %s
 
+// RUN: %clang -target x86_64-unknown-linux-gnu \
+// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN: %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu --hip-link -fgpu-rdc \
+// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN: %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED %s
+
 // RUN: %clang -target x86_64-unknown-linux-gnu \
 // RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
 // RUN: -c %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED-NEG %s
 
+// RUN: %clang -target x86_64-unknown-linux-gnu \
+// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN: %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED-NEG %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu --hip-link -fgpu-rdc \
+// RUN: -ccc-print-phases --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN: %S/Inputs/empty.hip %S/Inputs/empty.cpp 2>&1 | FileCheck -check-prefixes=MIXED-NEG %s
+
 // MIXED-DAG: input, "{{.*}}empty.hip", hip, (host-hip)
 // MIXED-DAG: input, "{{.*}}empty.hip", hip, (device-hip, gfx803)
 // MIXED-DAG: input, "{{.*}}empty.hip", hip, (device-hip, gfx900)
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2465,6 +2465,9 @@
   /// Map between an input argument and the offload kinds used to process it.
   std::map InputArgToOffloadKindMap;
 
+  /// Map between a host action and its originating input argument.
+  std::map HostActionToInputArgMap;
+
   /// Builder interface. It doesn't build anything or keep any state.
   class DeviceActionBuilder {
   public:
@@ -3449,6 +3452,17 @@
   delete SB;
   }
 
+  /// Record a host action and its originating input argument.
+  void recordHostAction(Action *HostAction, const Arg *InputArg) {
+assert(HostAction && "Invalid host action");
+assert(InputArg && "Invalid input argument");
+auto Loc = HostActionToInputArgMap.find(HostAction);
+if (Loc == HostActionToInputArgMap.end())
+  HostActionToInputArgMap[HostAction] = InputArg;
+assert(HostActionToInputArgMap[HostAction] == InputArg &&
+   "host action mapped to multiple input arguments");
+  }
+
   /// Generate an action that adds device dependences (if any) to a host action.
   /// If no device dependence actions exist, just return the host action \a
   /// HostAction. If an error is found or if no builder requires the host action
@@ -3464,6 +3478,7 @@
   return HostAction;
 
 assert(HostAction && "Invalid host action!");
+recordHostAction(HostAction, InputArg);
 
 OffloadAction::DeviceDependences DDeps;
 // Check if all the programming models agree we should not emit the host
@@ -3517,6 +3532,8 @@
 if (!IsValid)
   return true;
 
+recordHostAction(HostAction, InputArg);
+
 // If we are supporting bundling/unbundling and the current action is an
 // input action of non-source file, we replace the host action by the
 // unbundling action. The bundler tool has the logic to detect if an input
@@ -3533,6 +3550,7 @@
   C.getSingleOffloadToolChain(),
   /*BoundArch=*/StringRef(), Action::OFK_Host);
   HostAction = UnbundlingHostAction;
+  recordHostAction(HostAction, InputArg);
 }
 
 assert(HostAction && "Invalid host action!");
@@ -3569,6 +3587,9 @@
   /// pr

[clang] 7b85f0f - [PS4] isPS4 and isPS4CPU are not meaningfully different

2022-03-03 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-03-03T11:36:59-05:00
New Revision: 7b85f0f32f81f594016b065f71b58373cf2f7d35

URL: 
https://github.com/llvm/llvm-project/commit/7b85f0f32f81f594016b065f71b58373cf2f7d35
DIFF: 
https://github.com/llvm/llvm-project/commit/7b85f0f32f81f594016b065f71b58373cf2f7d35.diff

LOG: [PS4] isPS4 and isPS4CPU are not meaningfully different

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/Arch/X86.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Lex/InitHeaderSearch.cpp
clang/lib/Sema/SemaTemplate.cpp
llvm/include/llvm/ADT/Triple.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86Subtarget.h
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8e18ded7d3765..34884f621e770 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1195,12 +1195,12 @@ class TargetInfo : public virtual 
TransferrableTargetInfo,
   /// Microsoft C++ code using dllimport/export attributes?
   virtual bool shouldDLLImportComdatSymbols() const {
 return getTriple().isWindowsMSVCEnvironment() ||
-   getTriple().isWindowsItaniumEnvironment() || getTriple().isPS4CPU();
+   getTriple().isWindowsItaniumEnvironment() || getTriple().isPS4();
   }
 
   // Does this target have PS4 specific dllimport/export handling?
   virtual bool hasPS4DLLImportExport() const {
-return getTriple().isPS4CPU() ||
+return getTriple().isPS4() ||
// Windows Itanium support allows for testing the SCEI flavour of
// dllimport/export handling on a Windows system.
(getTriple().isWindowsItaniumEnvironment() &&

diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index d657d21bfcdb0..88e8ae76ccb20 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -67,8 +67,8 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList 
&Args,
   return ToolChain::RM_Disabled;
   }
 
-  // -frtti is default, except for the PS4 CPU.
-  return (Triple.isPS4CPU()) ? ToolChain::RM_Disabled : ToolChain::RM_Enabled;
+  // -frtti is default, except for the PS4.
+  return (Triple.isPS4()) ? ToolChain::RM_Disabled : ToolChain::RM_Enabled;
 }
 
 ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,

diff  --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index bfa008f964e19..73df835585239 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -89,7 +89,7 @@ std::string x86::getX86TargetCPU(const Driver &D, const 
ArgList &Args,
   }
 
   // Set up default CPU name for PS4 compilers.
-  if (Triple.isPS4CPU())
+  if (Triple.isPS4())
 return "btver2";
 
   // On Android use targets compatible with gcc

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 14f33a0ae66e9..7cb8df6e44c04 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -451,7 +451,7 @@ static bool addExceptionArgs(const ArgList &Args, types::ID 
InputType,
   if (types::isCXX(InputType)) {
 // Disable C++ EH by default on XCore and PS4.
 bool CXXExceptionsEnabled =
-Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU();
+Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4();
 Arg *ExceptionArg = Args.getLastArg(
 options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions,
 options::OPT_fexceptions, options::OPT_fno_exceptions);
@@ -612,10 +612,10 @@ getFramePointerKind(const ArgList &Args, const 
llvm::Triple &Triple) {
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool OmitLeafFP = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
- options::OPT_mno_omit_leaf_frame_pointer,
- Triple.isAArch64() || Triple.isPS4CPU() ||
- Triple.isVE());
+  bool OmitLeafFP =
+  Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+   options::OPT_mno_omit_leaf_frame_pointer,
+   Triple.isAArch64() || Triple.isPS4() || Triple.isVE());
   if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
   (!OmitFP && useFrameP

[PATCH] D120132: [HIP] Fix HIP include path

2022-03-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.
Herald added a project: All.

In D120132#3352255 , @tra wrote:

> In D120132#3351999 , @yaxunl wrote:
>
>> In D120132#3351853 , @tra wrote:
>>
>>> In D120132#3351391 , @yaxunl 
>>> wrote:
>>>
 
>>>
>>>
>>>
 If any input file is HIP program, clang driver will use HIP offload kind 
 for all inputs. This behavior is similar as cuda-clang.
>>>
>>> I do not think this is the case as illustrated by the example above. CUDA 
>>> paths are only added to CUDA compilation. C++ compilation of `b.cc` does 
>>> not have any of them.
>>
>> I noticed that with "-c" HIP/CUDA include path is not used for C++ program. 
>> However without "-c" HIP/CUDA include path is used for C++ program. Probably 
>> this is a bug.
>
> This is, indeed, a bug. cc1 invocation for a C++ file should have remained 
> the same, yet we're passing not only include paths but also a bunch of other 
> CUDA-related options that are not relevant for C++ compilation.
>
>> In the current patch, AddClangSystemIncludeArgs is modified to add HIP 
>> include path. However, there is no good way to know if the current job 
>> action is HIP or C++ program.
>>
>> The signature of AddClangSystemIncludeArgs is
>>
>>   void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
>> ArgStringList &CC1Args) const ;
>>
>> In the case of two input files `a.hip` and `b.cpp`, DriverArgs contain both 
>> `a.hip` and `b.cpp`. Clang does not know if the call of 
>> AddClangSystemIncludeArgs is for `a.hip` or `b.cpp`. The current patch adds 
>> HIP include path for both HIP and C++ programs.
>>
>> To fix this issue, we either need to add a JobAction argument to 
>> AddClangSystemIncludeArgs to let clang know the current call of 
>> AddClangSystemIncludeArgs is for HIP program or C++ program, or we need to 
>> add HIP include path in a location where the current JobAction is known.
>
> I think we first  need to figure out first why compilation w/o `-c` behaves 
> incorrectly and what we can do about it.
> I suspect if we fix it and make clang add options consistently regardless of 
> whether we use `-c` or not, then we would not need to pass job info around. 
> That is, unless the fix is to pass that info around. :-/
>
> IMO mixed-language compilation falls into a grey area where it may sometimes 
> work, but I doubt it's expected to work in general. I don't think it's worth 
> complicating things over it.

I created two patches for fixing the existing issues about CUDA/HIP include path

https://reviews.llvm.org/D120910 - HIP specific issue for "-c" with mixed 
HIP/C++ programs

https://reviews.llvm.org/D120911 - common CUDA/HIP issue for linking with mixed 
HIP/C++ programs

These issues are due to active offload kind of job actions not set correctly 
for mixed CUDA or HIP programs and C++ programs.

These issues are orthogonal to the issue which the current patch is trying to 
resolve.

Even with the above two issues fixed, my argument for the current patch still 
holds. And it is not just for mixed-language. It happens with single language 
too. To fix this issue, we either need to add a JobAction argument to 
AddClangSystemIncludeArgs to let clang know the current call of 
AddClangSystemIncludeArgs is for HIP program or C++ program, or we need to add 
HIP include path in a location where the current JobAction is known.


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

https://reviews.llvm.org/D120132

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


[clang] 3717b96 - [NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in

2022-03-03 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2022-03-03T08:54:46-08:00
New Revision: 3717b9661fd660933811c980a36a5e5deb8dcf40

URL: 
https://github.com/llvm/llvm-project/commit/3717b9661fd660933811c980a36a5e5deb8dcf40
DIFF: 
https://github.com/llvm/llvm-project/commit/3717b9661fd660933811c980a36a5e5deb8dcf40.diff

LOG: [NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in
CGBlocks.cpp

Differential Revision: https://reviews.llvm.org/D120856

Added: 


Modified: 
clang/lib/CodeGen/CGBlocks.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 5af61e52b9be..08f0bf692314 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1263,8 +1263,7 @@ Address CodeGenFunction::GetAddrOfBlockDecl(const VarDecl 
*variable) {
 // to byref*.
 
 auto &byrefInfo = getBlockByrefInfo(variable);
-addr =
-Address::deprecated(Builder.CreateLoad(addr), 
byrefInfo.ByrefAlignment);
+addr = Address(Builder.CreateLoad(addr), Int8Ty, byrefInfo.ByrefAlignment);
 
 addr = Builder.CreateElementBitCast(addr, byrefInfo.Type, "byref.addr");
 
@@ -1441,7 +1440,7 @@ void CodeGenFunction::setBlockContextParameter(const 
ImplicitParamDecl *D,
 Address CodeGenFunction::LoadBlockStruct() {
   assert(BlockInfo && "not in a block invocation function!");
   assert(BlockPointer && "no block pointer set!");
-  return Address::deprecated(BlockPointer, BlockInfo->BlockAlign);
+  return Address(BlockPointer, BlockInfo->StructureType, 
BlockInfo->BlockAlign);
 }
 
 llvm::Function *CodeGenFunction::GenerateBlockFunction(
@@ -1938,12 +1937,12 @@ CodeGenFunction::GenerateCopyHelperFunction(const 
CGBlockInfo &blockInfo) {
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   Address src = GetAddrOfLocalVar(&SrcDecl);
-  src = Address::deprecated(Builder.CreateLoad(src), blockInfo.BlockAlign);
+  src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign);
   src = Builder.CreateElementBitCast(src, blockInfo.StructureType,
  "block.source");
 
   Address dst = GetAddrOfLocalVar(&DstDecl);
-  dst = Address::deprecated(Builder.CreateLoad(dst), blockInfo.BlockAlign);
+  dst = Address(Builder.CreateLoad(dst), Int8Ty, blockInfo.BlockAlign);
   dst =
   Builder.CreateElementBitCast(dst, blockInfo.StructureType, "block.dest");
 
@@ -2128,7 +2127,7 @@ CodeGenFunction::GenerateDestroyHelperFunction(const 
CGBlockInfo &blockInfo) {
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   Address src = GetAddrOfLocalVar(&SrcDecl);
-  src = Address::deprecated(Builder.CreateLoad(src), blockInfo.BlockAlign);
+  src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign);
   src = Builder.CreateElementBitCast(src, blockInfo.StructureType, "block");
 
   CodeGenFunction::RunCleanupsScope cleanups(*this);
@@ -2373,16 +2372,16 @@ generateByrefCopyHelper(CodeGenFunction &CGF, const 
BlockByrefInfo &byrefInfo,
   if (generator.needsCopy()) {
 // dst->x
 Address destField = CGF.GetAddrOfLocalVar(&Dst);
-destField = Address::deprecated(CGF.Builder.CreateLoad(destField),
-byrefInfo.ByrefAlignment);
+destField = Address(CGF.Builder.CreateLoad(destField), CGF.Int8Ty,
+byrefInfo.ByrefAlignment);
 destField = CGF.Builder.CreateElementBitCast(destField, byrefInfo.Type);
 destField =
 CGF.emitBlockByrefAddress(destField, byrefInfo, false, "dest-object");
 
 // src->x
 Address srcField = CGF.GetAddrOfLocalVar(&Src);
-srcField = Address::deprecated(CGF.Builder.CreateLoad(srcField),
-   byrefInfo.ByrefAlignment);
+srcField = Address(CGF.Builder.CreateLoad(srcField), CGF.Int8Ty,
+   byrefInfo.ByrefAlignment);
 srcField = CGF.Builder.CreateElementBitCast(srcField, byrefInfo.Type);
 srcField =
 CGF.emitBlockByrefAddress(srcField, byrefInfo, false, "src-object");
@@ -2439,8 +2438,8 @@ generateByrefDisposeHelper(CodeGenFunction &CGF,
 
   if (generator.needsDispose()) {
 Address addr = CGF.GetAddrOfLocalVar(&Src);
-addr = Address::deprecated(CGF.Builder.CreateLoad(addr),
-   byrefInfo.ByrefAlignment);
+addr = Address(CGF.Builder.CreateLoad(addr), CGF.Int8Ty,
+   byrefInfo.ByrefAlignment);
 addr = CGF.Builder.CreateElementBitCast(addr, byrefInfo.Type);
 addr = CGF.emitBlockByrefAddress(addr, byrefInfo, false, "object");
 
@@ -2587,8 +2586,8 @@ Address CodeGenFunction::emitBlockByrefAddress(Address 
baseAddr,
   // Chase the forwarding address if requested.
   if (followForward) {
 Address forwardingAddr = Builder.CreateStructGEP(baseAddr, 1, 
"forwarding");
-baseAddr = Address::deprecated(Builder.CreateLoad(forwardingAddr),
-   info.ByrefAlignment);
+baseAd

[PATCH] D120856: [NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in CGBlocks.cpp

2022-03-03 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3717b9661fd6: [NFC][Clang][OpaquePtr] Remove calls to 
Address::deprecated in (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120856

Files:
  clang/lib/CodeGen/CGBlocks.cpp


Index: clang/lib/CodeGen/CGBlocks.cpp
===
--- clang/lib/CodeGen/CGBlocks.cpp
+++ clang/lib/CodeGen/CGBlocks.cpp
@@ -1263,8 +1263,7 @@
 // to byref*.
 
 auto &byrefInfo = getBlockByrefInfo(variable);
-addr =
-Address::deprecated(Builder.CreateLoad(addr), 
byrefInfo.ByrefAlignment);
+addr = Address(Builder.CreateLoad(addr), Int8Ty, byrefInfo.ByrefAlignment);
 
 addr = Builder.CreateElementBitCast(addr, byrefInfo.Type, "byref.addr");
 
@@ -1441,7 +1440,7 @@
 Address CodeGenFunction::LoadBlockStruct() {
   assert(BlockInfo && "not in a block invocation function!");
   assert(BlockPointer && "no block pointer set!");
-  return Address::deprecated(BlockPointer, BlockInfo->BlockAlign);
+  return Address(BlockPointer, BlockInfo->StructureType, 
BlockInfo->BlockAlign);
 }
 
 llvm::Function *CodeGenFunction::GenerateBlockFunction(
@@ -1938,12 +1937,12 @@
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   Address src = GetAddrOfLocalVar(&SrcDecl);
-  src = Address::deprecated(Builder.CreateLoad(src), blockInfo.BlockAlign);
+  src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign);
   src = Builder.CreateElementBitCast(src, blockInfo.StructureType,
  "block.source");
 
   Address dst = GetAddrOfLocalVar(&DstDecl);
-  dst = Address::deprecated(Builder.CreateLoad(dst), blockInfo.BlockAlign);
+  dst = Address(Builder.CreateLoad(dst), Int8Ty, blockInfo.BlockAlign);
   dst =
   Builder.CreateElementBitCast(dst, blockInfo.StructureType, "block.dest");
 
@@ -2128,7 +2127,7 @@
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   Address src = GetAddrOfLocalVar(&SrcDecl);
-  src = Address::deprecated(Builder.CreateLoad(src), blockInfo.BlockAlign);
+  src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign);
   src = Builder.CreateElementBitCast(src, blockInfo.StructureType, "block");
 
   CodeGenFunction::RunCleanupsScope cleanups(*this);
@@ -2373,16 +2372,16 @@
   if (generator.needsCopy()) {
 // dst->x
 Address destField = CGF.GetAddrOfLocalVar(&Dst);
-destField = Address::deprecated(CGF.Builder.CreateLoad(destField),
-byrefInfo.ByrefAlignment);
+destField = Address(CGF.Builder.CreateLoad(destField), CGF.Int8Ty,
+byrefInfo.ByrefAlignment);
 destField = CGF.Builder.CreateElementBitCast(destField, byrefInfo.Type);
 destField =
 CGF.emitBlockByrefAddress(destField, byrefInfo, false, "dest-object");
 
 // src->x
 Address srcField = CGF.GetAddrOfLocalVar(&Src);
-srcField = Address::deprecated(CGF.Builder.CreateLoad(srcField),
-   byrefInfo.ByrefAlignment);
+srcField = Address(CGF.Builder.CreateLoad(srcField), CGF.Int8Ty,
+   byrefInfo.ByrefAlignment);
 srcField = CGF.Builder.CreateElementBitCast(srcField, byrefInfo.Type);
 srcField =
 CGF.emitBlockByrefAddress(srcField, byrefInfo, false, "src-object");
@@ -2439,8 +2438,8 @@
 
   if (generator.needsDispose()) {
 Address addr = CGF.GetAddrOfLocalVar(&Src);
-addr = Address::deprecated(CGF.Builder.CreateLoad(addr),
-   byrefInfo.ByrefAlignment);
+addr = Address(CGF.Builder.CreateLoad(addr), CGF.Int8Ty,
+   byrefInfo.ByrefAlignment);
 addr = CGF.Builder.CreateElementBitCast(addr, byrefInfo.Type);
 addr = CGF.emitBlockByrefAddress(addr, byrefInfo, false, "object");
 
@@ -2587,8 +2586,8 @@
   // Chase the forwarding address if requested.
   if (followForward) {
 Address forwardingAddr = Builder.CreateStructGEP(baseAddr, 1, 
"forwarding");
-baseAddr = Address::deprecated(Builder.CreateLoad(forwardingAddr),
-   info.ByrefAlignment);
+baseAddr = Address(Builder.CreateLoad(forwardingAddr), info.Type,
+   info.ByrefAlignment);
   }
 
   return Builder.CreateStructGEP(baseAddr, info.FieldIndex, name);


Index: clang/lib/CodeGen/CGBlocks.cpp
===
--- clang/lib/CodeGen/CGBlocks.cpp
+++ clang/lib/CodeGen/CGBlocks.cpp
@@ -1263,8 +1263,7 @@
 // to byref*.
 
 auto &byrefInfo = getBlockByrefInfo(variable);
-addr =
-Address::deprecated(Builder.CreateLoad(addr), byrefInfo.ByrefAlignment);
+addr = Address(Builder.CreateLoad(addr), Int8Ty, byrefInfo.ByrefAlignment);
 
 addr = Builder.CreateElementBitCast(addr, byr

[PATCH] D120907: [docs] Add PowerPC release notes for LLVM 14

2022-03-03 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

LGTM for libc++. I assume this is targeting `release/14.x` only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120907

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


[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Is there anything special about `SourceLocation`s? I wonder whether we just 
want a templated `Set` lattice and instantiate it with `SourceLocation`s.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120890

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


[clang] de5785a - [NFC] Change TemplateInstantiator to refer to the base using a typedef

2022-03-03 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2022-03-03T09:12:05-08:00
New Revision: de5785ad9d61c6b59793a6438a08973da42f9039

URL: 
https://github.com/llvm/llvm-project/commit/de5785ad9d61c6b59793a6438a08973da42f9039
DIFF: 
https://github.com/llvm/llvm-project/commit/de5785ad9d61c6b59793a6438a08973da42f9039.diff

LOG: [NFC] Change TemplateInstantiator to refer to the base using a typedef

A few places were inconsistent here, which makes a refactor to support
delayed concepts significantly more difficult.

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 46da97968a937..1143023bb5baa 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1121,12 +1121,12 @@ namespace {
 
 ExprResult TransformLambdaExpr(LambdaExpr *E) {
   LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
-  return TreeTransform::TransformLambdaExpr(E);
+  return inherited::TransformLambdaExpr(E);
 }
 
 ExprResult TransformRequiresExpr(RequiresExpr *E) {
   LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
-  return TreeTransform::TransformRequiresExpr(E);
+  return inherited::TransformRequiresExpr(E);
 }
 
 bool TransformRequiresExprRequirements(
@@ -1336,10 +1336,7 @@ 
TemplateInstantiator::RebuildElaboratedType(SourceLocation KeywordLoc,
 }
   }
 
-  return TreeTransform::RebuildElaboratedType(KeywordLoc,
-Keyword,
-  QualifierLoc,
-T);
+  return inherited::RebuildElaboratedType(KeywordLoc, Keyword, QualifierLoc, 
T);
 }
 
 TemplateName TemplateInstantiator::TransformTemplateName(
@@ -1714,7 +1711,7 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr 
*E) {
 if (PD->isParameterPack())
   return TransformFunctionParmPackRefExpr(E, PD);
 
-  return TreeTransform::TransformDeclRefExpr(E);
+  return inherited::TransformDeclRefExpr(E);
 }
 
 ExprResult TemplateInstantiator::TransformCXXDefaultArgExpr(



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


[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D120890#3357438 , @xazax.hun wrote:

> Is there anything special about `SourceLocation`s? I wonder whether we just 
> want a templated `PowerSet` lattice and instantiate it with `SourceLocation`s.

Not really. Just that we use this lattice in a bunch of analyses for "unsafe 
access", like `std::optional` and `absl::Statusor` and (eventually) pointers. 
So, it seems generally useful as is. I agree that we should have core powerset 
lattice, its just that doing so will require a little more design effort 
(similar to the map lattice I added).  Happy to add that as a FIXME (which we 
plan to start tacking with github issues soon!), if that sounds good to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120890

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


[PATCH] D120900: [clang][dataflow] Add `MatchSwitch` utility library.

2022-03-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h:51
+template 
+using MatchSwitch = std::function;
+

When we instantiate this with `TransferState` we have `ASTContext` both as an 
argument and as a member of `State`. Is this intentional?



Comment at: clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h:110
+size_t Index = 0;
+if (ID.consume_front("Tag") && !ID.getAsInteger(10, Index) &&
+Index < Actions.size()) {

This does not need to be addressed here but it looks like it could be a useful 
feature to be able to tag nodes with integer identifiers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120900

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


[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
Herald added a subscriber: rnkovacs.

In D120890#3357454 , @ymandel wrote:

> In D120890#3357438 , @xazax.hun 
> wrote:
>
>> Is there anything special about `SourceLocation`s? I wonder whether we just 
>> want a templated `PowerSet` lattice and instantiate it with 
>> `SourceLocation`s.
>
> Not really. Just that we use this lattice in a bunch of analyses for "unsafe 
> access", like `std::optional` and `absl::Statusor` and (eventually) pointers. 
> So, it seems generally useful as is. I agree that we should have core 
> powerset lattice, its just that doing so will require a little more design 
> effort (similar to the map lattice I added).  Happy to add that as a FIXME 
> (which we plan to start tacking with github issues soon!), if that sounds 
> good to you.

Sounds good, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120890

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


[PATCH] D120360: [libTooling] Generalize string explanation as Any metadata

2022-03-03 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua updated this revision to Diff 412746.
li.zhe.hua marked 7 inline comments as done.
li.zhe.hua added a comment.

Fixes from comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120360

Files:
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
  clang/include/clang/Tooling/Transformer/RewriteRule.h
  clang/include/clang/Tooling/Transformer/Transformer.h
  clang/lib/Tooling/Transformer/RewriteRule.cpp
  clang/lib/Tooling/Transformer/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -31,9 +31,11 @@
 using ::clang::transformer::member;
 using ::clang::transformer::name;
 using ::clang::transformer::node;
+using ::clang::transformer::noEdits;
 using ::clang::transformer::remove;
 using ::clang::transformer::rewriteDescendants;
 using ::clang::transformer::RewriteRule;
+using ::clang::transformer::RewriteRuleWith;
 using ::clang::transformer::statement;
 using ::testing::ElementsAre;
 using ::testing::IsEmpty;
@@ -129,7 +131,7 @@
 Changes.insert(Changes.end(), std::make_move_iterator(C->begin()),
std::make_move_iterator(C->end()));
   } else {
-// FIXME: stash this error rather then printing.
+// FIXME: stash this error rather than printing.
 llvm::errs() << "Error generating changes: "
  << llvm::toString(C.takeError()) << "\n";
 ++ErrorCount;
@@ -137,27 +139,58 @@
 };
   }
 
-  template 
-  void testRule(R Rule, StringRef Input, StringRef Expected) {
+  auto consumerWithStringMetadata() {
+return [this](Expected> C) {
+  if (C) {
+Changes.insert(Changes.end(),
+   std::make_move_iterator(C->Changes.begin()),
+   std::make_move_iterator(C->Changes.end()));
+StringMetadata.push_back(std::move(C->Metadata));
+  } else {
+// FIXME: stash this error rather than printing.
+llvm::errs() << "Error generating changes: "
+ << llvm::toString(C.takeError()) << "\n";
+++ErrorCount;
+  }
+};
+  }
+
+  void testRule(RewriteRule Rule, StringRef Input, StringRef Expected) {
 Transformers.push_back(
 std::make_unique(std::move(Rule), consumer()));
 Transformers.back()->registerMatchers(&MatchFinder);
 compareSnippets(Expected, rewrite(Input));
   }
 
-  template  void testRuleFailure(R Rule, StringRef Input) {
+  void testRule(RewriteRuleWith Rule, StringRef Input,
+StringRef Expected) {
+Transformers.push_back(std::make_unique(
+std::move(Rule), consumerWithStringMetadata()));
+Transformers.back()->registerMatchers(&MatchFinder);
+compareSnippets(Expected, rewrite(Input));
+  }
+
+  void testRuleFailure(RewriteRule Rule, StringRef Input) {
 Transformers.push_back(
 std::make_unique(std::move(Rule), consumer()));
 Transformers.back()->registerMatchers(&MatchFinder);
 ASSERT_FALSE(rewrite(Input)) << "Expected failure to rewrite code";
   }
 
+  void testRuleFailure(RewriteRuleWith Rule, StringRef Input) {
+Transformers.push_back(std::make_unique(
+std::move(Rule), consumerWithStringMetadata()));
+Transformers.back()->registerMatchers(&MatchFinder);
+ASSERT_FALSE(rewrite(Input)) << "Expected failure to rewrite code";
+  }
+
   // Transformers are referenced by MatchFinder.
   std::vector> Transformers;
   clang::ast_matchers::MatchFinder MatchFinder;
   // Records whether any errors occurred in individual changes.
   int ErrorCount = 0;
   AtomicChanges Changes;
+  std::vector StringMetadata;
 
 private:
   FileContentMappings FileContents = {{"header.h", ""}};
@@ -169,7 +202,7 @@
 };
 
 // Given string s, change strlen($s.c_str()) to REPLACED.
-static RewriteRule ruleStrlenSize() {
+static RewriteRuleWith ruleStrlenSize() {
   StringRef StringExpr = "strexpr";
   auto StringType = namedDecl(hasAnyName("::basic_string", "::string"));
   auto R = makeRule(
@@ -886,12 +919,12 @@
 
 TEST_F(TransformerTest, OrderedRuleUnrelated) {
   StringRef Flag = "flag";
-  RewriteRule FlagRule = makeRule(
+  RewriteRuleWith FlagRule = makeRule(
   cxxMemberCallExpr(on(expr(hasType(cxxRecordDecl(
 hasName("proto::ProtoCommandLineFlag"
.bind(Flag)),
 unless(callee(cxxMethodDecl(

[PATCH] D120360: [libTooling] Generalize string explanation as Any metadata

2022-03-03 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua added inline comments.



Comment at: clang/include/clang/Tooling/Transformer/RewriteRule.h:300
 /// Constructs a simple \c RewriteRule.
 RewriteRule makeRule(ast_matchers::internal::DynTypedMatcher M,
+ EditGenerator Edits);

ymandel wrote:
> Maybe add an adaptor for edit generator like we do in Stencil::cat. That will 
> allow us to collapse the 6 overloads (2 * 3) into 2 (for makerule) + 3 (for 
> the adaptor).  Only saves 1 but I think it will clearer and more flexible for 
> the future.
So, I ended up needing to add an overload for `std::initializer_list` as well, 
as it was somewhat common for people to do something like


```
makeRule(matchers(), {doThing1(), doThing2()})
```

which would have gone to the `llvm::SmallVector` overload.



Comment at: clang/include/clang/Tooling/Transformer/Transformer.h:48
+/// \c RewriteRule.
+class PlainConsumer final : public TransformerImpl {
+  transformer::RewriteRule Rule;

ymandel wrote:
> I'm afraid the use of the name `Consumer` (here and below) might be confused 
> with the `Consumer` argument.  What about just `Impl` or something similar?
I went with `NoMetadataImpl` (to be more descriptive than "plain") and 
`WithMetadataImpl`.



Comment at: clang/include/clang/Tooling/Transformer/Transformer.h:116
+  explicit Transformer(transformer::RewriteRuleWith Rule,
+   ConsumerFn Consumer);
 

ymandel wrote:
> why won't we have the same SFINAE here to ensure ConsumerFn is invocable?
I can't figure out how to implement the SFINAE without instantiating 
`Result` (which is invalid because `T Metadata` is illegal then). My 
current attempt is

```
  template <
  typename T, typename ConsumerFn,
  std::enable_if_t<
  std::conjunction<
  std::negation>,
  llvm::is_invocable>>>::value,
  int> = 0>
  explicit Transformer(transformer::RewriteRuleWith Rule,
   ConsumerFn Consumer);
```

I suppose I could provide a specialization of `Result` that is valid? I 
guess I'll go with that, and just document why it exists?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120360

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


[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 412747.
ymandel added a comment.

added FIXME


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120890

Files:
  clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp
@@ -0,0 +1,68 @@
+//===- unittests/Analysis/FlowSensitive/SourceLocationsLatticeTest.cpp ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/SourceLocationsLattice.h"
+
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Basic/SourceLocation.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace dataflow {
+namespace {
+
+TEST(SourceLocationsLatticeTest, Comparison) {
+  const SourceLocationsLattice Bottom;
+  const SourceLocationsLattice NonBottom(
+  {SourceLocation::getFromRawEncoding(0)});
+
+  EXPECT_TRUE(Bottom == Bottom);
+  EXPECT_FALSE(Bottom == NonBottom);
+  EXPECT_FALSE(NonBottom == Bottom);
+  EXPECT_TRUE(NonBottom == NonBottom);
+
+  EXPECT_FALSE(Bottom != Bottom);
+  EXPECT_TRUE(Bottom != NonBottom);
+  EXPECT_TRUE(NonBottom != Bottom);
+  EXPECT_FALSE(NonBottom != NonBottom);
+}
+
+TEST(SourceLocationsLatticeTest, Join) {
+  const SourceLocationsLattice Bottom;
+  const SourceLocationsLattice NonBottom(
+  {SourceLocation::getFromRawEncoding(0)});
+  {
+SourceLocationsLattice LHS = Bottom;
+const SourceLocationsLattice RHS = Bottom;
+EXPECT_EQ(LHS.join(RHS), LatticeJoinEffect::Unchanged);
+EXPECT_EQ(LHS, Bottom);
+  }
+  {
+SourceLocationsLattice LHS = NonBottom;
+const SourceLocationsLattice RHS = Bottom;
+EXPECT_EQ(LHS.join(RHS), LatticeJoinEffect::Unchanged);
+EXPECT_EQ(LHS, NonBottom);
+  }
+  {
+SourceLocationsLattice LHS = Bottom;
+const SourceLocationsLattice RHS = NonBottom;
+EXPECT_EQ(LHS.join(RHS), LatticeJoinEffect::Changed);
+EXPECT_EQ(LHS, NonBottom);
+  }
+  {
+SourceLocationsLattice LHS = NonBottom;
+const SourceLocationsLattice RHS = NonBottom;
+EXPECT_EQ(LHS.join(RHS), LatticeJoinEffect::Unchanged);
+EXPECT_EQ(LHS, NonBottom);
+  }
+}
+
+} // namespace
+} // namespace dataflow
+} // namespace clang
Index: clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
===
--- clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
+++ clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
@@ -9,6 +9,7 @@
   MapLatticeTest.cpp
   MultiVarConstantPropagationTest.cpp
   SingleVarConstantPropagationTest.cpp
+  SourceLocationsLatticeTest.cpp
   TestingSupport.cpp
   TestingSupportTest.cpp
   TransferTest.cpp
Index: clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
===
--- /dev/null
+++ clang/lib/Analysis/FlowSensitive/SourceLocationsLattice.cpp
@@ -0,0 +1,51 @@
+//===- SourceLocationsLattice.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file implements a lattice that collects source locations of interest.
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/SourceLocationsLattice.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace dataflow {
+
+LatticeJoinEffect
+SourceLocationsLattice::join(const SourceLocationsLattice &Other) {
+  auto SizeBefore = Locs.size();
+  Locs.insert(Other.Locs.begin(), Other.Locs.end());
+  return SizeBefore == Locs.size() ? LatticeJoinEffect::Unchanged
+   : LatticeJoinEffect::Changed;
+}
+
+std::string DebugString(const SourceLocationsLattice &Lattice,
+const ASTContext &Context) {
+  if (Lattice.getSourceLocations().empty())
+retur

[PATCH] D120814: [clang-tidy] Add check to perfer pre-increment over post-increment

2022-03-03 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

See D72553 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120814

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


[PATCH] D120890: [clang][dataflow] Add a lattice to track source locations.

2022-03-03 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev accepted this revision.
sgatev added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/SourceLocationsLattice.h:56
+// Returns a string that represents the source locations of the lattice.
+std::string DebugString(const SourceLocationsLattice &Lattice,
+const ASTContext &Context);

ymandel wrote:
> sgatev wrote:
> > Can you please add tests for this too?
> I'm not sure what I would test, since it (intentionally) has no guaranteed 
> API. Do you have something particular in mind? I generally avoid testing 
> things like DebugString because we don't want users to rely on them.
Fair point. Let's keep it as is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120890

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


[PATCH] D120489: [analyzer] Done some changes to detect Uninitialized read by the char array manipulation functions

2022-03-03 Thread Shivam Rajput via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbd1917c88a32: [analyzer] Done some changes to detect 
Uninitialized read by the char array… (authored by Shivam 
<75530356+phybrack...@users.noreply.github.com>, committed by 
phyBrackets).

Changed prior to commit:
  https://reviews.llvm.org/D120489?vs=412464&id=412750#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120489

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/bstring.c
  clang/test/Analysis/bstring_UninitRead.c

Index: clang/test/Analysis/bstring_UninitRead.c
===
--- /dev/null
+++ clang/test/Analysis/bstring_UninitRead.c
@@ -0,0 +1,59 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN: -analyzer-checker=core,alpha.unix.cstring
+
+
+// This file is generally for the alpha.unix.cstring.UninitializedRead Checker, the reason for putting it into
+// the separate file because the checker is break the some existing test cases in bstring.c file , so we don't 
+// wanna mess up with some existing test case so it's better to create separate file for it, this file also include 
+// the broken test for the reference in future about the broken tests.
+
+
+typedef typeof(sizeof(int)) size_t;
+
+void clang_analyzer_eval(int);
+
+void *memcpy(void *restrict s1, const void *restrict s2, size_t n);
+
+void top(char *dst) {
+  char buf[10];
+  memcpy(dst, buf, 10); // expected-warning{{Bytes string function accesses uninitialized/garbage values}}
+  (void)buf;
+}
+
+//===--===
+// mempcpy()
+//===--===
+
+void *mempcpy(void *restrict s1, const void *restrict s2, size_t n);
+
+void mempcpy14() {
+  int src[] = {1, 2, 3, 4};
+  int dst[5] = {0};
+  int *p;
+
+  p = mempcpy(dst, src, 4 * sizeof(int)); // expected-warning{{Bytes string function accesses uninitialized/garbage values}}
+   // FIXME: This behaviour is actually surprising and needs to be fixed, 
+   // mempcpy seems to consider the very last byte of the src buffer uninitialized
+   // and returning undef unfortunately. It should have returned unknown or a conjured value instead.
+
+  clang_analyzer_eval(p == &dst[4]); // no-warning (above is fatal)
+}
+
+struct st {
+  int i;
+  int j;
+};
+
+
+void mempcpy15() {
+  struct st s1 = {0};
+  struct st s2;
+  struct st *p1;
+  struct st *p2;
+
+  p1 = (&s2) + 1;
+  p2 = mempcpy(&s2, &s1, sizeof(struct st)); // expected-warning{{Bytes string function accesses uninitialized/garbage values}}
+  // FIXME: It seems same as mempcpy14() case.
+  
+  clang_analyzer_eval(p1 == p2); // no-warning (above is fatal)
+}
Index: clang/test/Analysis/bstring.c
===
--- clang/test/Analysis/bstring.c
+++ clang/test/Analysis/bstring.c
@@ -2,13 +2,15 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=unix.cstring \
 // RUN:   -analyzer-checker=alpha.unix.cstring \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.UninitializedRead \
 // RUN:   -analyzer-checker=debug.ExprInspection \
-// RUN:   -analyzer-config eagerly-assume=false
+// RUN:   -analyzer-config eagerly-assume=false  
 //
 // RUN: %clang_analyze_cc1 -verify %s -DUSE_BUILTINS \
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=unix.cstring \
 // RUN:   -analyzer-checker=alpha.unix.cstring \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.UninitializedRead \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config eagerly-assume=false
 //
@@ -16,6 +18,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=unix.cstring \
 // RUN:   -analyzer-checker=alpha.unix.cstring \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.UninitializedRead \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config eagerly-assume=false
 //
@@ -23,6 +26,7 @@
 // RUN:   -analyzer-checker=core \
 // RUN:   -analyzer-checker=unix.cstring \
 // RUN:   -analyzer-checker=alpha.unix.cstring \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.UninitializedRead \
 // RUN:   -analyzer-checker=debug.ExprInspection \
 // RUN:   -analyzer-config eagerly-assume=false
 
@@ -315,7 +319,7 @@
 
   p1 = (&s2) + 1;
   p2 = mempcpy(&s2, &s1, sizeof(struct st));
-
+  
   clang_analyzer_eval(p1 == p2); // expected-warning{{TRUE}}
 }
 
Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -80,7 +80,7 @@
  

[clang] bd1917c - [analyzer] Done some changes to detect Uninitialized read by the char array manipulation functions

2022-03-03 Thread via cfe-commits

Author: Shivam
Date: 2022-03-03T23:21:26+05:30
New Revision: bd1917c88a32c0930864d04f4e71155dcc3fa592

URL: 
https://github.com/llvm/llvm-project/commit/bd1917c88a32c0930864d04f4e71155dcc3fa592
DIFF: 
https://github.com/llvm/llvm-project/commit/bd1917c88a32c0930864d04f4e71155dcc3fa592.diff

LOG: [analyzer] Done some changes to detect Uninitialized read by the char 
array manipulation functions

Few weeks back I was experimenting with reading the uninitialized values from 
src , which is actually a bug but the CSA seems to give up at that point . I 
was curious about that and I pinged @steakhal on the discord and according to 
him this seems to be a genuine issue and needs to be fix. So I goes with fixing 
this bug and thanks to @steakhal who help me creating this patch. This feature 
seems to break some tests but this was the genuine problem and the broken tests 
also needs to fix in certain manner. I add a test but yeah we need more 
tests,I'll try to add more tests.Thanks

Reviewed By: steakhal, NoQ

Differential Revision: https://reviews.llvm.org/D120489

Added: 
clang/test/Analysis/bstring_UninitRead.c

Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/test/Analysis/bstring.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index a42e3e6960777..a9ebe063c6c8b 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2625,13 +2625,44 @@ alpha.unix.cstring.OutOfBounds (C)
 ""
 Check for out-of-bounds access in string functions; applies to:`` strncopy, 
strncat``.
 
-
 .. code-block:: c
 
  void test() {
int y = strlen((char *)&test); // warn
  }
 
+.. _alpha-unix-cstring-UninitializedRead:
+
+alpha.unix.cstring.UninitializedRead (C)
+
+Check for uninitialized reads from common memory copy/manipulation functions 
such as:
+ ``memcpy, mempcpy, memmove, memcmp, strcmp, strncmp, strcpy, strlen, strsep`` 
and many more.
+
+.. code-block:: c 
+
+ void test() {
+  char src[10];
+  char dst[5];
+  memcpy(dst,src,sizeof(dst)); // warn: Bytes string function accesses 
uninitialized/garbage values
+ }
+
+Limitations:
+  
+   - Due to limitations of the memory modeling in the analyzer, one can likely
+ observe a lot of false-positive reports like this:
+  .. code-block:: c
+  
+void false_positive() {
+  int src[] = {1, 2, 3, 4};
+  int dst[5] = {0};
+  memcpy(dst, src, 4 * sizeof(int)); // false-positive:
+  // The 'src' buffer was correctly initialized, yet we cannot conclude
+  // that since the analyzer could not see a direct initialization of 
the
+  // very last byte of the source buffer.
+}
+  
+ More details at the corresponding `GitHub issue 
`_.
+  
 .. _alpha-nondeterminism-PointerIteration:
 
 alpha.nondeterminism.PointerIteration (C++)

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 6b72d64950106..9340a114ac456 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -475,7 +475,12 @@ def CStringNotNullTerm : Checker<"NotNullTerminated">,
   HelpText<"Check for arguments which are not null-terminating strings">,
   Dependencies<[CStringModeling]>,
   Documentation;
-
+ 
+def CStringUninitializedRead : Checker<"UninitializedRead">,
+  HelpText<"Checks if the string manipulation function would read 
uninitialized bytes">,
+  Dependencies<[CStringModeling]>,
+  Documentation;
+  
 } // end "alpha.unix.cstring"
 
 let ParentPackage = Unix in {

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 8483a1a47cea1..54c9e887b8c8c 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -80,7 +80,7 @@ class CStringChecker : public Checker< eval::Call,
  check::RegionChanges
  > {
   mutable std::unique_ptr BT_Null, BT_Bounds, BT_Overlap,
-  BT_NotCString, BT_AdditionOverflow;
+  BT_NotCString, BT_AdditionOverflow, BT_UninitRead;
 
   mutable const char *CurrentFunctionDescription;
 
@@ -92,11 +92,13 @@ class CStringChecker : public Checker< eval::Call,
 DefaultBool CheckCStringOutOfBounds;
 DefaultBool CheckCStringBufferOverlap;
 DefaultBool CheckCStringNotNullTerm;
+DefaultBool CheckCStringUninitializedRead;
 
 CheckerNameRef CheckNameCStringNullArg;
 CheckerNameRef CheckNameCStringOutOfBounds;
 CheckerNam

[PATCH] D120900: [clang][dataflow] Add `MatchSwitch` utility library.

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked an inline comment as done.
ymandel added a comment.

Thanks for the fast review!




Comment at: clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h:51
+template 
+using MatchSwitch = std::function;
+

xazax.hun wrote:
> When we instantiate this with `TransferState` we have `ASTContext` both as an 
> argument and as a member of `State`. Is this intentional?
Yes, but...
The `ASTContext` is needed for the match itself, but the `State` type is not 
guaranteed to be `TransferState`, so won't necessarily hold the context.

But, we could reorganize a bit. Either: 
a) pass MatchFinder::MatchResult, instead of BoundNodes. That would bundle the 
nodes, context and source manager, which seems like a good idea.
b) bake TransferState into MatchSwitch, and make the parameter genericy named 
rather than "lattice".

I'm inclined towards the first option, since it seems "right" to give full 
access to the `MatchResult`. WDYT?



Comment at: clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h:110
+size_t Index = 0;
+if (ID.consume_front("Tag") && !ID.getAsInteger(10, Index) &&
+Index < Actions.size()) {

xazax.hun wrote:
> This does not need to be addressed here but it looks like it could be a 
> useful feature to be able to tag nodes with integer identifiers.
Great point. I'm not sure that would work here, fwiw, because we prefix with 
"Tag" here to protect against interfering with any IDs in the matcher. I 
suppose we could "reserve" a portion of the ID space.

But, in general, integers would make more sense in other situations that deal 
w/ matchers. The problem is that, unless we encode them as strings, the 
implementation inside the matchers could be kind of messy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120900

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


[PATCH] D120397: [C++20] [Modules] Make the linkage consistent for template and its specialization

2022-03-03 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/Modules/inconsist-export-template.cpp:19-23
+// FIXME: We should reject following specialization,
+// since it tries to export a name which is already introduced.
+export template <>
+void f1() {
+

urnathan wrote:
> ChuanqiXu wrote:
> > iains wrote:
> > > iains wrote:
> > > > ChuanqiXu wrote:
> > > > > urnathan wrote:
> > > > > > I don't think we should be testing for ill-formed code here.  We 
> > > > > > want to verify that explicit instantiations, explicit 
> > > > > > specializations and implicit instantiations all get the expected 
> > > > > > linkage -- both external linkage on exported entities, module 
> > > > > > linkage on non-exported module-purview entities.
> > > > > I think it could add an `expected-error` once we complete the check 
> > > > > in compiler so I added the FIXME here.
> > > > would it be possible to find a suitable place in the source for the 
> > > > FIXME?
> > > > I would be concerned that it could get forgotten in the test-case.
> > > or maybe just file a PR for accepts invalid code?
> > I would like to send an issue after the patch to remind me not forgetting 
> > it. The issue is needed after the patch since it would crash too. I prefer 
> > to remain the FIXME here so that it would look like a pre-commit test case, 
> > which should be good.
> The way to not forget about this is to file a bug and assign it to yourself.  
> Not add a known-wrong testcase.
FWIW, I do sometimes put in known-bad test cases to document existing issues 
and also to make it easier to find existing test coverage/a good home for the 
test case (often I/we end up adding a new test file, because it's not obvious 
where related existing test coverage is).

If this is the right place for the future test case, and it documents a 
limitation with the existing behavior, I wouldn't be totally against including 
it here, with a FIXME and reference to a filed bug, ideally (though I think 
I've done this without a bug filed too).


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

https://reviews.llvm.org/D120397

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


[PATCH] D120911: [CUDA][HIP] Fix offloading kind for linking C++ programs

2022-03-03 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

We should probably also check what happens when we specify compilation language 
explicitly: E.g. `clang -x cuda a.cu -x c++ b.cc`,  `clang -x cuda a.cu  b.cc` 
and `clang  a.cu  -x cuda b.cc`.


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

https://reviews.llvm.org/D120911

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


[PATCH] D120907: [docs] Add PowerPC release notes for LLVM 14

2022-03-03 Thread Lei Huang via Phabricator via cfe-commits
lei added a comment.

In D120907#3357433 , @ldionne wrote:

> LGTM for libc++. I assume this is targeting `release/14.x` only.

yes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120907

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


[PATCH] D120489: [analyzer] Done some changes to detect Uninitialized read by the char array manipulation functions

2022-03-03 Thread Shivam Rajput via Phabricator via cfe-commits
phyBrackets added a comment.

https://github.com/llvm/llvm-project/commit/bd1917c88a32c0930864d04f4e71155dcc3fa592
 , Hey @steakhal , I land it but why it is not showing the

void emitUninitializedReadBug(CheckerContext &C, ProgramStateRef State,
   const Expr *E) const;
  ``` ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120489

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


[PATCH] D120360: [libTooling] Generalize string explanation as Any metadata

2022-03-03 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua updated this revision to Diff 412755.
li.zhe.hua added a comment.

Fix use-after-move in asserts


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120360

Files:
  clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
  clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
  clang/include/clang/Tooling/Transformer/RewriteRule.h
  clang/include/clang/Tooling/Transformer/Transformer.h
  clang/lib/Tooling/Transformer/RewriteRule.cpp
  clang/lib/Tooling/Transformer/Transformer.cpp
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -31,9 +31,11 @@
 using ::clang::transformer::member;
 using ::clang::transformer::name;
 using ::clang::transformer::node;
+using ::clang::transformer::noEdits;
 using ::clang::transformer::remove;
 using ::clang::transformer::rewriteDescendants;
 using ::clang::transformer::RewriteRule;
+using ::clang::transformer::RewriteRuleWith;
 using ::clang::transformer::statement;
 using ::testing::ElementsAre;
 using ::testing::IsEmpty;
@@ -129,7 +131,7 @@
 Changes.insert(Changes.end(), std::make_move_iterator(C->begin()),
std::make_move_iterator(C->end()));
   } else {
-// FIXME: stash this error rather then printing.
+// FIXME: stash this error rather than printing.
 llvm::errs() << "Error generating changes: "
  << llvm::toString(C.takeError()) << "\n";
 ++ErrorCount;
@@ -137,27 +139,58 @@
 };
   }
 
-  template 
-  void testRule(R Rule, StringRef Input, StringRef Expected) {
+  auto consumerWithStringMetadata() {
+return [this](Expected> C) {
+  if (C) {
+Changes.insert(Changes.end(),
+   std::make_move_iterator(C->Changes.begin()),
+   std::make_move_iterator(C->Changes.end()));
+StringMetadata.push_back(std::move(C->Metadata));
+  } else {
+// FIXME: stash this error rather than printing.
+llvm::errs() << "Error generating changes: "
+ << llvm::toString(C.takeError()) << "\n";
+++ErrorCount;
+  }
+};
+  }
+
+  void testRule(RewriteRule Rule, StringRef Input, StringRef Expected) {
 Transformers.push_back(
 std::make_unique(std::move(Rule), consumer()));
 Transformers.back()->registerMatchers(&MatchFinder);
 compareSnippets(Expected, rewrite(Input));
   }
 
-  template  void testRuleFailure(R Rule, StringRef Input) {
+  void testRule(RewriteRuleWith Rule, StringRef Input,
+StringRef Expected) {
+Transformers.push_back(std::make_unique(
+std::move(Rule), consumerWithStringMetadata()));
+Transformers.back()->registerMatchers(&MatchFinder);
+compareSnippets(Expected, rewrite(Input));
+  }
+
+  void testRuleFailure(RewriteRule Rule, StringRef Input) {
 Transformers.push_back(
 std::make_unique(std::move(Rule), consumer()));
 Transformers.back()->registerMatchers(&MatchFinder);
 ASSERT_FALSE(rewrite(Input)) << "Expected failure to rewrite code";
   }
 
+  void testRuleFailure(RewriteRuleWith Rule, StringRef Input) {
+Transformers.push_back(std::make_unique(
+std::move(Rule), consumerWithStringMetadata()));
+Transformers.back()->registerMatchers(&MatchFinder);
+ASSERT_FALSE(rewrite(Input)) << "Expected failure to rewrite code";
+  }
+
   // Transformers are referenced by MatchFinder.
   std::vector> Transformers;
   clang::ast_matchers::MatchFinder MatchFinder;
   // Records whether any errors occurred in individual changes.
   int ErrorCount = 0;
   AtomicChanges Changes;
+  std::vector StringMetadata;
 
 private:
   FileContentMappings FileContents = {{"header.h", ""}};
@@ -169,7 +202,7 @@
 };
 
 // Given string s, change strlen($s.c_str()) to REPLACED.
-static RewriteRule ruleStrlenSize() {
+static RewriteRuleWith ruleStrlenSize() {
   StringRef StringExpr = "strexpr";
   auto StringType = namedDecl(hasAnyName("::basic_string", "::string"));
   auto R = makeRule(
@@ -886,12 +919,12 @@
 
 TEST_F(TransformerTest, OrderedRuleUnrelated) {
   StringRef Flag = "flag";
-  RewriteRule FlagRule = makeRule(
+  RewriteRuleWith FlagRule = makeRule(
   cxxMemberCallExpr(on(expr(hasType(cxxRecordDecl(
 hasName("proto::ProtoCommandLineFlag"
.bind(Flag)),
 unless(callee(cxxMethodDecl(hasName("GetProto"),
-  cha

[PATCH] D120489: [analyzer] Done some changes to detect Uninitialized read by the char array manipulation functions

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Looks like this broke the build. I'm getting:

  FAILED: 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/CStringChecker.cpp.o
  /usr/bin/clang++-11 ... -std=c++14 -MD -MT 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/CStringChecker.cpp.o
 -MF 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/CStringChecker.cpp.o.d
 -o 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/CStringChecker.cpp.o
 -c 
/usr/local/google/home/yitzhakm/remote-build/llvm-git/llvm-project/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  
/usr/local/google/home/yitzhakm/remote-build/llvm-git/llvm-project/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:376:7:
 error: use of undeclared identifier 'emitUninitializedReadBug'
emitUninitializedReadBug(C, StInBound, Buffer.Expression);
^
  
/usr/local/google/home/yitzhakm/remote-build/llvm-git/llvm-project/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:592:22:
 error: out-of-line definition of 'emitUninitializedReadBug' does not match any 
declaration in '(anonymous namespace)::CStringChecker'
  void CStringChecker::emitUninitializedReadBug(CheckerContext &C,
   ^~~~
  2 errors generated.FAILED: 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/CStringChecker.cpp.o
  /usr/bin/clang++-11 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/usr/local/google/home/yitzhakm/remote-build/llvm-git/build/tools/clang/lib/StaticAnalyzer/Checkers
 
-I/usr/local/google/home/yitzhakm/remote-build/llvm-git/llvm-project/clang/lib/StaticAnalyzer/Checkers
 
-I/usr/local/google/home/yitzhakm/remote-build/llvm-git/llvm-project/clang/include
 
-I/usr/local/google/home/yitzhakm/remote-build/llvm-git/build/tools/clang/include
 -I/usr/local/google/home/yitzhakm/remote-build/llvm-git/build/include 
-I/usr/local/google/home/yitzhakm/remote-build/llvm-git/llvm-project/llvm/include
 -gmlt -Wall -fPIC -fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -fdiagnostics-color -ffunction-sections 
-fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 
-DNDEBUG  -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/CStringChecker.cpp.o
 -MF 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/CStringChecker.cpp.o.d
 -o 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/CStringChecker.cpp.o
 -c 
/usr/local/google/home/yitzhakm/remote-build/llvm-git/llvm-project/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  
/usr/local/google/home/yitzhakm/remote-build/llvm-git/llvm-project/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:376:7:
 error: use of undeclared identifier 'emitUninitializedReadBug'
emitUninitializedReadBug(C, StInBound, Buffer.Expression);
^
  
/usr/local/google/home/yitzhakm/remote-build/llvm-git/llvm-project/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp:592:22:
 error: out-of-line definition of 'emitUninitializedReadBug' does not match any 
declaration in '(anonymous namespace)::CStringChecker'
  void CStringChecker::emitUninitializedReadBug(CheckerContext &C,
   ^~~~
  2 errors generated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120489

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


[PATCH] D120907: [docs] Add PowerPC release notes for LLVM 14

2022-03-03 Thread Lei Huang via Phabricator via cfe-commits
lei closed this revision.
lei added a comment.

Commited to release/14.x


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120907

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


[PATCH] D120489: [analyzer] Done some changes to detect Uninitialized read by the char array manipulation functions

2022-03-03 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added a comment.

broke our hip buildbot as well.

https://lab.llvm.org/buildbot/#/builders/165/builds/17076


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120489

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


[PATCH] D120900: [clang][dataflow] Add `MatchSwitch` utility library.

2022-03-03 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 412763.
ymandel marked an inline comment as done.
ymandel added a comment.

moved to `MatchFinder::MatchResult`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120900

Files:
  clang/include/clang/Analysis/FlowSensitive/MatchSwitch.h
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
@@ -0,0 +1,204 @@
+//===- unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a simplistic version of Constant Propagation as an example
+//  of a forward, monotonic dataflow analysis. The analysis tracks all
+//  variables in the scope, but lacks escape analysis.
+//
+//===--===//
+
+#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
+#include "TestingSupport.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
+#include "clang/Analysis/FlowSensitive/MapLattice.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang;
+using namespace dataflow;
+
+namespace {
+using ::testing::Pair;
+using ::testing::UnorderedElementsAre;
+
+class BooleanLattice {
+public:
+  BooleanLattice() : Value(false) {}
+  explicit BooleanLattice(bool B) : Value(B) {}
+
+  static BooleanLattice bottom() { return BooleanLattice(false); }
+
+  static BooleanLattice top() { return BooleanLattice(true); }
+
+  LatticeJoinEffect join(BooleanLattice Other) {
+auto Prev = Value;
+Value = Value || Other.Value;
+return Prev == Value ? LatticeJoinEffect::Unchanged
+ : LatticeJoinEffect::Changed;
+  }
+
+  friend bool operator==(BooleanLattice LHS, BooleanLattice RHS) {
+return LHS.Value == RHS.Value;
+  }
+
+  friend std::ostream &operator<<(std::ostream &Os, const BooleanLattice &B) {
+Os << B.Value;
+return Os;
+  }
+
+  bool value() const { return Value; }
+
+private:
+  bool Value;
+};
+} // namespace
+
+MATCHER_P(Holds, m,
+  ((negation ? "doesn't hold" : "holds") +
+   llvm::StringRef(" a lattice element that ") +
+   ::testing::DescribeMatcher(m, negation))
+  .str()) {
+  return ExplainMatchResult(m, arg.Lattice, result_listener);
+}
+
+void TransferSetTrue(const DeclRefExpr *,
+ TransferState &State) {
+  State.Lattice = BooleanLattice(true);
+}
+
+void TransferSetFalse(const Stmt *,
+  const ast_matchers::MatchFinder::MatchResult &,
+  TransferState &State) {
+  State.Lattice = BooleanLattice(false);
+}
+
+class TestAnalysis : public DataflowAnalysis {
+  MatchSwitch> TransferSwitch;
+
+public:
+  explicit TestAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {
+using namespace ast_matchers;
+TransferSwitch =
+MatchSwitchBuilder>()
+.CaseOf(declRefExpr(to(varDecl(hasName("X", TransferSetTrue)
+.CaseOf(callExpr(callee(functionDecl(hasName("Foo",
+TransferSetFalse)
+.Build();
+  }
+
+  static BooleanLattice initialElement() { return BooleanLattice::bottom(); }
+
+  void transfer(const Stmt *S, BooleanLattice &L, Environment &Env) {
+TransferState State(L, Env);
+TransferSwitch(*S, getASTContext(), State);
+  }
+};
+
+class MatchSwitchTest : public ::testing::Test {
+protected:
+  template 
+  void RunDataflow(llvm::StringRef Code, Matcher Expectations) {
+ASSERT_THAT_ERROR(
+test::checkDataflow(
+Code, "fun",
+[](ASTContext &C, Environment &) { return TestAnalysis(C); },
+[&Expectations](
+llvm::ArrayRef>>
+Results,
+ASTCont

  1   2   >