[clang] [CIR] Upstream pointer subtraction handling (PR #163306)

2025-10-15 Thread Shawn K via cfe-commits

https://github.com/kimsh02 edited 
https://github.com/llvm/llvm-project/pull/163306
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Add checker 'core.NullPointerArithm' (PR #157129)

2025-10-15 Thread Balázs Kéri via cfe-commits

https://github.com/balazske closed 
https://github.com/llvm/llvm-project/pull/157129
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [ARM][KCFI] Add backend support for Kernel Control-Flow Integrity (PR #163698)

2025-10-15 Thread Kees Cook via cfe-commits

https://github.com/kees updated https://github.com/llvm/llvm-project/pull/163698

>From e60ef75c3f524d892cbda25937c740671fc6f49e Mon Sep 17 00:00:00 2001
From: Kees Cook 
Date: Wed, 15 Oct 2025 16:32:16 -0700
Subject: [PATCH] [ARM][KCFI] Add backend support for Kernel Control-Flow
 Integrity

Implement KCFI (Kernel Control Flow Integrity) backend support for ARM32
(ARM mode only, not Thumb), as is already supported for x86, aarch64,
and riscv. The Linux kernel has supported ARM KCFI via Clang's generic
KCFI implementation, but this has finally started to
[cause problems](https://github.com/ClangBuiltLinux/linux/issues/2124)
so it's time to get the KCFI operand bundle lowering working on ARM.

Implementation notes:
- Four-instruction EOR sequence builds the 32-bit type ID byte-by-byte
  to work within ARM's modified immediate encoding constraints.
- Scratch register selection: r12 (IP) is preferred, r3 used as fallback
  when r12 holds the call target
- Automatic r3 spill/reload when r3 is live as a call argument (5+ args)
- UDF trap encoding: 0x8000 | (0x1F << 5) | target_reg_index, similar
  to aarch64's trap encoding.
- Support for patchable-function-prefix with adjusted load offsets
- Only enabled for ARM mode

Frontend integration updated to skip the KCFI IR pass for ARM targets,
allowing the backend to handle KCFI operand bundle lowering directly,
matching the implementation used by the other architectures.
---
 clang/lib/CodeGen/BackendUtil.cpp |   3 +-
 llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 112 
 llvm/lib/Target/ARM/ARMAsmPrinter.h   |   3 +
 llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp  |   2 +
 llvm/lib/Target/ARM/ARMISelLowering.cpp   |  47 +++
 llvm/lib/Target/ARM/ARMISelLowering.h |   6 +
 llvm/lib/Target/ARM/ARMInstrInfo.td   |   8 ++
 llvm/lib/Target/ARM/ARMTargetMachine.cpp  |   7 +
 llvm/test/CodeGen/ARM/kcfi-arm.ll |  65 ++
 .../ARM/kcfi-patchable-function-prefix.ll |  46 +++
 llvm/test/CodeGen/ARM/kcfi-r3-spill.ll| 121 ++
 .../CodeGen/ARM/{kcfi.ll => kcfi-thumb.ll}|   0
 12 files changed, 419 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/ARM/kcfi-arm.ll
 create mode 100644 llvm/test/CodeGen/ARM/kcfi-patchable-function-prefix.ll
 create mode 100644 llvm/test/CodeGen/ARM/kcfi-r3-spill.ll
 rename llvm/test/CodeGen/ARM/{kcfi.ll => kcfi-thumb.ll} (100%)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 602068436101b..91a0fdfea96a0 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -687,7 +687,8 @@ static void addKCFIPass(const Triple &TargetTriple, const 
LangOptions &LangOpts,
 PassBuilder &PB) {
   // If the back-end supports KCFI operand bundle lowering, skip KCFIPass.
   if (TargetTriple.getArch() == llvm::Triple::x86_64 ||
-  TargetTriple.isAArch64(64) || TargetTriple.isRISCV())
+  TargetTriple.isAArch64(64) || TargetTriple.isRISCV() ||
+  TargetTriple.isARM())
 return;
 
   // Ensure we lower KCFI operand bundles with -O0.
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp 
b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 1f773e2a7e0fc..e028d726e4025 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -1471,6 +1471,115 @@ void ARMAsmPrinter::EmitUnwindingInstruction(const 
MachineInstr *MI) {
 // instructions) auto-generated.
 #include "ARMGenMCPseudoLowering.inc"
 
+void ARMAsmPrinter::LowerKCFI_CHECK(const MachineInstr &MI) {
+  Register AddrReg = MI.getOperand(0).getReg();
+  const int64_t Type = MI.getOperand(1).getImm();
+
+  // Get the call instruction that follows this KCFI_CHECK.
+  assert(std::next(MI.getIterator())->isCall() &&
+ "KCFI_CHECK not followed by a call instruction");
+  const MachineInstr &Call = *std::next(MI.getIterator());
+
+  // Choose scratch register (r12 or r3): r12 (IP) is the primary choice;
+  // use r3 if r12 is the target.
+  unsigned ScratchReg = ARM::R12;
+  bool NeedSpillR3 = false;
+
+  if (AddrReg == ARM::R12) {
+ScratchReg = ARM::R3;
+
+// Check if r3 is live (used as implicit operand in the call).
+// If so, we need to spill/restore it.
+for (const MachineOperand &MO : Call.implicit_operands()) {
+  if (MO.isReg() && MO.getReg() == ARM::R3 && MO.isUse()) {
+NeedSpillR3 = true;
+break;
+  }
+}
+  }
+
+  // Adjust the offset for patchable-function-prefix.
+  int64_t PrefixNops = 0;
+  MI.getMF()
+  ->getFunction()
+  .getFnAttribute("patchable-function-prefix")
+  .getValueAsString()
+  .getAsInteger(10, PrefixNops);
+
+  // If we need to spill r3, push it first.
+  if (NeedSpillR3) {
+// push {r3}
+EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::STMDB_UPD)
+ .addReg(ARM::SP)
+ .addReg(ARM::SP)

[clang-tools-extra] [clang-tidy] Rename and move 'cert-oop57-cpp' to 'bugprone-libc-memory-calls-on-nontrivial-types' (PR #162039)

2025-10-15 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code linter clang-tidy found issues in your code. :warning:



You can test this locally with the following command:


```bash

git diff -U0 origin/main...HEAD -- 
clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp 
clang-tools-extra/clang-tidy/bugprone/LibcMemoryCallsOnNonTrivialTypesCheck.cpp 
clang-tools-extra/clang-tidy/bugprone/LibcMemoryCallsOnNonTrivialTypesCheck.h |
python3 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py \
  -path build -p1 -quiet
```





View the output from clang-tidy here.


```

clang-tools-extra/clang-tidy/bugprone/LibcMemoryCallsOnNonTrivialTypesCheck.h:9:9:
 warning: header guard does not follow preferred style [llvm-header-guard]
9 | #ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONTRIVIALTYPESLIBCMEMORYCALLSCHECK_H
  | 
^~~~
  | 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LIBCMEMORYCALLSONNONTRIVIALTYPESCHECK_H
   10 | #define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONTRIVIALTYPESLIBCMEMORYCALLSCHECK_H
  | 

  | 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_LIBCMEMORYCALLSONNONTRIVIALTYPESCHECK_H
```




https://github.com/llvm/llvm-project/pull/162039
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Matrix][Clang][HLSL] Move MaxMatrixDimension to a LangOpt (PR #163307)

2025-10-15 Thread Helena Kotas via cfe-commits

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

LGTM!

https://github.com/llvm/llvm-project/pull/163307
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ByteCode] Remove a redundant call to std::unique_ptr::get (NFC) (PR #163512)

2025-10-15 Thread Tim Gymnich via cfe-commits

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


https://github.com/llvm/llvm-project/pull/163512
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [X86] Add support for Wildcat Lake (PR #163214)

2025-10-15 Thread Mikołaj Piróg via cfe-commits

https://github.com/mikolaj-pirog closed 
https://github.com/llvm/llvm-project/pull/163214
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libclc] Fix double NAN_MASK (PR #163522)

2025-10-15 Thread Wenju He via cfe-commits

https://github.com/wenju-he created 
https://github.com/llvm/llvm-project/pull/163522

0x7ff0 is +inf. Change it to quiet nan 0x7ff8.

>From 9a49cb5e37f308fd889dfc5ee96981139c3221d2 Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Wed, 15 Oct 2025 10:29:34 +0200
Subject: [PATCH] [libclc] Fix double NAN_MASK

0x7ff0 is +inf. Change it to quiet nan 0x7ff8.
---
 libclc/clc/lib/generic/math/clc_nan.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libclc/clc/lib/generic/math/clc_nan.inc 
b/libclc/clc/lib/generic/math/clc_nan.inc
index 46e828ba48c7e..47527088960da 100644
--- a/libclc/clc/lib/generic/math/clc_nan.inc
+++ b/libclc/clc/lib/generic/math/clc_nan.inc
@@ -7,7 +7,7 @@
 
//===--===//
 
 #if __CLC_FPSIZE == 64
-#define NAN_MASK 0x7ff0ul
+#define NAN_MASK 0x7ff8ul
 #elif __CLC_FPSIZE == 32
 #define NAN_MASK 0x7fc0
 #elif __CLC_FPSIZE == 16

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][x86][bytecode] Replace interp__builtin_parity/clrsb/bitreverse/ffs with static bool interp__builtin_elementwise_int_unaryop callback (PR #162346)

2025-10-15 Thread Timm Baeder via cfe-commits


@@ -3209,7 +3182,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const CallExpr *Call,
   case Builtin::BI__builtin_ffs:
   case Builtin::BI__builtin_ffsl:
   case Builtin::BI__builtin_ffsll:
-return interp__builtin_ffs(S, OpPC, Frame, Call);
+return interp__builtin_elementwise_int_unaryop(
+S, OpPC, Call, [](const APSInt &Val) {

tbaederr wrote:

I usually add a trailing return type when I write lambdas, but I think that's 
the exception when looking at the entire code base, so I don't mind either way.

https://github.com/llvm/llvm-project/pull/162346
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [compiler-rt] [llvm] [X86] Add support for Wildcat Lake (PR #163214)

2025-10-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-quick` 
running on `linaro-clang-aarch64-quick` while building `clang,compiler-rt,llvm` 
at step 5 "ninja check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clangd Unit Tests :: ./ClangdTests/113/334' FAILED 

Script(shard):
--
GTEST_OUTPUT=json:/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests-Clangd
 Unit Tests-1071044-113-334.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=334 
GTEST_SHARD_INDEX=113 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests
--

Note: This is test shard 114 of 334.
[==] Running 4 tests from 4 test suites.
[--] Global test environment set-up.
[--] 1 test from CompletionTest
[ RUN  ] CompletionTest.CommentsFromSystemHeaders
ASTWorker building file /clangd-test/foo.cpp version null with command 
[/clangd-test]
clang -ffreestanding /clangd-test/foo.cpp
Driver produced command: cc1 -cc1 -triple aarch64-unknown-linux-gnu 
-fsyntax-only -disable-free -clear-ast-before-backend -main-file-name foo.cpp 
-mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=non-leaf 
-fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases 
-ffreestanding -enable-tlsdesc -target-cpu generic -target-feature +v8a 
-target-feature +fp-armv8 -target-feature +neon -target-abi aapcs 
-debugger-tuning=gdb -fdebug-compilation-dir=/clangd-test 
-fcoverage-compilation-dir=/clangd-test -resource-dir lib/clang/22 
-internal-isystem lib/clang/22/include -internal-isystem /usr/local/include 
-internal-externc-isystem /include -internal-externc-isystem /usr/include 
-fdeprecated-macro -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 
-fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -no-round-trip-args 
-target-feature -fmv -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ 
/clangd-test/foo.cpp
Building first preamble for /clangd-test/foo.cpp version null
Built preamble of size 740092 for file /clangd-test/foo.cpp version null in 
6.70 seconds
indexed preamble AST for /clangd-test/foo.cpp version null:
  symbol slab: 1 symbols, 4448 bytes
  ref slab: 0 symbols, 0 refs, 128 bytes
  relations slab: 0 relations, 24 bytes
Build dynamic index for header symbols with estimated memory usage of 6892 bytes
not idle after addDocument
UNREACHABLE executed at 
../llvm/clang-tools-extra/clangd/unittests/SyncAPI.cpp:22!
indexed file AST for /clangd-test/foo.cpp version null:
  symbol slab: 1 symbols, 4448 bytes
  ref slab: 2 symbols, 2 refs, 4272 bytes
  relations slab: 0 relations, 24 bytes
Build dynamic index for main-file symbols with estimated memory usage of 11576 
bytes
 #0 0xc82e5924fd24 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xcffd24)
 #1 0xc82e5924d814 llvm::sys::RunSignalHandlers() 
(/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xcfd814)
 #2 0xc82e59250b64 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0xf0921f6688f8 (linux-vdso.so.1+0x8f8)
 #4 0xf0921f182008 __pthread_kill_implementation 
./nptl/./nptl/pthread_kill.c:44:76
 #5 0xf0921f13a83c gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #6 0xf0921f127134 abort ./stdlib/./stdlib/abort.c:81:7
 #7 0xc82e591fbddc llvm::RTTIRoot::anchor() 
(/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xcabddc)
 #8 0xc82e59092a04 
clang::clangd::runCodeComplete(clang::clangd::ClangdServer&, llvm::StringRef, 
clang::clangd::Position, clang::clangd::CodeCompleteOptions) 
(/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xb42a04)
 #9 0xc82e58bc8148 clang::clangd::(anonymous 
namespace)::CompletionTest_CommentsFromSystemHeaders_Test::TestBody() 
CodeCompleteTests.cpp:0:0
#10 0xc82e592aae50 testing::Test::Run() 
(/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xd5ae50)
#11 0xc82e592ac160 testing::TestInfo::Run() 
(/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xd5c160)
#12 0xc82e592acd28 testing::TestSuite::Run() 
(/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xd5cd28)
#13 0xc82e592bda70 testing::internal::UnitTestImpl::RunAllTests() 
(/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/clangd/unittests/./ClangdTests+0xd6da70)
#14 0xc82e592bd3d

[clang] [clang][Basic] Add helper APIs to get language version codes from LangOptions (PR #163348)

2025-10-15 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/163348

>From 375a56e2def366b838a79042b2c11e08dfbd8a4c Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Mon, 13 Oct 2025 23:59:16 +0100
Subject: [PATCH 1/5] [clang][Basic] Add helper APIs to get language version
 codes from LangOptions

---
 clang/include/clang/Basic/LangOptions.h | 31 +
 clang/lib/Basic/LangOptions.cpp | 46 +
 clang/lib/Frontend/InitPreprocessor.cpp | 37 +++-
 clang/unittests/Basic/CMakeLists.txt|  1 +
 4 files changed, 82 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 41595ec2a060d..940e79634ccd5 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -184,6 +184,28 @@ class LangOptionsBase {
 HLSL_202y = 2029,
   };
 
+  /// C language version codes as defined by the standard.
+  enum CLangStd : uint32_t {
+// FIXME: Use correct value for C2y.
+C_2y = 202400,
+C_23 = 202311,
+C_17 = 201710,
+C_11 = 201112,
+C_99 = 199901,
+  };
+
+  /// C++ language version codes as defined by the standard.
+  enum CPlusPlusLangStd : uint32_t {
+// FIXME: Use correct value for C++26.
+CPP_26 = 202400,
+CPP_23 = 202302,
+CPP_20 = 202002,
+CPP_17 = 201703,
+CPP_14 = 201402,
+CPP_11 = 201103,
+CPP_03 = 199711,
+  };
+
   /// Clang versions with different platform ABI conformance.
   enum class ClangABI {
 #define ABI_VER_MAJOR_MINOR(Major, Minor) Ver##Major##_##Minor,
@@ -756,6 +778,15 @@ class LangOptions : public LangOptionsBase {
   bool isTargetDevice() const {
 return OpenMPIsTargetDevice || CUDAIsDevice || SYCLIsDevice;
   }
+
+  /// Returns the most applicable C standard-compliant language version code.
+  /// If none could be determined, returns \ref std::nullopt.
+  std::optional GetCLangStd() const;
+
+  /// Returns the most applicable C++ standard-compliant language
+  /// version code.
+  /// If none could be determined, returns \ref std::nullopt.
+  std::optional GetCPlusPlusLangStd() const;
 };
 
 /// Floating point control options
diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp
index f034514466d3f..6745427e2c223 100644
--- a/clang/lib/Basic/LangOptions.cpp
+++ b/clang/lib/Basic/LangOptions.cpp
@@ -243,3 +243,49 @@ LLVM_DUMP_METHOD void FPOptionsOverride::dump() {
 #include "clang/Basic/FPOptions.def"
   llvm::errs() << "\n";
 }
+
+std::optional
+LangOptions::GetCPlusPlusLangStd() const {
+  if (!CPlusPlus)
+return std::nullopt;
+
+  if (CPlusPlus26)
+return clang::LangOptionsBase::CPP_26;
+
+  if (CPlusPlus23)
+return clang::LangOptionsBase::CPP_23;
+
+  if (CPlusPlus20)
+return clang::LangOptionsBase::CPP_20;
+
+  if (CPlusPlus17)
+return clang::LangOptionsBase::CPP_17;
+
+  if (CPlusPlus14)
+return clang::LangOptionsBase::CPP_14;
+
+  if (CPlusPlus11)
+return clang::LangOptionsBase::CPP_11;
+
+  return clang::LangOptionsBase::CPP_03;
+}
+
+std::optional
+LangOptions::GetCLangStd() const {
+  if (C2y)
+return clang::LangOptionsBase::C_2y;
+
+  if (C23)
+return clang::LangOptionsBase::C_23;
+
+  if (C17)
+return clang::LangOptionsBase::C_17;
+
+  if (C11)
+return clang::LangOptionsBase::C_11;
+
+  if (C99)
+return clang::LangOptionsBase::C_99;
+
+  return std::nullopt;
+}
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index b899fb9c6494a..27bc4cf7108cc 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -459,43 +459,14 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
   //  value is, are implementation-defined.
   // (Removed in C++20.)
   if (!LangOpts.CPlusPlus) {
-if (LangOpts.C2y)
-  Builder.defineMacro("__STDC_VERSION__", "202400L");
-else if (LangOpts.C23)
-  Builder.defineMacro("__STDC_VERSION__", "202311L");
-else if (LangOpts.C17)
-  Builder.defineMacro("__STDC_VERSION__", "201710L");
-else if (LangOpts.C11)
-  Builder.defineMacro("__STDC_VERSION__", "201112L");
-else if (LangOpts.C99)
-  Builder.defineMacro("__STDC_VERSION__", "199901L");
+if (auto LangStd = LangOpts.GetCLangStd())
+  Builder.defineMacro("__STDC_VERSION__", Twine(*LangStd) + "L");
 else if (!LangOpts.GNUMode && LangOpts.Digraphs)
   Builder.defineMacro("__STDC_VERSION__", "199409L");
   } else {
 //   -- __cplusplus
-if (LangOpts.CPlusPlus26)
-  // FIXME: Use correct value for C++26.
-  Builder.defineMacro("__cplusplus", "202400L");
-else if (LangOpts.CPlusPlus23)
-  Builder.defineMacro("__cplusplus", "202302L");
-//  [C++20] The integer literal 202002L.
-else if (LangOpts.CPlusPlus20)
-  Builder.defineMacro("__cplusplus", "202002L");
-//  [C++17] The integer literal 2

[clang] [clang][Basic] Add helper APIs to get language version codes from LangOptions (PR #163348)

2025-10-15 Thread Michael Buch via cfe-commits


@@ -184,6 +184,28 @@ class LangOptionsBase {
 HLSL_202y = 2029,
   };
 
+  /// C language version codes as defined by the standard.
+  enum CLangStd : uint32_t {
+// FIXME: Use correct value for C2y.
+C_2y = 202400,
+C_23 = 202311,
+C_17 = 201710,
+C_11 = 201112,
+C_99 = 199901,
+  };
+
+  /// C++ language version codes as defined by the standard.
+  enum CPlusPlusLangStd : uint32_t {
+// FIXME: Use correct value for C++26.
+CPP_26 = 202400,

Michael137 wrote:

Not applicable now that we use `LangStandards.def`

https://github.com/llvm/llvm-project/pull/163348
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][bytecode] Diagnose out-of-bounds enum values in .... (PR #163530)

2025-10-15 Thread Timm Baeder via cfe-commits

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

... non-constexpr variable initializers.

>From 5c4d238f58065519ee38ae3af0522a6db73cc1ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 15 Oct 2025 10:42:44 +0200
Subject: [PATCH] [clang][bytecode] Diagnose out-of-bounds enum values in 

... non-constexpr variable initializers.
---
 clang/lib/AST/ByteCode/Interp.cpp | 3 ---
 clang/test/AST/ByteCode/cxx11.cpp | 8 
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 89043968915a9..a72282caf5e73 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1358,9 +1358,6 @@ bool Free(InterpState &S, CodePtr OpPC, bool 
DeleteIsArrayForm,
 
 void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED,
const APSInt &Value) {
-  if (S.EvaluatingDecl && !S.EvaluatingDecl->isConstexpr())
-return;
-
   llvm::APInt Min;
   llvm::APInt Max;
   ED->getValueRange(Max, Min);
diff --git a/clang/test/AST/ByteCode/cxx11.cpp 
b/clang/test/AST/ByteCode/cxx11.cpp
index 72bc7622eb6d8..8efd3201d6200 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -146,6 +146,14 @@ void testValueInRangeOfEnumerationValues() {
 
   const NumberType neg_one = (NumberType) ((NumberType) 0 - (NumberType) 1); 
// ok, not a constant expression context
 }
+struct EnumTest {
+  enum type {
+  Type1,
+  BOUND
+  };
+  static const type binding_completed = type(BOUND + 1); // both-error 
{{in-class initializer for static data member is not a constant expression}} \
+ // both-note 
{{integer value 2 is outside the valid range of values}}
+};
 
 template struct Bitfield {
   static constexpr T max = static_cast((1 << size) - 1);

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HIP][SPIRV] Enable the SPIRV backend instead of the translator through an experimental flag. (PR #162282)

2025-10-15 Thread Manuel Carrasco via cfe-commits


@@ -175,15 +175,33 @@ void AMDGCN::Linker::constructLinkAndEmitSpirvCommand(
 
   constructLlvmLinkCommand(C, JA, Inputs, LinkedBCFile, Args);
 
-  // Emit SPIR-V binary.
-  llvm::opt::ArgStringList TrArgs{
-  "--spirv-max-version=1.6",
-  "--spirv-ext=+all",
-  "--spirv-allow-unknown-intrinsics",
-  "--spirv-lower-const-expr",
-  "--spirv-preserve-auxdata",
-  "--spirv-debug-info-version=nonsemantic-shader-200"};
-  SPIRV::constructTranslateCommand(C, *this, JA, Output, LinkedBCFile, TrArgs);
+  bool UseSPIRVBackend = Args.hasFlag(
+  options::OPT_use_experimental_spirv_backend,
+  options::OPT_no_use_experimental_spirv_backend, /*Default=*/false);
+
+  // Emit SPIR-V binary either using the SPIRV backend or the translator.
+  if (UseSPIRVBackend) {
+llvm::opt::ArgStringList CmdArgs;
+const char *Triple =
+C.getArgs().MakeArgString("-triple=spirv64-amd-amdhsa");
+CmdArgs.append({"-cc1", Triple, "-emit-obj", LinkedBCFile.getFilename(),

mgcarrasco wrote:

Thank you all for the feedback. 

@arsenm `-emit-obj` is not breaking `-save-temps` (files are saved). There is 
no existing function to call for this. 

@jhuber6 Following up on @AlexVlx's 
[comment](https://github.com/llvm/llvm-project/pull/162282/#discussion_r2420855314),
 making the target directly emit object instead of IR would require substantial 
changes in places like the Driver and also it would make the code less 
maintainable when it comes to keep it in sync with the existing translator 
code. That is why I prefer to call -cc1 as we do now.


https://github.com/llvm/llvm-project/pull/162282
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Add support for ternary operator as lvalue (PR #163580)

2025-10-15 Thread Morris Hafner via cfe-commits

https://github.com/mmha created https://github.com/llvm/llvm-project/pull/163580

Added support for ConditionalOperator, BinaryConditionalOperator and 
OpaqueValueExpr as lvalue.

Implemented support for ternary operators with one branch being a throw 
expression. This required weakening the requirement that the true and false 
regions of the ternary operator must terminate with a `YieldOp`. Instead the 
true and false regions are now allowed to terminate with an `UnreachableOp` and 
no `YieldOp` gets emitted when the block throws.

>From c01e53fe7ce0d5ffd3d5874755e96bf512cdda16 Mon Sep 17 00:00:00 2001
From: Morris Hafner 
Date: Wed, 15 Oct 2025 22:45:06 +0700
Subject: [PATCH] [CIR] Add support for ternary operator as lvalue

Added support for ConditionalOperator, BinaryConditionalOperator and
OpaqueValueExpr as lvalue.

Implemented support for ternary operators with one branch being a throw
expression. This required weakening the requirement that the true and
false regions of the ternary operator must terminate with a `YieldOp`.
Instead the true and false regions are now allowed to terminate with an
`UnreachableOp` and no `YieldOp` gets emitted when the block throws.
---
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  | 179 ++
 clang/lib/CIR/CodeGen/CIRGenFunction.cpp  |   6 +
 clang/lib/CIR/CodeGen/CIRGenFunction.h|   4 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   |  11 +-
 .../lib/CIR/Dialect/Transforms/FlattenCFG.cpp |  31 +-
 clang/test/CIR/CodeGen/opaque.cpp | 163 +
 clang/test/CIR/CodeGen/ternary.cpp| 309 +-
 7 files changed, 682 insertions(+), 21 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index f416571181153..27ce368f57fec 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -2394,6 +2394,185 @@ LValue CIRGenFunction::emitPredefinedLValue(const 
PredefinedExpr *e) {
   return emitStringLiteralLValue(sl, gvName);
 }
 
+LValue CIRGenFunction::emitOpaqueValueLValue(const OpaqueValueExpr *e) {
+  assert(OpaqueValueMappingData::shouldBindAsLValue(e));
+  return getOrCreateOpaqueLValueMapping(e);
+}
+
+namespace {
+// Handle the case where the condition is a constant evaluatable simple 
integer,
+// which means we don't have to separately handle the true/false blocks.
+std::optional handleConditionalOperatorLValueSimpleCase(
+CIRGenFunction &cgf, const AbstractConditionalOperator *e) {
+  const Expr *condExpr = e->getCond();
+  llvm::APSInt condExprInt;
+  if (cgf.constantFoldsToSimpleInteger(condExpr, condExprInt)) {
+bool condExprBool = condExprInt.getBoolValue();
+const Expr *live = e->getTrueExpr(), *dead = e->getFalseExpr();
+if (!condExprBool)
+  std::swap(live, dead);
+
+if (!cgf.containsLabel(dead)) {
+  // If the true case is live, we need to track its region.
+  assert(!cir::MissingFeatures::incrementProfileCounter());
+  assert(!cir::MissingFeatures::pgoUse());
+  // If a throw expression we emit it and return an undefined lvalue
+  // because it can't be used.
+  if (auto *throwExpr = dyn_cast(live->IgnoreParens())) {
+cgf.emitCXXThrowExpr(throwExpr);
+// Return an undefined lvalue - the throw terminates execution
+// so this value will never actually be used
+mlir::Type elemTy = cgf.convertType(dead->getType());
+mlir::Type ptrTy = cir::PointerType::get(elemTy);
+mlir::Value undefPtr = cgf.getBuilder().getNullValue(
+ptrTy, cgf.getLoc(throwExpr->getSourceRange()));
+return cgf.makeAddrLValue(Address(undefPtr, elemTy, CharUnits::One()),
+  dead->getType());
+  }
+  return cgf.emitLValue(live);
+}
+  }
+  return std::nullopt;
+}
+
+/// Emit the operand of a glvalue conditional operator. This is either a 
glvalue
+/// or a (possibly-parenthesized) throw-expression. If this is a throw, no
+/// LValue is returned and the current block has been terminated.
+static std::optional emitLValueOrThrowExpression(CIRGenFunction &cgf,
+ const Expr *operand) {
+  if (auto *throwExpr = dyn_cast(operand->IgnoreParens())) {
+cgf.emitCXXThrowExpr(throwExpr);
+return std::nullopt;
+  }
+
+  return cgf.emitLValue(operand);
+}
+} // namespace
+
+// Create and generate the 3 blocks for a conditional operator.
+// Leaves the 'current block' in the continuation basic block.
+template 
+CIRGenFunction::ConditionalInfo
+CIRGenFunction::emitConditionalBlocks(const AbstractConditionalOperator *e,
+  const FuncTy &branchGenFunc) {
+  ConditionalInfo info;
+  ConditionalEvaluation eval(*this);
+  mlir::Location loc = getLoc(e->getSourceRange());
+  CIRGenBuilderTy &builder = getBuilder();
+
+  mlir::Value condV = emitOpOnBoolExpr(loc, e->getCond());
+  SmallVector insertPoints{};
+  mlir::Type 

[clang] [AArch64][llvm] Add support for new vcvt* intrinsics (PR #163572)

2025-10-15 Thread Jonathan Thackray via cfe-commits

https://github.com/jthackray updated 
https://github.com/llvm/llvm-project/pull/163572

>From 23653d3d12f342c4c45897866f92865bd6aafc5d Mon Sep 17 00:00:00 2001
From: Jonathan Thackray 
Date: Tue, 14 Oct 2025 12:40:51 +0100
Subject: [PATCH 1/2] [AArch64][llvm] Add support for new vcvt* intrinsics

Add support for these new vcvt* intrinsics:

```
  int64_t  vcvts_s64_f32(float32_t);
  uint64_t vcvts_u64_f32(float32_t);
  int32_t  vcvtd_s32_f64(float64_t);
  uint32_t vcvtd_u32_f64(float64_t);

  int64_t  vcvtns_s64_f32(float32_t);
  uint64_t vcvtns_u64_f32(float32_t);
  int32_t  vcvtnd_s32_f64(float64_t);
  uint32_t vcvtnd_u32_f64(float64_t);

  int64_t  vcvtms_s64_f32(float32_t);
  uint64_t vcvtms_u64_f32(float32_t);
  int32_t  vcvtmd_s32_f64(float64_t);
  uint32_t vcvtmd_u32_f64(float64_t);

  int64_t  vcvtps_s64_f32(float32_t);
  uint64_t vcvtps_u64_f32(float32_t);
  int32_t  vcvtpd_s32_f64(float64_t);
  uint32_t vcvtpd_u32_f64(float64_t);

  int64_t  vcvtas_s64_f32(float32_t);
  uint64_t vcvtas_u64_f32(float32_t);
  int32_t  vcvtad_s32_f64(float64_t);
  uint32_t vcvtad_u32_f64(float64_t);
```
---
 clang/include/clang/Basic/arm_neon.td |  65 +++--
 clang/lib/CodeGen/TargetBuiltins/ARM.cpp  |  20 ++
 .../CodeGen/AArch64/neon-fcvt-intrinsics.c| 225 +-
 3 files changed, 288 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index ef196103035e8..315c60692dcaf 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1466,26 +1466,51 @@ def SCALAR_UCVTFD : SInst<"vcvt_f64", "(1F)(1!)", 
"SUl">;
 

 // Scalar Floating-point Converts
 def SCALAR_FCVTXN  : IInst<"vcvtx_f32", "(1F<)(1!)", "Sd">;
-def SCALAR_FCVTNSS : SInst<"vcvtn_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTNUS : SInst<"vcvtn_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTNSD : SInst<"vcvtn_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTNUD : SInst<"vcvtn_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTMSS : SInst<"vcvtm_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTMUS : SInst<"vcvtm_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTMSD : SInst<"vcvtm_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTMUD : SInst<"vcvtm_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTASS : SInst<"vcvta_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTAUS : SInst<"vcvta_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTASD : SInst<"vcvta_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTAUD : SInst<"vcvta_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTPSS : SInst<"vcvtp_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTPUS : SInst<"vcvtp_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTPSD : SInst<"vcvtp_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTPUD : SInst<"vcvtp_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTZSS : SInst<"vcvt_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTZUS : SInst<"vcvt_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTZSD : SInst<"vcvt_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTZUD : SInst<"vcvt_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTN_F32toSS  : SInst<"vcvtn_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUS  : SInst<"vcvtn_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSS  : SInst<"vcvtn_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUS  : SInst<"vcvtn_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTN_F32toSD  : SInst<"vcvtn_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUD  : SInst<"vcvtn_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSD  : SInst<"vcvtn_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUD  : SInst<"vcvtn_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTM_F32toSS  : SInst<"vcvtm_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUS  : SInst<"vcvtm_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSS  : SInst<"vcvtm_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUS  : SInst<"vcvtm_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTM_F32toSD  : SInst<"vcvtm_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUD  : SInst<"vcvtm_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSD  : SInst<"vcvtm_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUD  : SInst<"vcvtm_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTA_F32toSS  : SInst<"vcvta_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTA_F32toUS  : SInst<"vcvta_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTA_F64toSS  : SInst<"vcvta_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTA_F64toUS  : SInst<"vcvta_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTA_F32toSD  : SInst<"vcvta_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTA_F32toUD  : SInst<"vcvta_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTA_F64toSD  : SInst<"vcvta_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTA_F64toUD  : SInst<"vcvta_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTP_F32toSS  : SInst<"vcvtp_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTP_F32toUS  : SInst<"vcvtp_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTP_F64toSS  : SInst<"vcvtp_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTP_F64toUS  : SInst<"vcvtp_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTP_F32toSD  : SInst<"vcvtp_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTP_F32toUD  : SInst<"vcvtp_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTP_F64toSD  : SInst<"vcvtp_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTP_F64toUD  : S

[clang] [Clang][CodeGen] Make UnqualPtrTy match llvm::PointerType::getUnqual (PR #163207)

2025-10-15 Thread Eli Friedman via cfe-commits
Juan Manuel Martinez =?utf-8?q?Caama=C3=B1o?= ,
Juan Manuel Martinez =?utf-8?q?Caama=C3=B1o?= 
Message-ID:
In-Reply-To: 


efriedma-quic wrote:

Sure, that seems like a good approach.

https://github.com/llvm/llvm-project/pull/163207
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] ThrowOp with Complex type as Subexpr (PR #163078)

2025-10-15 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper closed 
https://github.com/llvm/llvm-project/pull/163078
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AArch64][llvm] Add support for new vcvt* intrinsics (PR #163572)

2025-10-15 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic edited 
https://github.com/llvm/llvm-project/pull/163572
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Add support for ternary operator as lvalue (PR #163580)

2025-10-15 Thread Erich Keane via cfe-commits


@@ -2394,6 +2394,185 @@ LValue CIRGenFunction::emitPredefinedLValue(const 
PredefinedExpr *e) {
   return emitStringLiteralLValue(sl, gvName);
 }
 
+LValue CIRGenFunction::emitOpaqueValueLValue(const OpaqueValueExpr *e) {
+  assert(OpaqueValueMappingData::shouldBindAsLValue(e));
+  return getOrCreateOpaqueLValueMapping(e);
+}
+
+namespace {
+// Handle the case where the condition is a constant evaluatable simple 
integer,
+// which means we don't have to separately handle the true/false blocks.
+std::optional handleConditionalOperatorLValueSimpleCase(
+CIRGenFunction &cgf, const AbstractConditionalOperator *e) {
+  const Expr *condExpr = e->getCond();
+  llvm::APSInt condExprInt;
+  if (cgf.constantFoldsToSimpleInteger(condExpr, condExprInt)) {

erichkeane wrote:

I would suggest doing an early-exit here?

https://github.com/llvm/llvm-project/pull/163580
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Add support for ternary operator as lvalue (PR #163580)

2025-10-15 Thread Erich Keane via cfe-commits


@@ -2394,6 +2394,185 @@ LValue CIRGenFunction::emitPredefinedLValue(const 
PredefinedExpr *e) {
   return emitStringLiteralLValue(sl, gvName);
 }
 
+LValue CIRGenFunction::emitOpaqueValueLValue(const OpaqueValueExpr *e) {
+  assert(OpaqueValueMappingData::shouldBindAsLValue(e));
+  return getOrCreateOpaqueLValueMapping(e);
+}
+
+namespace {
+// Handle the case where the condition is a constant evaluatable simple 
integer,
+// which means we don't have to separately handle the true/false blocks.
+std::optional handleConditionalOperatorLValueSimpleCase(
+CIRGenFunction &cgf, const AbstractConditionalOperator *e) {
+  const Expr *condExpr = e->getCond();
+  llvm::APSInt condExprInt;
+  if (cgf.constantFoldsToSimpleInteger(condExpr, condExprInt)) {
+bool condExprBool = condExprInt.getBoolValue();
+const Expr *live = e->getTrueExpr(), *dead = e->getFalseExpr();
+if (!condExprBool)
+  std::swap(live, dead);
+
+if (!cgf.containsLabel(dead)) {
+  // If the true case is live, we need to track its region.
+  assert(!cir::MissingFeatures::incrementProfileCounter());
+  assert(!cir::MissingFeatures::pgoUse());
+  // If a throw expression we emit it and return an undefined lvalue
+  // because it can't be used.
+  if (auto *throwExpr = dyn_cast(live->IgnoreParens())) {
+cgf.emitCXXThrowExpr(throwExpr);
+// Return an undefined lvalue - the throw terminates execution
+// so this value will never actually be used
+mlir::Type elemTy = cgf.convertType(dead->getType());
+mlir::Type ptrTy = cir::PointerType::get(elemTy);
+mlir::Value undefPtr = cgf.getBuilder().getNullValue(
+ptrTy, cgf.getLoc(throwExpr->getSourceRange()));
+return cgf.makeAddrLValue(Address(undefPtr, elemTy, CharUnits::One()),
+  dead->getType());
+  }
+  return cgf.emitLValue(live);
+}
+  }
+  return std::nullopt;
+}
+
+/// Emit the operand of a glvalue conditional operator. This is either a 
glvalue
+/// or a (possibly-parenthesized) throw-expression. If this is a throw, no
+/// LValue is returned and the current block has been terminated.
+static std::optional emitLValueOrThrowExpression(CIRGenFunction &cgf,
+ const Expr *operand) {
+  if (auto *throwExpr = dyn_cast(operand->IgnoreParens())) {
+cgf.emitCXXThrowExpr(throwExpr);
+return std::nullopt;
+  }
+
+  return cgf.emitLValue(operand);
+}
+} // namespace
+
+// Create and generate the 3 blocks for a conditional operator.
+// Leaves the 'current block' in the continuation basic block.
+template 
+CIRGenFunction::ConditionalInfo
+CIRGenFunction::emitConditionalBlocks(const AbstractConditionalOperator *e,
+  const FuncTy &branchGenFunc) {
+  ConditionalInfo info;
+  ConditionalEvaluation eval(*this);
+  mlir::Location loc = getLoc(e->getSourceRange());
+  CIRGenBuilderTy &builder = getBuilder();
+
+  mlir::Value condV = emitOpOnBoolExpr(loc, e->getCond());
+  SmallVector insertPoints{};
+  mlir::Type yieldTy{};
+
+  auto patchVoidOrThrowSites = [&] {
+if (insertPoints.empty())
+  return;
+// If both arms are void, so be it.
+if (!yieldTy)
+  yieldTy = VoidTy;
+
+// Insert required yields.
+for (mlir::OpBuilder::InsertPoint &toInsert : insertPoints) {
+  mlir::OpBuilder::InsertionGuard guard(builder);
+  builder.restoreInsertionPoint(toInsert);
+
+  // Block does not return: build empty yield.
+  if (mlir::isa(yieldTy)) {
+cir::YieldOp::create(builder, loc);
+  } else { // Block returns: set null yield value.
+mlir::Value op0 = builder.getNullValue(yieldTy, loc);
+cir::YieldOp::create(builder, loc, op0);
+  }
+}
+  };
+
+  auto emitBranch = [&](mlir::OpBuilder &b, mlir::Location loc,
+const Expr *expr, std::optional &resultLV) {
+CIRGenFunction::LexicalScope lexScope{*this, loc, b.getInsertionBlock()};
+curLexScope->setAsTernary();
+
+assert(!cir::MissingFeatures::incrementProfileCounter());
+eval.beginEvaluation();
+resultLV = branchGenFunc(*this, expr);
+mlir::Value resultPtr = resultLV ? resultLV->getPointer() : mlir::Value();
+eval.endEvaluation();
+
+if (resultPtr) {
+  yieldTy = resultPtr.getType();
+  cir::YieldOp::create(b, loc, resultPtr);
+} else {
+  // If LHS or RHS is a void expression we need
+  // to patch arms as to properly match yield types.
+  // If the current block's terminator is an UnreachableOp (from a throw),
+  // we don't need a yield
+  if (builder.getInsertionBlock()->mightHaveTerminator()) {
+mlir::Operation *terminator =
+builder.getInsertionBlock()->getTerminator();
+if (isa_and_nonnull(terminator))
+  insertPoints.push_back(b.saveInsertionPoint());
+  }
+}
+  };
+
+  info.result = cir::Ternary

[clang] f49e3d1 - Repair test for WG14 N3364 (#163551)

2025-10-15 Thread via cfe-commits

Author: Aaron Ballman
Date: 2025-10-15T12:51:12-04:00
New Revision: f49e3d178b8b8ab3ad6a87f999b42a5a76353c2e

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

LOG: Repair test for WG14 N3364 (#163551)

The CodeGen test was missing a call to FileCheck which is now added

Added: 


Modified: 
clang/test/C/C2y/n3364.c

Removed: 




diff  --git a/clang/test/C/C2y/n3364.c b/clang/test/C/C2y/n3364.c
index d75f17d0a7a84..f95c77fb3018f 100644
--- a/clang/test/C/C2y/n3364.c
+++ b/clang/test/C/C2y/n3364.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -verify -std=c2y -ffreestanding -Wall -pedantic -emit-llvm 
-o - %s
-// RUN: %clang_cc1 -verify -ffreestanding -Wall -pedantic -emit-llvm -o - %s
+// RUN: %clang_cc1 -verify -std=c2y -ffreestanding -Wall -pedantic -emit-llvm 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -verify -ffreestanding -Wall -pedantic -emit-llvm -o - %s | 
FileCheck %s
 // expected-no-diagnostics
 
 /* WG14 N3364: Yes
@@ -23,20 +23,20 @@
 float f1 = FLT_SNAN;
 float f2 = +FLT_SNAN;
 float f3 = -FLT_SNAN;
-// CHECK: @f1 = {{.*}}global float 0x7FF02000
-// CHECK: @f2 = {{.*}}global float 0x7FF02000
-// CHECK: @f3 = {{.*}}global float 0xFFF02000
+// CHECK: @f1 = {{.*}}global float 0x7FF4
+// CHECK: @f2 = {{.*}}global float 0x7FF4
+// CHECK: @f3 = {{.*}}global float 0xFFF4
 
 double d1 = DBL_SNAN;
 double d2 = +DBL_SNAN;
 double d3 = -DBL_SNAN;
-// CHECK: @d1 = {{.*}}global double 0x7FF1
-// CHECK: @d2 = {{.*}}global double 0x7FF1
-// CHECK: @d3 = {{.*}}global double 0xFFF1
+// CHECK: @d1 = {{.*}}global double 0x7FF4
+// CHECK: @d2 = {{.*}}global double 0x7FF4
+// CHECK: @d3 = {{.*}}global double 0xFFF4
 
 long double ld1 = LDBL_SNAN;
 long double ld2 = +LDBL_SNAN;
 long double ld3 = -LDBL_SNAN;
-// CHECK: @ld1 = {{.*}}global {{double 0x7FF1|x86_fp80 
0xK7FFF8001|fp128 0xL00017FFF}}
-// CHECK: @ld2 = {{.*}}global {{double 0x7FF1|x86_fp80 
0xK7FFF8001|fp128 0xL00017FFF}}
-// CHECK: @ld3 = {{.*}}global {{double 0xFFF1|x86_fp80 
0xK8001|fp128 0xL0001}}
+// CHECK: @ld1 = {{.*}}global {{double 0x7FF4|x86_fp80 
0xK7FFFA000|fp128 0xL7FFF4000}}
+// CHECK: @ld2 = {{.*}}global {{double 0x7FF4|x86_fp80 
0xK7FFFA000|fp128 0xL7FFF4000}}
+// CHECK: @ld3 = {{.*}}global {{double 0xFFF4|x86_fp80 
0xKA000|fp128 0xL4000}}



___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Upstream support for variable length arrays (PR #163297)

2025-10-15 Thread Amr Hesham via cfe-commits

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

LGTM, Thanks!

https://github.com/llvm/llvm-project/pull/163297
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [DirectX] Add 32- and 64-bit 3-element vectors to DataLayout (PR #160955)

2025-10-15 Thread Chris B via cfe-commits

https://github.com/llvm-beanz approved this pull request.


https://github.com/llvm/llvm-project/pull/160955
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] disallow constexpr with auto and explicit type in C23 (PR #163469)

2025-10-15 Thread Oleksandr T. via cfe-commits


@@ -62,6 +62,8 @@ auto basic_usage(auto auto) {   // c23-error {{'auto' not 
allowed in function pr
 
   int auto_cxx_decl = auto(0);  // expected-error {{expected expression}}
 
+  constexpr auto int x = 0; // c23-error {{cannot combine with previous 'auto' 
declaration specifier}} \

a-tarasyuk wrote:

@AaronBallman should we handle this case as-is 
(https://godbolt.org/z/9fTocMzrP)?

```c
constexpr int auto y = 9; // cannot combine with previous 'int' declaration 
specifier

```

https://github.com/llvm/llvm-project/pull/163469
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

2025-10-15 Thread JJ Marr via cfe-commits


@@ -0,0 +1,143 @@
+// RUN: %check_clang_tidy %s readability-avoid-default-lambda-capture %t -- -- 
-Wno-vla-extension
+
+void test_default_captures() {
+  int value = 42;
+  int another = 10;
+
+  auto lambda1 = [=](int x) { return value + x; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto lambda1 = [value](int x) { return value + x; };
+
+  auto lambda2 = [&](int x) { return value + x; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto lambda2 = [&value](int x) { return value + x; };
+
+  auto lambda3 = [=, &another](int x) { return value + another + x; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto lambda3 = [value, &another](int x) { return value + 
another + x; };
+
+  auto lambda4 = [&, value](int x) { return value + another + x; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto lambda4 = [&another, value](int x) { return value + 
another + x; };
+}
+
+void test_acceptable_captures() {
+  int value = 42;
+  int another = 10;
+
+  auto lambda1 = [value](int x) { return value + x; };
+  auto lambda2 = [&value](int x) { return value + x; };
+  auto lambda3 = [value, another](int x) { return value + another + x; };
+  auto lambda4 = [&value, &another](int x) { return value + another + x; };
+
+  auto lambda5 = [](int x, int y) { return x + y; };
+
+  struct S {
+int member = 5;
+void foo() {
+  auto lambda = [this]() { return member; };
+}
+  };
+}
+
+void test_nested_lambdas() {
+  int outer_var = 1;
+  int middle_var = 2;
+  int inner_var = 3;
+
+  auto outer = [=]() {
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+// CHECK-FIXES: auto outer = [outer_var, middle_var, inner_var]() {
+
+auto inner = [&](int x) { return outer_var + middle_var + inner_var + x; };
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+// CHECK-FIXES: auto inner = [&outer_var, &middle_var, &inner_var](int x) 
{ return outer_var + middle_var + inner_var + x; };
+
+return inner(10);
+  };
+}
+
+void test_lambda_returns() {
+  int a = 1, b = 2, c = 3;
+
+  auto create_adder = [=](int x) {
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+// CHECK-FIXES: auto create_adder = [](int x) {
+return [x](int y) { return x + y; }; // Inner lambda is fine - explicit 
capture
+  };
+  
+  auto func1 = [&]() { return a; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto func1 = [&a]() { return a; };
+
+  auto func2 = [=]() { return b; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto func2 = [b]() { return b; };
+}
+
+class TestClass {
+  int member = 42;
+  
+public:
+  void test_member_function_lambdas() {
+int local = 10;
+
+auto lambda1 = [=]() { return member + local; };
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+// CHECK-FIXES: auto lambda1 = [this, local]() { return member + local; };
+
+auto lambda2 = [&]() { return member + local; };
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+// CHECK-FIXES: auto lambda2 = [this, &local]() { return member + local; };
+
+auto lambda3 = [this, local]() { return member + local; };
+auto lambda4 = [this, &local]() { return member + local; };
+  }
+};
+
+// Lambda captures dependent on a template parameter don't have a fix it
+template
+void test_template_lambdas() {
+  T value{};
+  
+  auto lambda = [=](T x) { return value + x; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: lambda default 

[clang] [llvm] [HLSL] Implement the `fwidth` intrinsic for DXIL and SPIR-V target (PR #161378)

2025-10-15 Thread Farzon Lotfi via cfe-commits


@@ -162,6 +162,8 @@ def int_dx_splitdouble : 
DefaultAttrsIntrinsic<[llvm_anyint_ty, LLVMMatchType<0>
 [LLVMScalarOrSameVectorWidth<0, llvm_double_ty>], [IntrNoMem]>;
 def int_dx_radians : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], 
[LLVMMatchType<0>], [IntrNoMem]>;
 def int_dx_discard : DefaultAttrsIntrinsic<[], [llvm_i1_ty], []>;
+def int_dx_deriv_coarse_x : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], 
[LLVMMatchType<0>], [IntrNoMem]>;
+def int_dx_deriv_coarse_y : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], 
[LLVMMatchType<0>], [IntrNoMem]>;

farzonl wrote:

I have concerns with how we are going about this because these need spirv 
implementations and we are half implementing other tickets to make progress on 
fwidth. I kind of feel like fwidth should be blocked until we do these two 
tickets
- https://github.com/llvm/llvm-project/issues/99100
- https://github.com/llvm/llvm-project/issues/99097

https://github.com/llvm/llvm-project/pull/161378
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Headers][X86] Allow AVX512 masked shuffles to be used in constexpr (PR #162301)

2025-10-15 Thread Simon Pilgrim via cfe-commits

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

still quite a few missing tests - and need to avoid using "0xFF" allbits" style 
masks

https://github.com/llvm/llvm-project/pull/162301
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

2025-10-15 Thread JJ Marr via cfe-commits


@@ -0,0 +1,143 @@
+// RUN: %check_clang_tidy %s readability-avoid-default-lambda-capture %t -- -- 
-Wno-vla-extension
+
+void test_default_captures() {
+  int value = 42;
+  int another = 10;
+
+  auto lambda1 = [=](int x) { return value + x; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto lambda1 = [value](int x) { return value + x; };
+
+  auto lambda2 = [&](int x) { return value + x; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto lambda2 = [&value](int x) { return value + x; };
+
+  auto lambda3 = [=, &another](int x) { return value + another + x; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto lambda3 = [value, &another](int x) { return value + 
another + x; };
+
+  auto lambda4 = [&, value](int x) { return value + another + x; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are 
discouraged; prefer to capture specific variables explicitly 
[readability-avoid-default-lambda-capture]
+  // CHECK-FIXES: auto lambda4 = [&another, value](int x) { return value + 
another + x; };
+}
+
+void test_acceptable_captures() {

jjmarr-amd wrote:

My checker handled this case wrong, thanks.

https://github.com/llvm/llvm-project/pull/160150
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Emit debug info with original source location for tokens from macros … (PR #163190)

2025-10-15 Thread David Blaikie via cfe-commits

https://github.com/dwblaikie edited 
https://github.com/llvm/llvm-project/pull/163190
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Avoid use of `CallEvent`s with obsolete state (PR #160707)

2025-10-15 Thread Artem Dergachev via cfe-commits
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy 
Message-ID:
In-Reply-To: 


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

Not really! Everything looks perfect to me!

https://github.com/llvm/llvm-project/pull/160707
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][x86][bytecode] Replace interp__builtin_parity/clrsb/bitreverse/ffs with static bool interp__builtin_elementwise_int_unaryop callback (PR #162346)

2025-10-15 Thread via cfe-commits


@@ -3209,7 +3182,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const CallExpr *Call,
   case Builtin::BI__builtin_ffs:
   case Builtin::BI__builtin_ffsl:
   case Builtin::BI__builtin_ffsll:
-return interp__builtin_ffs(S, OpPC, Frame, Call);
+return interp__builtin_elementwise_int_unaryop(
+S, OpPC, Call, [](const APSInt &Val) {

donneypr wrote:

Just my novice 2 cents: If we're keeping the trailing return type for some of 
the functions eg. `Val.reverseBits()`, I think it would better to add it to all 
of them for uniformity. 

https://github.com/llvm/llvm-project/pull/162346
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [lld] [llvm] [Wasm][Clang] Add support for pointer to externref (PR #163610)

2025-10-15 Thread Hood Chatham via cfe-commits

https://github.com/hoodmane updated 
https://github.com/llvm/llvm-project/pull/163610

>From 8b96ea038cc64e4640c597942534b33a9a899d4f Mon Sep 17 00:00:00 2001
From: Hood Chatham 
Date: Wed, 15 Oct 2025 13:53:50 -0400
Subject: [PATCH] [Wasm][Clang] Add support for pointer to externref

Add support for values of type `__externref_t *`.
We add a special table called `__externref_table`. Loads and stores
to externref pointers are converted to table_get and table_set
instructions using `__externref_table`.

This is a bit tricky because tables are given type array of externref
`__externref_t table[]`. Tables are also not first class values and
most operations don't work on them. However, arrays decay to pointers.
Previously since `__externref_t*` was always illegal, this wasn't a
problem. I dealt with this by preventing arrays from decaying to
pointers if the value type of the array is `__externref_t`.
---
 clang/lib/AST/Type.cpp|  3 -
 clang/lib/Sema/Sema.cpp   |  7 +++
 clang/lib/Sema/SemaExprCXX.cpp| 12 ++--
 clang/lib/Sema/SemaType.cpp   |  7 +--
 .../test/CodeGen/WebAssembly/wasm-externref.c | 40 
 clang/test/Sema/wasm-refs-and-tables.c| 62 +--
 lld/test/wasm/externref-table-defined.s   | 31 ++
 lld/test/wasm/externref-table-undefined.s | 30 +
 lld/wasm/Config.h |  3 +
 lld/wasm/Driver.cpp   |  1 +
 lld/wasm/SymbolTable.cpp  | 43 +
 lld/wasm/SymbolTable.h|  3 +
 lld/wasm/Symbols.cpp  |  1 +
 lld/wasm/Symbols.h|  1 +
 lld/wasm/Writer.cpp   | 11 
 llvm/include/llvm/MC/MCSymbolWasm.h   |  4 ++
 llvm/lib/Object/WasmObjectFile.cpp| 12 +++-
 .../WebAssembly/Utils/WasmAddressSpaces.h |  3 +
 .../WebAssembly/WebAssemblyISelDAGToDAG.cpp   | 43 +
 .../WebAssembly/WebAssemblyUtilities.cpp  | 26 
 .../Target/WebAssembly/WebAssemblyUtilities.h |  4 ++
 .../CodeGen/WebAssembly/externref-load.ll | 13 
 .../CodeGen/WebAssembly/externref-store.ll| 14 +
 23 files changed, 329 insertions(+), 45 deletions(-)
 create mode 100644 lld/test/wasm/externref-table-defined.s
 create mode 100644 lld/test/wasm/externref-table-undefined.s
 create mode 100644 llvm/test/CodeGen/WebAssembly/externref-load.ll
 create mode 100644 llvm/test/CodeGen/WebAssembly/externref-store.ll

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index ee7a68ee8ba7e..48a00d5a8aa12 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2559,9 +2559,6 @@ bool Type::isWebAssemblyTableType() const {
   if (const auto *ATy = dyn_cast(this))
 return ATy->getElementType().isWebAssemblyReferenceType();
 
-  if (const auto *PTy = dyn_cast(this))
-return PTy->getPointeeType().isWebAssemblyReferenceType();
-
   return false;
 }
 
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 39fa25f66f3b7..f1851a7096f80 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -832,6 +832,13 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
 }
   }
 }
+// WebAssembly tables are not first class values and cannot decay to
+// pointers. If they are used anywhere they would decay, it is an error.
+if (ExprTy->isWebAssemblyTableType()) {
+  Diag(E->getExprLoc(), diag::err_wasm_cast_table)
+  << 1 << E->getSourceRange();
+  return ExprError();
+}
   }
 
   if (ImplicitCastExpr *ImpCast = dyn_cast(E)) {
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 0fe242dce45e9..99e12ba0bb936 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4779,12 +4779,16 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 break;
   }
 
-  case ICK_Array_To_Pointer:
+  case ICK_Array_To_Pointer: {
 FromType = Context.getArrayDecayedType(FromType);
-From = ImpCastExprToType(From, FromType, CK_ArrayToPointerDecay, 
VK_PRValue,
- /*BasePath=*/nullptr, CCK)
-   .get();
+auto Expr =
+ImpCastExprToType(From, FromType, CK_ArrayToPointerDecay, VK_PRValue,
+  /*BasePath=*/nullptr, CCK);
+if (Expr.isInvalid())
+  return ExprError();
+From = Expr.get();
 break;
+  }
 
   case ICK_HLSL_Array_RValue:
 if (ToType->isArrayParameterType()) {
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index a9e7c34de94f4..89230071e1bb5 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1837,11 +1837,10 @@ QualType Sema::BuildPointerType(QualType T,
   if (getLangOpts().OpenCL)
 T = deduceOpenCLPointeeAddrSpace(*this, T);
 
-  // In WebAssembly, pointers to reference types and pointers to tables are
-  //

[clang] [Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow AVX512 conflict intrinsics to be used in constexpr (PR #163293)

2025-10-15 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

@chaitanyav Make sure you merge against trunk latest after #163475 drops as it 
will affect your __DEFAULT_FN_ATTRS cleanups

https://github.com/llvm/llvm-project/pull/163293
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Basic] Add helper APIs to get language version codes from LangOptions (PR #163348)

2025-10-15 Thread via cfe-commits

https://github.com/yronglin deleted 
https://github.com/llvm/llvm-project/pull/163348
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enable offloadlib option in SYCL and CL mode (PR #162980)

2025-10-15 Thread via cfe-commits

https://github.com/jinge90 edited 
https://github.com/llvm/llvm-project/pull/162980
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HLSL][SPIR-V] Add `-fspv-enable-maximal-reconvergence` flag to clang dxc. (PR #163474)

2025-10-15 Thread Steven Perron via cfe-commits


@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple spirv1.6-unknown-vulkan1.3-compute 
-fspv-enable-maximal-reconvergence -emit-llvm -o - -O0 %s | FileCheck %s 
--check-prefixes=CHECK
+// RUN: %clang_cc1 -triple spirv1.6-unknown-vulkan1.3-compute -hlsl-entry test 
-fspv-enable-maximal-reconvergence -emit-llvm -o - -O0 %s | FileCheck %s 
--check-prefixes=CHECK-ENTRY
+
+[numthreads(1,1,1)]
+void main() {
+// CHECK: define void @main() [[attributeNumber:#[0-9]+]] {
+}
+
+// CHECK: attributes [[attributeNumber]] = {{.*}} 
"enable-maximal-reconvergence"="true" {{.*}}
+
+
+[numthreads(1,1,1)]
+void test() {
+// CHECK-ENTRY: define void @test() [[attributeNumber:#[0-9]+]] {
+}
+
+// CHECK-ENTRY: attributes [[attributeNumber]] = {{.*}} 
"enable-maximal-reconvergence"="true" {{.*}}

s-perron wrote:

Add the new line at the end of the file.

https://github.com/llvm/llvm-project/pull/163474
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LinkerWrapper] Update deprecated fatbin command line option (PR #163571)

2025-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)


Changes



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


2 Files Affected:

- (modified) clang/test/Driver/linker-wrapper.c (+2-2) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+2-2) 


``diff
diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index 52a961d7b2388..39b9bcd7425ab 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -102,7 +102,7 @@ __attribute__((visibility("protected"), used)) int x;
 
 // CUDA: clang{{.*}} -o [[IMG_SM70:.+]] -dumpdir a.out.nvptx64.sm_70.img. 
--target=nvptx64-nvidia-cuda -march=sm_70
 // CUDA: clang{{.*}} -o [[IMG_SM52:.+]] -dumpdir a.out.nvptx64.sm_52.img. 
--target=nvptx64-nvidia-cuda -march=sm_52
-// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin 
--image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]]
+// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin 
--image3=kind=elf,sm=70,file=[[IMG_SM70]] 
--image3=kind=elf,sm=52,file=[[IMG_SM52]]
 // CUDA: usr/bin/ld{{.*}} {{.*}}.openmp.image.{{.*}}.o 
{{.*}}.cuda.image.{{.*}}.o
 
 // RUN: llvm-offload-binary -o %t.out \
@@ -236,7 +236,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN:   %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=RELOCATABLE-LINK-CUDA
 
 // RELOCATABLE-LINK-CUDA: clang{{.*}} -o {{.*}}.img -dumpdir 
a.out.nvptx64.sm_89.img. --target=nvptx64-nvidia-cuda
-// RELOCATABLE-LINK-CUDA: fatbinary{{.*}} -64 --create {{.*}}.fatbin 
--image=profile=sm_89,file={{.*}}.img
+// RELOCATABLE-LINK-CUDA: fatbinary{{.*}} -64 --create {{.*}}.fatbin 
--image3=kind=elf,sm=89,file={{.*}}.img
 // RELOCATABLE-LINK-CUDA: /usr/bin/ld.lld{{.*}}-r
 // RELOCATABLE-LINK-CUDA: llvm-objcopy{{.*}}a.out --remove-section 
.llvm.offloading
 
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 4d5b956031674..bfeca17d2147e 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -396,8 +396,8 @@ fatbinary(ArrayRef> 
InputFiles,
   CmdArgs.push_back("--create");
   CmdArgs.push_back(*TempFileOrErr);
   for (const auto &[File, Arch] : InputFiles)
-CmdArgs.push_back(
-Args.MakeArgString("--image=profile=" + Arch + ",file=" + File));
+CmdArgs.push_back(Args.MakeArgString(
+"--image3=kind=elf,sm=" + Arch.drop_front(3) + ",file=" + File));
 
   if (Error Err = executeCommands(*FatBinaryPath, CmdArgs))
 return std::move(Err);

``




https://github.com/llvm/llvm-project/pull/163571
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AArch64][llvm] Add support for new vcvt* intrinsics (PR #163572)

2025-10-15 Thread Jonathan Thackray via cfe-commits

https://github.com/jthackray created 
https://github.com/llvm/llvm-project/pull/163572

Add support for these new vcvt* intrinsics:

```
  int64_t  vcvts_s64_f32(float32_t);
  uint64_t vcvts_u64_f32(float32_t);
  int32_t  vcvtd_s32_f64(float64_t);
  uint32_t vcvtd_u32_f64(float64_t);

  int64_t  vcvtns_s64_f32(float32_t);
  uint64_t vcvtns_u64_f32(float32_t);
  int32_t  vcvtnd_s32_f64(float64_t);
  uint32_t vcvtnd_u32_f64(float64_t);

  int64_t  vcvtms_s64_f32(float32_t);
  uint64_t vcvtms_u64_f32(float32_t);
  int32_t  vcvtmd_s32_f64(float64_t);
  uint32_t vcvtmd_u32_f64(float64_t);

  int64_t  vcvtps_s64_f32(float32_t);
  uint64_t vcvtps_u64_f32(float32_t);
  int32_t  vcvtpd_s32_f64(float64_t);
  uint32_t vcvtpd_u32_f64(float64_t);

  int64_t  vcvtas_s64_f32(float32_t);
  uint64_t vcvtas_u64_f32(float32_t);
  int32_t  vcvtad_s32_f64(float64_t);
  uint32_t vcvtad_u32_f64(float64_t);
```

>From 23653d3d12f342c4c45897866f92865bd6aafc5d Mon Sep 17 00:00:00 2001
From: Jonathan Thackray 
Date: Tue, 14 Oct 2025 12:40:51 +0100
Subject: [PATCH] [AArch64][llvm] Add support for new vcvt* intrinsics

Add support for these new vcvt* intrinsics:

```
  int64_t  vcvts_s64_f32(float32_t);
  uint64_t vcvts_u64_f32(float32_t);
  int32_t  vcvtd_s32_f64(float64_t);
  uint32_t vcvtd_u32_f64(float64_t);

  int64_t  vcvtns_s64_f32(float32_t);
  uint64_t vcvtns_u64_f32(float32_t);
  int32_t  vcvtnd_s32_f64(float64_t);
  uint32_t vcvtnd_u32_f64(float64_t);

  int64_t  vcvtms_s64_f32(float32_t);
  uint64_t vcvtms_u64_f32(float32_t);
  int32_t  vcvtmd_s32_f64(float64_t);
  uint32_t vcvtmd_u32_f64(float64_t);

  int64_t  vcvtps_s64_f32(float32_t);
  uint64_t vcvtps_u64_f32(float32_t);
  int32_t  vcvtpd_s32_f64(float64_t);
  uint32_t vcvtpd_u32_f64(float64_t);

  int64_t  vcvtas_s64_f32(float32_t);
  uint64_t vcvtas_u64_f32(float32_t);
  int32_t  vcvtad_s32_f64(float64_t);
  uint32_t vcvtad_u32_f64(float64_t);
```
---
 clang/include/clang/Basic/arm_neon.td |  65 +++--
 clang/lib/CodeGen/TargetBuiltins/ARM.cpp  |  20 ++
 .../CodeGen/AArch64/neon-fcvt-intrinsics.c| 225 +-
 3 files changed, 288 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index ef196103035e8..315c60692dcaf 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1466,26 +1466,51 @@ def SCALAR_UCVTFD : SInst<"vcvt_f64", "(1F)(1!)", 
"SUl">;
 

 // Scalar Floating-point Converts
 def SCALAR_FCVTXN  : IInst<"vcvtx_f32", "(1F<)(1!)", "Sd">;
-def SCALAR_FCVTNSS : SInst<"vcvtn_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTNUS : SInst<"vcvtn_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTNSD : SInst<"vcvtn_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTNUD : SInst<"vcvtn_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTMSS : SInst<"vcvtm_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTMUS : SInst<"vcvtm_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTMSD : SInst<"vcvtm_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTMUD : SInst<"vcvtm_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTASS : SInst<"vcvta_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTAUS : SInst<"vcvta_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTASD : SInst<"vcvta_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTAUD : SInst<"vcvta_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTPSS : SInst<"vcvtp_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTPUS : SInst<"vcvtp_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTPSD : SInst<"vcvtp_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTPUD : SInst<"vcvtp_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTZSS : SInst<"vcvt_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTZUS : SInst<"vcvt_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTZSD : SInst<"vcvt_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTZUD : SInst<"vcvt_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTN_F32toSS  : SInst<"vcvtn_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUS  : SInst<"vcvtn_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSS  : SInst<"vcvtn_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUS  : SInst<"vcvtn_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTN_F32toSD  : SInst<"vcvtn_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUD  : SInst<"vcvtn_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSD  : SInst<"vcvtn_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUD  : SInst<"vcvtn_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTM_F32toSS  : SInst<"vcvtm_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUS  : SInst<"vcvtm_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSS  : SInst<"vcvtm_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUS  : SInst<"vcvtm_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTM_F32toSD  : SInst<"vcvtm_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUD  : SInst<"vcvtm_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSD  : SInst<"vcvtm_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUD  : SInst<"vcvtm_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTA_F32toSS  : SInst<"vcvta_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTA_F32toUS  : SInst<"vcvta_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTA_F64toSS  : SInst<"vcvta_s32", "(1S)1

[clang] [AArch64][llvm] Add support for new vcvt* intrinsics (PR #163572)

2025-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jonathan Thackray (jthackray)


Changes

Add support for these new vcvt* intrinsics:

```
  int64_t  vcvts_s64_f32(float32_t);
  uint64_t vcvts_u64_f32(float32_t);
  int32_t  vcvtd_s32_f64(float64_t);
  uint32_t vcvtd_u32_f64(float64_t);

  int64_t  vcvtns_s64_f32(float32_t);
  uint64_t vcvtns_u64_f32(float32_t);
  int32_t  vcvtnd_s32_f64(float64_t);
  uint32_t vcvtnd_u32_f64(float64_t);

  int64_t  vcvtms_s64_f32(float32_t);
  uint64_t vcvtms_u64_f32(float32_t);
  int32_t  vcvtmd_s32_f64(float64_t);
  uint32_t vcvtmd_u32_f64(float64_t);

  int64_t  vcvtps_s64_f32(float32_t);
  uint64_t vcvtps_u64_f32(float32_t);
  int32_t  vcvtpd_s32_f64(float64_t);
  uint32_t vcvtpd_u32_f64(float64_t);

  int64_t  vcvtas_s64_f32(float32_t);
  uint64_t vcvtas_u64_f32(float32_t);
  int32_t  vcvtad_s32_f64(float64_t);
  uint32_t vcvtad_u32_f64(float64_t);
```

---

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


3 Files Affected:

- (modified) clang/include/clang/Basic/arm_neon.td (+45-20) 
- (modified) clang/lib/CodeGen/TargetBuiltins/ARM.cpp (+20) 
- (modified) clang/test/CodeGen/AArch64/neon-fcvt-intrinsics.c (+223-2) 


``diff
diff --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index ef196103035e8..315c60692dcaf 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1466,26 +1466,51 @@ def SCALAR_UCVTFD : SInst<"vcvt_f64", "(1F)(1!)", 
"SUl">;
 

 // Scalar Floating-point Converts
 def SCALAR_FCVTXN  : IInst<"vcvtx_f32", "(1F<)(1!)", "Sd">;
-def SCALAR_FCVTNSS : SInst<"vcvtn_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTNUS : SInst<"vcvtn_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTNSD : SInst<"vcvtn_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTNUD : SInst<"vcvtn_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTMSS : SInst<"vcvtm_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTMUS : SInst<"vcvtm_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTMSD : SInst<"vcvtm_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTMUD : SInst<"vcvtm_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTASS : SInst<"vcvta_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTAUS : SInst<"vcvta_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTASD : SInst<"vcvta_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTAUD : SInst<"vcvta_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTPSS : SInst<"vcvtp_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTPUS : SInst<"vcvtp_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTPSD : SInst<"vcvtp_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTPUD : SInst<"vcvtp_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTZSS : SInst<"vcvt_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTZUS : SInst<"vcvt_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTZSD : SInst<"vcvt_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTZUD : SInst<"vcvt_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTN_F32toSS  : SInst<"vcvtn_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUS  : SInst<"vcvtn_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSS  : SInst<"vcvtn_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUS  : SInst<"vcvtn_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTN_F32toSD  : SInst<"vcvtn_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUD  : SInst<"vcvtn_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSD  : SInst<"vcvtn_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUD  : SInst<"vcvtn_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTM_F32toSS  : SInst<"vcvtm_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUS  : SInst<"vcvtm_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSS  : SInst<"vcvtm_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUS  : SInst<"vcvtm_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTM_F32toSD  : SInst<"vcvtm_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUD  : SInst<"vcvtm_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSD  : SInst<"vcvtm_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUD  : SInst<"vcvtm_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTA_F32toSS  : SInst<"vcvta_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTA_F32toUS  : SInst<"vcvta_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTA_F64toSS  : SInst<"vcvta_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTA_F64toUS  : SInst<"vcvta_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTA_F32toSD  : SInst<"vcvta_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTA_F32toUD  : SInst<"vcvta_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTA_F64toSD  : SInst<"vcvta_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTA_F64toUD  : SInst<"vcvta_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTP_F32toSS  : SInst<"vcvtp_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTP_F32toUS  : SInst<"vcvtp_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTP_F64toSS  : SInst<"vcvtp_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTP_F64toUS  : SInst<"vcvtp_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTP_F32toSD  : SInst<"vcvtp_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTP_F32toUD  : SInst<"vcvtp_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTP_F64toSD  : SInst<"vcvtp_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTP_F64toUD  : SInst<"vcvtp_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTZ_F32toSS  : SInst<"vcvt_s32", "(1S)1

[clang] [AArch64][llvm] Add support for new vcvt* intrinsics (PR #163572)

2025-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Jonathan Thackray (jthackray)


Changes

Add support for these new vcvt* intrinsics:

```
  int64_t  vcvts_s64_f32(float32_t);
  uint64_t vcvts_u64_f32(float32_t);
  int32_t  vcvtd_s32_f64(float64_t);
  uint32_t vcvtd_u32_f64(float64_t);

  int64_t  vcvtns_s64_f32(float32_t);
  uint64_t vcvtns_u64_f32(float32_t);
  int32_t  vcvtnd_s32_f64(float64_t);
  uint32_t vcvtnd_u32_f64(float64_t);

  int64_t  vcvtms_s64_f32(float32_t);
  uint64_t vcvtms_u64_f32(float32_t);
  int32_t  vcvtmd_s32_f64(float64_t);
  uint32_t vcvtmd_u32_f64(float64_t);

  int64_t  vcvtps_s64_f32(float32_t);
  uint64_t vcvtps_u64_f32(float32_t);
  int32_t  vcvtpd_s32_f64(float64_t);
  uint32_t vcvtpd_u32_f64(float64_t);

  int64_t  vcvtas_s64_f32(float32_t);
  uint64_t vcvtas_u64_f32(float32_t);
  int32_t  vcvtad_s32_f64(float64_t);
  uint32_t vcvtad_u32_f64(float64_t);
```

---

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


3 Files Affected:

- (modified) clang/include/clang/Basic/arm_neon.td (+45-20) 
- (modified) clang/lib/CodeGen/TargetBuiltins/ARM.cpp (+20) 
- (modified) clang/test/CodeGen/AArch64/neon-fcvt-intrinsics.c (+223-2) 


``diff
diff --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index ef196103035e8..315c60692dcaf 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1466,26 +1466,51 @@ def SCALAR_UCVTFD : SInst<"vcvt_f64", "(1F)(1!)", 
"SUl">;
 

 // Scalar Floating-point Converts
 def SCALAR_FCVTXN  : IInst<"vcvtx_f32", "(1F<)(1!)", "Sd">;
-def SCALAR_FCVTNSS : SInst<"vcvtn_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTNUS : SInst<"vcvtn_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTNSD : SInst<"vcvtn_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTNUD : SInst<"vcvtn_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTMSS : SInst<"vcvtm_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTMUS : SInst<"vcvtm_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTMSD : SInst<"vcvtm_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTMUD : SInst<"vcvtm_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTASS : SInst<"vcvta_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTAUS : SInst<"vcvta_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTASD : SInst<"vcvta_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTAUD : SInst<"vcvta_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTPSS : SInst<"vcvtp_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTPUS : SInst<"vcvtp_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTPSD : SInst<"vcvtp_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTPUD : SInst<"vcvtp_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTZSS : SInst<"vcvt_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTZUS : SInst<"vcvt_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTZSD : SInst<"vcvt_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTZUD : SInst<"vcvt_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTN_F32toSS  : SInst<"vcvtn_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUS  : SInst<"vcvtn_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSS  : SInst<"vcvtn_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUS  : SInst<"vcvtn_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTN_F32toSD  : SInst<"vcvtn_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUD  : SInst<"vcvtn_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSD  : SInst<"vcvtn_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUD  : SInst<"vcvtn_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTM_F32toSS  : SInst<"vcvtm_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUS  : SInst<"vcvtm_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSS  : SInst<"vcvtm_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUS  : SInst<"vcvtm_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTM_F32toSD  : SInst<"vcvtm_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUD  : SInst<"vcvtm_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSD  : SInst<"vcvtm_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUD  : SInst<"vcvtm_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTA_F32toSS  : SInst<"vcvta_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTA_F32toUS  : SInst<"vcvta_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTA_F64toSS  : SInst<"vcvta_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTA_F64toUS  : SInst<"vcvta_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTA_F32toSD  : SInst<"vcvta_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTA_F32toUD  : SInst<"vcvta_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTA_F64toSD  : SInst<"vcvta_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTA_F64toUD  : SInst<"vcvta_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTP_F32toSS  : SInst<"vcvtp_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTP_F32toUS  : SInst<"vcvtp_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTP_F64toSS  : SInst<"vcvtp_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTP_F64toUS  : SInst<"vcvtp_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTP_F32toSD  : SInst<"vcvtp_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTP_F32toUD  : SInst<"vcvtp_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTP_F64toSD  : SInst<"vcvtp_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTP_F64toUD  : SInst<"vcvtp_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTZ_F32toSS  : SInst<"vcvt_s32"

[clang] [HLSL] Allow input semantics on structs (PR #159047)

2025-10-15 Thread Chris B via cfe-commits
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= 
Message-ID:
In-Reply-To: 



@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-pixel -x hlsl 
-finclude-default-header -o - %s -ast-dump | FileCheck %s
 
-float4 main(float4 a : SV_Position) {
+float4 main(float4 a : SV_Position2) {

llvm-beanz wrote:

This code is technically invalid right? It should require a semantic on the 
return type.

Since this is an area you're actively working on I think it is fine to have a 
test that includes invalid code, but we should put a comment in the test 
identifying that it is invalid and maybe link to an issue that will resolve it 
so that we can associate the fix correctly.

https://github.com/llvm/llvm-project/pull/159047
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [libc] [libcxx] [lld] [lldb] [llvm] [mlir] [openmp] [polly] Python-related cleanups (PR #163566)

2025-10-15 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

Relevant PEP: https://peps.python.org/pep-0394/

To quote:
"For scripts that are only expected to be run in an activated virtual 
environment, shebang lines can be written as #!/usr/bin/env python, as this 
instructs the script to respect the active virtual environment."

So I'm not sure the shebang for venvs should be changed to python3.

Mote over, this may have pretty big implications since the implementation of 
these commands 8s very inconsistent across platforms and no common rules seem 
to exist.
Some platforms have `python` that aliases to `python3`, some alias it to 
`python2`, some only have `python` etc. so I'm not convinced it's a good idea 
to just change these broadly without considering possible platform specific 
requirements 

https://github.com/llvm/llvm-project/pull/163566
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [compiler-rt] [libc] [libcxx] [lld] [lldb] [llvm] [mlir] [openmp] [polly] Python-related cleanups (PR #163566)

2025-10-15 Thread David Spickett via cfe-commits

DavidSpickett wrote:

> This suggests that the polly/utils scripts haven't been ran by anyone for 
> quite some time.

Yes, this makes sense. I tried "vermin" on it and it reports the same lines as 
not being python3 compatible. You can exclude the Polly changes.

> The PYTHON_EXECUTABLE and the shebang cleanups are entirely unrelated except 
> by theme, I can split them it that would make things easier.

Yes please. Even if it doesn't fix your use case in itself, if it's explainable 
on its own, we can review it as is.

https://github.com/llvm/llvm-project/pull/163566
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Matrix][Clang][HLSL] Move MaxMatrixDimension to a LangOpt (PR #163307)

2025-10-15 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/163307

>From 30a88ad2539c83473da70b7dd083ae4974eb3a57 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Mon, 13 Oct 2025 21:50:45 -0400
Subject: [PATCH 1/3] [NFC][Matrix][Clang][HLSL] Move MaxMatrixDimension to a
 LangOpt

fixes #160190

This change just makes MaxMatrixDimension configurable by language mode.
It was previously introduced in 
https://github.com/llvm/llvm-project/commit/94b43118e2203fed8ca0377ae762c08189aa6f3d
when there was not a need to make dimensions configurable.

Current testing to this effect exists in:
- clang/test/Sema/matrix-type-builtins.c
- clang/test/SemaCXX/matrix-type-builtins.cpp
- clang/test/SemaHLSL/BuiltIns/matrix-basic_types-errors.hlsl

I considered adding a driver flag to `clang/include/clang/Driver/Options.td`
but HLSL matrix max dim is always 4 so we don't need this configurable
beyond that size for our use case.
---
 clang/include/clang/AST/TypeBase.h| 12 
 clang/include/clang/Basic/LangOptions.def |  1 +
 clang/lib/AST/ASTContext.cpp  |  4 ++--
 clang/lib/Basic/LangOptions.cpp   |  8 ++--
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  3 ++-
 clang/lib/Sema/SemaChecking.cpp   |  4 ++--
 clang/lib/Sema/SemaType.cpp   |  4 ++--
 7 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/AST/TypeBase.h 
b/clang/include/clang/AST/TypeBase.h
index 625cc77dc1f08..5c51ec52daed3 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -4378,8 +4378,6 @@ class ConstantMatrixType final : public MatrixType {
   unsigned NumRows;
   unsigned NumColumns;
 
-  static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1;
-
   ConstantMatrixType(QualType MatrixElementType, unsigned NRows,
  unsigned NColumns, QualType CanonElementType);
 
@@ -4398,16 +4396,6 @@ class ConstantMatrixType final : public MatrixType {
 return getNumRows() * getNumColumns();
   }
 
-  /// Returns true if \p NumElements is a valid matrix dimension.
-  static constexpr bool isDimensionValid(size_t NumElements) {
-return NumElements > 0 && NumElements <= MaxElementsPerDimension;
-  }
-
-  /// Returns the maximum number of elements per dimension.
-  static constexpr unsigned getMaxElementsPerDimension() {
-return MaxElementsPerDimension;
-  }
-
   void Profile(llvm::FoldingSetNodeID &ID) {
 Profile(ID, getElementType(), getNumRows(), getNumColumns(),
 getTypeClass());
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 9e850089ad87f..690439c1258c1 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -432,6 +432,7 @@ ENUM_LANGOPT(RegisterStaticDestructors, 
RegisterStaticDestructorsKind, 2,
 LANGOPT(RegCall4, 1, 0, NotCompatible, "Set __regcall4 as a default calling 
convention to respect __regcall ABI v.4")
 
 LANGOPT(MatrixTypes, 1, 0, NotCompatible, "Enable or disable the builtin 
matrix type")
+VALUE_LANGOPT(MaxMatrixDimension, 32, (1 << 20) - 1, NotCompatible, "maximum 
allowed matrix dimension")
 
 LANGOPT(CXXAssumptions, 1, 1, NotCompatible, "Enable or disable codegen and 
compile-time checks for C++23's [[assume]] attribute")
 
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a8b41ba18fa01..fa363bc6fea7c 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4713,8 +4713,8 @@ QualType ASTContext::getConstantMatrixType(QualType 
ElementTy, unsigned NumRows,
 
   assert(MatrixType::isValidElementType(ElementTy) &&
  "need a valid element type");
-  assert(ConstantMatrixType::isDimensionValid(NumRows) &&
- ConstantMatrixType::isDimensionValid(NumColumns) &&
+  assert(NumRows > 0 && NumRows <= LangOpts.MaxMatrixDimension &&
+ NumColumns > 0 && NumColumns <= LangOpts.MaxMatrixDimension &&
  "need valid matrix dimensions");
   void *InsertPos = nullptr;
   if (ConstantMatrixType *MTP = MatrixTypes.FindNodeOrInsertPos(ID, InsertPos))
diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp
index f034514466d3f..4f5d20d946de8 100644
--- a/clang/lib/Basic/LangOptions.cpp
+++ b/clang/lib/Basic/LangOptions.cpp
@@ -131,8 +131,12 @@ void LangOptions::setLangDefaults(LangOptions &Opts, 
Language Lang,
   Opts.NamedLoops = Std.isC2y();
 
   Opts.HLSL = Lang == Language::HLSL;
-  if (Opts.HLSL && Opts.IncludeDefaultHeader)
-Includes.push_back("hlsl.h");
+  if (Opts.HLSL) {
+if (Opts.IncludeDefaultHeader)
+  Includes.push_back("hlsl.h");
+// Set maximum matrix dimension to 4 for HLSL
+Opts.MaxMatrixDimension = 4;
+  }
 
   // Set OpenCL Version.
   Opts.OpenCL = Std.isOpenCL();
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index e118dda4780e2..81c836fe60452 100644
--- a/clang/lib/

[clang] [llvm] [AArch64] Add intrinsics support for SVE2p2 instructions (PR #163575)

2025-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Lukacma)


Changes

This patch add intrinsics for SVE2p2 instructions defined in 
[this](https://github.com/ARM-software/acle/pull/412) ACLE proposal

---

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


10 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+11-1) 
- (modified) clang/test/CodeGen/AArch64/sve-intrinsics/acle_sve_compact.c (+6) 
- (added) clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_compact.c 
(+142) 
- (added) clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_expand.c 
(+243) 
- (added) clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_firstp.c 
(+101) 
- (added) clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_lastp.c 
(+101) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+3) 
- (modified) llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td (+3-3) 
- (modified) llvm/lib/Target/AArch64/SVEInstrFormats.td (+10-8) 
- (modified) llvm/test/CodeGen/AArch64/sve2p2-intrinsics.ll (+173) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index d2b7b78b9970f..716c2cd68ffcc 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -984,6 +984,11 @@ let SMETargetGuard = "sme2p2" in {
 def SVCOMPACT : SInst<"svcompact[_{d}]", "dPd",  "ilUiUlfd", MergeNone, 
"aarch64_sve_compact", [VerifyRuntimeMode]>;
 }
 
+let SVETargetGuard = "sve2p2|sme2p2",  SMETargetGuard = "sme2p2" in {
+def SVCOMPACT_BH : SInst<"svcompact[_{d}]", "dPd",  "cUcsUsmbh", MergeNone, 
"aarch64_sve_compact", [VerifyRuntimeMode]>;
+def SVEXPAND  : SInst<"svexpand[_{d}]",  "dPd",  "cUcsUsiUilUlmbhfd", 
MergeNone, "aarch64_sve_expand",  [VerifyRuntimeMode]>;
+}
+
 // Note: svdup_lane is implemented using the intrinsic for TBL to represent a
 // splat of any possible lane. It is upto LLVM to pick a more efficient
 // instruction such as DUP (indexed) if the lane index fits the range of the
@@ -,6 +1116,11 @@ def SVCNTD : SInst<"svcntd", "nv", "", MergeNone, 
"aarch64_sve_cntd", [IsAppendS
 def SVCNTP : SInst<"svcntp_{d}",  "nPP", "PcPsPiPl", MergeNone, 
"aarch64_sve_cntp", [VerifyRuntimeMode]>;
 def SVLEN  : SInst<"svlen[_{d}]", "nd",  "csilUcUsUiUlhfdb", MergeNone, "", 
[VerifyRuntimeMode]>;
 
+let SVETargetGuard = "sve2p2|sme2p2",  SMETargetGuard = "sve2p2|sme2p2" in {
+  def SVFIRSTP  : SInst<"svfirstp_{d}", "lPP", "PcPsPiPl", MergeNone, 
"aarch64_sve_firstp", [VerifyRuntimeMode], []>;
+  def SVLASTP  : SInst<"svlastp_{d}", "lPP", "PcPsPiPl", MergeNone, 
"aarch64_sve_lastp", [VerifyRuntimeMode], []>;
+}
+
 

 // Saturating scalar arithmetic
 
@@ -2388,4 +2398,4 @@ let SVETargetGuard = "sve2,fp8fma", SMETargetGuard = 
"ssve-fp8fma" in {
   def SVFMLALLBT_LANE : SInst<"svmlallbt_lane[_f32_mf8]", "dd~~i>", "f", 
MergeNone, "aarch64_sve_fp8_fmlallbt_lane", [VerifyRuntimeMode], [ImmCheck<3, 
ImmCheck0_7>]>;
   def SVFMLALLTB_LANE : SInst<"svmlalltb_lane[_f32_mf8]", "dd~~i>", "f", 
MergeNone, "aarch64_sve_fp8_fmlalltb_lane", [VerifyRuntimeMode], [ImmCheck<3, 
ImmCheck0_7>]>;
   def SVFMLALLTT_LANE : SInst<"svmlalltt_lane[_f32_mf8]", "dd~~i>", "f", 
MergeNone, "aarch64_sve_fp8_fmlalltt_lane", [VerifyRuntimeMode], [ImmCheck<3, 
ImmCheck0_7>]>;
-}
+}
\ No newline at end of file
diff --git a/clang/test/CodeGen/AArch64/sve-intrinsics/acle_sve_compact.c 
b/clang/test/CodeGen/AArch64/sve-intrinsics/acle_sve_compact.c
index 4c18969e78f0c..75ee18cb134d7 100644
--- a/clang/test/CodeGen/AArch64/sve-intrinsics/acle_sve_compact.c
+++ b/clang/test/CodeGen/AArch64/sve-intrinsics/acle_sve_compact.c
@@ -14,6 +14,12 @@
 #define SVE_ACLE_FUNC(A1,A2,A3,A4) A1##A2##A3##A4
 #endif
 
+#ifdef __ARM_FEATURE_SME
+#define STREAMING __arm_streaming
+#else
+#define STREAMING
+#endif
+
 // CHECK-LABEL: @test_svcompact_s32(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[PG:%.*]])
diff --git a/clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_compact.c 
b/clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_compact.c
new file mode 100644
index 0..8bee2ed1121a6
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_compact.c
@@ -0,0 +1,142 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sve -target-feature 
+sve2p2 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature 
+sme2p2 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sve -targ

[clang] [HLSL] Allow input semantics on structs (PR #159047)

2025-10-15 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

> We should have tests for some cases like:
> 
> ```
> struct S {
>   float4 f0 : SV_Position;
>   float4 f1;  // error due to missing semantic here!
> };
> 
> float4 main(S s) { }
> 
> // Semantics on return objects are required but not supported yet (right?)
> float4 main2(float4 p : SV_POSITION, float4 f) { } // error for missing 
> semantic on `f`
> ```

Yes, I'll add several sema checks now that those are validated in sema.

https://github.com/llvm/llvm-project/pull/159047
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 16dfd31 - [llvm] Fix C++23 error in ParentMapContext (#163553)

2025-10-15 Thread via cfe-commits

Author: Victor Vianna
Date: 2025-10-15T17:25:46+02:00
New Revision: 16dfd317f38ebfc0bd39a5e20e2a8851daa4f8b8

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

LOG: [llvm] Fix C++23 error in ParentMapContext (#163553)

ParentMapContext::ParentMapContext(ASTContext &Ctx) instantiates
~unique_ptr, so it must be defined after
that class is a complete type.

Co-authored-by: Victor Hugo Vianna Silva 

Added: 


Modified: 
clang/lib/AST/ParentMapContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ParentMapContext.cpp 
b/clang/lib/AST/ParentMapContext.cpp
index acc011cb2faa4..7138dffb46e19 100644
--- a/clang/lib/AST/ParentMapContext.cpp
+++ b/clang/lib/AST/ParentMapContext.cpp
@@ -20,36 +20,6 @@
 
 using namespace clang;
 
-ParentMapContext::ParentMapContext(ASTContext &Ctx) : ASTCtx(Ctx) {}
-
-ParentMapContext::~ParentMapContext() = default;
-
-void ParentMapContext::clear() { Parents.reset(); }
-
-const Expr *ParentMapContext::traverseIgnored(const Expr *E) const {
-  return traverseIgnored(const_cast(E));
-}
-
-Expr *ParentMapContext::traverseIgnored(Expr *E) const {
-  if (!E)
-return nullptr;
-
-  switch (Traversal) {
-  case TK_AsIs:
-return E;
-  case TK_IgnoreUnlessSpelledInSource:
-return E->IgnoreUnlessSpelledInSource();
-  }
-  llvm_unreachable("Invalid Traversal type!");
-}
-
-DynTypedNode ParentMapContext::traverseIgnored(const DynTypedNode &N) const {
-  if (const auto *E = N.get()) {
-return DynTypedNode::create(*traverseIgnored(E));
-  }
-  return N;
-}
-
 template 
 static std::tuple
 matchParents(const DynTypedNodeList &NodeList,
@@ -334,6 +304,36 @@ matchParents(const DynTypedNodeList &NodeList,
   return MatchParents::match(NodeList, ParentMap);
 }
 
+ParentMapContext::ParentMapContext(ASTContext &Ctx) : ASTCtx(Ctx) {}
+
+ParentMapContext::~ParentMapContext() = default;
+
+void ParentMapContext::clear() { Parents.reset(); }
+
+const Expr *ParentMapContext::traverseIgnored(const Expr *E) const {
+  return traverseIgnored(const_cast(E));
+}
+
+Expr *ParentMapContext::traverseIgnored(Expr *E) const {
+  if (!E)
+return nullptr;
+
+  switch (Traversal) {
+  case TK_AsIs:
+return E;
+  case TK_IgnoreUnlessSpelledInSource:
+return E->IgnoreUnlessSpelledInSource();
+  }
+  llvm_unreachable("Invalid Traversal type!");
+}
+
+DynTypedNode ParentMapContext::traverseIgnored(const DynTypedNode &N) const {
+  if (const auto *E = N.get()) {
+return DynTypedNode::create(*traverseIgnored(E));
+  }
+  return N;
+}
+
 /// Template specializations to abstract away from pointers and TypeLocs.
 /// @{
 template  static DynTypedNode createDynTypedNode(const T &Node) {



___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Matrix][Clang][HLSL] Move MaxMatrixDimension to a LangOpt (PR #163307)

2025-10-15 Thread Chris B via cfe-commits

https://github.com/llvm-beanz approved this pull request.

This looks reasonable to me. I've suggested a few extra test cases to consider. 
It looks like the C++ matrix dimensions are reasonably well covered over in 
https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/matrix-type.cpp.

https://github.com/llvm/llvm-project/pull/163307
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][DebugInfo] Emit DW_AT_language_name for DWARFv6 (PR #163208)

2025-10-15 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/163208

>From 8e29980ab1af05245ad24762bc5a05e41d7ffcb7 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 7 Oct 2025 11:56:22 +0100
Subject: [PATCH 1/3] [llvm][DebugInfo] [llvm][DebugInfo] Add
 'sourceLanguageVersion' field support to DICompileUnit

(cherry picked from commit 2a2bd988b47e8772312c22681f97bbf528898f88)
---
 llvm/lib/AsmParser/LLParser.cpp   |  8 +-
 llvm/lib/Bitcode/Reader/MetadataLoader.cpp|  6 +++--
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |  1 +
 llvm/lib/IR/AsmWriter.cpp | 11 +---
 .../dicompileunit-invalid-language-version.ll | 25 +++
 .../Bitcode/dwarf-source-language-version.ll  | 17 +
 6 files changed, 62 insertions(+), 6 deletions(-)
 create mode 100644 
llvm/test/Assembler/dicompileunit-invalid-language-version.ll
 create mode 100644 llvm/test/Bitcode/dwarf-source-language-version.ll

diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 7a3cd83cdd887..cf6328580fd21 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -5876,6 +5876,7 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool 
IsDistinct) {
   REQUIRED(file, MDField, (/* AllowNull */ false));
\
   OPTIONAL(language, DwarfLangField, );
\
   OPTIONAL(sourceLanguageName, DwarfSourceLangNameField, );
\
+  OPTIONAL(sourceLanguageVersion, MDUnsignedField, (0, UINT32_MAX));   
\
   OPTIONAL(producer, MDStringField, ); 
\
   OPTIONAL(isOptimized, MDBoolField, );
\
   OPTIONAL(flags, MDStringField, );
\
@@ -5905,10 +5906,15 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool 
IsDistinct) {
 return error(Loc, "can only specify one of 'language' and "
   "'sourceLanguageName' on !DICompileUnit");
 
+  if (sourceLanguageVersion.Seen && !sourceLanguageName.Seen)
+return error(Loc, "'sourceLanguageVersion' requires an associated "
+  "'sourceLanguageName' on !DICompileUnit");
+
   Result = DICompileUnit::getDistinct(
   Context,
   language.Seen ? DISourceLanguageName(language.Val)
-: DISourceLanguageName(sourceLanguageName.Val, 0),
+: DISourceLanguageName(sourceLanguageName.Val,
+   sourceLanguageVersion.Val),
   file.Val, producer.Val, isOptimized.Val, flags.Val, runtimeVersion.Val,
   splitDebugFilename.Val, emissionKind.Val, enums.Val, retainedTypes.Val,
   globals.Val, imports.Val, macros.Val, dwoId.Val, splitDebugInlining.Val,
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp 
b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index cdcf7a80ffac7..ed0443f599a44 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -1860,7 +1860,7 @@ Error 
MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
 break;
   }
   case bitc::METADATA_COMPILE_UNIT: {
-if (Record.size() < 14 || Record.size() > 22)
+if (Record.size() < 14 || Record.size() > 23)
   return error("Invalid record");
 
 // Ignore Record[0], which indicates whether this compile unit is
@@ -1869,11 +1869,13 @@ Error 
MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
 
 const auto LangVersionMask = (uint64_t(1) << 63);
 const bool HasVersionedLanguage = Record[1] & LangVersionMask;
+const uint32_t LanguageVersion = Record.size() > 22 ? Record[22] : 0;
 
 auto *CU = DICompileUnit::getDistinct(
 Context,
 HasVersionedLanguage
-? DISourceLanguageName(Record[1] & ~LangVersionMask, 0)
+? DISourceLanguageName(Record[1] & ~LangVersionMask,
+   LanguageVersion)
 : DISourceLanguageName(Record[1]),
 getMDOrNull(Record[2]), getMDString(Record[3]), Record[4],
 getMDString(Record[5]), Record[6], getMDString(Record[7]), Record[8],
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp 
b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 54e916e2dcfe1..8ff3aa9817571 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -2142,6 +2142,7 @@ void ModuleBitcodeWriter::writeDICompileUnit(const 
DICompileUnit *N,
   Record.push_back(N->getRangesBaseAddress());
   Record.push_back(VE.getMetadataOrNullID(N->getRawSysRoot()));
   Record.push_back(VE.getMetadataOrNullID(N->getRawSDK()));
+  Record.push_back(Lang.hasVersionedName() ? Lang.getVersion() : 0);
 
   Stream.EmitRecord(bitc::METADATA_COMPILE_UNIT, Record, Abbrev);
   Record.clear();
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 2430d988ddb04..3908a78f48412 100644
--- a/llvm/lib/IR/

[clang] [llvm] [clang][DebugInfo] Emit DW_AT_language_name for DWARFv6 (PR #163208)

2025-10-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-clang

Author: Michael Buch (Michael137)


Changes

Depends on:
* https://github.com/llvm/llvm-project/pull/163348
* https://github.com/llvm/llvm-project/pull/162632

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


11 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+104-30) 
- (added) clang/test/DebugInfo/CXX/versioned-language.cpp (+23) 
- (added) clang/test/DebugInfo/Generic/versioned-language.c (+17) 
- (added) clang/test/DebugInfo/ObjC/versioned-language.m (+9) 
- (added) clang/test/DebugInfo/ObjCXX/versioned-language.mm (+9) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+7-1) 
- (modified) llvm/lib/Bitcode/Reader/MetadataLoader.cpp (+4-2) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+1) 
- (modified) llvm/lib/IR/AsmWriter.cpp (+8-3) 
- (added) llvm/test/Assembler/dicompileunit-invalid-language-version.ll (+25) 
- (added) llvm/test/Bitcode/dwarf-source-language-version.ll (+17) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 9fe9a13610296..79079ccb216cd 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -41,8 +41,10 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
@@ -647,6 +649,77 @@ StringRef CGDebugInfo::getCurrentDirname() {
   return CGM.getCodeGenOpts().DebugCompilationDir;
 }
 
+static llvm::dwarf::SourceLanguage GetSourceLanguage(const CodeGenModule &CGM) 
{
+  const CodeGenOptions &CGO = CGM.getCodeGenOpts();
+  const LangOptions &LO = CGM.getLangOpts();
+
+  assert(CGO.DwarfVersion <= 5);
+
+  llvm::dwarf::SourceLanguage LangTag;
+  if (LO.CPlusPlus) {
+if (LO.ObjC)
+  LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
+else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
+else if (LO.CPlusPlus14)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
+else if (LO.CPlusPlus11)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
+else
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
+  } else if (LO.ObjC) {
+LangTag = llvm::dwarf::DW_LANG_ObjC;
+  } else if (LO.OpenCL && (!CGO.DebugStrictDwarf || CGO.DwarfVersion >= 5)) {
+LangTag = llvm::dwarf::DW_LANG_OpenCL;
+  } else if (LO.C11 && !(CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)) {
+LangTag = llvm::dwarf::DW_LANG_C11;
+  } else if (LO.C99) {
+LangTag = llvm::dwarf::DW_LANG_C99;
+  } else {
+LangTag = llvm::dwarf::DW_LANG_C89;
+  }
+
+  return LangTag;
+}
+
+static std::pair
+GetSourceLanguageName(const CodeGenModule &CGM) {
+  const CodeGenOptions &CGO = CGM.getCodeGenOpts();
+  const LangOptions &LO = CGM.getLangOpts();
+
+  assert(CGO.DwarfVersion >= 6);
+
+  uint32_t LangVersion = 0;
+  llvm::dwarf::SourceLanguageName LangTag;
+  if (LO.CPlusPlus) {
+if (LO.ObjC) {
+  LangTag = llvm::dwarf::DW_LNAME_ObjC_plus_plus;
+} else {
+  LangTag = llvm::dwarf::DW_LNAME_C_plus_plus;
+  LangVersion = LO.getCPlusPlusLangStd().value_or(0);
+}
+  } else if (LO.ObjC) {
+LangTag = llvm::dwarf::DW_LNAME_ObjC;
+  } else if (LO.OpenCL) {
+LangTag = llvm::dwarf::DW_LNAME_OpenCL_C;
+  } else {
+LangTag = llvm::dwarf::DW_LNAME_C;
+LangVersion = LO.getCLangStd().value_or(0);
+  }
+
+  return {LangTag, LangVersion};
+}
+
+static llvm::DISourceLanguageName
+GetDISourceLanguageName(const CodeGenModule &CGM) {
+  // Emit pre-DWARFv6 language codes.
+  if (CGM.getCodeGenOpts().DwarfVersion < 6)
+return llvm::DISourceLanguageName(GetSourceLanguage(CGM));
+
+  auto [LName, LVersion] = GetSourceLanguageName(CGM);
+  return llvm::DISourceLanguageName(LName, LVersion);
+}
+
 void CGDebugInfo::CreateCompileUnit() {
   SmallString<64> Checksum;
   std::optional CSKind;
@@ -702,31 +775,6 @@ void CGDebugInfo::CreateCompileUnit() {
 }
   }
 
-  llvm::dwarf::SourceLanguage LangTag;
-  if (LO.CPlusPlus) {
-if (LO.ObjC)
-  LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
-else if (LO.CPlusPlus14)
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11)
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
-else
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
-  } else if (LO.ObjC) {
-LangTag = llvm::dwarf::DW_LANG_ObjC;
-  } else if (LO.OpenCL && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
-   CGM.getCodeGenOpts().DwarfVersion >= 5)) {
-LangTag = llvm::dwarf::DW_LANG_OpenCL;
-  } else if (LO.C11 && !(CGO.DebugStrictDwarf && CGO.DwarfVersio

[clang] [llvm] [clang][DebugInfo] Emit DW_AT_language_{name, version} for DWARFv6 (PR #163208)

2025-10-15 Thread Michael Buch via cfe-commits

https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/163208
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Add intrinsics support for SVE2p2 instructions (PR #163575)

2025-10-15 Thread Jonathan Thackray via cfe-commits

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

LGTM

https://github.com/llvm/llvm-project/pull/163575
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang][DebugInfo] Emit DW_AT_language_version for DWARFv6 (PR #163208)

2025-10-15 Thread Michael Buch via cfe-commits

https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/163208
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Emit debug info with original source location for tokens from macros … (PR #163190)

2025-10-15 Thread via cfe-commits

https://github.com/SergejSalnikov edited 
https://github.com/llvm/llvm-project/pull/163190
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] PowerPC: Support Atomic Memory Operations in Inline Asm (PR #163616)

2025-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-powerpc

Author: Kamau Bridgeman (kamaub)


Changes

Support atomic memory operations by enabling `P` argument modified `Q`
constrained inputs to inline assembly memory operations.
Constraint Q was not defined as a C_Memory constraint type in the
PowerPC backend.
The `P` constraint argument modifier is an GCC extended inline asm feature that
has been observed to translate to an X-Form [Reg] register allocation and
address mode encoding. i.e `ldx R, %P, R == ldx 
r3, r1, r2`.
This allows users to modify the default addressing mode, D-Form,
to X-Form for `Q`, `m`, and `Z`, inline asm constraint types.
These constraints produce `([reg])` otherwise.
References: 

1. https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
2. 
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Generic-Operand-Modifiers
3. https://llvm.org/docs/LangRef.html#asm-template-argument-modifiers


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


4 Files Affected:

- (added) clang/test/CodeGen/PowerPC/inline-asm-constraints.c (+29) 
- (modified) llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp (+18-2) 
- (modified) llvm/lib/Target/PowerPC/PPCISelLowering.cpp (+1) 
- (added) llvm/test/CodeGen/PowerPC/inline-asm-constraints.ll (+21) 


``diff
diff --git a/clang/test/CodeGen/PowerPC/inline-asm-constraints.c 
b/clang/test/CodeGen/PowerPC/inline-asm-constraints.c
new file mode 100644
index 0..1464500359046
--- /dev/null
+++ b/clang/test/CodeGen/PowerPC/inline-asm-constraints.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -emit-llvm -triple powerpc64-ibm-aix-xcoff \
+// RUN:   %s -o - | FileCheck %s
+
+#include 
+
+// Test Atomic Memory Operation Support:
+// This test case takes an address and performs an atomic load at that address.
+// The purpose is to test the Q machine constraint and P machine constraint
+// argument modifier together.
+// These constraints on the pointer `ptr` read as: constrain (uint32_t*)ptr to
+// read and writeable X-Form Addressed Memory operands.
+static __attribute__((noinline))
+uint32_t atomic_load(uint32_t *ptr, uint32_t val)
+{
+// CHECK-LABEL: define{{.*}} i32 @atomic_load(ptr noundef %ptr, i32 noundef 
zeroext %val)
+// CHECK:  %3 = call { i128, i32 } asm sideeffect "mr ${1:L},$3\0A\09 lwat 
$1,${0:P},$4\0A\09 mr $2,$1\0A", "=*Q,=&r,=r,r,n,0"(ptr elementtype(i32) 
%arrayidx, i32 %2, i32 0, i32 %1)
+  unsigned __int128 tmp;
+  uint32_t ret;
+  __asm__ volatile ("mr %L1,%3\n"
+"\t lwat %1,%P0,%4\n"
+"\t mr %2,%1\n"
+: "+Q" (ptr[0]), "=&r" (tmp), "=r" (ret)
+: "r" (val), "n" (0x00));
+  return ret;
+}
+
+int main(int argc, char **argv) {
+   return atomic_load((uint32_t*)argv[1], (uint32_t)*(argv[2]));
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp 
b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index bcb3f507e98d6..2e31ea7392aeb 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -411,11 +411,24 @@ bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr 
*MI, unsigned OpNo,
 bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned 
OpNo,
   const char *ExtraCode,
   raw_ostream &O) {
+  auto reportAsmMemError = [&] (StringRef errMsg) {
+const char *AsmStr = MI->getOperand(0).getSymbolName();
+const MDNode *LocMD = MI->getLocCookieMD();
+uint64_t LocCookie = LocMD ?
+ mdconst::extract(LocMD->getOperand(0))->getZExtValue() : 0;
+const Function &Fn = MI->getMF()->getFunction();
+Fn.getContext().diagnose(DiagnosticInfoInlineAsm(
+LocCookie, errMsg + Twine(AsmStr) + "'"));
+return true;
+  };
   if (ExtraCode && ExtraCode[0]) {
-if (ExtraCode[1] != 0) return true; // Unknown modifier.
+if (ExtraCode[1] != 0)
+  return reportAsmMemError("Unknown modifier in inline asm:");
 
 switch (ExtraCode[0]) {
-default: return true;  // Unknown modifier.
+default: {
+  return reportAsmMemError("Unknown modifier in inline asm:");
+}
 case 'L': // A memory reference to the upper word of a double word op.
   O << getDataLayout().getPointerSize() << "(";
   printOperand(MI, OpNo, O);
@@ -425,6 +438,9 @@ bool PPCAsmPrinter::PrintAsmMemoryOperand(const 
MachineInstr *MI, unsigned OpNo,
   O << "0, ";
   printOperand(MI, OpNo, O);
   return false;
+case 'P': // A memory reference for an single inout to an X-form instr.
+  printOperand(MI, OpNo, O);
+  return false;
 case 'I':
   // Write 'i' if an integer constant, otherwise nothing.  Used to print
   // addi vs add, etc.
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index 8bf0d118da575..de26677c161d1 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowe

[clang] [Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - Allow AVX512 conflict intrinsics to be used in constexpr (PR #163293)

2025-10-15 Thread NagaChaitanya Vellanki via cfe-commits

https://github.com/chaitanyav updated 
https://github.com/llvm/llvm-project/pull/163293

>From 9e2b1aab5e48c69b7ad7c0e5c10d8809c218b71e Mon Sep 17 00:00:00 2001
From: NagaChaitanya Vellanki 
Date: Sun, 12 Oct 2025 02:19:26 -0700
Subject: [PATCH] [Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin
 - Allow AVX512 conflict intrinsics to be used in constexpr

Resolves #160524
---
 clang/include/clang/Basic/BuiltinsX86.td |  14 +-
 clang/lib/AST/ByteCode/InterpBuiltin.cpp |  35 -
 clang/lib/AST/ExprConstant.cpp   |  31 
 clang/lib/Headers/avx512cdintrin.h   |  81 +-
 clang/lib/Headers/avx512vlcdintrin.h | 149 ---
 clang/test/CodeGen/X86/avx512cd-builtins.c   |  28 +++-
 clang/test/CodeGen/X86/avx512vlcd-builtins.c |  55 +--
 7 files changed, 231 insertions(+), 162 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index 279c0c7935e36..62c70fba946be 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -1359,23 +1359,17 @@ let Features = "avx512bw", Attributes = [NoThrow, 
Const, Constexpr, RequiredVect
   def pshufb512 : X86Builtin<"_Vector<64, char>(_Vector<64, char>, _Vector<64, 
char>)">;
 }
 
-let Features = "avx512cd,avx512vl", Attributes = [NoThrow, Const, 
RequiredVectorWidth<128>] in {
+let Features = "avx512cd,avx512vl", Attributes = [NoThrow, Const, Constexpr, 
RequiredVectorWidth<128>] in {
   def vpconflictdi_128 : X86Builtin<"_Vector<2, long long int>(_Vector<2, long 
long int>)">;
-}
-
-let Features = "avx512cd,avx512vl", Attributes = [NoThrow, Const, 
RequiredVectorWidth<256>] in {
-  def vpconflictdi_256 : X86Builtin<"_Vector<4, long long int>(_Vector<4, long 
long int>)">;
-}
-
-let Features = "avx512cd,avx512vl", Attributes = [NoThrow, Const, 
RequiredVectorWidth<128>] in {
   def vpconflictsi_128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>)">;
 }
 
-let Features = "avx512cd,avx512vl", Attributes = [NoThrow, Const, 
RequiredVectorWidth<256>] in {
+let Features = "avx512cd,avx512vl", Attributes = [NoThrow, Const, Constexpr, 
RequiredVectorWidth<256>] in {
+  def vpconflictdi_256 : X86Builtin<"_Vector<4, long long int>(_Vector<4, long 
long int>)">;
   def vpconflictsi_256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>)">;
 }
 
-let Features = "avx512cd", Attributes = [NoThrow, Const, 
RequiredVectorWidth<512>] in {
+let Features = "avx512cd", Attributes = [NoThrow, Const, Constexpr, 
RequiredVectorWidth<512>] in {
   def vpconflictdi_512 : X86Builtin<"_Vector<8, long long int>(_Vector<8, long 
long int>)">;
   def vpconflictsi_512 : X86Builtin<"_Vector<16, int>(_Vector<16, int>)">;
 }
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index b69f3607e82d6..a0d2c764121d9 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -3101,6 +3101,33 @@ static bool interp__builtin_vec_set(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_ia32_vpconflict(InterpState &S, CodePtr OpPC,
+const CallExpr *Call) {
+  assert(Call->getNumArgs() == 1);
+
+  QualType Arg0Type = Call->getArg(0)->getType();
+  const auto *VecT = Arg0Type->castAs();
+  PrimType ElemT = *S.getContext().classify(VecT->getElementType());
+  unsigned NumElems = VecT->getNumElements();
+  bool DestUnsigned = Call->getType()->isUnsignedIntegerOrEnumerationType();
+  const Pointer &Src = S.Stk.pop();
+  const Pointer &Dst = S.Stk.peek();
+
+  for (unsigned I = 0; I != NumElems; ++I) {
+INT_TYPE_SWITCH_NO_BOOL(ElemT, {
+  APSInt ElemI = Src.elem(I).toAPSInt();
+  APInt ConflictMask(ElemI.getBitWidth(), 0);
+  for (unsigned J = 0; J != I; ++J) {
+APSInt ElemJ = Src.elem(J).toAPSInt();
+ConflictMask.setBitVal(J, ElemI == ElemJ);
+  }
+  Dst.elem(I) = static_cast(APSInt(ConflictMask, DestUnsigned));
+});
+  }
+  Dst.initializeAllElements();
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
   uint32_t BuiltinID) {
   if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -3891,7 +3918,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const CallExpr *Call,
 [](const APSInt &Lo, const APSInt &Hi, const APSInt &Amt) {
   return llvm::APIntOps::fshr(Hi, Lo, Amt);
 });
-
+  case X86::BI__builtin_ia32_vpconflictsi_128:
+  case X86::BI__builtin_ia32_vpconflictsi_256:
+  case X86::BI__builtin_ia32_vpconflictsi_512:
+  case X86::BI__builtin_ia32_vpconflictdi_128:
+  case X86::BI__builtin_ia32_vpconflictdi_256:
+  case X86::BI__builtin_ia32_vpconflictdi_512:
+return interp__builtin_ia32_vpconflict(S, OpPC, Call);
   case clang::X86::BI__builtin_ia32_blendpd:
   case clang::X86::BI__builtin_ia32_blendpd256:
   case clang::X86::BI__builtin

[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

2025-10-15 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor edited 
https://github.com/llvm/llvm-project/pull/160150
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] PowerPC: Support Atomic Memory Operations in Inline Asm (PR #163616)

2025-10-15 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 origin/main HEAD --extensions c,cpp -- 
clang/test/CodeGen/PowerPC/inline-asm-constraints.c 
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp 
llvm/lib/Target/PowerPC/PPCISelLowering.cpp --diff_from_common_commit
``

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp 
b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 2e31ea739..448b03ee2 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -411,14 +411,16 @@ bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr 
*MI, unsigned OpNo,
 bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned 
OpNo,
   const char *ExtraCode,
   raw_ostream &O) {
-  auto reportAsmMemError = [&] (StringRef errMsg) {
+  auto reportAsmMemError = [&](StringRef errMsg) {
 const char *AsmStr = MI->getOperand(0).getSymbolName();
 const MDNode *LocMD = MI->getLocCookieMD();
-uint64_t LocCookie = LocMD ?
- mdconst::extract(LocMD->getOperand(0))->getZExtValue() : 0;
+uint64_t LocCookie =
+LocMD ? mdconst::extract(LocMD->getOperand(0))
+->getZExtValue()
+  : 0;
 const Function &Fn = MI->getMF()->getFunction();
-Fn.getContext().diagnose(DiagnosticInfoInlineAsm(
-LocCookie, errMsg + Twine(AsmStr) + "'"));
+Fn.getContext().diagnose(
+DiagnosticInfoInlineAsm(LocCookie, errMsg + Twine(AsmStr) + "'"));
 return true;
   };
   if (ExtraCode && ExtraCode[0]) {

``




https://github.com/llvm/llvm-project/pull/163616
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C2y] Support WG14 N3457, the __COUNTER__ macro (PR #162662)

2025-10-15 Thread Hubert Tong via cfe-commits

hubert-reinterpretcast wrote:

> Clang and GCC get the same behavior, EDG has `1 2 3 0`, and MSVC comes up 
> with `1 2 __VA_OPT__(3) 0` so there's implementation divergence; changing the 
> behavior to deviate from GCC seems like something we may want to consider 
> outside of the scope of this particular PR. How about I add test coverage for 
> this with a FIXME comment and mark our support as partial? Then I can file an 
> issue to track the behavior and we can get around to fixing that when we do.

Sounds good. For info, the "new" MSVC preprocessor gives `0 23 1` 
(https://godbolt.org/z/Go6P4xq4a).
With respect to the relative positioning for `2` and `3`, we have a situation 
where all implementations behave one way and the wording implies another.

https://github.com/llvm/llvm-project/pull/162662
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][DebugInfo] Emit DW_AT_language_{name, version} for DWARFv6 (PR #163208)

2025-10-15 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/163208

>From 532be3831f51937b38a8dbff4187585099f69afa Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Tue, 7 Oct 2025 09:52:19 +0100
Subject: [PATCH 1/4] [clang][DebugInfo] Emit DW_AT_language_name for DWARFv6

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 134 ++
 .../test/DebugInfo/CXX/versioned-language.cpp |  23 +++
 .../DebugInfo/Generic/versioned-language.c|  17 +++
 .../test/DebugInfo/ObjC/versioned-language.m  |   9 ++
 .../DebugInfo/ObjCXX/versioned-language.mm|   9 ++
 5 files changed, 162 insertions(+), 30 deletions(-)
 create mode 100644 clang/test/DebugInfo/CXX/versioned-language.cpp
 create mode 100644 clang/test/DebugInfo/Generic/versioned-language.c
 create mode 100644 clang/test/DebugInfo/ObjC/versioned-language.m
 create mode 100644 clang/test/DebugInfo/ObjCXX/versioned-language.mm

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 9fe9a13610296..79079ccb216cd 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -41,8 +41,10 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DataLayout.h"
+#include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
@@ -647,6 +649,77 @@ StringRef CGDebugInfo::getCurrentDirname() {
   return CGM.getCodeGenOpts().DebugCompilationDir;
 }
 
+static llvm::dwarf::SourceLanguage GetSourceLanguage(const CodeGenModule &CGM) 
{
+  const CodeGenOptions &CGO = CGM.getCodeGenOpts();
+  const LangOptions &LO = CGM.getLangOpts();
+
+  assert(CGO.DwarfVersion <= 5);
+
+  llvm::dwarf::SourceLanguage LangTag;
+  if (LO.CPlusPlus) {
+if (LO.ObjC)
+  LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
+else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
+else if (LO.CPlusPlus14)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
+else if (LO.CPlusPlus11)
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
+else
+  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
+  } else if (LO.ObjC) {
+LangTag = llvm::dwarf::DW_LANG_ObjC;
+  } else if (LO.OpenCL && (!CGO.DebugStrictDwarf || CGO.DwarfVersion >= 5)) {
+LangTag = llvm::dwarf::DW_LANG_OpenCL;
+  } else if (LO.C11 && !(CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)) {
+LangTag = llvm::dwarf::DW_LANG_C11;
+  } else if (LO.C99) {
+LangTag = llvm::dwarf::DW_LANG_C99;
+  } else {
+LangTag = llvm::dwarf::DW_LANG_C89;
+  }
+
+  return LangTag;
+}
+
+static std::pair
+GetSourceLanguageName(const CodeGenModule &CGM) {
+  const CodeGenOptions &CGO = CGM.getCodeGenOpts();
+  const LangOptions &LO = CGM.getLangOpts();
+
+  assert(CGO.DwarfVersion >= 6);
+
+  uint32_t LangVersion = 0;
+  llvm::dwarf::SourceLanguageName LangTag;
+  if (LO.CPlusPlus) {
+if (LO.ObjC) {
+  LangTag = llvm::dwarf::DW_LNAME_ObjC_plus_plus;
+} else {
+  LangTag = llvm::dwarf::DW_LNAME_C_plus_plus;
+  LangVersion = LO.getCPlusPlusLangStd().value_or(0);
+}
+  } else if (LO.ObjC) {
+LangTag = llvm::dwarf::DW_LNAME_ObjC;
+  } else if (LO.OpenCL) {
+LangTag = llvm::dwarf::DW_LNAME_OpenCL_C;
+  } else {
+LangTag = llvm::dwarf::DW_LNAME_C;
+LangVersion = LO.getCLangStd().value_or(0);
+  }
+
+  return {LangTag, LangVersion};
+}
+
+static llvm::DISourceLanguageName
+GetDISourceLanguageName(const CodeGenModule &CGM) {
+  // Emit pre-DWARFv6 language codes.
+  if (CGM.getCodeGenOpts().DwarfVersion < 6)
+return llvm::DISourceLanguageName(GetSourceLanguage(CGM));
+
+  auto [LName, LVersion] = GetSourceLanguageName(CGM);
+  return llvm::DISourceLanguageName(LName, LVersion);
+}
+
 void CGDebugInfo::CreateCompileUnit() {
   SmallString<64> Checksum;
   std::optional CSKind;
@@ -702,31 +775,6 @@ void CGDebugInfo::CreateCompileUnit() {
 }
   }
 
-  llvm::dwarf::SourceLanguage LangTag;
-  if (LO.CPlusPlus) {
-if (LO.ObjC)
-  LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
-else if (LO.CPlusPlus14)
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11)
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
-else
-  LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
-  } else if (LO.ObjC) {
-LangTag = llvm::dwarf::DW_LANG_ObjC;
-  } else if (LO.OpenCL && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
-   CGM.getCodeGenOpts().DwarfVersion >= 5)) {
-LangTag = llvm::dwarf::DW_LANG_OpenCL;
-  } else if (LO.C11 && !(CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)) {
-  LangTag = llvm::dwarf::DW_LANG_C11;
-  } else if (LO.C99) {
-LangTag = llvm::dwarf::DW_

[clang] [llvm] [FlowSensitive] [StatusOr] [1/N] Add mock headers (PR #163261)

2025-10-15 Thread Jan Voung via cfe-commits

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


https://github.com/llvm/llvm-project/pull/163261
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][LoongArch] Add support for UEFI target (PR #155598)

2025-10-15 Thread Prabhu Rajasekaran via cfe-commits

Prabhuk wrote:

> Hi @Prabhuk and @heiher , Could you please take a look at this patch when you 
> have time ? Thank you!

Sorry I missed this. I'll take a look.

https://github.com/llvm/llvm-project/pull/155598
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

2025-10-15 Thread JJ Marr via cfe-commits


@@ -0,0 +1,179 @@
+// RUN: %check_clang_tidy %s readability-avoid-default-lambda-capture %t -- -- 
-Wno-vla-extension -std=c++20

jjmarr-amd wrote:

But the init-capture test case is only valid for C++20-or-later, which is why I 
added that.

https://github.com/llvm/llvm-project/pull/160150
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

2025-10-15 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor edited 
https://github.com/llvm/llvm-project/pull/160150
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add __builtin_bswapg (PR #162433)

2025-10-15 Thread via cfe-commits

https://github.com/clingfei updated 
https://github.com/llvm/llvm-project/pull/162433

>From 92466f3789ce1849ebee8a405efd42e191c591f5 Mon Sep 17 00:00:00 2001
From: clingfei <[email protected]>
Date: Wed, 8 Oct 2025 15:05:44 +0800
Subject: [PATCH 1/7] [Clang] Add __builtin_bswapg

---
 clang/include/clang/Basic/Builtins.td |  6 
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  | 10 ++-
 clang/lib/AST/ExprConstant.cpp| 11 
 clang/lib/CodeGen/CGBuiltin.cpp   |  1 +
 clang/lib/Sema/SemaChecking.cpp   | 28 +++
 clang/test/AST/ByteCode/builtin-functions.cpp |  4 +++
 clang/test/CodeGen/builtins.c |  2 +-
 clang/test/Sema/constant-builtins-2.c |  4 +++
 clang/test/Sema/constant-builtins.c   |  5 +++-
 9 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 468121f7d20ab..e65ed2f20be97 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -755,6 +755,12 @@ def BSwap : Builtin, Template<["unsigned short", 
"uint32_t", "uint64_t"],
   let Prototype = "T(T)";
 }
 
+def BSwapg : Builtin {
+  let Spellings = ["__builtin_bswapg"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "int(...)";
+}
+
 def Bitreverse : BitInt8_16_32_64BuiltinsTemplate, Builtin {
   let Spellings = ["__builtin_bitreverse"];
   let Attributes = [NoThrow, Const, Constexpr];
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 1eea813b8c556..b8d17fbce6d4e 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -3288,7 +3288,15 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const CallExpr *Call,
   case Builtin::BI__builtin_elementwise_ctzg:
 return interp__builtin_elementwise_countzeroes(S, OpPC, Frame, Call,
BuiltinID);
-
+  case Builtin::BI__builtin_bswapg: {
+const APSInt &Val = popToAPSInt(S, Call->getArg(0));
+  assert(Val.getActiveBits() <= 64);
+if (Val.getBitWidth() == 8)
+pushInteger(S, Val, Call->getType());
+else
+pushInteger(S, Val.byteSwap(), Call->getType());
+return true;
+  }
   case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64:
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 618e1636e9e53..058905e7fd3c0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13982,6 +13982,17 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 
 return Success(Val.reverseBits(), E);
   }
+  case Builtin::BI__builtin_bswapg: {
+APSInt Val;
+if (!EvaluateInteger(E->getArg(0), Val, Info))
+  return false;
+if (Val.getBitWidth() == 8) {
+bool ret =  Success(Val, E);
+return ret;
+}
+
+return Success(Val.byteSwap(), E);
+  }
 
   case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9ee810c9d5775..7733f4dc15f5d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3622,6 +3622,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   Builder.CreateArithmeticFence(ArgValue, ConvertType(ArgType)));
 return RValue::get(ArgValue);
   }
+  case Builtin::BI__builtin_bswapg:
   case Builtin::BI__builtin_bswap16:
   case Builtin::BI__builtin_bswap32:
   case Builtin::BI__builtin_bswap64:
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 063db05665af1..362b53676feaa 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2200,6 +2200,30 @@ static bool BuiltinCpu(Sema &S, const TargetInfo &TI, 
CallExpr *TheCall,
   return false;
 }
 
+/// Checks that __builtin_bswapg was called with a single argument, which is an
+/// unsigned integer, and overrides the return value type to the integer type.
+static bool BuiltinBswapg(Sema &S, CallExpr *TheCall) {
+  if (S.checkArgCount(TheCall, 1))
+return true;
+  ExprResult ArgRes = S.DefaultLvalueConversion(TheCall->getArg(0));
+  if (ArgRes.isInvalid())
+return true;
+
+  Expr *Arg = ArgRes.get();
+  TheCall->setArg(0, Arg);
+
+  QualType ArgTy = Arg->getType();
+
+  if (!ArgTy->isIntegerType()) {
+S.Diag(Arg->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+<< 1 << /* scalar */ 1 << /* unsigned integer ty */ 1 << /* no fp */ 0
+<< ArgTy;
+return true;
+  }
+  TheCall->setType(ArgTy);
+  return false;
+}
+
 /// Checks that __builtin_popcountg was called with a single argument, which is
 /// an unsigned integer.
 static bool BuiltinPopcountg(Sema &S, CallExpr *TheCall) {
@@ -3448

[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

2025-10-15 Thread Victor Chernyakin via cfe-commits


@@ -93,6 +94,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-container-size-empty");
 CheckFactories.registerCheck(
 "readability-convert-member-functions-to-static");
+CheckFactories.registerCheck(
+"readability-avoid-default-lambda-capture");

localspook wrote:

Should be moved up to preserve alphabetical order

https://github.com/llvm/llvm-project/pull/160150
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

2025-10-15 Thread Victor Chernyakin via cfe-commits


@@ -377,6 +377,7 @@ Clang-Tidy Checks
:doc:`readability-container-data-pointer 
`, "Yes"
:doc:`readability-container-size-empty `, 
"Yes"
:doc:`readability-convert-member-functions-to-static 
`, "Yes"
+   :doc:`readability-avoid-default-lambda-capture 
`,

localspook wrote:

This should be moved up to preserve alphabetical order. Also, since the check 
now provides fixes:
```suggestion
   :doc:`readability-avoid-default-lambda-capture 
`, "Yes"
```

https://github.com/llvm/llvm-project/pull/160150
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

2025-10-15 Thread Victor Chernyakin via cfe-commits


@@ -0,0 +1,33 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDDEFAULTLAMBDACAPTURECHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDDEFAULTLAMBDACAPTURECHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// Flags lambdas that use default capture modes
+///
+/// For the user-facing documentation see:
+/// 
https://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-default-lambda-capture.html
+class AvoidDefaultLambdaCaptureCheck : public ClangTidyCheck {
+public:
+  AvoidDefaultLambdaCaptureCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+};

localspook wrote:

Lambdas are a C++11 feature, so there should be:
```suggestion
  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
  }
};
```

https://github.com/llvm/llvm-project/pull/160150
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

2025-10-15 Thread Victor Chernyakin via cfe-commits


@@ -0,0 +1,57 @@
+.. title:: clang-tidy - readability-avoid-default-lambda-capture
+
+readability-avoid-default-lambda-capture
+
+
+Warns on default lambda captures (e.g. ``[&](){ ... }``, ``[=](){ ... }``).
+  
+Captures can lead to subtle bugs including dangling references and unnecessary
+copies. Writing out the name of the variables being captured reminds 
programmers
+and reviewers to know what is being captured.

localspook wrote:

"reminds [...] to know" sounds a bit unnatural to me, maybe:
```suggestion
and reviewers about what is being captured.
```

https://github.com/llvm/llvm-project/pull/160150
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] disallow constexpr with auto and explicit type in C23 (PR #163469)

2025-10-15 Thread Oleksandr T. via cfe-commits

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

>From 3856379ddbb59c6dcd813765571a67f635034a3c Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Wed, 15 Oct 2025 01:42:15 +0300
Subject: [PATCH 1/4] [Clang] disallow constexpr with auto and explicit type in
 C23

---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/lib/Sema/DeclSpec.cpp  | 2 +-
 clang/test/Parser/c2x-auto.c | 2 ++
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index edb872c1f388d..de745e54a0cbd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -269,6 +269,8 @@ Non-comprehensive list of changes in this release
   allocation functions with a token ID can be enabled via the
   ``-fsanitize=alloc-token`` flag.
 
+- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an 
explicit type. (#GH163090)
+
 New Compiler Flags
 --
 - New option ``-fno-sanitize-debug-trap-reasons`` added to disable emitting 
trap reasons into the debug info when compiling with trapping UBSan (e.g. 
``-fsanitize-trap=undefined``).
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 184d31ecd1e40..482cb1fe703fe 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1369,7 +1369,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy 
&Policy) {
 
   if (S.getLangOpts().C23 &&
   getConstexprSpecifier() == ConstexprSpecKind::Constexpr &&
-  StorageClassSpec == SCS_extern) {
+  (StorageClassSpec == SCS_extern || StorageClassSpec == SCS_auto)) {
 S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
 << DeclSpec::getSpecifierName(getStorageClassSpec())
 << SourceRange(getStorageClassSpecLoc());
diff --git a/clang/test/Parser/c2x-auto.c b/clang/test/Parser/c2x-auto.c
index b878a5b7c42d4..b33b267841132 100644
--- a/clang/test/Parser/c2x-auto.c
+++ b/clang/test/Parser/c2x-auto.c
@@ -62,6 +62,8 @@ auto basic_usage(auto auto) {   // c23-error {{'auto' not 
allowed in function pr
 
   int auto_cxx_decl = auto(0);  // expected-error {{expected expression}}
 
+  constexpr auto int x = 0; // c23-error {{cannot combine with previous 'auto' 
declaration specifier}} \
+   c17-error {{use of undeclared identifier 
'constexpr'}}
   return c;
 }
 

>From 6bbca07057a9824badb0d04c6d7dc55b703378ed Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Wed, 15 Oct 2025 14:36:37 +0300
Subject: [PATCH 2/4] add additional test

---
 clang/test/Parser/c2x-auto.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/test/Parser/c2x-auto.c b/clang/test/Parser/c2x-auto.c
index b33b267841132..e8e36df096e08 100644
--- a/clang/test/Parser/c2x-auto.c
+++ b/clang/test/Parser/c2x-auto.c
@@ -64,6 +64,10 @@ auto basic_usage(auto auto) {   // c23-error {{'auto' not 
allowed in function pr
 
   constexpr auto int x = 0; // c23-error {{cannot combine with previous 'auto' 
declaration specifier}} \
c17-error {{use of undeclared identifier 
'constexpr'}}
+
+  constexpr int auto y = 0; // c23-error {{cannot combine with previous 'int' 
declaration specifier}} \
+   c17-error {{use of undeclared identifier 
'constexpr'}}
+
   return c;
 }
 

>From a6b55edcb4e28a774b604ba652589604cd527f6d Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Wed, 15 Oct 2025 14:42:11 +0300
Subject: [PATCH 3/4] update release notes

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b4620dff8e9fe..4f7a72cc62985 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -271,7 +271,7 @@ Non-comprehensive list of changes in this release
   allocation functions with a token ID can be enabled via the
   ``-fsanitize=alloc-token`` flag.
 
-- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an 
explicit type. (#GH163090)
+- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an 
explicit type in C. (#GH163090)
 
 New Compiler Flags
 --

>From 9bbce08f30878ed426f6e5cbd05d278234692e5a Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Wed, 15 Oct 2025 23:28:31 +0300
Subject: [PATCH 4/4] update tests

---
 clang/test/Parser/c2x-auto.c | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/clang/test/Parser/c2x-auto.c b/clang/test/Parser/c2x-auto.c
index e8e36df096e08..7f80b0717ab25 100644
--- a/clang/test/Parser/c2x-auto.c
+++ b/clang/test/Parser/c2x-auto.c
@@ -62,12 +62,6 @@ auto basic_usage(auto auto) {   // c23-error {{'auto' not 
allowed in function pr
 
   int auto_cxx_decl = auto(0);  // expected-error {{expected expression}}
 
-  constexpr auto int x = 0; // c23-error {{cannot combine with previous 'auto' 
declaration specifier}} \
-  

[clang] b936f2c - [OpenACC] Call 'cleanup' on lexical scopes before yield

2025-10-15 Thread via cfe-commits

Author: erichkeane
Date: 2025-10-15T13:59:25-07:00
New Revision: b936f2ceeba3e0b17858660a828f36e3415f0288

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

LOG: [OpenACC] Call 'cleanup' on lexical scopes before yield

When creating a 'yield', we have to make sure that the lexical scope we
created gets cleaned up.  This isn't really testable until a followup
patch, but I got this wrong in quite a few places.

Added: 


Modified: 
clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.cpp

Removed: 




diff  --git a/clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.cpp 
b/clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.cpp
index ce14aa8aaad40..f638d391d55cd 100644
--- a/clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenOpenACCRecipe.cpp
@@ -398,6 +398,7 @@ void OpenACCRecipeBuilderBase::createRecipeDestroySection(
 emitDestroy(block->getArgument(1), elementTy);
   }
 
+  ls.forceCleanup();
   mlir::acc::YieldOp::create(builder, locEnd);
 }
 void OpenACCRecipeBuilderBase::makeBoundsInit(
@@ -480,6 +481,7 @@ void OpenACCRecipeBuilderBase::createInitRecipe(
  /*isInitSection=*/true);
   }
 
+  ls.forceCleanup();
   mlir::acc::YieldOp::create(builder, locEnd);
 }
 
@@ -518,6 +520,7 @@ void OpenACCRecipeBuilderBase::createFirstprivateRecipeCopy(
   cgf.emitAutoVarInit(tempDeclEmission);
 
   builder.setInsertionPointToEnd(©Region.back());
+  ls.forceCleanup();
   mlir::acc::YieldOp::create(builder, locEnd);
 }
 
@@ -662,6 +665,7 @@ void 
OpenACCRecipeBuilderBase::createReductionRecipeCombiner(
   }
 
   builder.setInsertionPointToEnd(&recipe.getCombinerRegion().back());
+  ls.forceCleanup();
   mlir::acc::YieldOp::create(builder, locEnd, block->getArgument(0));
 }
 



___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RISCV] Set __GCC_CONSTRUCTIVE_SIZE/__GCC_DESTRUCTIVE_SIZE to 64 for riscv64 (PR #162986)

2025-10-15 Thread Sam Elliott via cfe-commits

lenary wrote:

I added some RISC-V specific documentation here: 
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/129

https://github.com/llvm/llvm-project/pull/162986
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] disallow constexpr with auto and explicit type in C23 (PR #163469)

2025-10-15 Thread Oleksandr T. via cfe-commits

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

>From 3856379ddbb59c6dcd813765571a67f635034a3c Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Wed, 15 Oct 2025 01:42:15 +0300
Subject: [PATCH 1/4] [Clang] disallow constexpr with auto and explicit type in
 C23

---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/lib/Sema/DeclSpec.cpp  | 2 +-
 clang/test/Parser/c2x-auto.c | 2 ++
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index edb872c1f388d..de745e54a0cbd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -269,6 +269,8 @@ Non-comprehensive list of changes in this release
   allocation functions with a token ID can be enabled via the
   ``-fsanitize=alloc-token`` flag.
 
+- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an 
explicit type. (#GH163090)
+
 New Compiler Flags
 --
 - New option ``-fno-sanitize-debug-trap-reasons`` added to disable emitting 
trap reasons into the debug info when compiling with trapping UBSan (e.g. 
``-fsanitize-trap=undefined``).
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 184d31ecd1e40..482cb1fe703fe 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1369,7 +1369,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy 
&Policy) {
 
   if (S.getLangOpts().C23 &&
   getConstexprSpecifier() == ConstexprSpecKind::Constexpr &&
-  StorageClassSpec == SCS_extern) {
+  (StorageClassSpec == SCS_extern || StorageClassSpec == SCS_auto)) {
 S.Diag(ConstexprLoc, diag::err_invalid_decl_spec_combination)
 << DeclSpec::getSpecifierName(getStorageClassSpec())
 << SourceRange(getStorageClassSpecLoc());
diff --git a/clang/test/Parser/c2x-auto.c b/clang/test/Parser/c2x-auto.c
index b878a5b7c42d4..b33b267841132 100644
--- a/clang/test/Parser/c2x-auto.c
+++ b/clang/test/Parser/c2x-auto.c
@@ -62,6 +62,8 @@ auto basic_usage(auto auto) {   // c23-error {{'auto' not 
allowed in function pr
 
   int auto_cxx_decl = auto(0);  // expected-error {{expected expression}}
 
+  constexpr auto int x = 0; // c23-error {{cannot combine with previous 'auto' 
declaration specifier}} \
+   c17-error {{use of undeclared identifier 
'constexpr'}}
   return c;
 }
 

>From 6bbca07057a9824badb0d04c6d7dc55b703378ed Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Wed, 15 Oct 2025 14:36:37 +0300
Subject: [PATCH 2/4] add additional test

---
 clang/test/Parser/c2x-auto.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/test/Parser/c2x-auto.c b/clang/test/Parser/c2x-auto.c
index b33b267841132..e8e36df096e08 100644
--- a/clang/test/Parser/c2x-auto.c
+++ b/clang/test/Parser/c2x-auto.c
@@ -64,6 +64,10 @@ auto basic_usage(auto auto) {   // c23-error {{'auto' not 
allowed in function pr
 
   constexpr auto int x = 0; // c23-error {{cannot combine with previous 'auto' 
declaration specifier}} \
c17-error {{use of undeclared identifier 
'constexpr'}}
+
+  constexpr int auto y = 0; // c23-error {{cannot combine with previous 'int' 
declaration specifier}} \
+   c17-error {{use of undeclared identifier 
'constexpr'}}
+
   return c;
 }
 

>From a6b55edcb4e28a774b604ba652589604cd527f6d Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Wed, 15 Oct 2025 14:42:11 +0300
Subject: [PATCH 3/4] update release notes

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b4620dff8e9fe..4f7a72cc62985 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -271,7 +271,7 @@ Non-comprehensive list of changes in this release
   allocation functions with a token ID can be enabled via the
   ``-fsanitize=alloc-token`` flag.
 
-- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an 
explicit type. (#GH163090)
+- Clang now rejects the invalid use of ``constexpr`` with ``auto`` and an 
explicit type in C. (#GH163090)
 
 New Compiler Flags
 --

>From 9bbce08f30878ed426f6e5cbd05d278234692e5a Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Wed, 15 Oct 2025 23:28:31 +0300
Subject: [PATCH 4/4] update tests

---
 clang/test/Parser/c2x-auto.c | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/clang/test/Parser/c2x-auto.c b/clang/test/Parser/c2x-auto.c
index e8e36df096e08..7f80b0717ab25 100644
--- a/clang/test/Parser/c2x-auto.c
+++ b/clang/test/Parser/c2x-auto.c
@@ -62,12 +62,6 @@ auto basic_usage(auto auto) {   // c23-error {{'auto' not 
allowed in function pr
 
   int auto_cxx_decl = auto(0);  // expected-error {{expected expression}}
 
-  constexpr auto int x = 0; // c23-error {{cannot combine with previous 'auto' 
declaration specifier}} \
-  

[clang] [compiler-rt] [ASan] Document define to disable container overflow checks at compile time. (PR #163468)

2025-10-15 Thread Paddy McDonald via cfe-commits

https://github.com/padriff updated 
https://github.com/llvm/llvm-project/pull/163468

>From 1755359430f780b0fe904dcaf28219e4b3633f24 Mon Sep 17 00:00:00 2001
From: Paddy McDonald 
Date: Tue, 14 Oct 2025 15:41:13 -0700
Subject: [PATCH] Document a define to allow library developers to support
 disabling AddressSanitizer's container overflow detection in template code at
 compile time.

The primary motivation is to reduce false positives in environments where
libraries and frameworks that cannot be recompiled with sanitizers enabled
are called from application code.  This supports disabling checks when the
runtime environment cannot be reliably controlled to use ASAN_OPTIONS.

Key changes:
- Update documentation in AddressSanitizer.rst to suggest and illustrate
  use of the define
- Add details of the define in PrintContainerOverflowHint()
- Add test disable_container_overflow_checks to verify new hints on the
  error and fill the testing gap that ASAN_OPTIONS=detect_container_overflow=0
  works

This requires no compiler changes and should be supportable cross compiler 
toolchains.

An RFC has been opened to discuss: 
https://discourse.llvm.org/t/rfc-add-fsanitize-address-disable-container-overflow-flag-to-addresssanitizer/88349
---
 clang/docs/AddressSanitizer.rst   | 50 +++
 compiler-rt/lib/asan/asan_errors.cpp  | 14 --
 .../disable_container_overflow_checks.cpp | 50 +++
 3 files changed, 109 insertions(+), 5 deletions(-)
 create mode 100644 
compiler-rt/test/asan/TestCases/disable_container_overflow_checks.cpp

diff --git a/clang/docs/AddressSanitizer.rst b/clang/docs/AddressSanitizer.rst
index 21e1a3652192e..92caa596a3b26 100644
--- a/clang/docs/AddressSanitizer.rst
+++ b/clang/docs/AddressSanitizer.rst
@@ -164,6 +164,19 @@ To summarize: 
``-fsanitize-address-use-after-return=``
   * ``always``: Enables detection of UAR errors in all cases. (reduces code
 size, but not as much as ``never``).
 
+Container Overflow Detection
+
+
+AddressSanitizer can detect overflows in containers with custom allocators
+(such as std::vector) where the Library developers have added calls into the
+AddressSanitizer runtime to indicate which memory is poisoned etc.
+
+In environments where not all the process binaries can be recompiled with 
+AddressSanitizer enabled, these checks can cause false positives.
+
+See `Disabling container overflow checks`_ for details on suppressing false
+positives.
+
 Memory leak detection
 -
 
@@ -242,6 +255,43 @@ AddressSanitizer also supports
 works similar to ``__attribute__((no_sanitize("address")))``, but it also
 prevents instrumentation performed by other sanitizers.
 
+Disabling container overflow checks
+---
+
+Runtime suppression
+^^^
+
+Container overflow checks can be disabled at runtime using
+``ASAN_OPTIONS=detect_container_overflow=0``
+
+Compile time suppression
+
+
+``-D__ASAN_DISABLE_CONTAINER_OVERFLOW__`` can be used at compile time to
+disable container overflow checks if the container library has added support
+for this define.
+
+To support a standard way to disable container overflow checks at compile time,
+Library developers should use this definition in conjunction with the 
+AddressSanitizer feature test to conditionally include container overflow 
+related code compiled into user code:
+
+The recommended form is
+
+.. code-block:: c
+
+#if __has_feature(address_sanitizer) && 
!__ASAN_DISABLE_CONTAINER_OVERFLOW__
+// Container overflow detection enabled - include annotations
+__sanitizer_annotate_contiguous_container(beg, end, old_mid, new_mid);
+#endif
+
+This pattern ensures that:
+
+* Container overflow annotations are only included when AddressSanitizer is
+  enabled
+* Container overflow detection can be disabled by passing 
+  ``-D__ASAN_DISABLE_CONTAINER_OVERFLOW__`` to the compiler
+
 Suppressing Errors in Recompiled Code (Ignorelist)
 --
 
diff --git a/compiler-rt/lib/asan/asan_errors.cpp 
b/compiler-rt/lib/asan/asan_errors.cpp
index 2a207cd06ccac..ee71c789116c0 100644
--- a/compiler-rt/lib/asan/asan_errors.cpp
+++ b/compiler-rt/lib/asan/asan_errors.cpp
@@ -514,11 +514,15 @@ ErrorGeneric::ErrorGeneric(u32 tid, uptr pc_, uptr bp_, 
uptr sp_, uptr addr,
 }
 
 static void PrintContainerOverflowHint() {
-  Printf("HINT: if you don't care about these errors you may set "
- "ASAN_OPTIONS=detect_container_overflow=0.\n"
- "If you suspect a false positive see also: "
- "https://github.com/google/sanitizers/wiki/";
- "AddressSanitizerContainerOverflow.\n");
+  Printf(
+  "HINT: if you don't care about these errors you may set "
+  "ASAN_OPTIONS=detect_container_overflow=0.\n"
+  "If supported by the container library, pass "
+  "-D__ASAN_DISABLE_CONTAINER_OVERFLOW__ to the c

[clang] [lldb] [Clang] Introduce OverflowBehaviorType for fine-grained overflow control (PR #148914)

2025-10-15 Thread Kees Cook via cfe-commits

kees wrote:

> please cc me on the email thread regarding a video call. FYI, I'll be at '25 
> dev mtng.
> 
> I think there is some confusion in this thread about how to tell the compiler 
> about intentional data loss.
> 
> The UX I like the most is something like the following:
> 
> ```c
> void foo() {
>   int __ob_trap a = -1;
> 
>   u16 b = a; // trap, semantics we just agreed upon. implicit casts are 
> sketchy
> 
>   u16 c = (u16)a; // no trap, inform compiler about our intent explicitly, 
> Rust equivalent 'a as u16'
> 
>   u16 d = (u16 __ob_wrap)a; // no trap, inform compiler about our intent 
> explcitly
> 
>   u16 e = (u16 __ob_trap)a; // trap, Rust equivalent: 'a.try_into().unwrap()'
> }
> ```
> 
> My understanding is that @kees would prefer if the `d` example was the _only_ 
> way to inform the compiler about intentional data loss and the `c` example 
> wouldn't be enough (i.e., should trap too). Am I right kees?

Right, I think `c` is what is already happening with `b`: a cast to `u16` tells 
us nothing about the desired OB. We need to say `u16 __ob_trap` ("I want to 
trap") or `u16 __ob_wrap` ("I want wrap-around on overflow").

https://github.com/llvm/llvm-project/pull/148914
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [alpha.webkit.UnretainedCallArgsChecker] Recognize [allocObj() init] pattern (PR #161019)

2025-10-15 Thread Ryosuke Niwa via cfe-commits

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

>From 5566404aae55af74f79e745f46ac5630131ab087 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 27 Sep 2025 13:04:11 -0700
Subject: [PATCH] [alpha.webkit.UnretainedCallArgsChecker] Recognize
 [allocObj() init] pattern

Generalize the check for recognizing [[Obj alloc] init] to also recognize 
[allocObj() init].
We do this by utilizing isAllocInit function in RetainPtrCtorAdoptChecker.
---
 .../Checkers/WebKit/ASTUtils.cpp  | 45 +++
 .../StaticAnalyzer/Checkers/WebKit/ASTUtils.h |  4 ++
 .../WebKit/RawPtrRefCallArgsChecker.cpp   |  9 +---
 .../WebKit/RetainPtrCtorAdoptChecker.cpp  | 44 --
 .../Checkers/WebKit/unretained-call-args.mm   |  3 ++
 5 files changed, 54 insertions(+), 51 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 419d2631fef81..8f4750b627046 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -313,6 +313,51 @@ bool isExprToGetCheckedPtrCapableMember(const clang::Expr 
*E) {
   return result && *result;
 }
 
+bool isAllocInit(const Expr *E, const Expr **InnerExpr) {
+  auto *ObjCMsgExpr = dyn_cast(E);
+  if (auto *POE = dyn_cast(E)) {
+if (unsigned ExprCount = POE->getNumSemanticExprs()) {
+  auto *Expr = POE->getSemanticExpr(ExprCount - 1)->IgnoreParenCasts();
+  ObjCMsgExpr = dyn_cast(Expr);
+  if (InnerExpr)
+*InnerExpr = ObjCMsgExpr;
+}
+  }
+  if (!ObjCMsgExpr)
+return false;
+  auto Selector = ObjCMsgExpr->getSelector();
+  auto NameForFirstSlot = Selector.getNameForSlot(0);
+  if (NameForFirstSlot.starts_with("alloc") ||
+  NameForFirstSlot.starts_with("copy") ||
+  NameForFirstSlot.starts_with("mutableCopy"))
+return true;
+  if (!NameForFirstSlot.starts_with("init") &&
+  !NameForFirstSlot.starts_with("_init"))
+return false;
+  if (!ObjCMsgExpr->isInstanceMessage())
+return false;
+  auto *Receiver = ObjCMsgExpr->getInstanceReceiver();
+  if (!Receiver)
+return false;
+  Receiver = Receiver->IgnoreParenCasts();
+  if (auto *Inner = dyn_cast(Receiver)) {
+if (InnerExpr)
+  *InnerExpr = Inner;
+auto InnerSelector = Inner->getSelector();
+return InnerSelector.getNameForSlot(0).starts_with("alloc");
+  } else if (auto *CE = dyn_cast(Receiver)) {
+if (InnerExpr)
+  *InnerExpr = CE;
+if (auto *Callee = CE->getDirectCallee()) {
+  if (Callee->getDeclName().isIdentifier()) {
+auto CalleeName = Callee->getName();
+return CalleeName.starts_with("alloc");
+  }
+}
+  }
+  return false;
+}
+
 class EnsureFunctionVisitor
 : public ConstStmtVisitor {
 public:
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h
index 9fff456b7e8b8..d0a3e471365e2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.h
@@ -77,6 +77,10 @@ bool isConstOwnerPtrMemberExpr(const clang::Expr *E);
 /// supports CheckedPtr.
 bool isExprToGetCheckedPtrCapableMember(const clang::Expr *E);
 
+/// \returns true if \p E is a [[alloc] init] pattern expression.
+/// Sets \p InnerExpr to the inner function call or selector invocation.
+bool isAllocInit(const Expr *E, const Expr **InnerExpr = nullptr);
+
 /// \returns true if E is a CXXMemberCallExpr which returns a const smart
 /// pointer type.
 class EnsureFunctionAnalysis {
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
index 791e70998477f..dcc14a0aecdf7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
@@ -177,16 +177,11 @@ class RawPtrRefCallArgsChecker
 if (BR->getSourceManager().isInSystemHeader(E->getExprLoc()))
   return;
 
-auto Selector = E->getSelector();
 if (auto *Receiver = E->getInstanceReceiver()) {
   std::optional IsUnsafe = isUnsafePtr(E->getReceiverType());
   if (IsUnsafe && *IsUnsafe && !isPtrOriginSafe(Receiver)) {
-if (auto *InnerMsg = dyn_cast(Receiver)) {
-  auto InnerSelector = InnerMsg->getSelector();
-  if (InnerSelector.getNameForSlot(0) == "alloc" &&
-  Selector.getNameForSlot(0).starts_with("init"))
-return;
-}
+if (isAllocInit(E))
+  return;
 reportBugOnReceiver(Receiver, D);
   }
 }
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp
index 955b8d19a820c..e10ad3242fe79 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp
+++ b/c

[clang] [alpha.webkit.UnretainedCallArgsChecker] Treat getter on a dependent smart pointer type as safe (PR #161025)

2025-10-15 Thread Ryosuke Niwa via cfe-commits

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

>From 2d45c8209389ccdc293165e4cd73f45c65b84e27 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 27 Sep 2025 14:26:46 -0700
Subject: [PATCH] [alpha.webkit.UnretainedCallArgsChecker] Treat getter on a
 dependent smart pointer type as safe

Add the support for recognizing smart pointer type appearing as the type of the 
object pointer
in CXXDependentScopeMemberExpr.
---
 .../Checkers/WebKit/ASTUtils.cpp  |  8 +
 .../Checkers/WebKit/unretained-call-args.mm   | 29 +++
 2 files changed, 37 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 419d2631fef81..84adbf318e9f8 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -173,6 +173,14 @@ bool tryToFindPtrOrigin(
   if (isSingleton(E->getFoundDecl()))
 return callback(E, true);
 }
+
+if (auto *MemberExpr = dyn_cast(CalleeE)) 
{
+  auto *Base = MemberExpr->getBase();
+  auto MemberName = MemberExpr->getMember().getAsString();
+  bool IsGetter = MemberName == "get" || MemberName == "ptr";
+  if (Base && isSafePtrType(Base->getType()) && IsGetter)
+return callback(E, true);
+}
   }
 
   // Sometimes, canonical type erroneously turns Ref into T.
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm 
b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
index 4f231ee8b1c84..8bef24f93ceed 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm
@@ -596,6 +596,35 @@ void foo() {
 
 } // namespace sel_string
 
+namespace template_function {
+
+class Base {
+public:
+virtual ~Base() = default;
+void send(dispatch_queue_t) const;
+void ref() const;
+void deref() const;
+};
+
+template
+class Derived : public Base {
+public:
+virtual ~Derived() = default;
+
+void send(typename Traits::MessageType) const;
+
+virtual OSObjectPtr msg(typename Traits::MessageType) 
const = 0;
+};
+
+template
+void Derived::send(typename Traits::MessageType messageType) const
+{
+OSObjectPtr dictionary = msg(messageType);
+Base::send(dictionary.get());
+}
+
+} // namespace template_function
+
 @interface TestObject : NSObject
 - (void)doWork:(NSString *)msg, ...;
 - (void)doWorkOnSelf;

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AArch64][llvm] Add support for new vcvt* intrinsics (PR #163572)

2025-10-15 Thread Jonathan Thackray via cfe-commits

jthackray wrote:

> Oh, also, we probably want a release note for this.

Thanks. Our team is adding quite a few new intrinsics soon (I've got another 
intrinsics patch soon I'm working on) so I'll ensure they're all documented.

https://github.com/llvm/llvm-project/pull/163572
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Enforce Unix line endings (PR #163650)

2025-10-15 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor auto_merge_enabled 
https://github.com/llvm/llvm-project/pull/163650
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AArch64][llvm] Add support for new vcvt* intrinsics (PR #163572)

2025-10-15 Thread Jonathan Thackray via cfe-commits

https://github.com/jthackray updated 
https://github.com/llvm/llvm-project/pull/163572

>From 23653d3d12f342c4c45897866f92865bd6aafc5d Mon Sep 17 00:00:00 2001
From: Jonathan Thackray 
Date: Tue, 14 Oct 2025 12:40:51 +0100
Subject: [PATCH 1/4] [AArch64][llvm] Add support for new vcvt* intrinsics

Add support for these new vcvt* intrinsics:

```
  int64_t  vcvts_s64_f32(float32_t);
  uint64_t vcvts_u64_f32(float32_t);
  int32_t  vcvtd_s32_f64(float64_t);
  uint32_t vcvtd_u32_f64(float64_t);

  int64_t  vcvtns_s64_f32(float32_t);
  uint64_t vcvtns_u64_f32(float32_t);
  int32_t  vcvtnd_s32_f64(float64_t);
  uint32_t vcvtnd_u32_f64(float64_t);

  int64_t  vcvtms_s64_f32(float32_t);
  uint64_t vcvtms_u64_f32(float32_t);
  int32_t  vcvtmd_s32_f64(float64_t);
  uint32_t vcvtmd_u32_f64(float64_t);

  int64_t  vcvtps_s64_f32(float32_t);
  uint64_t vcvtps_u64_f32(float32_t);
  int32_t  vcvtpd_s32_f64(float64_t);
  uint32_t vcvtpd_u32_f64(float64_t);

  int64_t  vcvtas_s64_f32(float32_t);
  uint64_t vcvtas_u64_f32(float32_t);
  int32_t  vcvtad_s32_f64(float64_t);
  uint32_t vcvtad_u32_f64(float64_t);
```
---
 clang/include/clang/Basic/arm_neon.td |  65 +++--
 clang/lib/CodeGen/TargetBuiltins/ARM.cpp  |  20 ++
 .../CodeGen/AArch64/neon-fcvt-intrinsics.c| 225 +-
 3 files changed, 288 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index ef196103035e8..315c60692dcaf 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1466,26 +1466,51 @@ def SCALAR_UCVTFD : SInst<"vcvt_f64", "(1F)(1!)", 
"SUl">;
 

 // Scalar Floating-point Converts
 def SCALAR_FCVTXN  : IInst<"vcvtx_f32", "(1F<)(1!)", "Sd">;
-def SCALAR_FCVTNSS : SInst<"vcvtn_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTNUS : SInst<"vcvtn_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTNSD : SInst<"vcvtn_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTNUD : SInst<"vcvtn_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTMSS : SInst<"vcvtm_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTMUS : SInst<"vcvtm_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTMSD : SInst<"vcvtm_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTMUD : SInst<"vcvtm_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTASS : SInst<"vcvta_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTAUS : SInst<"vcvta_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTASD : SInst<"vcvta_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTAUD : SInst<"vcvta_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTPSS : SInst<"vcvtp_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTPUS : SInst<"vcvtp_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTPSD : SInst<"vcvtp_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTPUD : SInst<"vcvtp_u64", "(1U)1", "Sd">;
-def SCALAR_FCVTZSS : SInst<"vcvt_s32", "(1S)1", "Sf">;
-def SCALAR_FCVTZUS : SInst<"vcvt_u32", "(1U)1", "Sf">;
-def SCALAR_FCVTZSD : SInst<"vcvt_s64", "(1S)1", "Sd">;
-def SCALAR_FCVTZUD : SInst<"vcvt_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTN_F32toSS  : SInst<"vcvtn_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUS  : SInst<"vcvtn_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSS  : SInst<"vcvtn_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUS  : SInst<"vcvtn_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTN_F32toSD  : SInst<"vcvtn_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTN_F32toUD  : SInst<"vcvtn_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTN_F64toSD  : SInst<"vcvtn_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTN_F64toUD  : SInst<"vcvtn_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTM_F32toSS  : SInst<"vcvtm_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUS  : SInst<"vcvtm_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSS  : SInst<"vcvtm_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUS  : SInst<"vcvtm_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTM_F32toSD  : SInst<"vcvtm_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTM_F32toUD  : SInst<"vcvtm_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTM_F64toSD  : SInst<"vcvtm_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTM_F64toUD  : SInst<"vcvtm_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTA_F32toSS  : SInst<"vcvta_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTA_F32toUS  : SInst<"vcvta_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTA_F64toSS  : SInst<"vcvta_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTA_F64toUS  : SInst<"vcvta_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTA_F32toSD  : SInst<"vcvta_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTA_F32toUD  : SInst<"vcvta_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTA_F64toSD  : SInst<"vcvta_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTA_F64toUD  : SInst<"vcvta_u64", "(1U)1", "Sd">;
+
+def SCALAR_FCVTP_F32toSS  : SInst<"vcvtp_s32", "(1S)1", "Sf">;
+def SCALAR_FCVTP_F32toUS  : SInst<"vcvtp_u32", "(1U)1", "Sf">;
+def SCALAR_FCVTP_F64toSS  : SInst<"vcvtp_s32", "(1S)1", "Sd">;
+def SCALAR_FCVTP_F64toUS  : SInst<"vcvtp_u32", "(1U)1", "Sd">;
+def SCALAR_FCVTP_F32toSD  : SInst<"vcvtp_s64", "(1S)1", "Sf">;
+def SCALAR_FCVTP_F32toUD  : SInst<"vcvtp_u64", "(1U)1", "Sf">;
+def SCALAR_FCVTP_F64toSD  : SInst<"vcvtp_s64", "(1S)1", "Sd">;
+def SCALAR_FCVTP_F64toUD  : S

[clang] [AArch64][llvm] Add support for new vcvt* intrinsics (PR #163572)

2025-10-15 Thread Jonathan Thackray via cfe-commits

jthackray wrote:

> Oh, also, we probably want a release note for this.

Done ✅ 

https://github.com/llvm/llvm-project/pull/163572
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CIR] Upstream pointer subtraction handling (PR #163306)

2025-10-15 Thread Shawn K via cfe-commits

https://github.com/kimsh02 updated 
https://github.com/llvm/llvm-project/pull/163306

>From 9f2ec3c40d9c4f28531e4a18f392703ca16ab2d7 Mon Sep 17 00:00:00 2001
From: kimsh02 
Date: Mon, 13 Oct 2025 13:18:28 -0700
Subject: [PATCH 1/9] Copy incubator tests

---
 clang/test/CIR/CodeGen/ptrdiff.c   | 18 ++
 clang/test/CIR/CodeGen/ptrdiff.cpp | 23 +++
 2 files changed, 41 insertions(+)
 create mode 100644 clang/test/CIR/CodeGen/ptrdiff.c
 create mode 100644 clang/test/CIR/CodeGen/ptrdiff.cpp

diff --git a/clang/test/CIR/CodeGen/ptrdiff.c b/clang/test/CIR/CodeGen/ptrdiff.c
new file mode 100644
index 0..2ccbbb02dddaa
--- /dev/null
+++ b/clang/test/CIR/CodeGen/ptrdiff.c
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o 
%t.cir
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o 
%t.ll
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
+
+int addrcmp(const void* a, const void* b) {
+  // CIR-LABEL: addrcmp
+  // CIR: %[[R:.*]] = cir.ptr_diff
+  // CIR: cir.cast integral  %[[R]] : !s64i -> !s32
+
+  // LLVM-LABEL: addrcmp
+  // LLVM: %[[PTR_A:.*]] = ptrtoint ptr {{.*}} to i64
+  // LLVM: %[[PTR_B:.*]] = ptrtoint ptr {{.*}} to i64
+  // LLVM: %[[SUB:.*]] = sub i64 %[[PTR_A]], %[[PTR_B]]
+  // LLVM-NOT: sdiv
+  // LLVM: trunc i64 %[[SUB]] to i32
+  return *(const void**)a - *(const void**)b;
+}
diff --git a/clang/test/CIR/CodeGen/ptrdiff.cpp 
b/clang/test/CIR/CodeGen/ptrdiff.cpp
new file mode 100644
index 0..ba54b7a3b11bf
--- /dev/null
+++ b/clang/test/CIR/CodeGen/ptrdiff.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir 
-emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s
+
+typedef unsigned long size_type;
+size_type size(unsigned long *_start, unsigned long *_finish) {
+  return static_cast(_finish - _start);
+}
+
+// CHECK: cir.func dso_local @_Z4sizePmS_(%arg0: !cir.ptr
+// CHECK:   %3 = cir.load{{.*}} %1 : !cir.ptr>, !cir.ptr
+// CHECK:   %4 = cir.load{{.*}} %0 : !cir.ptr>, !cir.ptr
+// CHECK:   %5 = cir.ptr_diff %3, %4 : !cir.ptr -> !s64i
+// CHECK:   %6 = cir.cast integral %5 : !s64i -> !u64i
+
+long add(char *a, char *b) {
+  return a - b + 1;
+}
+
+// CHECK: cir.func dso_local @_Z3addPcS_(%arg0: !cir.ptr
+//  %5 = cir.ptr_diff %3, %4 : !cir.ptr -> !s64i
+//  %6 = cir.const #cir.int<1> : !s32i
+//  %7 = cir.cast integral %6 : !s32i -> !s64i
+//  %8 = cir.binop(add, %5, %7) : !s64i

>From db85047a5f606caad31770219f468f66985b2ed1 Mon Sep 17 00:00:00 2001
From: kimsh02 
Date: Mon, 13 Oct 2025 19:05:05 -0700
Subject: [PATCH 2/9] Stash

---
 clang/include/clang/CIR/MissingFeatures.h |  2 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp|  3 +-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 34 +
 clang/test/CIR/CodeGen/ptrdiff.c  | 14 +++
 clang/test/CIR/CodeGen/ptrdiff.cpp| 37 +--
 5 files changed, 75 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 4fbae150b587e..8edb4adcf48de 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -321,7 +321,7 @@ struct MissingFeatures {
   static bool ifOp() { return false; }
   static bool invokeOp() { return false; }
   static bool labelOp() { return false; }
-  static bool ptrDiffOp() { return false; }
+  static bool ptrDiffOp() { return true; }
   static bool ptrStrideOp() { return false; }
   static bool switchOp() { return false; }
   static bool throwOp() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 637f9ef65c88f..6c6e25c3f6caa 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -1735,8 +1735,7 @@ mlir::Value ScalarExprEmitter::emitSub(const BinOpInfo 
&ops) {
   //
   // See more in `EmitSub` in CGExprScalar.cpp.
   assert(!cir::MissingFeatures::ptrDiffOp());
-  cgf.cgm.errorNYI("ptrdiff");
-  return {};
+  return builder.create(cgf.getLoc(ops.loc), cgf.PtrDiffTy, 
ops.lhs, ops.rhs);
 }
 
 mlir::Value ScalarExprEmitter::emitShl(const BinOpInfo &ops) {
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index f0d73ac872386..5f4fb2aa5c09d 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1499,6 +1499,40 @@ mlir::LogicalResult 
CIRToLLVMConstantOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMPtrDiffOpLowering::matchAndRewrite(
+cir::PtrDiffOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+  auto dstTy = mlir::cast(op.getType()

[clang] [clang][utils] Add auto mode to reduction script (PR #163282)

2025-10-15 Thread Arthur Eubanks via cfe-commits

https://github.com/aeubanks commented:

we really need to come up with some sort of testing strategy for this, 
otherwise I think it'll be very hard to maintain this script and make 
improvements without breaking things (would need some blessed way to crash the 
compiler, e.g. `#pragma clang __debug crash` crashes the frontend, need to 
figure out how to crash the middle/backend). I think I'd prefer that we figure 
that out before making improvements

https://github.com/llvm/llvm-project/pull/163282
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [llvm][clang] Sandbox filesystem reads (PR #162151)

2025-10-15 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code linter clang-tidy found issues in your code. :warning:



You can test this locally with the following command:


```bash

git diff -U0 origin/main...HEAD -- 
clang-tools-extra/clang-tidy/llvm/IOSandboxCheck.cpp 
clang-tools-extra/clang-tidy/llvm/IOSandboxCheck.h 
clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp |
python3 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py \
  -path build -p1 -quiet
```





View the output from clang-tidy here.


```

clang-tools-extra/clang-tidy/llvm/IOSandboxCheck.h:7:9: warning: header guard 
does not follow preferred style [llvm-header-guard]
7 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_IOSANDBOXCHECK_H
  | ^~~
  | LLVM_IOSANDBOXCHECK_H
8 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_IOSANDBOXCHECK_H
  | ~~~
  | LLVM_IOSANDBOXCHECK_H
```




https://github.com/llvm/llvm-project/pull/162151
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Allow weak/selectany external definitions in header units. (PR #162713)

2025-10-15 Thread via cfe-commits

https://github.com/akrieger updated 
https://github.com/llvm/llvm-project/pull/162713

>From d6a45028865b876d20639dfc54621b04b48eb597 Mon Sep 17 00:00:00 2001
From: Andrew Krieger 
Date: Thu, 9 Oct 2025 13:33:22 -0700
Subject: [PATCH] Allow weak/selectany external definitions in header units.

Summary:
weak and selectany are mechanisms for allowing the linker to
resolve ODR violations. [module.import/6] states

> A header unit shall not contain a definition of a non-inline function
or variable whose name has external linkage.

But this prevents compiling any headers with such weak symbols defined.
These occur in eg. some Windows SDK headers like `DirectXMath.h`.
---
 clang/lib/Sema/SemaDecl.cpp| 27 +-
 clang/test/CXX/module/module.import/p6.cpp | 13 +++
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6eaf7b9435491..bebcfbd6df959 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13816,13 +13816,20 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
   VDecl->setInvalidDecl();
   }
 
-  // C++ [module.import/6] external definitions are not permitted in header
-  // units.
+  // C++ [module.import/6]
+  //   ...
+  //   A header unit shall not contain a definition of a non-inline function or
+  //   variable whose name has external linkage.
+  //
+  // We choose to allow weak & selectany definitions, as they are common in
+  // headers, and have semantics similar to inline definitions which are 
allowed
+  // in header units.
   if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
   !VDecl->isInvalidDecl() && VDecl->isThisDeclarationADefinition() &&
   VDecl->getFormalLinkage() == Linkage::External && !VDecl->isInline() &&
   !VDecl->isTemplated() && !isa(VDecl) &&
-  !VDecl->getInstantiatedFromStaticDataMember()) {
+  !VDecl->getInstantiatedFromStaticDataMember() &&
+  !(VDecl->hasAttr() || VDecl->hasAttr())) {
 Diag(VDecl->getLocation(), diag::err_extern_def_in_header_unit);
 VDecl->setInvalidDecl();
   }
@@ -16153,16 +16160,24 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope 
*FnBodyScope, Decl *D,
 }
   }
 
-  // C++ [module.import/6] external definitions are not permitted in header
-  // units.  Deleted and Defaulted functions are implicitly inline (but the
+  // C++ [module.import/6]
+  //   ...
+  //   A header unit shall not contain a definition of a non-inline function or
+  //   variable whose name has external linkage.
+  //
+  // Deleted and Defaulted functions are implicitly inline (but the
   // inline state is not set at this point, so check the BodyKind explicitly).
+  // We choose to allow weak & selectany definitions, as they are common in
+  // headers, and have semantics similar to inline definitions which are 
allowed
+  // in header units.
   // FIXME: Consider an alternate location for the test where the inlined()
   // state is complete.
   if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
   !FD->isInvalidDecl() && !FD->isInlined() &&
   BodyKind != FnBodyKind::Delete && BodyKind != FnBodyKind::Default &&
   FD->getFormalLinkage() == Linkage::External && !FD->isTemplated() &&
-  !FD->isTemplateInstantiation()) {
+  !FD->isTemplateInstantiation() &&
+  !(FD->hasAttr() || FD->hasAttr())) {
 assert(FD->isThisDeclarationADefinition());
 Diag(FD->getLocation(), diag::err_extern_def_in_header_unit);
 FD->setInvalidDecl();
diff --git a/clang/test/CXX/module/module.import/p6.cpp 
b/clang/test/CXX/module/module.import/p6.cpp
index cb2d799e5b565..9e378a5fe7759 100644
--- a/clang/test/CXX/module/module.import/p6.cpp
+++ b/clang/test/CXX/module/module.import/p6.cpp
@@ -3,6 +3,9 @@
 
 // RUN: %clang_cc1 -std=c++20 -x c++-header %t/bad-header-unit.h \
 // RUN:  -emit-header-unit -o %t/bad-header-unit.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -x c++-header %t/bad-header-unit-declspec.h \
+// RUN:  -emit-header-unit -o %t/bad-header-unit.pcm -verify \
+// RUN:  -fdeclspec
 
 //--- bad-header-unit.h
 
@@ -77,3 +80,13 @@ template  bool b() {
 }
 
 inline bool B = b();
+
+__attribute__((weak)) int weak_fun_definition() { return 42; }
+
+__attribute__((weak)) int weak_var_definition = 42;
+
+//--- bad-header-unit-declspec.h
+
+/* The cases below should compile without diagnostics.  */
+
+__declspec(selectany) int selectany_var_definition = 42; // 
expected-no-diagnostics

___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV][LLVM] Enable atomics for 'Zalrsc' (PR #163672)

2025-10-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (slachowsky)


Changes

The 'A' atomics extension is composed of two subextensions, 'Zaamo' which has
atomic memory operation instructions, and 'Zalrsc' which has load-reserve /
store-conditional instructions.

For machines where 'Zalrsc' is present, but 'Zaamo' is not, implement and enable
atomics memory operations through pseudo expansion.  Updates the predication
and lowering control to be more precise about which 'Zaamo'/'Zalrsc' feature
was truly requisite.

There will be no functional change to subtargets supporting 'A', while allowing
'Zalrsc' only subtargets to utilize atomics at an increased code footprint.

---

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


11 Files Affected:

- (modified) clang/lib/Basic/Targets/RISCV.cpp (+3-1) 
- (modified) clang/lib/Basic/Targets/RISCV.h (+2-2) 
- (modified) llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp (+258-28) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+2-1) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+3-3) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoA.td (+68-8) 
- (modified) llvm/test/CodeGen/RISCV/atomic-fence.ll (+4) 
- (modified) llvm/test/CodeGen/RISCV/atomic-load-store.ll (+406) 
- (modified) llvm/test/CodeGen/RISCV/atomic-rmw-sub.ll (+102) 
- (modified) llvm/test/CodeGen/RISCV/atomic-rmw.ll (+17688) 
- (modified) llvm/test/CodeGen/RISCV/atomic-signext.ll (+2644) 


``diff
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 04da4e637af51..edfd92fc20bde 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -192,8 +192,10 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__riscv_muldiv");
   }
 
-  if (ISAInfo->hasExtension("a")) {
+  if (ISAInfo->hasExtension("a"))
 Builder.defineMacro("__riscv_atomic");
+
+  if (ISAInfo->hasExtension("a") || ISAInfo->hasExtension("zalrsc")) {
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index d8b0e64c90dd6..3e1442db131a7 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -195,7 +195,7 @@ class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public 
RISCVTargetInfo {
   void setMaxAtomicWidth() override {
 MaxAtomicPromoteWidth = 128;
 
-if (ISAInfo->hasExtension("a"))
+if (ISAInfo->hasExtension("a") || ISAInfo->hasExtension("zalrsc"))
   MaxAtomicInlineWidth = 32;
   }
 };
@@ -225,7 +225,7 @@ class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public 
RISCVTargetInfo {
   void setMaxAtomicWidth() override {
 MaxAtomicPromoteWidth = 128;
 
-if (ISAInfo->hasExtension("a"))
+if (ISAInfo->hasExtension("a") || ISAInfo->hasExtension("zalrsc"))
   MaxAtomicInlineWidth = 64;
   }
 };
diff --git a/llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp 
b/llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp
index 5dd4bf415a23c..8f033b6b14038 100644
--- a/llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp
+++ b/llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp
@@ -109,12 +109,72 @@ bool RISCVExpandAtomicPseudo::expandMI(MachineBasicBlock 
&MBB,
   // expanded instructions for each pseudo is correct in the Size field of the
   // tablegen definition for the pseudo.
   switch (MBBI->getOpcode()) {
+  case RISCV::PseudoAtomicSwap32:
+return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::Xchg, false, 32,
+ NextMBBI);
+  case RISCV::PseudoAtomicSwap64:
+return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::Xchg, false, 64,
+ NextMBBI);
+  case RISCV::PseudoAtomicLoadAdd32:
+return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::Add, false, 32,
+ NextMBBI);
+  case RISCV::PseudoAtomicLoadAdd64:
+return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::Add, false, 64,
+ NextMBBI);
+  case RISCV::PseudoAtomicLoadSub32:
+return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::Sub, false, 32,
+ NextMBBI);
+  case RISCV::PseudoAtomicLoadSub64:
+return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::Sub, false, 64,
+ NextMBBI);
+  case RISCV::PseudoAtomicLoadAnd32:
+return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::And, false, 32,
+ NextMBBI);
+  case RISCV::PseudoAtomicLoadAnd64:
+return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::And, false, 64,
+ NextMBBI);
+  case RISCV::PseudoAtomicLoadOr32:
+return expandAtomicBinOp(MBB, MBBI, AtomicRMWInst::Or, false, 32,
+ NextMBBI);
+  c

[clang] [X86][ByteCode] Allow PSHUFB intrinsics to be used in constexpr #156612 (PR #163148)

2025-10-15 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon closed 
https://github.com/llvm/llvm-project/pull/163148
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8a09111 - [AArch64] Add intrinsics for multi-vector FEAT_SVE_BFSCALE instructions (#163346)

2025-10-15 Thread via cfe-commits

Author: Lukacma
Date: 2025-10-15T10:29:38+01:00
New Revision: 8a09111fe481e6b1be98c323cbba20d37fe9e31a

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

LOG: [AArch64] Add intrinsics for multi-vector FEAT_SVE_BFSCALE instructions 
(#163346)

This patch add intrinsics support for multi-vector BFMUL and BFSCALE
instruction based on
[this](https://github.com/ARM-software/acle/pull/410) ACLE specification
proposal

Added: 
clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_bfmul.c
clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_bfscale.c
llvm/test/CodeGen/AArch64/sme2-intrinsics-bfmul.ll
llvm/test/CodeGen/AArch64/sme2-intrinsics-bfscale.ll

Modified: 
clang/include/clang/Basic/arm_sve.td
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index d2b7b78b9970f..96b5e55beca6d 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2082,6 +2082,13 @@ let SVETargetGuard = InvalidMode, SMETargetGuard = 
"sme2,sve-b16b16"in {
   defm SVBFMAXNM : BfSingleMultiVector<"maxnm">;
 }
 
+let SVETargetGuard = InvalidMode, SMETargetGuard = "sme2,sve-bfscale" in {
+  // BFMUL
+  defm SVBFMUL : BfSingleMultiVector<"mul">;
+  // BFSCALE
+  defm SVBFSCALE : BfSingleMultiVector<"scale">;
+}
+
 let SVETargetGuard = InvalidMode, SMETargetGuard = "sme2" in {
   // == ADD (vectors) ==
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;

diff  --git a/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_bfmul.c 
b/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_bfmul.c
new file mode 100644
index 0..187e9390f742c
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_bfmul.c
@@ -0,0 +1,76 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme2 -target-feature +sve-bfscale -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme2 -target-feature +sve-bfscale -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sme2 -target-feature +sve-bfscale 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sme2 -target-feature +sve-bfscale 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme2 -target-feature +sve-bfscale -S -disable-O0-optnone 
-Werror -Wall -o /dev/null %s
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
+#else
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
+#endif
+
+// CHECK-LABEL: define dso_local { ,  } @test_svmul_single_bf16_x2(
+// CHECK-SAME:  [[ZDN_COERCE0:%.*]],  [[ZDN_COERCE1:%.*]],  [[ZM:%.*]]) 
#[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sve.fmul.single.x2.nxv8bf16( 
[[ZDN_COERCE0]],  [[ZDN_COERCE1]],  
[[ZM]])
+// CHECK-NEXT:ret { ,  } [[TMP0]]
+//
+// CPP-CHECK-LABEL: define dso_local { ,  } @_Z25test_svmul_single_bf16_x214svbfloat16x2_tu14__SVBfloat16_t(
+// CPP-CHECK-SAME:  [[ZDN_COERCE0:%.*]],  [[ZDN_COERCE1:%.*]],  [[ZM:%.*]]) 
#[[ATTR0:[0-9]+]] {
+// CPP-CHECK-NEXT:  [[ENTRY:.*:]]
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { , 
 } @llvm.aarch64.sve.fmul.single.x2.nxv8bf16( [[ZDN_COERCE0]],  [[ZDN_COERCE1]],  [[ZM]])
+// CPP-CHECK-NEXT:ret { ,  } 
[[TMP0]]
+//
+svbfloat16x2_t test_svmul_single_bf16_x2(svbfloat16x2_t zdn, svbfloat16_t zm) 
__arm_streaming{
+  return SVE_ACLE_FUNC(svmul,_single_bf16_x2)(zdn, zm);
+}
+// CHECK-LABEL: define dso_local { , , ,  } 
@test_svmul_single_bf16_x4(
+// CHECK-SAME:  [[ZDN_COERCE0:%.*]],  [[ZDN_COERCE1:%.*]],  [[ZDN_COERCE2:%.*]],  [[ZDN_COERCE3:%.*]],  [[ZM:%.*]]) #[[ATTR0]] 
{
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[TMP0:%.*]] = tail cal

[clang] [Clang] VectorExprEvaluator::VisitCallExpr / InterpretBuiltin - allow AVX512 mask broadcast intrinsics to be used in constexpr (PR #163475)

2025-10-15 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon closed 
https://github.com/llvm/llvm-project/pull/163475
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Always register `asm` attribute first in a Decl. (PR #162687)

2025-10-15 Thread Giuliano Belinassi via cfe-commits

https://github.com/giulianobelinassi updated 
https://github.com/llvm/llvm-project/pull/162687

>From 60ff775737f748eef897eea35962afe699b33bdc Mon Sep 17 00:00:00 2001
From: Giuliano Belinassi 
Date: Thu, 9 Oct 2025 13:01:44 -0300
Subject: [PATCH] Always register `asm` attribute first in a Decl.

Previously, clang's SemaDecl processed `asm` attributes after every
other attribute in the Decl, unlike gcc and clang's own parser which
requires `asm` attributes to be the first one in the declaration
(see #162556).  Therefore, move the processing of `asm` attributes
to be the first one in the attributes list.

Signed-off-by: Giuliano Belinassi 
---
 clang/docs/ReleaseNotes.rst |  11 +++
 clang/include/clang/Sema/Sema.h |   8 ++
 clang/lib/Sema/SemaDecl.cpp | 136 ++--
 clang/test/Sema/attr-print.c|   3 +
 4 files changed, 99 insertions(+), 59 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5e9a71e1e74d6..4d7b2b071b6f8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -128,6 +128,17 @@ AST Dumping Potentially Breaking Changes
 
 - Default arguments of template template parameters are pretty-printed now.
 
+- Pretty-printing of ``asm`` attributes are now always the first attribute
+  on the right side of the declaration.  Before we had, e.g.:
+
+``__attribute__(("visibility")) asm("string")``
+
+  Now we have:
+
+``asm("string") __attribute__(("visibility"))``
+
+  Which is accepted by both clang and gcc parsers.
+
 Clang Frontend Potentially Breaking Changes
 ---
 - Members of anonymous unions/structs are now injected as ``IndirectFieldDecl``
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 265462a86e405..52b41bd786cb7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3961,6 +3961,14 @@ class Sema final : public SemaBase {
  bool &AddToScope,
  ArrayRef Bindings = {});
 
+  private:
+
+  // Perform a check on an AsmLabel to verify its consistency and emit
+  // diagnostics in case of an error.
+  void CheckAsmLabel(Scope *S, Expr *AsmLabelExpr, StorageClass SC,
+ TypeSourceInfo *TInfo, VarDecl *);
+  public:
+
   /// Perform semantic checking on a newly-created variable
   /// declaration.
   ///
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6eaf7b9435491..ac70158c391c8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7640,6 +7640,58 @@ static bool isMainVar(DeclarationName Name, VarDecl *VD) 
{
   VD->isExternC());
 }
 
+void Sema::CheckAsmLabel(Scope *S, Expr *E, StorageClass SC,
+ TypeSourceInfo *TInfo, VarDecl *NewVD) {
+
+  // Quickly return if the function does not have an `asm` attribute.
+  if (E == nullptr)
+return;
+
+  // The parser guarantees this is a string.
+  StringLiteral *SE = cast(E);
+  StringRef Label = SE->getString();
+  QualType R = TInfo->getType();
+  if (S->getFnParent() != nullptr) {
+switch (SC) {
+case SC_None:
+case SC_Auto:
+  Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) << Label;
+  break;
+case SC_Register:
+  // Local Named register
+  if (!Context.getTargetInfo().isValidGCCRegisterName(Label) &&
+  DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl()))
+Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
+  break;
+case SC_Static:
+case SC_Extern:
+case SC_PrivateExtern:
+  break;
+}
+  } else if (SC == SC_Register) {
+// Global Named register
+if (DeclAttrsMatchCUDAMode(getLangOpts(), NewVD)) {
+  const auto &TI = Context.getTargetInfo();
+  bool HasSizeMismatch;
+
+  if (!TI.isValidGCCRegisterName(Label))
+Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label;
+  else if (!TI.validateGlobalRegisterVariable(Label, 
Context.getTypeSize(R),
+  HasSizeMismatch))
+Diag(E->getExprLoc(), diag::err_asm_invalid_global_var_reg) << Label;
+  else if (HasSizeMismatch)
+Diag(E->getExprLoc(), diag::err_asm_register_size_mismatch) << Label;
+}
+
+if (!R->isIntegralType(Context) && !R->isPointerType()) {
+  Diag(TInfo->getTypeLoc().getBeginLoc(),
+   diag::err_asm_unsupported_register_type)
+  << TInfo->getTypeLoc().getSourceRange();
+  NewVD->setInvalidDecl(true);
+}
+  }
+}
+
 NamedDecl *Sema::ActOnVariableDeclarator(
 Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo,
 LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists,
@@ -8124,6 +8176,26 @@ NamedDecl *Sema::ActOnVariableDeclarator(
 }
   }
 
+  if (Expr *E = D.getAsmLabel()) {
+// The parser guarantees this is a string.
+St

[clang] 705b996 - Allow weak/selectany external definitions in header units. (#162713)

2025-10-15 Thread via cfe-commits

Author: akrieger
Date: 2025-10-16T02:12:46Z
New Revision: 705b99607c0c1aadc75fddef8738f22be206da25

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

LOG: Allow weak/selectany external definitions in header units. (#162713)

weak and selectany are mechanisms for allowing the linker to resolve ODR
violations. [module.import/6] states

> A header unit shall not contain a definition of a non-inline function
or variable whose name has external linkage.

But this prevents compiling any headers with such weak symbols defined.
These occur in eg. some Windows SDK headers like `DirectXMath.h`.

```
#ifndef XMGLOBALCONST
#if defined(__GNUC__) && !defined(__MINGW32__)
#define XMGLOBALCONST extern const __attribute__((weak))
#else
#define XMGLOBALCONST extern const __declspec(selectany)
#endif
#endif

XMGLOBALCONST XMVECTORF32 g_XMSinCoefficients0 = { { { -0.1667f, 
+0.008310f, -0.00019840874f, +2.7525562e-06f } } };
```

Proposed solution: Do not emit `diag::err_extern_def_in_header_unit` if
the `FD` or `VDecl` have either `SelectAnyAttr` or `WeakAttr`.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/CXX/module/module.import/p6.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8ac09c4d30f1a..04d46d6941a40 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13816,13 +13816,20 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
   VDecl->setInvalidDecl();
   }
 
-  // C++ [module.import/6] external definitions are not permitted in header
-  // units.
+  // C++ [module.import/6]
+  //   ...
+  //   A header unit shall not contain a definition of a non-inline function or
+  //   variable whose name has external linkage.
+  //
+  // We choose to allow weak & selectany definitions, as they are common in
+  // headers, and have semantics similar to inline definitions which are 
allowed
+  // in header units.
   if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
   !VDecl->isInvalidDecl() && VDecl->isThisDeclarationADefinition() &&
   VDecl->getFormalLinkage() == Linkage::External && !VDecl->isInline() &&
   !VDecl->isTemplated() && !isa(VDecl) &&
-  !VDecl->getInstantiatedFromStaticDataMember()) {
+  !VDecl->getInstantiatedFromStaticDataMember() &&
+  !(VDecl->hasAttr() || VDecl->hasAttr())) {
 Diag(VDecl->getLocation(), diag::err_extern_def_in_header_unit);
 VDecl->setInvalidDecl();
   }
@@ -16153,16 +16160,24 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope 
*FnBodyScope, Decl *D,
 }
   }
 
-  // C++ [module.import/6] external definitions are not permitted in header
-  // units.  Deleted and Defaulted functions are implicitly inline (but the
+  // C++ [module.import/6]
+  //   ...
+  //   A header unit shall not contain a definition of a non-inline function or
+  //   variable whose name has external linkage.
+  //
+  // Deleted and Defaulted functions are implicitly inline (but the
   // inline state is not set at this point, so check the BodyKind explicitly).
+  // We choose to allow weak & selectany definitions, as they are common in
+  // headers, and have semantics similar to inline definitions which are 
allowed
+  // in header units.
   // FIXME: Consider an alternate location for the test where the inlined()
   // state is complete.
   if (getLangOpts().CPlusPlusModules && currentModuleIsHeaderUnit() &&
   !FD->isInvalidDecl() && !FD->isInlined() &&
   BodyKind != FnBodyKind::Delete && BodyKind != FnBodyKind::Default &&
   FD->getFormalLinkage() == Linkage::External && !FD->isTemplated() &&
-  !FD->isTemplateInstantiation()) {
+  !FD->isTemplateInstantiation() &&
+  !(FD->hasAttr() || FD->hasAttr())) {
 assert(FD->isThisDeclarationADefinition());
 Diag(FD->getLocation(), diag::err_extern_def_in_header_unit);
 FD->setInvalidDecl();

diff  --git a/clang/test/CXX/module/module.import/p6.cpp 
b/clang/test/CXX/module/module.import/p6.cpp
index cb2d799e5b565..9e378a5fe7759 100644
--- a/clang/test/CXX/module/module.import/p6.cpp
+++ b/clang/test/CXX/module/module.import/p6.cpp
@@ -3,6 +3,9 @@
 
 // RUN: %clang_cc1 -std=c++20 -x c++-header %t/bad-header-unit.h \
 // RUN:  -emit-header-unit -o %t/bad-header-unit.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -x c++-header %t/bad-header-unit-declspec.h \
+// RUN:  -emit-header-unit -o %t/bad-header-unit.pcm -verify \
+// RUN:  -fdeclspec
 
 //--- bad-header-unit.h
 
@@ -77,3 +80,13 @@ template  bool b() {
 }
 
 inline bool B = b();
+
+__attribute__((weak)) int weak_fun_definition() { return 42; }
+
+__attribute__((weak)) int weak_var_definition = 42;
+
+//--- bad-header-unit-declspec.h
+
+/* The cases below should compile without 

[clang] [clang-tools-extra] [flang] [lldb] [llvm] [clang] Move options from clangDriver into new clangOptions library (NFC) (PR #163659)

2025-10-15 Thread Naveen Seth Hanig via cfe-commits

https://github.com/naveen-seth edited 
https://github.com/llvm/llvm-project/pull/163659
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV][LLVM] Enable atomics for 'Zalrsc' (PR #163672)

2025-10-15 Thread Sam Elliott via cfe-commits

lenary wrote:

Is there an abridged history of the RISC-V "A" spec anywhere? I feel reasonably 
out-of-touch with how it has developed (and been split into sub-extensions). 

https://github.com/llvm/llvm-project/pull/163672
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits