[libunwind] libunwind: Implement the unw_strerror function for better nongnu libunwind compatibility (PR #160887)

2025-10-18 Thread Gleb Popov via cfe-commits

https://github.com/arrowd created 
https://github.com/llvm/llvm-project/pull/160887

As it was explained to me in 
https://discourse.llvm.org/t/libunwinds-raison-detre/88283/2 the LLVM version 
of libunwind is mostly compatible with nongnu one. This change improves the 
compatibility a bit further.

>From f892211da547a857beeec279c2e493fbd75d0865 Mon Sep 17 00:00:00 2001
From: Gleb Popov <[email protected]>
Date: Fri, 26 Sep 2025 12:58:47 +0300
Subject: [PATCH] libunwind: Implement the unw_strerror function for better
 nongnu libunwind compatibility

---
 libunwind/include/libunwind.h |  1 +
 libunwind/src/libunwind.cpp   | 23 +++
 libunwind/src/libunwind_ext.h |  1 +
 3 files changed, 25 insertions(+)

diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index 94928f436025a..9d2ccc4dda7fa 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -130,6 +130,7 @@ extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) 
LIBUNWIND_AVAIL;
 extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
 extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) 
LIBUNWIND_AVAIL;
 //extern int   unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
+extern const char *unw_strerror (int) LIBUNWIND_AVAIL;
 
 extern unw_addr_space_t unw_local_addr_space;
 
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index cf39ec5f7dbdf..23335ba577e52 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -347,6 +347,29 @@ void __unw_remove_dynamic_eh_frame_section(unw_word_t 
eh_frame_start) {
 }
 
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
+
+/// Maps the UNW_* error code to a textual representation
+_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) {
+  switch (error_code) {
+  case UNW_ESUCCESS: return "no error";
+  case UNW_EUNSPEC: return "unspecified (general) error";
+  case UNW_ENOMEM: return "out of memory";
+  case UNW_EBADREG: return "bad register number";
+  case UNW_EREADONLYREG: return "attempt to write read-only register";
+  case UNW_ESTOPUNWIND: return "stop unwinding";
+  case UNW_EINVALIDIP: return "invalid IP";
+  case UNW_EBADFRAME: return "bad frame";
+  case UNW_EINVAL: return "unsupported operation or bad value";
+  case UNW_EBADVERSION: return "unwind info has unsupported version";
+  case UNW_ENOINFO: return "no unwind info found";
+#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY)
+  case UNW_ECROSSRASIGNING: return "return address require authentication";
+#endif
+  }
+  return "invalid error code";
+}
+_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror)
+
 #endif // !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
 
 #ifdef __APPLE__
diff --git a/libunwind/src/libunwind_ext.h b/libunwind/src/libunwind_ext.h
index 28db43a4f6eef..ed503ceb70c5a 100644
--- a/libunwind/src/libunwind_ext.h
+++ b/libunwind/src/libunwind_ext.h
@@ -42,6 +42,7 @@ extern int __unw_get_proc_info(unw_cursor_t *, 
unw_proc_info_t *);
 extern int __unw_is_fpreg(unw_cursor_t *, unw_regnum_t);
 extern int __unw_is_signal_frame(unw_cursor_t *);
 extern int __unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *);
+extern const char *__unw_strerror(int);
 
 #if defined(_AIX)
 extern uintptr_t __unw_get_data_rel_base(unw_cursor_t *);

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


[clang] [Clang][Sema] Switch diagnostics from toString to operator<< for APSInt/APInt (PR #161474)

2025-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Samarth Narang (snarang181)


Changes

This patch continues the cleanup with respect to 
StreamingDiagnostic::operator<< overloads for APSInt and APInt.

Implements https://github.com/issues/assigned?issue=llvm%7Cllvm-project%7C161325

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


8 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+6-7) 
- (modified) clang/test/AST/ByteCode/const-eval.c (+1-1) 
- (modified) clang/test/Sema/const-eval.c (+1-1) 
- (modified) clang/test/Sema/integer-overflow.c (+1-1) 
- (modified) clang/test/Sema/unbounded-array-bounds.c (+23-23) 
- (modified) clang/test/SemaCXX/array-bounds.cpp (+2-2) 
- (modified) clang/test/SemaCXX/constant-expression-cxx14.cpp (+1-1) 
- (modified) clang/test/SemaCXX/integer-overflow.cpp (+1-1) 


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 39c3aa2243338..08e4a693bd556 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14882,7 +14882,7 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const 
Expr *IndexExpr,
   // dependent CharUnits)
   DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
   PDiag(DiagID)
-  << toString(index, 10, true) << AddrBits
+  << index << AddrBits
   << (unsigned)ASTC.toBits(*ElemCharUnits)
   << toString(ElemBytes, 10, false)
   << toString(MaxElems, 10, false)
@@ -14970,10 +14970,10 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, 
const Expr *IndexExpr,
 unsigned CastMsg = (!ASE || BaseType == EffectiveType) ? 0 : 1;
 QualType CastMsgTy = ASE ? ASE->getLHS()->getType() : QualType();
 
-DiagRuntimeBehavior(
-BaseExpr->getBeginLoc(), BaseExpr,
-PDiag(DiagID) << toString(index, 10, true) << ArrayTy->desugar()
-  << CastMsg << CastMsgTy << IndexExpr->getSourceRange());
+DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
+PDiag(DiagID)
+<< index << ArrayTy->desugar() << CastMsg
+<< CastMsgTy << IndexExpr->getSourceRange());
   } else {
 unsigned DiagID = diag::warn_array_index_precedes_bounds;
 if (!ASE) {
@@ -14982,8 +14982,7 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, const 
Expr *IndexExpr,
 }
 
 DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
-PDiag(DiagID) << toString(index, 10, true)
-  << IndexExpr->getSourceRange());
+PDiag(DiagID) << index << IndexExpr->getSourceRange());
   }
 
   const NamedDecl *ND = nullptr;
diff --git a/clang/test/AST/ByteCode/const-eval.c 
b/clang/test/AST/ByteCode/const-eval.c
index c6b51d16b811e..407e1f19ca756 100644
--- a/clang/test/AST/ByteCode/const-eval.c
+++ b/clang/test/AST/ByteCode/const-eval.c
@@ -144,7 +144,7 @@ EVAL_EXPR(52, &pr24622 == (void *)&PR24622);
 
 // We evaluate these by providing 2s' complement semantics in constant
 // expressions, like we do for integers.
-void *PR28739a = (__int128)(unsigned long)-1 + &PR28739a;  // 
both-warning {{the pointer incremented by 18446744073709551615 refers past the 
last possible element for an array in 64-bit address space containing 64-bit 
(8-byte) elements (max possible 2305843009213693952 elements)}}
+void *PR28739a = (__int128)(unsigned long)-1 + &PR28739a;  // 
both-warning {{the pointer incremented by 18'446'744'073'709'551'615 refers 
past the last possible element for an array in 64-bit address space containing 
64-bit (8-byte) elements (max possible 2305843009213693952 elements)}}
 
 void *PR28739b = &PR28739b + (__int128)(unsigned long)-1;  // 
both-warning {{refers past the last possible element}}
 __int128 PR28739c = (&PR28739c + (__int128)(unsigned long)-1) - &PR28739c; // 
both-warning {{refers past the last possible element}}
diff --git a/clang/test/Sema/const-eval.c b/clang/test/Sema/const-eval.c
index 11cc7fbc0feb3..531bde9814438 100644
--- a/clang/test/Sema/const-eval.c
+++ b/clang/test/Sema/const-eval.c
@@ -138,7 +138,7 @@ EVAL_EXPR(52, &pr24622 == (void *)&PR24622);
 
 // We evaluate these by providing 2s' complement semantics in constant
 // expressions, like we do for integers.
-void *PR28739a = (__int128)(unsigned long)-1 + &PR28739a;  // 
expected-warning {{the pointer incremented by 18446744073709551615 refers past 
the last possible element for an array in 64-bit address space containing 
64-bit (8-byte) elements (max possible 2305843009213693952 elements)}}
+void *PR28739a = (__int128)(unsigned long)-1 + &PR28739a;  // 
expected-warning {{the pointer incremented by 18'446'744'073'709'551'615 refers 
past the last possible element 

[clang] [CIR] Refactor cir.cast to use uniform assembly form w/o parens, commas (PR #161431)

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

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

LGTM, Thanks!

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


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

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


@@ -0,0 +1,94 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "AvoidDefaultLambdaCaptureCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/Lambda.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {

jjmarr-amd wrote:

do not re-open namespace in source file.

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] [Driver][Hurd] Add AArch64 and RISCV64 support (PR #157212)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-asan` running on `sanitizer-buildbot7` while 
building `clang,llvm` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:530:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:530:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:530:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:530:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:530:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:530:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:530:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:74:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 90760 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.
FAIL: lit :: shtest-readfile-external.py (87575 of 90760)
 TEST 'lit :: shtest-readfile-external.py' FAILED 

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 4
env LIT_USE_INTERNAL_SHELL=0 not env -u FILECHECK_OPTS "/usr/bin/python3" 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py
 -j1 --order=lexical -a -v Inputs/shtest-readfile | FileCheck -match-full-lines 
-DTEMP_PATH=/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/utils/lit/tests/Inputs/shtest-readfile/Output
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/utils/lit/tests/shtest-readfile-external.py
# executed command: env LIT_USE_INTERNAL_SHELL=0 not env -u FILECHECK_OPTS 
/usr/bin/python3 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py
 -j1 --order=lexical -a -v Inputs/shtest-readfile
# note: command had no output on stdout or stderr
# executed command: FileCheck -match-full-lines 
-DTEMP_PATH=/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/utils/lit/tests/Inputs/shtest-readfile/Output
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/utils/lit/tests/shtest-readfile-external.py
# .---command stderr
# | 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/utils/lit/tests/shtest-readfile-external.py:10:10:
 error: CHECK: expected string not found in input
# | # CHECK: + echo hello
# |  ^
# | :16:316: note: scanning from here
# | echo $(cat 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/utils/lit/tests/Inputs/shtest-readfile/Output/absolute-paths.txt.tmp)
 && test -e 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/utils/lit/tests/Inputs/shtest-readfile/Output/absolute-paths.txt.tmp
 # RUN: at line 3
# | 


   ^
# | :21:1: note: possible intended match here
# | + not echo return
# | ^
# | 
# | Input file: 
# | Check file: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/utils/lit/tests/shtest-readfile-external.py
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# | .
# | .
# |   

[clang] [Headers][X86] Allow MMX/SSE/AVX MOVMSK intrinsics to be used in constexpr (PR #161914)

2025-10-18 Thread Shafik Yaghmour via cfe-commits


@@ -2817,6 +2817,46 @@ static bool interp__builtin_ia32_pshuf(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_ia32_movmsk_op(InterpState &S, CodePtr OpPC,
+   const CallExpr *Call) {
+  assert(Call->getNumArgs() == 1);
+
+  const Pointer &Source = S.Stk.pop();
+
+  unsigned SourceLen = Source.getNumElems();

shafik wrote:

How large can `SourceLen` be? I would guess 64 or 128? Should we assert this or 
produce a diagnostic?

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


[clang] [Headers][X86] VectorExprEvaluator::VisitCallExpr - allow SSE/AVX2/AVX512 pack intrinsics to be used in constexpr (PR #156003)

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


@@ -11575,6 +11575,46 @@ static bool handleVectorElementCast(EvalInfo &Info, 
const FPOptions FPO,
   return false;
 }
 
+static bool evalPackBuiltin(const CallExpr *E, EvalInfo &Info, APValue &Result,
+llvm::function_ref PackFn) {
+  APValue LHS, RHS;
+  if (!EvaluateAsRValue(Info, E->getArg(0), LHS) ||
+  !EvaluateAsRValue(Info, E->getArg(1), RHS))
+return false;
+
+  unsigned LHSVecLen = LHS.getVectorLength();
+  unsigned RHSVecLen = RHS.getVectorLength();
+
+  assert(LHSVecLen != 0 && LHSVecLen == RHSVecLen &&
+ "pack builtin LHSVecLen must equal to RHSVecLen");
+
+  const VectorType *VT0 = E->getArg(0)->getType()->castAs();
+  const unsigned SrcBits = Info.Ctx.getIntWidth(VT0->getElementType());
+
+  const VectorType *DstVT = E->getType()->castAs();
+  QualType DstElemTy = DstVT->getElementType();
+  const bool DstIsUnsigned = DstElemTy->isUnsignedIntegerType();
+
+  const unsigned srcPerLane = 128 / SrcBits;

RKSimon wrote:

(style) Capitalize first letter of variables: SrcPerLane, Lanes, Lane, I etc.

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


[clang] [llvm] [Offload][PGO] Fix PGO on NVPTX targets (PR #143568)

2025-10-18 Thread Joseph Huber via cfe-commits


@@ -947,11 +954,18 @@ bool InstrLowerer::lower() {
   if (!ContainsProfiling && !CoverageNamesVar)
 return MadeChange;
 
+  // Cached info for generating delayed offset calculations
+  // This is only relevant on NVPTX targets
+  SmallVector Kernels;
+  SmallVector ValueSites;

jhuber6 wrote:

Self-referential initializers are busted in PTX because whoever programmed it 
decided that it didn't work. The only way to work around it is to change how 
it's initialized to no longer be self-referential.

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


[clang-tools-extra] [clang-tidy] Add IgnoredRegex to 'bugprone-suspicious-include' (PR #160958)

2025-10-18 Thread via cfe-commits
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= ,
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= ,
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= ,
=?utf-8?q?Bj=C3=B6rn_Sch=C3=A4pers?= 
Message-ID:
In-Reply-To: 



@@ -28,9 +27,12 @@ class SuspiciousIncludeCheck : public ClangTidyCheck {
   SuspiciousIncludeCheck(StringRef Name, ClangTidyContext *Context);
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
 
   FileExtensionsSet HeaderFileExtensions;
   FileExtensionsSet ImplementationFileExtensions;
+  std::optional IgnoredRegexString;

EugeneZelenko wrote:

Please make all data members private.

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


[clang] [clang][docs] Remove Python2 import handler in dump_ast_matchers.py (PR #163730)

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

https://github.com/DavidSpickett created 
https://github.com/llvm/llvm-project/pull/163730

LLVM requires Python >=3.8 and in Python 3.0 urllib2 was renamed to urllib.

https://docs.python.org/3/whatsnew/3.0.html#library-changes

>From 9e4e8bf34098b03a83db320b18b295325e9038db Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Thu, 16 Oct 2025 10:06:39 +
Subject: [PATCH] [clang][docs] Remove Python2 import handler in
 dump_ast_matchers.py

LLVM requires Python >=3.8 and in Python 3.0 urllib2 was renamed
to urllib.

https://docs.python.org/3/whatsnew/3.0.html#library-changes
---
 clang/docs/tools/dump_ast_matchers.py | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/docs/tools/dump_ast_matchers.py 
b/clang/docs/tools/dump_ast_matchers.py
index 46b7bb718ba08..5db6826070934 100755
--- a/clang/docs/tools/dump_ast_matchers.py
+++ b/clang/docs/tools/dump_ast_matchers.py
@@ -6,11 +6,8 @@
 import collections
 import re
 import os
+from urllib.request import urlopen
 
-try:
-from urllib.request import urlopen
-except ImportError:
-from urllib2 import urlopen
 
 CLASS_INDEX_PAGE_URL = "https://clang.llvm.org/doxygen/classes.html";
 try:

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


[clang] [CIR][NFC] Update existing atomic ops to match assembly conventions (PR #161543)

2025-10-18 Thread Bruno Cardoso Lopes via cfe-commits

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

Good catch! LGTM - perhaps this is more NFCI than NFC? Seems like it's fixing 
some parser bugs?

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


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

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

https://github.com/jjmarr-amd updated 
https://github.com/llvm/llvm-project/pull/160150

>From 35df1c6ea3af8dbaea2d7049ae79b14ce39f0774 Mon Sep 17 00:00:00 2001
From: JJ Marr 
Date: Fri, 11 Jul 2025 14:40:57 -0400
Subject: [PATCH 01/22] Bugprone-default-lambda-capture

on-behalf-of: @AMD 
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/DefaultLambdaCaptureCheck.cpp| 35 +++
 .../bugprone/DefaultLambdaCaptureCheck.h  | 26 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  9 ++
 .../bugprone/default-lambda-capture.rst   | 42 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../bugprone/default-lambda-capture.cpp   | 98 +++
 8 files changed, 215 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/DefaultLambdaCaptureCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/DefaultLambdaCaptureCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/default-lambda-capture.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/default-lambda-capture.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 491de6acea2b7..db99d57c511b8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -23,6 +23,7 @@
 #include "CopyConstructorInitCheck.h"
 #include "CrtpConstructorAccessibilityCheck.h"
 #include "DanglingHandleCheck.h"
+#include "DefaultLambdaCaptureCheck.h"
 #include "DynamicStaticInitializersCheck.h"
 #include "EasilySwappableParametersCheck.h"
 #include "EmptyCatchCheck.h"
@@ -134,6 +135,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-copy-constructor-init");
 CheckFactories.registerCheck(
 "bugprone-dangling-handle");
+CheckFactories.registerCheck(
+"bugprone-default-lambda-capture");
 CheckFactories.registerCheck(
 "bugprone-dynamic-static-initializers");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 46bc8efd44bc5..66125c9d22c1c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -19,6 +19,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   CopyConstructorInitCheck.cpp
   CrtpConstructorAccessibilityCheck.cpp
   DanglingHandleCheck.cpp
+  DefaultLambdaCaptureCheck.cpp
   DynamicStaticInitializersCheck.cpp
   EasilySwappableParametersCheck.cpp
   EmptyCatchCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/DefaultLambdaCaptureCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/DefaultLambdaCaptureCheck.cpp
new file mode 100644
index 0..6c95fbc984c5a
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/DefaultLambdaCaptureCheck.cpp
@@ -0,0 +1,35 @@
+#include "DefaultLambdaCaptureCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void DefaultLambdaCaptureCheck::registerMatchers(MatchFinder *Finder) {
+  // Match any lambda expression
+  Finder->addMatcher(lambdaExpr().bind("lambda"), this);
+}
+
+void DefaultLambdaCaptureCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Lambda = Result.Nodes.getNodeAs("lambda");
+  if (!Lambda)
+return;
+
+  // Check if lambda has a default capture
+  if (Lambda->getCaptureDefault() == LCD_None)
+return;
+
+  SourceLocation DefaultCaptureLoc = Lambda->getCaptureDefaultLoc();
+  if (DefaultCaptureLoc.isInvalid())
+return;
+
+  const char *CaptureKind =
+  (Lambda->getCaptureDefault() == LCD_ByCopy) ? "by-copy" : "by-reference";
+
+  diag(DefaultCaptureLoc, "lambda %0 default capture is discouraged; "
+  "prefer to capture specific variables explicitly")
+  << CaptureKind;
+}
+
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/DefaultLambdaCaptureCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/DefaultLambdaCaptureCheck.h
new file mode 100644
index 0..ac47c866cfccd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/DefaultLambdaCaptureCheck.h
@@ -0,0 +1,26 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DEFAULT_LAMBDA_CAPTURE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DEFAULT_LAMBDA_CAPTURE_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/** Flags lambdas that use default capture modes
+ *
+ * For the user-facing documentation see:
+ * 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/default-lambda-capture.html
+ */
+class DefaultLambdaCaptureCheck : public ClangTidyCheck {
+public:
+  DefaultLambdaCaptureCheck(StringRef Na

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

2025-10-18 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;

erichkeane wrote:

I might suggest naming this `condExprVal` or something?

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] [Sema] Don't call isNonConstantStorage on incomplete variable types (PR #161590)

2025-10-18 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak updated 
https://github.com/llvm/llvm-project/pull/161590

>From a46d41190f491e7f6f3cf7bcdbbbdf1d4ab7b030 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Wed, 1 Oct 2025 11:58:31 -0700
Subject: [PATCH 1/3] [Sema] Don't call isNonConstantStorage on incomplete
 variable types

The code that applies section attributes to global variables was
crashing when it encountered a variable whose type was incomplete. This
change adds a check to ensure the variable's type is complete before
calling the function.

Fixes #120371

rdar://155577913
---
 clang/lib/Sema/SemaDecl.cpp | 95 +++--
 clang/test/SemaCXX/attr-section.cpp |  8 +++
 2 files changed, 58 insertions(+), 45 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0069b08f1991a..e6271745e7ac1 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -14918,52 +14918,57 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
   }
 
   // Apply section attributes and pragmas to global variables.
-  if (GlobalStorage && var->isThisDeclarationADefinition() &&
-  !inTemplateInstantiation()) {
-PragmaStack *Stack = nullptr;
-int SectionFlags = ASTContext::PSF_Read;
-bool MSVCEnv =
-Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment();
-std::optional Reason;
-if (HasConstInit &&
-!(Reason = var->getType().isNonConstantStorage(Context, true, false))) 
{
-  Stack = &ConstSegStack;
-} else {
-  SectionFlags |= ASTContext::PSF_Write;
-  Stack = var->hasInit() && HasConstInit ? &DataSegStack : &BSSSegStack;
-}
-if (const SectionAttr *SA = var->getAttr()) {
-  if (SA->getSyntax() == AttributeCommonInfo::AS_Declspec)
+  [&]() {
+if (GlobalStorage && var->isThisDeclarationADefinition() &&
+!inTemplateInstantiation()) {
+  PragmaStack *Stack = nullptr;
+  int SectionFlags = ASTContext::PSF_Read;
+  bool MSVCEnv =
+  Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment();
+  std::optional Reason;
+  if (HasConstInit && var->getType()->isIncompleteType())
+return;
+  if (HasConstInit && !(Reason = var->getType().isNonConstantStorage(
+Context, true, false))) {
+Stack = &ConstSegStack;
+  } else {
+SectionFlags |= ASTContext::PSF_Write;
+Stack = var->hasInit() && HasConstInit ? &DataSegStack : &BSSSegStack;
+  }
+  if (const SectionAttr *SA = var->getAttr()) {
+if (SA->getSyntax() == AttributeCommonInfo::AS_Declspec)
+  SectionFlags |= ASTContext::PSF_Implicit;
+UnifySection(SA->getName(), SectionFlags, var);
+  } else if (Stack->CurrentValue) {
+if (Stack != &ConstSegStack && MSVCEnv &&
+ConstSegStack.CurrentValue != ConstSegStack.DefaultValue &&
+var->getType().isConstQualified()) {
+  assert((!Reason || Reason != QualType::NonConstantStorageReason::
+   NonConstNonReferenceType) &&
+ "This case should've already been handled elsewhere");
+  Diag(var->getLocation(), diag::warn_section_msvc_compat)
+  << var << ConstSegStack.CurrentValue
+  << (int)(!HasConstInit
+   ? QualType::NonConstantStorageReason::NonTrivialCtor
+   : *Reason);
+}
 SectionFlags |= ASTContext::PSF_Implicit;
-  UnifySection(SA->getName(), SectionFlags, var);
-} else if (Stack->CurrentValue) {
-  if (Stack != &ConstSegStack && MSVCEnv &&
-  ConstSegStack.CurrentValue != ConstSegStack.DefaultValue &&
-  var->getType().isConstQualified()) {
-assert((!Reason || Reason != QualType::NonConstantStorageReason::
- NonConstNonReferenceType) &&
-   "This case should've already been handled elsewhere");
-Diag(var->getLocation(), diag::warn_section_msvc_compat)
-<< var << ConstSegStack.CurrentValue << (int)(!HasConstInit
-? QualType::NonConstantStorageReason::NonTrivialCtor
-: *Reason);
-  }
-  SectionFlags |= ASTContext::PSF_Implicit;
-  auto SectionName = Stack->CurrentValue->getString();
-  var->addAttr(SectionAttr::CreateImplicit(Context, SectionName,
-   Stack->CurrentPragmaLocation,
-   
SectionAttr::Declspec_allocate));
-  if (UnifySection(SectionName, SectionFlags, var))
-var->dropAttr();
-}
-
-// Apply the init_seg attribute if this has an initializer.  If the
-// initializer turns out to not be dynamic, we'll end up ignoring this
-// attribute.
-if (CurInitSeg && var->getInit())
-  var->addAttr(InitSegAttr::CreateImplicit(Context, 
CurInitSeg->getString(),
-   

[clang-tools-extra] [clang-doc] fix CSS, JS paths for HTML Mustache generation (PR #160360)

2025-10-18 Thread Erick Velez via cfe-commits

evelez7 wrote:

This fix has to delete the HTML Mustache unit tests because I don't think it's 
possible to create nested temporary directories like what the unit test was 
doing. We'd need a temp "HTML" dir inside the temp "createResourcesTest" dir. 
I'm not sure if this also aligns with the previous "anti-pattern" of 
creating/checking files during unit tests.

I could avoid deleting the unit test if the resource files were placed one 
level above the `HTML` dir (so in the context `RootDir`), but then the 
templates would need to refer to `../clang-doc.css`, etc. That would mean the 
`HTML` dir cant be moved around easily.

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


[clang] [clang] Implement __builtin_stdc_rotate_left, __builtin_stdc_rotate_right (PR #160259)

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

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

>From 26d8f5393ce6c4795868d1038177e321b19576de Mon Sep 17 00:00:00 2001
From: NagaChaitanya Vellanki 
Date: Tue, 23 Sep 2025 02:17:49 -0700
Subject: [PATCH] [clang] Implement __builtin_stdc_rotate_left and
 __builtin_stdc_rotate_right

This patch adds type-generic rotate builtins that accept any unsigned integer
type. These builtins provide:

- Support for all unsigned integer types, including _BitInt
- Constexpr evaluation capability
- Automatic normalization of rotation counts modulo the bit-width
- Proper handling of negative rotation counts (converted to equivalent
  positive rotations in the opposite direction)
- Implicit conversion support for both arguments, allowing bool, float, and
  types with conversion operators (not limited to record types)

The builtins follow C23 naming conventions.

Resolves #122819
---
 clang/docs/LanguageExtensions.rst |  36 +++
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/Basic/Builtins.td |  12 +
 clang/lib/AST/ExprConstant.cpp|  60 +++--
 clang/lib/CodeGen/CGBuiltin.cpp   |  35 ++-
 clang/lib/Sema/SemaChecking.cpp   |  67 ++
 clang/test/CodeGen/builtin-rotate.c   | 214 ++
 clang/test/Sema/builtin-stdc-rotate.c | 126 +++
 .../SemaCXX/constexpr-builtin-stdc-rotate.cpp | 199 
 9 files changed, 738 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Sema/builtin-stdc-rotate.c
 create mode 100644 clang/test/SemaCXX/constexpr-builtin-stdc-rotate.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 6bb99c757cd19..3a650e4aa13bd 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3680,6 +3680,42 @@ the arguments. Both arguments and the result have the 
bitwidth specified
 by the name of the builtin. These builtins can be used within constant
 expressions.
 
+``__builtin_stdc_rotate_left`` and ``__builtin_stdc_rotate_right``
+--
+
+**Syntax**:
+
+.. code-block:: c
+
+T __builtin_stdc_rotate_left(T value, count)
+T __builtin_stdc_rotate_right(T value, count)
+
+where ``T`` is any unsigned integer type and ``count`` is any integer type.
+
+**Description**:
+
+These builtins rotate the bits in ``value`` by ``count`` positions. The
+``__builtin_stdc_rotate_left`` builtin rotates bits to the left, while
+``__builtin_stdc_rotate_right`` rotates bits to the right. The first
+argument (``value``) must be an unsigned integer type, including ``_BitInt`` 
types.
+The second argument (``count``) can be any integer type. The rotation count is
+normalized modulo the bit-width of the value being rotated, with negative
+counts converted to equivalent positive rotations (e.g., rotating left
+by ``-1`` is equivalent to rotating left by ``BitWidth-1``). These builtins can
+be used within constant expressions.
+
+**Example of use**:
+
+.. code-block:: c
+
+  unsigned char rotated_left = __builtin_stdc_rotate_left((unsigned char)0xB1, 
3);
+  unsigned int rotated_right = __builtin_stdc_rotate_right(0x12345678U, 8);
+
+  unsigned char neg_rotate = __builtin_stdc_rotate_left((unsigned char)0xB1, 
-1);
+
+  unsigned _BitInt(20) value = 0xABCDE;
+  unsigned _BitInt(20) rotated = __builtin_stdc_rotate_left(value, 5);
+
 ``__builtin_unreachable``
 -
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5e9a71e1e74d6..dbec3eb4130ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -257,6 +257,11 @@ Non-comprehensive list of changes in this release
 
 - Fixed a crash when the second argument to ``__builtin_assume_aligned`` was 
not constant (#GH161314)
 
+- Added ``__builtin_stdc_rotate_left`` and ``__builtin_stdc_rotate_right``
+  for bit rotation of unsigned integers including ``_BitInt`` types. Rotation
+  counts are normalized modulo the bit-width and support negative values.
+  Usable in constant expressions.
+
 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/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 468121f7d20ab..bc5be5551318b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -767,12 +767,24 @@ def RotateLeft : BitInt8_16_32_64BuiltinsTemplate, 
Builtin {
   let Prototype = "T(T, T)";
 }
 
+def StdcRotateLeft : Builtin {
+  let Spellings = ["__builtin_stdc_rotate_left"];
+  let Attributes = [NoThrow, Const, Constexpr, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 def RotateRight : BitInt8_16_32_64BuiltinsTemplate, Builtin {
   let Spellings 

[clang] [CIR] Upstream Exception CXXTryStmt (PR #162528)

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

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/162528

Upstream, the basic support for the C++ try catch statement with an empty try 
block and with a catch-all statement

Issue #154992

>From 22d4680619e8b41b2985090d78c3ddcd687a2eef Mon Sep 17 00:00:00 2001
From: Amr Hesham 
Date: Tue, 7 Oct 2025 20:26:05 +0200
Subject: [PATCH] [CIR] Upstream Exception CXXTryStmt

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  64 +++-
 clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp|   4 +
 clang/lib/CIR/CodeGen/CIRGenCXXABI.h  |   3 +
 clang/lib/CIR/CodeGen/CIRGenCleanup.cpp   |   7 +
 clang/lib/CIR/CodeGen/CIRGenCleanup.h |  94 ++-
 clang/lib/CIR/CodeGen/CIRGenException.cpp | 155 ++
 clang/lib/CIR/CodeGen/CIRGenFunction.h|  21 +++
 clang/lib/CIR/CodeGen/CIRGenStmt.cpp  |   3 +-
 clang/lib/CIR/CodeGen/EHScopeStack.h  |   8 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 133 +++
 .../lib/CIR/Dialect/Transforms/FlattenCFG.cpp |  32 +++-
 clang/test/CIR/CodeGen/try-catch.cpp  |  29 
 12 files changed, 546 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/CIR/CodeGen/try-catch.cpp

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 66c4c04f23108..d472445362e6f 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -537,7 +537,7 @@ def CIR_StoreOp : CIR_Op<"store", [
 
 defvar CIR_ReturnableScopes = [
   "FuncOp", "ScopeOp", "IfOp", "SwitchOp", "CaseOp",
-  "DoWhileOp", "WhileOp", "ForOp"
+  "DoWhileOp", "WhileOp", "ForOp", "TryOp"
 ];
 
 def CIR_ReturnOp : CIR_Op<"return", [
@@ -684,7 +684,7 @@ def CIR_ConditionOp : CIR_Op<"condition", [
 
 defvar CIR_YieldableScopes = [
   "ArrayCtor", "ArrayDtor", "CaseOp", "DoWhileOp", "ForOp", "GlobalOp", "IfOp",
-  "ScopeOp", "SwitchOp", "TernaryOp", "WhileOp"
+  "ScopeOp", "SwitchOp", "TernaryOp", "WhileOp", "TryOp"
 ];
 
 def CIR_YieldOp : CIR_Op<"yield", [
@@ -4202,6 +4202,66 @@ def CIR_AllocExceptionOp : CIR_Op<"alloc.exception"> {
   }];
 }
 
+//===--===//
+// TryOp
+//===--===//
+
+// Represents the unwind region where unwind continues or
+// the program std::terminate's.
+def CIR_CatchUnwind : CIR_UnitAttr<"CatchUnwind", "unwind"> {
+  let storageType = [{ CatchUnwind }];
+}
+
+// Represents the catch_all region.
+def CIR_CatchAll : CIR_UnitAttr<"CatchAll", "all"> {
+  let storageType = [{ CatchAllAttr }];
+}
+
+def CIR_TryOp : CIR_Op<"try",[
+  DeclareOpInterfaceMethods,
+  RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments
+]> {
+  let summary = "C++ try block";
+  let description = [{
+```mlir
+
+Holds the lexical scope of `try {}`. Note that resources used on catch
+clauses are usually allocated in the same parent as `cir.try`.
+
+`synthetic`: use `cir.try` to represent try/catches not originally
+present in the source code (e.g. `g = new Class` under `-fexceptions`).
+
+`cleanup`: signal to targets (LLVM for now) that this try/catch, needs
+to specially tag their landing pads as needing "cleanup".
+
+Example: TBD
+```
+  }];
+
+  let arguments = (ins UnitAttr:$synthetic, UnitAttr:$cleanup,
+   OptionalAttr:$catch_types);
+  let regions = (region AnyRegion:$try_region,
+VariadicRegion:$catch_regions);
+
+  let assemblyFormat = [{
+(`synthetic` $synthetic^)?
+(`cleanup` $cleanup^)?
+$try_region
+custom($catch_regions, $catch_types)
+attr-dict
+  }];
+
+  // Everything already covered elsewhere.
+  let builders = [
+OpBuilder<(ins
+  "llvm::function_ref":$tryBuilder,
+  "llvm::function_ref"
+  :$catchBuilder)>,
+  ];
+
+  let hasLLVMLowering = false;
+}
+
 
//===--===//
 // Atomic operations
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp 
b/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp
index 5f1faabde22a5..9c5ea54c3adb6 100644
--- a/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp
@@ -36,6 +36,10 @@ CIRGenCXXABI::AddedStructorArgCounts 
CIRGenCXXABI::addImplicitConstructorArgs(
 addedArgs.suffix.size());
 }
 
+CatchTypeInfo CIRGenCXXABI::getCatchAllTypeInfo() {
+  return CatchTypeInfo{nullptr, 0};
+}
+
 void CIRGenCXXABI::buildThisParam(CIRGenFunction &cgf,
   FunctionArgList ¶ms) {
   const auto *md = cast(cgf.curGD.getDecl());
diff --git a/clang/lib/CIR/CodeGen/CIRGenCXXABI.h 
b/clang/lib/CIR/CodeGen/CIRGenCXXABI.h
index be66240c280ec..fc16e15fd6950 100644
--- a/clang/lib/CI

[clang] [CIR] Add array new cookie support (PR #163649)

2025-10-18 Thread via cfe-commits

https://github.com/jiang1997 updated 
https://github.com/llvm/llvm-project/pull/163649

>From 8c5e9b829f152a373e89ee38de447beb7ad4458a Mon Sep 17 00:00:00 2001
From: jiang1997 
Date: Mon, 13 Oct 2025 03:09:05 +0800
Subject: [PATCH] [CIR] Add array new cookie support

---
 clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp|   3 +-
 clang/lib/CIR/CodeGen/CIRGenCXXABI.h  |  22 +++-
 clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp   |  73 +--
 clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp |  74 ++-
 clang/lib/CIR/CodeGen/CIRGenModule.cpp|   2 +-
 clang/lib/CIR/CodeGen/CIRGenTypeCache.h   |  10 +-
 clang/test/CIR/CodeGen/new.cpp| 119 ++
 7 files changed, 287 insertions(+), 16 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp 
b/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp
index df42af828b0a3..1cd74f7688416 100644
--- a/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp
@@ -81,8 +81,7 @@ CharUnits CIRGenCXXABI::getArrayCookieSize(const CXXNewExpr 
*e) {
   if (!requiresArrayCookie(e))
 return CharUnits::Zero();
 
-  cgm.errorNYI(e->getSourceRange(), "CIRGenCXXABI::getArrayCookieSize");
-  return CharUnits::Zero();
+  return getArrayCookieSizeImpl(e->getAllocatedType());
 }
 
 bool CIRGenCXXABI::requiresArrayCookie(const CXXNewExpr *e) {
diff --git a/clang/lib/CIR/CodeGen/CIRGenCXXABI.h 
b/clang/lib/CIR/CodeGen/CIRGenCXXABI.h
index 06f41cd8fcfdb..e9ee5e9713258 100644
--- a/clang/lib/CIR/CodeGen/CIRGenCXXABI.h
+++ b/clang/lib/CIR/CodeGen/CIRGenCXXABI.h
@@ -290,8 +290,28 @@ class CIRGenCXXABI {
   ///   - non-array allocations never need a cookie
   ///   - calls to \::operator new(size_t, void*) never need a cookie
   ///
-  /// \param E - the new-expression being allocated.
+  /// \param e - the new-expression being allocated.
   virtual CharUnits getArrayCookieSize(const CXXNewExpr *e);
+
+  /// Initialize the array cookie for the given allocation.
+  ///
+  /// \param newPtr - a char* which is the presumed-non-null
+  ///   return value of the allocation function
+  /// \param numElements - the computed number of elements,
+  ///   potentially collapsed from the multidimensional array case;
+  ///   always a size_t
+  /// \param elementType - the base element allocated type,
+  ///   i.e. the allocated type after stripping all array types
+  virtual Address initializeArrayCookie(CIRGenFunction &cgf, Address newPtr,
+mlir::Value numElements,
+const CXXNewExpr *e,
+QualType elementType) = 0;
+
+protected:
+  /// Returns the extra size required in order to store the array
+  /// cookie for the given type.  Assumes that an array cookie is
+  /// required.
+  virtual CharUnits getArrayCookieSizeImpl(QualType elementType) = 0;
 };
 
 /// Creates and Itanium-family ABI
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
index 97c0944fca336..c2a062441c289 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
@@ -283,6 +283,7 @@ static mlir::Value emitCXXNewAllocSize(CIRGenFunction &cgf, 
const CXXNewExpr *e,
 mlir::cast(constNumElements).getValue();
 
 unsigned numElementsWidth = count.getBitWidth();
+bool hasAnyOverflow = false;
 
 // The equivalent code in CodeGen/CGExprCXX.cpp handles these cases as
 // overflow, but that should never happen. The size argument is implicitly
@@ -313,11 +314,22 @@ static mlir::Value emitCXXNewAllocSize(CIRGenFunction 
&cgf, const CXXNewExpr *e,
 
 // Add in the cookie, and check whether it's overflowed.
 if (cookieSize != 0) {
-  cgf.cgm.errorNYI(e->getSourceRange(),
-   "emitCXXNewAllocSize: array cookie");
+  // Save the current size without a cookie.  This shouldn't be
+  // used if there was overflow
+  sizeWithoutCookie = cgf.getBuilder().getConstInt(
+  loc, allocationSize.zextOrTrunc(sizeWidth));
+
+  allocationSize = allocationSize.uadd_ov(cookieSize, overflow);
+  hasAnyOverflow |= overflow;
 }
 
-size = cgf.getBuilder().getConstInt(loc, allocationSize);
+// On overflow, produce a -1 so operator new will fail
+if (hasAnyOverflow) {
+  size =
+  cgf.getBuilder().getConstInt(loc, 
llvm::APInt::getAllOnes(sizeWidth));
+} else {
+  size = cgf.getBuilder().getConstInt(loc, allocationSize);
+}
   } else {
 // TODO: Handle the variable size case
 cgf.cgm.errorNYI(e->getSourceRange(),
@@ -367,7 +379,50 @@ void CIRGenFunction::emitNewArrayInitializer(
   if (!e->hasInitializer())
 return;
 
-  cgm.errorNYI(e->getSourceRange(), "emitNewArrayInitializer");
+  unsigned initListElements = 0;
+
+  const Expr *init = e->getInitializer();
+  const InitListExpr *ile = dyn_cast(init);
+  if (ile) {
+cgm.errorNYI(ile->getSourceRange(), "emitNewAr

[clang] [CIR] Implement GenericSelectionExpr for AggregateExpr (PR #161003)

2025-10-18 Thread Andy Kaylor via cfe-commits


@@ -93,3 +93,31 @@ void f3() {
 // OGCG:   %[[O:.*]] = alloca %struct.Outer, align 4
 // OGCG:   %[[O_I:.*]] = getelementptr inbounds nuw %struct.Outer, ptr %[[O]], 
i32 0, i32 0
 // OGCG:   %[[O_I_N:.*]] = getelementptr inbounds nuw %struct.Inner, ptr 
%[[O_I]], i32 0, i32 0
+
+void generic_selection() {
+  CompleteS a;
+  CompleteS b;
+  int c;
+  CompleteS d = _Generic(c, int : a, default: b);
+}
+
+// CIR: cir.func{{.*}} @_Z17generic_selectionv()
+// CIR:   %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, 
!cir.ptr, ["a"]
+// CIR:   %[[B_ADDR:.*]] = cir.alloca !rec_CompleteS, 
!cir.ptr, ["b"]
+// CIR:   %[[C_ADDR:.*]] = cir.alloca !s32i, !cir.ptr, ["c"]
+// CIR:   %[[D_ADDR:.*]] = cir.alloca !rec_CompleteS, 
!cir.ptr, ["d", init]
+// CIR:   cir.call @_ZN9CompleteSC1ERKS_(%[[D_ADDR]], %[[A_ADDR]]) nothrow : 
(!cir.ptr, !cir.ptr) -> ()

andykaylor wrote:

Again, a comment saying that we should be using `cir.copy` would be helpful.

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


[clang] [CIR] Upstream CIR Dialect TryOp with Catch Attrs (PR #162897)

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


@@ -0,0 +1,84 @@
+// RUN: cir-opt %s --verify-roundtrip | FileCheck %s
+
+!u8i = !cir.int
+
+module {
+
+cir.global "private" constant external @_ZTIi : !cir.ptr
+cir.global "private" constant external @_ZTIPKc : !cir.ptr
+
+cir.func dso_local @empty_try_block_with_catch_all() {
+  cir.scope {
+cir.try {
+  cir.yield
+} catch [type #cir.all {
+  cir.yield
+}]
+  }
+  cir.return
+}
+
+// CHECK:  cir.func dso_local @empty_try_block_with_catch_all() {
+// CHECK:cir.scope {
+// CHECK:  cir.try {
+// CHECK:cir.yield
+// CHECK:  } catch [type #cir.all {
+// CHECK:cir.yield
+// CHECK:  }]
+// CHECK:}
+// CHECK:cir.return
+// CHECK:  }
+
+cir.func dso_local @empty_try_block_with_catch_unwind() {
+  cir.scope {
+cir.try {
+  cir.yield
+} catch [#cir.unwind {
+  cir.yield
+}]
+  }
+  cir.return
+}
+
+// CHECK: cir.func dso_local @empty_try_block_with_catch_unwind() {
+// CHECK:  cir.scope {
+// CHECK:cir.try {
+// CHECK:  cir.yield
+// CHECK:} catch [#cir.unwind {
+// CHECK:  cir.yield
+// CHECK:}]
+// CHECK:  }
+// CHECK:  cir.return
+// CHECK: }
+
+cir.func dso_local @empty_try_block_with_catch_ist() {
+  cir.scope {
+cir.try {
+  cir.yield
+} catch [type #cir.global_view<@_ZTIi> : !cir.ptr {
+  cir.yield
+}, type #cir.global_view<@_ZTIPKc> : !cir.ptr {
+  cir.yield
+}, #cir.unwind {
+  cir.yield
+}]
+  }
+  cir.return
+}
+
+// CHECK: cir.func dso_local @empty_try_block_with_catch_ist() {
+// CHECK:   cir.scope {
+// CHECK: cir.try {
+// CHECK:   cir.yield
+// CHECK: } catch [type #cir.global_view<@_ZTIi> : !cir.ptr {
+// CHECK:   cir.yield
+// CHECK: }, type #cir.global_view<@_ZTIPKc> : !cir.ptr {

AmrDeveloper wrote:

Yes, because the current format is like a  followed by an array of 
catcher's blocks, I agree it would be better to change the format to have catch 
before each block

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


[clang] [CIR] Add support for global destructors (PR #162532)

2025-10-18 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor edited 
https://github.com/llvm/llvm-project/pull/162532
___
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-18 Thread Aaron Ballman via cfe-commits




AaronBallman wrote:

You can't, the driver automagically handles that:

> `error: invalid integral value '-1' in '-finitial-counter-value=-1'`

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] 3fdef23 - Remove WG14 N3563

2025-10-18 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2025-10-10T08:16:00-04:00
New Revision: 3fdef23873c61522e8de2ba5171d05b4c6d127be

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

LOG: Remove WG14 N3563

This paper had only non-normative changes and was already covered by
existing nullptr_t test coverage.

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 1a5fa4bbda3dc..6c1ba3c8643a0 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -361,11 +361,6 @@ C2y implementation status
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3532.pdf";>N3532
   Yes

-
-  Representation of Pointers and nullptr_t
-  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3563.pdf";>N3563
-  Unknown
-   
 
   Classification of the register storage-class specifier
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3544.txt";>N3544



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


[libcxx] [libcxxabi] [libunwind] [libcxx] Use %{temp} instead of %T (PR #162323)

2025-10-18 Thread Louis Dionne via cfe-commits

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

Thanks for the patch! LGTM but can you please undo the formatting changes that 
were done in this patch?

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


[clang] [CIR] Handle return with cleanups (PR #163849)

2025-10-18 Thread Bruno Cardoso Lopes via cfe-commits

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

LGTM

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


[clang] [NFC][clang][AST] Add compile-time dispatch for random access iterators in append() (PR #162000)

2025-10-18 Thread Samarth Narang via cfe-commits

snarang181 wrote:

> fwiw: 
> https://llvm-compile-time-tracker.com/compare.php?from=5284c83a8ff143b2d93853d1209f06d7d571f865&to=35bfd864bd0d43d54b1b2270613d46fb973b38c1&stat=instructions:u

Nice, thanks. 

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


[clang] [Headers][X86] Enable constexpr handling for MMX/SSE/AVX/AVX512 PMADDWD/PMADDUBSW intrinsics (PR #161563)

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


@@ -11724,6 +11724,52 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
   case clang::X86::BI__builtin_ia32_pavgw512:
 return EvaluateBinOpExpr(llvm::APIntOps::avgCeilU);
 
+  case clang::X86::BI__builtin_ia32_pmaddubsw128:
+  case clang::X86::BI__builtin_ia32_pmaddubsw256:
+  case clang::X86::BI__builtin_ia32_pmaddubsw512:
+  case clang::X86::BI__builtin_ia32_pmaddwd128:
+  case clang::X86::BI__builtin_ia32_pmaddwd256:
+  case clang::X86::BI__builtin_ia32_pmaddwd512: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen / 2);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; EltNum += 2) {
+  APInt U_LHS0 = SourceLHS.getVectorElt(EltNum).getInt();
+  APInt U_LHS1 = SourceLHS.getVectorElt(EltNum + 1).getInt();
+  APSInt LHS0 = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt LHS1 = SourceLHS.getVectorElt(EltNum + 1).getInt();
+  APSInt RHS0 = SourceRHS.getVectorElt(EltNum).getInt();
+  APSInt RHS1 = SourceRHS.getVectorElt(EltNum + 1).getInt();
+  unsigned BitWidth = LHS0.getBitWidth();
+
+  switch (E->getBuiltinCallee()) {
+  case clang::X86::BI__builtin_ia32_pmaddubsw128:
+  case clang::X86::BI__builtin_ia32_pmaddubsw256:
+  case clang::X86::BI__builtin_ia32_pmaddubsw512:
+ResultElements.push_back(APValue(
+APSInt(APInt(U_LHS0.zext(BitWidth)) *
+   RHS0.sext(BitWidth).sadd_sat(APInt(U_LHS1.zext(BitWidth)) *
+RHS1.sext(BitWidth);
+break;
+  case clang::X86::BI__builtin_ia32_pmaddwd128:
+  case clang::X86::BI__builtin_ia32_pmaddwd256:
+  case clang::X86::BI__builtin_ia32_pmaddwd512:
+ResultElements.push_back(
+APValue(APSInt(LHS0.sext(BitWidth) * RHS0.sext(BitWidth) +
+   LHS1.sext(BitWidth) * RHS1.sext(BitWidth;

RKSimon wrote:

Missing signedness control

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


[clang] [Android] Drop workarounds for older Android API levels pre 23 (PR #161893)

2025-10-18 Thread Brad Smith via cfe-commits

brad0 wrote:

I split the diffs in two.

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


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

2025-10-18 Thread Michael Spencer via cfe-commits


@@ -7,7 +7,7 @@
 
//===--===//
 
 def GlobalDocumentation {
-  code Intro =[{..
+  code Intro = [{..

Bigcheese wrote:

Extra formatting snuck in?

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] [clang][NVPTX] Add intrinsics and builtins for CVT RS rounding mode (PR #160494)

2025-10-18 Thread Durgadoss R via cfe-commits

durga4github wrote:

LGTM, with one optional nit.

@Artem-B , Please help us with a review on the Clang side of things.

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


[clang] [Headers][X86] Allow MMX/SSE/AVX MOVMSK intrinsics to be used in constexpr (PR #161914)

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


@@ -2817,6 +2817,46 @@ static bool interp__builtin_ia32_pshuf(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_ia32_movmsk_op(InterpState &S, CodePtr OpPC,
+   const CallExpr *Call) {
+  assert(Call->getNumArgs() == 1);
+
+  const Pointer &Source = S.Stk.pop();
+
+  unsigned SourceLen = Source.getNumElems();
+  const QualType ElemQT = getElemType(Source);
+  const OptPrimType ElemPT = S.getContext().classify(ElemQT);
+  unsigned LaneWidth = S.getASTContext().getTypeSize(ElemQT);
+
+  if (ElemQT->isIntegerType()) {
+unsigned Byte = 8;
+unsigned ResultLen = (LaneWidth * SourceLen) / Byte;

RKSimon wrote:

ResultLen needs to be determined from the DestVT, its always going to be 32 but 
we should still use the destination type

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


[clang] [Clang] Fix a regression introduced by #147046 (PR #150893)

2025-10-18 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

@cor3ntin the regression being fixed here snuck into the 21 release -- do you 
think we could backport the fix?

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


[clang] [NFC][clang] Quote literal builtin attribute markers in Builtins.def docs (PR #160080)

2025-10-18 Thread Radovan Božić via cfe-commits

bozicrHT wrote:

> > > > But I'm not sure what we could use reasonably.
> > > 
> > > 
> > > We could replace it w/ e.g. `*` and add a note along the lines of ‘where 
> > > `*` is any integer/index/whatever it’s actually supposed to be’
> > 
> > 
> > Asterisk seems pretty overloaded here... maybe the same except with `{num}` 
> > or something like that?
> 
> What about using two letters, e.g., `"nn"`, to mark `nonnull`?

I experimented with using `"nn"` as the marker for builtin nonnull, but that 
caused 137 test failures (in SemaHLSL, SemaSPIRV, CodeGenSPIRV, CodeGenHLSL, 
etc.). Using `"{null}"` reduced it to 3 failing tests:
```
Clang :: CodeGen/AArch64/strictfp-builtins.c
Clang :: CodeGen/X86/strictfp_builtins.c
Clang :: CodeGen/strictfp_builtins.c
```
The most stable option so far is **`"NN"`**, where all tests pass.

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


@@ -13822,7 +13822,10 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
   !VDecl->isInvalidDecl() && VDecl->isThisDeclarationADefinition() &&
   VDecl->getFormalLinkage() == Linkage::External && !VDecl->isInline() &&
   !VDecl->isTemplated() && !isa(VDecl) &&
-  !VDecl->getInstantiatedFromStaticDataMember()) {
+  !VDecl->getInstantiatedFromStaticDataMember() &&
+  // The intent of the above section seems to be to prevent ODR issues.
+  // Weak symbols do the same but are not part of the c++ spec.

akrieger wrote:

"the above section" was meant to refer to the section of the c++ spec, I see 
how that's ambiguous here.

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


[clang] [Headers][X86] Allow MMX/SSE/AVX MOVMSK intrinsics to be used in constexpr (PR #161914)

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


@@ -2817,6 +2817,46 @@ static bool interp__builtin_ia32_pshuf(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_ia32_movmsk_op(InterpState &S, CodePtr OpPC,
+   const CallExpr *Call) {
+  assert(Call->getNumArgs() == 1);
+
+  const Pointer &Source = S.Stk.pop();
+
+  unsigned SourceLen = Source.getNumElems();
+  const QualType ElemQT = getElemType(Source);
+  const OptPrimType ElemPT = S.getContext().classify(ElemQT);
+  unsigned LaneWidth = S.getASTContext().getTypeSize(ElemQT);
+
+  if (ElemQT->isIntegerType()) {
+unsigned Byte = 8;
+unsigned ResultLen = (LaneWidth * SourceLen) / Byte;
+APInt Result(ResultLen, 0);
+unsigned ResultIdx = 0;
+for (unsigned I = 0; I != SourceLen; ++I) {
+  APInt Lane;
+  INT_TYPE_SWITCH_NO_BOOL(*ElemPT,
+  { Lane = Source.elem(I).toAPSInt(); });
+  for (unsigned J = 0; J != LaneWidth; J += Byte) {
+Result.setBitVal(ResultIdx++, Lane[J + 7]);
+  }

RKSimon wrote:

MOVMSK needs to work per element, not per byte - PMOVMSKB has a vXi8 type so 
each element happens to be byte size, but all the ElemBitWidth/BitsInAByte code 
is unnecessary

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


[clang] [Headers][X86] Allow MMX/SSE/AVX MOVMSK intrinsics to be used in constexpr (PR #161914)

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

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


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


[clang] [alpha.webkit.UnretainedCallArgsChecker] Treat NSStringFromSelector and alike as trivial and returns a retained value (PR #161135)

2025-10-18 Thread Rashmi Mudduluru via cfe-commits

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

LGTM!

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


[clang] [clang] Support building native tools when cross-compiling standalone clang (PR #160605)

2025-10-18 Thread Ross Burton via cfe-commits

https://github.com/rossburton created 
https://github.com/llvm/llvm-project/pull/160605

When cross-compiling the LLVM project as a whole (from llvm/), if it cannot 
find presupplied tools it will create a native build environment to build the 
tools it needs.

However, when doing a standalone build of clang (that is, from clang/ and 
linking against an existing libLLVM) this doesn't work. Instead a _target_ 
binary is built which predictably then fails.

The conventional workaround for this is to build the native tools in a separate 
native compile phase and pass the paths to the cross build, for example see 
OpenEmbedded[1] or Nix[2]. But we can do better!

The first problem is that LLVM_USE_HOST_TOOLS is only set in the llvm/ 
CMakeLists.txt, so setup_host_tool() will never consider building a native 
binary.  This can be solved by setting LLVM_USE_HOST_TOOLS based on 
CMAKE_CROSSCOMPILING in clang/CMakeLists.txt in the standalone case.

Now setup_host_tool() will try to build a native tool, but it needs 
build_native_tool() from CrossCompile.cmake, so that also needs to be included.

Finally, the native binary then fails because there's no provider for the 
dependency "CONFIGURE_Clang_NATIVE", so use llvm_create_cross_target to create 
the native environment.

These few lines mirror what the lldb CMakeLists.txt does in the standalone 
case, so there is prior art for this.

[1] 
https://git.openembedded.org/openembedded-core/tree/meta/recipes-devtools/clang/clang_git.bb?id=e18d697e92b55e57124e80234369d46575226386#n212
[2] 
https://github.com/NixOS/nixpkgs/blob/3354d448f2a26117a74638957b0131ce3da9c8c4/pkgs/development/compilers/llvm/common/tblgen.nix#L54

>From 2ff1134d1d2b9f3c207e3ebd98de922f9ef6c15a Mon Sep 17 00:00:00 2001
From: Ross Burton 
Date: Wed, 24 Sep 2025 17:02:57 +0100
Subject: [PATCH] [clang] Support building native tools when cross-compiling
 standalone clang

When cross-compiling the LLVM project as a whole (from llvm/), if it
cannot find presupplied tools it will create a native build environment
to build the tools it needs.

However, when doing a standalone build of clang (that is, from clang/
and linking against an existing libLLVM) this doesn't work. Instead
a _target_ binary is built which predictably then fails.

The conventional workaround for this is to build the native tools in a
separate native compile phase and pass the paths to the cross build, for
example see OpenEmbedded[1] or Nix[2]. But we can do better!

The first problem is that LLVM_USE_HOST_TOOLS is only set in the llvm/
CMakeLists.txt, so setup_host_tool() will never consider building a
native binary.  This can be solved by setting LLVM_USE_HOST_TOOLS based
on CMAKE_CROSSCOMPILING in clang/CMakeLists.txt in the standalone case.

Now setup_host_tool() will try to build a native tool, but it needs
build_native_tool() from CrossCompile.cmake, so that also needs to be
included.

Finally, the native binary then fails because there's no provider for
the dependency "CONFIGURE_Clang_NATIVE", so use llvm_create_cross_target
to create the native environment.

These few lines mirror what the lldb CMakeLists.txt does in the
standalone case, so there is prior art for this.

[1] 
https://git.openembedded.org/openembedded-core/tree/meta/recipes-devtools/clang/clang_git.bb?id=e18d697e92b55e57124e80234369d46575226386#n212
[2] 
https://github.com/NixOS/nixpkgs/blob/3354d448f2a26117a74638957b0131ce3da9c8c4/pkgs/development/compilers/llvm/common/tblgen.nix#L54
---
 clang/CMakeLists.txt | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 1bb73599970c1..4eaa712899856 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -80,6 +80,12 @@ if(CLANG_BUILT_STANDALONE)
   include(GetErrcMessages)
   include(LLVMDistributionSupport)
 
+  if(CMAKE_CROSSCOMPILING)
+set(LLVM_USE_HOST_TOOLS ON)
+include(CrossCompile)
+llvm_create_cross_target(Clang NATIVE "" Release)
+  endif()
+
   set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
   set(BUG_REPORT_URL "${LLVM_PACKAGE_BUGREPORT}" CACHE STRING
 "Default URL where bug reports are to be submitted.")

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


[clang] 99f02ea - [CIR][NFC] Improve the output for missing builtin calls (#163884)

2025-10-18 Thread via cfe-commits

Author: Andy Kaylor
Date: 2025-10-16T17:39:16-07:00
New Revision: 99f02ea177fefe8ae5dd8673965d8f2485f2eb33

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

LOG: [CIR][NFC] Improve the output for missing builtin calls (#163884)

This improves the diagnostic emitted when `errorNYI` is called for
missing builtin calls so that the builtin being called is displayed in
the diagnostic.

Added: 


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

Removed: 




diff  --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 4cfa91e09efb4..ea31871806bd7 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -463,7 +463,9 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
 return emitLibraryCall(*this, fd, e,
cgm.getBuiltinLibFunction(fd, builtinID));
 
-  cgm.errorNYI(e->getSourceRange(), "unimplemented builtin call");
+  cgm.errorNYI(e->getSourceRange(),
+   std::string("unimplemented builtin call: ") +
+   getContext().BuiltinInfo.getName(builtinID));
   return getUndefRValue(e->getType());
 }
 



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


[clang] [Clang] Add diagnostic for why std::is_abstract is false (PR #156199)

2025-10-18 Thread Shafik Yaghmour via cfe-commits

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


[clang] [OpenMP] Update 6.1 implementation status. (PR #161449)

2025-10-18 Thread via cfe-commits

https://github.com/CatherineMoore created 
https://github.com/llvm/llvm-project/pull/161449

@jhuber6: Please review

>From 29a1f172efa348154b953b66997a2490d464bd49 Mon Sep 17 00:00:00 2001
From: Catherine Moore 
Date: Tue, 30 Sep 2025 16:32:32 -0500
Subject: [PATCH] Update 6.1 implementation status.

---
 clang/docs/OpenMPSupport.rst | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 68ca7bedddb06..cf89e31aa93ef 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -580,9 +580,12 @@ implementation.
 | need_device_addr modifier for adjust_args clause| 
:part:`partial`   | :none:`unclaimed` | Parsing/Sema: 
https://github.com/llvm/llvm-project/pull/143442   |
 | |
   |   |   
https://github.com/llvm/llvm-project/pull/149586   |
 
+-+---+---+--+
-| Prescriptive num_threads| :part:`In 
Progress`   | :none:`unclaimed` | ro-i  
   |
+| Prescriptive num_threads| :good:`done`   
   | :none:`unclaimed` |  
https://github.com/llvm/llvm-project/pull/160659|
+| |
   |   |  
https://github.com/llvm/llvm-project/pull/146403|
+| |
   |   |  
https://github.com/llvm/llvm-project/pull/146404|
+| |
   |   |  
https://github.com/llvm/llvm-project/pull/146405|
 
+-+---+---+--+
-| Message and severity clauses| :part:`In 
Progress`   | :none:`unclaimed` | ro-i  
   |
+| Message and severity clauses| :good:`done`   
   | :none:`unclaimed` |  
https://github.com/llvm/llvm-project/pull/146093|
 
+-+---+---+--+
 | Local clause on declare target  | :part:`In 
Progress`   | :none:`unclaimed` |   
   |
 
+-+---+---+--+

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


[clang] [llvm] [HLSL] [SPIR-V] Add initial support for typed buffer counters (PR #161414)

2025-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Steven Perron (s-perron)


Changes

This is part 1 of implementing the typed buffer counters proposal:
https://github.com/llvm/wg-hlsl/blob/main/proposals/0023-typed-buffer-counters.md

This patch adds the initial plumbing for supporting counter variables
associated with structured buffers for the SPIR-V backend. It introduces
an `IsCounter` attribute to `HLSLAttributedResourceType` and threads it
through the AST, type printing, and mangling. It also adds a
`__counter_handle` member to the relevant buffer types in
`HLSLBuiltinTypeDeclBuilder`.


---

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


17 Files Affected:

- (modified) clang/include/clang/AST/TypeBase.h (+12-5) 
- (modified) clang/include/clang/AST/TypeProperties.td (+4-1) 
- (modified) clang/include/clang/Basic/Attr.td (+6) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+2) 
- (modified) clang/lib/AST/TypePrinter.cpp (+3) 
- (modified) clang/lib/CodeGen/Targets/SPIR.cpp (+6) 
- (modified) clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp (+121-11) 
- (modified) clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h (+4) 
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+18-3) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+11) 
- (modified) clang/test/AST/HLSL/StructuredBuffers-AST.hlsl (+18-3) 
- (modified) 
clang/test/CodeGenHLSL/resources/RWStructuredBuffer-elementtype.hlsl (+17-17) 
- (modified) 
clang/test/CodeGenHLSL/resources/StructuredBuffers-constructors.hlsl (+2-2) 
- (modified) 
clang/test/CodeGenHLSL/resources/StructuredBuffers-methods-lib.hlsl (+3-3) 
- (modified) clang/test/CodeGenHLSL/resources/StructuredBuffers-methods-ps.hlsl 
(+1-1) 
- (modified) clang/test/CodeGenHLSL/resources/resource-bindings.hlsl (+1-1) 
- (modified) llvm/lib/Target/SPIRV/SPIRVLegalizeImplicitBinding.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/TypeBase.h 
b/clang/include/clang/AST/TypeBase.h
index b02d9c7499fe5..b60ef6911d84a 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -6700,15 +6700,21 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 LLVM_PREFERRED_TYPE(bool)
 uint8_t RawBuffer : 1;
 
+LLVM_PREFERRED_TYPE(bool)
+uint8_t IsCounter : 1;
+
 Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV = false,
-   bool RawBuffer = false)
-: ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
+   bool RawBuffer = false, bool IsCounter = false)
+: ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer),
+  IsCounter(IsCounter) {}
 
-Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
+Attributes()
+: Attributes(llvm::dxil::ResourceClass::UAV, false, false, false) {}
 
 friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
-  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
- std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
+  return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer,
+  LHS.IsCounter) == std::tie(RHS.ResourceClass, RHS.IsROV,
+ RHS.RawBuffer, RHS.IsCounter);
 }
 friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
   return !(LHS == RHS);
@@ -6749,6 +6755,7 @@ class HLSLAttributedResourceType : public Type, public 
llvm::FoldingSetNode {
 ID.AddInteger(static_cast(Attrs.ResourceClass));
 ID.AddBoolean(Attrs.IsROV);
 ID.AddBoolean(Attrs.RawBuffer);
+ID.AddBoolean(Attrs.IsCounter);
   }
 
   static bool classof(const Type *T) {
diff --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/clang/AST/TypeProperties.td
index b3932a67db69d..9dc85fb88e267 100644
--- a/clang/include/clang/AST/TypeProperties.td
+++ b/clang/include/clang/AST/TypeProperties.td
@@ -662,6 +662,9 @@ let Class = HLSLAttributedResourceType in {
   def : Property<"rawBuffer", Bool> {
 let Read = [{ node->getAttrs().RawBuffer }];
   }
+  def : Property<"isCounter", Bool> {
+let Read = [{ node->getAttrs().IsCounter }];
+  }
   def : Property<"wrappedTy", QualType> {
 let Read = [{ node->getWrappedType() }];
   }
@@ -669,7 +672,7 @@ let Class = HLSLAttributedResourceType in {
 let Read = [{ node->getContainedType() }];
   }
   def : Creator<[{
-HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV, rawBuffer);
+HLSLAttributedResourceType::Attributes 
attrs(static_cast(resClass), isROV, rawBuffer, 
isCounter);
 return ctx.getHLSLAttributedResourceType(wrappedTy, containedTy, attrs);
   }]>;
 }
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 2623f9ff6972f..1d6f4e809a1fa 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr

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

2025-10-18 Thread Mariya Podchishchaeva via cfe-commits


@@ -1737,7 +1737,18 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
   Diag(getLastFPEvalPragmaLocation(), diag::note_pragma_entered_here);
 }
   } else if (II == Ident__COUNTER__) {
-// __COUNTER__ expands to a simple numeric value.
+Diag(Tok.getLocation(),
+ getLangOpts().C2y ? diag::warn_counter : diag::ext_counter);
+// __COUNTER__ expands to a simple numeric value that must be less than
+// 2147483647.
+if (CounterValue > 2147483647) {

Fznamznon wrote:

Maybe makes sense to put `2147483647` into a constant somewhere?

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] [CIR] Add support for virtual destructor calls (PR #162725)

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

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


[clang] [clang] add array out-of-bounds access constraints using llvm.assume (PR #159046)

2025-10-18 Thread Sebastian Pop via cfe-commits

https://github.com/sebpop updated 
https://github.com/llvm/llvm-project/pull/159046

>From 7fdec0a94298caae4bb7bd69a9d165524df11fb7 Mon Sep 17 00:00:00 2001
From: Sebastian Pop 
Date: Tue, 16 Sep 2025 06:23:44 -0500
Subject: [PATCH 1/6] [clang] add array out-of-bounds access constraints using
 llvm.assume

Following C and C++ standards, generate llvm.assume statements for array
subscript bounds to provide optimization hints.

For this code:
```
int arr[10];
int example(int i) {
  return arr[i];
}
```
clang now generates an `assume(i < 10)`:
```
define i32 @example(i32 noundef %i) local_unnamed_addr #0 {
entry:
  %idxprom = zext nneg i32 %i to i64
  %bounds.constraint = icmp ult i32 %i, 10
  tail call void @llvm.assume(i1 %bounds.constraint)
  %arrayidx = getelementptr inbounds nuw i32, ptr @arr, i64 %idxprom
  %0 = load i32, ptr %arrayidx, align 4, !tbaa !2
  ret i32 %0
}
```
---
 clang/lib/CodeGen/CGExpr.cpp  | 112 ++
 clang/lib/CodeGen/CGExprScalar.cpp|   3 +
 clang/lib/CodeGen/CodeGenFunction.h   |   7 ++
 clang/test/CodeGen/array-bounds-constraints.c |  39 ++
 4 files changed, 161 insertions(+)
 create mode 100644 clang/test/CodeGen/array-bounds-constraints.c

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index e6e4947882544..d4425d76d10fe 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4559,6 +4559,97 @@ void CodeGenFunction::EmitCountedByBoundsChecking(
   }
 }
 
+/// Emit array bounds constraints using llvm.assume for optimization hints.
+///
+/// C Standard (ISO/IEC 9899:2011 - C11)
+/// Section J.2 (Undefined behavior): An array subscript is out of range, even
+/// if an object is apparently accessible with the given subscript (as in the
+/// lvalue expression a[1][7] given the declaration int a[4][5]) (6.5.6).
+///
+/// Section 6.5.6 (Additive operators): If both the pointer operand and the
+/// result point to elements of the same array object, or one past the last
+/// element of the array object, the evaluation shall not produce an overflow;
+/// otherwise, the behavior is undefined.
+///
+/// C++ Standard (ISO/IEC 14882 - 2017)
+/// Section 8.7 (Additive operators):
+/// 4 When an expression that has integral type is added to or subtracted from 
a
+///   pointer, the result has the type of the pointer operand. If the 
expression
+///   P points to element x[i] of an array object x with n elements,^86 the
+///   expressions P + J and J + P (where J has the value j) point to the
+///   (possibly-hypothetical) element x[i + j] if 0 ≤ i + j ≤ n; otherwise, the
+///   behavior is undefined. Likewise, the expression P - J points to the
+///   (possibly-hypothetical) element x[i − j] if 0 ≤ i − j ≤ n; otherwise, the
+///   behavior is undefined.
+/// ^86 A pointer past the last element of an array x of n elements is
+/// considered to be equivalent to a pointer to a hypothetical element x[n]
+/// for this purpose; see 6.9.2.
+///
+/// This function emits llvm.assume statements to inform the optimizer that
+/// array subscripts are within bounds, enabling better optimization without
+/// duplicating side effects from the subscript expression. The IndexVal
+/// parameter should be the already-emitted index value to avoid re-evaluation.
+void CodeGenFunction::EmitArrayBoundsConstraints(const ArraySubscriptExpr *E,
+ llvm::Value *IndexVal) {
+  const Expr *Base = E->getBase();
+  const Expr *Idx = E->getIdx();
+  QualType BaseType = Base->getType();
+
+  if (const auto *ICE = dyn_cast(Base)) {
+if (ICE->getCastKind() == CK_ArrayToPointerDecay) {
+  BaseType = ICE->getSubExpr()->getType();
+}
+  }
+
+  // For now: only handle constant array types.
+  const ConstantArrayType *CAT = getContext().getAsConstantArrayType(BaseType);
+  if (!CAT)
+return;
+
+  llvm::APInt ArraySize = CAT->getSize();
+  if (ArraySize == 0)
+return;
+
+  QualType IdxType = Idx->getType();
+  llvm::Type *IndexType = ConvertType(IdxType);
+  llvm::Value *Zero = llvm::ConstantInt::get(IndexType, 0);
+
+  uint64_t ArraySizeValue = ArraySize.getLimitedValue();
+  llvm::Value *ArraySizeVal = llvm::ConstantInt::get(IndexType, 
ArraySizeValue);
+
+  // Use the provided IndexVal to avoid duplicating side effects.
+  // The caller has already emitted the index expression once.
+  if (!IndexVal)
+return;
+
+  // Ensure index value has the same type as our constants.
+  if (IndexVal->getType() != IndexType) {
+bool IsSigned = IdxType->isSignedIntegerOrEnumerationType();
+IndexVal = Builder.CreateIntCast(IndexVal, IndexType, IsSigned, 
"idx.cast");
+  }
+
+  // Create bounds constraint: 0 <= index && index < size.
+  // C arrays are 0-based, so valid indices are [0, size-1].
+  // This enforces the C18 standard requirement that array subscripts
+  // must be "greater than or equal to zero and less than the size of the
+  // array."
+  llvm::

[clang] [HLSL][NFC] Refactor structured buffer methods tests - 2nd attempt (PR #163605)

2025-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Helena Kotas (hekota)


Changes

Refactoring methods tests for structured buffers to make it clearer that:
- the test functions call the buffer methods and do not directly call the LLVM 
intrinsic
- the buffer methods are defined after each test function
- show what the buffer methods bodies look like
- use buffers with different element types, not just `float`
- use `llvm-cxxfilt` tool to de-mangle names

This is a second attempt to land this. Previous 
[PR](https://github.com/llvm/llvm-project/pull/161908) broke the build because 
the test baselines did not reflect the introduction of counter handles since 
its validation build.

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


2 Files Affected:

- (modified) 
clang/test/CodeGenHLSL/resources/StructuredBuffers-methods-lib.hlsl (+82-34) 
- (modified) clang/test/CodeGenHLSL/resources/StructuredBuffers-methods-ps.hlsl 
(+54-20) 


``diff
diff --git 
a/clang/test/CodeGenHLSL/resources/StructuredBuffers-methods-lib.hlsl 
b/clang/test/CodeGenHLSL/resources/StructuredBuffers-methods-lib.hlsl
index 43ddd2e768ea0..2cf6a101a44e1 100644
--- a/clang/test/CodeGenHLSL/resources/StructuredBuffers-methods-lib.hlsl
+++ b/clang/test/CodeGenHLSL/resources/StructuredBuffers-methods-lib.hlsl
@@ -1,64 +1,112 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
-// RUN-DISABLED: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm 
-disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library 
-finclude-default-header -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt 
| FileCheck %s --check-prefixes=CHECK,DXIL
+// RUN-DISABLED: %clang_cc1 -triple spirv-vulkan-library 
-finclude-default-header -emit-llvm -disable-llvm-passes -o - %s | llvm-cxxfilt 
| FileCheck %s --check-prefixes=CHECK,SPV
 
 // NOTE: SPIRV codegen for resource methods is not yet implemented
 
 StructuredBuffer SB1 : register(t0);
 RWStructuredBuffer RWSB1 : register(u0);
-RWStructuredBuffer RWSB2 : register(u1);
+RWStructuredBuffer RWSB2 : register(u1);
 AppendStructuredBuffer ASB : register(u2);
-ConsumeStructuredBuffer CSB : register(u3);
+ConsumeStructuredBuffer CSB : register(u3);
 
-// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", 
float, 0, 0) }
-// CHECK: %"class.hlsl::RWStructuredBuffer" = type { target("dx.RawBuffer", 
float, 1, 0), target("dx.RawBuffer", float, 1, 0) }
-// CHECK: %"class.hlsl::AppendStructuredBuffer" = type { 
target("dx.RawBuffer", float, 1, 0), target("dx.RawBuffer", float, 1, 0) }
-// CHECK: %"class.hlsl::ConsumeStructuredBuffer" = type { 
target("dx.RawBuffer", float, 1, 0), target("dx.RawBuffer", float, 1, 0) }
+// DXIL: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", 
float, 0, 0) }
+// DXIL: %"class.hlsl::RWStructuredBuffer" = type { target("dx.RawBuffer", 
float, 1, 0), target("dx.RawBuffer", float, 1, 0) }
+// DXIL: %"class.hlsl::RWStructuredBuffer.0" = type { target("dx.RawBuffer", 
<4 x i32>, 1, 0), target("dx.RawBuffer", <4 x i32>, 1, 0) }
+// DXIL: %"class.hlsl::AppendStructuredBuffer" = type { target("dx.RawBuffer", 
float, 1, 0), target("dx.RawBuffer", float, 1, 0) }
+// DXIL: %"class.hlsl::ConsumeStructuredBuffer" = type { 
target("dx.RawBuffer", double, 1, 0), target("dx.RawBuffer", double, 1, 0) }
 
 export int TestIncrementCounter() {
 return RWSB1.IncrementCounter();
 }
 
-// CHECK: define noundef i32 @_Z20TestIncrementCounterv()
-// CHECK-DXIL: %[[INDEX:.*]] = call i32 
@llvm.dx.resource.updatecounter.tdx.RawBuffer_f32_1_0t(target("dx.RawBuffer", 
float, 1, 0) %{{[0-9]+}}, i8 1)
-// CHECK-DXIL: ret i32 %[[INDEX]]
+// CHECK: define noundef i32 @TestIncrementCounter()()
+// CHECK: call noundef i32 
@hlsl::RWStructuredBuffer::IncrementCounter()(ptr {{.*}} @RWSB1)
+// CHECK: ret
+
+// CHECK: define {{.*}} noundef i32 
@hlsl::RWStructuredBuffer::IncrementCounter()(ptr {{.*}} %this)
+// CHECK: %__counter_handle = getelementptr inbounds nuw 
%"class.hlsl::RWStructuredBuffer", ptr %{{.*}}, i32 0, i32 1
+// DXIL-NEXT: %[[COUNTER_HANDLE:.*]] = load target("dx.RawBuffer", float, 1, 
0), ptr %__counter_handle
+// DXIL-NEXT: %[[COUNTER:.*]] = call i32 
@llvm.dx.resource.updatecounter.tdx.RawBuffer_f32_1_0t(target("dx.RawBuffer", 
float, 1, 0) %[[COUNTER_HANDLE]], i8 1)
+// CHECK-NEXT:  ret i32 %[[COUNTER]]
+
 export int TestDecrementCounter() {
 return RWSB2.DecrementCounter();
 }
+// CHECK: define {{.*}} i32 @TestDecrementCounter()()
+// CHECK: call noundef i32 @hlsl::RWStructuredBuffer::DecrementCounter()(ptr {{.*}} @RWSB2)
+// CHECK: ret
 
-// CHECK: define noundef i32 @_Z20TestDecrementCounterv()
-// CHECK-DXIL: %[[INDEX:.*]] = call i32 
@llvm.dx.resource.updatecounter.tdx.RawBuffer_f32_1_0t(target("dx.RawBuffer", 
float, 1, 0) %{{[0-9]+}}, i8 -1)
-/

[libclc] libclc: Add gfx1250 and gfx1251 to amdgpu target list (PR #162034)

2025-10-18 Thread Matt Arsenault via cfe-commits

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


[clang] [llvm] [Android] Drop workarounds for older Android API levels (PR #161893)

2025-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Brad Smith (brad0)


Changes

Drop workarounds for Android API levels pre 9, 17, 21 and 23.

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


11 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/Linux.cpp (+1-3) 
- (modified) clang/test/Driver/aarch64-features.c (+1-5) 
- (modified) clang/test/Driver/aarch64-fmv.c (+2-10) 
- (modified) clang/test/Driver/linux-ld.c (+2-9) 
- (modified) llvm/include/llvm/IR/RuntimeLibcalls.h (+1-1) 
- (modified) llvm/lib/Target/X86/X86ISelLoweringCall.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+1-3) 
- (modified) llvm/test/CodeGen/ARM/sincos.ll (+1-26) 
- (modified) llvm/test/CodeGen/X86/stack-protector-target.ll (+1-11) 
- (modified) llvm/test/Instrumentation/AddressSanitizer/with-ifunc.ll (+1-6) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 412a176006bc0..9e2e7d7be4f75 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7870,7 +7870,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   if (Triple.isAArch64() &&
   (Args.hasArg(options::OPT_mno_fmv) ||
-   (Triple.isAndroid() && Triple.isAndroidVersionLT(23)) ||
getToolChain().GetRuntimeLibType(Args) != ToolChain::RLT_CompilerRT)) {
 // Disable Function Multiversioning on AArch64 target.
 CmdArgs.push_back("-target-feature");
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 16e35b08cfbd6..dde6f8203cacc 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -300,12 +300,10 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
   // and the MIPS ABI require .dynsym to be sorted in different ways.
   // .gnu.hash needs symbols to be grouped by hash code whereas the MIPS
   // ABI requires a mapping between the GOT and the symbol table.
-  // Android loader does not support .gnu.hash until API 23.
   // Hexagon linker/loader does not support .gnu.hash
   if (!IsMips && !IsHexagon) {
 if (Distro.IsOpenSUSE() || Distro == Distro::UbuntuLucid ||
-Distro == Distro::UbuntuJaunty || Distro == Distro::UbuntuKarmic ||
-(IsAndroid && Triple.isAndroidVersionLT(23)))
+Distro == Distro::UbuntuJaunty || Distro == Distro::UbuntuKarmic)
   ExtraOpts.push_back("--hash-style=both");
 else
   ExtraOpts.push_back("--hash-style=gnu");
diff --git a/clang/test/Driver/aarch64-features.c 
b/clang/test/Driver/aarch64-features.c
index faef3878c0ab0..d2dc5a20119ee 100644
--- a/clang/test/Driver/aarch64-features.c
+++ b/clang/test/Driver/aarch64-features.c
@@ -8,14 +8,10 @@
 // CHECK: fno-signed-char
 
 // Check Function Multi Versioning option and rtlib dependency.
-// RUN: %clang --target=aarch64-linux-android23 -rtlib=compiler-rt \
-// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-FMV %s
 // RUN: %clang --target=aarch64-linux-android -rtlib=compiler-rt \
-// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-FMV-OFF %s
+// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-FMV %s
 // RUN: %clang --target=aarch64-linux-android -rtlib=compiler-rt -mno-fmv \
 // RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-FMV-OFF %s
-// RUN: %clang --target=aarch64-linux-android22 -rtlib=compiler-rt \
-// RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-FMV-OFF %s
 
 // RUN: %clang --target=aarch64-linux-gnu -rtlib=libgcc \
 // RUN: -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-FMV-OFF %s
diff --git a/clang/test/Driver/aarch64-fmv.c b/clang/test/Driver/aarch64-fmv.c
index e7d01d1d5906a..84fb55c67a315 100644
--- a/clang/test/Driver/aarch64-fmv.c
+++ b/clang/test/Driver/aarch64-fmv.c
@@ -1,24 +1,16 @@
 // Test which driver flags enable/disable Function Multiversioning on aarch64.
 
-// FMV is enabled for non-android aarch64 targets:
+// FMV is enabled with compiler-rt:
 // RUN: %clang --target=aarch64 --rtlib=compiler-rt -### -c %s 2>&1 | 
FileCheck -check-prefix=FMV-ENABLED %s
 // RUN: %clang --target=aarch64-linux-gnu --rtlib=compiler-rt -### -c %s 2>&1 
| FileCheck -check-prefix=FMV-ENABLED %s
+// RUN: %clang --target=aarch64-linux-android --rtlib=compiler-rt -### -c %s 
2>&1 | FileCheck -check-prefix=FMV-ENABLED %s
 // RUN: %clang --target=arm64-apple-ios --rtlib=compiler-rt -### -c %s 2>&1 | 
FileCheck -check-prefix=FMV-ENABLED %s
 // RUN: %clang --target=arm64-apple-macosx --rtlib=compiler-rt -### -c %s 2>&1 
| FileCheck -check-prefix=FMV-ENABLED %s
 
-// android23 defaults to --rtlib=compiler-rt:
-// RUN: %clang --target=aarch64-linux-android23 -### -c %s 2>&1 | FileCheck 
-check-prefix=FMV-ENABLED %s
-// RUN: %clang --target=aarch64-linux-android23 --rtlib=compiler-rt  -### -c 
%s 2>&1 | FileCheck -check-prefix=FMV-ENABLED %s
-
 // FMV 

[clang] [Headers][X86] Allow MMX/SSE/AVX MOVMSK intrinsics to be used in constexpr (PR #161914)

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


@@ -2817,6 +2817,46 @@ static bool interp__builtin_ia32_pshuf(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_ia32_movmsk_op(InterpState &S, CodePtr OpPC,
+   const CallExpr *Call) {
+  assert(Call->getNumArgs() == 1);
+
+  const Pointer &Source = S.Stk.pop();
+
+  unsigned SourceLen = Source.getNumElems();
+  const QualType ElemQT = getElemType(Source);
+  const OptPrimType ElemPT = S.getContext().classify(ElemQT);
+  unsigned LaneWidth = S.getASTContext().getTypeSize(ElemQT);
+
+  if (ElemQT->isIntegerType()) {
+unsigned Byte = 8;
+unsigned ResultLen = (LaneWidth * SourceLen) / Byte;
+APInt Result(ResultLen, 0);
+unsigned ResultIdx = 0;
+for (unsigned I = 0; I != SourceLen; ++I) {
+  APInt Lane;
+  INT_TYPE_SWITCH_NO_BOOL(*ElemPT,
+  { Lane = Source.elem(I).toAPSInt(); });
+  for (unsigned J = 0; J != LaneWidth; J += Byte) {
+Result.setBitVal(ResultIdx++, Lane[J + 7]);
+  }
+}
+pushInteger(S, Result.getZExtValue(), Call->getType());
+return true;
+  }
+  if (ElemQT->isFloatingType()) {
+APInt Result(SourceLen, 0);
+using T = PrimConv::T;
+for (unsigned I = 0; I != SourceLen; ++I) {
+  APInt Lane = Source.elem(I).getAPFloat().bitcastToAPInt();
+  Result.setBitVal(I, Lane[LaneWidth - 1]);

RKSimon wrote:

Lane.isNegative()

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


[clang] [compiler-rt] [llvm] [AIX] Implement the ifunc attribute. (PR #153049)

2025-10-18 Thread Sean Fertile via cfe-commits

https://github.com/mandlebug commented:

Partway through my review but though I'd leave some of the initial comments.

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


[clang] 89e2d58 - [clang-tidy] Fix false positives about references in `misc-const-correctness` (#160971)

2025-10-18 Thread via cfe-commits

Author: flovent
Date: 2025-10-08T15:15:29+08:00
New Revision: 89e2d58ec8189e77c34e39b1e8c9992315ad682f

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

LOG: [clang-tidy] Fix false positives about references in 
`misc-const-correctness` (#160971)

It's not legal to cast const pointer type to it's non-const reference
type implicitly, and will cause compile error.

And for explicit cast, it's legal but the pointer is mutable through
this reference.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp
clang/lib/Analysis/ExprMutationAnalyzer.cpp
clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7e836a7114d50..4197abac273b0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -318,6 +318,10 @@ Changes in existing checks
 
   - ``for`` loops are supported.
 
+- Improved :doc:`misc-const-correctness
+  ` check to avoid false
+  positives when pointers is tranferred to non-const references.
+
 - Improved :doc:`misc-header-include-cycle
   ` check performance.
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp
index 2ef47266b02b0..bcd946e7404c1 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp
@@ -48,3 +48,18 @@ void ignore_const_alias() {
   p_local0 = &a[1];
 }
 
+void takeNonConstRef(int *&r);
+
+void ignoreNonConstRefOps() {
+  // init with non-const ref
+  int* p0 {nullptr};
+  int*& r1 = p0;
+  
+  // non-const ref param
+  int* p1 {nullptr};
+  takeNonConstRef(p1);
+
+  // cast
+  int* p2 {nullptr};
+  int*& r2 = (int*&)p2;
+}

diff  --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 3fcd3481c2d6b..1e376da1be83d 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -755,22 +755,23 @@ 
ExprMutationAnalyzer::Analyzer::findPointeeMemberMutation(const Expr *Exp) {
 
 const Stmt *
 ExprMutationAnalyzer::Analyzer::findPointeeToNonConst(const Expr *Exp) {
-  const auto NonConstPointerOrDependentType =
-  type(anyOf(nonConstPointerType(), isDependentType()));
+  const auto NonConstPointerOrNonConstRefOrDependentType = type(
+  anyOf(nonConstPointerType(), nonConstReferenceType(), 
isDependentType()));
 
   // assign
   const auto InitToNonConst =
-  varDecl(hasType(NonConstPointerOrDependentType),
+  varDecl(hasType(NonConstPointerOrNonConstRefOrDependentType),
   hasInitializer(expr(canResolveToExprPointee(Exp)).bind("stmt")));
-  const auto AssignToNonConst =
-  binaryOperation(hasOperatorName("="),
-  hasLHS(expr(hasType(NonConstPointerOrDependentType))),
-  hasRHS(canResolveToExprPointee(Exp)));
+  const auto AssignToNonConst = binaryOperation(
+  hasOperatorName("="),
+  hasLHS(expr(hasType(NonConstPointerOrNonConstRefOrDependentType))),
+  hasRHS(canResolveToExprPointee(Exp)));
   // arguments like
   const auto ArgOfInstantiationDependent = allOf(
   hasAnyArgument(canResolveToExprPointee(Exp)), 
isInstantiationDependent());
-  const auto ArgOfNonConstParameter = forEachArgumentWithParamType(
-  canResolveToExprPointee(Exp), NonConstPointerOrDependentType);
+  const auto ArgOfNonConstParameter =
+  forEachArgumentWithParamType(canResolveToExprPointee(Exp),
+   
NonConstPointerOrNonConstRefOrDependentType);
   const auto CallLikeMatcher =
   anyOf(ArgOfNonConstParameter, ArgOfInstantiationDependent);
   const auto PassAsNonConstArg =
@@ -779,9 +780,9 @@ ExprMutationAnalyzer::Analyzer::findPointeeToNonConst(const 
Expr *Exp) {
  parenListExpr(has(canResolveToExprPointee(Exp))),
  initListExpr(hasAnyInit(canResolveToExprPointee(Exp);
   // cast
-  const auto CastToNonConst =
-  explicitCastExpr(hasSourceExpression(canResolveToExprPointee(Exp)),
-   hasDestinationType(NonConstPointerOrDependentType));
+  const auto CastToNonConst = explicitCastExpr(
+  hasSourceExpression(canResolveToExprPointee(Exp)),
+  hasDestinationType(NonConstPointerOrNonConstRefOrDependentType));
 
   // capture
   // FIXME: false positive if the pointee does not change in lambda

diff  --git a/clang/unittests/Analysis/ExprMutationAn

[clang] [compiler-rt] [llvm] [AIX] Implement the ifunc attribute. (PR #153049)

2025-10-18 Thread Sean Fertile via cfe-commits


@@ -2865,8 +2880,10 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() {
   static_cast(CurrentFnDescSym)->getRepresentedCsect());
 
   // Emit aliasing label for function descriptor csect.
-  for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()])
-OutStreamer->emitLabel(getSymbol(Alias));
+  if (MF) // TODO MF is unset when processing an ifunc, handle it better than

mandlebug wrote:

I don't think you need any better way to handle it, just update the comment to 
drop the TODO part.

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [runtimes][PAC] Harden unwinding when possible (PR #143230)

2025-10-18 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

> The patch looks fine to me but you should finish addressing comments by 
> @kovdan01 .
> 
> I wonder, however, what kind of test coverage we have for your changes. Do we 
> have any? In the current CI, are we even exercising these changes?

These changes do not effect behavior if there is no pointer authentication - if 
there is pointer authentication then these have to be consistent with the host 
platform so I'm not sure how to test conformance without adding what are in 
essence "expected fail" tests where we construct intentionally incorrect frames 
and attempt to unwind through them. Having this upstreamed would permitted 
arm64e apple silicon test bots to run which might be useful?

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


[clang] [llvm] [RISCV] Remove Zicntr from sifive-p450/p470/p670. (PR #161444)

2025-10-18 Thread Craig Topper via cfe-commits

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


[clang] [Serialization] Fix lazy template loading (PR #133057)

2025-10-18 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo updated 
https://github.com/llvm/llvm-project/pull/133057

>From cae06d118bb3092cf3b45244b089db6476c9bf72 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Tue, 25 Mar 2025 11:27:59 +0100
Subject: [PATCH 1/4] [Serialization] Hash inner template arguments

The code is applied from ODRHash::AddDecl with the reasoning given
in the comment, to reduce collisions. This was particularly visible
with STL types templated on std::pair where its template arguments
were not taken into account.
---
 .../lib/Serialization/TemplateArgumentHasher.cpp  | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/clang/lib/Serialization/TemplateArgumentHasher.cpp 
b/clang/lib/Serialization/TemplateArgumentHasher.cpp
index 353e8a2daa925..da2c70ca17b79 100644
--- a/clang/lib/Serialization/TemplateArgumentHasher.cpp
+++ b/clang/lib/Serialization/TemplateArgumentHasher.cpp
@@ -202,6 +202,21 @@ void TemplateArgumentHasher::AddDecl(const Decl *D) {
   }
 
   AddDeclarationName(ND->getDeclName());
+
+  // If this was a specialization we should take into account its template
+  // arguments. This helps to reduce collisions coming when visiting template
+  // specialization types (eg. when processing type template arguments).
+  ArrayRef Args;
+  if (auto *CTSD = dyn_cast(D))
+Args = CTSD->getTemplateArgs().asArray();
+  else if (auto *VTSD = dyn_cast(D))
+Args = VTSD->getTemplateArgs().asArray();
+  else if (auto *FD = dyn_cast(D))
+if (FD->getTemplateSpecializationArgs())
+  Args = FD->getTemplateSpecializationArgs()->asArray();
+
+  for (auto &TA : Args)
+AddTemplateArgument(TA);
 }
 
 void TemplateArgumentHasher::AddQualType(QualType T) {

>From c8183e71f406dcf0361b06fa25e7d5dd08fcac7b Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Tue, 25 Mar 2025 11:31:23 +0100
Subject: [PATCH 2/4] [Serialization] Complete only needed partial
 specializations

It is unclear (to me) why this needs to be done "for safety", but
this change significantly improves the effectiveness of lazy loading.
---
 clang/lib/Serialization/ASTReader.cpp | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8b3fd41adb465..dc45c3b17ea68 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -8084,14 +8084,8 @@ void ASTReader::CompleteRedeclChain(const Decl *D) {
 }
   }
 
-  if (Template) {
-// For partitial specialization, load all the specializations for safety.
-if (isa(D))
-  Template->loadLazySpecializationsImpl();
-else
-  Template->loadLazySpecializationsImpl(Args);
-  }
+  if (Template)
+Template->loadLazySpecializationsImpl(Args);
 }
 
 CXXCtorInitializer **

>From 3a272ba3e512218976660912ef9354ff5576c95d Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Tue, 25 Mar 2025 11:42:20 +0100
Subject: [PATCH 3/4] [Serialization] Load only needed partial specializations

Similar as the last commit, it is unclear why we need to load all
specializations, including non-partial ones, when we have a TPL.
---
 clang/lib/AST/DeclTemplate.cpp | 6 --
 1 file changed, 6 deletions(-)

diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 2f7ae6d6cac63..e76e46499038c 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -369,12 +369,6 @@ bool RedeclarableTemplateDecl::loadLazySpecializationsImpl(
   if (!ExternalSource)
 return false;
 
-  // If TPL is not null, it implies that we're loading specializations for
-  // partial templates. We need to load all specializations in such cases.
-  if (TPL)
-return 
ExternalSource->LoadExternalSpecializations(this->getCanonicalDecl(),
-   /*OnlyPartial=*/false);
-
   return ExternalSource->LoadExternalSpecializations(this->getCanonicalDecl(),
  Args);
 }

>From c44e2b21d1c87cf8ac42c27962390e910ba67b64 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Tue, 25 Mar 2025 11:59:46 +0100
Subject: [PATCH 4/4] [Serialization] Remove bail-out logic in
 TemplateArgumentHasher

While it is correct to assign a single fixed hash to all template
arguments, it can reduce the effectiveness of lazy loading and is
not actually needed: we are allowed to ignore parts that cannot be
handled because they will be analogously ignored by all hashings.
---
 .../Serialization/TemplateArgumentHasher.cpp  | 36 ++-
 1 file changed, 3 insertions(+), 33 deletions(-)

diff --git a/clang/lib/Serialization/TemplateArgumentHasher.cpp 
b/clang/lib/Serialization/TemplateArgumentHasher.cpp
index da2c70ca17b79..6b598d26c3098 100644
--- a/clang/lib/Serialization/TemplateArgumentHasher.cpp
+++ b/clang/lib/Serialization/TemplateArgumentHasher.cpp
@@ -22,17 +22,6 @@ using namespace clang;
 namespace {
 
 class TemplateArgumentHasher {
-  // If

[clang] [Headers][X86] Allow basic AVX512 predicate ops to be used in constexpr (PR #159998)

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

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


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

leecheechen 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.

Thanks for looking! Let me know if you have any questions.

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] [X86][Clang] Add AVX512 Integer Comparison Intrinsics for constexpr Evaluation (PR #164026)

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

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


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


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

2025-10-18 Thread via cfe-commits

https://github.com/shashank1545 updated 
https://github.com/llvm/llvm-project/pull/163148

>From 8d16fb7a55101dd282678bc06f91f8fca3d246ae Mon Sep 17 00:00:00 2001
From: shashank1545 
Date: Mon, 13 Oct 2025 14:06:45 +0530
Subject: [PATCH 1/4] [X86][ByteCode] Allow PSHUFB intrinsics to be used in
 constexpr #156612
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The PSHUFB instruction shuffles bytes within each 128-bit lane: for each
control byte, if bit 7 is set, the output byte is zeroed; otherwise, the
low 4 bits select a source byte (0–15) from the same lane.
---
 clang/include/clang/Basic/BuiltinsX86.td |  8 +--
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 40 +++
 clang/lib/AST/ExprConstant.cpp   | 54 
 clang/lib/Headers/avx2intrin.h   |  5 +-
 clang/lib/Headers/avx512bwintrin.h   | 15 +++---
 clang/lib/Headers/avx512vlbwintrin.h | 20 +++-
 clang/lib/Headers/tmmintrin.h| 21 
 clang/test/CodeGen/X86/avx2-builtins.c   |  2 +
 clang/test/CodeGen/X86/avx512bw-builtins.c   |  9 
 clang/test/CodeGen/X86/avx512vlbw-builtins.c | 13 +
 clang/test/CodeGen/X86/mmx-builtins.c|  2 +
 clang/test/CodeGen/X86/ssse3-builtins.c  |  2 +
 12 files changed, 153 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index 217589d7add1d..d5e6e94ce6010 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -124,7 +124,6 @@ let Attributes = [Const, NoThrow, RequiredVectorWidth<128>] 
in {
 }
 
 def pmulhrsw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, 
_Vector<8, short>)">;
-def pshufb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, 
_Vector<16, char>)">;
 def psignb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, 
_Vector<16, char>)">;
 def psignw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, 
_Vector<8, short>)">;
 def psignd128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, 
int>)">;
@@ -132,6 +131,7 @@ let Attributes = [Const, NoThrow, RequiredVectorWidth<128>] 
in {
 
   let Features = "ssse3", Attributes = [NoThrow, Const, Constexpr, 
RequiredVectorWidth<128>] in {
 def pmaddubsw128 : X86Builtin<"_Vector<8, short>(_Vector<16, char>, 
_Vector<16, char>)">;
+def pshufb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, 
_Vector<16, char>)">;
   }
 }
 
@@ -588,7 +588,6 @@ let Features = "avx2", Attributes = [NoThrow, Const, 
RequiredVectorWidth<256>] i
   def pmovmskb256 : X86Builtin<"int(_Vector<32, char>)">;
   def pmulhrsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, 
_Vector<16, short>)">;
   def psadbw256 : X86Builtin<"_Vector<4, long long int>(_Vector<32, char>, 
_Vector<32, char>)">;
-  def pshufb256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, 
char>)">;
   def psignb256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, 
char>)">;
   def psignw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, 
_Vector<16, short>)">;
   def psignd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, 
int>)">;
@@ -627,6 +626,8 @@ let Features = "avx2", Attributes = [NoThrow, Const, 
Constexpr, RequiredVectorWi
   def pmuldq256 : X86Builtin<"_Vector<4, long long int>(_Vector<8, int>, 
_Vector<8, int>)">;
   def pmuludq256 : X86Builtin<"_Vector<4, long long int>(_Vector<8, int>, 
_Vector<8, int>)">;
 
+  def pshufb256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, 
char>)">;
+
   def psllwi256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, int)">;
   def pslldi256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, int)">;
   def psllqi256 : X86Builtin<"_Vector<4, long long int>(_Vector<4, long long 
int>, int)">;
@@ -1318,7 +1319,6 @@ let Features = "avx512f", Attributes = [NoThrow, Const, 
RequiredVectorWidth<512>
 
 let Features = "avx512bw", Attributes = [NoThrow, Const, 
RequiredVectorWidth<512>] in {
   def ucmpw512_mask : X86Builtin<"unsigned int(_Vector<32, short>, _Vector<32, 
short>, _Constant int, unsigned int)">;
-  def pshufb512 : X86Builtin<"_Vector<64, char>(_Vector<64, char>, _Vector<64, 
char>)">;
 }
 
 let Features = "avx512bw", Attributes = [NoThrow, Const, Constexpr, 
RequiredVectorWidth<512>] in {
@@ -1326,6 +1326,8 @@ let Features = "avx512bw", Attributes = [NoThrow, Const, 
Constexpr, RequiredVect
   def packssdw512 : X86Builtin<"_Vector<32, short>(_Vector<16, int>, 
_Vector<16, int>)">;
   def packuswb512 : X86Builtin<"_Vector<64, char>(_Vector<32, short>, 
_Vector<32, short>)">;
   def packusdw512 : X86Builtin<"_Vector<32, short>(_Vector<16, int>, 
_Vector<16, int>)">;
+
+  def pshufb512 : X86Builtin<"_Vector<64, char>(_Vector<64, char>, _Vector<64, 
char>)">;
 }
 
 let Features = "avx512cd,avx512vl", Attributes = [NoThrow, Const, 
RequiredVectorWidth<128>] in {
diff --git 

[clang] [clang][x86] bmi-builtins.c - add i386 test coverage (PR #161171)

2025-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Simon Pilgrim (RKSimon)


Changes



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


1 Files Affected:

- (modified) clang/test/CodeGen/X86/bmi-builtins.c (+47-45) 


``diff
diff --git a/clang/test/CodeGen/X86/bmi-builtins.c 
b/clang/test/CodeGen/X86/bmi-builtins.c
index ded40ca59781e..8c9d3a64fb177 100644
--- a/clang/test/CodeGen/X86/bmi-builtins.c
+++ b/clang/test/CodeGen/X86/bmi-builtins.c
@@ -1,7 +1,9 @@
-// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +bmi -emit-llvm -o - -Wall -Werror | FileCheck %s 
--check-prefixes=CHECK,TZCNT
-// RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility 
-fms-compatibility-version=17.00 -ffreestanding %s -triple=x86_64-windows-msvc 
-emit-llvm -o - -Wall -Werror -DTEST_TZCNT | FileCheck %s --check-prefix=TZCNT
-// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +bmi -emit-llvm -o - -Wall -Werror 
| FileCheck %s --check-prefixes=CHECK,TZCNT
-// RUN: %clang_cc1 -x c++ -std=c++11 -fms-extensions -fms-compatibility 
-fms-compatibility-version=17.00 -ffreestanding %s -triple=x86_64-windows-msvc 
-emit-llvm -o - -Wall -Werror -DTEST_TZCNT | FileCheck %s --check-prefix=TZCNT
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +bmi -emit-llvm -o - -Wall -Werror | FileCheck %s 
--check-prefixes=CHECK,X64,TZCNT,TZCNT64
+// RUN: %clang_cc1 -x c -ffreestanding %s -triple=i386-apple-darwin 
-target-feature +bmi -emit-llvm -o - -Wall -Werror | FileCheck %s 
--check-prefixes=CHECK,TZCNT
+// RUN: %clang_cc1 -x c -fms-extensions -fms-compatibility 
-fms-compatibility-version=17.00 -ffreestanding %s -triple=x86_64-windows-msvc 
-emit-llvm -o - -Wall -Werror -DTEST_TZCNT | FileCheck %s 
--check-prefixes=TZCNT,TZCNT64
+// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +bmi -emit-llvm -o - -Wall -Werror | FileCheck %s 
--check-prefixes=CHECK,X64,TZCNT,TZCNT64
+// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=i386-apple-darwin 
-target-feature +bmi -emit-llvm -o - -Wall -Werror | FileCheck %s 
--check-prefixes=CHECK,TZCNT
+// RUN: %clang_cc1 -x c++ -fms-extensions -fms-compatibility 
-fms-compatibility-version=17.00 -ffreestanding %s -triple=x86_64-windows-msvc 
-emit-llvm -o - -Wall -Werror -DTEST_TZCNT | FileCheck %s 
--check-prefixes=TZCNT,TZCNT64
 
 
 #include 
@@ -48,20 +50,20 @@ unsigned int test_tzcnt_u32(unsigned int __X) {
 
 #ifdef __x86_64__
 unsigned long long test__tzcnt_u64(unsigned long long __X) {
-// TZCNT-LABEL: test__tzcnt_u64
-// TZCNT: i64 @llvm.cttz.i64(i64 %{{.*}}, i1 false)
+// TZCNT64-LABEL: test__tzcnt_u64
+// TZCNT64: i64 @llvm.cttz.i64(i64 %{{.*}}, i1 false)
   return __tzcnt_u64(__X);
 }
 
 long long test_mm_tzcnt_64(unsigned long long __X) {
-// TZCNT-LABEL: test_mm_tzcnt_64
-// TZCNT: i64 @llvm.cttz.i64(i64 %{{.*}}, i1 false)
+// TZCNT64-LABEL: test_mm_tzcnt_64
+// TZCNT64: i64 @llvm.cttz.i64(i64 %{{.*}}, i1 false)
   return _mm_tzcnt_64(__X);
 }
 
 unsigned long long test_tzcnt_u64(unsigned long long __X) {
-// TZCNT-LABEL: test_tzcnt_u64
-// TZCNT: i64 @llvm.cttz.i64(i64 %{{.*}}, i1 false)
+// TZCNT64-LABEL: test_tzcnt_u64
+// TZCNT64: i64 @llvm.cttz.i64(i64 %{{.*}}, i1 false)
   return _tzcnt_u64(__X);
 }
 #endif
@@ -103,36 +105,36 @@ unsigned int test__blsr_u32(unsigned int __X) {
 
 #ifdef __x86_64__
 unsigned long long test__andn_u64(unsigned long __X, unsigned long __Y) {
-// CHECK-LABEL: test__andn_u64
-// CHECK: xor i64 %{{.*}}, -1
-// CHECK: and i64 %{{.*}}, %{{.*}}
+// X64-LABEL: test__andn_u64
+// X64: xor i64 %{{.*}}, -1
+// X64: and i64 %{{.*}}, %{{.*}}
   return __andn_u64(__X, __Y);
 }
 
 unsigned long long test__bextr_u64(unsigned long __X, unsigned long __Y) {
-// CHECK-LABEL: test__bextr_u64
-// CHECK: i64 @llvm.x86.bmi.bextr.64(i64 %{{.*}}, i64 %{{.*}})
+// X64-LABEL: test__bextr_u64
+// X64: i64 @llvm.x86.bmi.bextr.64(i64 %{{.*}}, i64 %{{.*}})
   return __bextr_u64(__X, __Y);
 }
 
 unsigned long long test__blsi_u64(unsigned long long __X) {
-// CHECK-LABEL: test__blsi_u64
-// CHECK: sub i64 0, %{{.*}}
-// CHECK: and i64 %{{.*}}, %{{.*}}
+// X64-LABEL: test__blsi_u64
+// X64: sub i64 0, %{{.*}}
+// X64: and i64 %{{.*}}, %{{.*}}
   return __blsi_u64(__X);
 }
 
 unsigned long long test__blsmsk_u64(unsigned long long __X) {
-// CHECK-LABEL: test__blsmsk_u64
-// CHECK: sub i64 %{{.*}}, 1
-// CHECK: xor i64 %{{.*}}, %{{.*}}
+// X64-LABEL: test__blsmsk_u64
+// X64: sub i64 %{{.*}}, 1
+// X64: xor i64 %{{.*}}, %{{.*}}
   return __blsmsk_u64(__X);
 }
 
 unsigned long long test__blsr_u64(unsigned long long __X) {
-// CHECK-LABEL: test__blsr_u64
-// CHECK: sub i64 %{{.*}}, 1
-// CHECK: and i64 %{{.*}}, %{{.*}}
+// X64-LABEL: test__blsr_u64
+// X64: sub i64 %{{.*}}, 1
+// X64: and i64 %{{.*}}, %{{.*}}
   return __blsr_u64(__X);
 }
 #endif
@@ -186,49 +188,49 @@ unsigned int test_blsr_u32(unsigne

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

2025-10-18 Thread via cfe-commits




clingfei wrote:

Fixed in my recent commit, please review it.

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


[clang] [clang][x86][bytecode] Replace interp__builtin_rotate with static bool interp__builtin_elementwise_int_binop callback #160289 (PR #161924)

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


@@ -56,6 +56,20 @@ static APSInt popToAPSInt(InterpState &S, QualType T) {
   return popToAPSInt(S.Stk, *S.getContext().classify(T));
 }
 
+static APInt ROTL_fn(const APSInt &A, const APSInt &B) {
+  const APInt &X = static_cast(A);
+  const unsigned BW = X.getBitWidth();
+  const uint64_t Amt = B.getZExtValue();
+  return X.rotl(static_cast(Amt % BW));
+}
+
+static APInt ROTR_fn(const APSInt &A, const APSInt &B) {
+  const APInt &X = static_cast(A);
+  const unsigned BW = X.getBitWidth();

tbaederr wrote:

Don't make local non-references/non-pointers const.

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


[libcxx] [libcxxabi] [libunwind] [runtimes][NFC] Consistently declare main() functions in tests (PR #162548)

2025-10-18 Thread Louis Dionne via cfe-commits

ldionne wrote:

Merging since the CI issues are unrelated.

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


[clang] [clang] Fix test to require x86 (PR #162318)

2025-10-18 Thread Fangrui Song via cfe-commits

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


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


[clang] [CIR] vTableClassNameForType: return correct VTableClass name for Type::ObjCObjectPointer, Type::Pointer (PR #163850)

2025-10-18 Thread via cfe-commits

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


[clang] [Driver] Remove support for FreeBSD 13.x (PR #163847)

2025-10-18 Thread Brad Smith via cfe-commits

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


[clang] [Mips] Fix mcpu flag with i6400/i6500 (PR #161330)

2025-10-18 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-mips

Author: None (ArielCPU)


Changes

The compiler is missing cases where it checks mips64r6 but not i6400/i6500 
causing wrong defines to be generated

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


4 Files Affected:

- (modified) clang/lib/Basic/Targets/Mips.cpp (+2-2) 
- (modified) clang/lib/Basic/Targets/Mips.h (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Arch/Mips.cpp (+2) 
- (modified) clang/test/Preprocessor/init-mips.c (+22) 


``diff
diff --git a/clang/lib/Basic/Targets/Mips.cpp b/clang/lib/Basic/Targets/Mips.cpp
index 34837cc363a37..c806c5f7671d0 100644
--- a/clang/lib/Basic/Targets/Mips.cpp
+++ b/clang/lib/Basic/Targets/Mips.cpp
@@ -72,7 +72,7 @@ unsigned MipsTargetInfo::getISARev() const {
   .Cases("mips32r2", "mips64r2", "octeon", "octeon+", 2)
   .Cases("mips32r3", "mips64r3", 3)
   .Cases("mips32r5", "mips64r5", "p5600", 5)
-  .Cases("mips32r6", "mips64r6", 6)
+  .Cases("mips32r6", "mips64r6", "i6400", "i6500", 6)
   .Default(0);
 }
 
@@ -271,7 +271,7 @@ bool MipsTargetInfo::validateTarget(DiagnosticsEngine 
&Diags) const {
   }
   // Mips revision 6 and -mfp32 are incompatible
   if (FPMode != FP64 && FPMode != FPXX && (CPU == "mips32r6" ||
-  CPU == "mips64r6")) {
+  CPU == "mips64r6" || CPU == "i6400" || CPU == "i6500")) {
 Diags.Report(diag::err_opt_not_valid_with_opt) << "-mfp32" << CPU;
 return false;
   }
diff --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index e199df32f56ee..106c4f8d637eb 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -83,7 +83,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
   }
 
   bool isIEEE754_2008Default() const {
-return CPU == "mips32r6" || CPU == "mips64r6";
+return CPU == "mips32r6" || CPU == "mips64r6" || CPU == "i6400" || CPU == 
"i6500";
   }
 
   enum FPModeEnum getDefaultFPMode() const {
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index 8787c8276721c..bac8681921877 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -442,6 +442,8 @@ bool mips::hasCompactBranches(StringRef &CPU) {
   return llvm::StringSwitch(CPU)
   .Case("mips32r6", true)
   .Case("mips64r6", true)
+  .Case("i6400", true)
+  .Case("i6500", true)
   .Default(false);
 }
 
diff --git a/clang/test/Preprocessor/init-mips.c 
b/clang/test/Preprocessor/init-mips.c
index 125872a001bac..c829eebdc9ec9 100644
--- a/clang/test/Preprocessor/init-mips.c
+++ b/clang/test/Preprocessor/init-mips.c
@@ -1649,6 +1649,28 @@
 // MIPS-ARCH-OCTEONP:#define __OCTEON__ 1
 // MIPS-ARCH-OCTEONP:#define __mips_isa_rev 2
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \
+// RUN:-target-cpu i6400 < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS-ARCH-I6400 %s
+//
+// MIPS-ARCH-I6400:#define _MIPS_ARCH "i6400"
+// MIPS-ARCH-I6400:#define _MIPS_ARCH_I6400 1
+// MIPS-ARCH-I6400:#define _MIPS_ISA _MIPS_ISA_MIPS64
+// MIPS-ARCH-I6400:#define __mips_abs2008 1
+// MIPS-ARCH-I6400:#define __mips_isa_rev 6
+// MIPS-ARCH-I6400:#define __mips_nan2008 1
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=mips64-none-none \
+// RUN:-target-cpu i6500 < /dev/null \
+// RUN:   | FileCheck -match-full-lines -check-prefix MIPS-ARCH-I6500 %s
+//
+// MIPS-ARCH-I6500:#define _MIPS_ARCH "i6500"
+// MIPS-ARCH-I6500:#define _MIPS_ARCH_I6500 1
+// MIPS-ARCH-I6500:#define _MIPS_ISA _MIPS_ISA_MIPS64
+// MIPS-ARCH-I6500:#define __mips_abs2008 1
+// MIPS-ARCH-I6500:#define __mips_isa_rev 6
+// MIPS-ARCH-I6500:#define __mips_nan2008 1
+
 // Check MIPS float ABI macros
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding \

``




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


[clang] [clang][x86][bytecode] Replace interp__builtin_rotate with static bool interp__builtin_elementwise_int_binop callback #160289 (PR #161924)

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


@@ -56,6 +56,20 @@ static APSInt popToAPSInt(InterpState &S, QualType T) {
   return popToAPSInt(S.Stk, *S.getContext().classify(T));
 }
 
+static APInt ROTL_fn(const APSInt &A, const APSInt &B) {
+  const APInt &X = static_cast(A);
+  const unsigned BW = X.getBitWidth();
+  const uint64_t Amt = B.getZExtValue();
+  return X.rotl(static_cast(Amt % BW));
+}
+
+static APInt ROTR_fn(const APSInt &A, const APSInt &B) {
+  const APInt &X = static_cast(A);

tbaederr wrote:

This explicit cast is unnecessary AFAIK.

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

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

... non-constexpr variable initializers.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.cpp (-3) 
- (modified) clang/test/AST/ByteCode/cxx11.cpp (+8) 


``diff
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);

``




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


[clang] 8570ba2 - [clang][analyzer] Add checker 'core.NullPointerArithm' (#157129)

2025-10-18 Thread via cfe-commits

Author: Balázs Kéri
Date: 2025-10-16T08:44:56+02:00
New Revision: 8570ba2d87eb4877c428fa616b6fe4141684e467

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

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

Added: 
clang/test/Analysis/null-pointer-arithm.c

Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
clang/test/Analysis/analyzer-enabled-checkers.c
clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index d942578dd7596..dcfa4e3ccc401 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -205,6 +205,50 @@ pointers with a specified address space. If the option is 
set to false, then
 reports from the specific x86 address spaces 256, 257 and 258 are still
 suppressed, but null dereferences from other address spaces are reported.
 
+.. _core-NullPointerArithm:
+
+core.NullPointerArithm (C, C++)
+"""
+Check for undefined arithmetic operations with null pointers.
+
+The checker can detect the following cases:
+
+  - ``p + x`` and ``x + p`` where ``p`` is a null pointer and ``x`` is a 
nonzero
+integer value.
+  - ``p - x`` where ``p`` is a null pointer and ``x`` is a nonzero integer
+value.
+  - ``p1 - p2`` where one of ``p1`` and ``p2`` is null and the other a
+non-null pointer.
+
+Result of these operations is undefined according to the standard.
+In the above listed cases, the checker will warn even if the expression
+described to be "nonzero" or "non-null" has unknown value, because it is likely
+that it can have non-zero value during the program execution.
+
+.. code-block:: c
+
+ void test1(int *p, int offset) {
+   if (p)
+ return;
+
+   int *p1 = p + offset; // warn: 'p' is null, 'offset' is unknown but likely 
non-zero
+ }
+
+ void test2(int *p, int offset) {
+   if (p) { } // this indicates that it is possible for 'p' to be null
+   if (offset == 0)
+ return;
+
+   int *p1 = p - offset; // warn: 'p' is null, 'offset' is known to be non-zero
+ }
+
+ void test3(char *p1, char *p2) {
+   if (p1)
+ return;
+
+   int a = p1 - p2; // warn: 'p1' is null, 'p2' can be likely non-null
+ }
+
 .. _core-StackAddressEscape:
 
 core.StackAddressEscape (C)

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 4473c54d8d6e3..b83bbcdb85a8f 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -195,6 +195,11 @@ def NullDereferenceChecker
   HelpText<"Check for dereferences of null pointers">,
   Documentation;
 
+def NullPointerArithmChecker
+: Checker<"NullPointerArithm">,
+  HelpText<"Check for undefined arithmetic operations on null pointers">,
+  Documentation;
+
 def NonNullParamChecker : Checker<"NonNullParamChecker">,
   HelpText<"Check for null pointers passed as arguments to a function whose "
"arguments are references or marked with the 'nonnull' attribute">,

diff  --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
index 395d724cdfd11..37f5ec3557400 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -19,6 +19,7 @@
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
@@ -39,9 +40,10 @@ class DerefBugType : public BugType {
 
 class DereferenceChecker
 : public CheckerFamily,
EventDispatcher> {
-  void reportBug(const DerefBugType &BT, ProgramStateRef State, const Stmt *S,
- CheckerContext &C) const;
+  void reportDerefBug(const DerefBugType &BT, ProgramStateRef State,
+  const Stmt *S, CheckerContext &C) const;
 
   bool suppressReport(CheckerContext &C, const Expr *E) const;
 
@@ -50,6 +52,7 @@ class DereferenceChecker
  CheckerContext &C) const;
   void checkBind(SVal L, SVal V, const Stmt *S, bool AtDeclInit,
  CheckerContext &C) const;
+  void checkPreStmt(const BinaryOperator *Op, CheckerContext &C) const;
 
   static void AddDerefSource(raw_ostream &os,
  SmallVectorImpl &Ranges,
@@ -57,7 +60,7 @@ class DereferenceChe

[clang] [llvm] [SYCL] Add offload wrapping for SYCL kind. (PR #147508)

2025-10-18 Thread Maksim Sabianin via cfe-commits


@@ -52,6 +54,23 @@ LLVM_ABI llvm::Error wrapHIPBinary(llvm::Module &M, 
llvm::ArrayRef Images,
EntryArrayTy EntryArray,
llvm::StringRef Suffix = "",
bool EmitSurfacesAndTextures = true);
+
+struct SYCLJITOptions {
+  // Target/compiler specific options that are suggested to use to "compile"
+  // program at runtime.
+  std::string CompileOptions;
+  // Target/compiler specific options that are suggested to use to "link"
+  // program at runtime.
+  std::string LinkOptions;
+};
+
+/// Wraps OffloadBinaries in the given \p Buffers into the module \p M
+/// as global symbols and registers the images with the SYCL Runtime.
+/// \param Options Data that needs to be encoded for the later use in a 
runtime.
+LLVM_ABI llvm::Error
+wrapSYCLBinaries(llvm::Module &M, llvm::ArrayRef Buffer,
+ SYCLJITOptions Options = SYCLJITOptions());

maksimsab wrote:

Yes, AOT mode is a case when it is too late to pass any options.

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


[clang] [clang] Fix inconsistencies with the device_kernel attr on different targets (PR #161905)

2025-10-18 Thread Nick Sarnie via cfe-commits

https://github.com/sarnex updated 
https://github.com/llvm/llvm-project/pull/161905

>From a27574f3b80235b7975e3cae9d24fef3c24b3627 Mon Sep 17 00:00:00 2001
From: "Sarnie, Nick" 
Date: Fri, 3 Oct 2025 12:33:38 -0700
Subject: [PATCH] [clang] Fix inconsistencies with the device_kernel attr on
 different targets

Signed-off-by: Sarnie, Nick 
---
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Basic/Attr.td  |  2 +-
 clang/lib/AST/TypePrinter.cpp  |  3 --
 clang/lib/Basic/Targets/NVPTX.h|  2 +-
 clang/lib/CodeGen/Targets/AMDGPU.cpp   |  6 ++--
 clang/lib/CodeGen/Targets/SPIR.cpp | 33 ++--
 clang/lib/Sema/SemaDeclAttr.cpp| 36 --
 clang/lib/Sema/SemaType.cpp| 18 ++-
 clang/test/Sema/callingconv-devicekernel.c | 24 +++
 clang/test/Sema/callingconv.c  |  4 +++
 10 files changed, 100 insertions(+), 29 deletions(-)
 create mode 100644 clang/test/Sema/callingconv-devicekernel.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d2e5bd284d350..da391082eba5b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -401,6 +401,7 @@ Bug Fixes to Attribute Support
 - Using ``[[gnu::cleanup(some_func)]]`` where some_func is annotated with
   ``[[gnu::error("some error")]]`` now correctly triggers an error. (#GH146520)
 - Fix a crash when the function name is empty in the `swift_name` attribute. 
(#GH157075)
+- Fixes crashes or missing diagnostics with the `device_kernel` attribute. 
(#GH161905)
 
 Bug Fixes to C++ Support
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 3c697ed8dd882..6ec0eac529245 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1599,7 +1599,7 @@ def CUDAShared : InheritableAttr {
 }
 def : MutualExclusions<[CUDAConstant, CUDAShared, HIPManaged]>;
 
-def DeviceKernel : DeclOrTypeAttr {
+def DeviceKernel : InheritableAttr {
   let Spellings = [Clang<"device_kernel">, Clang<"sycl_kernel">,
Clang<"nvptx_kernel">, Clang<"amdgpu_kernel">,
CustomKeyword<"__kernel">, CustomKeyword<"kernel">];
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 66a1b684ec68b..568d56ab0b911 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2147,9 +2147,6 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
   }
   case attr::AArch64VectorPcs: OS << "aarch64_vector_pcs"; break;
   case attr::AArch64SVEPcs: OS << "aarch64_sve_pcs"; break;
-  case attr::DeviceKernel:
-OS << T->getAttr()->getSpelling();
-break;
   case attr::IntelOclBicc:
 OS << "inteloclbicc";
 break;
diff --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h
index 33c29586359be..f5c8396f398aa 100644
--- a/clang/lib/Basic/Targets/NVPTX.h
+++ b/clang/lib/Basic/Targets/NVPTX.h
@@ -200,7 +200,7 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public 
TargetInfo {
 // a host function.
 if (HostTarget)
   return HostTarget->checkCallingConvention(CC);
-return CCCR_Warning;
+return CC == CC_DeviceKernel ? CCCR_OK : CCCR_Warning;
   }
 
   bool hasBitIntType() const override { return true; }
diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index 0fcbf7e458a34..d54b1dc128254 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -419,9 +419,11 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes(
 return;
 
   const FunctionDecl *FD = dyn_cast_or_null(D);
-  if (FD)
+  if (FD) {
 setFunctionDeclAttributes(FD, F, M);
-
+if (FD->hasAttr() && !M.getLangOpts().OpenCL)
+  F->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
+  }
   if (!getABIInfo().getCodeGenOpts().EmitIEEENaNCompliantInsts)
 F->addFnAttr("amdgpu-ieee", "false");
 }
diff --git a/clang/lib/CodeGen/Targets/SPIR.cpp 
b/clang/lib/CodeGen/Targets/SPIR.cpp
index 4aa63143a66cd..42ef1c704831c 100644
--- a/clang/lib/CodeGen/Targets/SPIR.cpp
+++ b/clang/lib/CodeGen/Targets/SPIR.cpp
@@ -61,6 +61,8 @@ class CommonSPIRTargetCodeGenInfo : public TargetCodeGenInfo {
   QualType SampledType, CodeGenModule &CGM) const;
   void
   setOCLKernelStubCallingConvention(const FunctionType *&FT) const override;
+  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule &M) const override;
 };
 class SPIRVTargetCodeGenInfo : public CommonSPIRTargetCodeGenInfo {
 public:
@@ -240,6 +242,26 @@ void 
CommonSPIRTargetCodeGenInfo::setOCLKernelStubCallingConvention(
   FT, FT->getExtInfo().withCallingConv(CC_SpirFunction));
 }
 
+void CommonSPIRTargetCodeGenInfo::setTargetAttributes(
+const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
+  if (M.getLangOpts().OpenCL)
+

[clang-tools-extra] clangd: Make callHierarchy follow inheritance (PR #163024)

2025-10-18 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> Also I wanted to ask if getting `check-clangd` to successfully run is the 
> last hold-back for this PR

No hold-back, just haven't had the time to look at it yet. I have a day job and 
some weeks are busier than others.

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


[clang] [X86][Clang] Allow SSE/AVX COMI/UCOMI/CMPS/CMPP fp comparison intrinsics to be used in constexpr (PR #160876)

2025-10-18 Thread via cfe-commits

https://github.com/zeyi2 updated 
https://github.com/llvm/llvm-project/pull/160876

>From dc9c318af379bc8328c69ee7d14787e99e906816 Mon Sep 17 00:00:00 2001
From: mtx 
Date: Sat, 27 Sep 2025 18:15:20 +0800
Subject: [PATCH 1/6] [X86][Clang] Support `__builtin_ia32_(u)comi(sd)`

---
 clang/include/clang/Basic/BuiltinsX86.td |   4 +-
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 149 ++-
 clang/lib/AST/ExprConstant.cpp   | 143 ++
 clang/lib/Headers/avx512fp16intrin.h |  48 +++---
 clang/lib/Headers/emmintrin.h|  48 +++---
 clang/lib/Headers/xmmintrin.h|  60 +++-
 clang/test/CodeGen/X86/avx512fp16-builtins.c |  46 +-
 7 files changed, 408 insertions(+), 90 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index 77e599587edc3..c044fee65847d 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -58,7 +58,7 @@ let Attributes = [NoThrow, Const, RequiredVectorWidth<64>], 
Features = "sse" in
 }
 
 // SSE intrinsics
-let Attributes = [Const, NoThrow, RequiredVectorWidth<128>] in {
+let Attributes = [Const, Constexpr, NoThrow, RequiredVectorWidth<128>] in {
   foreach Cmp = ["eq", "lt", "le", "gt", "ge", "neq"] in {
 let Features = "sse" in {
   def comi#Cmp : X86Builtin<"int(_Vector<4, float>, _Vector<4, float>)">;
@@ -3423,7 +3423,7 @@ let Features = "avx512vp2intersect,avx512vl", Attributes 
= [NoThrow, RequiredVec
   def vp2intersect_d_128 : X86Builtin<"void(_Vector<4, int>, _Vector<4, int>, 
unsigned char *, unsigned char *)">;
 }
 
-let Features = "avx512fp16", Attributes = [NoThrow, Const, 
RequiredVectorWidth<128>] in {
+let Features = "avx512fp16", Attributes = [NoThrow, Const, Constexpr, 
RequiredVectorWidth<128>] in {
   def vcomish : X86Builtin<"int(_Vector<8, _Float16>, _Vector<8, _Float16>, 
_Constant int, _Constant int)">;
 }
 
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 891344d4e6ed0..fd3c21a0a4a68 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -11,6 +11,7 @@
 #include "Interp.h"
 #include "InterpBuiltinBitCast.h"
 #include "PrimType.h"
+#include "immintrin.h"
 #include "clang/AST/OSLog.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/Basic/Builtins.h"
@@ -2967,6 +2968,122 @@ static bool 
interp__builtin_x86_insert_subvector(InterpState &S, CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_x86_vcomish(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame,
+const CallExpr *Call) {
+  using CmpResult = llvm::APFloatBase::cmpResult;
+
+  llvm::APSInt R =
+  popToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(3)));
+  llvm::APSInt P =
+  popToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)));
+  const Pointer &VB = S.Stk.pop();
+  const Pointer &VA = S.Stk.pop();
+
+  llvm::APFloat A0 = VA.elem(0).getAPFloat();
+  llvm::APFloat B0 = VB.elem(0).getAPFloat();
+  CmpResult cmp = A0.compare(B0);
+
+  bool isEq = cmp == (CmpResult::cmpEqual);
+  bool isGt = cmp == (CmpResult::cmpGreaterThan);
+  bool isLt = cmp == (CmpResult::cmpLessThan);
+  bool result = false;
+
+  switch (P.getZExtValue()) {
+  case _CMP_EQ_OQ: /* _mm_ucomieq_sh */
+  case _CMP_EQ_OS: /* _mm_comieq_sh */
+result = isEq && !A0.isNaN() && !B0.isNaN();
+break;
+  case _CMP_NEQ_US: /* _mm_comineq_sh */
+  case _CMP_NEQ_UQ: /* _mm_ucomineq_sh */
+result = !isEq || A0.isNaN() || B0.isNaN();
+break;
+  case _CMP_GE_OS: /* _mm_comige_sh */
+  case _CMP_GE_OQ: /* _mm_ucomige_sh */
+result = !isLt && !A0.isNaN() && !B0.isNaN();
+break;
+  case _CMP_LT_OS: /* _mm_comilt_sh */
+  case _CMP_LT_OQ: /* _mm_ucomilt_sh */
+result = isLt && !A0.isNaN() && !B0.isNaN();
+break;
+  case _CMP_GT_OS: /* _mm_comigt_sh */
+  case _CMP_GT_OQ: /* _mm_ucomigt_sh */
+result = isGt && !A0.isNaN() && !B0.isNaN();
+break;
+  case _CMP_LE_OS: /* _mm_comile_sh */
+  case _CMP_LE_OQ: /*_mm_ucomile_sh */
+result = !isGt && !A0.isNaN() && !B0.isNaN();
+break;
+  default:
+return false;
+  }
+
+  pushInteger(S, result ? 1 : 0, Call->getType());
+  return true;
+}
+
+static bool interp__builtin_x86_compare_scalar(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const CallExpr *Call,
+   unsigned ID) {
+  using CmpResult = llvm::APFloatBase::cmpResult;
+
+  const Pointer &VB = S.Stk.pop();
+  const Pointer &VA = S.Stk.pop();
+
+  llvm::APFloat A0 = VA.elem(0).getAPFloat();
+  llvm::APFloat B0 = VB.elem(0).getAPFloat();
+  CmpResult cmp = A0.compare(B0);
+
+  bool isEq = cmp == (CmpResult::cmpEqual);
+  bool isGt = cmp == (CmpResult::c

[clang] Reapply "[clang] Convert second arg of __builtin_assume_aligned to Co… (PR #161945)

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

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


[clang] 9abb344 - [Darwin][Driver] Avoid duplicate -lc++ with -fsanitize=fuzzer (#161304)

2025-10-18 Thread via cfe-commits

Author: Andrew Haberlandt
Date: 2025-10-09T09:38:27+01:00
New Revision: 9abb344e572e165f01d7789522113d9a4d8b0ca6

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

LOG: [Darwin][Driver] Avoid duplicate -lc++ with -fsanitize=fuzzer (#161304)

On Darwin, duplicate `-l` options cause a warning to be printed.

Invoking clang as clang++ and using `-fsanitize=fuzzer` will cause `-lc++`
to be passed twice to the linker, causing a warning.

i.e. AddCXXStdlibLibArgs is called twice in this case:

1)
https://github.com/llvm/llvm-project/blob/19c4e86f3e8582c3f087a9fec5ac036838e58ec4/clang/lib/Driver/ToolChains/Darwin.cpp#L743
because `ShouldLinkCXXStdlib(Args)` is true.
2) The subject of this PR

We now skip adding the -lc++ argument if `ShouldLinkCXXStdlib(Args)`
(since that means the other path already added it).

rdar://136431775

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 234683f2f4882..d2356ebdfa86c 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1609,7 +1609,12 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 if (Sanitize.needsFuzzer() && !Args.hasArg(options::OPT_dynamiclib)) {
   AddLinkSanitizerLibArgs(Args, CmdArgs, "fuzzer", /*shared=*/false);
 
-// Libfuzzer is written in C++ and requires libcxx.
+  // Libfuzzer is written in C++ and requires libcxx.
+  // Since darwin::Linker::ConstructJob already adds -lc++ for clang++
+  // by default if ShouldLinkCXXStdlib(Args), we only add the option if
+  // !ShouldLinkCXXStdlib(Args). This avoids duplicate library errors
+  // on Darwin.
+  if (!ShouldLinkCXXStdlib(Args))
 AddCXXStdlibLibArgs(Args, CmdArgs);
 }
 if (Sanitize.needsStatsRt()) {



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

https://github.com/Lukacma created 
https://github.com/llvm/llvm-project/pull/163575

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

>From e7a2489497e4c896d1a2a425356f2c1dac2de1d4 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 15 Oct 2025 15:09:35 +
Subject: [PATCH] [AArch64] Add intrinsics support for SVE2p2 instructions

---
 clang/include/clang/Basic/arm_sve.td  |  12 +-
 .../AArch64/sve-intrinsics/acle_sve_compact.c |   6 +
 .../sve2p2-intriniscs/acle_sve2p2_compact.c   | 142 ++
 .../sve2p2-intriniscs/acle_sve2p2_expand.c| 243 ++
 .../sve2p2-intriniscs/acle_sve2p2_firstp.c| 101 
 .../sve2p2-intriniscs/acle_sve2p2_lastp.c | 101 
 llvm/include/llvm/IR/IntrinsicsAArch64.td |   3 +
 .../lib/Target/AArch64/AArch64SVEInstrInfo.td |   6 +-
 llvm/lib/Target/AArch64/SVEInstrFormats.td|  18 +-
 .../test/CodeGen/AArch64/sve2p2-intrinsics.ll | 173 +
 10 files changed, 793 insertions(+), 12 deletions(-)
 create mode 100644 
clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_compact.c
 create mode 100644 
clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_expand.c
 create mode 100644 
clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_firstp.c
 create mode 100644 
clang/test/CodeGen/AArch64/sve2p2-intriniscs/acle_sve2p2_lastp.c

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-

[clang] bcf9e91 - [Clang] Fix a regression introduced by #161163. (#162612)

2025-10-18 Thread via cfe-commits

Author: Corentin Jabot
Date: 2025-10-15T11:54:04+02:00
New Revision: bcf9e917142de4a5c4799b4debe7d11500cee426

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

LOG: [Clang] Fix a regression introduced by #161163. (#162612)

Classes with a user provided constructor are still implicit lifetime if
they have an implicit, trivial copy ctr.

Added: 


Modified: 
clang/lib/Sema/SemaTypeTraits.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTypeTraits.cpp 
b/clang/lib/Sema/SemaTypeTraits.cpp
index 3e34675cbf064..aca21cc793170 100644
--- a/clang/lib/Sema/SemaTypeTraits.cpp
+++ b/clang/lib/Sema/SemaTypeTraits.cpp
@@ -1076,8 +1076,7 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 if (T.isPODType(C) || T->isObjCLifetimeType())
   return true;
 if (CXXRecordDecl *RD = C.getBaseElementType(T)->getAsCXXRecordDecl()) {
-  if (RD->hasTrivialDefaultConstructor() &&
-  !RD->hasNonTrivialDefaultConstructor())
+  if (RD->hasTrivialDefaultConstructor())
 return true;
 
   bool FoundConstructor = false;
@@ -1165,14 +1164,26 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, 
TypeTrait UTT,
 const CXXDestructorDecl *Dtor = RD->getDestructor();
 if (UnqualT->isAggregateType() && (!Dtor || !Dtor->isUserProvided()))
   return true;
-if (RD->hasTrivialDestructor() && (!Dtor || !Dtor->isDeleted())) {
-  for (CXXConstructorDecl *Ctr : RD->ctors()) {
-if (Ctr->isIneligibleOrNotSelected() || Ctr->isDeleted())
-  continue;
-if (Ctr->isTrivial())
-  return true;
-  }
+bool HasTrivialNonDeletedDtr =
+RD->hasTrivialDestructor() && (!Dtor || !Dtor->isDeleted());
+if (!HasTrivialNonDeletedDtr)
+  return false;
+for (CXXConstructorDecl *Ctr : RD->ctors()) {
+  if (Ctr->isIneligibleOrNotSelected() || Ctr->isDeleted())
+continue;
+  if (Ctr->isTrivial())
+return true;
 }
+if (RD->needsImplicitDefaultConstructor() &&
+RD->hasTrivialDefaultConstructor() &&
+!RD->hasNonTrivialDefaultConstructor())
+  return true;
+if (RD->needsImplicitCopyConstructor() && RD->hasTrivialCopyConstructor() 
&&
+!RD->defaultedCopyConstructorIsDeleted())
+  return true;
+if (RD->needsImplicitMoveConstructor() && RD->hasTrivialMoveConstructor() 
&&
+!RD->defaultedMoveConstructorIsDeleted())
+  return true;
 return false;
   }
   case UTT_IsIntangibleType:

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 901d510bba847..9ef44d0346b48 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2066,7 +2066,28 @@ class UserProvidedConstructor {
 UserProvidedConstructor(const UserProvidedConstructor&)= 
delete;
 UserProvidedConstructor& operator=(const UserProvidedConstructor&) = 
delete;
 };
+struct Ctr {
+  Ctr();
+};
+struct Ctr2 {
+  Ctr2();
+private:
+  NoEligibleTrivialContructor inner;
+};
+
+struct NonCopyable{
+NonCopyable() = default;
+NonCopyable(const NonCopyable&) = delete;
+};
+
+class C {
+NonCopyable nc;
+};
 
+static_assert(__builtin_is_implicit_lifetime(Ctr));
+static_assert(!__builtin_is_implicit_lifetime(Ctr2));
+static_assert(__builtin_is_implicit_lifetime(C));
+static_assert(!__builtin_is_implicit_lifetime(NoEligibleTrivialContructor));
 static_assert(__builtin_is_implicit_lifetime(NonAggregate));
 static_assert(!__builtin_is_implicit_lifetime(DataMemberInitializer));
 static_assert(!__builtin_is_implicit_lifetime(UserProvidedConstructor));
@@ -2076,9 +2097,27 @@ template 
 class Tpl {
 Tpl() requires false = default ;
 };
-static_assert(!__builtin_is_implicit_lifetime(Tpl));
+static_assert(__builtin_is_implicit_lifetime(Tpl));
+
+template 
+class MultipleDefaults {
+  MultipleDefaults() {};
+  MultipleDefaults() requires true = default;
+};
+static_assert(__builtin_is_implicit_lifetime(MultipleDefaults));
+template 
+class MultipleDefaults2 {
+  MultipleDefaults2() requires true {};
+  MultipleDefaults2() = default;
+};
+
+static_assert(__builtin_is_implicit_lifetime(MultipleDefaults2));
+
 
 #endif
+
+
+
 }
 
 void is_signed()



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


[clang] [clang] Fix catching pointers by reference on mingw targets (PR #162546)

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

efriedma-quic wrote:

> (See the SEH ifdef in `_Unwind_Exception` in clang/lib/Headers/unwind.h.)

The header also checks that `__USING_SJLJ_EXCEPTIONS__` is not defined.  Is 
that just redundant?

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


[clang] [Clang] Ensure compound requirements do not contain placeholder expressions (PR #162618)

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

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


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


[clang] [clang-tools-extra] [clang-tidy] `bugprone-unchecked-optional-access`: handle `BloombergLP::bdlb:NullableValue::makeValue` to prevent false-positives (PR #144313)

2025-10-18 Thread Yitzhak Mandelbaum via cfe-commits


@@ -985,6 +985,20 @@ auto buildTransferMatchSwitch() {
   isOptionalMemberCallWithNameMatcher(hasName("isNull")),
   transferOptionalIsNullCall)
 
+  // NullableValue::makeValue, NullableValue::makeValueInplace
+  // Only NullableValue has these methods, but this
+  // will also pass for other types
+  .CaseOfCFGStmt(
+  isOptionalMemberCallWithNameMatcher(
+  hasAnyName("makeValue", "makeValueInplace")),
+  [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &,
+ LatticeTransferState &State) {
+if (RecordStorageLocation *Loc =
+getImplicitObjectLocation(*E, State.Env)) {
+  setHasValue(*Loc, State.Env.getBoolLiteralValue(true), 
State.Env);
+}
+  })
+

ymand wrote:

Replied on the discourse discussion. Sorry for the delay -- missed this one!

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


[clang] [clang-format] Add SpaceBeforeUnderscoreParens option for GNU gettext… (PR #159925)

2025-10-18 Thread via cfe-commits

owenca wrote:

I would add `SBPO_GNU`:
```
SpaceBeforeParens:
  GNU # same as Always except when preceded by an underscore as the function 
name
```

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


[clang] [flang] [llvm] [openmp] [clang][OpenMP] New OpenMP 6.0 threadset clause (PR #135807)

2025-10-18 Thread Michael Klemm via cfe-commits

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

LGTM

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


[clang] [Headers][X86] VectorExprEvaluator::VisitCallExpr - allow SSE/AVX2/AVX512 pack intrinsics to be used in constexpr (PR #156003)

2025-10-18 Thread via cfe-commits


@@ -55,6 +55,7 @@
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/APFixedPoint.h"
+#include "llvm/ADT/APSInt.h"

woruyu wrote:

Done! yes, removed

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


[clang] [Clang][HIP][CUDA] Add `__cluster_dims__` and `__no_cluster__` attribute (PR #156686)

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

erichkeane wrote:

> > I think the declspec spellings aren't done yet
> 
> I think that is also part of the "established nomenclature" that @Artem-B was 
> referring to.

The difference is (AFAIK) that Clang actually ALWAYS supports the 
double-underscore start/end spellings by adding them to the beginning/end of 
the existing name.  So I'm saying you shouldn't need them in the Attr.td file, 
as they will be auto-added.  You can document the "established 
nomenclature"/use it anyway, but the Attr.td shouldn't have it AFAIK

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


[clang] [CIR] vTableClassNameForType: return correct VTableClass name for Type::ObjCObjectPointer, Type::Pointer (PR #163850)

2025-10-18 Thread via cfe-commits

https://github.com/n2h9 updated https://github.com/llvm/llvm-project/pull/163850

>From d637988bd2d4252fe5fe635a54b1fb4de17197d2 Mon Sep 17 00:00:00 2001
From: Nikita B 
Date: Thu, 16 Oct 2025 21:12:14 +0200
Subject: [PATCH 1/2] [CIR] vTableClassNameForType: return correct VTableClass
 name for Type::ObjCObjectPointer, Type::Pointer

Signed-off-by: Nikita B 
---
 clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp 
b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
index 1b85a530cbdd7..9494faa5ddfc7 100644
--- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
@@ -978,8 +978,7 @@ const char *vTableClassNameForType(const CIRGenModule &cgm, 
const Type *ty) {
 
   case Type::ObjCObjectPointer:
   case Type::Pointer:
-cgm.errorNYI("VTableClassNameForType: __pointer_type_info");
-break;
+return "_ZTVN10__cxxabiv119__pointer_type_infoE";
 
   case Type::MemberPointer:
 cgm.errorNYI("VTableClassNameForType: __pointer_to_member_type_info");

>From c08ef2e7db5e79f0bb7e5d761d256c4e970568ea Mon Sep 17 00:00:00 2001
From: Nikita B 
Date: Sat, 18 Oct 2025 13:15:23 +0200
Subject: [PATCH 2/2] [CIR] vTableClassNameForType: add throw test for
 Type::Pointer

Signed-off-by: Nikita B 
---
 clang/test/CIR/CodeGen/throws.cpp | 29 +
 1 file changed, 29 insertions(+)

diff --git a/clang/test/CIR/CodeGen/throws.cpp 
b/clang/test/CIR/CodeGen/throws.cpp
index 89cb0729c636c..6f2d136b4c6fd 100644
--- a/clang/test/CIR/CodeGen/throws.cpp
+++ b/clang/test/CIR/CodeGen/throws.cpp
@@ -196,3 +196,32 @@ void throw_ext_vector_type() {
 // OGCG: store <4 x i32> %[[TMP_A]], ptr %[[EXCEPTION_ADDR]], align 16
 // OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIDv4_i, ptr 
null)
 // OGCG: unreachable
+
+void throw_pointer_type() {
+  static int var = 42;
+  int *ptr = &var;
+  throw ptr;
+}
+
+// CIR: %[[PTR_ADDR:.*]] = cir.alloca !cir.ptr, 
!cir.ptr>, ["ptr", init]
+// CIR: %[[VAR_ADDR:.*]] = cir.get_global @_ZZ18throw_pointer_typevE3var : 
!cir.ptr
+// CIR: cir.store{{.*}} %[[VAR_ADDR]], %[[PTR_ADDR]] : !cir.ptr, 
!cir.ptr>
+// CIR: %[[EXCEPTION_ADDR:.*]] = cir.alloc.exception 8 -> 
!cir.ptr>
+// CIR: %[[TMP_PTR:.*]] = cir.load{{.*}} %[[PTR_ADDR]] : 
!cir.ptr>, !cir.ptr
+// CIR: cir.store{{.*}} %[[TMP_PTR]], %[[EXCEPTION_ADDR]] : !cir.ptr, 
!cir.ptr>
+// CIR: cir.throw %[[EXCEPTION_ADDR]] : !cir.ptr>, @_ZTIPi
+// CIR: cir.unreachable
+
+// LLVM: %[[PTR_ADDR:.*]] = alloca ptr,{{.*}} align 8
+// LLVM: store ptr @_ZZ18throw_pointer_typevE3var, ptr %[[PTR_ADDR]], align 8
+// LLVM: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 8)
+// LLVM: %[[TMP_PTR:.*]] = load ptr, ptr %[[PTR_ADDR]], align 8
+// LLVM: store ptr %[[TMP_PTR]], ptr %[[EXCEPTION_ADDR]], align 16
+// LLVM: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIPi, ptr null)
+
+// OGCG: %[[PTR_ADDR:.*]] = alloca ptr, align 8
+// OGCG: store ptr @_ZZ18throw_pointer_typevE3var, ptr %[[PTR_ADDR]], align 8
+// OGCG: %[[EXCEPTION_ADDR:.*]] = call ptr @__cxa_allocate_exception(i64 8)
+// OGCG: %[[TMP_PTR:.*]] = load ptr, ptr %[[PTR_ADDR]], align 8
+// OGCG: store ptr %[[TMP_PTR]], ptr %[[EXCEPTION_ADDR]], align 16
+// OGCG: call void @__cxa_throw(ptr %[[EXCEPTION_ADDR]], ptr @_ZTIPi, ptr null)

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


[clang] [Clang][HIP][CUDA] Add `__cluster_dims__` and `__no_cluster__` attribute (PR #156686)

2025-10-18 Thread Shilei Tian via cfe-commits


@@ -1572,6 +1572,23 @@ def HIPManaged : InheritableAttr {
   let Documentation = [HIPManagedAttrDocs];
 }
 
+def CUDAClusterDims : InheritableAttr {
+  let Spellings = [GNU<"cluster_dims">, Declspec<"cluster_dims">];

shiltian wrote:

I'm pretty sure we don't want them, at least at this moment. Now I'm even 
thinking whether we want to support the Microsoft spelling as well, since no 
matter on Windows or Linux, it is always a macro, as @Artem-B pointed out 
earlier. I'm gonna remove `Declspec` as well.

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


[clang] [lldb] [clang][Expr] Teach IgnoreUnlessSpelledInSource about implicit calls to std::get free function (PR #122265)

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

Michael137 wrote:

@mgorny Any chance you have access to the full IR when compiling it with the 
clang on that bot?

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


[clang] [CIR][NFC] Update existing atomic ops to match assembly conventions (PR #161543)

2025-10-18 Thread Sirui Mu via cfe-commits


@@ -4245,20 +4244,17 @@ def CIR_AtomicCmpXchg : CIR_Op<"atomic.cmpxchg", [
UnitAttr:$is_volatile);
 
   let assemblyFormat = [{
-`(`
-  $ptr `:` qualified(type($ptr)) `,`
-  $expected `:` type($expected) `,`
-  $desired `:` type($desired) `,`
-  `success` `=`  $succ_order `,`
-  `failure` `=`  $fail_order
-`)`
-(`align` `(` $alignment^ `)`)?
 (`weak` $weak^)?
+custom($succ_order, $fail_order)

Lancern wrote:

The intention here is to avoid showing the same memory order twice when 
`$succ_order` and `$fail_order` are the same.

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


[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-10-18 Thread via cfe-commits


@@ -0,0 +1,48 @@
+.. title:: clang-tidy - performance-lost-std-move
+
+performance-lost-std-move
+=
+
+Warns if copy constructor is used instead of ``std::move()`` and suggests a 
fix.
+It honours cycles, lambdas, and unspecified call order in compound expressions.
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ f(x);  // warning: Could be std::move() [performance-lost-std-move]
+   }
+
+It finds the last local variable usage, and if it is a copy, emits a warning.
+The check is based on pure AST matching and doesn't take into account any
+data flow information. Thus, it doesn't catch assign-after-copy cases.
+
+Also it does notice variable references "behind the scenes":
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ auto &y = x;
+ f(x);  // does not emit a warning
+ y.f();  // because x is still used via y
+   }
+
+If you want to ignore assigns to reference variables, set ::option::
+`StrictMode` to `true`.

EugeneZelenko wrote:

```suggestion
If you want to ignore assigns to reference variables, set :option:`StrictMode` 
to `true`.
```

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


[clang] [libcxx] [clang] [libc++] fix _Atomic c11 compare exchange does not update expected results (PR #78707)

2025-10-18 Thread via cfe-commits

https://github.com/huixie90 updated 
https://github.com/llvm/llvm-project/pull/78707

>From 0dc5bf91516e2138ed73b602cb17943ef6bcc878 Mon Sep 17 00:00:00 2001
From: Hui 
Date: Fri, 19 Jan 2024 12:33:43 +
Subject: [PATCH 1/6] [libc++] fix _Atomic c11 compare exchange does not update
 expected results

---
 clang/lib/CodeGen/CGAtomic.cpp | 61 +-
 1 file changed, 37 insertions(+), 24 deletions(-)

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 4a3446abcc78f..01d02c2dbed45 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -376,6 +376,7 @@ bool AtomicInfo::emitMemSetZeroIfNecessary() const {
 static void emitAtomicCmpXchg(CodeGenFunction &CGF, AtomicExpr *E, bool IsWeak,
   Address Dest, Address Ptr,
   Address Val1, Address Val2,
+  Address ExpectedResult,
   uint64_t Size,
   llvm::AtomicOrdering SuccessOrder,
   llvm::AtomicOrdering FailureOrder,
@@ -411,9 +412,17 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 
   CGF.Builder.SetInsertPoint(StoreExpectedBB);
   // Update the memory at Expected with Old's value.
-  auto *I = CGF.Builder.CreateStore(Old, Val1);
-  CGF.addInstToCurrentSourceAtom(I, Old);
 
+  llvm::Type *ExpectedType = ExpectedResult.getElementType();
+  uint64_t OriginalSizeInBits = 
CGF.CGM.getDataLayout().getTypeSizeInBits(ExpectedType);
+  if (OriginalSizeInBits / 8 == Size) {
+auto *I = CGF.Builder.CreateStore(Old, ExpectedResult);
+CGF.addInstToCurrentSourceAtom(I, Old);
+  } else {
+// How to just store N bytes to ExpectedResult ?
+auto *I = CGF.Builder.CreateStore(Old, ExpectedResult);
+CGF.addInstToCurrentSourceAtom(I, Old);
+  }
   // Finally, branch to the exit point.
   CGF.Builder.CreateBr(ContinueBB);
 
@@ -428,6 +437,7 @@ static void emitAtomicCmpXchg(CodeGenFunction &CGF, 
AtomicExpr *E, bool IsWeak,
 static void emitAtomicCmpXchgFailureSet(CodeGenFunction &CGF, AtomicExpr *E,
 bool IsWeak, Address Dest, Address Ptr,
 Address Val1, Address Val2,
+Address ExpectedResult,
 llvm::Value *FailureOrderVal,
 uint64_t Size,
 llvm::AtomicOrdering SuccessOrder,
@@ -458,7 +468,7 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 // success argument". This condition has been lifted and the only
 // precondition is 31.7.2.18. Effectively treat this as a DR and skip
 // language version checks.
-emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, 
SuccessOrder,
+emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
   FailureOrder, Scope);
 return;
   }
@@ -483,17 +493,17 @@ static void emitAtomicCmpXchgFailureSet(CodeGenFunction 
&CGF, AtomicExpr *E,
 
   // Emit all the different atomics
   CGF.Builder.SetInsertPoint(MonotonicBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult,
 Size, SuccessOrder, llvm::AtomicOrdering::Monotonic, 
Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(AcquireBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::Acquire, Scope);
   CGF.Builder.CreateBr(ContBB);
 
   CGF.Builder.SetInsertPoint(SeqCstBB);
-  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, Size, SuccessOrder,
+  emitAtomicCmpXchg(CGF, E, IsWeak, Dest, Ptr, Val1, Val2, ExpectedResult, 
Size, SuccessOrder,
 llvm::AtomicOrdering::SequentiallyConsistent, Scope);
   CGF.Builder.CreateBr(ContBB);
 
@@ -526,6 +536,7 @@ static llvm::Value *EmitPostAtomicMinMax(CGBuilderTy 
&Builder,
 
 static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr *E, Address Dest,
  Address Ptr, Address Val1, Address Val2,
+ Address ExpectedResult,
  llvm::Value *IsWeak, llvm::Value *FailureOrder,
  uint64_t Size, llvm::AtomicOrdering Order,
  llvm::SyncScope::ID Scope) {
@@ -542,13 +553,13 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
   case AtomicExpr::AO__hip_atomic_compare_exchange_strong:
   case AtomicExpr::AO__opencl_atomic_compare_exchange_strong:
 emitAtomicCmpXchgFailureSet(CGF, E, false, Dest, Ptr, Val1, Val2,
-FailureO

[clang] [Clang][Driver] New parameter allow-unrecognized-arguments (PR #162201)

2025-10-18 Thread Danny McClanahan via cfe-commits

cosmicexplorer wrote:

Referring to command-line flags which clearly specify the standards documents 
they're referring to in the flag itself as "gcc-specific arguments" seems 
disingenuous and unprofessional. The reference to [Kitware's 
proposal](https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2022/p1689r5.html)
 is the first result from google. The [kitware 
issue](https://gitlab.kitware.com/cmake/cmake/-/issues/26283) clearly describes 
how to turn these off in the cmake file:

> `set(CMAKE_CXX_SCAN_FOR_MODULES OFF)`

> If we give the user the ability to run clang-based tools without any changes 
> on they're project would, in my opinion, greatly simplify the integration of 
> those tools in existing projects.

As I understand it, modules are a pretty fundamental change to the way C++ 
dependencies work. The [`clang-tidy` 
docs](https://clang.llvm.org/extra/clang-tidy/) state that:

> Clang compiler errors (such as syntax errors, semantic errors, or other 
> failures that prevent Clang from compiling the code) are reported with the 
> check name clang-diagnostic-error. These represent fundamental compilation 
> failures that must be fixed before clang-tidy can perform its analysis. 
> Unlike other diagnostics, clang-diagnostic-error cannot be disabled, as 
> clang-tidy requires valid code to function.

I also see that `clang-tidy` has its own preferred flags for module support 
which do not implement any proposed standard:

```
  --enable-module-headers-parsing  - Enables preprocessor-level module header 
parsing
 for C++20 and above, empowering specific 
checks
 to detect macro definitions within 
modules. This
 feature may cause performance and parsing 
issues
 and is therefore considered experimental.
```

I also see that my locally installed copy of `clang` (version 20.1.8) already 
supports the exact same functionality, with very slightly misspelled names:

```
  -fmodule-map-file=
  Load this module map file
  -fmodules   Enable the 'modules' language feature
```

The linked issue regarding cmake describes these three arguments as problematic:
```
error: unknown argument: '-fdeps-format=p1689r5' [clang-diagnostic-error]
error: unknown argument: 
'-fmodule-mapper=my_exe/test/CMakeFiles/my_exe_lib_tests.dir/Debug/tests.cpp.o.modmap'
 [clang-diagnostic-error]
error: unknown argument: '-fmodules-ts' [clang-diagnostic-error]
```

The proposed methodology to directly ignore these inputs seems tantamount to a 
rejection of the proposals for interoperable module support across build 
systems.

> The main use case I see for this option would be to give the user the ability 
> to run clang-tidy, clangd (or any clang-based tool as a matter of fact) on a 
> gcc project and to get some decents results without having to maintain two 
> separate build commands or to write some convoluted script to transform the 
> gcc-based command line into something that clang will not complain about.

Given that modules are a standard API, and that clang already supports 
precisely the functionality needed, it's unclear why this is being described as 
"gcc-based". Is there context that's not being stated here?

> the "Unrecognized argument" is probably one of the only thing keeping them 
> from doing that.

Given that my laptop's clang++ version supports very similar command-line 
arguments already, I'm curious why clang-tidy wouldn't be able to make use of 
that support from clang. Is there some deeper issue that stops clang-tidy from 
being able to support C++20 modules, or from using the code in clang that 
processes module dependencies?

Much like the make jobserver protocol that ninja and cargo now implement, gcc 
describes a very explicit effort of at least 5 years to get external buy-in for 
the exact functionality that is being described as "gcc-based" here 
(https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Module-Mapper.html):

> The mapper protocol was published as “A Module Mapper” 
> https://wg21.link/p1184. The implementation is provided by libcody, 
> https://github.com/urnathan/libcody, which specifies the canonical protocol 
> definition. A proof of concept server implementation embedded in make was 
> described in ”Make Me A Module”, https://wg21.link/p1602.

Removing arguments which define dependency relationships from the command line, 
based upon internal filtering logic that's defined in the specific version of 
clang-tidy's compiled C++ code and not in the build system, strikes me as a 
decision which could incur later user requests for an additional flag to cancel 
out the first flag filtering functionality, if the user ever figures out their 
dependency issue was because of this filtering logic in the first place.

In particular, many build systems such as bazel will cache process executions 
based upon the command-line a

[clang] [Clang] Add diagnostic for why std::is_abstract is false (PR #156199)

2025-10-18 Thread Sebastian Proell via cfe-commits

sebproell wrote:

@shafik @erichkeane Thank you for reviewing.

> Can we add a more detailed summary, at least outlines the various cases you 
> seek to cover e.g. ref, array, union etc

@shafik I hope I understood this correctly and updated the PR description.



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


[clang] [OpenMP][docs] Update OpenMP 6.0 OMP_AVAILABLE_DEVICES status (PR #162440)

2025-10-18 Thread Michael Klemm via cfe-commits

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


[clang] [CIR] Upstream DynamicCastOp (PR #161734)

2025-10-18 Thread Henrich Lauko via cfe-commits


@@ -601,6 +601,60 @@ def CIR_VTableAttr : CIR_Attr<"VTable", "vtable", 
[TypedAttrInterface]> {
   }];
 }
 
+//===--===//
+// DynamicCastInfoAttr
+//===--===//
+
+def CIR_DynamicCastInfoAttr : CIR_Attr<"DynamicCastInfo", "dyn_cast_info"> {
+  let summary = "ABI specific information about a dynamic cast";
+  let description = [{
+Provide ABI specific information about a dynamic cast operation.
+
+The `srcRtti` and the `destRtti` parameters give the RTTI of the source
+record type and the destination record type, respectively.
+
+The `runtimeFunc` parameter gives the `__dynamic_cast` function which is
+provided by the runtime. The `badCastFunc` parameter gives the
+`__cxa_bad_cast` function which is also provided by the runtime.
+
+The `offsetHint` parameter gives the hint value that should be passed to 
the
+`__dynamic_cast` runtime function.
+  }];
+
+  let parameters = (ins
+CIR_GlobalViewAttr:$srcRtti,
+CIR_GlobalViewAttr:$destRtti,
+"mlir::FlatSymbolRefAttr":$runtimeFunc,
+"mlir::FlatSymbolRefAttr":$badCastFunc,
+CIR_IntAttr:$offsetHint
+  );
+
+  let builders = [
+AttrBuilderWithInferredContext<(ins "GlobalViewAttr":$srcRtti,
+"GlobalViewAttr":$destRtti,
+"mlir::FlatSymbolRefAttr":$runtimeFunc,
+"mlir::FlatSymbolRefAttr":$badCastFunc,
+"IntAttr":$offsetHint), [{
+  return $_get(srcRtti.getContext(), srcRtti, destRtti, runtimeFunc,
+   badCastFunc, offsetHint);
+}]>,
+  ];
+
+  let genVerifyDecl = 1;
+  let assemblyFormat = [{
+`<`
+  `srcRtti` `=` qualified($srcRtti) `,` `destRtti` `=` qualified($destRtti)
+  `,` `runtimeFunc` `=` $runtimeFunc `,` `badCastFunc` `=` $badCastFunc `,`
+  `offsetHint` `=` qualified($offsetHint)
+`>`

xlauko wrote:

Maybe `struct(qualified($srcRtti), qualified($destRtti), $runtimeFunc, 
$badCastFunc, qualified($offsetHint))` will work to preserve the names, but I 
have not found any example of this in upstream. 

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


[clang] [clang][bytecode] interp__builtin_ia32_pshuf - modulo lane index to allow reuse of PSHUFD/LW/HW mask decode. NFC (PR #162006)

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

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


[clang] [SPIRV][HLSL] Add Sema and CodeGen for implicit typed buffer counters (PR #162291)

2025-10-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Steven Perron (s-perron)


Changes

This commit implements the Sema and CodeGen portions of the typed buffer
counter proposal described in the HLSL WG proposal 0023.

This change introduces the necessary Sema and CodeGen logic to handle
implicit counter variables for typed buffers. This includes:

- Extending `HLSLResourceBindingAttr` to store the implicit counter
  binding order ID.
- Introducing the `__builtin_hlsl_resource_counterhandlefromimplicitbinding`
  builtin.
- Updating `SemaHLSL` to correctly initialize global resource declarations
  and resource arrays with implicit counter buffers.
- Adding CodeGen support for the new builtin, which generates a
  `llvm.spv.resource.counterhandlefromimplicitbinding` intrinsic for the
  SPIR-V target and aliases the main resource handle for the DXIL target.
- Adding and updating tests to verify the new functionality.

Fixes #137032



---

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


14 Files Affected:

- (modified) clang/include/clang/AST/HLSLResource.h (+13) 
- (modified) clang/include/clang/Basic/Attr.td (+12) 
- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/lib/CodeGen/CGHLSLBuiltins.cpp (+13) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+18-3) 
- (modified) clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp (+107-5) 
- (modified) clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h (+5-2) 
- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+91-22) 
- (modified) clang/test/AST/HLSL/StructuredBuffers-AST.hlsl (+129-55) 
- (modified) clang/test/AST/HLSL/vk_binding_attr.hlsl (+5-5) 
- (modified) 
clang/test/CodeGenHLSL/resources/StructuredBuffers-constructors.hlsl (+35-32) 
- (added) clang/test/CodeGenHLSL/resources/res-array-rw-counter.hlsl (+26) 
- (modified) clang/test/CodeGenHLSL/vk_binding_attr.hlsl (+1-1) 


``diff
diff --git a/clang/include/clang/AST/HLSLResource.h 
b/clang/include/clang/AST/HLSLResource.h
index 7440050c7b2b9..1be1e422f5f12 100644
--- a/clang/include/clang/AST/HLSLResource.h
+++ b/clang/include/clang/AST/HLSLResource.h
@@ -74,6 +74,19 @@ struct ResourceBindingAttrs {
 assert(hasBinding() && !isExplicit() && !hasImplicitOrderID());
 RegBinding->setImplicitBindingOrderID(Value);
   }
+  void setCounterImplicitOrderID(unsigned Value) const {
+assert(hasBinding() && !hasCounterImplicitOrderID());
+RegBinding->setImplicitCounterBindingOrderID(Value);
+  }
+
+  bool hasCounterImplicitOrderID() const {
+return RegBinding && RegBinding->hasImplicitCounterBindingOrderID();
+  }
+
+  unsigned getCounterImplicitOrderID() const {
+assert(hasCounterImplicitOrderID());
+return RegBinding->getImplicitCounterBindingOrderID();
+  }
 };
 
 } // namespace hlsl
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 3c697ed8dd882..3cde249e286fa 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4944,6 +4944,7 @@ def HLSLResourceBinding: InheritableAttr {
   std::optional SlotNumber;
   unsigned SpaceNumber;
   std::optional ImplicitBindingOrderID;
+  std::optional ImplicitCounterBindingOrderID;
 
   public:
   void setBinding(RegisterType RT, std::optional SlotNum, 
unsigned SpaceNum) {
@@ -4976,6 +4977,17 @@ def HLSLResourceBinding: InheritableAttr {
 assert(hasImplicitBindingOrderID() && "attribute does not have 
implicit binding order id");
 return ImplicitBindingOrderID.value();
   }
+  void setImplicitCounterBindingOrderID(uint32_t Value) {
+assert(!hasImplicitCounterBindingOrderID() && "attribute already has 
implicit counter binding order id");
+ImplicitCounterBindingOrderID = Value;
+  }
+  bool hasImplicitCounterBindingOrderID() const {
+return ImplicitCounterBindingOrderID.has_value();
+  }
+  uint32_t getImplicitCounterBindingOrderID() const {
+assert(hasImplicitCounterBindingOrderID() && "attribute does not have 
implicit counter binding order id");
+return ImplicitCounterBindingOrderID.value();
+  }
   }];
 }
 
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 468121f7d20ab..792e2e07ec594 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4945,6 +4945,12 @@ def HLSLResourceHandleFromImplicitBinding : 
LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLResourceCounterHandleFromImplicitBinding : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_resource_counterhandlefromimplicitbinding"];
+  let Attributes = [NoThrow, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 def HLSLResourceNonUniformIndex : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_resource_nonuniformindex"]

[clang] [HLSL][NFC] Add helper struct to simplify dealing with resource binding attributes (PR #161254)

2025-10-18 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 h,cpp -- 
clang/include/clang/AST/HLSLResource.h clang/lib/CodeGen/CGHLSLRuntime.cpp 
clang/lib/CodeGen/CGHLSLRuntime.h clang/lib/Sema/SemaHLSL.cpp
``

: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/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index ebe6d6058..ede178059 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -21,8 +21,8 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attrs.inc"
 #include "clang/AST/Decl.h"
-#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/HLSLResource.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
@@ -234,8 +234,7 @@ static std::optional 
initializeLocalResourceArray(
 
 CallArgList Args;
 CXXMethodDecl *CreateMethod = lookupResourceInitMethodAndSetupArgs(
-CGF.CGM, ResourceDecl, Range, Index, ResourceName, Binding,
-Args);
+CGF.CGM, ResourceDecl, Range, Index, ResourceName, Binding, Args);
 
 if (!CreateMethod)
   // This can happen if someone creates an array of structs that looks like

``




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


[libclc] [libclc] Replace float remquo with Intel IMF version (PR #162643)

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

https://github.com/wenju-he updated 
https://github.com/llvm/llvm-project/pull/162643

>From 4574b973070d237c88f8a951e9a3c0fc9afcaeaf Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Thu, 9 Oct 2025 14:19:17 +0200
Subject: [PATCH 1/3] [libclc] Replace float remquo with Intel IMF version

Current implementation has two issues:
- unconditionally soft flushes denormal.
- can't pass OpenCL CTS test "test_bruteforce remquo" on intel gpu.

This PR upstreams remquo implementation from Intel Math Functions (IMF)
Device Library. It supports denormal and can pass OpenCL CTS test.
---
 libclc/clc/lib/generic/math/clc_remquo.cl  |   1 +
 libclc/clc/lib/generic/math/clc_remquo.inc | 308 +
 2 files changed, 248 insertions(+), 61 deletions(-)

diff --git a/libclc/clc/lib/generic/math/clc_remquo.cl 
b/libclc/clc/lib/generic/math/clc_remquo.cl
index fd83ead06d89a..4039d39e17c65 100644
--- a/libclc/clc/lib/generic/math/clc_remquo.cl
+++ b/libclc/clc/lib/generic/math/clc_remquo.cl
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/libclc/clc/lib/generic/math/clc_remquo.inc 
b/libclc/clc/lib/generic/math/clc_remquo.inc
index 3a76ffed7f039..d248e770b7560 100644
--- a/libclc/clc/lib/generic/math/clc_remquo.inc
+++ b/libclc/clc/lib/generic/math/clc_remquo.inc
@@ -6,71 +6,257 @@
 //
 
//===--===//
 
+#define _sHighMask 0xf000u
+#define _iMaxQExp 0xbu
+// To prevent YLow to be denormal it should be checked
+// that Exp(Y) <= -127+23 (worst case when only last bit is non zero)
+//  Exp(Y) < -103 -> Y < 0x0C00
+// That value is used to construct _iYSub by setting up first bit to 1.
+// _iYCmp is get from max acceptable value 0x797f:
+//   0x797f - 0x8C00 = 0x(1)ED7F
+#define _iYSub 0x8C00u
+#define _iYCmp 0xED7Fu
+#define _iOne 0x0001u
+
+static _CLC_INLINE _CLC_OVERLOAD int
+internal_remquo(float x, float y, float *r, __CLC_ADDRESS_SPACE uint *q) {
+  uint signif_x, signif_y, rem_bit, quo_bit, tmp_x, tmp_y;
+  int exp_x, exp_y, i, j;
+  uint expabs_diff, special_op = 0, signbit_x, signbit_y, sign = 1;
+  float result, abs_x, abs_y;
+  float zero = 0.0f;
+  int nRet = 0;
+  // Remove sign bits
+  tmp_x = ((*(int *)&x)) & EXSIGNBIT_SP32;
+  tmp_y = ((*(int *)&y)) & EXSIGNBIT_SP32;
+  signbit_x = (uint)((*(int *)&x) >> 31);
+  signbit_y = (uint)((*(int *)&y) >> 31);
+  if (signbit_x ^ signbit_y)
+sign = (-sign);
+  // Get float absolute values
+  abs_x = *(float *)&tmp_x;
+  abs_y = *(float *)&tmp_y;
+  // Remove exponent bias
+  exp_x = (int)((tmp_x & (0x7FF0L)) >> 23) - 127;
+  exp_y = (int)((tmp_y & (0x7FF0L)) >> 23) - 127;
+  // Test for NaNs, Infs, and Zeros
+  if ((exp_x == (0x0080L)) || (exp_y == (0x0080L)) ||
+  (tmp_x == (0xL)) || (tmp_y == (0xL)))
+special_op++;
+  // Get significands
+  signif_x = (tmp_x & (0x007FL));
+  signif_y = (tmp_y & (0x007FL));
+  // Process NaNs, Infs, and Zeros
+  if (special_op) {
+(*q) = 0;
+// x is NaN
+if ((signif_x != (0xL)) && (exp_x == (0x0080L)))
+  result = x * 1.7f;
+// y is NaN
+else if ((signif_y != (0xL)) && (exp_y == (0x0080L)))
+  result = y * 1.7f;
+// y is zero
+else if (abs_y == zero) {
+  result = zero / zero;
+  nRet = 1;
+}
+// x is zero
+else if (abs_x == zero)
+  result = x;
+// x is Inf
+else if ((signif_x == (0xL)) && (exp_x == (0x0080L)))
+  result = zero / zero;
+// y is Inf
+else
+  result = x;
+(*r) = (result);
+return nRet;
+  }
+  // If x < y, fast return
+  if (abs_x <= abs_y) {
+(*q) = 1 * sign;
+if (abs_x == abs_y) {
+  (*r) = (zero * x);
+  return nRet;
+}
+// Is x too big to scale up by 2.0f?
+if (exp_x != 127) {
+  if ((2.0f * abs_x) <= abs_y) {
+(*q) = 0;
+(*r) = x;
+return nRet;
+  }
+}
+result = abs_x - abs_y;
+if (signbit_x) {
+  result = -result;
+}
+(*r) = (result);
+return nRet;
+  }
+  // Check for denormal x and y, adjust and normalize
+  if ((exp_x == -127) && (signif_x != (0xL))) {
+exp_x = -126;
+while (signif_x <= (0x007FL)) {
+  exp_x--;
+  signif_x <<= 1;
+};
+  } else
+signif_x = (signif_x | (0x0080L));
+  if ((exp_y == -127) && (signif_y != (0xL))) {
+exp_y = -126;
+while (signif_y <= (0x007FL)) {
+  exp_y--;
+  signif_y <<= 1;
+};
+  } else
+signif_y = (signif_y | (0x0080L));
+  //
+  // Main computational path
+  //
+  // Calculate exponent difference
+  expabs_diff = (exp_x - exp_y) + 1;
+  rem_bit = signif_x;
+  quo_bit = 0;
+  for (i = 0; i < expabs_diff; i++) {
+quo_bit = quo_bit << 1;
+if (rem_bit >= signif_y) {
+  rem_bit -= signif_y;
+  quo_bit++;
+}
+rem_bit <<= 1;
+  }
+  // Zero remquo .

[clang] [LLVM] [Clang] Fix clang to emit llvm-ir for fadd/fsub atomics (PR #162679)

2025-10-18 Thread Amina Chabane via cfe-commits

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


  1   2   3   4   5   6   7   8   9   10   >