[clang] [llvm] [MIPS] Add MIPS i6400 and i6500 processors (PR #130587)

2025-03-11 Thread Mallikarjuna Gouda via cfe-commits

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


[clang] [flang] [flang] Align `-x` language modes with `gfortran` (PR #130268)

2025-03-11 Thread Iñaki Amatria Barral via cfe-commits

inaki-amatria wrote:

> This LGTM now when @tarunprabhu is happy, thanks for seeing this through 
> despite my lengthy comments!

Thank you for the quick review, David! I also appreciate your patience with my 
lengthy comments. I was so caught up in the fixed-form assumption that I failed 
to realize that reverting the patch I had intended to undo in the previous PR 
would introduce a regression on your side. I truly appreciate your time and 
insights!

> This isn't to hold up this patch, but as a separate thought: I wonder if 
> there's even any reason to have `types::TY_PP_Fortran` and 
> `types::TY_Fortran`? Do we ever actually treat them differently..? It seems 
> we always decide whether to preprocess or not based on other criteria

As for your separate thought: I agree that this part of the code might benefit 
from a second look.

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


[clang] [alpha.webkit.UnretainedCallArgsChecker] Add a checker for NS or CF type call arguments. (PR #128586)

2025-03-11 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

> This PR adds alpha.webkit.UnretainedCallArgsChecker by generalizing 
> RawPtrRefLocalVarsChecker.
Do you mean RawPtrRefCallArgsChecker?

Oh yeah, not sure how I'm gonna fix the typo in a commit message other than 
force pushing it though.

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


[clang-tools-extra] [clang-tidy] 'modernize-use-starts-ends-with': fixed false positives on `find` and `rfind` (PR #129564)

2025-03-11 Thread Baranov Victor via cfe-commits

vbvictor wrote:

Reverted style changes in `ReleaseNotes.rst`, created new PR for cleanup: 
https://github.com/llvm/llvm-project/pull/130626.

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


[clang] [libc] [Clang] Add width handling for shuffle helper (PR #125896)

2025-03-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-s390x-linux-multistage` running on `systemz-1` while building 
`clang,libc` at step 5 "ninja check 1".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/98/builds/1124


Here is the relevant piece of the build log for the reference

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clang :: Headers/gpuintrin.c' FAILED 

Exit Code: 2

Command Output (stderr):
--
RUN: at line 2: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/bin/clang 
-cc1 -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/lib/clang/21/include
 -nostdsysteminc -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/Inputs/include
-internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/../../lib/Headers/
-triple amdgcn-amd-amdhsa -emit-llvm 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c
 -o -  | 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/bin/FileCheck
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c
 --check-prefix=AMDGPU
+ /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/bin/clang 
-cc1 -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/lib/clang/21/include
 -nostdsysteminc -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/Inputs/include
 -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/../../lib/Headers/
 -triple amdgcn-amd-amdhsa -emit-llvm 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c
 -o -
+ 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/bin/FileCheck
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c
 --check-prefix=AMDGPU
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c:103:35:
 error: too few arguments to function call, expected 4, have 3
  103 |   __gpu_shuffle_idx_u32(-1, -1, -1);
  |   ~   ^
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/lib/clang/21/include/amdgpuintrin.h:148:1:
 note: '__gpu_shuffle_idx_u32' declared here
  148 | __gpu_shuffle_idx_u32(uint64_t __lane_mask, uint32_t __idx, uint32_t 
__x,
  | ^ 
~~~
  149 |   uint32_t __width) {
  |   
1 error generated.
FileCheck error: '' is empty.
FileCheck command line:  
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/bin/FileCheck
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c
 --check-prefix=AMDGPU

--



Step 11 (ninja check 2) failure: stage 2 checked (failure)
 TEST 'Clang :: Headers/gpuintrin.c' FAILED 

Exit Code: 2

Command Output (stderr):
--
RUN: at line 2: 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/bin/clang 
-cc1 -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/lib/clang/21/include
 -nostdsysteminc -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/Inputs/include
-internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/../../lib/Headers/
-triple amdgcn-amd-amdhsa -emit-llvm 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c
 -o -  | 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/bin/FileCheck
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c
 --check-prefix=AMDGPU
+ /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/bin/clang 
-cc1 -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/lib/clang/21/include
 -nostdsysteminc -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/Inputs/include
 -internal-isystem 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/../../lib/Headers/
 -triple amdgcn-amd-amdhsa -emit-llvm 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c
 -o -
+ 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/bin/FileCheck
 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/clang/test/Headers/gpuintrin.c
 --check-prefix=AMDGPU
/home/uweigand/sandbox/buildbot/clang-s390x-linux-

[clang-tools-extra] 5cfc37b - [clang-tidy][NFC]clean ConstCorrectnessCheck (#130493)

2025-03-11 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-03-11T14:53:06+08:00
New Revision: 5cfc37b3458b89927e76950c9498152ab729803e

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

LOG: [clang-tidy][NFC]clean ConstCorrectnessCheck (#130493)

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 6e412e576e5f9..dbe59233df699 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -136,16 +136,14 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
 
   VariableCategory VC = VariableCategory::Value;
-  if (Variable->getType()->isReferenceType())
+  const QualType VT = Variable->getType();
+  if (VT->isReferenceType())
 VC = VariableCategory::Reference;
-  if (Variable->getType()->isPointerType())
+  else if (VT->isPointerType())
 VC = VariableCategory::Pointer;
-  if (Variable->getType()->isArrayType()) {
-if (const auto *ArrayT = dyn_cast(Variable->getType())) {
-  if (ArrayT->getElementType()->isPointerType())
-VC = VariableCategory::Pointer;
-}
-  }
+  else if (const auto *ArrayT = dyn_cast(VT))
+if (ArrayT->getElementType()->isPointerType())
+  VC = VariableCategory::Pointer;
 
   // Each variable can only be in one category: Value, Pointer, Reference.
   // Analysis can be controlled for every category.



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


[clang] [flang] [flang] Align `-x` language modes with `gfortran` (PR #130268)

2025-03-11 Thread Iñaki Amatria Barral via cfe-commits

https://github.com/inaki-amatria updated 
https://github.com/llvm/llvm-project/pull/130268

From 3753b14814c845ab695ffbe985f8b2fd5a478de2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?I=C3=B1aki=20Amatria=20Barral?= 
Date: Fri, 7 Mar 2025 08:45:05 +0100
Subject: [PATCH 1/2] [flang] Remove implicit assumption of fixed-form

This change ensures that flang no longer assumes fixed-form when using
`-x f95`. The only case where fixed-form is still assumed is when
`-x f95` is used with `.i` files, unless explicitly overridden by the
user.
---
 clang/lib/Driver/ToolChains/Flang.cpp|  9 +++--
 .../Driver/dash-x-f95-do-not-assume-fixed-form.f90   | 12 
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Driver/dash-x-f95-do-not-assume-fixed-form.f90

diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index d4fea633d0edf..3ee305fc0460d 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -817,8 +817,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   // 'flang -E' always produces output that is suitable for use as fixed form
   // Fortran. However it is only valid free form source if the original is also
-  // free form.
-  if (InputType == types::TY_PP_Fortran &&
+  // free form. Ensure this logic does not incorrectly assume fixed-form for
+  // cases where it shouldn't, such as `flang -x f95 foo.f90`.
+  bool isAtemporaryPreprocessedFile =
+  Input.isFilename() &&
+  llvm::sys::path::extension(Input.getFilename())
+  .ends_with(types::getTypeTempSuffix(InputType, /*CLStyle=*/false));
+  if (InputType == types::TY_PP_Fortran && isAtemporaryPreprocessedFile &&
   !Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form))
 CmdArgs.push_back("-ffixed-form");
 
diff --git a/flang/test/Driver/dash-x-f95-do-not-assume-fixed-form.f90 
b/flang/test/Driver/dash-x-f95-do-not-assume-fixed-form.f90
new file mode 100644
index 0..d6faa4b5c00ae
--- /dev/null
+++ b/flang/test/Driver/dash-x-f95-do-not-assume-fixed-form.f90
@@ -0,0 +1,12 @@
+! This test verifies that using `-x f95` does not cause the driver to assume
+! this file is in fixed-form.
+
+program main
+  print *, "Hello, World!"
+end
+
+! RUN: %flang -### -x f95 %s 2>&1 | FileCheck --check-prefix=PRINT-PHASES %s
+! PRINT-PHASES-NOT: -ffixed-form
+
+! RUN: %flang -Werror -fsyntax-only -x f95 %s 2>&1 | FileCheck 
--check-prefix=COMPILE --allow-empty %s
+! COMPILE-NOT: error

From 91f1deeb01cf23cf415c8dd31745630ec591e432 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?I=C3=B1aki=20Amatria=20Barral?= 
Date: Fri, 7 Mar 2025 08:57:30 +0100
Subject: [PATCH 2/2] [flang] Ensure `-x f95-cpp-input` enables `-cpp`

This change ensures that specifying `-x f95-cpp-input` automatically
enables `-cpp`, making `flang`'s behavior consistent with `gfortran`.

`flang/test/Driver/input-from-stdin/input-from-stdin.f90` changes
because the driver assumes `-x f95-cpp-input` for ``. Therefore,
after this patch, Fortran source that comes from `` will now be
preprocessed.
---
 flang/lib/Frontend/CompilerInvocation.cpp |  6 
 flang/test/Driver/dash-x-f95-cpp-input.f  | 35 +++
 .../input-from-stdin/input-from-stdin.f90 |  2 +-
 3 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/dash-x-f95-cpp-input.f

diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 8b07a50824899..1537122ddced5 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -863,6 +863,12 @@ static void 
parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts,
 (currentArg->getOption().matches(clang::driver::options::OPT_cpp))
 ? PPMacrosFlag::Include
 : PPMacrosFlag::Exclude;
+  // Enable -cpp based on -x unless explicitly disabled with -nocpp
+  if (opts.macrosFlag != PPMacrosFlag::Exclude)
+if (const auto *dashX = args.getLastArg(clang::driver::options::OPT_x))
+  opts.macrosFlag = llvm::StringSwitch(dashX->getValue())
+.Case("f95-cpp-input", PPMacrosFlag::Include)
+.Default(opts.macrosFlag);
 
   opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat);
   opts.preprocessIncludeLines =
diff --git a/flang/test/Driver/dash-x-f95-cpp-input.f 
b/flang/test/Driver/dash-x-f95-cpp-input.f
new file mode 100644
index 0..7c4689c6374d3
--- /dev/null
+++ b/flang/test/Driver/dash-x-f95-cpp-input.f
@@ -0,0 +1,35 @@
+program main
+  print *, __FILE__, __LINE__
+end
+
+! This test verifies that `flang`'s `-x` options behave like `gfortran`'s.
+! Specifically:
+! - `-x f95` should process the file based on its extension unless overridden.
+! - `-x f95-cpp-input` should behave like `-x f95` but with preprocessing
+!   (`-cpp`) enabled unless overridde

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2025-03-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `polly-x86_64-linux` 
running on `polly-x86_64-gce1` while building `llvm` at step 5 "build".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/105/builds/7318


Here is the relevant piece of the build log for the reference

```
Step 5 (build) failure: 'ninja' (failure)
...
[344/4171] Copying clang's lsxintrin.h...
[345/4171] Copying clang's hlsl/hlsl_alias_intrinsics.h...
[346/4171] Copying clang's opencl-c-base.h...
[347/4171] Copying clang's avx512vlintrin.h...
[348/4171] Copying clang's htmxlintrin.h...
[349/4171] Copying clang's htmintrin.h...
[350/4171] Copying clang's opencl-c.h...
[351/4171] Copying clang's altivec.h...
[352/4171] Copying clang's riscv_bitmanip.h...
[353/4171] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/Mustache.cpp.o
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/Mustache.cpp.o 
ccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS 
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS 
-I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.obj/lib/Support 
-I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/lib/Support
 -I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.obj/include 
-I/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/include 
-fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
-fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings 
-Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long 
-Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess 
-Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -O3 -DNDEBUG -UNDEBUG -std=c++17  
-fno-exceptions -funwind-tables -fno-rtti -MD -MT 
lib/Support/CMakeFiles/LLVMSupport.dir/Mustache.cpp.o -MF 
lib/Support/CMakeFiles/LLVMSupport.dir/Mustache.cpp.o.d -o 
lib/Support/CMakeFiles/LLVMSupport.dir/Mustache.cpp.o -c 
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/lib/Support/Mustache.cpp
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/lib/Support/Mustache.cpp:109:12:
 error: declaration of ‘{anonymous}::Accessor llvm::mustache::Token::Accessor’ 
changes meaning of ‘Accessor’ [-fpermissive]
  109 |   Accessor Accessor;
  |^~~~
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/lib/Support/Mustache.cpp:19:7:
 note: ‘Accessor’ declared here as ‘using Accessor = class 
llvm::SmallVector >’
   19 | using Accessor = SmallVector;
  |   ^~~~
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/lib/Support/Mustache.cpp:186:18:
 error: declaration of ‘const Accessor llvm::mustache::ASTNode::Accessor’ 
changes meaning of ‘Accessor’ [-fpermissive]
  186 |   const Accessor Accessor;
  |  ^~~~
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/lib/Support/Mustache.cpp:19:7:
 note: ‘Accessor’ declared here as ‘using Accessor = class 
llvm::SmallVector >’
   19 | using Accessor = SmallVector;
  |   ^~~~
In file included from 
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/lib/Support/Mustache.cpp:8:
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/include/llvm/Support/Mustache.h:
 In constructor 
‘llvm::mustache::Template::Template(llvm::mustache::Template&&)’:
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/include/llvm/Support/Mustache.h:123:12:
 warning: ‘llvm::mustache::Template::Tree’ will be initialized after [-Wreorder]
  123 |   ASTNode *Tree;
  |^~~~
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/include/llvm/Support/Mustache.h:120:26:
 warning:   ‘llvm::BumpPtrAllocator llvm::mustache::Template::AstAllocator’ 
[-Wreorder]
  120 |   llvm::BumpPtrAllocator AstAllocator;
  |  ^~~~
/home/worker/buildbot-workers/polly-x86_64-gce1/rundir/llvm.src/llvm/lib/Support/Mustache.cpp:769:1:
 warning:   when initialized here [-Wreorder]
  769 | Template::Template(Template &&Other) noexcept
  | ^~~~
[354/4171] Copying clang's riscv_corev_alu.h...
[355/4171] Copying clang's riscv_crypto.h...
[356/4171] Copying clang's s390intrin.h...
[357/4171] Copying clang's sifive_vector.h...
[358/4171] Copying clang's riscv_ntlh.h...
ninja: build stopped: subcommand failed.

```



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


[clang] [alpha.webkit.UnretainedCallArgsChecker] Add a checker for NS or CF type call arguments. (PR #130729)

2025-03-11 Thread Ryosuke Niwa via cfe-commits

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

This PR adds alpha.webkit.UnretainedCallArgsChecker by generalizing 
RawPtrRefCallArgsChecker. It checks call arguments of NS or CF types are backed 
by a RetainPtr or not. The new checker emits warnings for CF types in 
Objective-C++ code regardless of ARC and it emits warning for NS types when ARC 
is disabled.

Hard-code a few cases as safe: class and superclass properties on class 
interfaces and constant dictionary or array literals as well as the return 
value of NSClassFromString.

Finally, add the support for variadic function calls and selector invocations.

>From 10c89bccbb1d09d8db60718f426e83e249a21b80 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 24 Feb 2025 13:43:04 -0800
Subject: [PATCH] [alpha.webkit.UnretainedCallArgsChecker] Add a checker for NS
 or CF type call arguments.

This PR adds alpha.webkit.UnretainedCallArgsChecker by generalizing 
RawPtrRefCallArgsChecker.
It checks call arguments of NS or CF types are backed by a RetainPtr or not. 
The new checker
emits warnings for CF types in Objective-C++ code regardless of ARC and it 
emits warning for
NS types when ARC is disabled.

Hard-code a few cases as safe: class and superclass properties on class 
interfaces and
constant dictionary or array literals as well as the return value of 
NSClassFromString.

Finally, add the support for variadic function calls and selector invocations.
---
 clang/docs/analyzer/checkers.rst  |   6 +
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../Checkers/WebKit/ASTUtils.cpp  |  38 ++
 .../Checkers/WebKit/PtrTypesSemantics.cpp |   6 +-
 .../WebKit/RawPtrRefCallArgsChecker.cpp   | 136 +-
 .../WebKit/unretained-call-args-arc.mm|  30 ++
 .../Checkers/WebKit/unretained-call-args.mm   | 396 ++
 7 files changed, 608 insertions(+), 8 deletions(-)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm
 create mode 100644 clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index c947f26204159..e9df204480643 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3642,6 +3642,12 @@ The goal of this rule is to make sure that lifetime of 
any dynamically allocated
 
 The rules of when to use and not to use CheckedPtr / CheckedRef are same as 
alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
 
+alpha.webkit.UnretainedCallArgsChecker
+""
+The goal of this rule is to make sure that lifetime of any dynamically 
allocated NS or CF objects passed as a call argument keeps its memory region 
past the end of the call. This applies to call to any function, method, lambda, 
function pointer or functor. NS or CF objects aren't supposed to be allocated 
on stack so we check arguments for parameters of raw pointers and references to 
unretained types.
+
+The rules of when to use and not to use RetainPtr are same as 
alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
+
 alpha.webkit.UncountedLocalVarsChecker
 ""
 The goal of this rule is to make sure that any uncounted local variable is 
backed by a ref-counted object with lifetime that is strictly larger than the 
scope of the uncounted local variable. To be on the safe side we require the 
scope of an uncounted variable to be embedded in the scope of ref-counted 
object that backs it.
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 21b585169cf40..22fd97b32032b 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1781,6 +1781,10 @@ def UncheckedCallArgsChecker : 
Checker<"UncheckedCallArgsChecker">,
   HelpText<"Check unchecked call arguments.">,
   Documentation;
 
+def UnretainedCallArgsChecker : Checker<"UnretainedCallArgsChecker">,
+  HelpText<"Check unretained call arguments.">,
+  Documentation;
+
 def UncountedLocalVarsChecker : Checker<"UncountedLocalVarsChecker">,
   HelpText<"Check uncounted local variables.">,
   Documentation;
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 5e67cb29d08e4..ae0f8ad09f26e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -8,6 +8,7 @@
 
 #include "ASTUtils.h"
 #include "PtrTypesSemantics.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
@@ -28,6 +29,15 @@ bool tryToFindPtrOrigin(
 std::function isSafePtrType,
 std::function callback) {
   while (E) {
+if (auto *DRE = dyn_cast(E)) {
+  auto *ValDecl = DRE->getDecl

[clang] [flang] [flang] Align `-x` language modes with `gfortran` (PR #130268)

2025-03-11 Thread Iñaki Amatria Barral via cfe-commits


@@ -0,0 +1,35 @@
+program main
+  print *, __FILE__, __LINE__
+end
+
+! This test verifies that `flang`'s `-x` options behave like `gfortran`'s.
+! Specifically:
+! - `-x f95` should process the file based on its extension unless overridden.
+! - `-x f95-cpp-input` should behave like `-x f95` but with preprocessing
+!   (`-cpp`) enabled unless overridden.
+
+! ---
+! Ensure the file is treated as fixed-form unless explicitly set otherwise
+! ---
+! RUN: not %flang -Werror -x f95 -cpp %s 2>&1 | FileCheck 
--check-prefix=SCAN-ERROR %s
+! RUN: not %flang -Werror -x f95-cpp-input %s 2>&1 | FileCheck 
--check-prefix=SCAN-ERROR %s
+
+! SCAN-ERROR: error
+
+! RUN: %flang -Werror -x f95 -cpp -ffree-form %s 2>&1 | FileCheck 
--check-prefix=NO-SCAN-ERROR --allow-empty %s
+! RUN: %flang -Werror -x f95-cpp-input -ffree-form %s 2>&1 | FileCheck 
--check-prefix=NO-SCAN-ERROR --allow-empty %s
+
+! NO-SCAN-ERROR-NOT: error
+
+! ---
+! Ensure `-cpp` is not enabled by default unless explicitly requested
+! ---
+! RUN: not %flang -Werror -x f95 -ffree-form %s 2>&1 | FileCheck 
--check-prefix=SEMA-ERROR %s
+! RUN: not %flang -Werror -x f95-cpp-input -nocpp -ffree-form %s 2>&1 | 
FileCheck --check-prefix=SEMA-ERROR %s
+
+! SEMA-ERROR: error

inaki-amatria wrote:

Fixed. I replaced the `! CHECK: error` pattern with specific checks!

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


[clang-tools-extra] [clang-tidy] support different precisions (PR #130540)

2025-03-11 Thread Piotr Zegar via cfe-commits

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

LGTM

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


[clang] [Sema] Instantiate destructors for initialized members (PR #128866)

2025-03-11 Thread Maurice Heumann via cfe-commits


@@ -5863,6 +5869,26 @@ 
Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
  &DirectVirtualBases);
 }
 
+void Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
+  CXXRecordDecl *ClassDecl) {
+  // Ignore dependent contexts. Also ignore unions, since their members never
+  // have destructors implicitly called.
+  if (ClassDecl->isDependentContext() || ClassDecl->isUnion())
+return;
+
+  // FIXME: all the access-control diagnostics are positioned on the
+  // field/base declaration.  That's probably good; that said, the
+  // user might reasonably want to know why the destructor is being
+  // emitted, and we currently don't say.

momo5502 wrote:

@cor3ntin shall I remove it or keep it?

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


[clang] [clang-format] Add support for absl nullability macros (PR #130346)

2025-03-11 Thread Owen Pan via cfe-commits

owenca wrote:

> > I wish they had not been added to the default but can't take them off the 
> > lists for backward compatibility. I don't think we should add more. The 
> > reason is that people wouldn't be able to turn off the special meaning if 
> > they wanted to use e.g. `absl_nonnull` as a regular identifier.
> 
> What if this is limited to the Google style? +cc some folks involved in the 
> Google style @ilya-biryukov It is not yet in the style guide, but we are 
> working on getting the style guide updated.

I would have no problem with that.

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


[clang] [Sema] Instantiate destructors for initialized members (PR #128866)

2025-03-11 Thread Maurice Heumann via cfe-commits

https://github.com/momo5502 updated 
https://github.com/llvm/llvm-project/pull/128866

>From b6c1d10fb99a45f07ba044ad516c44a1b6ff4a0c Mon Sep 17 00:00:00 2001
From: Maurice Heumann 
Date: Wed, 26 Feb 2025 14:31:47 +0100
Subject: [PATCH 1/7] Instantiate destructors from initialized anonymous union
 fields

---
 clang/include/clang/Sema/Sema.h   |  2 +
 clang/lib/Sema/SemaDeclCXX.cpp| 95 ---
 clang/test/SemaCXX/cxx0x-nontrivial-union.cpp |  6 +-
 .../test/SemaCXX/union-member-destructor.cpp  | 48 ++
 4 files changed, 113 insertions(+), 38 deletions(-)
 create mode 100644 clang/test/SemaCXX/union-member-destructor.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9ac26d8728446..50ab9b07c4333 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5445,6 +5445,8 @@ class Sema final : public SemaBase {
   void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc,
   CXXRecordDecl *Record);
 
+  void MarkFieldDestructorReferenced(SourceLocation Loc, FieldDecl *Field);
+
   /// Mark destructors of virtual bases of this class referenced. In the 
Itanium
   /// C++ ABI, this is done when emitting a destructor for any non-abstract
   /// class. In the Microsoft C++ ABI, this is done any time a class's
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 1edbe62f1c79a..df38d418cba8b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -5453,10 +5453,31 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl 
*Constructor, bool AnyErrors,
NumInitializers * sizeof(CXXCtorInitializer*));
 Constructor->setCtorInitializers(baseOrMemberInitializers);
 
+SourceLocation Location = Constructor->getLocation();
+
+for (CXXCtorInitializer *Initializer : Info.AllToInit) {
+  FieldDecl *Field = Initializer->getAnyMember();
+  if (!Field)
+continue;
+
+  RecordDecl *Parent = Field->getParent();
+
+  while (Parent) {
+if (Parent->isUnion()) {
+  MarkFieldDestructorReferenced(Location, Field);
+  break;
+}
+
+if (!Parent->isAnonymousStructOrUnion() || Parent == ClassDecl) {
+  break;
+}
+
+Parent = cast(Parent->getDeclContext());
+  }
+}
 // Constructors implicitly reference the base and member
 // destructors.
-MarkBaseAndMemberDestructorsReferenced(Constructor->getLocation(),
-   Constructor->getParent());
+MarkBaseAndMemberDestructorsReferenced(Location, Constructor->getParent());
   }
 
   return HadError;
@@ -5761,6 +5782,42 @@ void Sema::ActOnMemInitializers(Decl *ConstructorDecl,
   DiagnoseUninitializedFields(*this, Constructor);
 }
 
+void Sema::MarkFieldDestructorReferenced(SourceLocation Location,
+ FieldDecl *Field) {
+  if (Field->isInvalidDecl())
+return;
+
+  // Don't destroy incomplete or zero-length arrays.
+  if (isIncompleteOrZeroLengthArrayType(Context, Field->getType()))
+return;
+
+  QualType FieldType = Context.getBaseElementType(Field->getType());
+
+  const RecordType *RT = FieldType->getAs();
+  if (!RT)
+return;
+
+  CXXRecordDecl *FieldClassDecl = cast(RT->getDecl());
+  if (FieldClassDecl->isInvalidDecl())
+return;
+  if (FieldClassDecl->hasIrrelevantDestructor())
+return;
+  // The destructor for an implicit anonymous union member is never invoked.
+  if (FieldClassDecl->isUnion() && FieldClassDecl->isAnonymousStructOrUnion())
+return;
+
+  CXXDestructorDecl *Dtor = LookupDestructor(FieldClassDecl);
+  // Dtor might still be missing, e.g because it's invalid.
+  if (!Dtor)
+return;
+  CheckDestructorAccess(Field->getLocation(), Dtor,
+PDiag(diag::err_access_dtor_field)
+<< Field->getDeclName() << FieldType);
+
+  MarkFunctionReferenced(Location, Dtor);
+  DiagnoseUseOfDecl(Dtor, Location);
+}
+
 void
 Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
  CXXRecordDecl *ClassDecl) {
@@ -5776,39 +5833,7 @@ 
Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
 
   // Non-static data members.
   for (auto *Field : ClassDecl->fields()) {
-if (Field->isInvalidDecl())
-  continue;
-
-// Don't destroy incomplete or zero-length arrays.
-if (isIncompleteOrZeroLengthArrayType(Context, Field->getType()))
-  continue;
-
-QualType FieldType = Context.getBaseElementType(Field->getType());
-
-const RecordType* RT = FieldType->getAs();
-if (!RT)
-  continue;
-
-CXXRecordDecl *FieldClassDecl = cast(RT->getDecl());
-if (FieldClassDecl->isInvalidDecl())
-  continue;
-if (FieldClassDecl->hasIrrelevantDestructor())
-  continue;
-// The destructor for an implicit anonymous

[clang] [WebKit checkers] Don't treat virtual functions as safe. (PR #129632)

2025-03-11 Thread Ryosuke Niwa via cfe-commits

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


[clang] Better diagnostics when assertion fails in `consteval` (PR #130458)

2025-03-11 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy][NFC]clean ConstCorrectnessCheck (PR #130493)

2025-03-11 Thread Carlos Galvez via cfe-commits


@@ -136,16 +136,14 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
 
   VariableCategory VC = VariableCategory::Value;
-  if (Variable->getType()->isReferenceType())
+  const QualType VT = Variable->getType();
+  if (VT->isReferenceType())
 VC = VariableCategory::Reference;
-  if (Variable->getType()->isPointerType())
+  else if (VT->isPointerType())
 VC = VariableCategory::Pointer;
-  if (Variable->getType()->isArrayType()) {
-if (const auto *ArrayT = dyn_cast(Variable->getType())) {
-  if (ArrayT->getElementType()->isPointerType())
-VC = VariableCategory::Pointer;
-}
-  }
+  else if (const auto *ArrayT = dyn_cast(VT))

carlosgalvezp wrote:

Is this allowed by out current guidelines? This `else if` blocks contains 2 
lines. I think this is rather fragile and can easily break in the future.

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


[clang] [llvm] [RISCV] Add Qualcomn uC Xqcili (load large immediates) extension (PR #130012)

2025-03-11 Thread Sudharsan Veeravalli via cfe-commits


@@ -0,0 +1,21 @@
+# Xqcili - Qualcomm uC Load Large Immediate Extension
+# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-xqcili < %s 2>&1 \

svs-quic wrote:

Please add a run line with mattr=-experimental-xqcili

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


[clang] [Clang] Implement P0963R3 "Structured binding declaration as a condition" (PR #130228)

2025-03-11 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> Hum, do we want to add tests for 
> https://cplusplus.github.io/CWG/issues/2867.html at the same time?

I'll look into that in a followup

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


[clang] [Clang] Fix the printout of CXXParenListInitExpr involving default arguments (PR #130731)

2025-03-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/130731

>From c643ba2de0bb3e5fcb6514b70c86e594badc396b Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 11 Mar 2025 14:18:20 +0800
Subject: [PATCH 1/2] [Clang] Fix the printout of CXXParenListInitExpr
 involving default arguments

The parantheses are unnecessary IMO because they should have been
handled in the parents of such expressions, e.g. in
CXXFunctionalCastExpr.

Moreover, we shouldn't join CXXDefaultInitExpr either because they
are not printed at all.
---
 clang/lib/AST/StmtPrinter.cpp  |  4 +---
 clang/test/CodeGen/p0963r3.cpp |  3 ---
 clang/test/SemaCXX/paren-list-agg-init.cpp | 18 ++
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index facdc4104c374..e0063ec5f25eb 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -2659,10 +2659,8 @@ void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
 }
 
 void StmtPrinter::VisitCXXParenListInitExpr(CXXParenListInitExpr *Node) {
-  OS << "(";
-  llvm::interleaveComma(Node->getInitExprs(), OS,
+  llvm::interleaveComma(Node->getUserSpecifiedInitExprs(), OS,
 [&](Expr *E) { PrintExpr(E); });
-  OS << ")";
 }
 
 void StmtPrinter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) 
{
diff --git a/clang/test/CodeGen/p0963r3.cpp b/clang/test/CodeGen/p0963r3.cpp
index b48b5294e093e..4a5e6c3f5d751 100644
--- a/clang/test/CodeGen/p0963r3.cpp
+++ b/clang/test/CodeGen/p0963r3.cpp
@@ -139,9 +139,6 @@ constexpr int bar(auto) {
   }();
   static_assert(value == S(1, 2));
 
-  // FIXME: The diagnostic message adds a trailing comma "static assertion 
failed due to requirement 'value == Case1::S((0, 1, ))'"
-  // static_assert(value == S(0, 1));
-
   constexpr auto value2 = [] {
 if (auto [a, b] = S(1, 2))
   return S(a, b);
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index 61afba85e1dff..c55604003bc33 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -357,3 +357,21 @@ ThroughAlias e(42);
 // beforecxx20-warning@-1 {{aggregate initialization of type 
'ThroughAlias' (aka 'int[1]') from a parenthesized list of values is a 
C++20 extension}} 
 
 }
+
+namespace CXXParenListInitExpr {
+
+struct S {
+  int a, b;
+  bool flag = false;
+
+  constexpr bool operator==(S rhs) {
+return a == rhs.a && b == rhs.b;
+  }
+};
+
+static_assert(S(1, 2) == S(1, 2));
+
+static_assert(S(1, 2) == S(3, 4));
+// expected-error@-1 {{failed due to requirement 'S(1, 2) == S(3, 4)'}}
+
+}

>From 2c6f6a193e895129151fd627ca2b490f6643126f Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 11 Mar 2025 17:43:30 +0800
Subject: [PATCH 2/2] Fix CI

---
 clang/test/SemaCXX/paren-list-agg-init.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index c55604003bc33..e5c0757d0970c 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -372,6 +372,6 @@ struct S {
 static_assert(S(1, 2) == S(1, 2));
 
 static_assert(S(1, 2) == S(3, 4));
-// expected-error@-1 {{failed due to requirement 'S(1, 2) == S(3, 4)'}}
+// expected-error@-1 {{failed due to requirement 'CXXParenListInitExpr::S(1, 
2) == CXXParenListInitExpr::S(3, 4)'}}
 
 }

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


[clang] [Clang] Add __builtin_elementwise_exp10 in the same fashion as exp/exp2 (PR #130746)

2025-03-11 Thread Juan Manuel Martinez Caamaño via cfe-commits

https://github.com/jmmartinez created 
https://github.com/llvm/llvm-project/pull/130746

Clang has __builtin_elementwise_exp and __builtin_elementwise_exp2
intrinsics, but no __builtin_elementwise_exp10.

There doesn't seem to be a good reason not to expose the exp10 flavour
of this intrinsic too.

This commit introduces this intrinsic following the same pattern as the
exp and exp2 versions.

Fixes: SWDEV-519541

From 7d2bf9087389770b496f10198a9c9b6ae275fe37 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Mon, 10 Mar 2025 15:40:00 +0100
Subject: [PATCH 1/2] [Clang][NFC] update_cc_test_checks over
 strictfp-elementwise-bulitins.cpp

---
 clang/test/CodeGen/strictfp-elementwise-bulitins.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp 
b/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
index 175ad22601839..9b92c259c9895 100644
--- a/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
+++ b/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
@@ -340,9 +340,8 @@ float4 strict_elementwise_pow(float4 a, float4 b) {
 // CHECK-LABEL: define dso_local noundef <4 x float> 
@_Z23strict_elementwise_fmodDv4_fS_
 // CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]],
-// CHECK-SAME:metadata !"round.dynamic", metadata !"fpexcept.strict") 
#[[ATTR4]]
-// CHECK-NEXT:ret <4 x float> [[TMP0]]
+// CHECK-NEXT:[[FMOD:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]], 
metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR4]]
+// CHECK-NEXT:ret <4 x float> [[FMOD]]
 //
 float4 strict_elementwise_fmod(float4 a, float4 b) {
   return __builtin_elementwise_fmod(a, b);

From 08ab1901170c5b91814c60f5bcafbb39fd9d4fa2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Mon, 10 Mar 2025 15:35:27 +0100
Subject: [PATCH 2/2] [Clang] Add __builtin_elementwise_exp10 in the same
 fashion as exp/exp2

Clang has __builtin_elementwise_exp and __builtin_elementwise_exp2
intrinsics, but no __builtin_elementwise_exp10.

There doesn't seem to be a good reason not to expose the exp10 flavour
of this intrinsic too.

This commit introduces this intrinsic following the same pattern as the
exp and exp2 versions.

Fixes: SWDEV-519541
---
 clang/docs/LanguageExtensions.rst |  1 +
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 +++
 clang/lib/Sema/SemaChecking.cpp   |  1 +
 clang/lib/Sema/SemaHLSL.cpp   |  1 +
 .../test/CodeGen/builtins-elementwise-math.c  | 15 ++
 .../CodeGen/strictfp-elementwise-bulitins.cpp | 10 ++
 clang/test/Sema/builtins-elementwise-math.c   | 20 +++
 .../SemaCXX/builtins-elementwise-math.cpp |  7 +++
 9 files changed, 64 insertions(+)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 578ee02f09b9b..7f8992dc202c3 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -786,6 +786,7 @@ of different sizes and signs is forbidden in binary and 
ternary builtins.
  T __builtin_elementwise_bitreverse(T x)return the integer represented 
after reversing the bits of x   integer types
  T __builtin_elementwise_exp(T x)   returns the base-e 
exponential, e^x, of the specified valuefloating point types
  T __builtin_elementwise_exp2(T x)  returns the base-2 
exponential, 2^x, of the specified valuefloating point types
+ T __builtin_elementwise_exp10(T x) returns the base-10 
exponential, 10^x, of the specified value  floating point types
 
  T __builtin_elementwise_sqrt(T x)  return the square root of a 
floating-point number  floating point types
  T __builtin_elementwise_roundeven(T x) round x to the nearest integer 
value in floating point format, floating point types
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2268df70927a7..2fbdfaea57ccd 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1340,6 +1340,12 @@ def ElementwiseExp2 : Builtin {
   let Prototype = "void(...)";
 }
 
+def ElementwiseExp10 : Builtin {
+  let Spellings = ["__builtin_elementwise_exp10"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 def ElementwiseFloor : Builtin {
   let Spellings = ["__builtin_elementwise_floor"];
   let Attributes = [NoThrow, Const, CustomTypeChecking];
diff --git a/clang/lib/CodeGen/CGBuiltin.

[clang] [Clang] Add __builtin_elementwise_exp10 in the same fashion as exp/exp2 (PR #130746)

2025-03-11 Thread via cfe-commits
Juan Manuel Martinez =?utf-8?q?Caamaño?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-hlsl

Author: Juan Manuel Martinez Caamaño (jmmartinez)


Changes

Clang has __builtin_elementwise_exp and __builtin_elementwise_exp2
intrinsics, but no __builtin_elementwise_exp10.

There doesn't seem to be a good reason not to expose the exp10 flavour
of this intrinsic too.

This commit introduces this intrinsic following the same pattern as the
exp and exp2 versions.

Fixes: SWDEV-519541

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


9 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+1) 
- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+3) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+1) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+1) 
- (modified) clang/test/CodeGen/builtins-elementwise-math.c (+15) 
- (modified) clang/test/CodeGen/strictfp-elementwise-bulitins.cpp (+12-3) 
- (modified) clang/test/Sema/builtins-elementwise-math.c (+20) 
- (modified) clang/test/SemaCXX/builtins-elementwise-math.cpp (+7) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 578ee02f09b9b..7f8992dc202c3 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -786,6 +786,7 @@ of different sizes and signs is forbidden in binary and 
ternary builtins.
  T __builtin_elementwise_bitreverse(T x)return the integer represented 
after reversing the bits of x   integer types
  T __builtin_elementwise_exp(T x)   returns the base-e 
exponential, e^x, of the specified valuefloating point types
  T __builtin_elementwise_exp2(T x)  returns the base-2 
exponential, 2^x, of the specified valuefloating point types
+ T __builtin_elementwise_exp10(T x) returns the base-10 
exponential, 10^x, of the specified value  floating point types
 
  T __builtin_elementwise_sqrt(T x)  return the square root of a 
floating-point number  floating point types
  T __builtin_elementwise_roundeven(T x) round x to the nearest integer 
value in floating point format, floating point types
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2268df70927a7..2fbdfaea57ccd 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1340,6 +1340,12 @@ def ElementwiseExp2 : Builtin {
   let Prototype = "void(...)";
 }
 
+def ElementwiseExp10 : Builtin {
+  let Spellings = ["__builtin_elementwise_exp10"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 def ElementwiseFloor : Builtin {
   let Spellings = ["__builtin_elementwise_floor"];
   let Attributes = [NoThrow, Const, CustomTypeChecking];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 20b793c06..b748d8e80dad0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4282,6 +4282,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_exp2:
 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
 *this, E, llvm::Intrinsic::exp2, "elt.exp2"));
+  case Builtin::BI__builtin_elementwise_exp10:
+return RValue::get(emitBuiltinWithOneOverloadedType<1>(
+*this, E, llvm::Intrinsic::exp10, "elt.exp10"));
   case Builtin::BI__builtin_elementwise_log:
 return RValue::get(emitBuiltinWithOneOverloadedType<1>(
 *this, E, llvm::Intrinsic::log, "elt.log"));
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f9926c6b4adab..5cb517a87c21a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2723,6 +2723,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
   case Builtin::BI__builtin_elementwise_cosh:
   case Builtin::BI__builtin_elementwise_exp:
   case Builtin::BI__builtin_elementwise_exp2:
+  case Builtin::BI__builtin_elementwise_exp10:
   case Builtin::BI__builtin_elementwise_floor:
   case Builtin::BI__builtin_elementwise_log:
   case Builtin::BI__builtin_elementwise_log2:
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index aff349a932eec..074290a427acb 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2641,6 +2641,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   case Builtin::BI__builtin_elementwise_cosh:
   case Builtin::BI__builtin_elementwise_exp:
   case Builtin::BI__builtin_elementwise_exp2:
+  case Builtin::BI__builtin_elementwise_exp10:
   case Builtin::BI__builtin_elementwise_floor:
   case Builtin::BI__builtin_elementwise_fmod:
   case Builtin::BI__builtin_elementwise_log:
diff

[clang] [Clang][NFC] update_cc_test_checks over strictfp-elementwise-bulitins.cpp (PR #130747)

2025-03-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Juan Manuel Martinez Caamaño (jmmartinez)


Changes



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


1 Files Affected:

- (modified) clang/test/CodeGen/strictfp-elementwise-bulitins.cpp (+2-3) 


``diff
diff --git a/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp 
b/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
index 175ad22601839..9b92c259c9895 100644
--- a/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
+++ b/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
@@ -340,9 +340,8 @@ float4 strict_elementwise_pow(float4 a, float4 b) {
 // CHECK-LABEL: define dso_local noundef <4 x float> 
@_Z23strict_elementwise_fmodDv4_fS_
 // CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]],
-// CHECK-SAME:metadata !"round.dynamic", metadata !"fpexcept.strict") 
#[[ATTR4]]
-// CHECK-NEXT:ret <4 x float> [[TMP0]]
+// CHECK-NEXT:[[FMOD:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]], 
metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR4]]
+// CHECK-NEXT:ret <4 x float> [[FMOD]]
 //
 float4 strict_elementwise_fmod(float4 a, float4 b) {
   return __builtin_elementwise_fmod(a, b);

``




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


[clang] [Clang][NFC] update_cc_test_checks over strictfp-elementwise-bulitins.cpp (PR #130747)

2025-03-11 Thread Juan Manuel Martinez Caamaño via cfe-commits

https://github.com/jmmartinez created 
https://github.com/llvm/llvm-project/pull/130747

None

From 7d2bf9087389770b496f10198a9c9b6ae275fe37 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Mon, 10 Mar 2025 15:40:00 +0100
Subject: [PATCH] [Clang][NFC] update_cc_test_checks over
 strictfp-elementwise-bulitins.cpp

---
 clang/test/CodeGen/strictfp-elementwise-bulitins.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp 
b/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
index 175ad22601839..9b92c259c9895 100644
--- a/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
+++ b/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
@@ -340,9 +340,8 @@ float4 strict_elementwise_pow(float4 a, float4 b) {
 // CHECK-LABEL: define dso_local noundef <4 x float> 
@_Z23strict_elementwise_fmodDv4_fS_
 // CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]],
-// CHECK-SAME:metadata !"round.dynamic", metadata !"fpexcept.strict") 
#[[ATTR4]]
-// CHECK-NEXT:ret <4 x float> [[TMP0]]
+// CHECK-NEXT:[[FMOD:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]], 
metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR4]]
+// CHECK-NEXT:ret <4 x float> [[FMOD]]
 //
 float4 strict_elementwise_fmod(float4 a, float4 b) {
   return __builtin_elementwise_fmod(a, b);

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


[clang] [NFC][analyzer] OOB test consolidation IV: rename files (PR #129697)

2025-03-11 Thread Donát Nagy via cfe-commits

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


[clang] [Clang] Add __builtin_elementwise_exp10 in the same fashion as exp/exp2 (PR #130746)

2025-03-11 Thread Juan Manuel Martinez Caamaño via cfe-commits


@@ -340,9 +350,8 @@ float4 strict_elementwise_pow(float4 a, float4 b) {
 // CHECK-LABEL: define dso_local noundef <4 x float> 
@_Z23strict_elementwise_fmodDv4_fS_
 // CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]],
-// CHECK-SAME:metadata !"round.dynamic", metadata !"fpexcept.strict") 
#[[ATTR4]]
-// CHECK-NEXT:ret <4 x float> [[TMP0]]
+// CHECK-NEXT:[[FMOD:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]], 
metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR4]]

jmmartinez wrote:

These 2 lines are updated separately by 
https://github.com/llvm/llvm-project/pull/130747

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


[clang] [clang-tools-extra] [AstMatcher]`templateArgumentCountIs` support `FunctionDecl` (PR #130416)

2025-03-11 Thread Aaron Ballman via cfe-commits

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

Generally LG, but I did have a testing and commenting request.

Please also add a note to `clang/docs/ReleaseNotes.rst` so users know about the 
new match.

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


[clang] [NFC][analyzer] Split [[assume]] tests to a separate file (PR #130763)

2025-03-11 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

No problem, in git we can eventually track down and resolve everything.

However, let's try to pay attention to putting logically separate tests into 
separate files -- our tests are badly disorganized, but we can gradually 
improve the average quality if we spend some attention on this.

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


[clang] a7d7db7 - [NFC][analyzer] OOB test consolidation IV: rename files (#129697)

2025-03-11 Thread via cfe-commits

Author: Donát Nagy
Date: 2025-03-11T13:54:41+01:00
New Revision: a7d7db71db2f4b1bca2484f2039ac57b01566a0e

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

LOG: [NFC][analyzer] OOB test consolidation IV: rename files (#129697)

This commit finishes the reorganization of the tests for the checker
`security.ArrayBound`.

Previously these tests were all named `out-of-bounds-*` which was only
weakly connected to the checker name; this commit moves them to a
directory named after the checker (`ArrayBound`). I decided to use a
directory instead of the more common filename prefix ("poor man's
directory") system because it seems to be a more natural use of the
filesystem and there are already a few precedents for it.

I also added (or edited) comments at the beginning of each test file to
describe their purpose; and I added a single new testcase to highlight
that the assumption note tags can be added to reports by any checker.
(Previously all tests in the file triggered out-of-bounds reports to
reveal the note tags; but that was just for convenience.)

Added: 
clang/test/Analysis/ArrayBound/assumption-reporting.c
clang/test/Analysis/ArrayBound/assumptions.c
clang/test/Analysis/ArrayBound/brief-tests.c
clang/test/Analysis/ArrayBound/cplusplus.cpp
clang/test/Analysis/ArrayBound/verbose-tests.c

Modified: 


Removed: 
clang/test/Analysis/out-of-bounds-constraint-check.c
clang/test/Analysis/out-of-bounds-diagnostics.c
clang/test/Analysis/out-of-bounds-new.cpp
clang/test/Analysis/out-of-bounds-notes.c
clang/test/Analysis/out-of-bounds.c



diff  --git a/clang/test/Analysis/out-of-bounds-notes.c 
b/clang/test/Analysis/ArrayBound/assumption-reporting.c
similarity index 88%
rename from clang/test/Analysis/out-of-bounds-notes.c
rename to clang/test/Analysis/ArrayBound/assumption-reporting.c
index 7256beb7e893e..d687886ada1ae 100644
--- a/clang/test/Analysis/out-of-bounds-notes.c
+++ b/clang/test/Analysis/ArrayBound/assumption-reporting.c
@@ -1,6 +1,16 @@
 // RUN: %clang_analyze_cc1 -Wno-array-bounds -analyzer-output=text\
 // RUN: -analyzer-checker=core,security.ArrayBound,unix.Malloc,optin.taint 
-verify %s
 
+// When the checker security.ArrayBound encounters an array subscript operation
+// that _may be_ in bounds, it assumes that indexing _is_ in bound. These
+// assumptions will be reported to the user if the execution path leads to a
+// bug report (made by any checker) and the symbol which was constrainted by
+// the assumption is marked as interesting (with `markInteresting` or
+// indirectly via `trackExpressionValue`) in that bug report.
+//
+// This test file validates the content of these note tags which describe the
+// assumptions for the user.
+
 int TenElements[10];
 
 int irrelevantAssumptions(int arg) {
@@ -197,3 +207,14 @@ int *extentInterestingness(int arg) {
   // expected-warning@-1 {{Out of bound access to memory after the end of the 
heap area}}
   // expected-note@-2 {{Access of 'int' element in the heap area at index 12}}
 }
+
+int triggeredByAnyReport(int arg) {
+  // Verify that note tags explaining the assumptions made by ArrayBound are
+  // not limited to ArrayBound reports but will appear on any bug report (that
+  // marks the relevant symbol as interesting).
+  TenElements[arg + 10] = 8;
+  // expected-note@-1 {{Assuming index is non-negative and less than 10, the 
number of 'int' elements in 'TenElements'}}
+  return 1024 >> arg;
+  // expected-warning@-1 {{Right operand is negative in right shift}}
+  // expected-note@-2 {{The result of right shift is undefined because the 
right operand is negative}}
+}

diff  --git a/clang/test/Analysis/out-of-bounds-constraint-check.c 
b/clang/test/Analysis/ArrayBound/assumptions.c
similarity index 100%
rename from clang/test/Analysis/out-of-bounds-constraint-check.c
rename to clang/test/Analysis/ArrayBound/assumptions.c

diff  --git a/clang/test/Analysis/out-of-bounds.c 
b/clang/test/Analysis/ArrayBound/brief-tests.c
similarity index 96%
rename from clang/test/Analysis/out-of-bounds.c
rename to clang/test/Analysis/ArrayBound/brief-tests.c
index 2174dafc0021b..f4811efd8d8b6 100644
--- a/clang/test/Analysis/out-of-bounds.c
+++ b/clang/test/Analysis/ArrayBound/brief-tests.c
@@ -1,5 +1,10 @@
 // RUN: %clang_analyze_cc1 -Wno-array-bounds 
-analyzer-checker=core,security.ArrayBound,debug.ExprInspection -verify %s
 
+// Miscellaneous tests for `security.ArrayBound` where we only test the
+// presence or absence of a bug report. If a test doesn't fit in a more
+// specific file and doesn't need to verify the details of 'note' diagnostics,
+// then it should be placed here.
+
 void clang_analyzer_value(int);
 
 // Tests doing an out-of-bounds access after the end of an array using:

diff

[clang] [Clang] emit -Wunused-variable warning for unused structured bindings without the [[maybe_unused]] attribute (PR #127061)

2025-03-11 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/127061

>From a76ee008bdb87655da465e21d09c840edecc2b1b Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 13 Feb 2025 15:24:09 +0200
Subject: [PATCH 1/2] [Clang] emit -Wunused-variable warning for unused
 structured bindings without the [[maybe_unused]] attribute

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaDecl.cpp|  9 +
 clang/test/SemaCXX/unused-bindings.cpp | 17 +
 clang/test/SemaCXX/unused.cpp  |  3 ++-
 4 files changed, 26 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/SemaCXX/unused-bindings.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6344c4b36e357..4f20415ec006d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -160,6 +160,8 @@ Bug Fixes to C++ Support
 - Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 - The initialization kind of elements of structured bindings
   direct-list-initialized from an array is corrected to direct-initialization.
+- Clang now emits the ``-Wunused-variable`` warning when some structured 
bindings are unused
+  and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6eedc77ed20a0..19a73a66be5af 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1921,13 +1921,14 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions 
&LangOpts,
 // For a decomposition declaration, warn if none of the bindings are
 // referenced, instead of if the variable itself is referenced (which
 // it is, by the bindings' expressions).
-bool IsAllPlaceholders = true;
+bool IsAllIgnored = true;
 for (const auto *BD : DD->bindings()) {
-  if (BD->isReferenced() || BD->hasAttr())
+  if (BD->isReferenced())
 return false;
-  IsAllPlaceholders = IsAllPlaceholders && BD->isPlaceholderVar(LangOpts);
+  IsAllIgnored = IsAllIgnored && (BD->isPlaceholderVar(LangOpts) ||
+  BD->hasAttr());
 }
-if (IsAllPlaceholders)
+if (IsAllIgnored)
   return false;
   } else if (!D->getDeclName()) {
 return false;
diff --git a/clang/test/SemaCXX/unused-bindings.cpp 
b/clang/test/SemaCXX/unused-bindings.cpp
new file mode 100644
index 0..01f2126133a20
--- /dev/null
+++ b/clang/test/SemaCXX/unused-bindings.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2c -Wunused %s
+
+namespace GH125810 {
+struct S {
+  int a, b;
+};
+
+void t(S s) {
+  auto &[_, _] = s;
+  auto &[a1, _] = s; // expected-warning {{unused variable '[a1, _]'}}
+  auto &[_, b2] = s; // expected-warning {{unused variable '[_, b2]'}}
+
+  auto &[a3 [[maybe_unused]], b3 [[maybe_unused]]] = s;
+  auto &[a4, b4 [[maybe_unused]]] = s; // expected-warning {{unused variable 
'[a4, b4]'}}
+  auto &[a5 [[maybe_unused]], b5] = s; // expected-warning {{unused variable 
'[a5, b5]'}}
+}
+}
diff --git a/clang/test/SemaCXX/unused.cpp b/clang/test/SemaCXX/unused.cpp
index 1f40c1b1ca903..ab728069f2faf 100644
--- a/clang/test/SemaCXX/unused.cpp
+++ b/clang/test/SemaCXX/unused.cpp
@@ -114,7 +114,8 @@ namespace maybe_unused_binding {
 
 void test() {
   struct X { int a, b; } x;
-  auto [a [[maybe_unused]], b] = x; // expected-warning {{an attribute 
specifier sequence attached to a structured binding declaration is a C++2c 
extension}}
+  auto [a [[maybe_unused]], b] = x; // expected-warning {{an attribute 
specifier sequence attached to a structured binding declaration is a C++2c 
extension}} \
+// expected-warning {{unused variable '[a, 
b]'}}
 }
 
 }

>From c600c2a2378310c3f2fc82edaca66ca80b40284d Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 14 Feb 2025 13:43:53 +0200
Subject: [PATCH 2/2] update test to use std c++26

---
 clang/test/SemaCXX/unused-bindings.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/unused-bindings.cpp 
b/clang/test/SemaCXX/unused-bindings.cpp
index 01f2126133a20..83250dd4b0a11 100644
--- a/clang/test/SemaCXX/unused-bindings.cpp
+++ b/clang/test/SemaCXX/unused-bindings.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2c -Wunused %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++26 -Wunused %s
 
 namespace GH125810 {
 struct S {

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


[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130494)

2025-03-11 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/130494

>From 353f538f425ead9ee10ca6c046a6517b9e157db4 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 9 Mar 2025 15:43:37 +
Subject: [PATCH 1/2] [clang-tidy] support pointee mutation check in
 misc-const-correctness

---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp | 156 --
 .../clang-tidy/misc/ConstCorrectnessCheck.h   |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../checks/misc/const-correctness.rst |  44 +
 .../const-correctness-pointer-as-pointers.cpp |  50 ++
 .../const-correctness-transform-values.cpp|   1 +
 .../const-correctness-values-before-cxx23.cpp |   1 +
 .../misc/const-correctness-values.cpp |   1 +
 .../misc/const-correctness-wrong-config.cpp   |   7 +-
 9 files changed, 207 insertions(+), 59 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index dbe59233df699..023c834d5700f 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -13,6 +13,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/Support/Casting.h"
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -39,34 +41,47 @@ ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
 : ClangTidyCheck(Name, Context),
   AnalyzeValues(Options.get("AnalyzeValues", true)),
   AnalyzeReferences(Options.get("AnalyzeReferences", true)),
+  AnalyzePointers(Options.get("AnalyzePointers", true)),
   WarnPointersAsValues(Options.get("WarnPointersAsValues", false)),
+  WarnPointersAsPointers(Options.get("WarnPointersAsPointers", true)),
   TransformValues(Options.get("TransformValues", true)),
   TransformReferences(Options.get("TransformReferences", true)),
   TransformPointersAsValues(
   Options.get("TransformPointersAsValues", false)),
+  TransformPointersAsPointers(
+  Options.get("TransformPointersAsPointers", true)),
   AllowedTypes(
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
-  if (AnalyzeValues == false && AnalyzeReferences == false)
+  if (AnalyzeValues == false && AnalyzeReferences == false &&
+  AnalyzePointers == false)
 this->configurationDiag(
 "The check 'misc-const-correctness' will not "
-"perform any analysis because both 'AnalyzeValues' and "
-"'AnalyzeReferences' are false.");
+"perform any analysis because both 'AnalyzeValues', "
+"'AnalyzeReferences' and 'AnalyzePointers' are false.");
 }
 
 void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AnalyzeValues", AnalyzeValues);
   Options.store(Opts, "AnalyzeReferences", AnalyzeReferences);
+  Options.store(Opts, "AnalyzePointers", AnalyzePointers);
   Options.store(Opts, "WarnPointersAsValues", WarnPointersAsValues);
+  Options.store(Opts, "WarnPointersAsPointers", WarnPointersAsPointers);
 
   Options.store(Opts, "TransformValues", TransformValues);
   Options.store(Opts, "TransformReferences", TransformReferences);
   Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
+  Options.store(Opts, "TransformPointersAsPointers",
+TransformPointersAsPointers);
   Options.store(Opts, "AllowedTypes",
 utils::options::serializeStringList(AllowedTypes));
 }
 
 void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstType = hasType(isConstQualified());
+  const auto ConstType = hasType(
+  qualType(isConstQualified(),
+   // pointee check will check the const pointer and const array
+   unless(pointerType()), unless(arrayType(;
+
   const auto ConstReference = hasType(references(isConstQualified()));
   const auto RValueReference = hasType(
   referenceType(anyOf(rValueReferenceType(), 
unless(isSpelledAsLValue();
@@ -124,6 +139,11 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
+  const auto *VarDeclStmt = Result.Nodes.getNodeAs("decl-stmt");
+  // It can not be guaranteed that the variable is declared isolated,
+  // therefore a transformation might effect the other variables as well and
+  // be incorrect.
+  const bool CanBeFixIt = VarDeclStmt != nullptr && 
VarDeclStmt->isSingleDecl();
 
   /// If the variable was declared in a template it might be analyzed multiple
   /// times. Only one of those ins

[clang] [llvm] [Support] Remove output file checks from `LockFileManager` (PR #130395)

2025-03-11 Thread Jan Svoboda via cfe-commits

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


[clang] [flang] [flang] Add support for -f[no-]verbose-asm (PR #130788)

2025-03-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Tom Eccles (tblah)


Changes

This flag provides extra commentary in the assembly output. It is in 
CodeGenOptions to match what is done in clang, even though the backend treats 
it as a target option.

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


6 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+3-2) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+2-1) 
- (modified) flang/include/flang/Frontend/CodeGenOptions.def (+2) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+4) 
- (modified) flang/lib/Frontend/FrontendActions.cpp (+2) 
- (added) flang/test/Driver/verbose-asm.f90 (+16) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e69cd6b833c3a..ac6392f92f311 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3467,7 +3467,7 @@ defm use_cxa_atexit : BoolFOption<"use-cxa-atexit",
   PosFlag>;
 def fno_unwind_tables : Flag<["-"], "fno-unwind-tables">, Group;
 def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   MarshallingInfoNegativeFlag>;
 def fno_working_directory : Flag<["-"], "fno-working-directory">, 
Group;
 def fobjc_arc : Flag<["-"], "fobjc-arc">, Group,
@@ -4142,7 +4142,8 @@ defm use_init_array : BoolFOption<"use-init-array",
   PosFlag>;
 def fno_var_tracking : Flag<["-"], "fno-var-tracking">, 
Group;
 def fverbose_asm : Flag<["-"], "fverbose-asm">, Group,
-  HelpText<"Generate verbose assembly output">;
+  HelpText<"Generate verbose assembly output">,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
 def dA : Flag<["-"], "dA">, Alias;
 defm visibility_from_dllstorageclass : 
BoolFOption<"visibility-from-dllstorageclass",
   LangOpts<"VisibilityFromDLLStorageClass">, DefaultFalse,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index d4fea633d0edf..09b77b4aab03d 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -172,7 +172,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_finit_global_zero,
options::OPT_fno_init_global_zero, 
options::OPT_ftime_report,
options::OPT_ftime_report_EQ, options::OPT_funroll_loops,
-   options::OPT_fno_unroll_loops});
+   options::OPT_fno_unroll_loops, options::OPT_fverbose_asm,
+   options::OPT_fno_verbose_asm});
 }
 
 void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 44cb5a2cdd497..d2ff06d5fe08a 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -42,5 +42,7 @@ ENUM_CODEGENOPT(DebugInfo,  
llvm::codegenoptions::DebugInfoKind, 4,  llvm::codeg
 ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, 
llvm::driver::VectorLibrary::NoLibrary) ///< Vector functions library to use
 ENUM_CODEGENOPT(FramePointer, llvm::FramePointerKind, 2, 
llvm::FramePointerKind::None) ///< Enable the usage of frame pointers
 
+CODEGENOPT(AsmVerbose, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 8b07a50824899..5451006960e8b 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -254,6 +254,10 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
   clang::driver::options::OPT_fno_unroll_loops,
   (opts.OptimizationLevel > 1));
 
+  if (args.hasFlag(clang::driver::options::OPT_fverbose_asm,
+   clang::driver::options::OPT_fno_verbose_asm, false))
+opts.AsmVerbose = 1;
+
   opts.AliasAnalysis = opts.OptimizationLevel > 0;
 
   // -mframe-pointer=none/non-leaf/all option.
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 94de376aaf7d6..0ef2708bb42fb 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1284,6 +1284,8 @@ void CodeGenAction::executeAction() {
   // given on the command-line).
   llvm::TargetMachine &targetMachine = ci.getTargetMachine();
 
+  targetMachine.Options.MCOptions.AsmVerbose = codeGenOpts.AsmVerbose;
+
   const llvm::Triple &theTriple = targetMachine.getTargetTriple();
 
   if (llvmModule->getTargetTriple() != theTriple) {
diff --git a/flang/test/Driver/verbose-asm.f90 
b/flang/test/Driver/verbose-asm.f90
new file mode 100644
index 0..20e930d22bf0a
--- /dev/null
+++ b/flang/test/Driver/verbose-asm.f90
@@ -0,0 +1,16 @@
+

[clang] ae98526 - [RISCV] Update to Xqciint v0.4 (#130219)

2025-03-11 Thread via cfe-commits

Author: Sam Elliott
Date: 2025-03-11T08:54:22-07:00
New Revision: ae985267d0a107119038e1a1e62b3aed6523f28c

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

LOG: [RISCV] Update to Xqciint v0.4 (#130219)

The Xqci 0.7.0 spec just came out, with some updates to Xqciint,
bringing it to v0.4. The main update of any relevance is that
`qc.c.mienter` and `qc.c.mienter.nest` now update both the stack pointer
and the frame pointer (before, they only updated the stack pointer).
They both remain compatible with the frame pointer convention.

This change bumps the Xqciint version, and ensures that we don't emit
the unneeded frame pointer adjustment instruction after
`qc.c.mienter(.nest)`.

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td
clang/test/Driver/print-supported-extensions-riscv.c
llvm/docs/RISCVUsage.rst
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp
llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/CodeGen/RISCV/qci-interrupt-attr.ll
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 1f2f02a4453fc..34e7ff9612859 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2883,7 +2883,7 @@ 
https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Function-Attributes.html
 https://riscv.org/specifications/privileged-isa/
 The RISC-V Instruction Set Manual Volume II: Privileged Architecture
 Version 1.10.
-https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.6
+https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7
   }];
 }
 

diff  --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 69b76f0c4c4cd..d9335fe502bb6 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -201,7 +201,7 @@
 // CHECK-NEXT: xqcicm   0.2   'Xqcicm' (Qualcomm uC 
Conditional Move Extension)
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
 // CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
-// CHECK-NEXT: xqciint  0.2   'Xqciint' (Qualcomm uC 
Interrupts Extension)
+// CHECK-NEXT: xqciint  0.4   'Xqciint' (Qualcomm uC 
Interrupts Extension)
 // CHECK-NEXT: xqcilia  0.2   'Xqcilia' (Qualcomm uC Large 
Immediate Arithmetic Extension)
 // CHECK-NEXT: xqcilo   0.2   'Xqcilo' (Qualcomm uC Large 
Offset Load Store Extension)
 // CHECK-NEXT: xqcilsm  0.2   'Xqcilsm' (Qualcomm uC Load 
Store Multiple Extension)

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 62c6a4fd80fd4..831e8fd5d186b 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -454,7 +454,7 @@ The current vendor extensions supported are:
   LLVM implements `version 0.2 of the Qualcomm uC CSR extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
 ``experimental-Xqciint``
-  LLVM implements `version 0.2 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+  LLVM implements `version 0.4 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 
 ``experimental-Xqcilia``
   LLVM implements `version 0.2 of the Qualcomm uC Large Immediate Arithmetic 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.

diff  --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 35db027509d94..544ad14266183 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1351,7 +1351,7 @@ def HasVendorXqcicm
  "'Xqcicm' (Qualcomm uC Conditional Move Extension)

[clang] [llvm] [RISCV] Add Qualcomn uC Xqcili (load large immediates) extension (PR #130012)

2025-03-11 Thread Sudharsan Veeravalli via cfe-commits

svs-quic wrote:

It looks like there are some conflicts. Please fix them before merging.

Also just noticed that you have been updating the same commit with the changes 
requested in the reviews. Please have them as separate commits in the future so 
that we can know what changed.

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Morris Hafner via cfe-commits


@@ -78,6 +79,67 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return create(loc, val, dst);
   }
 
+  
//======//
+  // Cast/Conversion Operators
+  
//======//
+
+  mlir::Value createCast(mlir::Location loc, cir::CastKind kind,
+ mlir::Value src, mlir::Type newTy) {
+if (newTy == src.getType())
+  return src;
+return create(loc, newTy, kind, src);
+  }
+
+  mlir::Value createCast(cir::CastKind kind, mlir::Value src,
+ mlir::Type newTy) {
+if (newTy == src.getType())
+  return src;
+return createCast(src.getLoc(), kind, src, newTy);
+  }
+
+  mlir::Value createIntCast(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::integral, src, newTy);
+  }
+
+  mlir::Value createIntToPtr(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::int_to_ptr, src, newTy);
+  }
+
+  mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::ptr_to_int, src, newTy);
+  }
+
+  mlir::Value createPtrToBoolCast(mlir::Value v) {
+return createCast(cir::CastKind::ptr_to_bool, v, getBoolTy());
+  }
+
+  mlir::Value createBoolToInt(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::bool_to_int, src, newTy);
+  }
+
+  mlir::Value createBitcast(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::bitcast, src, newTy);
+  }
+
+  mlir::Value createBitcast(mlir::Location loc, mlir::Value src,
+mlir::Type newTy) {
+return createCast(loc, cir::CastKind::bitcast, src, newTy);
+  }
+
+  mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy) {

mmha wrote:

This is a utility function used in a couple of other `create` or `emit` 
functions in the incubator, for example to cast the pointer type in 
`createLoad` and `createStore` in the incubator. 

Looking at it again this function isn't used in this patch and I copied this by 
accident. I'll remove it for now.

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


[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130494)

2025-03-11 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/130494

>From 353f538f425ead9ee10ca6c046a6517b9e157db4 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 9 Mar 2025 15:43:37 +
Subject: [PATCH 1/3] [clang-tidy] support pointee mutation check in
 misc-const-correctness

---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp | 156 --
 .../clang-tidy/misc/ConstCorrectnessCheck.h   |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../checks/misc/const-correctness.rst |  44 +
 .../const-correctness-pointer-as-pointers.cpp |  50 ++
 .../const-correctness-transform-values.cpp|   1 +
 .../const-correctness-values-before-cxx23.cpp |   1 +
 .../misc/const-correctness-values.cpp |   1 +
 .../misc/const-correctness-wrong-config.cpp   |   7 +-
 9 files changed, 207 insertions(+), 59 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index dbe59233df699..023c834d5700f 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -13,6 +13,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/Support/Casting.h"
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -39,34 +41,47 @@ ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
 : ClangTidyCheck(Name, Context),
   AnalyzeValues(Options.get("AnalyzeValues", true)),
   AnalyzeReferences(Options.get("AnalyzeReferences", true)),
+  AnalyzePointers(Options.get("AnalyzePointers", true)),
   WarnPointersAsValues(Options.get("WarnPointersAsValues", false)),
+  WarnPointersAsPointers(Options.get("WarnPointersAsPointers", true)),
   TransformValues(Options.get("TransformValues", true)),
   TransformReferences(Options.get("TransformReferences", true)),
   TransformPointersAsValues(
   Options.get("TransformPointersAsValues", false)),
+  TransformPointersAsPointers(
+  Options.get("TransformPointersAsPointers", true)),
   AllowedTypes(
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
-  if (AnalyzeValues == false && AnalyzeReferences == false)
+  if (AnalyzeValues == false && AnalyzeReferences == false &&
+  AnalyzePointers == false)
 this->configurationDiag(
 "The check 'misc-const-correctness' will not "
-"perform any analysis because both 'AnalyzeValues' and "
-"'AnalyzeReferences' are false.");
+"perform any analysis because both 'AnalyzeValues', "
+"'AnalyzeReferences' and 'AnalyzePointers' are false.");
 }
 
 void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AnalyzeValues", AnalyzeValues);
   Options.store(Opts, "AnalyzeReferences", AnalyzeReferences);
+  Options.store(Opts, "AnalyzePointers", AnalyzePointers);
   Options.store(Opts, "WarnPointersAsValues", WarnPointersAsValues);
+  Options.store(Opts, "WarnPointersAsPointers", WarnPointersAsPointers);
 
   Options.store(Opts, "TransformValues", TransformValues);
   Options.store(Opts, "TransformReferences", TransformReferences);
   Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
+  Options.store(Opts, "TransformPointersAsPointers",
+TransformPointersAsPointers);
   Options.store(Opts, "AllowedTypes",
 utils::options::serializeStringList(AllowedTypes));
 }
 
 void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstType = hasType(isConstQualified());
+  const auto ConstType = hasType(
+  qualType(isConstQualified(),
+   // pointee check will check the const pointer and const array
+   unless(pointerType()), unless(arrayType(;
+
   const auto ConstReference = hasType(references(isConstQualified()));
   const auto RValueReference = hasType(
   referenceType(anyOf(rValueReferenceType(), 
unless(isSpelledAsLValue();
@@ -124,6 +139,11 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
+  const auto *VarDeclStmt = Result.Nodes.getNodeAs("decl-stmt");
+  // It can not be guaranteed that the variable is declared isolated,
+  // therefore a transformation might effect the other variables as well and
+  // be incorrect.
+  const bool CanBeFixIt = VarDeclStmt != nullptr && 
VarDeclStmt->isSingleDecl();
 
   /// If the variable was declared in a template it might be analyzed multiple
   /// times. Only one of those ins

[clang-tools-extra] [clang-tidy][NFC] clean ReleaseNotes.rst (PR #130626)

2025-03-11 Thread Congcong Cai via cfe-commits

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


https://github.com/llvm/llvm-project/pull/130626
___
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-03-11 Thread Baranov Victor via cfe-commits

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

>From bc1b4ada7615d407c2df009f414d62da3857ee86 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Mon, 3 Mar 2025 09:25:03 +0300
Subject: [PATCH 1/4] [clang-tidy] add scoped-lock-check

---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseScopedLockCheck.cpp  | 319 +++
 .../clang-tidy/modernize/UseScopedLockCheck.h |  54 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-scoped-lock.rst  | 102 +
 .../clang-tidy/checkers/Inputs/Headers/mutex  |  33 ++
 ...e-lock-warn-on-using-and-typedef-false.cpp |  31 ++
 ...scoped-lock-warn-on-single-locks-false.cpp |  96 +
 .../checkers/modernize/use-scoped-lock.cpp| 372 ++
 11 files changed, 1018 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/Inputs/Headers/mutex
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-scope-lock-warn-on-using-and-typedef-false.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-scoped-lock-warn-on-single-locks-false.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 bab1167fb15ff..619a27b2f9bb6 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 fc46c72982fdc..b2d4ddd667502 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 0..5dbb3a2f671e6
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseScopedLockCheck.cpp
@@ -0,0 +1,319 @@
+//===--- 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/SmallVector.h"
+#include "llvm/ADT/Twine.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+
+bool isLockGuard(const QualType &Type) {
+  if (const auto *Record = Type->getAs()) {
+if (const RecordDecl *Decl = Record->getDecl()) {
+  return Decl->getName() == "lock_guard" && Decl->isInStdNamespace();
+}
+  }
+
+  if (const auto *TemplateSpecType =
+  Type->getAs()) {
+if (const TemplateDecl *Decl =
+TemplateSpecType->getTemplateName().getAsTemplateDecl()) {
+  return Decl->getName() == "lock_guard" && Decl->isInStdNamespace();
+}
+  }
+
+  return false;
+}
+
+llvm::SmallVector getLockGuardsFromDecl(const DeclStmt *DS) {
+  llvm::SmallVector LockGuards;
+
+  for (const Decl *Decl : DS->decls()) {
+if (

[clang-tools-extra] [clang-tidy] support pointee mutation check in misc-const-correctness (PR #130494)

2025-03-11 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/130494

>From 353f538f425ead9ee10ca6c046a6517b9e157db4 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sun, 9 Mar 2025 15:43:37 +
Subject: [PATCH 1/4] [clang-tidy] support pointee mutation check in
 misc-const-correctness

---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp | 156 --
 .../clang-tidy/misc/ConstCorrectnessCheck.h   |   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   3 +-
 .../checks/misc/const-correctness.rst |  44 +
 .../const-correctness-pointer-as-pointers.cpp |  50 ++
 .../const-correctness-transform-values.cpp|   1 +
 .../const-correctness-values-before-cxx23.cpp |   1 +
 .../misc/const-correctness-values.cpp |   1 +
 .../misc/const-correctness-wrong-config.cpp   |   7 +-
 9 files changed, 207 insertions(+), 59 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index dbe59233df699..023c834d5700f 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -13,6 +13,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/Support/Casting.h"
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -39,34 +41,47 @@ ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
 : ClangTidyCheck(Name, Context),
   AnalyzeValues(Options.get("AnalyzeValues", true)),
   AnalyzeReferences(Options.get("AnalyzeReferences", true)),
+  AnalyzePointers(Options.get("AnalyzePointers", true)),
   WarnPointersAsValues(Options.get("WarnPointersAsValues", false)),
+  WarnPointersAsPointers(Options.get("WarnPointersAsPointers", true)),
   TransformValues(Options.get("TransformValues", true)),
   TransformReferences(Options.get("TransformReferences", true)),
   TransformPointersAsValues(
   Options.get("TransformPointersAsValues", false)),
+  TransformPointersAsPointers(
+  Options.get("TransformPointersAsPointers", true)),
   AllowedTypes(
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
-  if (AnalyzeValues == false && AnalyzeReferences == false)
+  if (AnalyzeValues == false && AnalyzeReferences == false &&
+  AnalyzePointers == false)
 this->configurationDiag(
 "The check 'misc-const-correctness' will not "
-"perform any analysis because both 'AnalyzeValues' and "
-"'AnalyzeReferences' are false.");
+"perform any analysis because both 'AnalyzeValues', "
+"'AnalyzeReferences' and 'AnalyzePointers' are false.");
 }
 
 void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AnalyzeValues", AnalyzeValues);
   Options.store(Opts, "AnalyzeReferences", AnalyzeReferences);
+  Options.store(Opts, "AnalyzePointers", AnalyzePointers);
   Options.store(Opts, "WarnPointersAsValues", WarnPointersAsValues);
+  Options.store(Opts, "WarnPointersAsPointers", WarnPointersAsPointers);
 
   Options.store(Opts, "TransformValues", TransformValues);
   Options.store(Opts, "TransformReferences", TransformReferences);
   Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
+  Options.store(Opts, "TransformPointersAsPointers",
+TransformPointersAsPointers);
   Options.store(Opts, "AllowedTypes",
 utils::options::serializeStringList(AllowedTypes));
 }
 
 void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstType = hasType(isConstQualified());
+  const auto ConstType = hasType(
+  qualType(isConstQualified(),
+   // pointee check will check the const pointer and const array
+   unless(pointerType()), unless(arrayType(;
+
   const auto ConstReference = hasType(references(isConstQualified()));
   const auto RValueReference = hasType(
   referenceType(anyOf(rValueReferenceType(), 
unless(isSpelledAsLValue();
@@ -124,6 +139,11 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
+  const auto *VarDeclStmt = Result.Nodes.getNodeAs("decl-stmt");
+  // It can not be guaranteed that the variable is declared isolated,
+  // therefore a transformation might effect the other variables as well and
+  // be incorrect.
+  const bool CanBeFixIt = VarDeclStmt != nullptr && 
VarDeclStmt->isSingleDecl();
 
   /// If the variable was declared in a template it might be analyzed multiple
   /// times. Only one of those ins

[clang] [Clang] add additional tests for -Wshift-bool (PR #130339)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -22,4 +23,6 @@ void t() {
 
   if ((y << 1) != 0) { }
   if ((y >> 1) != 0) { } // expected-warning {{right shifting a 'bool' 
implicitly converts it to 'int'}}
+
+  bool k = (x < z) >> 1; // expected-warning {{right shifting a 'bool' 
implicitly converts it to 'int'}}

AaronBallman wrote:

I think we still want the C++ test change that got removed.

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


[clang] [Clang] add additional tests for -Wshift-bool (PR #130339)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -Wshift-bool -verify %s
+
+void t() {
+  int x = 10;
+  int y = 1;
+
+  int a = y << x;
+  int b = y >> x;
+
+  int c = 0 << x;
+  int d = 0 >> x;
+
+  int e = y << 1;
+  int f = y >> 1;
+
+  int g = y << -1; // expected-warning {{shift count is negative}}
+  int h = y >> -1; // expected-warning {{shift count is negative}}
+
+  int i = y << 0;
+  int j = y >> 0;
+
+  if ((y << 1) != 0) { }
+  if ((y >> 1) != 0) { }

AaronBallman wrote:

None of these are about shifting with a Boolean operand. I think you should 
replicate the C++ test cases but in C.

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


[clang] f90aa41 - [Support] Remove output file checks from `LockFileManager` (#130395)

2025-03-11 Thread via cfe-commits

Author: Jan Svoboda
Date: 2025-03-11T08:51:28-07:00
New Revision: f90aa418978748c0613036b0285bb80af40570b7

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

LOG: [Support] Remove output file checks from `LockFileManager` (#130395)

Currently, `LockFileManager` assumes the owner of the lock file creates
an output file. This is problematic for at least three reasons:

1. It is orthogonal to the main purpose of this class - mutual
exclusion. This makes creating an alternative implementation more
complicated than it needs to be.

2. Some clients (like the upstream `AMDGPUSplitModule.cpp` file) assume
the output file is not necessary. The owner of the lock file does not
write the file expected by `LockFileManager` and the processes waiting
for the non-owned lock file to be unlocked therefore assume the owner
has died. This means that the work gets repeated by each waiting
process, serially.

3. The documentation makes it sound like successfully waiting for a
non-owned lock file guarantees the output file to be present on the file
system. Implicitly-built modules rely on this. However, the module file
may disappear between `LockFileManager` performing the check and the
compiler loading the module (for example due to module cache pruning
with short intervals, or intervention from outside of Clang). The
compiler assumes this cannot happen, and fails the build if it does.

This PR solves this situation by removing the check, reflecting that in
the `LockFileManager` documentation, and fixing the time-of-check
time-of-use bug in implicit modules.

Added: 


Modified: 
clang/lib/Frontend/CompilerInstance.cpp
llvm/include/llvm/Support/LockFileManager.h
llvm/lib/Support/LockFileManager.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index c11c857ea0606..6098e2e30af9d 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1406,7 +1406,7 @@ static bool readASTAfterCompileModule(CompilerInstance 
&ImportingInstance,
   SourceLocation ImportLoc,
   SourceLocation ModuleNameLoc,
   Module *Module, StringRef ModuleFileName,
-  bool *OutOfDate) {
+  bool *OutOfDate, bool *Missing) {
   DiagnosticsEngine &Diags = ImportingInstance.getDiagnostics();
 
   unsigned ModuleLoadCapabilities = ASTReader::ARR_Missing;
@@ -1427,6 +1427,12 @@ static bool readASTAfterCompileModule(CompilerInstance 
&ImportingInstance,
 return false;
   }
 
+  // The caller wants to handle missing module files.
+  if (Missing && ReadResult == ASTReader::Missing) {
+*Missing = true;
+return false;
+  }
+
   // The ASTReader didn't diagnose the error, so conservatively report it.
   if (ReadResult == ASTReader::Missing || !Diags.hasErrorOccurred())
 Diags.Report(ModuleNameLoc, diag::err_module_not_built)
@@ -1452,7 +1458,7 @@ static bool compileModuleAndReadASTImpl(CompilerInstance 
&ImportingInstance,
 
   return readASTAfterCompileModule(ImportingInstance, ImportLoc, ModuleNameLoc,
Module, ModuleFileName,
-   /*OutOfDate=*/nullptr);
+   /*OutOfDate=*/nullptr, /*Missing=*/nullptr);
 }
 
 /// Compile a module in a separate compiler instance and read the AST,
@@ -1517,15 +1523,17 @@ static bool compileModuleAndReadASTBehindLock(
 
 // Read the module that was just written by someone else.
 bool OutOfDate = false;
+bool Missing = false;
 if (readASTAfterCompileModule(ImportingInstance, ImportLoc, ModuleNameLoc,
-  Module, ModuleFileName, &OutOfDate))
+  Module, ModuleFileName, &OutOfDate, 
&Missing))
   return true;
-if (!OutOfDate)
+if (!OutOfDate && !Missing)
   return false;
 
-// The module may be out of date in the presence of file system races,
-// or if one of its imports depends on header search paths that are not
-// consistent with this ImportingInstance.  Try again...
+// The module may be missing or out of date in the presence of file system
+// races. It may also be out of date if one of its imports depends on 
header
+// search paths that are not consistent with this ImportingInstance.
+// Try again...
   }
 }
 

diff  --git a/llvm/include/llvm/Support/LockFileManager.h 
b/llvm/include/llvm/Support/LockFileManager.h
index 92c7ceed6a929..4bb8919a0ab31 100644
--- a/llvm/include/llvm/Support/LockFileManager.h
+++ b/llvm/include/llvm/Support/LockFileManager.h
@@ -16,14 +16,13 @@
 namespac

[clang] [llvm] [MIPS] Add MIPS i6400 and i6500 processors (PR #130587)

2025-03-11 Thread Djordje Todorovic via cfe-commits


@@ -43,7 +43,7 @@ class MipsSubtarget : public MipsGenSubtargetInfo {
 Mips3, Mips4, Mips5, Mips64, Mips64r2, Mips64r3, Mips64r5, Mips64r6
   };
 
-  enum class CPU { P5600 };
+  enum class CPU { P5600, I6400 };

djtodoro wrote:

do we need "i6500" here as well?

i6500 is just a multi-cluster version of i6400, right?

Please also attach/link documentation files for those CPUs.

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


[clang] [Clang] Add __builtin_elementwise_exp10 in the same fashion as exp/exp2 (PR #130746)

2025-03-11 Thread Juan Manuel Martinez Caamaño via cfe-commits

https://github.com/jmmartinez updated 
https://github.com/llvm/llvm-project/pull/130746

From c017072c34203a25f4f179dc70e4adc27094c5dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Mon, 10 Mar 2025 15:40:00 +0100
Subject: [PATCH 1/2] [Clang][NFC] Rename and update_cc_test_checks over
 strictfp-elementwise-builtins.cpp

---
 ...ntwise-bulitins.cpp => strictfp-elementwise-builtins.cpp} | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
 rename clang/test/CodeGen/{strictfp-elementwise-bulitins.cpp => 
strictfp-elementwise-builtins.cpp} (98%)

diff --git a/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp 
b/clang/test/CodeGen/strictfp-elementwise-builtins.cpp
similarity index 98%
rename from clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
rename to clang/test/CodeGen/strictfp-elementwise-builtins.cpp
index 175ad22601839..9b92c259c9895 100644
--- a/clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
+++ b/clang/test/CodeGen/strictfp-elementwise-builtins.cpp
@@ -340,9 +340,8 @@ float4 strict_elementwise_pow(float4 a, float4 b) {
 // CHECK-LABEL: define dso_local noundef <4 x float> 
@_Z23strict_elementwise_fmodDv4_fS_
 // CHECK-SAME: (<4 x float> noundef [[A:%.*]], <4 x float> noundef [[B:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]],
-// CHECK-SAME:metadata !"round.dynamic", metadata !"fpexcept.strict") 
#[[ATTR4]]
-// CHECK-NEXT:ret <4 x float> [[TMP0]]
+// CHECK-NEXT:[[FMOD:%.*]] = tail call <4 x float> 
@llvm.experimental.constrained.frem.v4f32(<4 x float> [[A]], <4 x float> [[B]], 
metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR4]]
+// CHECK-NEXT:ret <4 x float> [[FMOD]]
 //
 float4 strict_elementwise_fmod(float4 a, float4 b) {
   return __builtin_elementwise_fmod(a, b);

From 0b6ce4fa3034f0cb7b93de26470f3f82df14d326 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Mon, 10 Mar 2025 15:35:27 +0100
Subject: [PATCH 2/2] [Clang] Add __builtin_elementwise_exp10 in the same
 fashion as exp/exp2

Clang has __builtin_elementwise_exp and __builtin_elementwise_exp2
intrinsics, but no __builtin_elementwise_exp10.

There doesn't seem to be a good reason not to expose the exp10 flavour
of this intrinsic too.

This commit introduces this intrinsic following the same pattern as the
exp and exp2 versions.

Fixes: SWDEV-519541
---
 clang/docs/LanguageExtensions.rst |  1 +
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 +++
 clang/lib/Sema/SemaChecking.cpp   |  1 +
 clang/lib/Sema/SemaHLSL.cpp   |  1 +
 .../test/CodeGen/builtins-elementwise-math.c  | 15 ++
 .../CodeGen/strictfp-elementwise-builtins.cpp | 10 ++
 clang/test/Sema/builtins-elementwise-math.c   | 20 +++
 .../SemaCXX/builtins-elementwise-math.cpp |  7 +++
 10 files changed, 65 insertions(+)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 578ee02f09b9b..7f8992dc202c3 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -786,6 +786,7 @@ of different sizes and signs is forbidden in binary and 
ternary builtins.
  T __builtin_elementwise_bitreverse(T x)return the integer represented 
after reversing the bits of x   integer types
  T __builtin_elementwise_exp(T x)   returns the base-e 
exponential, e^x, of the specified valuefloating point types
  T __builtin_elementwise_exp2(T x)  returns the base-2 
exponential, 2^x, of the specified valuefloating point types
+ T __builtin_elementwise_exp10(T x) returns the base-10 
exponential, 10^x, of the specified value  floating point types
 
  T __builtin_elementwise_sqrt(T x)  return the square root of a 
floating-point number  floating point types
  T __builtin_elementwise_roundeven(T x) round x to the nearest integer 
value in floating point format, floating point types
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 629149bf459b1..6b1afa80325d0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -116,6 +116,7 @@ Non-comprehensive list of changes in this release
 -
 
 - Support parsing the `cc` operand modifier and alias it to the `c` modifier 
(#GH127719).
+- Added `__builtin_elementwise_exp10`.
 
 New Compiler Flags
 --
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2268df70927a7..2fbdfaea57ccd 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/cl

[clang] [NFC][analyzer] Remove CheckerNameRef::getName() (PR #130780)

2025-03-11 Thread Balazs Benics via cfe-commits

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


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


[clang] [clang-format] Add support for absl nullability macros (PR #130346)

2025-03-11 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

Google C++ Style Guide and Abseil go hand-in-hand from Google's perspective. We 
are the stewards of both and we would prefer to keep the two in sync. We have 
opted to have the Google Style available as builtin in `clang-format` and have 
been sticking to that decision until now. I think it benefits everyone that 
each user of Abseil doesn't need to update their configuration files 
everywhere. We don't even have any downstream mechanisms to configure 
`clang-format` internally because we are committed to keep `clang-format` 
aligned with what we use.

#76239 was a former precedent where we got some mild pushback, but it 
ultimately landed. 

> The reason is that people wouldn't be able to turn off the special meaning if 
> they wanted to use e.g. absl_nonnull as a regular identifier.

@owenca we deliberately use the prefixes to make sure it has almost zero chance 
of clashes with anyone else. What are the chances of somebody prefixing their 
code with `absl_`? I searched for `absl_nonnull` and found two results, both 
related to Abseil. 

> Imagine if we did this for every "toolkit"... we'd be inundated with add 
> this/that etc... why can't people who use Abseil not add them to their 
> .clang-format? Outside of google are that many people even using Abseil?
> Abseil itself doesn't even define them in their .clang-format file.
> This is a no from me.

People from Google were the original authors of `clang-format` and introduced 
google as one of default styles supported by the binary. We have never 
negotiated it explicitly, but having the ability to change the Google Style is 
definitely something we expected to keep going forward.

Do people on this thread feel it is a reasonable ask from Google? If not, could 
you elaborate and suggest a different governance model for the style defined by 
`clang-format -style=google`?
It is fairly important for us to clarify what folks are thinking about this and 
how we can move forward with these types of changes going further.

The question is mainly to @mydeveloperday @owenca, but also cc 
@HazardyKnusperkeks @rymiel who were mentioned in #76239.


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


[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-03-11 Thread Jack Styles via cfe-commits

Stylie777 wrote:

Thanks @jthackray. The CI Failure seems to be unrelated. 

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


[clang] [clang-tools-extra] [clang-tidy] Avoid processing declarations in system headers (PR #128150)

2025-03-11 Thread Carlos Galvez via cfe-commits


@@ -1573,19 +1574,42 @@ bool MatchASTVisitor::TraverseAttr(Attr *AttrNode) {
 class MatchASTConsumer : public ASTConsumer {
 public:
   MatchASTConsumer(MatchFinder *Finder,
-   MatchFinder::ParsingDoneTestCallback *ParsingDone)
-  : Finder(Finder), ParsingDone(ParsingDone) {}
+   MatchFinder::ParsingDoneTestCallback *ParsingDone,
+   bool SkipSystemHeaders = false)

carlosgalvezp wrote:

Makes, sense fixed!

https://github.com/llvm/llvm-project/pull/128150
___
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 check on constexpr & static values in modernize-use-default-member-init (PR #129425)

2025-03-11 Thread David Rivera via cfe-commits

RiverDave wrote:

> @RiverDave Unless you want this to be merged using github generated private 
> email, change your email privacy settings.

My email should be public now

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


[clang] f1e3675 - [HLSL] error on out of bounds vector accesses (#128952)

2025-03-11 Thread via cfe-commits

Author: Sarah Spall
Date: 2025-03-11T07:12:18-07:00
New Revision: f1e36759d2e6c26d2d5825f955c51fd595909b52

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

LOG: [HLSL] error on out of bounds vector accesses (#128952)

Add Sema checking and diagnostics to error on out of bounds vector
accesses
Add tests
Closes #91640

-

Co-authored-by: Chris B 
Co-authored-by: Aaron Ballman 

Added: 
clang/test/SemaHLSL/Language/VectorOutOfRange-errors.hlsl

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGenCXX/x86_64-arguments.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 145c5972a2043..004f78f22ac36 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -235,6 +235,8 @@ Improvements to Clang's diagnostics
   under the subgroup ``-Wunsafe-buffer-usage-in-libc-call``.
 - Diagnostics on chained comparisons (``a < b < c``) are now an error by 
default. This can be disabled with
   ``-Wno-error=parentheses``.
+- Adds an error diagnostic for out of bounds vector accesses; produces an error
+  for compile time statically provable out of bounds vector accesses.
 - The ``-Wshift-bool`` warning has been added to warn about shifting a 
boolean. (#GH28334)
 - Fixed diagnostics adding a trailing ``::`` when printing some source code
   constructs, like base classes.

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e6e6e892cdd7..4bdbb797c2b86 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10688,6 +10688,9 @@ def err_block_on_vm : Error<
 def err_sizeless_nonlocal : Error<
   "non-local variable with sizeless type %0">;
 
+def err_vector_index_out_of_range : Error<
+  "vector element index %0 is out of bounds">;
+
 def err_vec_builtin_non_vector : Error<
  "%select{first two|all}1 arguments to %0 must be vectors">;
 def err_vec_builtin_incompatible_vector : Error<

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9ac26d8728446..c034de0e633da 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2468,6 +2468,7 @@ class Sema final : public SemaBase {
 const ArraySubscriptExpr *ASE = nullptr,
 bool AllowOnePastEnd = true, bool IndexNegated = 
false);
   void CheckArrayAccess(const Expr *E);
+  void CheckVectorAccess(const Expr *BaseExpr, const Expr *IndexExpr);
 
   bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall,
 const FunctionProtoType *Proto);

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a6cdbbafec666..89932b5d61dc8 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14054,6 +14054,23 @@ void Sema::CheckCastAlign(Expr *Op, QualType T, 
SourceRange TRange) {
 << TRange << Op->getSourceRange();
 }
 
+void Sema::CheckVectorAccess(const Expr *BaseExpr, const Expr *IndexExpr) {
+  const auto *VTy = BaseExpr->getType()->getAs();
+  if (!VTy)
+return;
+
+  Expr::EvalResult Result;
+  if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))
+return;
+
+  unsigned DiagID = diag::err_vector_index_out_of_range;
+
+  llvm::APSInt index = Result.Val.getInt();
+  if (index.isNegative() || index >= VTy->getNumElements())
+Diag(BaseExpr->getBeginLoc(), DiagID) << toString(index, 10, true);
+  return;
+}
+
 void Sema::CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr,
 const ArraySubscriptExpr *ASE,
 bool AllowOnePastEnd, bool IndexNegated) {
@@ -14068,6 +14085,12 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, 
const Expr *IndexExpr,
   const Type *EffectiveType =
   BaseExpr->getType()->getPointeeOrArrayElementType();
   BaseExpr = BaseExpr->IgnoreParenCasts();
+
+  if (BaseExpr->getType()->isVectorType()) {
+CheckVectorAccess(BaseExpr, IndexExpr);
+return;
+  }
+
   const ConstantArrayType *ArrayTy =
   Context.getAsConstantArrayType(BaseExpr->getType());
 

diff  --git a/clang/test/CodeGenCXX/x86_64-arguments.cpp 
b/clang/test/CodeGenCXX/x86_64-arguments.cpp
index ebeba7fd65495..6915e5d6761dd 100644
--- a/clang/test/CodeGenCXX/x86_64-arguments.cpp
+++ b/clang/test/CodeGenCXX/x86_64-arguments.cpp
@@ -215,6 +215,6 @@ union U {
   float f1;
   char __attribute__((__vector_size__(1))) f2;
 };
-int f(union U u) { return u.f2[1]; }
+int f(union U u) { return u.f2[0]; }
 // CHECK-LABEL: define{{.*}} i32 @_ZN6test111fENS_1

[clang] [clang-tools-extra] [clang-tidy] Avoid processing declarations in system headers (PR #128150)

2025-03-11 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/128150

>From 1c2f485beb810d46553783689ed83ca595f51354 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Thu, 20 Feb 2025 12:37:15 +
Subject: [PATCH] [clang-tidy] Avoid processing declarations in system headers

Currently, clang-tidy processes the entire TranslationUnit, including
declarations in system headers. However, the work done in system
headers is discarded at the very end when presenting results, unless
the SystemHeaders option is active.

This is a lot of wasted work, and makes clang-tidy very slow.
In comparison, clangd only processes declarations in the main file,
and it's claimed to be 10x faster than clang-tidy:

https://github.com/lljbash/clangd-tidy

To solve this problem, we can apply a similar solution done in clangd
into clang-tidy. We do this by changing the traversal scope from the
default TranslationUnitDecl, to only contain the top-level declarations
that are _not_ part of system headers. We do this in the
MatchASTConsumer class, so the logic can be reused by other tools.
This behavior is currently off by default, and only clang-tidy
enables skipping system headers. If wanted, this behavior can be
activated by other tools in follow-up patches.

I had to move MatchFinderOptions out of the MatchFinder class,
because otherwise I could not set a default value for the
"bool SkipSystemHeaders" member otherwise. The compiler error message
was "default member initializer required before the end of its
enclosing class".

Note: this behavior is not active if the user requests warnings from
system headers via the SystemHeaders option.

Note2: out of all the unit tests, only one of them fails:

readability/identifier-naming-anon-record-fields.cpp

This is because the limited traversal scope no longer includes the
"CXXRecordDecl" of the global anonymous union, see:
https://github.com/llvm/llvm-project/issues/130618

I have not found a way to make this work. For now, document the
technical debt introduced.

Note3: I have purposely decided to make this new feature enabled by
default, instead of adding a new "opt-in/opt-out" flag. Having a new
flag would mean duplicating all our tests to ensure they work in both
modes, which would be infeasible. Having it enabled by default allow
people to get the benefits immediately. Given that all unit tests pass,
the risk for regressions is low. Even if that's the case, the only
issue would be false negatives (fewer things are detected), which
are much more tolerable than false positives.

Credits: original implementation by @njames93, here:
https://reviews.llvm.org/D150126

This implementation is simpler in the sense that it does not consider
HeaderFilterRegex to filter even further. A follow-up patch could
include the functionality if wanted.

Fixes #52959
---
 clang-tools-extra/clang-query/Query.cpp   |  2 +-
 clang-tools-extra/clang-tidy/ClangTidy.cpp|  6 +++-
 .../cert/DontModifyStdNamespaceCheck.cpp  | 32 ++---
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +++
 .../identifier-naming-anon-record-fields.cpp  | 22 +++-
 .../clang-tidy/infrastructure/file-filter.cpp |  7 
 .../infrastructure/system-headers.cpp |  4 +--
 clang/docs/ReleaseNotes.rst   |  5 +++
 .../clang/ASTMatchers/ASTMatchFinder.h| 33 ++
 clang/lib/ASTMatchers/ASTMatchFinder.cpp  | 34 ---
 .../ASTMatchers/ASTMatchersInternalTest.cpp   |  2 +-
 11 files changed, 107 insertions(+), 45 deletions(-)

diff --git a/clang-tools-extra/clang-query/Query.cpp 
b/clang-tools-extra/clang-query/Query.cpp
index 382aa5d6fe25e..091713600686e 100644
--- a/clang-tools-extra/clang-query/Query.cpp
+++ b/clang-tools-extra/clang-query/Query.cpp
@@ -114,7 +114,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession 
&QS) const {
 Profiler.emplace();
 
   for (auto &AST : QS.ASTs) {
-ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
+ast_matchers::MatchFinderOptions FinderOptions;
 std::optional> Records;
 if (QS.EnableProfile) {
   Records.emplace();
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 733a53a0f5dcc..d99847a82d168 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -420,7 +420,7 @@ ClangTidyASTConsumerFactory::createASTConsumer(
   std::vector> Checks =
   CheckFactories->createChecksForLanguage(&Context);
 
-  ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
+  ast_matchers::MatchFinderOptions FinderOptions;
 
   std::unique_ptr Profiling;
   if (Context.getEnableProfiling()) {
@@ -429,6 +429,10 @@ ClangTidyASTConsumerFactory::createASTConsumer(
 FinderOptions.CheckProfiling.emplace(Profiling->Records);
   }
 
+  // Avoid processing system headers, unless the user explicitly requests it
+  if (!Context.getOptions()

[clang] [Clang][NFC] Rename and update_cc_test_checks over strictfp-elementwise-builtins.cpp (PR #130747)

2025-03-11 Thread Matt Arsenault via cfe-commits

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


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


[clang] [clang] Predefine `_CRT_USE_BUILTIN_OFFSETOF` in MS-compatible modes (PR #127568)

2025-03-11 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja updated 
https://github.com/llvm/llvm-project/pull/127568

>From 2c9e6e45944891af54cba9648297a996bb4d8cca Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Tue, 18 Feb 2025 14:03:35 +0800
Subject: [PATCH 1/3] [clang] Predefine `_CRT_USE_BUILTIN_OFFSETOF` in
 MS-compatible modes

This patch makes Clang predefine `_CRT_USE_BUILTIN_OFFSETOF` in
MS-compatible modes. The macro can make the offsetof provided by MS
UCRT's `` to select the `__builtin_offsetof` version,
so with it Clang (Clang-cl) can directly consume UCRT's `offsetof`.

MSVC predefines the macro as `1` since at least VS 2017 19.14, but I
think it's also OK to define it in "older" compatible modes.
---
 clang/lib/Basic/Targets/OSTargets.cpp |  2 ++
 clang/test/Sema/offsetof-ucrt.c   | 17 +
 clang/test/SemaCXX/offsetof-ucrt.cpp  | 17 +
 3 files changed, 36 insertions(+)
 create mode 100644 clang/test/Sema/offsetof-ucrt.c
 create mode 100644 clang/test/SemaCXX/offsetof-ucrt.cpp

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 8af6623e5cb15..2e57c286c9a16 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -220,6 +220,8 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
 // FIXME We cannot encode the revision information into 32-bits
 Builder.defineMacro("_MSC_BUILD", Twine(1));
+// https://github.com/llvm/llvm-project/issues/59689
+Builder.defineMacro("_CRT_USE_BUILTIN_OFFSETOF", Twine(1));
 
 if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
   Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
diff --git a/clang/test/Sema/offsetof-ucrt.c b/clang/test/Sema/offsetof-ucrt.c
new file mode 100644
index 0..60c9ae3b5650e
--- /dev/null
+++ b/clang/test/Sema/offsetof-ucrt.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify 
-fms-compatibility
+// expected-no-diagnostics
+
+typedef __typeof__(sizeof(0)) size_t;
+
+#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF
+#ifdef __cplusplus
+#define offsetof(s,m) ((::size_t)&reinterpret_casts*)0)->m)))
+#else
+#define offsetof(s,m) ((size_t)&(((s*)0)->m))
+#endif
+#else
+#define offsetof(s,m) __builtin_offsetof(s,m)
+#endif
+
+struct S { int a; };
+_Static_assert(offsetof(struct S, a) == 0, "");
diff --git a/clang/test/SemaCXX/offsetof-ucrt.cpp 
b/clang/test/SemaCXX/offsetof-ucrt.cpp
new file mode 100644
index 0..a679fa01133f4
--- /dev/null
+++ b/clang/test/SemaCXX/offsetof-ucrt.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify 
-fms-compatibility
+// expected-no-diagnostics
+
+typedef __typeof__(sizeof(0)) size_t;
+
+#if defined _MSC_VER && !defined _CRT_USE_BUILTIN_OFFSETOF
+#ifdef __cplusplus
+#define offsetof(s,m) ((::size_t)&reinterpret_casts*)0)->m)))
+#else
+#define offsetof(s,m) ((size_t)&(((s*)0)->m))
+#endif
+#else
+#define offsetof(s,m) __builtin_offsetof(s,m)
+#endif
+
+struct S { int a; };
+_Static_assert(offsetof(S, a) == 0, "");

>From 4dc9bed47d7b4802e91b1774d8371e169f3f942c Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Fri, 21 Feb 2025 17:00:37 +0800
Subject: [PATCH 2/3] Address @AaronBallman's review comments

---
 clang/lib/Basic/Targets/OSTargets.cpp |  2 +-
 clang/test/Sema/offsetof-ucrt.c   | 11 +++
 clang/test/SemaCXX/offsetof-ucrt.cpp  | 11 +++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index 2e57c286c9a16..e744e84a5b079 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -220,7 +220,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
 // FIXME We cannot encode the revision information into 32-bits
 Builder.defineMacro("_MSC_BUILD", Twine(1));
-// https://github.com/llvm/llvm-project/issues/59689
+// Exposed by MSVC, used in their stddef.h.
 Builder.defineMacro("_CRT_USE_BUILTIN_OFFSETOF", Twine(1));
 
 if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
diff --git a/clang/test/Sema/offsetof-ucrt.c b/clang/test/Sema/offsetof-ucrt.c
index 60c9ae3b5650e..05c3d87ce66ca 100644
--- a/clang/test/Sema/offsetof-ucrt.c
+++ b/clang/test/Sema/offsetof-ucrt.c
@@ -1,8 +1,19 @@
 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify 
-fms-compatibility
+// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -verify
 // expected-no-diagnostics
 
 typedef __typeof__(sizeof(0)) size_t;
 
+#ifdef _MSC_VER
+#ifndef _CRT_USE_BUILTIN_OFFSETOF
+#error _CRT_USE_BUILTIN_OFFSETOF should be predefined in MSVC-compatible modes.
+#endif
+#

[clang] [NFC][analyzer] Remove CheckerNameRef::getName() (PR #130780)

2025-03-11 Thread via cfe-commits

llvmbot wrote:




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

Author: Donát Nagy (NagyDonat)


Changes

`CheckerNameRef` is a trivial wrapper around a `StringRef` which is guaranteed 
to be owned by the `CheckerRegistry` (the only `friend` of the class) because 
other code can't call the private constructor.

This class had offered two ways to recover the plain `StringRef`: an an 
`operator StringRef()` for implicit conversion and a method `StringRef 
getName()` which could be called explicitly.

However this method name was really confusing, because it implies "get the name 
of this object" instead of "get this name as a plain `StringRef`"; so I removed 
it from the codebase and used `static_cast` in the two 
locations where the cast wasn't performed implicitly.

This commit "prepares the ground" for planned improvements in checker name 
handling.

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


7 Files Affected:

- (modified) clang/include/clang/StaticAnalyzer/Core/CheckerManager.h (-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp (+6-6) 
- (modified) clang/lib/StaticAnalyzer/Core/BugReporter.cpp (+2-2) 
- (modified) clang/lib/StaticAnalyzer/Core/Checker.cpp (+3-5) 
- (modified) clang/lib/StaticAnalyzer/Core/CheckerManager.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h 
b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index 7d3120b5395c4..929ce96824e95 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -113,7 +113,6 @@ class CheckerNameRef {
 public:
   CheckerNameRef() = default;
 
-  StringRef getName() const { return Name; }
   operator StringRef() const { return Name; }
 };
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index 0b6c5163a1637..1b87a0d8af38d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -431,7 +431,7 @@ void ExprInspectionChecker::analyzerHashDump(const CallExpr 
*CE,
   const SourceManager &SM = C.getSourceManager();
   FullSourceLoc FL(CE->getArg(0)->getBeginLoc(), SM);
   std::string HashContent =
-  getIssueString(FL, getCheckerName().getName(), "Category",
+  getIssueString(FL, getCheckerName(), "Category",
  C.getLocationContext()->getDecl(), Opts);
 
   reportBug(HashContent, C);
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 0d1213ddf8b01..1c4293c30abdb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -3885,7 +3885,7 @@ void MallocChecker::printState(raw_ostream &Out, 
ProgramStateRef State,
   Out << " : ";
   Data.dump(Out);
   if (CheckKind)
-Out << " (" << CheckNames[*CheckKind].getName() << ")";
+Out << " (" << CheckNames[*CheckKind] << ")";
   Out << NL;
 }
   }
diff --git a/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
index 28320f46f237a..bd2f88c7b1bcc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
@@ -272,12 +272,12 @@ void ValistChecker::reportLeakedVALists(const 
RegionVector &LeakedVALists,
 if (!BT_leakedvalist) {
   // FIXME: maybe creating a new check name for this type of bug is a 
better
   // solution.
-  BT_leakedvalist.reset(
-  new BugType(CheckNames[CK_Unterminated].getName().empty()
-  ? CheckNames[CK_Uninitialized]
-  : CheckNames[CK_Unterminated],
-  "Leaked va_list", categories::MemoryError,
-  /*SuppressOnSink=*/true));
+  BT_leakedvalist.reset(new BugType(
+  static_cast(CheckNames[CK_Unterminated]).empty()
+  ? CheckNames[CK_Uninitialized]
+  : CheckNames[CK_Unterminated],
+  "Leaked va_list", categories::MemoryError,
+  /*SuppressOnSink=*/true));
 }
 
 const ExplodedNode *StartNode = getStartCallSite(N, Reg);
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 7101b1eb2c7f5..93ea4cc1d66db 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3442,8 +3442,8 @@ void BugReporter::EmitBasicReport(const Decl 
*DeclWithIssue,
 BugType *BugReporter::getBugTypeForName(CheckerNameRef CheckName,
 StringRef name, StringRef category) {
   SmallStr

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcibi (Branch Immediate) extension (PR #130779)

2025-03-11 Thread via cfe-commits

https://github.com/hchandel created 
https://github.com/llvm/llvm-project/pull/130779

This extension adds twelve conditional branch instructions that use an 
immediate operand for the source.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.


>From ed67e38e0e2d8dbdf67bd2e5123b49f3271e9e58 Mon Sep 17 00:00:00 2001
From: Harsh Chandel 
Date: Tue, 11 Mar 2025 13:01:34 +0530
Subject: [PATCH] [RISCV] Add Qualcomm uC Xqcibi (Branch Immediate) extension
 This extension adds twelve conditional branch instructions that use an
 immediate operand for the source.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.

Change-Id: I20307dd485ec0234bc08b0ad3940563b9779ea70
---
 .../Driver/print-supported-extensions-riscv.c |   1 +
 llvm/docs/RISCVUsage.rst  |   3 +
 llvm/docs/ReleaseNotes.md |   2 +
 .../Target/RISCV/AsmParser/RISCVAsmParser.cpp |  42 
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  11 +-
 .../Target/RISCV/MCTargetDesc/RISCVBaseInfo.h |   3 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   8 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td   |  68 ++
 llvm/lib/TargetParser/RISCVISAInfo.cpp|   6 +-
 llvm/test/CodeGen/RISCV/attributes.ll |   2 +
 llvm/test/MC/RISCV/xqcibi-invalid.s   | 208 ++
 llvm/test/MC/RISCV/xqcibi-valid.s |  71 ++
 .../TargetParser/RISCVISAInfoTest.cpp |   4 +-
 13 files changed, 420 insertions(+), 9 deletions(-)
 create mode 100644 llvm/test/MC/RISCV/xqcibi-invalid.s
 create mode 100644 llvm/test/MC/RISCV/xqcibi-valid.s

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 69b76f0c4c4cd..87140220fea9b 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -196,6 +196,7 @@
 // CHECK-NEXT: xqccmp   0.1   'Xqccmp' (Qualcomm 16-bit 
Push/Pop and Double Moves)
 // CHECK-NEXT: xqcia0.4   'Xqcia' (Qualcomm uC 
Arithmetic Extension)
 // CHECK-NEXT: xqciac   0.3   'Xqciac' (Qualcomm uC 
Load-Store Address Calculation Extension)
+// CHECK-NEXT: xqcibi   0.2   'Xqcibi' (Qualcomm uC Branch 
Immediate Extension)
 // CHECK-NEXT: xqcibm   0.4   'Xqcibm' (Qualcomm uC Bit 
Manipulation Extension)
 // CHECK-NEXT: xqcicli  0.2   'Xqcicli' (Qualcomm uC 
Conditional Load Immediate Extension)
 // CHECK-NEXT: xqcicm   0.2   'Xqcicm' (Qualcomm uC 
Conditional Move Extension)
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 62c6a4fd80fd4..ecf63eda38723 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -438,6 +438,9 @@ The current vendor extensions supported are:
 ``experimental-Xqciac``
   LLVM implements `version 0.3 of the Qualcomm uC Load-Store Address 
Calculation extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
+``experimental-Xqcibi``
+  LLVM implements `version 0.2 of the Qualcomm uC Branch Immediate extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+
 ``experimental-Xqcibm``
   LLVM implements `version 0.4 of the Qualcomm uC Bit Manipulation extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index d7a80ae93aa34..2f537b33577c4 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -111,6 +111,8 @@ Changes to the RISC-V Backend
   extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcibm` (Bit 
Manipulation)
   extension.
+* Adds experimental assembler support for the Qualcomm uC 'Xqcibi` (Branch 
Immediate)
+  extension.
 * Adds experimental assembler and code generation support for the Qualcomm
   'Xqccmp' extension, which is a frame-pointer convention compatible version of
   Zcmp.
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index b342c18bece08..eb8396224a128 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -825,6 +825,17 @@ struct RISCVOperand final : public MCParsedAsmOperand {
VK ==

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcibi (Branch Immediate) extension (PR #130779)

2025-03-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: quic_hchandel (hchandel)


Changes

This extension adds twelve conditional branch instructions that use an 
immediate operand for the source.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.


---

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


13 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1) 
- (modified) llvm/docs/RISCVUsage.rst (+3) 
- (modified) llvm/docs/ReleaseNotes.md (+2) 
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+42) 
- (modified) llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp (+6-5) 
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h (+3) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+8) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td (+68) 
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+3-3) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+2) 
- (added) llvm/test/MC/RISCV/xqcibi-invalid.s (+208) 
- (added) llvm/test/MC/RISCV/xqcibi-valid.s (+71) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+3-1) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 69b76f0c4c4cd..87140220fea9b 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -196,6 +196,7 @@
 // CHECK-NEXT: xqccmp   0.1   'Xqccmp' (Qualcomm 16-bit 
Push/Pop and Double Moves)
 // CHECK-NEXT: xqcia0.4   'Xqcia' (Qualcomm uC 
Arithmetic Extension)
 // CHECK-NEXT: xqciac   0.3   'Xqciac' (Qualcomm uC 
Load-Store Address Calculation Extension)
+// CHECK-NEXT: xqcibi   0.2   'Xqcibi' (Qualcomm uC Branch 
Immediate Extension)
 // CHECK-NEXT: xqcibm   0.4   'Xqcibm' (Qualcomm uC Bit 
Manipulation Extension)
 // CHECK-NEXT: xqcicli  0.2   'Xqcicli' (Qualcomm uC 
Conditional Load Immediate Extension)
 // CHECK-NEXT: xqcicm   0.2   'Xqcicm' (Qualcomm uC 
Conditional Move Extension)
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 62c6a4fd80fd4..ecf63eda38723 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -438,6 +438,9 @@ The current vendor extensions supported are:
 ``experimental-Xqciac``
   LLVM implements `version 0.3 of the Qualcomm uC Load-Store Address 
Calculation extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
+``experimental-Xqcibi``
+  LLVM implements `version 0.2 of the Qualcomm uC Branch Immediate extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+
 ``experimental-Xqcibm``
   LLVM implements `version 0.4 of the Qualcomm uC Bit Manipulation extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index d7a80ae93aa34..2f537b33577c4 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -111,6 +111,8 @@ Changes to the RISC-V Backend
   extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcibm` (Bit 
Manipulation)
   extension.
+* Adds experimental assembler support for the Qualcomm uC 'Xqcibi` (Branch 
Immediate)
+  extension.
 * Adds experimental assembler and code generation support for the Qualcomm
   'Xqccmp' extension, which is a frame-pointer convention compatible version of
   Zcmp.
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index b342c18bece08..eb8396224a128 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -825,6 +825,17 @@ struct RISCVOperand final : public MCParsedAsmOperand {
VK == RISCVMCExpr::VK_RISCV_None;
   }
 
+  bool isSImm5NonZero() const {
+if (!isImm())
+  return false;
+RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
+int64_t Imm;
+bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
+return IsConstantImm && Imm != 0 &&
+   isInt<5>(fixImmediateForRV32(Imm, isRV64Imm())) &&
+   VK == RISCVMCExpr::VK_RISCV_None;
+  }
+
   bool isSImm6() const {
 if (!isImm())
   

[clang] [NFC][analyzer] Remove CheckerNameRef::getName() (PR #130780)

2025-03-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Donát Nagy (NagyDonat)


Changes

`CheckerNameRef` is a trivial wrapper around a `StringRef` which is guaranteed 
to be owned by the `CheckerRegistry` (the only `friend` of the class) because 
other code can't call the private constructor.

This class had offered two ways to recover the plain `StringRef`: an an 
`operator StringRef()` for implicit conversion and a method `StringRef 
getName()` which could be called explicitly.

However this method name was really confusing, because it implies "get the name 
of this object" instead of "get this name as a plain `StringRef`"; so I removed 
it from the codebase and used `static_cast` in the two 
locations where the cast wasn't performed implicitly.

This commit "prepares the ground" for planned improvements in checker name 
handling.

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


7 Files Affected:

- (modified) clang/include/clang/StaticAnalyzer/Core/CheckerManager.h (-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp (+6-6) 
- (modified) clang/lib/StaticAnalyzer/Core/BugReporter.cpp (+2-2) 
- (modified) clang/lib/StaticAnalyzer/Core/Checker.cpp (+3-5) 
- (modified) clang/lib/StaticAnalyzer/Core/CheckerManager.cpp (+3-3) 


``diff
diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h 
b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index 7d3120b5395c4..929ce96824e95 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -113,7 +113,6 @@ class CheckerNameRef {
 public:
   CheckerNameRef() = default;
 
-  StringRef getName() const { return Name; }
   operator StringRef() const { return Name; }
 };
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index 0b6c5163a1637..1b87a0d8af38d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -431,7 +431,7 @@ void ExprInspectionChecker::analyzerHashDump(const CallExpr 
*CE,
   const SourceManager &SM = C.getSourceManager();
   FullSourceLoc FL(CE->getArg(0)->getBeginLoc(), SM);
   std::string HashContent =
-  getIssueString(FL, getCheckerName().getName(), "Category",
+  getIssueString(FL, getCheckerName(), "Category",
  C.getLocationContext()->getDecl(), Opts);
 
   reportBug(HashContent, C);
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 0d1213ddf8b01..1c4293c30abdb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -3885,7 +3885,7 @@ void MallocChecker::printState(raw_ostream &Out, 
ProgramStateRef State,
   Out << " : ";
   Data.dump(Out);
   if (CheckKind)
-Out << " (" << CheckNames[*CheckKind].getName() << ")";
+Out << " (" << CheckNames[*CheckKind] << ")";
   Out << NL;
 }
   }
diff --git a/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
index 28320f46f237a..bd2f88c7b1bcc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
@@ -272,12 +272,12 @@ void ValistChecker::reportLeakedVALists(const 
RegionVector &LeakedVALists,
 if (!BT_leakedvalist) {
   // FIXME: maybe creating a new check name for this type of bug is a 
better
   // solution.
-  BT_leakedvalist.reset(
-  new BugType(CheckNames[CK_Unterminated].getName().empty()
-  ? CheckNames[CK_Uninitialized]
-  : CheckNames[CK_Unterminated],
-  "Leaked va_list", categories::MemoryError,
-  /*SuppressOnSink=*/true));
+  BT_leakedvalist.reset(new BugType(
+  static_cast(CheckNames[CK_Unterminated]).empty()
+  ? CheckNames[CK_Uninitialized]
+  : CheckNames[CK_Unterminated],
+  "Leaked va_list", categories::MemoryError,
+  /*SuppressOnSink=*/true));
 }
 
 const ExplodedNode *StartNode = getStartCallSite(N, Reg);
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index 7101b1eb2c7f5..93ea4cc1d66db 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3442,8 +3442,8 @@ void BugReporter::EmitBasicReport(const Decl 
*DeclWithIssue,
 BugType *BugReporter::getBugTypeForName(CheckerNameRef CheckName,
 StringRef name, StringRef category) {
   SmallString<136> fullDesc;

[clang] [llvm] [RISCV] Add Qualcomm uC Xqcibi (Branch Immediate) extension (PR #130779)

2025-03-11 Thread via cfe-commits

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


[clang] [clang-tools-extra] [AstMatcher]`templateArgumentCountIs` support `FunctionDecl` (PR #130416)

2025-03-11 Thread Aaron Ballman via cfe-commits


@@ -4833,6 +4833,17 @@ Narrowing Matchers
 
 
 
+MatcherFunctionDecl>templateArgumentCountIsunsigned
 N
+Matches if 
the number of template arguments equals N.
+
+Given
+  template struct C {};

AaronBallman wrote:

This is auto-generated from the python script based on the comments on the 
matcher.

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


[clang] [NFC][analyzer] Remove CheckerNameRef::getName() (PR #130780)

2025-03-11 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

:thinking: Instead of this change I could also imagine introducing an 
accurately named explicit method – e.g. `StringRef toStringRef()` – and using 
that for all `CheckerNameRef` → `StringRef` conversions (including the half 
dozen cases where the codebase already uses `operator StringRef()` implicitly). 

@steakhal or anybody else: What do you think about this situation? Which would 
be the more elegant approach: the implicit `operator StringRef()` or the 
explicit `toStringRef()`?

I would be grateful for a quick review on this PR, because I have several 
mostly written changes that I will need to refactor depending on this change.

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


[clang] [NFC][analyzer] Remove CheckerNameRef::getName() (PR #130780)

2025-03-11 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat created 
https://github.com/llvm/llvm-project/pull/130780

`CheckerNameRef` is a trivial wrapper around a `StringRef` which is guaranteed 
to be owned by the `CheckerRegistry` (the only `friend` of the class) because 
other code can't call the private constructor.

This class had offered two ways to recover the plain `StringRef`: an an 
`operator StringRef()` for implicit conversion and a method `StringRef 
getName()` which could be called explicitly.

However this method name was really confusing, because it implies "get the name 
of this object" instead of "get this name as a plain `StringRef`"; so I removed 
it from the codebase and used `static_cast` in the two locations 
where the cast wasn't performed implicitly.

This commit "prepares the ground" for planned improvements in checker name 
handling.

From 0a110977e8b170ab1361e6120e6f673ee5089f3f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Tue, 11 Mar 2025 14:52:50 +0100
Subject: [PATCH] [NFC][analyzer] Remove CheckerNameRef::getName()

`CheckerNameRef` is a trivial wrapper around a `StringRef` which is
guaranteed to be owned by the `CheckerRegistry` (the only `friend` of
the class) because other code can't call the private constructor.

This class had offered two ways to recover the plain `StringRef`: an
an `operator StringRef()` for implicit conversion and a method
`StringRef getName()` which could be called explicitly.

However this method name was really confusing, because it implies "get
the name of this object" instead of "get this name as a plain
`StringRef`"; so I removed it from the codebase and used
`static_cast` in the two locations where the cast wasn't
performed implicitly.

This commit "prepares the ground" for planned improvements in checker
name handling.
---
 .../clang/StaticAnalyzer/Core/CheckerManager.h   |  1 -
 .../Checkers/ExprInspectionChecker.cpp   |  2 +-
 clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp  |  2 +-
 clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp  | 12 ++--
 clang/lib/StaticAnalyzer/Core/BugReporter.cpp|  4 ++--
 clang/lib/StaticAnalyzer/Core/Checker.cpp|  8 +++-
 clang/lib/StaticAnalyzer/Core/CheckerManager.cpp |  6 +++---
 7 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h 
b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index 7d3120b5395c4..929ce96824e95 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -113,7 +113,6 @@ class CheckerNameRef {
 public:
   CheckerNameRef() = default;
 
-  StringRef getName() const { return Name; }
   operator StringRef() const { return Name; }
 };
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
index 0b6c5163a1637..1b87a0d8af38d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -431,7 +431,7 @@ void ExprInspectionChecker::analyzerHashDump(const CallExpr 
*CE,
   const SourceManager &SM = C.getSourceManager();
   FullSourceLoc FL(CE->getArg(0)->getBeginLoc(), SM);
   std::string HashContent =
-  getIssueString(FL, getCheckerName().getName(), "Category",
+  getIssueString(FL, getCheckerName(), "Category",
  C.getLocationContext()->getDecl(), Opts);
 
   reportBug(HashContent, C);
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index 0d1213ddf8b01..1c4293c30abdb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -3885,7 +3885,7 @@ void MallocChecker::printState(raw_ostream &Out, 
ProgramStateRef State,
   Out << " : ";
   Data.dump(Out);
   if (CheckKind)
-Out << " (" << CheckNames[*CheckKind].getName() << ")";
+Out << " (" << CheckNames[*CheckKind] << ")";
   Out << NL;
 }
   }
diff --git a/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
index 28320f46f237a..bd2f88c7b1bcc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
@@ -272,12 +272,12 @@ void ValistChecker::reportLeakedVALists(const 
RegionVector &LeakedVALists,
 if (!BT_leakedvalist) {
   // FIXME: maybe creating a new check name for this type of bug is a 
better
   // solution.
-  BT_leakedvalist.reset(
-  new BugType(CheckNames[CK_Unterminated].getName().empty()
-  ? CheckNames[CK_Uninitialized]
-  : CheckNames[CK_Unterminated],
-  "Leaked va_list", categories::MemoryError,
-  /*SuppressOnSink=*/true));
+  BT_leakedval

[clang] [clang-tools-extra] [AstMatcher]`templateArgumentCountIs` support `FunctionDecl` (PR #130416)

2025-03-11 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/130416

>From ca39210f6a28569116759f9e62b6120ddd746968 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 8 Mar 2025 21:22:47 +0800
Subject: [PATCH 1/5] [clang-tidy][NFC]refactor matcher for
 bugprone-optional-value-conversion

The old `constructFrom` has hidden requirement which TypeMatcher must be used 
before ArgumentMatcher because there are bind inside.
Inlining this function to make it more intuitive.
---
 .../bugprone/OptionalValueConversionCheck.cpp | 42 +--
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
index 55ca4809f058a..33e823ac07490 100644
--- a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
@@ -27,28 +27,11 @@ AST_MATCHER_P(QualType, hasCleanType, Matcher, 
InnerMatcher) {
   Finder, Builder);
 }
 
-constexpr std::array NameList{
+constexpr std::array MakeSmartPtrList{
 "::std::make_unique",
 "::std::make_shared",
 };
 
-Matcher constructFrom(Matcher TypeMatcher,
-Matcher ArgumentMatcher) {
-  return expr(
-  anyOf(
-  // construct optional
-  cxxConstructExpr(argumentCountIs(1U), hasType(TypeMatcher),
-   hasArgument(0U, ArgumentMatcher)),
-  // known template methods in std
-  callExpr(argumentCountIs(1),
-   callee(functionDecl(
-   matchers::matchesAnyListedName(NameList),
-   hasTemplateArgument(0, refersToType(TypeMatcher,
-   hasArgument(0, ArgumentMatcher))),
-  unless(anyOf(hasAncestor(typeLoc()),
-   hasAncestor(expr(matchers::hasUnevaluatedContext());
-}
-
 } // namespace
 
 OptionalValueConversionCheck::OptionalValueConversionCheck(
@@ -74,7 +57,7 @@ void 
OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
   auto EqualsBoundOptionalType =
   qualType(hasCleanType(equalsBoundNode("optional-type")));
 
-  auto OptionalDereferenceMatcher = callExpr(
+  auto OptionalDerefMatcherImpl = callExpr(
   anyOf(
   cxxOperatorCallExpr(hasOverloadedOperatorName("*"),
   
hasUnaryOperand(hasType(EqualsBoundOptionalType)))
@@ -88,11 +71,24 @@ void 
OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
 
   auto StdMoveCallMatcher =
   callExpr(argumentCountIs(1), 
callee(functionDecl(hasName("::std::move"))),
-   hasArgument(0, ignoringImpCasts(OptionalDereferenceMatcher)));
+   hasArgument(0, ignoringImpCasts(OptionalDerefMatcherImpl)));
+  auto OptionalDerefMatcher =
+  ignoringImpCasts(anyOf(OptionalDerefMatcherImpl, StdMoveCallMatcher));
+
   Finder->addMatcher(
-  expr(constructFrom(BindOptionalType,
- ignoringImpCasts(anyOf(OptionalDereferenceMatcher,
-StdMoveCallMatcher
+  expr(anyOf(
+   // construct optional
+   cxxConstructExpr(argumentCountIs(1), hasType(BindOptionalType),
+hasArgument(0, OptionalDerefMatcher)),
+   // known template methods in std
+   callExpr(
+   argumentCountIs(1),
+   callee(functionDecl(
+   matchers::matchesAnyListedName(MakeSmartPtrList),
+   hasTemplateArgument(0, 
refersToType(BindOptionalType,
+   hasArgument(0, OptionalDerefMatcher))),
+   unless(anyOf(hasAncestor(typeLoc()),
+hasAncestor(expr(matchers::hasUnevaluatedContext())
   .bind("expr"),
   this);
 }

>From 97ea31513d00893e797ff3c97ac441e54a11bbb8 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 8 Mar 2025 21:33:02 +0800
Subject: [PATCH 2/5] [AstMatcher]`templateArgumentCountIs` support
 `FunctionDecl`

`hasTemplateArgument` and `templateArgumentCountIs` are always used together. 
It is more convenient to make then support `FunctionDecl`.
---
 clang/include/clang/ASTMatchers/ASTMatchers.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 0f7e3a8a01762..03d522072f6c1 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1090,6 +1090,7 @@ AST_POLYMORPHIC_MATCHER_P2(
 AST_POLYMORPHIC_MATCHER_P(
 templateArgumentCountIs,
 AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,
+VarTemplateSpecializationDecl, 
FunctionDecl,
 TemplateSpecializationType),
 unsigned, N) {
   retur

[clang] [llvm] [RISCV] Update to Xqciint v0.4 (PR #130219)

2025-03-11 Thread Sam Elliott via cfe-commits

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


[clang] [llvm] [RISCV] Add Qualcomn uC Xqcili (load large immediates) extension (PR #130012)

2025-03-11 Thread Sam Elliott via cfe-commits

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

LGTM. Thanks!

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


[clang] [flang] [flang] Add support for -f[no-]verbose-asm (PR #130788)

2025-03-11 Thread Tom Eccles via cfe-commits

https://github.com/tblah created 
https://github.com/llvm/llvm-project/pull/130788

This flag provides extra commentary in the assembly output. It is in 
CodeGenOptions to match what is done in clang, even though the backend treats 
it as a target option.

>From 5d3c1cc1d40b308b93cc47c78c6c3ca677f55155 Mon Sep 17 00:00:00 2001
From: Tom Eccles 
Date: Tue, 11 Mar 2025 15:54:35 +
Subject: [PATCH] [flang] Add support for -f[no-]verbose-asm

This flag provides extra commentary in the assembly output. It is in
CodeGenOptions to match what is done in clang, even though the backend
treats it as a target option.
---
 clang/include/clang/Driver/Options.td   |  5 +++--
 clang/lib/Driver/ToolChains/Flang.cpp   |  3 ++-
 flang/include/flang/Frontend/CodeGenOptions.def |  2 ++
 flang/lib/Frontend/CompilerInvocation.cpp   |  4 
 flang/lib/Frontend/FrontendActions.cpp  |  2 ++
 flang/test/Driver/verbose-asm.f90   | 16 
 6 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Driver/verbose-asm.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e69cd6b833c3a..ac6392f92f311 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3467,7 +3467,7 @@ defm use_cxa_atexit : BoolFOption<"use-cxa-atexit",
   PosFlag>;
 def fno_unwind_tables : Flag<["-"], "fno-unwind-tables">, Group;
 def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   MarshallingInfoNegativeFlag>;
 def fno_working_directory : Flag<["-"], "fno-working-directory">, 
Group;
 def fobjc_arc : Flag<["-"], "fobjc-arc">, Group,
@@ -4142,7 +4142,8 @@ defm use_init_array : BoolFOption<"use-init-array",
   PosFlag>;
 def fno_var_tracking : Flag<["-"], "fno-var-tracking">, 
Group;
 def fverbose_asm : Flag<["-"], "fverbose-asm">, Group,
-  HelpText<"Generate verbose assembly output">;
+  HelpText<"Generate verbose assembly output">,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>;
 def dA : Flag<["-"], "dA">, Alias;
 defm visibility_from_dllstorageclass : 
BoolFOption<"visibility-from-dllstorageclass",
   LangOpts<"VisibilityFromDLLStorageClass">, DefaultFalse,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index d4fea633d0edf..09b77b4aab03d 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -172,7 +172,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
options::OPT_finit_global_zero,
options::OPT_fno_init_global_zero, 
options::OPT_ftime_report,
options::OPT_ftime_report_EQ, options::OPT_funroll_loops,
-   options::OPT_fno_unroll_loops});
+   options::OPT_fno_unroll_loops, options::OPT_fverbose_asm,
+   options::OPT_fno_verbose_asm});
 }
 
 void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 44cb5a2cdd497..d2ff06d5fe08a 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -42,5 +42,7 @@ ENUM_CODEGENOPT(DebugInfo,  
llvm::codegenoptions::DebugInfoKind, 4,  llvm::codeg
 ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, 
llvm::driver::VectorLibrary::NoLibrary) ///< Vector functions library to use
 ENUM_CODEGENOPT(FramePointer, llvm::FramePointerKind, 2, 
llvm::FramePointerKind::None) ///< Enable the usage of frame pointers
 
+CODEGENOPT(AsmVerbose, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 8b07a50824899..5451006960e8b 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -254,6 +254,10 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
   clang::driver::options::OPT_fno_unroll_loops,
   (opts.OptimizationLevel > 1));
 
+  if (args.hasFlag(clang::driver::options::OPT_fverbose_asm,
+   clang::driver::options::OPT_fno_verbose_asm, false))
+opts.AsmVerbose = 1;
+
   opts.AliasAnalysis = opts.OptimizationLevel > 0;
 
   // -mframe-pointer=none/non-leaf/all option.
diff --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 94de376aaf7d6..0ef2708bb42fb 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1284,6 +1284,8 @@ void CodeGenAction::executeAction() {
   // given on the command-line).
   llvm::TargetMachine &targetMachine = ci.getTargetMachine();
 
+  targetMachine.Options.MCOptions.AsmVerbose = 

[clang] [Clang] Fix the printout of CXXParenListInitExpr involving default arguments (PR #130731)

2025-03-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/130731

>From c643ba2de0bb3e5fcb6514b70c86e594badc396b Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 11 Mar 2025 14:18:20 +0800
Subject: [PATCH] [Clang] Fix the printout of CXXParenListInitExpr involving
 default arguments

The parantheses are unnecessary IMO because they should have been
handled in the parents of such expressions, e.g. in
CXXFunctionalCastExpr.

Moreover, we shouldn't join CXXDefaultInitExpr either because they
are not printed at all.
---
 clang/lib/AST/StmtPrinter.cpp  |  4 +---
 clang/test/CodeGen/p0963r3.cpp |  3 ---
 clang/test/SemaCXX/paren-list-agg-init.cpp | 18 ++
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index facdc4104c374..e0063ec5f25eb 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -2659,10 +2659,8 @@ void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
 }
 
 void StmtPrinter::VisitCXXParenListInitExpr(CXXParenListInitExpr *Node) {
-  OS << "(";
-  llvm::interleaveComma(Node->getInitExprs(), OS,
+  llvm::interleaveComma(Node->getUserSpecifiedInitExprs(), OS,
 [&](Expr *E) { PrintExpr(E); });
-  OS << ")";
 }
 
 void StmtPrinter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) 
{
diff --git a/clang/test/CodeGen/p0963r3.cpp b/clang/test/CodeGen/p0963r3.cpp
index b48b5294e093e..4a5e6c3f5d751 100644
--- a/clang/test/CodeGen/p0963r3.cpp
+++ b/clang/test/CodeGen/p0963r3.cpp
@@ -139,9 +139,6 @@ constexpr int bar(auto) {
   }();
   static_assert(value == S(1, 2));
 
-  // FIXME: The diagnostic message adds a trailing comma "static assertion 
failed due to requirement 'value == Case1::S((0, 1, ))'"
-  // static_assert(value == S(0, 1));
-
   constexpr auto value2 = [] {
 if (auto [a, b] = S(1, 2))
   return S(a, b);
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index 61afba85e1dff..c55604003bc33 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -357,3 +357,21 @@ ThroughAlias e(42);
 // beforecxx20-warning@-1 {{aggregate initialization of type 
'ThroughAlias' (aka 'int[1]') from a parenthesized list of values is a 
C++20 extension}} 
 
 }
+
+namespace CXXParenListInitExpr {
+
+struct S {
+  int a, b;
+  bool flag = false;
+
+  constexpr bool operator==(S rhs) {
+return a == rhs.a && b == rhs.b;
+  }
+};
+
+static_assert(S(1, 2) == S(1, 2));
+
+static_assert(S(1, 2) == S(3, 4));
+// expected-error@-1 {{failed due to requirement 'S(1, 2) == S(3, 4)'}}
+
+}

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


[clang] [Clang][CodeGen] Do not set inbounds flag for struct GEP with null base pointers (PR #130734)

2025-03-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yingwei Zheng (dtcxzyw)


Changes

In the LLVM middle-end we want to fold `gep inbounds null, idx -> null`: 
https://alive2.llvm.org/ce/z/5ZkPx-
This pattern is common in real-world programs. Generally, it exists in some 
(actually) unreachable blocks, which is introduced by JumpThreading.

However, some old-style offsetof macros are still widely used in real-world 
C/C++ code (e.g., hwloc/slurm/luajit). To avoid breaking existing code and 
inconvenience to downstream users, this patch removes the inbounds flag from 
the struct gep if the base pointer is null.


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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGBuilder.h (+10-5) 
- (modified) 
clang/test/CodeGen/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.c (+1-1) 
- (modified) 
clang/test/CodeGenCXX/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.cpp 
(+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index b8036cf6e6a30..11e8818b33397 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -223,11 +223,16 @@ class CGBuilderTy : public CGBuilderBaseTy {
 const llvm::StructLayout *Layout = DL.getStructLayout(ElTy);
 auto Offset = CharUnits::fromQuantity(Layout->getElementOffset(Index));
 
-return Address(CreateStructGEP(Addr.getElementType(), 
Addr.getBasePointer(),
-   Index, Name),
-   ElTy->getElementType(Index),
-   Addr.getAlignment().alignmentAtOffset(Offset),
-   Addr.isKnownNonNull());
+// Specially, we don't add inbounds flags if the base pointer is null.
+// This is a workaround for old-style offsetof macros.
+llvm::GEPNoWrapFlags NWFlags = llvm::GEPNoWrapFlags::noUnsignedWrap();
+if (!isa(Addr.getBasePointer()))
+  NWFlags |= llvm::GEPNoWrapFlags::inBounds();
+return Address(
+CreateConstGEP2_32(Addr.getElementType(), Addr.getBasePointer(), 0,
+   Index, Name, NWFlags),
+ElTy->getElementType(Index),
+Addr.getAlignment().alignmentAtOffset(Offset), Addr.isKnownNonNull());
   }
 
   /// Given
diff --git 
a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.c 
b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.c
index 68c0ee3a3a885..a7cfd77766712 100644
--- a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.c
+++ b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.c
@@ -17,7 +17,7 @@ struct S {
 
 // CHECK-LABEL: @get_offset_of_y_naively(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:ret i64 ptrtoint (ptr getelementptr inbounds nuw 
([[STRUCT_S:%.*]], ptr null, i32 0, i32 1) to i64)
+// CHECK-NEXT:ret i64 ptrtoint (ptr getelementptr nuw ([[STRUCT_S:%.*]], 
ptr null, i32 0, i32 1) to i64)
 //
 uintptr_t get_offset_of_y_naively(void) {
   return ((uintptr_t)(&(((struct S *)0)->y)));
diff --git 
a/clang/test/CodeGenCXX/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.cpp 
b/clang/test/CodeGenCXX/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.cpp
index 34d4f4c9e34eb..f00a2c486574c 100644
--- 
a/clang/test/CodeGenCXX/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.cpp
+++ 
b/clang/test/CodeGenCXX/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.cpp
@@ -10,7 +10,7 @@ struct S {
 
 // CHECK-LABEL: @_Z23get_offset_of_y_naivelyv(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:ret i64 ptrtoint (ptr getelementptr inbounds nuw 
([[STRUCT_S:%.*]], ptr null, i32 0, i32 1) to i64)
+// CHECK-NEXT:ret i64 ptrtoint (ptr getelementptr nuw ([[STRUCT_S:%.*]], 
ptr null, i32 0, i32 1) to i64)
 //
 uintptr_t get_offset_of_y_naively() {
   return ((uintptr_t)(&(((S *)nullptr)->y)));

``




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


[clang] [clang-format] Add support for absl nullability macros (PR #130346)

2025-03-11 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

>From the Google's perspective, we are happy with any change that makes those 
>macros available in `-style=google`.
It seems that either of the options gives us that, so up to the rest of the 
folks in the thread.


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


[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-03-11 Thread Jack Styles via cfe-commits

https://github.com/Stylie777 updated 
https://github.com/llvm/llvm-project/pull/130623

>From d6772d64ff6fd515621c073b6545c40e918893b5 Mon Sep 17 00:00:00 2001
From: Jack Styles 
Date: Fri, 7 Mar 2025 15:51:34 +
Subject: [PATCH 1/3] [NFC][ARM] Split SIMD identifier away from MVE

Previously, the use of MVE or MVE.FP would be defined
by using the `ARM::AEK_SIMD` identifier. SIMD relates to
the Cortex-A and Cortex-R extension that enables NEON
instructions, which is called MVE for Cortex-M. To enable the
linking of `+simd` and `+nosimd` to `+neon` and `-neon`
when using clang, MVE and MVE.FP can now be defined
using a unique enum identifier, rather than using the existing
identifier for SIMD.

This was originally planned to be merged as part of #130296 but
the changes made `+nosimd` an invalid argument, which, while not
having any functionality, was allowed in previous versions of
LLVM. To avoid regressions being introduced, this has been
combined with the fix for `+nosimd` on AArch32.
---
 llvm/include/llvm/TargetParser/ARMTargetParser.def | 10 +-
 llvm/include/llvm/TargetParser/ARMTargetParser.h   |  1 +
 llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp |  2 +-
 llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp |  2 +-
 llvm/unittests/TargetParser/TargetParserTest.cpp   |  6 +++---
 5 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.def 
b/llvm/include/llvm/TargetParser/ARMTargetParser.def
index 6b96c3e83c8c4..e515ab665d117 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.def
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.def
@@ -224,8 +224,8 @@ ARM_ARCH_EXT_NAME("dotprod", ARM::AEK_DOTPROD, "+dotprod", 
"-dotprod")
 ARM_ARCH_EXT_NAME("dsp", ARM::AEK_DSP, "+dsp", "-dsp")
 ARM_ARCH_EXT_NAME("fp", ARM::AEK_FP, {}, {})
 ARM_ARCH_EXT_NAME("fp.dp", ARM::AEK_FP_DP, {}, {})
-ARM_ARCH_EXT_NAME("mve", (ARM::AEK_DSP | ARM::AEK_SIMD), "+mve", "-mve")
-ARM_ARCH_EXT_NAME("mve.fp", (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP),
+ARM_ARCH_EXT_NAME("mve", (ARM::AEK_DSP | ARM::AEK_MVE), "+mve", "-mve")
+ARM_ARCH_EXT_NAME("mve.fp", (ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP),
   "+mve.fp", "-mve.fp")
 ARM_ARCH_EXT_NAME("idiv", (ARM::AEK_HWDIVARM | ARM::AEK_HWDIVTHUMB), {}, {})
 ARM_ARCH_EXT_NAME("mp", ARM::AEK_MP, {}, {})
@@ -345,12 +345,12 @@ ARM_CPU_NAME("cortex-m33", ARMV8MMainline, 
FK_FPV5_SP_D16, false, ARM::AEK_DSP)
 ARM_CPU_NAME("star-mc1", ARMV8MMainline, FK_FPV5_SP_D16, false, ARM::AEK_DSP)
 ARM_CPU_NAME("cortex-m35p", ARMV8MMainline, FK_FPV5_SP_D16, false, 
ARM::AEK_DSP)
 ARM_CPU_NAME("cortex-m55", ARMV8_1MMainline, FK_FP_ARMV8_FULLFP16_D16, false,
- (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP | ARM::AEK_FP16))
+ (ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP | ARM::AEK_FP16))
 ARM_CPU_NAME("cortex-m85", ARMV8_1MMainline, FK_FP_ARMV8_FULLFP16_D16, false,
- (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP | ARM::AEK_FP16 |
+ (ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP | ARM::AEK_FP16 |
   ARM::AEK_RAS | ARM::AEK_PACBTI))
 ARM_CPU_NAME("cortex-m52", ARMV8_1MMainline, FK_FP_ARMV8_FULLFP16_D16, false,
- (ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP | ARM::AEK_FP16 |
+ (ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP | ARM::AEK_FP16 |
   ARM::AEK_RAS | ARM::AEK_PACBTI))
 ARM_CPU_NAME("cortex-a32", ARMV8A, FK_CRYPTO_NEON_FP_ARMV8, false, 
ARM::AEK_CRC)
 ARM_CPU_NAME("cortex-a35", ARMV8A, FK_CRYPTO_NEON_FP_ARMV8, false, 
ARM::AEK_CRC)
diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.h 
b/llvm/include/llvm/TargetParser/ARMTargetParser.h
index 5dbcfd3d2d693..b2403f42f1b79 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.h
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.h
@@ -61,6 +61,7 @@ enum ArchExtKind : uint64_t {
   AEK_CDECP6 = 1 << 28,
   AEK_CDECP7 = 1 << 29,
   AEK_PACBTI = 1 << 30,
+  AEK_MVE = 1ULL << 31,
   // Unsupported extensions.
   AEK_OS = 1ULL << 59,
   AEK_IWMMXT = 1ULL << 60,
diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp 
b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index d6a586e1f247b..79b54e6b04330 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -12971,7 +12971,7 @@ bool ARMAsmParser::enableArchExtFeature(StringRef Name, 
SMLoc &ExtLoc) {
   {ARM::AEK_CRYPTO,
{Feature_HasV8Bit},
{ARM::FeatureCrypto, ARM::FeatureNEON, ARM::FeatureFPARMv8}},
-  {(ARM::AEK_DSP | ARM::AEK_SIMD | ARM::AEK_FP),
+  {(ARM::AEK_DSP | ARM::AEK_MVE | ARM::AEK_FP),
{Feature_HasV8_1MMainlineBit},
{ARM::HasMVEFloatOps}},
   {ARM::AEK_FP,
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp 
b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
index b0fa03a35ec04..632dbebf58f04 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
+++ b/

[clang-tools-extra] [clang-tidy][NFC] clean ReleaseNotes.rst (PR #130626)

2025-03-11 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor updated 
https://github.com/llvm/llvm-project/pull/130626

>From 9fa8915b822314b52ea4b21d5f701b8a4718b015 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Mon, 10 Mar 2025 18:54:53 +0300
Subject: [PATCH] [clang-tidy] NFS-clean release notes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 28 -
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fa68b6fabd549..5b938853b14f9 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -97,8 +97,8 @@ New checks
 - New :doc:`bugprone-unintended-char-ostream-output
   ` check.
 
-  Finds unintended character output from ``unsigned char`` and ``signed char`` 
to an
-  ``ostream``.
+  Finds unintended character output from ``unsigned char`` and ``signed char``
+  to an ``ostream``.
 
 - New :doc:`readability-ambiguous-smartptr-reset-call
   ` check.
@@ -137,28 +137,28 @@ Changes in existing checks
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
   examples and fixing some macro related false positives.
+
+- Improved :doc:`misc-unused-using-decls
+  ` check by fixing false positives
+  on ``operator""`` with template parameters.
+
+- Improved :doc:`misc-use-internal-linkage
+  ` check by fix false positives
+  for function or variable in header file which contains macro expansion.
   
 - Improved :doc:`modernize-use-ranges
   ` check by updating suppress 
   warnings logic for ``nullptr`` in ``std::find``.
 
-- Improved :doc:`misc-use-internal-linkage
-  ` check by fix false positives
-  for function or variable in header file which contains macro expansion.
+- Improved :doc:`performance-move-const-arg
+  ` check by fixing false
+  negatives on ternary operators calling ``std::move``.
 
-- Improved :doc:`performance/unnecessary-value-param
+- Improved :doc:`performance-unnecessary-value-param
   ` check performance by
   tolerating fix-it breaking compilation when functions is used as pointers
   to avoid matching usage of functions within the current compilation unit.
 
-- Improved :doc:`performance-move-const-arg
-  ` check by fixing false 
negatives
-  on ternary operators calling ``std::move``.
-
-- Improved :doc:`misc-unused-using-decls
-  ` check by fixing false positives
-  on ``operator""`` with template parameters.
-
 Removed checks
 ^^
 

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


[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-03-11 Thread Jack Styles via cfe-commits


@@ -85,6 +85,9 @@ Changes to the AMDGPU Backend
 
 Changes to the ARM Backend
 --
+* The `+nosimd` attribute is now fully supported. Previously, this had no 
effect when being used with
+AArch32 targets, however will now disable NEON instructions being generated. 
The `simd` is also now
+printed when the `--print-supported-extensions` option is used..

Stylie777 wrote:

Done

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


[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-03-11 Thread Jack Styles via cfe-commits


@@ -85,6 +85,9 @@ Changes to the AMDGPU Backend
 
 Changes to the ARM Backend
 --
+* The `+nosimd` attribute is now fully supported. Previously, this had no 
effect when being used with
+AArch32 targets, however will now disable NEON instructions being generated. 
The `simd` is also now

Stylie777 wrote:

Done

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


[clang] [AstMatcher][NFC]fix doc gen for ast matchers (PR #130726)

2025-03-11 Thread Congcong Cai via cfe-commits

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


[clang] [llvm] [RISCV] Add Qualcomn uC Xqcili (load large immediates) extension (PR #130012)

2025-03-11 Thread via cfe-commits

https://github.com/u4f3 updated https://github.com/llvm/llvm-project/pull/130012

>From b8d8e7d3f442d28f9771317c337fb650dd50aaa9 Mon Sep 17 00:00:00 2001
From: u4f3 
Date: Fri, 7 Mar 2025 15:01:57 +0800
Subject: [PATCH] [RISCV] Add Qualcomn uC Xqcili (load large immediates)
 extension

The Xqcili extension includes a two instructions that load large immediates 
than is available with the base RISC-V ISA.

The current spec can be found at: 
https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7.0

This patch adds assembler only support.
---
 .../Driver/print-supported-extensions-riscv.c |  1 +
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/docs/ReleaseNotes.md |  2 +
 .../Target/RISCV/AsmParser/RISCVAsmParser.cpp | 13 ++
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  5 +-
 .../Target/RISCV/MCTargetDesc/RISCVBaseInfo.h |  1 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|  8 
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td   | 15 ++
 llvm/lib/TargetParser/RISCVISAInfo.cpp|  6 +--
 llvm/test/CodeGen/RISCV/attributes.ll |  2 +
 llvm/test/MC/RISCV/xqcili-invalid.s   | 27 +++
 llvm/test/MC/RISCV/xqcili-valid.s | 46 +++
 .../TargetParser/RISCVISAInfoTest.cpp |  4 +-
 13 files changed, 127 insertions(+), 6 deletions(-)
 create mode 100644 llvm/test/MC/RISCV/xqcili-invalid.s
 create mode 100644 llvm/test/MC/RISCV/xqcili-valid.s

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 69b76f0c4c4cd..21f79c7565295 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -202,6 +202,7 @@
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
 // CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
 // CHECK-NEXT: xqciint  0.2   'Xqciint' (Qualcomm uC 
Interrupts Extension)
+// CHECK-NEXT: xqcili   0.2   'Xqcili' (Qualcomm uC Load 
Large Immediate Extension)
 // CHECK-NEXT: xqcilia  0.2   'Xqcilia' (Qualcomm uC Large 
Immediate Arithmetic Extension)
 // CHECK-NEXT: xqcilo   0.2   'Xqcilo' (Qualcomm uC Large 
Offset Load Store Extension)
 // CHECK-NEXT: xqcilsm  0.2   'Xqcilsm' (Qualcomm uC Load 
Store Multiple Extension)
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 62c6a4fd80fd4..38c49d10d7999 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -456,6 +456,9 @@ The current vendor extensions supported are:
 ``experimental-Xqciint``
   LLVM implements `version 0.2 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 
+``experimental-Xqcili``
+  LLVM implements `version 0.2 of the Qualcomm uC Load Large Immediate 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
+
 ``experimental-Xqcilia``
   LLVM implements `version 0.2 of the Qualcomm uC Large Immediate Arithmetic 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index fe3b508d5c5b0..733f6947da823 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -107,6 +107,8 @@ Changes to the PowerPC Backend
 Changes to the RISC-V Backend
 -
 
+* Adds experimental assembler support for the Qualcomm uC 'Xqcili` (Load Large 
Immediate)
+  extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcilia` (Large 
Immediate Arithmetic)
   extension.
 * Adds experimental assembler support for the Qualcomm uC 'Xqcibm` (Bit 
Manipulation)
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index b342c18bece08..372e2e2ad8ba1 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1076,6 +1076,16 @@ struct RISCVOperand final : public MCParsedAsmOperand {
VK == RISCVMCExpr::VK_RISCV_None;
   }
 
+  bool isSImm20() const {
+if (!isImm())
+  return false;
+RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
+int64_t Imm;
+bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
+return IsConstantImm && (VK == RISCVMCExpr::VK_RISCV_None) &&
+ 

[clang-tools-extra] [clang-tidy][NFC]clean ConstCorrectnessCheck (PR #130493)

2025-03-11 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

### Merge activity

* **Mar 11, 2:51 AM EDT**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/130493).


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


[clang] [OpenMP 6.0] Parse/Sema support for reduction over private variable with reduction clause. (PR #129938)

2025-03-11 Thread Alexey Bataev via cfe-commits


@@ -17391,7 +17392,8 @@ OMPClause 
*SemaOpenMP::ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
 Res = ActOnOpenMPReductionClause(
 VarList, static_cast(ExtraModifier),
 StartLoc, LParenLoc, ExtraModifierLoc, ColonLoc, EndLoc,
-Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId);
+Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId, {},
+static_cast(OriginalSharingModifier));

alexey-bataev wrote:

Better to pack these members into struct already, there are too many parameters 
in the functions

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


[clang] [OpenMP 6.0] Parse/Sema support for reduction over private variable with reduction clause. (PR #129938)

2025-03-11 Thread Alexey Bataev via cfe-commits


@@ -4668,6 +4668,34 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind 
DKind,
   assert(Tok.is(tok::comma) && "Expected comma.");
   (void)ConsumeToken();
 }
+// Handle original(private / shared) Modifier
+if (Kind == OMPC_reduction && getLangOpts().OpenMP >= 60 &&
+Tok.is(tok::identifier) && PP.getSpelling(Tok) == "original" &&
+NextToken().is(tok::l_paren)) {
+  // Parse original(private) modifier.
+  ConsumeToken();
+  BalancedDelimiterTracker ParenT(*this, tok::l_paren, tok::r_paren);
+  ParenT.consumeOpen();
+  if (Tok.is(tok::kw_private)) {
+Data.OriginalSharingModifier = OMPC_ORIGINAL_SHARING_private;
+Data.OriginalSharingModifierLoc = Tok.getLocation();
+ConsumeToken();
+  } else if (Tok.is(tok::identifier) &&
+ (PP.getSpelling(Tok) == "shared" ||
+  PP.getSpelling(Tok) == "default")) {
+Data.OriginalSharingModifier = OMPC_ORIGINAL_SHARING_shared;
+Data.OriginalSharingModifierLoc = Tok.getLocation();
+ConsumeToken();
+  } else {
+Diag(Tok.getLocation(), diag::err_expected)
+<< "'private or shared or default'";
+SkipUntil(tok::r_paren);
+return false;
+  }
+  ParenT.consumeClose();
+  assert(Tok.is(tok::comma) && "Expected comma.");

alexey-bataev wrote:

This should be an error, not an assertion, otherwise compiler will crash if the 
token is not a comma

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


[clang] [llvm] [analysis] Software Bill of Mitigations (PR #130103)

2025-03-11 Thread Matthew Levy via cfe-commits

https://github.com/matthewlevy97 updated 
https://github.com/llvm/llvm-project/pull/130103

>From fb04b7bf5f2b668bf354632fc53e7521f44880c9 Mon Sep 17 00:00:00 2001
From: Matt Levy 
Date: Wed, 5 Mar 2025 12:36:02 -0500
Subject: [PATCH 1/4] [clang][CodeGen] Software Bill of Mitigations Metadata

The goal of this stack is to create a high fidelity mapping of mitigations to 
their possible insertion points and their actual insertion points. This would 
let us track where we do and don't have mitigations rather than the current 
approach of tracking where we have the flag.

There are some challenges posed by this like:
- Some mitigations are not emitted by the compiler, but the preprocessor
- Some mitigations are lowered later during IR -> MIR (stack cookies)
---
 clang/include/clang/Basic/CodeGenOptions.def |  1 +
 clang/include/clang/Driver/Options.td|  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp  | 10 +++
 clang/lib/CodeGen/CGClass.cpp|  3 +
 clang/lib/CodeGen/CGDecl.cpp |  4 +
 clang/lib/CodeGen/CGExpr.cpp |  5 ++
 clang/lib/CodeGen/CGExprCXX.cpp  |  6 ++
 clang/lib/CodeGen/CMakeLists.txt |  1 +
 clang/lib/CodeGen/CodeGenModule.cpp  | 22 +
 clang/lib/CodeGen/MitigationTagging.cpp  | 84 
 clang/lib/CodeGen/MitigationTagging.h| 45 +++
 clang/lib/Driver/ToolChains/Clang.cpp|  3 +
 12 files changed, 190 insertions(+)
 create mode 100644 clang/lib/CodeGen/MitigationTagging.cpp
 create mode 100644 clang/lib/CodeGen/MitigationTagging.h

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index a7f5f1abbb825..76a46ac3e592b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -191,6 +191,7 @@ CODEGENOPT(NoTypeCheck   , 1, 0) ///< Set when 
-Wa,--no-type-check is enable
 CODEGENOPT(MisExpect , 1, 0) ///< Set when -Wmisexpect is enabled
 CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is 
enabled.
 CODEGENOPT(StackClashProtector, 1, 0) ///< Set when -fstack-clash-protection 
is enabled.
+CODEGENOPT(MitigationAnalysis, 1, 0) ///< Set when -fmitigation-analysis is 
enabled.
 CODEGENOPT(NoImplicitFloat   , 1, 0) ///< Set when -mno-implicit-float is 
enabled.
 CODEGENOPT(NullPointerIsValid , 1, 0) ///< Assume Null pointer deference is 
defined.
 CODEGENOPT(OpenCLCorrectlyRoundedDivSqrt, 1, 0) ///< 
-cl-fp32-correctly-rounded-divide-sqrt
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d0414aba35209..e50bb5c1c2cb4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3891,6 +3891,12 @@ defm split_stack : BoolFOption<"split-stack",
   CodeGenOpts<"EnableSegmentedStacks">, DefaultFalse,
   NegFlag,
   PosFlag>;
+defm mitigation_analysis : BoolFOption<"mitigation-analysis",
+  CodeGenOpts<"MitigationAnalysis">, DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption], " mitigation analysis">>,
+  DocBrief<"Instrument mitigations (CFI, Stack Protectors, Auto-Var-Init, 
StackClashProtection) to analyze their coverage">;
 def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group,
   HelpText<"Enable stack protectors for all functions">;
 defm stack_clash_protection : BoolFOption<"stack-clash-protection",
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ab8f19b25fa66..4e180bb1a87cf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -21,6 +21,7 @@
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "ConstantEmitter.h"
+#include "MitigationTagging.h"
 #include "PatternInit.h"
 #include "TargetInfo.h"
 #include "clang/AST/ASTContext.h"
@@ -83,6 +84,8 @@ static void initializeAlloca(CodeGenFunction &CGF, AllocaInst 
*AI, Value *Size,
   switch (CGF.getLangOpts().getTrivialAutoVarInit()) {
   case LangOptions::TrivialAutoVarInitKind::Uninitialized:
 // Nothing to initialize.
+AttachMitigationMetadataToFunction(CGF, MitigationKey::AUTO_VAR_INIT,
+   false);
 return;
   case LangOptions::TrivialAutoVarInitKind::Zero:
 Byte = CGF.Builder.getInt8(0x00);
@@ -94,6 +97,7 @@ static void initializeAlloca(CodeGenFunction &CGF, AllocaInst 
*AI, Value *Size,
 break;
   }
   }
+  AttachMitigationMetadataToFunction(CGF, MitigationKey::AUTO_VAR_INIT, true);
   if (CGF.CGM.stopAutoInit())
 return;
   auto *I = CGF.Builder.CreateMemSet(AI, Byte, Size, AlignmentInBytes);
@@ -4642,6 +4646,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 AI->setAlignment(SuitableAlignmentInBytes);
 if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
   initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
+else
+  AttachMitigationMetadataToFunction(*t

[clang] [Driver] Teach Barmetal toolchain about GCC installation(1/3) (PR #121829)

2025-03-11 Thread Garvit Gupta via cfe-commits

quic-garvgupt wrote:

Hi @petrhosek, I've addressed all your comments. Please review the changes and 
approve the PR if everything looks good.

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


[clang] [Clang] Fix the printout of CXXParenListInitExpr involving default arguments (PR #130731)

2025-03-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/130731

>From c643ba2de0bb3e5fcb6514b70c86e594badc396b Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 11 Mar 2025 14:18:20 +0800
Subject: [PATCH 1/3] [Clang] Fix the printout of CXXParenListInitExpr
 involving default arguments

The parantheses are unnecessary IMO because they should have been
handled in the parents of such expressions, e.g. in
CXXFunctionalCastExpr.

Moreover, we shouldn't join CXXDefaultInitExpr either because they
are not printed at all.
---
 clang/lib/AST/StmtPrinter.cpp  |  4 +---
 clang/test/CodeGen/p0963r3.cpp |  3 ---
 clang/test/SemaCXX/paren-list-agg-init.cpp | 18 ++
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index facdc4104c374..e0063ec5f25eb 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -2659,10 +2659,8 @@ void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) {
 }
 
 void StmtPrinter::VisitCXXParenListInitExpr(CXXParenListInitExpr *Node) {
-  OS << "(";
-  llvm::interleaveComma(Node->getInitExprs(), OS,
+  llvm::interleaveComma(Node->getUserSpecifiedInitExprs(), OS,
 [&](Expr *E) { PrintExpr(E); });
-  OS << ")";
 }
 
 void StmtPrinter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) 
{
diff --git a/clang/test/CodeGen/p0963r3.cpp b/clang/test/CodeGen/p0963r3.cpp
index b48b5294e093e..4a5e6c3f5d751 100644
--- a/clang/test/CodeGen/p0963r3.cpp
+++ b/clang/test/CodeGen/p0963r3.cpp
@@ -139,9 +139,6 @@ constexpr int bar(auto) {
   }();
   static_assert(value == S(1, 2));
 
-  // FIXME: The diagnostic message adds a trailing comma "static assertion 
failed due to requirement 'value == Case1::S((0, 1, ))'"
-  // static_assert(value == S(0, 1));
-
   constexpr auto value2 = [] {
 if (auto [a, b] = S(1, 2))
   return S(a, b);
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index 61afba85e1dff..c55604003bc33 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -357,3 +357,21 @@ ThroughAlias e(42);
 // beforecxx20-warning@-1 {{aggregate initialization of type 
'ThroughAlias' (aka 'int[1]') from a parenthesized list of values is a 
C++20 extension}} 
 
 }
+
+namespace CXXParenListInitExpr {
+
+struct S {
+  int a, b;
+  bool flag = false;
+
+  constexpr bool operator==(S rhs) {
+return a == rhs.a && b == rhs.b;
+  }
+};
+
+static_assert(S(1, 2) == S(1, 2));
+
+static_assert(S(1, 2) == S(3, 4));
+// expected-error@-1 {{failed due to requirement 'S(1, 2) == S(3, 4)'}}
+
+}

>From 2c6f6a193e895129151fd627ca2b490f6643126f Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 11 Mar 2025 17:43:30 +0800
Subject: [PATCH 2/3] Fix CI

---
 clang/test/SemaCXX/paren-list-agg-init.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index c55604003bc33..e5c0757d0970c 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -372,6 +372,6 @@ struct S {
 static_assert(S(1, 2) == S(1, 2));
 
 static_assert(S(1, 2) == S(3, 4));
-// expected-error@-1 {{failed due to requirement 'S(1, 2) == S(3, 4)'}}
+// expected-error@-1 {{failed due to requirement 'CXXParenListInitExpr::S(1, 
2) == CXXParenListInitExpr::S(3, 4)'}}
 
 }

>From ca9c153de00eba8efb2805a5b7c7bce7c9ba5ee2 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 11 Mar 2025 19:53:20 +0800
Subject: [PATCH 3/3] Fix it again

---
 clang/test/SemaCXX/paren-list-agg-init.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index e5c0757d0970c..b2d0f2564bb59 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -369,9 +369,10 @@ struct S {
   }
 };
 
-static_assert(S(1, 2) == S(1, 2));
+static_assert(S(1, 2) == S(1, 2)); // beforecxx20-warning 2{{C++20 extension}}
 
 static_assert(S(1, 2) == S(3, 4));
-// expected-error@-1 {{failed due to requirement 'CXXParenListInitExpr::S(1, 
2) == CXXParenListInitExpr::S(3, 4)'}}
+// expected-error@-1 {{failed due to requirement 'CXXParenListInitExpr::S(1, 
2) == CXXParenListInitExpr::S(3, 4)'}} \
+// beforecxx20-warning@-1 2{{C++20 extension}}
 
 }

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


[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-03-11 Thread Jonathan Thackray via cfe-commits

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

Thanks for the fixes. LGTM now.

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


[clang] [profile] runtime counter relocation is needed on windows-msvc targets (PR #127858)

2025-03-11 Thread Wael Yehia via cfe-commits

w2yehia wrote:

> Can you summarize the high level use case which didn't work before, and in 
> which way it used to fail before, which gets fixed by this change?

Continuous profiling (that is continuous profile syncing to disk) is an 
existing feature, which is OFF by default on most platforms. 
The feature 
[mmap's](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/profile/InstrProfilingFile.c#L273)
 the profile file rather than writing it at program exit (the default 
non-continuous mode behavior). There are two implementations in 
`InstrProfilingFile.c`, 
[one](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/profile/InstrProfilingFile.c#L160)
 that mmap's onto existing memory, and 
[another](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/profile/InstrProfilingFile.c#L273)
 that mmap's without an address hint. The latter relies on a corresponding 
compiler action (added in 
[this](https://github.com/llvm/llvm-project/commit/d3db13af7e5c01632fbf28149a2d4f9c4841aeba)
 commit), which is enabled using `-mllvm -runtime-counter-relocation`. 

What I added, in a previous PR (#124353), was a clang option 
(-fprofile-continuous) to enable the feature and take care of the nuances of 
setting up the compiler and runtime: (1) override the profile file name by 
appending '%c' into it, and (2) pass `-runtime-counter-relocation` to the 
backend on certain platforms.
This PR added `T.isKnownWindowsMSVCEnvironment()` to the conditions under which 
the drivers passes `-runtime-counter-relocation` to the backend, and the 
question is whether this is sufficient for windows or more changes to the 
conditions are needed. 
Note if we miss a condition/configuration then it doesn't break the feature 
there, it just would 
[fail](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/profile/InstrProfilingFile.c#L662)
 at runtime if you try enabling using this new clang option 
(-fprofile-continuous).

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -36,6 +36,18 @@ class ScalarExprEmitter : public 
StmtVisitor {
 bool ira = false)
   : cgf(cgf), builder(builder), ignoreResultAssign(ira) {}
 
+  
//======//
+  //   Utilities
+  
//======//
+
+  bool TestAndClearIgnoreResultAssign() {

erichkeane wrote:

Oh boy this name is a bit of a word-soup :D  This is actually more of an 
`exchange` in c++ parlance.

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::bool_to_int;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::bool_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::integral;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::int_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+/

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))

erichkeane wrote:

```suggestion
if (llvm::isa(srcType))
```

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::bool_to_int;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::bool_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::integral;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::int_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+/

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::bool_to_int;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::bool_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::integral;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::int_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+/

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -130,17 +389,136 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr 
*ce) {
   QualType destTy = ce->getType();
   CastKind kind = ce->getCastKind();
 
+  // These cases are generally not written to ignore the result of evaluating
+  // their sub-expressions, so we clear this now.
+  [[maybe_unused]] bool ignored = TestAndClearIgnoreResultAssign();
+
   switch (kind) {
+  case clang::CK_Dependent:
+llvm_unreachable("dependent cast kind in CIR gen!");
+  case clang::CK_BuiltinFnToFnPtr:
+llvm_unreachable("builtin functions are handled elsewhere");
+
+  case CK_CPointerToObjCPointerCast:
+  case CK_BlockPointerToObjCPointerCast:
+  case CK_AnyPointerToBlockPointerCast:
+  case CK_BitCast: {
+auto src = Visit(const_cast(e));

erichkeane wrote:

another place we can't use auto.

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::bool_to_int;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::bool_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::integral;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::int_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+/

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -130,17 +389,136 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr 
*ce) {
   QualType destTy = ce->getType();
   CastKind kind = ce->getCastKind();
 
+  // These cases are generally not written to ignore the result of evaluating
+  // their sub-expressions, so we clear this now.
+  [[maybe_unused]] bool ignored = TestAndClearIgnoreResultAssign();
+
   switch (kind) {
+  case clang::CK_Dependent:
+llvm_unreachable("dependent cast kind in CIR gen!");
+  case clang::CK_BuiltinFnToFnPtr:
+llvm_unreachable("builtin functions are handled elsewhere");
+
+  case CK_CPointerToObjCPointerCast:
+  case CK_BlockPointerToObjCPointerCast:
+  case CK_AnyPointerToBlockPointerCast:
+  case CK_BitCast: {
+auto src = Visit(const_cast(e));
+mlir::Type dstTy = convertType(destTy);
+
+assert(!cir::MissingFeatures::addressSpace());
+
+if (cgf.sanOpts.has(SanitizerKind::CFIUnrelatedCast))
+  cgf.getCIRGenModule().errorNYI(e->getSourceRange(), "sanitizer support");
+
+if (cgf.cgm.getCodeGenOpts().StrictVTablePointers)
+  cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
+ "strict vtable pointers");
+
+// Update heapallocsite metadata when there is an explicit pointer cast.
+assert(!cir::MissingFeatures::addHeapAllocSiteMetadata());
+
+// If Src is a fixed vector and Dst is a scalable vector, and both have the
+// same element type, use the llvm.vector.insert intrinsic to perform the
+// bitcast.
+assert(!cir::MissingFeatures::scalableVectors());
+
+// If Src is a scalable vector and Dst is a fixed vector, and both have the
+// same element type, use the llvm.vector.extract intrinsic to perform the
+// bitcast.
+assert(!cir::MissingFeatures::scalableVectors());
+
+// Perform VLAT <-> VLST bitcast through memory.
+// TODO: since the llvm.experimental.vector.{insert,extract} intrinsics
+//   require the element types of the vectors to be the same, we
+//   need to keep this around for bitcasts between VLAT <-> VLST where
+//   the element types of the vectors are not the same, until we figure
+//   out a better way of doing these casts.
+assert(!cir::MissingFeatures::scalableVectors());
+
+return cgf.getBuilder().createBitcast(cgf.getLoc(e->getSourceRange()), src,
+  dstTy);
+  }
+
+  case CK_AtomicToNonAtomic:
+cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
+   "CastExpr: ", ce->getCastKindName());
+break;
+  case CK_NonAtomicToAtomic:
+  case CK_UserDefinedConversion:
+return Visit(const_cast(e));
+  case CK_NoOp: {
+auto v = Visit(const_cast(e));
+if (v) {
+  // CK_NoOp can model a pointer qualification conversion, which can remove
+  // an array bound and change the IR type.
+  // FIXME: Once pointee types are removed from IR, remove this.
+  auto t = convertType(destTy);

erichkeane wrote:

not a place we can use `auto`.

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::bool_to_int;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::bool_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::integral;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::int_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+/

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::bool_to_int;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::bool_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::integral;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::int_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+/

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -84,26 +96,266 @@ class ScalarExprEmitter : public 
StmtVisitor {
   }
 
   mlir::Value VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *e) {
-mlir::Type type = cgf.convertType(e->getType());
+mlir::Type type = convertType(e->getType());
 return builder.create(
 cgf.getLoc(e->getExprLoc()), type,
 builder.getCIRBoolAttr(e->getValue()));
   }
 
-  mlir::Value VisitCastExpr(CastExpr *E);
+  mlir::Value VisitCastExpr(CastExpr *e);
+
+  mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
+return VisitCastExpr(e);
+  }
+
+  /// Perform a pointer to boolean conversion.
+  mlir::Value emitPointerToBoolConversion(mlir::Value v, QualType qt) {
+// TODO(cir): comparing the ptr to null is done when lowering CIR to LLVM.
+// We might want to have a separate pass for these types of conversions.
+return cgf.getBuilder().createPtrToBoolCast(v);
+  }
+
+  mlir::Value emitFloatToBoolConversion(mlir::Value src, mlir::Location loc) {
+auto boolTy = builder.getBoolTy();
+return builder.create(loc, boolTy,
+   cir::CastKind::float_to_bool, src);
+  }
+
+  mlir::Value emitIntToBoolConversion(mlir::Value srcVal, mlir::Location loc) {
+// Because of the type rules of C, we often end up computing a
+// logical value, then zero extending it to int, then wanting it
+// as a logical value again.
+// TODO: optimize this common case here or leave it for later
+// CIR passes?
+mlir::Type boolTy = convertType(cgf.getContext().BoolTy);
+return builder.create(loc, boolTy, cir::CastKind::int_to_bool,
+   srcVal);
+  }
+
+  /// Convert the specified expression value to a boolean (!cir.bool) truth
+  /// value. This is equivalent to "Val != 0".
+  mlir::Value emitConversionToBool(mlir::Value src, QualType srcType,
+   mlir::Location loc) {
+assert(srcType.isCanonical() && "EmitScalarConversion strips typedefs");
+
+if (srcType->isRealFloatingType())
+  return emitFloatToBoolConversion(src, loc);
+
+if ([[maybe_unused]] auto *mpt = 
llvm::dyn_cast(srcType))
+  cgf.getCIRGenModule().errorNYI(loc, "member pointer to bool conversion");
+
+if (srcType->isIntegerType())
+  return emitIntToBoolConversion(src, loc);
+
+assert(::mlir::isa(src.getType()));
+return emitPointerToBoolConversion(src, srcType);
+  }
+
+  // Emit a conversion from the specified type to the specified destination
+  // type, both of which are CIR scalar types.
+  struct ScalarConversionOpts {
+bool treatBooleanAsSigned;
+bool emitImplicitIntegerTruncationChecks;
+bool emitImplicitIntegerSignChangeChecks;
+
+ScalarConversionOpts()
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(false),
+  emitImplicitIntegerSignChangeChecks(false) {}
+
+ScalarConversionOpts(clang::SanitizerSet sanOpts)
+: treatBooleanAsSigned(false),
+  emitImplicitIntegerTruncationChecks(
+  sanOpts.hasOneOf(SanitizerKind::ImplicitIntegerTruncation)),
+  emitImplicitIntegerSignChangeChecks(
+  sanOpts.has(SanitizerKind::ImplicitIntegerSignChange)) {}
+  };
+
+  // Conversion from bool, integral, or floating-point to integral or
+  // floating-point. Conversions involving other types are handled elsewhere.
+  // Conversion to bool is handled elsewhere because that's a comparison 
against
+  // zero, not a simple cast. This handles both individual scalars and vectors.
+  mlir::Value emitScalarCast(mlir::Value src, QualType srcType,
+ QualType dstType, mlir::Type srcTy,
+ mlir::Type dstTy, ScalarConversionOpts opts) {
+assert(!srcType->isMatrixType() && !dstType->isMatrixType() &&
+   "Internal error: matrix types not handled by this function.");
+if (mlir::isa(srcTy) ||
+mlir::isa(dstTy))
+  llvm_unreachable("Obsolete code. Don't use mlir::IntegerType with CIR.");
+
+mlir::Type fullDstTy = dstTy;
+assert(!cir::MissingFeatures::vectorType());
+
+std::optional castKind;
+
+if (mlir::isa(srcTy)) {
+  if (opts.treatBooleanAsSigned)
+cgf.getCIRGenModule().errorNYI("signed bool");
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::bool_to_int;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::bool_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (cgf.getBuilder().isInt(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+castKind = cir::CastKind::integral;
+  } else if (mlir::isa(dstTy)) {
+castKind = cir::CastKind::int_to_float;
+  } else {
+llvm_unreachable("Internal error: Cast to unexpected type");
+  }
+} else if (mlir::isa(srcTy)) {
+  if (cgf.getBuilder().isInt(dstTy)) {
+/

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

We have to be mroe careful I think with uses of the `errorNYI` in a few places, 
we are using it too much like `assert` when it is more like `emitDiag`. 

Also, this patch uses `auto` a bunch in ways that are contrary to the coding 
standard.  See : 
https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable

`auto` is really only to be used (rule of thumb) when the type is already 
'listed' on the RHS, or naming the type is so obnoxious as to be irrelevant 
(iterators/etc).

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits

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


[clang] [NFC][analyzer] Remove CheckerNameRef::getName() (PR #130780)

2025-03-11 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

I have no strong feelings about the implicit/explicit question. I am also not 
sure we need this lightweight wrapper type. 

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-11 Thread Erich Keane via cfe-commits


@@ -78,6 +79,67 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return create(loc, val, dst);
   }
 
+  
//======//
+  // Cast/Conversion Operators
+  
//======//
+
+  mlir::Value createCast(mlir::Location loc, cir::CastKind kind,
+ mlir::Value src, mlir::Type newTy) {
+if (newTy == src.getType())
+  return src;
+return create(loc, newTy, kind, src);
+  }
+
+  mlir::Value createCast(cir::CastKind kind, mlir::Value src,
+ mlir::Type newTy) {
+if (newTy == src.getType())
+  return src;
+return createCast(src.getLoc(), kind, src, newTy);
+  }
+
+  mlir::Value createIntCast(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::integral, src, newTy);
+  }
+
+  mlir::Value createIntToPtr(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::int_to_ptr, src, newTy);
+  }
+
+  mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::ptr_to_int, src, newTy);
+  }
+
+  mlir::Value createPtrToBoolCast(mlir::Value v) {
+return createCast(cir::CastKind::ptr_to_bool, v, getBoolTy());
+  }
+
+  mlir::Value createBoolToInt(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::bool_to_int, src, newTy);
+  }
+
+  mlir::Value createBitcast(mlir::Value src, mlir::Type newTy) {
+return createCast(cir::CastKind::bitcast, src, newTy);
+  }
+
+  mlir::Value createBitcast(mlir::Location loc, mlir::Value src,
+mlir::Type newTy) {
+return createCast(loc, cir::CastKind::bitcast, src, newTy);
+  }
+
+  mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy) {

erichkeane wrote:

I'm not terribly sure what is going on here, can you share what the point of 
this function is?  It seems like an odd operation to model specifically (that 
is, bitcast(&Thing)).

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


[clang] [Clang] add additional tests for -Wshift-bool (PR #130339)

2025-03-11 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/130339

>From bed2cb009ae2e560aa00f86b90c57d82f97bb435 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 7 Mar 2025 22:10:24 +0200
Subject: [PATCH 1/2] [Clang] add additional tests for -Wshift-bool

---
 clang/test/Sema/shift-bool.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/test/Sema/shift-bool.cpp b/clang/test/Sema/shift-bool.cpp
index a17a0e0ad9e7d..efaca65aacaed 100644
--- a/clang/test/Sema/shift-bool.cpp
+++ b/clang/test/Sema/shift-bool.cpp
@@ -3,6 +3,7 @@
 void t() {
   int x = 10;
   bool y = true;
+  int z = 1;
 
   bool a = y << x;
   bool b = y >> x; // expected-warning {{right shifting a 'bool' implicitly 
converts it to 'int'}}
@@ -22,4 +23,6 @@ void t() {
 
   if ((y << 1) != 0) { }
   if ((y >> 1) != 0) { } // expected-warning {{right shifting a 'bool' 
implicitly converts it to 'int'}}
+
+  bool k = (x < z) >> 1; // expected-warning {{right shifting a 'bool' 
implicitly converts it to 'int'}}
 }

>From 9be7657ef45482a84c571b6b3f15be833841467a Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 11 Mar 2025 17:15:52 +0200
Subject: [PATCH 2/2] add c test

---
 clang/test/Sema/shift-bool.c   | 24 
 clang/test/Sema/shift-bool.cpp |  3 ---
 2 files changed, 24 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Sema/shift-bool.c

diff --git a/clang/test/Sema/shift-bool.c b/clang/test/Sema/shift-bool.c
new file mode 100644
index 0..589ba49fa2bba
--- /dev/null
+++ b/clang/test/Sema/shift-bool.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -Wshift-bool -verify %s
+
+void t() {
+  int x = 10;
+  int y = 1;
+
+  int a = y << x;
+  int b = y >> x;
+
+  int c = 0 << x;
+  int d = 0 >> x;
+
+  int e = y << 1;
+  int f = y >> 1;
+
+  int g = y << -1; // expected-warning {{shift count is negative}}
+  int h = y >> -1; // expected-warning {{shift count is negative}}
+
+  int i = y << 0;
+  int j = y >> 0;
+
+  if ((y << 1) != 0) { }
+  if ((y >> 1) != 0) { }
+}
diff --git a/clang/test/Sema/shift-bool.cpp b/clang/test/Sema/shift-bool.cpp
index efaca65aacaed..a17a0e0ad9e7d 100644
--- a/clang/test/Sema/shift-bool.cpp
+++ b/clang/test/Sema/shift-bool.cpp
@@ -3,7 +3,6 @@
 void t() {
   int x = 10;
   bool y = true;
-  int z = 1;
 
   bool a = y << x;
   bool b = y >> x; // expected-warning {{right shifting a 'bool' implicitly 
converts it to 'int'}}
@@ -23,6 +22,4 @@ void t() {
 
   if ((y << 1) != 0) { }
   if ((y >> 1) != 0) { } // expected-warning {{right shifting a 'bool' 
implicitly converts it to 'int'}}
-
-  bool k = (x < z) >> 1; // expected-warning {{right shifting a 'bool' 
implicitly converts it to 'int'}}
 }

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


[clang] [Clang][NFC] update_cc_test_checks over strictfp-elementwise-bulitins.cpp (PR #130747)

2025-03-11 Thread Matt Arsenault via cfe-commits

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

Test name also also has typo "bulitins"

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


  1   2   3   4   5   6   7   >