[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/130177

>From 728e1bd9cccb56a0acaf5abb35fe64cacc5b4ae9 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 6 Mar 2025 15:08:25 -0600
Subject: [PATCH 1/4] [Clang] Treat `ext_vector_type` as a regular type
 attribute

Summary:
This attribute is mostly borrowed from OpenCL, but is useful in general
for accessing the LLVM vector types. Previously the only way to use it
was through typedefs. This patch changes that to allow use as a regular
type attribute, similar to address spaces.
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td | 13 +++--
 clang/include/clang/Basic/AttrDocs.td | 23 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++-
 clang/test/CodeGenCUDA/amdgpu-bf16.cu | 12 
 clang/test/Sema/types.c   |  2 +-
 6 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86bf836b4a999..695c458b36702 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,7 @@ Adding [[clang::unsafe_buffer_usage]] attribute to a method 
definition now turns
 related warnings within the method body.
 
 - The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names.
+- The ``ext_vector_type(n)`` attribute can now be used as a generic type 
attribute.
 - Clang now diagnoses use of declaration attributes on void parameters. 
(#GH108819)
 - Clang now allows ``__attribute__((model("small")))`` and
   ``__attribute__((model("large")))`` on non-TLS globals in x86-64 
compilations.
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc9b462126125..161a4fe8e0f12 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1721,17 +1721,10 @@ def EnableIf : InheritableAttr {
   let Documentation = [EnableIfDocs];
 }
 
-def ExtVectorType : Attr {
-  // This is an OpenCL-related attribute and does not receive a [[]] spelling.
-  let Spellings = [GNU<"ext_vector_type">];
-  // FIXME: This subject list is wrong; this is a type attribute.
-  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+def ExtVectorType : TypeAttr {
+  let Spellings = [Clang<"ext_vector_type">];
   let Args = [ExprArgument<"NumElements">];
-  let ASTNode = 0;
-  let Documentation = [Undocumented];
-  // This is a type attribute with an incorrect subject list, so should not be
-  // permitted by #pragma clang attribute.
-  let PragmaAttributeSupport = 0;
+  let Documentation = [ExtVectorTypeDocs];
 }
 
 def FallThrough : StmtAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f44fad95423ee..c309b4849b731 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1113,6 +1113,29 @@ template instantiation, so the value for ``T::number`` 
is known.
   }];
 }
 
+def ExtVectorTypeDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+
+The ext_vector_type(N) attribute specifies that a type is a vector with N
+elements, directly mapping to an LLVM vector type. Originally from OpenCL, it
+allows element access via [] or x, y, z, w for graphics-style indexing. This
+attribute enables efficient SIMD operations and is usable in general-purpose
+code.
+
+.. code-block:: c++
+
+  template 
+  constexpr T simd_reduce(T [[clang::ext_vector_type(N)]] v) {
+T sum{};
+for (uint32_t i = 0; i < N; ++i) {
+  sum += v[i];
+}
+return sum;
+  }
+  }];
+}
+
 def DiagnoseIfDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1405ee5341dcf..d32320c581656 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1191,7 +1191,8 @@ static void handleTestTypestateAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 
 static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Remember this typedef decl, we will need it later for diagnostics.
-  S.ExtVectorDecls.push_back(cast(D));
+  if (isa(D))
+S.ExtVectorDecls.push_back(cast(D));
 }
 
 static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
diff --git a/clang/test/CodeGenCUDA/amdgpu-bf16.cu 
b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
index 4610b4ae3cbe5..f6533d7faf296 100644
--- a/clang/test/CodeGenCUDA/amdgpu-bf16.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
@@ -111,19 +111,15 @@ __device__ __bf16 test_call( __bf16 in) {
 // CHECK-NEXT:ret void
 //
 __device__ void test_vec_assign() {
-  typedef __attribute__((ext_vector_type(2))) __bf16 bf16_x2;
-  bf16_x2 vec2_a, vec2_b;
+  __bf16 [[clang::ext_vector_type(2)]] vec2_a, vec2_b;
   vec2_a = vec2_b;
 
-  typedef __attribute__((ext_vector_type(4))) __bf16 bf16_x4;
-  bf16_x4 vec4_a, vec4_b;
+  __bf16 [[clang::ext_vector_type(4)]] v

[clang] Allow direct dispatch for the ObjFW runtime (PR #126382)

2025-03-06 Thread John McCall via cfe-commits


@@ -,6 +,96 @@ class CGObjCObjFW: public CGObjCGNU {
 return ClassSymbol;
   }
 
+  void GenerateDirectMethodPrologue(
+  CodeGenFunction &CGF, llvm::Function *Fn, const ObjCMethodDecl *OMD,
+  const ObjCContainerDecl *CD) override {
+auto &Builder = CGF.Builder;
+bool ReceiverCanBeNull = true;
+auto selfAddr = CGF.GetAddrOfLocalVar(OMD->getSelfDecl());
+auto selfValue = Builder.CreateLoad(selfAddr);
+
+// Generate:
+//
+// /* for class methods only to force class lazy initialization */
+// self = [self self];
+//
+// /* unless the receiver is never NULL */
+// if (self == nil) {
+// return (ReturnType){ };
+// }
+//
+// _cmd = @selector(...)
+// ...
+
+if (OMD->isClassMethod()) {
+  const ObjCInterfaceDecl *OID = cast(CD);
+  assert(
+  OID &&
+  "GenerateDirectMethod() should be called with the Class Interface");

rjmccall wrote:

Heh, alright.

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


[clang] [clang][bytecode] Yet another __builtin_constant_p implementation (PR #130143)

2025-03-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/130143

>From 3bdebdee5bce1891b05807a78a639d72e72cd52a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 6 Mar 2025 16:18:49 +0100
Subject: [PATCH 1/3] [clang][bytecode] Yet another __builtin_constant_p
 implementation

---
 clang/lib/AST/ByteCode/ByteCodeEmitter.cpp|  11 ++
 clang/lib/AST/ByteCode/ByteCodeEmitter.h  |   5 +
 clang/lib/AST/ByteCode/Compiler.cpp   |  22 
 clang/lib/AST/ByteCode/Compiler.h |   7 +-
 clang/lib/AST/ByteCode/EvalEmitter.cpp|  28 +
 clang/lib/AST/ByteCode/EvalEmitter.h  |   6 +
 clang/lib/AST/ByteCode/Interp.cpp |  80 +
 clang/lib/AST/ByteCode/Interp.h   |  22 
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  |  79 -
 clang/lib/AST/ByteCode/InterpState.h  |   3 +
 clang/lib/AST/ByteCode/Opcodes.td |  10 +-
 .../test/AST/ByteCode/builtin-constant-p.cpp  | 110 +-
 clang/test/CodeGen/builtin-constant-p.c   |   3 +
 clang/test/CodeGenCXX/builtin-constant-p.cpp  |   1 +
 14 files changed, 303 insertions(+), 84 deletions(-)

diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp 
b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index 5bd1b73133d65..d07b45de8e601 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -367,6 +367,17 @@ bool ByteCodeEmitter::fallthrough(const LabelTy &Label) {
   return true;
 }
 
+bool ByteCodeEmitter::speculate(const CallExpr *E, const LabelTy &EndLabel) {
+  const Expr *Arg = E->getArg(0);
+  PrimType T = Ctx.classify(Arg->getType()).value_or(PT_Ptr);
+  bool CheckPointer = (T == PT_Ptr);
+  if (!this->emitBCP(getOffset(EndLabel), CheckPointer, T, E))
+return false;
+  if (!this->visit(Arg))
+return false;
+  return true;
+}
+
 
//===--===//
 // Opcode emitters
 
//===--===//
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.h 
b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
index ac728830527a2..a45f7325569f9 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.h
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
@@ -48,6 +48,9 @@ class ByteCodeEmitter {
   virtual bool visitFunc(const FunctionDecl *E) = 0;
   virtual bool visitExpr(const Expr *E, bool DestroyToplevelScope) = 0;
   virtual bool visitDeclAndReturn(const VarDecl *E, bool ConstantContext) = 0;
+  virtual bool visit(const Expr *E) = 0;
+  virtual bool discard(const Expr *E) = 0;
+  virtual bool emitBool(bool V, const Expr *E) = 0;
 
   /// Emits jumps.
   bool jumpTrue(const LabelTy &Label);
@@ -55,6 +58,8 @@ class ByteCodeEmitter {
   bool jump(const LabelTy &Label);
   bool fallthrough(const LabelTy &Label);
 
+  bool speculate(const CallExpr *E, const LabelTy &EndLabel);
+
   /// We're always emitting bytecode.
   bool isActive() const { return true; }
 
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 281fb7e14a57d..3eca12897681d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4681,6 +4681,28 @@ bool Compiler::visitAPValueInitializer(const 
APValue &Val,
 template 
 bool Compiler::VisitBuiltinCallExpr(const CallExpr *E,
  unsigned BuiltinID) {
+
+  if (BuiltinID == Builtin::BI__builtin_constant_p) {
+// Void argument is always invalid and harder to handle later.
+if (E->getArg(0)->getType()->isVoidType()) {
+  if (DiscardResult)
+return true;
+  return this->emitConst(0, E);
+}
+
+if (!this->emitStartSpeculation(E))
+  return false;
+LabelTy EndLabel = this->getLabel();
+if (!this->speculate(E, EndLabel))
+  return false;
+this->fallthrough(EndLabel);
+if (!this->emitEndSpeculation(E))
+  return false;
+if (DiscardResult)
+  return this->emitPop(classifyPrim(E), E);
+return true;
+  }
+
   const Function *Func = getFunction(E->getDirectCallee());
   if (!Func)
 return false;
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index 77fcc3d1b41ce..4e5e13833de32 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -274,14 +274,14 @@ class Compiler : public 
ConstStmtVisitor, bool>,
   /// Evaluates an expression and places the result on the stack. If the
   /// expression is of composite type, a local variable will be created
   /// and a pointer to said variable will be placed on the stack.
-  bool visit(const Expr *E);
+  bool visit(const Expr *E) override;
   /// Compiles an initializer. This is like visit() but it will never
   /// create a variable and instead rely on a variable already having
   /// been cre

[clang] [clang] Fix typos in options text. (PR #130129)

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryan Mansfield (rjmansfield)


Changes



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


2 Files Affected:

- (modified) clang/include/clang/Basic/LangOptions.def (+1-1) 
- (modified) clang/include/clang/Driver/Options.td (+3-3) 


``diff
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 383440ddbc0ea..d6748f8ede36f 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -515,7 +515,7 @@ VALUE_LANGOPT(FuchsiaAPILevel, 32, 0, "Fuchsia API level")
 // on large _BitInts.
 BENIGN_VALUE_LANGOPT(MaxBitIntWidth, 32, 128, "Maximum width of a _BitInt")
 
-COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process 
statements"
+COMPATIBLE_LANGOPT(IncrementalExtensions, 1, 0, " True if we want to process 
statements "
 "on the global scope, ignore EOF token and continue later on (thus "
 "avoid tearing the Lexer and etc. down). Controlled by "
 "-fincremental-extensions.")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d0414aba35209..02844be2205aa 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -876,7 +876,7 @@ def Wa_COMMA : CommaJoined<["-"], "Wa,">,
   MetaVarName<"">;
 def warning_suppression_mappings_EQ : Joined<["--"],
   "warning-suppression-mappings=">, Group,
-  HelpText<"File containing diagnostic suppresion mappings. See user manual "
+  HelpText<"File containing diagnostic suppression mappings. See user manual "
   "for file format.">, Visibility<[ClangOption, CC1Option]>;
 def Wall : Flag<["-"], "Wall">, Group, Flags<[HelpHidden]>,
   Visibility<[ClangOption, CC1Option, FlangOption]>;
@@ -941,7 +941,7 @@ def Xarch__
   target matches the specified architecture. This can be used with the target
   CPU, triple architecture, or offloading host and device. It is most useful
   for separating behavior undesirable on one of the targets when combining many
-  compilation jobs, as is commong with offloading. For example, -Xarch_x86_64,
+  compilation jobs, as is common with offloading. For example, -Xarch_x86_64,
   -Xarch_gfx90a, and -Xarch_device are all valid selectors. -Xarch_device will
   forward the argument to the offloading device while -Xarch_host will target
   the host system, which can be used to suppress incompatible GPU 
arguments.}]>,
@@ -1678,7 +1678,7 @@ def fsample_profile_use_profi : Flag<["-"], 
"fsample-profile-use-profi">,
 HelpText<"Use profi to infer block and edge counts">,
 DocBrief<[{Infer block and edge counts. If the profiles have errors or 
missing
blocks caused by sampling, profile inference (profi) can convert
-   basic block counts to branch probabilites to fix them by 
extended
+   basic block counts to branch probabilities to fix them by 
extended
and re-engineered classic MCMF (min-cost max-flow) approach.}]>;
 def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">, 
Group;
 def fno_auto_profile : Flag<["-"], "fno-auto-profile">, Group,

``




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


[clang] [clang][bytecode] Yet another __builtin_constant_p implementation (PR #130143)

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

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/130143

>From 3bdebdee5bce1891b05807a78a639d72e72cd52a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 6 Mar 2025 16:18:49 +0100
Subject: [PATCH] [clang][bytecode] Yet another __builtin_constant_p
 implementation

---
 clang/lib/AST/ByteCode/ByteCodeEmitter.cpp|  11 ++
 clang/lib/AST/ByteCode/ByteCodeEmitter.h  |   5 +
 clang/lib/AST/ByteCode/Compiler.cpp   |  22 
 clang/lib/AST/ByteCode/Compiler.h |   7 +-
 clang/lib/AST/ByteCode/EvalEmitter.cpp|  28 +
 clang/lib/AST/ByteCode/EvalEmitter.h  |   6 +
 clang/lib/AST/ByteCode/Interp.cpp |  80 +
 clang/lib/AST/ByteCode/Interp.h   |  22 
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  |  79 -
 clang/lib/AST/ByteCode/InterpState.h  |   3 +
 clang/lib/AST/ByteCode/Opcodes.td |  10 +-
 .../test/AST/ByteCode/builtin-constant-p.cpp  | 110 +-
 clang/test/CodeGen/builtin-constant-p.c   |   3 +
 clang/test/CodeGenCXX/builtin-constant-p.cpp  |   1 +
 14 files changed, 303 insertions(+), 84 deletions(-)

diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp 
b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index 5bd1b73133d65..d07b45de8e601 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -367,6 +367,17 @@ bool ByteCodeEmitter::fallthrough(const LabelTy &Label) {
   return true;
 }
 
+bool ByteCodeEmitter::speculate(const CallExpr *E, const LabelTy &EndLabel) {
+  const Expr *Arg = E->getArg(0);
+  PrimType T = Ctx.classify(Arg->getType()).value_or(PT_Ptr);
+  bool CheckPointer = (T == PT_Ptr);
+  if (!this->emitBCP(getOffset(EndLabel), CheckPointer, T, E))
+return false;
+  if (!this->visit(Arg))
+return false;
+  return true;
+}
+
 
//===--===//
 // Opcode emitters
 
//===--===//
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.h 
b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
index ac728830527a2..a45f7325569f9 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.h
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
@@ -48,6 +48,9 @@ class ByteCodeEmitter {
   virtual bool visitFunc(const FunctionDecl *E) = 0;
   virtual bool visitExpr(const Expr *E, bool DestroyToplevelScope) = 0;
   virtual bool visitDeclAndReturn(const VarDecl *E, bool ConstantContext) = 0;
+  virtual bool visit(const Expr *E) = 0;
+  virtual bool discard(const Expr *E) = 0;
+  virtual bool emitBool(bool V, const Expr *E) = 0;
 
   /// Emits jumps.
   bool jumpTrue(const LabelTy &Label);
@@ -55,6 +58,8 @@ class ByteCodeEmitter {
   bool jump(const LabelTy &Label);
   bool fallthrough(const LabelTy &Label);
 
+  bool speculate(const CallExpr *E, const LabelTy &EndLabel);
+
   /// We're always emitting bytecode.
   bool isActive() const { return true; }
 
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 281fb7e14a57d..3eca12897681d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4681,6 +4681,28 @@ bool Compiler::visitAPValueInitializer(const 
APValue &Val,
 template 
 bool Compiler::VisitBuiltinCallExpr(const CallExpr *E,
  unsigned BuiltinID) {
+
+  if (BuiltinID == Builtin::BI__builtin_constant_p) {
+// Void argument is always invalid and harder to handle later.
+if (E->getArg(0)->getType()->isVoidType()) {
+  if (DiscardResult)
+return true;
+  return this->emitConst(0, E);
+}
+
+if (!this->emitStartSpeculation(E))
+  return false;
+LabelTy EndLabel = this->getLabel();
+if (!this->speculate(E, EndLabel))
+  return false;
+this->fallthrough(EndLabel);
+if (!this->emitEndSpeculation(E))
+  return false;
+if (DiscardResult)
+  return this->emitPop(classifyPrim(E), E);
+return true;
+  }
+
   const Function *Func = getFunction(E->getDirectCallee());
   if (!Func)
 return false;
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index 77fcc3d1b41ce..4e5e13833de32 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -274,14 +274,14 @@ class Compiler : public 
ConstStmtVisitor, bool>,
   /// Evaluates an expression and places the result on the stack. If the
   /// expression is of composite type, a local variable will be created
   /// and a pointer to said variable will be placed on the stack.
-  bool visit(const Expr *E);
+  bool visit(const Expr *E) override;
   /// Compiles an initializer. This is like visit() but it will never
   /// create a variable and instead rely on a variable already having
   /// been created. visitInitializer() then relies on a pointer to this
   /// variable being 

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

2025-03-06 Thread Henrich Lauko via cfe-commits


@@ -94,10 +203,59 @@ void CIRGenFunction::emitVarDecl(const VarDecl &d) {
 
   assert(d.hasLocalStorage());
 
-  assert(!cir::MissingFeatures::opAllocaVarDeclContext());
+  CIRGenFunction::VarDeclContext varDeclCtx{*this, &d};
   return emitAutoVarDecl(d);
 }
 
+void CIRGenFunction::emitScalarInit(const Expr *init, mlir::Location loc,
+LValue lvalue, bool capturedByInit) {
+  Qualifiers::ObjCLifetime lifetime = Qualifiers::ObjCLifetime::OCL_None;

xlauko wrote:

Why not:
```
  Qualifiers::ObjCLifetime lifetime = lvalue.getObjCLifetime();
```
as in main codegen?

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


[clang] [Clang][NFC] Change uses of getAs() to castAs() where the target type is assured. (PR #130188)

2025-03-06 Thread Tom Honermann via cfe-commits

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


[clang] [clang][dataflow] Add test for crash repro and clean up const accessor handling (PR #129930)

2025-03-06 Thread Jan Voung via cfe-commits


@@ -577,57 +580,62 @@ void handleConstMemberCall(const CallExpr *CE,
   auto &ResultLoc = State.Env.getResultObjectLocation(*CE);
   copyRecord(cast(Loc), ResultLoc, State.Env);
 }
-return;
+return true;
   }
 
   // Cache if the const method returns a reference
-  if (RecordLoc != nullptr && CE->isGLValue()) {
+  if (CE->isGLValue()) {
 const FunctionDecl *DirectCallee = CE->getDirectCallee();
 if (DirectCallee == nullptr)
-  return;
+  return false;
 
 StorageLocation &Loc =
 State.Lattice.getOrCreateConstMethodReturnStorageLocation(
 *RecordLoc, DirectCallee, State.Env, [&](StorageLocation &Loc) {
   // no-op
+  // NOTE: if we want to support const ref to pointers or bools
+  // we should initialize their values here.
 });
 
 State.Env.setStorageLocation(*CE, Loc);
-return;
-  }
-
-  // Cache if the const method returns a boolean or pointer type.
-  // We may decide to cache other return types in the future.
-  if (RecordLoc != nullptr &&
-  (CE->getType()->isBooleanType() || CE->getType()->isPointerType())) {
+return true;
+  } else if (CE->getType()->isBooleanType() || CE->getType()->isPointerType()) 
{
+// Cache if the const method returns a boolean or pointer type.
 Value *Val = State.Lattice.getOrCreateConstMethodReturnValue(*RecordLoc, 
CE,
  State.Env);
 if (Val == nullptr)
-  return;
+  return false;
 State.Env.setValue(*CE, *Val);
-return;
+return true;
   }
 
-  // Perform default handling if the call returns an optional
-  // but wasn't handled above (if RecordLoc is nullptr).
-  if (isSupportedOptionalType(CE->getType())) {
-transferCallReturningOptional(CE, Result, State);
-  }
+  return false;
 }
 
-void transferValue_ConstMemberCall(const CXXMemberCallExpr *MCE,
-   const MatchFinder::MatchResult &Result,
-   LatticeTransferState &State) {
-  handleConstMemberCall(
-  MCE, dataflow::getImplicitObjectLocation(*MCE, State.Env), Result, 
State);
+void transferConstMemberCall(const CXXMemberCallExpr *MCE,
+ const MatchFinder::MatchResult &Result,
+ LatticeTransferState &State) {
+  if (!handleConstMemberCall(
+  MCE, dataflow::getImplicitObjectLocation(*MCE, State.Env), Result,
+  State)) {
+// Perform default handling if the call returns an optional,
+// but wasn't handled.
+if (isSupportedOptionalType(MCE->getType()))
+  transferCallReturningOptional(MCE, Result, State);

jvoung wrote:

I was trying not to repeat the default handling too much (in the return false 
cases of handleConstMemberCall -- or have a lambda or something that I call), 
but consolidated to one place now that is shared w/ these two transfer 
functions.

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


[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

2025-03-06 Thread Alex Voicu via cfe-commits

AlexVlx wrote:

I'm not super thrilled about NOT having to introduce a type name, I'm not 
looking forward to the exciting world of `void foo(int 
__attribute__((ext_vector_type(4))) x)` replacing `void foo(int4 x)`.

I am extremely not at ease with flipping this to be a C++ attribute. Back in 
the dawn of time, C++ attributes were meant to be non-semantic / removable with 
no effect. This has kindof become muddled throughout the years, and we're 
probably moving away from that, and yes you have namespaced it, but I'd like 
such things to not be super cute and to remain clearly double prefix scary 
things.

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


[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

jhuber6 wrote:

> I'm not super thrilled about NOT having to introduce a type name, I'm not 
> looking forward to the exciting world of `void foo(int 
> __attribute__((ext_vector_type(4))) x)` replacing `void foo(int4 x)`.

This makes introducing a type name easier because you can use `using` with 
templates. But I really don't think that it makes sense to restrict this to 
`only` typedef, it's even listed as a FIXME in the original patch.

> I am extremely not at ease with flipping this to be a C++ attribute. Back in 
> the dawn of time, C++ attributes were meant to be non-semantic / removable 
> with no effect. This has kindof become muddled throughout the years, and 
> we're probably moving away from that, and yes you have namespaced it, but I'd 
> like such things to not be super cute and to remain clearly double prefix 
> scary things.

I think 
https://github.com/llvm/llvm-project/commit/301eb6b68f30074ee3a90e2dfbd11dfd87076323
 tried to solve some of those issues. A lot of type / expression level 
attributes are expected to be droppable, but we have tons of existing ones that 
definitely aren't. E.g. address spaces and the fifty different vector types for 
each target. I could force it to be double prefixed, but this really still 
should be a type level attribute, since it maps 1-to-1 with the LLVM vector 
type. I'd greatly prefer not to arbitrarily restrict it though, since it would 
be a major outlier.

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


[clang] [llvm] [MTE] generalize overalignment / size of MTE globals (PR #121957)

2025-03-06 Thread Florian Mayer via cfe-commits

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

>From 2feb85c15f64546cb6874e1ca0a1310bd1e1bedd Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Tue, 7 Jan 2025 07:57:09 -0800
Subject: [PATCH 1/6] =?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
---
 llvm/include/llvm/IR/GlobalVariable.h  |  7 +
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 34 ++
 llvm/lib/IR/Globals.cpp| 10 +++
 3 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/llvm/include/llvm/IR/GlobalVariable.h 
b/llvm/include/llvm/IR/GlobalVariable.h
index 83e484816d7d4..c1f8cdc4fd0a6 100644
--- a/llvm/include/llvm/IR/GlobalVariable.h
+++ b/llvm/include/llvm/IR/GlobalVariable.h
@@ -267,6 +267,13 @@ class GlobalVariable : public GlobalObject, public 
ilist_node {
getAttributes().hasAttribute("rodata-section");
   }
 
+  MaybeAlign getRequiredGlobalAlignment() {
+return isTagged() && getAlign().valueOrOne() < 16 ? MaybeAlign(16)
+  : std::nullopt;
+  }
+
+  std::optional getRequiredGlobalSize();
+
   /// Get the custom code model raw value of this global.
   ///
   unsigned getCodeModelRaw() const {
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 7bd3fb33b47d2..8e594a8f92b20 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2398,17 +2398,23 @@ void 
AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
   OutStreamer->emitBinaryData(Buf);
 }
 
-static void tagGlobalDefinition(Module &M, GlobalVariable *G) {
-  Constant *Initializer = G->getInitializer();
+static uint64_t globalSize(const GlobalVariable &G) {
+  const Constant *Initializer = G.getInitializer();
   uint64_t SizeInBytes =
-  M.getDataLayout().getTypeAllocSize(Initializer->getType());
+  G.getParent()->getDataLayout().getTypeAllocSize(Initializer->getType());
 
-  uint64_t NewSize = alignTo(SizeInBytes, 16);
-  if (SizeInBytes != NewSize) {
+  return SizeInBytes;
+}
+
+static void tagGlobalDefinition(GlobalVariable *G) {
+  Module &M = *G->getParent();
+  uint64_t SizeInBytes = globalSize(*G);
+  if (auto NewSize = G->getRequiredGlobalSize()) {
+assert(*NewSize > SizeInBytes);
 // Pad the initializer out to the next multiple of 16 bytes.
-llvm::SmallVector Init(NewSize - SizeInBytes, 0);
+llvm::SmallVector Init(*NewSize - SizeInBytes, 0);
 Constant *Padding = ConstantDataArray::get(M.getContext(), Init);
-Initializer = ConstantStruct::getAnon({Initializer, Padding});
+auto *Initializer = ConstantStruct::getAnon({G->getInitializer(), 
Padding});
 auto *NewGV = new GlobalVariable(
 M, Initializer->getType(), G->isConstant(), G->getLinkage(),
 Initializer, "", G, G->getThreadLocalMode(), G->getAddressSpace());
@@ -2422,8 +2428,10 @@ static void tagGlobalDefinition(Module &M, 
GlobalVariable *G) {
 G = NewGV;
   }
 
-  if (G->getAlign().valueOrOne() < 16)
-G->setAlignment(Align(16));
+  if (auto Align = G->getRequiredGlobalAlignment()) {
+assert(*Align > G->getAlign().valueOrOne());
+G->setAlignment(*Align);
+  }
 
   // Ensure that tagged globals don't get merged by ICF - as they should have
   // different tags at runtime.
@@ -2438,12 +2446,14 @@ bool AsmPrinter::doFinalization(Module &M) {
 
   std::vector GlobalsToTag;
   for (GlobalVariable &G : M.globals()) {
-if (G.isDeclaration() || !G.isTagged())
+if (G.isDeclaration())
   continue;
-GlobalsToTag.push_back(&G);
+if (G.getRequiredGlobalAlignment().has_value() ||
+G.getRequiredGlobalSize().has_value())
+  GlobalsToTag.push_back(&G);
   }
   for (GlobalVariable *G : GlobalsToTag)
-tagGlobalDefinition(M, G);
+tagGlobalDefinition(G);
 
   // Gather all GOT equivalent globals in the module. We really need two
   // passes over the globals: one to compute and another to avoid its emission
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index db5e1cb57b1ba..79ff120c250e4 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -540,6 +540,16 @@ void GlobalVariable::setCodeModel(CodeModel::Model CM) {
   assert(getCodeModel() == CM && "Code model representation error!");
 }
 
+std::optional GlobalVariable::getRequiredGlobalSize() {
+  if (!isTagged())
+return std::nullopt;
+  Constant *Initializer = getInitializer();
+  uint64_t SizeInBytes =
+  getParent()->getDataLayout().getTypeAllocSize(Initializer->getType());
+  uint64_t Aligned = alignTo(SizeInBytes, 16);
+  return Aligned != SizeInBytes ? std::optional(Aligned) : std::nullopt;
+}
+
 
//===--===//
 // GlobalAlias Implementation
 

[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

2025-03-06 Thread Alex Voicu via cfe-commits

AlexVlx wrote:

> > I'm not super thrilled about NOT having to introduce a type name, I'm not 
> > looking forward to the exciting world of `void foo(int 
> > __attribute__((ext_vector_type(4))) x)` replacing `void foo(int4 x)`.
> 
> This makes introducing a type name easier because you can use `using` with 
> templates. But I really don't think that it makes sense to restrict this to 
> _only_ typedef, it's even listed as a FIXME in the original patch.

It is not restricted to `typedef` today, you can use it with `using`: 
. Not sure what you have in mind when you 
mention templates, there were indeed some oddities around them in dependent 
contexts, but this patch wouldn't address those I don't think so it's possible 
they got sorted out. Could you please clarify?

> I could force it to be double prefixed, but this really still should be a 
> type level attribute, since it maps 1-to-1 with the LLVM vector type. I'd 
> greatly prefer not to arbitrarily restrict it though, since it would be a 
> major outlier.

I think you misunderstand, possibly because of my wording. I am not asking you 
to double prefix, I am saying you should not make this a C++ attribute, and 
leave it exclusively as is is today i.e. do not change it's spelling from GNU 
to Clang, which was called out in the initial design (confusingly tied to OCL, 
but different kettle of fish). It is perfectly fine and desirable for this to 
only be available as `__attribute__((ext_vector_type))`



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


[clang] [compiler-rt] [lld] [llvm] [InstrProf] Remove -forder-file-instrumentation (PR #130192)

2025-03-06 Thread Ellis Hoag via cfe-commits

https://github.com/ellishg created 
https://github.com/llvm/llvm-project/pull/130192

Completely remove `-forder-file-instrumentation`. This was deprecated in 
https://github.com/llvm/llvm-project/pull/121514 and removal was planned in 
https://discourse.llvm.org/t/deprecate-forder-file-instrumentation-in-favor-of-temporal-profiling/83903.
 Since LLVM 20 has been cut 
(https://github.com/llvm/llvm-project/releases/tag/llvmorg-20.1.0), we can 
remove this feature.

>From 72109c24229ce3a1deda9f8303e6e75677cd0ce4 Mon Sep 17 00:00:00 2001
From: Ellis Hoag 
Date: Thu, 6 Mar 2025 14:17:51 -0800
Subject: [PATCH] [InstrProf] Remove -forder-file-instrumentation

---
 clang/docs/UsersManual.rst|   1 -
 clang/include/clang/Driver/Options.td |  16 +-
 clang/lib/Driver/ToolChain.cpp|   1 -
 clang/lib/Driver/ToolChains/Clang.cpp |  15 --
 clang/lib/Driver/ToolChains/SYCL.cpp  |   5 +-
 clang/test/Driver/clang_f_opts.c  |   8 -
 compiler-rt/include/profile/InstrProfData.inc |  22 ---
 .../include/profile/instr_prof_interface.h|   4 -
 compiler-rt/lib/profile/InstrProfiling.h  |   3 -
 compiler-rt/lib/profile/InstrProfilingFile.c  |  91 +-
 .../lib/profile/InstrProfilingPlatformAIX.c   |  11 +-
 .../profile/InstrProfilingPlatformDarwin.c|   4 -
 .../lib/profile/InstrProfilingPlatformLinux.c |   5 -
 .../lib/profile/InstrProfilingPlatformOther.c |   4 -
 .../profile/InstrProfilingPlatformWindows.c   |   3 -
 .../profile/Inputs/instrprof-order-file.c |  17 --
 .../test/profile/instrprof-order-file.test|  17 --
 lld/test/MachO/start-end.s|  18 --
 .../llvm/ProfileData/InstrProfData.inc|  22 ---
 .../Instrumentation/InstrOrderFile.h  |  27 ---
 llvm/lib/Passes/PassBuilder.cpp   |   1 -
 llvm/lib/Passes/PassBuilderPipelines.cpp  |   8 -
 llvm/lib/Passes/PassRegistry.def  |   1 -
 .../Transforms/Instrumentation/CMakeLists.txt |   1 -
 .../Instrumentation/InstrOrderFile.cpp| 169 --
 .../Instrumentation/InstrOrderFile/basic.ll   |  23 ---
 .../lib/Transforms/Instrumentation/BUILD.gn   |   1 -
 27 files changed, 14 insertions(+), 484 deletions(-)
 delete mode 100644 compiler-rt/test/profile/Inputs/instrprof-order-file.c
 delete mode 100644 compiler-rt/test/profile/instrprof-order-file.test
 delete mode 100644 
llvm/include/llvm/Transforms/Instrumentation/InstrOrderFile.h
 delete mode 100644 llvm/lib/Transforms/Instrumentation/InstrOrderFile.cpp
 delete mode 100644 llvm/test/Instrumentation/InstrOrderFile/basic.ll

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 8213334b61c22..f70f786c07085 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3195,7 +3195,6 @@ be collected.
the profile file to ``Name``.
  * ``void __llvm_profile_reset_counters(void)``: resets all counters to zero.
  * ``int __llvm_profile_dump(void)``: write the profile data to disk.
- * ``int __llvm_orderfile_dump(void)``: write the order file to disk.
 
 For example, the following pattern can be used to skip profiling program
 initialization, profile two specific hot regions, and skip profiling program
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d0414aba35209..04eb01e146853 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1811,15 +1811,13 @@ def fprofile_continuous : Flag<["-"], 
"fprofile-continuous">,
 HelpText<"Enable continuous instrumentation profiling mode">,
 MarshallingInfoFlag>;
 
-defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
-  CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption, CC1Option],
-  " pseudo probes for sample profiling">>;
-def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
-Group, Visibility<[ClangOption, CC1Option, CLOption]>,
-HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var). Deprecated, please use -ftemporal-profile">;
+defm pseudo_probe_for_profiling
+: BoolFOption<"pseudo-probe-for-profiling",
+  CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, CC1Option],
+" pseudo probes for sample profiling">>;
 def fprofile_list_EQ : Joined<["-"], "fprofile-list=">,
 Group, Visibility<[ClangOption, CC1Option, CLOption]>,
 HelpText<"Filename defining the list of functions/files to instrument. "
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 65acbe8a9dbea..7700321b7b8cb 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -952,7 +952,6 @@ bool Too

[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

jhuber6 wrote:

I suppose I could try to introduce the RegularKeyword usage that the other 
patch used? That would make it like `__ext_vector_type` I think. (And honestly, 
while I'm at it, do you think we could drop the `ext`?)

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


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

2025-03-06 Thread Andy Kaylor via cfe-commits


@@ -0,0 +1,322 @@
+//===--===//
+//
+// 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 contains code to emit Constant Expr nodes as LLVM code.
+//
+//===--===//
+
+#include "Address.h"
+#include "CIRGenConstantEmitter.h"
+#include "CIRGenFunction.h"
+#include "CIRGenModule.h"
+#include "mlir/IR/Attributes.h"
+#include "mlir/IR/BuiltinAttributeInterfaces.h"
+#include "mlir/IR/BuiltinAttributes.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
+#include "clang/AST/OperationKinds.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/AST/StmtVisitor.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/Specifiers.h"
+#include "clang/CIR/Dialect/IR/CIRAttrs.h"
+#include "clang/CIR/Dialect/IR/CIRTypes.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Sequence.h"
+#include "llvm/Support/ErrorHandling.h"
+
+using namespace clang;
+using namespace clang::CIRGen;
+
+//===--===//
+// ConstExprEmitter
+//===--===//
+
+// This class only needs to handle arrays, structs and unions.
+//
+// In LLVM codegen, when outside C++11 mode, those types are not constant
+// folded, while all other types are handled by constant folding.
+//
+// In CIR codegen, instead of folding things here, we should defer that work
+// to MLIR: do not attempt to do much here.
+class ConstExprEmitter
+: public StmtVisitor {
+  CIRGenModule &cgm;
+  LLVM_ATTRIBUTE_UNUSED ConstantEmitter &emitter;
+
+public:
+  ConstExprEmitter(ConstantEmitter &emitter)
+  : cgm(emitter.cgm), emitter(emitter) {}
+
+  
//======//
+  //Visitor Methods
+  
//======//
+
+  mlir::Attribute VisitStmt(Stmt *S, QualType T) { return {}; }
+
+  mlir::Attribute VisitConstantExpr(ConstantExpr *ce, QualType t) {
+if (mlir::Attribute result = emitter.tryEmitConstantExpr(ce))
+  return result;
+return Visit(ce->getSubExpr(), t);
+  }
+
+  mlir::Attribute VisitParenExpr(ParenExpr *pe, QualType t) {
+return Visit(pe->getSubExpr(), t);
+  }
+
+  mlir::Attribute
+  VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *pe,
+QualType t) {
+return Visit(pe->getReplacement(), t);
+  }
+
+  mlir::Attribute VisitGenericSelectionExpr(GenericSelectionExpr *ge,
+QualType t) {
+return Visit(ge->getResultExpr(), t);
+  }
+
+  mlir::Attribute VisitChooseExpr(ChooseExpr *ce, QualType t) {
+return Visit(ce->getChosenSubExpr(), t);
+  }
+
+  mlir::Attribute VisitCompoundLiteralExpr(CompoundLiteralExpr *e, QualType t) 
{
+return Visit(e->getInitializer(), t);
+  }
+
+  mlir::Attribute VisitCastExpr(CastExpr *e, QualType destType) {
+cgm.errorNYI(e->getBeginLoc(), "ConstExprEmitter::VisitCastExpr");
+return {};
+  }
+
+  mlir::Attribute VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die, QualType t) 
{
+cgm.errorNYI(die->getBeginLoc(),
+ "ConstExprEmitter::VisitCXXDefaultInitExpr");
+return {};
+  }
+
+  mlir::Attribute VisitExprWithCleanups(ExprWithCleanups *e, QualType t) {
+// Since this about constant emission no need to wrap this under a scope.
+return Visit(e->getSubExpr(), t);
+  }
+
+  mlir::Attribute VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *e,
+QualType t) {
+return Visit(e->getSubExpr(), t);
+  }
+
+  mlir::Attribute VisitImplicitValueInitExpr(ImplicitValueInitExpr *E,
+ QualType T) {
+cgm.errorNYI(E->getBeginLoc(),
+ "ConstExprEmitter::VisitImplicitValueInitExpr");
+return {};
+  }
+
+  mlir::Attribute VisitInitListExpr(InitListExpr *ile, QualType t) {
+cgm.errorNYI(ile->getBeginLoc(), "ConstExprEmitter::VisitInitListExpr");
+return {};
+  }
+
+  mlir::Attribute VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *e,
+QualType destType) {
+mlir::Attribute c = Visit(e->getBase(), destType);
+if (!c)
+  return {};
+
+cgm.errorNYI(e->getBeginLoc(),
+ "ConstExprEmitter::VisitDesignatedInitUpdateExpr");
+return {};
+  }
+
+  mlir::Attribute VisitCXXConstructExpr(CXXConstructExpr *e, QualType ty) {
+cgm.errorNYI(e->get

[clang] [llvm] [AArch64][SVE] Improve fixed-length addressing modes. (PR #129732)

2025-03-06 Thread Omair Javaid via cfe-commits

omjavaid wrote:

This PR appears to have broken 
[clang-aarch64-sve-vls](https://lab.llvm.org/buildbot/#/builders/143) buildbot. 
Here is the failing build 
https://lab.llvm.org/buildbot/#/builders/143/builds/5952



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


[clang] Fix amdgpu-arch for dll name on Windows (PR #101350)

2025-03-06 Thread Yaxun Liu via cfe-commits


@@ -31,16 +44,118 @@ typedef hipError_t (*hipGetDeviceCount_t)(int *);
 typedef hipError_t (*hipDeviceGet_t)(int *, int);
 typedef hipError_t (*hipGetDeviceProperties_t)(hipDeviceProp_t *, int);
 
-int printGPUsByHIP() {
+extern cl::opt Verbose;
+
 #ifdef _WIN32
-  constexpr const char *DynamicHIPPath = "amdhip64.dll";
+static std::vector getSearchPaths() {
+  std::vector Paths;
+
+  // Get the directory of the current executable
+  if (auto MainExe = sys::fs::getMainExecutable(nullptr, nullptr);
+  !MainExe.empty())
+Paths.push_back(sys::path::parent_path(MainExe).str());
+
+  // Get the system directory
+  wchar_t SystemDirectory[MAX_PATH];
+  if (GetSystemDirectoryW(SystemDirectory, MAX_PATH) > 0) {
+std::string Utf8SystemDir;
+if (convertUTF16ToUTF8String(
+ArrayRef(reinterpret_cast(SystemDirectory),
+wcslen(SystemDirectory)),
+Utf8SystemDir))
+  Paths.push_back(Utf8SystemDir);
+  }
+
+  // Get the Windows directory
+  wchar_t WindowsDirectory[MAX_PATH];
+  if (GetWindowsDirectoryW(WindowsDirectory, MAX_PATH) > 0) {
+std::string Utf8WindowsDir;
+if (convertUTF16ToUTF8String(
+ArrayRef(reinterpret_cast(WindowsDirectory),
+wcslen(WindowsDirectory)),
+Utf8WindowsDir))
+  Paths.push_back(Utf8WindowsDir);
+  }
+
+  // Get the current working directory
+  SmallVector CWD;
+  if (sys::fs::current_path(CWD))
+Paths.push_back(std::string(CWD.begin(), CWD.end()));
+
+  // Get the PATH environment variable
+  if (std::optional PathEnv = sys::Process::GetEnv("PATH")) {
+SmallVector PathList;
+StringRef(*PathEnv).split(PathList, sys::EnvPathSeparator);
+for (auto &Path : PathList)
+  Paths.push_back(Path.str());
+  }
+
+  return Paths;
+}
+
+// Custom comparison function for dll name
+static bool compareVersions(const std::string &a, const std::string &b) {
+  // Extract version numbers
+  int versionA = std::stoi(a.substr(a.find_last_of('_') + 1));
+  int versionB = std::stoi(b.substr(b.find_last_of('_') + 1));
+  return versionA > versionB;
+}
+
+#endif
+
+// On Windows, prefer amdhip64_n.dll where n is ROCm major version and greater
+// value of n takes precedence. If amdhip64_n.dll is not found, fall back to
+// amdhip64.dll. The reason is that a normal driver installation only has
+// amdhip64_n.dll but we do not know what n is since this program may be used
+// with a future version of HIP runtime.
+//
+// On Linux, always use default libamdhip64.so.
+static std::pair findNewestHIPDLL() {
+#ifdef _WIN32
+  StringRef HipDLLPrefix = "amdhip64_";
+  StringRef HipDLLSuffix = ".dll";
+
+  std::vector SearchPaths = getSearchPaths();
+  std::vector DLLNames;
+
+  for (const auto &Dir : SearchPaths) {
+std::error_code EC;
+for (sys::fs::directory_iterator DirIt(Dir, EC), DirEnd;
+ DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+  StringRef Filename = sys::path::filename(DirIt->path());
+  if (Filename.starts_with(HipDLLPrefix) &&
+  Filename.ends_with(HipDLLSuffix))
+DLLNames.push_back(sys::path::convert_to_slash(DirIt->path()));
+}
+if (!DLLNames.empty())
+  break;
+  }
+
+  if (DLLNames.empty())
+return {"amdhip64.dll", true};
+
+  std::sort(DLLNames.begin(), DLLNames.end(), compareVersions);

yxsamliu wrote:

will do

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


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

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

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


[clang] [clang] Fix typos in options text. (PR #130129)

2025-03-06 Thread via cfe-commits

https://github.com/hstk30-hw approved this pull request.


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


[clang] [hexagon] Enable --eh-frame-hdr (PR #130225)

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Brian Cain (androm3da)


Changes

The missing `PT_GNU_EH_FRAME` was causing C++ exception handling test failures 
in llvm-test-suite.  We should unconditionally add this argument like the other 
drivers do.

Discovered-by: Alexey Karyakin  
Fixes: #129745

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


3 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+1) 
- (modified) clang/test/Driver/hexagon-toolchain-elf.c (+1) 
- (modified) clang/test/Driver/hexagon-toolchain-linux.c (+1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 7ca5ab9af8810..6ea701a7882d1 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -313,6 +313,7 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
  // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_static_libgcc);
 
+  CmdArgs.push_back("--eh-frame-hdr");
   
//
   //
   
//
diff --git a/clang/test/Driver/hexagon-toolchain-elf.c 
b/clang/test/Driver/hexagon-toolchain-elf.c
index be812dda40d57..de2ebfeeda26c 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -555,6 +555,7 @@
 // RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
 // RUN:   -mcpu=hexagonv60 \
 // RUN:   -fuse-ld=lld %s 2>&1 | FileCheck -check-prefix=CHECK382 %s
+// CHECK382:  "--eh-frame-hdr
 // CHECK382-NOT:  "-march=
 // CHECK382-NOT:  "-mcpu=
 // 
-
diff --git a/clang/test/Driver/hexagon-toolchain-linux.c 
b/clang/test/Driver/hexagon-toolchain-linux.c
index 6f7f3b20f9141..e791353cca07f 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -127,6 +127,7 @@
 // RUN:--target=hexagon-unknown-linux-musl %s -### 2>&1 \
 // RUN:| FileCheck -check-prefix=CHECK011 %s
 // CHECK011:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK011:   "--eh-frame-hdr"
 // CHECK011:   crt1.o
 // CHECK011-NOT:  "-lunwind"
 // CHECK011-NOT:  "-lgcc_eh"

``




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


[clang] [hexagon] Enable --eh-frame-hdr (PR #130225)

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-hexagon

Author: Brian Cain (androm3da)


Changes

The missing `PT_GNU_EH_FRAME` was causing C++ exception handling test failures 
in llvm-test-suite.  We should unconditionally add this argument like the other 
drivers do.

Discovered-by: Alexey Karyakin  
Fixes: #129745

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


3 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+1) 
- (modified) clang/test/Driver/hexagon-toolchain-elf.c (+1) 
- (modified) clang/test/Driver/hexagon-toolchain-linux.c (+1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 7ca5ab9af8810..6ea701a7882d1 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -313,6 +313,7 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
  // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_static_libgcc);
 
+  CmdArgs.push_back("--eh-frame-hdr");
   
//
   //
   
//
diff --git a/clang/test/Driver/hexagon-toolchain-elf.c 
b/clang/test/Driver/hexagon-toolchain-elf.c
index be812dda40d57..de2ebfeeda26c 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -555,6 +555,7 @@
 // RUN:   -ccc-install-dir %S/Inputs/hexagon_tree/Tools/bin \
 // RUN:   -mcpu=hexagonv60 \
 // RUN:   -fuse-ld=lld %s 2>&1 | FileCheck -check-prefix=CHECK382 %s
+// CHECK382:  "--eh-frame-hdr
 // CHECK382-NOT:  "-march=
 // CHECK382-NOT:  "-mcpu=
 // 
-
diff --git a/clang/test/Driver/hexagon-toolchain-linux.c 
b/clang/test/Driver/hexagon-toolchain-linux.c
index 6f7f3b20f9141..e791353cca07f 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -127,6 +127,7 @@
 // RUN:--target=hexagon-unknown-linux-musl %s -### 2>&1 \
 // RUN:| FileCheck -check-prefix=CHECK011 %s
 // CHECK011:   InstalledDir: [[INSTALLED_DIR:.+]]
+// CHECK011:   "--eh-frame-hdr"
 // CHECK011:   crt1.o
 // CHECK011-NOT:  "-lunwind"
 // CHECK011-NOT:  "-lgcc_eh"

``




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


[clang] [llvm] [HLSL][NFC] Update resource metadata tests to not use obsolete metadata annotations (PR #130222)

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-directx

Author: Helena Kotas (hekota)


Changes

Update resource metadata tests to generate metadata based on 
`llvm.dx.resource.handlefrombinding` data collected in 
`DXILResourceBindingAnalysis`.

- `UAVMetadata.ll` is renamed to `uav_metadata.ll`, updated and placed under 
`Metadata` directory in `llvm/test/CodeGen/DirectX`
- `srv_metadata.ll` is a new test for SRV resource metadata
- `cbuf.ll` and `legacy_cb_layout_{0|1}.ll` tests were merged and updated into 
`cbuffer_metadata.ll`
- `legacy_cb_layout_{2|3}.ll` tests we moved to `cbuffer.hlsl` in Clang CodeGen 
because there were more of a layout  than metadata tests

Related to [#114126](https://github.com/llvm/llvm-project/issues/114126)



---

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


10 Files Affected:

- (modified) clang/test/CodeGenHLSL/cbuffer.hlsl (+76-2) 
- (added) llvm/test/CodeGen/DirectX/Metadata/cbuffer_metadata.ll (+80) 
- (added) llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll (+103) 
- (added) llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll (+135) 
- (removed) llvm/test/CodeGen/DirectX/UAVMetadata.ll (-77) 
- (removed) llvm/test/CodeGen/DirectX/cbuf.ll (-37) 
- (removed) llvm/test/CodeGen/DirectX/legacy_cb_layout_0.ll (-14) 
- (removed) llvm/test/CodeGen/DirectX/legacy_cb_layout_1.ll (-37) 
- (removed) llvm/test/CodeGen/DirectX/legacy_cb_layout_2.ll (-51) 
- (removed) llvm/test/CodeGen/DirectX/legacy_cb_layout_3.ll (-81) 


``diff
diff --git a/clang/test/CodeGenHLSL/cbuffer.hlsl 
b/clang/test/CodeGenHLSL/cbuffer.hlsl
index 38093c6dfacd7..b5e435619438f 100644
--- a/clang/test/CodeGenHLSL/cbuffer.hlsl
+++ b/clang/test/CodeGenHLSL/cbuffer.hlsl
@@ -20,6 +20,14 @@
 // CHECK: %anon = type <{ float }>
 // CHECK: %anon.0 = type <{ <2 x i32> }>
 
+// CHECK: %__cblayout_CB_A = type <{ [2 x double], [3 x <3 x float>], float, 
[3 x double], half, [1 x <2 x double>], float, [2 x <3 x half>], <3 x half> }>
+// CHECK: %__cblayout_CB_B = type <{ [3 x <3 x double>], <3 x half> }>
+// CHECK: %__cblayout_CB_C = type <{ i32, target("dx.Layout", %F, 96, 0, 16, 
28, 32, 56, 64, 80, 84, 90), half, target("dx.Layout", %G, 258, 0, 48, 64, 
256), double }>
+
+// CHECK: %F = type <{ double, <3 x float>, float, <3 x double>, half, <2 x 
double>, float, <3 x half>, <3 x half> }>
+// CHECK: %G = type <{ target("dx.Layout", %E, 36, 0, 8, 16, 20, 22, 24, 32), 
[1 x float], [2 x target("dx.Layout", %F, 96, 0, 16, 28, 32, 56, 64, 80, 84, 
90)], half }>
+// CHECK: %E = type <{ float, double, float, half, i16, i64, i32 }>
+
 cbuffer CBScalars : register(b1, space5) {
   float a1;
   double a2;
@@ -155,6 +163,64 @@ cbuffer CBMix {
 uint16_t f9;
 };  
 
+// CHECK: @CB_A.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB_A, 188, 0, 32, 76, 80, 120, 128, 144, 160, 
182))
+
+cbuffer CB_A {
+  double B0[2];
+  float3 B1[3];
+  float B2;
+  double B3[3];
+  half B4;
+  double2 B5[1];
+  float B6;
+  half3 B7[2];
+  half3 B8;
+}
+
+// CHECK: @CB_B.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB_B, 94, 0, 88))
+cbuffer CB_B {
+  double3 B9[3];
+  half3 B10;
+}
+
+struct E {
+  float A0;
+  double A1;
+  float A2;
+  half A3;
+  int16_t A4;
+  int64_t A5;
+  int A6;
+};
+
+struct F {
+  double B0;
+  float3 B1;
+  float B2;
+  double3 B3;
+  half B4;
+  double2 B5;
+  float B6;
+  half3 B7;
+  half3 B8;
+};
+
+struct G {
+  E C0;
+  float C1[1];
+  F C2[2];
+  half C3;
+};
+
+// CHECK: @CB_C.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CB_C, 400, 0, 16, 112, 128, 392))
+cbuffer CB_C {
+  int D0;
+  F D1;
+  half D2;
+  G D3;
+  double D4;
+}
+
 // CHECK: define internal void @_init_resource_CBScalars.cb()
 // CHECK-NEXT: entry:
 // CHECK-NEXT: %[[HANDLE1:.*]] = call target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBScalars, 56, 0, 8, 16, 24, 32, 36, 40, 48))
@@ -171,7 +237,7 @@ RWBuffer Buf;
 
 [numthreads(4,1,1)]
 void main() {
-  Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1;
+  Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1 + B1[0].x + B10.z + D1.B2;
 }
 
 // CHECK: define internal void @_GLOBAL__sub_I_cbuffer.hlsl()
@@ -179,7 +245,8 @@ void main() {
 // CHECK-NEXT: call void @_init_resource_CBScalars.cb()
 // CHECK-NEXT: call void @_init_resource_CBArrays.cb()
 
-// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], 
![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]]}
+// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], 
![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]],
+// CHECK-SAME: ![[CB_A:[0-9]+]], ![[CB_B:[0-9]+]], ![[CB_C:[0-9]+]]}
 
 // CHECK: ![[CBSCALARS]] = !{ptr @CBScalars.cb, ptr addrspace(2) @a1, ptr 
addrspace(2) @a2, ptr addrspace(2) @a3, ptr addrspace(2) @a4,
 // CHECK-SAME: ptr addrspace(2) @a5, ptr addrspace(2) @a6, ptr addrspace(2) 
@a7, ptr addrspace(2) @a8}
@@ -195,

[clang] [llvm] [RISCV] Mark {vl, vtype} as clobber in inline assembly (PR #128636)

2025-03-06 Thread Hank Chang via cfe-commits


@@ -68,7 +68,11 @@ class RISCVTargetInfo : public TargetInfo {
 return TargetInfo::VoidPtrBuiltinVaList;
   }
 
-  std::string_view getClobbers() const override { return ""; }
+  std::string_view getClobbers() const override {
+if (ISAInfo->hasExtension("zve32x"))

HankChang736 wrote:

I just reverted this implementation.

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


[clang] [HLSL] Buffer handle globals should not be constants (PR #130231)

2025-03-06 Thread Justin Bogner via cfe-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/130231

If these are constants their initializers will be removed by InstCombine. 
Change them to not be constants and initialize them with poison.

>From 669992be34615e00e199ed2bbc8eb5ee5bd134ef Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Thu, 6 Mar 2025 17:50:12 -0800
Subject: [PATCH] [HLSL] Buffer handle globals should not be constants

If these are constants their initializers will be removed by
InstCombine. Change them to not be constants and initialize them with
poison.
---
 clang/lib/CodeGen/CGHLSLRuntime.cpp | 13 ++---
 clang/test/CodeGenHLSL/cbuffer.hlsl | 10 +-
 clang/test/CodeGenHLSL/cbuffer_and_namespaces.hlsl  |  6 +++---
 clang/test/CodeGenHLSL/cbuffer_with_packoffset.hlsl |  2 +-
 .../cbuffer_with_static_global_and_function.hlsl|  2 +-
 clang/test/CodeGenHLSL/default_cbuffer.hlsl |  2 +-
 6 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index dc34653e8f497..4e14c6a3e72a2 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -31,7 +31,6 @@
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Value.h"
 #include "llvm/Support/Alignment.h"
-
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
 
@@ -214,12 +213,12 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl 
*BufDecl) {
   llvm::TargetExtType *TargetTy =
   cast(convertHLSLSpecificType(
   ResHandleTy, BufDecl->hasValidPackoffset() ? &Layout : nullptr));
-  llvm::GlobalVariable *BufGV =
-  new GlobalVariable(TargetTy, /*isConstant*/ true,
- GlobalValue::LinkageTypes::ExternalLinkage, nullptr,
- llvm::formatv("{0}{1}", BufDecl->getName(),
-   BufDecl->isCBuffer() ? ".cb" : ".tb"),
- GlobalValue::NotThreadLocal);
+  llvm::GlobalVariable *BufGV = new GlobalVariable(
+  TargetTy, /*isConstant*/ false,
+  GlobalValue::LinkageTypes::ExternalLinkage, PoisonValue::get(TargetTy),
+  llvm::formatv("{0}{1}", BufDecl->getName(),
+BufDecl->isCBuffer() ? ".cb" : ".tb"),
+  GlobalValue::NotThreadLocal);
   CGM.getModule().insertGlobalVariable(BufGV);
 
   // Add globals for constant buffer elements and create metadata nodes
diff --git a/clang/test/CodeGenHLSL/cbuffer.hlsl 
b/clang/test/CodeGenHLSL/cbuffer.hlsl
index 38093c6dfacd7..d70ce0aae7b64 100644
--- a/clang/test/CodeGenHLSL/cbuffer.hlsl
+++ b/clang/test/CodeGenHLSL/cbuffer.hlsl
@@ -31,7 +31,7 @@ cbuffer CBScalars : register(b1, space5) {
   int64_t a8;
 }
 
-// CHECK: @CBScalars.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBScalars, 
+// CHECK: @CBScalars.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBScalars,
 // CHECK-SAME: 56, 0, 8, 16, 24, 32, 36, 40, 48))
 // CHECK: @a1 = external addrspace(2) global float, align 4
 // CHECK: @a2 = external addrspace(2) global double, align 8
@@ -53,7 +53,7 @@ cbuffer CBVectors {
   // FIXME: add a bool vectors after llvm-project/llvm#91639 is added
 }
 
-// CHECK: @CBVectors.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBVectors, 
+// CHECK: @CBVectors.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBVectors,
 // CHECK-SAME: 136, 0, 16, 40, 48, 80, 96, 112))
 // CHECK: @b1 = external addrspace(2) global <3 x float>, align 16
 // CHECK: @b2 = external addrspace(2) global <3 x double>, align 32
@@ -74,7 +74,7 @@ cbuffer CBArrays : register(b2) {
   bool c8[4];
 }
 
-// CHECK: @CBArrays.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBArrays, 
+// CHECK: @CBArrays.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBArrays,
 // CHECK-SAME: 708, 0, 48, 112, 176, 224, 608, 624, 656))
 // CHECK: @c1 = external addrspace(2) global [3 x float], align 4
 // CHECK: @c2 = external addrspace(2) global [2 x <3 x double>], align 32
@@ -105,7 +105,7 @@ struct D {
   Empty es;
 };
 
-// CHECK: @CBStructs.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBStructs, 
+// CHECK: @CBStructs.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBStructs,
 // CHECK-SAME: 246, 0, 16, 32, 64, 144, 238, 240))
 // CHECK: @a = external addrspace(2) global target("dx.Layout", %A, 8, 0), 
align 8
 // CHECK: @b = external addrspace(2) global target("dx.Layout", %B, 14, 0, 8), 
align 8
@@ -129,7 +129,7 @@ struct Test {
 float a, b;
 };
 
-// CHECK: @CBMix.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBMix,
+// CHECK: @CBMix.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBMix,
 // CHECK-SAME: 170, 0, 24, 32, 120, 128, 136, 144, 152, 160, 168))
 // CHECK: @test = external addrspace(2) global [2 

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

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

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

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

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

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

[clang] [lldb] [C++20][Modules] Do not update the declaration generation number if the redeclaration chain completion was delayed. (PR #129982)

2025-03-06 Thread Michael Park via cfe-commits


@@ -9180,6 +9180,12 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, 
NamedDecl **Suggested,
   if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility)
 return true;
 
+  // The external source may have additional definitions of this entity that 
are
+  // visible, so complete the redeclaration chain now.
+  if (auto *Source = Context.getExternalSource()) {
+Source->CompleteRedeclChain(D);
+  }

mpark wrote:

Further findings: in this case, what I'm seeing is that 
[`LazyGenerationalUpdatePtr::get`](https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/ExternalASTSource.h#L487-L497)
 is called twice for [4].

The first invocation, the generation numbers don't match, and 
`CompleteRedeclChain` is called (*outside* of the deserialization stage) and 
gets to 
[`DC->lookup(Name);`](https://github.com/llvm/llvm-project/blob/c6d95c441a29a45782ff72d6cb82839b86fd0e4a/clang/lib/Serialization/ASTReader.cpp#L7862).
 We don't discover the definition in the first invocation.

The second invocation is from 
[here](https://github.com/llvm/llvm-project/blob/c6d95c441a29a45782ff72d6cb82839b86fd0e4a/clang/lib/Sema/SemaType.cpp#L9174)
 (via the `getMostRecentDecl()` call within `getDefinition`). This time, the 
generation numbers **match**, and `CompleteRedeclChain` is **not** called. 
However, if I explicitly invoke `CompleteRedeclChain` on it, it gets to the 
same `DC->lookup(Name);` line as before with exactly the same values for `DC` 
and `Name`. However, this time the definition **is** found. To be clear, this 
is invoking `CompleteRedeclChain` on [4] **directly** rather than on [1], [2] 
or [3], and also not **indirectly** via something like `getMostRecentDecl()` or 
`redecls()` since `CompleteRedeclChain` will not be called through those 
functions because the generation numbers match.

In short, I'm seeing that the `DC->lookup(Name)` has different behaviors 
between two invocations, without either generation numbers changing. I wonder 
if maybe another module was loaded in between the two calls, and the 
`ExternalASTSource`'s generation number should have been incremented but it 
wasn't for some reason...

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


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

2025-03-06 Thread via cfe-commits


@@ -1358,6 +1358,12 @@ def HasVendorXqciint
   AssemblerPredicate<(all_of FeatureVendorXqciint),
  "'Xqciint' (Qualcomm uC Interrupts Extension)">;
 
+def FeatureVendorXqcili : RISCVExperimentalExtension<0, 2, "Qualcomm uC Load 
Large Immediate Extension", []>;

u4f3 wrote:

It seems that this requirement is not explicitly specified in the spec, or I'm 
missing some part of documents somewhere. Anyway I add [FeatureStdExtZca].

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


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

2025-03-06 Thread via cfe-commits

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

>From 5de5813b39245162a6c33ceb36fcc6fd5e988c04 Mon Sep 17 00:00:00 2001
From: Austin 
Date: Thu, 6 Mar 2025 17:25:55 +0800
Subject: [PATCH] [ARM] Using cp15  while mtp =auto and arch is arm_arch6k and
 support thumb2

We follow GCC mtp=auto when arch is arm_arch6k and support thumb2

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

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

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

2025-03-06 Thread via cfe-commits

Author: Owen Pan
Date: 2025-03-06T21:08:25-08:00
New Revision: 3664b4e2d5800eca5c8253a3915b87fa12ea7ebc

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

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

This effectively reverts d1aed486efc6d35a81ca4acbabb4203c4b91cda9
because of
#129426.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 14e984529d640..000a5105ca407 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -116,36 +116,18 @@ class LevelIndentTracker {
 Style.isCSharp()) {
   return 0;
 }
-
-auto IsAccessModifier = [&](const FormatToken &RootToken) {
-  if (Line.Type == LT_AccessModifier || RootToken.isObjCAccessSpecifier())
-return true;
-
-  const auto *Next = RootToken.Next;
-
-  // Handle Qt signals.
-  if (RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) &&
-  Next && Next->is(tok::colon)) {
-return true;
-  }
-
-  if (Next && Next->isOneOf(Keywords.kw_slots, Keywords.kw_qslots) &&
-  Next->Next && Next->Next->is(tok::colon)) {
-return true;
-  }
-
-  // Handle malformed access specifier e.g. 'private' without trailing ':'.
-  return !Next && RootToken.isAccessSpecifier(false);
-};
-
-if (IsAccessModifier(*Line.First)) {
+const auto &RootToken = *Line.First;
+if (Line.Type == LT_AccessModifier ||
+RootToken.isAccessSpecifier(/*ColonRequired=*/false) ||
+RootToken.isObjCAccessSpecifier() ||
+(RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) &&
+ RootToken.Next && RootToken.Next->is(tok::colon))) {
   // The AccessModifierOffset may be overridden by IndentAccessModifiers,
   // in which case we take a negative value of the IndentWidth to simulate
   // the upper indent level.
   return Style.IndentAccessModifiers ? -Style.IndentWidth
  : Style.AccessModifierOffset;
 }
-
 return 0;
   }
 

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index efb22bcdbe53f..6854e224c2631 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3386,75 +3386,15 @@ void UnwrappedLineParser::parseSwitch(bool IsExpr) {
 NestedTooDeep.pop_back();
 }
 
-// Operators that can follow a C variable.
-static bool isCOperatorFollowingVar(tok::TokenKind Kind) {
-  switch (Kind) {
-  case tok::ampamp:
-  case tok::ampequal:
-  case tok::arrow:
-  case tok::caret:
-  case tok::caretequal:
-  case tok::comma:
-  case tok::ellipsis:
-  case tok::equal:
-  case tok::equalequal:
-  case tok::exclaim:
-  case tok::exclaimequal:
-  case tok::greater:
-  case tok::greaterequal:
-  case tok::greatergreater:
-  case tok::greatergreaterequal:
-  case tok::l_paren:
-  case tok::l_square:
-  case tok::less:
-  case tok::lessequal:
-  case tok::lessless:
-  case tok::lesslessequal:
-  case tok::minus:
-  case tok::minusequal:
-  case tok::minusminus:
-  case tok::percent:
-  case tok::percentequal:
-  case tok::period:
-  case tok::pipe:
-  case tok::pipeequal:
-  case tok::pipepipe:
-  case tok::plus:
-  case tok::plusequal:
-  case tok::plusplus:
-  case tok::question:
-  case tok::r_brace:
-  case tok::r_paren:
-  case tok::r_square:
-  case tok::semi:
-  case tok::slash:
-  case tok::slashequal:
-  case tok::star:
-  case tok::starequal:
-return true;
-  default:
-return false;
-  }
-}
-
 void UnwrappedLineParser::parseAccessSpecifier() {
-  FormatToken *AccessSpecifierCandidate = FormatTok;
   nextToken();
   // Understand Qt's slots.
   if (FormatTok->isOneOf(Keywords.kw_slots, Keywords.kw_qslots))
 nextToken();
   // Otherwise, we don't know what it is, and we'd better keep the next token.
-  if (FormatTok->is(tok::colon)) {
+  if (FormatTok->is(tok::colon))
 nextToken();
-addUnwrappedLine();
-  } else if (FormatTok->isNot(tok::coloncolon) &&
- !isCOperatorFollowingVar(FormatTok->Tok.getKind())) {
-// Not a variable name nor namespace name.
-addUnwrappedLine();
-  } else if (AccessSpecifierCandidate) {
-// Consider the access specifier to be a C identifier.
-AccessSpecifierCandidate->Tok.setKind(tok::identifier);
-  }
+  addUnwrappedLine();
 }
 
 /// \brief Parses a requires, decides if it is a clause or an expression.

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp

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

2025-03-06 Thread via cfe-commits

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

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

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

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

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

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

[clang] [lldb] [C++20][Modules] Do not update the declaration generation number if the redeclaration chain completion was delayed. (PR #129982)

2025-03-06 Thread Michael Park via cfe-commits

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


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

2025-03-06 Thread Carlos Alberto Enciso via cfe-commits

https://github.com/CarlosAlbertoEnciso created 
https://github.com/llvm/llvm-project/pull/130255

The IR now includes a global variable for the debugger that holds
the address of the vtable.

Now every class that contains virtual functions, has a static
member (marked as artificial) that identifies where that vtable
is loaded in memory. The unmangled name is '_vtable$'.

This new symbol will allow a debugger to easily associate
classes with the physical location of their VTables using
only the DWARF information. Previously, this had to be done
by searching for ELF symbols with matching names; something
that was time-consuming and error-prone in certain edge cases.


>From 4bd0c48e12114301d8b81e9abe59e538684a6f71 Mon Sep 17 00:00:00 2001
From: Carlos Alberto Enciso 
Date: Tue, 25 Feb 2025 09:23:24 +
Subject: [PATCH] [DebugInfo] Add symbol for debugger with VTable information.

The IR now includes a global variable for the debugger that
holds the address of the vtable.

Now every class that contains virtual functions, has a static
member (marked as artificial) that identifies where that vtable
is loaded in memory. The unmangled name is '_vtable$'.

This new symbol will allow a debugger to easily associate
classes with the physical location of their VTables using
only the DWARF information. Previously, this had to be done
by searching for ELF symbols with matching names; something
that was time-consuming and error-prone in certain edge cases.
---
 clang/lib/CodeGen/CGDebugInfo.cpp |  53 +
 clang/lib/CodeGen/CGDebugInfo.h   |   3 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |   4 +
 ...ble-debug-info-inheritance-simple-base.cpp |  14 ++
 ...table-debug-info-inheritance-simple-base.h |  15 ++
 ...-debug-info-inheritance-simple-derived.cpp |  13 ++
 ...le-debug-info-inheritance-simple-derived.h |  14 ++
 clang/test/CodeGenCXX/debug-info-class.cpp|  26 ++-
 .../CodeGenCXX/debug-info-template-member.cpp |  52 ++---
 .../vtable-debug-info-inheritance-diamond.cpp |  87 
 ...vtable-debug-info-inheritance-multiple.cpp |  72 ++
 ...ble-debug-info-inheritance-simple-main.cpp |  87 
 .../vtable-debug-info-inheritance-simple.cpp  |  55 +
 .../vtable-debug-info-inheritance-virtual.cpp |  87 
 clang/test/Modules/ExtDebugInfo.cpp   |  10 +-
 .../vtable-debug-info-inheritance-simple.ll   | 206 ++
 16 files changed, 755 insertions(+), 43 deletions(-)
 create mode 100644 
clang/test/CodeGenCXX/Inputs/vtable-debug-info-inheritance-simple-base.cpp
 create mode 100644 
clang/test/CodeGenCXX/Inputs/vtable-debug-info-inheritance-simple-base.h
 create mode 100644 
clang/test/CodeGenCXX/Inputs/vtable-debug-info-inheritance-simple-derived.cpp
 create mode 100644 
clang/test/CodeGenCXX/Inputs/vtable-debug-info-inheritance-simple-derived.h
 create mode 100644 
clang/test/CodeGenCXX/vtable-debug-info-inheritance-diamond.cpp
 create mode 100644 
clang/test/CodeGenCXX/vtable-debug-info-inheritance-multiple.cpp
 create mode 100644 
clang/test/CodeGenCXX/vtable-debug-info-inheritance-simple-main.cpp
 create mode 100644 
clang/test/CodeGenCXX/vtable-debug-info-inheritance-simple.cpp
 create mode 100644 
clang/test/CodeGenCXX/vtable-debug-info-inheritance-virtual.cpp
 create mode 100644 
llvm/test/DebugInfo/X86/vtable-debug-info-inheritance-simple.ll

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0e6daa42ee7bf..9cadeadc54111 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2518,6 +2518,59 @@ StringRef CGDebugInfo::getVTableName(const CXXRecordDecl 
*RD) {
   return internString("_vptr$", RD->getNameAsString());
 }
 
+// Emit symbol for the debugger that points to the vtable address for
+// the given class. The symbol is named as '_vtable$'.
+// The debugger does not need to know any details about the contents of the
+// vtable as it can work this out using its knowledge of the ABI and the
+// existing information in the DWARF. The type is assumed to be 'void *'.
+void CGDebugInfo::emitVTableSymbol(llvm::GlobalVariable *VTable,
+   const CXXRecordDecl *RD) {
+  ASTContext &Context = CGM.getContext();
+  SmallString<64> Buffer;
+  Twine SymbolName = internString("_vtable$");
+  StringRef SymbolNameRef = SymbolName.toStringRef(Buffer);
+  DeclContext *DC = static_cast(const_cast(RD));
+  SourceLocation Loc;
+  QualType VoidPtr = Context.getPointerType(Context.VoidTy);
+
+  // We deal with two different contexts:
+  // - The type for the variable, which is part of the class that has the
+  //   vtable, is placed in the context of the DICompositeType metadata.
+  // - The DIGlobalVariable for the vtable is put in the DICompileUnitScope.
+
+  // The created non-member should be mark as 'artificial'. It will be
+  // placed it inside the scope of the C++ class/structure.
+  llvm::DIScope *DContext = getContextDescriptor(cast(DC), TheCU);
+ 

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

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Carlos Alberto Enciso (CarlosAlbertoEnciso)


Changes

The IR now includes a global variable for the debugger that holds
the address of the vtable.

Now every class that contains virtual functions, has a static
member (marked as artificial) that identifies where that vtable
is loaded in memory. The unmangled name is '_vtable$'.

This new symbol will allow a debugger to easily associate
classes with the physical location of their VTables using
only the DWARF information. Previously, this had to be done
by searching for ELF symbols with matching names; something
that was time-consuming and error-prone in certain edge cases.


---

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


16 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+53) 
- (modified) clang/lib/CodeGen/CGDebugInfo.h (+3) 
- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+4) 
- (added) 
clang/test/CodeGenCXX/Inputs/vtable-debug-info-inheritance-simple-base.cpp 
(+14) 
- (added) 
clang/test/CodeGenCXX/Inputs/vtable-debug-info-inheritance-simple-base.h (+15) 
- (added) 
clang/test/CodeGenCXX/Inputs/vtable-debug-info-inheritance-simple-derived.cpp 
(+13) 
- (added) 
clang/test/CodeGenCXX/Inputs/vtable-debug-info-inheritance-simple-derived.h 
(+14) 
- (modified) clang/test/CodeGenCXX/debug-info-class.cpp (+14-12) 
- (modified) clang/test/CodeGenCXX/debug-info-template-member.cpp (+26-26) 
- (added) clang/test/CodeGenCXX/vtable-debug-info-inheritance-diamond.cpp (+87) 
- (added) clang/test/CodeGenCXX/vtable-debug-info-inheritance-multiple.cpp 
(+72) 
- (added) clang/test/CodeGenCXX/vtable-debug-info-inheritance-simple-main.cpp 
(+87) 
- (added) clang/test/CodeGenCXX/vtable-debug-info-inheritance-simple.cpp (+55) 
- (added) clang/test/CodeGenCXX/vtable-debug-info-inheritance-virtual.cpp (+87) 
- (modified) clang/test/Modules/ExtDebugInfo.cpp (+5-5) 
- (added) llvm/test/DebugInfo/X86/vtable-debug-info-inheritance-simple.ll 
(+206) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0e6daa42ee7bf..9cadeadc54111 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2518,6 +2518,59 @@ StringRef CGDebugInfo::getVTableName(const CXXRecordDecl 
*RD) {
   return internString("_vptr$", RD->getNameAsString());
 }
 
+// Emit symbol for the debugger that points to the vtable address for
+// the given class. The symbol is named as '_vtable$'.
+// The debugger does not need to know any details about the contents of the
+// vtable as it can work this out using its knowledge of the ABI and the
+// existing information in the DWARF. The type is assumed to be 'void *'.
+void CGDebugInfo::emitVTableSymbol(llvm::GlobalVariable *VTable,
+   const CXXRecordDecl *RD) {
+  ASTContext &Context = CGM.getContext();
+  SmallString<64> Buffer;
+  Twine SymbolName = internString("_vtable$");
+  StringRef SymbolNameRef = SymbolName.toStringRef(Buffer);
+  DeclContext *DC = static_cast(const_cast(RD));
+  SourceLocation Loc;
+  QualType VoidPtr = Context.getPointerType(Context.VoidTy);
+
+  // We deal with two different contexts:
+  // - The type for the variable, which is part of the class that has the
+  //   vtable, is placed in the context of the DICompositeType metadata.
+  // - The DIGlobalVariable for the vtable is put in the DICompileUnitScope.
+
+  // The created non-member should be mark as 'artificial'. It will be
+  // placed it inside the scope of the C++ class/structure.
+  llvm::DIScope *DContext = getContextDescriptor(cast(DC), TheCU);
+  auto *Ctxt = cast(DContext);
+  llvm::DIFile *Unit = getOrCreateFile(Loc);
+  llvm::DIType *VTy = getOrCreateType(VoidPtr, Unit);
+  llvm::DINode::DIFlags Flags = getAccessFlag(AccessSpecifier::AS_private, RD);
+  auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
+ ? llvm::dwarf::DW_TAG_variable
+ : llvm::dwarf::DW_TAG_member;
+  llvm::DIDerivedType *OldDT = DBuilder.createStaticMemberType(
+  Ctxt, SymbolNameRef, Unit, /*LineNumber=*/0, VTy, Flags,
+  /*Val=*/nullptr, Tag);
+  llvm::DIDerivedType *DT =
+  static_cast(DBuilder.createArtificialType(OldDT));
+
+  // Use the same vtable pointer to global alignment for the symbol.
+  LangAS AS = CGM.GetGlobalVarAddressSpace(nullptr);
+  unsigned PAlign = CGM.getItaniumVTableContext().isRelativeLayout()
+? 32
+: CGM.getTarget().getPointerAlign(AS);
+
+  // The global variable is in the CU scope, and links back to the type it's
+  // "within" via the declaration field.
+  llvm::DIGlobalVariableExpression *GVE =
+  DBuilder.createGlobalVariableExpression(
+  TheCU, SymbolNameRef, VTable->getName(), Unit, /*LineNo=*/0,
+  getOrCreateType(VoidPtr, Unit), VTable->hasLocalLinkage(),
+  /*isDefined=*/true, nullp

[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/130177

>From 728e1bd9cccb56a0acaf5abb35fe64cacc5b4ae9 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 6 Mar 2025 15:08:25 -0600
Subject: [PATCH 1/7] [Clang] Treat `ext_vector_type` as a regular type
 attribute

Summary:
This attribute is mostly borrowed from OpenCL, but is useful in general
for accessing the LLVM vector types. Previously the only way to use it
was through typedefs. This patch changes that to allow use as a regular
type attribute, similar to address spaces.
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td | 13 +++--
 clang/include/clang/Basic/AttrDocs.td | 23 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++-
 clang/test/CodeGenCUDA/amdgpu-bf16.cu | 12 
 clang/test/Sema/types.c   |  2 +-
 6 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86bf836b4a999..695c458b36702 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,7 @@ Adding [[clang::unsafe_buffer_usage]] attribute to a method 
definition now turns
 related warnings within the method body.
 
 - The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names.
+- The ``ext_vector_type(n)`` attribute can now be used as a generic type 
attribute.
 - Clang now diagnoses use of declaration attributes on void parameters. 
(#GH108819)
 - Clang now allows ``__attribute__((model("small")))`` and
   ``__attribute__((model("large")))`` on non-TLS globals in x86-64 
compilations.
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc9b462126125..161a4fe8e0f12 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1721,17 +1721,10 @@ def EnableIf : InheritableAttr {
   let Documentation = [EnableIfDocs];
 }
 
-def ExtVectorType : Attr {
-  // This is an OpenCL-related attribute and does not receive a [[]] spelling.
-  let Spellings = [GNU<"ext_vector_type">];
-  // FIXME: This subject list is wrong; this is a type attribute.
-  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+def ExtVectorType : TypeAttr {
+  let Spellings = [Clang<"ext_vector_type">];
   let Args = [ExprArgument<"NumElements">];
-  let ASTNode = 0;
-  let Documentation = [Undocumented];
-  // This is a type attribute with an incorrect subject list, so should not be
-  // permitted by #pragma clang attribute.
-  let PragmaAttributeSupport = 0;
+  let Documentation = [ExtVectorTypeDocs];
 }
 
 def FallThrough : StmtAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f44fad95423ee..c309b4849b731 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1113,6 +1113,29 @@ template instantiation, so the value for ``T::number`` 
is known.
   }];
 }
 
+def ExtVectorTypeDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+
+The ext_vector_type(N) attribute specifies that a type is a vector with N
+elements, directly mapping to an LLVM vector type. Originally from OpenCL, it
+allows element access via [] or x, y, z, w for graphics-style indexing. This
+attribute enables efficient SIMD operations and is usable in general-purpose
+code.
+
+.. code-block:: c++
+
+  template 
+  constexpr T simd_reduce(T [[clang::ext_vector_type(N)]] v) {
+T sum{};
+for (uint32_t i = 0; i < N; ++i) {
+  sum += v[i];
+}
+return sum;
+  }
+  }];
+}
+
 def DiagnoseIfDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1405ee5341dcf..d32320c581656 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1191,7 +1191,8 @@ static void handleTestTypestateAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 
 static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Remember this typedef decl, we will need it later for diagnostics.
-  S.ExtVectorDecls.push_back(cast(D));
+  if (isa(D))
+S.ExtVectorDecls.push_back(cast(D));
 }
 
 static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
diff --git a/clang/test/CodeGenCUDA/amdgpu-bf16.cu 
b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
index 4610b4ae3cbe5..f6533d7faf296 100644
--- a/clang/test/CodeGenCUDA/amdgpu-bf16.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
@@ -111,19 +111,15 @@ __device__ __bf16 test_call( __bf16 in) {
 // CHECK-NEXT:ret void
 //
 __device__ void test_vec_assign() {
-  typedef __attribute__((ext_vector_type(2))) __bf16 bf16_x2;
-  bf16_x2 vec2_a, vec2_b;
+  __bf16 [[clang::ext_vector_type(2)]] vec2_a, vec2_b;
   vec2_a = vec2_b;
 
-  typedef __attribute__((ext_vector_type(4))) __bf16 bf16_x4;
-  bf16_x4 vec4_a, vec4_b;
+  __bf16 [[clang::ext_vector_type(4)]] v

[clang] [llvm] [HLSL][NFC] Update resource metadata tests to not use obsolete metadata annotations (PR #130222)

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

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


[clang] [clang][bytecode] Yet another __builtin_constant_p implementation (PR #130143)

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

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/130143

>From dd4291322d7f00c4110ac64b6e39b0349d1122c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 6 Mar 2025 16:18:49 +0100
Subject: [PATCH] [clang][bytecode] Yet another __builtin_constant_p
 implementation

---
 clang/lib/AST/ByteCode/ByteCodeEmitter.cpp|  10 ++
 clang/lib/AST/ByteCode/ByteCodeEmitter.h  |   4 +
 clang/lib/AST/ByteCode/Compiler.cpp   |  22 
 clang/lib/AST/ByteCode/Compiler.h |   5 +-
 clang/lib/AST/ByteCode/EvalEmitter.cpp|  27 +
 clang/lib/AST/ByteCode/EvalEmitter.h  |   4 +
 clang/lib/AST/ByteCode/Interp.cpp |  89 ++
 clang/lib/AST/ByteCode/Interp.h   |  22 
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  |  79 -
 clang/lib/AST/ByteCode/InterpState.h  |   3 +
 clang/lib/AST/ByteCode/Opcodes.td |  10 +-
 .../test/AST/ByteCode/builtin-constant-p.cpp  | 110 +-
 clang/test/CodeGen/builtin-constant-p.c   |   3 +
 clang/test/CodeGenCXX/builtin-constant-p.cpp  |   1 +
 14 files changed, 306 insertions(+), 83 deletions(-)

diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp 
b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index 5bd1b73133d65..4162b55070da9 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -367,6 +367,16 @@ bool ByteCodeEmitter::fallthrough(const LabelTy &Label) {
   return true;
 }
 
+bool ByteCodeEmitter::speculate(const CallExpr *E, const LabelTy &EndLabel) {
+  const Expr *Arg = E->getArg(0);
+  PrimType T = Ctx.classify(Arg->getType()).value_or(PT_Ptr);
+  if (!this->emitBCP(getOffset(EndLabel), T, E))
+return false;
+  if (!this->visit(Arg))
+return false;
+  return true;
+}
+
 
//===--===//
 // Opcode emitters
 
//===--===//
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.h 
b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
index ac728830527a2..64670c32cbcf6 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.h
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
@@ -48,12 +48,16 @@ class ByteCodeEmitter {
   virtual bool visitFunc(const FunctionDecl *E) = 0;
   virtual bool visitExpr(const Expr *E, bool DestroyToplevelScope) = 0;
   virtual bool visitDeclAndReturn(const VarDecl *E, bool ConstantContext) = 0;
+  virtual bool visit(const Expr *E) = 0;
+  virtual bool emitBool(bool V, const Expr *E) = 0;
 
   /// Emits jumps.
   bool jumpTrue(const LabelTy &Label);
   bool jumpFalse(const LabelTy &Label);
   bool jump(const LabelTy &Label);
   bool fallthrough(const LabelTy &Label);
+  /// Speculative execution.
+  bool speculate(const CallExpr *E, const LabelTy &EndLabel);
 
   /// We're always emitting bytecode.
   bool isActive() const { return true; }
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 281fb7e14a57d..3eca12897681d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4681,6 +4681,28 @@ bool Compiler::visitAPValueInitializer(const 
APValue &Val,
 template 
 bool Compiler::VisitBuiltinCallExpr(const CallExpr *E,
  unsigned BuiltinID) {
+
+  if (BuiltinID == Builtin::BI__builtin_constant_p) {
+// Void argument is always invalid and harder to handle later.
+if (E->getArg(0)->getType()->isVoidType()) {
+  if (DiscardResult)
+return true;
+  return this->emitConst(0, E);
+}
+
+if (!this->emitStartSpeculation(E))
+  return false;
+LabelTy EndLabel = this->getLabel();
+if (!this->speculate(E, EndLabel))
+  return false;
+this->fallthrough(EndLabel);
+if (!this->emitEndSpeculation(E))
+  return false;
+if (DiscardResult)
+  return this->emitPop(classifyPrim(E), E);
+return true;
+  }
+
   const Function *Func = getFunction(E->getDirectCallee());
   if (!Func)
 return false;
diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index 77fcc3d1b41ce..7683d60f869f6 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -274,7 +274,7 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   /// Evaluates an expression and places the result on the stack. If the
   /// expression is of composite type, a local variable will be created
   /// and a pointer to said variable will be placed on the stack.
-  bool visit(const Expr *E);
+  bool visit(const Expr *E) override;
   /// Compiles an initializer. This is like visit() but it will never
   /// create a variable and instead rely on a variable already having
   /// been created. visitInitializer() then relies on a pointer to this
@@ -342,6 +342,9 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   /// Emits an intege

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

2025-03-06 Thread via cfe-commits

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


[clang] [llvm] [MTE] generalize overalignment / size of MTE globals (PR #121957)

2025-03-06 Thread Florian Mayer via cfe-commits

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

>From 2feb85c15f64546cb6874e1ca0a1310bd1e1bedd Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Tue, 7 Jan 2025 07:57:09 -0800
Subject: [PATCH 1/7] =?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
---
 llvm/include/llvm/IR/GlobalVariable.h  |  7 +
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 34 ++
 llvm/lib/IR/Globals.cpp| 10 +++
 3 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/llvm/include/llvm/IR/GlobalVariable.h 
b/llvm/include/llvm/IR/GlobalVariable.h
index 83e484816d7d4..c1f8cdc4fd0a6 100644
--- a/llvm/include/llvm/IR/GlobalVariable.h
+++ b/llvm/include/llvm/IR/GlobalVariable.h
@@ -267,6 +267,13 @@ class GlobalVariable : public GlobalObject, public 
ilist_node {
getAttributes().hasAttribute("rodata-section");
   }
 
+  MaybeAlign getRequiredGlobalAlignment() {
+return isTagged() && getAlign().valueOrOne() < 16 ? MaybeAlign(16)
+  : std::nullopt;
+  }
+
+  std::optional getRequiredGlobalSize();
+
   /// Get the custom code model raw value of this global.
   ///
   unsigned getCodeModelRaw() const {
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 7bd3fb33b47d2..8e594a8f92b20 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2398,17 +2398,23 @@ void 
AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
   OutStreamer->emitBinaryData(Buf);
 }
 
-static void tagGlobalDefinition(Module &M, GlobalVariable *G) {
-  Constant *Initializer = G->getInitializer();
+static uint64_t globalSize(const GlobalVariable &G) {
+  const Constant *Initializer = G.getInitializer();
   uint64_t SizeInBytes =
-  M.getDataLayout().getTypeAllocSize(Initializer->getType());
+  G.getParent()->getDataLayout().getTypeAllocSize(Initializer->getType());
 
-  uint64_t NewSize = alignTo(SizeInBytes, 16);
-  if (SizeInBytes != NewSize) {
+  return SizeInBytes;
+}
+
+static void tagGlobalDefinition(GlobalVariable *G) {
+  Module &M = *G->getParent();
+  uint64_t SizeInBytes = globalSize(*G);
+  if (auto NewSize = G->getRequiredGlobalSize()) {
+assert(*NewSize > SizeInBytes);
 // Pad the initializer out to the next multiple of 16 bytes.
-llvm::SmallVector Init(NewSize - SizeInBytes, 0);
+llvm::SmallVector Init(*NewSize - SizeInBytes, 0);
 Constant *Padding = ConstantDataArray::get(M.getContext(), Init);
-Initializer = ConstantStruct::getAnon({Initializer, Padding});
+auto *Initializer = ConstantStruct::getAnon({G->getInitializer(), 
Padding});
 auto *NewGV = new GlobalVariable(
 M, Initializer->getType(), G->isConstant(), G->getLinkage(),
 Initializer, "", G, G->getThreadLocalMode(), G->getAddressSpace());
@@ -2422,8 +2428,10 @@ static void tagGlobalDefinition(Module &M, 
GlobalVariable *G) {
 G = NewGV;
   }
 
-  if (G->getAlign().valueOrOne() < 16)
-G->setAlignment(Align(16));
+  if (auto Align = G->getRequiredGlobalAlignment()) {
+assert(*Align > G->getAlign().valueOrOne());
+G->setAlignment(*Align);
+  }
 
   // Ensure that tagged globals don't get merged by ICF - as they should have
   // different tags at runtime.
@@ -2438,12 +2446,14 @@ bool AsmPrinter::doFinalization(Module &M) {
 
   std::vector GlobalsToTag;
   for (GlobalVariable &G : M.globals()) {
-if (G.isDeclaration() || !G.isTagged())
+if (G.isDeclaration())
   continue;
-GlobalsToTag.push_back(&G);
+if (G.getRequiredGlobalAlignment().has_value() ||
+G.getRequiredGlobalSize().has_value())
+  GlobalsToTag.push_back(&G);
   }
   for (GlobalVariable *G : GlobalsToTag)
-tagGlobalDefinition(M, G);
+tagGlobalDefinition(G);
 
   // Gather all GOT equivalent globals in the module. We really need two
   // passes over the globals: one to compute and another to avoid its emission
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index db5e1cb57b1ba..79ff120c250e4 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -540,6 +540,16 @@ void GlobalVariable::setCodeModel(CodeModel::Model CM) {
   assert(getCodeModel() == CM && "Code model representation error!");
 }
 
+std::optional GlobalVariable::getRequiredGlobalSize() {
+  if (!isTagged())
+return std::nullopt;
+  Constant *Initializer = getInitializer();
+  uint64_t SizeInBytes =
+  getParent()->getDataLayout().getTypeAllocSize(Initializer->getType());
+  uint64_t Aligned = alignTo(SizeInBytes, 16);
+  return Aligned != SizeInBytes ? std::optional(Aligned) : std::nullopt;
+}
+
 
//===--===//
 // GlobalAlias Implementation
 

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

2025-03-06 Thread Derek Schuff via cfe-commits

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


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


[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/130177

>From 728e1bd9cccb56a0acaf5abb35fe64cacc5b4ae9 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 6 Mar 2025 15:08:25 -0600
Subject: [PATCH 1/6] [Clang] Treat `ext_vector_type` as a regular type
 attribute

Summary:
This attribute is mostly borrowed from OpenCL, but is useful in general
for accessing the LLVM vector types. Previously the only way to use it
was through typedefs. This patch changes that to allow use as a regular
type attribute, similar to address spaces.
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td | 13 +++--
 clang/include/clang/Basic/AttrDocs.td | 23 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++-
 clang/test/CodeGenCUDA/amdgpu-bf16.cu | 12 
 clang/test/Sema/types.c   |  2 +-
 6 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86bf836b4a999..695c458b36702 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,7 @@ Adding [[clang::unsafe_buffer_usage]] attribute to a method 
definition now turns
 related warnings within the method body.
 
 - The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names.
+- The ``ext_vector_type(n)`` attribute can now be used as a generic type 
attribute.
 - Clang now diagnoses use of declaration attributes on void parameters. 
(#GH108819)
 - Clang now allows ``__attribute__((model("small")))`` and
   ``__attribute__((model("large")))`` on non-TLS globals in x86-64 
compilations.
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc9b462126125..161a4fe8e0f12 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1721,17 +1721,10 @@ def EnableIf : InheritableAttr {
   let Documentation = [EnableIfDocs];
 }
 
-def ExtVectorType : Attr {
-  // This is an OpenCL-related attribute and does not receive a [[]] spelling.
-  let Spellings = [GNU<"ext_vector_type">];
-  // FIXME: This subject list is wrong; this is a type attribute.
-  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+def ExtVectorType : TypeAttr {
+  let Spellings = [Clang<"ext_vector_type">];
   let Args = [ExprArgument<"NumElements">];
-  let ASTNode = 0;
-  let Documentation = [Undocumented];
-  // This is a type attribute with an incorrect subject list, so should not be
-  // permitted by #pragma clang attribute.
-  let PragmaAttributeSupport = 0;
+  let Documentation = [ExtVectorTypeDocs];
 }
 
 def FallThrough : StmtAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f44fad95423ee..c309b4849b731 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1113,6 +1113,29 @@ template instantiation, so the value for ``T::number`` 
is known.
   }];
 }
 
+def ExtVectorTypeDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+
+The ext_vector_type(N) attribute specifies that a type is a vector with N
+elements, directly mapping to an LLVM vector type. Originally from OpenCL, it
+allows element access via [] or x, y, z, w for graphics-style indexing. This
+attribute enables efficient SIMD operations and is usable in general-purpose
+code.
+
+.. code-block:: c++
+
+  template 
+  constexpr T simd_reduce(T [[clang::ext_vector_type(N)]] v) {
+T sum{};
+for (uint32_t i = 0; i < N; ++i) {
+  sum += v[i];
+}
+return sum;
+  }
+  }];
+}
+
 def DiagnoseIfDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1405ee5341dcf..d32320c581656 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1191,7 +1191,8 @@ static void handleTestTypestateAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 
 static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Remember this typedef decl, we will need it later for diagnostics.
-  S.ExtVectorDecls.push_back(cast(D));
+  if (isa(D))
+S.ExtVectorDecls.push_back(cast(D));
 }
 
 static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
diff --git a/clang/test/CodeGenCUDA/amdgpu-bf16.cu 
b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
index 4610b4ae3cbe5..f6533d7faf296 100644
--- a/clang/test/CodeGenCUDA/amdgpu-bf16.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
@@ -111,19 +111,15 @@ __device__ __bf16 test_call( __bf16 in) {
 // CHECK-NEXT:ret void
 //
 __device__ void test_vec_assign() {
-  typedef __attribute__((ext_vector_type(2))) __bf16 bf16_x2;
-  bf16_x2 vec2_a, vec2_b;
+  __bf16 [[clang::ext_vector_type(2)]] vec2_a, vec2_b;
   vec2_a = vec2_b;
 
-  typedef __attribute__((ext_vector_type(4))) __bf16 bf16_x4;
-  bf16_x4 vec4_a, vec4_b;
+  __bf16 [[clang::ext_vector_type(4)]] v

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

2025-03-06 Thread via cfe-commits

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

>From ae03b5c6bd5bf69b9fbbcaa31ca8da487648bb0f Mon Sep 17 00:00:00 2001
From: Austin 
Date: Thu, 6 Mar 2025 17:25:55 +0800
Subject: [PATCH] [ARM] Using cp15  while mtp =auto and arch is arm_arch6k and
 support thumb2

We follow GCC mtp=auto when arch is arm_arch6k and support thumb2

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

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

[clang] [llvm] [MTE] generalize overalignment / size of MTE globals (PR #121957)

2025-03-06 Thread Florian Mayer via cfe-commits


@@ -715,8 +715,16 @@ MCSymbol *AsmPrinter::getSymbolPreferLocal(const 
GlobalValue &GV) const {
   return TM.getSymbol(&GV);
 }
 
-/// EmitGlobalVariable - Emit the specified global variable to the .s file.
 void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
+  MaybeAlign RequiredAlignment = getRequiredGlobalAlignment(*GV);

fmayer wrote:

For MTE, we don't really need this. We can add this in a followup if that's 
required by CHERI.

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


[clang] [HLSL] Buffer handle globals should not be constants (PR #130231)

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Justin Bogner (bogner)


Changes

If these are constants their initializers will be removed by InstCombine. 
Change them to not be constants and initialize them with poison.

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


6 Files Affected:

- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+6-7) 
- (modified) clang/test/CodeGenHLSL/cbuffer.hlsl (+5-5) 
- (modified) clang/test/CodeGenHLSL/cbuffer_and_namespaces.hlsl (+3-3) 
- (modified) clang/test/CodeGenHLSL/cbuffer_with_packoffset.hlsl (+1-1) 
- (modified) 
clang/test/CodeGenHLSL/cbuffer_with_static_global_and_function.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/default_cbuffer.hlsl (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index dc34653e8f497..4e14c6a3e72a2 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -31,7 +31,6 @@
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Value.h"
 #include "llvm/Support/Alignment.h"
-
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
 
@@ -214,12 +213,12 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl 
*BufDecl) {
   llvm::TargetExtType *TargetTy =
   cast(convertHLSLSpecificType(
   ResHandleTy, BufDecl->hasValidPackoffset() ? &Layout : nullptr));
-  llvm::GlobalVariable *BufGV =
-  new GlobalVariable(TargetTy, /*isConstant*/ true,
- GlobalValue::LinkageTypes::ExternalLinkage, nullptr,
- llvm::formatv("{0}{1}", BufDecl->getName(),
-   BufDecl->isCBuffer() ? ".cb" : ".tb"),
- GlobalValue::NotThreadLocal);
+  llvm::GlobalVariable *BufGV = new GlobalVariable(
+  TargetTy, /*isConstant*/ false,
+  GlobalValue::LinkageTypes::ExternalLinkage, PoisonValue::get(TargetTy),
+  llvm::formatv("{0}{1}", BufDecl->getName(),
+BufDecl->isCBuffer() ? ".cb" : ".tb"),
+  GlobalValue::NotThreadLocal);
   CGM.getModule().insertGlobalVariable(BufGV);
 
   // Add globals for constant buffer elements and create metadata nodes
diff --git a/clang/test/CodeGenHLSL/cbuffer.hlsl 
b/clang/test/CodeGenHLSL/cbuffer.hlsl
index 38093c6dfacd7..d70ce0aae7b64 100644
--- a/clang/test/CodeGenHLSL/cbuffer.hlsl
+++ b/clang/test/CodeGenHLSL/cbuffer.hlsl
@@ -31,7 +31,7 @@ cbuffer CBScalars : register(b1, space5) {
   int64_t a8;
 }
 
-// CHECK: @CBScalars.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBScalars, 
+// CHECK: @CBScalars.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBScalars,
 // CHECK-SAME: 56, 0, 8, 16, 24, 32, 36, 40, 48))
 // CHECK: @a1 = external addrspace(2) global float, align 4
 // CHECK: @a2 = external addrspace(2) global double, align 8
@@ -53,7 +53,7 @@ cbuffer CBVectors {
   // FIXME: add a bool vectors after llvm-project/llvm#91639 is added
 }
 
-// CHECK: @CBVectors.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBVectors, 
+// CHECK: @CBVectors.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBVectors,
 // CHECK-SAME: 136, 0, 16, 40, 48, 80, 96, 112))
 // CHECK: @b1 = external addrspace(2) global <3 x float>, align 16
 // CHECK: @b2 = external addrspace(2) global <3 x double>, align 32
@@ -74,7 +74,7 @@ cbuffer CBArrays : register(b2) {
   bool c8[4];
 }
 
-// CHECK: @CBArrays.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBArrays, 
+// CHECK: @CBArrays.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBArrays,
 // CHECK-SAME: 708, 0, 48, 112, 176, 224, 608, 624, 656))
 // CHECK: @c1 = external addrspace(2) global [3 x float], align 4
 // CHECK: @c2 = external addrspace(2) global [2 x <3 x double>], align 32
@@ -105,7 +105,7 @@ struct D {
   Empty es;
 };
 
-// CHECK: @CBStructs.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBStructs, 
+// CHECK: @CBStructs.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBStructs,
 // CHECK-SAME: 246, 0, 16, 32, 64, 144, 238, 240))
 // CHECK: @a = external addrspace(2) global target("dx.Layout", %A, 8, 0), 
align 8
 // CHECK: @b = external addrspace(2) global target("dx.Layout", %B, 14, 0, 8), 
align 8
@@ -129,7 +129,7 @@ struct Test {
 float a, b;
 };
 
-// CHECK: @CBMix.cb = external constant target("dx.CBuffer", 
target("dx.Layout", %__cblayout_CBMix,
+// CHECK: @CBMix.cb = global target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CBMix,
 // CHECK-SAME: 170, 0, 24, 32, 120, 128, 136, 144, 152, 160, 168))
 // CHECK: @test = external addrspace(2) global [2 x target("dx.Layout", %Test, 
8, 0, 4)], align 4
 // CHECK: @f1 = external addrspace(2) global float, align 4
diff --git a/clang/test/CodeGenHLSL/cbuffer_and_namespaces.hlsl 
b/clang/test/CodeGenHLSL/cbuffer_and_namespaces.hlsl
index 393ca3825c638..7cbde19b67d1f

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

2025-03-06 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic updated 
https://github.com/llvm/llvm-project/pull/129952

>From 9ac636ee137248cafe38f4d2e016cfb885142dff Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Wed, 5 Mar 2025 14:20:21 -0800
Subject: [PATCH 1/3] [clang] Reject constexpr-unknown values as constant
 expressions more consistently.

Perform the check for constexpr-unknown values in the same place we
perform checks for other values which don't count as constant
expressions.

While I'm here, also fix a rejects-valid with a reference that doesn't
have an initializer.  This diagnostic was also covering up some of the
bugs here.

The existing behavior with -fexperimental-new-constant-interpreter seems
to be correct, but the diagnostics are slightly different; it would be
helpful if someone could check on that as a followup.

Followup to #128409.

Fixes #129844. Fixes #129845.
---
 clang/lib/AST/ExprConstant.cpp| 25 +--
 clang/test/CodeGenCXX/cxx23-p2280r4.cpp   | 12 +
 .../SemaCXX/constant-expression-cxx11.cpp |  4 +--
 .../SemaCXX/constant-expression-p2280r4.cpp   | 25 ++-
 4 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d9a1e5bb42343..216bc478bb28b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2419,6 +2419,16 @@ static bool CheckLValueConstantExpression(EvalInfo 
&Info, SourceLocation Loc,
   LVal.getLValueCallIndex() == 0) &&
  "have call index for global lvalue");
 
+  if (LVal.allowConstexprUnknown()) {
+if (BaseVD) {
+  Info.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << 
BaseVD;
+  NoteLValueLocation(Info, Base);
+} else {
+  Info.FFDiag(Loc);
+}
+return false;
+  }
+
   if (Base.is()) {
 Info.FFDiag(Loc, diag::note_constexpr_dynamic_alloc)
 << IsReferenceType << !Designator.Entries.empty();
@@ -3597,7 +3607,8 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const 
Expr *E,
   // expressions here; doing so would regress diagnostics for things like
   // reading from a volatile constexpr variable.
   if ((Info.getLangOpts().CPlusPlus && !VD->hasConstantInitialization() &&
-   VD->mightBeUsableInConstantExpressions(Info.Ctx)) ||
+   VD->mightBeUsableInConstantExpressions(Info.Ctx) &&
+   !AllowConstexprUnknown) ||
   ((Info.getLangOpts().CPlusPlus || Info.getLangOpts().OpenCL) &&
!Info.getLangOpts().CPlusPlus11 && !VD->hasICEInitializer(Info.Ctx))) {
 if (Init) {
@@ -16993,18 +17004,6 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const 
ASTContext &Ctx,
 
 if (!Info.discardCleanups())
   llvm_unreachable("Unhandled cleanup; missing full expression marker?");
-
-if (Value.allowConstexprUnknown()) {
-  assert(Value.isLValue() && "Expected an lvalue");
-  auto Base = Value.getLValueBase();
-  const auto *NewVD = Base.dyn_cast();
-  if (!NewVD)
-NewVD = VD;
-  Info.FFDiag(getExprLoc(), diag::note_constexpr_var_init_non_constant, 1)
-  << NewVD;
-  NoteLValueLocation(Info, Base);
-  return false;
-}
   }
 
   return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,
diff --git a/clang/test/CodeGenCXX/cxx23-p2280r4.cpp 
b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
index d5409be451df0..c91457e5c20de 100644
--- a/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
+++ b/clang/test/CodeGenCXX/cxx23-p2280r4.cpp
@@ -13,3 +13,15 @@ int& test() {
   auto &i = s;
   return i;
 }
+
+// CHECK: @_Z1fv(
+// CHECK-NEXT: entry:
+// CHECK-NEXT: getelementptr inbounds nuw %struct.B
+// CHECK-NEXT: getelementptr inbounds nuw %struct.A
+// CHECK-NEXT: [[X:%.*]] = load ptr, ptr @x, align 8
+// CHECK-NEXT: store ptr [[X]]
+int &ff();
+int &x = ff();
+struct A { int& x; };
+struct B { A x[20]; };
+B f() { return {x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x}; }
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 76e2f81947051..c35f3a5632a05 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1472,8 +1472,8 @@ namespace ConvertedConstantExpr {
   enum class E {
 em = m,
 en = n, // expected-error {{enumerator value is not a constant 
expression}} cxx11_20-note {{initializer of 'n' is unknown}}
-eo = (m + // pre-cxx23-error {{not a constant expression}}
-  n // cxx11_20-note {{initializer of 'n' is unknown}} cxx23-error 
{{not a constant expression}}
+eo = (m + // expected-error {{not a constant expression}}
+  n // cxx11_20-note {{initializer of 'n' is unknown}}
   ),
 eq = reinterpret_cast((int*)0) // expected-error {{not a constant 
expression}} expected-note {{reinterpret_cast}}
   };
diff --git a/clang/test/SemaCXX/constant-expression-p2280r4.cpp 
b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
index 65e5e6b34b48f..731b0

[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/130177

>From 728e1bd9cccb56a0acaf5abb35fe64cacc5b4ae9 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 6 Mar 2025 15:08:25 -0600
Subject: [PATCH 1/5] [Clang] Treat `ext_vector_type` as a regular type
 attribute

Summary:
This attribute is mostly borrowed from OpenCL, but is useful in general
for accessing the LLVM vector types. Previously the only way to use it
was through typedefs. This patch changes that to allow use as a regular
type attribute, similar to address spaces.
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td | 13 +++--
 clang/include/clang/Basic/AttrDocs.td | 23 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++-
 clang/test/CodeGenCUDA/amdgpu-bf16.cu | 12 
 clang/test/Sema/types.c   |  2 +-
 6 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86bf836b4a999..695c458b36702 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,7 @@ Adding [[clang::unsafe_buffer_usage]] attribute to a method 
definition now turns
 related warnings within the method body.
 
 - The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names.
+- The ``ext_vector_type(n)`` attribute can now be used as a generic type 
attribute.
 - Clang now diagnoses use of declaration attributes on void parameters. 
(#GH108819)
 - Clang now allows ``__attribute__((model("small")))`` and
   ``__attribute__((model("large")))`` on non-TLS globals in x86-64 
compilations.
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc9b462126125..161a4fe8e0f12 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1721,17 +1721,10 @@ def EnableIf : InheritableAttr {
   let Documentation = [EnableIfDocs];
 }
 
-def ExtVectorType : Attr {
-  // This is an OpenCL-related attribute and does not receive a [[]] spelling.
-  let Spellings = [GNU<"ext_vector_type">];
-  // FIXME: This subject list is wrong; this is a type attribute.
-  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+def ExtVectorType : TypeAttr {
+  let Spellings = [Clang<"ext_vector_type">];
   let Args = [ExprArgument<"NumElements">];
-  let ASTNode = 0;
-  let Documentation = [Undocumented];
-  // This is a type attribute with an incorrect subject list, so should not be
-  // permitted by #pragma clang attribute.
-  let PragmaAttributeSupport = 0;
+  let Documentation = [ExtVectorTypeDocs];
 }
 
 def FallThrough : StmtAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f44fad95423ee..c309b4849b731 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1113,6 +1113,29 @@ template instantiation, so the value for ``T::number`` 
is known.
   }];
 }
 
+def ExtVectorTypeDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+
+The ext_vector_type(N) attribute specifies that a type is a vector with N
+elements, directly mapping to an LLVM vector type. Originally from OpenCL, it
+allows element access via [] or x, y, z, w for graphics-style indexing. This
+attribute enables efficient SIMD operations and is usable in general-purpose
+code.
+
+.. code-block:: c++
+
+  template 
+  constexpr T simd_reduce(T [[clang::ext_vector_type(N)]] v) {
+T sum{};
+for (uint32_t i = 0; i < N; ++i) {
+  sum += v[i];
+}
+return sum;
+  }
+  }];
+}
+
 def DiagnoseIfDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1405ee5341dcf..d32320c581656 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1191,7 +1191,8 @@ static void handleTestTypestateAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 
 static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Remember this typedef decl, we will need it later for diagnostics.
-  S.ExtVectorDecls.push_back(cast(D));
+  if (isa(D))
+S.ExtVectorDecls.push_back(cast(D));
 }
 
 static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
diff --git a/clang/test/CodeGenCUDA/amdgpu-bf16.cu 
b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
index 4610b4ae3cbe5..f6533d7faf296 100644
--- a/clang/test/CodeGenCUDA/amdgpu-bf16.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
@@ -111,19 +111,15 @@ __device__ __bf16 test_call( __bf16 in) {
 // CHECK-NEXT:ret void
 //
 __device__ void test_vec_assign() {
-  typedef __attribute__((ext_vector_type(2))) __bf16 bf16_x2;
-  bf16_x2 vec2_a, vec2_b;
+  __bf16 [[clang::ext_vector_type(2)]] vec2_a, vec2_b;
   vec2_a = vec2_b;
 
-  typedef __attribute__((ext_vector_type(4))) __bf16 bf16_x4;
-  bf16_x4 vec4_a, vec4_b;
+  __bf16 [[clang::ext_vector_type(4)]] v

[clang] [Clang] Make '-Wglobal-constructors` work on the GNU attributes (PR #129917)

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

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


[clang] [HLSL] Make sure `isSigned` flag is set on target type for `TypedBuffer` resources for signed int vectors (PR #130223)

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

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/130223

Fixes #130191

>From e3f4108f1a0677569bf6bd8ae73569e0dae8d78a Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 6 Mar 2025 18:41:12 -0800
Subject: [PATCH] [HLSL] Make sure to set isSigned flag on TypedBuffer
 resources for integer vectors

Fixes #130191
---
 clang/lib/CodeGen/Targets/DirectX.cpp  | 10 --
 .../CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl |  7 ---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp 
b/clang/lib/CodeGen/Targets/DirectX.cpp
index 77091eb45f5cf..0556527e2fdd6 100644
--- a/clang/lib/CodeGen/Targets/DirectX.cpp
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -59,8 +59,14 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(
 SmallVector Ints = {/*IsWriteable*/ ResAttrs.ResourceClass ==
  llvm::dxil::ResourceClass::UAV,
  /*IsROV*/ ResAttrs.IsROV};
-if (!ResAttrs.RawBuffer)
-  Ints.push_back(/*IsSigned*/ ContainedTy->isSignedIntegerType());
+if (!ResAttrs.RawBuffer) {
+  const clang::Type *ElemType = ContainedTy->getUnqualifiedDesugaredType();
+  if (ElemType->isVectorType())
+ElemType = cast(ElemType)
+   ->getElementType()
+   ->getUnqualifiedDesugaredType();
+  Ints.push_back(/*IsSigned*/ ElemType->isSignedIntegerType());
+}
 
 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
   }
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
index 11c77644a906d..0944ad59d5fb5 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
@@ -10,10 +10,11 @@
 // DXIL: %"class.hlsl::RWBuffer.5" = type { target("dx.TypedBuffer", half, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.6" = type { target("dx.TypedBuffer", float, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.7" = type { target("dx.TypedBuffer", double, 
1, 0, 0) }
-// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 1) }
 // DXIL: %"class.hlsl::RWBuffer.9" = type { target("dx.TypedBuffer", <3 x 
i32>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.10" = type { target("dx.TypedBuffer", <2 x 
half>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.11" = type { target("dx.TypedBuffer", <3 x 
float>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.12" = type { target("dx.TypedBuffer", <4 x 
i32>, 1, 0, 1) }
 
 // SPIRV: %"class.hlsl::RWBuffer" = type { target("spirv.Image", i16, 5, 2, 0, 
0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.0" = type { target("spirv.Image", i16, 5, 2, 
0, 0, 2, 0) }
@@ -28,8 +29,7 @@
 // SPIRV: %"class.hlsl::RWBuffer.9" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.10" = type { target("spirv.Image", half, 5, 
2, 0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.11" = type { target("spirv.Image", float, 5, 
2, 0, 0, 2, 0) }
-
-
+// SPIRV: %"class.hlsl::RWBuffer.12" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 
 RWBuffer BufI16;
 RWBuffer BufU16;
@@ -44,6 +44,7 @@ RWBuffer< vector > BufI16x4;
 RWBuffer< vector > BufU32x3;
 RWBuffer BufF16x2;
 RWBuffer BufF32x3;
+RWBuffer BufI32x4;
 // TODO: RWBuffer BufSNormF16; -> 11
 // TODO: RWBuffer BufUNormF16; -> 12
 // TODO: RWBuffer BufSNormF32; -> 13

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


[clang] [HLSL] Make sure `isSigned` flag is set on target type for `TypedBuffer` resources for signed int vectors (PR #130223)

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-directx

Author: Helena Kotas (hekota)


Changes

Fixes #130191

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/DirectX.cpp (+8-2) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl (+4-3) 


``diff
diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp 
b/clang/lib/CodeGen/Targets/DirectX.cpp
index 77091eb45f5cf..0556527e2fdd6 100644
--- a/clang/lib/CodeGen/Targets/DirectX.cpp
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -59,8 +59,14 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(
 SmallVector Ints = {/*IsWriteable*/ ResAttrs.ResourceClass ==
  llvm::dxil::ResourceClass::UAV,
  /*IsROV*/ ResAttrs.IsROV};
-if (!ResAttrs.RawBuffer)
-  Ints.push_back(/*IsSigned*/ ContainedTy->isSignedIntegerType());
+if (!ResAttrs.RawBuffer) {
+  const clang::Type *ElemType = ContainedTy->getUnqualifiedDesugaredType();
+  if (ElemType->isVectorType())
+ElemType = cast(ElemType)
+   ->getElementType()
+   ->getUnqualifiedDesugaredType();
+  Ints.push_back(/*IsSigned*/ ElemType->isSignedIntegerType());
+}
 
 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
   }
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
index 11c77644a906d..0944ad59d5fb5 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
@@ -10,10 +10,11 @@
 // DXIL: %"class.hlsl::RWBuffer.5" = type { target("dx.TypedBuffer", half, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.6" = type { target("dx.TypedBuffer", float, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.7" = type { target("dx.TypedBuffer", double, 
1, 0, 0) }
-// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 1) }
 // DXIL: %"class.hlsl::RWBuffer.9" = type { target("dx.TypedBuffer", <3 x 
i32>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.10" = type { target("dx.TypedBuffer", <2 x 
half>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.11" = type { target("dx.TypedBuffer", <3 x 
float>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.12" = type { target("dx.TypedBuffer", <4 x 
i32>, 1, 0, 1) }
 
 // SPIRV: %"class.hlsl::RWBuffer" = type { target("spirv.Image", i16, 5, 2, 0, 
0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.0" = type { target("spirv.Image", i16, 5, 2, 
0, 0, 2, 0) }
@@ -28,8 +29,7 @@
 // SPIRV: %"class.hlsl::RWBuffer.9" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.10" = type { target("spirv.Image", half, 5, 
2, 0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.11" = type { target("spirv.Image", float, 5, 
2, 0, 0, 2, 0) }
-
-
+// SPIRV: %"class.hlsl::RWBuffer.12" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 
 RWBuffer BufI16;
 RWBuffer BufU16;
@@ -44,6 +44,7 @@ RWBuffer< vector > BufI16x4;
 RWBuffer< vector > BufU32x3;
 RWBuffer BufF16x2;
 RWBuffer BufF32x3;
+RWBuffer BufI32x4;
 // TODO: RWBuffer BufSNormF16; -> 11
 // TODO: RWBuffer BufUNormF16; -> 12
 // TODO: RWBuffer BufSNormF32; -> 13

``




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


[clang] [HLSL] Make sure `isSigned` flag is set on target type for `TypedBuffer` resources for signed int vectors (PR #130223)

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Helena Kotas (hekota)


Changes

Fixes #130191

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/DirectX.cpp (+8-2) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl (+4-3) 


``diff
diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp 
b/clang/lib/CodeGen/Targets/DirectX.cpp
index 77091eb45f5cf..0556527e2fdd6 100644
--- a/clang/lib/CodeGen/Targets/DirectX.cpp
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -59,8 +59,14 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(
 SmallVector Ints = {/*IsWriteable*/ ResAttrs.ResourceClass ==
  llvm::dxil::ResourceClass::UAV,
  /*IsROV*/ ResAttrs.IsROV};
-if (!ResAttrs.RawBuffer)
-  Ints.push_back(/*IsSigned*/ ContainedTy->isSignedIntegerType());
+if (!ResAttrs.RawBuffer) {
+  const clang::Type *ElemType = ContainedTy->getUnqualifiedDesugaredType();
+  if (ElemType->isVectorType())
+ElemType = cast(ElemType)
+   ->getElementType()
+   ->getUnqualifiedDesugaredType();
+  Ints.push_back(/*IsSigned*/ ElemType->isSignedIntegerType());
+}
 
 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
   }
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
index 11c77644a906d..0944ad59d5fb5 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
@@ -10,10 +10,11 @@
 // DXIL: %"class.hlsl::RWBuffer.5" = type { target("dx.TypedBuffer", half, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.6" = type { target("dx.TypedBuffer", float, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.7" = type { target("dx.TypedBuffer", double, 
1, 0, 0) }
-// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 1) }
 // DXIL: %"class.hlsl::RWBuffer.9" = type { target("dx.TypedBuffer", <3 x 
i32>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.10" = type { target("dx.TypedBuffer", <2 x 
half>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.11" = type { target("dx.TypedBuffer", <3 x 
float>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.12" = type { target("dx.TypedBuffer", <4 x 
i32>, 1, 0, 1) }
 
 // SPIRV: %"class.hlsl::RWBuffer" = type { target("spirv.Image", i16, 5, 2, 0, 
0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.0" = type { target("spirv.Image", i16, 5, 2, 
0, 0, 2, 0) }
@@ -28,8 +29,7 @@
 // SPIRV: %"class.hlsl::RWBuffer.9" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.10" = type { target("spirv.Image", half, 5, 
2, 0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.11" = type { target("spirv.Image", float, 5, 
2, 0, 0, 2, 0) }
-
-
+// SPIRV: %"class.hlsl::RWBuffer.12" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 
 RWBuffer BufI16;
 RWBuffer BufU16;
@@ -44,6 +44,7 @@ RWBuffer< vector > BufI16x4;
 RWBuffer< vector > BufU32x3;
 RWBuffer BufF16x2;
 RWBuffer BufF32x3;
+RWBuffer BufI32x4;
 // TODO: RWBuffer BufSNormF16; -> 11
 // TODO: RWBuffer BufUNormF16; -> 12
 // TODO: RWBuffer BufSNormF32; -> 13

``




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


[clang] [HLSL] Make sure `isSigned` flag is set on target type for `TypedBuffer` resources for signed int vectors (PR #130223)

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Helena Kotas (hekota)


Changes

Fixes #130191

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/DirectX.cpp (+8-2) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl (+4-3) 


``diff
diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp 
b/clang/lib/CodeGen/Targets/DirectX.cpp
index 77091eb45f5cf..0556527e2fdd6 100644
--- a/clang/lib/CodeGen/Targets/DirectX.cpp
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -59,8 +59,14 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(
 SmallVector Ints = {/*IsWriteable*/ ResAttrs.ResourceClass ==
  llvm::dxil::ResourceClass::UAV,
  /*IsROV*/ ResAttrs.IsROV};
-if (!ResAttrs.RawBuffer)
-  Ints.push_back(/*IsSigned*/ ContainedTy->isSignedIntegerType());
+if (!ResAttrs.RawBuffer) {
+  const clang::Type *ElemType = ContainedTy->getUnqualifiedDesugaredType();
+  if (ElemType->isVectorType())
+ElemType = cast(ElemType)
+   ->getElementType()
+   ->getUnqualifiedDesugaredType();
+  Ints.push_back(/*IsSigned*/ ElemType->isSignedIntegerType());
+}
 
 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
   }
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
index 11c77644a906d..0944ad59d5fb5 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
@@ -10,10 +10,11 @@
 // DXIL: %"class.hlsl::RWBuffer.5" = type { target("dx.TypedBuffer", half, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.6" = type { target("dx.TypedBuffer", float, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.7" = type { target("dx.TypedBuffer", double, 
1, 0, 0) }
-// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 1) }
 // DXIL: %"class.hlsl::RWBuffer.9" = type { target("dx.TypedBuffer", <3 x 
i32>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.10" = type { target("dx.TypedBuffer", <2 x 
half>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.11" = type { target("dx.TypedBuffer", <3 x 
float>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.12" = type { target("dx.TypedBuffer", <4 x 
i32>, 1, 0, 1) }
 
 // SPIRV: %"class.hlsl::RWBuffer" = type { target("spirv.Image", i16, 5, 2, 0, 
0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.0" = type { target("spirv.Image", i16, 5, 2, 
0, 0, 2, 0) }
@@ -28,8 +29,7 @@
 // SPIRV: %"class.hlsl::RWBuffer.9" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.10" = type { target("spirv.Image", half, 5, 
2, 0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.11" = type { target("spirv.Image", float, 5, 
2, 0, 0, 2, 0) }
-
-
+// SPIRV: %"class.hlsl::RWBuffer.12" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 
 RWBuffer BufI16;
 RWBuffer BufU16;
@@ -44,6 +44,7 @@ RWBuffer< vector > BufI16x4;
 RWBuffer< vector > BufU32x3;
 RWBuffer BufF16x2;
 RWBuffer BufF32x3;
+RWBuffer BufI32x4;
 // TODO: RWBuffer BufSNormF16; -> 11
 // TODO: RWBuffer BufUNormF16; -> 12
 // TODO: RWBuffer BufSNormF32; -> 13

``




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


[clang] [llvm] [HLSL][NFC] Update resource metadata tests to not use obsolete metadata annotations (PR #130222)

2025-03-06 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,103 @@
+; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s
+; RUN: opt -S --passes="dxil-pretty-printer" < %s 2>&1 | FileCheck %s 
--check-prefix=PRINT
+; RUN: llc %s --filetype=asm -o - < %s 2>&1 | FileCheck %s 
--check-prefixes=CHECK,PRINT
+
+target datalayout = 
"e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+%"class.hlsl::Buffer" = type { target("dx.TypedBuffer", <4 x half>, 0, 0, 0) }
+%"class.hlsl::Buffer.1" = type { target("dx.TypedBuffer", <2 x float>, 0, 0, 
0) }
+%"class.hlsl::Buffer.2" = type { target("dx.TypedBuffer", double, 0, 0, 0) }
+%"class.hlsl::Buffer.3" = type { target("dx.TypedBuffer", i32, 0, 0, 1) }
+%"class.hlsl::ByteAddressBuffer" = type { target("dx.RawBuffer", i8, 0, 0) }
+%"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", i16, 0, 0) }
+%"class.hlsl::Buffer.4" = type { target("dx.TypedBuffer", i64, 0, 0, 0) }
+
+@Zero = internal global %"class.hlsl::Buffer" poison, align 4
+@One = internal global %"class.hlsl::Buffer.1" poison, align 4
+@Two = internal global %"class.hlsl::Buffer.2" poison, align 4
+@Three = internal global %"class.hlsl::Buffer.3" poison, align 4
+@Four = internal global %"class.hlsl::ByteAddressBuffer" poison, align 4
+@Five = internal global %"class.hlsl::StructuredBuffer" poison, align 4
+@Six = internal global %"class.hlsl::Buffer.4" poison, align 4
+
+; PRINT:; Resource Bindings:
+; PRINT-NEXT:;
+; PRINT-NEXT:; Name Type  Format Dim   
   ID  HLSL Bind  Count
+; PRINT-NEXT:; -- -- --- --- 
--- -- --
+; PRINT-NEXT:;   SRV f16 buf   
   T0 t0 1
+; PRINT-NEXT:;   SRV f32 buf   
   T1 t1 1
+; PRINT-NEXT:;   SRV f64 buf   
   T2 t2 1
+; PRINT-NEXT:;   SRV i32 buf   
   T3 t3 1
+; PRINT-NEXT:;   SRVbyte r/o   
   T4 t5 1
+; PRINT-NEXT:;   SRV  struct r/o   
   T5 t6 1
+; PRINT-NEXT:;   SRV u64 buf   
   T6 t10,space2 1
+
+define void @test() #0 {
+  ; RWBuffer Buf : register(u0)

bogner wrote:

This isn't `RWBuffer`, it's `Buffer` - the former is a UAV. This 
applies to all of the RWBuffer in this file.

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


[clang] [Clang] Fix 'gpuintrin.h' match when included with no arch set (PR #129927)

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

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


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


[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/130177

>From 728e1bd9cccb56a0acaf5abb35fe64cacc5b4ae9 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 6 Mar 2025 15:08:25 -0600
Subject: [PATCH 1/7] [Clang] Treat `ext_vector_type` as a regular type
 attribute

Summary:
This attribute is mostly borrowed from OpenCL, but is useful in general
for accessing the LLVM vector types. Previously the only way to use it
was through typedefs. This patch changes that to allow use as a regular
type attribute, similar to address spaces.
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td | 13 +++--
 clang/include/clang/Basic/AttrDocs.td | 23 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++-
 clang/test/CodeGenCUDA/amdgpu-bf16.cu | 12 
 clang/test/Sema/types.c   |  2 +-
 6 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86bf836b4a999..695c458b36702 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,7 @@ Adding [[clang::unsafe_buffer_usage]] attribute to a method 
definition now turns
 related warnings within the method body.
 
 - The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names.
+- The ``ext_vector_type(n)`` attribute can now be used as a generic type 
attribute.
 - Clang now diagnoses use of declaration attributes on void parameters. 
(#GH108819)
 - Clang now allows ``__attribute__((model("small")))`` and
   ``__attribute__((model("large")))`` on non-TLS globals in x86-64 
compilations.
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc9b462126125..161a4fe8e0f12 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1721,17 +1721,10 @@ def EnableIf : InheritableAttr {
   let Documentation = [EnableIfDocs];
 }
 
-def ExtVectorType : Attr {
-  // This is an OpenCL-related attribute and does not receive a [[]] spelling.
-  let Spellings = [GNU<"ext_vector_type">];
-  // FIXME: This subject list is wrong; this is a type attribute.
-  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+def ExtVectorType : TypeAttr {
+  let Spellings = [Clang<"ext_vector_type">];
   let Args = [ExprArgument<"NumElements">];
-  let ASTNode = 0;
-  let Documentation = [Undocumented];
-  // This is a type attribute with an incorrect subject list, so should not be
-  // permitted by #pragma clang attribute.
-  let PragmaAttributeSupport = 0;
+  let Documentation = [ExtVectorTypeDocs];
 }
 
 def FallThrough : StmtAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f44fad95423ee..c309b4849b731 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1113,6 +1113,29 @@ template instantiation, so the value for ``T::number`` 
is known.
   }];
 }
 
+def ExtVectorTypeDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+
+The ext_vector_type(N) attribute specifies that a type is a vector with N
+elements, directly mapping to an LLVM vector type. Originally from OpenCL, it
+allows element access via [] or x, y, z, w for graphics-style indexing. This
+attribute enables efficient SIMD operations and is usable in general-purpose
+code.
+
+.. code-block:: c++
+
+  template 
+  constexpr T simd_reduce(T [[clang::ext_vector_type(N)]] v) {
+T sum{};
+for (uint32_t i = 0; i < N; ++i) {
+  sum += v[i];
+}
+return sum;
+  }
+  }];
+}
+
 def DiagnoseIfDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1405ee5341dcf..d32320c581656 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1191,7 +1191,8 @@ static void handleTestTypestateAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 
 static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Remember this typedef decl, we will need it later for diagnostics.
-  S.ExtVectorDecls.push_back(cast(D));
+  if (isa(D))
+S.ExtVectorDecls.push_back(cast(D));
 }
 
 static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
diff --git a/clang/test/CodeGenCUDA/amdgpu-bf16.cu 
b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
index 4610b4ae3cbe5..f6533d7faf296 100644
--- a/clang/test/CodeGenCUDA/amdgpu-bf16.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
@@ -111,19 +111,15 @@ __device__ __bf16 test_call( __bf16 in) {
 // CHECK-NEXT:ret void
 //
 __device__ void test_vec_assign() {
-  typedef __attribute__((ext_vector_type(2))) __bf16 bf16_x2;
-  bf16_x2 vec2_a, vec2_b;
+  __bf16 [[clang::ext_vector_type(2)]] vec2_a, vec2_b;
   vec2_a = vec2_b;
 
-  typedef __attribute__((ext_vector_type(4))) __bf16 bf16_x4;
-  bf16_x4 vec4_a, vec4_b;
+  __bf16 [[clang::ext_vector_type(4)]] v

[clang] [llvm] [MTE] generalize overalignment / size of MTE globals (PR #121957)

2025-03-06 Thread Florian Mayer via cfe-commits

fmayer wrote:

Actually, there was a bug I fixed: even if the alignment of the original 
variable is >= 16, we still need to fix up the size.

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


[clang] [clang] Fix FP -Wformat in functions with 2+ attribute((format)) (PR #129954)

2025-03-06 Thread Henrik G. Olsson via cfe-commits

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


[clang] [clang][test] Fix -DBUILD_SHARED_LIBS build by adding depency on Targ… (PR #130105)

2025-03-06 Thread Kito Cheng via cfe-commits

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


[clang] Reland "[HIP] Use original file path for CUID" (#108771) (PR #111885)

2025-03-06 Thread Yaxun Liu via cfe-commits

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


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

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

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


[clang] Fix amdgpu-arch for dll name on Windows (PR #101350)

2025-03-06 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/101350

>From aba3005a829cecdeb13c1bc4118cbc5ad959affe Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Wed, 31 Jul 2024 09:23:05 -0400
Subject: [PATCH] Fix amdgpu-arch for dll name on Windows

Recently HIP runtime changed dll name to amdhip64_n.dll on Windows, where
n is ROCm major version number.

Fix amdgpu-arch to search for amdhip64_n.dll on Windows.
---
 clang/tools/amdgpu-arch/AMDGPUArch.cpp  |   3 +
 clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp | 131 +++-
 2 files changed, 130 insertions(+), 4 deletions(-)

diff --git a/clang/tools/amdgpu-arch/AMDGPUArch.cpp 
b/clang/tools/amdgpu-arch/AMDGPUArch.cpp
index 6c10cbc5c46a8..86f3e31f47bbc 100644
--- a/clang/tools/amdgpu-arch/AMDGPUArch.cpp
+++ b/clang/tools/amdgpu-arch/AMDGPUArch.cpp
@@ -21,6 +21,9 @@ static cl::opt Help("h", cl::desc("Alias for -help"), 
cl::Hidden);
 // Mark all our options with this category.
 static cl::OptionCategory AMDGPUArchCategory("amdgpu-arch options");
 
+cl::opt Verbose("verbose", cl::desc("Enable verbose output"),
+  cl::init(false), cl::cat(AMDGPUArchCategory));
+
 static void PrintVersion(raw_ostream &OS) {
   OS << clang::getClangToolFullVersion("amdgpu-arch") << '\n';
 }
diff --git a/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp 
b/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp
index 7338872dbf32f..be90b93a8f650 100644
--- a/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp
+++ b/clang/tools/amdgpu-arch/AMDGPUArchByHIP.cpp
@@ -11,9 +11,24 @@
 //
 
//===--===//
 
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/DynamicLibrary.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
+
+#ifdef _WIN32
+#include 
+#endif
 
 using namespace llvm;
 
@@ -31,16 +46,124 @@ typedef hipError_t (*hipGetDeviceCount_t)(int *);
 typedef hipError_t (*hipDeviceGet_t)(int *, int);
 typedef hipError_t (*hipGetDeviceProperties_t)(hipDeviceProp_t *, int);
 
-int printGPUsByHIP() {
+extern cl::opt Verbose;
+
 #ifdef _WIN32
-  constexpr const char *DynamicHIPPath = "amdhip64.dll";
+static std::vector getSearchPaths() {
+  std::vector Paths;
+
+  // Get the directory of the current executable
+  if (auto MainExe = sys::fs::getMainExecutable(nullptr, nullptr);
+  !MainExe.empty())
+Paths.push_back(sys::path::parent_path(MainExe).str());
+
+  // Get the system directory
+  wchar_t SystemDirectory[MAX_PATH];
+  if (GetSystemDirectoryW(SystemDirectory, MAX_PATH) > 0) {
+std::string Utf8SystemDir;
+if (convertUTF16ToUTF8String(
+ArrayRef(reinterpret_cast(SystemDirectory),
+wcslen(SystemDirectory)),
+Utf8SystemDir))
+  Paths.push_back(Utf8SystemDir);
+  }
+
+  // Get the Windows directory
+  wchar_t WindowsDirectory[MAX_PATH];
+  if (GetWindowsDirectoryW(WindowsDirectory, MAX_PATH) > 0) {
+std::string Utf8WindowsDir;
+if (convertUTF16ToUTF8String(
+ArrayRef(reinterpret_cast(WindowsDirectory),
+wcslen(WindowsDirectory)),
+Utf8WindowsDir))
+  Paths.push_back(Utf8WindowsDir);
+  }
+
+  // Get the current working directory
+  SmallVector CWD;
+  if (sys::fs::current_path(CWD))
+Paths.push_back(std::string(CWD.begin(), CWD.end()));
+
+  // Get the PATH environment variable
+  if (std::optional PathEnv = sys::Process::GetEnv("PATH")) {
+SmallVector PathList;
+StringRef(*PathEnv).split(PathList, sys::EnvPathSeparator);
+for (auto &Path : PathList)
+  Paths.push_back(Path.str());
+  }
+
+  return Paths;
+}
+
+// Custom comparison function for dll name
+static bool compareVersions(StringRef A, StringRef B) {
+  auto ParseVersion = [](StringRef S) -> VersionTuple {
+unsigned Pos = S.find_last_of('_');
+StringRef VerStr = (Pos == StringRef::npos) ? S : S.substr(Pos + 1);
+VersionTuple Vt;
+(void)VersionTuple::parse(VerStr, Vt);
+return Vt;
+  };
+
+  VersionTuple VtA = ParseVersion(A);
+  VersionTuple VtB = ParseVersion(B);
+  return VtA > VtB;
+}
+#endif
+
+// On Windows, prefer amdhip64_n.dll where n is ROCm major version and greater
+// value of n takes precedence. If amdhip64_n.dll is not found, fall back to
+// amdhip64.dll. The reason is that a normal driver installation only has
+// amdhip64_n.dll but we do not know what n is since this program may be used
+// with a future version of HIP runtime.
+//
+// On Linux, always use default libamdhip64.so.
+static std::pair findNewestHIPDLL() {
+#ifdef _WIN32
+  StringRef HipDLLPrefix = "amdhip64_";
+  StringRef HipDLLSuffix = ".dll";
+
+  std::vec

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

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

llvm-ci wrote:

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

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[   OK ] AddressSanitizer.AtoiAndFriendsOOBTest (2288 ms)
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (12 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (187 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (51 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (128 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (3 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (125 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (110 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN  ] AddressSanitizer.LongDoubleNegativeTest
[   OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[--] 19 tests from AddressSanitizer (28000 ms total)

[--] Global test environment tear-down
[==] 22 tests from 2 test suites ran. (28006 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

Step 24 (run instrumented asan tests 
[aarch64/aosp_coral-userdebug/AOSP.MASTER]) failure: run instrumented asan 
tests [aarch64/aosp_coral-userdebug/AOSP.MASTER] (failure)
...
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (7 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (330 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (21 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (241 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (1 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (290 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (307 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] Addre

[clang] C89 doesn't have `math.h` functions (PR #129979)

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

frederick-vs-ja wrote:

> While `log` does exist since C89 _within _, it should be allowed for 
> a `.c` to define `int log = 0;` because the `math.h` has not been included. 
> Thereby, even if `double log(double);` exists in C89 (in `math.h`), it's not 
> been declared in the current translation unit, so declaring a symbol with the 
> same name as `log` seems to be valid IMO.

However, declaration it as an object with _external_ linkage is UB (or 
ill-formed, no diagnostic required in the C++ standard wording).

Per [N3220](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf) 7.1.3/1
> [...]
> — All identifiers with external linkage in any of the following subclauses 
> (including the future library directions) and `errno` are always reserved for 
> use as identifiers with external linkage.218)
> [...]

In C89 that was in 4.1.2 
> [...] All external identifiers declared in any of the headers are reserved, 
> whether or not the associated header is included. [...]

It seem to me that the following program was well-defined in C89 but became 
undefined (IFNDR) since C99.
```C
int logf = 0; /* N.B. static not used */
int main(void) { return logf; }
```

But if `logf` if replaced with `log`, the program is invalid even in C89.

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


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

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

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

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

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

>From 7a3a5ede6f2ade1fb51f79ea0cc40f562744ac0c Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Wed, 5 Mar 2025 23:32:38 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Recognize
 CXXUnresolvedConstructExpr as a safe origin.

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

Also fix a bug in isPtrOfType that it was not recognizing 
DeducedTemplateSpecializationType.
---
 .../Checkers/WebKit/ASTUtils.cpp  |  4 +++
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 15 
 .../Analysis/Checkers/WebKit/call-args.cpp| 35 +++
 3 files changed, 47 insertions(+), 7 deletions(-)

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

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


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

2025-03-06 Thread via cfe-commits

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

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

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

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

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

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

[clang] [clang-repl] Disable EmulatedTLS on Windows for interpreter executor (PR #127468)

2025-03-06 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Our local windows expert is @bellenot. Maybe he can help us out here.

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


[clang] [CIR] Initial implementation of lowering CIR to MLIR (PR #127835)

2025-03-06 Thread Andy Kaylor via cfe-commits

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

>From 4f69f1700f9f982e9271157c5b870eda71e0c0f2 Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Fri, 14 Feb 2025 17:30:54 -0800
Subject: [PATCH 1/6] [CIR] Initial implementation of lowering CIR to MLIR

Add support for lowering CIR to MLIR and emitting an MLIR text file.

Lowering of global pointers is not yet supported.
---
 clang/include/clang/CIR/CIRGenerator.h|   1 +
 .../clang/CIR/FrontendAction/CIRGenAction.h   |   8 +
 clang/include/clang/CIR/LowerToLLVM.h |   4 +
 clang/include/clang/Driver/Options.td |   2 +
 .../include/clang/Frontend/FrontendOptions.h  |   3 +
 clang/lib/CIR/FrontendAction/CIRGenAction.cpp |  17 ++
 clang/lib/CIR/FrontendAction/CMakeLists.txt   |   1 +
 clang/lib/CIR/Lowering/CMakeLists.txt |   1 +
 .../CIR/Lowering/ThroughMLIR/CMakeLists.txt   |  16 ++
 .../Lowering/ThroughMLIR/LowerCIRToMLIR.cpp   | 201 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   2 +
 .../ExecuteCompilerInvocation.cpp |   6 +
 .../CIR/Lowering/ThroughMLIR/global-ptrs.cpp  |  29 +++
 .../test/CIR/Lowering/ThroughMLIR/global.cpp  |  79 +++
 14 files changed, 370 insertions(+)
 create mode 100644 clang/lib/CIR/Lowering/ThroughMLIR/CMakeLists.txt
 create mode 100644 clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp
 create mode 100644 clang/test/CIR/Lowering/ThroughMLIR/global-ptrs.cpp
 create mode 100644 clang/test/CIR/Lowering/ThroughMLIR/global.cpp

diff --git a/clang/include/clang/CIR/CIRGenerator.h 
b/clang/include/clang/CIR/CIRGenerator.h
index 414eba80b88b8..76b662c68615c 100644
--- a/clang/include/clang/CIR/CIRGenerator.h
+++ b/clang/include/clang/CIR/CIRGenerator.h
@@ -55,6 +55,7 @@ class CIRGenerator : public clang::ASTConsumer {
   void Initialize(clang::ASTContext &astContext) override;
   bool HandleTopLevelDecl(clang::DeclGroupRef group) override;
   mlir::ModuleOp getModule() const;
+  mlir::MLIRContext &getContext() { return *mlirContext; }
 };
 
 } // namespace cir
diff --git a/clang/include/clang/CIR/FrontendAction/CIRGenAction.h 
b/clang/include/clang/CIR/FrontendAction/CIRGenAction.h
index 99495f4718c5f..1ac1719c4 100644
--- a/clang/include/clang/CIR/FrontendAction/CIRGenAction.h
+++ b/clang/include/clang/CIR/FrontendAction/CIRGenAction.h
@@ -29,6 +29,7 @@ class CIRGenAction : public clang::ASTFrontendAction {
 EmitCIR,
 EmitLLVM,
 EmitBC,
+EmitMLIR,
 EmitObj,
   };
 
@@ -59,6 +60,13 @@ class EmitCIRAction : public CIRGenAction {
   EmitCIRAction(mlir::MLIRContext *MLIRCtx = nullptr);
 };
 
+class EmitMLIRAction : public CIRGenAction {
+  virtual void anchor();
+
+public:
+  EmitMLIRAction(mlir::MLIRContext *MLIRCtx = nullptr);
+};
+
 class EmitLLVMAction : public CIRGenAction {
   virtual void anchor();
 
diff --git a/clang/include/clang/CIR/LowerToLLVM.h 
b/clang/include/clang/CIR/LowerToLLVM.h
index 6e1b0270fcd2b..e780a5a747730 100644
--- a/clang/include/clang/CIR/LowerToLLVM.h
+++ b/clang/include/clang/CIR/LowerToLLVM.h
@@ -20,6 +20,7 @@ class Module;
 } // namespace llvm
 
 namespace mlir {
+class MLIRContext;
 class ModuleOp;
 } // namespace mlir
 
@@ -30,6 +31,9 @@ std::unique_ptr
 lowerDirectlyFromCIRToLLVMIR(mlir::ModuleOp mlirModule,
  llvm::LLVMContext &llvmCtx);
 } // namespace direct
+
+mlir::ModuleOp lowerFromCIRToMLIR(mlir::ModuleOp mlirModule,
+  mlir::MLIRContext &mlirCtx);
 } // namespace cir
 
 #endif // CLANG_CIR_LOWERTOLLVM_H
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d0414aba35209..02cabdbcee861 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2987,6 +2987,8 @@ defm clangir : BoolFOption<"clangir",
   BothFlags<[], [ClangOption, CC1Option], "">>;
 def emit_cir : Flag<["-"], "emit-cir">, Visibility<[ClangOption, CC1Option]>,
   Group, HelpText<"Build ASTs and then lower to ClangIR">;
+def emit_cir_mlir : Flag<["-"], "emit-cir-mlir">, Visibility<[CC1Option]>, 
Group,
+  HelpText<"Build ASTs and then lower through ClangIR to MLIR, emit the .milr 
file">;
 /// ClangIR-specific options - END
 
 def flto_EQ : Joined<["-"], "flto=">,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 99b2d9a98ed1f..e15ce247d1e6e 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -68,6 +68,9 @@ enum ActionKind {
   /// Emit a .cir file
   EmitCIR,
 
+  /// Emit a .mlir file
+  EmitMLIR,
+
   /// Emit a .ll file.
   EmitLLVM,
 
diff --git a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp 
b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp
index 0f686a36b982b..74f795e7e3307 100644
--- a/clang/lib/CIR/FrontendAction/CIRGenAction.cpp
+++ b/clang/lib/CIR/FrontendAction/CIRGenAction.cpp
@@ -24,6 +24,7 @@ static BackendAction
 get

[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

jhuber6 wrote:

I don't know why the documentation build keeps failing, just says it's missing 
a header, but this one looks like all the other ones.

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


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

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

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


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

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


@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+namespace t1{
+template  struct VSX {
+  ~VSX() { static_assert(sizeof(T) != 4, ""); } // expected-error {{static 
assertion failed due to requirement 'sizeof(int) != 4':}} \
+// expected-note {{expression 
evaluates to '4 != 4'}}
+};
+struct VS {
+  union {
+VSX _Tail;
+  };
+  ~VS() { }
+  VS(short);
+};
+VS::VS(short) : _Tail() { } // expected-note {{in instantiation of member 
function 't1::VSX::~VSX' requested here}}

shafik wrote:

Makes sense, that might be a bit subtle for folks running into the test, so it 
is worth it to add a comment noting that.

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


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

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

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

LGTM besides the last comment I made on adding a comment to the test.

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


[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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


@@ -1721,17 +1721,10 @@ def EnableIf : InheritableAttr {
   let Documentation = [EnableIfDocs];
 }
 
-def ExtVectorType : Attr {
-  // This is an OpenCL-related attribute and does not receive a [[]] spelling.
-  let Spellings = [GNU<"ext_vector_type">];
-  // FIXME: This subject list is wrong; this is a type attribute.
-  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+def ExtVectorType : TypeAttr {
+  let Spellings = [RegularKeyword<"__vector_type">, GNU<"ext_vector_type">];

erichkeane wrote:

I don't like the keyword here, particuarly when it doesn't match the attribute. 
For better or worse, these types are a wart from the GNU variants of these, and 
we should stick it that way.  As a keyword it isn't clear whether this should 
be treated as a qualifier or specifier, and this patch doesn't answer that at 
all.

Additionally, the `Clang` spelling was the right one, this is a clang 
attribute, we should spell it like 'clang.

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


[clang] [CIR] Initial implementation of lowering CIR to MLIR (PR #127835)

2025-03-06 Thread Andy Kaylor via cfe-commits

andykaylor wrote:

I've rebased this PR to bring in recent changes, fixed a few problems that were 
caused by recent changes, and generally refactored the command-line handling to 
align with a similar change that was made in the incubator.

This doesn't lower the ops and types that have been added since this PR was 
originally created. I'll handle that in a follow-up PR.

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


[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

arsenm wrote:

It completely changes the type, it's much more aggressive than a type 
attribute? sizeof is no longer the same 

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


[clang] [HLSL] Make sure `isSigned` flag is set on target type for `TypedBuffer` resources with signed int vectors (PR #130223)

2025-03-06 Thread Justin Bogner via cfe-commits

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


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


[clang] [llvm] [HLSL][NFC] Update resource metadata tests to not use obsolete metadata annotations (PR #130222)

2025-03-06 Thread Justin Bogner via cfe-commits

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


[clang] [llvm] [HLSL][NFC] Update resource metadata tests to not use obsolete annotations (PR #130222)

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

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


[clang] Fix amdgpu-arch for dll name on Windows (PR #101350)

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

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


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


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

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

YutongZhuu wrote:

Sorry, I accidentally requested for a review. Did not mean it.

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


[clang] clang/HIP: Do not call ocml in scalbln implementations (PR #129639)

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

arsenm wrote:

### Merge activity

* **Mar 6, 7:53 PM EST**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/129639).


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


[clang] [lldb] [C++20][Modules] Do not update the declaration generation number if the redeclaration chain completion was delayed. (PR #129982)

2025-03-06 Thread Michael Park via cfe-commits

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


[clang] clang/HIP: Do not call ocml in scalbln implementations (PR #129639)

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

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


[clang] [Clang] add -Wshift-bool warning to handle shifting of bool (PR #127336)

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

https://github.com/shafik commented:

Does this also warns on expressions that result in a `bool` e.g. 
https://godbolt.org/z/aY3cons4T

```cpp
bool a = (x < y) << 1;
```

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


[clang] [Clang] add -Wshift-bool warning to handle shifting of bool (PR #127336)

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

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


[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

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

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


[clang] 3304a43 - clang/HIP: Do not call ocml in scalbln implementations (#129639)

2025-03-06 Thread via cfe-commits

Author: Matt Arsenault
Date: 2025-03-07T07:55:26+07:00
New Revision: 3304a430f291e31c6b71ff73a1b44f51456dca56

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

LOG: clang/HIP: Do not call ocml in scalbln implementations (#129639)

I do not understand why this was calling the float version with
an implicit cast from the long. Just clamp to the bounds of int,
and use the generic ldexp (this is also how musl does it, except
scalbnf is the base implementation there).

Somehow INT_MIN was also not defined, so deal with that.

Added: 


Modified: 
clang/lib/Headers/__clang_hip_math.h
clang/lib/Headers/__clang_hip_runtime_wrapper.h
clang/test/Headers/__clang_hip_math.hip

Removed: 




diff  --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 51d9acbb87270..f6c06eaf4afe0 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -639,8 +639,11 @@ float rsqrtf(float __x) { return __ocml_rsqrt_f32(__x); }
 
 __DEVICE__
 float scalblnf(float __x, long int __n) {
-  return (__n < INT_MAX) ? __builtin_amdgcn_ldexpf(__x, __n)
- : __ocml_scalb_f32(__x, __n);
+  if (__n > INT_MAX)
+__n = INT_MAX;
+  else if (__n < INT_MIN)
+__n = INT_MIN;
+  return __builtin_ldexpf(__x, (int)__n);
 }
 
 __DEVICE__
@@ -1044,8 +1047,11 @@ double rsqrt(double __x) { return __ocml_rsqrt_f64(__x); 
}
 
 __DEVICE__
 double scalbln(double __x, long int __n) {
-  return (__n < INT_MAX) ? __builtin_amdgcn_ldexp(__x, __n)
- : __ocml_scalb_f64(__x, __n);
+  if (__n > INT_MAX)
+__n = INT_MAX;
+  else if (__n < INT_MIN)
+__n = INT_MIN;
+  return __builtin_ldexp(__x, (int)__n);
 }
 __DEVICE__
 double scalbn(double __x, int __n) { return __builtin_amdgcn_ldexp(__x, __n); }

diff  --git a/clang/lib/Headers/__clang_hip_runtime_wrapper.h 
b/clang/lib/Headers/__clang_hip_runtime_wrapper.h
index ed1550038e63e..da1e39ac7270e 100644
--- a/clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ b/clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -125,11 +125,13 @@ typedef __SIZE_TYPE__ size_t;
 #pragma push_macro("uint64_t")
 #pragma push_macro("CHAR_BIT")
 #pragma push_macro("INT_MAX")
+#pragma push_macro("INT_MIN")
 #define NULL (void *)0
 #define uint32_t __UINT32_TYPE__
 #define uint64_t __UINT64_TYPE__
 #define CHAR_BIT __CHAR_BIT__
 #define INT_MAX __INTMAX_MAX__
+#define INT_MIN (-__INT_MAX__ - 1)
 #endif // __HIPCC_RTC__
 
 #include <__clang_hip_libdevice_declares.h>
@@ -154,6 +156,7 @@ typedef __SIZE_TYPE__ size_t;
 #pragma pop_macro("uint64_t")
 #pragma pop_macro("CHAR_BIT")
 #pragma pop_macro("INT_MAX")
+#pragma pop_macro("INT_MIN")
 #endif // __HIPCC_RTC__
 #endif // __HIP__
 #endif // __CLANG_HIP_RUNTIME_WRAPPER_H__

diff  --git a/clang/test/Headers/__clang_hip_math.hip 
b/clang/test/Headers/__clang_hip_math.hip
index ff9f55a8e0710..e879fec0ebe5a 100644
--- a/clang/test/Headers/__clang_hip_math.hip
+++ b/clang/test/Headers/__clang_hip_math.hip
@@ -4984,63 +4984,31 @@ extern "C" __device__ double test_rsqrt(double x) {
 
 // DEFAULT-LABEL: @test_scalblnf(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CMP_NOT_I:%.*]] = icmp eq i64 [[Y:%.*]], 
9223372036854775807
-// DEFAULT-NEXT:br i1 [[CMP_NOT_I]], label [[COND_FALSE_I:%.*]], label 
[[COND_TRUE_I:%.*]]
-// DEFAULT:   cond.true.i:
-// DEFAULT-NEXT:[[CONV_I:%.*]] = trunc i64 [[Y]] to i32
-// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract float 
@llvm.ldexp.f32.i32(float [[X:%.*]], i32 [[CONV_I]])
-// DEFAULT-NEXT:br label [[_ZL8SCALBLNFFL_EXIT:%.*]]
-// DEFAULT:   cond.false.i:
-// DEFAULT-NEXT:[[CALL_I:%.*]] = tail call contract float 
@__ocml_scalb_f32(float noundef [[X]], float noundef 0x43E0) 
#[[ATTR12]]
-// DEFAULT-NEXT:br label [[_ZL8SCALBLNFFL_EXIT]]
-// DEFAULT:   _ZL8scalblnffl.exit:
-// DEFAULT-NEXT:[[COND_I:%.*]] = phi contract float [ [[TMP0]], 
[[COND_TRUE_I]] ], [ [[CALL_I]], [[COND_FALSE_I]] ]
-// DEFAULT-NEXT:ret float [[COND_I]]
+// DEFAULT-NEXT:[[SPEC_STORE_SELECT_I:%.*]] = tail call i64 
@llvm.smax.i64(i64 [[Y:%.*]], i64 -2147483648)
+// DEFAULT-NEXT:[[CONV_I:%.*]] = trunc i64 [[SPEC_STORE_SELECT_I]] to i32
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract noundef float 
@llvm.ldexp.f32.i32(float [[X:%.*]], i32 [[CONV_I]])
+// DEFAULT-NEXT:ret float [[TMP0]]
 //
 // FINITEONLY-LABEL: @test_scalblnf(
 // FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:[[CMP_NOT_I:%.*]] = icmp eq i64 [[Y:%.*]], 
9223372036854775807
-// FINITEONLY-NEXT:br i1 [[CMP_NOT_I]], label [[COND_FALSE_I:%.*]], label 
[[COND_TRUE_I:%.*]]
-// FINITEONLY:   cond.true.i:
-// FINITEONLY-NEXT:[[CONV_I:%.*]] = trunc i64 [[Y]] to i32
-// FINITEONLY-NEXT:[[

[clang] Fix amdgpu-arch for dll name on Windows (PR #101350)

2025-03-06 Thread Yaxun Liu via cfe-commits


@@ -31,16 +44,118 @@ typedef hipError_t (*hipGetDeviceCount_t)(int *);
 typedef hipError_t (*hipDeviceGet_t)(int *, int);
 typedef hipError_t (*hipGetDeviceProperties_t)(hipDeviceProp_t *, int);
 
-int printGPUsByHIP() {
+extern cl::opt Verbose;
+
 #ifdef _WIN32
-  constexpr const char *DynamicHIPPath = "amdhip64.dll";
+static std::vector getSearchPaths() {
+  std::vector Paths;
+
+  // Get the directory of the current executable
+  if (auto MainExe = sys::fs::getMainExecutable(nullptr, nullptr);
+  !MainExe.empty())
+Paths.push_back(sys::path::parent_path(MainExe).str());
+
+  // Get the system directory
+  wchar_t SystemDirectory[MAX_PATH];
+  if (GetSystemDirectoryW(SystemDirectory, MAX_PATH) > 0) {
+std::string Utf8SystemDir;
+if (convertUTF16ToUTF8String(
+ArrayRef(reinterpret_cast(SystemDirectory),
+wcslen(SystemDirectory)),
+Utf8SystemDir))
+  Paths.push_back(Utf8SystemDir);
+  }
+
+  // Get the Windows directory
+  wchar_t WindowsDirectory[MAX_PATH];
+  if (GetWindowsDirectoryW(WindowsDirectory, MAX_PATH) > 0) {
+std::string Utf8WindowsDir;
+if (convertUTF16ToUTF8String(
+ArrayRef(reinterpret_cast(WindowsDirectory),
+wcslen(WindowsDirectory)),
+Utf8WindowsDir))
+  Paths.push_back(Utf8WindowsDir);
+  }
+
+  // Get the current working directory
+  SmallVector CWD;
+  if (sys::fs::current_path(CWD))
+Paths.push_back(std::string(CWD.begin(), CWD.end()));
+
+  // Get the PATH environment variable
+  if (std::optional PathEnv = sys::Process::GetEnv("PATH")) {
+SmallVector PathList;
+StringRef(*PathEnv).split(PathList, sys::EnvPathSeparator);
+for (auto &Path : PathList)
+  Paths.push_back(Path.str());
+  }
+
+  return Paths;
+}
+
+// Custom comparison function for dll name
+static bool compareVersions(const std::string &a, const std::string &b) {
+  // Extract version numbers
+  int versionA = std::stoi(a.substr(a.find_last_of('_') + 1));
+  int versionB = std::stoi(b.substr(b.find_last_of('_') + 1));

yxsamliu wrote:

will do

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


[clang] [Clang] Add test for CWG2285 "Issues with structured bindings" (PR #126421)

2025-03-06 Thread via cfe-commits

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


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

2025-03-06 Thread via cfe-commits

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

>From 3c656c189cd23d0d7cc3acf6e40663f15ec2f4e0 Mon Sep 17 00:00:00 2001
From: Austin 
Date: Thu, 6 Mar 2025 17:25:55 +0800
Subject: [PATCH] [ARM] Using cp15  while mtp =auto and arch is arm_arch6k and
 support thumb2

We follow GCC mtp=auto when arch is arm_arch6k and support thumb2

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

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

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

2025-03-06 Thread via cfe-commits

cor3ntin wrote:

@YutongZhuu Will you need someone to merge this for you?

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


[clang] [C2y] Implement WG14 N3411 (PR #130180)

2025-03-06 Thread via cfe-commits


@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -verify=c2y -std=c2y -Wall -pedantic %s
+// RUN: %clang_cc1 -verify -Wnewline-eof -std=c2y -Wall -pedantic %s
+// RUN: %clang_cc1 -verify -std=c23 -Wall -pedantic %s

cor3ntin wrote:

maybe add a test for c23, no warning / no pedantic

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


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

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


@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+namespace t1{
+template  struct VSX {
+  ~VSX() { static_assert(sizeof(T) != 4, ""); } // expected-error {{static 
assertion failed due to requirement 'sizeof(int) != 4':}} \
+// expected-note {{expression 
evaluates to '4 != 4'}}
+};
+struct VS {
+  union {
+VSX _Tail;
+  };
+  ~VS() { }
+  VS(short);
+};
+VS::VS(short) : _Tail() { } // expected-note {{in instantiation of member 
function 't1::VSX::~VSX' requested here}}

momo5502 wrote:

alright, done.

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


[clang] [llvm] [HLSL][NFC] Update resource metadata tests to not use obsolete metadata annotations (PR #130222)

2025-03-06 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,80 @@
+; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s
+; RUN: opt -S --passes="dxil-pretty-printer" < %s 2>&1 | FileCheck %s 
--check-prefix=PRINT
+; RUN: llc %s --filetype=asm -o - < %s 2>&1 | FileCheck %s 
--check-prefixes=CHECK,PRINT
+
+target datalayout = 
"e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+%__cblayout_CB1 = type <{ float, i32, double, <2 x i32> }>
+@CB1.cb = external constant target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CB1, 24, 0, 4, 8, 16))
+
+%__cblayout_CB2 = type <{ float, double, float, half, i16, i64, i32 }>
+@CB2.cb = external constant target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32))
+
+%__cblayout_CB3 = type <{ double, <3 x float>, float, <3 x double>, half, <2 x 
double>, float, <3 x half>, <3 x half> }>
+@CB3.cb = external constant target("dx.CBuffer", target("dx.Layout", 
%__cblayout_CB3, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90))
+
+; PRINT:; Resource Bindings:
+; PRINT-NEXT:;
+; PRINT-NEXT:; Name Type  Format Dim   
   ID  HLSL Bind  Count
+; PRINT-NEXT:; -- -- --- --- 
--- -- --
+; PRINT-NEXT:;   cbuffer  NA  NA   
  CB0cb0 1
+; PRINT-NEXT:;   cbuffer  NA  NA   
  CB1cb1 1
+; PRINT-NEXT:;   cbuffer  NA  NA   
  CB2cb5,space15 1
+
+define void @test() #0 {
+
+  ; cbuffer CB1 : register(b0) {
+  ;   float a;
+  ;   int b;
+  ;   double c;
+  ;   int2 d;
+  ; }
+  %CB1.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB1, 
24, 0, 4, 8, 16))
+
@llvm.dx.resource.handlefrombinding.tdx.CBuffer_tdx.Layout_s___cblayout_CB1s_24_0_4_8_16tt(
+i32 0, i32 0, i32 1, i32 0, i1 false)

bogner wrote:

You can omit the overload mangling in these intrinsic calls to make this more 
readable. The parser will add it as necessary.

```suggestion
@llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 
false)
```

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


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

2025-03-06 Thread Kito Cheng via cfe-commits

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


[clang] [llvm] [RISCV] Mark {vl, vtype} as clobber in inline assembly (PR #128636)

2025-03-06 Thread Hank Chang via cfe-commits

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


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

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


haoNoQ wrote:

The static analyzer handles this pretty well already. I haven't heard of any 
problems in this area. I think it makes sense to use the same logic by default 
in other tools unless you do have specific concerns.

Also please take a note of the test case 
[check-deserialization.cpp](https://github.com/llvm/llvm-project/blob/main/clang/test/Analysis/check-deserialization.cpp)
 which demonstrates that the static analyzer not only skips the analysis of 
system headers - but it also skips deserialization of that code when 
PCHs/modules are involved. Which might be another source of performance gains 
for your patch. It might be a good idea to generalize this test case to 
clang-tidy.

> Note2: out of all the unit tests, only one of them fails:
> readability/identifier-naming-anon-record-fields.cpp

I feel a sudden urge to channel my inner Mr. Heckles.

![mr_heckles](https://github.com/user-attachments/assets/0f00b458-d96d-46c9-9b89-1ecfc1e2f0ac)

It's probably true that most of the existing clang-tidy checks are unaffected 
by this change. That said, I suspect that your patch alters the underlying 
contract of clang-tidy checker API quite significantly.

For example, with the current design, the checker is allowed to confirm the 
presence of a certain declaration in the included system headers before making 
other decisions. For example, a checker may refuse to emit a fix-it hint that 
suggests `std::move` if it knows that `std::move` is not defined in the current 
translation unit. (Or maybe the checker will turn itself off entirely in this 
situation.) And it is allowed to figure that out by simply scanning the 
translation unit for a declaration of a function named `move` inside a 
namespace named `std`. With your implementation, the checker will be unable to 
rely on the results of such scan, given that the system header will refuse to 
get scanned.

So I think your patch should be seen as more than a performance optimization; 
it's a somewhat significant change of contract between the checker developer 
and the tool's engine.

I see a few conversations about that in the previous discussions of that patch 
too:
> https://reviews.llvm.org/D150126#4359323
> I love an idea, but i'm afraid that it may impact checks that build some 
> internal database, like misc-confusable-identifiers or 
> misc-unused-using-decls.

Do we have some kind of consensus on this change of direction? I'm personally 
on board with this either way but I'm not a clang-tidy maintainer.

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


[clang] [Clang] [Sema] Allow non-local/non-variable declarations in for loop (PR #129737)

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


@@ -1,13 +1,21 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c11 -std=c11 -pedantic %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 -Wpre-c23-compat %s
 
 // Check C99 6.8.5p3
 void b1 (void) { for (void (*f) (void);;); }
-void b2 (void) { for (void f (void);;); }   // expected-error {{non-variable 
declaration in 'for' loop}}
-void b3 (void) { for (static int f;;); }// expected-error {{declaration of 
non-local variable}}
-void b4 (void) { for (typedef int f;;); }   // expected-error {{non-variable 
declaration in 'for' loop}}
+void b2 (void) { for (void f (void);;); }   /* c11-warning {{non-variable 
declaration in 'for' loop is a C23 extension}}

shafik wrote:

I think these test should have show the non-local variables being used within 
the loops as well. Otherwise the tests are not fully testing the functionality 
and are not fully protecting against regressions.



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


[clang] [Clang] Treat `ext_vector_type` as a regular type attribute (PR #130177)

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

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/130177

>From 728e1bd9cccb56a0acaf5abb35fe64cacc5b4ae9 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 6 Mar 2025 15:08:25 -0600
Subject: [PATCH 1/6] [Clang] Treat `ext_vector_type` as a regular type
 attribute

Summary:
This attribute is mostly borrowed from OpenCL, but is useful in general
for accessing the LLVM vector types. Previously the only way to use it
was through typedefs. This patch changes that to allow use as a regular
type attribute, similar to address spaces.
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Attr.td | 13 +++--
 clang/include/clang/Basic/AttrDocs.td | 23 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++-
 clang/test/CodeGenCUDA/amdgpu-bf16.cu | 12 
 clang/test/Sema/types.c   |  2 +-
 6 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86bf836b4a999..695c458b36702 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,7 @@ Adding [[clang::unsafe_buffer_usage]] attribute to a method 
definition now turns
 related warnings within the method body.
 
 - The ``no_sanitize`` attribute now accepts both ``gnu`` and ``clang`` names.
+- The ``ext_vector_type(n)`` attribute can now be used as a generic type 
attribute.
 - Clang now diagnoses use of declaration attributes on void parameters. 
(#GH108819)
 - Clang now allows ``__attribute__((model("small")))`` and
   ``__attribute__((model("large")))`` on non-TLS globals in x86-64 
compilations.
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc9b462126125..161a4fe8e0f12 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1721,17 +1721,10 @@ def EnableIf : InheritableAttr {
   let Documentation = [EnableIfDocs];
 }
 
-def ExtVectorType : Attr {
-  // This is an OpenCL-related attribute and does not receive a [[]] spelling.
-  let Spellings = [GNU<"ext_vector_type">];
-  // FIXME: This subject list is wrong; this is a type attribute.
-  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+def ExtVectorType : TypeAttr {
+  let Spellings = [Clang<"ext_vector_type">];
   let Args = [ExprArgument<"NumElements">];
-  let ASTNode = 0;
-  let Documentation = [Undocumented];
-  // This is a type attribute with an incorrect subject list, so should not be
-  // permitted by #pragma clang attribute.
-  let PragmaAttributeSupport = 0;
+  let Documentation = [ExtVectorTypeDocs];
 }
 
 def FallThrough : StmtAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f44fad95423ee..c309b4849b731 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1113,6 +1113,29 @@ template instantiation, so the value for ``T::number`` 
is known.
   }];
 }
 
+def ExtVectorTypeDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+
+The ext_vector_type(N) attribute specifies that a type is a vector with N
+elements, directly mapping to an LLVM vector type. Originally from OpenCL, it
+allows element access via [] or x, y, z, w for graphics-style indexing. This
+attribute enables efficient SIMD operations and is usable in general-purpose
+code.
+
+.. code-block:: c++
+
+  template 
+  constexpr T simd_reduce(T [[clang::ext_vector_type(N)]] v) {
+T sum{};
+for (uint32_t i = 0; i < N; ++i) {
+  sum += v[i];
+}
+return sum;
+  }
+  }];
+}
+
 def DiagnoseIfDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 1405ee5341dcf..d32320c581656 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1191,7 +1191,8 @@ static void handleTestTypestateAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 
 static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   // Remember this typedef decl, we will need it later for diagnostics.
-  S.ExtVectorDecls.push_back(cast(D));
+  if (isa(D))
+S.ExtVectorDecls.push_back(cast(D));
 }
 
 static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
diff --git a/clang/test/CodeGenCUDA/amdgpu-bf16.cu 
b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
index 4610b4ae3cbe5..f6533d7faf296 100644
--- a/clang/test/CodeGenCUDA/amdgpu-bf16.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-bf16.cu
@@ -111,19 +111,15 @@ __device__ __bf16 test_call( __bf16 in) {
 // CHECK-NEXT:ret void
 //
 __device__ void test_vec_assign() {
-  typedef __attribute__((ext_vector_type(2))) __bf16 bf16_x2;
-  bf16_x2 vec2_a, vec2_b;
+  __bf16 [[clang::ext_vector_type(2)]] vec2_a, vec2_b;
   vec2_a = vec2_b;
 
-  typedef __attribute__((ext_vector_type(4))) __bf16 bf16_x4;
-  bf16_x4 vec4_a, vec4_b;
+  __bf16 [[clang::ext_vector_type(4)]] v

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

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

https://github.com/aheejin created 
https://github.com/llvm/llvm-project/pull/130220

I think it is generally better for tests have some descriptive function names 
so that we can insert new tests in the middle and don't have to renumber all 
tests.

Also recently I added a (named) test to this file in #129020 so I think it's 
consistent for other tests to be named.

>From 2bfb5e6c062edfc878c55667ce1355f86590293b Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Fri, 7 Mar 2025 01:36:03 +
Subject: [PATCH] [WebAssembly] Rename functions in wasm-eh.cpp

I think it is generally better for tests have some descriptive function
names so that we can insert new tests in the middle and don't have to
renumber all tests.

Also recently I added a (named) test to this file in #129020 so I think
it's consistent for other tests to be named.
---
 clang/test/CodeGenCXX/wasm-eh.cpp | 44 +++
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/clang/test/CodeGenCXX/wasm-eh.cpp 
b/clang/test/CodeGenCXX/wasm-eh.cpp
index e8797794e7c1e..faff764878f5d 100644
--- a/clang/test/CodeGenCXX/wasm-eh.cpp
+++ b/clang/test/CodeGenCXX/wasm-eh.cpp
@@ -17,7 +17,7 @@ struct Cleanup {
 };
 
 // Multiple catch clauses w/o catch-all
-void test0() {
+void multiple_catches_wo_catch_all() {
   try {
 may_throw();
   } catch (int) {
@@ -27,7 +27,7 @@ void test0() {
   }
 }
 
-// CHECK-LABEL: define void @_Z5test0v() {{.*}} personality ptr 
@__gxx_wasm_personality_v0
+// CHECK-LABEL: define void @_Z29multiple_catches_wo_catch_allv() {{.*}} 
personality ptr @__gxx_wasm_personality_v0
 
 // CHECK:   %[[INT_ALLOCA:.*]] = alloca i32
 // CHECK:   invoke void @_Z9may_throwv()
@@ -73,7 +73,7 @@ void test0() {
 // CHECK-NEXT:   unreachable
 
 // Single catch-all
-void test1() {
+void single_catch_all() {
   try {
 may_throw();
   } catch (...) {
@@ -81,7 +81,7 @@ void test1() {
   }
 }
 
-// CATCH-LABEL: @_Z5test1v()
+// CATCH-LABEL: @_Z16single_catch_allv()
 
 // CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label 
%[[CATCHSTART_BB:.*]]] unwind to caller
 
@@ -93,7 +93,7 @@ void test1() {
 // CHECK:   catchret from %[[CATCHPAD]] to label
 
 // Multiple catch clauses w/ catch-all
-void test2() {
+void multiple_catches_w_catch_all() {
   try {
 may_throw();
   } catch (int) {
@@ -103,7 +103,7 @@ void test2() {
   }
 }
 
-// CHECK-LABEL: @_Z5test2v()
+// CHECK-LABEL: @_Z28multiple_catches_w_catch_allv()
 
 // CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label 
%[[CATCHSTART_BB:.*]]] unwind to caller
 
@@ -118,12 +118,12 @@ void test2() {
 // CHECK:   catchret from %[[CATCHPAD]] to label
 
 // Cleanup
-void test3() {
+void cleanup() {
   Cleanup c;
   may_throw();
 }
 
-// CHECK-LABEL: @_Z5test3v()
+// CHECK-LABEL: @_Z7cleanupv()
 
 // CHECK:   invoke void @_Z9may_throwv()
 // CHECK-NEXT:   to label {{.*}} unwind label %[[EHCLEANUP_BB:.*]]
@@ -134,7 +134,7 @@ void test3() {
 // CHECK-NEXT:   cleanupret from %[[CLEANUPPAD]] unwind to caller
 
 // Possibly throwing function call within a catch
-void test4() {
+void catch_int() {
   try {
 may_throw();
   } catch (int) {
@@ -142,7 +142,7 @@ void test4() {
   }
 }
 
-// CHECK-LABEL: @_Z5test4v()
+// CHECK-LABEL: @_Z9catch_intv()
 
 // CHECK:   %[[CATCHSWITCH]] = catchswitch within none [label 
%[[CATCHSTART_BB]]] unwind to caller
 
@@ -162,7 +162,7 @@ void test4() {
 // CHECK-NEXT:   cleanupret from %[[CLEANUPPAD]] unwind to caller
 
 // Possibly throwing function call within a catch-all
-void test5() {
+void catch_all() {
   try {
 may_throw();
   } catch (...) {
@@ -170,7 +170,7 @@ void test5() {
   }
 }
 
-// CHECK-LABEL: @_Z5test5v()
+// CHECK-LABEL: @_Z9catch_allv()
 
 // CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label 
%[[CATCHSTART_BB]]] unwind to caller
 
@@ -198,7 +198,7 @@ void test5() {
 // CHECK-NEXT:   unreachable
 
 // Try-catch with cleanups
-void test6() {
+void try_catch_w_cleanups() {
   Cleanup c1;
   try {
 Cleanup c2;
@@ -209,7 +209,7 @@ void test6() {
   }
 }
 
-// CHECK-LABEL: @_Z5test6v()
+// CHECK-LABEL: @_Z20try_catch_w_cleanupsv()
 // CHECK:   invoke void @_Z9may_throwv()
 // CHECK-NEXT:   to label %{{.*}} unwind label %[[EHCLEANUP_BB0:.*]]
 
@@ -254,7 +254,7 @@ void test6() {
 // CHECK-NEXT:   unreachable
 
 // Nested try-catches within a try with cleanups
-void test7() {
+void nested_try_catches_with_cleanups() {
   Cleanup c1;
   may_throw();
   try {
@@ -275,7 +275,7 @@ void test7() {
   }
 }
 
-// CHECK-LABEL: @_Z5test7v()
+// CHECK-LABEL: @_Z32nested_try_catches_with_cleanupsv()
 // CHECK:   invoke void @_Z9may_throwv()
 
 // CHECK:   invoke void @_Z9may_throwv()
@@ -340,7 +340,7 @@ void test7() {
 // CHECK:   unreachable
 
 // Nested try-catches within a catch
-void test8() {
+void nested_try_catch_within_catch() {
   try {
 may_throw();
   } catch (int) {
@@ -352,7 +352,7 @@ void test8() {
   }
 }
 
-// CHECK-LABEL: @_Z5test8v()
+// CHECK-LABEL: @_Z29nested_t

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

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Heejin Ahn (aheejin)


Changes

I think it is generally better for tests have some descriptive function names 
so that we can insert new tests in the middle and don't have to renumber all 
tests.

Also recently I added a (named) test to this file in #129020 so I think 
it's consistent for other tests to be named.

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


1 Files Affected:

- (modified) clang/test/CodeGenCXX/wasm-eh.cpp (+22-22) 


``diff
diff --git a/clang/test/CodeGenCXX/wasm-eh.cpp 
b/clang/test/CodeGenCXX/wasm-eh.cpp
index e8797794e7c1e..faff764878f5d 100644
--- a/clang/test/CodeGenCXX/wasm-eh.cpp
+++ b/clang/test/CodeGenCXX/wasm-eh.cpp
@@ -17,7 +17,7 @@ struct Cleanup {
 };
 
 // Multiple catch clauses w/o catch-all
-void test0() {
+void multiple_catches_wo_catch_all() {
   try {
 may_throw();
   } catch (int) {
@@ -27,7 +27,7 @@ void test0() {
   }
 }
 
-// CHECK-LABEL: define void @_Z5test0v() {{.*}} personality ptr 
@__gxx_wasm_personality_v0
+// CHECK-LABEL: define void @_Z29multiple_catches_wo_catch_allv() {{.*}} 
personality ptr @__gxx_wasm_personality_v0
 
 // CHECK:   %[[INT_ALLOCA:.*]] = alloca i32
 // CHECK:   invoke void @_Z9may_throwv()
@@ -73,7 +73,7 @@ void test0() {
 // CHECK-NEXT:   unreachable
 
 // Single catch-all
-void test1() {
+void single_catch_all() {
   try {
 may_throw();
   } catch (...) {
@@ -81,7 +81,7 @@ void test1() {
   }
 }
 
-// CATCH-LABEL: @_Z5test1v()
+// CATCH-LABEL: @_Z16single_catch_allv()
 
 // CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label 
%[[CATCHSTART_BB:.*]]] unwind to caller
 
@@ -93,7 +93,7 @@ void test1() {
 // CHECK:   catchret from %[[CATCHPAD]] to label
 
 // Multiple catch clauses w/ catch-all
-void test2() {
+void multiple_catches_w_catch_all() {
   try {
 may_throw();
   } catch (int) {
@@ -103,7 +103,7 @@ void test2() {
   }
 }
 
-// CHECK-LABEL: @_Z5test2v()
+// CHECK-LABEL: @_Z28multiple_catches_w_catch_allv()
 
 // CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label 
%[[CATCHSTART_BB:.*]]] unwind to caller
 
@@ -118,12 +118,12 @@ void test2() {
 // CHECK:   catchret from %[[CATCHPAD]] to label
 
 // Cleanup
-void test3() {
+void cleanup() {
   Cleanup c;
   may_throw();
 }
 
-// CHECK-LABEL: @_Z5test3v()
+// CHECK-LABEL: @_Z7cleanupv()
 
 // CHECK:   invoke void @_Z9may_throwv()
 // CHECK-NEXT:   to label {{.*}} unwind label %[[EHCLEANUP_BB:.*]]
@@ -134,7 +134,7 @@ void test3() {
 // CHECK-NEXT:   cleanupret from %[[CLEANUPPAD]] unwind to caller
 
 // Possibly throwing function call within a catch
-void test4() {
+void catch_int() {
   try {
 may_throw();
   } catch (int) {
@@ -142,7 +142,7 @@ void test4() {
   }
 }
 
-// CHECK-LABEL: @_Z5test4v()
+// CHECK-LABEL: @_Z9catch_intv()
 
 // CHECK:   %[[CATCHSWITCH]] = catchswitch within none [label 
%[[CATCHSTART_BB]]] unwind to caller
 
@@ -162,7 +162,7 @@ void test4() {
 // CHECK-NEXT:   cleanupret from %[[CLEANUPPAD]] unwind to caller
 
 // Possibly throwing function call within a catch-all
-void test5() {
+void catch_all() {
   try {
 may_throw();
   } catch (...) {
@@ -170,7 +170,7 @@ void test5() {
   }
 }
 
-// CHECK-LABEL: @_Z5test5v()
+// CHECK-LABEL: @_Z9catch_allv()
 
 // CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label 
%[[CATCHSTART_BB]]] unwind to caller
 
@@ -198,7 +198,7 @@ void test5() {
 // CHECK-NEXT:   unreachable
 
 // Try-catch with cleanups
-void test6() {
+void try_catch_w_cleanups() {
   Cleanup c1;
   try {
 Cleanup c2;
@@ -209,7 +209,7 @@ void test6() {
   }
 }
 
-// CHECK-LABEL: @_Z5test6v()
+// CHECK-LABEL: @_Z20try_catch_w_cleanupsv()
 // CHECK:   invoke void @_Z9may_throwv()
 // CHECK-NEXT:   to label %{{.*}} unwind label %[[EHCLEANUP_BB0:.*]]
 
@@ -254,7 +254,7 @@ void test6() {
 // CHECK-NEXT:   unreachable
 
 // Nested try-catches within a try with cleanups
-void test7() {
+void nested_try_catches_with_cleanups() {
   Cleanup c1;
   may_throw();
   try {
@@ -275,7 +275,7 @@ void test7() {
   }
 }
 
-// CHECK-LABEL: @_Z5test7v()
+// CHECK-LABEL: @_Z32nested_try_catches_with_cleanupsv()
 // CHECK:   invoke void @_Z9may_throwv()
 
 // CHECK:   invoke void @_Z9may_throwv()
@@ -340,7 +340,7 @@ void test7() {
 // CHECK:   unreachable
 
 // Nested try-catches within a catch
-void test8() {
+void nested_try_catch_within_catch() {
   try {
 may_throw();
   } catch (int) {
@@ -352,7 +352,7 @@ void test8() {
   }
 }
 
-// CHECK-LABEL: @_Z5test8v()
+// CHECK-LABEL: @_Z29nested_try_catch_within_catchv()
 // CHECK:   invoke void @_Z9may_throwv()
 
 // CHECK:   %[[CATCHSWITCH0:.*]] = catchswitch within none
@@ -402,19 +402,19 @@ void noexcept_throw() noexcept {
 // This is controlled by -Wwasm-exception-spec, which is on by default. This
 // warning can be suppressed with -Wno-wasm-exception-spec. Checks if a warning
 // message is correctly printed or not printed depending on the options.
-void test9() thr

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

2025-03-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Sam Elliott (lenary)


Changes

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

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

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


11 Files Affected:

- (modified) clang/include/clang/Basic/AttrDocs.td (+1-1) 
- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1-1) 
- (modified) llvm/docs/RISCVUsage.rst (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.cpp (+3-4) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp (+24) 
- (modified) llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h (+6) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/qci-interrupt-attr.ll (-12) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+2-2) 


``diff
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdc58d1c92c0d..02bab407d08fe 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2848,7 +2848,7 @@ 
https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Function-Attributes.html
 https://riscv.org/specifications/privileged-isa/
 The RISC-V Instruction Set Manual Volume II: Privileged Architecture
 Version 1.10.
-https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.6
+https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7
   }];
 }
 
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 69b76f0c4c4cd..d9335fe502bb6 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -201,7 +201,7 @@
 // CHECK-NEXT: xqcicm   0.2   'Xqcicm' (Qualcomm uC 
Conditional Move Extension)
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
 // CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
-// CHECK-NEXT: xqciint  0.2   'Xqciint' (Qualcomm uC 
Interrupts Extension)
+// CHECK-NEXT: xqciint  0.4   'Xqciint' (Qualcomm uC 
Interrupts Extension)
 // CHECK-NEXT: xqcilia  0.2   'Xqcilia' (Qualcomm uC Large 
Immediate Arithmetic Extension)
 // CHECK-NEXT: xqcilo   0.2   'Xqcilo' (Qualcomm uC Large 
Offset Load Store Extension)
 // CHECK-NEXT: xqcilsm  0.2   'Xqcilsm' (Qualcomm uC Load 
Store Multiple Extension)
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 62c6a4fd80fd4..831e8fd5d186b 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -454,7 +454,7 @@ The current vendor extensions supported are:
   LLVM implements `version 0.2 of the Qualcomm uC CSR extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
 ``experimental-Xqciint``
-  LLVM implements `version 0.2 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+  LLVM implements `version 0.4 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 
 ``experimental-Xqcilia``
   LLVM implements `version 0.2 of the Qualcomm uC Large Immediate Arithmetic 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 35db027509d94..544ad14266183 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1351,7 +1351,7 @@ def HasVendorXqcicm
  "'Xqcicm' (Qualcomm uC Conditional Move Extension)">;
 
 def FeatureVendorXqciint
-: RISCVExperimentalExtension<0, 2, "Qualcomm uC 

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

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

https://github.com/lenary updated 
https://github.com/llvm/llvm-project/pull/130219

>From 30cc00694a8c1d57f201101121d008e89444743a Mon Sep 17 00:00:00 2001
From: Sam Elliott 
Date: Thu, 6 Mar 2025 17:25:44 -0800
Subject: [PATCH 1/2] [RISCV] Update to Xqciint v0.4

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

This change bumps the Xqciint version, and ensures that we don't emit
the unneeded frame pointer adjustment instruction after
`qc.c.mienter(.nest)`.
---
 clang/include/clang/Basic/AttrDocs.td |  2 +-
 .../Driver/print-supported-extensions-riscv.c |  2 +-
 llvm/docs/RISCVUsage.rst  |  2 +-
 llvm/lib/Target/RISCV/RISCVFeatures.td|  2 +-
 llvm/lib/Target/RISCV/RISCVFrameLowering.cpp  |  7 +++---
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td   |  2 +-
 .../Target/RISCV/RISCVMachineFunctionInfo.cpp | 24 +++
 .../Target/RISCV/RISCVMachineFunctionInfo.h   |  6 +
 llvm/test/CodeGen/RISCV/attributes.ll |  2 +-
 llvm/test/CodeGen/RISCV/qci-interrupt-attr.ll | 12 --
 .../TargetParser/RISCVISAInfoTest.cpp |  4 ++--
 11 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index fdc58d1c92c0d..02bab407d08fe 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2848,7 +2848,7 @@ 
https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Function-Attributes.html
 https://riscv.org/specifications/privileged-isa/
 The RISC-V Instruction Set Manual Volume II: Privileged Architecture
 Version 1.10.
-https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.6
+https://github.com/quic/riscv-unified-db/releases/tag/Xqci-0.7
   }];
 }
 
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 69b76f0c4c4cd..d9335fe502bb6 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -201,7 +201,7 @@
 // CHECK-NEXT: xqcicm   0.2   'Xqcicm' (Qualcomm uC 
Conditional Move Extension)
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
 // CHECK-NEXT: xqcicsr  0.2   'Xqcicsr' (Qualcomm uC CSR 
Extension)
-// CHECK-NEXT: xqciint  0.2   'Xqciint' (Qualcomm uC 
Interrupts Extension)
+// CHECK-NEXT: xqciint  0.4   'Xqciint' (Qualcomm uC 
Interrupts Extension)
 // CHECK-NEXT: xqcilia  0.2   'Xqcilia' (Qualcomm uC Large 
Immediate Arithmetic Extension)
 // CHECK-NEXT: xqcilo   0.2   'Xqcilo' (Qualcomm uC Large 
Offset Load Store Extension)
 // CHECK-NEXT: xqcilsm  0.2   'Xqcilsm' (Qualcomm uC Load 
Store Multiple Extension)
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 62c6a4fd80fd4..831e8fd5d186b 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -454,7 +454,7 @@ The current vendor extensions supported are:
   LLVM implements `version 0.2 of the Qualcomm uC CSR extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
 ``experimental-Xqciint``
-  LLVM implements `version 0.2 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+  LLVM implements `version 0.4 of the Qualcomm uC Interrupts extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
 
 ``experimental-Xqcilia``
   LLVM implements `version 0.2 of the Qualcomm uC Large Immediate Arithmetic 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 35db027509d94..544ad14266183 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1351,7 +1351,7 @@ def HasVendorXqcicm
  "'Xqcicm' (Qualcomm uC Conditional Move Extension)">;
 
 def FeatureVendorXqciint
- 

  1   2   3   4   >