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

2025-03-07 Thread via cfe-commits

cor3ntin wrote:

> This needs a higher-level description of the overall goal, and why you've 
> picked the specific instrumentation points you've chosen.

And tests! Thanks

https://github.com/llvm/llvm-project/pull/130103
___
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-07 Thread via cfe-commits

u4f3 wrote:

Seems that the error in `/llvm-project/clang/test/Driver/offload-Xarch.c` is 
not relevant. And I can't reproduce this error since I don't have a windows 
machine...

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] [alpha.webkit.UncountedCallArgsChecker] Recognize CXXUnresolvedConstructExpr as a safe origin. (PR #130258)

2025-03-07 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

Handle CXXUnresolvedConstructExpr in tryToFindPtrOrigin so that constructing 
Ref, RefPtr, CheckedRef, CheckedPtr, ... constructed in such a way that its 
type is unresolved at AST level will be still treated as a safe pointer origin.

Also fix a bug in isPtrOfType that it was not recognizing 
DeducedTemplateSpecializationType.

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


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+4) 
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+8-7) 
- (modified) clang/test/Analysis/Checkers/WebKit/call-args.cpp (+35) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index dc86c4fcc64b1..885203550b8a8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -43,6 +43,10 @@ bool tryToFindPtrOrigin(
 break;
   }
 }
+if (auto *TempExpr = dyn_cast(E)) {
+  if (isSafePtrType(TempExpr->getTypeAsWritten()))
+return callback(TempExpr, true);
+}
 if (auto *POE = dyn_cast(E)) {
   if (auto *RF = POE->getResultExpr()) {
 E = RF;
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 7899b19854806..8a304a07296fc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -162,13 +162,14 @@ static bool isPtrOfType(const clang::QualType T, 
Predicate Pred) {
   type = elaboratedT->desugar();
   continue;
 }
-auto *SpecialT = type->getAs();
-if (!SpecialT)
-  return false;
-auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
-if (!Decl)
-  return false;
-return Pred(Decl->getNameAsString());
+if (auto *SpecialT = type->getAs()) {
+  auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
+  return Decl && Pred(Decl->getNameAsString());
+} else if (auto *DTS = type->getAs()) {
+  auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
+  return Decl && Pred(Decl->getNameAsString());
+} else
+  break;
   }
   return false;
 }
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index b4613d5090f29..e7afd9798da3e 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -359,6 +359,41 @@ namespace call_with_ptr_on_ref {
   }
 }
 
+namespace call_with_explicit_construct_from_auto {
+
+  struct Impl {
+void ref() const;
+void deref() const;
+
+static Ref create();
+  };
+
+  template 
+  struct ArgObj {
+T* t;
+  };
+
+  struct Object {
+Object();
+Object(Ref&&);
+
+Impl* impl() const { return m_impl.get(); }
+
+static Object create(ArgObj&) { return Impl::create(); }
+static void bar(Impl&);
+
+  private:
+RefPtr m_impl;
+  };
+
+  template void foo()
+  {
+  auto result = Object::create(ArgObj { });
+  Object::bar(Ref { *result.impl() });
+  }
+
+}
+
 namespace call_with_explicit_temporary_obj {
   void foo() {
 Ref { *provide() }->method();

``




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


[clang] 3a67c7c - [Clang] Check for uninitialized use in lambda within CXXOperatorCallExpr (#129198)

2025-03-07 Thread via cfe-commits

Author: zhaohui
Date: 2025-03-07T16:01:23+08:00
New Revision: 3a67c7c6f7f6d41adf4487d099c1225c31caf8c3

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

LOG: [Clang] Check for uninitialized use in lambda within CXXOperatorCallExpr 
(#129198)

Track whether a LambdaExpr is an immediate operand of a
CXXOperatorCallExpr using a new flag, isInCXXOperatorCall. This enables
special handling of capture initializations to detect uninitialized
variable uses, such as in `S s = [&]() { return s; }();`.

Fix #128058

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/uninitialized.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e42541818a0e9..28856c27317f3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -299,6 +299,7 @@ Improvements to C++ diagnostics
 Bug Fixes to AST Handling
 ^
 - Fixed type checking when a statement expression ends in an l-value of atomic 
type. (#GH106576)
+- Fixed uninitialized use check in a lambda within CXXOperatorCallExpr. 
(#GH129198)
 
 Miscellaneous Bug Fixes
 ^^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8c5125b8eb6d9..714210c3856d7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -61,6 +61,7 @@
 #include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/SaveAndRestore.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 #include 
@@ -12611,6 +12612,7 @@ namespace {
 bool isRecordType;
 bool isPODType;
 bool isReferenceType;
+bool isInCXXOperatorCall;
 
 bool isInitList;
 llvm::SmallVector InitFieldIndex;
@@ -12623,6 +12625,7 @@ namespace {
   isPODType = false;
   isRecordType = false;
   isReferenceType = false;
+  isInCXXOperatorCall = false;
   isInitList = false;
   if (ValueDecl *VD = dyn_cast(OrigDecl)) {
 isPODType = VD->getType().isPODType(S.Context);
@@ -12810,6 +12813,7 @@ namespace {
 }
 
 void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  llvm::SaveAndRestore CxxOpCallScope(isInCXXOperatorCall, true);
   Expr *Callee = E->getCallee();
 
   if (isa(Callee))
@@ -12820,6 +12824,19 @@ namespace {
 HandleValue(Arg->IgnoreParenImpCasts());
 }
 
+void VisitLambdaExpr(LambdaExpr *E) {
+  if (!isInCXXOperatorCall) {
+Inherited::VisitLambdaExpr(E);
+return;
+  }
+
+  for (Expr *Init : E->capture_inits())
+if (DeclRefExpr *DRE = dyn_cast_if_present(Init))
+  HandleDeclRefExpr(DRE);
+else if (Init)
+  Visit(Init);
+}
+
 void VisitUnaryOperator(UnaryOperator *E) {
   // For POD record types, addresses of its own members are well-defined.
   if (E->getOpcode() == UO_AddrOf && isRecordType &&

diff  --git a/clang/test/SemaCXX/uninitialized.cpp 
b/clang/test/SemaCXX/uninitialized.cpp
index 4af2c998f082e..c7b987e2172e6 100644
--- a/clang/test/SemaCXX/uninitialized.cpp
+++ b/clang/test/SemaCXX/uninitialized.cpp
@@ -892,6 +892,11 @@ namespace lambdas {
   return a1.x;
 });
 A a2([&] { return a2.x; }); // ok
+A a3([=] { return a3.x; }()); // expected-warning{{variable 'a3' is 
uninitialized when used within its own initialization}}
+A a4([&] { return a4.x; }()); // expected-warning{{variable 'a4' is 
uninitialized when used within its own initialization}}
+A a5([&] { return a5; }()); // expected-warning{{variable 'a5' is 
uninitialized when used within its own initialization}}
+A a6([&] { return a5.x; }()); // ok
+A a7 = [&a7] { return a7; }(); // expected-warning{{variable 'a7' is 
uninitialized when used within its own initialization}}
   }
 }
 



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


[clang] [clang][SPIR-V] Use the SPIR-V backend by default (PR #129545)

2025-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-spir-v

Author: Nick Sarnie (sarnex)


Changes

The SPIR-V backend is now a supported backend, and we believe it is ready to be 
used by default in Clang over the SPIR-V translator. 

Some IR generated by Clang today, such as those requiring SPIR-V target address 
spaces, cannot be compiled by the translator for reasons in this 
[RFC](https://discourse.llvm.org/t/rfc-the-spir-v-backend-should-change-its-address-space-mappings/82640),
 so we expect even more programs to work as well.

Enable it by default, but keep some of the code as it is still called by the 
HIP toolchain directly.

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


5 Files Affected:

- (modified) clang/docs/UsersManual.rst (+1-31) 
- (modified) clang/lib/Driver/ToolChains/SPIRV.cpp (-8) 
- (modified) clang/lib/Driver/ToolChains/SPIRV.h (+1-3) 
- (modified) clang/test/Driver/spirv-openmp-toolchain.c (+4-6) 
- (modified) clang/test/Driver/spirv-toolchain.cl (+18-24) 


``diff
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 8213334b61c22..b4a99d5e8 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -4681,25 +4681,7 @@ Clang supports generation of SPIR-V conformant to `the 
OpenCL Environment
 Specification
 
`_.
 
-To generate SPIR-V binaries, Clang uses the external ``llvm-spirv`` tool from 
the
-`SPIRV-LLVM-Translator repo
-`_.
-
-Prior to the generation of SPIR-V binary with Clang, ``llvm-spirv``
-should be built or installed. Please refer to `the following instructions
-`_
-for more details. Clang will look for ``llvm-spirv-`` and
-``llvm-spirv`` executables, in this order, in the ``PATH`` environment 
variable.
-Clang uses ``llvm-spirv`` with `the widely adopted assembly syntax package
-`_.
-
-`The versioning
-`_ of
-``llvm-spirv`` is aligned with Clang major releases. The same applies to the
-main development branch. It is therefore important to ensure the ``llvm-spirv``
-version is in alignment with the Clang version. For troubleshooting purposes
-``llvm-spirv`` can be `tested in isolation
-`_.
+To generate SPIR-V binaries, Clang uses the in-tree LLVM SPIR-V backend.
 
 Example usage for OpenCL kernel compilation:
 
@@ -4717,18 +4699,6 @@ Converting to SPIR-V produced with the optimization 
levels other than `-O0` is
 currently available as an experimental feature and it is not guaranteed to work
 in all cases.
 
-Clang also supports integrated generation of SPIR-V without use of 
``llvm-spirv``
-tool as an experimental feature when ``-fintegrated-objemitter`` flag is 
passed in
-the command line.
-
-   .. code-block:: console
-
- $ clang --target=spirv32 -fintegrated-objemitter -c test.cl
-
-Note that only very basic functionality is supported at this point and 
therefore
-it is not suitable for arbitrary use cases. This feature is only enabled when 
clang
-build is configured with ``-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=SPIRV`` option.
-
 Linking is done using ``spirv-link`` from `the SPIRV-Tools project
 `_. Similar to other 
external
 linkers, Clang will expect ``spirv-link`` to be installed separately and to be
diff --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 5a7894f5435fc..8ff39fe42f3aa 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -93,12 +93,6 @@ void SPIRV::Assembler::ConstructJob(Compilation &C, const 
JobAction &JA,
   constructAssembleCommand(C, *this, JA, Output, Inputs[0], {});
 }
 
-clang::driver::Tool *SPIRVToolChain::getTranslator() const {
-  if (!Translator)
-Translator = std::make_unique(*this);
-  return Translator.get();
-}
-
 clang::driver::Tool *SPIRVToolChain::getAssembler() const {
   if (!Assembler)
 Assembler = std::make_unique(*this);
@@ -114,8 +108,6 @@ clang::driver::Tool 
*SPIRVToolChain::getTool(Action::ActionClass AC) const {
   switch (AC) {
   default:
 break;
-  case Action::BackendJobClass:
-return SPIRVToolChain::getTranslator();
   case Action::AssembleJobClass:
 return SPIRVToolChain::getAssembler();
   }
diff --git a/clang/lib/Driver/ToolChains/SPIRV.h 
b/clang/lib/Driver/ToolChains/SPIRV.h
index 6223d55eca643..924eb01adcbbf 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.h
+++ b/clang/lib/Driver/ToolChains/SPIRV.h
@@ -69,7 +69,6 @@ class LLVM_LIBRARY_VISIBILITY Assembler final : public Tool {
 namespace toolchains {
 
 class LLVM_LIBRARY_VISIBILITY SPIRVToolChain : public 

[clang] [flang] [lldb] [llvm] [mlir] [polly] [IR] Store Triple in Module (NFC) (PR #129868)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-nvptx-nvidia-ubuntu` 
running on `as-builder-7` while building 
`clang,flang,lldb,llvm,mlir,offload,polly` at step 5 "build-unified-tree".

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


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

```
Step 5 (build-unified-tree) failure: build (failure)
...
138.817 [252/128/2338] Building CXX object 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86LowerAMXType.cpp.o
138.875 [251/128/2339] Building CXX object 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86LowerAMXIntrinsics.cpp.o
139.737 [250/128/2340] Building CXX object 
lib/Target/X86/Disassembler/CMakeFiles/LLVMX86Disassembler.dir/X86Disassembler.cpp.o
139.860 [249/128/2341] Linking CXX shared library 
lib/libLLVMX86Disassembler.so.21.0git
139.900 [248/128/2342] Creating library symlink lib/libLLVMX86Disassembler.so
140.428 [247/128/2343] Building CXX object 
tools/llvm-objdump/CMakeFiles/llvm-objdump.dir/WasmDump.cpp.o
140.480 [246/128/2344] Building CXX object 
tools/llvm-gsymutil/CMakeFiles/llvm-gsymutil.dir/llvm-gsymutil.cpp.o
140.616 [245/128/2345] Building CXX object 
lib/AsmParser/CMakeFiles/LLVMAsmParser.dir/LLParser.cpp.o
140.647 [244/128/2346] Building CXX object 
tools/llvm-ml/CMakeFiles/llvm-ml.dir/Disassembler.cpp.o
140.710 [243/128/2347] Linking CXX shared library 
lib/libLLVMAsmParser.so.21.0git
FAILED: lib/libLLVMAsmParser.so.21.0git 
: && /usr/bin/c++ -fPIC -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  -Wl,-z,defs -Wl,-z,nodelete -fuse-ld=gold   
-Wl,--gc-sections -shared -Wl,-soname,libLLVMAsmParser.so.21.0git -o 
lib/libLLVMAsmParser.so.21.0git 
lib/AsmParser/CMakeFiles/LLVMAsmParser.dir/LLLexer.cpp.o 
lib/AsmParser/CMakeFiles/LLVMAsmParser.dir/LLParser.cpp.o 
lib/AsmParser/CMakeFiles/LLVMAsmParser.dir/Parser.cpp.o  
-Wl,-rpath,"\$ORIGIN/../lib:/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/lib:"
  lib/libLLVMCore.so.21.0git  lib/libLLVMBinaryFormat.so.21.0git  
lib/libLLVMSupport.so.21.0git  
-Wl,-rpath-link,/home/buildbot/worker/as-builder-7/ramdisk/llvm-nvptx-nvidia-ubuntu/build/lib
 && :
lib/AsmParser/CMakeFiles/LLVMAsmParser.dir/LLParser.cpp.o:LLParser.cpp:function 
llvm::LLParser::parseTargetDefinition(std::__cxx11::basic_string, std::allocator >&, llvm::SMLoc&) [clone 
.localalias]: error: undefined reference to 'llvm::Triple::Triple(llvm::Twine 
const&)'
collect2: error: ld returned 1 exit status
140.768 [243/127/2348] Building CXX object 
tools/llvm-dwarfdump/CMakeFiles/llvm-dwarfdump.dir/llvm-dwarfdump.cpp.o
140.804 [243/126/2349] Building CXX object 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86CmovConversion.cpp.o
140.920 [243/125/2350] Building CXX object 
tools/sancov/CMakeFiles/sancov.dir/sancov.cpp.o
141.309 [243/124/2351] Building CXX object 
tools/llvm-lipo/CMakeFiles/llvm-lipo.dir/llvm-lipo.cpp.o
141.332 [243/123/2352] Building CXX object 
lib/Target/NVPTX/CMakeFiles/LLVMNVPTXCodeGen.dir/NVPTXTargetMachine.cpp.o
141.682 [243/122/2353] Building CXX object 
tools/llvm-reduce/CMakeFiles/llvm-reduce.dir/deltas/ReduceDbgRecords.cpp.o
141.714 [243/121/2354] Building CXX object 
tools/llvm-jitlink/CMakeFiles/llvm-jitlink.dir/llvm-jitlink-coff.cpp.o
141.719 [243/120/2355] Building CXX object 
tools/llvm-objdump/CMakeFiles/llvm-objdump.dir/OffloadDump.cpp.o
141.788 [243/119/2356] Building CXX object 
tools/llvm-jitlink/CMakeFiles/llvm-jitlink.dir/llvm-jitlink-statistics.cpp.o
141.831 [243/118/2357] Building CXX object 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86FloatingPoint.cpp.o
141.837 [243/117/2358] Building CXX object 
tools/llvm-reduce/CMakeFiles/llvm-reduce.dir/deltas/ReduceGlobalValues.cpp.o
141.915 [243/116/2359] Building CXX object 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86AvoidTrailingCall.cpp.o
141.985 [243/115/2360] Building CXX object 
tools/llvm-jitlink/CMakeFiles/llvm-jitlink.dir/llvm-jitlink-elf.cpp.o
142.003 [243/114/2361] Building CXX object 
lib/Target/X86/CMakeFiles/LLVMX86CodeGen.dir/X86MacroFusion.cpp.o
142.069 [243/113/2362] Building CXX object 
tools/llvm-reduce/CMakeFiles/llvm-reduce.dir/deltas/ReduceAliases.cpp.o
142.069 [243/112/2363] Building CXX object 
tools/llvm-reduce/CMakeFiles/llvm-reduce.dir/deltas/ReduceFunctions.cpp.o
142.080 [243/111/2364] Building CXX object 
tools/llvm-reduce/CMakeFiles/llvm-reduce.dir/deltas/ReduceGlobalObjects.cpp.o
142.188 [243/110/2365] Building CXX object 
lib/

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

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

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

>From bb4091d2f9b7062aa83e5bee2ba525478a7dbd0a Mon Sep 17 00:00:00 2001
From: Maurice Heumann 
Date: Wed, 26 Feb 2025 14:31:47 +0100
Subject: [PATCH 1/6] 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 5b5cee5810488..c5b2d58a78fd2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5432,6 +5432,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 a3a028b9485d6..761f6a09037a7 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -5450,10 +5450,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;
@@ -5758,6 +5779,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) {
@@ -5773,39 +5830,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-tools-extra] [clang-tidy] Avoid processing declarations in system headers (PR #128150)

2025-03-07 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

> This does not sound controversial or hard.

It is already controversial for clang-tidy, surely it will be even more 
controversial if we involve many other tools?

Besides, this request involves a much larger scope (in terms of modified 
behaviors, not lines of code) than intended. The scope of this patch is only to 
improve clang-tidy. Everything can always be improved, but it does not need to 
happen in one single commit. It's [good 
practice](https://llvm.org/docs/CodeReview.html#code-reviews-speed-and-reciprocity)
 to keep commits small, focused on doing one single thing, especially if there 
is risk of revert. The risk of revert is a lot higher if N tools are modified 
than if only one tool is modified. It wouldn't be good to revert changes to 
clang-tidy just because this change breaks another unrelated tool.

Like I said, I'm not against improving the other tools, simply that it should 
be done in follow-up patches, one step at a time. What would be the drawback of 
that?

> helping them out documenting the rationale and suggesting workarounds

Sure, makes sense. Do you have any concrete suggestion in mind? Personally I 
can't think of a way to enable individual checks to regain access to the "full 
analysis". Like I said above, that would be great, but I don't know how to 
achieve that in practice.

If we want to protect downstream users, I suppose we can add a configuration 
option to revert back to the "full analysis" behavior. Would that lower the 
risk?

> Could you summarize what you tried and why it did not work?

I diffed which declarations were picked up with "full analysis" and with this 
patch, on [this example code](https://godbolt.org/z/bjs3nW6js). It appears that 
`IndirectFieldDecl` (which is picked up by the check) is not a **top-level 
declaration,** and therefore it no longer becomes part of the traversal scope. 
That is, this issue is unrelated to system headers or not, but rather that 
there are some declarations that are not top-level declarations. Why that's the 
case, or if it's intentional, is way beyond my knowledge.

I searched for functionality to handle these special declarations in the 
`ASTConsumer` class but couldn't find a suitable `handle*` function for that.

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] 494bf26 - Add a link to the paper to a release note; NFC

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

Author: Aaron Ballman
Date: 2025-03-07T11:10:28-05:00
New Revision: 494bf26736f49db3a1932ef6067b2fc1737d78be

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

LOG: Add a link to the paper to a release note; NFC

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7d443b4ee8a29..cf363d6af4583 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -111,9 +111,9 @@ C Language Changes
 
 C2y Feature Support
 ^^^
-- Implemented N3411 which allows a source file to not end with a newline
-  character. This is still reported as a conforming extension in earlier
-  language modes.
+- Implemented `WG14 N3411 
`_
+  which allows a source file to not end with a newline character. This is still
+  reported as a conforming extension in earlier language modes.
 
 C23 Feature Support
 ^^^



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


[clang] [C2y] Implement WG14 N3409 (PR #130299)

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

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/130299

>From 8ee44f1f2beb659a37c693b4f323491f6bfd8caa Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Fri, 7 Mar 2025 11:04:31 -0500
Subject: [PATCH] [C2y] Implement WG14 N3409

This paper removes UB around use of void expressions. Previously, code
like this had undefined behavior:

  void foo(void) {
(void)(void)1;
extern void x;
x;
  }

and this is now well-defined in C2y. Functionally, this now means that
it is valid to use `void` as a `_Generic` association.
---
 clang/docs/ReleaseNotes.rst   |  4 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  9 --
 clang/lib/Sema/SemaExpr.cpp   |  7 +++-
 clang/test/C/C2y/n3409.c  | 32 +++
 4 files changed, 49 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/C/C2y/n3409.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 577b3f2130df7..df8d2eed1ec0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -114,6 +114,10 @@ C2y Feature Support
 - Implemented N3411 which allows a source file to not end with a newline
   character. This is still reported as a conforming extension in earlier
   language modes.
+- Implement `WG14 N3409 
`_
+  which removes UB around use of ``void`` expressions. In practice, this means
+  that ``_Generic`` selection associations may now have ``void`` type, but it
+  also removes UB with code like ``(void)(void)1;``.
 
 C23 Feature Support
 ^^^
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1b46920e09619..d6e5005003322 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10425,8 +10425,13 @@ def warn_type_safety_null_pointer_required : Warning<
   "specified %0 type tag requires a null pointer">, InGroup;
 
 // Generic selections.
-def err_assoc_type_incomplete : Error<
-  "type %0 in generic association incomplete">;
+def ext_assoc_type_incomplete : Extension<
+  "ISO C requires a complete type in a '_Generic' association; %0 is an "
+  "incomplete type">;
+def warn_c2y_compat_assoc_type_incomplete : Warning<
+  "use of an incomplete type in a '_Generic' association is incompatible with "
+  "C standards before C2y; %0 is an incomplete type">,
+  InGroup, DefaultIgnore;
 def err_assoc_type_nonobject : Error<
   "type %0 in generic association not an object type">;
 def err_assoc_type_variably_modified : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f896ccab53a54..de7be6b2805af 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1748,9 +1748,14 @@ ExprResult Sema::CreateGenericSelectionExpr(
 //
 // C11 6.5.1.1p2 "The type name in a generic association shall specify 
a
 // complete object type other than a variably modified type."
+// C2y removed the requirement that an expression form must
+// use a complete type, though it's still as-if the type has undergone
+// lvalue conversion. We support this as an extension in C23 and
+// earlier because GCC does so.
 unsigned D = 0;
 if (ControllingExpr && Types[i]->getType()->isIncompleteType())
-  D = diag::err_assoc_type_incomplete;
+  D = LangOpts.C2y ? diag::warn_c2y_compat_assoc_type_incomplete
+   : diag::ext_assoc_type_incomplete;
 else if (ControllingExpr && !Types[i]->getType()->isObjectType())
   D = diag::err_assoc_type_nonobject;
 else if (Types[i]->getType()->isVariablyModifiedType())
diff --git a/clang/test/C/C2y/n3409.c b/clang/test/C/C2y/n3409.c
new file mode 100644
index 0..2fc789891c71d
--- /dev/null
+++ b/clang/test/C/C2y/n3409.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -verify -std=c2y -pedantic %s
+// RUN: %clang_cc1 -verify=pre-c2y -std=c2y -Wpre-c2y-compat %s
+// RUN: %clang_cc1 -verify=ext -std=c23 -pedantic %s
+// expected-no-diagnostics
+
+/* WG14 N3409: Clang 21
+ * Slay Some Earthly Demons X
+ *
+ * Removes the requirement that an expression with type void cannot be used in
+ * any way. This was making it UB to use a void expression in a _Generic
+ * selection expression for no good reason, as well as making it UB to cast a
+ * void expression to void, etc.
+ */
+
+extern void x;
+void foo() {
+  // FIXME: this is technically an extension before C2y and should be diagnosed
+  // under -pedantic.
+  (void)(void)1;
+  // FIXME: same with this.
+  x;
+  _Generic(x, void: 1);  /* pre-c2y-warning {{use of an incomplete type in 
a '_Generic' association is incompatible with C standards before C2y; 'void' is 
an incomplete type}}
+ext-warning {{ISO C requires a complete type 
in a '_Gener

[clang] [C2y] Implement WG14 N3409 (PR #130299)

2025-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)


Changes

This paper removes UB around use of void expressions. Previously, code like 
this had undefined behavior:
```
  void foo(void) {
(void)(void)1;
extern void x;
x;
  }
```
and this is now well-defined in C2y. Functionally, this now means that it is 
valid to use `void` as a `_Generic` association.

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+7-2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+6-1) 
- (added) clang/test/C/C2y/n3409.c (+32) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 577b3f2130df7..df8d2eed1ec0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -114,6 +114,10 @@ C2y Feature Support
 - Implemented N3411 which allows a source file to not end with a newline
   character. This is still reported as a conforming extension in earlier
   language modes.
+- Implement `WG14 N3409 
`_
+  which removes UB around use of ``void`` expressions. In practice, this means
+  that ``_Generic`` selection associations may now have ``void`` type, but it
+  also removes UB with code like ``(void)(void)1;``.
 
 C23 Feature Support
 ^^^
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1b46920e09619..d6e5005003322 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10425,8 +10425,13 @@ def warn_type_safety_null_pointer_required : Warning<
   "specified %0 type tag requires a null pointer">, InGroup;
 
 // Generic selections.
-def err_assoc_type_incomplete : Error<
-  "type %0 in generic association incomplete">;
+def ext_assoc_type_incomplete : Extension<
+  "ISO C requires a complete type in a '_Generic' association; %0 is an "
+  "incomplete type">;
+def warn_c2y_compat_assoc_type_incomplete : Warning<
+  "use of an incomplete type in a '_Generic' association is incompatible with "
+  "C standards before C2y; %0 is an incomplete type">,
+  InGroup, DefaultIgnore;
 def err_assoc_type_nonobject : Error<
   "type %0 in generic association not an object type">;
 def err_assoc_type_variably_modified : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f896ccab53a54..de7be6b2805af 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1748,9 +1748,14 @@ ExprResult Sema::CreateGenericSelectionExpr(
 //
 // C11 6.5.1.1p2 "The type name in a generic association shall specify 
a
 // complete object type other than a variably modified type."
+// C2y removed the requirement that an expression form must
+// use a complete type, though it's still as-if the type has undergone
+// lvalue conversion. We support this as an extension in C23 and
+// earlier because GCC does so.
 unsigned D = 0;
 if (ControllingExpr && Types[i]->getType()->isIncompleteType())
-  D = diag::err_assoc_type_incomplete;
+  D = LangOpts.C2y ? diag::warn_c2y_compat_assoc_type_incomplete
+   : diag::ext_assoc_type_incomplete;
 else if (ControllingExpr && !Types[i]->getType()->isObjectType())
   D = diag::err_assoc_type_nonobject;
 else if (Types[i]->getType()->isVariablyModifiedType())
diff --git a/clang/test/C/C2y/n3409.c b/clang/test/C/C2y/n3409.c
new file mode 100644
index 0..2fc789891c71d
--- /dev/null
+++ b/clang/test/C/C2y/n3409.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -verify -std=c2y -pedantic %s
+// RUN: %clang_cc1 -verify=pre-c2y -std=c2y -Wpre-c2y-compat %s
+// RUN: %clang_cc1 -verify=ext -std=c23 -pedantic %s
+// expected-no-diagnostics
+
+/* WG14 N3409: Clang 21
+ * Slay Some Earthly Demons X
+ *
+ * Removes the requirement that an expression with type void cannot be used in
+ * any way. This was making it UB to use a void expression in a _Generic
+ * selection expression for no good reason, as well as making it UB to cast a
+ * void expression to void, etc.
+ */
+
+extern void x;
+void foo() {
+  // FIXME: this is technically an extension before C2y and should be diagnosed
+  // under -pedantic.
+  (void)(void)1;
+  // FIXME: same with this.
+  x;
+  _Generic(x, void: 1);  /* pre-c2y-warning {{use of an incomplete type in 
a '_Generic' association is incompatible with C standards before C2y; 'void' is 
an incomplete type}}
+ext-warning {{ISO C requires a complete type 
in a '_Generic' association; 'void' is an incomplete type}}
+  */
+  _Generic(x, typeof(x): 1); /* pre-c2y-warning {{use of an incomplete type in 
a '_Generic' association is i

[clang-tools-extra] [clang-tidy] Add new check bugprone-capture-this-by-field (PR #130297)

2025-03-07 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 5685def507ed7c95bf93572e5cf8c30efbc7d99b 
8f49378e77a8b248f34d689996835629c279d7c6 --extensions cpp,h -- 
clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.cpp 
clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.h 
clang-tools-extra/test/clang-tidy/checkers/bugprone/capture-this-by-field.cpp 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.h
index 72c0a540a7..0329614ad2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.h
@@ -15,8 +15,9 @@
 
 namespace clang::tidy::bugprone {
 
-/// Finds lambda captures that capture the ``this`` pointer and store it as 
class
-/// members without handle the copy and move constructors and the assignments.
+/// Finds lambda captures that capture the ``this`` pointer and store it as
+/// class members without handle the copy and move constructors and the
+/// assignments.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/capture-this-by-field.html

``




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


[clang] [LinkerWrapper] Try to fix testing on Windows (PR #130285)

2025-03-07 Thread Michael Kruse via cfe-commits

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


[clang] [C2y] Implement WG14 N3409 (PR #130299)

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

https://github.com/AaronBallman created 
https://github.com/llvm/llvm-project/pull/130299

This paper removes UB around use of void expressions. Previously, code like 
this had undefined behavior:
```
  void foo(void) {
(void)(void)1;
extern void x;
x;
  }
```
and this is now well-defined in C2y. Functionally, this now means that it is 
valid to use `void` as a `_Generic` association.

>From 8ee44f1f2beb659a37c693b4f323491f6bfd8caa Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Fri, 7 Mar 2025 11:04:31 -0500
Subject: [PATCH] [C2y] Implement WG14 N3409

This paper removes UB around use of void expressions. Previously, code
like this had undefined behavior:

  void foo(void) {
(void)(void)1;
extern void x;
x;
  }

and this is now well-defined in C2y. Functionally, this now means that
it is valid to use `void` as a `_Generic` association.
---
 clang/docs/ReleaseNotes.rst   |  4 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  9 --
 clang/lib/Sema/SemaExpr.cpp   |  7 +++-
 clang/test/C/C2y/n3409.c  | 32 +++
 4 files changed, 49 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/C/C2y/n3409.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 577b3f2130df7..df8d2eed1ec0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -114,6 +114,10 @@ C2y Feature Support
 - Implemented N3411 which allows a source file to not end with a newline
   character. This is still reported as a conforming extension in earlier
   language modes.
+- Implement `WG14 N3409 
`_
+  which removes UB around use of ``void`` expressions. In practice, this means
+  that ``_Generic`` selection associations may now have ``void`` type, but it
+  also removes UB with code like ``(void)(void)1;``.
 
 C23 Feature Support
 ^^^
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1b46920e09619..d6e5005003322 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10425,8 +10425,13 @@ def warn_type_safety_null_pointer_required : Warning<
   "specified %0 type tag requires a null pointer">, InGroup;
 
 // Generic selections.
-def err_assoc_type_incomplete : Error<
-  "type %0 in generic association incomplete">;
+def ext_assoc_type_incomplete : Extension<
+  "ISO C requires a complete type in a '_Generic' association; %0 is an "
+  "incomplete type">;
+def warn_c2y_compat_assoc_type_incomplete : Warning<
+  "use of an incomplete type in a '_Generic' association is incompatible with "
+  "C standards before C2y; %0 is an incomplete type">,
+  InGroup, DefaultIgnore;
 def err_assoc_type_nonobject : Error<
   "type %0 in generic association not an object type">;
 def err_assoc_type_variably_modified : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f896ccab53a54..de7be6b2805af 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1748,9 +1748,14 @@ ExprResult Sema::CreateGenericSelectionExpr(
 //
 // C11 6.5.1.1p2 "The type name in a generic association shall specify 
a
 // complete object type other than a variably modified type."
+// C2y removed the requirement that an expression form must
+// use a complete type, though it's still as-if the type has undergone
+// lvalue conversion. We support this as an extension in C23 and
+// earlier because GCC does so.
 unsigned D = 0;
 if (ControllingExpr && Types[i]->getType()->isIncompleteType())
-  D = diag::err_assoc_type_incomplete;
+  D = LangOpts.C2y ? diag::warn_c2y_compat_assoc_type_incomplete
+   : diag::ext_assoc_type_incomplete;
 else if (ControllingExpr && !Types[i]->getType()->isObjectType())
   D = diag::err_assoc_type_nonobject;
 else if (Types[i]->getType()->isVariablyModifiedType())
diff --git a/clang/test/C/C2y/n3409.c b/clang/test/C/C2y/n3409.c
new file mode 100644
index 0..2fc789891c71d
--- /dev/null
+++ b/clang/test/C/C2y/n3409.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -verify -std=c2y -pedantic %s
+// RUN: %clang_cc1 -verify=pre-c2y -std=c2y -Wpre-c2y-compat %s
+// RUN: %clang_cc1 -verify=ext -std=c23 -pedantic %s
+// expected-no-diagnostics
+
+/* WG14 N3409: Clang 21
+ * Slay Some Earthly Demons X
+ *
+ * Removes the requirement that an expression with type void cannot be used in
+ * any way. This was making it UB to use a void expression in a _Generic
+ * selection expression for no good reason, as well as making it UB to cast a
+ * void expression to void, etc.
+ */
+
+extern void x;
+void foo() {
+  // FIXME: this is technically an extension before C2y and should be diagnosed
+  // under -pedantic.
+  (void)(void)1;

[clang] clang: Enable linker-wrapper test on windows (PR #130248)

2025-03-07 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

https://github.com/llvm/llvm-project/pull/130285 I'll see if this makes CI 
happy, thanks so much for your diagnosis.

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


[clang] [-Wunsafe-buffer-usage] Add alloc_size knowledge to the 2-param span constructor warning (PR #114894)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-win` 
running on `sie-win-worker` while building `clang` at step 7 
"test-build-unified-tree-check-all".

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


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

```
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'LLVM-Unit :: Support/./SupportTests.exe/6/44' FAILED 

Script(shard):
--
GTEST_OUTPUT=json:Z:\b\llvm-clang-x86_64-sie-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-14604-6-44.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=44 GTEST_SHARD_INDEX=6 
Z:\b\llvm-clang-x86_64-sie-win\build\unittests\Support\.\SupportTests.exe
--

Script:
--
Z:\b\llvm-clang-x86_64-sie-win\build\unittests\Support\.\SupportTests.exe 
--gtest_filter=Caching.NoCommit
--
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\Support\Caching.cpp(142):
 error: Value of: AddStream
  Actual: false
Expected: true


Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\Support\Caching.cpp:142
Value of: AddStream
  Actual: false
Expected: true






```



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


[clang] 55f86cf - [RISCV][clang] Fix wrong VLS CC detection (#130107)

2025-03-07 Thread via cfe-commits

Author: Kito Cheng
Date: 2025-03-07T11:15:20+08:00
New Revision: 55f86cf02336e0a1bce81403296cce6d4cfbb1e4

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

LOG: [RISCV][clang] Fix wrong VLS CC detection (#130107)

RISCVABIInfo::detectVLSCCEligibleStruct should early exit if VLS calling
convention is not used, however the sentinel value was not set to
correctly, it should be zero instead of one.

Added: 
clang/test/CodeGen/RISCV/pr129995.cc

Modified: 
clang/lib/CodeGen/Targets/RISCV.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/RISCV.cpp 
b/clang/lib/CodeGen/Targets/RISCV.cpp
index 081ae8a403111..5aa10ba41f5ed 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -389,7 +389,7 @@ ABIArgInfo RISCVABIInfo::coerceAndExpandFPCCEligibleStruct(
 bool RISCVABIInfo::detectVLSCCEligibleStruct(QualType Ty, unsigned ABIVLen,
  llvm::Type *&VLSType) const {
   // No riscv_vls_cc attribute.
-  if (ABIVLen == 1)
+  if (ABIVLen == 0)
 return false;
 
   // Legal struct for VLS calling convention should fulfill following rules:

diff  --git a/clang/test/CodeGen/RISCV/pr129995.cc 
b/clang/test/CodeGen/RISCV/pr129995.cc
new file mode 100644
index 0..590c6b9fbdf96
--- /dev/null
+++ b/clang/test/CodeGen/RISCV/pr129995.cc
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 triple riscv64 -emit-llvm -target-feature +m 
-target-feature +v -target-abi lp64d -o /dev/null %s
+
+struct a {
+  using b = char __attribute__((vector_size(sizeof(char;
+};
+class c {
+  using d = a::b;
+  d e;
+
+public:
+  static c f();
+};
+class g {
+public:
+  template  g(h);
+  friend g operator^(g, g) { c::f; }
+  friend g operator^=(g i, g j) { i ^ j; }
+};
+template  using k = g;
+template  using m = k;
+void n() {
+  void o();
+  m p = o ^= p;
+}



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


[clang] [Clang] Check for uninitialized use in lambda within CXXOperatorCallExpr (PR #129198)

2025-03-07 Thread Shafik Yaghmour via cfe-commits


@@ -12796,6 +12799,7 @@ namespace {
 }
 
 void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+  llvm::SaveAndRestore CxxOpCallScope(isInCXXOperatorCall, true);

shafik wrote:

We should be using 
[bugprone-argument-comment](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html)
 style for all literal arguments like this.

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


[clang] Implement the `fmod` intrinsic (PR #130320)

2025-03-07 Thread Deric C. via cfe-commits

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


[clang] clang/HIP: Use regex for final path separator in hip-partial-link, again (PR #130371)

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

https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/130371

Follow up to c6b9d5ce76a155b682b1562122f43166aaa6391d in another instance.
This is still failing in unrelated PR prechecks, but passing its own check.

>From 41ecac5701fec0f0a358f4503f469f2562b31210 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Sat, 8 Mar 2025 07:26:56 +0700
Subject: [PATCH] clang/HIP: Use regex for final path separator in
 hip-partial-link, again

Follow up to c6b9d5ce76a155b682b1562122f43166aaa6391d in another instance.
This is still failing in unrelated PR prechecks, but passing its own check.
---
 clang/test/Driver/hip-partial-link.hip | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/test/Driver/hip-partial-link.hip 
b/clang/test/Driver/hip-partial-link.hip
index 5c538556a5070..d1a57bbe1d75c 100644
--- a/clang/test/Driver/hip-partial-link.hip
+++ b/clang/test/Driver/hip-partial-link.hip
@@ -32,11 +32,11 @@
 // LD-R: Found undefined HIP fatbin symbol: __hip_fatbin_[[ID2:[0-9a-f]+]]
 // LD-R: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID1]]
 // LD-R: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID2]]
-// LD-R: "{{.*}}/clang-offload-bundler" {{.*}}-unbundle
-// LD-R: "{{.*}}/lld" -flavor gnu -m elf64_amdgpu
-// LD-R: "{{.*}}/clang-offload-bundler"
-// LD-R: "{{.*}}/clang{{.*}}" -target x86_64-unknown-linux-gnu
-// LD-R: "{{.*}}/ld.lld" {{.*}} -r
+// LD-R: "{{.*[/\\]}}clang-offload-bundler" {{.*}}-unbundle
+// LD-R: "{{.*[/\\]}}lld" -flavor gnu -m elf64_amdgpu
+// LD-R: "{{.*[/\\]}}clang-offload-bundler"
+// LD-R: "{{.*[/\\]}}clang{{.*}}" -target x86_64-unknown-linux-gnu
+// LD-R: "{{.*[/\\]}}ld.lld" {{.*}} -r
 
 // RUN: llvm-nm  %t.lib.o | FileCheck -check-prefix=OBJ %s
 // OBJ:  B __hip_cuid_[[ID1:[0-9a-f]+]]

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


[clang] [Clang] Check for uninitialized use in lambda within CXXOperatorCallExpr (PR #129198)

2025-03-07 Thread Shafik Yaghmour via cfe-commits

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


[clang] [Clang] Check for uninitialized use in lambda within CXXOperatorCallExpr (PR #129198)

2025-03-07 Thread Shafik Yaghmour via cfe-commits


@@ -12609,6 +12611,7 @@ namespace {
   isPODType = false;
   isRecordType = false;
   isReferenceType = false;
+  isInCXXOperatorCall = false;

shafik wrote:

It feels like changing this to use in class member initializers would have been 
a big win.

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


[clang] [WebAssembly] Rename functions in wasm-eh.cpp (PR #130220)

2025-03-07 Thread Heejin Ahn via cfe-commits

aheejin wrote:

@llvm-ci The CI failure does not look relevant.

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


[clang] [alpha.webkit.webkit.RetainPtrCtorAdoptChecker] Add a new WebKit checker for correct use of RetainPtr, adoptNS, and adoptCF (PR #128679)

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

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

>From b4001f95cf6d35f59ef8af6df8f2bdbe043da380 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Tue, 25 Feb 2025 00:47:45 -0800
Subject: [PATCH 1/6] [alpha.webkit.webkit.RetainPtrCtorAdoptChecker] Add a new
 WebKit checker for correct use of RetainPtr, adoptNS, and adoptCF

Add a new WebKit checker to validate the correct use of RetainPtr constructor 
as well as adoptNS and adoptCF functions.
adoptNS and adoptCf are used for +1 semantics and RetainPtr constructor is used 
for +0 semantics.
---
 clang/docs/analyzer/checkers.rst  |  20 +
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 +
 .../Checkers/WebKit/PtrTypesSemantics.cpp |   7 +-
 .../Checkers/WebKit/PtrTypesSemantics.h   |   3 +-
 .../WebKit/RetainPtrCtorAdoptChecker.cpp  | 347 ++
 .../Checkers/WebKit/objc-mock-types.h | 146 +++-
 .../WebKit/retain-ptr-ctor-adopt-use-arc.mm   |  85 +
 .../WebKit/retain-ptr-ctor-adopt-use.mm   |  85 +
 9 files changed, 680 insertions(+), 18 deletions(-)
 create mode 100644 
clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index c1eedb33e74d2..4cbd31f44d3f6 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3713,6 +3713,26 @@ Here are some examples of situations that we warn about 
as they *might* be poten
   NSObject* unretained = retained.get(); // warn
 }
 
+webkit.RetainPtrCtorAdoptChecker
+
+The goal of this rule is to make sure the constructor of RetinPtr as well as 
adoptNS and adoptCF are used correctly.
+When creating a RetainPtr with +1 semantics, adoptNS or adoptCF should be 
used, and in +0 semantics, RetainPtr constructor should be used.
+Warn otherwise.
+
+These are examples of cases that we consider correct:
+
+  .. code-block:: cpp
+
+RetainPtr ptr = adoptNS([[NSObject alloc] init]); // ok
+RetainPtr ptr = CGImageGetColorSpace(image); // ok
+
+Here are some examples of cases that we consider incorrect use of RetainPtr 
constructor and adoptCF
+
+  .. code-block:: cpp
+
+RetainPtr ptr = [[NSObject alloc] init]; // warn
+auto ptr = adoptCF(CGImageGetColorSpace(image)); // warn
+
 Debug Checkers
 ---
 
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 410f841630660..9aa696d8803b1 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1786,4 +1786,8 @@ def UnretainedLocalVarsChecker : 
Checker<"UnretainedLocalVarsChecker">,
   HelpText<"Check unretained local variables.">,
   Documentation;
 
+def RetainPtrCtorAdoptChecker : Checker<"RetainPtrCtorAdoptChecker">,
+  HelpText<"Check for correct use of RetainPtr constructor, adoptNS, and 
adoptCF">,
+  Documentation;
+
 } // end alpha.webkit
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 5910043440987..0b6b169d7b447 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -133,6 +133,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   WebKit/MemoryUnsafeCastChecker.cpp
   WebKit/PtrTypesSemantics.cpp
   WebKit/RefCntblBaseVirtualDtorChecker.cpp
+  WebKit/RetainPtrCtorAdoptChecker.cpp
   WebKit/RawPtrRefCallArgsChecker.cpp
   WebKit/UncountedLambdaCapturesChecker.cpp
   WebKit/RawPtrRefLocalVarsChecker.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 7899b19854806..7e7bd49ca0bdb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -225,15 +225,16 @@ void RetainTypeChecker::visitTypedef(const TypedefDecl 
*TD) {
 return;
 
   for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) {
-if (Redecl->getAttr()) {
+if (Redecl->getAttr() ||
+Redecl->getAttr()) {
   CFPointees.insert(RT);
   return;
 }
   }
 }
 
-bool RetainTypeChecker::isUnretained(const QualType QT) {
-  if (ento::cocoa::isCocoaObjectRef(QT) && !IsARCEnabled)
+bool RetainTypeChecker::isUnretained(const QualType QT, bool ignoreARC) {
+  if (ento::cocoa::isCocoaObjectRef(QT) && (!IsARCEnabled || ignoreARC))
 return true;
   auto CanonicalType = QT.getCanonicalType();
   auto PointeeType = CanonicalType->getPointeeType();
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTyp

[clang] [alpha.webkit.webkit.RetainPtrCtorAdoptChecker] Add a new WebKit checker for correct use of RetainPtr, adoptNS, and adoptCF (PR #128679)

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

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

>From b4001f95cf6d35f59ef8af6df8f2bdbe043da380 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Tue, 25 Feb 2025 00:47:45 -0800
Subject: [PATCH 1/5] [alpha.webkit.webkit.RetainPtrCtorAdoptChecker] Add a new
 WebKit checker for correct use of RetainPtr, adoptNS, and adoptCF

Add a new WebKit checker to validate the correct use of RetainPtr constructor 
as well as adoptNS and adoptCF functions.
adoptNS and adoptCf are used for +1 semantics and RetainPtr constructor is used 
for +0 semantics.
---
 clang/docs/analyzer/checkers.rst  |  20 +
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 +
 .../Checkers/WebKit/PtrTypesSemantics.cpp |   7 +-
 .../Checkers/WebKit/PtrTypesSemantics.h   |   3 +-
 .../WebKit/RetainPtrCtorAdoptChecker.cpp  | 347 ++
 .../Checkers/WebKit/objc-mock-types.h | 146 +++-
 .../WebKit/retain-ptr-ctor-adopt-use-arc.mm   |  85 +
 .../WebKit/retain-ptr-ctor-adopt-use.mm   |  85 +
 9 files changed, 680 insertions(+), 18 deletions(-)
 create mode 100644 
clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index c1eedb33e74d2..4cbd31f44d3f6 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3713,6 +3713,26 @@ Here are some examples of situations that we warn about 
as they *might* be poten
   NSObject* unretained = retained.get(); // warn
 }
 
+webkit.RetainPtrCtorAdoptChecker
+
+The goal of this rule is to make sure the constructor of RetinPtr as well as 
adoptNS and adoptCF are used correctly.
+When creating a RetainPtr with +1 semantics, adoptNS or adoptCF should be 
used, and in +0 semantics, RetainPtr constructor should be used.
+Warn otherwise.
+
+These are examples of cases that we consider correct:
+
+  .. code-block:: cpp
+
+RetainPtr ptr = adoptNS([[NSObject alloc] init]); // ok
+RetainPtr ptr = CGImageGetColorSpace(image); // ok
+
+Here are some examples of cases that we consider incorrect use of RetainPtr 
constructor and adoptCF
+
+  .. code-block:: cpp
+
+RetainPtr ptr = [[NSObject alloc] init]; // warn
+auto ptr = adoptCF(CGImageGetColorSpace(image)); // warn
+
 Debug Checkers
 ---
 
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 410f841630660..9aa696d8803b1 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1786,4 +1786,8 @@ def UnretainedLocalVarsChecker : 
Checker<"UnretainedLocalVarsChecker">,
   HelpText<"Check unretained local variables.">,
   Documentation;
 
+def RetainPtrCtorAdoptChecker : Checker<"RetainPtrCtorAdoptChecker">,
+  HelpText<"Check for correct use of RetainPtr constructor, adoptNS, and 
adoptCF">,
+  Documentation;
+
 } // end alpha.webkit
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 5910043440987..0b6b169d7b447 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -133,6 +133,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   WebKit/MemoryUnsafeCastChecker.cpp
   WebKit/PtrTypesSemantics.cpp
   WebKit/RefCntblBaseVirtualDtorChecker.cpp
+  WebKit/RetainPtrCtorAdoptChecker.cpp
   WebKit/RawPtrRefCallArgsChecker.cpp
   WebKit/UncountedLambdaCapturesChecker.cpp
   WebKit/RawPtrRefLocalVarsChecker.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 7899b19854806..7e7bd49ca0bdb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -225,15 +225,16 @@ void RetainTypeChecker::visitTypedef(const TypedefDecl 
*TD) {
 return;
 
   for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) {
-if (Redecl->getAttr()) {
+if (Redecl->getAttr() ||
+Redecl->getAttr()) {
   CFPointees.insert(RT);
   return;
 }
   }
 }
 
-bool RetainTypeChecker::isUnretained(const QualType QT) {
-  if (ento::cocoa::isCocoaObjectRef(QT) && !IsARCEnabled)
+bool RetainTypeChecker::isUnretained(const QualType QT, bool ignoreARC) {
+  if (ento::cocoa::isCocoaObjectRef(QT) && (!IsARCEnabled || ignoreARC))
 return true;
   auto CanonicalType = QT.getCanonicalType();
   auto PointeeType = CanonicalType->getPointeeType();
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTyp

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

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

https://github.com/owenca requested changes to this pull request.

Why should we  add those macros to the default list? Can't you use the 
[`AttributeMacros`](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#attributemacros)
 option instead?

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] [clang-tools-extra] [C2y] Implement WG14 N3409 (PR #130299)

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

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


[clang] fefb685 - [Clang][Docs] Fix ``ext_vector_type`` code block documentation

2025-03-07 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2025-03-07T13:55:39-06:00
New Revision: fefb6858da42053268b53c07aff8e1cf84dc1ada

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

LOG: [Clang][Docs] Fix ``ext_vector_type`` code block documentation

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a1b08ac23ee9d..1f2f02a4453fc 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1116,10 +1116,10 @@ template instantiation, so the value for ``T::number`` 
is known.
 def ExtVectorTypeDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
-The ext_vector_type(N) attribute specifies that a type is a vector with N
+The ``ext_vector_type(N)`` attribute specifies that a type is a vector with N
 elements, directly mapping to an LLVM vector type. Originally from OpenCL, it
-allows element access the array subscript operator ``[]``, ``sN`` where ``N`` 
is
-a hexadecimal value, or ``x``, ``y``, ``z``, ``w`` for graphics-style indexing.
+allows element access the array subscript operator ``[]``, ``sN`` where N is
+a hexadecimal value, or ``x, y, z, w`` for graphics-style indexing.
 This attribute enables efficient SIMD operations and is usable in
 general-purpose code.
 
@@ -1128,17 +1128,16 @@ general-purpose code.
   template 
   constexpr T simd_reduce(T [[clang::ext_vector_type(N)]] v) {
 static_assert((N & (N - 1)) == 0, "N must be a power of two");
-if constexpr (N == 1) {
+if constexpr (N == 1)
   return v[0];
-} else {
-  T [[clang::ext_vector_type(N / 2)]] reduced = v.hi + v.lo;
-  return simd_reduce(reduced);
-}
+else
+  return simd_reduce(v.hi + v.lo);
   }
 
 The vector type also supports swizzling up to sixteen elements. This can be 
done
-using the object accessors. The OpenCL documentation lists the full list of
-accepted values.
+using the object accessors. The OpenCL documentation lists all of the accepted
+values.
+
 .. code-block:: c++
 
   using f16_x16 = _Float16 __attribute__((ext_vector_type(16)));



___
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-07 Thread Oleksandr T. via cfe-commits

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

Fixes 
https://github.com/llvm/llvm-project/pull/127336#pullrequestreview-2665950553

>From bed2cb009ae2e560aa00f86b90c57d82f97bb435 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 7 Mar 2025 22:10:24 +0200
Subject: [PATCH] [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'}}
 }

___
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-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes 
https://github.com/llvm/llvm-project/pull/127336#pullrequestreview-2665950553

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


1 Files Affected:

- (modified) clang/test/Sema/shift-bool.cpp (+3) 


``diff
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'}}
 }

``




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] [CIR] Disable gcc partially overloaded virtual warning (PR #130322)

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

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

Someone better equipped to review cmake should review this, but looks ok to me.

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


[clang] Fixed vec_pack_to_short_fp32 in Clang altivec.h (PR #129923)

2025-03-07 Thread Lei Huang via cfe-commits

https://github.com/lei137 commented:

Thank-you for the fix John!

It would be good if your patch can show the changes that is being introduced 
via this patch.  In prep for that I have put up a 
[PR](https://github.com/llvm/llvm-project/pull/130324) to add the existing 
checks for this test.  Can you add the changes that will be introduced as part 
of this PR?  Here is the diff once my patch lands.

```
diff --git a/clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c
index 68d32ee14c8f..824267b98564 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c
@@ -854,15 +854,13 @@ vector unsigned short test74(void) {
 // CHECK-BE: @llvm.ppc.vsx.xvcvsphp(<4 x float>
 // CHECK-BE: @llvm.ppc.vsx.xvcvsphp(<4 x float>
 // CHECK-BE: [[REG0:%[0-9]+]] = call <4 x i32> @llvm.ppc.altivec.vperm
-// CHECK-BE-NEXT: [[REG1:%[0-9]+]] = bitcast <4 x i32> [[REG0]] to <4 x float>
-// CHECK-BE-NEXT: [[REG2:%[0-9]+]] = bitcast <4 x float> [[REG1]] to <8 x i16>
-// CHECK-BE-NEXT: ret <8 x i16> [[REG2]]
+// CHECK-BE-NEXT: [[REG1:%[0-9]+]] = bitcast <4 x i32> [[REG0]] to <8 x i16>
+// CHECK-BE-NEXT: ret <8 x i16> [[REG1]]
 // CHECK: @llvm.ppc.vsx.xvcvsphp(<4 x float>
 // CHECK: @llvm.ppc.vsx.xvcvsphp(<4 x float>
 // CHECK: [[REG0:%[0-9]+]] = call <4 x i32> @llvm.ppc.altivec.vperm
-// CHECK-NEXT: [[REG1:%[0-9]+]] = bitcast <4 x i32> [[REG0]] to <4 x float>
-// CHECK-NEXT: [[REG2:%[0-9]+]] = bitcast <4 x float> [[REG1]] to <8 x i16>
-// CHECK-NEXT: ret <8 x i16> [[REG2]]
+// CHECK-NEXT: [[REG1:%[0-9]+]] = bitcast <4 x i32> [[REG0]] to <8 x i16>
+// CHECK-NEXT: ret <8 x i16> [[REG1]]
   return vec_pack_to_short_fp32(vfa, vfb);
 }
 vector unsigned int test75(void) {
```
Thank-you!

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


[clang] [CIR] Emit init of local variables (PR #130164)

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

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


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


[clang] [HLSL] Implement explicit layout for default constant buffer ($Globals) (PR #128991)

2025-03-07 Thread Helena Kotas via cfe-commits

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


[clang] Implement the `fmod` intrinsic (PR #130320)

2025-03-07 Thread Deric C. via cfe-commits


@@ -22,56 +22,144 @@
 //
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
 // RUN:   spirv-unknown-vulkan-compute %s -fnative-half-type \
-// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -emit-llvm -o - | FileCheck %s \
 // RUN:   -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=half
 
 //
 // -- No Native Half support test ---
 //
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
+// RUN:   spirv-unknown-vulkan-compute %s -emit-llvm \
 // RUN:   -o - | FileCheck %s \
 // RUN:   -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=float
 
 
 
+// DXCHECK: define [[FNATTRS]] [[TYPE]] @
+// DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn [[TYPE]]

Icohedron wrote:

I would leave the llvm passes disabled because the passes are eliminating some 
of the instructions you are emitting.
You can use [string substitution substitution 
blocks](https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-string-substitution-blocks)
 to replace register names like %7 with something more descriptive.

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


[clang] Implement the `fmod` intrinsic (PR #130320)

2025-03-07 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] Implement the `fmod` intrinsic (PR #130320)

2025-03-07 Thread Kaitlin Peng via cfe-commits


@@ -22,56 +22,144 @@
 //
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
 // RUN:   spirv-unknown-vulkan-compute %s -fnative-half-type \
-// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -emit-llvm -o - | FileCheck %s \
 // RUN:   -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=half

kmpeng wrote:

Code updated with suggested changes.

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


[clang] [llvm] [clang][DebugInfo] Add symbol for debugger with VTable information. (PR #130255)

2025-03-07 Thread David Blaikie via cfe-commits

dwblaikie wrote:

I wouldn't mind a few more details here on the motivation.

> This new symbol will allow a debugger to easily associate classes with the 
> physical location of their VTables using only the DWARF information. 

What sort of features are you picturing building with this?

The DWARF currently provides access to the vtable location for /instances/ of 
the class, so curious what the distinction/need is for doing this from the 
class, without instances?

> Previously, this had to be done by searching for ELF symbols with matching 
> names; something that was time-consuming and error-prone in certain edge 
> cases.

(I can appreciate that, if we are at the point of searching the symbol table, 
it's not a great one - but could you talk more about the edge cases/error-prone 
situations?)

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


[clang] Implement the `fmod` intrinsic (PR #130320)

2025-03-07 Thread Kaitlin Peng via cfe-commits

https://github.com/kmpeng updated 
https://github.com/llvm/llvm-project/pull/130320

>From bdb66b5a68090e304647ddbbeb403ac408fcea65 Mon Sep 17 00:00:00 2001
From: kmpeng 
Date: Tue, 25 Feb 2025 14:50:09 -0800
Subject: [PATCH 1/8] start implementation

---
 clang/lib/Headers/hlsl/hlsl_detail.h | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 39254a3cc3a0a..e7e910e30957e 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -97,6 +97,20 @@ constexpr vector reflect_vec_impl(vector I, 
vector N) {
 #endif
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+fmod_vec_impl(vector X, vector Y) {
+#if !defined(__DirectX__)
+  return __builtin_elementwise_fmod(X, Y);
+#else 
+  vector div = X / Y;
+  vector result = 
__builtin_hlsl_elementwise_frac(__builtin_elementwise_abs(div)) * Y; 
+  vector condition = (div >= -div);
+  vector realResult = __builtin_hlsl_select(condition, result, -result);
+  return realResult;
+#endif
+}
+
 } // namespace __detail
 } // namespace hlsl
 #endif //_HLSL_HLSL_DETAILS_H_

>From fe73beac17b99b0f7836ffdb7050e04595d96dba Mon Sep 17 00:00:00 2001
From: kmpeng 
Date: Wed, 26 Feb 2025 15:57:59 -0800
Subject: [PATCH 2/8] finished implementation, working on fmod.hlsl tests

---
 clang/lib/Headers/hlsl/hlsl_detail.h  | 14 +++---
 clang/test/CodeGenHLSL/builtins/fmod.hlsl | 32 +++
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index e7e910e30957e..bc2dd463e0404 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -97,6 +97,12 @@ constexpr vector reflect_vec_impl(vector I, 
vector N) {
 #endif
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+fmod_impl(T X, T Y) {
+  return __builtin_elementwise_fmod(X, Y);
+}
+
 template 
 constexpr enable_if_t::value || is_same::value, T>
 fmod_vec_impl(vector X, vector Y) {
@@ -104,10 +110,10 @@ fmod_vec_impl(vector X, vector Y) {
   return __builtin_elementwise_fmod(X, Y);
 #else 
   vector div = X / Y;
-  vector result = 
__builtin_hlsl_elementwise_frac(__builtin_elementwise_abs(div)) * Y; 
-  vector condition = (div >= -div);
-  vector realResult = __builtin_hlsl_select(condition, result, -result);
-  return realResult;
+  vector ge = div >= -div;
+  vector frc = 
__builtin_hlsl_elementwise_frac(__builtin_elementwise_abs(div)); 
+  vector realFrc = __builtin_hlsl_select(ge, frc, -frc);
+  return realFrc * Y;
 #endif
 }
 
diff --git a/clang/test/CodeGenHLSL/builtins/fmod.hlsl 
b/clang/test/CodeGenHLSL/builtins/fmod.hlsl
index b62967114d456..22376638bd093 100644
--- a/clang/test/CodeGenHLSL/builtins/fmod.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/fmod.hlsl
@@ -36,42 +36,42 @@
 
 
 // CHECK: define [[FNATTRS]] [[TYPE]] @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn [[TYPE]]
-// CHECK: ret [[TYPE]] %fmod
+// CHECK: call reassoc nnan ninf nsz arcp afn [[FNATTRS]] [[TYPE]] 
@{{.*}}([[TYPE]] noundef nofpclass(nan inf) %{{.*}}, [[TYPE]] noundef 
nofpclass(nan inf) %{{.*}}) #{{.*}}
+// CHECK: ret [[TYPE]] %call
 half test_fmod_half(half p0, half p1) { return fmod(p0, p1); }
 
 // CHECK: define [[FNATTRS]] <2 x [[TYPE]]> @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]>
-// CHECK: ret <2 x [[TYPE]]> %fmod
+// CHECK: call reassoc nnan ninf nsz arcp afn [[FNATTRS]] [[TYPE]] @{{.*}}(<2 
x [[TYPE]]> noundef nofpclass(nan inf) %{{.*}}, <2 x [[TYPE]]> noundef 
nofpclass(nan inf) %{{.*}}) #{{.*}}
+// CHECK: ret <2 x [[TYPE]]> %splat.splat
 half2 test_fmod_half2(half2 p0, half2 p1) { return fmod(p0, p1); }
 
 // CHECK: define [[FNATTRS]] <3 x [[TYPE]]> @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn <3 x [[TYPE]]>
-// CHECK: ret <3 x [[TYPE]]> %fmod
+// CHECK: call reassoc nnan ninf nsz arcp afn [[FNATTRS]] [[TYPE]] @{{.*}}(<3 
x [[TYPE]]> noundef nofpclass(nan inf) %{{.*}}, <3 x [[TYPE]]> noundef 
nofpclass(nan inf) %{{.*}} #{{.*}}
+// CHECK: ret <3 x [[TYPE]]> %splat.splat
 half3 test_fmod_half3(half3 p0, half3 p1) { return fmod(p0, p1); }
 
 // CHECK: define [[FNATTRS]] <4 x [[TYPE]]> @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn <4 x [[TYPE]]>
-// CHECK: ret <4 x [[TYPE]]> %fmod
+// CHECK: call reassoc nnan ninf nsz arcp afn [[FNATTRS]] [[TYPE]] @{{.*}}(<4 
x [[TYPE]]> noundef nofpclass(nan inf) %{{.*}}, <4 x [[TYPE]]> noundef 
nofpclass(nan inf) %{{.*}}) #{{.*}}
+// CHECK: ret <4 x [[TYPE]]> %splat.splat
 half4 test_fmod_half4(half4 p0, half4 p1) { return fmod(p0, p1); }
 
 // CHECK: define [[FNATTRS]] float @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn float
-// CHECK: ret float %fmod
+// CHECK: call reassoc nnan ninf nsz arcp afn [[FNATTRS]] float @{{.*}}(float 
noundef nofpclass(nan inf) %{{.*}}, float noundef nofpclass(nan inf) %{{.*}}) 
#{{.*}}
+// CHECK: re

[clang] [HLSL] make semantic matching case insensitive (PR #129773)

2025-03-07 Thread Sarah Spall via cfe-commits

https://github.com/spall updated 
https://github.com/llvm/llvm-project/pull/129773

>From 6c2e22d2fa59f34401156ac6fd85c44730bf8c45 Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Tue, 4 Mar 2025 12:58:13 -0800
Subject: [PATCH 1/3] make semantics case insensitive. update tests. add new
 tests

---
 clang/include/clang/Basic/Attr.td |  8 ++---
 clang/lib/Parse/ParseHLSL.cpp |  2 ++
 clang/test/ParserHLSL/semantic_parsing.hlsl   |  2 +-
 clang/test/SemaHLSL/Semantics/groupindex.hlsl | 12 +++
 .../Semantics/invalid_entry_parameter.hlsl| 32 +--
 .../Semantics/valid_entry_parameter.hlsl  | 18 +++
 6 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 458747a1f7155..973e6a6015e98 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4724,21 +4724,21 @@ def HLSLNumThreads: InheritableAttr {
 }
 
 def HLSLSV_GroupThreadID: HLSLAnnotationAttr {
-  let Spellings = [HLSLAnnotation<"SV_GroupThreadID">];
+  let Spellings = [HLSLAnnotation<"sv_groupthreadid">];
   let Subjects = SubjectList<[ParmVar, Field]>;
   let LangOpts = [HLSL];
   let Documentation = [HLSLSV_GroupThreadIDDocs];
 }
 
 def HLSLSV_GroupID: HLSLAnnotationAttr {
-  let Spellings = [HLSLAnnotation<"SV_GroupID">];
+  let Spellings = [HLSLAnnotation<"sv_groupid">];
   let Subjects = SubjectList<[ParmVar, Field]>;
   let LangOpts = [HLSL];
   let Documentation = [HLSLSV_GroupIDDocs];
 }
 
 def HLSLSV_GroupIndex: HLSLAnnotationAttr {
-  let Spellings = [HLSLAnnotation<"SV_GroupIndex">];
+  let Spellings = [HLSLAnnotation<"sv_groupindex">];
   let Subjects = SubjectList<[ParmVar, GlobalVar]>;
   let LangOpts = [HLSL];
   let Documentation = [HLSLSV_GroupIndexDocs];
@@ -4790,7 +4790,7 @@ def HLSLPackOffset: HLSLAnnotationAttr {
 }
 
 def HLSLSV_DispatchThreadID: HLSLAnnotationAttr {
-  let Spellings = [HLSLAnnotation<"SV_DispatchThreadID">];
+  let Spellings = [HLSLAnnotation<"sv_dispatchthreadid">];
   let Subjects = SubjectList<[ParmVar, Field]>;
   let LangOpts = [HLSL];
   let Documentation = [HLSLSV_DispatchThreadIDDocs];
diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp
index f4c109f9a81a2..423b919ffbbee 100644
--- a/clang/lib/Parse/ParseHLSL.cpp
+++ b/clang/lib/Parse/ParseHLSL.cpp
@@ -141,6 +141,8 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs,
 return;
   }
 
+  II = PP.getIdentifierInfo(II->getName().lower());
+
   SourceLocation Loc = ConsumeToken();
   if (EndLoc)
 *EndLoc = Tok.getLocation();
diff --git a/clang/test/ParserHLSL/semantic_parsing.hlsl 
b/clang/test/ParserHLSL/semantic_parsing.hlsl
index 34df1805c5a95..0a921773c1d6f 100644
--- a/clang/test/ParserHLSL/semantic_parsing.hlsl
+++ b/clang/test/ParserHLSL/semantic_parsing.hlsl
@@ -3,5 +3,5 @@
 // expected-error@+1 {{expected HLSL Semantic identifier}}
 void Entry(int GI : ) { }
 
-// expected-error@+1 {{unknown HLSL semantic 'SV_IWantAPony'}}
+// expected-error@+1 {{unknown HLSL semantic 'sv_iwantapony'}}
 void Pony(int GI : SV_IWantAPony) { }
diff --git a/clang/test/SemaHLSL/Semantics/groupindex.hlsl 
b/clang/test/SemaHLSL/Semantics/groupindex.hlsl
index a33e060c82906..d5f28f066cc65 100644
--- a/clang/test/SemaHLSL/Semantics/groupindex.hlsl
+++ b/clang/test/SemaHLSL/Semantics/groupindex.hlsl
@@ -4,26 +4,26 @@
 [shader("compute")][numthreads(32,1,1)]
 void compute(int GI : SV_GroupIndex) {}
 
-// expected-error@+2 {{attribute 'SV_GroupIndex' is unsupported in 'pixel' 
shaders}}
+// expected-error@+2 {{attribute 'sv_groupindex' is unsupported in 'pixel' 
shaders}}
 [shader("pixel")]
 void pixel(int GI : SV_GroupIndex) {}
 
-// expected-error@+2 {{attribute 'SV_GroupIndex' is unsupported in 'vertex' 
shaders}}
+// expected-error@+2 {{attribute 'sv_groupindex' is unsupported in 'vertex' 
shaders}}
 [shader("vertex")]
 void vertex(int GI : SV_GroupIndex) {}
 
-// expected-error@+2 {{attribute 'SV_GroupIndex' is unsupported in 'geometry' 
shaders}}
+// expected-error@+2 {{attribute 'sv_groupindex' is unsupported in 'geometry' 
shaders}}
 [shader("geometry")]
 void geometry(int GI : SV_GroupIndex) {}
 
-// expected-error@+2 {{attribute 'SV_GroupIndex' is unsupported in 'domain' 
shaders}}
+// expected-error@+2 {{attribute 'sv_groupindex' is unsupported in 'domain' 
shaders}}
 [shader("domain")]
 void domain(int GI : SV_GroupIndex) {}
 
-// expected-error@+2 {{attribute 'SV_GroupIndex' is unsupported in 
'amplification' shaders}}
+// expected-error@+2 {{attribute 'sv_groupindex' is unsupported in 
'amplification' shaders}}
 [shader("amplification")][numthreads(32,1,1)]
 void amplification(int GI : SV_GroupIndex) {}
 
-// expected-error@+2 {{attribute 'SV_GroupIndex' is unsupported in 'mesh' 
shaders}}
+// expected-error@+2 {{attribute 'sv_groupindex' is unsupported in 'mesh' 
shaders}}
 [shader("mesh")][numthreads(32,1,1)]
 void mesh(int GI : SV_GroupIndex) {}
di

[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-03-07 Thread Jonas Paulsson via cfe-commits

JonPsson1 wrote:

> To clarify, the code is calling `__extendhfdf2` then `__truncdfhf2` from 
> either libgcc or from compiler-rt with your patches, and the compiler-rt 
> version is incorrect? Could you have it print the intermediate results as u16 
> hex (`Op0 + Op1`, `Res2`, `Res`)?

Yes, my test program is calling either libgcc or compiler-rt implementaions of 
the same function. Yes, on this branch.

```
  libgcccompiler-rt

vlreph  %v0, 0(%r1)   0x3e00 (1.5)  0x3e00
brasl   %r14, __extendhfdf2@PLT   0x3ff8
0x3fc0
ldr %f8, %f0
vlreph  %v0, 0(%r13)  0x3800 (0.5)  0x3800
brasl   %r14, __extendhfdf2@PLT   0x3fe0
0x3f00
ldr %f2, %f0
ldr %f0, %f8
brasl   %r14, fun2@PLT0x4000 (2.0)  
0x3fc00100
brasl   %r14, __truncdfhf2@PLT0x40000x3000
brasl   %r14, __extendhfsf2@PLT   0x40000x3e00

```

> Not sure if you are testing only on s390x but there should probably be a unit 
> test at 
> https://github.com/llvm/llvm-project/tree/d90423e310482bdbc731242fa25dcb3dd44e69de/compiler-rt/test/builtins/Unit
>  to see if things work on other platforms.

I am testing on s390x, and I guess it's unfortunate that there is no such test 
for hfdf - this is the file that was missing and that I added. I guess it 
should be added once it is confirmed to work properly (or if someone would 
provide the right values). The tests that are already there have been passing 
always while working on this, even when building with gcc.


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


[clang] [NFC] Add additional checks to test for vec_pack_to_short_fp32 (PR #130324)

2025-03-07 Thread Lei Huang via cfe-commits

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


[clang] 0ea5223 - [DXC] Add `-metal` flag to DXC driver (#130173)

2025-03-07 Thread via cfe-commits

Author: Chris B
Date: 2025-03-07T17:28:41-06:00
New Revision: 0ea52234fc3510463df2d8718404cede874e9b5e

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

LOG: [DXC] Add `-metal` flag to DXC driver (#130173)

This adds a flag to the DXC driver to enable calling the metal shader
converter if it is available to convert the final shader output for
metal.

Added: 
clang/test/Driver/HLSL/metal-converter.hlsl

Modified: 
clang/include/clang/Driver/Action.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/Action.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/HLSL.cpp
clang/lib/Driver/ToolChains/HLSL.h

Removed: 




diff  --git a/clang/include/clang/Driver/Action.h 
b/clang/include/clang/Driver/Action.h
index e5307b0fcedd5..92bb19314e3d6 100644
--- a/clang/include/clang/Driver/Action.h
+++ b/clang/include/clang/Driver/Action.h
@@ -75,9 +75,10 @@ class Action {
 LinkerWrapperJobClass,
 StaticLibJobClass,
 BinaryAnalyzeJobClass,
+BinaryTranslatorJobClass,
 
 JobClassFirst = PreprocessJobClass,
-JobClassLast = BinaryAnalyzeJobClass
+JobClassLast = BinaryTranslatorJobClass
   };
 
   // The offloading kind determines if this action is binded to a particular
@@ -675,6 +676,17 @@ class BinaryAnalyzeJobAction : public JobAction {
   }
 };
 
+class BinaryTranslatorJobAction : public JobAction {
+  void anchor() override;
+
+public:
+  BinaryTranslatorJobAction(Action *Input, types::ID Type);
+
+  static bool classof(const Action *A) {
+return A->getKind() == BinaryTranslatorJobClass;
+  }
+};
+
 } // namespace driver
 } // namespace clang
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d0414aba35209..6ed579cb88d90 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -9085,6 +9085,7 @@ def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, 
Group,
   HelpText<"Embed PDB in shader container (ignored)">;
 def spirv : DXCFlag<"spirv">,
   HelpText<"Generate SPIR-V code">;
+def metal : DXCFlag<"metal">, HelpText<"Generate Metal library">;
 def fspv_target_env_EQ : Joined<["-"], "fspv-target-env=">, Group,
   HelpText<"Specify the target environment">,
   Values<"vulkan1.2, vulkan1.3">;

diff  --git a/clang/lib/Driver/Action.cpp b/clang/lib/Driver/Action.cpp
index 0899b8ef00152..ec09726044812 100644
--- a/clang/lib/Driver/Action.cpp
+++ b/clang/lib/Driver/Action.cpp
@@ -50,6 +50,8 @@ const char *Action::getClassName(ActionClass AC) {
 return "static-lib-linker";
   case BinaryAnalyzeJobClass:
 return "binary-analyzer";
+  case BinaryTranslatorJobClass:
+return "binary-translator";
   }
 
   llvm_unreachable("invalid class");
@@ -459,3 +461,9 @@ void BinaryAnalyzeJobAction::anchor() {}
 
 BinaryAnalyzeJobAction::BinaryAnalyzeJobAction(Action *Input, types::ID Type)
 : JobAction(BinaryAnalyzeJobClass, Input, Type) {}
+
+void BinaryTranslatorJobAction::anchor() {}
+
+BinaryTranslatorJobAction::BinaryTranslatorJobAction(Action *Input,
+ types::ID Type)
+: JobAction(BinaryTranslatorJobClass, Input, Type) {}

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e998c94aeacd1..08ae8173db6df 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4669,6 +4669,16 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
   Actions.push_back(C.MakeAction(
   LastAction, types::TY_DX_CONTAINER));
 }
+if (Args.getLastArg(options::OPT_metal)) {
+  Action *LastAction = Actions.back();
+  // Metal shader converter runs on DXIL containers, which can either be
+  // validated (in which case they are TY_DX_CONTAINER), or unvalidated
+  // (TY_OBJECT).
+  if (LastAction->getType() == types::TY_DX_CONTAINER ||
+  LastAction->getType() == types::TY_Object)
+Actions.push_back(C.MakeAction(
+LastAction, types::TY_DX_CONTAINER));
+}
   }
 
   // Claim ignored clang-cl options.

diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 65acbe8a9dbea..fa810457a06cd 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -639,6 +639,7 @@ Tool *ToolChain::getTool(Action::ActionClass AC) const {
   case Action::DsymutilJobClass:
   case Action::VerifyDebugInfoJobClass:
   case Action::BinaryAnalyzeJobClass:
+  case Action::BinaryTranslatorJobClass:
 llvm_unreachable("Invalid tool kind.");
 
   case Action::CompileJobClass:

diff  --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index ad44c2cfcd811..62e4d14390b90 100644
--- a/clang/lib/Driv

[clang] 23a44b9 - [NFC] Add additional checks to test for vec_pack_to_short_fp32 (#130324)

2025-03-07 Thread via cfe-commits

Author: Lei Huang
Date: 2025-03-07T18:27:35-05:00
New Revision: 23a44b925a7599301c5ae92e03dc7e1067385961

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

LOG: [NFC] Add additional checks to test for vec_pack_to_short_fp32 (#130324)

Update test in prep for IR changes that will be introduced in
https://github.com/llvm/llvm-project/pull/129923

Added: 


Modified: 
clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c

Removed: 




diff  --git a/clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c
index b55a522ed2608..68d32ee14c8fa 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-p9vector.c
@@ -853,10 +853,16 @@ vector unsigned char test73(void) {
 vector unsigned short test74(void) {
 // CHECK-BE: @llvm.ppc.vsx.xvcvsphp(<4 x float>
 // CHECK-BE: @llvm.ppc.vsx.xvcvsphp(<4 x float>
-// CHECK-BE: @llvm.ppc.altivec.vperm
+// CHECK-BE: [[REG0:%[0-9]+]] = call <4 x i32> @llvm.ppc.altivec.vperm
+// CHECK-BE-NEXT: [[REG1:%[0-9]+]] = bitcast <4 x i32> [[REG0]] to <4 x float>
+// CHECK-BE-NEXT: [[REG2:%[0-9]+]] = bitcast <4 x float> [[REG1]] to <8 x i16>
+// CHECK-BE-NEXT: ret <8 x i16> [[REG2]]
 // CHECK: @llvm.ppc.vsx.xvcvsphp(<4 x float>
 // CHECK: @llvm.ppc.vsx.xvcvsphp(<4 x float>
-// CHECK: @llvm.ppc.altivec.vperm
+// CHECK: [[REG0:%[0-9]+]] = call <4 x i32> @llvm.ppc.altivec.vperm
+// CHECK-NEXT: [[REG1:%[0-9]+]] = bitcast <4 x i32> [[REG0]] to <4 x float>
+// CHECK-NEXT: [[REG2:%[0-9]+]] = bitcast <4 x float> [[REG1]] to <8 x i16>
+// CHECK-NEXT: ret <8 x i16> [[REG2]]
   return vec_pack_to_short_fp32(vfa, vfb);
 }
 vector unsigned int test75(void) {



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


[clang] [llvm] Add support for template as type parameter (PR #127654)

2025-03-07 Thread David Blaikie via cfe-commits

dwblaikie wrote:


> > Mostly I worry it won't be terribly complete, because it can't work through 
> > situations, like this:
> > ```
> > template
> > struct trait {
> >   using type = T;
> > };
> > template
> > struct other {
> >   trait::type v1;
> >   T v2;
> > };
> > ```
> > In this case, v2 can be described as being of type "T" referencing the 
> > template_type_parameter, but v1 can't be - because it references 
> > trait::type, for instance.
> 
> I believe, in this case, the debug information of "v2" can still be improved 
> and align with DWARF v5

Right - like I said, I get that "v2" gets better, but "v1" doesn't, right? And 
I imagine many/(most?) uses of type parameters in templates are more 
complicated - so I'm not sure how much this helps, and will feel awkwardly 
inconsistent for DWARF consumers/users?

> > Also, I'd worry that most debuggers/DWARF consumers aren't ready to handle 
> > type references to template_type_parameters? So best to test this with at 
> > least LLDB and GDB before we commit it.
> 
> While I acknowledge that current debuggers may not fully support this DWARF 
> representation, I suggest that this implementation be controlled by a switch 
> until downstream tools are updated to accommodate these changes.

Yeah - not sure it rises to the level of needing a flag (flags are a bit of an 
unfortunate maintenance burden - means more DWARF variety, harder to know 
everyone's doing the same thing, etc... ) - but some testing ahead of time 
would be good.

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


[clang] [DXC] Add `-metal` flag to DXC driver (PR #130173)

2025-03-07 Thread Chris B via cfe-commits

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


[clang-tools-extra] [clang-tidy] Switch misc-confusable-identifiers check to a faster algorithm. (PR #130369)

2025-03-07 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 1b75b9e665ee3c43de85c25f8d5f10d4efb3ca39 
870c0ea0c6dde2232ad63ec51f968007702cef90 --extensions h,cpp -- 
clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp 
clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.h 
clang-tools-extra/test/clang-tidy/checkers/misc/confusable-identifiers.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
index 70b948c078..85f7515cc8 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
@@ -93,7 +93,7 @@ struct Entry {
   const NamedDecl *ND;
   bool FromDerivedClass;
 };
-}
+} // namespace
 
 using DeclsWithinContextMap =
 llvm::DenseMap>;
@@ -158,7 +158,7 @@ void ConfusableIdentifierCheck::check(
 }
 
 void ConfusableIdentifierCheck::onEndOfTranslationUnit() {
-  llvm::StringMap> SkeletonToNames;
+  llvm::StringMap> 
SkeletonToNames;
   // Compute the skeleton for each identifier.
   for (auto &[Ident, Decls] : NameToDecls) {
 SkeletonToNames[skeleton(Ident->getName())].push_back(Ident);
@@ -209,7 +209,7 @@ void ConfusableIdentifierCheck::onEndOfTranslationUnit() {
   diag(Inner.ND->getLocation(), "%0 is confusable with %1")
   << Inner.ND << OuterND;
   diag(OuterND->getLocation(), "other declaration found here",
-DiagnosticIDs::Note);
+   DiagnosticIDs::Note);
 }
   }
 }

``




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


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

2025-03-07 Thread Congcong Cai via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


HerrCai0907 wrote:

I prefer to start from this patch. Because it is already here without 
additional effort.

Just like the incubator, when it has been tested by a certain number of users 
and is stable enough, then we can consider moving it to the ast-matcher.

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] Implement the `fmod` intrinsic (PR #130320)

2025-03-07 Thread Kaitlin Peng via cfe-commits


@@ -22,56 +22,144 @@
 //
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
 // RUN:   spirv-unknown-vulkan-compute %s -fnative-half-type \
-// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -emit-llvm -o - | FileCheck %s \
 // RUN:   -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=half
 
 //
 // -- No Native Half support test ---
 //
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
+// RUN:   spirv-unknown-vulkan-compute %s -emit-llvm \
 // RUN:   -o - | FileCheck %s \
 // RUN:   -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=float
 
 
 
+// DXCHECK: define [[FNATTRS]] [[TYPE]] @

kmpeng wrote:

Code updated with suggested changes.

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


[clang] [clang][bytecode] Implement __builtin_constant_p (PR #130143)

2025-03-07 Thread Timm Baeder via cfe-commits

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


[clang-tools-extra] [clang-tidy][misc-use-internal-linkage] fix false positives for function or variable in header file which contains macro expansion (PR #129594)

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

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


[clang-tools-extra] [clang-tidy][misc-use-internal-linkage] fix false positives for function or variable in header file which contains macro expansion (PR #129594)

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

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


[clang-tools-extra] 6f7570c - [clang-tidy][misc-use-internal-linkage] fix false positives for function or variable in header file which contains macro expansion (#129594)

2025-03-07 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-03-08T13:41:24+08:00
New Revision: 6f7570c200aa1ee9af9d1eb7a378d56264ee297e

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

LOG: [clang-tidy][misc-use-internal-linkage] fix false positives for function 
or variable in header file which contains macro expansion (#129594)

When check whether in main file, spelling loc will lead to ``. instead, expansion loc is close to loc after preprocess. It is
suitable to analyze linkage.

Added: 

clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-macro.hpp

Modified: 
clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index 4778182944abd..a1a20c0782230 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -52,7 +52,7 @@ AST_MATCHER(FunctionDecl, hasBody) { return Node.hasBody(); }
 static bool isInMainFile(SourceLocation L, SourceManager &SM,
  const FileExtensionsSet &HeaderFileExtensions) {
   for (;;) {
-if (utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions))
+if (utils::isExpansionLocInHeaderFile(L, SM, HeaderFileExtensions))
   return false;
 if (SM.isInMainFile(L))
   return true;

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ce1418a2a7d58..453617efaae26 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -129,6 +129,10 @@ Changes in existing checks
   ` check by providing additional
   examples and fixing some macro related false positives.
 
+- 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/unnecessary-value-param
   ` check performance by
   tolerating fix-it breaking compilation when functions is used as pointers 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-macro.hpp
 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-macro.hpp
new file mode 100644
index 0..209bd56028c3d
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-macro.hpp
@@ -0,0 +1,5 @@
+// RUN: %check_clang_tidy %s misc-use-internal-linkage %t -- -- 
-I%S/Inputs/use-internal-linkage
+
+#define B A##C
+
+inline void B() {}



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


[clang] [Clang] Force expressions with UO_Not to not be non-negative (PR #126846)

2025-03-07 Thread Yutong Zhu via cfe-commits

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

>From 106a982e3c6bcfa3ee7c26133f0919791699f31a Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sun, 23 Feb 2025 18:16:06 -0500
Subject: [PATCH 1/5] Fix signed-unsigned comparison with UO_Not and UO_Minus

---
 clang/docs/ReleaseNotes.rst |  3 +++
 clang/lib/Sema/SemaChecking.cpp | 18 ++
 clang/test/Sema/compare.c   |  8 
 3 files changed, 29 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 307edf77ebb58..03058205e61cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -204,6 +204,9 @@ Improvements to Clang's diagnostics
   as function arguments or return value respectively. Note that
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
+- The ``-Wsign-compare`` warning now treats expressions with bitwise not(~) 
and minus(-) as signed integers 
+  except for the case where the operand is an unsigned integer
+  and throws warning if they are compared with unsigned integers (##18878).
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f9926c6b4adab..4d5a318f7a01f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10619,6 +10619,24 @@ static std::optional 
TryGetExprRange(ASTContext &C, const Expr *E,
 case UO_AddrOf: // should be impossible
   return IntRange::forValueOfType(C, GetExprType(E));
 
+case UO_Minus:
+case UO_Not: {
+  if (E->getType()->isUnsignedIntegerType()) {
+return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, 
InConstantContext,
+   Approximate);
+  }
+
+  std::optional SubRange = TryGetExprRange(
+  C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
+
+  if (!SubRange)
+return std::nullopt;
+
+  // The width increments by 1 if the sub-expression cannot be negative
+  // since it now can be.
+  return IntRange(SubRange->Width + (int)SubRange->NonNegative, false);
+}
+
 default:
   return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, InConstantContext,
  Approximate);
diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c
index 17cf0351ef4f5..950793631c38c 100644
--- a/clang/test/Sema/compare.c
+++ b/clang/test/Sema/compare.c
@@ -419,3 +419,11 @@ void pr36008(enum PR36008EnumTest lhs) {
   if (x == y) x = y; // no warning
   if (y == x) y = x; // no warning
 }
+
+int test13(unsigned a, int b) {
+return a > ~(95 != b); // expected-warning {{comparison of integers of 
different signs}}
+}
+
+int test14(unsigned a, int b) {
+return a > -(95 != b); // expected-warning {{comparison of integers of 
different signs}}
+}

>From b8f947a4cc2795451d6c4f8912859e9ce20502dd Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sun, 2 Mar 2025 14:24:01 -0500
Subject: [PATCH 2/5] Add logic for UO_Minus

---
 clang/lib/Sema/SemaChecking.cpp | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 4d5a318f7a01f..082613ab07102 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10619,7 +10619,20 @@ static std::optional 
TryGetExprRange(ASTContext &C, const Expr *E,
 case UO_AddrOf: // should be impossible
   return IntRange::forValueOfType(C, GetExprType(E));
 
-case UO_Minus:
+case UO_Minus: {
+  if (E->getType()->isUnsignedIntegerType()) {
+return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, 
InConstantContext,
+   Approximate);
+  }
+
+  std::optional SubRange = TryGetExprRange(
+  C, UO->getSubExpr(), MaxWidth, InConstantContext, Approximate);
+
+  if (!SubRange)
+return std::nullopt;
+
+  return IntRange(SubRange->Width + 1, false);
+}
 case UO_Not: {
   if (E->getType()->isUnsignedIntegerType()) {
 return TryGetExprRange(C, UO->getSubExpr(), MaxWidth, 
InConstantContext,

>From 9f6897d8affa185eac0b4ef790870b06ae97d110 Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sun, 2 Mar 2025 14:24:01 -0500
Subject: [PATCH 3/5] Fix incorrect range for UO_Minus


>From b9081bbb6ba446a9158d5f6eebd9c442fbcf666b Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sun, 2 Mar 2025 20:27:19 -0500
Subject: [PATCH 4/5] Add additional test and comment

---
 clang/lib/Sema/SemaChecking.cpp |  5 +
 clang/test/Sema/compare.c   | 18 +-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 082613ab07102..84d4341e323d3 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/Sema

[clang] [clang] Reject constexpr-unknown values as constant expressions more consistently (PR #129952)

2025-03-07 Thread Timm Baeder via cfe-commits


@@ -154,3 +154,26 @@ int g() {
 static_assert(f(arr) == 5);
 }
 }
+
+namespace GH128409 {
+  int &ff();
+  int &x = ff(); // nointerpreter-note {{declared here}}
+  constinit int &z = x; // expected-error {{variable does not have a constant 
initializer}}
+// expected-note@-1 {{required by 'constinit' 
specifier here}}
+// nointerpreter-note@-2 {{initializer of 'x' is not a 
constant expression}}

tbaederr wrote:

https://godbolt.org/z/81M8aYGPn
Yeah, not a fan of any of this. But this patch LGTM.

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


[clang] [clang][bytecode] Implement __builtin_constant_p (PR #130143)

2025-03-07 Thread Timm Baeder via cfe-commits

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


[clang] [clang][bytecode] Loosen assertion This() for array elements (PR #130399)

2025-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

getRecord() returns null on array elements, even for composite arrays. The 
assertion here was overly restrictive and having an array element as instance 
pointer should be fine otherwise.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.h (+5-2) 
- (modified) clang/test/AST/ByteCode/placement-new.cpp (+24) 


``diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index d8f90e45b0ced..8a36db1cd84b4 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2431,9 +2431,12 @@ inline bool This(InterpState &S, CodePtr OpPC) {
   // Ensure the This pointer has been cast to the correct base.
   if (!This.isDummy()) {
 assert(isa(S.Current->getFunction()->getDecl()));
-assert(This.getRecord());
+[[maybe_unused]] const Record *R = This.getRecord();
+if (!R)
+  R = This.narrow().getRecord();
+assert(R);
 assert(
-This.getRecord()->getDecl() ==
+R->getDecl() ==
 cast(S.Current->getFunction()->getDecl())->getParent());
   }
 
diff --git a/clang/test/AST/ByteCode/placement-new.cpp 
b/clang/test/AST/ByteCode/placement-new.cpp
index 7a4fc89a27dac..c353162a7aab0 100644
--- a/clang/test/AST/ByteCode/placement-new.cpp
+++ b/clang/test/AST/ByteCode/placement-new.cpp
@@ -339,6 +339,30 @@ namespace PR48606 {
   static_assert(f());
 }
 
+/// This used to crash because of an assertion in the implementation
+/// of the This instruction.
+namespace ExplicitThisOnArrayElement {
+  struct S {
+int a = 12;
+constexpr S(int a) {
+  this->a = a;
+}
+  };
+
+  template 
+  constexpr void construct_at(_Tp *__location, _Args &&...__args) {
+new (__location) _Tp(__args...);
+  }
+
+  constexpr bool foo() {
+auto *M = std::allocator().allocate(13); // both-note {{allocation 
performed here was not deallocated}}
+construct_at(M, 12);
+return true;
+  }
+
+  static_assert(foo()); // both-error {{not an integral constant expression}}
+}
+
 #ifdef BYTECODE
 constexpr int N = [] // expected-error {{must be initialized by a constant 
expression}} \
  // expected-note {{assignment to dereferenced 
one-past-the-end pointer is not allowed in a constant expression}} \

``




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


[clang] [clang][bytecode] Implement __builtin_constant_p (PR #130143)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-bootstrap-msan` running on `sanitizer-buildbot6` while 
building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 86442 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90
FAIL: LLVM-Unit :: Support/./SupportTests/47/88 (82071 of 86442)
 TEST 'LLVM-Unit :: Support/./SupportTests/47/88' FAILED 

Script(shard):
--
GTEST_OUTPUT=json:/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/unittests/Support/./SupportTests-LLVM-Unit-2645672-47-88.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=88 GTEST_SHARD_INDEX=47 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/unittests/Support/./SupportTests
--

Script:
--
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/unittests/Support/./SupportTests
 --gtest_filter=Caching.WriteAfterCommit
--
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/unittests/Support/Caching.cpp:103:
 Failure
Value of: AddStream
  Actual: false
Expected: true


/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/unittests/Support/Caching.cpp:103
Value of: AddStream
  Actual: false
Expected: true




Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90
FAIL: LLVM-Unit :: Support/./SupportTests/48/88 (82078 of 86442)
 TEST 'LLVM-Unit :: Support/./SupportTests/48/88' FAILED 

Script(shard):
--
GTEST_OUTPUT=json:/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/unittests/Support/./SupportTests-LLVM-Unit-2645672-48-88.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=88 GTEST_SHARD_INDEX=48 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/unittests/Support/./SupportTests
--

Script:
--
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/unittests/Support/./SupportTests
 --gtest_filter=Caching.NoCommit
--
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/unittests/Support/Caching.cpp:149:
 Failure
Value of: llvm::detail::TakeError(CFS->commit())
Step 14 (stage3/msan check) failure: stage3/msan check (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_msan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:512:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm_build2_m

[clang] [clang][bytecode] Implement __builtin_constant_p (PR #130143)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-aarch64-sve2-vla-2stage` running on `linaro-g4-01` while building 
`clang` at step 12 "ninja check 2".

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


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

```
Step 12 (ninja check 2) failure: stage 2 checked (failure)
 TEST 'LLVM-Unit :: Support/./SupportTests/47/88' FAILED 

Script(shard):
--
GTEST_OUTPUT=json:/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla-2stage/stage2/unittests/Support/./SupportTests-LLVM-Unit-1723671-47-88.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=88 GTEST_SHARD_INDEX=47 
/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla-2stage/stage2/unittests/Support/./SupportTests
--

Script:
--
/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla-2stage/stage2/unittests/Support/./SupportTests
 --gtest_filter=Caching.WriteAfterCommit
--
/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla-2stage/llvm/llvm/unittests/Support/Caching.cpp:103:
 Failure
Value of: AddStream
  Actual: false
Expected: true


/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla-2stage/llvm/llvm/unittests/Support/Caching.cpp:103
Value of: AddStream
  Actual: false
Expected: true






```



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


[clang] [clang][bytecode] Loosen assertion This() for array elements (PR #130399)

2025-03-07 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/130399

getRecord() returns null on array elements, even for composite arrays. The 
assertion here was overly restrictive and having an array element as instance 
pointer should be fine otherwise.

>From a4327462a417aebd592dd5b25c2cceb2489286e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 8 Mar 2025 07:22:59 +0100
Subject: [PATCH] [clang][bytecode] Loosen assertion This() for array elements

getRecord() returns null on array elements, even for composite arrays.
The assertion here was overly restrictive and having an array element
as instance pointer should be fine otherwise.
---
 clang/lib/AST/ByteCode/Interp.h   |  7 +--
 clang/test/AST/ByteCode/placement-new.cpp | 24 +++
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index d8f90e45b0ced..8a36db1cd84b4 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2431,9 +2431,12 @@ inline bool This(InterpState &S, CodePtr OpPC) {
   // Ensure the This pointer has been cast to the correct base.
   if (!This.isDummy()) {
 assert(isa(S.Current->getFunction()->getDecl()));
-assert(This.getRecord());
+[[maybe_unused]] const Record *R = This.getRecord();
+if (!R)
+  R = This.narrow().getRecord();
+assert(R);
 assert(
-This.getRecord()->getDecl() ==
+R->getDecl() ==
 cast(S.Current->getFunction()->getDecl())->getParent());
   }
 
diff --git a/clang/test/AST/ByteCode/placement-new.cpp 
b/clang/test/AST/ByteCode/placement-new.cpp
index 7a4fc89a27dac..c353162a7aab0 100644
--- a/clang/test/AST/ByteCode/placement-new.cpp
+++ b/clang/test/AST/ByteCode/placement-new.cpp
@@ -339,6 +339,30 @@ namespace PR48606 {
   static_assert(f());
 }
 
+/// This used to crash because of an assertion in the implementation
+/// of the This instruction.
+namespace ExplicitThisOnArrayElement {
+  struct S {
+int a = 12;
+constexpr S(int a) {
+  this->a = a;
+}
+  };
+
+  template 
+  constexpr void construct_at(_Tp *__location, _Args &&...__args) {
+new (__location) _Tp(__args...);
+  }
+
+  constexpr bool foo() {
+auto *M = std::allocator().allocate(13); // both-note {{allocation 
performed here was not deallocated}}
+construct_at(M, 12);
+return true;
+  }
+
+  static_assert(foo()); // both-error {{not an integral constant expression}}
+}
+
 #ifdef BYTECODE
 constexpr int N = [] // expected-error {{must be initialized by a constant 
expression}} \
  // expected-note {{assignment to dereferenced 
one-past-the-end pointer is not allowed in a constant expression}} \

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


[clang] [alpha.webkit.webkit.RetainPtrCtorAdoptChecker] Add a new WebKit checker for correct use of RetainPtr, adoptNS, and adoptCF (PR #128679)

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

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

>From b4001f95cf6d35f59ef8af6df8f2bdbe043da380 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Tue, 25 Feb 2025 00:47:45 -0800
Subject: [PATCH 1/4] [alpha.webkit.webkit.RetainPtrCtorAdoptChecker] Add a new
 WebKit checker for correct use of RetainPtr, adoptNS, and adoptCF

Add a new WebKit checker to validate the correct use of RetainPtr constructor 
as well as adoptNS and adoptCF functions.
adoptNS and adoptCf are used for +1 semantics and RetainPtr constructor is used 
for +0 semantics.
---
 clang/docs/analyzer/checkers.rst  |  20 +
 .../clang/StaticAnalyzer/Checkers/Checkers.td |   4 +
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   1 +
 .../Checkers/WebKit/PtrTypesSemantics.cpp |   7 +-
 .../Checkers/WebKit/PtrTypesSemantics.h   |   3 +-
 .../WebKit/RetainPtrCtorAdoptChecker.cpp  | 347 ++
 .../Checkers/WebKit/objc-mock-types.h | 146 +++-
 .../WebKit/retain-ptr-ctor-adopt-use-arc.mm   |  85 +
 .../WebKit/retain-ptr-ctor-adopt-use.mm   |  85 +
 9 files changed, 680 insertions(+), 18 deletions(-)
 create mode 100644 
clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index c1eedb33e74d2..4cbd31f44d3f6 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3713,6 +3713,26 @@ Here are some examples of situations that we warn about 
as they *might* be poten
   NSObject* unretained = retained.get(); // warn
 }
 
+webkit.RetainPtrCtorAdoptChecker
+
+The goal of this rule is to make sure the constructor of RetinPtr as well as 
adoptNS and adoptCF are used correctly.
+When creating a RetainPtr with +1 semantics, adoptNS or adoptCF should be 
used, and in +0 semantics, RetainPtr constructor should be used.
+Warn otherwise.
+
+These are examples of cases that we consider correct:
+
+  .. code-block:: cpp
+
+RetainPtr ptr = adoptNS([[NSObject alloc] init]); // ok
+RetainPtr ptr = CGImageGetColorSpace(image); // ok
+
+Here are some examples of cases that we consider incorrect use of RetainPtr 
constructor and adoptCF
+
+  .. code-block:: cpp
+
+RetainPtr ptr = [[NSObject alloc] init]; // warn
+auto ptr = adoptCF(CGImageGetColorSpace(image)); // warn
+
 Debug Checkers
 ---
 
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 410f841630660..9aa696d8803b1 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1786,4 +1786,8 @@ def UnretainedLocalVarsChecker : 
Checker<"UnretainedLocalVarsChecker">,
   HelpText<"Check unretained local variables.">,
   Documentation;
 
+def RetainPtrCtorAdoptChecker : Checker<"RetainPtrCtorAdoptChecker">,
+  HelpText<"Check for correct use of RetainPtr constructor, adoptNS, and 
adoptCF">,
+  Documentation;
+
 } // end alpha.webkit
diff --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index 5910043440987..0b6b169d7b447 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -133,6 +133,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   WebKit/MemoryUnsafeCastChecker.cpp
   WebKit/PtrTypesSemantics.cpp
   WebKit/RefCntblBaseVirtualDtorChecker.cpp
+  WebKit/RetainPtrCtorAdoptChecker.cpp
   WebKit/RawPtrRefCallArgsChecker.cpp
   WebKit/UncountedLambdaCapturesChecker.cpp
   WebKit/RawPtrRefLocalVarsChecker.cpp
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 7899b19854806..7e7bd49ca0bdb 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -225,15 +225,16 @@ void RetainTypeChecker::visitTypedef(const TypedefDecl 
*TD) {
 return;
 
   for (auto *Redecl : RT->getDecl()->getMostRecentDecl()->redecls()) {
-if (Redecl->getAttr()) {
+if (Redecl->getAttr() ||
+Redecl->getAttr()) {
   CFPointees.insert(RT);
   return;
 }
   }
 }
 
-bool RetainTypeChecker::isUnretained(const QualType QT) {
-  if (ento::cocoa::isCocoaObjectRef(QT) && !IsARCEnabled)
+bool RetainTypeChecker::isUnretained(const QualType QT, bool ignoreARC) {
+  if (ento::cocoa::isCocoaObjectRef(QT) && (!IsARCEnabled || ignoreARC))
 return true;
   auto CanonicalType = QT.getCanonicalType();
   auto PointeeType = CanonicalType->getPointeeType();
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTyp

[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2025-03-07 Thread Alexander Richardson via cfe-commits

arichardson wrote:

> @arichardson as promised, I have rebased the changes. I'm not sure about the 
> test failures, it would seem to me that they are unlikely to be caused by 
> anything I did?

Yes it looks like an issue with the android CI setup, nothing related to this 
patch I believe.

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

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

AaronBallman wrote:

I am comfortable landing the changes ahead of acceptance at WG21 plenary so 
long as it's understood that if WG21 makes changes which break us, we'll 
implement those changes. And based on that, I think setting the feature test 
macro is fine.

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


[libunwind] [libunwind] Remove unnecessary dependencies on fprintf and stdio.h for increased baremetal friendliness (PR #72040)

2025-03-07 Thread Alexander Richardson via cfe-commits

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


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


[clang] Implement the `fmod` intrinsic (PR #130320)

2025-03-07 Thread Kaitlin Peng via cfe-commits

https://github.com/kmpeng created 
https://github.com/llvm/llvm-project/pull/130320

Replaced the current `fmod` definition with a templatized version, implemented 
`fmod` algorithm for DirectX targets that matches the DXC implementation, added 
corresponding tests in `clang/test/CodeGenHLSL/builtins/fmod.hlsl` and 
`clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl`.

>From bdb66b5a68090e304647ddbbeb403ac408fcea65 Mon Sep 17 00:00:00 2001
From: kmpeng 
Date: Tue, 25 Feb 2025 14:50:09 -0800
Subject: [PATCH 1/7] start implementation

---
 clang/lib/Headers/hlsl/hlsl_detail.h | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 39254a3cc3a0a..e7e910e30957e 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -97,6 +97,20 @@ constexpr vector reflect_vec_impl(vector I, 
vector N) {
 #endif
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+fmod_vec_impl(vector X, vector Y) {
+#if !defined(__DirectX__)
+  return __builtin_elementwise_fmod(X, Y);
+#else 
+  vector div = X / Y;
+  vector result = 
__builtin_hlsl_elementwise_frac(__builtin_elementwise_abs(div)) * Y; 
+  vector condition = (div >= -div);
+  vector realResult = __builtin_hlsl_select(condition, result, -result);
+  return realResult;
+#endif
+}
+
 } // namespace __detail
 } // namespace hlsl
 #endif //_HLSL_HLSL_DETAILS_H_

>From fe73beac17b99b0f7836ffdb7050e04595d96dba Mon Sep 17 00:00:00 2001
From: kmpeng 
Date: Wed, 26 Feb 2025 15:57:59 -0800
Subject: [PATCH 2/7] finished implementation, working on fmod.hlsl tests

---
 clang/lib/Headers/hlsl/hlsl_detail.h  | 14 +++---
 clang/test/CodeGenHLSL/builtins/fmod.hlsl | 32 +++
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index e7e910e30957e..bc2dd463e0404 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -97,6 +97,12 @@ constexpr vector reflect_vec_impl(vector I, 
vector N) {
 #endif
 }
 
+template 
+constexpr enable_if_t::value || is_same::value, T>
+fmod_impl(T X, T Y) {
+  return __builtin_elementwise_fmod(X, Y);
+}
+
 template 
 constexpr enable_if_t::value || is_same::value, T>
 fmod_vec_impl(vector X, vector Y) {
@@ -104,10 +110,10 @@ fmod_vec_impl(vector X, vector Y) {
   return __builtin_elementwise_fmod(X, Y);
 #else 
   vector div = X / Y;
-  vector result = 
__builtin_hlsl_elementwise_frac(__builtin_elementwise_abs(div)) * Y; 
-  vector condition = (div >= -div);
-  vector realResult = __builtin_hlsl_select(condition, result, -result);
-  return realResult;
+  vector ge = div >= -div;
+  vector frc = 
__builtin_hlsl_elementwise_frac(__builtin_elementwise_abs(div)); 
+  vector realFrc = __builtin_hlsl_select(ge, frc, -frc);
+  return realFrc * Y;
 #endif
 }
 
diff --git a/clang/test/CodeGenHLSL/builtins/fmod.hlsl 
b/clang/test/CodeGenHLSL/builtins/fmod.hlsl
index b62967114d456..22376638bd093 100644
--- a/clang/test/CodeGenHLSL/builtins/fmod.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/fmod.hlsl
@@ -36,42 +36,42 @@
 
 
 // CHECK: define [[FNATTRS]] [[TYPE]] @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn [[TYPE]]
-// CHECK: ret [[TYPE]] %fmod
+// CHECK: call reassoc nnan ninf nsz arcp afn [[FNATTRS]] [[TYPE]] 
@{{.*}}([[TYPE]] noundef nofpclass(nan inf) %{{.*}}, [[TYPE]] noundef 
nofpclass(nan inf) %{{.*}}) #{{.*}}
+// CHECK: ret [[TYPE]] %call
 half test_fmod_half(half p0, half p1) { return fmod(p0, p1); }
 
 // CHECK: define [[FNATTRS]] <2 x [[TYPE]]> @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]>
-// CHECK: ret <2 x [[TYPE]]> %fmod
+// CHECK: call reassoc nnan ninf nsz arcp afn [[FNATTRS]] [[TYPE]] @{{.*}}(<2 
x [[TYPE]]> noundef nofpclass(nan inf) %{{.*}}, <2 x [[TYPE]]> noundef 
nofpclass(nan inf) %{{.*}}) #{{.*}}
+// CHECK: ret <2 x [[TYPE]]> %splat.splat
 half2 test_fmod_half2(half2 p0, half2 p1) { return fmod(p0, p1); }
 
 // CHECK: define [[FNATTRS]] <3 x [[TYPE]]> @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn <3 x [[TYPE]]>
-// CHECK: ret <3 x [[TYPE]]> %fmod
+// CHECK: call reassoc nnan ninf nsz arcp afn [[FNATTRS]] [[TYPE]] @{{.*}}(<3 
x [[TYPE]]> noundef nofpclass(nan inf) %{{.*}}, <3 x [[TYPE]]> noundef 
nofpclass(nan inf) %{{.*}} #{{.*}}
+// CHECK: ret <3 x [[TYPE]]> %splat.splat
 half3 test_fmod_half3(half3 p0, half3 p1) { return fmod(p0, p1); }
 
 // CHECK: define [[FNATTRS]] <4 x [[TYPE]]> @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn <4 x [[TYPE]]>
-// CHECK: ret <4 x [[TYPE]]> %fmod
+// CHECK: call reassoc nnan ninf nsz arcp afn [[FNATTRS]] [[TYPE]] @{{.*}}(<4 
x [[TYPE]]> noundef nofpclass(nan inf) %{{.*}}, <4 x [[TYPE]]> noundef 
nofpclass(nan inf) %{{.*}}) #{{.*}}
+// CHECK: ret <4 x [[TYPE]]> %splat.splat
 half4 test_fmod_half4(half4 p0, half4 p1) { return fmod(p0, p1); }
 
 // CHECK: define [[FNA

[libunwind] [libunwind][RISCV] Make asm statement volatile (PR #130286)

2025-03-07 Thread Alexander Richardson via cfe-commits

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


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


[clang] [C2y] Implement WG14 N3409 (PR #130299)

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


@@ -10425,8 +10425,13 @@ def warn_type_safety_null_pointer_required : Warning<
   "specified %0 type tag requires a null pointer">, InGroup;
 
 // Generic selections.
-def err_assoc_type_incomplete : Error<
-  "type %0 in generic association incomplete">;
+def ext_assoc_type_incomplete : Extension<
+  "ISO C requires a complete type in a '_Generic' association; %0 is an "
+  "incomplete type">;

AaronBallman wrote:

Sure, I can change that!

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


[clang] Implement the `fmod` intrinsic (PR #130320)

2025-03-07 Thread Kaitlin Peng via cfe-commits


@@ -22,56 +22,144 @@
 //
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
 // RUN:   spirv-unknown-vulkan-compute %s -fnative-half-type \
-// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -emit-llvm -o - | FileCheck %s \
 // RUN:   -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=half
 
 //
 // -- No Native Half support test ---
 //
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
+// RUN:   spirv-unknown-vulkan-compute %s -emit-llvm \
 // RUN:   -o - | FileCheck %s \
 // RUN:   -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=float
 
 
 
+// DXCHECK: define [[FNATTRS]] [[TYPE]] @
+// DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn [[TYPE]]

kmpeng wrote:

@Icohedron Would you recommend running the DirectX tests with -O1 then if we 
want to check the operands? Currently the dependent instructions are not 
necessarily receiving the same operands/outputs from the instructions they 
depend on (e.g. `%fneg.i` depends on `%div1.i`, but `%div1.i` becomes `%7` and 
then `%7` is passed to `%fneg.i` instead). Running with -O1 solves this, but it 
also optimizes away the first `fneg` instruction I check for.

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


[clang] [HLSL] make semantic matching case insensitive (PR #129773)

2025-03-07 Thread via cfe-commits

https://github.com/joaosaffran commented:

nit: is there a way to check that the spelling is consistent in the error 
messages? Asking since I am no familiar with this part of the code.

https://github.com/llvm/llvm-project/pull/129773
___
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 bugprone-capture-this-by-field (PR #130297)

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


@@ -0,0 +1,99 @@
+//===--- CaptureThisByFieldCheck.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 "CaptureThisByFieldCheck.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, correctHandleCaptureThisLambda) {
+  // unresolved
+  if (Node.needsOverloadResolutionForCopyConstructor() &&
+  Node.needsImplicitCopyConstructor())
+return false;
+  if (Node.needsOverloadResolutionForMoveConstructor() &&
+  Node.needsImplicitMoveConstructor())
+return false;
+  if (Node.needsOverloadResolutionForCopyAssignment() &&
+  Node.needsImplicitCopyAssignment())
+return false;
+  if (Node.needsOverloadResolutionForMoveAssignment() &&
+  Node.needsImplicitMoveAssignment())
+return false;
+  // default but not deleted
+  if (Node.hasSimpleCopyConstructor())
+return false;
+  if (Node.hasSimpleMoveConstructor())
+return false;
+  if (Node.hasSimpleCopyAssignment())
+return false;
+  if (Node.hasSimpleMoveAssignment())
+return false;
+
+  for (CXXConstructorDecl const *C : Node.ctors()) {
+if (C->isCopyOrMoveConstructor() && C->isDefaulted() && !C->isDeleted())
+  return false;
+  }
+  for (CXXMethodDecl const *M : Node.methods()) {
+if (M->isCopyAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
+  return false;
+if (M->isMoveAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
+  return false;
+  }
+  // FIXME: find ways to identifier correct handle capture this lambda
+  return true;
+}
+
+} // namespace
+
+void CaptureThisByFieldCheck::registerMatchers(MatchFinder *Finder) {
+  auto IsStdFunctionField =
+  fieldDecl(hasType(cxxRecordDecl(hasName("::std::function"
+  .bind("field");
+  auto CaptureThis = lambdaCapture(anyOf(
+  // [this]
+  capturesThis(),
+  // [self = this]
+  capturesVar(varDecl(hasInitializer(cxxThisExpr());
+  auto IsInitWithLambda = cxxConstructExpr(hasArgument(
+  0,
+  lambdaExpr(hasAnyCapture(CaptureThis.bind("capture"))).bind("lambda")));
+  Finder->addMatcher(
+  cxxRecordDecl(
+  has(cxxConstructorDecl(
+  unless(isCopyConstructor()), unless(isMoveConstructor()),
+  hasAnyConstructorInitializer(cxxCtorInitializer(
+  isMemberInitializer(), forField(IsStdFunctionField),
+  withInitializer(IsInitWithLambda),
+  unless(correctHandleCaptureThisLambda())),
+  this);
+}
+
+void CaptureThisByFieldCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Capture = Result.Nodes.getNodeAs("capture");
+  const auto *Lambda = Result.Nodes.getNodeAs("lambda");
+  const auto *Field = Result.Nodes.getNodeAs("field");
+  diag(Lambda->getBeginLoc(),
+   "using lambda expressions to capture this and storing it in class "

vbvictor wrote:

```suggestion
   "using lambda expressions to capture 'this' and storing it in class "
```
Consider using ticks for language constructs

https://github.com/llvm/llvm-project/pull/130297
___
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-07 Thread Jan Voung via cfe-commits

https://github.com/jvoung created 
https://github.com/llvm/llvm-project/pull/130346

None

>From 10df1857532a6a27b0e5286e10c9f0724d6d7e1d Mon Sep 17 00:00:00 2001
From: Jan Voung 
Date: Fri, 7 Mar 2025 21:02:16 +
Subject: [PATCH] [clang-format] Add support for absl nullability macros

---
 clang/lib/Format/Format.cpp|  4 
 clang/unittests/Format/ConfigParseTest.cpp |  4 +++-
 clang/unittests/Format/FormatTest.cpp  | 19 +--
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index b5f1241321891..1401b51586d03 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1508,6 +1508,10 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
   LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
   LLVMStyle.AttributeMacros.push_back("__capability");
+  // Abseil aliases to clang's `_Nonnull`, `_Nullable` and `_Null_unspecified`.
+  LLVMStyle.AttributeMacros.push_back("absl_nonnull");
+  LLVMStyle.AttributeMacros.push_back("absl_nullable");
+  LLVMStyle.AttributeMacros.push_back("absl_nullability_unknown");
   LLVMStyle.BinPackArguments = true;
   LLVMStyle.BinPackLongBracedList = true;
   LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 273bab87b1ee1..2cc2a45a7a590 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -908,7 +908,9 @@ TEST(ConfigParseTest, ParsesConfiguration) {
 
   Style.AttributeMacros.clear();
   CHECK_PARSE("BasedOnStyle: LLVM", AttributeMacros,
-  std::vector{"__capability"});
+  std::vector({"__capability", "absl_nonnull", 
"absl_nullable",
+"absl_nullability_unknown"}));
+  Style.AttributeMacros.clear();
   CHECK_PARSE("AttributeMacros: [attr1, attr2]", AttributeMacros,
   std::vector({"attr1", "attr2"}));
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index bd335f4b6a21b..a17cad0b67b08 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12375,6 +12375,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("vector v;");
   verifyFormat("vector v;");
   verifyFormat("vector v;");
+  verifyFormat("vector v;");
+  verifyFormat("vector v;");
+  verifyFormat("vector v;");
   verifyFormat("vector v;");
   verifyFormat("vector v;");
   verifyFormat("vector v;");
@@ -12518,6 +12521,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("MACRO(A *_Nonnull a);");
   verifyIndependentOfContext("MACRO(A *_Nullable a);");
   verifyIndependentOfContext("MACRO(A *_Null_unspecified a);");
+  verifyIndependentOfContext("MACRO(A *absl_nonnull a);");
+  verifyIndependentOfContext("MACRO(A *absl_nullable a);");
+  verifyIndependentOfContext("MACRO(A *absl_nullability_unknown a);");
   verifyIndependentOfContext("MACRO(A *__attribute__((foo)) a);");
   verifyIndependentOfContext("MACRO(A *__attribute((foo)) a);");
   verifyIndependentOfContext("MACRO(A *[[clang::attr]] a);");
@@ -12674,6 +12680,12 @@ TEST_F(FormatTest, UnderstandsAttributes) {
   verifyFormat("SomeType *__unused s{InitValue};", CustomAttrs);
   verifyFormat("SomeType s __unused(InitValue);", CustomAttrs);
   verifyFormat("SomeType s __unused{InitValue};", CustomAttrs);
+  verifyFormat("SomeType *absl_nonnull s(InitValue);", CustomAttrs);
+  verifyFormat("SomeType *absl_nonnull s{InitValue};", CustomAttrs);
+  verifyFormat("SomeType *absl_nullable s(InitValue);", CustomAttrs);
+  verifyFormat("SomeType *absl_nullable s{InitValue};", CustomAttrs);
+  verifyFormat("SomeType *absl_nullability_unknown s(InitValue);", 
CustomAttrs);
+  verifyFormat("SomeType *absl_nullability_unknown s{InitValue};", 
CustomAttrs);
   verifyFormat("SomeType *__capability s(InitValue);", CustomAttrs);
   verifyFormat("SomeType *__capability s{InitValue};", CustomAttrs);
 }
@@ -12687,7 +12699,9 @@ TEST_F(FormatTest, UnderstandsPointerQualifiersInCast) {
   verifyFormat("x = (foo *_Nonnull)*v;");
   verifyFormat("x = (foo *_Nullable)*v;");
   verifyFormat("x = (foo *_Null_unspecified)*v;");
-  verifyFormat("x = (foo *_Nonnull)*v;");
+  verifyFormat("x = (foo *absl_nonnull)*v;");
+  verifyFormat("x = (foo *absl_nullable)*v;");
+  verifyFormat("x = (foo *absl_nullability_unknown)*v;");
   verifyFormat("x = (foo *[[clang::attr]])*v;");
   verifyFormat("x = (foo *[[clang::attr(\"foo\")]])*v;");
   verifyFormat("x = (foo *__ptr32)*v;");
@@ -12701,7 +12715,8 @@ TEST_F(FormatTest, UnderstandsPointerQualifiersInCast) {
   LongPointerLeft.PointerAlignment = FormatStyle::PAS_Left;
   StringRef AllQualifiers =
   "const volatile restrict __attribute__((foo)) _Nonnull _Null_unspecified 
"
-

[clang] [alpha.webkit.UncountedCallArgsChecker] Recognize CXXUnresolvedConstructExpr as a safe origin. (PR #130258)

2025-03-07 Thread Rashmi Mudduluru via cfe-commits

https://github.com/t-rasmud approved this pull request.

LGTM!

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


[clang] [CIR] Disable gcc partially overloaded virtual warning (PR #130322)

2025-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Andy Kaylor (andykaylor)


Changes

GCC, unlike clang, issues a warning when one virtual function is overridden in 
a derived class but one or more other virtual functions with the same name and 
different signature from a base class are not overridden. This leads to many 
warnings in the MLIR and ClangIR code when using the 
OpenConversionPattern<>::matchAndRewrite() function in the ordinary way. 
The "hiding" behavior is what we want, so we're just disabling the warning here.

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


2 Files Affected:

- (modified) clang/lib/CIR/CMakeLists.txt (+11) 
- (modified) clang/tools/cir-opt/CMakeLists.txt (+11) 


``diff
diff --git a/clang/lib/CIR/CMakeLists.txt b/clang/lib/CIR/CMakeLists.txt
index 4a99ecb33dfb2..7bdf3fcc59035 100644
--- a/clang/lib/CIR/CMakeLists.txt
+++ b/clang/lib/CIR/CMakeLists.txt
@@ -1,6 +1,17 @@
 include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
 include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
 
+# GCC, unlike clang, issues a warning when one virtual function is overridden
+# in a derived class but one or more other virtual functions with the same
+# name and different signature from a base class are not overridden. This
+# leads to many warnings in the MLIR and ClangIR code when using the
+# OpenConversionPattern<>::matchAndRewrite() function in the ordinary way.
+# The "hiding" behavior is what we want, so we're just disabling the warning
+# here.
+if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND (NOT "${CMAKE_CXX_COMPILER_ID}" 
MATCHES "Clang"))
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual")
+endif()
+
 add_subdirectory(Dialect)
 add_subdirectory(CodeGen)
 add_subdirectory(FrontendAction)
diff --git a/clang/tools/cir-opt/CMakeLists.txt 
b/clang/tools/cir-opt/CMakeLists.txt
index 75bec5f4e1b0b..ca7ee44f6fd75 100644
--- a/clang/tools/cir-opt/CMakeLists.txt
+++ b/clang/tools/cir-opt/CMakeLists.txt
@@ -4,6 +4,17 @@ get_property(conversion_libs GLOBAL PROPERTY 
MLIR_CONVERSION_LIBS)
 include_directories(${LLVM_MAIN_SRC_DIR}/../mlir/include)
 include_directories(${CMAKE_BINARY_DIR}/tools/mlir/include)
 
+# GCC, unlike clang, issues a warning when one virtual function is overridden
+# in a derived class but one or more other virtual functions with the same
+# name and different signature from a base class are not overridden. This
+# leads to many warnings in the MLIR and ClangIR code when using the
+# OpenConversionPattern<>::matchAndRewrite() function in the ordinary way.
+# The "hiding" behavior is what we want, so we're just disabling the warning
+# here.
+if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND (NOT "${CMAKE_CXX_COMPILER_ID}" 
MATCHES "Clang"))
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual")
+endif()
+
 add_clang_tool(cir-opt
   cir-opt.cpp
 )

``




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


[clang] [Clang] use constant evaluation context for constexpr if conditions (PR #123667)

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

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

>From 00b8b64879ad3ae35a0a671da563ac876ffaf228 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 20 Jan 2025 22:51:00 +0200
Subject: [PATCH 1/5] [Clang] use constant evaluation context for constexpr if
 conditions

---
 clang/docs/ReleaseNotes.rst |  2 +-
 clang/lib/Parse/ParseExprCXX.cpp|  6 ++
 clang/test/SemaCXX/constexpr-if.cpp | 10 ++
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/constexpr-if.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f6d5c346021d6..cd16ce13a4e6b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -963,7 +963,7 @@ Bug Fixes to C++ Support
 - Fixed a crash caused by the incorrect construction of template arguments for 
CTAD alias guides when type
   constraints are applied. (#GH122134)
 - Fixed canonicalization of pack indexing types - Clang did not always 
recognized identical pack indexing. (#GH123033)
-
+- Clang now permits the use of immediate-escalating expressions in 
``constexpr`` if conditions. (#GH123524)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 33a90e0cb8a42..e174d9a24e744 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,6 +2203,12 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
+EnterExpressionEvaluationContext Eval(
+Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+/*LambdaContextDecl=*/nullptr,
+/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
new file mode 100644
index 0..1832086fee42d
--- /dev/null
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++26 -verify %s
+
+// expected-no-diagnostics
+
+namespace GH123524 {
+consteval void fn1() {}
+void fn2() {
+  if constexpr (&fn1 != nullptr) { }
+}
+}

>From df6fd0c3f762d5fb76bdf98c6425a79ef01f4d7e Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 21 Jan 2025 10:27:57 +0200
Subject: [PATCH 2/5] update tests to verify changes from c++20

---
 clang/test/SemaCXX/constexpr-if.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/test/SemaCXX/constexpr-if.cpp 
b/clang/test/SemaCXX/constexpr-if.cpp
index 1832086fee42d..494fc45c55c4e 100644
--- a/clang/test/SemaCXX/constexpr-if.cpp
+++ b/clang/test/SemaCXX/constexpr-if.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -std=c++26 -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
+// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
+// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s
 
 // expected-no-diagnostics
 

>From bba89e7dc79d4d78a794ccf0e7e5196a22b72820 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:35:54 +0200
Subject: [PATCH 3/5] ensure context is applied only during expression parsing

---
 clang/lib/Parse/ParseExprCXX.cpp | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index e174d9a24e744..5d5e015d548f5 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2203,14 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, 
SourceLocation Loc,
   return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
 }
 
-EnterExpressionEvaluationContext Eval(
-Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
-/*LambdaContextDecl=*/nullptr,
-/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
-/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
-
-// Parse the expression.
-ExprResult Expr = ParseExpression(); // expression
+ExprResult Expr;
+{
+  EnterExpressionEvaluationContext Eval(
+  Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
+  /*LambdaContextDecl=*/nullptr,
+  /*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
+  /*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);
+
+  // Parse the expression.
+  Expr = ParseExpression(); // expression
+}
+
 if (Expr.isInvalid())
   return Sema::ConditionError();
 

>From 666d5bf9574fb583f9da27331545c861eed66488 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 20 Feb 2025 00:36:11 +0200
Subject: [PATCH 4/5] update release notes

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(

[clang] [alpha.webkit.UncountedCallArgsChecker] Recognize CXXUnresolvedConstructExpr as a safe origin. (PR #130258)

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

rniwa wrote:

Thanks for the review!

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


[clang] c419acd - [alpha.webkit.UncountedCallArgsChecker] Recognize CXXUnresolvedConstructExpr as a safe origin. (#130258)

2025-03-07 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2025-03-07T14:40:33-08:00
New Revision: c419acdf82d3b33cf151f78865469cf155ddf372

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

LOG: [alpha.webkit.UncountedCallArgsChecker] Recognize 
CXXUnresolvedConstructExpr as a safe origin. (#130258)

Handle CXXUnresolvedConstructExpr in tryToFindPtrOrigin so that
constructing Ref, RefPtr, CheckedRef, CheckedPtr, ... constructed in
such a way that its type is unresolved at AST level will be still
treated as a safe pointer origin.

Also fix a bug in isPtrOfType that it was not recognizing
DeducedTemplateSpecializationType.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/test/Analysis/Checkers/WebKit/call-args.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 58020ec4e084d..c8151e932997e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -43,6 +43,10 @@ bool tryToFindPtrOrigin(
 break;
   }
 }
+if (auto *TempExpr = dyn_cast(E)) {
+  if (isSafePtrType(TempExpr->getTypeAsWritten()))
+return callback(TempExpr, true);
+}
 if (auto *POE = dyn_cast(E)) {
   if (auto *RF = POE->getResultExpr()) {
 E = RF;

diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 7899b19854806..8a304a07296fc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -162,13 +162,14 @@ static bool isPtrOfType(const clang::QualType T, 
Predicate Pred) {
   type = elaboratedT->desugar();
   continue;
 }
-auto *SpecialT = type->getAs();
-if (!SpecialT)
-  return false;
-auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
-if (!Decl)
-  return false;
-return Pred(Decl->getNameAsString());
+if (auto *SpecialT = type->getAs()) {
+  auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
+  return Decl && Pred(Decl->getNameAsString());
+} else if (auto *DTS = type->getAs()) {
+  auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
+  return Decl && Pred(Decl->getNameAsString());
+} else
+  break;
   }
   return false;
 }

diff  --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index b4613d5090f29..e7afd9798da3e 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -359,6 +359,41 @@ namespace call_with_ptr_on_ref {
   }
 }
 
+namespace call_with_explicit_construct_from_auto {
+
+  struct Impl {
+void ref() const;
+void deref() const;
+
+static Ref create();
+  };
+
+  template 
+  struct ArgObj {
+T* t;
+  };
+
+  struct Object {
+Object();
+Object(Ref&&);
+
+Impl* impl() const { return m_impl.get(); }
+
+static Object create(ArgObj&) { return Impl::create(); }
+static void bar(Impl&);
+
+  private:
+RefPtr m_impl;
+  };
+
+  template void foo()
+  {
+  auto result = Object::create(ArgObj { });
+  Object::bar(Ref { *result.impl() });
+  }
+
+}
+
 namespace call_with_explicit_temporary_obj {
   void foo() {
 Ref { *provide() }->method();



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


[clang] clang: Enable linker-wrapper test on windows (PR #130248)

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

arsenm wrote:

Replaced by #130285

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


[clang] 0ea02e7 - [C2y] Claim nonconformance to WG14 N3410

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

Author: Aaron Ballman
Date: 2025-03-07T15:15:53-05:00
New Revision: 0ea02e77218d8aee37bc1a7c776caeeff468dc39

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

LOG: [C2y] Claim nonconformance to WG14 N3410

This paper made it a constraint violation for the same identifier
within a TU to have both internal and external linkage. It was
previously UB.

Clang does not correctly diagnose the constraint in some cases,
documented in the added test case.

Added: 
clang/test/C/C2y/n3410.c

Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/test/C/C2y/n3410.c b/clang/test/C/C2y/n3410.c
new file mode 100644
index 0..e1cb41f375b82
--- /dev/null
+++ b/clang/test/C/C2y/n3410.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -Wno-unused %s
+
+/* WG14 N3410: No
+ * Slay Some Earthly Demons XI
+ *
+ * It is now ill-formed for the same identifier within a TU to have both
+ * internal and external linkage.
+ */
+
+void func1() {
+  extern int a; // #a
+}
+
+// This 'a' is the same as the one declared extern above.
+static int a; /* expected-error {{static declaration of 'a' follows non-static 
declaration}}
+ expected-note@#a {{previous declaration is here}}
+   */
+
+static int b;
+void func2() {
+  // This 'b' is the same as the one declaraed static above, but this is not
+  // ill-formed because of C2y 6.2.2p4, which gives this variable internal
+  // linkage because the previous declaration had internal linkage.
+  extern int b; // Ok
+}
+
+static int c, d;
+void func3() {
+  int c; // no linkage, 
diff erent object from the one declared above.
+  for (int d;;) {
+// This 'c' is the same as the one declared at file scope, but because of
+// the local scope 'c', the file scope 'c' is not visible.
+// FIXME: This should be diagnosed under N3410.
+extern int c;
+// This 'd' is the same as the one declared at file scope as well, but
+// because of the 'd' declared within the for loop, the file scope 'd' is
+// also not visible, same as with 'c'.
+// FIXME: This should be diagnosed under N3410.
+extern int d;
+  }
+  for (static int e;;) {
+extern int e; // Ok for the same reason as 'b' above.
+  }
+}
+

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index f9dc3a48654c7..1850bd2093e0c 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -289,7 +289,7 @@ C2y implementation status
 
   Slay Some Earthly Demons XI
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3410.pdf";>N3410
-  Unknown
+  No

 
   Slay Some Earthly Demons XII



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


[clang] [HLSL] select scalar overloads for vector conditions (PR #129396)

2025-03-07 Thread Chris B via cfe-commits

https://github.com/llvm-beanz updated 
https://github.com/llvm/llvm-project/pull/129396

>From 7620f9fac9932a13f1da0468b02c1aeceb212a0b Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Wed, 19 Feb 2025 17:18:20 -0600
Subject: [PATCH 1/3] [HLSL] select scalar overloads for vector conditions

This PR adds scalar/vector overloads for vector conditions to the
`select` builtin, and updates the sema checking and codegen to allow
scalars to extend to vectors.

Fixes #126570

clang-format
clang-format
'cbieneman/select' on '44f0fe9a2806'.
---
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  8 ++
 .../lib/Headers/hlsl/hlsl_alias_intrinsics.h  | 36 +++
 clang/lib/Headers/hlsl/hlsl_detail.h  |  5 +
 clang/lib/Sema/SemaHLSL.cpp   | 56 ++-
 clang/test/CodeGenHLSL/builtins/select.hlsl   | 29 ++
 .../test/SemaHLSL/BuiltIns/select-errors.hlsl | 98 +--
 7 files changed, 135 insertions(+), 100 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 21be7c358a61d..2514fb68bf5b0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12707,6 +12707,9 @@ def err_hlsl_param_qualifier_mismatch :
 def err_hlsl_vector_compound_assignment_truncation : Error<
   "left hand operand of type %0 to compound assignment cannot be truncated "
   "when used with right hand operand of type %1">;
+def err_hlsl_builtin_scalar_vector_mismatch : Error<
+  "%select{all|second and third}0 arguments to %1 must be of scalar or "
+  "vector type with matching scalar element type%diff{: $ vs $|}2,3">;
 
 def warn_hlsl_impcast_vector_truncation : Warning<
   "implicit conversion truncates vector: %0 to %1">, InGroup;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b86bb242755be..ba78de049ce96 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19836,6 +19836,14 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
 RValFalse.isScalar()
 ? RValFalse.getScalarVal()
 : RValFalse.getAggregatePointer(E->getArg(2)->getType(), *this);
+if (auto *VTy = E->getType()->getAs()) {
+  if (!OpTrue->getType()->isVectorTy())
+OpTrue =
+Builder.CreateVectorSplat(VTy->getNumElements(), OpTrue, "splat");
+  if (!OpFalse->getType()->isVectorTy())
+OpFalse =
+Builder.CreateVectorSplat(VTy->getNumElements(), OpFalse, "splat");
+}
 
 Value *SelectVal =
 Builder.CreateSelect(OpCond, OpTrue, OpFalse, "hlsl.select");
diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
index 7573f6e024167..7a550a58e705c 100644
--- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
@@ -2123,6 +2123,42 @@ template 
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
 vector select(vector, vector, vector);
 
+
+/// \fn vector select(vector Conds, T TrueVal,
+/// vector FalseVals)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVal The scalar value to splat from when conditions are true.
+/// \param FalseVals The vector values are chosen from when conditions are
+/// false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+vector select(vector, T, vector);
+
+/// \fn vector select(vector Conds, vector TrueVals,
+/// T FalseVal)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVals The vector values are chosen from when conditions are true.
+/// \param FalseVal The scalar value to splat from when conditions are false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+vector select(vector, vector, T);
+
+/// \fn vector select(vector Conds, vector TrueVals,
+/// T FalseVal)
+/// \brief ternary operator for vectors. All vectors must be the same size.
+/// \param Conds The Condition input values.
+/// \param TrueVal The scalar value to splat from when conditions are true.
+/// \param FalseVal The scalar value to splat from when conditions are false.
+
+template 
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
+__detail::enable_if_t<__detail::is_arithmetic::Value, vector> select(
+vector, T, T);
+
 
//===--===//
 // sin builtins
 
//===--===//
diff --git a/clang/lib/Headers/hlsl/hlsl_detail.h 
b/clang/lib/Headers/hlsl/hlsl_detail.h
index 39254a3cc3a0a..086c527614a43 100644
--- a/clang/lib/Headers/hlsl/hlsl_detail.h
+++ b/clang/lib/Headers/hlsl/hlsl_detail.h
@@ -97,6 +97,11 @@ constexpr

[clang] [clang-format] Remove special handling of C++ access specifiers in C (PR #129983)

2025-03-07 Thread via cfe-commits

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


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


[clang] [llvm] [Clang][LLVM] Implement single-multi vectors MOP4{A/S} (PR #128854)

2025-03-07 Thread Virginia Cangelosi via cfe-commits

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Recognize CXXUnresolvedConstructExpr as a safe origin. (PR #130258)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang` at step 6 "test-openmp".

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


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

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp   -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang] [Clang] Check for uninitialized use in lambda within CXXOperatorCallExpr (PR #129198)

2025-03-07 Thread Shafik Yaghmour via cfe-commits


@@ -892,6 +892,11 @@ namespace lambdas {
   return a1.x;
 });
 A a2([&] { return a2.x; }); // ok
+A a3([=] { return a3.x; }()); // expected-warning{{variable 'a3' is 
uninitialized when used within its own initialization}}

shafik wrote:

Do we now also catch this case: https://godbolt.org/z/bnYEqhqY9

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


[clang] clang/HIP: Use regex for final path separator in hip-partial-link, again (PR #130371)

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

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


[clang] clang/HIP: Use regex for final path separator in hip-partial-link, again (PR #130371)

2025-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Matt Arsenault (arsenm)


Changes

Follow up to c6b9d5ce76a155b682b1562122f43166aaa6391d in another instance.
This is still failing in unrelated PR prechecks, but passing its own check.

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


1 Files Affected:

- (modified) clang/test/Driver/hip-partial-link.hip (+5-5) 


``diff
diff --git a/clang/test/Driver/hip-partial-link.hip 
b/clang/test/Driver/hip-partial-link.hip
index 5c538556a5070..d1a57bbe1d75c 100644
--- a/clang/test/Driver/hip-partial-link.hip
+++ b/clang/test/Driver/hip-partial-link.hip
@@ -32,11 +32,11 @@
 // LD-R: Found undefined HIP fatbin symbol: __hip_fatbin_[[ID2:[0-9a-f]+]]
 // LD-R: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID1]]
 // LD-R: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID2]]
-// LD-R: "{{.*}}/clang-offload-bundler" {{.*}}-unbundle
-// LD-R: "{{.*}}/lld" -flavor gnu -m elf64_amdgpu
-// LD-R: "{{.*}}/clang-offload-bundler"
-// LD-R: "{{.*}}/clang{{.*}}" -target x86_64-unknown-linux-gnu
-// LD-R: "{{.*}}/ld.lld" {{.*}} -r
+// LD-R: "{{.*[/\\]}}clang-offload-bundler" {{.*}}-unbundle
+// LD-R: "{{.*[/\\]}}lld" -flavor gnu -m elf64_amdgpu
+// LD-R: "{{.*[/\\]}}clang-offload-bundler"
+// LD-R: "{{.*[/\\]}}clang{{.*}}" -target x86_64-unknown-linux-gnu
+// LD-R: "{{.*[/\\]}}ld.lld" {{.*}} -r
 
 // RUN: llvm-nm  %t.lib.o | FileCheck -check-prefix=OBJ %s
 // OBJ:  B __hip_cuid_[[ID1:[0-9a-f]+]]

``




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


[clang] clang/HIP: Use regex for final path separator in hip-partial-link, again (PR #130371)

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

arsenm wrote:

* **#130371** https://app.graphite.dev/github/pr/llvm/llvm-project/130371?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/130371?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[clang] [compiler-rt] [llvm] [SystemZ] Add support for half (fp16) (PR #109164)

2025-03-07 Thread Trevor Gross via cfe-commits

tgross35 wrote:

Nothing about the implementation stands out to me as wrong. It looks like the 
exponent isn't correct, I guess you could step through this portion 
https://github.com/llvm/llvm-project/blob/ae42f071032b29821beef6a337712580861c/compiler-rt/lib/builtins/fp_extend_impl.inc#L65-L66
 and double check the intermediate values? Our implementation is doing 
something similar except it adds in place rather than shifting back and forth, 
but I don't know why that would make a difference 
https://github.com/rust-lang/compiler-builtins/blob/7bec089672eb5cd83d7902edd59479527bc9d8d1/src/float/extend.rs#L42-L45.

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


[clang] [llvm] Use global TimerGroups for both new pass manager and old pass manager timers (PR #130375)

2025-03-07 Thread Alan Zhao via cfe-commits

https://github.com/alanzhao1 created 
https://github.com/llvm/llvm-project/pull/130375

Additionally, remove the behavior for both pass manager's timer manager classes 
(`PassTimingInfo` for the old pass manager and `TimePassesHandler` for the new 
pass manager) where these classes would print the values of their timers upon 
destruction.

Currently, each pass manager manages their own `TimerGroup`s. This is 
problematic because of duplicate `TimerGroup`s (both pass managers have a 
`TimerGroup` for pass times with identical names and descriptions). The result 
is that in Clang, `-ftime-report` has two "Pass execution timing report" 
sections (one for the new pass manager which manages optimization passes, and 
one for the old pass manager which manages the backend). The result of this 
change is that Clang's `-ftime-report` now prints both optimization and backend 
pass timing info in a unified "Pass execution timing report" section.

Moving the ownership of the `TimerGroups` to globals also  makes it easier to 
implement JSON-formatted `-ftime-report`. This was not possible with the old 
structure because the two pass managers were created and destroyed in far parts 
of the codebase and outputting JSON requires the printing logic to be at the 
same place because of formatting.

Previous discourse discussion: 
https://discourse.llvm.org/t/difficulties-with-implementing-json-formatted-ftime-report/84353

>From b2b4d522a442867aa65655cac1a0ece02616252b Mon Sep 17 00:00:00 2001
From: Alan Zhao 
Date: Mon, 24 Feb 2025 11:10:04 -0800
Subject: [PATCH] Use global TimerGroups for both new pass manager and old pass
 manager timers

Additionally, remove the behavior for both pass manager's timer manager
classes (`PassTimingInfo` for the old pass manager and
`TimePassesHandler` for the new pass manager) where these classes would
print the values of their timers upon destruction.

Currently, each pass manager manages their own `TimerGroup`s. This is
problematic because of duplicate `TimerGroup`s (both pass managers have
a `TimerGroup` for pass times with identical names and descriptions).
The result is that in Clang, `-ftime-report` has two "Pass execution
timing report" sections (one for the new pass manager which manages
optimization passes, and one for the old pass manager which manages the
backend). The result of this change is that Clang's `-ftime-report` now
prints both optimization and backend pass timing info in a unified "Pass
execution timing report" section.

Moving the ownership of the `TimerGroups` to globals also  makes it
easier to implement JSON-formatted `-ftime-report`. This was not
possible with the old structure because the two pass managers were
created and destroyed in far parts of the codebase and outputting JSON
requires the printing logic to be at the same place because of
formatting.

Previous discourse discussion: 
https://discourse.llvm.org/t/difficulties-with-implementing-json-formatted-ftime-report/84353
---
 clang/test/Misc/time-passes.c |  1 -
 llvm/include/llvm/IR/PassTimingInfo.h | 12 ++
 llvm/include/llvm/Support/Timer.h | 11 +
 llvm/lib/IR/PassTimingInfo.cpp| 60 +--
 llvm/lib/Support/Timer.cpp| 42 +++
 llvm/unittests/IR/TimePassesTest.cpp  |  4 +-
 6 files changed, 79 insertions(+), 51 deletions(-)

diff --git a/clang/test/Misc/time-passes.c b/clang/test/Misc/time-passes.c
index 395da216aad42..c1669826b2268 100644
--- a/clang/test/Misc/time-passes.c
+++ b/clang/test/Misc/time-passes.c
@@ -19,6 +19,5 @@
 // NPM:   InstCombinePass{{$}}
 // NPM-NOT:   InstCombinePass #
 // TIME: Total{{$}}
-// NPM: Pass execution timing report
 
 int foo(int x, int y) { return x + y; }
diff --git a/llvm/include/llvm/IR/PassTimingInfo.h 
b/llvm/include/llvm/IR/PassTimingInfo.h
index 1148399943186..13947f7405245 100644
--- a/llvm/include/llvm/IR/PassTimingInfo.h
+++ b/llvm/include/llvm/IR/PassTimingInfo.h
@@ -39,19 +39,14 @@ Timer *getPassTimer(Pass *);
 /// This class implements -time-passes functionality for new pass manager.
 /// It provides the pass-instrumentation callbacks that measure the pass
 /// execution time. They collect timing info into individual timers as
-/// passes are being run. At the end of its life-time it prints the resulting
-/// timing report.
+/// passes are being run.
 class TimePassesHandler {
   /// Value of this type is capable of uniquely identifying pass invocations.
   /// It is a pair of string Pass-Identifier (which for now is common
   /// to all the instance of a given pass) + sequential invocation counter.
   using PassInvocationID = std::pair;
 
-  /// Groups of timers for passes and analyses.
-  TimerGroup PassTG;
-  TimerGroup AnalysisTG;
-
-  using TimerVector = llvm::SmallVector, 4>;
+  using TimerVector = llvm::SmallVector;
   /// Map of timers for pass invocations
   StringMap TimingData;
 
@@ -74,8 +69,7 @@ class TimePassesHandler {
   TimePassesHandler();
   TimePassesHandle

[clang] [llvm] Use global TimerGroups for both new pass manager and old pass manager timers (PR #130375)

2025-03-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alan Zhao (alanzhao1)


Changes

Additionally, remove the behavior for both pass manager's timer manager classes 
(`PassTimingInfo` for the old pass manager and `TimePassesHandler` for the new 
pass manager) where these classes would print the values of their timers upon 
destruction.

Currently, each pass manager manages their own `TimerGroup`s. This is 
problematic because of duplicate `TimerGroup`s (both pass managers have a 
`TimerGroup` for pass times with identical names and descriptions). The result 
is that in Clang, `-ftime-report` has two "Pass execution timing report" 
sections (one for the new pass manager which manages optimization passes, and 
one for the old pass manager which manages the backend). The result of this 
change is that Clang's `-ftime-report` now prints both optimization and backend 
pass timing info in a unified "Pass execution timing report" section.

Moving the ownership of the `TimerGroups` to globals also  makes it easier to 
implement JSON-formatted `-ftime-report`. This was not possible with the old 
structure because the two pass managers were created and destroyed in far parts 
of the codebase and outputting JSON requires the printing logic to be at the 
same place because of formatting.

Previous discourse discussion: 
https://discourse.llvm.org/t/difficulties-with-implementing-json-formatted-ftime-report/84353

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


6 Files Affected:

- (modified) clang/test/Misc/time-passes.c (-1) 
- (modified) llvm/include/llvm/IR/PassTimingInfo.h (+3-9) 
- (modified) llvm/include/llvm/Support/Timer.h (+11) 
- (modified) llvm/lib/IR/PassTimingInfo.cpp (+30-30) 
- (modified) llvm/lib/Support/Timer.cpp (+33-9) 
- (modified) llvm/unittests/IR/TimePassesTest.cpp (+2-2) 


``diff
diff --git a/clang/test/Misc/time-passes.c b/clang/test/Misc/time-passes.c
index 395da216aad42..c1669826b2268 100644
--- a/clang/test/Misc/time-passes.c
+++ b/clang/test/Misc/time-passes.c
@@ -19,6 +19,5 @@
 // NPM:   InstCombinePass{{$}}
 // NPM-NOT:   InstCombinePass #
 // TIME: Total{{$}}
-// NPM: Pass execution timing report
 
 int foo(int x, int y) { return x + y; }
diff --git a/llvm/include/llvm/IR/PassTimingInfo.h 
b/llvm/include/llvm/IR/PassTimingInfo.h
index 1148399943186..13947f7405245 100644
--- a/llvm/include/llvm/IR/PassTimingInfo.h
+++ b/llvm/include/llvm/IR/PassTimingInfo.h
@@ -39,19 +39,14 @@ Timer *getPassTimer(Pass *);
 /// This class implements -time-passes functionality for new pass manager.
 /// It provides the pass-instrumentation callbacks that measure the pass
 /// execution time. They collect timing info into individual timers as
-/// passes are being run. At the end of its life-time it prints the resulting
-/// timing report.
+/// passes are being run.
 class TimePassesHandler {
   /// Value of this type is capable of uniquely identifying pass invocations.
   /// It is a pair of string Pass-Identifier (which for now is common
   /// to all the instance of a given pass) + sequential invocation counter.
   using PassInvocationID = std::pair;
 
-  /// Groups of timers for passes and analyses.
-  TimerGroup PassTG;
-  TimerGroup AnalysisTG;
-
-  using TimerVector = llvm::SmallVector, 4>;
+  using TimerVector = llvm::SmallVector;
   /// Map of timers for pass invocations
   StringMap TimingData;
 
@@ -74,8 +69,7 @@ class TimePassesHandler {
   TimePassesHandler();
   TimePassesHandler(bool Enabled, bool PerRun = false);
 
-  /// Destructor handles the print action if it has not been handled before.
-  ~TimePassesHandler() { print(); }
+  ~TimePassesHandler() = default;
 
   /// Prints out timing information and then resets the timers.
   void print();
diff --git a/llvm/include/llvm/Support/Timer.h 
b/llvm/include/llvm/Support/Timer.h
index abe30451dd2f2..3e115df1500fe 100644
--- a/llvm/include/llvm/Support/Timer.h
+++ b/llvm/include/llvm/Support/Timer.h
@@ -169,6 +169,17 @@ struct NamedRegionTimer : public TimeRegion {
   explicit NamedRegionTimer(StringRef Name, StringRef Description,
 StringRef GroupName,
 StringRef GroupDescription, bool Enabled = true);
+
+  // Create or get a timer stored in the same global map as other timers owned
+  // by NamedRegionTimer.
+  static Timer &getNamedGroupTimer(StringRef Name, StringRef Description,
+   StringRef GroupName,
+   StringRef GroupDescription);
+
+  // Create or get a TimerGroup stored in the same global map owned by
+  // NamedRegionTimer.
+  static TimerGroup &getNamedGroupTimerGroup(StringRef GroupName,
+ StringRef GroupDescription);
 };
 
 /// The TimerGroup class is used to group together related timers into a single
diff --git a/llvm/lib/IR/PassTimingInfo.cpp b/llvm/lib/IR/PassTimingInfo.cpp
index 46db2c74a5c76..0d133be890ce2 100644
--- a/llv

[clang] Implement the `fmod` intrinsic (PR #130320)

2025-03-07 Thread Deric C. via cfe-commits


@@ -22,56 +22,136 @@
 //
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
 // RUN:   spirv-unknown-vulkan-compute %s -fnative-half-type \
-// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
-// RUN:   -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=half
+// RUN:   -emit-llvm -o - | FileCheck %s \
+// RUN:   -DTYPE=half --check-prefixes=CHECK,SPVCHECK
 
 //
 // -- No Native Half support test ---
 //
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \
+// RUN:   spirv-unknown-vulkan-compute %s -emit-llvm \
 // RUN:   -o - | FileCheck %s \
-// RUN:   -DFNATTRS="spir_func noundef nofpclass(nan inf)" -DTYPE=float
+// RUN:   -DTYPE=float --check-prefixes=CHECK,SPVCHECK
 
 
 
-// CHECK: define [[FNATTRS]] [[TYPE]] @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn [[TYPE]]
-// CHECK: ret [[TYPE]] %fmod
+// CHECK-LABEL: test_fmod_half
+// DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn [[TYPE]] [[X:%.*]], 
[[Y:%.*]]
+// DXCHECK: %fneg.i = fneg reassoc nnan ninf nsz arcp afn [[TYPE]] 
[[DIV1_I:%.*]]
+// DXCHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn oge [[TYPE]] 
[[DIV1_I_2:%.*]], %fneg.i
+// DXNATIVE_HALF: %elt.abs.i = call reassoc nnan ninf nsz arcp afn [[TYPE]] 
@llvm.fabs.f16([[TYPE]] [[DIV1_I_3:%.*]])
+// DXNO_HALF: %elt.abs.i = call reassoc nnan ninf nsz arcp afn [[TYPE]] 
@llvm.fabs.f32([[TYPE]] [[DIV1_I_3:%.*]])
+// DXNATIVE_HALF: %hlsl.frac.i = call reassoc nnan ninf nsz arcp afn [[TYPE]] 
@llvm.dx.frac.f16([[TYPE]] %elt.abs.i)
+// DXNO_HALF: %hlsl.frac.i = call reassoc nnan ninf nsz arcp afn [[TYPE]] 
@llvm.dx.frac.f32([[TYPE]] %elt.abs.i)
+// DXCHECK: %fneg2.i = fneg reassoc nnan ninf nsz arcp afn [[TYPE]] 
[[HLSL_FRAC_I:%.*]]
+// DXCHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn i1 
[[CMP_I:%.*]], [[TYPE]] [[HLSL_FRAC_I_2:%.*]], [[TYPE]] %fneg2.i
+// DXCHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn [[TYPE]] 
%hlsl.select.i, [[Y_2:%.*]]
+// DXCHECK: ret [[TYPE]] %mul.i
+// SPVCHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn [[TYPE]] [[X:%.*]], 
[[Y:%.*]]
+// SPVCHECK: ret [[TYPE]] %fmod.i
 half test_fmod_half(half p0, half p1) { return fmod(p0, p1); }
 
-// CHECK: define [[FNATTRS]] <2 x [[TYPE]]> @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]>
-// CHECK: ret <2 x [[TYPE]]> %fmod
+// CHECK-LABEL: test_fmod_half2
+// DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]> 
[[X:%.*]], [[Y:%.*]]
+// DXCHECK: %fneg.i = fneg reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]> 
[[DIV1_I:%.*]]
+// DXCHECK: %cmp.i = fcmp reassoc nnan ninf nsz arcp afn oge <2 x [[TYPE]]> 
[[DIV1_I_2:%.*]], %fneg.i
+// DXNATIVE_HALF: %elt.abs.i = call reassoc nnan ninf nsz arcp afn <2 x 
[[TYPE]]> @llvm.fabs.v2f16(<2 x [[TYPE]]> [[DIV1_I_3:%.*]])
+// DXNO_HALF: %elt.abs.i = call reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]> 
@llvm.fabs.v2f32(<2 x [[TYPE]]> [[DIV1_I_3:%.*]])
+// DXNATIVE_HALF: %hlsl.frac.i = call reassoc nnan ninf nsz arcp afn <2 x 
[[TYPE]]> @llvm.dx.frac.v2f16(<2 x [[TYPE]]> %elt.abs.i)
+// DXNO_HALF: %hlsl.frac.i = call reassoc nnan ninf nsz arcp afn <2 x 
[[TYPE]]> @llvm.dx.frac.v2f32(<2 x [[TYPE]]> %elt.abs.i)
+// DXCHECK: %fneg2.i = fneg reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]> 
[[HLSL_FRAC_I:%.*]]
+// DXCHECK: %hlsl.select.i = select reassoc nnan ninf nsz arcp afn <2 x i1> 
[[CMP_I:%.*]], <2 x [[TYPE]]> [[HLSL_FRAC_I_2:%.*]], <2 x [[TYPE]]> %fneg2.i
+// DXCHECK: %mul.i = fmul reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]> 
%hlsl.select.i, [[Y_2:%.*]]
+// DXCHECK: ret <2 x [[TYPE]]> %mul.i
+// SPVCHECK: %fmod.i = frem reassoc nnan ninf nsz arcp afn <2 x [[TYPE]]> 
[[X:%.*]], [[Y:%.*]]
+// SPVCHECK: ret <2 x [[TYPE]]> %fmod.i
 half2 test_fmod_half2(half2 p0, half2 p1) { return fmod(p0, p1); }
 
-// CHECK: define [[FNATTRS]] <3 x [[TYPE]]> @
-// CHECK: %fmod = frem reassoc nnan ninf nsz arcp afn <3 x [[TYPE]]>
-// CHECK: ret <3 x [[TYPE]]> %fmod
+// CHECK-LABEL: test_fmod_half3
+// DXCHECK: %div1.i = fdiv reassoc nnan ninf nsz arcp afn <3 x [[TYPE]]> 
[[X:%.*]], [[Y:%.*]]
+// DXCHECK: %fneg.i = fneg reassoc nnan ninf nsz arcp afn <3 x [[TYPE]]> 
[[DIV1_I:%.*]]

Icohedron wrote:

I would also add the instructions that are producing `[[DIV1_I_2:%.*]]` and 
`[[DIV1_I_3:%.*]]`, so that we can see where they are coming from.

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


[clang] [WebAssembly] Rename functions in wasm-eh.cpp (PR #130220)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-win` 
running on `sie-win-worker` while building `clang` at step 7 
"test-build-unified-tree-check-all".

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


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

```
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'LLVM-Unit :: Support/./SupportTests.exe/6/44' FAILED 

Script(shard):
--
GTEST_OUTPUT=json:Z:\b\llvm-clang-x86_64-sie-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-22196-6-44.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=44 GTEST_SHARD_INDEX=6 
Z:\b\llvm-clang-x86_64-sie-win\build\unittests\Support\.\SupportTests.exe
--

Script:
--
Z:\b\llvm-clang-x86_64-sie-win\build\unittests\Support\.\SupportTests.exe 
--gtest_filter=Caching.NoCommit
--
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\Support\Caching.cpp(142):
 error: Value of: AddStream
  Actual: false
Expected: true


Z:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\unittests\Support\Caching.cpp:142
Value of: AddStream
  Actual: false
Expected: true






```



https://github.com/llvm/llvm-project/pull/130220
___
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 bugprone-capture-this-by-field (PR #130297)

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

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

>From 8ef214f6c78d710dbd9c74b06c7c637baf93e527 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 8 Mar 2025 00:03:39 +0800
Subject: [PATCH 1/2] [clang-tidy] Add new check bugprone-capture-this-by-field

---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../bugprone/CaptureThisByFieldCheck.cpp  |  99 +
 .../bugprone/CaptureThisByFieldCheck.h|  39 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../checks/bugprone/capture-this-by-field.rst |  28 
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../bugprone/capture-this-by-field.cpp| 133 ++
 8 files changed, 310 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/capture-this-by-field.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/capture-this-by-field.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 0a3376949b6e5..ee9fa5ef06c7a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -16,6 +16,7 @@
 #include "BitwisePointerCastCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
+#include "CaptureThisByFieldCheck.h"
 #include "CastingThroughVoidCheck.h"
 #include "ChainedComparisonCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
@@ -118,6 +119,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "bugprone-bool-pointer-implicit-conversion");
 CheckFactories.registerCheck("bugprone-branch-clone");
+CheckFactories.registerCheck(
+"bugprone-capture-this-by-field");
 CheckFactories.registerCheck(
 "bugprone-casting-through-void");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index dab139b77c770..4d1d50c4ea2a0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -12,6 +12,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   BoolPointerImplicitConversionCheck.cpp
   BranchCloneCheck.cpp
   BugproneTidyModule.cpp
+  CaptureThisByFieldCheck.cpp
   CastingThroughVoidCheck.cpp
   ChainedComparisonCheck.cpp
   ComparePointerToMemberVirtualFunctionCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.cpp
new file mode 100644
index 0..1f0f68acf335f
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.cpp
@@ -0,0 +1,99 @@
+//===--- CaptureThisByFieldCheck.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 "CaptureThisByFieldCheck.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, correctHandleCaptureThisLambda) {
+  // unresolved
+  if (Node.needsOverloadResolutionForCopyConstructor() &&
+  Node.needsImplicitCopyConstructor())
+return false;
+  if (Node.needsOverloadResolutionForMoveConstructor() &&
+  Node.needsImplicitMoveConstructor())
+return false;
+  if (Node.needsOverloadResolutionForCopyAssignment() &&
+  Node.needsImplicitCopyAssignment())
+return false;
+  if (Node.needsOverloadResolutionForMoveAssignment() &&
+  Node.needsImplicitMoveAssignment())
+return false;
+  // default but not deleted
+  if (Node.hasSimpleCopyConstructor())
+return false;
+  if (Node.hasSimpleMoveConstructor())
+return false;
+  if (Node.hasSimpleCopyAssignment())
+return false;
+  if (Node.hasSimpleMoveAssignment())
+return false;
+
+  for (CXXConstructorDecl const *C : Node.ctors()) {
+if (C->isCopyOrMoveConstructor() && C->isDefaulted() && !C->isDeleted())
+  return false;
+  }
+  for (CXXMethodDecl const *M : Node.methods()) {
+if (M->isCopyAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
+  return false;
+if (M->isMoveAssignmentOperator() && M->isDefaulted() && !M->isDel

[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)

2025-03-07 Thread Akira Hatanaka via cfe-commits


@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -verify 
-fptrauth-intrinsics -std=c++11 %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify 
-fptrauth-intrinsics -std=c++11 %s
+
+template  struct G {
+  T __ptrauth(0,0,1234) test;
+  // expected-error@-1 2 {{type '__ptrauth(0,0,1234) T' is already 
__ptrauth-qualified}}
+};
+
+template  struct Indirect {
+  G layers;
+  // expected-note@-1{{in instantiation of template class 'G' requested here}}
+  // expected-note@-2{{in instantiation of template class 'G' requested here}}
+};
+
+void f3() {
+  Indirect one;
+  // expected-note@-1{{in instantiation of template class 'Indirect' requested here}}
+  Indirect two;
+  // expected-note@-1{{in instantiation of template class 'Indirect' requested here}}
+  Indirect three;
+}

ahatanak wrote:

This isn't possible as template parameters cannot be passed to `__ptrauth` and 
`__ptrauth` can't be used on function parameters.

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


[clang] [ARM] mtp = auto using hard point while arch supports thumb2 and hardtp (PR #130027)

2025-03-07 Thread via cfe-commits

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


[clang] [ARM] mtp = auto using hard point while arch supports thumb2 and hardtp (PR #130027)

2025-03-07 Thread via cfe-commits

Zhenhang1213 wrote:

> @Zhenhang1213 : Code looks ok. Are all edge cases covered by the lit test now?
> 
> Could you please adjust the commit message to reflect the actual changes?

OK, I add more tests to cover, thx!

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


[clang] [ARM] mtp = auto using hard point while arch supports thumb2 and hardtp (PR #130027)

2025-03-07 Thread via cfe-commits

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


[clang] [ARM] Using cp15 while mtp =auto and arch is arm_arch6k and support thumb2 (PR #130027)

2025-03-07 Thread via cfe-commits

https://github.com/Zhenhang1213 updated 
https://github.com/llvm/llvm-project/pull/130027

>From b7c6a38f913f5e83e9a72e0b81607de01a8a1b01 Mon Sep 17 00:00:00 2001
From: Austin 
Date: Thu, 6 Mar 2025 17:25:55 +0800
Subject: [PATCH] [ARM] mtp = auto using hard point while arch supports thumb2
 and hardtp

mtp = auto using hard point while arch supports thumb2 and hardtp

Reference: https://reviews.llvm.org/D114116
---
 clang/lib/Driver/ToolChains/Arch/ARM.cpp | 24 +--
 clang/test/Driver/arm-thread-pointer.c   | 52 
 2 files changed, 65 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 51454de1b9dcc..e50cb3836f2c9 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -202,13 +202,25 @@ bool arm::useAAPCSForMachO(const llvm::Triple &T) {
  T.getOS() == llvm::Triple::UnknownOS || isARMMProfile(T);
 }
 
-// We follow GCC and support when the backend has support for the MRC/MCR
+// Check whether the architecture backend has support for the MRC/MCR
 // instructions that are used to set the hard thread pointer ("CP15 C13
 // Thread id").
+// This is not identical to ability to use the instruction, as the ARMV6K
+// variants can only use it in Arm mode since they don't support Thumb2
+// encoding.
 bool arm::isHardTPSupported(const llvm::Triple &Triple) {
   int Ver = getARMSubArchVersionNumber(Triple);
   llvm::ARM::ArchKind AK = llvm::ARM::parseArch(Triple.getArchName());
-  return Triple.isARM() || AK == llvm::ARM::ArchKind::ARMV6T2 ||
+  return AK == llvm::ARM::ArchKind::ARMV6K ||
+ AK == llvm::ARM::ArchKind::ARMV6KZ ||
+ (Ver >= 7 && !isARMMProfile(Triple));
+}
+
+// Checks whether the architecture is capable of supporting the Thumb2 encoding
+static bool supportsThumb2Encoding(const llvm::Triple &Triple) {
+  int Ver = arm::getARMSubArchVersionNumber(Triple);
+  llvm::ARM::ArchKind AK = llvm::ARM::parseArch(Triple.getArchName());
+  return AK == llvm::ARM::ArchKind::ARMV6T2 ||
  (Ver >= 7 && AK != llvm::ARM::ArchKind::ARMV8MBaseline);
 }
 
@@ -240,7 +252,13 @@ arm::ReadTPMode arm::getReadTPMode(const Driver &D, const 
ArgList &Args,
   D.Diag(diag::err_drv_invalid_mtp) << A->getAsString(Args);
 return ReadTPMode::Invalid;
   }
-  return (isHardTPSupported(Triple) ? ReadTPMode::TPIDRURO : ReadTPMode::Soft);
+  // In auto mode we enable HW mode only if both the hardware supports it and
+  // the thumb2 encoding. For example ARMV6T2 supports thumb2, but not 
hardware.
+  // ARMV6K has HW suport, but not thumb2. Otherwise we could enable it for
+  // ARMV6K in thumb mode.
+  bool autoUseHWTPMode =
+  isHardTPSupported(Triple) && supportsThumb2Encoding(Triple);
+  return autoUseHWTPMode ? ReadTPMode::TPIDRURO : ReadTPMode::Soft;
 }
 
 void arm::setArchNameInTriple(const Driver &D, const ArgList &Args,
diff --git a/clang/test/Driver/arm-thread-pointer.c 
b/clang/test/Driver/arm-thread-pointer.c
index 985c5046f6d26..ce075b1fe8b6b 100644
--- a/clang/test/Driver/arm-thread-pointer.c
+++ b/clang/test/Driver/arm-thread-pointer.c
@@ -14,18 +14,18 @@
 // RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-TPIDRPRW %s
 // ARMv7_THREAD_POINTER-TPIDRPRW: "-target-feature" "+read-tp-tpidrprw"
 
-// RUN: %clang --target=armv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s
-// RUN: %clang --target=thumbv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s
 // RUN: %clang --target=armv6k-linux -mtp=cp15 -### -S %s 2>&1 | \
 // RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s
-// RUN: %clang --target=armv6-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s
-// RUN: %clang --target=armv5t-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s
 // ARM_THREAD_POINTER-HARD: "-target-feature" "+read-tp-tpidruro"
 
+// RUN: %clang --target=armv6k-linux -mtp=auto -### -S %s 2>&1 | \
+// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER_AUTO %s
+// ARM_THREAD_POINTER_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
+
+// RUN: not %clang --target=thumbv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \
+// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER_NO_HARD %s
+// ARM_THREAD_POINTER_NO_HARD: hardware TLS register is not supported for the 
armv6t2 sub-architecture
+
 // RUN: %clang --target=armv5t-linux -mtp=cp15 -x assembler -### %s 2>&1 | \
 // RUN: FileCheck -check-prefix=ARMv5_THREAD_POINTER_ASSEMBLER %s
 // ARMv5_THREAD_POINTER_ASSEMBLER-NOT: hardware TLS register is not supported 
for the armv5 sub-architecture
@@ -47,3 +47,39 @@
 // RUN: %clang --target=armv7-linux -mtp=auto -### -S %s 2>&1 | \
 // RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_Auto %s
 // ARMv7_THREAD_POINTER_Auto: "-target-feature" "+read-tp-tpidruro"
+
+// RUN: %clang --target

[clang] 7602d78 - clang/HIP: Use regex for final path separator in hip-partial-link, again (#130371)

2025-03-07 Thread via cfe-commits

Author: Matt Arsenault
Date: 2025-03-08T10:53:03+07:00
New Revision: 7602d781b03427052c44537fa4b9c2a6da15697c

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

LOG: clang/HIP: Use regex for final path separator in hip-partial-link, again 
(#130371)

Added: 


Modified: 
clang/test/Driver/hip-partial-link.hip

Removed: 




diff  --git a/clang/test/Driver/hip-partial-link.hip 
b/clang/test/Driver/hip-partial-link.hip
index 5c538556a5070..d1a57bbe1d75c 100644
--- a/clang/test/Driver/hip-partial-link.hip
+++ b/clang/test/Driver/hip-partial-link.hip
@@ -32,11 +32,11 @@
 // LD-R: Found undefined HIP fatbin symbol: __hip_fatbin_[[ID2:[0-9a-f]+]]
 // LD-R: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID1]]
 // LD-R: Found undefined HIP gpubin handle symbol: __hip_gpubin_handle_[[ID2]]
-// LD-R: "{{.*}}/clang-offload-bundler" {{.*}}-unbundle
-// LD-R: "{{.*}}/lld" -flavor gnu -m elf64_amdgpu
-// LD-R: "{{.*}}/clang-offload-bundler"
-// LD-R: "{{.*}}/clang{{.*}}" -target x86_64-unknown-linux-gnu
-// LD-R: "{{.*}}/ld.lld" {{.*}} -r
+// LD-R: "{{.*[/\\]}}clang-offload-bundler" {{.*}}-unbundle
+// LD-R: "{{.*[/\\]}}lld" -flavor gnu -m elf64_amdgpu
+// LD-R: "{{.*[/\\]}}clang-offload-bundler"
+// LD-R: "{{.*[/\\]}}clang{{.*}}" -target x86_64-unknown-linux-gnu
+// LD-R: "{{.*[/\\]}}ld.lld" {{.*}} -r
 
 // RUN: llvm-nm  %t.lib.o | FileCheck -check-prefix=OBJ %s
 // OBJ:  B __hip_cuid_[[ID1:[0-9a-f]+]]



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


[clang] [CIR] Disable gcc partially overloaded virtual warning (PR #130322)

2025-03-07 Thread Bruno Cardoso Lopes via cfe-commits

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

LGTM, same observation as Erich regarding CMAKE stuff tho

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


[clang] clang/HIP: Use regex for final path separator in hip-partial-link, again (PR #130371)

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

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


  1   2   3   4   5   >