[clang] [alpha.webkit.ForwardDeclChecker] Ignore forward declared struct. (PR #133804)

2025-04-04 Thread Ryosuke Niwa via cfe-commits

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


[clang] 6c8e9a6 - [clang][bytecode][NFC] Add assert to ptrauth_string_discriminator (#132527)

2025-04-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-22T08:05:28+01:00
New Revision: 6c8e9a6192a812237415d7d03d5ae234bc244c97

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

LOG: [clang][bytecode][NFC] Add assert to ptrauth_string_discriminator (#132527)

As pointed out by @shafik, this confuses static analysis and most
probably humans as well. Add an assertion to ensure the given array has
at least one element.

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltin.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 57037b674feba..a6e1884404287 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1477,6 +1477,9 @@ static bool interp__builtin_ptrauth_string_discriminator(
   const auto &Ptr = S.Stk.peek();
   assert(Ptr.getFieldDesc()->isPrimitiveArray());
 
+  // This should be created for a StringLiteral, so should alway shold at least
+  // one array element.
+  assert(Ptr.getFieldDesc()->getNumElems() >= 1);
   StringRef R(&Ptr.deref(), Ptr.getFieldDesc()->getNumElems() - 1);
   uint64_t Result = getPointerAuthStableSipHash(R);
   pushInteger(S, Result, Call->getType());



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


[clang] [RFC][clang] Fix for regression #130917 (PR #132214)

2025-04-04 Thread Matheus Izvekov via cfe-commits


@@ -2572,7 +2572,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
   // Friend function defined withing class template may stop being function
   // definition during AST merges from different modules, in this case decl
   // with function body should be used for instantiation.
-  if (isFriend) {
+  if (isFriend && D->hasOwningModule()) {

mizvekov wrote:

Clang AST is open to modifications.

Can't you add a new bit to `Redeclarable` to keep track of this?

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


[clang] [llvm] [fatlto] Use the ThinLTO default pipeline for FatLTO (PR #134434)

2025-04-04 Thread Paul Kirth via cfe-commits

ilovepi wrote:

cc: @mcatanzaro

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


[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-04-04 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor updated 
https://github.com/llvm/llvm-project/pull/132468

>From 6e84a91e4721d066ff3b79d5cb3535ac92f05af1 Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Fri, 21 Mar 2025 13:11:11 -0700
Subject: [PATCH 1/4] [CIR] Emit allocas into the proper lexical scope

Alloca operations were being emitted into the entry block of the current
function unconditionally, even if the variable they represented was
declared in a different scope. This change upstreams the code for handling
insertion of the alloca into the proper lexcial scope. It also adds a
CIR-to-CIR transformation to hoist allocas to the function entry block,
which is necessary to produce the expected LLVM IR during lowering.
---
 clang/include/clang/CIR/Dialect/Passes.h  |   1 +
 clang/include/clang/CIR/Dialect/Passes.td |  10 ++
 clang/include/clang/CIR/MissingFeatures.h |   3 +
 clang/lib/CIR/CodeGen/CIRGenDecl.cpp  |   3 +-
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  37 --
 clang/lib/CIR/CodeGen/CIRGenFunction.cpp  |   6 +-
 clang/lib/CIR/CodeGen/CIRGenFunction.h|  10 +-
 .../lib/CIR/Dialect/Transforms/CMakeLists.txt |   1 +
 .../CIR/Dialect/Transforms/HoistAllocas.cpp   |  81 +
 clang/lib/CIR/Lowering/CIRPasses.cpp  |   1 +
 clang/test/CIR/CodeGen/loop.cpp   |  97 +++
 clang/test/CIR/Transforms/hoist-allocas.cir   | 113 ++
 clang/tools/cir-opt/cir-opt.cpp   |   4 +
 13 files changed, 353 insertions(+), 14 deletions(-)
 create mode 100644 clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp
 create mode 100644 clang/test/CIR/Transforms/hoist-allocas.cir

diff --git a/clang/include/clang/CIR/Dialect/Passes.h 
b/clang/include/clang/CIR/Dialect/Passes.h
index aa84241bdecf0..133eb462dcf1f 100644
--- a/clang/include/clang/CIR/Dialect/Passes.h
+++ b/clang/include/clang/CIR/Dialect/Passes.h
@@ -22,6 +22,7 @@ namespace mlir {
 
 std::unique_ptr createCIRCanonicalizePass();
 std::unique_ptr createCIRFlattenCFGPass();
+std::unique_ptr createHoistAllocasPass();
 
 void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
 
diff --git a/clang/include/clang/CIR/Dialect/Passes.td 
b/clang/include/clang/CIR/Dialect/Passes.td
index 16133d020a7c8..74c255861c879 100644
--- a/clang/include/clang/CIR/Dialect/Passes.td
+++ b/clang/include/clang/CIR/Dialect/Passes.td
@@ -29,6 +29,16 @@ def CIRCanonicalize : Pass<"cir-canonicalize"> {
   let dependentDialects = ["cir::CIRDialect"];
 }
 
+def HoistAllocas : Pass<"cir-hoist-allocas"> {
+  let summary = "Hoist allocas to the entry of the function";
+  let description = [{
+This pass hoist all non-dynamic allocas to the entry of the function.
+This is helpful for later code generation.
+  }];
+  let constructor = "mlir::createHoistAllocasPass()";
+  let dependentDialects = ["cir::CIRDialect"];
+}
+
 def CIRFlattenCFG : Pass<"cir-flatten-cfg"> {
   let summary = "Produces flatten CFG";
   let description = [{
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 3e33e5dc60194..3f2e56a43fbef 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -127,6 +127,9 @@ struct MissingFeatures {
   static bool ternaryOp() { return false; }
   static bool tryOp() { return false; }
   static bool zextOp() { return false; }
+
+  // Future CIR attributes
+  static bool optInfoAttr() { return false; }
 };
 
 } // namespace cir
diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp 
b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
index a93e8dbcb42de..f2153c23ebb43 100644
--- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
@@ -49,7 +49,8 @@ CIRGenFunction::emitAutoVarAlloca(const VarDecl &d) {
   // A normal fixed sized variable becomes an alloca in the entry block,
   mlir::Type allocaTy = convertTypeForMem(ty);
   // Create the temp alloca and declare variable using it.
-  address = createTempAlloca(allocaTy, alignment, loc, d.getName());
+  address = createTempAlloca(allocaTy, alignment, loc, d.getName(),
+ /*insertIntoFnEntryBlock=*/false);
   declare(address.getPointer(), &d, ty, getLoc(d.getSourceRange()), alignment);
 
   emission.Addr = address;
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 306130b80d457..d16480143c47e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -261,10 +261,27 @@ void CIRGenFunction::emitIgnoredExpr(const Expr *e) {
 }
 
 mlir::Value CIRGenFunction::emitAlloca(StringRef name, mlir::Type ty,
-   mlir::Location loc,
-   CharUnits alignment) {
-  mlir::Block *entryBlock = getCurFunctionEntryBlock();
+   mlir::Location loc, CharUnits alignment,
+   bool insertIntoFnEntryBlock,
+

[libclc] [libclc] Move lgamma, lgamma_r & tgamma to CLC library (PR #134053)

2025-04-04 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/134053

>From 81675d67f9f182966b86ab630eaa05afe0dc9129 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 2 Apr 2025 09:48:43 +0100
Subject: [PATCH 1/2] [libclc] Move lgamma, lgamma_r & tgamma to CLC library

Also enable half-precision variants of tgamma, which were previously
missing.

Note that unlike recent work, these builtins are not vectorized as part
of this commit. Ultimately all three call into lgamma_r, which has
heavy control flow (including switch statements) that would be difficult
to vectorize. Additionally the lgamma_r algorithm is copyrighted to
SunPro so may need a rewrite in the future anyway.

There are no codegen changes (to non-SPIR-V targets) with this commit,
aside from the new half builtins.
---
 .../include/clc/math/clc_lgamma.h}|  15 +-
 libclc/clc/include/clc/math/clc_lgamma_r.h|  20 +
 libclc/clc/include/clc/math/clc_tgamma.h  |  20 +
 .../include/clc/math/unary_def_via_fp32.inc}  |   7 +-
 libclc/clc/lib/generic/SOURCES|   3 +
 libclc/clc/lib/generic/math/clc_lgamma.cl |  13 +
 libclc/clc/lib/generic/math/clc_lgamma.inc|  12 +
 libclc/clc/lib/generic/math/clc_lgamma_r.cl   | 611 ++
 libclc/clc/lib/generic/math/clc_lgamma_r.inc  |  15 +
 libclc/clc/lib/generic/math/clc_tgamma.cl |  73 +++
 libclc/generic/include/clc/math/lgamma_r.h|   7 +-
 libclc/generic/lib/math/lgamma.cl |  31 +-
 libclc/generic/lib/math/lgamma_r.cl   | 485 +-
 libclc/generic/lib/math/tgamma.cl |  49 +-
 14 files changed, 798 insertions(+), 563 deletions(-)
 rename libclc/{generic/include/clc/math/lgamma_r.inc => 
clc/include/clc/math/clc_lgamma.h} (57%)
 create mode 100644 libclc/clc/include/clc/math/clc_lgamma_r.h
 create mode 100644 libclc/clc/include/clc/math/clc_tgamma.h
 rename libclc/{generic/lib/math/lgamma_r.inc => 
clc/include/clc/math/unary_def_via_fp32.inc} (62%)
 create mode 100644 libclc/clc/lib/generic/math/clc_lgamma.cl
 create mode 100644 libclc/clc/lib/generic/math/clc_lgamma.inc
 create mode 100644 libclc/clc/lib/generic/math/clc_lgamma_r.cl
 create mode 100644 libclc/clc/lib/generic/math/clc_lgamma_r.inc
 create mode 100644 libclc/clc/lib/generic/math/clc_tgamma.cl

diff --git a/libclc/generic/include/clc/math/lgamma_r.inc 
b/libclc/clc/include/clc/math/clc_lgamma.h
similarity index 57%
rename from libclc/generic/include/clc/math/lgamma_r.inc
rename to libclc/clc/include/clc/math/clc_lgamma.h
index 0f78c0e686386..7e516c1f08793 100644
--- a/libclc/generic/include/clc/math/lgamma_r.inc
+++ b/libclc/clc/include/clc/math/clc_lgamma.h
@@ -6,6 +6,15 @@
 //
 
//===--===//
 
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, global 
__CLC_INTN *iptr);
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, local 
__CLC_INTN *iptr);
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE lgamma_r(__CLC_GENTYPE x, private 
__CLC_INTN *iptr);
+#ifndef __CLC_MATH_CLC_LGAMMA_H__
+#define __CLC_MATH_CLC_LGAMMA_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_lgamma
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_LGAMMA_H__
diff --git a/libclc/clc/include/clc/math/clc_lgamma_r.h 
b/libclc/clc/include/clc/math/clc_lgamma_r.h
new file mode 100644
index 0..5db55a13b4d82
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_lgamma_r.h
@@ -0,0 +1,20 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef __CLC_MATH_CLC_LGAMMA_R_H__
+#define __CLC_MATH_CLC_LGAMMA_R_H__
+
+#define __CLC_FUNCTION __clc_lgamma_r
+#define __CLC_BODY 
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_LGAMMA_R_H__
diff --git a/libclc/clc/include/clc/math/clc_tgamma.h 
b/libclc/clc/include/clc/math/clc_tgamma.h
new file mode 100644
index 0..c4e5714616fae
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_tgamma.h
@@ -0,0 +1,20 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef __CLC_MATH_CLC_TGAMMA_H__
+#define __CLC_MATH_CLC_TGAMMA_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_tgamma
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_TGAMMA_H__
diff --git

[clang] [llvm] [llvm][clang] Allocate a new stack instead of spawning a new thread to get more stack space (PR #133173)

2025-04-04 Thread Reid Kleckner via cfe-commits


@@ -0,0 +1,115 @@
+//===--- RunOnNewStack.cpp - Crash Recovery 
---===//
+//
+// 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 "llvm/Support/ProgramStack.h"
+#include "llvm/Config/config.h"
+#include "llvm/Support/Compiler.h"
+
+#ifdef HAVE_SYS_RESOURCE_H
+# include 
+#endif
+
+#ifdef _MSC_VER
+# include   // for _AddressOfReturnAddress
+#endif
+
+// Currently only Apple AArch64 is known to support split stacks in the 
debugger
+// and other tooling.
+#if defined(__APPLE__) && defined(__aarch64__) &&  
\
+LLVM_HAS_CPP_ATTRIBUTE(gnu::naked) && __has_extension(gnu_asm)
+# define LLVM_HAS_SPLIT_STACKS
+# define LLVM_HAS_SPLIT_STACKS_AARCH64
+#include 
+#endif
+
+#ifndef LLVM_HAS_SPLIT_STACKS
+# include "llvm/Support/thread.h"
+#endif
+
+using namespace llvm;
+
+uintptr_t llvm::getStackPointer() {
+#if __GNUC__ || __has_builtin(__builtin_frame_address)
+  return (uintptr_t)__builtin_frame_address(0);
+#elif defined(_MSC_VER)
+  return (uintptr_t)_AddressOfReturnAddress();
+#else
+  char CharOnStack = 0;

rnk wrote:

This `#else` case breaks down in situations where the compiler moves all the 
user data out to the heap, like with Seperate Data And Control Stacks (SCADS) 
or ASan use-after-return detection mode. I think we probably don't care, since 
those will be handled above.

I guess I don't have any actionable suggestions, other than to make the 
character variable itself volatile. It seems to me like it would be 
semantics-preserving for a compiler to promote CharOnStack into a global 
constant 0, for example, since we never write through the pointer that we store 
into a volatile local.

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


[clang] Improve diagnostic wording for invalid callback attribute uses (PR #134423)

2025-04-04 Thread Aaron Ballman via cfe-commits

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


[clang] a2d983c - Improve diagnostic wording for invalid callback attribute uses (#134423)

2025-04-04 Thread via cfe-commits

Author: Aaron Ballman
Date: 2025-04-04T15:01:36-04:00
New Revision: a2d983cffba87f9f35ededf7a2d6515d3698216e

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

LOG: Improve diagnostic wording for invalid callback attribute uses (#134423)

We were previously telling the user how many arguments were passed to
the attribute rather than saying how many arguments were expected to be
passed to the callback function. This rewords the diagnostic to
hopefully be a bit more clear.

Fixes #47451

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Sema/attr-callback-broken.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 77252e3a98235..5217e04b5e83f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -367,6 +367,10 @@ Bug Fixes to Attribute Support
   or ``__attribute__((malloc(deallocator, ptr-index)))``
   (`#51607 `_).
 
+- Corrected the diagnostic for the ``callback`` attribute when passing too many
+  or too few attribute argument indicies for the specified callback function.
+  (#GH47451)
+
 Bug Fixes to C++ Support
 
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 52dc477039129..dc98ceadd23ca 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3195,6 +3195,10 @@ def err_attribute_wrong_number_arguments : Error<
 def err_attribute_wrong_number_arguments_for : Error <
   "%0 attribute references function %1, which %plural{0:takes no 
arguments|1:takes one argument|"
   ":takes exactly %2 arguments}2">;
+def err_callback_attribute_wrong_arg_count : Error<
+  "'callback' attribute references function of type %0 which expects %1 "
+  "%plural{1:argument|:arguments}1 but attribute specifies %2 parameter index "
+  "%plural{1:argument|:arguments}2">;
 def err_attribute_bounds_for_function : Error<
   "%0 attribute references parameter %1, but the function %2 has only %3 
parameters">;
 def err_attribute_no_member_function : Error<

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 0b844b44930b9..d76afe9d6464d 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -4145,15 +4145,10 @@ static void handleCallbackAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
 return;
   }
 
-  if (CalleeFnProtoType->getNumParams() > EncodingIndices.size() - 1) {
-S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
-<< AL << (unsigned)(EncodingIndices.size() - 1);
-return;
-  }
-
-  if (CalleeFnProtoType->getNumParams() < EncodingIndices.size() - 1) {
-S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
-<< AL << (unsigned)(EncodingIndices.size() - 1);
+  if (CalleeFnProtoType->getNumParams() != EncodingIndices.size() - 1) {
+S.Diag(AL.getLoc(), diag::err_callback_attribute_wrong_arg_count)
+<< QualType{CalleeFnProtoType, 0} << CalleeFnProtoType->getNumParams()
+<< (unsigned)(EncodingIndices.size() - 1);
 return;
   }
 

diff  --git a/clang/test/Sema/attr-callback-broken.c 
b/clang/test/Sema/attr-callback-broken.c
index b9e5f45f405ef..ec6ec04ae0e67 100644
--- a/clang/test/Sema/attr-callback-broken.c
+++ b/clang/test/Sema/attr-callback-broken.c
@@ -2,13 +2,13 @@
 
 __attribute__((callback())) void no_callee(void (*callback)(void)); // 
expected-error {{'callback' attribute specifies no callback callee}}
 
-__attribute__((callback(1, 1))) void too_many_args_1(void (*callback)(void)) 
{}  // expected-error {{'callback' attribute takes one argument}}
-__attribute__((callback(1, -1))) void too_many_args_2(double 
(*callback)(void)); // expected-error {{'callback' attribute takes one 
argument}}
-__attribute__((callback(1, 2, 2))) void too_many_args_3(void (*callback)(int), 
int); // expected-error {{'callback' attribute requires exactly 2 arguments}}
+__attribute__((callback(1, 1))) void too_many_args_1(void (*callback)(void)) 
{}  // expected-error-re {{'callback' attribute references function of type 
'void ({{(void)?}})' which expects 0 arguments but attribute specifies 1 
parameter index argument}}
+__attribute__((callback(1, -1))) void too_many_args_2(double 
(*callback)(void)); // expected-error-re {{'callback' attribute references 
function of type 'double ({{(void)?}})' which expects 0 arguments but attribute 
specifies 1 parameter index argument}}
+__attribute__((callback(1, 2, 2))) void too_many_args_3(void (*callback)(int), 
int); // expected-error {{'callba

[clang] [CodeGen][NFC] Run mem2reg and sroa on complex range tests (PR #131925)

2025-04-04 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Running both mem2reg and sroa is redunant; just run sroa.

If the undefs are getting introduced by sroa, that's fine; they'll go away when 
we fix sroa.

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


[clang] [C11] Implement WG14 N1285 (temporary lifetimes) (PR #133472)

2025-04-04 Thread Eli Friedman via cfe-commits


@@ -27,7 +27,7 @@ void testva (int n, ...) {
   va_start(ap,n);
   // CHECK: [[AP:%[a-z0-9]+]] = alloca ptr, align 4
   // CHECK: [[V5:%[a-z0-9]+]] = alloca %struct.x, align 4
-  // CHECK: [[TMP:%[a-z0-9]+]] = alloca [4 x i32], align 4
+  // CHECK: [[TMP:%[a-z0-9\.]+]] = alloca [4 x i32], align 4

efriedma-quic wrote:

I meant just `[[TMP:%[a-z0-9.]+]]`, as opposed to `\.`

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


[clang] [llvm] [fatlto] Use the ThinLTO default pipeline for FatLTO (PR #134434)

2025-04-04 Thread Nikita Popov via cfe-commits

https://github.com/nikic commented:

Switching to the ThinLTO post-link pipeline will have a big impact on 
optimization behavior and compile-time. I think it would be safer to make a 
change along the lines of https://github.com/llvm/llvm-project/pull/126168, 
i.e. to schedule the necessary passes in the FatLTO pipeline. Without having 
looked into it closely, it would probably be okay to just schedule them before 
the buildModuleOptimizationPipeline call.

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


[clang] [libclang/python] Add some bindings to the `Cursor` interface (PR #132377)

2025-04-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jannick Kremer (DeinAlptraum)


Changes

Make Cursor hashable
Add `Cursor.has_attr()`
Add `Cursor.specialized_template`

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


3 Files Affected:

- (modified) clang/bindings/python/clang/cindex.py (+17) 
- (modified) clang/bindings/python/tests/cindex/test_cursor.py (+40) 
- (modified) clang/docs/ReleaseNotes.rst (+6) 


``diff
diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 879a0a3c5c58c..090ee899ad60e 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1561,6 +1561,9 @@ def __eq__(self, other):
 def __ne__(self, other):
 return not self.__eq__(other)
 
+def __hash__(self) -> int:
+return self.hash
+
 def is_definition(self):
 """
 Returns true if the declaration pointed at by the cursor is also a
@@ -2035,6 +2038,13 @@ def lexical_parent(self):
 
 return self._lexical_parent
 
+@property
+def specialized_template(self) -> Cursor | None:
+"""Return the primary template that this cursor is a specialization 
of, if any."""
+return Cursor.from_cursor_result(
+conf.lib.clang_getSpecializedCursorTemplate(self), self
+)
+
 @property
 def translation_unit(self):
 """Returns the TranslationUnit to which this Cursor belongs."""
@@ -2178,6 +2188,12 @@ def get_bitfield_width(self):
 """
 return conf.lib.clang_getFieldDeclBitWidth(self)  # type: ignore 
[no-any-return]
 
+def has_attrs(self) -> bool:
+"""
+Determine whether the given cursor has any attributes.
+"""
+return bool(conf.lib.clang_Cursor_hasAttrs(self))
+
 @staticmethod
 def from_result(res, arg):
 assert isinstance(res, Cursor)
@@ -3932,6 +3948,7 @@ def set_property(self, property, value):
 ("clang_getCursorType", [Cursor], Type),
 ("clang_getCursorUSR", [Cursor], _CXString),
 ("clang_Cursor_getMangling", [Cursor], _CXString),
+("clang_Cursor_hasAttrs", [Cursor], c_uint),
 # ("clang_getCXTUResourceUsage",
 #  [TranslationUnit],
 #  CXTUResourceUsage),
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py 
b/clang/bindings/python/tests/cindex/test_cursor.py
index c6aa65ce3c29f..9947f551cc2f8 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/bindings/python/tests/cindex/test_cursor.py
@@ -4,6 +4,7 @@
 AvailabilityKind,
 BinaryOperator,
 Config,
+Cursor,
 CursorKind,
 PrintingPolicy,
 PrintingPolicyProperty,
@@ -995,3 +996,42 @@ def test_pretty_print(self):
 pp.set_property(PrintingPolicyProperty.Bool, False)
 self.assertEqual(pp.get_property(PrintingPolicyProperty.Bool), False)
 self.assertEqual(f.pretty_printed(pp), "void f(_Bool x) {\n}\n")
+
+def test_has_attrs(self):
+tu = get_tu(
+"""
+struct A;
+struct A final {};
+
+struct B;
+struct B {};
+""",
+lang="cpp",
+)
+A = get_cursor(tu, "A")
+B = get_cursor(tu, "B")
+self.assertTrue(A.get_definition().has_attrs())
+self.assertFalse(B.get_definition().has_attrs())
+
+def test_hash(self):
+def accumulate_cursors(cursor: Cursor, all_cursors: list[Cursor]):
+all_cursors.append(cursor)
+for child in cursor.get_children():
+all_cursors = accumulate_cursors(child, all_cursors)
+return all_cursors
+
+tu = get_tu(kInput)
+all_cursors = accumulate_cursors(tu.cursor, [])
+cursor_hashes = set()
+for cursor in all_cursors:
+self.assertNotIn(hash(cursor), cursor_hashes)
+cursor_hashes.add(hash(cursor))
+
+def test_specialized_template(self):
+tu = get_tu(kTemplateArgTest, lang="cpp")
+foos = get_cursors(tu, "foo")
+prime_foo = foos[1].specialized_template
+
+self.assertNotEqual(foos[0], foos[1])
+self.assertEqual(foos[0], prime_foo)
+self.assertIsNone(tu.cursor.specialized_template)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a25808e36bd51..ab68be3702840 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -442,6 +442,12 @@ Sanitizers
 
 Python Binding Changes
 --
+- Made ``Cursor`` hashable.
+- Added ``Cursor.has_attrs``, a binding for ``clang_Cursor_hasAttrs``, to check
+  whether a cursor has any attributes.
+- Added ``Cursor.specialized_template``, a binding for
+  ``clang_getSpecializedCursorTemplate``, to retrieve the primary template that
+  the cursor is a specialization of.
 - Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which
   allows visiting the methods of a class.
 

``




https://github.com/llvm/llvm-project/pull/132377
__

[clang] Revert "[HLSL][RootSignature] Define and integrate `HLSLRootSignatureAttr`" (PR #134273)

2025-04-04 Thread Finn Plummer via cfe-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/134273

Reverts llvm/llvm-project#134124

The build is failing again to a linking error: 
[here](https://github.com/llvm/llvm-project/pull/134124#issuecomment-2776370486).
 Again the error was not present locally or any of the pre-merge builds and 
must have been transitively linked in these build environments...

>From ae6728d3dd3943a291314604ced5b9a4b8b4f754 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Thu, 3 Apr 2025 09:38:32 -0700
Subject: [PATCH] =?UTF-8?q?Revert=20"[HLSL][RootSignature]=20Define=20and?=
 =?UTF-8?q?=20integrate=20`HLSLRootSignatureAttr`=20(#=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 65fa57bdcc9d745dd8c222426e79618fb7cf1c91.
---
 clang/include/clang/AST/Attr.h  |  1 -
 clang/include/clang/Basic/Attr.td   | 19 ---
 clang/include/clang/Basic/AttrDocs.td   | 11 ---
 clang/include/clang/Sema/SemaHLSL.h |  1 -
 clang/lib/Sema/SemaDeclAttr.cpp |  3 --
 clang/lib/Sema/SemaHLSL.cpp | 35 -
 clang/test/AST/HLSL/RootSignatures-AST.hlsl | 24 --
 clang/test/SemaHLSL/RootSignature-err.hlsl  |  9 --
 8 files changed, 103 deletions(-)
 delete mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl
 delete mode 100644 clang/test/SemaHLSL/RootSignature-err.hlsl

diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 37c3f8bbfb5f9..994f236337b99 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,7 +26,6 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Support/Compiler.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
-#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 9ef4f2b6b91ed..fd9e686485552 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4710,25 +4710,6 @@ def Error : InheritableAttr {
   let Documentation = [ErrorAttrDocs];
 }
 
-def HLSLRootSignature : Attr {
-  /// [RootSignature(Signature)]
-  let Spellings = [Microsoft<"RootSignature">];
-  let Args = [StringArgument<"Signature">];
-  let Subjects = SubjectList<[Function],
- ErrorDiag, "'function'">;
-  let LangOpts = [HLSL];
-  let Documentation = [HLSLRootSignatureDocs];
-  let AdditionalMembers = [{
-private:
-  ArrayRef RootElements;
-public:
-  void setElements(ArrayRef Elements) {
-RootElements = Elements;
-  }
-  auto getElements() const { return RootElements; }
-}];
-}
-
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 1b969e456b910..c8b371280e35d 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8145,17 +8145,6 @@ and 
https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html
   }];
 }
 
-def HLSLRootSignatureDocs : Documentation {
-  let Category = DocCatFunction;
-  let Content = [{
-The ``RootSignature`` attribute applies to HLSL entry functions to define what
-types of resources are bound to the graphics pipeline.
-
-For details about the use and specification of Root Signatures please see here:
-https://learn.microsoft.com/en-us/windows/win32/direct3d12/root-signatures
-  }];
-}
-
 def NumThreadsDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 1bd35332612cd..f333fe30e8da0 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -118,7 +118,6 @@ class SemaHLSL : public SemaBase {
bool IsCompAssign);
   void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
 
-  void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index b36d327f5bd0a..0b844b44930b9 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7498,9 +7498,6 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
 break;
 
   // HLSL attributes:
-  case ParsedAttr::AT_HLSLRootSignature:
-S.HLSL().handleRootSignatureAttr(D, AL);
-break;
   case ParsedAttr::AT_HLSLNumThreads:
 S.HLSL().handleNumThreadsAttr(D, AL);
 break;
diff --g

[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-04-04 Thread via cfe-commits


@@ -148,6 +158,32 @@ class AnnotatingParser {
 }
   }
 
+  const FormatStyle::FunctionDeclarationWithKeywords *
+  findFunctionWithKeywordedParameters() const {
+const FormatToken *TokBeforeFirstLParent{};
+for (const FormatToken *T = Line.First; T != Line.Last; T = T->Next) {
+  if (T->TokenText == StringRef("(", 1)) {

mydeveloperday wrote:

does it need to be found by string? could it be by T->is(l_paren)

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


[clang] [llvm] [Clang][NVVM] Support `-f[no-]cuda-prec-sqrt` and propagate precision flag to `NVVMReflect` (PR #134244)

2025-04-04 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

At first glance, it seems like a good idea to allow people to choose how their 
square roots are lowered on a per-function level: some code cares about precise 
square roots, some doesn't, and you should be able to make choices on a 
case-by-case basis.

But looking at the code structure, maybe cuda doesn't allow that?

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


[clang] [llvm] [PowerPC] Enable indiviual crbits tracking at -O2 (PR #133617)

2025-04-04 Thread Henry Jiang via cfe-commits

https://github.com/mustartt updated 
https://github.com/llvm/llvm-project/pull/133617

>From 8a71c3bb096045a10c8800d9abbc9bb9cb603ebe Mon Sep 17 00:00:00 2001
From: Henry Jiang 
Date: Sun, 30 Mar 2025 00:23:10 -0400
Subject: [PATCH] Enable indiviual crbits tracking at O2

---
 clang/lib/Basic/Targets/PPC.cpp  |  5 --
 llvm/lib/Target/PowerPC/PPC.td   | 82 ++--
 llvm/lib/Target/PowerPC/PPCSubtarget.cpp |  9 +++
 llvm/lib/Target/PowerPC/PPCSubtarget.h   |  1 +
 llvm/lib/Target/PowerPC/PPCTargetMachine.cpp |  7 --
 llvm/test/CodeGen/PowerPC/crbit-asm.ll   |  4 +-
 6 files changed, 55 insertions(+), 53 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 425ad68bb9098..61d567892b498 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -559,11 +559,6 @@ bool PPCTargetInfo::initFeatureMap(
 .Case("pwr9", true)
 .Case("pwr8", true)
 .Default(false);
-  Features["crbits"] = llvm::StringSwitch(CPU)
-.Case("ppc64le", true)
-.Case("pwr9", true)
-.Case("pwr8", true)
-.Default(false);
   Features["vsx"] = llvm::StringSwitch(CPU)
 .Case("ppc64le", true)
 .Case("pwr9", true)
diff --git a/llvm/lib/Target/PowerPC/PPC.td b/llvm/lib/Target/PowerPC/PPC.td
index 39da428461393..9f0f271b619c7 100644
--- a/llvm/lib/Target/PowerPC/PPC.td
+++ b/llvm/lib/Target/PowerPC/PPC.td
@@ -74,7 +74,7 @@ def Feature64BitRegs : 
SubtargetFeature<"64bitregs","Use64BitRegs", "true",
 
 // Specify if we should store and manipulate i1 values in the individual
 // condition register bits.
-def FeatureCRBits: SubtargetFeature<"crbits", "UseCRBits", "true",
+def FeatureCRBits: SubtargetFeature<"crbits", "HasCRBits", "true",
   "Use condition-register bits individually">;
 def FeatureFPU   : SubtargetFeature<"fpu","HasFPU","true",
 "Enable classic FPU instructions",
@@ -390,6 +390,7 @@ def ProcessorFeatures {
   FeatureFPCVT,
   FeatureISEL,
   FeaturePOPCNTD,
+  FeatureCRBits,
   FeatureCMPB,
   FeatureLDBRX,
   Feature64Bit,
@@ -577,79 +578,82 @@ include "GISel/PPCRegisterBanks.td"
 //
 
 def : Processor<"generic", G3Itineraries, [Directive32, FeatureHardFloat,
-   FeatureMFTB]>;
+   FeatureMFTB, FeatureCRBits]>;
 def : ProcessorModel<"440", PPC440Model, [Directive440, FeatureISEL,
   FeatureFRES, FeatureFRSQRTE,
   FeatureICBT, FeatureBookE,
-  FeatureMSYNC, FeatureMFTB]>;
+  FeatureMSYNC, FeatureMFTB,
+  FeatureCRBits]>;
 def : ProcessorModel<"450", PPC440Model, [Directive440, FeatureISEL,
   FeatureFRES, FeatureFRSQRTE,
   FeatureICBT, FeatureBookE,
-  FeatureMSYNC, FeatureMFTB]>;
-def : Processor<"601", G3Itineraries, [Directive601, FeatureFPU]>;
+  FeatureMSYNC, FeatureMFTB,
+  FeatureCRBits]>;
+def : Processor<"601", G3Itineraries, [Directive601, FeatureFPU,
+   FeatureCRBits]>;
 def : Processor<"602", G3Itineraries, [Directive602, FeatureFPU,
-   FeatureMFTB]>;
-def : Processor<"603", G3Itineraries, [Directive603,
-   FeatureFRES, FeatureFRSQRTE,
-   FeatureMFTB]>;
-def : Processor<"603e", G3Itineraries, [Directive603,
-FeatureFRES, FeatureFRSQRTE,
-FeatureMFTB]>;
+   FeatureMFTB, FeatureCRBits]>;
+def : Processor<"603", G3Itineraries, [Directive603, FeatureFRES,
+   FeatureFRSQRTE, FeatureMFTB,
+   FeatureCRBits]>;
+def : Processor<"603e", G3Itineraries, [Directive603, FeatureFRES,
+FeatureFRSQRTE, FeatureMFTB,
+FeatureCRBits]>;
 def : Processor<"603ev", G3Itinera

[clang] [clang-tools-extra] [lldb] Reland: [clang] preserve class type sugar when taking pointer to member (PR #132401)

2025-04-04 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@nico thanks, that's landed. Let me know if it's all green now, otherwise we 
proceed with the revert.

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


[clang] [clang][ExprConst] Check record base classes for valid structs (PR #132270)

2025-04-04 Thread Erich Keane via cfe-commits

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


[clang] [C11] Implement WG14 N1285 (temporary lifetimes) (PR #133472)

2025-04-04 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

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


[clang-tools-extra] [clang-tidy][NFC][doc] improve "options" sections of `misc-`, `cppcore-` and other checks (PR #133694)

2025-04-04 Thread Baranov Victor via cfe-commits

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

>From 3f2086a843ccbc2dca5185199bbb91c366bcae06 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Mon, 31 Mar 2025 13:12:23 +0300
Subject: [PATCH 1/4] [clang-tidy] improve docs for various checks

---
 .../checks/android/comparison-in-temp-failure-retry.rst  | 1 +
 .../docs/clang-tidy/checks/cert/msc51-cpp.rst| 2 +-
 .../docs/clang-tidy/checks/concurrency/mt-unsafe.rst | 3 +++
 .../clang-tidy/checks/cppcoreguidelines/no-malloc.rst| 6 +++---
 .../checks/cppcoreguidelines/owning-memory.rst   | 4 ++--
 .../pro-bounds-constant-array-index.rst  | 1 +
 .../checks/cppcoreguidelines/pro-type-member-init.rst| 1 +
 .../clang-tidy/checks/misc/coroutine-hostile-raii.rst| 8 
 .../docs/clang-tidy/checks/misc/include-cleaner.rst  | 4 ++--
 .../misc/non-private-member-variables-in-classes.rst | 9 +
 10 files changed, 23 insertions(+), 16 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/android/comparison-in-temp-failure-retry.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/android/comparison-in-temp-failure-retry.rst
index 93112ee2bea64..31cc72b0579c4 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/android/comparison-in-temp-failure-retry.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/android/comparison-in-temp-failure-retry.rst
@@ -41,3 +41,4 @@ Options
 .. option:: RetryMacros
 
A comma-separated list of the names of retry macros to be checked.
+   Default is `TEMP_FAILURE_RETRY`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst 
b/clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst
index 1e0e34efe0a58..99e550aef0e7a 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst
@@ -37,4 +37,4 @@ Options
 .. option:: DisallowedSeedTypes
 
A comma-separated list of the type names which are disallowed.
-   Default values are ``time_t``, ``std::time_t``.
+   Default value is `time_t,std::time_t`.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/concurrency/mt-unsafe.rst 
b/clang-tools-extra/docs/clang-tidy/checks/concurrency/mt-unsafe.rst
index 4e46ba1edc34f..337be787d962b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/concurrency/mt-unsafe.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/concurrency/mt-unsafe.rst
@@ -32,6 +32,9 @@ Examples:
 
 sleep(1); // implementation may use SIGALRM
 
+Options
+---
+
 .. option:: FunctionSet
 
   Specifies which functions in libc should be considered thread-safe,
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-malloc.rst 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-malloc.rst
index 237520aa6690a..e3a162078a3b8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-malloc.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-malloc.rst
@@ -35,14 +35,14 @@ Options
 .. option:: Allocations
 
Semicolon-separated list of fully qualified names of memory allocation 
functions.
-   Defaults to ``::malloc;::calloc``.
+   Defaults to `::malloc;::calloc`.
 
 .. option:: Deallocations
 
Semicolon-separated list of fully qualified names of memory allocation 
functions.
-   Defaults to ``::free``.
+   Defaults to `::free`.
 
 .. option:: Reallocations
 
Semicolon-separated list of fully qualified names of memory allocation 
functions.
-   Defaults to ``::realloc``.
+   Defaults to `::realloc`.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/owning-memory.rst 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/owning-memory.rst
index 3c91d09dda1f2..4fc49f8bd6eee 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/owning-memory.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/owning-memory.rst
@@ -95,14 +95,14 @@ Options
 
Semicolon-separated list of fully qualified names of legacy functions that 
create
resources but cannot introduce ``gsl::owner<>``.
-   Defaults to 
``::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile``.
+   Defaults to 
`::malloc;::aligned_alloc;::realloc;::calloc;::fopen;::freopen;::tmpfile`.
 
 
 .. option:: LegacyResourceConsumers
 
Semicolon-separated list of fully qualified names of legacy functions 
expecting
resource owners as pointer arguments but cannot introduce ``gsl::owner<>``.
-   Defaults to ``::free;::realloc;::freopen;::fclose``.
+   Defaults to `::free;::realloc;::freopen;::fclose`.
 
 
 Limitations
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-constant-array-index.rst
index 4e877676cf1fe..9b82e0c45a314 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-cons

[clang] [llvm] [X86][AVX10.2] Remove YMM rounding from VMINMAXP[H,S,D] (PR #132405)

2025-04-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Phoebe Wang (phoebewang)


Changes

Ref: https://cdrdv2.intel.com/v1/dl/getContent/784343

---

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


15 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsX86.td (+3-3) 
- (modified) clang/lib/Headers/avx10_2minmaxintrin.h (+18-63) 
- (modified) clang/lib/Sema/SemaX86.cpp (+3-6) 
- (modified) clang/test/CodeGen/X86/avx10_2_512minmax-error.c (-11) 
- (modified) clang/test/CodeGen/X86/avx10_2minmax-builtins.c (+9-63) 
- (modified) llvm/include/llvm/IR/IntrinsicsX86.td (+8-8) 
- (modified) llvm/lib/Target/X86/X86InstrAVX10.td (+1-10) 
- (modified) llvm/lib/Target/X86/X86IntrinsicsInfo.h (+6-6) 
- (modified) llvm/test/CodeGen/X86/avx10_2minmax-intrinsics.ll (+15-107) 
- (modified) llvm/test/MC/Disassembler/X86/avx10.2minmax-32.txt (-24) 
- (modified) llvm/test/MC/Disassembler/X86/avx10.2minmax-64.txt (-24) 
- (modified) llvm/test/MC/X86/avx10.2minmax-32-att.s (-24) 
- (modified) llvm/test/MC/X86/avx10.2minmax-32-intel.s (-24) 
- (modified) llvm/test/MC/X86/avx10.2minmax-64-att.s (-24) 
- (modified) llvm/test/MC/X86/avx10.2minmax-64-intel.s (-24) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index ea0d6df4a33c2..adb174a9fc62d 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -4823,7 +4823,7 @@ let Features = "avx10.2-256", Attributes = [NoThrow, 
RequiredVectorWidth<128>] i
 }
 
 let Features = "avx10.2-256", Attributes = [NoThrow, RequiredVectorWidth<256>] 
in {
-  def vminmaxpd256_round_mask : X86Builtin<"_Vector<4, double>(_Vector<4, 
double>, _Vector<4, double>, _Constant int, _Vector<4, double>, unsigned char, 
_Constant int)">;
+  def vminmaxpd256_mask : X86Builtin<"_Vector<4, double>(_Vector<4, double>, 
_Vector<4, double>, _Constant int, _Vector<4, double>, unsigned char)">;
 }
 
 let Features = "avx10.2-512", Attributes = [NoThrow, RequiredVectorWidth<512>] 
in {
@@ -4835,7 +4835,7 @@ let Features = "avx10.2-256", Attributes = [NoThrow, 
RequiredVectorWidth<128>] i
 }
 
 let Features = "avx10.2-256", Attributes = [NoThrow, RequiredVectorWidth<256>] 
in {
-  def vminmaxph256_round_mask : X86Builtin<"_Vector<16, _Float16>(_Vector<16, 
_Float16>, _Vector<16, _Float16>, _Constant int, _Vector<16, _Float16>, 
unsigned short, _Constant int)">;
+  def vminmaxph256_mask : X86Builtin<"_Vector<16, _Float16>(_Vector<16, 
_Float16>, _Vector<16, _Float16>, _Constant int, _Vector<16, _Float16>, 
unsigned short)">;
 }
 
 let Features = "avx10.2-512", Attributes = [NoThrow, RequiredVectorWidth<512>] 
in {
@@ -4847,7 +4847,7 @@ let Features = "avx10.2-256", Attributes = [NoThrow, 
RequiredVectorWidth<128>] i
 }
 
 let Features = "avx10.2-256", Attributes = [NoThrow, RequiredVectorWidth<256>] 
in {
-  def vminmaxps256_round_mask : X86Builtin<"_Vector<8, float>(_Vector<8, 
float>, _Vector<8, float>, _Constant int, _Vector<8, float>, unsigned char, 
_Constant int)">;
+  def vminmaxps256_mask : X86Builtin<"_Vector<8, float>(_Vector<8, float>, 
_Vector<8, float>, _Constant int, _Vector<8, float>, unsigned char)">;
 }
 
 let Features = "avx10.2-512", Attributes = [NoThrow, RequiredVectorWidth<512>] 
in {
diff --git a/clang/lib/Headers/avx10_2minmaxintrin.h 
b/clang/lib/Headers/avx10_2minmaxintrin.h
index 8164d49d89f1f..809a01b04f13e 100644
--- a/clang/lib/Headers/avx10_2minmaxintrin.h
+++ b/clang/lib/Headers/avx10_2minmaxintrin.h
@@ -66,34 +66,19 @@
   (__v2df)_mm_setzero_pd(), (__mmask8)(U)))
 
 #define _mm256_minmax_pd(A, B, C)  
\
-  ((__m256d)__builtin_ia32_vminmaxpd256_round_mask(
\
+  ((__m256d)__builtin_ia32_vminmaxpd256_mask(  
\
   (__v4df)(__m256d)(A), (__v4df)(__m256d)(B), (int)(C),
\
-  (__v4df)_mm256_setzero_pd(), (__mmask8)-1, _MM_FROUND_NO_EXC))
+  (__v4df)_mm256_setzero_pd(), (__mmask8)-1))
 
 #define _mm256_mask_minmax_pd(W, U, A, B, C)   
\
-  ((__m256d)__builtin_ia32_vminmaxpd256_round_mask(
\
+  ((__m256d)__builtin_ia32_vminmaxpd256_mask(  
\
   (__v4df)(__m256d)(A), (__v4df)(__m256d)(B), (int)(C),
\
-  (__v4df)(__m256d)(W), (__mmask8)(U), _MM_FROUND_NO_EXC))
+  (__v4df)(__m256d)(W), (__mmask8)(U)))
 
 #define _mm256_maskz_minmax_pd(U, A, B, C) 
\
-  ((__m256d)__builtin_ia32_vminmaxpd256_round_mask(
\
+  ((__m256d)__builtin_ia32_vminmaxpd256_mask(  
\
   (__v4df)(__m256d)(A), (__v4df)(__m256d)(B), (int)(C),
\
-  (__v4df)_mm256_setzero_pd(), (__mmask8)(U), _MM_FROUND_NO_EXC))
-
-#define _mm256_minmax_round_pd(A, B, C

[clang] [CIR] Upstream CmpOp (PR #133159)

2025-04-04 Thread Andy Kaylor via cfe-commits


@@ -710,6 +710,89 @@ class ScalarExprEmitter : public 
StmtVisitor {
   HANDLEBINOP(Xor)
   HANDLEBINOP(Or)
 #undef HANDLEBINOP
+
+  mlir::Value emitCmp(const BinaryOperator *e) {
+mlir::Value result;
+QualType lhsTy = e->getLHS()->getType();
+QualType rhsTy = e->getRHS()->getType();
+
+auto clangCmpToCIRCmp =
+[](clang::BinaryOperatorKind clangCmp) -> cir::CmpOpKind {
+  switch (clangCmp) {
+  case BO_LT:
+return cir::CmpOpKind::lt;
+  case BO_GT:
+return cir::CmpOpKind::gt;
+  case BO_LE:
+return cir::CmpOpKind::le;
+  case BO_GE:
+return cir::CmpOpKind::ge;
+  case BO_EQ:
+return cir::CmpOpKind::eq;
+  case BO_NE:
+return cir::CmpOpKind::ne;
+  default:
+llvm_unreachable("unsupported comparison kind");
+  }
+};
+
+if (lhsTy->getAs()) {
+  assert(e->getOpcode() == BO_EQ || e->getOpcode() == BO_NE);
+  mlir::Value lhs = cgf.emitScalarExpr(e->getLHS());
+  mlir::Value rhs = cgf.emitScalarExpr(e->getRHS());
+  cir::CmpOpKind kind = clangCmpToCIRCmp(e->getOpcode());
+  result =
+  builder.createCompare(cgf.getLoc(e->getExprLoc()), kind, lhs, rhs);
+} else if (!lhsTy->isAnyComplexType() && !rhsTy->isAnyComplexType()) {
+  BinOpInfo boInfo = emitBinOps(e);
+  mlir::Value lhs = boInfo.lhs;
+  mlir::Value rhs = boInfo.rhs;
+
+  if (lhsTy->isVectorType()) {
+assert(!cir::MissingFeatures::vectorType());
+cgf.cgm.errorNYI(boInfo.loc, "vector comparisons");
+result = builder.getBool(false, cgf.getLoc(boInfo.loc));
+  } else if (boInfo.isFixedPointOp()) {
+assert(!cir::MissingFeatures::fixedPointType());
+cgf.cgm.errorNYI(boInfo.loc, "fixed point comparisons");
+result = builder.getBool(false, cgf.getLoc(boInfo.loc));
+  } else if (lhsTy->hasSignedIntegerRepresentation()) {
+cir::CmpOpKind kind = clangCmpToCIRCmp(e->getOpcode());
+result = builder.createCompare(cgf.getLoc(boInfo.loc), kind, lhs, rhs);
+  } else {
+// Unsigned integers and pointers.
+if (cgf.cgm.getCodeGenOpts().StrictVTablePointers &&
+mlir::isa(lhs.getType()) &&
+mlir::isa(rhs.getType())) {
+  cgf.cgm.errorNYI(boInfo.loc, "strict vtable pointer comparisons");
+  result = builder.getBool(false, cgf.getLoc(boInfo.loc));
+}
+
+cir::CmpOpKind kind = clangCmpToCIRCmp(e->getOpcode());
+result = builder.createCompare(cgf.getLoc(boInfo.loc), kind, lhs, rhs);
+  }
+} else {
+  // Complex Comparison: can only be an equality comparison.
+  assert(!cir::MissingFeatures::complexType());
+  const mlir::Location loc = cgf.getLoc(e->getSourceRange());
+  cgf.cgm.errorNYI(loc, "complex comparison");
+  result = builder.getBool(false, loc);
+}
+
+return emitScalarConversion(result, cgf.getContext().BoolTy, e->getType(),
+e->getExprLoc());
+  }

andykaylor wrote:

I agree that we need to look at context to decide which source location/range 
makes sense. I've seen problems where we were getting source locations from 
operands rather than from the expression where the operand is used, which was 
wrong in that case.

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


[libclc] [libclc] Add license headers to files missing them (PR #132239)

2025-04-04 Thread Kristof Beyls via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Added Conflicting Global Accesses checker (PR #130421)

2025-04-04 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

If this is a CERT check, please add the corresponding aliases towards the CERT 
module.

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


[clang] [Clang] Add warning message for C++17 alias template CTAD (PR #133806)

2025-04-04 Thread via cfe-commits

Sirraide wrote:

(grep for `DiagCompat()` if you’re unsure as to what to do)

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


[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)

2025-04-04 Thread Balazs Benics via cfe-commits


@@ -1139,6 +1289,271 @@ void deque_insert_end(std::deque &D, int n) {
   // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: 
expect warning $D.end() - 1
 }
 
+/// insert_range()
+///
+/// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator
+///ahead of the insertion point are decremented; if the
+///relation between the insertion point and the first
+///position of the container is known, the first position
+///of the container is also decremented).
+///
+/// - Iterator invalidation rules depend the container type.
+
+/// std::list-like containers: No iterators are invalidated.
+
+void list_insert_range_begin(std::list &L, std::vector& vec) {
+  auto i0 = L.cbegin(), i1 = L.cend();
+
+  clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()");
+  clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()");
+
+  auto i2 = L.insert_range(i0, vec);
+
+  clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); 
//expected-warning{{TRUE}}
+  clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); 
//expected-warning{{TRUE}}
+
+  clang_analyzer_express(clang_analyzer_iterator_position(i0)); // 
expected-warning-re {{$L.begin(){{$
+  // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: 
expect warning $L.begin() - 1

steakhal wrote:

Why is this line disabled? We could (and should) expect the actual output; and 
put a FIXME there if it's actually not what is desired.

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


[clang] [C11] Implement WG14 N1285 (temporary lifetimes) (PR #133472)

2025-04-04 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,212 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -std=c99 -Wno-dangling -emit-llvm -o - %s | FileCheck %s 
--check-prefix=C99
+// RUN: %clang_cc1 -std=c11 -Wno-dangling -emit-llvm -o - %s | FileCheck %s 
--check-prefix=C11

AaronBallman wrote:

I added that to the line setting an optimization level; or should I be setting 
that always for codegen tests regardless of passing `-On`?

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


[clang] [clang] Track final substitution for Subst* AST nodes (PR #132748)

2025-04-04 Thread Jan Voung via cfe-commits

jvoung wrote:

> @ymand @jvoung I'd like to know if you tried this patch within google and 
> within your tooling, and if you can report whether it is suited and if there 
> is any noteworthy performance impact.

Ok, I tried some experiments. Our nullability analysis tests do now pass 
without the flag =) One of our test expectations ended up improving around 
alias templates with default arguments as well. Maybe that is related to the 
test expectation change in your patch `subst_default_argument` in 
`clang/test/AST/ast-dump-template-decls.cpp` ?

No noteworthy performance impact (some same, some diffs within the stddev of 
several runs, one really big translation unit ended up compiling faster by a 
little).

One question is, would you be okay with doing the flag removal separately? 
I.e., make it a no-op first, then delete it as a follow up with some time to 
adjust? That may allow integrating the change more incrementally (1) merge + 
update test expectations (2) stop using the flag, then (3) merge again with the 
flag deleted. 

And, thank you so much for helping with this change!

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


[clang] [llvm] Hlsl asint16 intrinsic (PR #131900)

2025-04-04 Thread via cfe-commits

https://github.com/metkarpoonam updated 
https://github.com/llvm/llvm-project/pull/131900

>From 7ef40ee7d88872dbee1345cbd822e4aed8a22626 Mon Sep 17 00:00:00 2001
From: Poonam Vilas Metkar 
Date: Tue, 18 Mar 2025 11:30:15 -0700
Subject: [PATCH 01/14] Add codegen tests, Sema tests, SPIR-V backend test
 case, and apply clang formatting

---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 18 ++
 clang/test/CodeGenHLSL/builtins/asint16.hlsl  | 48 
 .../SemaHLSL/BuiltIns/asint16-errors.hlsl | 29 ++
 .../CodeGen/SPIRV/hlsl-intrinsics/asint16.ll  | 55 +++
 4 files changed, 150 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/asint16.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/asint16-errors.hlsl
 create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/asint16.ll

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index a48a8e998a015..e0366693deae0 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -80,6 +80,24 @@ void asuint(double3, out uint3, out uint3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
 void asuint(double4, out uint4, out uint4);
 
+//===--===//
+// asint16 builtins
+//===--===//
+
+/// \fn int16_t asint16(T Val)
+/// \brief Interprets the bit pattern of x as an 16-bit integer.
+/// \param Val The input value.
+#ifdef __HLSL_ENABLE_16_BIT
+
+template  constexpr vector asint16(vector 
V) {
+  return __detail::bit_cast(V);
+}
+
+template  constexpr int16_t asint16(T F) {
+  return __detail::bit_cast(F);
+}
+#endif
+
 
//===--===//
 // distance builtins
 
//===--===//
diff --git a/clang/test/CodeGenHLSL/builtins/asint16.hlsl 
b/clang/test/CodeGenHLSL/builtins/asint16.hlsl
new file mode 100644
index 0..0cd6ee63fa078
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/asint16.hlsl
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.2-library %s -fnative-half-type -emit-llvm -O1 -o - | 
FileCheck %s
+// CHECK: define {{.*}}test_ints{{.*}}(i16 {{.*}} [[VAL:%.*]]){{.*}}
+// CHECK-NOT: bitcast
+// CHECK: ret i16 [[VAL]]
+int16_t test_int(int16_t p0)
+{
+return asint16(p0);
+}
+
+//CHECK: define {{.*}}test_uint{{.*}}(i16 {{.*}} [[VAL:%.*]]){{.*}}
+//CHECK-NOT: bitcast
+//CHECK: ret i16 [[VAL]]
+int16_t test_uint(uint16_t p0)
+{
+return asint16(p0);
+}
+
+//CHECK: define {{.*}}test_half{{.*}}(half {{.*}} [[VAL:%.*]]){{.*}}
+//CHECK: [[RES:%.*]] = bitcast half [[VAL]] to i16
+//CHECK : ret i16 [[RES]]
+int16_t test_half(half p0)
+{
+return asint16(p0);
+}
+
+//CHECK: define {{.*}}test_vector_int{{.*}}(<4 x i16> {{.*}} [[VAL:%.*]]){{.*}}
+//CHECK-NOT: bitcast
+//CHECK: ret <4 x i16> [[VAL]]
+int16_t4 test_vector_int(int16_t4 p0)
+{
+return asint16(p0);
+}
+
+//CHECK: define {{.*}}test_vector_uint{{.*}}(<4 x i16> {{.*}} 
[[VAL:%.*]]){{.*}}
+//CHECK-NOT: bitcast
+//CHECK: ret <4 x i16> [[VAL]]
+int16_t4 test_vector_uint(uint16_t4 p0)
+{
+return asint16(p0);
+}
+
+//CHECK: define {{.*}}fn{{.*}}(<4 x half> {{.*}} [[VAL:%.*]]){{.*}}
+//CHECK: [[RES:%.*]] = bitcast <4 x half> [[VAL]] to <4 x i16>
+//CHECK: ret <4 x i16> [[RES]]
+int16_t4 fn(half4 p1)
+{
+return asint16(p1);
+}
\ No newline at end of file
diff --git a/clang/test/SemaHLSL/BuiltIns/asint16-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/asint16-errors.hlsl
new file mode 100644
index 0..03a3e46bd1d46
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/asint16-errors.hlsl
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.2-library %s -fnative-half-type -verify
+
+
+int16_t4 test_asint_too_many_arg(uint16_t p0, uint16_t p1)
+{
+return asint16(p0, p1);
+  // expected-error@-1 {{no matching function for call to 'asint16'}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires single argument 'V', but 2 arguments were provided}}
+  // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not 
viable: requires single argument 'F', but 2 arguments were provided}}
+}
+
+
+int16_t test_asint_int(int p1)
+{
+return asint16(p1);
+// expected-error@hlsl/hlsl_intrinsics.h:* {{no matching function for call 
to 'bit_cast'}}
+// expected-note@-2 {{in instantiation of function template specialization 
'hlsl::asint16'}}
+// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: could 
not match 'vector' against 'int'}}
+// expected-note@hlsl/hlsl_detail.h:* {{candidate template ignored: 
substitution failure [with U = int16_t, T = int]: no type named 'Type'}}
+}
+
+int16_t test_asint_float(floa

[clang] [NFC][HLSL][RootSignature] Make the Lexer adhere to naming conventions (PR #134136)

2025-04-04 Thread Deric C. via cfe-commits

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


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


[clang] [clang] Fix array types comparison in getCommonSugaredType (PR #131649)

2025-04-04 Thread Serge Pavlov via cfe-commits

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


[clang] [clang] Do not infer lifetimebound for functions with void return type (PR #131997)

2025-04-04 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov approved this pull request.


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


[clang] [Arm] Add more -mtp=cp15 tests (PR #134098)

2025-04-04 Thread Simon Tatham via cfe-commits


@@ -1,93 +1,94 @@
-// Test of the AArch32 values of -mtp=, checking that each one maps to
-// the right target features.
-
-// RUN: %clang --target=armv7-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-HARD %s
-// ARMv7_THREAD_POINTER-HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -mtp=tpidruro -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-HARD %s
-// RUN: %clang --target=armv7-linux -mtp=tpidrurw -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-TPIDRURW %s
-// ARMv7_THREAD_POINTER-TPIDRURW: "-target-feature" "+read-tp-tpidrurw"
-// RUN: %clang --target=armv7-linux -mtp=tpidrprw -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER-TPIDRPRW %s
-// ARMv7_THREAD_POINTER-TPIDRPRW: "-target-feature" "+read-tp-tpidrprw"
-
-// RUN: %clang --target=armv6k-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER-HARD %s
-// ARM_THREAD_POINTER-HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6k-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER_AUTO %s
-// ARM_THREAD_POINTER_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=thumbv6k-apple-darwin -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_NO_AUTO %s
-// THUMBv6_THREAD_POINTER_NO_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: not %clang --target=thumbv6k-apple-darwin -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_NO_HARD %s
-// THUMBv6_THREAD_POINTER_NO_HARD: unsupported option '-mtp=' for target 
'thumbv6k-apple-darwin'
-
-// RUN: not %clang --target=thumbv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARM_THREAD_POINTER_NO_HARD %s
-// ARM_THREAD_POINTER_NO_HARD: hardware TLS register is not supported for the 
armv6t2 sub-architecture
-
-// RUN: %clang --target=armv5t-linux -mtp=cp15 -x assembler -### %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv5_THREAD_POINTER_ASSEMBLER %s
-// ARMv5_THREAD_POINTER_ASSEMBLER-NOT: hardware TLS register is not supported 
for the armv5 sub-architecture
-
-// RUN: not %clang --target=armv6-linux -mthumb -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_UNSUPP %s
-// RUN: not %clang --target=thumbv6-linux -mthumb -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=THUMBv6_THREAD_POINTER_UNSUPP %s
-// THUMBv6_THREAD_POINTER_UNSUPP: hardware TLS register is not supported for 
the thumbv6 sub-architecture
-
-// RUN: %clang --target=armv7-linux -mtp=soft -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_SOFT %s
-// ARMv7_THREAD_POINTER_SOFT-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_NON %s
-// ARMv7_THREAD_POINTER_NON: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_Auto %s
-// ARMv7_THREAD_POINTER_Auto: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7_THREAD_POINTER_HARD %s
-// ARMv7_THREAD_POINTER_HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv7m-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7m_THREAD_POINTER_Auto %s
-// ARMv7m_THREAD_POINTER_Auto-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: not %clang --target=armv7m-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv7m_THREAD_POINTER_HARD %s
-// ARMv7m_THREAD_POINTER_HARD: hardware TLS register is not supported for the 
thumbv7m sub-architecture
-
-// RUN: %clang --target=armv5t-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv5t_THREAD_POINTER_Auto %s
-// ARMv5t_THREAD_POINTER_Auto-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6k-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv6k_THREAD_POINTER_Auto %s
-// ARMv6k_THREAD_POINTER_Auto: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: not %clang --target=armv6t2-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv6t2_THREAD_POINTER_HARD %s
-// ARMv6t2_THREAD_POINTER_HARD: hardware TLS register is not supported for the 
armv6t2 sub-architecture
-
-// RUN: %clang --target=armv6t2-linux -mtp=auto -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMV6t2_THREAD_POINTER_AUTO %s
-// ARMV6t2_THREAD_POINTER_AUTO-NOT: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target=armv6kz-linux -mtp=cp15 -### -S %s 2>&1 | \
-// RUN: FileCheck -check-prefix=ARMv6kz_THREAD_POINTER_HARD %s
-// ARMv6kz_THREAD_POINTER_HARD: "-target-feature" "+read-tp-tpidruro"
-
-// RUN: %clang --target

[clang] [Clang][Diagnostics] Update select uses in DiagnosticXKinds.td to use enum_select (PR #130868)

2025-04-04 Thread Erich Keane via cfe-commits


@@ -2474,9 +2476,9 @@ inline bool DoShift(InterpState &S, CodePtr OpPC, LT 
&LHS, RT &RHS) {
 if (!S.noteUndefinedBehavior())
   return false;
 RHS = -RHS;
-return DoShifthttps://github.com/llvm/llvm-project/pull/130868
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NFC] [ASTMatchers] Share code of `forEachArgumentWithParamType` with UnsafeBufferUsage (PR #132387)

2025-04-04 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov updated 
https://github.com/llvm/llvm-project/pull/132387

>From ef63166c24f7328af8177220be706a573d97009e Mon Sep 17 00:00:00 2001
From: Ilya Biryukov 
Date: Fri, 21 Mar 2025 11:42:32 +0100
Subject: [PATCH 1/3] [NFC] [ASTMatchers] Share code of
 `forEachArgumentWithParamType` with UnsafeBufferUsage

This changes exposes a low-level helper that is also used to implement
`forEachArgumentWithParamType`, but can be used without matchers, e.g.
if performance is a concern.

Commit f5ee10538b68835112323c241ca7db67ca78bf62 introduced a copy of the
implementation of the `forEachArgumentWithParamType` matcher that was
needed for optimizing performance of `-Wunsafe-buffer-usage`.

This change will ensure the code is shared so that we do not repeat
ourselves and any bugfixes or changes will be picked up by both
implementations in the future.
---
 clang/include/clang/ASTMatchers/ASTMatchers.h |  75 +++--
 .../clang/ASTMatchers/LowLevelHelpers.h   |  37 ++
 clang/lib/ASTMatchers/CMakeLists.txt  |   1 +
 clang/lib/ASTMatchers/LowLevelHelpers.cpp | 105 ++
 clang/lib/Analysis/UnsafeBufferUsage.cpp  |  95 +---
 5 files changed, 162 insertions(+), 151 deletions(-)
 create mode 100644 clang/include/clang/ASTMatchers/LowLevelHelpers.h
 create mode 100644 clang/lib/ASTMatchers/LowLevelHelpers.cpp

diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 738617759eb29..26a58cea49b5a 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -71,6 +71,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/ASTMatchers/ASTMatchersInternal.h"
 #include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/ASTMatchers/LowLevelHelpers.h"
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/FileManager.h"
@@ -5215,68 +5216,26 @@ AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParamType,
   // argument of the method which should not be matched against a parameter, so
   // we skip over it here.
   BoundNodesTreeBuilder Matches;
-  unsigned ArgIndex =
-  cxxOperatorCallExpr(
-  callee(cxxMethodDecl(unless(isExplicitObjectMemberFunction()
-  .matches(Node, Finder, &Matches)
-  ? 1
-  : 0;
-  const FunctionProtoType *FProto = nullptr;
-
-  if (const auto *Call = dyn_cast(&Node)) {
-if (const auto *Value =
-dyn_cast_or_null(Call->getCalleeDecl())) {
-  QualType QT = Value->getType().getCanonicalType();
-
-  // This does not necessarily lead to a `FunctionProtoType`,
-  // e.g. K&R functions do not have a function prototype.
-  if (QT->isFunctionPointerType())
-FProto = QT->getPointeeType()->getAs();
-
-  if (QT->isMemberFunctionPointerType()) {
-const auto *MP = QT->getAs();
-assert(MP && "Must be member-pointer if its a memberfunctionpointer");
-FProto = MP->getPointeeType()->getAs();
-assert(FProto &&
-   "The call must have happened through a member function "
-   "pointer");
-  }
-}
-  }
 
-  unsigned ParamIndex = 0;
   bool Matched = false;
-  unsigned NumArgs = Node.getNumArgs();
-  if (FProto && FProto->isVariadic())
-NumArgs = std::min(NumArgs, FProto->getNumParams());
-
-  for (; ArgIndex < NumArgs; ++ArgIndex, ++ParamIndex) {
+  auto ProcessParamAndArg = [&](QualType ParamType, const Expr *Arg) {
 BoundNodesTreeBuilder ArgMatches(*Builder);
-if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), 
Finder,
-   &ArgMatches)) {
-  BoundNodesTreeBuilder ParamMatches(ArgMatches);
+if (!ArgMatcher.matches(*Arg, Finder, &ArgMatches))
+  return;
+BoundNodesTreeBuilder ParamMatches(std::move(ArgMatches));
+if (!ParamMatcher.matches(ParamType, Finder, &ParamMatches))
+  return;
+Result.addMatch(ParamMatches);
+Matched = true;
+return;
+  };
+  if (auto *Call = llvm::dyn_cast(&Node))
+matchEachArgumentWithParamType(*Call, ProcessParamAndArg);
+  else if (auto *Construct = llvm::dyn_cast(&Node))
+matchEachArgumentWithParamType(*Construct, ProcessParamAndArg);
+  else
+return false;
 
-  // This test is cheaper compared to the big matcher in the next if.
-  // Therefore, please keep this order.
-  if (FProto && FProto->getNumParams() > ParamIndex) {
-QualType ParamType = FProto->getParamType(ParamIndex);
-if (ParamMatcher.matches(ParamType, Finder, &ParamMatches)) {
-  Result.addMatch(ParamMatches);
-  Matched = true;
-  continue;
-}
-  }
-  if (expr(anyOf(cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
- hasParameter(ParamIndex, hasType(ParamMatcher),
- callExpr(callee(functionDecl(
- hasParameter

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits


@@ -462,6 +462,58 @@ def ReturnOp : CIR_Op<"return", [ParentOneOf<["FuncOp", 
"ScopeOp", "DoWhileOp",
   let hasVerifier = 1;
 }
 
+//===--===//
+// IfOp
+//===--===//
+
+def IfOp : CIR_Op<"if",
+ [DeclareOpInterfaceMethods,
+ RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments]>{
+
+  let summary = "the if-then-else operation";
+  let description = [{
+The `cir.if` operation represents an if-then-else construct for
+conditionally executing two regions of code. The operand is a `cir.bool`
+type.
+
+Examples:
+
+```mlir
+cir.if %b  {

andykaylor wrote:

I'm guessing the reason for the difference is that the condition only needs to 
be executed once for if statements. Any operations needed to evaluate the 
condition will appear in the lexical scope enclosing the if operation, similar 
to how the init section of for loops are handled.

I think it would be good to change for consistency (and maybe also revisit the 
init section of for loops).

Consider:
```
if (int x = *p)
  n += x;
```
Gives us:
```
cir.scope {
  %3 = cir.alloca !s32i, !cir.ptr, ["x", init]
  %4 = cir.load deref %0 : !cir.ptr>, !cir.ptr
  %5 = cir.load %4 : !cir.ptr, !s32i
  cir.store %5, %3 : !s32i, !cir.ptr
  %6 = cir.load %3 : !cir.ptr, !s32i
  %7 = cir.cast(int_to_bool, %6 : !s32i), !cir.bool
  cir.if %7 {
%8 = cir.load %3 : !cir.ptr, !s32i
%9 = cir.load %1 : !cir.ptr, !s32i
%10 = cir.binop(add, %9, %8) nsw : !s32i
cir.store %10, %1 : !s32i, !cir.ptr
  }
}
```
But
```
while (int x = *p)
  n += x;
```
Gives us:
```
cir.scope {
  %3 = cir.alloca !s32i, !cir.ptr, ["x", init]
  cir.while {
%4 = cir.load deref %0 : !cir.ptr>, !cir.ptr
%5 = cir.load %4 : !cir.ptr, !s32i
cir.store %5, %3 : !s32i, !cir.ptr
%6 = cir.load %3 : !cir.ptr, !s32i
%7 = cir.cast(int_to_bool, %6 : !s32i), !cir.bool
cir.condition(%7)
  } do {
%4 = cir.load %3 : !cir.ptr, !s32i
%5 = cir.load %1 : !cir.ptr, !s32i
%6 = cir.binop(add, %5, %4) nsw : !s32i
cir.store %6, %1 : !s32i, !cir.ptr
cir.yield
  }
}
```
Maybe the if representation should be:

```
cir.scope {
  %3 = cir.alloca !s32i, !cir.ptr, ["x", init]
  cir.if {
%4 = cir.load deref %0 : !cir.ptr>, !cir.ptr
%5 = cir.load %4 : !cir.ptr, !s32i
cir.store %5, %3 : !s32i, !cir.ptr
%6 = cir.load %3 : !cir.ptr, !s32i
%7 = cir.cast(int_to_bool, %6 : !s32i), !cir.bool
cir.condition(%7)
  } then {
%8 = cir.load %3 : !cir.ptr, !s32i
%9 = cir.load %1 : !cir.ptr, !s32i
%10 = cir.binop(add, %9, %8) nsw : !s32i
cir.store %10, %1 : !s32i, !cir.ptr
  }
}
```

@bcardosolopes What do you think?

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


[clang] [clang] ASTContex: fix getCommonSugaredType for array types (PR #132559)

2025-04-04 Thread Matheus Izvekov via cfe-commits

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


[clang] [llvm] [RISCV] SiFive CLIC Support (PR #132481)

2025-04-04 Thread Kito Cheng via cfe-commits


@@ -486,6 +486,24 @@ def : SysReg<"mctrctl", 0x34e>;
 // Vendor CSRs
 //===---
 
+// XSfmclic
+let FeaturesRequired = [{ {RISCV::FeatureVendorXSfmclic} }] in {
+def : SysReg<"mtvt", 0x307>;
+def : SysReg<"mnxti", 0x345>;
+def : SysReg<"mintstatus", 0x346>;
+def : SysReg<"mscratchcsw", 0x348>;
+def : SysReg<"mscratchcswl", 0x349>;
+}
+
+// XSfsclic
+let FeaturesRequired = [{ {RISCV::FeatureVendorXSfsclic} }] in {
+def : SysReg<"stvt", 0x107>;
+def : SysReg<"snxti", 0x145>;
+def : SysReg<"sintstatus", 0x146>;
+def : SysReg<"sscratchcsw", 0x148>;
+def : SysReg<"sscratchcswl", 0x149>;
+}

kito-cheng wrote:

I am little hesitate here, we should have sf. prefix here in theory

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


[clang] [llvm] [HLSL] Implement dot2add intrinsic (PR #131237)

2025-04-04 Thread Sumit Agarwal via cfe-commits

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


[clang] [llvm] [fatlto] Use the ThinLTO default pipeline for FatLTO (PR #134434)

2025-04-04 Thread Paul Kirth via cfe-commits

ilovepi wrote:

hmm, I tried adding some of the individual passes, and ran into some other 
errors. Let me give that another try w/ that PR as an example. 

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


[clang] [CIR] Remove failing binop test (PR #133001)

2025-04-04 Thread Andy Kaylor via cfe-commits

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


[clang] Optimize Module Dependency Handling for Efficient Memory Usage (PR #132287)

2025-04-04 Thread Ayush Pareek via cfe-commits

ayushpareek2003 wrote:

@Bigcheese Please have a look

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


[clang] [Clang][CodeGen] Do not use the GEP result to infer offset and result type (PR #134221)

2025-04-04 Thread Nikita Popov via cfe-commits

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

LGTM. Please edit the commit message to avoid auto-close of 
https://github.com/llvm/llvm-project/issues/132449.

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


[clang] Reland [Clang][Cmake] fix libtool duplicate member name warnings (PR #133850)

2025-04-04 Thread Farzon Lotfi via cfe-commits

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

>From beba62a4b257836076147e5146b9bb693e467f83 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Sun, 30 Mar 2025 00:59:48 -0400
Subject: [PATCH 1/3] [Clang][Cmake] fix libtool duplicate member name warnings

fixes #133199

PR #132252 Created a second file that shared .cpp in 
`clang/lib/CodeGen/CMakeLists.txt`

For example There were two AMDGPU.cpp's one in TargetBuiltins and the
other in Targets. Even though these were in different directories
libtool warns that it might not distinguish them because they share the same 
base name.

There are two fixes. The easy fix is to rename one of them and keep one
cmake file. That solution though doesn't future proof this problem in
the event of a third .cpp and it seems teams want to
just use the target name
https://github.com/llvm/llvm-project/pull/132252#issuecomment-2758178483.

The alternative fix is to seperate the cmake files into their own sub
directories. I chose to create static libraries.  It might of been
possible to build an OBJECT, but I only saw examples of $
in compiler-rt and test directories so assumed there was a reason it wasn't 
used.
---
 clang/lib/CodeGen/CMakeLists.txt  | 49 +--
 clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp   |  2 +-
 .../lib/CodeGen/TargetBuiltins/CMakeLists.txt | 14 ++
 clang/lib/CodeGen/Targets/CMakeLists.txt  | 30 
 4 files changed, 57 insertions(+), 38 deletions(-)
 create mode 100644 clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
 create mode 100644 clang/lib/CodeGen/Targets/CMakeLists.txt

diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index ebe2fbd7db295..cdf9f909a3675 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -116,45 +116,8 @@ add_clang_library(clangCodeGen
   PatternInit.cpp
   SanitizerMetadata.cpp
   SwiftCallingConv.cpp
-  TargetBuiltins/ARM.cpp
-  TargetBuiltins/AMDGPU.cpp
-  TargetBuiltins/Hexagon.cpp
-  TargetBuiltins/NVPTX.cpp
-  TargetBuiltins/PPC.cpp
-  TargetBuiltins/RISCV.cpp
-  TargetBuiltins/SPIR.cpp
-  TargetBuiltins/SystemZ.cpp
-  TargetBuiltins/WebAssembly.cpp
-  TargetBuiltins/X86.cpp
   TargetInfo.cpp
-  Targets/AArch64.cpp
-  Targets/AMDGPU.cpp
-  Targets/ARC.cpp
-  Targets/ARM.cpp
-  Targets/AVR.cpp
-  Targets/BPF.cpp
-  Targets/CSKY.cpp
-  Targets/DirectX.cpp
-  Targets/Hexagon.cpp
-  Targets/Lanai.cpp
-  Targets/LoongArch.cpp
-  Targets/M68k.cpp
-  Targets/MSP430.cpp
-  Targets/Mips.cpp
-  Targets/NVPTX.cpp
-  Targets/PNaCl.cpp
-  Targets/PPC.cpp
-  Targets/RISCV.cpp
-  Targets/SPIR.cpp
-  Targets/Sparc.cpp
-  Targets/SystemZ.cpp
-  Targets/TCE.cpp
-  Targets/VE.cpp
-  Targets/WebAssembly.cpp
-  Targets/X86.cpp
-  Targets/XCore.cpp
   VarBypassDetector.cpp
-
   DEPENDS
   vt_gen
   intrinsics_gen
@@ -170,4 +133,16 @@ add_clang_library(clangCodeGen
   clangFrontend
   clangLex
   clangSerialization
+  clangCodeGenTargetBuiltins
+  clangCodeGenTargets
+  )
+
+  target_include_directories(clangCodeGen
+PUBLIC
+${CMAKE_CURRENT_SOURCE_DIR}
+${CMAKE_CURRENT_SOURCE_DIR}/TargetBuiltins
+${CMAKE_CURRENT_SOURCE_DIR}/Targets
   )
+  
+  add_subdirectory(TargetBuiltins)
+  add_subdirectory(Targets)
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp 
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index b56b739094ff3..577fee05d4af6 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -1,4 +1,4 @@
-//===--- AMDCPU.cpp - Emit LLVM Code for builtins 
-===//
+//===--- AMDGPU.cpp - Emit LLVM Code for builtins 
-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt 
b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
new file mode 100644
index 0..76be68a11d02a
--- /dev/null
+++ b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
@@ -0,0 +1,14 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargetBuiltins STATIC
+  ARM.cpp
+  AMDGPU.cpp
+  Hexagon.cpp
+  NVPTX.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  SystemZ.cpp
+  WebAssembly.cpp
+  X86.cpp
+)
diff --git a/clang/lib/CodeGen/Targets/CMakeLists.txt 
b/clang/lib/CodeGen/Targets/CMakeLists.txt
new file mode 100644
index 0..6b6e7ce5b0b29
--- /dev/null
+++ b/clang/lib/CodeGen/Targets/CMakeLists.txt
@@ -0,0 +1,30 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargets STATIC
+  AArch64.cpp
+  AMDGPU.cpp
+  ARC.cpp
+  ARM.cpp
+  AVR.cpp
+  BPF.cpp
+  CSKY.cpp
+  DirectX.cpp
+  Hexagon.cpp
+  Lanai.cpp
+  LoongArch.cpp
+  M68k.cpp
+  MSP430.cpp
+  Mips.cpp
+  NVPTX.cpp
+  PNaCl.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  Sparc.cpp
+  SystemZ.cpp
+  TCE.cpp
+  VE.cpp
+  WebAssem

[clang] [CMAKE][AMDGPU] fix build failure caused by PR #133619 (PR #133776)

2025-04-04 Thread Farzon Lotfi via cfe-commits

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


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

2025-04-04 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,142 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -std=c++11  -fptrauth-calls 
-fptrauth-intrinsics -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -std=c++11  -fptrauth-calls 
-fptrauth-intrinsics -verify -fsyntax-only %s
+
+#define AQ __ptrauth(1,1,50)
+#define AQ2 __ptrauth(1,1,51)
+#define IQ __ptrauth(1,0,50)
+
+struct __attribute__((trivial_abi)) AddrDisc { // expected-warning 
{{'trivial_abi' cannot be applied to 'AddrDisc'}} expected-note {{'trivial_abi' 
is disallowed on 'AddrDisc' because it has an address-discriminated '__ptrauth' 
field}}
+  int * AQ m0;
+};
+
+struct __attribute__((trivial_abi)) NoAddrDisc {
+  int * IQ m0;
+};
+
+namespace test_union {
+
+  union U0 {
+int * AQ f0; // expected-note 4 {{'U0' is implicitly deleted because 
variant field 'f0' has an address-discriminated '__ptrauth' qualifier}}
+
+// ptrauth fields that don't have an address-discriminated qualifier don't
+// delete the special functions.
+int * IQ f1;
+  };
+
+  union U1 {
+int * AQ f0; // expected-note 8 {{'U1' is implicitly deleted because 
variant field 'f0' has an address-discriminated '__ptrauth' qualifier}}
+U1() = default;
+~U1() = default;
+U1(const U1 &) = default; // expected-warning {{explicitly defaulted copy 
constructor is implicitly deleted}} expected-note 2 {{explicitly defaulted 
function was implicitly deleted here}} expected-note{{replace 'default'}}
+U1(U1 &&) = default; // expected-warning {{explicitly defaulted move 
constructor is implicitly deleted}} expected-note{{replace 'default'}}
+U1 & operator=(const U1 &) = default; // expected-warning {{explicitly 
defaulted copy assignment operator is implicitly deleted}} expected-note 2 
{{explicitly defaulted function was implicitly deleted here}} 
expected-note{{replace 'default'}}
+U1 & operator=(U1 &&) = default; // expected-warning {{explicitly 
defaulted move assignment operator is implicitly deleted}} 
expected-note{{replace 'default'}}
+  };
+
+  // It's fine if the user has explicitly defined the special functions.
+  union U2 {
+int * AQ f0;
+U2() = default;
+~U2() = default;
+U2(const U2 &);
+U2(U2 &&);
+U2 & operator=(const U2 &);
+U2 & operator=(U2 &&);
+  };
+
+  // Address-discriminated ptrauth fields in anonymous union fields delete the
+  // defaulted copy/move constructors/assignment operators of the containing
+  // class.
+  struct S0 {
+union {
+  int * AQ f0; // expected-note 4 {{' is implicitly deleted because 
variant field 'f0' has an address-discriminated '__ptrauth' qualifier}}
+  char f1;
+};
+  };
+
+  struct S1 {
+union {
+  union {
+int * AQ f0; // expected-note 4 {{implicitly deleted because variant 
field 'f0' has an address-discriminated '__ptrauth' qualifier}}
+char f1;
+  } u; // expected-note 4 {{'S1' is implicitly deleted because field 'u' 
has a deleted}}
+  int f2;
+};
+  };
+
+  U0 *x0;
+  U1 *x1;
+  U2 *x2;
+  S0 *x3;
+  S1 *x4;
+
+  // No diagnostics since constructors/destructors of the unions aren't 
deleted by default.
+  void testDefaultConstructor() {
+U0 u0;
+U1 u1;
+U2 u2;
+S0 s0;
+S1 s1;
+  }
+
+  // No diagnostics since destructors of the unions aren't deleted by default.
+  void testDestructor(U0 *u0, U1 *u1, U2 *u2, S0 *s0, S1 *s1) {
+delete u0;
+delete u1;
+delete u2;
+delete s0;
+delete s1;
+  }
+
+  void testCopyConstructor(U0 *u0, U1 *u1, U2 *u2, S0 *s0, S1 *s1) {
+U0 t0(*u0); // expected-error {{call to implicitly-deleted copy 
constructor}}
+U1 t1(*u1); // expected-error {{call to implicitly-deleted copy 
constructor}}
+U2 t2(*u2);
+S0 t3(*s0); // expected-error {{call to implicitly-deleted copy 
constructor}}
+S1 t4(*s1); // expected-error {{call to implicitly-deleted copy 
constructor}}
+  }
+
+  void testCopyAssignment(U0 *u0, U1 *u1, U2 *u2, S0 *s0, S1 *s1) {
+*x0 = *u0; // expected-error {{cannot be assigned because its copy 
assignment operator is implicitly deleted}}
+*x1 = *u1; // expected-error {{cannot be assigned because its copy 
assignment operator is implicitly deleted}}
+*x2 = *u2;
+*x3 = *s0; // expected-error {{cannot be assigned because its copy 
assignment operator is implicitly deleted}}
+*x4 = *s1; // expected-error {{cannot be assigned because its copy 
assignment operator is implicitly deleted}}
+  }
+
+  void testMoveConstructor(U0 *u0, U1 *u1, U2 *u2, S0 *s0, S1 *s1) {
+U0 t0(static_cast(*u0)); // expected-error {{call to 
implicitly-deleted copy constructor}}
+U1 t1(static_cast(*u1)); // expected-error {{call to 
implicitly-deleted copy constructor}}
+U2 t2(static_cast(*u2));
+S0 t3(static_cast(*s0)); // expected-error {{call to 
implicitly-deleted copy constructor}}
+S1 t4(static_cast(*s1)); // expected-error {{call to 
implicitly-deleted copy constructor}}
+  }
+
+  void testMoveAssignme

[clang] [llvm] Hlsl asuint16 function (PR #132315)

2025-04-04 Thread via cfe-commits

https://github.com/metkarpoonam updated 
https://github.com/llvm/llvm-project/pull/132315

>From 6ce249d7e4bea669480c06a935f88a21894aba67 Mon Sep 17 00:00:00 2001
From: Poonam Vilas Metkar 
Date: Wed, 19 Mar 2025 09:16:30 -0700
Subject: [PATCH 1/9] Add asuint16 intrinsic and codegen test

---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 17 +++
 clang/test/CodeGenHLSL/builtins/asuint16.hlsl | 48 +++
 2 files changed, 65 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/asuint16.hlsl

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index a48a8e998a015..4d06aa7f5e207 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -80,6 +80,23 @@ void asuint(double3, out uint3, out uint3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_splitdouble)
 void asuint(double4, out uint4, out uint4);
 
+//===--===//
+// asuint16 builtins
+//===--===//
+
+/// \fn uint16_t asuint16(T Val)
+/// \brief Interprets the bit pattern of x as an 16-bit unsigned integer.
+/// \param Val The input value.
+#ifdef __HLSL_ENABLE_16BIT
+template  constexpr vector asuint16(vector V) {
+  return __detail::bit_cast(V);
+}
+
+template  constexpr uint16_t asuint16(T F) {
+  return __detail::bit_cast(F);
+}
+#endif
+
 
//===--===//
 // distance builtins
 
//===--===//
diff --git a/clang/test/CodeGenHLSL/builtins/asuint16.hlsl 
b/clang/test/CodeGenHLSL/builtins/asuint16.hlsl
new file mode 100644
index 0..7387520947efe
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/asuint16.hlsl
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple 
dxil-pc-shadermodel6.2-library %s -fnative-half-type -emit-llvm -O1 -o - | 
FileCheck %s
+// CHECK: define {{.*}}test_ints{{.*}}(i16 {{.*}} [[VAL:%.*]]){{.*}}
+// CHECK-NOT: bitcast
+// CHECK: ret i16 [[VAL]]
+uint16_t test_int(int16_t p0)
+{
+return asuint16(p0);
+}
+
+//CHECK: define {{.*}}test_uint{{.*}}(i16 {{.*}} [[VAL:%.*]]){{.*}}
+//CHECK-NOT: bitcast
+//CHECK: ret i16 [[VAL]]
+uint16_t test_uint(uint16_t p0)
+{
+return asuint16(p0);
+}
+
+//CHECK: define {{.*}}test_half{{.*}}(half {{.*}} [[VAL:%.*]]){{.*}}
+//CHECK: [[RES:%.*]] = bitcast half [[VAL]] to i16
+//CHECK : ret i16 [[RES]]
+uint16_t test_half(half p0)
+{
+return asuint16(p0);
+}
+
+//CHECK: define {{.*}}test_vector_int{{.*}}(<4 x i16> {{.*}} [[VAL:%.*]]){{.*}}
+//CHECK-NOT: bitcast
+//CHECK: ret <4 x i16> [[VAL]]
+uint16_t4 test_vector_int(int16_t4 p0)
+{
+return asuint16(p0);
+}
+
+//CHECK: define {{.*}}test_vector_uint{{.*}}(<4 x i16> {{.*}} 
[[VAL:%.*]]){{.*}}
+//CHECK-NOT: bitcast
+//CHECK: ret <4 x i16> [[VAL]]
+uint16_t4 test_vector_uint(uint16_t4 p0)
+{
+return asuint16(p0);
+}
+
+//CHECK: define {{.*}}fn{{.*}}(<4 x half> {{.*}} [[VAL:%.*]]){{.*}}
+//CHECK: [[RES:%.*]] = bitcast <4 x half> [[VAL]] to <4 x i16>
+//CHECK: ret <4 x i16> [[RES]]
+uint16_t4 fn(half4 p1)
+{
+return asuint16(p1);
+}

>From a912b35743a13079679b111702dbe313ec0683ee Mon Sep 17 00:00:00 2001
From: Poonam Vilas Metkar 
Date: Thu, 20 Mar 2025 11:06:29 -0700
Subject: [PATCH 2/9] Update the uint16 function call and add space in
 uint16.hlsl

---
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 23 ++-
 clang/test/CodeGenHLSL/builtins/asuint16.hlsl |  2 ++
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 4d06aa7f5e207..70cbed851f0f0 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -84,15 +84,26 @@ void asuint(double4, out uint4, out uint4);
 // asuint16 builtins
 
//===--===//
 
-/// \fn uint16_t asuint16(T Val)
-/// \brief Interprets the bit pattern of x as an 16-bit unsigned integer.
-/// \param Val The input value.
-#ifdef __HLSL_ENABLE_16BIT
-template  constexpr vector asuint16(vector V) {
+/// \fn uint16_t asuint16(T X)
+/// \brief Interprets the bit pattern of \a X as an 16-bit unsigned integer.
+/// \param X The input value.
+#ifdef __HLSL_ENABLE_16_BIT
+
+template 
+constexpr __detail::enable_if_t<__detail::is_same::value ||
+__detail::is_same::value ||
+__detail::is_same::value,
+vector>
+asuint16(vector V) {
   return __detail::bit_cast(V);
 }
 
-template  constexpr uint16_t asuint16(T F) {
+template 
+constexpr __detail::enable_if_t<__detail::is_same::value ||
+__detail::is_same::value ||
+

[clang] [llvm] [HLSL] Implement dot2add intrinsic (PR #131237)

2025-04-04 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,152 @@
+// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \
+// RUN:   dxil-pc-shadermodel6.3-compute %s -emit-llvm -o - | \
+// RUN:   FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -finclude-default-header -fnative-half-type -triple \
+// RUN:   spirv-pc-vulkan-compute %s -emit-llvm -o - | \
+// RUN:   FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
+
+// Test basic lowering to runtime function call.
+
+// CHECK-LABEL: define {{.*}}test_default_parameter_type
+float test_default_parameter_type(half2 p1, half2 p2, float p3) {
+  // CHECK-SPIRV:  %[[MUL:.*]] = call reassoc nnan ninf nsz arcp afn half 
@llvm.spv.fdot.v2f16(<2 x half> %7, <2 x half> %8)
+  // CHECK-SPIRV:  %[[CONV:.*]] = fpext reassoc nnan ninf nsz arcp afn half 
%[[MUL]] to float
+  // CHECK-SPIRV:  %[[C:.*]] = load float, ptr %c.addr.i, align 4
+  // CHECK-SPIRV:  %[[RES:.*]] = fadd reassoc nnan ninf nsz arcp afn float 
%[[CONV]], %[[C]]
+  // CHECK-DXIL:  %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x 
half> %6, <2 x half> %7, float %8)

farzonl wrote:

We don't typically lile to capture the register arguments because doing so can 
make the tests brittle to future changes and force updates if a register name 
changes instead do what sarah is doing here:
https://github.com/llvm/llvm-project/pull/133941/files `{{.*}}`.
```suggestion
  // CHECK-DXIL:  %[[RES:.*]] = call {{.*}} float @llvm.dx.dot2add.v2f16(<2 x 
half> %{{.*}}, <2 x half> %{{.*}}, float %{{.*}})
```

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


[clang] [llvm] [HLSL] Implement dot2add intrinsic (PR #131237)

2025-04-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Sumit Agarwal (sumitsays)


Changes

Resolves #99221 
Key points: For SPIRV backend, it decompose into a `dot` followed a `add`.

- [x] Implement dot2add clang builtin,
- [x] Link dot2add clang builtin with hlsl_intrinsics.h
- [x] Add sema checks for dot2add to CheckHLSLBuiltinFunctionCall in 
SemaHLSL.cpp
- [x] Add codegen for dot2add to EmitHLSLBuiltinExpr in CGBuiltin.cpp
- [x] Add codegen tests to clang/test/CodeGenHLSL/builtins/dot2add.hlsl
- [x] Add sema tests to clang/test/SemaHLSL/BuiltIns/dot2add-errors.hlsl
- [x] Create the int_dx_dot2add intrinsic in IntrinsicsDirectX.td
- [x] Create the DXILOpMapping of int_dx_dot2add to 162 in DXIL.td
- [x] Create the dot2add.ll and dot2add_errors.ll tests in 
llvm/test/CodeGen/DirectX/
- [ ] ~~Create the int_spv_dot2add intrinsic in IntrinsicsSPIRV.td~~ --- Not 
needed
- [ ] ~~In SPIRVInstructionSelector.cpp create the dot2add lowering and map it 
to int_spv_dot2add in SPIRVInstructionSelector::selectIntrinsic.~~ --- Not 
needed
- [ ] ~~Create SPIR-V backend test case in 
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/dot2add.ll~~ --- Not needed

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


11 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+15) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h (+8) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+12) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+50-9) 
- (added) clang/test/CodeGenHLSL/builtins/dot2add.hlsl (+17) 
- (added) clang/test/SemaHLSL/BuiltIns/Dot2Add-errors.hlsl (+11) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+4) 
- (modified) llvm/lib/Target/DirectX/DXIL.td (+11) 
- (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+47-2) 
- (added) llvm/test/CodeGen/DirectX/dot2add.ll (+8) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 72a5e495c4059..76ab463ca0ed6 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4891,6 +4891,12 @@ def HLSLDotProduct : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLDot2Add : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_dot2add"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 def HLSLDot4AddI8Packed : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_dot4add_i8packed"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c126f88b9e3a5..b3d9db5be7d8d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19681,6 +19681,21 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 getDotProductIntrinsic(CGM.getHLSLRuntime(), VecTy0->getElementType()),
 ArrayRef{Op0, Op1}, nullptr, "hlsl.dot");
   }
+  case Builtin::BI__builtin_hlsl_dot2add: {
+llvm::Triple::ArchType Arch = CGM.getTarget().getTriple().getArch();
+if (Arch != llvm::Triple::dxil) {
+  llvm_unreachable("Intrinsic dot2add can be executed as a builtin only on 
dxil");
+}
+Value *A = EmitScalarExpr(E->getArg(0));
+Value *B = EmitScalarExpr(E->getArg(1));
+Value *C = EmitScalarExpr(E->getArg(2));
+
+//llvm::Intrinsic::dx_##IntrinsicPostfix
+Intrinsic::ID ID = llvm ::Intrinsic::dx_dot2add;
+return Builder.CreateIntrinsic(
+/*ReturnType=*/C->getType(), ID, ArrayRef{A, B, C}, nullptr,
+"hlsl.dot2add");
+  }
   case Builtin::BI__builtin_hlsl_dot4add_i8packed: {
 Value *A = EmitScalarExpr(E->getArg(0));
 Value *B = EmitScalarExpr(E->getArg(1));
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
index 5f7c047dbf340..46653d7b295b2 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h
@@ -45,6 +45,14 @@ distance_vec_impl(vector X, vector Y) {
   return length_vec_impl(X - Y);
 }
 
+constexpr float dot2add_impl(half2 a, half2 b, float c) {
+#if defined(__DIRECTX__)
+  return __builtin_hlsl_dot2add(a, b, c);
+#else
+  return dot(a, b) + c;
+#endif
+}
+
 template  constexpr T reflect_impl(T I, T N) {
   return I - 2 * N * I * N;
 }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 5459cbeb34fd0..b1c1335ce3328 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -117,6 +117,18 @@ const inline float 
distance(__detail::HLSL_FIXED_VECTOR X,
   return __detail::distance_vec_impl(X, Y);
 }
 
+//===--===//
+// dot2add builtins
+//===--===//
+
+/// \fn float dot2add(half2 a, half2 b, float c)

[clang] [llvm] [LLVM][Clang][Cygwin] Fix Cygwin builds (PR #134458)

2025-04-04 Thread Mateusz Mikuła via cfe-commits

https://github.com/mati865 updated 
https://github.com/llvm/llvm-project/pull/134458

From adbcc7f650edfb4f2f86d1146b8116794a9de6df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= 
Date: Sat, 8 Feb 2025 01:13:06 +0100
Subject: [PATCH 1/4] [Clang][Cygwin] Enable few conditions that are shared
 with MinGW

---
 clang/lib/AST/ItaniumCXXABI.cpp   | 3 +--
 clang/lib/AST/RecordLayoutBuilder.cpp | 2 +-
 clang/lib/CodeGen/CodeGenModule.cpp   | 2 +-
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 7 ++-
 clang/lib/CodeGen/Targets/X86.cpp | 2 +-
 clang/lib/Driver/ToolChain.cpp| 4 +---
 clang/lib/Sema/SemaDecl.cpp   | 2 +-
 clang/lib/Sema/SemaDeclCXX.cpp| 4 ++--
 clang/lib/Sema/SemaTemplate.cpp   | 9 -
 9 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/clang/lib/AST/ItaniumCXXABI.cpp b/clang/lib/AST/ItaniumCXXABI.cpp
index a1b2551419f5e..11d8bbe8b24ba 100644
--- a/clang/lib/AST/ItaniumCXXABI.cpp
+++ b/clang/lib/AST/ItaniumCXXABI.cpp
@@ -236,8 +236,7 @@ class ItaniumCXXABI : public CXXABI {
 
   CallingConv getDefaultMethodCallConv(bool isVariadic) const override {
 const llvm::Triple &T = Context.getTargetInfo().getTriple();
-if (!isVariadic && T.isWindowsGNUEnvironment() &&
-T.getArch() == llvm::Triple::x86)
+if (!isVariadic && T.isOSCygMing() && T.getArch() == llvm::Triple::x86)
   return CC_X86ThisCall;
 return Context.getTargetInfo().getDefaultCallingConv();
   }
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 3e756ab9b9bfe..43b54850598af 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1950,7 +1950,7 @@ void ItaniumRecordLayoutBuilder::LayoutField(const 
FieldDecl *D,
   // silently there. For other targets that have ms_struct enabled
   // (most probably via a pragma or attribute), trigger a diagnostic
   // that defaults to an error.
-  if (!Context.getTargetInfo().getTriple().isWindowsGNUEnvironment())
+  if (!Context.getTargetInfo().getTriple().isOSCygMing())
 Diag(D->getLocation(), diag::warn_npot_ms_struct);
 }
 if (TypeSize > FieldAlign &&
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 8f9cf965af2b9..f4cf4f8ae7c0d 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1680,7 +1680,7 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
 
   const llvm::Triple &TT = CGM.getTriple();
   const auto &CGOpts = CGM.getCodeGenOpts();
-  if (TT.isWindowsGNUEnvironment()) {
+  if (TT.isOSCygMing()) {
 // In MinGW, variables without DLLImport can still be automatically
 // imported from a DLL by the linker; don't mark variables that
 // potentially could come from another DLL as DSO local.
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 2822d526a54b0..153bafc45740a 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3757,7 +3757,7 @@ static bool ShouldUseExternalRTTIDescriptor(CodeGenModule 
&CGM,
 bool IsDLLImport = RD->hasAttr();
 
 // Don't import the RTTI but emit it locally.
-if (CGM.getTriple().isWindowsGNUEnvironment())
+if (CGM.getTriple().isOSCygMing())
   return false;
 
 if (CGM.getVTables().isVTableExternal(RD)) {
@@ -4044,10 +4044,7 @@ static llvm::GlobalVariable::LinkageTypes 
getTypeInfoLinkage(CodeGenModule &CGM,
   return llvm::GlobalValue::ExternalLinkage;
   // MinGW always uses LinkOnceODRLinkage for type info.
   if (RD->isDynamicClass() &&
-  !CGM.getContext()
-   .getTargetInfo()
-   .getTriple()
-   .isWindowsGNUEnvironment())
+  !CGM.getContext().getTargetInfo().getTriple().isOSCygMing())
 return CGM.getVTableLinkage(RD);
 }
 
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index b36a6e1396653..cb09c52856744 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1391,7 +1391,7 @@ class WinX86_64ABIInfo : public ABIInfo {
 public:
   WinX86_64ABIInfo(CodeGen::CodeGenTypes &CGT, X86AVXABILevel AVXLevel)
   : ABIInfo(CGT), AVXLevel(AVXLevel),
-IsMingw64(getTarget().getTriple().isWindowsGNUEnvironment()) {}
+IsMingw64(getTarget().getTriple().isOSCygMing()) {}
 
   void computeInfo(CGFunctionInfo &FI) const override;
 
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 36d0ae34dec86..37e1e65310fbb 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -744,9 +744,7 @@ std::string ToolChain::buildCompilerRTBasename(const 
llvm::opt::ArgList &Args,
 Suffix = IsITANMSVCWindows ? ".lib" : ".a";
 break;
   case ToolChain::FT_Shared:
-Suffix = TT.isOSWindows()
- ? (

[clang] [llvm] [fatlto] Use the ThinLTO default pipeline for FatLTO (PR #134434)

2025-04-04 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/134434

>From 80c36153e55398bee01e0167e722c930732b48e7 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 4 Apr 2025 11:49:02 -0700
Subject: [PATCH 1/2] [fatlto] Add coroutine passes when using FatLTO with
 ThinLTO

When coroutines are used w/ both -ffat-lto-objects and -flto=thin,
the coroutine passes are not added to the optimization pipelines.
Ensure they are added before ModuleOptimization to generate a working
ELF object.

Fixes #134409.
---
 clang/test/CodeGenCoroutines/pr134409.cpp | 43 +++
 llvm/lib/Passes/PassBuilderPipelines.cpp  | 13 +++
 2 files changed, 56 insertions(+)
 create mode 100644 clang/test/CodeGenCoroutines/pr134409.cpp

diff --git a/clang/test/CodeGenCoroutines/pr134409.cpp 
b/clang/test/CodeGenCoroutines/pr134409.cpp
new file mode 100644
index 0..0e56e4efb0067
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/pr134409.cpp
@@ -0,0 +1,43 @@
+// An end-to-end test to make sure coroutine passes are added for thinlto.
+
+// RUN: %clang_cc1 -std=c++23 -ffat-lto-objects -flto=thin -emit-llvm %s -O3 
-o - \
+// RUN:  | FileCheck %s
+
+#include "Inputs/coroutine.h"
+
+class BasicCoroutine {
+public:
+struct Promise {
+BasicCoroutine get_return_object() { return BasicCoroutine {}; }
+
+void unhandled_exception() noexcept { }
+
+void return_void() noexcept { }
+
+std::suspend_never initial_suspend() noexcept { return {}; }
+std::suspend_never final_suspend() noexcept { return {}; }
+};
+using promise_type = Promise;
+};
+
+// COM: match the embedded module, so we don't match something in it by 
accident.
+// CHECK: @llvm.embedded.object = {{.*}}
+// CHECK: @llvm.compiler.used = {{.*}}
+
+BasicCoroutine coro() {
+// CHECK: define {{.*}} void @_Z4corov() {{.*}} {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+// CHECK-NEXT: }
+co_return;
+}
+
+int main() {
+// CHECK: define {{.*}} i32 @main() {{.*}} {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: tail call void @_Z4corov()
+// CHECK-NEXT: ret i32 0
+// CHECK-NEXT: }
+coro();
+}
+
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index a18b36ba40754..f222dbede7da7 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1692,6 +1692,19 @@ 
PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
   if (ThinLTO && PGOOpt && PGOOpt->Action == PGOOptions::SampleUse)
 MPM.addPass(buildThinLTODefaultPipeline(Level, /*ImportSummary=*/nullptr));
   else {
+// ModuleSimplification does not run the coroutine passes for
+// ThinLTOPreLink, so we need the coroutine passes to run for ThinLTO
+// builds, otherwise they will miscompile.
+if (ThinLTO) {
+  // TODO: replace w/ buildCoroWrapper() when it takes phase and level into
+  // consideration.
+  CGSCCPassManager CGPM;
+  CGPM.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  CGPM.addPass(CoroAnnotationElidePass());
+  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
+  MPM.addPass(CoroCleanupPass());
+}
+
 // otherwise, just use module optimization
 MPM.addPass(
 buildModuleOptimizationPipeline(Level, ThinOrFullLTOPhase::None));

>From fb945cf2d3b9e05123dc95f1d2efae75fc40b6c0 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 4 Apr 2025 16:02:47 -0700
Subject: [PATCH 2/2] Restrict test to only target ELF

---
 clang/test/CodeGenCoroutines/pr134409.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGenCoroutines/pr134409.cpp 
b/clang/test/CodeGenCoroutines/pr134409.cpp
index 0e56e4efb0067..142962d44ede4 100644
--- a/clang/test/CodeGenCoroutines/pr134409.cpp
+++ b/clang/test/CodeGenCoroutines/pr134409.cpp
@@ -1,6 +1,6 @@
 // An end-to-end test to make sure coroutine passes are added for thinlto.
-
-// RUN: %clang_cc1 -std=c++23 -ffat-lto-objects -flto=thin -emit-llvm %s -O3 
-o - \
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++23 
-ffat-lto-objects -flto=thin -emit-llvm %s -O3 -o - \
 // RUN:  | FileCheck %s
 
 #include "Inputs/coroutine.h"

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


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

2025-04-04 Thread Trevor Gross via cfe-commits


@@ -3,6 +3,18 @@
 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 | FileCheck %s
 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 | FileCheck %s
 
+; Test f16.
+declare half @llvm.fabs.f16(half %f)
+define half @f0(half %f) {
+; CHECK-LABEL: f0:
+; CHECK:  brasl %r14, __extendhfsf2@PLT
+; CHECK-NEXT: lpdfr %f0, %f0
+; CHECK-NEXT: brasl %r14, __truncsfhf2@PLT
+; CHECK: br %r14

tgross35 wrote:

Similarly `fabs `could be `a & !SIGN_MASK`. It looks like aarch64 uses this, 
x86 still seems to extend then truncate for whatever reason.

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


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

2025-04-04 Thread Trevor Gross via cfe-commits

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


[clang] [clang] fix partial ordering of NTTP packs (PR #134461)

2025-04-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

This fixes partial ordering of pack expansions of NTTPs, by procedding with the 
check using the pattern of the NTTP through the rules of the non-pack case.

This also unifies almost all of the different versions of 
FinishTemplateArgumentDeduction (except the function template case). This makes 
sure they all follow the rules consistently, instantiating the parameters and 
comparing those with the argument.

Fixes #132562

---

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


15 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/AST/ExprCXX.h (+3-3) 
- (modified) clang/include/clang/Sema/Sema.h (+9-8) 
- (modified) clang/lib/AST/ASTContext.cpp (+1-2) 
- (modified) clang/lib/AST/ASTImporter.cpp (+3-4) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+4-4) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+161-111) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+107-174) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+4-4) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+1-2) 
- (modified) clang/lib/Sema/TreeTransform.h (+1-2) 
- (modified) clang/test/Import/pack-expansion-expr/test.cpp (+1-1) 
- (modified) clang/test/SemaTemplate/attributes.cpp (+11-11) 
- (modified) clang/test/SemaTemplate/partial-order.cpp (+38-3) 
- (modified) clang/test/SemaTemplate/temp_arg_nontype.cpp (+9-7) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c521b56a98606..6756b0d924be6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -385,6 +385,7 @@ Bug Fixes to C++ Support
 - Improved fix for an issue with pack expansions of type constraints, where 
this
   now also works if the constraint has non-type or template template 
parameters.
   (#GH131798)
+- Fixes to partial ordering of non-type template parameter packs. (#GH132562)
 - Fix crash when evaluating the trailing requires clause of generic lambdas 
which are part of
   a pack expansion.
 - Fixes matching of nested template template parameters. (#GH130362)
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index ac78d2faefe42..c613ce162a6a4 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -4209,10 +4209,10 @@ class PackExpansionExpr : public Expr {
   Stmt *Pattern;
 
 public:
-  PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc,
+  PackExpansionExpr(Expr *Pattern, SourceLocation EllipsisLoc,
 UnsignedOrNone NumExpansions)
-  : Expr(PackExpansionExprClass, T, Pattern->getValueKind(),
- Pattern->getObjectKind()),
+  : Expr(PackExpansionExprClass, Pattern->getType(),
+ Pattern->getValueKind(), Pattern->getObjectKind()),
 EllipsisLoc(EllipsisLoc),
 NumExpansions(NumExpansions ? *NumExpansions + 1 : 0),
 Pattern(Pattern) {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b835697f99670..0f4377540bb51 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10126,13 +10126,14 @@ class Sema final : public SemaBase {
 
   /// Contexts in which a converted constant expression is required.
   enum CCEKind {
-CCEK_CaseValue,///< Expression in a case label.
-CCEK_Enumerator,   ///< Enumerator value with fixed underlying type.
-CCEK_TemplateArg,  ///< Value of a non-type template parameter.
-CCEK_InjectedTTP,  ///< Injected parameter of a template template 
parameter.
-CCEK_ArrayBound,   ///< Array bound in array declarator or new-expression.
-CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier.
-CCEK_Noexcept, ///< Condition in a noexcept(bool) specifier.
+CCEK_CaseValue, ///< Expression in a case label.
+CCEK_Enumerator,///< Enumerator value with fixed underlying type.
+CCEK_TemplateArg,   ///< Value of a non-type template parameter.
+CCEK_TempArgStrict, ///< As above, but applies strict template checking
+///< rules.
+CCEK_ArrayBound,///< Array bound in array declarator or new-expression.
+CCEK_ExplicitBool,  ///< Condition in an explicit(bool) specifier.
+CCEK_Noexcept,  ///< Condition in a noexcept(bool) specifier.
 CCEK_StaticAssertMessageSize, ///< Call to size() in a static assert
   ///< message.
 CCEK_StaticAssertMessageData, ///< Call to data() in a static assert
@@ -11894,7 +11895,7 @@ class Sema final : public SemaBase {
QualType InstantiatedParamType, Expr *Arg,
TemplateArgument &SugaredConverted,
TemplateArgument &CanonicalConverted,
-   bool Match

[clang] [llvm] [HLSL] Implement dot2add intrinsic (PR #131237)

2025-04-04 Thread Farzon Lotfi via cfe-commits


@@ -45,6 +45,14 @@ distance_vec_impl(vector X, vector Y) {
   return length_vec_impl(X - Y);
 }
 
+constexpr float dot2add_impl(half2 a, half2 b, float c) {
+#if defined(__DIRECTX__)

farzonl wrote:

there is no lowercase `__directx__`. and the lowercase spirv one was only just 
added last week so you won't see any code in our headers use lowercase 
`__spirv__` either.

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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-04-04 Thread Shilei Tian via cfe-commits

https://github.com/shiltian commented:

This is worth a release note item.

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


[clang] [clang] [sanitizer] predict trap checks succeed (PR #134310)

2025-04-04 Thread Thurston Dang via cfe-commits

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


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


[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-04 Thread Deric C. via cfe-commits

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


[clang] [clang] [sanitizer] predict trap checks succeed (PR #134310)

2025-04-04 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/134310

>From 44f9ccd6b4104fb07ad9cf9581c41c6d473525ec Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Thu, 3 Apr 2025 14:53:29 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/CGExpr.cpp  |  7 --
 clang/test/CodeGen/ubsan-trap-merge.c | 32 +--
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 3d3a111f0514a..56e5654bcf7e0 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3977,16 +3977,19 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value 
*Checked,
   NoMerge = NoMerge || !CGM.getCodeGenOpts().OptimizationLevel ||
 (CurCodeDecl && CurCodeDecl->hasAttr());
 
+  llvm::MDBuilder MDHelper(getLLVMContext());
   if (TrapBB && !NoMerge) {
 auto Call = TrapBB->begin();
 assert(isa(Call) && "Expected call in trap BB");
 
 Call->applyMergedLocation(Call->getDebugLoc(),
   Builder.getCurrentDebugLocation());
-Builder.CreateCondBr(Checked, Cont, TrapBB);
+Builder.CreateCondBr(Checked, Cont, TrapBB,
+ MDHelper.createLikelyBranchWeights());
   } else {
 TrapBB = createBasicBlock("trap");
-Builder.CreateCondBr(Checked, Cont, TrapBB);
+Builder.CreateCondBr(Checked, Cont, TrapBB,
+ MDHelper.createLikelyBranchWeights());
 EmitBlock(TrapBB);
 
 llvm::CallInst *TrapCall =
diff --git a/clang/test/CodeGen/ubsan-trap-merge.c 
b/clang/test/CodeGen/ubsan-trap-merge.c
index 486aa55f5b811..12344affe3ad6 100644
--- a/clang/test/CodeGen/ubsan-trap-merge.c
+++ b/clang/test/CodeGen/ubsan-trap-merge.c
@@ -1,3 +1,4 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
 // NOTE: Assertions have mostly been autogenerated by 
utils/update_cc_test_checks.py UTC_ARGS: --version 5
 // The most important assertions are the attributes at the end of the file, 
which
 // show whether -ubsan-unique-traps and -fno-sanitize-merge attach 'nomerge'
@@ -64,7 +65,7 @@
 // TRAP-NOMERGE-NEXT:  [[ENTRY:.*:]]
 // TRAP-NOMERGE-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } 
@llvm.sadd.with.overflow.i32(i32 [[X]], i32 125), !nosanitize [[META2:![0-9]+]]
 // TRAP-NOMERGE-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, 
!nosanitize [[META2]]
-// TRAP-NOMERGE-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label 
%[[CONT:.*]], !nosanitize [[META2]]
+// TRAP-NOMERGE-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label 
%[[CONT:.*]], !prof [[PROF3:![0-9]+]], !nosanitize [[META2]]
 // TRAP-NOMERGE:   [[TRAP]]:
 // TRAP-NOMERGE-NEXT:tail call void @llvm.ubsantrap(i8 0) 
#[[ATTR4:[0-9]+]], !nosanitize [[META2]]
 // TRAP-NOMERGE-NEXT:unreachable, !nosanitize [[META2]]
@@ -104,7 +105,7 @@
 // TRAP-MERGE-NEXT:  [[ENTRY:.*:]]
 // TRAP-MERGE-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } 
@llvm.sadd.with.overflow.i32(i32 [[X]], i32 125), !nosanitize [[META2:![0-9]+]]
 // TRAP-MERGE-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, 
!nosanitize [[META2]]
-// TRAP-MERGE-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], 
!nosanitize [[META2]]
+// TRAP-MERGE-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], 
!prof [[PROF3:![0-9]+]], !nosanitize [[META2]]
 // TRAP-MERGE:   [[TRAP]]:
 // TRAP-MERGE-NEXT:tail call void @llvm.ubsantrap(i8 0) #[[ATTR4:[0-9]+]], 
!nosanitize [[META2]]
 // TRAP-MERGE-NEXT:unreachable, !nosanitize [[META2]]
@@ -187,7 +188,7 @@ int f(int x) {
 // TRAP-NOMERGE-NEXT:  [[ENTRY:.*:]]
 // TRAP-NOMERGE-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } 
@llvm.sadd.with.overflow.i32(i32 [[X]], i32 127), !nosanitize [[META2]]
 // TRAP-NOMERGE-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, 
!nosanitize [[META2]]
-// TRAP-NOMERGE-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label 
%[[CONT:.*]], !nosanitize [[META2]]
+// TRAP-NOMERGE-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label 
%[[CONT:.*]], !prof [[PROF3]], !nosanitize [[META2]]
 // TRAP-NOMERGE:   [[TRAP]]:
 // TRAP-NOMERGE-NEXT:tail call void @llvm.ubsantrap(i8 0) #[[ATTR4]], 
!nosanitize [[META2]]
 // TRAP-NOMERGE-NEXT:unreachable, !nosanitize [[META2]]
@@ -227,7 +228,7 @@ int f(int x) {
 // TRAP-MERGE-NEXT:  [[ENTRY:.*:]]
 // TRAP-MERGE-NEXT:[[TMP0:%.*]] = tail call { i32, i1 } 
@llvm.sadd.with.overflow.i32(i32 [[X]], i32 127), !nosanitize [[META2]]
 // TRAP-MERGE-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1, 
!nosanitize [[META2]]
-// TRAP-MERGE-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]], label %[[CONT:.*]], 
!nosanitize [[META2]]
+// TRAP-MERGE-NEXT:br i1 [[TMP1]], label %[[TRAP:.*]]

[clang] [HLSL] Implement the `lit` intrinsic (PR #134171)

2025-04-04 Thread Deric C. via cfe-commits

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


[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Erich Keane via cfe-commits


@@ -462,6 +462,58 @@ def ReturnOp : CIR_Op<"return", [ParentOneOf<["FuncOp", 
"ScopeOp", "DoWhileOp",
   let hasVerifier = 1;
 }
 
+//===--===//
+// IfOp
+//===--===//
+
+def IfOp : CIR_Op<"if",
+ [DeclareOpInterfaceMethods,
+ RecursivelySpeculatable, AutomaticAllocationScope, NoRegionArguments]>{
+
+  let summary = "the if-then-else operation";
+  let description = [{
+The `cir.if` operation represents an if-then-else construct for
+conditionally executing two regions of code. The operand is a `cir.bool`
+type.
+
+Examples:
+
+```mlir
+cir.if %b  {

erichkeane wrote:

FWIW, I feel the above conversation/future directions is enough for me, so 
discuss/evolve as we go, but feel free to move on with the current 
representaiton here.

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


[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits

andykaylor wrote:

> @Andres-Salamanca thanks for working on this. We usually write tests that 
> exercise any possible different paths codegen can take. For next rounds: it's 
> fine if you add less things in one go and make it more incremental with the 
> use of (a) errorNYI and (b) assert on missing features.

We should probably make it a standard practice when upstreaming new ops like 
this that if the change goes above 500 lines or so, we should leave the 
lowering to LLVM IR and related transformations for a follow-up PR.

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


[clang] [HLSL][RootSignature] Define and integrate `HLSLRootSignatureAttr` (PR #134124)

2025-04-04 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`libc-x86_64-debian-dbg-bootstrap-build` running on `libc-x86_64-debian` while 
building `clang` at step 4 "annotate".

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


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

```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[646/658] Building CXX object 
tools/clang/tools/driver/CMakeFiles/clang.dir/cc1_main.cpp.o
[647/658] Linking CXX executable bin/sancov
[648/658] Building CXX object 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/WebKit/RetainPtrCtorAdoptChecker.cpp.o
[649/658] Linking CXX executable bin/llvm-jitlink
[650/658] Linking CXX static library lib/libclangStaticAnalyzerCheckers.a
[651/658] Linking CXX static library lib/libclangStaticAnalyzerFrontend.a
[652/658] Linking CXX static library lib/libclangFrontendTool.a
[653/658] Linking CXX executable bin/lli
[654/658] Linking CXX executable bin/opt
[655/658] Linking CXX executable bin/clang-20
FAILED: bin/clang-20 
: && /usr/bin/clang++ -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-fno-common -Woverloaded-virtual -Wno-nested-anon-types -g -Wl,--export-dynamic 
 
-Wl,-rpath-link,/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian/libc-x86_64-debian-dbg-bootstrap-build/build/./lib
 tools/clang/tools/driver/CMakeFiles/clang.dir/driver.cpp.o 
tools/clang/tools/driver/CMakeFiles/clang.dir/cc1_main.cpp.o 
tools/clang/tools/driver/CMakeFiles/clang.dir/cc1as_main.cpp.o 
tools/clang/tools/driver/CMakeFiles/clang.dir/cc1gen_reproducer_main.cpp.o 
tools/clang/tools/driver/CMakeFiles/clang.dir/clang-driver.cpp.o -o 
bin/clang-20  -Wl,-rpath,"\$ORIGIN/../lib:"  lib/libLLVMAArch64CodeGen.a  
lib/libLLVMAArch64AsmParser.a  lib/libLLVMAArch64Desc.a  
lib/libLLVMAArch64Disassembler.a  lib/libLLVMAArch64Info.a  
lib/libLLVMAArch64Utils.a  lib/libLLVMAMDGPUCodeGen.a  
lib/libLLVMAMDGPUAsmParser.a  lib/libLLVMAMDGPUDesc.a  
lib/libLLVMAMDGPUDisassembler.a  lib/libLLVMAMDGPUInfo.a  
lib/libLLVMAMDGPUUtils.a  lib/libLLVMARMCodeGen.a  lib/libLLVMARMAsmParser.a  
lib/libLLVMARMDesc.a  lib/libLLVMARMDisassembler.a  lib/libLLVMARMInfo.a  
lib/libLLVMARMUtils.a  lib/libLLVMAVRCodeGen.a  lib/libLLVMAVRAsmParser.a  
lib/libLLVMAVRDesc.a  lib/libLLVMAVRDisassembler.a  lib/libLLVMAVRInfo.a  
lib/libLLVMBPFCodeGen.a  lib/libLLVMBPFAsmParser.a  lib/libLLVMBPFDesc.a  
lib/libLLVMBPFDisassembler.a  lib/libLLVMBPFInfo.a  lib/libLLVMHexagonCodeGen.a 
 lib/libLLVMHexagonAsmParser.a  lib/libLLVMHexagonDesc.a  
lib/libLLVMHexagonDisassembler.a  lib/libLLVMHexagonInfo.a  
lib/libLLVMLanaiCodeGen.a  lib/libLLVMLanaiAsmParser.a  lib/libLLVMLanaiDesc.a  
lib/libLLVMLanaiDisassembler.a  lib/libLLVMLanaiInfo.a  
lib/libLLVMLoongArchCodeGen.a  lib/libLLVMLoongArchAsmParser.a  
lib/libLLVMLoongArchDesc.a  lib/libLLVMLoongArchDisassembler.a  
lib/libLLVMLoongArchInfo.a  lib/libLLVMMipsCodeGen.a  
lib/libLLVMMipsAsmParser.a  lib/libLLVMMipsDesc.a  
lib/libLLVMMipsDisassembler.a  lib/libLLVMMipsInfo.a  
lib/libLLVMMSP430CodeGen.a  lib/libLLVMMSP430AsmParser.a  
lib/libLLVMMSP430Desc.a  lib/libLLVMMSP430Disassembler.a  
lib/libLLVMMSP430Info.a  lib/libLLVMNVPTXCodeGen.a  lib/libLLVMNVPTXDesc.a  
lib/libLLVMNVPTXInfo.a  lib/libLLVMPowerPCCodeGen.a  
lib/libLLVMPowerPCAsmParser.a  lib/libLLVMPowerPCDesc.a  
lib/libLLVMPowerPCDisassembler.a  lib/libLLVMPowerPCInfo.a  
lib/libLLVMRISCVCodeGen.a  lib/libLLVMRISCVAsmParser.a  lib/libLLVMRISCVDesc.a  
lib/libLLVMRISCVDisassembler.a  lib/libLLVMRISCVInfo.a  
lib/libLLVMSparcCodeGen.a  lib/libLLVMSparcAsmParser.a  lib/libLLVMSparcDesc.a  
lib/libLLVMSparcDisassembler.a  lib/libLLVMSparcInfo.a  
lib/libLLVMSPIRVCodeGen.a  lib/libLLVMSPIRVDesc.a  lib/libLLVMSPIRVInfo.a  
lib/libLLVMSystemZCodeGen.a  lib/libLLVMSystemZAsmParser.a  
lib/libLLVMSystemZDesc.a  lib/libLLVMSystemZDisassembler.a  
lib/libLLVMSystemZInfo.a  lib/libLLVMVECodeGen.a  lib/libLLVMVEAsmParser.a  
lib/libLLVMVEDesc.a  lib/libLLVMVEDisassembler.a  lib/libLLVMVEInfo.a  
lib/libLLVMWebAssemblyCodeGen.a  lib/libLLVMWebAssemblyAsmParser.a  
lib/libLLVMWebAssemblyDesc.a  lib/libLLVMWebAssemblyDisassembler.a  
lib/libLLVMWebAssemblyInfo.a  lib/libLLVMWebAssemblyUtils.a  
lib/libLLVMX86CodeGen.a  lib/libLLVMX86AsmParser.a  lib/libLLVMX86Desc.a  
lib/libLLVMX86Disassembler.a  lib/libLLVMX86Info.a  lib/libLLVMXCoreCodeGen.a  
lib/libLLVMXCoreDesc.a  lib/libLLVMXCoreDisassembler.a  l

[clang] [llvm] [DirectX] Add target builtins (PR #134439)

2025-04-04 Thread Deric C. via cfe-commits

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


[clang] [llvm] [DirectX] Add target builtins (PR #134439)

2025-04-04 Thread Deric C. via cfe-commits

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

I like this change. It helps makes implementing builtins more consistent 
between SPIR-V and DirectX/DXIL

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


[clang] [Clang] Link libgcc_s.1.dylib when building for macOS 10.5 and older (PR #124651)

2025-04-04 Thread via cfe-commits

https://github.com/Un1q32 updated 
https://github.com/llvm/llvm-project/pull/124651

>From d4e97c4113086c3d2dfa3bf6e9ecfee377f8c4b6 Mon Sep 17 00:00:00 2001
From: Un1q32 
Date: Mon, 27 Jan 2025 18:00:34 -0500
Subject: [PATCH 1/3] [Clang] Link libgcc_s.1.dylib when building for macOS
 10.5 and older

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 9 +
 clang/test/Driver/darwin-ld.c  | 7 ++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 55c55bad73934..67f27a599b4c3 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1645,12 +1645,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 CmdArgs.push_back("-lSystem");
 
   // Select the dynamic runtime library and the target specific static library.
-  if (isTargetIOSBased()) {
+  if (isTargetIOSBased() || isTargetMacOSBased()) {
 // If we are compiling as iOS / simulator, don't attempt to link 
libgcc_s.1,
 // it never went into the SDK.
-// Linking against libgcc_s.1 isn't needed for iOS 5.0+
-if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
-getTriple().getArch() != llvm::Triple::aarch64)
+// Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+
+if ((isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
+ getTriple().getArch() != llvm::Triple::aarch64) ||
+isMacosxVersionLT(10, 6))
   CmdArgs.push_back("-lgcc_s.1");
   }
   AddLinkRuntimeLib(Args, CmdArgs, "builtins");
diff --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c
index f0ca411430cc7..5b10daaf007a2 100644
--- a/clang/test/Driver/darwin-ld.c
+++ b/clang/test/Driver/darwin-ld.c
@@ -240,6 +240,11 @@
 // RUN: FileCheck -check-prefix=LINK_NO_IOS_ARM64_LIBGCC_S %s < %t.log
 // LINK_NO_IOS_ARM64_LIBGCC_S-NOT: lgcc_s.1
 
+// Check that clang links with libgcc_s.1 for macOS 10.5 and earlier
+// RUN: %clang -target x86_64-apple-macos10.5 -mmacosx-version-min=10.5 -### 
%t.o 2> %t.log
+// RUN: FileCheck -check-prefix=LINK_OSX_LIBGCC_S %s < %t.log
+// LINK_OSX_LIBGCC_S: lgcc_s.1
+
 // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
 // RUN:   -fuse-ld= -mlinker-version=100 2> %t.log
 // RUN: FileCheck -check-prefix=LINK_NO_EXPORT_DYNAMIC %s < %t.log
@@ -385,4 +390,4 @@
 // RUN:   %clang -target armv7em-apple-darwin -mno-outline -### %t.o 2> %t.log
 // RUN: FileCheck -check-prefix=ARMV7EM-MNO_OUTLINE %s < %t.log
 // ARMV7EM-MNO_OUTLINE: {{ld(.exe)?"}}
-// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" 
"-mllvm" "-enable-linkonceodr-outlining"
\ No newline at end of file
+// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" 
"-mllvm" "-enable-linkonceodr-outlining"

>From 4407312c3b8f2edfd9279183a9d4fae316639469 Mon Sep 17 00:00:00 2001
From: Un1q32 
Date: Mon, 27 Jan 2025 18:59:53 -0500
Subject: [PATCH 2/3] fix

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 67f27a599b4c3..82f7d4597d0c7 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1645,15 +1645,15 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 CmdArgs.push_back("-lSystem");
 
   // Select the dynamic runtime library and the target specific static library.
-  if (isTargetIOSBased() || isTargetMacOSBased()) {
+  if (isTargetIOSBased()) {
 // If we are compiling as iOS / simulator, don't attempt to link 
libgcc_s.1,
 // it never went into the SDK.
 // Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+
-if ((isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
- getTriple().getArch() != llvm::Triple::aarch64) ||
-isMacosxVersionLT(10, 6))
+if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
+getTriple().getArch() != llvm::Triple::aarch64)
   CmdArgs.push_back("-lgcc_s.1");
-  }
+  } else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6))
+CmdArgs.push_back("-lgcc_s.1");
   AddLinkRuntimeLib(Args, CmdArgs, "builtins");
 }
 

>From 31bdca90a631f744f86fa3e25e1a178455901503 Mon Sep 17 00:00:00 2001
From: Un1q32 
Date: Mon, 17 Mar 2025 18:44:08 -0400
Subject: [PATCH 3/3] tidy this up a bit, also don't link libgcc_s on arm64
 ever

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 16 
 clang/test/Driver/darwin-ld.c  |  8 ++--
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 757ba50e4c865..acc0f9ca59316 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1642,14 +1642,14 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 C

[clang] [llvm] [clang] [OpenMP] New OpenMP 6.0 self_maps clause - CodeGen (PR #134131)

2025-04-04 Thread via cfe-commits


@@ -236,6 +236,8 @@ enum class OpenMPOffloadMappingFlags : uint64_t {
   // dynamic.
   // This is an OpenMP extension for the sake of OpenACC support.
   OMP_MAP_OMPX_HOLD = 0x2000,
+  /// Self directs mapping without creating a separate device copy.
+  OMP_MAP_SELF = 0x4000,

Ritanya-B-Bharadwaj wrote:

Right, I get that OMP_MAP_LITERAL just passes the pointer(or anything that fits 
into a register as you mentioned) as is, without changing anything.  But the 
problem is, it doesn’t guarantee that the memory it points to is actually 
accessible on the device. OMP_MAP_SELF explicitly states that the memory is 
already available on the device and avoids unnecessary mappings. The idea was 
to avoid unnecessary copies, especially for USM. 
If there’s another way to handle this cleanly, I’m open to discussing it. 
Please let me know. 

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


[clang] [Clang] Fix dependent local class instantiation bugs (PR #134038)

2025-04-04 Thread Younan Zhang via cfe-commits

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


[clang] [flang] [flang] Added driver options for arrays repacking. (PR #134002)

2025-04-04 Thread Tarun Prabhu via cfe-commits


@@ -0,0 +1,27 @@
+! Test forwarding just the forwarding of -frepack-arrays-contiguity options:
+! RUN: %flang -frepack-arrays-contiguity=whole %s -### -fsyntax-only 2>&1 | 
FileCheck --check-prefix=WHOLECMD %s
+! RUN: %flang -frepack-arrays-contiguity=innermost %s -### -fsyntax-only 2>&1 
| FileCheck --check-prefix=INNERMOSTCMD %s
+! RUN: %flang -frepack-arrays-contiguity=innermost 
-frepack-arrays-contiguity=whole %s -### -fsyntax-only 2>&1 | FileCheck 
--check-prefix=WHOLECMD %s
+! RUN: %flang -frepack-arrays-contiguity=whole 
-frepack-arrays-contiguity=innermost %s -### -fsyntax-only 2>&1 | FileCheck 
--check-prefix=INNERMOSTCMD %s
+
+! Test proper setting of the lowering options:
+! RUN: %flang_fc1 -frepack-arrays -frepack-arrays-contiguity=whole %s 
-emit-hlfir -o - | FileCheck --check-prefix=WHOLE %s
+! RUN: %flang_fc1 -frepack-arrays-contiguity=whole %s -emit-hlfir -o - | 
FileCheck --check-prefix=NOREPACK %s
+! RUN: %flang_fc1 -frepack-arrays -frepack-arrays-contiguity=innermost %s 
-emit-hlfir -o - | FileCheck --check-prefix=INNERMOST %s
+! RUN: %flang_fc1 -frepack-arrays-contiguity=innermost %s -emit-hlfir -o - | 
FileCheck --check-prefix=NOREPACK %s
+

tarunprabhu wrote:

Could we also add a test to check that an invalid option value raises an error? 
Perhaps also for a missing value.

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


[clang] Reland "[HLSL][RootSignature] Define and integrate HLSLRootSignatureAttr" (PR #134293)

2025-04-04 Thread Finn Plummer via cfe-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/134293

This pr relands https://github.com/llvm/llvm-project/pull/134124.

It resolves the many linking errors during build, 
[here](https://github.com/llvm/llvm-project/pull/134124#issuecomment-2776370486).
 There was a missing dependency for `clangParse` in `clangSema` now that we 
depend on `clangParse` to get acces to the `RootSignatureParser` during 
semantic analysis. This library was added to the dependencies to resolve the 
error. It wasn't caught previously as the library was transitively linked in 
local and pre-merge build environments

>From 9599f73fc5a4d12097f4ecfe573e5a177b673fc1 Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 2 Apr 2025 17:04:57 +
Subject: [PATCH 1/3] [HLSL][RootSignature] Define and integrate
 `HLSLRootSignatureAttr`

- Defines HLSLRootSignature Attr in `Attr.td`
- Define and implement handleHLSLRootSignature in `SemaHLSL`
- Adds sample test case to show AST Node is generated in
`RootSignatures-AST.hlsl`

This commit will "hook-up" the seperately defined RootSignature parser
and invoke it to create the RootElements, then store them on the
ASTContext and finally store the reference to the Elements in
RootSignatureAttr
---
 clang/include/clang/AST/Attr.h  |  1 +
 clang/include/clang/Basic/Attr.td   | 19 +++
 clang/include/clang/Basic/AttrDocs.td   | 11 +++
 clang/include/clang/Sema/SemaHLSL.h |  1 +
 clang/lib/Sema/SemaDeclAttr.cpp |  3 ++
 clang/lib/Sema/SemaHLSL.cpp | 35 +
 clang/test/AST/HLSL/RootSignatures-AST.hlsl | 24 ++
 clang/test/SemaHLSL/RootSignature-err.hlsl  |  9 ++
 8 files changed, 103 insertions(+)
 create mode 100644 clang/test/AST/HLSL/RootSignatures-AST.hlsl
 create mode 100644 clang/test/SemaHLSL/RootSignature-err.hlsl

diff --git a/clang/include/clang/AST/Attr.h b/clang/include/clang/AST/Attr.h
index 994f236337b99..37c3f8bbfb5f9 100644
--- a/clang/include/clang/AST/Attr.h
+++ b/clang/include/clang/AST/Attr.h
@@ -26,6 +26,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Support/Compiler.h"
 #include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 0999d8065e9f5..93524a0c873c1 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4709,6 +4709,25 @@ def Error : InheritableAttr {
   let Documentation = [ErrorAttrDocs];
 }
 
+def HLSLRootSignature : Attr {
+  /// [RootSignature(Signature)]
+  let Spellings = [Microsoft<"RootSignature">];
+  let Args = [StringArgument<"Signature">];
+  let Subjects = SubjectList<[Function],
+ ErrorDiag, "'function'">;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLRootSignatureDocs];
+  let AdditionalMembers = [{
+private:
+  ArrayRef RootElements;
+public:
+  void setElements(ArrayRef Elements) {
+RootElements = Elements;
+  }
+  auto getElements() const { return RootElements; }
+}];
+}
+
 def HLSLNumThreads: InheritableAttr {
   let Spellings = [Microsoft<"numthreads">];
   let Args = [IntArgument<"X">, IntArgument<"Y">, IntArgument<"Z">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a52ece467ec70..2ac9e2a4eaf39 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8143,6 +8143,17 @@ and 
https://microsoft.github.io/hlsl-specs/proposals/0013-wave-size-range.html
   }];
 }
 
+def HLSLRootSignatureDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``RootSignature`` attribute applies to HLSL entry functions to define what
+types of resources are bound to the graphics pipeline.
+
+For details about the use and specification of Root Signatures please see here:
+https://learn.microsoft.com/en-us/windows/win32/direct3d12/root-signatures
+  }];
+}
+
 def NumThreadsDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index f333fe30e8da0..1bd35332612cd 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -118,6 +118,7 @@ class SemaHLSL : public SemaBase {
bool IsCompAssign);
   void emitLogicalOperatorFixIt(Expr *LHS, Expr *RHS, BinaryOperatorKind Opc);
 
+  void handleRootSignatureAttr(Decl *D, const ParsedAttr &AL);
   void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL);
   void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL);
   void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 6cb6f6d10

[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-04-04 Thread David Rivera via cfe-commits

RiverDave wrote:

Ping @HerrCai0907 

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


[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-04 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/134188

>From b37d2b18e12cce53137eb78af5507ebf13ee45a1 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Wed, 2 Apr 2025 21:02:00 -0400
Subject: [PATCH] [clang-tidy] Improve integer comparison by matching valid
 expressions outside implicitCastExpr

---
 .../UseIntegerSignComparisonCheck.cpp | 17 +---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../modernize/use-integer-sign-comparison.cpp | 26 +++
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index eeba5cce80da5..8f2bb4c4ba8f2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -39,9 +39,11 @@ intCastExpression(bool IsSigned,
   // std::cmp_{} functions trigger a compile-time error if either LHS or RHS
   // is a non-integer type, char, enum or bool
   // (unsigned char/ signed char are Ok and can be used).
-  auto IntTypeExpr = expr(hasType(hasCanonicalType(qualType(
+  const auto HasIntegerType = hasType(hasCanonicalType(qualType(
   isInteger(), IsSigned ? isSignedInteger() : isUnsignedInteger(),
-  unless(isActualChar()), unless(booleanType()), unless(enumType());
+  unless(isActualChar()), unless(booleanType()), unless(enumType();
+
+  auto IntTypeExpr = expr(HasIntegerType);
 
   const auto ImplicitCastExpr =
   CastBindName.empty() ? implicitCastExpr(hasSourceExpression(IntTypeExpr))
@@ -52,8 +54,17 @@ intCastExpression(bool IsSigned,
   const auto StaticCastExpr = cxxStaticCastExpr(has(ImplicitCastExpr));
   const auto FunctionalCastExpr = cxxFunctionalCastExpr(has(ImplicitCastExpr));
 
+  // Match function calls or variable references not directly wrapped by an
+  // implicit cast
+  const auto CallIntExpr = CastBindName.empty()
+   ? callExpr(HasIntegerType)
+   : callExpr(HasIntegerType).bind(CastBindName);
+  const auto DeclRefIntExpr =
+  CastBindName.empty() ? declRefExpr(HasIntegerType)
+   : declRefExpr(HasIntegerType).bind(CastBindName);
+
   return expr(anyOf(ImplicitCastExpr, CStyleCastExpr, StaticCastExpr,
-FunctionalCastExpr));
+FunctionalCastExpr, CallIntExpr));
 }
 
 static StringRef parseOpCode(BinaryOperator::Opcode Code) {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6c1f05009df98..a341cbc273f31 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -166,6 +166,10 @@ Changes in existing checks
   excluding variables with ``thread_local`` storage class specifier from being
   matched.
 
+- Improved :doc:`modernize-use-integer-sign-comparison
+  ` check by matching
+  valid integer expressions not directly wrapped around an implicit cast.
+
 - Improved :doc:`modernize-use-default-member-init
   ` check by matching
   ``constexpr`` and ``static``` values on member initialization and by 
detecting
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
index 99f00444c2d3f..1d2f64a359a2c 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
@@ -120,3 +120,29 @@ int AllComparisons() {
 
 return 0;
 }
+
+namespace PR127471 {
+int getSignedValue();
+unsigned int getUnsignedValue();
+
+void callExprTest() {
+
+if (getSignedValue() < getUnsignedValue())
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES:  if (std::cmp_less(getSignedValue() , getUnsignedValue()))
+
+int sVar = 0;
+if (getUnsignedValue() > sVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getUnsignedValue() , sVar))
+
+unsigned int uVar = 0;
+if (getSignedValue() > uVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getSignedValue() , uVar))
+
+}
+} // namespace PR127471

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


[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-04 Thread David Rivera via cfe-commits


@@ -177,6 +177,10 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-integer-sign-comparison

RiverDave wrote:

Thanks, should be addressed now

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


[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-04 Thread via cfe-commits

https://github.com/irymarchyk updated 
https://github.com/llvm/llvm-project/pull/134337

>From df25a8bbfd827085265c51a44bedbf38deebbab4 Mon Sep 17 00:00:00 2001
From: Ivan Rymarchyk <>
Date: Sat, 29 Mar 2025 13:54:32 -0700
Subject: [PATCH 1/2] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add
 new AllowShortFunctionsOnASingleLineOptions for granular setup
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The currentĀ clang-formatĀ configuration optionĀ AllowShortFunctionsOnASingleLineĀ 
uses a single enum (ShortFunctionStyle) to control when short function 
definitions can be merged onto a single line. This enum provides predefined 
combinations of conditions (e.g.,Ā None,Ā EmptyĀ only,Ā InlineĀ only,Ā InlineĀ 
includingĀ Empty,Ā All).

This approach has limitations:

1. **Lack of Granularity:**Ā Users cannot specify arbitrary combinations of 
conditions. For example, a user might want to allow merging forĀ bothĀ empty 
functions and short top-level functions, butĀ notĀ for short functions defined 
within classes. This is not possible with the current enum options except by 
choosingĀ All, which might merge more than desired.

2. **Inflexibility:**Ā Adding new conditions for merging (e.g., distinguishing 
between member functions and constructors, handling lambdas specifically) would 
require adding many new combined enum values, leading to a combinatorial 
explosion and making the configuration complex.

3. **Implicit Behavior:**Ā Some options imply others (e.g.,Ā InlineĀ impliesĀ 
Empty), which might not always be intuitive or desired.

The goal is to replace this single-choice enum with a more flexible mechanism 
allowing users to specify aĀ setĀ of conditions that must be met for a short 
function to be merged onto a single line.

**Proposed Solution**

1. Introduce a new configuration option:Ā AllowShortFunctionsOnSingleLineOptions.

2. This option will accept a list of strings, where each string represents a 
specific condition allowing merging.

3. **Backward Compatibility:**

- IfĀ AllowShortFunctionsOnSingleLineOptionsĀ is present in the 
configuration, it takes precedence.

- IfĀ AllowShortFunctionsOnSingleLineOptionsĀ isĀ notĀ present, but the oldĀ 
AllowShortFunctionsOnASingleLineĀ isĀ present, the old option should be parsed 
and mapped to the corresponding new semantics for compatibility.
---
 clang/docs/ClangFormatStyleOptions.rst  |  64 +++
 clang/include/clang/Format/Format.h |  70 
 clang/lib/Format/Format.cpp |  52 +
 clang/lib/Format/TokenAnnotator.cpp |   7 +-
 clang/lib/Format/UnwrappedLineFormatter.cpp |   9 +-
 clang/unittests/Format/ConfigParseTest.cpp  |   6 ++
 clang/unittests/Format/FormatTest.cpp   | 111 
 7 files changed, 310 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..167701cf6585d 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1959,6 +1959,70 @@ the configuration (without a prefix: ``Auto``).
   };
   void f() { bar(); }
 
+  * ``SFS_Custom`` (in configuration: ``Custom``)
+Configure merge behavior using AllowShortFunctionsOnASingleLineOptions
+
+
+
+.. _AllowShortFunctionsOnASingleLineOptions:
+
+**AllowShortFunctionsOnASingleLineOptions** (``ShortFunctionMergeFlags``) 
:versionbadge:`clang-format 21` :ref:`¶ 
`
+  Precise control over merging short functions
+
+  If ``AllowShortFunctionsOnASingleLine`` is set to ``Custom``, use this to
+  specify behavior in different situations.
+
+  .. code-block:: yaml
+
+# Example of usage:
+AllowShortFunctionsOnASingleLine: Custom
+AllowShortFunctionsOnASingleLineOptions:
+  Empty: false
+  Inline: true
+  All: false
+
+  Nested configuration flags:
+
+  Precise control over merging short functions
+
+  .. code-block:: c++
+
+# Should be declared this way:
+AllowShortFunctionsOnASingleLine: Custom
+AllowShortFunctionsOnASingleLineOptions:
+  Empty: false
+  Inline: true
+  All: false
+
+  * ``bool Empty`` Only merge empty functions.
+
+.. code-block:: c++
+
+  void f() {}
+  void f2() {
+bar2();
+  }
+
+  * ``bool Inline`` Only merge functions defined inside a class.
+
+.. code-block:: c++
+
+  class Foo {
+void f() { foo(); }
+  };
+  void f() {
+foo();
+  }
+  void f() {}
+
+  * ``bool All`` Merge all functions fitting on a single line.
+
+.. code-block:: c++
+
+  class Foo {
+void f() { foo(); }
+  };
+  void f() { bar(); }
 
 
 .. _AllowShortIfStatementsOnASingleLine:
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..96b1ecab04e63 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -871,6 +871,8 @@ struct FormatStyle {
 /

[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-04 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/134188

>From 3a2d0c5cc8de153e6d0139154c2c6cd674936a40 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Wed, 2 Apr 2025 21:02:00 -0400
Subject: [PATCH] [clang-tidy] Improve integer comparison by matching valid
 expressions outside implicitCastExpr

---
 .../UseIntegerSignComparisonCheck.cpp | 17 +---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../modernize/use-integer-sign-comparison.cpp | 26 +++
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index eeba5cce80da5..8f2bb4c4ba8f2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -39,9 +39,11 @@ intCastExpression(bool IsSigned,
   // std::cmp_{} functions trigger a compile-time error if either LHS or RHS
   // is a non-integer type, char, enum or bool
   // (unsigned char/ signed char are Ok and can be used).
-  auto IntTypeExpr = expr(hasType(hasCanonicalType(qualType(
+  const auto HasIntegerType = hasType(hasCanonicalType(qualType(
   isInteger(), IsSigned ? isSignedInteger() : isUnsignedInteger(),
-  unless(isActualChar()), unless(booleanType()), unless(enumType());
+  unless(isActualChar()), unless(booleanType()), unless(enumType();
+
+  auto IntTypeExpr = expr(HasIntegerType);
 
   const auto ImplicitCastExpr =
   CastBindName.empty() ? implicitCastExpr(hasSourceExpression(IntTypeExpr))
@@ -52,8 +54,17 @@ intCastExpression(bool IsSigned,
   const auto StaticCastExpr = cxxStaticCastExpr(has(ImplicitCastExpr));
   const auto FunctionalCastExpr = cxxFunctionalCastExpr(has(ImplicitCastExpr));
 
+  // Match function calls or variable references not directly wrapped by an
+  // implicit cast
+  const auto CallIntExpr = CastBindName.empty()
+   ? callExpr(HasIntegerType)
+   : callExpr(HasIntegerType).bind(CastBindName);
+  const auto DeclRefIntExpr =
+  CastBindName.empty() ? declRefExpr(HasIntegerType)
+   : declRefExpr(HasIntegerType).bind(CastBindName);
+
   return expr(anyOf(ImplicitCastExpr, CStyleCastExpr, StaticCastExpr,
-FunctionalCastExpr));
+FunctionalCastExpr, CallIntExpr));
 }
 
 static StringRef parseOpCode(BinaryOperator::Opcode Code) {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6c1f05009df98..31f0870b6173e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -171,6 +171,10 @@ Changes in existing checks
   ``constexpr`` and ``static``` values on member initialization and by 
detecting
   explicit casting of built-in types within member list initialization.
 
+- Improved :doc:`modernize-use-integer-sign-comparison
+  ` check by matching
+  valid integer expressions not directly wrapped around an implicit cast.
+
 - Improved :doc:`modernize-use-ranges
   ` check by updating suppress 
   warnings logic for ``nullptr`` in ``std::find``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
index 99f00444c2d3f..1d2f64a359a2c 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
@@ -120,3 +120,29 @@ int AllComparisons() {
 
 return 0;
 }
+
+namespace PR127471 {
+int getSignedValue();
+unsigned int getUnsignedValue();
+
+void callExprTest() {
+
+if (getSignedValue() < getUnsignedValue())
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES:  if (std::cmp_less(getSignedValue() , getUnsignedValue()))
+
+int sVar = 0;
+if (getUnsignedValue() > sVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getUnsignedValue() , sVar))
+
+unsigned int uVar = 0;
+if (getSignedValue() > uVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getSignedValue() , uVar))
+
+}
+} // namespace PR127471

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


[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-04 Thread David Rivera via cfe-commits


@@ -166,6 +166,10 @@ Changes in existing checks
   excluding variables with ``thread_local`` storage class specifier from being
   matched.
 
+- Improved :doc:`modernize-use-integer-sign-comparison

RiverDave wrote:

Figured it out the instant I pushed my changes šŸ˜‚

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


[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-04 Thread via cfe-commits


@@ -166,6 +166,10 @@ Changes in existing checks
   excluding variables with ``thread_local`` storage class specifier from being
   matched.
 
+- Improved :doc:`modernize-use-integer-sign-comparison

EugeneZelenko wrote:

Should be after `modernize-use-default-member-init`.

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


[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-04 Thread via cfe-commits


@@ -871,13 +871,81 @@ struct FormatStyle {
 ///   void f() { bar(); }
 /// \endcode
 SFS_All,
+/// Configure merge behavior using AllowShortFunctionsOnASingleLineOptions
+SFS_Custom,
   };
 
   /// Dependent on the value, ``int f() { return 0; }`` can be put on a
   /// single line.
   /// \version 3.5
   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
 
+  /// Precise control over merging short functions
+  /// \code
+  ///   # Should be declared this way:
+  ///   AllowShortFunctionsOnASingleLine: Custom
+  ///   AllowShortFunctionsOnASingleLineOptions:
+  /// Empty: false
+  /// Inline: true
+  /// All: false
+  /// \endcode
+  struct ShortFunctionMergeFlags {
+/// Only merge empty functions.

irymarchyk wrote:

Yes, it is covering these. I've added test case for this:
```
  // test with comment
  verifyFormat("void f3() { /* comment */ }", CustomEmpty);
```
I fixed comment

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


[clang] [llvm] [DirectX] Add target builtins (PR #134439)

2025-04-04 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,23 @@
+//===- SemaDirectX.cpp - Semantic Analysis for DirectX 
constructs--===//
+//
+// 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
+//
+//===--===//
+// This implements Semantic Analysis for DirectX constructs.
+//===--===//
+
+#include "clang/Sema/SemaDirectX.h"
+#include "clang/Basic/TargetBuiltins.h"
+#include "clang/Sema/Sema.h"
+
+namespace clang {
+
+SemaDirectX::SemaDirectX(Sema &S) : SemaBase(S) {}
+
+bool SemaDirectX::CheckDirectXBuiltinFunctionCall(unsigned BuiltinID,
+  CallExpr *TheCall) {
+  return false;

farzonl wrote:

The plan right now is that we do target builtins when one of our two targets 
has an opcode and the other does not. Im not aware of another case right now 
for directx. The problem i have with removing this when i don’t have another 
candidate in mind is it feel like we have incomplete support for target 
builtins if we strip out all the sema changes.

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


[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-04 Thread via cfe-commits


@@ -871,13 +871,81 @@ struct FormatStyle {
 ///   void f() { bar(); }
 /// \endcode
 SFS_All,
+/// Configure merge behavior using AllowShortFunctionsOnASingleLineOptions
+SFS_Custom,
   };
 
   /// Dependent on the value, ``int f() { return 0; }`` can be put on a
   /// single line.
   /// \version 3.5
   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
 
+  /// Precise control over merging short functions
+  /// \code
+  ///   # Should be declared this way:
+  ///   AllowShortFunctionsOnASingleLine: Custom
+  ///   AllowShortFunctionsOnASingleLineOptions:
+  /// Empty: false
+  /// Inline: true
+  /// All: false
+  /// \endcode
+  struct ShortFunctionMergeFlags {
+/// Only merge empty functions.
+/// \code
+///   void f() {}
+///   void f2() {
+/// bar2();
+///   }
+/// \endcode
+bool Empty;
+/// Only merge functions defined inside a class.
+/// \code
+///   class Foo {
+/// void f() { foo(); }

irymarchyk wrote:

Thanks, fixed

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


[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-04 Thread via cfe-commits


@@ -871,13 +871,81 @@ struct FormatStyle {
 ///   void f() { bar(); }
 /// \endcode
 SFS_All,
+/// Configure merge behavior using AllowShortFunctionsOnASingleLineOptions
+SFS_Custom,
   };
 
   /// Dependent on the value, ``int f() { return 0; }`` can be put on a
   /// single line.
   /// \version 3.5
   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
 
+  /// Precise control over merging short functions
+  /// \code
+  ///   # Should be declared this way:
+  ///   AllowShortFunctionsOnASingleLine: Custom
+  ///   AllowShortFunctionsOnASingleLineOptions:
+  /// Empty: false
+  /// Inline: true
+  /// All: false
+  /// \endcode
+  struct ShortFunctionMergeFlags {
+/// Only merge empty functions.
+/// \code
+///   void f() {}
+///   void f2() {
+/// bar2();
+///   }
+/// \endcode
+bool Empty;
+/// Only merge functions defined inside a class.
+/// \code
+///   class Foo {
+/// void f() { foo(); }
+///   };
+///   void f() {
+/// foo();
+///   }
+///   void f() {}

irymarchyk wrote:

Thanks, I've copy/pasted and somehow missed this. Unit-test has this case and 
it works as expected (multiline)

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


[clang] [flang] [driver] Generalize the code that adds the path of libflang_rt.runtime.a. (PR #134362)

2025-04-04 Thread Slava Zakharin via cfe-commits

vzakhari wrote:

May I ask not to merge this yet?  I have a question above, but I will not be at 
work until next Thursday to discuss this in a timely manner.

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


[clang] [CIR] Upstream support for logical not operations (PR #133966)

2025-04-04 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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


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

```
Step 12 (ninja check 2) failure: stage 2 checked (failure)
...
PASS: Flang :: Driver/linker-flags.f90 (24782 of 96614)
PASS: Flang :: Driver/override-triple.ll (24783 of 96614)
PASS: Flang :: Driver/print-pipeline-passes.f90 (24784 of 96614)
PASS: Flang :: Driver/predefined-macros-compiler-version.F90 (24785 of 96614)
PASS: Flang :: Driver/print-resource-dir.F90 (24786 of 96614)
PASS: Flang :: Driver/fixed-line-length.f90 (24787 of 96614)
PASS: Flang :: Driver/phases.f90 (24788 of 96614)
PASS: Flang :: Driver/parse-error.ll (24789 of 96614)
PASS: Flang :: Driver/parse-fir-error.ll (24790 of 96614)
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (24791 of 96614)
 TEST 'Flang :: Driver/slp-vectorize.ll' FAILED 

Test has no 'RUN:' line

PASS: Flang :: Driver/macro-def-undef.F90 (24792 of 96614)
PASS: Flang :: Driver/print-target-triple.f90 (24793 of 96614)
PASS: Flang :: Driver/mlink-builtin-bc.f90 (24794 of 96614)
PASS: Flang :: Driver/pthread.f90 (24795 of 96614)
PASS: Flang :: Driver/lto-bc.f90 (24796 of 96614)
PASS: Flang :: Driver/parse-ir-error.f95 (24797 of 96614)
PASS: Flang :: Driver/scanning-error.f95 (24798 of 96614)
PASS: Flang :: Driver/std2018-wrong.f90 (24799 of 96614)
PASS: Flang :: Driver/missing-arg.f90 (24800 of 96614)
PASS: Flang :: Driver/mlir-pass-pipeline.f90 (24801 of 96614)
PASS: Flang :: Driver/supported-suffices/f03-suffix.f03 (24802 of 96614)
PASS: Flang :: Driver/pp-fixed-form.f90 (24803 of 96614)
PASS: Flang :: Driver/supported-suffices/f08-suffix.f08 (24804 of 96614)
PASS: Flang :: Driver/pass-plugin-not-found.f90 (24805 of 96614)
PASS: Clangd Unit Tests :: ./ClangdTests/73/81 (24806 of 96614)
PASS: Flang :: Driver/tco-code-gen-llvm.fir (24807 of 96614)
PASS: Flang :: Driver/target-gpu-features.f90 (24808 of 96614)
PASS: Flang :: Driver/q-unused-arguments.f90 (24809 of 96614)
PASS: Flang :: Driver/mllvm.f90 (24810 of 96614)
PASS: Flang :: Driver/fsave-optimization-record.f90 (24811 of 96614)
PASS: Flang :: Driver/target.f90 (24812 of 96614)
PASS: Flang :: Driver/lto-flags.f90 (24813 of 96614)
PASS: Flang :: Driver/unsupported-vscale-max-min.f90 (24814 of 96614)
PASS: Flang :: Driver/multiple-input-files.f90 (24815 of 96614)
PASS: Flang :: Driver/no-duplicate-main.f90 (24816 of 96614)
PASS: Flang :: Driver/input-from-stdin/input-from-stdin.f90 (24817 of 96614)
PASS: Flang :: Driver/std2018.f90 (24818 of 96614)
PASS: Flang :: Driver/unparse-with-modules.f90 (24819 of 96614)
PASS: Flang :: Driver/save-temps.f90 (24820 of 96614)
PASS: Flang :: Driver/unparse-use-analyzed.f95 (24821 of 96614)
PASS: Flang :: Driver/prescanner-diag.f90 (24822 of 96614)
PASS: Flang :: Driver/optimization-remark-invalid.f90 (24823 of 96614)
PASS: Flang :: Driver/save-temps-use-module.f90 (24824 of 96614)
PASS: Flang :: Driver/target-machine-error.f90 (24825 of 96614)
PASS: Flang :: Driver/target-cpu-features-invalid.f90 (24826 of 96614)
PASS: Flang :: Driver/falias-analysis.f90 (24827 of 96614)

```



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


[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits


@@ -263,6 +264,72 @@ static void terminateBody(CIRGenBuilderTy &builder, 
mlir::Region &r,
 b->erase();
 }
 
+mlir::LogicalResult CIRGenFunction::emitIfStmt(const IfStmt &s) {
+  mlir::LogicalResult res = mlir::success();
+  // The else branch of a consteval if statement is always the only branch
+  // that can be runtime evaluated.
+  const Stmt *ConstevalExecuted;
+  if (s.isConsteval()) {
+ConstevalExecuted = s.isNegatedConsteval() ? s.getThen() : s.getElse();
+if (!ConstevalExecuted) {
+  // No runtime code execution required
+  return res;
+}
+  }
+
+  // C99 6.8.4.1: The first substatement is executed if the expression
+  // compares unequal to 0.  The condition must be a scalar type.
+  auto ifStmtBuilder = [&]() -> mlir::LogicalResult {
+if (s.isConsteval())
+  return emitStmt(ConstevalExecuted, /*useCurrentScope=*/true);
+
+if (s.getInit())
+  if (emitStmt(s.getInit(), /*useCurrentScope=*/true).failed())
+return mlir::failure();
+
+if (s.getConditionVariable())
+  emitDecl(*s.getConditionVariable());
+
+// During LLVM codegen, if the condition constant folds and can be elided,
+// it tries to avoid emitting the condition and the dead arm of the 
if/else.
+// TODO(cir): we skip this in CIRGen, but should implement this as part of
+// SSCP or a specific CIR pass.
+bool CondConstant;
+if (ConstantFoldsToSimpleInteger(s.getCond(), CondConstant,

andykaylor wrote:

> Doing it in MLIR is probably nicer, but if we can "easily" (not too compile 
> time intensive) do it during CIRGen, shouldn't we?

I guess this is a philosophical question, but I'm of the opinion that the front 
end should strictly be producing IR that represents the semantics of the source 
code and has no business doing any sort of optimization. It took me a while to 
come to this conclusion when I was working on the optimizer, because it was 
jarring how inefficient the IR looked coming out of the front end (things like 
storing a variable to an alloca slot and then immediately reloading it, but I 
eventually came to realize that the front end was doing that because those were 
the unvarnished semantics of the source code. Taking that to the extreme, if 
the source code says "if (true)..." what business does the front end have 
removing that? Optimizations should be left to the optimizer.

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


[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits


@@ -442,6 +457,25 @@ class CIRGenFunction : public CIRGenTypeCache {
   mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s);
   LValue emitDeclRefLValue(const clang::DeclRefExpr *e);
 
+  /// Emit an if on a boolean condition to the specified blocks.
+  /// FIXME: Based on the condition, this might try to simplify the codegen of
+  /// the conditional based on the branch. TrueCount should be the number of

andykaylor wrote:

OK, so the comment here is basically saying we should consider performing the 
simplifications that are performed in the classic codegen. @Andres-Salamanca 
Can you reword the comment to reflect that? You should removed the sentence 
about TrueCount.

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


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

2025-04-04 Thread Trevor Gross via cfe-commits


@@ -0,0 +1,65 @@
+; Test copysign intrinsics involving half.
+;
+; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+
+declare half @llvm.copysign.f16(half, half)
+declare float @llvm.copysign.f32(float, float)
+declare double @llvm.copysign.f64(double, double)
+
+; Test f16 copies.
+define half @f0(half %a, half %b) {
+; CHECK-LABEL: f0:
+; CHECK: brasl %r14, __extendhfsf2@PLT
+; CHECK: brasl %r14, __extendhfsf2@PLT
+; CHECK: cpsdr %f0, %f9, %f0
+; CHECK: brasl %r14, __truncsfhf2@PLT
+; CHECK: br %r14
+  %res = call half @llvm.copysign.f16(half %a, half %b)

tgross35 wrote:

(Nonblocker) a few other architectures use an asm lowering to avoid the calls 
here, it's just `(a & !MASK) | (Y & MASK)` with `MASK = 1 << 15`.

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


[clang] [Clang] [NFC] Introduce a helper for emitting compatibility diagnostics (PR #132348)

2025-04-04 Thread via cfe-commits

Sirraide wrote:

Ah, I think I’ve found what the problem is: it would seem that moving the 
diagnostics around in the file caused whatever the ā€˜diagnostic category number’ 
is supposed to be of some of these diagnostics to change, and there were tests 
that check for that that still need to be updated. I’ll update the test and 
then try to reland this.

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


[clang] [MS][clang] Fix crash on deletion of array of pointers (PR #134088)

2025-04-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

Sometimes a non-array delete is treated as delete[] when input pointer is 
pointer to array. With vector deleting destructors support we now generate a 
virtual destructor call instead of simple loop over the elements. This patch 
adjusts the codepath that generates virtual call to expect the case of pointer 
to array.

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


3 Files Affected:

- (modified) clang/lib/AST/Expr.cpp (+3) 
- (modified) clang/lib/CodeGen/MicrosoftCXXABI.cpp (+3) 
- (modified) clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp (+47) 


``diff
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 9d5b4a60c9fe7..e7c3302f24756 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -71,6 +71,9 @@ const CXXRecordDecl *Expr::getBestDynamicClassType() const {
   if (const PointerType *PTy = DerivedType->getAs())
 DerivedType = PTy->getPointeeType();
 
+  while (const ArrayType *ATy = DerivedType->getAsArrayTypeUnsafe())
+DerivedType = ATy->getElementType();
+
   if (DerivedType->isDependentType())
 return nullptr;
 
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp 
b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 464d4370284fb..ccf24e0a3ebd7 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -2033,6 +2033,9 @@ llvm::Value *MicrosoftCXXABI::EmitVirtualDestructorCall(
 ThisTy = D->getDestroyedType();
   }
 
+  while (const ArrayType *ATy = ThisTy->getAsArrayTypeUnsafe())
+ThisTy = ATy->getElementType();
+
   This = adjustThisArgumentForVirtualFunctionCall(CGF, GD, This, true);
   RValue RV =
   CGF.EmitCXXDestructorCall(GD, Callee, This.emitRawPointer(CGF), ThisTy,
diff --git a/clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp 
b/clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp
index 439ff84456033..9d23708602a43 100644
--- a/clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp
+++ b/clang/test/CodeGenCXX/microsoft-vector-deleting-dtors.cpp
@@ -35,6 +35,10 @@ void operator delete(void *p) { i-=2; }
 void operator delete[](void *p) { i--; }
 };
 
+struct AllocatedAsArray : public Bird {
+
+};
+
 // Vector deleting dtor for Bird is an alias because no new Bird[] expressions
 // in the TU.
 // X64: @"??_EBird@@UEAAPEAXI@Z" = weak dso_local unnamed_addr alias ptr (ptr, 
i32), ptr @"??_GBird@@UEAAPEAXI@Z"
@@ -55,6 +59,14 @@ Bird* alloc() {
   return P;
 }
 
+
+template
+struct S {
+  void foo() { void *p = new C(); delete (C *)p; }
+};
+
+S sp;
+
 void bar() {
   dealloc(alloc());
 
@@ -63,6 +75,8 @@ void bar() {
 
   Bird *p = new HasOperatorDelete[2];
   dealloc(p);
+
+  sp.foo();
 }
 
 // CHECK-LABEL: define dso_local void @{{.*}}dealloc{{.*}}(
@@ -99,6 +113,36 @@ void bar() {
 // CHECK: delete.end:
 // CHECK-NEXT:   ret void
 
+// Definition of S::foo, check that it has vector deleting destructor call
+// X64-LABEL: define linkonce_odr dso_local void 
@"?foo@?$S@$$BY102UAllocatedAsArrayQEAAXXZ"
+// X86-LABEL: define linkonce_odr dso_local x86_thiscallcc void 
@"?foo@?$S@$$BY102UAllocatedAsArrayQAEXXZ"
+// CHECK: delete.notnull:   ; preds = 
%arrayctor.cont
+// CHECK-NEXT:   %[[DEL_PTR:.*]] = getelementptr inbounds [1 x [3 x 
%struct.AllocatedAsArray]], ptr %[[THE_ARRAY:.*]], i32 0, i32 0
+// X64-NEXT:   %[[COOKIEGEP:.*]] = getelementptr inbounds i8, ptr 
%[[DEL_PTR]], i64 -8
+// X86-NEXT:   %[[COOKIEGEP:.*]] = getelementptr inbounds i8, ptr 
%[[DEL_PTR]], i32 -4
+// X64-NEXT:   %[[HOWMANY:.*]] = load i64, ptr %[[COOKIEGEP]]
+// X86-NEXT:   %[[HOWMANY:.*]] = load i32, ptr %[[COOKIEGEP]]
+// X64-NEXT:   %[[ISNOELEM:.*]] = icmp eq i64 %[[HOWMANY]], 0
+// X86-NEXT:   %[[ISNOELEM:.*]] = icmp eq i32 %[[HOWMANY]], 0
+// CHECK-NEXT:   br i1 %[[ISNOELEM]], label %vdtor.nocall, label %vdtor.call
+// CHECK: vdtor.nocall: ; preds = 
%delete.notnull
+// X64-NEXT:   %[[HOWMANYBYTES:.*]] = mul i64 8, %[[HOWMANY]]
+// X86-NEXT:   %[[HOWMANYBYTES:.*]] = mul i32 4, %[[HOWMANY]]
+// X64-NEXT:   %[[ADDCOOKIESIZE:.*]] = add i64 %[[HOWMANYBYTES]], 8
+// X86-NEXT:   %[[ADDCOOKIESIZE:.*]] = add i32 %[[HOWMANYBYTES]], 4
+// X64-NEXT:   call void @"??_V@YAXPEAX_K@Z"(ptr noundef %[[COOKIEGEP]], i64 
noundef %[[ADDCOOKIESIZE]])
+// X86-NEXT:   call void @"??_V@YAXPAXI@Z"(ptr noundef %[[COOKIEGEP]], i32 
noundef %[[ADDCOOKIESIZE]])
+// CHECK-NEXT:   br label %delete.end
+// CHECK: vdtor.call:   ; preds = 
%delete.notnull
+// CHECK-NEXT:   %[[VTABLE:.*]] = load ptr, ptr %[[DEL_PTR]]
+// CHECK-NEXT:   %[[FPGEP:.*]] = getelementptr inbounds ptr, ptr %[[VTABLE]], 
i64 0
+// CHECK-NEXT:   %[[FPLOAD:.*]]  = load ptr, ptr %[[FPGEP]]
+// X64-NEXT:   %[[CALL:.*]] = call noundef ptr %[[FPLOAD]](ptr noundef nonnull 
align 8 dereferenceable(8) %[[DEL_PTR]], i32 noundef 3)
+// 

[clang] [WIP] Implement `-dump-deserialized-declaration-ranges` flag. (PR #133910)

2025-04-04 Thread Viktoriia Bakalova via cfe-commits


@@ -49,6 +51,150 @@ LLVM_INSTANTIATE_REGISTRY(FrontendPluginRegistry)
 
 namespace {
 
+/// DeserializedDeclsLineRangePrinter dumps ranges of deserialized declarations
+/// to aid debugging and bug minimization. It implements ASTConsumer and
+/// ASTDeserializationListener, so that an object of
+/// DeserializedDeclsLineRangePrinter registers as its own listener. The
+/// ASTDeserializationListener interface provides the DeclRead callback that we
+/// use to collect the deserialized Decls. Note that printing or otherwise
+/// processing them as this point is dangerous, since that could trigger
+/// additional deserialization and crash compilation. Therefore, we process the
+/// collected Decls in HandleTranslationUnit method of ASTConsumer. This is a
+/// safe point, since we know that by this point all the Decls needed by the
+/// compiler frontend have been deserialized. In case our processing causes
+/// further deserialization, DeclRead from the listener might be called again.
+/// However, at that point we don't accept any more Decls for processing.
+class DeserializedDeclsLineRangePrinter : public ASTDeserializationListener,
+  public ASTConsumer {
+public:
+  explicit DeserializedDeclsLineRangePrinter(
+  SourceManager &SM, std::unique_ptr OS)
+  : ASTDeserializationListener(), SM(SM), OS(std::move(OS)) {}
+
+  void DeclRead(GlobalDeclID ID, const Decl *D) override {
+if (!IsCollectingDecls) {
+  return;
+}
+if (!D || isa(D) || isa(D) ||
+isa(D))
+  return;
+if (auto *DC = D->getDeclContext(); !DC || !DC->isFileContext())
+  return;
+PendingDecls.push_back(D);
+ASTDeserializationListener::DeclRead(ID, D);
+  }
+
+  using Position = std::pair;
+  struct RequiredRanges {
+StringRef Filename;
+std::vector> FromTo;
+  };
+  void HandleTranslationUnit(ASTContext &Context) override {
+IsCollectingDecls = false;
+std::vector Decls = std::move(PendingDecls);
+if (!PendingDecls.empty()) {
+  llvm::errs() << "Deserialized more decls while printing, total of "
+   << PendingDecls.size() << "\n";
+  PendingDecls.clear();
+}
+
+// Merge ranges in each of the files. For simplicity, track lines and hope
+// they do not break things.
+struct FileData {
+  std::vector> FromTo;
+  std::vector> Columns;
+  OptionalFileEntryRef Ref;
+};
+llvm::DenseMap FileToLines;
+for (const Decl *D : Decls) {
+  CharSourceRange R = SM.getExpansionRange(D->getSourceRange());
+  if (!R.isValid())
+continue;
+
+  auto *F = SM.getFileEntryForID(SM.getFileID(R.getBegin()));
+  if (F != SM.getFileEntryForID(SM.getFileID(R.getEnd(
+continue;
+
+  auto &Data = FileToLines[F];
+  if (!Data.Ref)
+Data.Ref = SM.getFileEntryRefForID(SM.getFileID(R.getBegin()));
+  Data.FromTo.push_back({{SM.getSpellingLineNumber(R.getBegin()),
+  SM.getSpellingColumnNumber(R.getBegin())},
+ {SM.getSpellingLineNumber(R.getEnd()),
+  SM.getSpellingColumnNumber(R.getEnd())}});
+}
+
+std::vector Result;

VitaNuo wrote:

Done.

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


[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Erich Keane via cfe-commits


@@ -135,6 +135,55 @@ mlir::Location CIRGenFunction::getLoc(mlir::Location lhs, 
mlir::Location rhs) {
   return mlir::FusedLoc::get(locs, metadata, &getMLIRContext());
 }
 
+bool CIRGenFunction::ContainsLabel(const Stmt *s, bool ignoreCaseStmts) {
+  // Null statement, not a label!
+  if (!s)
+return false;
+
+  // If this is a label, we have to emit the code, consider something like:
+  // if (0) {  ...  foo:  bar(); }  goto foo;
+  //
+  // TODO: If anyone cared, we could track __label__'s, since we know that you
+  // can't jump to one from outside their declared region.
+  if (isa(s))
+return true;
+
+  // If this is a case/default statement, and we haven't seen a switch, we
+  // have to emit the code.
+  if (isa(s) && !ignoreCaseStmts)
+return true;
+
+  // If this is a switch statement, we want to ignore cases below it.
+  if (isa(s))

erichkeane wrote:

Its actually being the inverse of conservative, isn't it?  It is going to end 
up skipping blocks that it shouldn't, causing compile-issues.

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


[clang-tools-extra] [NFC] Remove dead code detected by code sanitizer. (PR #134385)

2025-04-04 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/134385

>From 02ae197808f19541127b3e80448aa8034a8e8b1d Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Fri, 4 Apr 2025 07:05:26 -0700
Subject: [PATCH 1/2] [NFC] Remove dead code detected by code santizer.

---
 .../clang-tidy/misc/RedundantExpressionCheck.cpp   | 10 --
 1 file changed, 10 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index c249244b1a1b2..fd72b8f5fd522 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -929,16 +929,6 @@ static bool areExprsSameMacroOrLiteral(const 
BinaryOperator *BinOp,
 
   const auto *LStrl = dyn_cast(Lhs);
   const auto *RStrl = dyn_cast(Rhs);
-  if (Lil && Ril) {
-const llvm::StringRef L = Lexer::getSourceText(
-CharSourceRange::getTokenRange(LStrl->getBeginLoc()), SM,
-Context->getLangOpts(), 0);
-const llvm::StringRef R = Lexer::getSourceText(
-CharSourceRange::getTokenRange(RStrl->getBeginLoc()), SM,
-Context->getLangOpts(), 0);
-return L.compare(R) == 0;
-  }
-
   const auto *Lbl = dyn_cast(Lhs);
   const auto *Rbl = dyn_cast(Rhs);
   if (Lbl && Rbl)

>From 61eb6fead4fab5908ddc7d1320e5217ee54f784f Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Fri, 4 Apr 2025 07:37:42 -0700
Subject: [PATCH 2/2] Addressed Firewave's review comments.

---
 clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index fd72b8f5fd522..8e5a528bc5d3e 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -927,8 +927,6 @@ static bool areExprsSameMacroOrLiteral(const BinaryOperator 
*BinOp,
   if (Lil && Ril)
 return Lil->getValue() == Ril->getValue();
 
-  const auto *LStrl = dyn_cast(Lhs);
-  const auto *RStrl = dyn_cast(Rhs);
   const auto *Lbl = dyn_cast(Lhs);
   const auto *Rbl = dyn_cast(Rhs);
   if (Lbl && Rbl)

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


[clang] [llvm][Stmt]:Fix musttail attribute on a function with not_tail_called attribute has no warning/error (PR #134465)

2025-04-04 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [llvm][Stmt]:Fix musttail attribute on a function with not_tail_called attribute has no warning/error (PR #134465)

2025-04-04 Thread via cfe-commits

https://github.com/MillePlateaux created 
https://github.com/llvm/llvm-project/pull/134465

Added judgment statements and accurately reported errors.Closes #133509

>From c7bd0c4413cbf4768105be178341ff169e460617 Mon Sep 17 00:00:00 2001
From: MillePlateaux 
Date: Fri, 4 Apr 2025 16:26:25 -0700
Subject: [PATCH] [llvm][Stmt]:git clang format

---
 clang/lib/Sema/SemaStmt.cpp | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index e1b9ccc693bd5..c8354198a5614 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -717,6 +717,14 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
 return false;
   }
 
+  if (const FunctionDecl *CalleeDecl = CE->getDirectCallee()) {
+if (CalleeDecl->hasAttr()) {
+  Diag(St->getBeginLoc(), 
diag::err_musttail_conflicts_with_not_tail_called)
+  << &MTA;
+  return false;
+}
+  }
+
   if (const auto *EWC = dyn_cast(E)) {
 if (EWC->cleanupsHaveSideEffects()) {
   Diag(St->getBeginLoc(), diag::err_musttail_needs_trivial_args) << &MTA;

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


[clang] [llvm][Stmt]:Fix musttail attribute on a function with not_tail_called attribute has no warning/error (PR #134465)

2025-04-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (MillePlateaux)


Changes

Added judgment statements and accurately reported errors.Closes #133509

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaStmt.cpp (+8) 


``diff
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index e1b9ccc693bd5..c8354198a5614 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -717,6 +717,14 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
 return false;
   }
 
+  if (const FunctionDecl *CalleeDecl = CE->getDirectCallee()) {
+if (CalleeDecl->hasAttr()) {
+  Diag(St->getBeginLoc(), 
diag::err_musttail_conflicts_with_not_tail_called)
+  << &MTA;
+  return false;
+}
+  }
+
   if (const auto *EWC = dyn_cast(E)) {
 if (EWC->cleanupsHaveSideEffects()) {
   Diag(St->getBeginLoc(), diag::err_musttail_needs_trivial_args) << &MTA;

``




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


[clang] [llvm] [DirectX] Add target builtins (PR #134439)

2025-04-04 Thread Deric C. via cfe-commits


@@ -0,0 +1,23 @@
+//===- SemaDirectX.cpp - Semantic Analysis for DirectX 
constructs--===//
+//
+// 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
+//
+//===--===//
+// This implements Semantic Analysis for DirectX constructs.
+//===--===//
+
+#include "clang/Sema/SemaDirectX.h"
+#include "clang/Basic/TargetBuiltins.h"
+#include "clang/Sema/Sema.h"
+
+namespace clang {
+
+SemaDirectX::SemaDirectX(Sema &S) : SemaBase(S) {}
+
+bool SemaDirectX::CheckDirectXBuiltinFunctionCall(unsigned BuiltinID,
+  CallExpr *TheCall) {
+  return false;

Icohedron wrote:

In that case, I think that if we want to add empty switch cases for this then 
it should be a separate PR to change it for all other the other builtins at 
once.

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


[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread via cfe-commits


@@ -263,6 +264,72 @@ static void terminateBody(CIRGenBuilderTy &builder, 
mlir::Region &r,
 b->erase();
 }
 
+mlir::LogicalResult CIRGenFunction::emitIfStmt(const IfStmt &s) {
+  mlir::LogicalResult res = mlir::success();
+  // The else branch of a consteval if statement is always the only branch
+  // that can be runtime evaluated.
+  const Stmt *ConstevalExecuted;
+  if (s.isConsteval()) {
+ConstevalExecuted = s.isNegatedConsteval() ? s.getThen() : s.getElse();
+if (!ConstevalExecuted) {
+  // No runtime code execution required
+  return res;
+}
+  }
+
+  // C99 6.8.4.1: The first substatement is executed if the expression
+  // compares unequal to 0.  The condition must be a scalar type.
+  auto ifStmtBuilder = [&]() -> mlir::LogicalResult {
+if (s.isConsteval())
+  return emitStmt(ConstevalExecuted, /*useCurrentScope=*/true);
+
+if (s.getInit())
+  if (emitStmt(s.getInit(), /*useCurrentScope=*/true).failed())
+return mlir::failure();
+
+if (s.getConditionVariable())
+  emitDecl(*s.getConditionVariable());
+
+// During LLVM codegen, if the condition constant folds and can be elided,

Andres-Salamanca wrote:

// If the condition folds to a constant and this is an 'if constexpr',
// we simplify it early in CIRGen to avoid emitting the full 'if'.

is this better ?

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


[clang] [Clang] Fix dependent local class instantiation bugs (PR #134038)

2025-04-04 Thread Younan Zhang via cfe-commits

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

>From a670287721da08e54e2908e9abe52ad86a92769b Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 2 Apr 2025 14:44:40 +0800
Subject: [PATCH 1/4] [Clang] Fix dependent local class instantiation bugs

---
 clang/docs/ReleaseNotes.rst|  1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 ++-
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 18 +-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e409f206f6eae..6107fd7667306 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,7 @@ Bug Fixes to C++ Support
   by template argument deduction.
 - Clang is now better at instantiating the function definition after its use 
inside
   of a constexpr lambda. (#GH125747)
+- Fixed a local class member function instantiation bug inside dependent 
lambdas. (#GH59734), (#GH132208)
 - Clang no longer crashes when trying to unify the types of arrays with
   certain differences in qualifiers (this could happen during template argument
   deduction or when building a ternary operator). (#GH97005)
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 00dcadb41e8fb..a46c8c7950710 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -4264,7 +4264,8 @@ Sema::InstantiateClassMembers(SourceLocation 
PointOfInstantiation,
   if (FunctionDecl *Pattern =
   Function->getInstantiatedFromMemberFunction()) {
 
-if (Function->isIneligibleOrNotSelected())
+if (!Instantiation->getDeclContext()->isDependentContext() &&
+Function->isIneligibleOrNotSelected())
   continue;
 
 if (Function->getTrailingRequiresClause()) {
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 8aaaea0bcdd66..2dc199dc8cbc2 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5590,7 +5590,6 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
   Function->setLocation(PatternDecl->getLocation());
   Function->setInnerLocStart(PatternDecl->getInnerLocStart());
   Function->setRangeEnd(PatternDecl->getEndLoc());
-  Function->setDeclarationNameLoc(PatternDecl->getNameInfo().getInfo());
 
   EnterExpressionEvaluationContext EvalContext(
   *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
@@ -5713,6 +5712,23 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs(
 Function, DC, /*Final=*/false, Innermost, false, PatternDecl);
 
+// Let the instantiation use the Pattern's DeclarationNameInfo, due to the
+// following awkwards:
+// 1. The function we're instantiating might come from an (implicit)
+// declaration, while the pattern comes from a definition.
+// 2. We want the instantiated definition to have a source range pointing 
to
+// the definition. Note that we can't set the pattern's DeclarationNameInfo
+// blindly, as it might contain associated TypeLocs that should have
+// already been transformed. So we transform the Pattern's DNI for that
+// purpose. Technically, we should create a new function declaration and
+// give it everything we want, but InstantiateFunctionDefinition does 
update
+// the declaration in place.
+DeclarationNameInfo DN =
+SubstDeclarationNameInfo(PatternDecl->getNameInfo(), TemplateArgs);
+if (!DN.getName())
+  return;
+Function->setDeclarationNameLoc(DN.getInfo());
+
 // Substitute into the qualifier; we can get a substitution failure here
 // through evil use of alias templates.
 // FIXME: Is CurContext correct for this? Should we go to the 
(instantiation

>From 5bd8347866850458fffbaa1713fe991d82d17bd0 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Wed, 2 Apr 2025 19:38:09 +0800
Subject: [PATCH 2/4] Rewrite everything

---
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 73 ++-
 1 file changed, 56 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 2dc199dc8cbc2..a8d23fb2be6d5 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5590,6 +5590,62 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
   Function->setLocation(PatternDecl->getLocation());
   Function->setInnerLocStart(PatternDecl->getInnerLocStart());
   Function->setRangeEnd(PatternDecl->getEndLoc());
+  // Let the instantiation use the Pattern's DeclarationNameLoc, due to the
+  // following awkward

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits


@@ -54,6 +56,67 @@ struct CIRFlattenCFGPass : public 
CIRFlattenCFGBase {
   void runOnOperation() override;
 };
 
+struct CIRIfFlattening : public mlir::OpRewritePattern {
+  using OpRewritePattern::OpRewritePattern;
+
+  mlir::LogicalResult
+  matchAndRewrite(cir::IfOp ifOp,
+  mlir::PatternRewriter &rewriter) const override {
+mlir::OpBuilder::InsertionGuard guard(rewriter);
+mlir::Location loc = ifOp.getLoc();
+bool emptyElse = ifOp.getElseRegion().empty();
+mlir::Block *currentBlock = rewriter.getInsertionBlock();
+mlir::Block *remainingOpsBlock =
+rewriter.splitBlock(currentBlock, rewriter.getInsertionPoint());
+mlir::Block *continueBlock;
+if (ifOp->getResults().empty())
+  continueBlock = remainingOpsBlock;
+else
+  llvm_unreachable("NYI");

andykaylor wrote:

@bcardosolopes What does this mean? What's not implemented here?

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


[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits


@@ -447,6 +448,133 @@ mlir::LogicalResult cir::ReturnOp::verify() {
   return success();
 }
 
+//===--===//
+// IfOp
+//===--===//
+
+ParseResult cir::IfOp::parse(OpAsmParser &parser, OperationState &result) {
+  // create the regions for 'then'.
+  result.regions.reserve(2);
+  Region *thenRegion = result.addRegion();
+  Region *elseRegion = result.addRegion();
+
+  mlir::Builder &builder = parser.getBuilder();
+  OpAsmParser::UnresolvedOperand cond;
+  Type boolType = cir::BoolType::get(builder.getContext());
+
+  if (parser.parseOperand(cond) ||
+  parser.resolveOperand(cond, boolType, result.operands))
+return failure();
+
+  // Parse 'then' region.
+  mlir::SMLoc parseThenLoc = parser.getCurrentLocation();
+  if (parser.parseRegion(*thenRegion, /*arguments=*/{}, /*argTypes=*/{}))
+return failure();
+
+  if (ensureRegionTerm(parser, *thenRegion, parseThenLoc).failed())
+return failure();
+
+  // If we find an 'else' keyword, parse the 'else' region.
+  if (!parser.parseOptionalKeyword("else")) {
+mlir::SMLoc parseElseLoc = parser.getCurrentLocation();
+if (parser.parseRegion(*elseRegion, /*arguments=*/{}, /*argTypes=*/{}))
+  return failure();
+if (ensureRegionTerm(parser, *elseRegion, parseElseLoc).failed())
+  return failure();
+  }
+
+  // Parse the optional attribute list.
+  if (parser.parseOptionalAttrDict(result.attributes))
+return failure();
+  return success();
+}
+
+void cir::IfOp::print(OpAsmPrinter &p) {
+
+  p << " " << getCondition() << " ";
+  mlir::Region &thenRegion = this->getThenRegion();
+  p.printRegion(thenRegion,
+/*printEntryBlockArgs=*/false,
+/*printBlockTerminators=*/!omitRegionTerm(thenRegion));
+
+  // Print the 'else' regions if it exists and has a block.
+  mlir::Region &elseRegion = this->getElseRegion();
+  if (!elseRegion.empty()) {
+p << " else ";
+p.printRegion(elseRegion,
+  /*printEntryBlockArgs=*/false,
+  /*printBlockTerminators=*/!omitRegionTerm(elseRegion));
+  }
+
+  p.printOptionalAttrDict(getOperation()->getAttrs());
+}
+
+/// Default callback for IfOp builders.
+void cir::buildTerminatedBody(OpBuilder &builder, Location loc) {
+  // add cir.yield to end of the block
+  builder.create(loc);
+}
+
+/// Given the region at `index`, or the parent operation if `index` is None,
+/// return the successor regions. These are the regions that may be selected
+/// during the flow of control. `operands` is a set of optional attributes that
+/// correspond to a constant value for each operand, or null if that operand is
+/// not a constant.
+void cir::IfOp::getSuccessorRegions(mlir::RegionBranchPoint point,
+SmallVectorImpl ®ions) 
{
+  // The `then` and the `else` region branch back to the parent operation.
+  if (!point.isParent()) {
+regions.push_back(RegionSuccessor());
+return;
+  }
+
+  // Don't consider the else region if it is empty.
+  Region *elseRegion = &this->getElseRegion();
+  if (elseRegion->empty())
+elseRegion = nullptr;
+
+  // Otherwise, the successor is dependent on the condition.
+  // bool condition;
+  // if (auto condAttr = operands.front().dyn_cast_or_null()) {

andykaylor wrote:

I'm not sure what this code was doing or when it was commented out. It should 
be removed.

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


  1   2   3   4   5   6   7   8   9   >