[clang] [clang-format] Handle C-style cast of member function pointer type (PR #126340)

2025-02-09 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Handle C-style cast of member function pointer type (PR #126340)

2025-02-09 Thread Owen Pan via cfe-commits

owenca wrote:

/cherry-pick 8d373ceaec1f1b27c9e682cfaf71aae19ea48d98

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


[clang] [clang-format] Handle C-style cast of member function pointer type (PR #126340)

2025-02-09 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#126479

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


[clang] [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading (PR #125646)

2025-02-09 Thread Aniket Lal via cfe-commits

https://github.com/lalaniket8 updated 
https://github.com/llvm/llvm-project/pull/125646

>From 7be637fa9fcde8977f650e208c7ddc1495080941 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Tue, 4 Feb 2025 12:13:20 +0530
Subject: [PATCH 1/3] [Driver][HIP] Do not pass -dependency-file flag for HIP
 Device offloading

When we launch hipcc with multiple offload architectures along with -MF 
dep_file flag, the clang compilation invocations for host and device offloads 
write to the same dep_file, and can lead to collision during file IO 
operations. This can typically happen during large workloads.
This commit provides a fix to generate dep_file only in host compilation.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 30 ++-
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0a6756eadba317b..66acd2f7b91a577 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1013,21 +1013,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 ArgM = ArgMD;
 
   if (ArgM) {
-// Determine the output location.
-const char *DepFile;
-if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
-  DepFile = MF->getValue();
-  C.addFailureResultFile(DepFile, &JA);
-} else if (Output.getType() == types::TY_Dependencies) {
-  DepFile = Output.getFilename();
-} else if (!ArgMD) {
-  DepFile = "-";
-} else {
-  DepFile = getDependencyFileName(Args, Inputs);
-  C.addFailureResultFile(DepFile, &JA);
+if (!JA.isDeviceOffloading(Action::OFK_HIP)) {
+  // Determine the output location.
+  const char *DepFile;
+  if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
+DepFile = MF->getValue();
+C.addFailureResultFile(DepFile, &JA);
+  } else if (Output.getType() == types::TY_Dependencies) {
+DepFile = Output.getFilename();
+  } else if (!ArgMD) {
+DepFile = "-";
+  } else {
+DepFile = getDependencyFileName(Args, Inputs);
+C.addFailureResultFile(DepFile, &JA);
+  }
+  CmdArgs.push_back("-dependency-file");
+  CmdArgs.push_back(DepFile);
 }
-CmdArgs.push_back("-dependency-file");
-CmdArgs.push_back(DepFile);
 
 bool HasTarget = false;
 for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {

>From 5c52e3a065d0c6e3bf59c450102ae95595ed5b10 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Wed, 5 Feb 2025 14:49:50 +0530
Subject: [PATCH 2/3] Adding littest

---
 .../dep-file-flag-with-multiple-offload-archs.hip   | 13 +
 1 file changed, 13 insertions(+)
 create mode 100644 
clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip

diff --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip 
b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
new file mode 100644
index 000..9dd4b6a4601a01e
--- /dev/null
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -0,0 +1,13 @@
+// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s
+
+// CHECK: Build config:
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1030"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1100"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1100"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1101"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1101"
+// CHECK: {{.*}}clang-offload-bundler
+// CHECK: {{.*}}clang{{.*}}"-target-cpu" "x86-64"{{.*}}"-dependency-file" 
"tmp.d"
+
+void main(){}

>From 03eec5d1d888923a34c6afb970f1f18ee23b9c64 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Mon, 10 Feb 2025 13:22:02 +0530
Subject: [PATCH 3/3] Added nogpuinc nogpulib flags

---
 clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip 
b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
index 9dd4b6a4601a01e..d26faf7242f915d 100644
--- a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -1,4 +1,4 @@
-// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s
+// RUN: %clang -### -nogpuinc -nogpulib --offload-arch=gfx1030 
--offload-arch=gfx1100 --offload-arch=gfx1101 -MD -MF tmp.d %s 2>&1 | FileCheck 
%s
 
 // CHECK: Build config:
 // CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" 
"tmp.d"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.ll

[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)

2025-02-09 Thread Nikolaos Chatzikonstantinou via cfe-commits

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


[clang] [BoundsSafety][doc] Fix a typo (PR #126247)

2025-02-09 Thread via cfe-commits

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


[clang] [BoundsSafety][doc] Fix a typo (PR #126247)

2025-02-09 Thread via cfe-commits

https://github.com/hstk30-hw approved this pull request.


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


[clang] 3a66eba - [BoundsSafety][doc] Fix a typo (#126247)

2025-02-09 Thread via cfe-commits

Author: Piotr Fusik
Date: 2025-02-10T15:55:27+08:00
New Revision: 3a66ebae06d72d500c52413b9b189e95762e01b3

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

LOG: [BoundsSafety][doc] Fix a typo (#126247)

Added: 


Modified: 
clang/docs/BoundsSafety.rst
clang/docs/BoundsSafetyImplPlans.rst

Removed: 




diff  --git a/clang/docs/BoundsSafety.rst b/clang/docs/BoundsSafety.rst
index 8635bec6e17c73a..cf5b0c75c0387d9 100644
--- a/clang/docs/BoundsSafety.rst
+++ b/clang/docs/BoundsSafety.rst
@@ -777,13 +777,13 @@ the transformed pseudo code of function ``alloc_buf()`` 
in the example below.
   size_t count;
} sized_buf_t;
 
-   void alloc_buf(sized_buf_t *sbuf, sized_t nelems) {
+   void alloc_buf(sized_buf_t *sbuf, size_t nelems) {
   sbuf->buf = (int *)malloc(sizeof(int) * nelems);
   sbuf->count = nelems;
}
 
// Transformed pseudo code:
-   void alloc_buf(sized_buf_t *sbuf, sized_t nelems) {
+   void alloc_buf(sized_buf_t *sbuf, size_t nelems) {
   // Materialize RHS values:
   int *tmp_ptr = (int *)malloc(sizeof(int) * nelems);
   int tmp_count = nelems;

diff  --git a/clang/docs/BoundsSafetyImplPlans.rst 
b/clang/docs/BoundsSafetyImplPlans.rst
index 93c2ed7b4340295..34276c920f31e2a 100644
--- a/clang/docs/BoundsSafetyImplPlans.rst
+++ b/clang/docs/BoundsSafetyImplPlans.rst
@@ -134,7 +134,7 @@ same basic block and without side effect in between.
   int *__counted_by(count) buf; size_t count;
} sized_buf_t;
 
-   void alloc_buf(sized_buf_t *sbuf, sized_t nelems) {
+   void alloc_buf(sized_buf_t *sbuf, size_t nelems) {
   sbuf->buf = (int *)malloc(sizeof(int) * nelems);
   sbuf->count = nelems;
}



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


[clang] [Clang][NFC] Add test for CWG2285 "Issues with structured bindings" (PR #126421)

2025-02-09 Thread Vlad Serebrennikov via cfe-commits


@@ -196,6 +196,16 @@ void g() {
 #endif
 } // namespace cwg2277
 
+namespace cwg2285 { // cwg2285: 4

Endilll wrote:

It seems that Clang 5 was the first release which exhibits the correct 
behavior: https://godbolt.org/z/qabGrdvPq

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


[clang] [llvm] [OpenMP] Remove 'libomptarget.devicertl.a' fatbinary and use static library (PR #126143)

2025-02-09 Thread Shilei Tian via cfe-commits

shiltian wrote:

> We already have a host-side libomptarget:

+1, though as @jhuber6 mentioned, we did name it prefix with 
`libomptarget-nvptx64` or `libomptarget-amdgcn` before. I think this is a great 
opportunity to make it more appropriate. However, I don't have strong opinion 
against it.

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


[clang] [llvm] [OpenMP] Remove 'libomptarget.devicertl.a' fatbinary and use static library (PR #126143)

2025-02-09 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> > We already have a host-side libomptarget:
> 
> +1, though as @jhuber6 mentioned, we did name it prefix with 
> `libomptarget-nvptx64` or `libomptarget-amdgcn` before. I think this is a 
> great opportunity to make it more appropriate. However, I don't have strong 
> opinion against it.

It's called `libompdevice.a` now.

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


[clang] [Serialization] Avoid repeated hash lookups (NFC) (PR #126429)

2025-02-09 Thread Nikita Popov via cfe-commits

https://github.com/nikic approved this pull request.


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


[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #126428)

2025-02-09 Thread Nikita Popov via cfe-commits

https://github.com/nikic approved this pull request.


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


[clang] [llvm] [AArch64][SelectionDAG] Add CodeGen support for scalar FEAT_CPA (PR #105669)

2025-02-09 Thread David Green via cfe-commits


@@ -401,7 +401,7 @@ def tblockaddress: SDNode<"ISD::TargetBlockAddress",  
SDTPtrLeaf, [],
 
 def add: SDNode<"ISD::ADD"   , SDTIntBinOp   ,
 [SDNPCommutative, SDNPAssociative]>;
-def ptradd : SDNode<"ISD::ADD"   , SDTPtrAddOp, []>;
+def ptradd : SDNode<"ISD::PTRADD", SDTPtrAddOp, []>;

davemgreen wrote:

It would be good to update the existing uses. If the AMD ptradd line is 
unnecessary, then removing it should not be a problem. It looks like it might 
be used for gisel at the moment though?

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


[clang-tools-extra] [clang-tidy] add new modernize-use-scoped-lock check (PR #126434)

2025-02-09 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor created 
https://github.com/llvm/llvm-project/pull/126434

Add new clang-tidy that finds uses of `std::lock_guard` and suggests replacing 
them with C++17's more flexible and safer alternative `std::scoped_lock`.

Here is a small description of how it works for better understanding of the 
code:
Two separate AST matchers are registered:

- The first one matches declarations of `std::lock_guard` that are single in 
their scope (only one `std::lock_guard` in `CompoundStmt`). It's an easy case, 
we can emit warning right away.

- The second one matches `CompoundStmt`'s that have multiple `std::lock_guard` 
declarations, which means that we may have consecutive declarations of 
`std::lock_guard` that can be replaced by a single `std::scoped_lock`. In order 
to ensure that declarations are consecutive, we need to loop over `Stmt`'s in 
`CompoundStmt`. Here is a small example:
```cpp
{
  std::mutex m1, m2;
  std::lock(m1, m2);
  std::lock_guard l1(m, std::adopt_lock); // first declaration of 
'std::lock_guard'
  std::lock_guard l2(m, std::adopt_lock); // second declaration of 
'std::lock_guard' that can be merged with first using 'scoped_lock'
}
```

If there is an easier way to find consecutive declarations of `std::lock_guard` 
in AST matchers, I'm happy to learn and adjust my code.

This PR closes https://github.com/llvm/llvm-project/issues/107839.

>From 92588a7eb3f87e74887e94f88d3402ec25c6ee53 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Sun, 9 Feb 2025 22:34:26 +0300
Subject: [PATCH] [clang-tidy] add modernize-use-scoped-lock check

---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseScopedLockCheck.cpp  | 234 ++
 .../clang-tidy/modernize/UseScopedLockCheck.h |  50 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-scoped-lock.rst  |  81 +
 .../use-scoped-lock-only-warn-on-multiple.cpp | 122 
 .../checkers/modernize/use-scoped-lock.cpp| 290 ++
 9 files changed, 788 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-scoped-lock.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-scoped-lock-only-warn-on-multiple.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-scoped-lock.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index bab1167fb15ff20..619a27b2f9bb6b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangTidyModernizeModule STATIC
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseRangesCheck.cpp
+  UseScopedLockCheck.cpp
   UseStartsEndsWithCheck.cpp
   UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index fc46c72982fdce8..b2d4ddd6675022a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -43,6 +43,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseRangesCheck.h"
+#include "UseScopedLockCheck.h"
 #include "UseStartsEndsWithCheck.h"
 #include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
@@ -80,6 +81,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "modernize-use-integer-sign-comparison");
 CheckFactories.registerCheck("modernize-use-ranges");
+CheckFactories.registerCheck(
+"modernize-use-scoped-lock");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 
CheckFactories.registerCheck("modernize-use-std-format");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
new file mode 100644
index 000..af2fea5ad310e6d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
@@ -0,0 +1,234 @@
+//===--- UseScopedLockCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseScopedLockCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/

[clang-tools-extra] [clang-tidy] add new modernize-use-scoped-lock check (PR #126434)

2025-02-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Baranov Victor (vbvictor)


Changes

Add new clang-tidy that finds uses of `std::lock_guard` and suggests replacing 
them with C++17's more flexible and safer alternative `std::scoped_lock`.

Here is a small description of how it works for better understanding of the 
code:
Two separate AST matchers are registered:

- The first one matches declarations of `std::lock_guard` that are single in 
their scope (only one `std::lock_guard` in `CompoundStmt`). It's an easy case, 
we can emit warning right away.

- The second one matches `CompoundStmt`'s that have multiple `std::lock_guard` 
declarations, which means that we may have consecutive declarations of 
`std::lock_guard` that can be replaced by a single `std::scoped_lock`. In order 
to ensure that declarations are consecutive, we need to loop over `Stmt`'s in 
`CompoundStmt`. Here is a small example:
```cpp
{
  std::mutex m1, m2;
  std::lock(m1, m2);
  std::lock_guard l1(m, std::adopt_lock); // first 
declaration of 'std::lock_guard'
  std::lock_guard l2(m, std::adopt_lock); // second 
declaration of 'std::lock_guard' that can be merged with first using 
'scoped_lock'
}
```

If there is an easier way to find consecutive declarations of `std::lock_guard` 
in AST matchers, I'm happy to learn and adjust my code.

This PR closes https://github.com/llvm/llvm-project/issues/107839.

---

Patch is 29.95 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/126434.diff


9 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/CMakeLists.txt (+1) 
- (modified) clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
(+3) 
- (added) clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp (+234) 
- (added) clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.h (+50) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-scoped-lock.rst (+81) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-scoped-lock-only-warn-on-multiple.cpp
 (+122) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-scoped-lock.cpp (+290) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index bab1167fb15ff20..619a27b2f9bb6b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangTidyModernizeModule STATIC
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseRangesCheck.cpp
+  UseScopedLockCheck.cpp
   UseStartsEndsWithCheck.cpp
   UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index fc46c72982fdce8..b2d4ddd6675022a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -43,6 +43,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseRangesCheck.h"
+#include "UseScopedLockCheck.h"
 #include "UseStartsEndsWithCheck.h"
 #include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
@@ -80,6 +81,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "modernize-use-integer-sign-comparison");
 CheckFactories.registerCheck("modernize-use-ranges");
+CheckFactories.registerCheck(
+"modernize-use-scoped-lock");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 
CheckFactories.registerCheck("modernize-use-std-format");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
new file mode 100644
index 000..af2fea5ad310e6d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
@@ -0,0 +1,234 @@
+//===--- UseScopedLockCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseScopedLockCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/Twine.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+

[clang-tools-extra] [clang-tidy] add new modernize-use-scoped-lock check (PR #126434)

2025-02-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Baranov Victor (vbvictor)


Changes

Add new clang-tidy that finds uses of `std::lock_guard` and suggests replacing 
them with C++17's more flexible and safer alternative `std::scoped_lock`.

Here is a small description of how it works for better understanding of the 
code:
Two separate AST matchers are registered:

- The first one matches declarations of `std::lock_guard` that are single in 
their scope (only one `std::lock_guard` in `CompoundStmt`). It's an easy case, 
we can emit warning right away.

- The second one matches `CompoundStmt`'s that have multiple `std::lock_guard` 
declarations, which means that we may have consecutive declarations of 
`std::lock_guard` that can be replaced by a single `std::scoped_lock`. In order 
to ensure that declarations are consecutive, we need to loop over `Stmt`'s in 
`CompoundStmt`. Here is a small example:
```cpp
{
  std::mutex m1, m2;
  std::lock(m1, m2);
  std::lock_guard l1(m, std::adopt_lock); // first 
declaration of 'std::lock_guard'
  std::lock_guard l2(m, std::adopt_lock); // second 
declaration of 'std::lock_guard' that can be merged with first using 
'scoped_lock'
}
```

If there is an easier way to find consecutive declarations of `std::lock_guard` 
in AST matchers, I'm happy to learn and adjust my code.

This PR closes https://github.com/llvm/llvm-project/issues/107839.

---

Patch is 29.95 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/126434.diff


9 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/CMakeLists.txt (+1) 
- (modified) clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
(+3) 
- (added) clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp (+234) 
- (added) clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.h (+50) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-scoped-lock.rst (+81) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-scoped-lock-only-warn-on-multiple.cpp
 (+122) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-scoped-lock.cpp (+290) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index bab1167fb15ff20..619a27b2f9bb6b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangTidyModernizeModule STATIC
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseRangesCheck.cpp
+  UseScopedLockCheck.cpp
   UseStartsEndsWithCheck.cpp
   UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index fc46c72982fdce8..b2d4ddd6675022a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -43,6 +43,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseRangesCheck.h"
+#include "UseScopedLockCheck.h"
 #include "UseStartsEndsWithCheck.h"
 #include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
@@ -80,6 +81,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "modernize-use-integer-sign-comparison");
 CheckFactories.registerCheck("modernize-use-ranges");
+CheckFactories.registerCheck(
+"modernize-use-scoped-lock");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 
CheckFactories.registerCheck("modernize-use-std-format");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
new file mode 100644
index 000..af2fea5ad310e6d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
@@ -0,0 +1,234 @@
+//===--- UseScopedLockCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseScopedLockCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/Twine.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namesp

[clang] f6f0526 - [Sema] Avoid repeated hash lookups (NFC) (#126428)

2025-02-09 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-02-09T13:33:03-08:00
New Revision: f6f052625e77632bb672c5ea40d414f0f33fd5b1

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

LOG: [Sema] Avoid repeated hash lookups (NFC) (#126428)

Added: 


Modified: 
clang/lib/Sema/JumpDiagnostics.cpp

Removed: 




diff  --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index 4b92d67e49d7d73..ffbb9bc0bfe7cd0 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -786,8 +786,7 @@ void JumpScopeChecker::VerifyIndirectJumps() {
 if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(TheLabel->getStmt(
   continue;
 unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt()];
-if (!TargetScopes.contains(LabelScope))
-  TargetScopes[LabelScope] = TheLabel;
+TargetScopes.try_emplace(LabelScope, TheLabel);
   }
 
   // For each target scope, make sure it's trivially reachable from



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


[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #126428)

2025-02-09 Thread Kazu Hirata via cfe-commits

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


[clang] b48b422 - [Serialization] Avoid repeated hash lookups (NFC) (#126429)

2025-02-09 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-02-09T13:33:46-08:00
New Revision: b48b422c08e85e6afd39aea7341fdf08d07d3e08

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

LOG: [Serialization] Avoid repeated hash lookups (NFC) (#126429)

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index b74bd586e74d7a9..3c64b67503195c3 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -645,10 +645,11 @@ collectMacroDefinitions(const PreprocessorOptions &PPOpts,
 
 // For an #undef'd macro, we only care about the name.
 if (IsUndef) {
-  if (MacroNames && !Macros.count(MacroName))
+  auto [It, Inserted] = Macros.try_emplace(MacroName);
+  if (MacroNames && Inserted)
 MacroNames->push_back(MacroName);
 
-  Macros[MacroName] = std::make_pair("", true);
+  It->second = std::make_pair("", true);
   continue;
 }
 
@@ -661,9 +662,10 @@ collectMacroDefinitions(const PreprocessorOptions &PPOpts,
   MacroBody = MacroBody.substr(0, End);
 }
 
-if (MacroNames && !Macros.count(MacroName))
+auto [It, Inserted] = Macros.try_emplace(MacroName);
+if (MacroNames && Inserted)
   MacroNames->push_back(MacroName);
-Macros[MacroName] = std::make_pair(MacroBody, false);
+It->second = std::make_pair(MacroBody, false);
   }
 }
 



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


[clang-tools-extra] [clang-tidy] add new check: modernize-use-scoped-lock (PR #126434)

2025-02-09 Thread Baranov Victor via cfe-commits

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


[clang] [llvm] [AArch64][SelectionDAG] Add CodeGen support for scalar FEAT_CPA (PR #105669)

2025-02-09 Thread David Green via cfe-commits


@@ -0,0 +1,451 @@
+; RUN: llc -mtriple=aarch64 -verify-machineinstrs --mattr=+cpa -O0 
-global-isel=0 -fast-isel=0 %s -o - 2>&1 | FileCheck %s 
--check-prefixes=CHECK-CPA-O0
+; RUN: llc -mtriple=aarch64 -verify-machineinstrs --mattr=+cpa -O3 
-global-isel=0 -fast-isel=0 %s -o - 2>&1 | FileCheck %s 
--check-prefixes=CHECK-CPA-O3
+; RUN: llc -mtriple=aarch64 -verify-machineinstrs --mattr=-cpa -O0 
-global-isel=0 -fast-isel=0 %s -o - 2>&1 | FileCheck %s 
--check-prefixes=CHECK-NOCPA-O0
+; RUN: llc -mtriple=aarch64 -verify-machineinstrs --mattr=-cpa -O3 
-global-isel=0 -fast-isel=0 %s -o - 2>&1 | FileCheck %s 
--check-prefixes=CHECK-NOCPA-O3
+
+%struct.my_type = type { i64, i64 }
+%struct.my_type2 = type { i64, i64, i64, i64, i64, i64 }
+
+@array = external dso_local global [10 x %struct.my_type], align 8
+@array2 = external dso_local global [10 x %struct.my_type2], align 8
+
+define void @addpt1(i64 %index, i64 %arg) {
+; CHECK-CPA-O0-LABEL:addpt1:

davemgreen wrote:

It helps keep the tests regular and easier to maintain. (If you don't do it 
now, someone will likely regenerate them in the future if they change). You 
might be able to use --check-prefixes=CHECK-CPA,CHECK-CPA-O0 if we expect the 
O0 and O3 codegen to be the same in some tests.

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


[clang] [compiler-rt] [rtsan] Enable RealtimeSanitizer for FreeBSD (PR #125389)

2025-02-09 Thread David CARLIER via cfe-commits


@@ -864,11 +864,18 @@ INTERCEPTOR(void *, pvalloc, size_t size) {
 #define RTSAN_MAYBE_INTERCEPT_PVALLOC
 #endif
 
+#if !SANITIZER_FREEBSD
+// enabling this interception on freebsd leads to infinite recursion
+// on pthread lib initialization

devnexen wrote:

![image](https://github.com/user-attachments/assets/3665d61a-ad9c-4d7d-b617-aac6b639c4c7)


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


[clang] [Analyzer][CFG] Correctly handle rebuilt default arg and default init expression (PR #117437)

2025-02-09 Thread via cfe-commits

yronglin wrote:

Thanks for reporting this bug, I'll take a look.

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


[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)

2025-02-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ryosuke Niwa (rniwa)


Changes

In WebKit, it's pretty common to capture "this" and "protectedThis" where 
"protectedThis" is a guardian variable of type Ref or RefPtr for "this". 
Furthermore, it's common for this "protectedThis" variable from being passed to 
an inner lambda by std::move. Recognize this pattern so that we don't emit 
warnings for nested inner lambdas.

To recognize this pattern, we introduce a new DenseSet, ProtectedThisDecls, 
which contains every "protectedThis" we've recognized to our subclass of 
DynamicRecursiveASTVisitor. This set is now populated in "hasProtectedThis" and 
"declProtectsThis" uses this DenseSet to determine a given value declaration 
constitutes a "protectedThis" pattern or not.

Because hasProtectedThis and declProtectsThis had to be moved from the checker 
class to the visitor class, it's now a responsibility of each caller of 
visitLambdaExpr to check whether a given lambda captures "this" without a 
"protectedThis" or not.

Finally, this PR improves the code to recognize "protectedThis" pattern by 
allowing more nested CXXBindTemporaryExpr, CXXOperatorCallExpr, and 
UnaryOperator expressions.

---
Full diff: https://github.com/llvm/llvm-project/pull/126443.diff


2 Files Affected:

- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
(+71-47) 
- (modified) clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp 
(+24) 


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index a56f48c83c660a9..c0a9e38b6aab41b 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -41,6 +41,7 @@ class UncountedLambdaCapturesChecker
   const UncountedLambdaCapturesChecker *Checker;
   llvm::DenseSet DeclRefExprsToIgnore;
   llvm::DenseSet LambdasToIgnore;
+  llvm::DenseSet ProtectedThisDecls;
   QualType ClsType;
 
   explicit LocalVisitor(const UncountedLambdaCapturesChecker *Checker)
@@ -65,7 +66,7 @@ class UncountedLambdaCapturesChecker
   bool VisitLambdaExpr(LambdaExpr *L) override {
 if (LambdasToIgnore.contains(L))
   return true;
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L));
 return true;
   }
 
@@ -93,7 +94,7 @@ class UncountedLambdaCapturesChecker
 if (!L)
   return true;
 LambdasToIgnore.insert(L);
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L));
 return true;
   }
 
@@ -118,7 +119,8 @@ class UncountedLambdaCapturesChecker
 if (auto *L = findLambdaInArg(Arg)) {
   LambdasToIgnore.insert(L);
   if (!Param->hasAttr() && !TreatAllArgsAsNoEscape)
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() &&
+!hasProtectedThis(L));
 }
 ++ArgIndex;
   }
@@ -145,6 +147,11 @@ class UncountedLambdaCapturesChecker
   return nullptr;
 if (auto *Lambda = dyn_cast(CtorArg))
   return Lambda;
+if (auto *TempExpr = dyn_cast(CtorArg)) {
+  E = TempExpr->getSubExpr()->IgnoreParenCasts();
+  if (auto *Lambda = dyn_cast(E))
+return Lambda;
+}
 auto *DRE = dyn_cast(CtorArg);
 if (!DRE)
   return nullptr;
@@ -189,9 +196,68 @@ class UncountedLambdaCapturesChecker
   return;
 DeclRefExprsToIgnore.insert(ArgRef);
 LambdasToIgnore.insert(L);
-Checker->visitLambdaExpr(L, shouldCheckThis(),
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L),
  /* ignoreParamVarDecl */ true);
   }
+
+  bool hasProtectedThis(LambdaExpr *L) {
+for (const LambdaCapture &OtherCapture : L->captures()) {
+  if (!OtherCapture.capturesVariable())
+continue;
+  if (auto *ValueDecl = OtherCapture.getCapturedVar()) {
+if (declProtectsThis(ValueDecl)) {
+  ProtectedThisDecls.insert(ValueDecl);
+  return true;
+}
+  }
+}
+return false;
+  }
+
+  bool declProtectsThis(const ValueDecl *ValueDecl) const {
+auto *VD = dyn_cast(ValueDecl);
+if (!VD)
+  return false;
+auto *Init = VD->getInit()->IgnoreParenCasts();
+if (!Init)
+  return false;
+const Expr *Arg = Init;
+do {
+  if (auto *BTE = dyn_cast(Arg))
+Arg = BTE->getSubExpr()->

[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)

2025-02-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

In WebKit, it's pretty common to capture "this" and "protectedThis" where 
"protectedThis" is a guardian variable of type Ref or RefPtr for "this". 
Furthermore, it's common for this "protectedThis" variable from being passed to 
an inner lambda by std::move. Recognize this pattern so that we don't emit 
warnings for nested inner lambdas.

To recognize this pattern, we introduce a new DenseSet, ProtectedThisDecls, 
which contains every "protectedThis" we've recognized to our subclass of 
DynamicRecursiveASTVisitor. This set is now populated in "hasProtectedThis" and 
"declProtectsThis" uses this DenseSet to determine a given value declaration 
constitutes a "protectedThis" pattern or not.

Because hasProtectedThis and declProtectsThis had to be moved from the checker 
class to the visitor class, it's now a responsibility of each caller of 
visitLambdaExpr to check whether a given lambda captures "this" without a 
"protectedThis" or not.

Finally, this PR improves the code to recognize "protectedThis" pattern by 
allowing more nested CXXBindTemporaryExpr, CXXOperatorCallExpr, and 
UnaryOperator expressions.

---
Full diff: https://github.com/llvm/llvm-project/pull/126443.diff


2 Files Affected:

- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
(+71-47) 
- (modified) clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp 
(+24) 


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index a56f48c83c660a9..c0a9e38b6aab41b 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -41,6 +41,7 @@ class UncountedLambdaCapturesChecker
   const UncountedLambdaCapturesChecker *Checker;
   llvm::DenseSet DeclRefExprsToIgnore;
   llvm::DenseSet LambdasToIgnore;
+  llvm::DenseSet ProtectedThisDecls;
   QualType ClsType;
 
   explicit LocalVisitor(const UncountedLambdaCapturesChecker *Checker)
@@ -65,7 +66,7 @@ class UncountedLambdaCapturesChecker
   bool VisitLambdaExpr(LambdaExpr *L) override {
 if (LambdasToIgnore.contains(L))
   return true;
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L));
 return true;
   }
 
@@ -93,7 +94,7 @@ class UncountedLambdaCapturesChecker
 if (!L)
   return true;
 LambdasToIgnore.insert(L);
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L));
 return true;
   }
 
@@ -118,7 +119,8 @@ class UncountedLambdaCapturesChecker
 if (auto *L = findLambdaInArg(Arg)) {
   LambdasToIgnore.insert(L);
   if (!Param->hasAttr() && !TreatAllArgsAsNoEscape)
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() &&
+!hasProtectedThis(L));
 }
 ++ArgIndex;
   }
@@ -145,6 +147,11 @@ class UncountedLambdaCapturesChecker
   return nullptr;
 if (auto *Lambda = dyn_cast(CtorArg))
   return Lambda;
+if (auto *TempExpr = dyn_cast(CtorArg)) {
+  E = TempExpr->getSubExpr()->IgnoreParenCasts();
+  if (auto *Lambda = dyn_cast(E))
+return Lambda;
+}
 auto *DRE = dyn_cast(CtorArg);
 if (!DRE)
   return nullptr;
@@ -189,9 +196,68 @@ class UncountedLambdaCapturesChecker
   return;
 DeclRefExprsToIgnore.insert(ArgRef);
 LambdasToIgnore.insert(L);
-Checker->visitLambdaExpr(L, shouldCheckThis(),
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L),
  /* ignoreParamVarDecl */ true);
   }
+
+  bool hasProtectedThis(LambdaExpr *L) {
+for (const LambdaCapture &OtherCapture : L->captures()) {
+  if (!OtherCapture.capturesVariable())
+continue;
+  if (auto *ValueDecl = OtherCapture.getCapturedVar()) {
+if (declProtectsThis(ValueDecl)) {
+  ProtectedThisDecls.insert(ValueDecl);
+  return true;
+}
+  }
+}
+return false;
+  }
+
+  bool declProtectsThis(const ValueDecl *ValueDecl) const {
+auto *VD = dyn_cast(ValueDecl);
+if (!VD)
+  return false;
+auto *Init = VD->getInit()->IgnoreParenCasts();
+if (!Init)
+  return false;
+const Expr *Arg = Init;
+do {
+  if (auto *BTE = dyn_cast(Arg))
+Arg = BTE->getSubExpr()->IgnoreParenCasts()

[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)

2025-02-09 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created 
https://github.com/llvm/llvm-project/pull/126443

In WebKit, it's pretty common to capture "this" and "protectedThis" where 
"protectedThis" is a guardian variable of type Ref or RefPtr for "this". 
Furthermore, it's common for this "protectedThis" variable from being passed to 
an inner lambda by std::move. Recognize this pattern so that we don't emit 
warnings for nested inner lambdas.

To recognize this pattern, we introduce a new DenseSet, ProtectedThisDecls, 
which contains every "protectedThis" we've recognized to our subclass of 
DynamicRecursiveASTVisitor. This set is now populated in "hasProtectedThis" and 
"declProtectsThis" uses this DenseSet to determine a given value declaration 
constitutes a "protectedThis" pattern or not.

Because hasProtectedThis and declProtectsThis had to be moved from the checker 
class to the visitor class, it's now a responsibility of each caller of 
visitLambdaExpr to check whether a given lambda captures "this" without a 
"protectedThis" or not.

Finally, this PR improves the code to recognize "protectedThis" pattern by 
allowing more nested CXXBindTemporaryExpr, CXXOperatorCallExpr, and 
UnaryOperator expressions.

>From a40e782b866ec4756ddf3f04cc09caff31845ebf Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 9 Feb 2025 13:50:26 -0800
Subject: [PATCH] [webkit.UncountedLambdaCapturesChecker] Recognize nested
 protectedThis pattern

In WebKit, it's pretty common to capture "this" and "protectedThis" where 
"protectedThis" is
a guardian variable of type Ref or RefPtr for "this". Furthermore, it's common 
for this
"protectedThis" variable from being passed to an inner lambda by std::move. 
Recognize this
pattern so that we don't emit warnings for nested inner lambdas.

To recognize this pattern, we introduce a new DenseSet, ProtectedThisDecls, 
which contains
every "protectedThis" we've recognized to our subclass of 
DynamicRecursiveASTVisitor. This
set is now populated in "hasProtectedThis" and "declProtectsThis" uses this 
DenseSet to
determine a given value declaration constitutes a "protectedThis" pattern or 
not.

Because hasProtectedThis and declProtectsThis had to be moved from the checker 
class to
the visitor class, it's now a responsibility of each caller of visitLambdaExpr 
to check
whether a given lambda captures "this" without a "protectedThis" or not.

Finally, this PR improves the code to recognize "protectedThis" pattern by 
allowing more
nested CXXBindTemporaryExpr, CXXOperatorCallExpr, and UnaryOperator expressions.
---
 .../WebKit/UncountedLambdaCapturesChecker.cpp | 118 +++---
 .../WebKit/uncounted-lambda-captures.cpp  |  24 
 2 files changed, 95 insertions(+), 47 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index a56f48c83c660a9..c0a9e38b6aab41b 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -41,6 +41,7 @@ class UncountedLambdaCapturesChecker
   const UncountedLambdaCapturesChecker *Checker;
   llvm::DenseSet DeclRefExprsToIgnore;
   llvm::DenseSet LambdasToIgnore;
+  llvm::DenseSet ProtectedThisDecls;
   QualType ClsType;
 
   explicit LocalVisitor(const UncountedLambdaCapturesChecker *Checker)
@@ -65,7 +66,7 @@ class UncountedLambdaCapturesChecker
   bool VisitLambdaExpr(LambdaExpr *L) override {
 if (LambdasToIgnore.contains(L))
   return true;
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L));
 return true;
   }
 
@@ -93,7 +94,7 @@ class UncountedLambdaCapturesChecker
 if (!L)
   return true;
 LambdasToIgnore.insert(L);
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L));
 return true;
   }
 
@@ -118,7 +119,8 @@ class UncountedLambdaCapturesChecker
 if (auto *L = findLambdaInArg(Arg)) {
   LambdasToIgnore.insert(L);
   if (!Param->hasAttr() && !TreatAllArgsAsNoEscape)
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() &&
+!hasProtectedThis(L));
 }
 ++ArgIndex;
   }
@@ -145,6 +147,11 @@ class UncountedLambdaCapturesChecker
   return nullptr;
 if (auto *Lambda = dyn_cast(CtorArg))
   return Lambda;
+if (auto *TempExpr = dyn_cast(CtorArg)) {
+  E = TempExpr->getSubExpr()->IgnoreParenCasts();
+  if (auto *Lambda = dyn_cast(E))
+return Lambda;
+}
 auto *DRE = dyn_cast(CtorArg);
 if (!DRE)
   

[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)

2025-02-09 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 4d3148d92681c154de51379a0cf393f9af8e1d75 
a40e782b866ec4756ddf3f04cc09caff31845ebf --extensions cpp -- 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
clang/test/Analysis/Checkers/WebKit/uncounted-lambda-captures.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index c0a9e38b6a..e3eeac8b98 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -120,7 +120,7 @@ public:
   LambdasToIgnore.insert(L);
   if (!Param->hasAttr() && !TreatAllArgsAsNoEscape)
 Checker->visitLambdaExpr(L, shouldCheckThis() &&
-!hasProtectedThis(L));
+!hasProtectedThis(L));
 }
 ++ArgIndex;
   }

``




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


[clang] [clang] Force AttributedStmtClass to not be scope parents (PR #125370)

2025-02-09 Thread Yutong Zhu via cfe-commits

https://github.com/YutongZhuu updated 
https://github.com/llvm/llvm-project/pull/125370

>From 380ae2020f71cc5006db2e29b0a69f61297f585c Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sat, 1 Feb 2025 20:09:13 -0500
Subject: [PATCH 1/3] Force AttributedStmtClass to not be scope parents

---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/JumpDiagnostics.cpp  | 17 +++--
 .../stmt.stmt/stmt.select/stmt.switch/p4.cpp| 11 +++
 3 files changed, 20 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4410b9f99e802f7..fc11f213b2be10e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -733,6 +733,8 @@ Improvements to Clang's diagnostics
   scope.Unlock();
   require(scope); // Warning!  Requires mu1.
 }
+
+- Clang now forces attributes to not be scope parents (#84072).
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index d465599450e7ffc..c5577e09a86a1c3 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -597,15 +597,6 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
 LabelAndGotoScopes[S] = ParentScope;
 break;
 
-  case Stmt::AttributedStmtClass: {
-AttributedStmt *AS = cast(S);
-if (GetMustTailAttr(AS)) {
-  LabelAndGotoScopes[AS] = ParentScope;
-  MustTailStmts.push_back(AS);
-}
-break;
-  }
-
   case Stmt::OpenACCComputeConstructClass: {
 unsigned NewParentScope = Scopes.size();
 OpenACCComputeConstruct *CC = cast(S);
@@ -658,7 +649,13 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
 Next = SC->getSubStmt();
   else if (LabelStmt *LS = dyn_cast(SubStmt))
 Next = LS->getSubStmt();
-  else
+  else if (AttributedStmt *AS = dyn_cast(SubStmt)) {
+if (GetMustTailAttr(AS)) {
+  LabelAndGotoScopes[AS] = ParentScope;
+  MustTailStmts.push_back(AS);
+}
+Next = AS->getSubStmt();
+  } else
 break;
 
   LabelAndGotoScopes[SubStmt] = ParentScope;
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
new file mode 100644
index 000..d89dda7215074f7
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang++ -fsyntax-only -std=c++20 -Xclang -verify %s
+
+void Func(int x) {
+switch (x) {
+[[likely]] case 0:
+case 1: 
+int i = 3; // expected-note {{jump bypasses variable 
initialization}}
+case 2: // expected-error {{cannot jump from switch statement to this 
case label}}
+break;
+}
+}

>From a47f6c1710600ece997a435c0ddd05c6935eea97 Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Fri, 7 Feb 2025 22:13:55 -0500
Subject: [PATCH 2/3] Fix test

---
 clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
index d89dda7215074f7..e816da18036943a 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.switch/p4.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang++ -fsyntax-only -std=c++20 -Xclang -verify %s
+// RUN: %clang -fsyntax-only -std=c++20 -Xclang -verify %s
 
 void Func(int x) {
 switch (x) {

>From f654f53a8062fd89a0ddc4998d5131fde71334c0 Mon Sep 17 00:00:00 2001
From: Yutong Zhu <115899167+yutongz...@users.noreply.github.com>
Date: Sun, 9 Feb 2025 20:48:24 -0500
Subject: [PATCH 3/3] Edit comments

---
 clang/lib/Sema/JumpDiagnostics.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index 4d443ce82379966..bac2cf392bfbc11 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -640,7 +640,7 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
   continue;
 }
 
-// Cases, labels, and defaults aren't "scope parents".  It's also
+// Cases, labels, attributes, and defaults aren't "scope parents".  It's 
also
 // important to handle these iteratively instead of recursively in
 // order to avoid blowing out the stack.
 while (true) {

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


[clang-tools-extra] [clang-tidy] Add modernize-nlohmann-json-explicit-conversions check (PR #126425)

2025-02-09 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

I am not sure whether we should accept this kind of "common" used library's 
custom check in clang-tidy.

- powerful and easy used tools which can help lots of C++ dev
- longer CI time
- larger binary size

I think we should a guideline this kind of cases to avoid to waste contributors 
effort. It is frustrating to write code and find out it can't possibly be 
merged.
@PiotrZSL @5chmidti @carlosgalvezp @AaronBallman WDYT?


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


[clang-tools-extra] [clang-tidy] Add performance-redundant-lookup check (PR #125420)

2025-02-09 Thread Kazu Hirata via cfe-commits

kazutakahirata wrote:

@steakhal, I don't meant to delay the landing of this PR, but I just want to 
bring up the following.  I'm wondering if your checker can catch repeated 
lookups within a loop like so:

```
for (int A : Vec)
  Map[Key].push_back(A);
```

in a function that does not reference `Map` anywhere else.  That is, 
statically, there is only one statement doing map lookups, but dynamically, the 
same lookup is repeated over and over.  Thanks!


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


[clang] [clang][ExtractAPI] combine typedef records if the underlying type's name is underscored (PR #125964)

2025-02-09 Thread Pete Lawrence via cfe-commits

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


[clang] [webkit.UncountedLambdaCapturesChecker] Recognize nested protectedThis pattern (PR #126443)

2025-02-09 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated 
https://github.com/llvm/llvm-project/pull/126443

>From a40e782b866ec4756ddf3f04cc09caff31845ebf Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 9 Feb 2025 13:50:26 -0800
Subject: [PATCH 1/2] [webkit.UncountedLambdaCapturesChecker] Recognize nested
 protectedThis pattern

In WebKit, it's pretty common to capture "this" and "protectedThis" where 
"protectedThis" is
a guardian variable of type Ref or RefPtr for "this". Furthermore, it's common 
for this
"protectedThis" variable from being passed to an inner lambda by std::move. 
Recognize this
pattern so that we don't emit warnings for nested inner lambdas.

To recognize this pattern, we introduce a new DenseSet, ProtectedThisDecls, 
which contains
every "protectedThis" we've recognized to our subclass of 
DynamicRecursiveASTVisitor. This
set is now populated in "hasProtectedThis" and "declProtectsThis" uses this 
DenseSet to
determine a given value declaration constitutes a "protectedThis" pattern or 
not.

Because hasProtectedThis and declProtectsThis had to be moved from the checker 
class to
the visitor class, it's now a responsibility of each caller of visitLambdaExpr 
to check
whether a given lambda captures "this" without a "protectedThis" or not.

Finally, this PR improves the code to recognize "protectedThis" pattern by 
allowing more
nested CXXBindTemporaryExpr, CXXOperatorCallExpr, and UnaryOperator expressions.
---
 .../WebKit/UncountedLambdaCapturesChecker.cpp | 118 +++---
 .../WebKit/uncounted-lambda-captures.cpp  |  24 
 2 files changed, 95 insertions(+), 47 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
index a56f48c83c660a9..c0a9e38b6aab41b 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -41,6 +41,7 @@ class UncountedLambdaCapturesChecker
   const UncountedLambdaCapturesChecker *Checker;
   llvm::DenseSet DeclRefExprsToIgnore;
   llvm::DenseSet LambdasToIgnore;
+  llvm::DenseSet ProtectedThisDecls;
   QualType ClsType;
 
   explicit LocalVisitor(const UncountedLambdaCapturesChecker *Checker)
@@ -65,7 +66,7 @@ class UncountedLambdaCapturesChecker
   bool VisitLambdaExpr(LambdaExpr *L) override {
 if (LambdasToIgnore.contains(L))
   return true;
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L));
 return true;
   }
 
@@ -93,7 +94,7 @@ class UncountedLambdaCapturesChecker
 if (!L)
   return true;
 LambdasToIgnore.insert(L);
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L));
 return true;
   }
 
@@ -118,7 +119,8 @@ class UncountedLambdaCapturesChecker
 if (auto *L = findLambdaInArg(Arg)) {
   LambdasToIgnore.insert(L);
   if (!Param->hasAttr() && !TreatAllArgsAsNoEscape)
-Checker->visitLambdaExpr(L, shouldCheckThis());
+Checker->visitLambdaExpr(L, shouldCheckThis() &&
+!hasProtectedThis(L));
 }
 ++ArgIndex;
   }
@@ -145,6 +147,11 @@ class UncountedLambdaCapturesChecker
   return nullptr;
 if (auto *Lambda = dyn_cast(CtorArg))
   return Lambda;
+if (auto *TempExpr = dyn_cast(CtorArg)) {
+  E = TempExpr->getSubExpr()->IgnoreParenCasts();
+  if (auto *Lambda = dyn_cast(E))
+return Lambda;
+}
 auto *DRE = dyn_cast(CtorArg);
 if (!DRE)
   return nullptr;
@@ -189,9 +196,68 @@ class UncountedLambdaCapturesChecker
   return;
 DeclRefExprsToIgnore.insert(ArgRef);
 LambdasToIgnore.insert(L);
-Checker->visitLambdaExpr(L, shouldCheckThis(),
+Checker->visitLambdaExpr(L, shouldCheckThis() && !hasProtectedThis(L),
  /* ignoreParamVarDecl */ true);
   }
+
+  bool hasProtectedThis(LambdaExpr *L) {
+for (const LambdaCapture &OtherCapture : L->captures()) {
+  if (!OtherCapture.capturesVariable())
+continue;
+  if (auto *ValueDecl = OtherCapture.getCapturedVar()) {
+if (declProtectsThis(ValueDecl)) {
+  ProtectedThisDecls.insert(ValueDecl);
+  return true;
+}
+  }
+}
+return false;
+  }
+
+  bool declProtectsThis(const ValueDecl *ValueDecl) const {
+auto *VD = dyn_cast(ValueDecl);
+if (!VD)
+  return false;
+auto *Init = VD->getInit()->IgnoreParenCasts();
+if (!Init)
+  return false;
+const Expr *Arg = In

[clang] 161cfc6 - [AVX10.2] Fix wrong intrinsic names after rename (#126390)

2025-02-09 Thread via cfe-commits

Author: Mikołaj Piróg
Date: 2025-02-10T12:48:02+08:00
New Revision: 161cfc6f39bef8994eb944687033ebd3570196e8

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

LOG: [AVX10.2] Fix wrong intrinsic names after rename  (#126390)

In my previous PR (#123656) to update the names of AVX10.2 intrinsics
and mnemonics, I have erroneously deleted `_ph` from few intrinsics.
This PR corrects this.

Added: 


Modified: 
clang/lib/Headers/avx10_2_512convertintrin.h
clang/lib/Headers/avx10_2convertintrin.h
clang/test/CodeGen/X86/avx10_2_512convert-builtins.c
clang/test/CodeGen/X86/avx10_2convert-builtins.c

Removed: 




diff  --git a/clang/lib/Headers/avx10_2_512convertintrin.h 
b/clang/lib/Headers/avx10_2_512convertintrin.h
index 0b5fca5cda5228f..516ccc68672d636 100644
--- a/clang/lib/Headers/avx10_2_512convertintrin.h
+++ b/clang/lib/Headers/avx10_2_512convertintrin.h
@@ -213,19 +213,19 @@ _mm512_maskz_cvts2ph_hf8(__mmask64 __U, __m512h __A, 
__m512h __B) {
   (__v64qi)(__m512i)_mm512_setzero_si512());
 }
 
-static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_cvthf8(__m256i __A) {
+static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_cvthf8_ph(__m256i __A) {
   return (__m512h)__builtin_ia32_vcvthf8_2ph512_mask(
   (__v32qi)__A, (__v32hf)(__m512h)_mm512_undefined_ph(), (__mmask32)-1);
 }
 
 static __inline__ __m512h __DEFAULT_FN_ATTRS512
-_mm512_mask_cvthf8(__m512h __W, __mmask32 __U, __m256i __A) {
+_mm512_mask_cvthf8_ph(__m512h __W, __mmask32 __U, __m256i __A) {
   return (__m512h)__builtin_ia32_vcvthf8_2ph512_mask(
   (__v32qi)__A, (__v32hf)(__m512h)__W, (__mmask32)__U);
 }
 
 static __inline__ __m512h __DEFAULT_FN_ATTRS512
-_mm512_maskz_cvthf8(__mmask32 __U, __m256i __A) {
+_mm512_maskz_cvthf8_ph(__mmask32 __U, __m256i __A) {
   return (__m512h)__builtin_ia32_vcvthf8_2ph512_mask(
   (__v32qi)__A, (__v32hf)(__m512h)_mm512_setzero_ph(), (__mmask32)__U);
 }

diff  --git a/clang/lib/Headers/avx10_2convertintrin.h 
b/clang/lib/Headers/avx10_2convertintrin.h
index c67a5b890f1957d..c419323910f187a 100644
--- a/clang/lib/Headers/avx10_2convertintrin.h
+++ b/clang/lib/Headers/avx10_2convertintrin.h
@@ -381,37 +381,36 @@ _mm256_maskz_cvts2ph_hf8(__mmask32 __U, __m256h __A, 
__m256h __B) {
   (__v32qi)(__m256i)_mm256_setzero_si256());
 }
 
-static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvthf8(__m128i __A) {
+static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvthf8_ph(__m128i __A) {
   return (__m128h)__builtin_ia32_vcvthf8_2ph128_mask(
   (__v16qi)__A, (__v8hf)(__m128h)_mm_undefined_ph(), (__mmask8)-1);
 }
 
-static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_mask_cvthf8(__m128h __W,
-__mmask8 __U,
-__m128i __A) {
+static __inline__ __m128h __DEFAULT_FN_ATTRS128
+_mm_mask_cvthf8_ph(__m128h __W, __mmask8 __U, __m128i __A) {
   return (__m128h)__builtin_ia32_vcvthf8_2ph128_mask(
   (__v16qi)__A, (__v8hf)(__m128h)__W, (__mmask8)__U);
 }
 
-static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_maskz_cvthf8(__mmask8 __U,
- __m128i __A) {
+static __inline__ __m128h __DEFAULT_FN_ATTRS128
+_mm_maskz_cvthf8_ph(__mmask8 __U, __m128i __A) {
   return (__m128h)__builtin_ia32_vcvthf8_2ph128_mask(
   (__v16qi)__A, (__v8hf)(__m128h)_mm_setzero_ph(), (__mmask8)__U);
 }
 
-static __inline__ __m256h __DEFAULT_FN_ATTRS256 _mm256_cvthf8(__m128i __A) {
+static __inline__ __m256h __DEFAULT_FN_ATTRS256 _mm256_cvthf8_ph(__m128i __A) {
   return (__m256h)__builtin_ia32_vcvthf8_2ph256_mask(
   (__v16qi)__A, (__v16hf)(__m256h)_mm256_undefined_ph(), (__mmask16)-1);
 }
 
 static __inline__ __m256h __DEFAULT_FN_ATTRS256
-_mm256_mask_cvthf8(__m256h __W, __mmask16 __U, __m128i __A) {
+_mm256_mask_cvthf8_ph(__m256h __W, __mmask16 __U, __m128i __A) {
   return (__m256h)__builtin_ia32_vcvthf8_2ph256_mask(
   (__v16qi)__A, (__v16hf)(__m256h)__W, (__mmask16)__U);
 }
 
 static __inline__ __m256h __DEFAULT_FN_ATTRS256
-_mm256_maskz_cvthf8(__mmask16 __U, __m128i __A) {
+_mm256_maskz_cvthf8_ph(__mmask16 __U, __m128i __A) {
   return (__m256h)__builtin_ia32_vcvthf8_2ph256_mask(
   (__v16qi)__A, (__v16hf)(__m256h)_mm256_setzero_ph(), (__mmask16)__U);
 }

diff  --git a/clang/test/CodeGen/X86/avx10_2_512convert-builtins.c 
b/clang/test/CodeGen/X86/avx10_2_512convert-builtins.c
index 22503c640a727f2..dcf7bbc005a7c6c 100644
--- a/clang/test/CodeGen/X86/avx10_2_512convert-builtins.c
+++ b/clang/test/CodeGen/X86/avx10_2_512convert-builtins.c
@@ -201,22 +201,22 @@ __m512i test_mm512_maskz_cvts2ph_hf8(__mmask64 __U, 
__m512h __A, __m512h __B) {
   return _mm512_maskz_cvts2ph_hf8(__U, __A, __B)

[clang] [AVX10.2] Fix wrong intrinsic names after rename (PR #126390)

2025-02-09 Thread Phoebe Wang via cfe-commits

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


[clang] [clang-cl] Accept `cl`-style output arguments (`/Fo`, `-Fo`) for `--fmodule-output` (PR #121046)

2025-02-09 Thread Sharadh Rajaraman via cfe-commits

sharadhr wrote:

A quick bump. I'd like to get this reviewed hopefully in time for the Clang 
20.x release. I think having it in 19.x is a lost battle, it's a bit too late 
for that. 

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


[clang] [Driver][ROCm][OpenMP] Fix default ockl linking for OpenMP. (PR #126186)

2025-02-09 Thread Amit Kumar Pandey via cfe-commits

https://github.com/ampandey-1995 updated 
https://github.com/llvm/llvm-project/pull/126186

>From 666f907b6b1c37d515a72d0bb1278399575db817 Mon Sep 17 00:00:00 2001
From: Amit Pandey 
Date: Fri, 7 Feb 2025 12:11:23 +0530
Subject: [PATCH] [Driver][ROCm][OpenMP] Fix default ockl linking for OpenMP.

ASan gpu runtime (asanrtl.bc) linking is dependent on 'ockl.bc'. Link
'ockl.bc' only when ASan is enabled for openmp amdgpu offloading
application.
---
 clang/lib/Driver/ToolChains/AMDGPU.cpp| 15 +++--
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp  |  2 +-
 .../Driver/amdgpu-openmp-sanitize-options.c   | 55 +--
 clang/test/Driver/hip-sanitize-options.hip|  2 +-
 4 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index e66e5a32e58acdc..202198e96c01278 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -1014,7 +1014,12 @@ RocmInstallationDetector::getCommonBitcodeLibs(
 bool isOpenMP = false) const {
   llvm::SmallVector BCLibs;
 
-  auto GPUSanEnabled = [GPUSan]() { return std::get(GPUSan); };
+  // GPU Sanitizer currently only supports ASan and is enabled through host
+  // ASan.
+  auto GPUSanEnabled = [GPUSan]() {
+return std::get(GPUSan) &&
+   std::get(GPUSan).needsAsanRt();
+  };
   auto AddBCLib = [&](ToolChain::BitCodeLibraryInfo BCLib,
   bool Internalize = true) {
 BCLib.ShouldInternalize = Internalize;
@@ -1022,9 +1027,7 @@ RocmInstallationDetector::getCommonBitcodeLibs(
   };
   auto AddSanBCLibs = [&]() {
 if (GPUSanEnabled()) {
-  auto SanArgs = std::get(GPUSan);
-  if (SanArgs.needsAsanRt())
-AddBCLib(getAsanRTLPath(), false);
+  AddBCLib(getAsanRTLPath(), false);
 }
   };
 
@@ -1066,7 +1069,7 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   // them all?
   std::tuple GPUSan(
   DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
- options::OPT_fno_gpu_sanitize, false),
+ options::OPT_fno_gpu_sanitize, true),
   getSanitizerArgs(DriverArgs));
   bool DAZ = DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
 options::OPT_fno_gpu_flush_denormals_to_zero,
@@ -1099,7 +1102,7 @@ bool AMDGPUToolChain::shouldSkipSanitizeOption(
 return false;
 
   if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
-  options::OPT_fno_gpu_sanitize, false))
+  options::OPT_fno_gpu_sanitize, true))
 return true;
 
   auto &Diags = TC.getDriver().getDiags();
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 00bf9c7338edd11..aba79f5fa6fa7b3 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -68,7 +68,7 @@ llvm::opt::DerivedArgList 
*AMDGPUOpenMPToolChain::TranslateArgs(
 Action::OffloadKind DeviceOffloadKind) const {
   DerivedArgList *DAL =
   HostTC.TranslateArgs(Args, BoundArch, DeviceOffloadKind);
-  if (!DAL)
+  if (!DAL || Args.hasArg(options::OPT_fsanitize_EQ))
 DAL = new DerivedArgList(Args.getBaseArgs());
 
   const OptTable &Opts = getDriver().getOpts();
diff --git a/clang/test/Driver/amdgpu-openmp-sanitize-options.c 
b/clang/test/Driver/amdgpu-openmp-sanitize-options.c
index c28a758bfc0c5e8..3fb864152766674 100644
--- a/clang/test/Driver/amdgpu-openmp-sanitize-options.c
+++ b/clang/test/Driver/amdgpu-openmp-sanitize-options.c
@@ -1,5 +1,3 @@
-// REQUIRES: x86-registered-target, amdgpu-registered-target
-
 // Fail on invalid ROCm Path.
 // RUN:   not %clang -no-canonical-prefixes -### 
--target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ 
-fsanitize=address -fgpu-sanitize -nogpuinc --rocm-path=%S/Inputs/rocm-invalid  
%s 2>&1 \
 // RUN:   | FileCheck --check-prefix=FAIL %s
@@ -13,38 +11,40 @@
 // RUN:   | FileCheck --check-prefix=NOTSUPPORTED %s
 
 // GPU ASan Enabled Test Cases
-// ASan enabled for amdgpu-arch [gfx908]
-// RUN:   %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu 
-fopenmp=libomp --offload-arch=gfx908 -fsanitize=address -fgpu-sanitize 
--rocm-path=%S/Inputs/rocm %s 2>&1 \
-// RUN:   | FileCheck -check-prefixes=NOXNACK,GPUSAN %s
-
-// GPU ASan enabled for amdgpu-arch [gfx908:xnack-]
-// RUN:   %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu 
-fopenmp=libomp --offload-arch=gfx908:xnack- -fsanitize=address -fgpu-sanitize 
--rocm-path=%S/Inputs/rocm %s 2>&1 \
-// RUN:   | FileCheck -check-prefixes=XNACKNEG,GPUSAN %s
 
 // GPU ASan enabled for amdgpu-arch [gfx908:xnack+]
 // RUN:   %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu 
-fopenmp=libomp --offload-arch=gfx908:xnack+ -fsanitize=address -fgpu-sanitize 
--rocm-path=%S/Inputs/rocm %s 2>&1 \
-// RUN:   | FileCheck -ch

[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)

2025-02-09 Thread Owen Pan via cfe-commits

owenca wrote:

> > Diagnostic output should go to stderr, but the informational output of 
> > git-clang-format is sent to stdout instead.
> 
> What does that mean? The printing of null-terminated paths on stdout is 
> pretty standard on unix utilities. What's "diagnostic" and "informational"?

Diagnostic messages are error/warning/informational messages.

> The `--null` option is so that the paths can be safely handled by other tools 
> in the shell pipeline.
> 
> > If you want to run git add in git-clang-format, we can add an option for 
> > that.
> 
> No, that's limiting to the user. The right thing to do is to print the paths 
> with null-terminated bytes in between, so that any utility wished can be 
> executed.

As you already admitted in 
https://github.com/llvm/llvm-project/pull/123926#issuecomment-2614296866 that 
you would only use this on `git clang-format --staged` with `git add` and 
didn't know about other use cases, how can you be sure it's the "right thing to 
do"?

> Are you perhaps not aware of the issues at play here? Paths on linux/bsd/etc 
> can contain any character. It's impossible to parse text output containing 
> paths safely. You have to use some kind of format, and the approach used by 
> all utilities is null-separated paths.

I used `find -print0 ... | xargs -0` myself before. That's why I requested that 
you rename `-0, --null` to `-print0`.

I don't know what @mydeveloperday and @HazardyKnusperkeks think, but I wouldn't 
be in support of your proposed option for the reasons mentioned earlier.

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


[clang-tools-extra] [clang-tidy] Add modernize-nlohmann-json-explicit-conversions check (PR #126425)

2025-02-09 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

I have some mixed feelings as well, this could open the door for clang-tidy 
becoming a tool for modernizing "any" 3rd-party library usage. It feels like 
instead nlohmann/json should be the one responsible for providing a "migration 
path" / tooling for these types of deprecated features. 

It could also easily become a mess when we have to deal with / support 
different versions of the libraries. 

Thus I would vote for keeping clang-tidy as a general tool for C++/STL only. 
Perhaps these types of utilities could be implemented as a clang-tidy 
**plugin** in the respective 3rd-party repository?

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


[clang] [clang-format] Handle C-style cast of member function pointer type (PR #126340)

2025-02-09 Thread Owen Pan via cfe-commits

owenca wrote:

You mean 20.x?

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


[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)

2025-02-09 Thread Nikolaos Chatzikonstantinou via cfe-commits

createyourpersonalaccount wrote:

I don't know what you're talking about. I know however that you're 
bikeshedding. Sad.

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


[clang] [clang-format] Handle C-style cast of member function pointer type (PR #126340)

2025-02-09 Thread via cfe-commits

rmarker wrote:

> You mean the 20.x release branch?

Yes.

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


[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread via cfe-commits

https://github.com/StarOne01 updated 
https://github.com/llvm/llvm-project/pull/123495

>From 6f2ce4c05c0e03b1c18c694ddea97dac184e2218 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 07:28:24 +0530
Subject: [PATCH 01/17] [clang][Sema] Add diagnostic note for function-like
 macros requiring parentheses

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaExpr.cpp  | 15 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index db54312ad965e89..9d98cd2d8bbc881 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5936,6 +5936,8 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
+def note_function_like_macro_requires_parens : Note<
+  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ae40895980d90a9..f9dd731d59a2dd7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2509,6 +2509,19 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 DC = DC->getLookupParent();
   }
 
+  // Check whether a similar function-like macro exists and suggest it
+  if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
+if (II->hasMacroDefinition()) {
+  MacroInfo *MI = PP.getMacroInfo(II);
+  if (MI && MI->isFunctionLike()) {
+Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+<< II->getName();
+return true;
+  }
+}
+  }
+
   // We didn't find anything, so try to correct for a typo.
   TypoCorrection Corrected;
   if (S && Out) {
@@ -2619,7 +2632,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-
+  
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;

>From 8e90d9a0a227442d1220f1d6f521f81b6397e146 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 08:30:39 +0530
Subject: [PATCH 02/17] [clang][Tests] Modify tests for function-like macros
 according to the new behavior and Format the changes

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td| 5 +++--
 clang/lib/Sema/SemaExpr.cpp | 7 ---
 clang/test/Preprocessor/macro_with_initializer_list.cpp | 6 --
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9d98cd2d8bbc881..37a9a67ac1efba8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5936,8 +5936,9 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
-def note_function_like_macro_requires_parens : Note<
-  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
+def note_function_like_macro_requires_parens
+: Note<"'%0' exists, but as a function-like macro; perhaps, did you forget 
"
+   "the parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f9dd731d59a2dd7..44bab3e47233cb0 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2514,8 +2514,9 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 if (II->hasMacroDefinition()) {
   MacroInfo *MI = PP.getMacroInfo(II);
   if (MI && MI->isFunctionLike()) {
-Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
-Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+Diag(R.getNameLoc(), diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(),
+ diag::note_function_like_macro_requires_parens)
 << II->getName();
 return true;
   }
@@ -2632,7 +2633,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-  
+
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;
diff --git a/clang/test/Preprocessor/macro_with_initializer_list.cpp 
b/clang/test/Preprocessor/

[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread via cfe-commits

https://github.com/StarOne01 updated 
https://github.com/llvm/llvm-project/pull/123495

>From 6f2ce4c05c0e03b1c18c694ddea97dac184e2218 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 07:28:24 +0530
Subject: [PATCH 1/8] [clang][Sema] Add diagnostic note for function-like
 macros requiring parentheses

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaExpr.cpp  | 15 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index db54312ad965e89..9d98cd2d8bbc881 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5936,6 +5936,8 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
+def note_function_like_macro_requires_parens : Note<
+  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ae40895980d90a9..f9dd731d59a2dd7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2509,6 +2509,19 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 DC = DC->getLookupParent();
   }
 
+  // Check whether a similar function-like macro exists and suggest it
+  if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
+if (II->hasMacroDefinition()) {
+  MacroInfo *MI = PP.getMacroInfo(II);
+  if (MI && MI->isFunctionLike()) {
+Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+<< II->getName();
+return true;
+  }
+}
+  }
+
   // We didn't find anything, so try to correct for a typo.
   TypoCorrection Corrected;
   if (S && Out) {
@@ -2619,7 +2632,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-
+  
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;

>From 8e90d9a0a227442d1220f1d6f521f81b6397e146 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 08:30:39 +0530
Subject: [PATCH 2/8] [clang][Tests] Modify tests for function-like macros
 according to the new behavior and Format the changes

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td| 5 +++--
 clang/lib/Sema/SemaExpr.cpp | 7 ---
 clang/test/Preprocessor/macro_with_initializer_list.cpp | 6 --
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9d98cd2d8bbc881..37a9a67ac1efba8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5936,8 +5936,9 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
-def note_function_like_macro_requires_parens : Note<
-  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
+def note_function_like_macro_requires_parens
+: Note<"'%0' exists, but as a function-like macro; perhaps, did you forget 
"
+   "the parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f9dd731d59a2dd7..44bab3e47233cb0 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2514,8 +2514,9 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 if (II->hasMacroDefinition()) {
   MacroInfo *MI = PP.getMacroInfo(II);
   if (MI && MI->isFunctionLike()) {
-Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
-Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+Diag(R.getNameLoc(), diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(),
+ diag::note_function_like_macro_requires_parens)
 << II->getName();
 return true;
   }
@@ -2632,7 +2633,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-  
+
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;
diff --git a/clang/test/Preprocessor/macro_with_initializer_list.cpp 
b/clang/test/Preprocessor/macr

[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread via cfe-commits

https://github.com/StarOne01 updated 
https://github.com/llvm/llvm-project/pull/123495

>From 6f2ce4c05c0e03b1c18c694ddea97dac184e2218 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 07:28:24 +0530
Subject: [PATCH 01/16] [clang][Sema] Add diagnostic note for function-like
 macros requiring parentheses

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaExpr.cpp  | 15 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index db54312ad965e89..9d98cd2d8bbc881 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5936,6 +5936,8 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
+def note_function_like_macro_requires_parens : Note<
+  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ae40895980d90a9..f9dd731d59a2dd7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2509,6 +2509,19 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 DC = DC->getLookupParent();
   }
 
+  // Check whether a similar function-like macro exists and suggest it
+  if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
+if (II->hasMacroDefinition()) {
+  MacroInfo *MI = PP.getMacroInfo(II);
+  if (MI && MI->isFunctionLike()) {
+Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+<< II->getName();
+return true;
+  }
+}
+  }
+
   // We didn't find anything, so try to correct for a typo.
   TypoCorrection Corrected;
   if (S && Out) {
@@ -2619,7 +2632,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-
+  
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;

>From 8e90d9a0a227442d1220f1d6f521f81b6397e146 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 08:30:39 +0530
Subject: [PATCH 02/16] [clang][Tests] Modify tests for function-like macros
 according to the new behavior and Format the changes

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td| 5 +++--
 clang/lib/Sema/SemaExpr.cpp | 7 ---
 clang/test/Preprocessor/macro_with_initializer_list.cpp | 6 --
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9d98cd2d8bbc881..37a9a67ac1efba8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5936,8 +5936,9 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
-def note_function_like_macro_requires_parens : Note<
-  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
+def note_function_like_macro_requires_parens
+: Note<"'%0' exists, but as a function-like macro; perhaps, did you forget 
"
+   "the parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f9dd731d59a2dd7..44bab3e47233cb0 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2514,8 +2514,9 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 if (II->hasMacroDefinition()) {
   MacroInfo *MI = PP.getMacroInfo(II);
   if (MI && MI->isFunctionLike()) {
-Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
-Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+Diag(R.getNameLoc(), diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(),
+ diag::note_function_like_macro_requires_parens)
 << II->getName();
 return true;
   }
@@ -2632,7 +2633,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-  
+
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;
diff --git a/clang/test/Preprocessor/macro_with_initializer_list.cpp 
b/clang/test/Preprocessor/

[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread via cfe-commits

StarOne01 wrote:

Okay, i have no idea what happened, why was everyone asked for review? BTW, got 
everything resolved

- Add recommended tests.
- Made the diagnostic message clear and concise.
- Add release notes

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


[clang] [clang-format] Add AlignAfterOpenBracketOptions (PR #108332)

2025-02-09 Thread Gedare Bloom via cfe-commits

https://github.com/gedare updated 
https://github.com/llvm/llvm-project/pull/108332

>From 5cec30f5d93a22f10a985cb3e4418e7d29d31a00 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Thu, 20 Jun 2024 17:35:39 -0600
Subject: [PATCH 1/7] Format: add AlignAfterOpenBracketOptions

Introduce new options to allow for control of AlwaysBreak and
BlockIndent selectively for If conditional statements (as currently
supported), other conditional statements (for/while/switch), and
other statements.

Fixes #67738.
Fixes #79176.
Fixes #80123.
---
 clang/docs/ClangFormatStyleOptions.rst |  60 +
 clang/include/clang/Format/Format.h|  73 +++
 clang/lib/Format/ContinuationIndenter.cpp  |  44 +--
 clang/lib/Format/Format.cpp|  26 
 clang/lib/Format/TokenAnnotator.cpp|   8 +-
 clang/unittests/Format/ConfigParseTest.cpp |  12 ++
 clang/unittests/Format/FormatTest.cpp  | 143 +
 7 files changed, 355 insertions(+), 11 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bf6dd9e13915f8c..8e3383ec027dede 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -246,6 +246,66 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _AlignAfterOpenBracketBreak:
+
+**AlignAfterOpenBracketBreak** (``AlignAfterOpenBracketCustom``) 
:versionbadge:`clang-format 20` :ref:`¶ `
+  Control of when ``AlignAfterOpenBracket`` breaks an opening bracket.
+
+  If ``AlignAfterOpenBracket`` is set to ``AlwaysBreak`` or ``BlockIndent``,
+  use this to specify how different cases of breaking the opening brackets
+  should be handled. Otherwise, this is ignored. Setting any of these to
+  ``false`` will cause them to not break. At least one of these must be set
+  to ``true``, otherwise a default (backward compatible) breaking behavior
+  is used. This is ignored for ``Align`` and ``DontAlign``.
+
+  .. code-block:: c++
+
+# Example of usage:
+AlignAfterOpenBracket: AlwaysBreak
+AlignAfterOpenBracketBreak:
+  InIfConditionalStatements: true
+  InOtherConditionalStatements: false
+  Other: true
+
+  Nested configuration flags:
+
+  Precise control over breaking the opening bracket of
+  ``AlignAfterOpenBracket``.
+
+  .. code-block:: c++
+
+# Should be declared this way:
+AlignAfterOpenBracketBreak:
+  InIfConditionalStatements: true
+  InOtherConditionalStatements: false
+  Other: true
+
+  * ``bool InIfConditionalStatements`` Break inside if/else if statements.
+
+.. code-block:: c++
+
+   true:  false:
+   if constexpr (   vs.   if constexpr (a ||
+  a || b)   b)
+
+  * ``bool InOtherConditionalStatements`` Break inside conditional statements 
not covered by preceding options.
+(``for/while/switch...``).
+
+.. code-block:: c++
+
+   true:  false:
+   while (  vs.   while (a &&
+  a && b ) { b) {
+
+  * ``bool Other`` Break inside brackets not covered by preceding options.
+
+.. code-block:: c++
+
+   true:  false:
+   someLongFunction(vs.   someLongFunction(argument1,
+  argument1, argument2);   argument2);
+
+
 .. _AlignArrayOfStructures:
 
 **AlignArrayOfStructures** (``ArrayInitializerAlignmentStyle``) 
:versionbadge:`clang-format 13` :ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 16956b4e0fbd4f3..4a24e39ab3aff7a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -106,6 +106,78 @@ struct FormatStyle {
   /// \version 3.8
   BracketAlignmentStyle AlignAfterOpenBracket;
 
+  /// Precise control over breaking the opening bracket of
+  /// ``AlignAfterOpenBracket``.
+  /// \code
+  ///   # Should be declared this way:
+  ///   AlignAfterOpenBracketBreak:
+  /// InIfConditionalStatements: true
+  /// InOtherConditionalStatements: false
+  /// Other: true
+  /// \endcode
+  struct AlignAfterOpenBracketCustom {
+/// Break inside if/else if statements.
+/// \code
+///true:  false:
+///if constexpr (   vs.   if constexpr (a ||
+///   a || b)   b)
+/// \endcode
+bool InIfConditionalStatements;
+/// Break inside conditional statements not covered by preceding options.
+/// (``for/while/switch...``).
+/// \code
+///true:  false:
+///while (  vs.   while (a &&
+///   a && b ) { b) {
+/// \endcode
+bool InOtherConditionalStatements;
+/// Break inside b

[clang] [Serialization] Avoid repeated hash lookups (NFC) (PR #126429)

2025-02-09 Thread Kazu Hirata via cfe-commits

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


[clang] Allow direct dispatch for the ObjFW runtime (PR #126382)

2025-02-09 Thread Jonathan Schleifer via cfe-commits

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


[clang] Allow direct dispatch for the ObjFW runtime (PR #126382)

2025-02-09 Thread Jonathan Schleifer via cfe-commits

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


[clang] [llvm] [OpenMP] Remove 'libomptarget.devicertl.a' fatbinary and use static library (PR #126143)

2025-02-09 Thread Shilei Tian via cfe-commits

https://github.com/shiltian approved this pull request.

Hope the bot will be happy as well

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


[clang] [llvm] [OpenMP] Remove 'libomptarget.devicertl.a' fatbinary and use static library (PR #126143)

2025-02-09 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> Hope the bot will be happy as well

I need to fix one thing unfortunately, there's this 
`--nvptx-lower-global-ctor-dtor` option that we pass for these 'direct' GPU 
compilations on NVPTX. That's defined in the NVPTX backend so if the user 
didn't build with it, then it is an error. It's an opt-in thing since CUDA 
can't handle it and they wanted it to remain an error. I'm thinking the easiest 
solution is to just define it somewhere in LLVM so it's always there. Don't 
know where a good spot would be though.

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


[clang] [TableGen] Avoid repeated hash lookups (NFC) (PR #126464)

2025-02-09 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/126464

None

>From 471b2f287c7b3b1ade9dbe5b1d9cb10affa0a6e6 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 9 Feb 2025 16:20:17 -0800
Subject: [PATCH] [TableGen] Avoid repeated hash lookups (NFC)

---
 clang/utils/TableGen/MveEmitter.cpp | 15 ---
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/clang/utils/TableGen/MveEmitter.cpp 
b/clang/utils/TableGen/MveEmitter.cpp
index 014b20667e03e4c..7bee2996382c115 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -1629,17 +1629,10 @@ void EmitterBase::EmitBuiltinCG(raw_ostream &OS) {
   for (const auto &OI : kv.second)
 key.push_back(OI.ParamValues[i]);
 
-  auto Found = ParamNumberMap.find(key);
-  if (Found != ParamNumberMap.end()) {
-// Yes, an existing parameter variable can be reused for this.
-ParamNumbers.push_back(Found->second);
-continue;
-  }
-
-  // No, we need a new parameter variable.
-  int ExistingIndex = ParamNumberMap.size();
-  ParamNumberMap[key] = ExistingIndex;
-  ParamNumbers.push_back(ExistingIndex);
+  // Obtain a new parameter variable if we don't have one.
+  int ParamNum =
+  ParamNumberMap.try_emplace(key, ParamNumberMap.size()).first->second;
+  ParamNumbers.push_back(ParamNum);
 }
 
 // Now we're ready to do the pass 2 code generation, which will emit the

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


[clang] [TableGen] Avoid repeated hash lookups (NFC) (PR #126464)

2025-02-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/126464.diff


1 Files Affected:

- (modified) clang/utils/TableGen/MveEmitter.cpp (+4-11) 


``diff
diff --git a/clang/utils/TableGen/MveEmitter.cpp 
b/clang/utils/TableGen/MveEmitter.cpp
index 014b20667e03e4c..7bee2996382c115 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -1629,17 +1629,10 @@ void EmitterBase::EmitBuiltinCG(raw_ostream &OS) {
   for (const auto &OI : kv.second)
 key.push_back(OI.ParamValues[i]);
 
-  auto Found = ParamNumberMap.find(key);
-  if (Found != ParamNumberMap.end()) {
-// Yes, an existing parameter variable can be reused for this.
-ParamNumbers.push_back(Found->second);
-continue;
-  }
-
-  // No, we need a new parameter variable.
-  int ExistingIndex = ParamNumberMap.size();
-  ParamNumberMap[key] = ExistingIndex;
-  ParamNumbers.push_back(ExistingIndex);
+  // Obtain a new parameter variable if we don't have one.
+  int ParamNum =
+  ParamNumberMap.try_emplace(key, ParamNumberMap.size()).first->second;
+  ParamNumbers.push_back(ParamNum);
 }
 
 // Now we're ready to do the pass 2 code generation, which will emit the

``




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


[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)

2025-02-09 Thread Owen Pan via cfe-commits

owenca wrote:

> > It seems that `git-clang-format` was not designed for its output to be 
> > consumed by another utility as it prints everything to `stdout` instead of 
> > `stderr`. Adding an option like`--print0` (especially just for `--staged`) 
> > looks odd to me.
> 
> No, the approach of printing to `stderr` for utilities is not accurate. I've 
> heard of this before, even the claim that this is the original UNIX way, but 
> it's not. I don't know the origin of this 
> [cargo-culting](https://en.wikipedia.org/wiki/Cargo_cult) factoid but I 
> assure you that it does not hold true. (The origin I suspect may be Microsoft 
> with its Powershell, i.e. see 
> [about_Output_Streams](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_output_streams?view=powershell-7.5))

Diagnostic output should go to stderr, but the informational output of 
git-clang-format is sent to stdout instead.

> There is a lot of value in `--null` since it allows `git clang-format` to be 
> used in git hooks. Why would a Python script designed as a git subcommand not 
> work well with git?

If you want to run `git add` in git-clang-format, we can add an option for that.

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


[clang] [Lex] Avoid repeated hash lookups (NFC) (PR #126462)

2025-02-09 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/126462

None

>From b976daf87b4b1e50b8aabd90fcb49afb45268083 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 9 Feb 2025 13:55:00 -0800
Subject: [PATCH] [Lex] Avoid repeated hash lookups (NFC)

---
 clang/lib/Lex/ModuleMap.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index ccf94f6345ff280..998e2b977d109ba 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -2928,9 +2928,10 @@ void ModuleMapParser::parseInferredModuleDecl(bool 
Framework, bool Explicit) {
 ActiveModule->InferExplicitSubmodules = Explicit;
   } else {
 // We'll be inferring framework modules for this directory.
-Map.InferredDirectories[Directory].InferModules = true;
-Map.InferredDirectories[Directory].Attrs = Attrs;
-Map.InferredDirectories[Directory].ModuleMapFID = ModuleMapFID;
+auto &InfDir = Map.InferredDirectories[Directory];
+InfDir.InferModules = true;
+InfDir.Attrs = Attrs;
+InfDir.ModuleMapFID = ModuleMapFID;
 // FIXME: Handle the 'framework' keyword.
   }
 

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


[clang] [Lex] Avoid repeated hash lookups (NFC) (PR #126462)

2025-02-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/126462.diff


1 Files Affected:

- (modified) clang/lib/Lex/ModuleMap.cpp (+4-3) 


``diff
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index ccf94f6345ff280..998e2b977d109ba 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -2928,9 +2928,10 @@ void ModuleMapParser::parseInferredModuleDecl(bool 
Framework, bool Explicit) {
 ActiveModule->InferExplicitSubmodules = Explicit;
   } else {
 // We'll be inferring framework modules for this directory.
-Map.InferredDirectories[Directory].InferModules = true;
-Map.InferredDirectories[Directory].Attrs = Attrs;
-Map.InferredDirectories[Directory].ModuleMapFID = ModuleMapFID;
+auto &InfDir = Map.InferredDirectories[Directory];
+InfDir.InferModules = true;
+InfDir.Attrs = Attrs;
+InfDir.ModuleMapFID = ModuleMapFID;
 // FIXME: Handle the 'framework' keyword.
   }
 

``




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


[clang] [AST] Avoid repeated hash lookups (NFC) (PR #126461)

2025-02-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/126461.diff


1 Files Affected:

- (modified) clang/lib/AST/RawCommentList.cpp (+4-4) 


``diff
diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp
index fddedd3a31856a..9658c6ab3d39dd 100644
--- a/clang/lib/AST/RawCommentList.cpp
+++ b/clang/lib/AST/RawCommentList.cpp
@@ -287,13 +287,13 @@ void RawCommentList::addComment(const RawComment &RC,
 
   // If this is the first Doxygen comment, save it (because there isn't
   // anything to merge it with).
-  if (OrderedComments[CommentFile].empty()) {
-OrderedComments[CommentFile][CommentOffset] =
-new (Allocator) RawComment(RC);
+  auto &OC = OrderedComments[CommentFile];
+  if (OC.empty()) {
+OC[CommentOffset] = new (Allocator) RawComment(RC);
 return;
   }
 
-  const RawComment &C1 = *OrderedComments[CommentFile].rbegin()->second;
+  const RawComment &C1 = *OC.rbegin()->second;
   const RawComment &C2 = RC;
 
   // Merge comments only if there is only whitespace between them.

``




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


[clang] [AST] Avoid repeated hash lookups (NFC) (PR #126461)

2025-02-09 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/126461

None

>From 38fe282d1e50b35d46ec368b86edba58e1898090 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 9 Feb 2025 13:54:03 -0800
Subject: [PATCH] [AST] Avoid repeated hash lookups (NFC)

---
 clang/lib/AST/RawCommentList.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/RawCommentList.cpp b/clang/lib/AST/RawCommentList.cpp
index fddedd3a31856a3..9658c6ab3d39dd6 100644
--- a/clang/lib/AST/RawCommentList.cpp
+++ b/clang/lib/AST/RawCommentList.cpp
@@ -287,13 +287,13 @@ void RawCommentList::addComment(const RawComment &RC,
 
   // If this is the first Doxygen comment, save it (because there isn't
   // anything to merge it with).
-  if (OrderedComments[CommentFile].empty()) {
-OrderedComments[CommentFile][CommentOffset] =
-new (Allocator) RawComment(RC);
+  auto &OC = OrderedComments[CommentFile];
+  if (OC.empty()) {
+OC[CommentOffset] = new (Allocator) RawComment(RC);
 return;
   }
 
-  const RawComment &C1 = *OrderedComments[CommentFile].rbegin()->second;
+  const RawComment &C1 = *OC.rbegin()->second;
   const RawComment &C2 = RC;
 
   // Merge comments only if there is only whitespace between them.

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


[clang] [WebKit Checkers] Allow operator T&() in a const member function (PR #126470)

2025-02-09 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created 
https://github.com/llvm/llvm-project/pull/126470

Allow operator T&() in a member function which returns a const member variable.

In particular, this will allow UniqueRef::operator T&() and Ref::operator T&() 
to be treated as a safe pointer origin when they're called on a const member.

>From b795148061279951c9fa97421d07f6bf812eb302 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 9 Feb 2025 21:48:15 -0800
Subject: [PATCH] [WebKit Checkers] Allow operator T&() in a const member
 function

Allow operator T&() in a member function which returns a const member variable.

In particular, this will allow UniqueRef::operator T&() and Ref::operator T&()
to be treated as a safe pointer origin when they're called on a const member.
---
 clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp | 8 
 .../Checkers/WebKit/call-args-counted-const-member.cpp| 4 
 clang/test/Analysis/Checkers/WebKit/mock-types.h  | 1 +
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index abf5d3ec193a41a..9eb0c8ed5c8419f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -154,10 +154,10 @@ bool isConstOwnerPtrMemberExpr(const clang::Expr *E) {
   if (auto *MCE = dyn_cast(E)) {
 if (auto *Callee = MCE->getDirectCallee()) {
   auto Name = safeGetName(Callee);
-  if (Name == "get" || Name == "ptr") {
-auto *ThisArg = MCE->getImplicitObjectArgument();
-E = ThisArg;
-  }
+  if (Name == "get" || Name == "ptr")
+E = MCE->getImplicitObjectArgument();
+  if (auto *CD = dyn_cast(Callee))
+E = MCE->getImplicitObjectArgument();
 }
   } else if (auto *OCE = dyn_cast(E)) {
 if (OCE->getOperator() == OO_Star && OCE->getNumArgs() == 1)
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
index 215238a7fcf0712..8da415a818a8296 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
@@ -31,6 +31,7 @@ class Foo {
 public:
   Foo();
   void bar();
+  RefCountable& obj1() const { return m_obj1; }
 
 private:
   const Ref m_obj1;
@@ -41,6 +42,7 @@ void Foo::bar() {
   m_obj1->method();
   m_obj2->method();
   // expected-warning@-1{{Call argument for 'this' parameter is uncounted and 
unsafe}}
+  obj1().method();
 }
 
 } // namespace call_args_const_ref_member
@@ -100,6 +102,7 @@ class Foo {
 public:
   Foo();
   void bar();
+  RefCountable& obj1() { return m_obj1; }
 
 private:
   const UniqueRef m_obj1;
@@ -110,6 +113,7 @@ void Foo::bar() {
   m_obj1->method();
   m_obj2->method();
   // expected-warning@-1{{Call argument for 'this' parameter is uncounted and 
unsafe}}
+  obj1().method();
 }
 
 } // namespace call_args_const_unique_ref
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index 85397c2d259516d..a1f0cc8b046b995 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -289,6 +289,7 @@ class UniqueRef {
 u.t = nullptr;
   }
   T &get() const { return *t; }
+  operator T&() const { return *t; }
   T *operator->() const { return t; }
   UniqueRef &operator=(T &) { return *this; }
 };

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


[clang] [WebKit Checkers] Allow operator T&() in a const member function (PR #126470)

2025-02-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ryosuke Niwa (rniwa)


Changes

Allow operator T&() in a member function which returns a const member 
variable.

In particular, this will allow UniqueRef::operator T&() and Ref::operator 
T&() to be treated as a safe pointer origin when they're called on a const 
member.

---
Full diff: https://github.com/llvm/llvm-project/pull/126470.diff


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+4-4) 
- (modified) 
clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp (+4) 
- (modified) clang/test/Analysis/Checkers/WebKit/mock-types.h (+1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index abf5d3ec193a41a..9eb0c8ed5c8419f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -154,10 +154,10 @@ bool isConstOwnerPtrMemberExpr(const clang::Expr *E) {
   if (auto *MCE = dyn_cast(E)) {
 if (auto *Callee = MCE->getDirectCallee()) {
   auto Name = safeGetName(Callee);
-  if (Name == "get" || Name == "ptr") {
-auto *ThisArg = MCE->getImplicitObjectArgument();
-E = ThisArg;
-  }
+  if (Name == "get" || Name == "ptr")
+E = MCE->getImplicitObjectArgument();
+  if (auto *CD = dyn_cast(Callee))
+E = MCE->getImplicitObjectArgument();
 }
   } else if (auto *OCE = dyn_cast(E)) {
 if (OCE->getOperator() == OO_Star && OCE->getNumArgs() == 1)
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
index 215238a7fcf0712..8da415a818a8296 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
@@ -31,6 +31,7 @@ class Foo {
 public:
   Foo();
   void bar();
+  RefCountable& obj1() const { return m_obj1; }
 
 private:
   const Ref m_obj1;
@@ -41,6 +42,7 @@ void Foo::bar() {
   m_obj1->method();
   m_obj2->method();
   // expected-warning@-1{{Call argument for 'this' parameter is uncounted and 
unsafe}}
+  obj1().method();
 }
 
 } // namespace call_args_const_ref_member
@@ -100,6 +102,7 @@ class Foo {
 public:
   Foo();
   void bar();
+  RefCountable& obj1() { return m_obj1; }
 
 private:
   const UniqueRef m_obj1;
@@ -110,6 +113,7 @@ void Foo::bar() {
   m_obj1->method();
   m_obj2->method();
   // expected-warning@-1{{Call argument for 'this' parameter is uncounted and 
unsafe}}
+  obj1().method();
 }
 
 } // namespace call_args_const_unique_ref
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index 85397c2d259516d..a1f0cc8b046b995 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -289,6 +289,7 @@ class UniqueRef {
 u.t = nullptr;
   }
   T &get() const { return *t; }
+  operator T&() const { return *t; }
   T *operator->() const { return t; }
   UniqueRef &operator=(T &) { return *this; }
 };

``




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


[clang] [WebKit Checkers] Allow operator T&() in a const member function (PR #126470)

2025-02-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

Allow operator T&() in a member function which returns a const member 
variable.

In particular, this will allow UniqueRef::operator T&() and Ref::operator 
T&() to be treated as a safe pointer origin when they're called on a const 
member.

---
Full diff: https://github.com/llvm/llvm-project/pull/126470.diff


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+4-4) 
- (modified) 
clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp (+4) 
- (modified) clang/test/Analysis/Checkers/WebKit/mock-types.h (+1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index abf5d3ec193a41a..9eb0c8ed5c8419f 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -154,10 +154,10 @@ bool isConstOwnerPtrMemberExpr(const clang::Expr *E) {
   if (auto *MCE = dyn_cast(E)) {
 if (auto *Callee = MCE->getDirectCallee()) {
   auto Name = safeGetName(Callee);
-  if (Name == "get" || Name == "ptr") {
-auto *ThisArg = MCE->getImplicitObjectArgument();
-E = ThisArg;
-  }
+  if (Name == "get" || Name == "ptr")
+E = MCE->getImplicitObjectArgument();
+  if (auto *CD = dyn_cast(Callee))
+E = MCE->getImplicitObjectArgument();
 }
   } else if (auto *OCE = dyn_cast(E)) {
 if (OCE->getOperator() == OO_Star && OCE->getNumArgs() == 1)
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
index 215238a7fcf0712..8da415a818a8296 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
@@ -31,6 +31,7 @@ class Foo {
 public:
   Foo();
   void bar();
+  RefCountable& obj1() const { return m_obj1; }
 
 private:
   const Ref m_obj1;
@@ -41,6 +42,7 @@ void Foo::bar() {
   m_obj1->method();
   m_obj2->method();
   // expected-warning@-1{{Call argument for 'this' parameter is uncounted and 
unsafe}}
+  obj1().method();
 }
 
 } // namespace call_args_const_ref_member
@@ -100,6 +102,7 @@ class Foo {
 public:
   Foo();
   void bar();
+  RefCountable& obj1() { return m_obj1; }
 
 private:
   const UniqueRef m_obj1;
@@ -110,6 +113,7 @@ void Foo::bar() {
   m_obj1->method();
   m_obj2->method();
   // expected-warning@-1{{Call argument for 'this' parameter is uncounted and 
unsafe}}
+  obj1().method();
 }
 
 } // namespace call_args_const_unique_ref
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/mock-types.h
index 85397c2d259516d..a1f0cc8b046b995 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-types.h
@@ -289,6 +289,7 @@ class UniqueRef {
 u.t = nullptr;
   }
   T &get() const { return *t; }
+  operator T&() const { return *t; }
   T *operator->() const { return t; }
   UniqueRef &operator=(T &) { return *this; }
 };

``




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


[clang] [clang-format] Handle C-style cast of member function pointer type (PR #126340)

2025-02-09 Thread via cfe-commits

rmarker wrote:

@owenca is it possible to get this fix on the 20 branch?

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


[clang] [clang-format] Add null-terminated path option (#123921) (PR #123926)

2025-02-09 Thread Nikolaos Chatzikonstantinou via cfe-commits

createyourpersonalaccount wrote:

> Diagnostic output should go to stderr, but the informational output of 
> git-clang-format is sent to stdout instead.
What does that mean? The printing of null-terminated paths on stdout is pretty 
standard on unix utilities. What's "diagnostic" and "informational"?

The `--null` option is so that the paths can be safely handled by other tools 
in the shell pipeline.

> If you want to run git add in git-clang-format, we can add an option for that.
No, that's limiting to the user. The right thing to do is to print the paths 
with null-terminated bytes in between, so that any utility wished can be 
executed.

Are you perhaps not aware of the issues at play here? Paths on linux/bsd/etc 
can contain any character. It's impossible to parse text output containing 
paths safely. You have to use some kind of format, and the approach used by all 
utilities is null-separated paths.

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


[clang] Lalaniket8 temp (PR #126471)

2025-02-09 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] Lalaniket8 temp (PR #126471)

2025-02-09 Thread Aniket Lal via cfe-commits

https://github.com/lalaniket8 created 
https://github.com/llvm/llvm-project/pull/126471

None

>From 7be637fa9fcde8977f650e208c7ddc1495080941 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Tue, 4 Feb 2025 12:13:20 +0530
Subject: [PATCH 1/3] [Driver][HIP] Do not pass -dependency-file flag for HIP
 Device offloading

When we launch hipcc with multiple offload architectures along with -MF 
dep_file flag, the clang compilation invocations for host and device offloads 
write to the same dep_file, and can lead to collision during file IO 
operations. This can typically happen during large workloads.
This commit provides a fix to generate dep_file only in host compilation.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 30 ++-
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0a6756eadba317b..66acd2f7b91a577 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1013,21 +1013,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 ArgM = ArgMD;
 
   if (ArgM) {
-// Determine the output location.
-const char *DepFile;
-if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
-  DepFile = MF->getValue();
-  C.addFailureResultFile(DepFile, &JA);
-} else if (Output.getType() == types::TY_Dependencies) {
-  DepFile = Output.getFilename();
-} else if (!ArgMD) {
-  DepFile = "-";
-} else {
-  DepFile = getDependencyFileName(Args, Inputs);
-  C.addFailureResultFile(DepFile, &JA);
+if (!JA.isDeviceOffloading(Action::OFK_HIP)) {
+  // Determine the output location.
+  const char *DepFile;
+  if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
+DepFile = MF->getValue();
+C.addFailureResultFile(DepFile, &JA);
+  } else if (Output.getType() == types::TY_Dependencies) {
+DepFile = Output.getFilename();
+  } else if (!ArgMD) {
+DepFile = "-";
+  } else {
+DepFile = getDependencyFileName(Args, Inputs);
+C.addFailureResultFile(DepFile, &JA);
+  }
+  CmdArgs.push_back("-dependency-file");
+  CmdArgs.push_back(DepFile);
 }
-CmdArgs.push_back("-dependency-file");
-CmdArgs.push_back(DepFile);
 
 bool HasTarget = false;
 for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {

>From 5c52e3a065d0c6e3bf59c450102ae95595ed5b10 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Wed, 5 Feb 2025 14:49:50 +0530
Subject: [PATCH 2/3] Adding littest

---
 .../dep-file-flag-with-multiple-offload-archs.hip   | 13 +
 1 file changed, 13 insertions(+)
 create mode 100644 
clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip

diff --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip 
b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
new file mode 100644
index 000..9dd4b6a4601a01e
--- /dev/null
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -0,0 +1,13 @@
+// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s
+
+// CHECK: Build config:
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1030"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1100"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1100"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1101"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1101"
+// CHECK: {{.*}}clang-offload-bundler
+// CHECK: {{.*}}clang{{.*}}"-target-cpu" "x86-64"{{.*}}"-dependency-file" 
"tmp.d"
+
+void main(){}

>From 70eee8d54d575627cc5a1baef56656c15eabd613 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Mon, 10 Feb 2025 11:36:42 +0530
Subject: [PATCH 3/3] remove filecheck

---
 clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip 
b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
index 9dd4b6a4601a01e..3e953f2171571e2 100644
--- a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -1,4 +1,4 @@
-// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s
+// RUN: %clang -### --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d %s 2>&1
 
 // CHECK: Build config:
 // CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" 
"tmp.d"

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

[clang] [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading test (PR #126471)

2025-02-09 Thread Aniket Lal via cfe-commits

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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-02-09 Thread Chris B via cfe-commits


@@ -0,0 +1,171 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+namespace clang {
+namespace hlsl {
+
+// Lexer Definitions
+
+static bool IsNumberChar(char C) {
+  // TODO(#120472): extend for float support exponents
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  bool Negative = Buffer.front() == '-';
+  bool Signed = Negative || Buffer.front() == '+';
+  if (Signed)
+AdvanceBuffer();
+
+  // Retrieve the possible number
+  StringRef NumSpelling = Buffer.take_while(IsNumberChar);
+
+  // Catch this now as the Literal Parser will accept it as valid
+  if (NumSpelling.empty()) {
+PP.getDiagnostics().Report(Result.TokLoc,
+   diag::err_hlsl_invalid_number_literal);

llvm-beanz wrote:

IIUC, this occurs if the parser sees a `-` or `+` but no specified literal 
value after that. Is that correct?

A more succinct error message like "expected numeric literal" is probably a 
better message. The current one "expected number literal is not a supported 
number literal of unsigned integer or integer" is quite confusing.


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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-02-09 Thread Chris B via cfe-commits


@@ -0,0 +1,171 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+namespace clang {
+namespace hlsl {
+
+// Lexer Definitions
+
+static bool IsNumberChar(char C) {
+  // TODO(#120472): extend for float support exponents
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  bool Negative = Buffer.front() == '-';
+  bool Signed = Negative || Buffer.front() == '+';
+  if (Signed)
+AdvanceBuffer();
+
+  // Retrieve the possible number
+  StringRef NumSpelling = Buffer.take_while(IsNumberChar);
+
+  // Catch this now as the Literal Parser will accept it as valid
+  if (NumSpelling.empty()) {
+PP.getDiagnostics().Report(Result.TokLoc,
+   diag::err_hlsl_invalid_number_literal);
+return true;
+  }
+
+  // Parse the numeric value and do semantic checks on its specification
+  clang::NumericLiteralParser Literal(NumSpelling, SourceLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return true; // Error has already been reported so just return
+
+  // Note: if IsNumberChar allows for hexidecimal we will need to turn this
+  // into a diagnostics for potential fixed-point literals
+  assert(Literal.isIntegerLiteral() && "IsNumberChar will only support 
digits");
+
+  // Retrieve the number value to store into the token
+  Result.Kind = TokenKind::int_literal;
+
+  // NOTE: for compabibility with DXC, we will treat any integer with '+' as an
+  // unsigned integer
+  llvm::APSInt X = llvm::APSInt(32, !Negative);
+  if (Literal.GetIntegerValue(X)) {
+// Report that the value has overflowed
+PP.getDiagnostics().Report(Result.TokLoc,
+   diag::err_hlsl_number_literal_overflow)
+<< (unsigned)Signed << NumSpelling;
+return true;
+  }
+
+  X = Negative ? -X : X;
+  Result.NumLiteral = APValue(X);
+
+  AdvanceBuffer(NumSpelling.size());
+  return false;
+}
+
+bool RootSignatureLexer::Lex(SmallVector &Tokens) {
+  // Discard any leading whitespace
+  AdvanceBuffer(Buffer.take_while(isspace).size());
+
+  while (!Buffer.empty()) {
+// Record where this token is in the text for usage in parser diagnostics
+RootSignatureToken Result(SourceLoc);
+if (LexToken(Result))
+  return true;
+
+// Successfully Lexed the token so we can store it
+Tokens.push_back(Result);
+
+// Discard any trailing whitespace
+AdvanceBuffer(Buffer.take_while(isspace).size());
+  }
+
+  return false;
+}
+
+bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
+  char C = Buffer.front();
+
+  // Punctuators
+  switch (C) {
+#define PUNCTUATOR(X, Y)   
\
+  case Y: {
\
+Result.Kind = TokenKind::pu_##X;   
\
+AdvanceBuffer();   
\
+return false;  
\
+  }
+#include "clang/Parse/HLSLRootSignatureTokenKinds.def"
+  default:
+break;
+  }
+
+  // Numeric constant
+  if (isdigit(C) || C == '-' || C == '+')
+return LexNumber(Result);
+
+  // All following tokens require at least one additional character
+  if (Buffer.size() <= 1) {
+PP.getDiagnostics().Report(Result.TokLoc, diag::err_hlsl_invalid_token);

llvm-beanz wrote:

This error doesn't seem particularly useful to end users who make a mistake. 
Why not just return false here because it can't construct a token?

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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-02-09 Thread Chris B via cfe-commits


@@ -0,0 +1,171 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+namespace clang {
+namespace hlsl {
+
+// Lexer Definitions
+
+static bool IsNumberChar(char C) {
+  // TODO(#120472): extend for float support exponents
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  bool Negative = Buffer.front() == '-';
+  bool Signed = Negative || Buffer.front() == '+';
+  if (Signed)
+AdvanceBuffer();
+
+  // Retrieve the possible number
+  StringRef NumSpelling = Buffer.take_while(IsNumberChar);
+
+  // Catch this now as the Literal Parser will accept it as valid
+  if (NumSpelling.empty()) {
+PP.getDiagnostics().Report(Result.TokLoc,
+   diag::err_hlsl_invalid_number_literal);
+return true;
+  }
+
+  // Parse the numeric value and do semantic checks on its specification
+  clang::NumericLiteralParser Literal(NumSpelling, SourceLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return true; // Error has already been reported so just return
+
+  // Note: if IsNumberChar allows for hexidecimal we will need to turn this
+  // into a diagnostics for potential fixed-point literals
+  assert(Literal.isIntegerLiteral() && "IsNumberChar will only support 
digits");
+
+  // Retrieve the number value to store into the token
+  Result.Kind = TokenKind::int_literal;
+
+  // NOTE: for compabibility with DXC, we will treat any integer with '+' as an
+  // unsigned integer
+  llvm::APSInt X = llvm::APSInt(32, !Negative);
+  if (Literal.GetIntegerValue(X)) {
+// Report that the value has overflowed
+PP.getDiagnostics().Report(Result.TokLoc,
+   diag::err_hlsl_number_literal_overflow)
+<< (unsigned)Signed << NumSpelling;
+return true;
+  }
+
+  X = Negative ? -X : X;
+  Result.NumLiteral = APValue(X);
+
+  AdvanceBuffer(NumSpelling.size());
+  return false;
+}
+
+bool RootSignatureLexer::Lex(SmallVector &Tokens) {

llvm-beanz wrote:

I'm not sure this function should exist.

Most modern compilers don't lex entire source files into allocated lists of 
tokens then parse, they do the two at the same time never allocating more than 
a couple tokens at a time. You can see this in Clang where the `ConsumeToken` 
API advances the token to the next token, and is called throughout the parser.

I've seen other compilers where the tokenizer is implemented as effectively an 
iterator where the iterator state tracks the current token.

For context, the reason compilers tend to do this is because lexing isn't 
always "fast". In particular translation of numeric literals into actual 
integer values can be quite slow, so if you lex all the tokens, you do all the 
transformations even if an error would be detected during parsing. If you lex 
one token at a time, you stop lexing once the error is encountered providing 
faster user feedback.

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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-02-09 Thread Chris B via cfe-commits


@@ -0,0 +1,151 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+namespace llvm {
+namespace hlsl {
+namespace root_signature {
+
+// Lexer Definitions
+
+static bool IsPreprocessorNumberChar(char C) {
+  // TODO: extend for float support with or without hexadecimal/exponent
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  Result.Signed = Buffer.front() == '-';
+  if (Result.Signed)
+AdvanceBuffer();
+
+  // Retrieve the possible number
+  StringRef NumSpelling = Buffer.take_while(IsPreprocessorNumberChar);
+
+  // Parse the numeric value and so semantic checks on its specification
+  clang::NumericLiteralParser Literal(NumSpelling, SourceLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return true; // Error has already been reported so just return
+
+  // Retrieve the number value to store into the token
+  if (Literal.isIntegerLiteral()) {
+Result.Kind = TokenKind::int_literal;
+
+APSInt X = APSInt(32, Result.Signed);
+if (Literal.GetIntegerValue(X))
+  return true; // TODO: Report overflow error
+
+X = Result.Signed ? -X : X;
+Result.IntLiteral = (uint32_t)X.getZExtValue();
+  } else {
+return true; // TODO: report unsupported number literal specification
+  }
+
+  AdvanceBuffer(NumSpelling.size());
+  return false;
+}
+
+bool RootSignatureLexer::Lex(SmallVector &Tokens) {
+  // Discard any leading whitespace
+  AdvanceBuffer(Buffer.take_while(isspace).size());
+
+  while (!Buffer.empty()) {
+RootSignatureToken Result;
+if (LexToken(Result))
+  return true;
+
+// Successfully Lexed the token so we can store it
+Tokens.push_back(Result);
+
+// Discard any trailing whitespace
+AdvanceBuffer(Buffer.take_while(isspace).size());
+  }
+
+  return false;
+}
+
+bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
+  // Record where this token is in the text for usage in parser diagnostics
+  Result.TokLoc = SourceLoc;
+
+  char C = Buffer.front();
+
+  // Punctuators
+  switch (C) {
+#define PUNCTUATOR(X, Y)   
\
+  case Y: {
\
+Result.Kind = TokenKind::pu_##X;   
\
+AdvanceBuffer();   
\
+return false;  
\
+  }
+#include "clang/Parse/HLSLRootSignatureTokenKinds.def"
+  default:
+break;
+  }
+
+  // Numeric constant
+  if (isdigit(C) || C == '-')
+return LexNumber(Result);
+
+  // All following tokens require at least one additional character
+  if (Buffer.size() <= 1)
+return true; // TODO: Report invalid token error
+
+  // Peek at the next character to deteremine token type
+  char NextC = Buffer[1];
+
+  // Registers: [tsub][0-9+]
+  if ((C == 't' || C == 's' || C == 'u' || C == 'b') && isdigit(NextC)) {
+AdvanceBuffer();
+
+if (LexNumber(Result))
+  return true;
+
+// Lex number could also parse a float so ensure it was an unsigned int
+if (Result.Kind != TokenKind::int_literal || Result.Signed)
+  return true; // Return invalid number literal for register error
+
+// Convert character to the register type.
+// This is done after LexNumber to override the TokenKind
+switch (C) {
+case 'b':
+  Result.Kind = TokenKind::bReg;
+  break;
+case 't':
+  Result.Kind = TokenKind::tReg;
+  break;
+case 'u':
+  Result.Kind = TokenKind::uReg;
+  break;
+case 's':
+  Result.Kind = TokenKind::sReg;
+  break;
+default:
+  llvm_unreachable("Switch for an expected token was not provided");
+  return true;
+}
+return false;
+  }
+
+  // Keywords and Enums:

llvm-beanz wrote:

I definitely prefer starting with the simple approach and only going 
complicated if we need to. DXC had a bunch of hand-rolled string matching 
functions that unrolled the strings... and a few of them had some bad bugs. So 
this is the perfect way to start.

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


[clang] [libc] [libcxx] [lldb] [llvm] [doc] Add Discord invite link alongside channel links (PR #126352)

2025-02-09 Thread Alex Bradbury via cfe-commits


@@ -12,7 +12,8 @@ The LLVM C Library
   LLVM-libc is not fully complete right now. Some programs may fail to build 
due
   to missing functions. If you would like to help us finish LLVM-libc, check
   out "`Contributing to the libc project `__" in the sidebar
-  or ask on `discord 
`__.
+  or ask on `discord 
`__
+  (`invite link `__).

asb wrote:

How about "or ask on Discord (join via this invite link)" (obviously with the 
relevant links added!).

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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-02-09 Thread Chris B via cfe-commits


@@ -1017,4 +1017,15 @@ Error<"'#pragma unsafe_buffer_usage' was not ended">;
 
 def err_pp_pragma_unsafe_buffer_usage_syntax :
 Error<"expected 'begin' or 'end'">;
+
+// HLSL Root Signature Lexing Errors
+let CategoryName = "Root Signature Lexical Issue" in {
+  def err_hlsl_invalid_number_literal:
+Error<"expected number literal is not a supported number literal of 
unsigned integer or integer">;
+  def err_hlsl_number_literal_overflow :
+Error<"provided %select{unsigned integer|signed integer}0 literal '%1' 
that overflows the maximum of 32 bits">;

llvm-beanz wrote:

The context of this error is really similar to an existing clang error: 
err_integer_literal_too_large. I don't think it makes sense to share the 
message, but we should at least use similar language.

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


[clang] d204724 - [CSKY] Default to unsigned char

2025-02-09 Thread via cfe-commits

Author: Alexander Richardson
Date: 2025-02-09T12:18:52-08:00
New Revision: d2047242e6d0f0deb7634ff22ab164354c520c79

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

LOG: [CSKY] Default to unsigned char

This matches the ABI document found at
https://github.com/c-sky/csky-doc/blob/master/C-SKY_V2_CPU_Applications_Binary_Interface_Standards_Manual.pdf

Partially addresses https://github.com/llvm/llvm-project/issues/115957

Reviewed By: zixuan-wu

Pull Request: https://github.com/llvm/llvm-project/pull/115961

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/csky-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 821407687ffa1d..fe879e8f8bd277 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1387,6 +1387,7 @@ static bool isSignedCharDefault(const llvm::Triple 
&Triple) {
   return true;
 return false;
 
+  case llvm::Triple::csky:
   case llvm::Triple::hexagon:
   case llvm::Triple::msp430:
   case llvm::Triple::ppcle:

diff  --git a/clang/test/Driver/csky-toolchain.c 
b/clang/test/Driver/csky-toolchain.c
index 66485464652ac8..638ce64ec98cde 100644
--- a/clang/test/Driver/csky-toolchain.c
+++ b/clang/test/Driver/csky-toolchain.c
@@ -3,6 +3,7 @@
 
 // RUN: %clang -### %s --target=csky 2>&1 | FileCheck -check-prefix=CC1 %s
 // CC1: "-cc1" "-triple" "csky"
+// CC1: "-fno-signed-char"
 
 // In the below tests, --rtlib=platform is used so that the driver ignores
 // the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib



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


[clang] [CSKY] Default to unsigned char (PR #115961)

2025-02-09 Thread Alexander Richardson via cfe-commits

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


[clang-tools-extra] [clang-tidy] add AllowedTypes option to misc-const-correctness (PR #122951)

2025-02-09 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.

lgtm


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


[clang] [ObjC] Expand isClassLayoutKnownStatically to base classes as long as the implementation of it is known (PR #85465)

2025-02-09 Thread via cfe-commits

https://github.com/AZero13 updated 
https://github.com/llvm/llvm-project/pull/85465

>From bd44589c1e5db8859157780208a991c7b5038657 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Fri, 15 Mar 2024 16:43:10 -0400
Subject: [PATCH] [ObjC] Expand isClassLayoutKnownStatically to base classes as
 long as the implementation of it is known

Only NSObject we can trust the layout of won't change even though we cannot 
directly see its @implementation.
---
 clang/lib/CodeGen/CGObjCMac.cpp   |  9 -
 clang/test/CodeGenObjC/arc-blocks.m   |  8 ++---
 clang/test/CodeGenObjC/arc-property.m | 22 +---
 clang/test/CodeGenObjC/arc-weak-property.m|  5 ++-
 clang/test/CodeGenObjC/arc.m  | 18 --
 clang/test/CodeGenObjC/arm64-int32-ivar.m |  5 ++-
 .../test/CodeGenObjC/bitfield-ivar-offsets.m  |  5 ++-
 .../constant-non-fragile-ivar-offset.m| 34 +--
 clang/test/CodeGenObjC/direct-method.m|  3 +-
 clang/test/CodeGenObjC/hidden-visibility.m|  2 +-
 clang/test/CodeGenObjC/interface-layout-64.m  | 16 +
 .../CodeGenObjC/ivar-base-as-invariant-load.m |  5 ++-
 clang/test/CodeGenObjC/metadata-symbols-64.m  |  4 +--
 .../nontrivial-c-struct-property.m|  4 ++-
 .../CodeGenObjC/objc-asm-attribute-test.m |  5 +--
 clang/test/CodeGenObjC/ubsan-bool.m   |  4 ++-
 16 files changed, 96 insertions(+), 53 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 6c929a6431c0f06..620761f35f3113a 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1592,6 +1592,11 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   bool isClassLayoutKnownStatically(const ObjCInterfaceDecl *ID) {
 // Test a class by checking its superclasses up to
 // its base class if it has one.
+
+// Cannot check a null class
+if (!ID)
+  return false;
+
 for (; ID; ID = ID->getSuperClass()) {
   // The layout of base class NSObject
   // is guaranteed to be statically known
@@ -1603,7 +1608,9 @@ class CGObjCNonFragileABIMac : public CGObjCCommonMac {
   if (!ID->getImplementation())
 return false;
 }
-return false;
+
+// We know the layout of all the intermediate classes and superclasses.
+return true;
   }
 
 public:
diff --git a/clang/test/CodeGenObjC/arc-blocks.m 
b/clang/test/CodeGenObjC/arc-blocks.m
index bed55bf18fe59f5..72bf35c2e117e51 100644
--- a/clang/test/CodeGenObjC/arc-blocks.m
+++ b/clang/test/CodeGenObjC/arc-blocks.m
@@ -422,16 +422,16 @@ @interface Test12
 @implementation Test12
 @synthesize ablock, nblock;
 // CHECK:define internal ptr @"\01-[Test12 ablock]"(
-// CHECK:call ptr @objc_getProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef {{%.*}}, i1 noundef zeroext true)
+// CHECK:call ptr @objc_getProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef 0, i1 noundef zeroext true)
 
 // CHECK:define internal void @"\01-[Test12 setAblock:]"(
-// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef {{%.*}}, ptr noundef {{%.*}}, i1 noundef zeroext true, i1 
noundef zeroext true)
+// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef 0, ptr noundef {{%.*}}, i1 noundef zeroext true, i1 
noundef zeroext true)
 
 // CHECK:define internal ptr @"\01-[Test12 nblock]"(
-// CHECK:%add.ptr = getelementptr inbounds i8, ptr %0, i64 %ivar
+// CHECK:%add.ptr = getelementptr inbounds i8, ptr %0, i64 8
 
 // CHECK:define internal void @"\01-[Test12 setNblock:]"(
-// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef {{%.*}}, ptr noundef {{%.*}}, i1 noundef zeroext false, i1 
noundef zeroext true)
+// CHECK:call void @objc_setProperty(ptr noundef {{%.*}}, ptr noundef 
{{%.*}}, i64 noundef 8, ptr noundef {{%.*}}, i1 noundef zeroext false, i1 
noundef zeroext true)
 @end
 
 void test13(id x) {
diff --git a/clang/test/CodeGenObjC/arc-property.m 
b/clang/test/CodeGenObjC/arc-property.m
index f57be6b4f6be410..3209993cc6d32cd 100644
--- a/clang/test/CodeGenObjC/arc-property.m
+++ b/clang/test/CodeGenObjC/arc-property.m
@@ -22,16 +22,14 @@ @implementation Test1
 @end
 //   The getter should be a simple load.
 // CHECK:define internal ptr @"\01-[Test1 pointer]"(
-// CHECK:  [[OFFSET:%.*]] = load i64, ptr @"OBJC_IVAR_$_Test1.pointer"
-// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i8, ptr {{%.*}}, i64 
[[OFFSET]]
+// CHECK: [[T1:%.*]] = getelementptr inbounds i8, ptr {{%.*}}, i64 0
 // CHECK-NEXT: [[T3:%.*]] = load ptr, ptr [[T1]], align 8
 // CHECK-NEXT: ret ptr [[T3]]
 
 //   The setter should be using objc_setProperty.
 // CHECK:define internal void @"\01-[Test1 setPointer:]"(
-// CHECK: [[OFFSET:%.*]] = load i64, ptr @"OBJC_IVAR_$_Test1.pointer"
-// CHECK-NEXT: [[T1:%.*]] = load ptr, ptr {{%.*}}
-// CHECK-NEXT: call vo

[clang] [ObjC] Expand isClassLayoutKnownStatically to base classes as long as the implementation of it is known (PR #85465)

2025-02-09 Thread via cfe-commits

AZero13 wrote:

@adrian-prantl thoughts on this?

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


[clang] [llvm] [AArch64][SelectionDAG] Add CodeGen support for scalar FEAT_CPA (PR #105669)

2025-02-09 Thread David Green via cfe-commits


@@ -5025,6 +5025,11 @@ def msve_vector_bits_EQ : Joined<["-"], 
"msve-vector-bits=">, Group,
   HelpText<"Specify the size in bits of an SVE vector register. Defaults to 
the"
" vector length agnostic value of \"scalable\". (AArch64 only)">;
+
+def mcpa_codegen : Flag<["-"], "mcpa-codegen">,

davemgreen wrote:

Can we make it just an internal option for the time being? Otherwise we need to 
agree to the interface with GCC, and I don't think that has been done yet. It 
might be something to add in a future patch when we are sure of the details.

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


[clang-tools-extra] [clang-tidy] Address false positives in misc-redundant-expression checker (PR #122841)

2025-02-09 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.

lgtm.
could you test the case
#define MACRO "bbb"
"aaa" MACRO == "aaabbb"

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


[clang] [compiler-rt] [rtsan] Enable RealtimeSanitizer for FreeBSD (PR #125389)

2025-02-09 Thread via cfe-commits


@@ -864,11 +864,18 @@ INTERCEPTOR(void *, pvalloc, size_t size) {
 #define RTSAN_MAYBE_INTERCEPT_PVALLOC
 #endif
 
+#if !SANITIZER_FREEBSD
+// enabling this interception on freebsd leads to infinite recursion
+// on pthread lib initialization

davidtrevelyan wrote:

@devnexen would it be possible for you to share a stack trace so we can 
understand the route to infinite recursion during pthread init?

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


[clang] [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading test (PR #126471)

2025-02-09 Thread Aniket Lal via cfe-commits

https://github.com/lalaniket8 updated 
https://github.com/llvm/llvm-project/pull/126471

>From 7be637fa9fcde8977f650e208c7ddc1495080941 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Tue, 4 Feb 2025 12:13:20 +0530
Subject: [PATCH 1/4] [Driver][HIP] Do not pass -dependency-file flag for HIP
 Device offloading

When we launch hipcc with multiple offload architectures along with -MF 
dep_file flag, the clang compilation invocations for host and device offloads 
write to the same dep_file, and can lead to collision during file IO 
operations. This can typically happen during large workloads.
This commit provides a fix to generate dep_file only in host compilation.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 30 ++-
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0a6756eadba317b..66acd2f7b91a577 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1013,21 +1013,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 ArgM = ArgMD;
 
   if (ArgM) {
-// Determine the output location.
-const char *DepFile;
-if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
-  DepFile = MF->getValue();
-  C.addFailureResultFile(DepFile, &JA);
-} else if (Output.getType() == types::TY_Dependencies) {
-  DepFile = Output.getFilename();
-} else if (!ArgMD) {
-  DepFile = "-";
-} else {
-  DepFile = getDependencyFileName(Args, Inputs);
-  C.addFailureResultFile(DepFile, &JA);
+if (!JA.isDeviceOffloading(Action::OFK_HIP)) {
+  // Determine the output location.
+  const char *DepFile;
+  if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
+DepFile = MF->getValue();
+C.addFailureResultFile(DepFile, &JA);
+  } else if (Output.getType() == types::TY_Dependencies) {
+DepFile = Output.getFilename();
+  } else if (!ArgMD) {
+DepFile = "-";
+  } else {
+DepFile = getDependencyFileName(Args, Inputs);
+C.addFailureResultFile(DepFile, &JA);
+  }
+  CmdArgs.push_back("-dependency-file");
+  CmdArgs.push_back(DepFile);
 }
-CmdArgs.push_back("-dependency-file");
-CmdArgs.push_back(DepFile);
 
 bool HasTarget = false;
 for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {

>From 5c52e3a065d0c6e3bf59c450102ae95595ed5b10 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Wed, 5 Feb 2025 14:49:50 +0530
Subject: [PATCH 2/4] Adding littest

---
 .../dep-file-flag-with-multiple-offload-archs.hip   | 13 +
 1 file changed, 13 insertions(+)
 create mode 100644 
clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip

diff --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip 
b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
new file mode 100644
index 000..9dd4b6a4601a01e
--- /dev/null
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -0,0 +1,13 @@
+// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s
+
+// CHECK: Build config:
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1030"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1100"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1100"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1101"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1101"
+// CHECK: {{.*}}clang-offload-bundler
+// CHECK: {{.*}}clang{{.*}}"-target-cpu" "x86-64"{{.*}}"-dependency-file" 
"tmp.d"
+
+void main(){}

>From 70eee8d54d575627cc5a1baef56656c15eabd613 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Mon, 10 Feb 2025 11:36:42 +0530
Subject: [PATCH 3/4] remove filecheck

---
 clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip 
b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
index 9dd4b6a4601a01e..3e953f2171571e2 100644
--- a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -1,4 +1,4 @@
-// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s
+// RUN: %clang -### --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d %s 2>&1
 
 // CHECK: Build config:
 // CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" 
"tmp.d"

>From dd9ac40cc36a28f9d7b85e698a3cdeb31ac9edcd Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Mon, 10 Feb 2025 12:06:00 +0530
Subject: [PATCH 4/4] adding new flags


[clang] [Driver][HIP] Do not pass -dependency-file flag for HIP Device offloading test (PR #126471)

2025-02-09 Thread Aniket Lal via cfe-commits

https://github.com/lalaniket8 updated 
https://github.com/llvm/llvm-project/pull/126471

>From 7be637fa9fcde8977f650e208c7ddc1495080941 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Tue, 4 Feb 2025 12:13:20 +0530
Subject: [PATCH 1/5] [Driver][HIP] Do not pass -dependency-file flag for HIP
 Device offloading

When we launch hipcc with multiple offload architectures along with -MF 
dep_file flag, the clang compilation invocations for host and device offloads 
write to the same dep_file, and can lead to collision during file IO 
operations. This can typically happen during large workloads.
This commit provides a fix to generate dep_file only in host compilation.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 30 ++-
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0a6756eadba317b..66acd2f7b91a577 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1013,21 +1013,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 ArgM = ArgMD;
 
   if (ArgM) {
-// Determine the output location.
-const char *DepFile;
-if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
-  DepFile = MF->getValue();
-  C.addFailureResultFile(DepFile, &JA);
-} else if (Output.getType() == types::TY_Dependencies) {
-  DepFile = Output.getFilename();
-} else if (!ArgMD) {
-  DepFile = "-";
-} else {
-  DepFile = getDependencyFileName(Args, Inputs);
-  C.addFailureResultFile(DepFile, &JA);
+if (!JA.isDeviceOffloading(Action::OFK_HIP)) {
+  // Determine the output location.
+  const char *DepFile;
+  if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
+DepFile = MF->getValue();
+C.addFailureResultFile(DepFile, &JA);
+  } else if (Output.getType() == types::TY_Dependencies) {
+DepFile = Output.getFilename();
+  } else if (!ArgMD) {
+DepFile = "-";
+  } else {
+DepFile = getDependencyFileName(Args, Inputs);
+C.addFailureResultFile(DepFile, &JA);
+  }
+  CmdArgs.push_back("-dependency-file");
+  CmdArgs.push_back(DepFile);
 }
-CmdArgs.push_back("-dependency-file");
-CmdArgs.push_back(DepFile);
 
 bool HasTarget = false;
 for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {

>From 5c52e3a065d0c6e3bf59c450102ae95595ed5b10 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Wed, 5 Feb 2025 14:49:50 +0530
Subject: [PATCH 2/5] Adding littest

---
 .../dep-file-flag-with-multiple-offload-archs.hip   | 13 +
 1 file changed, 13 insertions(+)
 create mode 100644 
clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip

diff --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip 
b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
new file mode 100644
index 000..9dd4b6a4601a01e
--- /dev/null
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -0,0 +1,13 @@
+// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s
+
+// CHECK: Build config:
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1030"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1100"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1100"
+// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1101"{{.*}}"-dependency-file" 
"tmp.d"
+// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1101"
+// CHECK: {{.*}}clang-offload-bundler
+// CHECK: {{.*}}clang{{.*}}"-target-cpu" "x86-64"{{.*}}"-dependency-file" 
"tmp.d"
+
+void main(){}

>From 70eee8d54d575627cc5a1baef56656c15eabd613 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Mon, 10 Feb 2025 11:36:42 +0530
Subject: [PATCH 3/5] remove filecheck

---
 clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip 
b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
index 9dd4b6a4601a01e..3e953f2171571e2 100644
--- a/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
+++ b/clang/test/Driver/dep-file-flag-with-multiple-offload-archs.hip
@@ -1,4 +1,4 @@
-// RUN: %clang -### -x hip --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d -v %s 2>&1 | FileCheck %s
+// RUN: %clang -### --offload-arch=gfx1030 --offload-arch=gfx1100 
--offload-arch=gfx1101 -MD -MF tmp.d %s 2>&1
 
 // CHECK: Build config:
 // CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" 
"tmp.d"

>From dd9ac40cc36a28f9d7b85e698a3cdeb31ac9edcd Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Mon, 10 Feb 2025 12:06:00 +0530
Subject: [PATCH 4/5] adding new flags


[clang-tools-extra] [clang-tidy] Add performance-redundant-lookup check (PR #125420)

2025-02-09 Thread Balazs Benics via cfe-commits

steakhal wrote:

I think this case would be caught by the static analyzer based implementation.

There the loop would be unrolled about 3-4 times, so the checker should get to 
see the redundant lookups.

I'll check if my assessment is correct.

But I decided that the complexity does not worth the CSA based solution 
compared to the AST based.

Both has their ups and downs.

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


[clang] [Clang] Forward `-Xarch_ -Wl,foo` for GPU toolchains (PR #126248)

2025-02-09 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> And just now another failure: 
> https://lab.llvm.org/buildbot/#/builders/190/builds/14342

Honestly, I don't know. I'd say that it's because we don't support offloading 
on Darwin, but the triple is supposed to be x64. I could probably just set the 
test to unsupported for darwin since GPU offloading isn't supported there.

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


[clang] a32efd8 - [Clang] Disable failing offload test on darwin

2025-02-09 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2025-02-09T07:32:50-06:00
New Revision: a32efd8edc6ec5f80ffa16b3d4e52e6407d5fe99

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

LOG: [Clang] Disable failing offload test on darwin

Summary:
We don't support offloading on Darwin. This fails because there's some
handling missing somewhere else that likely won't ever be added.

Added: 


Modified: 
clang/test/Driver/offload-Xarch.c

Removed: 




diff  --git a/clang/test/Driver/offload-Xarch.c 
b/clang/test/Driver/offload-Xarch.c
index 8856dac1984650..0f8f40a5cbd74d 100644
--- a/clang/test/Driver/offload-Xarch.c
+++ b/clang/test/Driver/offload-Xarch.c
@@ -1,3 +1,5 @@
+// UNSUPPORTED: target={{.*darwin.*}}
+
 // RUN: %clang --target=x86_64-unknown-linux-gnu -x cuda %s -Xarch_nvptx64 -O3 
-S -nogpulib -nogpuinc -### 2>&1 | FileCheck -check-prefix=O3ONCE %s
 // RUN: %clang -x cuda %s -Xarch_device -O3 -S -nogpulib -nogpuinc -### 2>&1 | 
FileCheck -check-prefix=O3ONCE %s
 // RUN: %clang -x hip %s -Xarch_amdgcn -O3 -S -nogpulib -nogpuinc -### 2>&1 | 
FileCheck -check-prefix=O3ONCE %s



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


[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread via cfe-commits

https://github.com/StarOne01 updated 
https://github.com/llvm/llvm-project/pull/123495

>From ea6c9ca9cffbf4327fc7bab85e37e2a3c2c0f0cd Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 07:28:24 +0530
Subject: [PATCH 1/8] [clang][Sema] Add diagnostic note for function-like
 macros requiring parentheses

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaExpr.cpp  | 15 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index bcae9e9f3009387..d9c8fcc66acf280 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5961,6 +5961,8 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
+def note_function_like_macro_requires_parens : Note<
+  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3cd4010740d1944..dff03ac31ef2aa6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2522,6 +2522,19 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 DC = DC->getLookupParent();
   }
 
+  // Check whether a similar function-like macro exists and suggest it
+  if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
+if (II->hasMacroDefinition()) {
+  MacroInfo *MI = PP.getMacroInfo(II);
+  if (MI && MI->isFunctionLike()) {
+Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+<< II->getName();
+return true;
+  }
+}
+  }
+
   // We didn't find anything, so try to correct for a typo.
   TypoCorrection Corrected;
   if (S && Out) {
@@ -2632,7 +2645,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-
+  
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;

>From c274178a0ce3a510eaaa9390b277b860bcc5a2a9 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 08:30:39 +0530
Subject: [PATCH 2/8] [clang][Tests] Modify tests for function-like macros
 according to the new behavior and Format the changes

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td| 5 +++--
 clang/lib/Sema/SemaExpr.cpp | 7 ---
 clang/test/Preprocessor/macro_with_initializer_list.cpp | 6 --
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d9c8fcc66acf280..697b92d32524007 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5961,8 +5961,9 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
-def note_function_like_macro_requires_parens : Note<
-  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
+def note_function_like_macro_requires_parens
+: Note<"'%0' exists, but as a function-like macro; perhaps, did you forget 
"
+   "the parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index dff03ac31ef2aa6..da894dd3a6d6a6c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2527,8 +2527,9 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 if (II->hasMacroDefinition()) {
   MacroInfo *MI = PP.getMacroInfo(II);
   if (MI && MI->isFunctionLike()) {
-Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
-Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+Diag(R.getNameLoc(), diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(),
+ diag::note_function_like_macro_requires_parens)
 << II->getName();
 return true;
   }
@@ -2645,7 +2646,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-  
+
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;
diff --git a/clang/test/Preprocessor/macro_with_initializer_list.cpp 
b/clang/test/Preprocessor/macr

[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread via cfe-commits

https://github.com/StarOne01 updated 
https://github.com/llvm/llvm-project/pull/123495

>From ea6c9ca9cffbf4327fc7bab85e37e2a3c2c0f0cd Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 07:28:24 +0530
Subject: [PATCH 1/9] [clang][Sema] Add diagnostic note for function-like
 macros requiring parentheses

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaExpr.cpp  | 15 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index bcae9e9f3009387..d9c8fcc66acf280 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5961,6 +5961,8 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
+def note_function_like_macro_requires_parens : Note<
+  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3cd4010740d1944..dff03ac31ef2aa6 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2522,6 +2522,19 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 DC = DC->getLookupParent();
   }
 
+  // Check whether a similar function-like macro exists and suggest it
+  if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
+if (II->hasMacroDefinition()) {
+  MacroInfo *MI = PP.getMacroInfo(II);
+  if (MI && MI->isFunctionLike()) {
+Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+<< II->getName();
+return true;
+  }
+}
+  }
+
   // We didn't find anything, so try to correct for a typo.
   TypoCorrection Corrected;
   if (S && Out) {
@@ -2632,7 +2645,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-
+  
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;

>From c274178a0ce3a510eaaa9390b277b860bcc5a2a9 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 08:30:39 +0530
Subject: [PATCH 2/9] [clang][Tests] Modify tests for function-like macros
 according to the new behavior and Format the changes

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td| 5 +++--
 clang/lib/Sema/SemaExpr.cpp | 7 ---
 clang/test/Preprocessor/macro_with_initializer_list.cpp | 6 --
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d9c8fcc66acf280..697b92d32524007 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5961,8 +5961,9 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
-def note_function_like_macro_requires_parens : Note<
-  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
+def note_function_like_macro_requires_parens
+: Note<"'%0' exists, but as a function-like macro; perhaps, did you forget 
"
+   "the parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index dff03ac31ef2aa6..da894dd3a6d6a6c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2527,8 +2527,9 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 if (II->hasMacroDefinition()) {
   MacroInfo *MI = PP.getMacroInfo(II);
   if (MI && MI->isFunctionLike()) {
-Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
-Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+Diag(R.getNameLoc(), diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(),
+ diag::note_function_like_macro_requires_parens)
 << II->getName();
 return true;
   }
@@ -2645,7 +2646,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-  
+
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;
diff --git a/clang/test/Preprocessor/macro_with_initializer_list.cpp 
b/clang/test/Preprocessor/macr

[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread via cfe-commits

StarOne01 wrote:

> Do you have commit access for LLVM? If not you might indeed not be able to.

No, i don't have commit access.

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


[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread Mark de Wever via cfe-commits

mordante wrote:

> Thanks @mordante, for explaining, but i don't think that i could remove a 
> reviewer? Could i?

Do you have commit access for LLVM? If not you might indeed not be able to.

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


[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread via cfe-commits

StarOne01 wrote:

Thanks @mordante, for explaining. but i don't think that i could remove 
reviewer? Could i?

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


[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread Mark de Wever via cfe-commits

mordante wrote:

I've removed the ones added by your merge.

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


[clang] [AVX10.2] Fix wrong intrinsic names after rename (PR #126390)

2025-02-09 Thread Mikołaj Piróg via cfe-commits

https://github.com/mikolaj-pirog updated 
https://github.com/llvm/llvm-project/pull/126390

From c684a0a31ff8bc870991f1efb9a1a672cc6f0042 Mon Sep 17 00:00:00 2001
From: "Pirog, Mikolaj Maciej" 
Date: Sat, 8 Feb 2025 16:12:36 -0800
Subject: [PATCH 1/2] Add missing _ph to intrinsics names

---
 clang/lib/Headers/avx10_2_512convertintrin.h  |  6 ++--
 clang/lib/Headers/avx10_2convertintrin.h  | 12 +++
 .../CodeGen/X86/avx10_2_512convert-builtins.c | 18 +-
 .../CodeGen/X86/avx10_2convert-builtins.c | 36 +--
 4 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/clang/lib/Headers/avx10_2_512convertintrin.h 
b/clang/lib/Headers/avx10_2_512convertintrin.h
index 0b5fca5cda5228f..516ccc68672d636 100644
--- a/clang/lib/Headers/avx10_2_512convertintrin.h
+++ b/clang/lib/Headers/avx10_2_512convertintrin.h
@@ -213,19 +213,19 @@ _mm512_maskz_cvts2ph_hf8(__mmask64 __U, __m512h __A, 
__m512h __B) {
   (__v64qi)(__m512i)_mm512_setzero_si512());
 }
 
-static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_cvthf8(__m256i __A) {
+static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_cvthf8_ph(__m256i __A) {
   return (__m512h)__builtin_ia32_vcvthf8_2ph512_mask(
   (__v32qi)__A, (__v32hf)(__m512h)_mm512_undefined_ph(), (__mmask32)-1);
 }
 
 static __inline__ __m512h __DEFAULT_FN_ATTRS512
-_mm512_mask_cvthf8(__m512h __W, __mmask32 __U, __m256i __A) {
+_mm512_mask_cvthf8_ph(__m512h __W, __mmask32 __U, __m256i __A) {
   return (__m512h)__builtin_ia32_vcvthf8_2ph512_mask(
   (__v32qi)__A, (__v32hf)(__m512h)__W, (__mmask32)__U);
 }
 
 static __inline__ __m512h __DEFAULT_FN_ATTRS512
-_mm512_maskz_cvthf8(__mmask32 __U, __m256i __A) {
+_mm512_maskz_cvthf8_ph(__mmask32 __U, __m256i __A) {
   return (__m512h)__builtin_ia32_vcvthf8_2ph512_mask(
   (__v32qi)__A, (__v32hf)(__m512h)_mm512_setzero_ph(), (__mmask32)__U);
 }
diff --git a/clang/lib/Headers/avx10_2convertintrin.h 
b/clang/lib/Headers/avx10_2convertintrin.h
index c67a5b890f1957d..cbc02e37b0cc245 100644
--- a/clang/lib/Headers/avx10_2convertintrin.h
+++ b/clang/lib/Headers/avx10_2convertintrin.h
@@ -381,37 +381,37 @@ _mm256_maskz_cvts2ph_hf8(__mmask32 __U, __m256h __A, 
__m256h __B) {
   (__v32qi)(__m256i)_mm256_setzero_si256());
 }
 
-static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvthf8(__m128i __A) {
+static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvthf8_ph(__m128i __A) {
   return (__m128h)__builtin_ia32_vcvthf8_2ph128_mask(
   (__v16qi)__A, (__v8hf)(__m128h)_mm_undefined_ph(), (__mmask8)-1);
 }
 
-static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_mask_cvthf8(__m128h __W,
+static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_mask_cvthf8_ph(__m128h __W,
 __mmask8 __U,
 __m128i __A) {
   return (__m128h)__builtin_ia32_vcvthf8_2ph128_mask(
   (__v16qi)__A, (__v8hf)(__m128h)__W, (__mmask8)__U);
 }
 
-static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_maskz_cvthf8(__mmask8 __U,
+static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_maskz_cvthf8_ph(__mmask8 
__U,
  __m128i __A) {
   return (__m128h)__builtin_ia32_vcvthf8_2ph128_mask(
   (__v16qi)__A, (__v8hf)(__m128h)_mm_setzero_ph(), (__mmask8)__U);
 }
 
-static __inline__ __m256h __DEFAULT_FN_ATTRS256 _mm256_cvthf8(__m128i __A) {
+static __inline__ __m256h __DEFAULT_FN_ATTRS256 _mm256_cvthf8_ph(__m128i __A) {
   return (__m256h)__builtin_ia32_vcvthf8_2ph256_mask(
   (__v16qi)__A, (__v16hf)(__m256h)_mm256_undefined_ph(), (__mmask16)-1);
 }
 
 static __inline__ __m256h __DEFAULT_FN_ATTRS256
-_mm256_mask_cvthf8(__m256h __W, __mmask16 __U, __m128i __A) {
+_mm256_mask_cvthf8_ph(__m256h __W, __mmask16 __U, __m128i __A) {
   return (__m256h)__builtin_ia32_vcvthf8_2ph256_mask(
   (__v16qi)__A, (__v16hf)(__m256h)__W, (__mmask16)__U);
 }
 
 static __inline__ __m256h __DEFAULT_FN_ATTRS256
-_mm256_maskz_cvthf8(__mmask16 __U, __m128i __A) {
+_mm256_maskz_cvthf8_ph(__mmask16 __U, __m128i __A) {
   return (__m256h)__builtin_ia32_vcvthf8_2ph256_mask(
   (__v16qi)__A, (__v16hf)(__m256h)_mm256_setzero_ph(), (__mmask16)__U);
 }
diff --git a/clang/test/CodeGen/X86/avx10_2_512convert-builtins.c 
b/clang/test/CodeGen/X86/avx10_2_512convert-builtins.c
index 22503c640a727f2..dcf7bbc005a7c6c 100644
--- a/clang/test/CodeGen/X86/avx10_2_512convert-builtins.c
+++ b/clang/test/CodeGen/X86/avx10_2_512convert-builtins.c
@@ -201,22 +201,22 @@ __m512i test_mm512_maskz_cvts2ph_hf8(__mmask64 __U, 
__m512h __A, __m512h __B) {
   return _mm512_maskz_cvts2ph_hf8(__U, __A, __B);
 }
 
-__m512h test_mm512_cvthf8(__m256i __A) {
-  // CHECK-LABEL: @test_mm512_cvthf8(
+__m512h test_mm512_cvthf8_ph(__m256i __A) {
+  // CHECK-LABEL: @test_mm512_cvthf8_ph(
   // CHECK: call <32 x half> @llvm.x86.avx10.mask.vcvthf82ph512(
-  return _mm512_cvthf8(__A);
+  return _mm512_cvthf8_ph(__A);
 }
 

[clang] [llvm] [Arch64][SVE] Lower svrev_* to llvm.vector.reverse (PR #116422)

2025-02-09 Thread Jorge Botto via cfe-commits

https://github.com/jf-botto updated 
https://github.com/llvm/llvm-project/pull/116422

>From 75cc7d90fa8a7f0cde0df969577556ac1098256b Mon Sep 17 00:00:00 2001
From: Jorge Botto 
Date: Fri, 15 Nov 2024 18:56:54 +
Subject: [PATCH 1/4] Making Clang emit llvm.vector.reverse instead of
 llvm.aarch64.sve.rev

---
 clang/include/clang/Basic/arm_sve.td  |  2 +-
 .../AArch64/sve-intrinsics/acle_sve_rev.c | 44 +--
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index b20383e72e66a37..c954a6582171728 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1060,7 +1060,7 @@ let SVETargetGuard = "sve,bf16", SMETargetGuard = 
"sme,bf16" in {
 def SVEXT: SInst<"svext[_{d}]",   "dddi", "csilUcUsUiUlhfd", 
MergeNone, "aarch64_sve_ext", [VerifyRuntimeMode], [ImmCheck<2, 
ImmCheckExtract, 1>]>;
 defm SVLASTA : SVEPerm<"svlasta[_{d}]",   "sPd",  "aarch64_sve_lasta">;
 defm SVLASTB : SVEPerm<"svlastb[_{d}]",   "sPd",  "aarch64_sve_lastb">;
-def SVREV: SInst<"svrev[_{d}]",   "dd",   "csilUcUsUiUlhfd", 
MergeNone, "aarch64_sve_rev", [VerifyRuntimeMode]>;
+def SVREV: SInst<"svrev[_{d}]",   "dd",   "csilUcUsUiUlhfd", 
MergeNone, "vector_reverse", [VerifyRuntimeMode]>;
 def SVSEL: SInst<"svsel[_{d}]",   "dPdd", "csilUcUsUiUlhfd", 
MergeNone, "aarch64_sve_sel", [VerifyRuntimeMode]>;
 def SVSPLICE : SInst<"svsplice[_{d}]","dPdd", "csilUcUsUiUlhfd", 
MergeNone, "aarch64_sve_splice", [VerifyRuntimeMode]>;
 def SVTBL: SInst<"svtbl[_{d}]",   "ddu",  "csilUcUsUiUlhfd", 
MergeNone, "aarch64_sve_tbl", [VerifyRuntimeMode]>;
diff --git a/clang/test/CodeGen/AArch64/sve-intrinsics/acle_sve_rev.c 
b/clang/test/CodeGen/AArch64/sve-intrinsics/acle_sve_rev.c
index 3c0ae7df79644fa..835d1c616aebcb0 100644
--- a/clang/test/CodeGen/AArch64/sve-intrinsics/acle_sve_rev.c
+++ b/clang/test/CodeGen/AArch64/sve-intrinsics/acle_sve_rev.c
@@ -24,12 +24,12 @@
 
 // CHECK-LABEL: @test_svrev_s8(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.rev.nxv16i8( [[OP:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.reverse.nxv16i8( [[OP:%.*]])
 // CHECK-NEXT:ret  [[TMP0]]
 //
 // CPP-CHECK-LABEL: @_Z13test_svrev_s8u10__SVInt8_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.rev.nxv16i8( [[OP:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.reverse.nxv16i8( [[OP:%.*]])
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint8_t test_svrev_s8(svint8_t op) MODE_ATTR
@@ -39,12 +39,12 @@ svint8_t test_svrev_s8(svint8_t op) MODE_ATTR
 
 // CHECK-LABEL: @test_svrev_s16(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.rev.nxv8i16( [[OP:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.reverse.nxv8i16( [[OP:%.*]])
 // CHECK-NEXT:ret  [[TMP0]]
 //
 // CPP-CHECK-LABEL: @_Z14test_svrev_s16u11__SVInt16_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.rev.nxv8i16( [[OP:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.reverse.nxv8i16( [[OP:%.*]])
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint16_t test_svrev_s16(svint16_t op) MODE_ATTR
@@ -54,12 +54,12 @@ svint16_t test_svrev_s16(svint16_t op) MODE_ATTR
 
 // CHECK-LABEL: @test_svrev_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.rev.nxv4i32( [[OP:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.reverse.nxv4i32( [[OP:%.*]])
 // CHECK-NEXT:ret  [[TMP0]]
 //
 // CPP-CHECK-LABEL: @_Z14test_svrev_s32u11__SVInt32_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.rev.nxv4i32( [[OP:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.reverse.nxv4i32( [[OP:%.*]])
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint32_t test_svrev_s32(svint32_t op) MODE_ATTR
@@ -69,12 +69,12 @@ svint32_t test_svrev_s32(svint32_t op) MODE_ATTR
 
 // CHECK-LABEL: @test_svrev_s64(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.rev.nxv2i64( [[OP:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.reverse.nxv2i64( [[OP:%.*]])
 // CHECK-NEXT:ret  [[TMP0]]
 //
 // CPP-CHECK-LABEL: @_Z14test_svrev_s64u11__SVInt64_t(
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.rev.nxv2i64( [[OP:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.reverse.nxv2i64( [[OP:%.*]])
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint64_t test_svrev_s64(svint64_t op) MODE_ATTR
@@ -84,12 +84,12 @@ svint64_t test_svrev_s64(svint64_t op) MODE_ATTR
 
 // CHECK-LABEL: @test_svrev_u8(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarc

[clang] [llvm] [Arch64][SVE] Lower svrev_* to llvm.vector.reverse (PR #116422)

2025-02-09 Thread Jorge Botto via cfe-commits


@@ -1060,7 +1060,7 @@ let SVETargetGuard = "sve,bf16", SMETargetGuard = 
"sme,bf16" in {
 def SVEXT: SInst<"svext[_{d}]",   "dddi", "csilUcUsUiUlhfd", 
MergeNone, "aarch64_sve_ext", [VerifyRuntimeMode], [ImmCheck<2, 
ImmCheckExtract, 1>]>;
 defm SVLASTA : SVEPerm<"svlasta[_{d}]",   "sPd",  "aarch64_sve_lasta">;
 defm SVLASTB : SVEPerm<"svlastb[_{d}]",   "sPd",  "aarch64_sve_lastb">;
-def SVREV: SInst<"svrev[_{d}]",   "dd",   "csilUcUsUiUlhfd", 
MergeNone, "aarch64_sve_rev", [VerifyRuntimeMode]>;
+def SVREV: SInst<"svrev[_{d}]",   "dd",   "csilUcUsUiUlhfd", 
MergeNone, "vector_reverse", [VerifyRuntimeMode]>;

jf-botto wrote:

Thank you for your comment and the explanation. I've fixed PR accordingly.

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


[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread Mark de Wever via cfe-commits

mordante wrote:

> Okay, i have no idea what just happened, why was everyone asked for review? 
> BTW, got everything resolved
> 
> * Add recommended tests.
> 
> * Made the diagnostic message clear and concise.
> 
> * Add release notes
> 
> 
> Also, i see the typo correction is unpredictable as I addressed above, is 
> that a expected behaviour?

Merging main into your branch tends to do that. Please remove the unwanted 
reviewers.
When you rebase your branch this doesn't happen.

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


[clang] [libc] [libcxx] [lldb] [llvm] [doc] Add Discord invite link alongside channel links (PR #126352)

2025-02-09 Thread Mark de Wever via cfe-commits

https://github.com/mordante approved this pull request.

Thanks, LGTM!

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


[clang] [AVX10.2] Fix wrong intrinsic names after rename (PR #126390)

2025-02-09 Thread Mikołaj Piróg via cfe-commits

mikolaj-pirog wrote:

> Good catch!

Thanks! I have fixed the formatting 

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


[clang] [AST] Avoid repeated hash lookups (NFC) (PR #126400)

2025-02-09 Thread Nikita Popov via cfe-commits

https://github.com/nikic approved this pull request.


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


[clang] [clang][Sema] Add diagnostic note for reference of function-like macros requiring without parentheses (PR #123495)

2025-02-09 Thread via cfe-commits

https://github.com/StarOne01 updated 
https://github.com/llvm/llvm-project/pull/123495

>From 6f2ce4c05c0e03b1c18c694ddea97dac184e2218 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 07:28:24 +0530
Subject: [PATCH 1/7] [clang][Sema] Add diagnostic note for function-like
 macros requiring parentheses

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaExpr.cpp  | 15 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index db54312ad965e89..9d98cd2d8bbc881 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5936,6 +5936,8 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
+def note_function_like_macro_requires_parens : Note<
+  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ae40895980d90a9..f9dd731d59a2dd7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2509,6 +2509,19 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 DC = DC->getLookupParent();
   }
 
+  // Check whether a similar function-like macro exists and suggest it
+  if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
+if (II->hasMacroDefinition()) {
+  MacroInfo *MI = PP.getMacroInfo(II);
+  if (MI && MI->isFunctionLike()) {
+Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+<< II->getName();
+return true;
+  }
+}
+  }
+
   // We didn't find anything, so try to correct for a typo.
   TypoCorrection Corrected;
   if (S && Out) {
@@ -2619,7 +2632,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-
+  
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;

>From 8e90d9a0a227442d1220f1d6f521f81b6397e146 Mon Sep 17 00:00:00 2001
From: Prashanth 
Date: Sun, 19 Jan 2025 08:30:39 +0530
Subject: [PATCH 2/7] [clang][Tests] Modify tests for function-like macros
 according to the new behavior and Format the changes

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td| 5 +++--
 clang/lib/Sema/SemaExpr.cpp | 7 ---
 clang/test/Preprocessor/macro_with_initializer_list.cpp | 6 --
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9d98cd2d8bbc881..37a9a67ac1efba8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5936,8 +5936,9 @@ def err_fold_expression_limit_exceeded: Error<
   "instantiating fold expression with %0 arguments exceeded expression nesting 
"
   "limit of %1">, DefaultFatal, NoSFINAE;
 
-def note_function_like_macro_requires_parens : Note<
-  "'%0' exists, but as a function-like macro; perhaps, did you forget the 
parentheses?">;
+def note_function_like_macro_requires_parens
+: Note<"'%0' exists, but as a function-like macro; perhaps, did you forget 
"
+   "the parentheses?">;
 def err_unexpected_typedef : Error<
   "unexpected type name %0: expected expression">;
 def err_unexpected_namespace : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f9dd731d59a2dd7..44bab3e47233cb0 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2514,8 +2514,9 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
 if (II->hasMacroDefinition()) {
   MacroInfo *MI = PP.getMacroInfo(II);
   if (MI && MI->isFunctionLike()) {
-Diag( R.getNameLoc() ,diag::err_undeclared_var_use) << II->getName();
-Diag(MI->getDefinitionLoc(), 
diag::note_function_like_macro_requires_parens)
+Diag(R.getNameLoc(), diag::err_undeclared_var_use) << II->getName();
+Diag(MI->getDefinitionLoc(),
+ diag::note_function_like_macro_requires_parens)
 << II->getName();
 return true;
   }
@@ -2632,7 +2633,7 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec 
&SS, LookupResult &R,
   << SS.getRange();
 return true;
   }
-  
+
   // Give up, we can't recover.
   Diag(R.getNameLoc(), diagnostic) << Name;
   return true;
diff --git a/clang/test/Preprocessor/macro_with_initializer_list.cpp 
b/clang/test/Preprocessor/macr

  1   2   >