[PATCH] D141032: [Clang][RISCV] Expose vlenb to user

2023-01-08 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 487302.
eopXD added a comment.

Update code: Avoid emit clang version in test case.
@pcwang-thead Thank you for checking and providing the corresponding 
resolution. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141032

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c


Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
@@ -0,0 +1,39 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv32 -target-feature +v -disable-O0-optnone 
-emit-llvm -Qn %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV32 %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone 
-emit-llvm -Qn %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV64 %s
+
+#include 
+
+// RV32-LABEL: @test_vlenb(
+// RV32-NEXT:  entry:
+// RV32-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.read_register.i32(metadata 
[[META3:![0-9]+]])
+// RV32-NEXT:ret i32 [[TMP0]]
+//
+// RV64-LABEL: @test_vlenb(
+// RV64-NEXT:  entry:
+// RV64-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.read_register.i64(metadata 
[[META3:![0-9]+]])
+// RV64-NEXT:ret i64 [[TMP0]]
+//
+unsigned long test_vlenb(void) {
+  return vlenb();
+}
+//.
+// RV32: attributes #0 = { mustprogress nofree noinline nosync nounwind 
willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" 
"target-features"="+32bit,+d,+f,+v,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
+// RV32: attributes #1 = { mustprogress nocallback nofree nosync nounwind 
willreturn memory(read) }
+//.
+// RV64: attributes #0 = { mustprogress nofree noinline nosync nounwind 
willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" 
"target-features"="+64bit,+d,+f,+v,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
+// RV64: attributes #1 = { mustprogress nocallback nofree nosync nounwind 
willreturn memory(read) }
+//.
+// RV32: !0 = !{i32 1, !"wchar_size", i32 4}
+// RV32: !1 = !{i32 1, !"target-abi", !"ilp32d"}
+// RV32: !2 = !{i32 1, !"SmallDataLimit", i32 0}
+// RV32: !3 = !{!"vlenb"}
+//.
+// RV64: !0 = !{i32 1, !"wchar_size", i32 4}
+// RV64: !1 = !{i32 1, !"target-abi", !"lp64d"}
+// RV64: !2 = !{i32 1, !"SmallDataLimit", i32 0}
+// RV64: !3 = !{!"vlenb"}
+//.
Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -1558,6 +1558,32 @@
 }] in
 def vread_vwrite_csr: RVVHeader;
 
+let HeaderCode =
+[{
+#define vlenb() __builtin_rvv_vlenb()
+}] in
+def vlenb_macro: RVVHeader;
+
+let HasBuiltinAlias = false, HasVL = false, HasMasked = false,
+UnMaskedPolicyScheme = NonePolicy, MaskedPolicyScheme = NonePolicy,
+Log2LMUL = [0], IRName = "",
+ManualCodegen = [{
+{
+  LLVMContext  = CGM.getLLVMContext();
+  llvm::MDBuilder MDHelper(Context);
+
+  llvm::Metadata *Ops[] = {llvm::MDString::get(Context, "vlenb")};
+  llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+  llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+  llvm::Function *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {SizeTy});
+  return Builder.CreateCall(F, Metadata);
+}
+}] in
+{
+  def vlenb : RVVBuiltin<"", "u", "i">;
+}
+
 // 6. Configuration-Setting Instructions
 // 6.1. vsetvli/vsetvl instructions
 


Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
@@ -0,0 +1,39 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv32 -target-feature +v -disable-O0-optnone -emit-llvm -Qn %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV32 %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone -emit-llvm -Qn %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV64 %s
+
+#include 
+
+// RV32-LABEL: @test_vlenb(
+// RV32-NEXT:  entry:
+// RV32-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.read_register.i32(metadata [[META3:![0-9]+]])
+// RV32-NEXT:ret i32 [[TMP0]]
+//
+// RV64-LABEL: @test_vlenb(
+// RV64-NEXT:  entry:
+// RV64-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.read_register.i64(metadata [[META3:![0-9]+]])
+// RV64-NEXT:ret i64 [[TMP0]]
+//
+unsigned long test_vlenb(void) {
+  

[PATCH] D141032: [Clang][RISCV] Expose vlenb to user

2023-01-08 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead added inline comments.



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c:33
+// RV32: !2 = !{i32 1, !"SmallDataLimit", i32 0}
+// RV32: !3 = !{!"clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
e80f0cc0a318fe8473ba460d6a16166d81b303b1)"}
+// RV32: !4 = !{!"vlenb"}

Hmm, why would we emit version info here? I think we should avoid this.
I find a clang option `-Qn` that can disable emitting this by setting 
`EmitVersionIdentMetadata` to `false`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141032

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


[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

On the other hand, the LLVM coding standards talk about "implementation file". 
Ok, will leave as is. Then I'd say it's ready for review! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

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


[PATCH] D141248: [Clang] [Python] Fix tests when default config file contains -include

2023-01-08 Thread Sam James via Phabricator via cfe-commits
thesamesam updated this revision to Diff 487296.
thesamesam added a comment.

Add comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141248

Files:
  clang/bindings/python/tests/cindex/util.py


Index: clang/bindings/python/tests/cindex/util.py
===
--- clang/bindings/python/tests/cindex/util.py
+++ clang/bindings/python/tests/cindex/util.py
@@ -77,6 +77,9 @@
 
 return cursors
 
+# Avoid configurations including '-include' from interfering with
+# our tests.
+os.environ["CLANG_NO_DEFAULT_CONFIG"] = "1"
 
 skip_if_no_fspath = unittest.skipUnless(HAS_FSPATH,
 "Requires file system path protocol / 
Python 3.6+")


Index: clang/bindings/python/tests/cindex/util.py
===
--- clang/bindings/python/tests/cindex/util.py
+++ clang/bindings/python/tests/cindex/util.py
@@ -77,6 +77,9 @@
 
 return cursors
 
+# Avoid configurations including '-include' from interfering with
+# our tests.
+os.environ["CLANG_NO_DEFAULT_CONFIG"] = "1"
 
 skip_if_no_fspath = unittest.skipUnless(HAS_FSPATH,
 "Requires file system path protocol / Python 3.6+")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141248: [Clang] [Python] Fix tests when default config file contains -include

2023-01-08 Thread Sam James via Phabricator via cfe-commits
thesamesam updated this revision to Diff 487295.
thesamesam added a comment.

Set CLANG_NO_DEFAULT_CONFIG in environment instead to reduce
cat-and-mouse issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141248

Files:
  clang/bindings/python/tests/cindex/util.py


Index: clang/bindings/python/tests/cindex/util.py
===
--- clang/bindings/python/tests/cindex/util.py
+++ clang/bindings/python/tests/cindex/util.py
@@ -77,6 +77,7 @@
 
 return cursors
 
+os.environ["CLANG_NO_DEFAULT_CONFIG"] = "1"
 
 skip_if_no_fspath = unittest.skipUnless(HAS_FSPATH,
 "Requires file system path protocol / 
Python 3.6+")


Index: clang/bindings/python/tests/cindex/util.py
===
--- clang/bindings/python/tests/cindex/util.py
+++ clang/bindings/python/tests/cindex/util.py
@@ -77,6 +77,7 @@
 
 return cursors
 
+os.environ["CLANG_NO_DEFAULT_CONFIG"] = "1"
 
 skip_if_no_fspath = unittest.skipUnless(HAS_FSPATH,
 "Requires file system path protocol / Python 3.6+")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D141000#4034307 , @carlosgalvezp 
wrote:

> Since we are at it - are we happy with the name 
> "ImplementationFileExtensions"? I think "SourceFileExtensions" is more common 
> in the literature, and it would look more visually pleasing in the config 
> file since it has the same length as "HeaderFileExtensions".
>
>   HeaderFileExtensions: ["h", "hh"]
>   ImplementationFileExtensions: ["c", "cc"]
>
> vs
>
>   HeaderFileExtensions: ["h", "hh"]
>   SourceFileExtensions: ["c", "cc"]

Yes, there's a clear preference in the repo:

  $ git grep -E [sS]ource.?[fF]ile | wc -l
  5932
  $ git grep -E [iI]mplementation.?[fF]ile | wc -l
  104

Will change accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

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


[PATCH] D141248: [Clang] [Python] Fix tests when default config file contains -include

2023-01-08 Thread Michał Górny via Phabricator via cfe-commits
mgorny added reviewers: jbcoe, bkramer.
mgorny added a comment.

I'm wondering if we shouldn't just by setting `CLANG_NO_DEFAULT_CONFIG=1` like 
in clang's test suite rather than tying to predict how different config files 
will affect these tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141248

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


[PATCH] D141032: [Clang][RISCV] Expose vlenb to user

2023-01-08 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 487293.
eopXD marked 5 inline comments as done.
eopXD added a comment.

Address comments from Craig.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141032

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c


Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
@@ -0,0 +1,41 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-globals
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv32 -target-feature +v -disable-O0-optnone 
-emit-llvm %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV32 %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone 
-emit-llvm %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV64 %s
+
+#include 
+
+// RV32-LABEL: @test_vlenb(
+// RV32-NEXT:  entry:
+// RV32-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.read_register.i32(metadata 
[[META4:![0-9]+]])
+// RV32-NEXT:ret i32 [[TMP0]]
+//
+// RV64-LABEL: @test_vlenb(
+// RV64-NEXT:  entry:
+// RV64-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.read_register.i64(metadata 
[[META4:![0-9]+]])
+// RV64-NEXT:ret i64 [[TMP0]]
+//
+unsigned long test_vlenb(void) {
+  return vlenb();
+}
+//.
+// RV32: attributes #0 = { mustprogress nofree noinline nosync nounwind 
willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" 
"target-features"="+32bit,+d,+f,+v,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
+// RV32: attributes #1 = { mustprogress nocallback nofree nosync nounwind 
willreturn memory(read) }
+//.
+// RV64: attributes #0 = { mustprogress nofree noinline nosync nounwind 
willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" 
"target-features"="+64bit,+d,+f,+v,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
+// RV64: attributes #1 = { mustprogress nocallback nofree nosync nounwind 
willreturn memory(read) }
+//.
+// RV32: !0 = !{i32 1, !"wchar_size", i32 4}
+// RV32: !1 = !{i32 1, !"target-abi", !"ilp32d"}
+// RV32: !2 = !{i32 1, !"SmallDataLimit", i32 0}
+// RV32: !3 = !{!"clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
e80f0cc0a318fe8473ba460d6a16166d81b303b1)"}
+// RV32: !4 = !{!"vlenb"}
+//.
+// RV64: !0 = !{i32 1, !"wchar_size", i32 4}
+// RV64: !1 = !{i32 1, !"target-abi", !"lp64d"}
+// RV64: !2 = !{i32 1, !"SmallDataLimit", i32 0}
+// RV64: !3 = !{!"clang version 16.0.0 (g...@github.com:llvm/llvm-project.git 
e80f0cc0a318fe8473ba460d6a16166d81b303b1)"}
+// RV64: !4 = !{!"vlenb"}
+//.
Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -1558,6 +1558,32 @@
 }] in
 def vread_vwrite_csr: RVVHeader;
 
+let HeaderCode =
+[{
+#define vlenb() __builtin_rvv_vlenb()
+}] in
+def vlenb_macro: RVVHeader;
+
+let HasBuiltinAlias = false, HasVL = false, HasMasked = false,
+UnMaskedPolicyScheme = NonePolicy, MaskedPolicyScheme = NonePolicy,
+Log2LMUL = [0], IRName = "",
+ManualCodegen = [{
+{
+  LLVMContext  = CGM.getLLVMContext();
+  llvm::MDBuilder MDHelper(Context);
+
+  llvm::Metadata *Ops[] = {llvm::MDString::get(Context, "vlenb")};
+  llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+  llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+  llvm::Function *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {SizeTy});
+  return Builder.CreateCall(F, Metadata);
+}
+}] in
+{
+  def vlenb : RVVBuiltin<"", "u", "i">;
+}
+
 // 6. Configuration-Setting Instructions
 // 6.1. vsetvli/vsetvl instructions
 


Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
@@ -0,0 +1,41 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv32 -target-feature +v -disable-O0-optnone -emit-llvm %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV32 %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone -emit-llvm %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV64 %s
+
+#include 
+
+// RV32-LABEL: @test_vlenb(
+// RV32-NEXT:  entry:
+// RV32-NEXT:[[TMP0:%.*]] = tail call i32 @llvm.read_register.i32(metadata [[META4:![0-9]+]])
+// RV32-NEXT:ret i32 [[TMP0]]
+//
+// RV64-LABEL: @test_vlenb(
+// RV64-NEXT:  entry:
+// RV64-NEXT:  

[PATCH] D136817: [RISCV] Add H extension

2023-01-08 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136817

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


[PATCH] D141032: [Clang][RISCV] Expose vlenb to user

2023-01-08 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:1579
+  llvm::Function *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+  return Builder.CreateCall(F, Metadata);

craig.topper wrote:
> pcwang-thead wrote:
> > The value type of `read_register` is `i32` in 
> > `llvm/test/CodeGen/RISCV/vlenb.ll`, but I don't insist on it.
> Doesn't this need to match the size of long?
So what about `i32` for rv32 and `i64` for rv64?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141032

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


[PATCH] D141032: [Clang][RISCV] Expose vlenb to user

2023-01-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:1579
+  llvm::Function *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+  return Builder.CreateCall(F, Metadata);

pcwang-thead wrote:
> The value type of `read_register` is `i32` in 
> `llvm/test/CodeGen/RISCV/vlenb.ll`, but I don't insist on it.
Doesn't this need to match the size of long?



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c:1
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target

pcwang-thead wrote:
> Add `--check-globals` or `--global-value-regex` to check if the metadata is 
> `vlenb` exactly?
Please test riscv32 as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141032

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


[PATCH] D141248: [Clang] [Python] Fix tests when default config file contains -include

2023-01-08 Thread Sam James via Phabricator via cfe-commits
thesamesam created this revision.
thesamesam added a reviewer: mgorny.
Herald added a subscriber: arphaman.
Herald added a project: All.
thesamesam requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In Gentoo, we make use of Clang's recently-enhanced config file support
and add a default include to `clang` invocations using '-include ...'.

This breaks clang-python tests like so:

  ==
  ERROR: test_includes (tests.cindex.test_translation_unit.TestTranslationUnit)
  --
  Traceback (most recent call last):
File 
"/var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/test_translation_unit.py",
 line 145, in test_includes
  eq(i[0], i[1])
File 
"/var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/test_translation_unit.py",
 line 132, in eq
  self.assert_normpaths_equal(expected[0], actual.source.name)
  AttributeError: 'NoneType' object has no attribute 'name'
  
  ==
  FAIL: test_inclusion_directive 
(tests.cindex.test_translation_unit.TestTranslationUnit)
  --
  Traceback (most recent call last):
File 
"/var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/test_translation_unit.py",
 line 157, in test_inclusion_directive
  self.assert_normpaths_equal(i[0], i[1])
File 
"/var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/test_translation_unit.py",
 line 126, in assert_normpaths_equal
  self.assertEqual(os.path.normpath(path1),
  AssertionError: '/var/tmp/portage/dev-python/clang-python-1[58 chars]r1.h' != 
'/usr/include/gentoo/fortify.h'
  - 
/var/tmp/portage/dev-python/clang-python-15.0.6/work/clang/bindings/python/tests/cindex/INPUTS/header1.h
  + /usr/include/gentoo/fortify.h

Disable using the default Clang configuration files on the system, like
we did for other tests.

Bug: https://bugs.gentoo.org/890204
Signed-off-by: Sam James 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141248

Files:
  clang/bindings/python/tests/cindex/test_translation_unit.py


Index: clang/bindings/python/tests/cindex/test_translation_unit.py
===
--- clang/bindings/python/tests/cindex/test_translation_unit.py
+++ clang/bindings/python/tests/cindex/test_translation_unit.py
@@ -140,7 +140,7 @@
 h3 = os.path.join(kInputsDir, "header3.h")
 inc = [(src, h1), (h1, h3), (src, h2), (h2, h3)]
 
-tu = TranslationUnit.from_source(src)
+tu = TranslationUnit.from_source(src, ["--no-default-config"])
 for i in zip(inc, tu.get_includes()):
 eq(i[0], i[1])
 
@@ -151,7 +151,7 @@
 h3 = os.path.join(kInputsDir, "header3.h")
 inc = [h1, h3, h2, h3, h1]
 
-tu = TranslationUnit.from_source(src, 
options=TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD)
+tu = TranslationUnit.from_source(src, ["--no-default-config"], 
options=TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD)
 inclusion_directive_files = [c.get_included_file().name for c in 
tu.cursor.get_children() if c.kind == CursorKind.INCLUSION_DIRECTIVE]
 for i in zip(inc, inclusion_directive_files):
 self.assert_normpaths_equal(i[0], i[1])


Index: clang/bindings/python/tests/cindex/test_translation_unit.py
===
--- clang/bindings/python/tests/cindex/test_translation_unit.py
+++ clang/bindings/python/tests/cindex/test_translation_unit.py
@@ -140,7 +140,7 @@
 h3 = os.path.join(kInputsDir, "header3.h")
 inc = [(src, h1), (h1, h3), (src, h2), (h2, h3)]
 
-tu = TranslationUnit.from_source(src)
+tu = TranslationUnit.from_source(src, ["--no-default-config"])
 for i in zip(inc, tu.get_includes()):
 eq(i[0], i[1])
 
@@ -151,7 +151,7 @@
 h3 = os.path.join(kInputsDir, "header3.h")
 inc = [h1, h3, h2, h3, h1]
 
-tu = TranslationUnit.from_source(src, options=TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD)
+tu = TranslationUnit.from_source(src, ["--no-default-config"], options=TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD)
 inclusion_directive_files = [c.get_included_file().name for c in tu.cursor.get_children() if c.kind == CursorKind.INCLUSION_DIRECTIVE]
 for i in zip(inc, inclusion_directive_files):
 self.assert_normpaths_equal(i[0], i[1])
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141032: [Clang][RISCV] Expose vlenb to user

2023-01-08 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead accepted this revision.
pcwang-thead added a comment.
This revision is now accepted and ready to land.

The code is OK to me, except that a few small comments.




Comment at: clang/include/clang/Basic/riscv_vector.td:1579
+  llvm::Function *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+  return Builder.CreateCall(F, Metadata);

The value type of `read_register` is `i32` in 
`llvm/test/CodeGen/RISCV/vlenb.ll`, but I don't insist on it.



Comment at: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c:1
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target

Add `--check-globals` or `--global-value-regex` to check if the metadata is 
`vlenb` exactly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141032

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


[clang] 2893bcd - [NFC] Fix the test failure in 08f957808e5f7e44b11d in armv8

2023-01-08 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-09T11:54:17+08:00
New Revision: 2893bcd6cd88310da9ba4a37c142c6db463ba79e

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

LOG: [NFC] Fix the test failure in  08f957808e5f7e44b11d in armv8

The test in 08f957808e5f7e44b11d may fail in armv8 since the signature
of the constructor may be different. This patch tries to fix it.

Added: 


Modified: 
clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm

Removed: 




diff  --git a/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm 
b/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
index c89bce5039a5..6080786ecd39 100644
--- a/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
+++ b/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
@@ -24,8 +24,8 @@ export A a;
 // CHECK: @_ZW1M1a = {{.*}}global %class.A zeroinitializer
 // CHECK: define{{.*}}void @__cxx_global_var_init()
 // CHECK-NEXT: entry:
-// CHECK-NEXT: call{{.*}}void @_ZNW1M1AC1Ev({{.*}}@_ZW1M1a
-// CHECK-NEXT: call{{.*}}i32 @__cxa_atexit(ptr @_ZNW1M1AD1Ev, ptr @_ZW1M1a
+// CHECK-NEXT: call{{.*}}@_ZNW1M1AC1Ev({{.*}}@_ZW1M1a
+// CHECK-NEXT: call{{.*}}@__cxa_atexit(ptr @_ZNW1M1AD1Ev, ptr @_ZW1M1a
 
 //--- Use.cpp
 import M;
@@ -54,5 +54,5 @@ void use() {
 // CHECK: @a = {{.*}}global %class.A zeroinitializer
 // CHECK: define{{.*}}void @__cxx_global_var_init()
 // CHECK-NEXT: entry:
-// CHECK-NEXT: call{{.*}}void @_ZN1AC1Ev({{.*}}@a
-// CHECK-NEXT: call{{.*}}i32 @__cxa_atexit(ptr @_ZN1AD1Ev, ptr @a
+// CHECK-NEXT: call{{.*}}@_ZN1AC1Ev({{.*}}@a
+// CHECK-NEXT: call{{.*}}@__cxa_atexit(ptr @_ZN1AD1Ev, ptr @a



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


[PATCH] D141226: [WIP][clangd] support expanding `decltype(expr)`

2023-01-08 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry added a comment.

If this is okay to go ahead, I'm considering renaming the tweak. Does 
`ExpandType` or `ExpandDeducedType` sound good?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141226

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


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2023-01-08 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added a comment.

> BTW, the series of clang-scan-deps patch (https://reviews.llvm.org/D139168) 
> is also necessary [...]

Yes, I meant both those series.

> [...] but I am not sure if we can land them in time. I guess it may be 
> possible to backport these patches to 16.x since it is relatively important?

Might make sense tagging the release managers if things get tight - perhaps 
it's possible. E.g. ranges for LLVM 15 was also finished after the branch.


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

https://reviews.llvm.org/D137058

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


[PATCH] D140867: [C++20] [Modules] Don't generate global ctors/dtors for variables which are available externally

2023-01-08 Thread Chuanqi Xu 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 rG08f957808e5f: [C++20] [Modules] Dont generate global 
ctors/dtors for variables which are… (authored by ChuanqiXu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D140867?vs=486449=487262#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140867

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm

Index: clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
===
--- /dev/null
+++ clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
@@ -0,0 +1,58 @@
+// https://github.com/llvm/llvm-project/issues/59765
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/M.cppm -triple %itanium_abi_triple -emit-module-interface -o %t/M.pcm
+// RUN: %clang_cc1 -std=c++20 %t/M.pcm -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %t/M.cppm
+// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %t/Use.cpp
+//
+// Check that the behavior of header units is normal as headers.
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple -xc++-user-header %t/foo.h -emit-header-unit -o %t/foo.pcm
+// RUN: %clang_cc1 -std=c++20 %t/UseHU.cpp -fmodule-file=%t/foo.pcm -triple %itanium_abi_triple -emit-llvm -o - | FileCheck %t/UseHU.cpp
+
+//--- M.cppm
+export module M;
+export class A {
+public:
+A();
+~A();
+void use();
+};
+export A a;
+
+// CHECK: @_ZW1M1a = {{.*}}global %class.A zeroinitializer
+// CHECK: define{{.*}}void @__cxx_global_var_init()
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call{{.*}}void @_ZNW1M1AC1Ev({{.*}}@_ZW1M1a
+// CHECK-NEXT: call{{.*}}i32 @__cxa_atexit(ptr @_ZNW1M1AD1Ev, ptr @_ZW1M1a
+
+//--- Use.cpp
+import M;
+void use() {
+a.use();
+}
+
+// CHECK-NOT: @_ZNW1M1AC1Ev
+// CHECK-NOT: @_ZNW1M1AD1Ev
+
+//--- foo.h
+class A {
+public:
+A();
+~A();
+void use();
+};
+A a;
+
+//--- UseHU.cpp
+import "foo.h";
+void use() {
+a.use();
+}
+
+// CHECK: @a = {{.*}}global %class.A zeroinitializer
+// CHECK: define{{.*}}void @__cxx_global_var_init()
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call{{.*}}void @_ZN1AC1Ev({{.*}}@a
+// CHECK-NEXT: call{{.*}}i32 @__cxa_atexit(ptr @_ZN1AD1Ev, ptr @a
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4824,7 +4824,13 @@
 
   llvm::TrackingVH Init;
   bool NeedsGlobalCtor = false;
+  // Whether the definition of the variable is available externally.
+  // If yes, we shouldn't emit the GloablCtor and GlobalDtor for the variable
+  // since this is the job for its original source.
+  bool IsDefinitionAvailableExternally =
+  getContext().GetGVALinkageForVariable(D) == GVA_AvailableExternally;
   bool NeedsGlobalDtor =
+  !IsDefinitionAvailableExternally &&
   D->needsDestruction(getContext()) == QualType::DK_cxx_destructor;
 
   const VarDecl *InitDecl;
@@ -4878,7 +4884,9 @@
 if (InitDecl->hasFlexibleArrayInit(getContext()))
   ErrorUnsupported(D, "flexible array initializer");
 Init = EmitNullConstant(T);
-NeedsGlobalCtor = true;
+
+if (!IsDefinitionAvailableExternally)
+  NeedsGlobalCtor = true;
   } else {
 ErrorUnsupported(D, "static initializer");
 Init = llvm::UndefValue::get(getTypes().ConvertType(T));
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -345,6 +345,9 @@
   `Issue 59792 `_
 - Fix an issue that makes Clang crash on lambda template parameters. This fixes
   `Issue 57960 `_
+- Fix issue that the standard C++ modules importer will call global
+  constructor/destructor for the global varaibles in the importing modules.
+  This fixes `Issue 59765 `_
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 08f9578 - [C++20] [Modules] Don't generate global ctors/dtors for variables which are available externally

2023-01-08 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-09T10:48:43+08:00
New Revision: 08f957808e5f7e44b11d5e9015925955fe1e9d32

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

LOG: [C++20] [Modules] Don't generate global ctors/dtors for variables which 
are available externally

Closes https://github.com/llvm/llvm-project/issues/59765.

Currently we will generate the global ctor/dtor for variables in
importing modules. It will cause multiple initialization/destructions.
It makes no sense. This patch tries to not generate global ctor/dtor for
variables which are available externally. Note that the variables in
header units and clang modules won't be available externally by default.

Reviewed By: iains

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

Added: 
clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b623d260dbb30..8718deab35bf2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -345,6 +345,9 @@ Bug Fixes
   `Issue 59792 `_
 - Fix an issue that makes Clang crash on lambda template parameters. This fixes
   `Issue 57960 `_
+- Fix issue that the standard C++ modules importer will call global
+  constructor/destructor for the global varaibles in the importing modules.
+  This fixes `Issue 59765 `_
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index fbf7c33254779..1239147ca27ff 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4824,7 +4824,13 @@ void CodeGenModule::EmitGlobalVarDefinition(const 
VarDecl *D,
 
   llvm::TrackingVH Init;
   bool NeedsGlobalCtor = false;
+  // Whether the definition of the variable is available externally.
+  // If yes, we shouldn't emit the GloablCtor and GlobalDtor for the variable
+  // since this is the job for its original source.
+  bool IsDefinitionAvailableExternally =
+  getContext().GetGVALinkageForVariable(D) == GVA_AvailableExternally;
   bool NeedsGlobalDtor =
+  !IsDefinitionAvailableExternally &&
   D->needsDestruction(getContext()) == QualType::DK_cxx_destructor;
 
   const VarDecl *InitDecl;
@@ -4878,7 +4884,9 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl 
*D,
 if (InitDecl->hasFlexibleArrayInit(getContext()))
   ErrorUnsupported(D, "flexible array initializer");
 Init = EmitNullConstant(T);
-NeedsGlobalCtor = true;
+
+if (!IsDefinitionAvailableExternally)
+  NeedsGlobalCtor = true;
   } else {
 ErrorUnsupported(D, "static initializer");
 Init = llvm::UndefValue::get(getTypes().ConvertType(T));

diff  --git a/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm 
b/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
new file mode 100644
index 0..c89bce5039a5d
--- /dev/null
+++ b/clang/test/CodeGenCXX/pr59765-modules-global-ctor-dtor.cppm
@@ -0,0 +1,58 @@
+// https://github.com/llvm/llvm-project/issues/59765
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/M.cppm -triple %itanium_abi_triple 
-emit-module-interface -o %t/M.pcm
+// RUN: %clang_cc1 -std=c++20 %t/M.pcm -triple %itanium_abi_triple -emit-llvm 
-o - | FileCheck %t/M.cppm
+// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t -triple 
%itanium_abi_triple -emit-llvm -o - | FileCheck %t/Use.cpp
+//
+// Check that the behavior of header units is normal as headers.
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple -xc++-user-header 
%t/foo.h -emit-header-unit -o %t/foo.pcm
+// RUN: %clang_cc1 -std=c++20 %t/UseHU.cpp -fmodule-file=%t/foo.pcm -triple 
%itanium_abi_triple -emit-llvm -o - | FileCheck %t/UseHU.cpp
+
+//--- M.cppm
+export module M;
+export class A {
+public:
+A();
+~A();
+void use();
+};
+export A a;
+
+// CHECK: @_ZW1M1a = {{.*}}global %class.A zeroinitializer
+// CHECK: define{{.*}}void @__cxx_global_var_init()
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call{{.*}}void @_ZNW1M1AC1Ev({{.*}}@_ZW1M1a
+// CHECK-NEXT: call{{.*}}i32 @__cxa_atexit(ptr @_ZNW1M1AD1Ev, ptr @_ZW1M1a
+
+//--- Use.cpp
+import M;
+void use() {
+a.use();
+}
+
+// CHECK-NOT: @_ZNW1M1AC1Ev
+// CHECK-NOT: @_ZNW1M1AD1Ev
+
+//--- foo.h
+class A {
+public:
+A();
+~A();
+void use();
+};
+A a;
+
+//--- UseHU.cpp
+import "foo.h";
+void use() {
+a.use();
+}
+
+// CHECK: @a = 

[PATCH] D139168: [C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)

2023-01-08 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

> FWIW, the same with should happen with -MT.

Yeah, it should be. Since the patch reuses the previous logics.


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

https://reviews.llvm.org/D139168

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


[PATCH] D139168: [C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)

2023-01-08 Thread Ben Boeckel via Phabricator via cfe-commits
ben.boeckel added a comment.

In D139168#4034885 , @ChuanqiXu wrote:

> @Arthapz Great to hear that! It is pretty important for us to know there are 
> more build systems which are using these functionality. BTW, for header 
> units, it is still under discussion that how should build system and compiler 
> interact about header units. It is still unclear whether or not the header 
> units should be transparent to build systems (and other tools).

Header units have even more need to be involved in the build graph than named 
units. ODR violations and cache invalidation problems await anyone just winging 
it on header units (at least that's the understanding I've gotten from SG15 
meetings).

> I mean, it is possible to get the make-style format information by 
> `clang-scan-deps -format=make --compilation-database=db.json`. (Although it 
> sounds not smart indeed)

I don't see the benefit of having to run two commands to get this information.

> Then how do you feel about the current strategy? `clang-scan-deps 
> --format=p1689 --compilation-database=db.json`. Then if every commands in 
> db.json has the same `-MF` value, it should be able to satisfy your 
> requirement.

This seems…reasonable. No worse than the other lies we have to tell in a 
databse. FWIW, the same with should happen with `-MT`.


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

https://reviews.llvm.org/D139168

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


[PATCH] D141023: [C++20] [Modules] Make placement allocation functions always acceptable

2023-01-08 Thread Chuanqi Xu 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 rGee1be282241b: [C++20] [Modules] Make placement allocation 
functions always visible (authored by ChuanqiXu).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141023

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/Modules/placement-new-reachable.cpp


Index: clang/test/Modules/placement-new-reachable.cpp
===
--- /dev/null
+++ clang/test/Modules/placement-new-reachable.cpp
@@ -0,0 +1,39 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t 
-fsyntax-only -verify
+
+//--- placement.h
+namespace std {
+  using size_t = decltype(sizeof(0));
+}
+void *operator new(std::size_t, void *p) { return p; }
+
+//--- A.cppm
+module;
+#include "placement.h"
+export module A;
+export template
+struct A {
+A(void *p) : ptr(new (p) T(43)) {}
+private:
+void *ptr;
+};
+
+export struct B {
+B(void *p) : ptr(new (p) int(43)) {}
+private:
+void *ptr;
+};
+
+//--- Use.cpp
+// expected-no-diagnostics
+import A;
+void bar(int *);
+void foo(void *ptr) {
+A(nullptr); // Good. It should be OK to construct A.
+void *p = ::operator new(sizeof(int), ptr); // Bad. The function shouldn't 
be visible here.
+void *q = new (ptr) int(43); // Good. We don't call the placement 
allocation function directly.
+}
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -2099,6 +2099,22 @@
   if (auto *DeductionGuide = ND->getDeclName().getCXXDeductionGuideTemplate())
 return SemaRef.hasReachableDefinition(DeductionGuide);
 
+  // FIXME: The lookup for allocation function is a standalone process.
+  // (We can find the logics in Sema::FindAllocationFunctions)
+  //
+  // Such structure makes it a problem when we instantiate a template
+  // declaration using placement allocation function if the placement
+  // allocation function is invisible.
+  // (See https://github.com/llvm/llvm-project/issues/59601)
+  //
+  // Here we workaround it by making the placement allocation functions
+  // always acceptable. The downside is that we can't diagnose the direct
+  // use of the invisible placement allocation functions. (Although such uses
+  // should be rare).
+  if (auto *FD = dyn_cast(ND);
+  FD && FD->isReservedGlobalPlacementOperator())
+return true;
+
   auto *DC = ND->getDeclContext();
   // If ND is not visible and it is at namespace scope, it shouldn't be found
   // by name lookup.


Index: clang/test/Modules/placement-new-reachable.cpp
===
--- /dev/null
+++ clang/test/Modules/placement-new-reachable.cpp
@@ -0,0 +1,39 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t -fsyntax-only -verify
+
+//--- placement.h
+namespace std {
+  using size_t = decltype(sizeof(0));
+}
+void *operator new(std::size_t, void *p) { return p; }
+
+//--- A.cppm
+module;
+#include "placement.h"
+export module A;
+export template
+struct A {
+A(void *p) : ptr(new (p) T(43)) {}
+private:
+void *ptr;
+};
+
+export struct B {
+B(void *p) : ptr(new (p) int(43)) {}
+private:
+void *ptr;
+};
+
+//--- Use.cpp
+// expected-no-diagnostics
+import A;
+void bar(int *);
+void foo(void *ptr) {
+A(nullptr); // Good. It should be OK to construct A.
+void *p = ::operator new(sizeof(int), ptr); // Bad. The function shouldn't be visible here.
+void *q = new (ptr) int(43); // Good. We don't call the placement allocation function directly.
+}
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -2099,6 +2099,22 @@
   if (auto *DeductionGuide = ND->getDeclName().getCXXDeductionGuideTemplate())
 return SemaRef.hasReachableDefinition(DeductionGuide);
 
+  // FIXME: The lookup for allocation function is a standalone process.
+  // (We can find the logics in Sema::FindAllocationFunctions)
+  //
+  // Such structure makes it a problem when we instantiate a template
+  // declaration using placement allocation function if the placement
+  // allocation function is invisible.
+  // (See https://github.com/llvm/llvm-project/issues/59601)
+  //
+  // Here we workaround it by making the placement allocation functions
+  // always 

[clang] ee1be28 - [C++20] [Modules] Make placement allocation functions always visible

2023-01-08 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-01-09T10:40:23+08:00
New Revision: ee1be282241b1253847e663af000f7082b7f03a3

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

LOG: [C++20] [Modules] Make placement allocation functions always visible

Close https://github.com/llvm/llvm-project/issues/59601.

This is actually a workaround for the issue. See the comments and the
test for example. The proper fix should make the placement allocation
functions acceptable based on the context. But it is harder and more
complex on the one side. On the other side, such workaround won't be too
bad in practice since users rarely call the placement allocation
functions directly.

So personally I prefer to address such problems in the simpler way.

Reviewed By: royjacobson

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

Added: 
clang/test/Modules/placement-new-reachable.cpp

Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 97b3c97a9e51e..4ec8a373ed47b 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -2099,6 +2099,22 @@ bool LookupResult::isAvailableForLookup(Sema , 
NamedDecl *ND) {
   if (auto *DeductionGuide = ND->getDeclName().getCXXDeductionGuideTemplate())
 return SemaRef.hasReachableDefinition(DeductionGuide);
 
+  // FIXME: The lookup for allocation function is a standalone process.
+  // (We can find the logics in Sema::FindAllocationFunctions)
+  //
+  // Such structure makes it a problem when we instantiate a template
+  // declaration using placement allocation function if the placement
+  // allocation function is invisible.
+  // (See https://github.com/llvm/llvm-project/issues/59601)
+  //
+  // Here we workaround it by making the placement allocation functions
+  // always acceptable. The downside is that we can't diagnose the direct
+  // use of the invisible placement allocation functions. (Although such uses
+  // should be rare).
+  if (auto *FD = dyn_cast(ND);
+  FD && FD->isReservedGlobalPlacementOperator())
+return true;
+
   auto *DC = ND->getDeclContext();
   // If ND is not visible and it is at namespace scope, it shouldn't be found
   // by name lookup.

diff  --git a/clang/test/Modules/placement-new-reachable.cpp 
b/clang/test/Modules/placement-new-reachable.cpp
new file mode 100644
index 0..29263173d78f4
--- /dev/null
+++ b/clang/test/Modules/placement-new-reachable.cpp
@@ -0,0 +1,39 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t 
-fsyntax-only -verify
+
+//--- placement.h
+namespace std {
+  using size_t = decltype(sizeof(0));
+}
+void *operator new(std::size_t, void *p) { return p; }
+
+//--- A.cppm
+module;
+#include "placement.h"
+export module A;
+export template
+struct A {
+A(void *p) : ptr(new (p) T(43)) {}
+private:
+void *ptr;
+};
+
+export struct B {
+B(void *p) : ptr(new (p) int(43)) {}
+private:
+void *ptr;
+};
+
+//--- Use.cpp
+// expected-no-diagnostics
+import A;
+void bar(int *);
+void foo(void *ptr) {
+A(nullptr); // Good. It should be OK to construct A.
+void *p = ::operator new(sizeof(int), ptr); // Bad. The function shouldn't 
be visible here.
+void *q = new (ptr) int(43); // Good. We don't call the placement 
allocation function directly.
+}



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


[PATCH] D139168: [C++20] [Modules] [ClangScanDeps] Enable to print make-style dependency file within P1689 format (4/4)

2023-01-08 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

> Hi, just wanted to say that i added support of these patch to XMake (i built 
> a LLVM with your 4 patches) and it work pretty well :) (except for header 
> units)

@Arthapz Great to hear that! It is pretty important for us to know there are 
more build systems which are using these functionality. BTW, for header units, 
it is still under discussion that how should build system and compiler interact 
about header units. It is still unclear whether or not the header units should 
be transparent to build systems (and other tools).

In D139168#4032866 , @ben.boeckel 
wrote:

> In D139168#4030425 , @ChuanqiXu 
> wrote:
>
>> BTW, if you are interested, it should be possible to use clang-scan-deps to 
>> get the make-style format information.
>
> I want a *single* depfile for *anything* scanned by the `clang-scan-deps` 
> invocation, not one per TU scanned. Also note that the `-MT` is the output of 
> `clang-scan-deps`; in this case, the `.ddi` file that contains P1689 
>  content. I think it'd be *very* weird to 
> have `clang-scan-deps -p1689-output=out.ddi -- clang -MF blah.d -MT out.ddi`.

I mean, it is possible to get the make-style format information by 
`clang-scan-deps -format=make --compilation-database=db.json`. (Although it 
sounds not smart indeed)

Then how do you feel about the current strategy? `clang-scan-deps 
--format=p1689 --compilation-database=db.json`. Then if every commands in 
db.json has the same `-MF` value, it should be able to satisfy your requirement.


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

https://reviews.llvm.org/D139168

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


[PATCH] D137058: [Driver] [Modules] Support -fmodule-output (1/2)

2023-01-08 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D137058#4033825 , @h-vetinari 
wrote:

> Without undue haste, I just wanted to comment from the peanut gallery that it 
> would be amazing if the patches that are necessary for CMake + Clang to use 
> C++ modules would make the cut-off for LLVM 16 that's coming up around the 
> 24th of January.

Thanks for the note. I'll land this patch in the next week if no further 
comments come in. BTW, the series of clang-scan-deps patch 
(https://reviews.llvm.org/D139168) is also necessary but I am not sure if we 
can land them in time. I guess it may be possible to backport these patches to 
16.x since it is relatively important?


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

https://reviews.llvm.org/D137058

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


[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

2023-01-08 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

gentle ping @jansvoboda11 . sorry for the a little bit hurried ping since 
LLVM-16 is going to be branched in  the 24th of January.


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

https://reviews.llvm.org/D137534

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


[PATCH] D141240: [SVE][Builtins] Add metadata to intrinsic calls for builtins that don't define the result of inactive lanes.

2023-01-08 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm updated this revision to Diff 487247.
paulwalker-arm added a comment.

Fixed typo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141240

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-unpredicate.ll

Index: llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-unpredicate.ll
===
--- /dev/null
+++ llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-unpredicate.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
+
+define  @unpredicate_add_x( %p,  %a,  %b) #0 {
+; CHECK-LABEL: @unpredicate_add_x(
+; CHECK-NEXT:[[OP1:%.*]] = add  [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:ret  [[OP1]]
+;
+  %op = tail call  @llvm.aarch64.sve.add.nxv4i32( %p,  %a,  %b), !inactive_lanes_undefined !0
+  ret  %op
+}
+
+declare  @llvm.aarch64.sve.add.nxv4i32(, , )
+
+attributes #0 = { "target-features"="+sve" }
+
+!0 = !{}
Index: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -1203,6 +1203,16 @@
Intrinsic::aarch64_sve_mad>(
   IC, II, false))
 return MAD;
+
+  // The predicate is redundant if we don't care about inactive lanes.
+  if (II.getIntrinsicID() == Intrinsic::aarch64_sve_add &&
+  II.hasMetadata("inactive_lanes_undefined")) {
+auto *UnpredAdd =
+BinaryOperator::Create(Instruction::Add, II.getArgOperand(1),
+   II.getArgOperand(2), II.getName(), );
+return IC.replaceInstUsesWith(II, UnpredAdd);
+  }
+
   return instCombineSVEVectorBinOp(IC, II);
 }
 
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
===
--- clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
@@ -296,12 +296,12 @@
 
 // CHECK-LABEL: @test_svadd_s8_x(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.add.nxv16i8( [[PG:%.*]],  [[OP1:%.*]],  [[OP2:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.add.nxv16i8( [[PG:%.*]],  [[OP1:%.*]],  [[OP2:%.*]]), !inactive_lanes_undefined !2
 // CHECK-NEXT:ret  [[TMP0]]
 //
 // CPP-CHECK-LABEL: @_Z15test_svadd_s8_xu10__SVBool_tu10__SVInt8_tu10__SVInt8_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.add.nxv16i8( [[PG:%.*]],  [[OP1:%.*]],  [[OP2:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.add.nxv16i8( [[PG:%.*]],  [[OP1:%.*]],  [[OP2:%.*]]), !inactive_lanes_undefined !2
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint8_t test_svadd_s8_x(svbool_t pg, svint8_t op1, svint8_t op2)
@@ -312,13 +312,13 @@
 // CHECK-LABEL: @test_svadd_s16_x(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PG:%.*]])
-// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.add.nxv8i16( [[TMP0]],  [[OP1:%.*]],  [[OP2:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.add.nxv8i16( [[TMP0]],  [[OP1:%.*]],  [[OP2:%.*]]), !inactive_lanes_undefined !2
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z16test_svadd_s16_xu10__SVBool_tu11__SVInt16_tu11__SVInt16_t(
 // CPP-CHECK-NEXT:  entry:
 // CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv8i1( [[PG:%.*]])
-// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.add.nxv8i16( [[TMP0]],  [[OP1:%.*]],  [[OP2:%.*]])
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.add.nxv8i16( [[TMP0]],  [[OP1:%.*]],  [[OP2:%.*]]), !inactive_lanes_undefined !2
 // CPP-CHECK-NEXT:ret  [[TMP1]]
 //
 svint16_t test_svadd_s16_x(svbool_t pg, svint16_t op1, svint16_t op2)
@@ -329,13 +329,13 @@
 // CHECK-LABEL: @test_svadd_s32_x(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[PG:%.*]])
-// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.add.nxv4i32( [[TMP0]],  [[OP1:%.*]],  [[OP2:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.add.nxv4i32( [[TMP0]],  [[OP1:%.*]],  [[OP2:%.*]]), !inactive_lanes_undefined !2
 // CHECK-NEXT:ret  [[TMP1]]
 //
 // CPP-CHECK-LABEL: @_Z16test_svadd_s32_xu10__SVBool_tu11__SVInt32_tu11__SVInt32_t(
 // CPP-CHECK-NEXT:  entry:
 // CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  

[PATCH] D141240: [SVE][Builtins] Add metadata to intrinsic calls for builtins that don't define the result of inactive lanes.

2023-01-08 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm created this revision.
Herald added subscribers: ctetreau, psnobl, hiraditya, tschuett.
Herald added a reviewer: efriedma.
Herald added a project: All.
paulwalker-arm requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

The ACLE for SVE define a repeating set of builtins that allow the
result of inactive lanes to be zeroed (Z), copied from an input
operand (M) or have an undefined value (X).  When lowering these
builtins we lose the semantics of the undefined variants because to
keep the intrinsic count down we chose to treat them as M forms.

This largely makes sense because in the majority of instances only
the M form is backed by a real instruction.  This does mean we miss
out on some optimisation opportunities and so this patch introduces
metadata to the intrinsic calls that allow us to represent the cases
where an M form can be considered to be an X form.  This metadata is
freely ignorable because copying the inactive lanes from an input
operand is a valid option to represent an undefined value, and
matches the behaviour before this patch.

To demonstrate the metadata's usage this patch includes a trivial
optimisation so that svadd_x emits the unpredicated variant of ADD
as expected.

NOTE: I did investigate representing the undefined lanes using a
select on the governing predicate but this proved a poor design
because optimisations became order sensitive, the extra IR made use
count protection harder to handle and the select instruction itself
has strict rules relating to poison that hampered the intent of this
change.



NOTE: All the existing tests pass without regeneration and so to
keep the reviewed patch small I only regenerated one of the tests
to show the affect.  If agreeable I'll regenerate all the other
tests just before landing the patch.

Depends on D141056 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141240

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
  llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
  llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-unpredicate.ll

Index: llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-unpredicate.ll
===
--- /dev/null
+++ llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-unpredicate.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes=instcombine < %s | FileCheck %s
+
+target triple = "aarch64-unknown-linux-gnu"
+
+define  @unpredicate_add_x( %p,  %a,  %b) #0 {
+; CHECK-LABEL: @unpredicate_add_x(
+; CHECK-NEXT:[[OP1:%.*]] = add  [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT:ret  [[OP1]]
+;
+  %op = tail call  @llvm.aarch64.sve.add.nxv4i32( %p,  %a,  %b), !inactive_lanes_undefined !0
+  ret  %op
+}
+
+declare  @llvm.aarch64.sve.add.nxv4i32(, , )
+
+attributes #0 = { "target-features"="+sve" }
+
+!0 = !{}
Index: llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
===
--- llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -1203,6 +1203,16 @@
Intrinsic::aarch64_sve_mad>(
   IC, II, false))
 return MAD;
+
+  // The predicate is redundant if we don't care about inactive lanes.
+  if (II.getIntrinsicID() == Intrinsic::aarch64_sve_add &&
+  II.hasMetadata("inactive_lanes_undefined")) {
+auto *UnpredShift =
+BinaryOperator::Create(Instruction::Add, II.getArgOperand(1),
+   II.getArgOperand(2), II.getName(), );
+return IC.replaceInstUsesWith(II, UnpredShift);
+  }
+
   return instCombineSVEVectorBinOp(IC, II);
 }
 
Index: clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
===
--- clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
+++ clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
@@ -296,12 +296,12 @@
 
 // CHECK-LABEL: @test_svadd_s8_x(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.add.nxv16i8( [[PG:%.*]],  [[OP1:%.*]],  [[OP2:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.add.nxv16i8( [[PG:%.*]],  [[OP1:%.*]],  [[OP2:%.*]]), !inactive_lanes_undefined !2
 // CHECK-NEXT:ret  [[TMP0]]
 //
 // CPP-CHECK-LABEL: @_Z15test_svadd_s8_xu10__SVBool_tu10__SVInt8_tu10__SVInt8_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.add.nxv16i8( [[PG:%.*]],  [[OP1:%.*]],  [[OP2:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.add.nxv16i8( [[PG:%.*]],  [[OP1:%.*]],  [[OP2:%.*]]), !inactive_lanes_undefined !2
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint8_t 

[PATCH] D141230: [clang-format-diff.py] give clang-format-diff a job pool (10x speed)

2023-01-08 Thread Sean Maher via Phabricator via cfe-commits
seanptmaher updated this revision to Diff 487243.
seanptmaher added a comment.

Update python formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141230

Files:
  clang/tools/clang-format/clang-format-diff.py


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -147,11 +147,11 @@
 if args.fallback_style:
   command.extend(['-fallback-style', args.fallback_style])
 try:
-  procs[i] = (subprocess.Popen(command,
-stdout=subprocess.PIPE,
-stderr=None,
-stdin=subprocess.PIPE,
-universal_newlines=True))
+  procs[i] = subprocess.Popen(command,
+  stdout=subprocess.PIPE,
+  stderr=None,
+  stdin=subprocess.PIPE,
+  universal_newlines=True)
 except OSError as e:
   # Give the user more context when clang-format isn't
   # found/isn't executable, etc.


Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -147,11 +147,11 @@
 if args.fallback_style:
   command.extend(['-fallback-style', args.fallback_style])
 try:
-  procs[i] = (subprocess.Popen(command,
-stdout=subprocess.PIPE,
-stderr=None,
-stdin=subprocess.PIPE,
-universal_newlines=True))
+  procs[i] = subprocess.Popen(command,
+  stdout=subprocess.PIPE,
+  stderr=None,
+  stdin=subprocess.PIPE,
+  universal_newlines=True)
 except OSError as e:
   # Give the user more context when clang-format isn't
   # found/isn't executable, etc.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139534: [analyzer] Don't escape local static memregions on bind

2023-01-08 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

> Here is the gist of one *new* TP:

Where would `sprops` get escaped? Did I miss that or was that reduced out of 
the example?

Overall, this looks like a hard nut to crack. Escaping too much or too little 
are both problematic, and we don't have the information we need to make the 
decision. The question is whether we want to make an absolute decision or come 
up with a heuristic like:

  static int* p;
  MyStruct reachable();
  
  indirect();
  direct();

escaping when `direct` is called, but not escaping when `indirect` is called.

Do you see any patterns in the real-world results that would show a pattern? I 
am not opposed to making a change, but I wonder if we should start documenting 
these decisions somewhere that are likely need revision in the future when we 
have more data.  What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139534

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


[PATCH] D141206: [clang] [MinGW] Avoid adding /include and /lib when cross compiling

2023-01-08 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

In D141206#4034451 , @mstorsjo wrote:

> In D141206#4034159 , @mati865 wrote:
>
>> I had thought we do that already so this change looks reasonable for me.
>> Just one thought, do we support multilib toolchains? I think in that case 
>> Clang would have to add `/include` despite different triple.
>
> This patch actually does that already, see the parameter `RequireArchMatch` 
> which is set to true for the `/lib` case and false for `/include`.

Ah, I have messed up those 2.
I haven't seen multilib mingw-w64 distribution either but just wanted to be 
cautious here to not accidentally regress if there is somebody doing that.
Then I cannot think of any issues this patch could cause.

BTW Looking at Arch Linux 32-bit libs are placed in `/32` but 
this is off-topic.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141206

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


[PATCH] D141198: [Clang][RISCV][NFC] Reorganize test case for rvv intrinsics

2023-01-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaadd.c:3
 // REQUIRES: riscv-registered-target
-// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone 
-emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck 
--check-prefix=CHECK-RV64 %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +zfh \
+// RUN:   -target-feature +experimental-zvfh -disable-O0-optnone -emit-llvm %s 
-o - | \

Why do we need to zfh and zvfh on integer tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141198

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


[PATCH] D141206: [clang] [MinGW] Avoid adding /include and /lib when cross compiling

2023-01-08 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D141206#4034451 , @mstorsjo wrote:

> In D141206#4034159 , @mati865 wrote:
>
>> I had thought we do that already so this change looks reasonable for me.
>> Just one thought, do we support multilib toolchains? I think in that case 
>> Clang would have to add `/include` despite different triple.
>
> This patch actually does that already, see the parameter `RequireArchMatch` 
> which is set to true for the `/lib` case and false for `/include`.

... but thanks for considering and bringing up that case, I hadn't really 
thought much about that - I don't see multilib setups that often actually. Not 
sure if and/or how well they work with clang.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141206

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


[PATCH] D141206: [clang] [MinGW] Avoid adding /include and /lib when cross compiling

2023-01-08 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D141206#4034159 , @mati865 wrote:

> I had thought we do that already so this change looks reasonable for me.
> Just one thought, do we support multilib toolchains? I think in that case 
> Clang would have to add `/include` despite different triple.

This patch actually does that already, see the parameter `RequireArchMatch` 
which is set to true for the `/lib` case and false for `/include`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141206

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


[PATCH] D141230: [clang-format-diff.py] give clang-format-diff a job pool (10x speed)

2023-01-08 Thread Sean Maher via Phabricator via cfe-commits
seanptmaher created this revision.
seanptmaher added a reviewer: MyDeveloperDay.
Herald added a project: All.
seanptmaher requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch changes the implementation of clang-format-diff.py to 
start up many clang-format processes in parallel in order to speed
up clang-format-diff.py by several orders of magnitude on large
patches (less than a minute instead of several tens of minutes).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141230

Files:
  clang/tools/clang-format/clang-format-diff.py

Index: clang/tools/clang-format/clang-format-diff.py
===
--- clang/tools/clang-format/clang-format-diff.py
+++ clang/tools/clang-format/clang-format-diff.py
@@ -25,6 +25,7 @@
 
 import argparse
 import difflib
+import os
 import re
 import subprocess
 import sys
@@ -99,46 +100,63 @@
   ['-lines', str(start_line) + ':' + str(end_line)])
 
   # Reformat files containing changes in place.
-  for filename, lines in lines_by_file.items():
-if args.i and args.verbose:
-  print('Formatting {}'.format(filename))
-command = [args.binary, filename]
-if args.i:
-  command.append('-i')
-if args.sort_includes:
-  command.append('-sort-includes')
-command.extend(lines)
-if args.style:
-  command.extend(['-style', args.style])
-if args.fallback_style:
-  command.extend(['-fallback-style', args.fallback_style])
-
+  lbf = list(lines_by_file.items())
+  procs = None
+  try:
+procs = [None for i in range(len(os.sched_getaffinity(0)) * 8)]
+  except AttributeError as e:
+# os.sched_getaffinity isn't defined on all platforms.
+import multiprocessing
 try:
-  p = subprocess.Popen(command,
-   stdout=subprocess.PIPE,
-   stderr=None,
-   stdin=subprocess.PIPE,
-   universal_newlines=True)
-except OSError as e:
-  # Give the user more context when clang-format isn't
-  # found/isn't executable, etc.
-  raise RuntimeError(
-'Failed to run "%s" - %s"' % (" ".join(command), e.strerror))
-
-stdout, stderr = p.communicate()
-if p.returncode != 0:
-  sys.exit(p.returncode)
+  procs = [None for i in range(multiprocessing.cpu_count())]
+except NotImplementedError as e:
+  # Fallback to 8 concurrent processes in the case that CPU count cannot be
+  # determined.
+  procs = [None for i in range(8)]
 
-if not args.i:
-  with open(filename) as f:
-code = f.readlines()
-  formatted_code = StringIO(stdout).readlines()
-  diff = difflib.unified_diff(code, formatted_code,
-  filename, filename,
-  '(before formatting)', '(after formatting)')
-  diff_string = ''.join(diff)
-  if len(diff_string) > 0:
-sys.stdout.write(diff_string)
+  while lbf:
+for i, proc in enumerate(procs):
+  if not lbf:
+break
+  if proc is None or proc.poll() is not None:
+if proc is not None:
+  stdout, stderr = proc.communicate()
+  if proc.returncode != 0:
+sys.exit(proc.returncode)
+  if not args.i:
+with open(filename) as f:
+  code = f.readlines()
+formatted_code = StringIO(stdout).readlines()
+diff = difflib.unified_diff(code, formatted_code,
+filename, filename,
+'(before formatting)', '(after formatting)')
+diff_string = ''.join(diff)
+if len(diff_string) > 0:
+  sys.stdout.write(diff_string)
+filename, lines = lbf.pop()
+if args.i and args.verbose:
+  print('Formatting {}'.format(filename))
+command = [args.binary, filename]
+if args.i:
+  command.append('-i')
+if args.sort_includes:
+  command.append('-sort-includes')
+command.extend(lines)
+if args.style:
+  command.extend(['-style', args.style])
+if args.fallback_style:
+  command.extend(['-fallback-style', args.fallback_style])
+try:
+  procs[i] = (subprocess.Popen(command,
+stdout=subprocess.PIPE,
+stderr=None,
+stdin=subprocess.PIPE,
+universal_newlines=True))
+except OSError as e:
+  # Give the user more context when clang-format isn't
+  # found/isn't executable, etc.
+  raise RuntimeError(
+  'Failed to run "%s" - %s"' % (" ".join(command), e.strerror))
 
 if __name__ == '__main__':
   main()
___
cfe-commits mailing 

[PATCH] D140915: [clangd] Fix getQueryScopes for using-directive with inline namespace

2023-01-08 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added inline comments.



Comment at: clang-tools-extra/clangd/CodeComplete.cpp:674
+else if (const auto *ND = dyn_cast(Context)) {
+  if (ND->isInlineNamespace())
+Scopes.AccessibleScopes.push_back(printQualifiedName(*ND) + "::");

kadircet wrote:
> tom-anders wrote:
> > kadircet wrote:
> > > since we know that the `Context` is a `NamespaceDecl` it should be safe 
> > > to use `printQualifiedName` always. any reason for the extra branching 
> > > here (apart from minimizing the change to behaviour)? if not I think we 
> > > can get rid of the special casing.
> > Unfortunately, this fails CompletionTest.EnclosingScopeComesFirst and 
> > CompletionTest.NoDuplicatedQueryScopes, I think because of anonymous 
> > namespaces (where printNameSpaceScope would return an empty string, but 
> > (printQualifiedName(*ND) + "::" does not). 
> i see. taking a closer look at this `getQueryScopes` is used for two things:
> - The scopes to query with fuzzyfind requests, hence this should use the same 
> "serialization" as symbolcollector (which only strips anon namespaces today, 
> but initially it were to strip both anon & inline namespaces. it got changed 
> inside clang without clangd tests catching it).
> - The shortening of the fully qualified name in `CodeCompletionBuilder`. Not 
> having inline namespaces spelled in the available namespaces implies getting 
> wrong qualifiers (such as the bug you're fixing).
> 
> so considering the requirements here:
> - when querying index, we actually want to hide inline namespaces (as 
> `ns::hidden::Foo` should be a viable alternative even if only `ns::` is 
> accessible). so we should actually fix `printQualifiedName` to set 
> `SuppressInlineNamespace` in printing policy to restore the old behaviour 
> (and keep using `printNamespaceScope` here).
> - inside `CodeCompletionBuilder`, we shouldn't use the same scopes we use 
> during index queries. we should use the visible namespaces while preserving 
> inline namespace information and only ignoring the anonymous namespaces.
> 
> hence can we have 2 separate scopes in `CodeCompleteFlow` instead?
> One called `QueryScopes`, which has the behavior we have today (fixing 
> printQualifiedName is a separate issues).
> Other called `AccessibleScopes`, which has accessible namespaces spelled 
> **with** inline namespaces, so that we can get proper qualification during 
> code-complete.
> 
> does that make sense?
tbh I'm a bit confused - I understand your requirements, but am not sure I 
understand your proposed solution. Can you expand a bit further? Looking at the 
code, there are already both `QueryScopes` and `AccessibleScopes` 
variables/fields in various classes, I'm not really sure at which places you 
want to make changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140915

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


[PATCH] D141032: [Clang][RISCV] Expose vlenb to user

2023-01-08 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD marked 2 inline comments as done.
eopXD added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:1565
+  unsigned long __rv = 0;
+  __asm__ __volatile__ ("csrr\t%0, vlenb" : "=r"(__rv) : : "memory");
+  return __rv;

pcwang-thead wrote:
> Inline assembly may not be elegant since it can't be optimized in many ways. 
> We can eliminate some redundant reads of vlenb currently(done in D125564). So 
> I think we may add a builtin function and lower it to `llvm.read_register`?
Thank you for the tip. Please review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141032

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


[PATCH] D141032: [Clang][RISCV] Expose vlenb to user

2023-01-08 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 487206.
eopXD marked an inline comment as not done.
eopXD added a comment.

Update code. Apply suggestion from @pcwang-thead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141032

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c


Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
@@ -0,0 +1,15 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone 
-emit-llvm %s -o - \
+// RUN: | opt -S -O2 | FileCheck  %s
+
+#include 
+
+// CHECK-LABEL: @test_vlenb(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 
@llvm.read_register.i64(metadata [[META4:![0-9]+]])
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+unsigned long test_vlenb(void) {
+  return vlenb();
+}
Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -1558,6 +1558,32 @@
 }] in
 def vread_vwrite_csr: RVVHeader;
 
+let HeaderCode =
+[{
+#define vlenb() __builtin_rvv_vlenb()
+}] in
+def vlenb_macro: RVVHeader;
+
+let HasBuiltinAlias = false, HasVL = false, HasMasked = false,
+UnMaskedPolicyScheme = NonePolicy, MaskedPolicyScheme = NonePolicy,
+Log2LMUL = [0], IRName = "",
+ManualCodegen = [{
+{
+  LLVMContext  = CGM.getLLVMContext();
+  llvm::MDBuilder MDHelper(Context);
+
+  llvm::Metadata *Ops[] = {llvm::MDString::get(Context, "vlenb")};
+  llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+  llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+  llvm::Function *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+  return Builder.CreateCall(F, Metadata);
+}
+}] in
+{
+  def vlenb : RVVBuiltin<"", "u", "i">;
+}
+
 // 6. Configuration-Setting Instructions
 // 6.1. vsetvli/vsetvl instructions
 


Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
@@ -0,0 +1,15 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone -emit-llvm %s -o - \
+// RUN: | opt -S -O2 | FileCheck  %s
+
+#include 
+
+// CHECK-LABEL: @test_vlenb(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.read_register.i64(metadata [[META4:![0-9]+]])
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+unsigned long test_vlenb(void) {
+  return vlenb();
+}
Index: clang/include/clang/Basic/riscv_vector.td
===
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -1558,6 +1558,32 @@
 }] in
 def vread_vwrite_csr: RVVHeader;
 
+let HeaderCode =
+[{
+#define vlenb() __builtin_rvv_vlenb()
+}] in
+def vlenb_macro: RVVHeader;
+
+let HasBuiltinAlias = false, HasVL = false, HasMasked = false,
+UnMaskedPolicyScheme = NonePolicy, MaskedPolicyScheme = NonePolicy,
+Log2LMUL = [0], IRName = "",
+ManualCodegen = [{
+{
+  LLVMContext  = CGM.getLLVMContext();
+  llvm::MDBuilder MDHelper(Context);
+
+  llvm::Metadata *Ops[] = {llvm::MDString::get(Context, "vlenb")};
+  llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+  llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+  llvm::Function *F =
+CGM.getIntrinsic(llvm::Intrinsic::read_register, {Int64Ty});
+  return Builder.CreateCall(F, Metadata);
+}
+}] in
+{
+  def vlenb : RVVBuiltin<"", "u", "i">;
+}
+
 // 6. Configuration-Setting Instructions
 // 6.1. vsetvli/vsetvl instructions
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D141000#4034305 , @Eugene.Zelenko 
wrote:

> It'll be good idea to check that `HeaderFileExtensions` and 
> `ImplementationFileExtensions` do not overlap.

Good idea, done!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

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


[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 487202.
carlosgalvezp added a comment.

Add check to ensure HeaderFileExtensions and ImplementationFileExtensions
do not overlap.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -75,13 +75,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -104,6 +111,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -116,6 +125,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -127,6 +138,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vector({"hpp", "hxx"}),
+*Options.HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"cpp", "cxx"}),
+*Options.ImplementationFileExtensions);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ("user2", *Options.User);
   ASSERT_TRUE(Options.ExtraArgs.has_value());
Index: clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
@@ -3,6 +3,8 @@
 
 // RUN: not clang-tidy -verify-config \
 // RUN: --checks='-*,bad*glob,llvm*,llvm-includeorder,my-made-up-check' --config='{Checks: "readability-else-after-ret", \
+// RUN: HeaderFileExtensions: ["h", "hh", "hpp"], \
+// RUN: ImplementationFileExtensions: ["c", "cc", "hpp"], \
 // RUN: CheckOptions: [{key: "IgnoreMacros", value: "true"}, \
 // RUN:{key: "StriceMode", value: "true"}, \
 // RUN:{key: modernize-lop-convert.UseCxx20ReverseRanges, value: true} \
@@ -12,6 +14,7 @@
 // CHECK-VERIFY-DAG: command-line option '-config': warning: unknown check 'readability-else-after-ret'; did you mean 'readability-else-after-return' [-verify-config]
 // CHECK-VERIFY-DAG: command-line option '-config': warning: unknown check option 'modernize-lop-convert.UseCxx20ReverseRanges'; did you mean 'modernize-loop-convert.UseCxx20ReverseRanges' [-verify-config]
 // 

[PATCH] D141192: [Clang] Fix warnings on bad shifts.

2023-01-08 Thread Dmitriy Chestnykh via Phabricator via cfe-commits
chestnykh updated this revision to Diff 487200.

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

https://reviews.llvm.org/D141192

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/Interp/shifts.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/Sema/shift-count-negative.c
  clang/test/Sema/shift-count-overflow.c
  clang/test/Sema/shift-negative-value.c
  clang/test/Sema/vla-2.c
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp
  clang/test/SemaCXX/shift.cpp

Index: clang/test/SemaCXX/shift.cpp
===
--- clang/test/SemaCXX/shift.cpp
+++ clang/test/SemaCXX/shift.cpp
@@ -22,7 +22,6 @@
   c = 1 << -1; // expected-warning {{shift count is negative}}
   c = 1 >> -1; // expected-warning {{shift count is negative}}
   c = 1 << (unsigned)-1; // expected-warning {{shift count >= width of type}}
- // expected-warning@-1 {{implicit conversion}}
   c = 1 >> (unsigned)-1; // expected-warning {{shift count >= width of type}}
   c = 1 << c;
   c <<= 0;
Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -21,7 +21,7 @@
 template
 struct A {
 // expected-note@-1+ {{candidate constructor}}
-  explicit(1 << a)
+  explicit(1 << a) // expected-warning {{shift count is negative}}
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
   A(int);
Index: clang/test/Sema/vla-2.c
===
--- clang/test/Sema/vla-2.c
+++ clang/test/Sema/vla-2.c
@@ -4,14 +4,17 @@
 // a different codepath when we have already emitted an error.)
 
 int PotentiallyEvaluatedSizeofWarn(int n) {
-  return (int)sizeof *(0 << 32,(int(*)[n])0); // expected-warning {{left operand of comma operator has no effect}} expected-warning {{shift count >= width of type}}
+  return (int)sizeof *(0 << 32,(int(*)[n])0); /* expected-warning {{shift count >= width of type}}
+ expected-warning {{left operand of comma operator has no effect}} */
 }
 
 void PotentiallyEvaluatedTypeofWarn(int n) {
-  __typeof(*(0 << 32,(int(*)[n])0)) x; // expected-warning {{left operand of comma operator has no effect}} expected-warning {{shift count >= width of type}}
+  __typeof(*(0 << 32,(int(*)[n])0)) x; /*expected-warning {{shift count >= width of type}}
+ expected-warning {{left operand of comma operator has no effect}} */
   (void)x;
 }
 
 void PotentiallyEvaluatedArrayBoundWarn(int n) {
-  (void)*(int(*)[(0 << 32,n)])0; // expected-warning {{left operand of comma operator has no effect}}
+  (void)*(int(*)[(0 << 32,n)])0; /* expected-warning {{shift count >= width of type}}
+expected-warning {{left operand of comma operator has no effect}} */
 }
Index: clang/test/Sema/shift-negative-value.c
===
--- /dev/null
+++ clang/test/Sema/shift-negative-value.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-negative-value %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-negative-value %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (-1<<29) //expected-warning {{shifting a negative signed value is undefined}}
+};
+
Index: clang/test/Sema/shift-count-overflow.c
===
--- /dev/null
+++ clang/test/Sema/shift-count-overflow.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-count-overflow %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (1<<32) // expected-warning {{shift count >= width of type}}   
+};
+
+
+
Index: clang/test/Sema/shift-count-negative.c
===
--- /dev/null
+++ clang/test/Sema/shift-count-negative.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-count-negative %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-count-negative %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (1<<-29) //expected-warning {{shift count is negative}}
+};
+
Index: clang/test/C/drs/dr0xx.c
===
--- clang/test/C/drs/dr0xx.c
+++ clang/test/C/drs/dr0xx.c
@@ -426,7 +426,7 @@
   /* Demonstrate that we don't crash when left shifting a signed value; that's
* implementation defined behavior.
*/
- _Static_assert(-1 << 1 == -2, "fail"); /* Didn't shift a zero into the "sign bit". */
+ _Static_assert(-1 << 1 == 

[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Since we are at it - are we happy with the name "ImplementationFileExtensions"? 
I think "SourceFileExtensions" is more common in the literature, and it would 
look more visually pleasing in the config file since it has the same length as 
"HeaderFileExtensions".

  HeaderFileExtensions: ["h", "hh"]
  ImplementationFileExtensions: ["c", "cc"]

vs

  HeaderFileExtensions: ["h", "hh"]
  SourceFileExtensions: ["c", "cc"]


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

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


[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

I've heard Clang 16 will be branched out on 24th January, it would be good to 
get this merged by then (if people are happy with it) so the full removal can 
happen in clang-tidy 18 :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

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


[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-08 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

It'll be good idea to check that `HeaderFileExtensions` and 
`ImplementationFileExtensions` do not overlap.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

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


[PATCH] D141226: [WIP][clangd] support expanding `decltype(expr)`

2023-01-08 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Enable the existing code action `ExpandAutoType` to expand
`decltype(expr)`, e.g.

  decltype(0) i;

will expand to

  int i;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141226

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
@@ -50,7 +50,10 @@
   StartsWith("fail: Could not deduce type for 'auto' type"));
   // function pointers should not be replaced
   EXPECT_THAT(apply("au^to x = ::Func;"),
-  StartsWith("fail: Could not expand type of function pointer"));
+  StartsWith("fail: Could not expand type of function"));
+  // function references should not be replaced
+  EXPECT_THAT(apply("au^to  = ns::Func;"),
+  StartsWith("fail: Could not expand type of function"));
   // lambda types are not replaced
   EXPECT_UNAVAILABLE("au^to x = []{};");
   // inline namespaces
@@ -78,6 +81,17 @@
   EXPECT_THAT(apply("template  void x() { ^auto y = T::z(); }"),
   StartsWith("fail: Could not deduce type for 'auto' type"));
 
+  EXPECT_EQ(apply("decl^type(0) i;"), "int i;");
+  EXPECT_THAT(apply("void f(); decl^type(f) g;"),
+  StartsWith("fail: Could not expand type of function"));
+  EXPECT_EQ(apply("decl^type(0) f();"), "int f();");
+  EXPECT_EQ(apply("auto f() -> decl^type(0) { return 0; }"),
+"auto f() -> int { return 0; }");
+  EXPECT_EQ(apply("template  class Foo {};"),
+"template  class Foo {};");
+  EXPECT_EQ(apply("template  class Bar {}; Bar b;"),
+"template  class Bar {}; Bar b;");
+
   ExtraArgs.push_back("-std=c++20");
   EXPECT_UNAVAILABLE("template  class Y;");
 
@@ -90,6 +104,9 @@
   // FIXME: should work on constrained auto params, once SourceRange is fixed.
   EXPECT_UNAVAILABLE("template concept C = true;"
  "auto X = [](C ^auto *){return 0;};");
+
+  EXPECT_UNAVAILABLE("auto f = [](){}; decl^type(f) g;");
+  EXPECT_UNAVAILABLE("decl^type([]{}) f;");
 }
 
 } // namespace
Index: clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
@@ -29,7 +29,6 @@
 /// After:
 ///MyClass x = Something();
 ///^^^
-/// FIXME: Handle decltype as well
 class ExpandAutoType : public Tweak {
 public:
   const char *id() const final;
@@ -41,12 +40,15 @@
   std::string title() const override;
 
 private:
-  SourceRange AutoRange;
+  SourceRange Range;
+  bool IsAutoType;
 };
 
 REGISTER_TWEAK(ExpandAutoType)
 
-std::string ExpandAutoType::title() const { return "Expand auto type"; }
+std::string ExpandAutoType::title() const {
+  return IsAutoType ? "Expand auto type" : "Expand decltype";
+}
 
 // Structured bindings must use auto, e.g. `const auto& [a,b,c] = ...;`.
 // Return whether N (an AutoTypeLoc) is such an auto that must not be expanded.
@@ -93,7 +95,7 @@
 if (!isStructuredBindingType(Node) &&
 !isDeducedAsLambda(Node, Result.getBeginLoc()) &&
 !isTemplateParam(Node))
-  AutoRange = Result.getSourceRange();
+  Range = Result.getSourceRange();
   }
   if (auto TTPAuto = TypeNode->getAs()) {
 // We exclude concept constraints for now, as the SourceRange is wrong.
@@ -102,41 +104,43 @@
 // TTPAuto->getSourceRange only covers "auto", not "C auto".
 if (TTPAuto.getDecl()->isImplicit() &&
 !TTPAuto.getDecl()->hasTypeConstraint())
-  AutoRange = TTPAuto.getSourceRange();
+  Range = TTPAuto.getSourceRange();
+  }
+  IsAutoType = true;
+
+  if (auto DTTL = TypeNode->getAs()) {
+if (!isDeducedAsLambda(Node, DTTL.getBeginLoc()))
+  Range = DTTL.getSourceRange();
+IsAutoType = false;
   }
 }
   }
 
-  return AutoRange.isValid();
+  return Range.isValid();
 }
 
-Expected ExpandAutoType::apply(const Selection& Inputs) {
+Expected ExpandAutoType::apply(const Selection ) {
   auto  = Inputs.AST->getSourceManager();
 
   std::optional DeducedType =
-  getDeducedType(Inputs.AST->getASTContext(), AutoRange.getBegin());
+  getDeducedType(Inputs.AST->getASTContext(), Range.getBegin());
 
   // if we can't resolve the type, return an error message
   if (DeducedType == std::nullopt || 

[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-08 Thread Akash Banerjee 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 rG310eea1c78e3: [OpenMP] Migrate OpenMPOffloadMappingFlags 
from Clang CodeGen to OMPConstants (authored by TIFitis).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -193,6 +193,62 @@
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };
 
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum class OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
+};
+
 enum class AddressSpace : unsigned {
   Generic = 0,
   Global = 1,
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6785,67 +6785,13 @@
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags signals that the base address of an entry should be
-/// passed to the target kernel as an argument.
-OMP_MAP_TARGET_PARAM = 0x20,
-/// Signal that the runtime library has to return the device pointer
-/// in the current position for the data being mapped. Used when we 

[clang] 310eea1 - [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-08 Thread Akash Banerjee via cfe-commits

Author: Akash Banerjee
Date: 2023-01-08T16:45:43Z
New Revision: 310eea1c78e3e7aac7c016ab9bdf00d04f354645

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

LOG: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to 
OMPConstants

This patch moves the OpenMPOffloadMappingFlags enum definiition from Clang 
codegen to OMPConstants.h

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 573367c646fc5..3cd0e438e317c 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6785,67 +6785,13 @@ LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags signals that the base address of an entry should be
-/// passed to the target kernel as an argument.
-OMP_MAP_TARGET_PARAM = 0x20,
-/// Signal that the runtime library has to return the device pointer
-/// in the current position for the data being mapped. Used when we have 
the
-/// use_device_ptr or use_device_addr clause.
-OMP_MAP_RETURN_PARAM = 0x40,
-/// This flag signals that the reference being passed is a pointer to
-/// private data.
-OMP_MAP_PRIVATE = 0x80,
-/// Pass the element to the device by value.
-OMP_MAP_LITERAL = 0x100,
-/// Implicit map
-OMP_MAP_IMPLICIT = 0x200,
-/// Close is a hint to the runtime to allocate memory close to
-/// the target device.
-OMP_MAP_CLOSE = 0x400,
-/// 0x800 is reserved for compatibility with XLC.
-/// Produce a runtime error if the data is not already allocated.
-OMP_MAP_PRESENT = 0x1000,
-// Increment and decrement a separate reference counter so that the data
-// cannot be unmapped within the associated region.  Thus, this flag is
-// intended to be used on 'target' and 'target data' directives because 
they
-// are inherently structured.  It is not intended to be used on 'target
-// enter data' and 'target exit data' directives because they are 
inherently
-// dynamic.
-// This is an OpenMP extension for the sake of OpenACC support.
-OMP_MAP_OMPX_HOLD = 0x2000,
-/// Signal that the runtime library should use args as an array of
-/// descriptor_dim pointers and use args_size as dims. Used when we have
-/// non-contiguous list items in target update directive
-OMP_MAP_NON_CONTIG = 0x1000,
-/// The 16 MSBs of the flags indicate whether the entry is member of some
-/// struct/class.
-OMP_MAP_MEMBER_OF = 0x,
-LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF),
-  };
-
   /// Get the offset of the OMP_MAP_MEMBER_OF field.
   static unsigned getFlagMemberOffset() {
 unsigned Offset = 0;
-for (uint64_t Remain = OMP_MAP_MEMBER_OF; !(Remain & 1);
- Remain = Remain >> 1)
+for (uint64_t Remain =
+ static_cast>(
+ OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF);
+ !(Remain & 1); Remain = Remain >> 1)
   Offset++;
 return Offset;
   }
@@ -7103,7 +7049,8 @@ class MappableExprsHandler {
   ArrayRef MotionModifiers, bool IsImplicit,
   bool AddPtrFlag, bool AddIsTargetParamFlag, bool IsNonContiguous) const {
 OpenMPOffloadMappingFlags Bits =
-IsImplicit ? OMP_MAP_IMPLICIT : OMP_MAP_NONE;
+IsImplicit ? OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT
+   : OpenMPOffloadMappingFlags::OMP_MAP_NONE;
 switch (MapType) {
 case OMPC_MAP_alloc:
 case OMPC_MAP_release:
@@ -7113,35 +7060,36 @@ class MappableExprsHandler {
   // type modifiers.
   break;
 case OMPC_MAP_to:
-  Bits |= OMP_MAP_TO;
+  Bits |= OpenMPOffloadMappingFlags::OMP_MAP_TO;
 

[clang] e68fc86 - [NFCI][Offload Bundler] Replace hand-rolled endian conversion with llvm::support

2023-01-08 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-01-08T17:37:02+01:00
New Revision: e68fc86b22fd92f15c464b69e8d98a76f139cebd

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

LOG: [NFCI][Offload Bundler] Replace hand-rolled endian conversion with 
llvm::support

Added: 


Modified: 
clang/lib/Driver/OffloadBundler.cpp

Removed: 




diff  --git a/clang/lib/Driver/OffloadBundler.cpp 
b/clang/lib/Driver/OffloadBundler.cpp
index 86fc4df5914a..7cffe4008b8e 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -29,8 +29,8 @@
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Casting.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/EndianStream.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
@@ -297,24 +297,12 @@ class FileHandler {
 
 /// Read 8-byte integers from a buffer in little-endian format.
 static uint64_t Read8byteIntegerFromBuffer(StringRef Buffer, size_t pos) {
-  uint64_t Res = 0;
-  const char *Data = Buffer.data();
-
-  for (unsigned i = 0; i < 8; ++i) {
-Res <<= 8;
-uint64_t Char = (uint64_t)Data[pos + 7 - i];
-Res |= 0xffu & Char;
-  }
-  return Res;
+  return llvm::support::endian::read64le(Buffer.data() + pos);
 }
 
 /// Write 8-byte integers to a buffer in little-endian format.
 static void Write8byteIntegerToBuffer(raw_fd_ostream , uint64_t Val) {
-  for (unsigned i = 0; i < 8; ++i) {
-char Char = (char)(Val & 0xffu);
-OS.write(, 1);
-Val >>= 8;
-  }
+  llvm::support::endian::write(OS, Val, llvm::support::little);
 }
 
 class BinaryFileHandler final : public FileHandler {



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


[clang] b6942a2 - [NFC] Hide implementation details in anonymous namespaces

2023-01-08 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2023-01-08T17:37:02+01:00
New Revision: b6942a2880c578d2eab89ecb75e637aac41c5e51

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

LOG: [NFC] Hide implementation details in anonymous namespaces

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/lib/Driver/OffloadBundler.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
llvm/lib/CodeGen/ExpandLargeDivRem.cpp
llvm/lib/CodeGen/ExpandLargeFpConvert.cpp
llvm/lib/CodeGen/MachineCycleAnalysis.cpp
llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
llvm/lib/MC/SPIRVObjectWriter.cpp
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
llvm/lib/Target/AMDGPU/GCNVOPDUtils.cpp
llvm/lib/Target/AMDGPU/R600ISelDAGToDAG.cpp
llvm/lib/Target/AMDGPU/R600MCInstLower.cpp
llvm/lib/Target/AMDGPU/R600TargetMachine.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/lib/Target/VE/VERegisterInfo.cpp
llvm/lib/Target/VE/VETargetMachine.cpp
llvm/lib/Target/X86/X86ReturnThunks.cpp
llvm/lib/Transforms/Scalar/LoopFlatten.cpp
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index e77f57008d82f..329718c99dc65 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8683,6 +8683,7 @@ Expected 
ASTImporter::Import(TypeSourceInfo *FromTSI) {
   return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
 }
 
+namespace {
 // To use this object, it should be created before the new attribute is 
created,
 // and destructed after it is created. The construction already performs the
 // import of the data.
@@ -8813,6 +8814,7 @@ class AttrImporter {
 return ToAttr;
   }
 };
+} // namespace
 
 Expected ASTImporter::Import(const Attr *FromAttr) {
   AttrImporter AI(*this);

diff  --git a/clang/lib/Driver/OffloadBundler.cpp 
b/clang/lib/Driver/OffloadBundler.cpp
index bcc0c320fa476..86fc4df5914a2 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -184,6 +184,7 @@ bool isCodeObjectCompatible(const OffloadTargetInfo 
,
   return true;
 }
 
+namespace {
 /// Generic file handler interface.
 class FileHandler {
 public:
@@ -491,8 +492,6 @@ class BinaryFileHandler final : public FileHandler {
   }
 };
 
-namespace {
-
 // This class implements a list of temporary files that are removed upon
 // object destruction.
 class TempFileHandlerRAII {
@@ -524,8 +523,6 @@ class TempFileHandlerRAII {
   std::forward_list> Files;
 };
 
-} // end anonymous namespace
-
 /// Handler for object files. The bundles are organized by sections with a
 /// designated name.
 ///
@@ -827,6 +824,7 @@ class TextFileHandler final : public FileHandler {
 return Error::success();
   }
 };
+} // namespace
 
 /// Return an appropriate object file handler. We use the specific object
 /// handler if we know how to deal with that format, otherwise we use a default

diff  --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index bde2036ec65c6..7f0677f3376f1 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2143,6 +2143,7 @@ class ConsumedWarningsHandler : public 
ConsumedWarningsHandlerBase {
 // Unsafe buffer usage analysis.
 
//===--===//
 
+namespace {
 class UnsafeBufferUsageReporter : public UnsafeBufferUsageHandler {
   Sema 
 
@@ -2163,7 +2164,7 @@ class UnsafeBufferUsageReporter : public 
UnsafeBufferUsageHandler {
   D << F;
   }
 };
-
+} // namespace
 
 
//===--===//
 // AnalysisBasedWarnings - Worker object used by Sema to execute analysis-based

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index 4583b2191bf2b..afacf735bdd43 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -613,6 +613,7 @@ static std::optional describeRegion(const 
MemRegion *MR) {
 
 using Bindings = llvm::SmallVector, 4>;
 
+namespace {
 class VarBindingsCollector : public StoreManager::BindingsHandler {
   SymbolRef 

[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-08 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 487195.
ccotter added a comment.

- tidy up docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-this-with-capture-default.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-this-with-capture-default.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-this-with-capture-default.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t
+
+struct Obj {
+  void lambdas_that_warn_default_capture_copy() {
+int local{};
+int local2{};
+
+auto explicit_this_capture = [=, this]() { };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [this]() { };
+
+auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [local, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [local, local2, this]() { return (local+local2) > 10; };
+
+auto explicit_this_capture_local_ref = [=, this, ]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [this, ]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref2 = [=, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref3 = [=, , this, ]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [, this, ]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref4 = [=, , , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [, , this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref_extra_whitespace = [=, &  local, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:62: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [&  local, , this]() { return (local+x) > 10; }
+
+auto explicit_this_capture_local_ref_with_comment = [=, & /* byref */ local, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:58: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [& /* byref */ local, , this]() { return (local+x) > 10; }
+
+auto implicit_this_capture = [=]() { return x > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [this]() { return x > 10; };
+
+auto implicit_this_capture_local = [=]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:41: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [local, this]() { return 

[PATCH] D140686: [WIP][Clang][RISCV] Update operand order for vmerge and vcompress

2023-01-08 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 487194.
eopXD added a comment.

Rebase upon D141198 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140686

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vcompress.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfmerge.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vmerge.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vcompress.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfmerge.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vmerge.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vcompress.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfmerge.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vmerge.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vcompress.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vfmerge.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vmerge.c

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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.

LGTM! Minor nit.




Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst:4
+cppcoreguidelines-avoid-capture-default-when-capturing-this
+=
+

Fix line so it's as long as the text above


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-08 Thread Chris Cotter via Phabricator via cfe-commits
ccotter marked an inline comment as done.
ccotter added a comment.

Thanks!

I opted for 'avoid-capture-default-when-capturing-this' and updated the name 
and docs etc in the most recent diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-08 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 487193.
ccotter added a comment.

- rename to avoid-capture-deafult-when-capturing-this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-this-with-capture-default.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-this-with-capture-default.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-this-with-capture-default.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t
+
+struct Obj {
+  void lambdas_that_warn_default_capture_copy() {
+int local{};
+int local2{};
+
+auto explicit_this_capture = [=, this]() { };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [this]() { };
+
+auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [local, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [local, local2, this]() { return (local+local2) > 10; };
+
+auto explicit_this_capture_local_ref = [=, this, ]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [this, ]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref2 = [=, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref3 = [=, , this, ]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [, this, ]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref4 = [=, , , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [, , this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref_extra_whitespace = [=, &  local, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:62: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [&  local, , this]() { return (local+x) > 10; }
+
+auto explicit_this_capture_local_ref_with_comment = [=, & /* byref */ local, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:58: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [& /* byref */ local, , this]() { return (local+x) > 10; }
+
+auto implicit_this_capture = [=]() { return x > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: [this]() { return x > 10; };
+
+auto implicit_this_capture_local = [=]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:41: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// 

[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 487192.
carlosgalvezp retitled this revision from "[clang-tidy] Introduce 
HeaderFileExtensions option" to "[clang-tidy] Introduce HeaderFileExtensions 
and ImplementationFileExtensions options".
carlosgalvezp edited the summary of this revision.
carlosgalvezp added a comment.

Update commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -75,13 +75,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -104,6 +111,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -116,6 +125,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -127,6 +138,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vector({"hpp", "hxx"}),
+*Options.HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"cpp", "cxx"}),
+*Options.ImplementationFileExtensions);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ("user2", *Options.User);
   ASSERT_TRUE(Options.ExtraArgs.has_value());
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -139,7 +139,7 @@
  When the value is empty, clang-tidy will
  attempt to find a file named .clang-tidy for
  each source file in its parent directories.
---config-file= - 
+--config-file= -
 Specify the path of .clang-tidy or custom config file:
   e.g. --config-file=/some/path/myTidyConfigFile
 This option internally works exactly the same way as
@@ -237,7 +237,7 @@
  format to stderr. When this option is passed,
  these per-TU profiles are instead stored as JSON.
 --system-headers   - Display the errors from system headers.
-

[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions option

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 487191.
carlosgalvezp added a comment.

- Add also ImplementationFileExtensions.
- Add deprecation notice to affected checks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

Files:
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -75,13 +75,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -104,6 +111,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -116,6 +125,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -127,6 +138,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vector({"hpp", "hxx"}),
+*Options.HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"cpp", "cxx"}),
+*Options.ImplementationFileExtensions);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ("user2", *Options.User);
   ASSERT_TRUE(Options.ExtraArgs.has_value());
Index: clang-tools-extra/docs/clang-tidy/index.rst
===
--- clang-tools-extra/docs/clang-tidy/index.rst
+++ clang-tools-extra/docs/clang-tidy/index.rst
@@ -139,7 +139,7 @@
  When the value is empty, clang-tidy will
  attempt to find a file named .clang-tidy for
  each source file in its parent directories.
---config-file= - 
+--config-file= -
 Specify the path of .clang-tidy or custom config file:
   e.g. --config-file=/some/path/myTidyConfigFile
 This option internally works exactly the same way as
@@ -237,7 +237,7 @@
  format to stderr. When this option is passed,
  these per-TU profiles are instead stored as JSON.
 --system-headers   - Display the errors from system headers.
---use-color- 
+--use-color-
 Use colors in diagnostics. If not set, colors
  

[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-08 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 487189.
ccotter added a comment.

- Use const&


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureThisWithCaptureDefaultCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureThisWithCaptureDefaultCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-this-with-capture-default.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-this-with-capture-default.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-this-with-capture-default.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-this-with-capture-default.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-this-with-capture-default %t
+
+struct Obj {
+  void lambdas_that_warn_default_capture_copy() {
+int local{};
+int local2{};
+
+auto explicit_this_capture = [=, this]() { };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [this]() { };
+
+auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [local, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [local, local2, this]() { return (local+local2) > 10; };
+
+auto explicit_this_capture_local_ref = [=, this, ]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [this, ]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref2 = [=, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref3 = [=, , this, ]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [, this, ]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref4 = [=, , , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [, , this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref_extra_whitespace = [=, &  local, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:62: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [&  local, , this]() { return (local+x) > 10; }
+
+auto explicit_this_capture_local_ref_with_comment = [=, & /* byref */ local, , this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:58: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [& /* byref */ local, , this]() { return (local+x) > 10; }
+
+auto implicit_this_capture = [=]() { return x > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [this]() { return x > 10; };
+
+auto implicit_this_capture_local = [=]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:41: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-this-with-capture-default]
+// CHECK-FIXES: [local, this]() { return (local+x) > 10; };
+  }
+
+  void 

[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-08 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureThisWithCaptureDefaultCheck.cpp:32
+  if (Capture.getCaptureKind() == LCK_ByRef) {
+SourceManager  = Context.getSourceManager();
+SourceLocation AddressofLoc = utils::lexer::findPreviousTokenKind(

Should be `const SourceManager &`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D141118: [clang-tidy][NFC] Remove unused User argument in misc-misleading-bidirectional check

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0d0b1237a9f: [clang-tidy][NFC] Remove unused User argument 
in misc-misleading-bidirectional… (authored by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141118

Files:
  clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp


Index: clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
===
--- clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
+++ clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
@@ -90,8 +90,7 @@
 class MisleadingBidirectionalCheck::MisleadingBidirectionalHandler
 : public CommentHandler {
 public:
-  MisleadingBidirectionalHandler(MisleadingBidirectionalCheck ,
- std::optional User)
+  MisleadingBidirectionalHandler(MisleadingBidirectionalCheck )
   : Check(Check) {}
 
   bool HandleComment(Preprocessor , SourceRange Range) override {
@@ -114,8 +113,7 @@
 MisleadingBidirectionalCheck::MisleadingBidirectionalCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  Handler(std::make_unique(
-  *this, Context->getOptions().User)) {}
+  Handler(std::make_unique(*this)) {}
 
 MisleadingBidirectionalCheck::~MisleadingBidirectionalCheck() = default;
 


Index: clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
===
--- clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
+++ clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
@@ -90,8 +90,7 @@
 class MisleadingBidirectionalCheck::MisleadingBidirectionalHandler
 : public CommentHandler {
 public:
-  MisleadingBidirectionalHandler(MisleadingBidirectionalCheck ,
- std::optional User)
+  MisleadingBidirectionalHandler(MisleadingBidirectionalCheck )
   : Check(Check) {}
 
   bool HandleComment(Preprocessor , SourceRange Range) override {
@@ -114,8 +113,7 @@
 MisleadingBidirectionalCheck::MisleadingBidirectionalCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  Handler(std::make_unique(
-  *this, Context->getOptions().User)) {}
+  Handler(std::make_unique(*this)) {}
 
 MisleadingBidirectionalCheck::~MisleadingBidirectionalCheck() = default;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] c0d0b12 - [clang-tidy][NFC] Remove unused User argument in misc-misleading-bidirectional check

2023-01-08 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-01-08T15:18:13Z
New Revision: c0d0b1237a9f9ee992f6775305113738e9374ca0

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

LOG: [clang-tidy][NFC] Remove unused User argument in 
misc-misleading-bidirectional check

It's not used anywhere.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp 
b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
index 3706f43d255b..dad6737ab40c 100644
--- a/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MisleadingBidirectional.cpp
@@ -90,8 +90,7 @@ static bool containsMisleadingBidi(StringRef Buffer,
 class MisleadingBidirectionalCheck::MisleadingBidirectionalHandler
 : public CommentHandler {
 public:
-  MisleadingBidirectionalHandler(MisleadingBidirectionalCheck ,
- std::optional User)
+  MisleadingBidirectionalHandler(MisleadingBidirectionalCheck )
   : Check(Check) {}
 
   bool HandleComment(Preprocessor , SourceRange Range) override {
@@ -114,8 +113,7 @@ class 
MisleadingBidirectionalCheck::MisleadingBidirectionalHandler
 MisleadingBidirectionalCheck::MisleadingBidirectionalCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  Handler(std::make_unique(
-  *this, Context->getOptions().User)) {}
+  Handler(std::make_unique(*this)) {}
 
 MisleadingBidirectionalCheck::~MisleadingBidirectionalCheck() = default;
 



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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-08 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM! Please give a few days for other reviewers to comment. If you are not 
100% happy with the check name I'd suggest to change it before merging, it will 
be much harder to change once it's in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D141192: [Clang] Fix warnings on bad shifts.

2023-01-08 Thread Dmitriy Chestnykh via Phabricator via cfe-commits
chestnykh updated this revision to Diff 487183.

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

https://reviews.llvm.org/D141192

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/Interp/shifts.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/Sema/shift-count-negative.c
  clang/test/Sema/shift-count-overflow.c
  clang/test/Sema/shift-negative-value.c
  clang/test/Sema/vla-2.c
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp

Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -21,7 +21,7 @@
 template
 struct A {
 // expected-note@-1+ {{candidate constructor}}
-  explicit(1 << a)
+  explicit(1 << a) // expected-warning {{shift count is negative}}
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
   A(int);
Index: clang/test/Sema/vla-2.c
===
--- clang/test/Sema/vla-2.c
+++ clang/test/Sema/vla-2.c
@@ -4,14 +4,17 @@
 // a different codepath when we have already emitted an error.)
 
 int PotentiallyEvaluatedSizeofWarn(int n) {
-  return (int)sizeof *(0 << 32,(int(*)[n])0); // expected-warning {{left operand of comma operator has no effect}} expected-warning {{shift count >= width of type}}
+  return (int)sizeof *(0 << 32,(int(*)[n])0); /* expected-warning {{shift count >= width of type}}
+ expected-warning {{left operand of comma operator has no effect}} */
 }
 
 void PotentiallyEvaluatedTypeofWarn(int n) {
-  __typeof(*(0 << 32,(int(*)[n])0)) x; // expected-warning {{left operand of comma operator has no effect}} expected-warning {{shift count >= width of type}}
+  __typeof(*(0 << 32,(int(*)[n])0)) x; /*expected-warning {{shift count >= width of type}}
+ expected-warning {{left operand of comma operator has no effect}} */
   (void)x;
 }
 
 void PotentiallyEvaluatedArrayBoundWarn(int n) {
-  (void)*(int(*)[(0 << 32,n)])0; // expected-warning {{left operand of comma operator has no effect}}
+  (void)*(int(*)[(0 << 32,n)])0; /* expected-warning {{shift count >= width of type}}
+expected-warning {{left operand of comma operator has no effect}} */
 }
Index: clang/test/Sema/shift-negative-value.c
===
--- /dev/null
+++ clang/test/Sema/shift-negative-value.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-negative-value %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-negative-value %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (-1<<29) //expected-warning {{shifting a negative signed value is undefined}}
+};
+
Index: clang/test/Sema/shift-count-overflow.c
===
--- /dev/null
+++ clang/test/Sema/shift-count-overflow.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-count-overflow %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (1<<32) // expected-warning {{shift count >= width of type}}   
+};
+
+
+
Index: clang/test/Sema/shift-count-negative.c
===
--- /dev/null
+++ clang/test/Sema/shift-count-negative.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-count-negative %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-count-negative %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (1<<-29) //expected-warning {{shift count is negative}}
+};
+
Index: clang/test/C/drs/dr0xx.c
===
--- clang/test/C/drs/dr0xx.c
+++ clang/test/C/drs/dr0xx.c
@@ -426,7 +426,7 @@
   /* Demonstrate that we don't crash when left shifting a signed value; that's
* implementation defined behavior.
*/
- _Static_assert(-1 << 1 == -2, "fail"); /* Didn't shift a zero into the "sign bit". */
+ _Static_assert(-1 << 1 == -2, "fail");  /* expected-warning {{shifting a negative signed value is undefined}} */
  _Static_assert(1 << 3 == 1u << 3u, "fail"); /* Shift of a positive signed value does sensible things. */
 }
 
Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -33,9 +33,7 @@
// FIXME: 'implicit conversion' warning missing in the new interpreter. \
// cxx17-warning {{shift count >= width of type}} \
  

[clang-tools-extra] f7e9d5b - [clangd] Fix an inlay-hint crash on a null deduced type.

2023-01-08 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2023-01-08T15:48:04+01:00
New Revision: f7e9d5b43e72439f5841f9ff5ef690a625fd312c

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

LOG: [clangd] Fix an inlay-hint crash on a null deduced type.

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 30c7c05e3c02..f4e38aeb653e 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -671,7 +671,8 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 if (QT->isDecltypeType())
   return true;
 if (const AutoType *AT = QT->getContainedAutoType())
-  if (AT->getDeducedType()->isDecltypeType())
+  if (!AT->getDeducedType().isNull() &&
+  AT->getDeducedType()->isDecltypeType())
 return true;
 return false;
   }

diff  --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 53621f97a604..06f2c055a4d3 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1378,11 +1378,16 @@ TEST(TypeHints, Decltype) {
 using G = Foo<$g[[decltype(0)]], float>;
 
 auto $h[[h]] = $i[[decltype(0)]]{};
+
+// No crash
+/* error-ok */
+auto $j[[s]];
   )cpp",
   ExpectedHint{": int", "a"}, ExpectedHint{": int", "b"},
   ExpectedHint{": int", "c"}, ExpectedHint{": int", "e"},
   ExpectedHint{": int", "f"}, ExpectedHint{": int", "g"},
-  ExpectedHint{": int", "h"}, ExpectedHint{": int", "i"});
+  ExpectedHint{": int", "h"}, ExpectedHint{": int", "i"},
+  ExpectedHint{": auto", "j"});
 }
 
 TEST(DesignatorHints, Basic) {



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


[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-08 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 487179.
TIFitis added a comment.

Missed the other llvm::find_if in previous revision. This should fix Windows 
build issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -193,6 +193,62 @@
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };
 
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum class OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
+};
+
 enum class AddressSpace : unsigned {
   Generic = 0,
   Global = 1,
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6796,67 +6796,13 @@
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags signals that the base address of an entry should be
-/// passed to the target kernel as an argument.
-OMP_MAP_TARGET_PARAM = 0x20,
-/// Signal that the runtime library has to return the device pointer
-/// in the current position for the data being mapped. Used when we have the
-/// use_device_ptr or use_device_addr clause.
-OMP_MAP_RETURN_PARAM = 0x40,
-

[PATCH] D141206: [clang] [MinGW] Avoid adding /include and /lib when cross compiling

2023-01-08 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 added a comment.

I had thought we do that already so this change looks reasonable for me.
Just one thought, do we support multilib toolchains? I think in that case Clang 
would have to add `/include` despite different triple.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141206

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


[PATCH] D141192: [Clang] Fix warnings on bad shifts.

2023-01-08 Thread Dmitriy Chestnykh via Phabricator via cfe-commits
chestnykh added a comment.

In D141192#4033962 , @tbaeder wrote:

> In D141192#4033591 , @shafik wrote:
>
>> So it looks like in `handleIntIntBinOp` we do hit this code:
>>
>>   unsigned SA = (unsigned) RHS.getLimitedValue(LHS.getBitWidth()-1);
>>if (SA != RHS) {
>>  Info.CCEDiag(E, diag::note_constexpr_large_shift)
>><< RHS << E->getType() << LHS.getBitWidth();
>>
>> So maybe we should figure out why we decide not to emit this diagnostic and 
>> fix it there.
>
> We return `true` anyway and so the diagnostics are not printed. This is 
> reached from a call to `VerifyIntegerConstantExpression()` IIRC.

Yes, but it seems there is no proper way to handle, for example, C code 
compiling in this place, so i left `DiagnoseBadShiftValues` changes.


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

https://reviews.llvm.org/D141192

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


[PATCH] D141192: [Clang] Fix warnings on bad shifts.

2023-01-08 Thread Dmitriy Chestnykh via Phabricator via cfe-commits
chestnykh added a comment.

I've modified `handleIntIntBinOp` so now it emits message about bad shift value.
`DiagnoseBadShiftValues` changes are also needed because `handleIntIntBinOp` 
cant properly cover for example the case we are not in c++11 mode.


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

https://reviews.llvm.org/D141192

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


[PATCH] D141192: [Clang] Fix warnings on bad shifts.

2023-01-08 Thread Dmitriy Chestnykh via Phabricator via cfe-commits
chestnykh updated this revision to Diff 487174.
chestnykh retitled this revision from "[Clang] Add warnings on bad shifts 
inside enums." to "[Clang] Fix warnings on bad shifts.".

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

https://reviews.llvm.org/D141192

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/Interp/shifts.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/Sema/shift-count-negative.c
  clang/test/Sema/shift-count-overflow.c
  clang/test/Sema/shift-negative-value.c
  clang/test/Sema/vla-2.c
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp

Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -21,7 +21,7 @@
 template
 struct A {
 // expected-note@-1+ {{candidate constructor}}
-  explicit(1 << a)
+  explicit(1 << a) // expected-warning {{shift count is negative}}
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
   A(int);
Index: clang/test/Sema/vla-2.c
===
--- clang/test/Sema/vla-2.c
+++ clang/test/Sema/vla-2.c
@@ -4,14 +4,17 @@
 // a different codepath when we have already emitted an error.)
 
 int PotentiallyEvaluatedSizeofWarn(int n) {
-  return (int)sizeof *(0 << 32,(int(*)[n])0); // expected-warning {{left operand of comma operator has no effect}} expected-warning {{shift count >= width of type}}
+  return (int)sizeof *(0 << 32,(int(*)[n])0); /* expected-warning {{shift count >= width of type}}
+ expected-warning {{left operand of comma operator has no effect}} */
 }
 
 void PotentiallyEvaluatedTypeofWarn(int n) {
-  __typeof(*(0 << 32,(int(*)[n])0)) x; // expected-warning {{left operand of comma operator has no effect}} expected-warning {{shift count >= width of type}}
+  __typeof(*(0 << 32,(int(*)[n])0)) x; /*expected-warning {{shift count >= width of type}}
+ expected-warning {{left operand of comma operator has no effect}} */
   (void)x;
 }
 
 void PotentiallyEvaluatedArrayBoundWarn(int n) {
-  (void)*(int(*)[(0 << 32,n)])0; // expected-warning {{left operand of comma operator has no effect}}
+  (void)*(int(*)[(0 << 32,n)])0; /* expected-warning {{shift count >= width of type}}
+expected-warning {{left operand of comma operator has no effect}} */
 }
Index: clang/test/Sema/shift-negative-value.c
===
--- /dev/null
+++ clang/test/Sema/shift-negative-value.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-negative-value %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-negative-value %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (-1<<29) //expected-warning {{shifting a negative signed value is undefined}}
+};
+
Index: clang/test/Sema/shift-count-overflow.c
===
--- /dev/null
+++ clang/test/Sema/shift-count-overflow.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-count-overflow %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-count-overflow %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (1<<32) //expected-warning {{shift count >= width of type}}
+};
+
Index: clang/test/Sema/shift-count-negative.c
===
--- /dev/null
+++ clang/test/Sema/shift-count-negative.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-count-negative %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-count-negative %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (1<<-29) //expected-warning {{shift count is negative}}
+};
+
Index: clang/test/C/drs/dr0xx.c
===
--- clang/test/C/drs/dr0xx.c
+++ clang/test/C/drs/dr0xx.c
@@ -426,7 +426,7 @@
   /* Demonstrate that we don't crash when left shifting a signed value; that's
* implementation defined behavior.
*/
- _Static_assert(-1 << 1 == -2, "fail"); /* Didn't shift a zero into the "sign bit". */
+ _Static_assert(-1 << 1 == -2, "fail");  /* expected-warning {{shifting a negative signed value is undefined}} */
  _Static_assert(1 << 3 == 1u << 3u, "fail"); /* Shift of a positive signed value does sensible things. */
 }
 
Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ 

[PATCH] D140292: [OpenMP] Migrate OpenMPOffloadMappingFlags from Clang CodeGen to OMPConstants

2023-01-08 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 487171.
TIFitis added a comment.

Second attempt at fixing windows build issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140292

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h

Index: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
@@ -193,6 +193,62 @@
   LLVM_MARK_AS_BITMASK_ENUM(/* LargestValue */ OMP_TGT_EXEC_MODE_GENERIC_SPMD)
 };
 
+/// Values for bit flags used to specify the mapping type for
+/// offloading.
+enum class OpenMPOffloadMappingFlags : uint64_t {
+  /// No flags
+  OMP_MAP_NONE = 0x0,
+  /// Allocate memory on the device and move data from host to device.
+  OMP_MAP_TO = 0x01,
+  /// Allocate memory on the device and move data from device to host.
+  OMP_MAP_FROM = 0x02,
+  /// Always perform the requested mapping action on the element, even
+  /// if it was already mapped before.
+  OMP_MAP_ALWAYS = 0x04,
+  /// Delete the element from the device environment, ignoring the
+  /// current reference count associated with the element.
+  OMP_MAP_DELETE = 0x08,
+  /// The element being mapped is a pointer-pointee pair; both the
+  /// pointer and the pointee should be mapped.
+  OMP_MAP_PTR_AND_OBJ = 0x10,
+  /// This flags signals that the base address of an entry should be
+  /// passed to the target kernel as an argument.
+  OMP_MAP_TARGET_PARAM = 0x20,
+  /// Signal that the runtime library has to return the device pointer
+  /// in the current position for the data being mapped. Used when we have the
+  /// use_device_ptr or use_device_addr clause.
+  OMP_MAP_RETURN_PARAM = 0x40,
+  /// This flag signals that the reference being passed is a pointer to
+  /// private data.
+  OMP_MAP_PRIVATE = 0x80,
+  /// Pass the element to the device by value.
+  OMP_MAP_LITERAL = 0x100,
+  /// Implicit map
+  OMP_MAP_IMPLICIT = 0x200,
+  /// Close is a hint to the runtime to allocate memory close to
+  /// the target device.
+  OMP_MAP_CLOSE = 0x400,
+  /// 0x800 is reserved for compatibility with XLC.
+  /// Produce a runtime error if the data is not already allocated.
+  OMP_MAP_PRESENT = 0x1000,
+  // Increment and decrement a separate reference counter so that the data
+  // cannot be unmapped within the associated region.  Thus, this flag is
+  // intended to be used on 'target' and 'target data' directives because they
+  // are inherently structured.  It is not intended to be used on 'target
+  // enter data' and 'target exit data' directives because they are inherently
+  // dynamic.
+  // This is an OpenMP extension for the sake of OpenACC support.
+  OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Signal that the runtime library should use args as an array of
+  /// descriptor_dim pointers and use args_size as dims. Used when we have
+  /// non-contiguous list items in target update directive
+  OMP_MAP_NON_CONTIG = 0x1000,
+  /// The 16 MSBs of the flags indicate whether the entry is member of some
+  /// struct/class.
+  OMP_MAP_MEMBER_OF = 0x,
+  LLVM_MARK_AS_BITMASK_ENUM(/* LargestFlag = */ OMP_MAP_MEMBER_OF)
+};
+
 enum class AddressSpace : unsigned {
   Generic = 0,
   Global = 1,
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6796,67 +6796,13 @@
 // code for that information.
 class MappableExprsHandler {
 public:
-  /// Values for bit flags used to specify the mapping type for
-  /// offloading.
-  enum OpenMPOffloadMappingFlags : uint64_t {
-/// No flags
-OMP_MAP_NONE = 0x0,
-/// Allocate memory on the device and move data from host to device.
-OMP_MAP_TO = 0x01,
-/// Allocate memory on the device and move data from device to host.
-OMP_MAP_FROM = 0x02,
-/// Always perform the requested mapping action on the element, even
-/// if it was already mapped before.
-OMP_MAP_ALWAYS = 0x04,
-/// Delete the element from the device environment, ignoring the
-/// current reference count associated with the element.
-OMP_MAP_DELETE = 0x08,
-/// The element being mapped is a pointer-pointee pair; both the
-/// pointer and the pointee should be mapped.
-OMP_MAP_PTR_AND_OBJ = 0x10,
-/// This flags signals that the base address of an entry should be
-/// passed to the target kernel as an argument.
-OMP_MAP_TARGET_PARAM = 0x20,
-/// Signal that the runtime library has to return the device pointer
-/// in the current position for the data being mapped. Used when we have the
-/// use_device_ptr or use_device_addr clause.
-OMP_MAP_RETURN_PARAM = 0x40,
-/// This flag signals that the reference being 

[PATCH] D141192: [Clang] Add warnings on bad shifts inside enums.

2023-01-08 Thread Dmitriy Chestnykh via Phabricator via cfe-commits
chestnykh updated this revision to Diff 487168.
chestnykh edited the summary of this revision.

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

https://reviews.llvm.org/D141192

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/Interp/shifts.cpp
  clang/test/C/drs/dr0xx.c
  clang/test/Sema/shift-count-negative.c
  clang/test/Sema/shift-count-overflow.c
  clang/test/Sema/shift-negative-value.c
  clang/test/Sema/vla-2.c
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp

Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -21,7 +21,7 @@
 template
 struct A {
 // pre20-note@-1+ {{candidate constructor}}
-  explicit(1 << a)
+  explicit(1 << a) // expected-warning {{shift count is negative}}
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
   A(int);
Index: clang/test/Sema/vla-2.c
===
--- clang/test/Sema/vla-2.c
+++ clang/test/Sema/vla-2.c
@@ -4,14 +4,17 @@
 // a different codepath when we have already emitted an error.)
 
 int PotentiallyEvaluatedSizeofWarn(int n) {
-  return (int)sizeof *(0 << 32,(int(*)[n])0); // expected-warning {{left operand of comma operator has no effect}} expected-warning {{shift count >= width of type}}
+  return (int)sizeof *(0 << 32,(int(*)[n])0); /* expected-warning {{shift count >= width of type}}
+ expected-warning {{left operand of comma operator has no effect}} */
 }
 
 void PotentiallyEvaluatedTypeofWarn(int n) {
-  __typeof(*(0 << 32,(int(*)[n])0)) x; // expected-warning {{left operand of comma operator has no effect}} expected-warning {{shift count >= width of type}}
+  __typeof(*(0 << 32,(int(*)[n])0)) x; /*expected-warning {{shift count >= width of type}}
+ expected-warning {{left operand of comma operator has no effect}} */
   (void)x;
 }
 
 void PotentiallyEvaluatedArrayBoundWarn(int n) {
-  (void)*(int(*)[(0 << 32,n)])0; // expected-warning {{left operand of comma operator has no effect}}
+  (void)*(int(*)[(0 << 32,n)])0; /* expected-warning {{shift count >= width of type}}
+expected-warning {{left operand of comma operator has no effect}} */
 }
Index: clang/test/Sema/shift-negative-value.c
===
--- /dev/null
+++ clang/test/Sema/shift-negative-value.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-negative-value %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-negative-value %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (-1<<29) //expected-warning {{shifting a negative signed value is undefined}}
+};
+
Index: clang/test/Sema/shift-count-overflow.c
===
--- /dev/null
+++ clang/test/Sema/shift-count-overflow.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-count-overflow %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-count-overflow %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (1<<32) //expected-warning {{shift count >= width of type}}
+};
+
Index: clang/test/Sema/shift-count-negative.c
===
--- /dev/null
+++ clang/test/Sema/shift-count-negative.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wshift-count-negative %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wshift-count-negative %s
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s
+
+enum shiftof {
+X = (1<<-29) //expected-warning {{shift count is negative}}
+};
+
Index: clang/test/C/drs/dr0xx.c
===
--- clang/test/C/drs/dr0xx.c
+++ clang/test/C/drs/dr0xx.c
@@ -426,7 +426,7 @@
   /* Demonstrate that we don't crash when left shifting a signed value; that's
* implementation defined behavior.
*/
- _Static_assert(-1 << 1 == -2, "fail"); /* Didn't shift a zero into the "sign bit". */
+ _Static_assert(-1 << 1 == -2, "fail");  /* expected-warning {{shifting a negative signed value is undefined}} */
  _Static_assert(1 << 3 == 1u << 3u, "fail"); /* Shift of a positive signed value does sensible things. */
 }
 
Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -33,9 +33,7 @@
// FIXME: 

[PATCH] D140261: [C++20][Modules] Do not allow non-inline external definitions in header units.

2023-01-08 Thread Iain Sandoe via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG335668b11643: [C++20][Modules] Do not allow non-inline 
external definitions in header units. (authored by iains).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140261

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CXX/module/module.import/p6.cpp
  clang/test/CodeGenCXX/module-initializer-header.cppm

Index: clang/test/CodeGenCXX/module-initializer-header.cppm
===
--- clang/test/CodeGenCXX/module-initializer-header.cppm
+++ clang/test/CodeGenCXX/module-initializer-header.cppm
@@ -8,24 +8,24 @@
 //
 //--- header.h
 int foo();
-int i = foo();
+static int i = foo();
 
 //--- M.cppm
 module;
 import "header.h";
 export module M;
 
-// CHECK: @i = {{.*}}global i32 0
+// CHECK: @_ZL1i = {{.*}}global i32 0
 // CHECK: void @__cxx_global_var_init()
 // CHECK-NEXT: entry:
 // CHECK-NEXT:  %call = call noundef{{.*}} i32 @_Z3foov()
-// CHECK-NEXT:  store i32 %call, ptr @i  
+// CHECK-NEXT:  store i32 %call, ptr @_ZL1i
 
 //--- Use.cpp
 import "header.h";
 
-// CHECK: @i = {{.*}}global i32 0
+// CHECK: @_ZL1i = {{.*}}global i32 0
 // CHECK: void @__cxx_global_var_init()
 // CHECK-NEXT: entry:
 // CHECK-NEXT:  %call = call noundef{{.*}} i32 @_Z3foov()
-// CHECK-NEXT:  store i32 %call, ptr @i  
+// CHECK-NEXT:  store i32 %call, ptr @_ZL1i
Index: clang/test/CXX/module/module.import/p6.cpp
===
--- /dev/null
+++ clang/test/CXX/module/module.import/p6.cpp
@@ -0,0 +1,24 @@
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -x c++-header %t/bad-header-unit.h \
+// RUN:  -emit-header-unit -o %t/bad-header-unit.pcm -verify
+
+//--- bad-header-unit.h
+
+inline int ok_foo () { return 0;}
+
+static int ok_bar ();
+
+int ok_decl ();
+
+int bad_def () { return 2;}  // expected-error {{non-inline external definitions are not permitted in C++ header units}}
+
+inline int ok_inline_var = 1;
+
+static int ok_static_var;
+
+int ok_var_decl;
+
+int bad_var_definition = 3;  // expected-error {{non-inline external definitions are not permitted in C++ header units}}
+
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13071,6 +13071,15 @@
   VDecl->setInvalidDecl();
   }
 
+  // C++ [module.import/6] external definitions are not permitted in header
+  // units.
+  if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
+  VDecl->getFormalLinkage() == Linkage::ExternalLinkage &&
+  !VDecl->isInline()) {
+Diag(VDecl->getLocation(), diag::err_extern_def_in_header_unit);
+VDecl->setInvalidDecl();
+  }
+
   // If adding the initializer will turn this declaration into a definition,
   // and we already have a definition for this variable, diagnose or otherwise
   // handle the situation.
@@ -15224,6 +15233,14 @@
 }
   }
 
+  // C++ [module.import/6] external definitions are not permitted in header
+  // units.
+  if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
+  FD->getFormalLinkage() == Linkage::ExternalLinkage && !FD->isInlined()) {
+Diag(FD->getLocation(), diag::err_extern_def_in_header_unit);
+FD->setInvalidDecl();
+  }
+
   // Ensure that the function's exception specification is instantiated.
   if (const FunctionProtoType *FPT = FD->getType()->getAs())
 ResolveExceptionSpec(D->getLocation(), FPT);
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -2325,6 +2325,12 @@
 return ModuleScopes.empty() ? false : ModuleScopes.back().ModuleInterface;
   }
 
+  /// Is the module scope we are in a C++ Header Unit?
+  bool currentModuleIsHeaderUnit() const {
+return ModuleScopes.empty() ? false
+: ModuleScopes.back().Module->isHeaderUnit();
+  }
+
   /// Get the module owning an entity.
   Module *getOwningModule(const Decl *Entity) {
 return Entity->getOwningModule();
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11236,6 +11236,8 @@
   "add 'export' here if this is intended to be a module interface unit">;
 def err_invalid_module_name : Error<
   "%0 is %select{an invalid|a reserved}1 name for a module">;
+def err_extern_def_in_header_unit : Error<
+  "non-inline external definitions are not permitted in C++ header units">;
 
 def 

[clang] 335668b - [C++20][Modules] Do not allow non-inline external definitions in header units.

2023-01-08 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2023-01-08T12:19:23Z
New Revision: 335668b116439d13c7555616e126acdc608ce59e

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

LOG: [C++20][Modules] Do not allow non-inline external definitions in header 
units.

[module.import/6] last sentence:
A header unit shall not contain a definition of a non-inline function or
variable whose name has external linkage.

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

Added: 
clang/test/CXX/module/module.import/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenCXX/module-initializer-header.cppm

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 91cb9049bcb4b..b623d260dbb30 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -187,6 +187,11 @@ code bases.
 - ``-p`` is rejected for all targets which are not AIX or OpenBSD. ``-p`` led
   to an ``-Wunused-command-line-argument`` warning in previous releases.
 
+- Clang now diagnoses non-inline externally-visible definitions in C++
+  standard header units as per ``[module.import/6]``.  Previously, in Clang-15,
+  these definitions were allowed.  Note that such definitions are ODR
+  violations if the header is included more than once.
+
 What's New in Clang |release|?
 ==
 Some of the major new features and improvements to Clang are listed

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d1bffc7e3e9c6..7154a8bcbde47 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11236,6 +11236,8 @@ def note_not_module_interface_add_export : Note<
   "add 'export' here if this is intended to be a module interface unit">;
 def err_invalid_module_name : Error<
   "%0 is %select{an invalid|a reserved}1 name for a module">;
+def err_extern_def_in_header_unit : Error<
+  "non-inline external definitions are not permitted in C++ header units">;
 
 def ext_equivalent_internal_linkage_decl_in_modules : ExtWarn<
   "ambiguous use of internal linkage declaration %0 defined in multiple 
modules">,

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1cbbcfd855121..4714b8b7cbde6 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2325,6 +2325,12 @@ class Sema final {
 return ModuleScopes.empty() ? false : ModuleScopes.back().ModuleInterface;
   }
 
+  /// Is the module scope we are in a C++ Header Unit?
+  bool currentModuleIsHeaderUnit() const {
+return ModuleScopes.empty() ? false
+: ModuleScopes.back().Module->isHeaderUnit();
+  }
+
   /// Get the module owning an entity.
   Module *getOwningModule(const Decl *Entity) {
 return Entity->getOwningModule();

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a1bfb57168c8a..d25f513591bcc 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13071,6 +13071,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
   VDecl->setInvalidDecl();
   }
 
+  // C++ [module.import/6] external definitions are not permitted in header
+  // units.
+  if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
+  VDecl->getFormalLinkage() == Linkage::ExternalLinkage &&
+  !VDecl->isInline()) {
+Diag(VDecl->getLocation(), diag::err_extern_def_in_header_unit);
+VDecl->setInvalidDecl();
+  }
+
   // If adding the initializer will turn this declaration into a definition,
   // and we already have a definition for this variable, diagnose or otherwise
   // handle the situation.
@@ -15224,6 +15233,14 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope 
*FnBodyScope, Decl *D,
 }
   }
 
+  // C++ [module.import/6] external definitions are not permitted in header
+  // units.
+  if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
+  FD->getFormalLinkage() == Linkage::ExternalLinkage && !FD->isInlined()) {
+Diag(FD->getLocation(), diag::err_extern_def_in_header_unit);
+FD->setInvalidDecl();
+  }
+
   // Ensure that the function's exception specification is instantiated.
   if (const FunctionProtoType *FPT = FD->getType()->getAs())
 ResolveExceptionSpec(D->getLocation(), FPT);

diff  --git a/clang/test/CXX/module/module.import/p6.cpp 
b/clang/test/CXX/module/module.import/p6.cpp
new file mode 100644
index 0..25c195038eb63
--- /dev/null
+++ b/clang/test/CXX/module/module.import/p6.cpp
@@ -0,0 +1,24 @@
+// RUN: mkdir -p %t
+// RUN: 

[PATCH] D136554: Implement CWG2631

2023-01-08 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 rGca6196138012: Implement CWG2631 (authored by cor3ntin).

Changed prior to commit:
  https://reviews.llvm.org/D136554?vs=486510=487151#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/UsedDeclVisitor.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/AST/ast-dump-records.cpp
  clang/test/CXX/class/class.local/p1-0x.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
  clang/test/CodeGenCXX/meminit-initializers-odr.cpp
  clang/test/PCH/default-argument-with-immediate-calls.cpp
  clang/test/SemaCXX/cxx11-default-member-initializers.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/source_location.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15593,7 +15593,7 @@
 https://wg21.link/cwg2631;>2631
 DR
 Immediate function evaluations in default arguments
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2632;>2632
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
 
 #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
@@ -8,15 +9,22 @@
 template 
 struct Printer;
 
+#ifdef USE_CONSTEVAL
+#define SOURCE_LOC_EVAL_KIND consteval
+#else
+#define SOURCE_LOC_EVAL_KIND constexpr
+#endif
+
 namespace std {
 class source_location {
   struct __impl;
 
 public:
-  static constexpr source_location current(const __impl *__p = __builtin_source_location()) noexcept {
-source_location __loc;
-__loc.__m_impl = __p;
-return __loc;
+  static SOURCE_LOC_EVAL_KIND source_location
+current(const __impl *__p = __builtin_source_location()) noexcept {
+  source_location __loc;
+  __loc.__m_impl = __p;
+  return __loc;
   }
   constexpr source_location() = default;
   constexpr source_location(source_location const &) = default;
@@ -593,3 +601,73 @@
   }
   static_assert(test());
 }
+
+namespace Lambda {
+#line 8000 "TestLambda.cpp"
+constexpr int nested_lambda(int l = []{
+  return SL::current().line();
+}()) {
+  return l;
+}
+static_assert(nested_lambda() == __LINE__ - 4);
+
+constexpr int lambda_param(int l = [](int l = SL::current().line()) {
+  return l;
+}()) {
+  return l;
+}
+static_assert(lambda_param() == __LINE__);
+
+
+}
+
+constexpr int compound_literal_fun(int a =
+  (int){ SL::current().line() }
+) { return a ;}
+static_assert(compound_literal_fun() == __LINE__);
+
+struct CompoundLiteral {
+  int a = (int){ SL::current().line() };
+};
+static_assert(CompoundLiteral{}.a == __LINE__);
+
+
+// FIXME
+// Init captures are subexpressions of the lambda expression
+// so according to the standard immediate invocations in init captures
+// should be evaluated at the call site.
+// However Clang does not yet implement this as it would introduce
+// a fair bit of complexity.
+// We intend to implement that functionality once we find real world
+// use cases that require it.
+constexpr int test_init_capture(int a =
+[b = SL::current().line()] { return b; }()) {
+  return a;
+}
+#ifdef USE_CONSTEVAL
+static_assert(test_init_capture() == __LINE__ - 4);
+#else
+static_assert(test_init_capture() == __LINE__ );
+#endif
+
+namespace check_immediate_invocations_in_templates {
+
+template 
+struct G {
+T line = __builtin_LINE();
+};
+template 
+struct S {
+int i = G{}.line;
+};
+static_assert(S{}.i != // intentional new line
+  S{}.i);
+
+template 
+constexpr int f(int i = G{}.line) {
+return i;
+}
+
+static_assert(f() != // intentional new line
+  f());
+}
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- 

[clang] ca61961 - Implement CWG2631

2023-01-08 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-01-08T10:35:26+01:00
New Revision: ca619613801233ef2def8c3cc7d311d5ed0033cb

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

LOG: Implement CWG2631

Implement https://cplusplus.github.io/CWG/issues/2631.html.

Immediate calls in default arguments and defaults members
are not evaluated.

Instead, we evaluate them when constructing a
`CXXDefaultArgExpr`/`BuildCXXDefaultInitExpr`.

The immediate calls are executed by doing a
transform on the initializing expression.

Note that lambdas are not considering subexpressions so
we do not need to transform them.

As a result of this patch, unused default member
initializers are not considered odr-used, and
errors about members binding to local variables
in an outer scope only surface at the point
where a constructor is defined.

Reviewed By: aaron.ballman, #clang-language-wg, rupprecht

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

Added: 
clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
clang/test/CodeGenCXX/meminit-initializers-odr.cpp
clang/test/PCH/default-argument-with-immediate-calls.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Sema/UsedDeclVisitor.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/AST/ast-dump-records.cpp
clang/test/CXX/class/class.local/p1-0x.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/test/CodeGenCXX/builtin-source-location.cpp
clang/test/SemaCXX/cxx11-default-member-initializers.cpp
clang/test/SemaCXX/source_location.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f2cfac238613c..91cb9049bcb4b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -671,6 +671,11 @@ C++ Language Changes in Clang
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
 - implemented `DR2654 `_ which undeprecates
   all compound assignements operations on volatile qualified variables.
+- Implemented DR2631. Invalid ``consteval`` calls in default arguments and 
default
+  member initializers are diagnosed when and if the default is used.
+  This Fixes `Issue 56379 `_
+  and changes the value of ``std::source_location::current()``
+  used in default parameters calls compared to previous versions of Clang.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index c2f6751d62ede..a0bdf50f57ac0 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1244,8 +1244,12 @@ class CXXThrowExpr : public Expr {
 /// This wraps up a function call argument that was created from the
 /// corresponding parameter's default argument, when the call did not
 /// explicitly supply arguments for all of the parameters.
-class CXXDefaultArgExpr final : public Expr {
+class CXXDefaultArgExpr final
+: public Expr,
+  private llvm::TrailingObjects {
   friend class ASTStmtReader;
+  friend class ASTReader;
+  friend TrailingObjects;
 
   /// The parameter whose default is being used.
   ParmVarDecl *Param;
@@ -1254,7 +1258,7 @@ class CXXDefaultArgExpr final : public Expr {
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-DeclContext *UsedContext)
+Expr *RewrittenExpr, DeclContext *UsedContext)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1263,28 +1267,54 @@ class CXXDefaultArgExpr final : public Expr {
  Param->getDefaultArg()->getObjectKind()),
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
+CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
+if (RewrittenExpr)
+  *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
+  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
+  : Expr(CXXDefaultArgExprClass, Empty) {
+

[PATCH] D141218: [clangd] Include the correct header for typeid()

2023-01-08 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Fixes https://github.com/clangd/clangd/issues/1449


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141218

Files:
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1528,6 +1528,24 @@
   "Include \"foo.h\" for symbol foo");
 }
 
+TEST(IncludeFixerTest, Typeid) {
+  Annotations Test(R"cpp(
+$insert[[]]void func() {
+  [[typeid]](int); // error-ok
+}
+  )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  auto Index = buildIndexWithSymbol({});
+  TU.ExternalIndex = Index.get();
+  EXPECT_THAT(
+  *TU.build().getDiagnostics(),
+  ElementsAre(AllOf(
+  Diag(Test.range(), "you need to include  before using "
+ "the 'typeid' operator"),
+  withFix(Fix(Test.range("insert"), "#include \n",
+  "Include ");
+}
+
 TEST(DiagsInHeaders, DiagInsideHeader) {
   Annotations Main(R"cpp(
 #include [["a.h"]]
Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -225,7 +225,7 @@
   case diag::err_implied_std_initializer_list_not_found:
 return only(insertHeader(""));
   case diag::err_need_header_before_typeid:
-return only(insertHeader(""));
+return only(insertHeader(""));
   case diag::err_need_header_before_placement_new:
   case diag::err_implicit_coroutine_std_nothrow_type_not_found:
 return only(insertHeader(""));


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1528,6 +1528,24 @@
   "Include \"foo.h\" for symbol foo");
 }
 
+TEST(IncludeFixerTest, Typeid) {
+  Annotations Test(R"cpp(
+$insert[[]]void func() {
+  [[typeid]](int); // error-ok
+}
+  )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  auto Index = buildIndexWithSymbol({});
+  TU.ExternalIndex = Index.get();
+  EXPECT_THAT(
+  *TU.build().getDiagnostics(),
+  ElementsAre(AllOf(
+  Diag(Test.range(), "you need to include  before using "
+ "the 'typeid' operator"),
+  withFix(Fix(Test.range("insert"), "#include \n",
+  "Include ");
+}
+
 TEST(DiagsInHeaders, DiagInsideHeader) {
   Annotations Main(R"cpp(
 #include [["a.h"]]
Index: clang-tools-extra/clangd/IncludeFixer.cpp
===
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ clang-tools-extra/clangd/IncludeFixer.cpp
@@ -225,7 +225,7 @@
   case diag::err_implied_std_initializer_list_not_found:
 return only(insertHeader(""));
   case diag::err_need_header_before_typeid:
-return only(insertHeader(""));
+return only(insertHeader(""));
   case diag::err_need_header_before_placement_new:
   case diag::err_implicit_coroutine_std_nothrow_type_not_found:
 return only(insertHeader(""));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits