[clang] [CIR][NFCI] Represent Complex RValues As Single Value (PR #144519)

2025-06-17 Thread Amr Hesham via cfe-commits

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

LGTM, Thanks!

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


[clang-tools-extra] [clang-tidy] Added bugprone-unsequenced-global-accesses check (PR #130421)

2025-06-17 Thread Áron Hárnási via cfe-commits

ConcreteCactus wrote:

Hi Everyone,

Thank you for the detailed suggestions. Now that I have a better idea of what 
CSA is, I also think that this check could be better implemented in 
clang-static-analyzer. Being able to reduce the number of false positives using 
path sensitive analysis is in my opinion the most important advantage of using 
CSA.

What do you think? Should I close this PR, and open a new one when I'm ready 
with the CSA checker?

By the way, I don't have any users. This check is more like a University 
project I picked. The reason I started with clang-tidy is simply because that 
was the suggestion my teacher gave me.

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


[clang] [CIR] Upstream ComplexType builtin_complex (PR #144225)

2025-06-17 Thread Amr Hesham via cfe-commits


@@ -176,3 +176,27 @@ void foo7() {
 // OGCG: store float %[[TMP_A]], ptr %[[C_REAL_PTR]], align 4
 // OGCG: store float 2.00e+00, ptr %[[C_IMAG_PTR]], align 4
 
+void foo9(double r, double i) {
+  double _Complex c = __builtin_complex(r, i);

AmrDeveloper wrote:

For arguments with expressions, I can update the tests when implementing new 
visitors 

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


[clang] Thread Safety Analysis: Very basic capability alias-analysis (PR #142955)

2025-06-17 Thread Marco Elver via cfe-commits

https://github.com/melver updated 
https://github.com/llvm/llvm-project/pull/142955

>From c2dcde6db1d853bc4b30e8c5daf6165f7b45c6c6 Mon Sep 17 00:00:00 2001
From: Marco Elver 
Date: Wed, 21 May 2025 23:49:48 +0200
Subject: [PATCH] Thread Safety Analysis: Very basic capability alias-analysis

Add a simple form of alias analysis for capabilities by substituting
local pointer variables with their initializers if they are `const` or
never reassigned.

For example, the analysis will no longer generate false positives for
cases such as:

void testNestedAccess(Container *c) {
  Foo *ptr = &c->foo;
  ptr->mu.Lock();
  c->foo.data = 42;  // OK - no false positive
  ptr->mu.Unlock();
}

void testNestedAcquire(Container *c) 
EXCLUSIVE_LOCK_FUNCTION(&c->foo.mu) {
  Foo *buf = &c->foo;
  buf->mu.Lock();  // OK - no false positive warning
}

This implementation would satisfy the basic needs of addressing the
concerns for Linux kernel application [1].

Current limitations:

* The analysis does not handle pointers that are reassigned; it
  conservatively assumes they could point to anything after the
  reassignment.

* Aliases created through complex control flow are not tracked.

Link: 
https://lore.kernel.org/all/CANpmjNPquO=W1JAh1FNQb8pMQjgeZAKCPQUAd7qUg=5pjJ6x=q...@mail.gmail.com/
 [1]
---
 .../Analysis/Analyses/ThreadSafetyCommon.h|   8 +-
 clang/lib/Analysis/ThreadSafety.cpp   |  16 ++-
 clang/lib/Analysis/ThreadSafetyCommon.cpp |  72 -
 clang/test/Sema/warn-thread-safety-analysis.c |   6 +-
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 102 +-
 5 files changed, 190 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index 6c97905a2d7f9..cd2c278c2278f 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -395,7 +395,7 @@ class SExprBuilder {
   CapabilityExpr translateAttrExpr(const Expr *AttrExp, CallingContext *Ctx);
 
   // Translate a variable reference.
-  til::LiteralPtr *createVariable(const VarDecl *VD);
+  til::SExpr *createVariable(const VarDecl *VD, CallingContext *Ctx = nullptr);
 
   // Translate a clang statement or expression to a TIL expression.
   // Also performs substitution of variables; Ctx provides the context.
@@ -501,6 +501,9 @@ class SExprBuilder {
   void mergeEntryMapBackEdge();
   void mergePhiNodesBackEdge(const CFGBlock *Blk);
 
+  // Returns true if a variable is assumed to be reassigned.
+  bool isVariableReassigned(const VarDecl *VD);
+
 private:
   // Set to true when parsing capability expressions, which get translated
   // inaccurately in order to hack around smart pointers etc.
@@ -531,6 +534,9 @@ class SExprBuilder {
   std::vector IncompleteArgs;
   til::BasicBlock *CurrentBB = nullptr;
   BlockInfo *CurrentBlockInfo = nullptr;
+
+  // Map caching if a local variable is reassigned.
+  llvm::DenseMap LocalVariableReassigned;
 };
 
 #ifndef NDEBUG
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 80e7c8eff671a..a0ab241125d1c 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1141,11 +1141,10 @@ class ThreadSafetyAnalyzer {
 
   void warnIfMutexNotHeld(const FactSet &FSet, const NamedDecl *D,
   const Expr *Exp, AccessKind AK, Expr *MutexExp,
-  ProtectedOperationKind POK, til::LiteralPtr *Self,
+  ProtectedOperationKind POK, til::SExpr *Self,
   SourceLocation Loc);
   void warnIfMutexHeld(const FactSet &FSet, const NamedDecl *D, const Expr 
*Exp,
-   Expr *MutexExp, til::LiteralPtr *Self,
-   SourceLocation Loc);
+   Expr *MutexExp, til::SExpr *Self, SourceLocation Loc);
 
   void checkAccess(const FactSet &FSet, const Expr *Exp, AccessKind AK,
ProtectedOperationKind POK);
@@ -1599,7 +1598,7 @@ class BuildLockset : public 
ConstStmtVisitor {
   }
 
   void handleCall(const Expr *Exp, const NamedDecl *D,
-  til::LiteralPtr *Self = nullptr,
+  til::SExpr *Self = nullptr,
   SourceLocation Loc = SourceLocation());
   void examineArguments(const FunctionDecl *FD,
 CallExpr::const_arg_iterator ArgBegin,
@@ -1629,7 +1628,7 @@ class BuildLockset : public 
ConstStmtVisitor {
 /// of at least the passed in AccessKind.
 void ThreadSafetyAnalyzer::warnIfMutexNotHeld(
 const FactSet &FSet, const NamedDecl *D, const Expr *Exp, AccessKind AK,
-Expr *MutexExp, ProtectedOperationKind POK, til::LiteralPtr *Self,
+Expr *MutexExp, ProtectedOperationKind POK, til::SExpr *Self,
 SourceLocation Loc) {
   LockKind LK = getLockKindFrom

[clang] eb31c42 - [Driver] Add support for GCC installation detection in Baremetal toolchain (#121829)

2025-06-17 Thread via cfe-commits

Author: Garvit Gupta
Date: 2025-06-17T21:43:17+05:30
New Revision: eb31c422d0dc816bf285a81bf92690d4d16273ed

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

LOG: [Driver] Add support for GCC installation detection in Baremetal toolchain 
(#121829)

This patch introduces enhancements to the Baremetal toolchain to support
GCC toolchain detection.
- If the --gcc-install-dir or --gcc-toolchain options are provided and
point to valid paths, the sysroot is derived from those locations.
- If not, the logic falls back to the existing sysroot inference
mechanism already present in the Baremetal toolchain.
- Support for adding include paths for the libstdc++ library has also
been added.

Additionally, the restriction to always use the integrated assembler has
been removed. With a valid GCC installation, the GNU assembler can now
be used as well.

This patch currently updates and adds tests for the ARM target only.
RISC-V-specific tests will be introduced in a later patch, once the
RISCVToolChain is fully merged into the Baremetal toolchain. At this
stage, there is no way to test the RISC-V target within this PR.

RFC:
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

Added: 

clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include/c++/8.2.1/.keep
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/.keep
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/crt0.o
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/bin/aarch64-none-elf-ld

clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o

clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtend.o

clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crt0.o

clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtbegin.o

clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtend.o
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/bin/aarch64-none-elf-ld

clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/include/c++/8.2.1/.keep
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/.keep
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/crt0.o
clang/test/Driver/Inputs/basic_arm_gcc_tree/bin/armv6m-none-eabi-ld

clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o

clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtend.o
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crt0.o

clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtbegin.o
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtend.o
clang/test/Driver/Inputs/basic_arm_nogcc_tree/bin/armv6m-none-eabi-ld
clang/test/Driver/aarch64-gnutools.c
clang/test/Driver/aarch64-toolchain-extra.c
clang/test/Driver/aarch64-toolchain.c
clang/test/Driver/arm-gnutools.c
clang/test/Driver/arm-toolchain-extra.c
clang/test/Driver/arm-toolchain.c
clang/test/Driver/check-no-multlib-warning.c

Modified: 
clang/docs/Toolchain.rst
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/BareMetal.h
clang/test/Driver/baremetal.cpp

Removed: 




diff  --git a/clang/docs/Toolchain.rst b/clang/docs/Toolchain.rst
index 958199eb7a2e2..d56b21d74c7e3 100644
--- a/clang/docs/Toolchain.rst
+++ b/clang/docs/Toolchain.rst
@@ -347,3 +347,8 @@ workarounds for issues discovered in libstdc++, and these 
are removed
 as fixed libstdc++ becomes sufficiently old.
 
 You can instruct Clang to use libstdc++ with the ``-stdlib=libstdc++`` flag.
+
+GCC Installation
+=
+Users can point to their GCC installation by using the ``-gcc-toolchain`` or by
+using ``-gcc-install-dir`` flag.

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 29f6480ba935c..94224e1038758 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -847,6 +847,9 @@ def note_drv_available_multilibs : Note<
   "available multilibs are:%0">;
 def err_drv_multilib_custom_error : Error<
   "multilib configuration error: %0">;
+def warn_drv_multilib_not_available_for_target: Warning<
+  "no multilib structure encoded for Arm, Aarch64 and PPC targets">,
+  InGroup>;
 
 def err_drv_experimental_crel : Error<
   "-Wa,--allow-experimental-crel must be specified to use -Wa,--crel. "

diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index d

[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #121829)

2025-06-17 Thread Garvit Gupta via cfe-commits

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


[clang] [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (PR #121830)

2025-06-17 Thread Garvit Gupta via cfe-commits

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


[clang] Thread Safety Analysis: Very basic capability alias-analysis (PR #142955)

2025-06-17 Thread Marco Elver via cfe-commits

https://github.com/melver updated 
https://github.com/llvm/llvm-project/pull/142955

>From 608c4f657e2bcc0591e2fc32606a6738445cade6 Mon Sep 17 00:00:00 2001
From: Marco Elver 
Date: Wed, 21 May 2025 23:49:48 +0200
Subject: [PATCH] Thread Safety Analysis: Very basic capability alias-analysis

Add a simple form of alias analysis for capabilities by substituting
local pointer variables with their initializers if they are `const` or
never reassigned.

For example, the analysis will no longer generate false positives for
cases such as:

void testNestedAccess(Container *c) {
  Foo *ptr = &c->foo;
  ptr->mu.Lock();
  c->foo.data = 42;  // OK - no false positive
  ptr->mu.Unlock();
}

void testNestedAcquire(Container *c) 
EXCLUSIVE_LOCK_FUNCTION(&c->foo.mu) {
  Foo *buf = &c->foo;
  buf->mu.Lock();  // OK - no false positive warning
}

This implementation would satisfy the basic needs of addressing the
concerns for Linux kernel application [1].

Current limitations:

* The analysis does not handle pointers that are reassigned; it
  conservatively assumes they could point to anything after the
  reassignment.

* Aliases created through complex control flow are not tracked.

Link: 
https://lore.kernel.org/all/CANpmjNPquO=W1JAh1FNQb8pMQjgeZAKCPQUAd7qUg=5pjJ6x=q...@mail.gmail.com/
 [1]
---
 .../Analysis/Analyses/ThreadSafetyCommon.h|   8 +-
 clang/lib/Analysis/ThreadSafety.cpp   |  16 ++-
 clang/lib/Analysis/ThreadSafetyCommon.cpp |  78 +-
 clang/test/Sema/warn-thread-safety-analysis.c |   6 +-
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 102 +-
 5 files changed, 196 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index 6c97905a2d7f9..cd2c278c2278f 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -395,7 +395,7 @@ class SExprBuilder {
   CapabilityExpr translateAttrExpr(const Expr *AttrExp, CallingContext *Ctx);
 
   // Translate a variable reference.
-  til::LiteralPtr *createVariable(const VarDecl *VD);
+  til::SExpr *createVariable(const VarDecl *VD, CallingContext *Ctx = nullptr);
 
   // Translate a clang statement or expression to a TIL expression.
   // Also performs substitution of variables; Ctx provides the context.
@@ -501,6 +501,9 @@ class SExprBuilder {
   void mergeEntryMapBackEdge();
   void mergePhiNodesBackEdge(const CFGBlock *Blk);
 
+  // Returns true if a variable is assumed to be reassigned.
+  bool isVariableReassigned(const VarDecl *VD);
+
 private:
   // Set to true when parsing capability expressions, which get translated
   // inaccurately in order to hack around smart pointers etc.
@@ -531,6 +534,9 @@ class SExprBuilder {
   std::vector IncompleteArgs;
   til::BasicBlock *CurrentBB = nullptr;
   BlockInfo *CurrentBlockInfo = nullptr;
+
+  // Map caching if a local variable is reassigned.
+  llvm::DenseMap LocalVariableReassigned;
 };
 
 #ifndef NDEBUG
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 80e7c8eff671a..a0ab241125d1c 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1141,11 +1141,10 @@ class ThreadSafetyAnalyzer {
 
   void warnIfMutexNotHeld(const FactSet &FSet, const NamedDecl *D,
   const Expr *Exp, AccessKind AK, Expr *MutexExp,
-  ProtectedOperationKind POK, til::LiteralPtr *Self,
+  ProtectedOperationKind POK, til::SExpr *Self,
   SourceLocation Loc);
   void warnIfMutexHeld(const FactSet &FSet, const NamedDecl *D, const Expr 
*Exp,
-   Expr *MutexExp, til::LiteralPtr *Self,
-   SourceLocation Loc);
+   Expr *MutexExp, til::SExpr *Self, SourceLocation Loc);
 
   void checkAccess(const FactSet &FSet, const Expr *Exp, AccessKind AK,
ProtectedOperationKind POK);
@@ -1599,7 +1598,7 @@ class BuildLockset : public 
ConstStmtVisitor {
   }
 
   void handleCall(const Expr *Exp, const NamedDecl *D,
-  til::LiteralPtr *Self = nullptr,
+  til::SExpr *Self = nullptr,
   SourceLocation Loc = SourceLocation());
   void examineArguments(const FunctionDecl *FD,
 CallExpr::const_arg_iterator ArgBegin,
@@ -1629,7 +1628,7 @@ class BuildLockset : public 
ConstStmtVisitor {
 /// of at least the passed in AccessKind.
 void ThreadSafetyAnalyzer::warnIfMutexNotHeld(
 const FactSet &FSet, const NamedDecl *D, const Expr *Exp, AccessKind AK,
-Expr *MutexExp, ProtectedOperationKind POK, til::LiteralPtr *Self,
+Expr *MutexExp, ProtectedOperationKind POK, til::SExpr *Self,
 SourceLocation Loc) {
   LockKind LK = getLockKindFro

[clang] Include [[clang::require_explicit_initialization]] warnings in system headers (PR #141133)

2025-06-17 Thread via cfe-commits

higher-performance wrote:

Got it, thanks for the update! Okay, let's see what they think when they have a 
chance to reply. If there's still disagreement, I'll try to suggest some other 
ways to move forward.

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


[clang] [llvm] Dump auto (c++11) type Inferences (Issue #17) (PR #144478)

2025-06-17 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- 
clang/test/Sema/fdump_auto-type-inference.cpp 
clang/include/clang/Basic/LangOptions.h clang/include/clang/Sema/Sema.h 
clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaStmt.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index f80ccb7ee..aee773d09 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -510,7 +510,7 @@ public:
   SanitizerSet Sanitize;
   /// Is at least one coverage instrumentation type enabled.
   bool SanitizeCoverage = false;
-  
+
   bool DumpAutoTypeInference = false;
   /// Paths to files specifying which objects
   /// (files, functions, variables) should not be instrumented.
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c955766cf..781f0a509 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -89,10 +89,10 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/CommandLine.h"
 #include 
 #include 
 #include 
@@ -108,15 +108,12 @@
 #include 
 #include 
 
-
-
 namespace opts {
 // Option for dumping auto type inference
 extern llvm::cl::OptionCategory DumpAutoInference;
 extern llvm::cl::opt DumpAutoTypeInference;
 } // namespace opts
 
-
 namespace llvm {
 struct InlineAsmIdentifierInfo;
 } // namespace llvm
@@ -933,14 +930,12 @@ public:
   /// Print out statistics about the semantic analysis.
   void PrintStats() const;
 
-/// Emits diagnostic remark indicating the compiler-deduced types and 
return
+  /// Emits diagnostic remark indicating the compiler-deduced types and return
   /// type for variables and functions
   void DumpAutoTypeInference(SourceManager &SM, SourceLocation Loc, bool isVar,
  ASTContext &Context, llvm::StringRef Name,
  QualType DeducedType);
 
-
-
   /// Run some code with "sufficient" stack space. (Currently, at least 256K is
   /// guaranteed). Produces a warning if we're low on stack space and allocates
   /// more in that case. Use this in code that may recurse deeply (for example,
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 707d7c0d5..e735b2529 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -84,8 +84,9 @@ namespace opts {
 llvm::cl::OptionCategory DumpAutoInference("DumpAutoInference");
 llvm::cl::opt DumpAutoTypeInference{
 "fdump-auto-type-inference",
-llvm::cl::desc("Dump compiler-deduced type for variables and return 
expressions declared using C++ 'auto' keyword"), llvm::cl::ZeroOrMore,
-llvm::cl::cat(DumpAutoInference)};
+llvm::cl::desc("Dump compiler-deduced type for variables and return "
+   "expressions declared using C++ 'auto' keyword"),
+llvm::cl::ZeroOrMore, llvm::cl::cat(DumpAutoInference)};
 } // namespace opts
 
 SourceLocation Sema::getLocForEndOfToken(SourceLocation Loc, unsigned Offset) {
@@ -651,8 +652,6 @@ void Sema::DumpAutoTypeInference(SourceManager &SM, 
SourceLocation Loc,
   }
 }
 
-
-
 void Sema::runWithSufficientStackSpace(SourceLocation Loc,
llvm::function_ref Fn) {
   StackHandler.runWithSufficientStackSpace(Loc, Fn);
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index de3a662d6..643135b10 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13159,7 +13159,7 @@ bool Sema::DeduceVariableDeclarationType(VarDecl 
*VDecl, bool DirectInit,
 
   VDecl->setType(DeducedType);
   assert(VDecl->isLinkageValid());
-  
+
   // Emit a remark indicating the compiler-deduced type for variables declared
   // using the C++ 'auto' keyword
   SourceManager &SM = getSourceManager();
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index a5406d279..796e81a58 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3834,7 +3834,7 @@ bool Sema::DeduceFunctionTypeFromReturnExpr(FunctionDecl 
*FD,
 // Update all declarations of the function to have the deduced return type.
 Context.adjustDeducedFunctionResultType(FD, Deduced);
 
-  // Emit a remark indicating the compiler-deduced return type for 
functions
+  // Emit a remark indicating the compiler-deduced return type for functions
   // declared using the C++ 'auto' keyword
   SourceManager &SM = getSourceManager();
   Sema::DumpAutoTypeInference(SM, FD->getLocation(), false, Contex

[clang] [clang][SYCL] Add sycl_external attribute and restrict emitting device code (PR #140282)

2025-06-17 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add missing colon in the docs of performance-enum-size (PR #144525)

2025-06-17 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo. Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. See 
[LLVM Developer 
Policy](https://llvm.org/docs/DeveloperPolicy.html#email-addresses) and [LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.

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


[clang] [analyzer] Avoid contradicting assumption in tainted div-by-0 error node (PR #144491)

2025-06-17 Thread via cfe-commits

llvmbot wrote:




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

Author: Arseniy Zaostrovnykh (necto)


Changes

This patch corrects the state of the error node generated by the 
core.DivideZero checker when it detects potential division by zero involving a 
tainted denominator.

The checker split in
https://github.com/llvm/llvm-project/pull/106389/commits/91ac5ed10a154410c246d985752c1bbfcf23b105
 started to introduce a conflicting assumption about the denominator into the 
error node:
Node with the Bug Report "Division by a tainted value, possibly zero" has an 
assumption "denominator != 0".

This has been done as a shortcut to continue analysis with the correct 
assumption *after* the division - if we proceed, we can only assume the 
denominator was not zero. However, this assumption is introduced one-node too 
soon, leading to a self-contradictory error node.

In this patch, I make the error node with assumption of zero denominator fatal, 
but allow analysis to continue on the second half of the state split with the 
assumption of non-zero denominator.

---

CPP-6376

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp (+4-4) 
- (modified) clang/test/Analysis/taint-generic.c (+13) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
index 15d73fb9ca39a..ab90615f63182 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
@@ -69,7 +69,7 @@ void DivZeroChecker::reportTaintBug(
 llvm::ArrayRef TaintedSyms) const {
   if (!TaintedDivChecker.isEnabled())
 return;
-  if (ExplodedNode *N = C.generateNonFatalErrorNode(StateZero)) {
+  if (ExplodedNode *N = C.generateErrorNode(StateZero)) {
 auto R =
 std::make_unique(TaintedDivChecker, Msg, N);
 bugreporter::trackExpressionValue(N, getDenomExpr(N), *R);
@@ -113,9 +113,9 @@ void DivZeroChecker::checkPreStmt(const BinaryOperator *B,
   if ((stateNotZero && stateZero)) {
 std::vector taintedSyms = getTaintedSymbols(C.getState(), *DV);
 if (!taintedSyms.empty()) {
-  reportTaintBug("Division by a tainted value, possibly zero", 
stateNotZero,
- C, taintedSyms);
-  return;
+  reportTaintBug("Division by a tainted value, possibly zero", stateZero, 
C,
+ taintedSyms);
+  // Fallthrough to continue analysis in case of non-zero denominator.
 }
   }
 
diff --git a/clang/test/Analysis/taint-generic.c 
b/clang/test/Analysis/taint-generic.c
index 3c520612c5d9b..9d6d2942df4a9 100644
--- a/clang/test/Analysis/taint-generic.c
+++ b/clang/test/Analysis/taint-generic.c
@@ -412,6 +412,19 @@ int testTaintedDivFP(void) {
   return 5/x; // x cannot be 0, so no tainted warning either
 }
 
+void clang_analyzer_warnIfReached();
+
+int testTaintDivZeroNonfatal() {
+  int x;
+  scanf("%d", &x);
+  int y = 5/x; // expected-warning {{Division by a tainted value, possibly 
zero}}
+  if (x == 0)
+clang_analyzer_warnIfReached();
+  else
+clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+  return y;
+}
+
 // Zero-sized VLAs.
 void testTaintedVLASize(void) {
   int x;

``




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


[clang] [lld] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2025-06-17 Thread Duncan Ogilvie via cfe-commits

mrexodia wrote:

Any updated on this? It would be really cool if we could use LLVM from 
WebAssembly!

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


[clang] [libc] [llvm] [DebugInfo][RemoveDIs] Suppress getNextNonDebugInfoInstruction (PR #144383)

2025-06-17 Thread Orlando Cazalet-Hyams via cfe-commits

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

This LGTM besides the one nit, but we should probably give @WenleiHe some time 
to respond before landing.

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


[clang] [libc] [llvm] [DebugInfo][RemoveDIs] Suppress getNextNonDebugInfoInstruction (PR #144383)

2025-06-17 Thread Orlando Cazalet-Hyams via cfe-commits


@@ -29,7 +29,7 @@ to learn about the defaults for your platform and target.
 - ``LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR``: Enable 
-fstack-protector-strong to defend against stack smashing attack.
 - ``LIBC_CONF_KEEP_FRAME_POINTER``: Keep frame pointer in functions for 
better debugging experience.
 * **"errno" options**
-- ``LIBC_CONF_ERRNO_MODE``: The implementation used for errno, acceptable 
values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, 
LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, 
and LIBC_ERRNO_MODE_SYSTEM.
+- ``LIBC_CONF_ERRNO_MODE``: The implementation used for errno, acceptable 
values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, 
LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, 
LIBC_ERRNO_MODE_SYSTEM, and LIBC_ERRNO_MODE_SYSTEM_INLINE.

OCHyams wrote:

Bad rebase or something?

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


[clang] [libc] [llvm] [DebugInfo][RemoveDIs] Suppress getNextNonDebugInfoInstruction (PR #144383)

2025-06-17 Thread Orlando Cazalet-Hyams via cfe-commits

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


[clang] [clang][ARM] Include arm_acle.h in intrin.h on supported platforms (PR #144172)

2025-06-17 Thread Nick Sarnie via cfe-commits

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


[clang] [CIR] Add support for __builtin_assume (PR #144376)

2025-06-17 Thread Sirui Mu via cfe-commits

https://github.com/Lancern updated 
https://github.com/llvm/llvm-project/pull/144376

>From 74b80387abe26da76d73b81682105228ef3dfc73 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Tue, 17 Jun 2025 23:39:34 +0800
Subject: [PATCH] [CIR] Add support for __builtin_assume

This patch adds support for the __builtin_assume builtin function.
---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 22 +++
 clang/include/clang/CIR/MissingFeatures.h |  3 ++
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp   | 38 +++
 clang/lib/CIR/CodeGen/CIRGenFunction.h|  4 ++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp |  9 +
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h   | 10 +
 clang/test/CIR/CodeGen/builtin_call.cpp   | 16 
 7 files changed, 102 insertions(+)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 8dd1f0ce361d7..4655cebc82ee7 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2387,4 +2387,26 @@ def ComplexCreateOp : CIR_Op<"complex.create", [Pure, 
SameTypeOperands]> {
   let hasFolder = 1;
 }
 
+//===--===//
+// Assume Operations
+//===--===//
+
+def AssumeOp : CIR_Op<"assume"> {
+  let summary = "Tell the optimizer that a boolean value is true";
+  let description = [{
+The `cir.assume` operation takes a single boolean prediate as its only
+argument and does not have any results. The operation tells the optimizer
+that the predicate is always true.
+
+This operation corresponds to the `__assume` and the `__builtin_assume`
+builtin functions.
+  }];
+
+  let arguments = (ins CIR_BoolType:$predicate);
+
+  let assemblyFormat = [{
+$predicate `:` type($predicate) attr-dict
+  }];
+}
+
 #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 3dc28e6f2e5bf..3d120903dea19 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -237,6 +237,9 @@ struct MissingFeatures {
   static bool lowerAggregateLoadStore() { return false; }
   static bool dataLayoutTypeAllocSize() { return false; }
   static bool asmLabelAttr() { return false; }
+  static bool builtinCall() { return false; }
+  static bool builtinCallF128() { return false; }
+  static bool builtinCallMathErrno() { return false; }
 
   // Missing types
   static bool dataMemberType() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 19fac00ab8736..83825f0835a1e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -12,6 +12,7 @@
 
//===--===//
 
 #include "CIRGenCall.h"
+#include "CIRGenConstantEmitter.h"
 #include "CIRGenFunction.h"
 #include "CIRGenModule.h"
 #include "CIRGenValue.h"
@@ -66,6 +67,32 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, 
unsigned builtinID,
 return emitLibraryCall(*this, fd, e,
cgm.getBuiltinLibFunction(fd, builtinID));
 
+  assert(!cir::MissingFeatures::builtinCallF128());
+
+  // If the builtin has been declared explicitly with an assembler label,
+  // disable the specialized emitting below. Ideally we should communicate the
+  // rename in IR, or at least avoid generating the intrinsic calls that are
+  // likely to get lowered to the renamed library functions.
+  unsigned builtinIDIfNoAsmLabel = fd->hasAttr() ? 0 : builtinID;
+
+  assert(!cir::MissingFeatures::builtinCallMathErrno());
+  assert(!cir::MissingFeatures::builtinCall());
+
+  switch (builtinIDIfNoAsmLabel) {
+  default:
+break;
+
+  case Builtin::BI__assume:
+  case Builtin::BI__builtin_assume: {
+if (e->getArg(0)->HasSideEffects(getContext()))
+  return RValue::get(nullptr);
+
+mlir::Value argValue = emitCheckedArgForAssume(e->getArg(0));
+builder.create(getLoc(e->getExprLoc()), argValue);
+return RValue::get(nullptr);
+  }
+  }
+
   cgm.errorNYI(e->getSourceRange(), "unimplemented builtin call");
   return getUndefRValue(e->getType());
 }
@@ -88,3 +115,14 @@ cir::FuncOp CIRGenModule::getBuiltinLibFunction(const 
FunctionDecl *fd,
   mlir::Type type = convertType(fd->getType());
   return getOrCreateCIRFunction(name, type, d, /*forVTable=*/false);
 }
+
+mlir::Value CIRGenFunction::emitCheckedArgForAssume(const Expr *e) {
+  mlir::Value argValue = evaluateExprAsBool(e);
+  if (!sanOpts.has(SanitizerKind::Builtin))
+return argValue;
+
+  assert(!cir::MissingFeatures::sanitizers());
+  cgm.errorNYI(e->getSourceRange(),
+   "emitCheckedArgForAssume: sanitizers are NYI");
+  return {};
+}
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h 

[clang] [clang][ARM] Include arm_acle.h in intrin.h on supported platforms (PR #144172)

2025-06-17 Thread Nick Sarnie via cfe-commits

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


[clang] [clang][ARM] Include arm_acle.h in intrin.h on supported platforms (PR #144172)

2025-06-17 Thread Nick Sarnie via cfe-commits

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


[clang] [clang][ARM] Include arm_acle.h in intrin.h on supported platforms (PR #144172)

2025-06-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Nick Sarnie (sarnex)


Changes

Warnings should suggest changes that are valid on both MSVC and Clang where 
possible. 
Right now when using ARM intrinsics without including `arm_acle.h`, we throw a 
warning saying to include it or provide a declaration for the function.
MSVC doesn't have any ARM-intrinsic specific header, so include Clang's ARM 
intrinsic header (`arm_acle.h`) in `intrin.h`, and update the intrinsic usage 
warnings to suggest `intrin.h`.

See https://github.com/llvm/llvm-project/pull/140910 for more info.

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


7 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinHeaders.def (-1) 
- (modified) clang/include/clang/Basic/BuiltinsAArch64.def (+8-8) 
- (modified) clang/include/clang/Basic/BuiltinsARM.def (+8-8) 
- (modified) clang/lib/Headers/intrin.h (+4) 
- (modified) 
clang/test/CodeGen/arm-former-microsoft-intrinsics-header-warning.c (+8-8) 
- (modified) 
clang/test/CodeGen/arm64-former-microsoft-intrinsics-header-warning.c (+8-8) 
- (added) clang/test/Headers/arm-acle-no-direct-include.c (+7) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinHeaders.def 
b/clang/include/clang/Basic/BuiltinHeaders.def
index 22668ec7a3396..8e4a2f9bee9aa 100644
--- a/clang/include/clang/Basic/BuiltinHeaders.def
+++ b/clang/include/clang/Basic/BuiltinHeaders.def
@@ -12,7 +12,6 @@
 
//===--===//
 
 HEADER(NO_HEADER, nullptr)
-HEADER(ARMACLE_H, "arm_acle.h")
 HEADER(BLOCKS_H, "Blocks.h")
 HEADER(COMPLEX_H, "complex.h")
 HEADER(CTYPE_H, "ctype.h")
diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 8867a9fe09fb9..4a1db34b9b30f 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -50,11 +50,11 @@ BUILTIN(__builtin_arm_wfi, "v", "")
 BUILTIN(__builtin_arm_sev, "v", "")
 BUILTIN(__builtin_arm_sevl, "v", "")
 BUILTIN(__builtin_arm_chkfeat, "WUiWUi", "")
-TARGET_HEADER_BUILTIN(__yield, "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__wfe,   "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__wfi,   "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__sev,   "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__sevl,  "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__yield, "v", "h", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__wfe,   "v", "h", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__wfi,   "v", "h", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__sev,   "v", "h", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__sevl,  "v", "h", INTRIN_H, ALL_LANGUAGES, "")
 
 // Like __builtin_trap but provide an 16-bit immediate reason code (which goes 
into `brk #N`).
 BUILTIN(__builtin_arm_trap, "vUIs", "nr")
@@ -87,9 +87,9 @@ TARGET_BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "", 
"mte,mops")
 BUILTIN(__builtin_arm_dmb, "vUi", "nc")
 BUILTIN(__builtin_arm_dsb, "vUi", "nc")
 BUILTIN(__builtin_arm_isb, "vUi", "nc")
-TARGET_HEADER_BUILTIN(__dmb, "vUi", "nch", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__dsb, "vUi", "nch", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__isb, "vUi", "nch", ARMACLE_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__dmb, "vUi", "nch", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__dsb, "vUi", "nch", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__isb, "vUi", "nch", INTRIN_H, ALL_LANGUAGES, "")
 
 TARGET_BUILTIN(__builtin_arm_jcvt, "Zid", "nc", "v8.3a")
 
diff --git a/clang/include/clang/Basic/BuiltinsARM.def 
b/clang/include/clang/Basic/BuiltinsARM.def
index 2592e25e95c37..20a41dc248859 100644
--- a/clang/include/clang/Basic/BuiltinsARM.def
+++ b/clang/include/clang/Basic/BuiltinsARM.def
@@ -186,19 +186,19 @@ BUILTIN(__builtin_arm_wfi, "v", "")
 BUILTIN(__builtin_arm_sev, "v", "")
 BUILTIN(__builtin_arm_sevl, "v", "")
 BUILTIN(__builtin_arm_dbg, "vUi", "")
-TARGET_HEADER_BUILTIN(__yield, "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__wfe, "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__wfi, "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__sev, "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
-TARGET_HEADER_BUILTIN(__sevl, "v", "h", ARMACLE_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__yield, "v", "h", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__wfe, "v", "h", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__wfi, "v", "h", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__sev, "v", "h", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(__sevl, "v", "h", INTRIN_H, ALL_LANGUAGES, "")
 
 // Data barrier
 BUILTIN(__builtin_arm_dmb, "vUi", "nc")
 BUILTIN(__builtin_arm_dsb, "vUi", "nc")
 BUILTIN(__builtin_arm_isb, "vUi", "nc")
-TARGET_HEADER_BUILTIN(__dmb, "vUi", "nch", ARMACLE_

[clang] [CIR] Add support for __builtin_assume (PR #144376)

2025-06-17 Thread Sirui Mu via cfe-commits


@@ -49,7 +52,43 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, 
unsigned builtinID,
 }
   }
 
+  assert(!cir::MissingFeatures::opCallBuiltin());

Lancern wrote:

Replaced it with several fine-grained missing feature flags.

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


[clang] [CIR] Add support for __builtin_assume (PR #144376)

2025-06-17 Thread Sirui Mu via cfe-commits

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


[clang] [clang][ARM] Include arm_acle.h in intrin.h on supported platforms (PR #144172)

2025-06-17 Thread Nick Sarnie via cfe-commits

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


[clang] [clang][ARM] Include arm_acle.h in intrin.h on supported platforms (PR #144172)

2025-06-17 Thread Nick Sarnie via cfe-commits

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


[clang] [clang][ARM] Include arm_acle.h in intrin.h on supported platforms (PR #144172)

2025-06-17 Thread Nick Sarnie via cfe-commits

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


[clang] [clang][ARM] Include arm_acle.h in intrin.h on supported platforms (PR #144172)

2025-06-17 Thread Nick Sarnie via cfe-commits

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


[clang] [lld] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2025-06-17 Thread via cfe-commits

whitequark wrote:

Not at the moment, I should be able to revisit this at some point given the 
movement in wasi-libc.

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


[clang] [lld] [llvm] Conditionalize use of POSIX features missing on WASI/WebAssembly (PR #92677)

2025-06-17 Thread via cfe-commits

whitequark wrote:

Not at the moment, I should be able to revisit this at some point given the 
movement in wasi-libc.

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


[clang] [win][clang] Align scalar deleting destructors with MSABI (PR #139566)

2025-06-17 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/139566

>From 1b0b6242e5749e776f02581ba8600d853bfef322 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Mon, 12 May 2025 07:25:57 -0700
Subject: [PATCH 1/7] [win][clang] Align scalar deleting destructors with MSABI

While working on vector deleting destructors support (GH19772), I
noticed that MSVC produces different code in scalar deleting destructor
body depending on whether class defined its own operator delete.
In MSABI deleting destructors accept an additional implicit flag
parameter allowing some sort of flexibility. The mismatch I noticed is
that whenever a global operator delete is called, i.e. ::delete, in the
code produced by MSVC the implicit flag argument has a value that makes
the 3rd bit set, i.e. "5" for scalar deleting destructors "7" for vector
deleting destructors.
Prior to this patch, clang handled ::delete via calling global operator
delete direct after the destructor call and not calling class operator
delete in scalar deleting destructor body by passing "0" as implicit
flag argument value. This is fine until there is an attempt to link binaries
compiled with clang with binaries compiled with MSVC. The problem is that in
binaries produced by MSVC the callsite of the destructor won't call global
operator delete because it is assumed that the destructor will do that and a
destructor body generated by clang will never do.
This patch removes call to global operator delete from the callsite and
add additional check of the 3rd bit of the implicit parameter inside of
scalar deleting destructor body.
---
 clang/include/clang/AST/DeclCXX.h | 11 +++
 clang/include/clang/Sema/Sema.h   | 10 ++-
 clang/lib/CodeGen/CGClass.cpp | 77 +++
 clang/lib/CodeGen/MicrosoftCXXABI.cpp | 11 +--
 clang/lib/Sema/SemaDeclCXX.cpp| 15 
 clang/lib/Sema/SemaExprCXX.cpp| 19 +++--
 .../CodeGenCXX/cxx2a-destroying-delete.cpp| 59 --
 .../CodeGenCXX/microsoft-abi-structors.cpp| 44 ++-
 8 files changed, 202 insertions(+), 44 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index b7980137002aa..cc2832ea99d4a 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -2855,6 +2855,7 @@ class CXXDestructorDecl : public CXXMethodDecl {
   // FIXME: Don't allocate storage for these except in the first declaration
   // of a virtual destructor.
   FunctionDecl *OperatorDelete = nullptr;
+  FunctionDecl *OperatorGlobalDelete = nullptr;
   Expr *OperatorDeleteThisArg = nullptr;
 
   CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
@@ -2885,6 +2886,16 @@ class CXXDestructorDecl : public CXXMethodDecl {
 return getCanonicalDecl()->OperatorDelete;
   }
 
+  const FunctionDecl *getOperatorGlobalDelete() const {
+return getCanonicalDecl()->OperatorGlobalDelete;
+  }
+
+  void setOperatorGlobalDelete(FunctionDecl *OD) {
+auto *First = cast(getFirstDecl());
+if (OD && !First->OperatorGlobalDelete)
+  First->OperatorGlobalDelete = OD;
+  }
+
   Expr *getOperatorDeleteThisArg() const {
 return getCanonicalDecl()->OperatorDeleteThisArg;
   }
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ea7ee281e14d..5f2ceebcd42e3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8495,10 +8495,12 @@ class Sema final : public SemaBase {
 bool Diagnose = true);
   FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc,
   ImplicitDeallocationParameters,
-  DeclarationName Name);
-  FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc,
-  CXXRecordDecl *RD,
-  bool Diagnose = true);
+  DeclarationName Name,
+  bool Diagnose = true);
+  FunctionDecl *
+  FindDeallocationFunctionForDestructor(SourceLocation StartLoc,
+CXXRecordDecl *RD, bool Diagnose = 
true,
+bool LookForGlobal = false);
 
   /// ActOnCXXDelete - Parsed a C++ 'delete' expression (C++ 5.3.5), as in:
   /// @code ::delete ptr; @endcode
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index befbfc64a680c..360876244cad9 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1589,25 +1589,74 @@ namespace {
   void EmitConditionalDtorDeleteCall(CodeGenFunction &CGF,
  llvm::Value *ShouldDeleteCondition,
  bool ReturnAfterDelete) {
+  

[clang] [CIR] Implement folder for VecSplatOp (PR #143771)

2025-06-17 Thread Amr Hesham via cfe-commits


@@ -142,7 +142,8 @@ void CIRCanonicalizePass::runOnOperation() {
 // Many operations are here to perform a manual `fold` in
 // applyOpPatternsGreedily.
 if (isa(op))
+VecExtractOp, VecShuffleOp, VecShuffleDynamicOp, VecSplatOp,
+VecTernaryOp>(op))

AmrDeveloper wrote:

Yes, that makes sense. I will move it to CIRSimplify

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


[clang] [CIR] Upstream ComplexType builtin_complex (PR #144225)

2025-06-17 Thread Amr Hesham via cfe-commits


@@ -49,6 +49,14 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, 
unsigned builtinID,
 }
   }
 
+  switch (builtinID) {
+  case Builtin::BI__builtin_complex: {
+mlir::Value real = emitScalarExpr(e->getArg(0));
+mlir::Value imag = emitScalarExpr(e->getArg(1));
+return RValue::getComplex(real, imag);

AmrDeveloper wrote:

Yes, once #144519 is merged, I will update it

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


[clang] [C++][Modules] A module directive may only appear as the first preprocessing tokens in a file (PR #144233)

2025-06-17 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/144233

>From 7d469c759ffde22d346c079a3bedbd03922e315d Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sun, 15 Jun 2025 01:16:41 +0800
Subject: [PATCH] [C++][Modules][P1857R3 2]: A module directive may only appear
 as the first preprocessing tokens in a file

Signed-off-by: yronglin 
---
 clang/include/clang/Lex/Lexer.h   |   3 +
 clang/include/clang/Lex/Preprocessor.h|  17 ++
 clang/include/clang/Lex/Token.h   |  12 +-
 clang/include/clang/Sema/Sema.h   |   3 +-
 clang/lib/Lex/Lexer.cpp   |  13 ++
 clang/lib/Lex/PPDirectives.cpp|   3 +
 clang/lib/Lex/PPMacroExpansion.cpp|   3 +
 clang/lib/Lex/Preprocessor.cpp|   2 +
 clang/lib/Parse/Parser.cpp|   7 +-
 clang/lib/Sema/SemaModule.cpp |  15 +-
 clang/test/CXX/basic/basic.link/p1.cpp| 143 ++
 clang/test/CXX/basic/basic.link/p2.cpp|  26 +--
 .../basic.scope/basic.scope.namespace/p2.cpp  |  82 ++---
 .../CXX/module/basic/basic.def.odr/p6.cppm| 174 ++
 .../basic/basic.link/module-declaration.cpp   |  64 ---
 clang/test/CXX/module/cpp.pre/module_decl.cpp |   8 +
 .../dcl.module/dcl.module.import/p1.cppm  |  34 +++-
 .../dcl.module/dcl.module.interface/p1.cppm   |  39 ++--
 .../test/CXX/module/dcl.dcl/dcl.module/p1.cpp |  44 +++--
 .../test/CXX/module/dcl.dcl/dcl.module/p5.cpp |  65 +--
 clang/test/CXX/module/module.interface/p2.cpp |  26 ++-
 clang/test/CXX/module/module.unit/p8.cpp  |  48 +++--
 clang/test/Driver/modules.cpp |  31 ++--
 clang/test/Modules/named-modules-adl-3.cppm   |   1 +
 clang/test/Modules/reserved-names-1.cppm  |  10 +
 .../reserved-names-system-header-1.cpp|   1 +
 .../reserved-names-system-header-2.cpp|   1 +
 clang/test/SemaCXX/modules.cppm   |  75 +---
 ...-aware-new-delete-transparent-contexts.cpp |  20 +-
 clang/unittests/Lex/LexerTest.cpp |  47 -
 30 files changed, 713 insertions(+), 304 deletions(-)
 create mode 100644 clang/test/CXX/module/cpp.pre/module_decl.cpp

diff --git a/clang/include/clang/Lex/Lexer.h b/clang/include/clang/Lex/Lexer.h
index bb65ae010cffa..ca812ba1583fb 100644
--- a/clang/include/clang/Lex/Lexer.h
+++ b/clang/include/clang/Lex/Lexer.h
@@ -143,6 +143,9 @@ class Lexer : public PreprocessorLexer {
   /// True if this is the first time we're lexing the input file.
   bool IsFirstTimeLexingFile;
 
+  /// True if current lexing token is the first pp-token.
+  bool IsFirstPPToken;
+
   // NewLinePtr - A pointer to new line character '\n' being lexed. For '\r\n',
   // it also points to '\n.'
   const char *NewLinePtr;
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 78be2bd64d61c..47830b428c8ad 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -350,6 +350,9 @@ class Preprocessor {
   /// Whether the last token we lexed was an '@'.
   bool LastTokenWasAt = false;
 
+  /// First pp-token in current translation unit.
+  std::optional FirstPPToken;
+
   /// A position within a C++20 import-seq.
   class StdCXXImportSeq {
   public:
@@ -1766,6 +1769,20 @@ class Preprocessor {
   std::optional LexEmbedParameters(Token &Current,
  bool ForHasEmbed);
 
+  /// Whether the preprocessor already seen the first pp-token in main file.
+  bool hasSeenMainFileFirstPPToken() const { return FirstPPToken.has_value(); }
+
+  /// Record first pp-token and check if it has a Token::FirstPPToken flag.
+  void HandleMainFileFirstPPToken(const Token &Tok) {
+if (!hasSeenMainFileFirstPPToken() && Tok.isFirstPPToken() &&
+SourceMgr.isWrittenInMainFile(Tok.getLocation()))
+  FirstPPToken = Tok;
+  }
+
+  Token getMainFileFirstPPToken() const {
+assert(FirstPPToken && "First main file pp-token doesn't exists");
+return *FirstPPToken;
+  }
   bool LexAfterModuleImport(Token &Result);
   void CollectPpImportSuffix(SmallVectorImpl &Toks);
 
diff --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h
index 4f29fb7d11415..d4dfd7b44d9af 100644
--- a/clang/include/clang/Lex/Token.h
+++ b/clang/include/clang/Lex/Token.h
@@ -86,9 +86,12 @@ class Token {
 // macro stringizing or charizing operator.
 CommaAfterElided = 0x200, // The comma following this token was elided 
(MS).
 IsEditorPlaceholder = 0x400, // This identifier is a placeholder.
-IsReinjected = 0x800, // A phase 4 token that was produced before and
-  // re-added, e.g. via EnterTokenStream. Annotation
-  // tokens are *not* reinjected.
+
+IsReinjected = 0x800,  // A phase 4 token that was produced before and
+   // re-added

[clang] c66be28 - [clang][bytecode] Allocate IntegralAP and Floating types using an allocator (#144246)

2025-06-17 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-06-17T18:31:06+02:00
New Revision: c66be289901b3f035187d391e80e3610d7d6232e

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

LOG: [clang][bytecode] Allocate IntegralAP and Floating types using an 
allocator (#144246)

Both `APInt` and `APFloat` will heap-allocate memory themselves using
the system allocator when the size of their data exceeds 64 bits.

This is why clang has `APNumericStorage`, which allocates its memory
using an allocator (via `ASTContext`) instead. Calling `getValue()` on
an ast node like that will then create a new `APInt`/`APFloat` , which
will copy the data (in the `APFloat` case, we even copy it twice).
That's sad but whatever.

In the bytecode interpreter, we have a similar problem. Large integers
and floating-point values are placement-new allocated into the
`InterpStack` (or into the bytecode, which is a `vector`).
When we then later interrupt interpretation, we don't run the destructor
for all items on the stack, which means we leak the memory the
`APInt`/`APFloat` (which backs the `IntegralAP`/`Floating` the
interpreter uses).

Fix this by using an approach similar to the one used in the AST. Add an
allocator to `InterpState`, which is used for temporaries and local
values. Those values will be freed at the end of interpretation. For
global variables, we need to promote the values to global lifetime,
which we do via `InitGlobal` and `FinishInitGlobal` ops.

Interestingly, this results in a slight _improvement_ in compile times:
https://llvm-compile-time-tracker.com/compare.php?from=6bfcdda9b1ddf0900f82f7e30cb5e3253a791d50&to=88d1d899127b408f0fb0f385c2c58e6283195049&stat=instructions:u
(but don't ask me why).

Fixes https://github.com/llvm/llvm-project/issues/139012

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Compiler.h
clang/lib/AST/ByteCode/Descriptor.cpp
clang/lib/AST/ByteCode/Disasm.cpp
clang/lib/AST/ByteCode/Floating.h
clang/lib/AST/ByteCode/Integral.h
clang/lib/AST/ByteCode/IntegralAP.h
clang/lib/AST/ByteCode/Interp.cpp
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
clang/lib/AST/ByteCode/InterpState.h
clang/lib/AST/ByteCode/Opcodes.td
clang/lib/AST/ByteCode/PrimType.h
clang/lib/AST/ByteCode/Program.h
clang/test/AST/ByteCode/builtin-bit-cast-long-double.cpp
clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 9fe4803ce98ec..3f884ed8d094a 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -748,7 +748,8 @@ bool Compiler::VisitFloatingLiteral(const 
FloatingLiteral *E) {
   if (DiscardResult)
 return true;
 
-  return this->emitConstFloat(E->getValue(), E);
+  APFloat F = E->getValue();
+  return this->emitFloat(F, E);
 }
 
 template 
@@ -4185,8 +4186,10 @@ bool Compiler::visitZeroInitializer(PrimType T, 
QualType QT,
  nullptr, E);
   case PT_MemberPtr:
 return this->emitNullMemberPtr(0, nullptr, E);
-  case PT_Float:
-return this->emitConstFloat(APFloat::getZero(Ctx.getFloatSemantics(QT)), 
E);
+  case PT_Float: {
+APFloat F = APFloat::getZero(Ctx.getFloatSemantics(QT));
+return this->emitFloat(F, E);
+  }
   case PT_FixedPoint: {
 auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->getType());
 return this->emitConstFixedPoint(FixedPoint::zero(Sem), E);
@@ -4674,10 +4677,7 @@ VarCreationState Compiler::visitVarDecl(const 
VarDecl *VD,
   if (!visitInitializer(Init))
 return false;
 
-  if (!this->emitFinishInit(Init))
-return false;
-
-  return this->emitPopPtr(Init);
+  return this->emitFinishInitGlobal(Init);
 };
 
 DeclScope LocalScope(this, VD);
@@ -4698,51 +4698,45 @@ VarCreationState Compiler::visitVarDecl(const 
VarDecl *VD,
   return false;
 
 return !Init || (checkDecl() && initGlobal(*GlobalIndex));
-  } else {
-InitLinkScope ILS(this, InitLink::Decl(VD));
-
-if (VarT) {
-  unsigned Offset = this->allocateLocalPrimitive(
-  VD, *VarT, VD->getType().isConstQualified(), nullptr,
-  ScopeKind::Block, IsConstexprUnknown);
-  if (Init) {
-// If this is a toplevel declaration, create a scope for the
-// initializer.
-if (Toplevel) {
-  LocalScope Scope(this);
-  if (!this->visit(Init))
-return false;
-  return this->emitSetLocal(*VarT, Offset, VD) && 
Scope.destroyLocals();
-} else {
-  if (!this->visit(Init))
-return false;
-  return this->emitSetLocal(*VarT, Off

[clang] [C++][Modules] A module directive may only appear as the first preprocessing tokens in a file (PR #144233)

2025-06-17 Thread via cfe-commits


@@ -3725,13 +3727,21 @@ bool Lexer::Lex(Token &Result) {
 HasLeadingEmptyMacro = false;
   }
 
+  if (IsFirstPPToken) {
+Result.setFlag(Token::FirstPPToken);
+IsFirstPPToken = false;
+  }
+
   bool atPhysicalStartOfLine = IsAtPhysicalStartOfLine;
   IsAtPhysicalStartOfLine = false;
   bool isRawLex = isLexingRawMode();
   (void) isRawLex;
   bool returnedToken = LexTokenInternal(Result, atPhysicalStartOfLine);
   // (After the LexTokenInternal call, the lexer might be destroyed.)
   assert((returnedToken || !isRawLex) && "Raw lex must succeed");
+
+  if (returnedToken && Result.isFirstPPToken() && PP)
+PP->setFirstPPToken(Result);

yronglin wrote:

Fixed

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


[clang] [Sema][ObjC] Loosen restrictions on reinterpret_cast involving indirect ARC-managed pointers (PR #144458)

2025-06-17 Thread Akira Hatanaka via cfe-commits

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

>From 180213a360c7b25784f84ada7112b30ee0bd1212 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Fri, 13 Jun 2025 15:01:26 -0700
Subject: [PATCH 1/4] [Sema][ObjC] Loosen restrictions on reinterpret_cast
 involving indirect ARC-managed pointers

Allow using reinterpret_cast for conversions between indirect ARC
pointers and other pointer types.

rdar://152905399
---
 clang/include/clang/Sema/SemaObjC.h  |  3 ++-
 clang/lib/Sema/SemaCast.cpp  | 11 +++
 clang/lib/Sema/SemaExprObjC.cpp  | 14 ++
 clang/test/SemaObjCXX/arc-type-conversion.mm | 14 --
 4 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Sema/SemaObjC.h 
b/clang/include/clang/Sema/SemaObjC.h
index b629c6d291402..ed08ff0acf89d 100644
--- a/clang/include/clang/Sema/SemaObjC.h
+++ b/clang/include/clang/Sema/SemaObjC.h
@@ -812,7 +812,8 @@ class SemaObjC : public SemaBase {
   CheckedConversionKind CCK,
   bool Diagnose = true,
   bool DiagnoseCFAudited = false,
-  BinaryOperatorKind Opc = BO_PtrMemD);
+  BinaryOperatorKind Opc = BO_PtrMemD,
+  bool IsReinterpretCast = false);
 
   Expr *stripARCUnbridgedCast(Expr *e);
   void diagnoseARCUnbridgedCast(Expr *e);
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 14e16bc39eb3a..e15a43c116516 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -161,12 +161,14 @@ namespace {
   Self.CheckCastAlign(SrcExpr.get(), DestType, OpRange);
 }
 
-void checkObjCConversion(CheckedConversionKind CCK) {
+void checkObjCConversion(CheckedConversionKind CCK,
+ bool IsReinterpretCast = false) {
   assert(Self.getLangOpts().allowsNonTrivialObjCLifetimeQualifiers());
 
   Expr *src = SrcExpr.get();
-  if (Self.ObjC().CheckObjCConversion(OpRange, DestType, src, CCK) ==
-  SemaObjC::ACR_unbridged)
+  if (Self.ObjC().CheckObjCConversion(
+  OpRange, DestType, src, CCK, true, false, BO_PtrMemD,
+  IsReinterpretCast) == SemaObjC::ACR_unbridged)
 IsARCUnbridgedCast = true;
   SrcExpr = src;
 }
@@ -1263,7 +1265,8 @@ void CastOperation::CheckReinterpretCast() {
 
   if (isValidCast(tcr)) {
 if (Self.getLangOpts().allowsNonTrivialObjCLifetimeQualifiers())
-  checkObjCConversion(CheckedConversionKind::OtherCast);
+  checkObjCConversion(CheckedConversionKind::OtherCast,
+  /*IsReinterpretCast=*/true);
 DiagnoseReinterpretUpDownCast(Self, SrcExpr.get(), DestType, OpRange);
 
 if (unsigned DiagID = checkCastFunctionType(Self, SrcExpr, DestType))
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 3505d9f38d23c..59a2e660364de 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -4390,7 +4390,7 @@ SemaObjC::ARCConversionResult
 SemaObjC::CheckObjCConversion(SourceRange castRange, QualType castType,
   Expr *&castExpr, CheckedConversionKind CCK,
   bool Diagnose, bool DiagnoseCFAudited,
-  BinaryOperatorKind Opc) {
+  BinaryOperatorKind Opc, bool IsReinterpretCast) {
   ASTContext &Context = getASTContext();
   QualType castExprType = castExpr->getType();
 
@@ -4450,13 +4450,19 @@ SemaObjC::CheckObjCConversion(SourceRange castRange, 
QualType castType,
   // must be explicit.
   // Allow conversions between pointers to lifetime types and coreFoundation
   // pointers too, but only when the conversions are explicit.
+  // Allow conversions requested with a reinterpret_cast that converts an
+  // expression of type T* to type U*.
   if (exprACTC == ACTC_indirectRetainable &&
   (castACTC == ACTC_voidPtr ||
-   (castACTC == ACTC_coreFoundation && SemaRef.isCast(CCK
+   (castACTC == ACTC_coreFoundation && SemaRef.isCast(CCK)) ||
+   (IsReinterpretCast && (effCastType->isPointerType() ||
+  effCastType->isObjCObjectPointerType()
 return ACR_okay;
   if (castACTC == ACTC_indirectRetainable &&
-  (exprACTC == ACTC_voidPtr || exprACTC == ACTC_coreFoundation) &&
-  SemaRef.isCast(CCK))
+  (((exprACTC == ACTC_voidPtr || exprACTC == ACTC_coreFoundation) &&
+SemaRef.isCast(CCK)) ||
+   (IsReinterpretCast && (castExprType->isPointerType() ||
+  castExprType->isObjCObjectPointerType()
 return ACR_okay;
 
   switch (ARCCastChecker(Context, exprACTC, castACTC, false).Visit(castExpr)) {
diff --git a/clang/test/SemaObjCXX/arc-type-conversion.mm 
b/

[clang] [clang][bytecode] Allocate IntegralAP and Floating types using an allocator (PR #144246)

2025-06-17 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 closed 
https://github.com/llvm/llvm-project/pull/144246
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Add support for crtbegin.o, crtend.o and libgloss lib to BareMetal toolchain object (PR #121830)

2025-06-17 Thread Garvit Gupta via cfe-commits

https://github.com/quic-garvgupt updated 
https://github.com/llvm/llvm-project/pull/121830

>From c490d1f4f1d1c3a65ad722d46b87fe49ade11c21 Mon Sep 17 00:00:00 2001
From: Garvit Gupta 
Date: Mon, 24 Mar 2025 04:58:57 -0700
Subject: [PATCH] [Driver] Add support for crtbegin.o, crtend.o and libgloss
 lib to BareMetal toolchain object

This patch conditionalise the addition of crt{begin,end}.o object files along
with addition of -lgloss lib based on whether libc selected is newlib or llvm
libc. Since there is no way a user can specify which libc it wants to link
against, currently passing valid GCCInstallation to driver will select newlib
otherwise it will default to llvm libc.

Moreover, this patch makes gnuld the default linker for baremetal toolchain
object. User need to pass `-fuse-ld=lld` explicitly to driver to select lld

This is the 2nd patch in the series of patches of merging RISCVToolchain into
BareMetal toolchain object.

RFC:
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

Change-Id: Ie06dc976c306cf04ec2733bbb2d271c57d201f86
---
 clang/lib/Driver/ToolChains/BareMetal.cpp   | 37 +++-
 clang/lib/Driver/ToolChains/BareMetal.h |  3 +-
 clang/test/Driver/aarch64-toolchain-extra.c | 13 ++-
 clang/test/Driver/aarch64-toolchain.c   | 95 
 clang/test/Driver/arm-toolchain-extra.c |  7 ++
 clang/test/Driver/arm-toolchain.c   | 99 -
 clang/test/Driver/baremetal.cpp |  3 +-
 clang/test/Driver/sanitizer-ld.c|  2 +-
 8 files changed, 246 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 0fbfe6c77f342..a08bb588dd764 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -584,9 +584,31 @@ void baremetal::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
-   options::OPT_r)) {
-CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o")));
+  bool NeedCRTs =
+  !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
+
+  const char *CRTBegin, *CRTEnd;
+  if (NeedCRTs) {
+if (!Args.hasArg(options::OPT_r))
+  CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o")));
+if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) {
+  auto RuntimeLib = TC.GetRuntimeLibType(Args);
+  switch (RuntimeLib) {
+  case (ToolChain::RLT_Libgcc): {
+CRTBegin = "crtbegin.o";
+CRTEnd = "crtend.o";
+break;
+  }
+  case (ToolChain::RLT_CompilerRT): {
+CRTBegin =
+TC.getCompilerRTArgString(Args, "crtbegin", ToolChain::FT_Object);
+CRTEnd =
+TC.getCompilerRTArgString(Args, "crtend", ToolChain::FT_Object);
+break;
+  }
+  }
+  CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTBegin)));
+}
   }
 
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
@@ -609,15 +631,22 @@ void baremetal::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+CmdArgs.push_back("--start-group");
 AddRunTimeLibs(TC, D, CmdArgs, Args);
-
 CmdArgs.push_back("-lc");
+if (TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D))
+  CmdArgs.push_back("-lgloss");
+CmdArgs.push_back("--end-group");
   }
 
   if (D.isUsingLTO())
 addLTOOptions(TC, Args, CmdArgs, Output, Inputs,
   D.getLTOMode() == LTOK_Thin);
 
+  if ((TC.hasValidGCCInstallation() || detectGCCToolchainAdjacent(D)) &&
+  NeedCRTs)
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(CRTEnd)));
+
   if (TC.getTriple().isRISCV())
 CmdArgs.push_back("-X");
 
diff --git a/clang/lib/Driver/ToolChains/BareMetal.h 
b/clang/lib/Driver/ToolChains/BareMetal.h
index 930f8584e6435..54805530bae82 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.h
+++ b/clang/lib/Driver/ToolChains/BareMetal.h
@@ -38,6 +38,7 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF {
 public:
   bool initGCCInstallation(const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
+  bool hasValidGCCInstallation() const { return IsGCCInstallationValid; }
   bool isBareMetal() const override { return true; }
   bool isCrossCompiling() const override { return true; }
   bool HasNativeLLVMSupport() const override { return true; }
@@ -63,8 +64,6 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF {
 return ToolChain::CST_Libcxx;
   }
 
-  const char *getDefaultLinker() const override { return "ld.lld"; }
-
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args) 

[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #121829)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `fuchsia-x86_64-linux` 
running on `fuchsia-debian-64-us-central1-a-1` while building `clang` at step 4 
"annotate".

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


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

```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)
...
[831/1376] Running the Clang regression tests
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using clang: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/clang
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126:
 note: Did not find cir-opt in 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin:/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126:
 note: Did not find clang-repl in 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin:/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/ld.lld
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/lld-link
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/ld64.lld
llvm-lit: 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/wasm-ld
-- Testing: 21688 tests, 60 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 
FAIL: Clang :: Driver/aarch64-toolchain.c (10981 of 21688)
 TEST 'Clang :: Driver/aarch64-toolchain.c' FAILED 

Exit Code: 1

Command Output (stderr):
--
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/clang -### 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/Driver/aarch64-toolchain.c
 -fuse-ld=--target=aarch64-none-elf --rtlib=libgcc
--gcc-toolchain=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/Driver/Inputs/basic_aarch64_gcc_tree

--sysroot=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf
 2>&1| 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/FileCheck 
-check-prefix=C-AARCH64-BAREMETAL 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/Driver/aarch64-toolchain.c
 # RUN: at line 3
+ /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/clang 
-### 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/Driver/aarch64-toolchain.c
 -fuse-ld= --target=aarch64-none-elf --rtlib=libgcc 
--gcc-toolchain=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/Driver/Inputs/basic_aarch64_gcc_tree
 
--sysroot=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf
+ 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/FileCheck 
-check-prefix=C-AARCH64-BAREMETAL 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/clang/test/Driver/aarch64-toolchain.c

--


Testing:  0.. 10.. 20.. 30.. 40.. 
FAIL: Clang :: Driver/aarch64-toolchain-extra.c (10982 of 21688)
 TEST 'Clang :: Driver/aarch64-toolchain-extra.c' FAILED 

Exit Code: 1

Command Output (stderr):
--
rm -rf 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/tools/clang/test/Driver/Output/aarch64-toolchain-extra.c.tmp
 # RUN: at line 14
+ rm -rf 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/tools/clang/test/Driver/Output/aarch64-toolchain-extra.c.tmp
mkdir -p 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/tools/clang/test/Driver/Output/aarch64-toolchain-extra.c.tmp/aarch64-nogcc/bin
 # RUN: at line 15
+ mkdir -p 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/tools/clang/test/Driver/Output/aarch64-toolchain-extra.c.tmp/aarch64-nogcc/bin
ln -s 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/clang 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/tools/clang/test/Driver/Output/aarch64-toolchain-extra.c.tmp/aarch64-nogcc/bin/clang
 # RUN: at line 16
+ ln -s 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-a90hdocr/bin/clang 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-buil

[clang] [C++][Modules] A module directive may only appear as the first preprocessing tokens in a file (PR #144233)

2025-06-17 Thread via cfe-commits

yronglin wrote:

@Bigcheese Could you please help review this approach is correct?

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


[clang] [HLSL] Use ExtVector for firstbit intrinsics (PR #142679)

2025-06-17 Thread Sarah Spall via cfe-commits

https://github.com/spall commented:

I don't fully understand this but lgtm I guess.

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


[clang] 0f8c721 - [C++20][Modules] Disable preferred_name when writing a C++20 header unit (#144377)

2025-06-17 Thread via cfe-commits

Author: Dmitry Polukhin
Date: 2025-06-17T09:45:18+01:00
New Revision: 0f8c72160ec001599ecb29f0fa182c5550f5dd0a

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

LOG: [C++20][Modules] Disable preferred_name when writing a C++20 header unit 
(#144377)

https://reviews.llvm.org/D130331 added workaround for named modules
only. But the same issue happens for headees units. Link issue #56490

Added: 
clang/test/Modules/preferred_name_header_unit.cpp

Modified: 
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index cf4ae610ea51f..0f49646f3f022 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -899,6 +899,10 @@ class ASTWriter : public ASTDeserializationListener,
 return WritingModule && WritingModule->isNamedModule();
   }
 
+  bool isWritingStdCXXHeaderUnit() const {
+return WritingModule && WritingModule->isHeaderUnit();
+  }
+
   bool isGeneratingReducedBMI() const { return GeneratingReducedBMI; }
 
   bool getDoneWritingDeclsAndTypes() const { return DoneWritingDeclsAndTypes; }

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index ab1b5b333e06a..be22ee5221911 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5167,8 +5167,9 @@ void ASTRecordWriter::AddAttr(const Attr *A) {
   // FIXME: Clang can't handle the serialization/deserialization of
   // preferred_name properly now. See
   // https://github.com/llvm/llvm-project/issues/56490 for example.
-  if (!A || (isa(A) &&
- Writer->isWritingStdCXXNamedModules()))
+  if (!A ||
+  (isa(A) && (Writer->isWritingStdCXXNamedModules() ||
+ Writer->isWritingStdCXXHeaderUnit(
 return Record.push_back(0);
 
   Record.push_back(A->getKind() + 1); // FIXME: stable encoding, target attrs

diff  --git a/clang/test/Modules/preferred_name_header_unit.cpp 
b/clang/test/Modules/preferred_name_header_unit.cpp
new file mode 100644
index 0..b1f1e3579f31e
--- /dev/null
+++ b/clang/test/Modules/preferred_name_header_unit.cpp
@@ -0,0 +1,64 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -verify -w -std=c++20 -fmodule-name=h1.h -emit-header-unit 
-xc++-user-header h1.h -o h1.pcm
+// RUN: %clang_cc1 -verify -w -std=c++20 -fmodule-map-file=module.modulemap 
-fmodule-file=h1.h=h1.pcm main.cpp -o main.o
+
+//--- module.modulemap
+module "h1.h" {
+  header "h1.h"
+  export *
+}
+
+//--- h0.h
+// expected-no-diagnostics
+#pragma once
+namespace std {
+
+template  class basic_string;
+
+namespace pmr {
+using string = basic_string;
+}
+
+template 
+class __attribute__((__preferred_name__(pmr::string))) basic_string;
+
+template  class basic_string_view {};
+
+template  class basic_string {
+  typedef _CharT value_type;
+  typedef _Allocator allocator_type;
+  struct __rep;
+public:
+  template 
+  basic_string(_Tp) {}
+  basic_string operator+=(value_type);
+};
+
+namespace filesystem {
+class path {
+  typedef char value_type;
+  value_type preferred_separator;
+  typedef basic_string string_type;
+  typedef basic_string_view __string_view;
+  template  void append(_Source) {
+__pn_ += preferred_separator;
+  }
+  void __root_directory() { append(string_type(__string_view{})); }
+  string_type __pn_;
+};
+} // namespace filesystem
+} // namespace std
+
+//--- h1.h
+// expected-no-diagnostics
+#pragma once
+
+#include "h0.h"
+
+//--- main.cpp
+// expected-no-diagnostics
+#include "h0.h"
+
+import "h1.h";



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


[clang-tools-extra] 26d082d - [clang-tidy][performance-unnecessary-value-param] Avoid in coroutines (#140912)

2025-06-17 Thread via cfe-commits

Author: Dmitry Polukhin
Date: 2025-06-17T09:47:15+01:00
New Revision: 26d082d330e4d8d1fc3194b4b87ede9332a297f5

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

LOG: [clang-tidy][performance-unnecessary-value-param] Avoid in coroutines 
(#140912)

Summary:
Replacing by-value parameters with passing by-reference is not safe for
coroutines because the caller may be executed in parallel with the
callee, which increases the chances of resulting in dangling references
and hard-to-find crashes. See for the reference
[cppcoreguidelines-avoid-reference-coroutine-parameters](https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.html).

Test Plan: check-clang-tools

Added: 

clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-coroutine.cpp

Modified: 
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-value-param.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
index a877f9a7ee912..d89c3a69fc841 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -50,7 +50,8 @@ UnnecessaryValueParamCheck::UnnecessaryValueParamCheck(
 utils::IncludeSorter::IS_LLVM),
areDiagsSelfContained()),
   AllowedTypes(
-  utils::options::parseStringList(Options.get("AllowedTypes", ""))) {}
+  utils::options::parseStringList(Options.get("AllowedTypes", ""))),
+  IgnoreCoroutines(Options.get("IgnoreCoroutines", true)) {}
 
 void UnnecessaryValueParamCheck::registerMatchers(MatchFinder *Finder) {
   const auto ExpensiveValueParamDecl = parmVarDecl(
@@ -61,12 +62,14 @@ void 
UnnecessaryValueParamCheck::registerMatchers(MatchFinder *Finder) {
matchers::matchesAnyListedName(AllowedTypes))),
   decl().bind("param"));
   Finder->addMatcher(
-  traverse(
-  TK_AsIs,
-  functionDecl(hasBody(stmt()), isDefinition(), unless(isImplicit()),
-   unless(cxxMethodDecl(anyOf(isOverride(), isFinal(,
-   has(typeLoc(forEach(ExpensiveValueParamDecl))),
-   decl().bind("functionDecl"))),
+  traverse(TK_AsIs,
+   functionDecl(
+   hasBody(IgnoreCoroutines ? stmt(unless(coroutineBodyStmt()))
+: stmt()),
+   isDefinition(), unless(isImplicit()),
+   unless(cxxMethodDecl(anyOf(isOverride(), isFinal(,
+   has(typeLoc(forEach(ExpensiveValueParamDecl))),
+   decl().bind("functionDecl"))),
   this);
 }
 
@@ -123,6 +126,7 @@ void UnnecessaryValueParamCheck::storeOptions(
   Options.store(Opts, "IncludeStyle", Inserter.getStyle());
   Options.store(Opts, "AllowedTypes",
 utils::options::serializeStringList(AllowedTypes));
+  Options.store(Opts, "IgnoreCoroutines", IgnoreCoroutines);
 }
 
 void UnnecessaryValueParamCheck::onEndOfTranslationUnit() {

diff  --git 
a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h 
b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
index 8bfd814d16357..b52043416e769 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.h
@@ -46,6 +46,7 @@ class UnnecessaryValueParamCheck : public ClangTidyCheck {
   ExprMutationAnalyzer::Memoized MutationAnalyzerCache;
   utils::IncludeInserter Inserter;
   const std::vector AllowedTypes;
+  bool IgnoreCoroutines;
 };
 
 } // namespace clang::tidy::performance

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19ccd1790e757..3c1ca2f929044 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -265,6 +265,8 @@ Changes in existing checks
   ` check performance by
   tolerating fix-it breaking compilation when functions is used as pointers
   to avoid matching usage of functions within the current compilation unit.
+  Added an option `IgnoreCoroutines` with the default value `true` to
+  suppress this check for coroutines where passing by reference may be unsafe.
 
 - Improved :doc:`readability-convert-member-functions-to-static
   ` check by

diff  --git 
a/clang-tools

[clang] e2551c1 - [analyzer] Fix a false memory leak reports involving placement new (#144341)

2025-06-17 Thread via cfe-commits

Author: Arseniy Zaostrovnykh
Date: 2025-06-17T10:31:38+02:00
New Revision: e2551c14d0d9180ccaef9d33c524d83e7813a361

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

LOG: [analyzer] Fix a false memory leak reports involving placement new 
(#144341)

Placement new does not allocate memory, so it should not be reported as
a memory leak. A recent MallocChecker refactor changed inlining of
placement-new calls with manual evaluation by MallocChecker.
https://github.com/llvm/llvm-project/commit/339282d49f5310a2837da45c0ccc19da15675554

This change avoids marking the value returned by placement new as
allocated and hence avoids the false leak reports.

Note that the there are two syntaxes to invoke placement new:
`new (p) int` and an explicit operator call `operator new(sizeof(int), p)`.
The first syntax was already properly handled by the engine.
This change corrects handling of the second syntax.

CPP-6375

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/test/Analysis/NewDelete-checker-test.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index fef33509c0b6e..35e98a5e2719a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1371,6 +1371,20 @@ void MallocChecker::checkIfFreeNameIndex(ProgramStateRef 
State,
   C.addTransition(State);
 }
 
+const Expr *getPlacementNewBufferArg(const CallExpr *CE,
+ const FunctionDecl *FD) {
+  // Checking for signature:
+  // void* operator new  ( std::size_t count, void* ptr );
+  // void* operator new[]( std::size_t count, void* ptr );
+  if (CE->getNumArgs() != 2 || (FD->getOverloadedOperator() != OO_New &&
+FD->getOverloadedOperator() != OO_Array_New))
+return nullptr;
+  auto BuffType = FD->getParamDecl(1)->getType();
+  if (BuffType.isNull() || !BuffType->isVoidPointerType())
+return nullptr;
+  return CE->getArg(1);
+}
+
 void MallocChecker::checkCXXNewOrCXXDelete(ProgramStateRef State,
const CallEvent &Call,
CheckerContext &C) const {
@@ -1386,6 +1400,14 @@ void 
MallocChecker::checkCXXNewOrCXXDelete(ProgramStateRef State,
   // processed by the checkPostStmt callbacks for CXXNewExpr and
   // CXXDeleteExpr.
   const FunctionDecl *FD = C.getCalleeDecl(CE);
+  if (const auto *BufArg = getPlacementNewBufferArg(CE, FD)) {
+// Placement new does not allocate memory
+auto RetVal = State->getSVal(BufArg, Call.getLocationContext());
+State = State->BindExpr(CE, C.getLocationContext(), RetVal);
+C.addTransition(State);
+return;
+  }
+
   switch (FD->getOverloadedOperator()) {
   case OO_New:
 State = MallocMemAux(C, Call, CE->getArg(0), UndefinedVal(), State,

diff  --git a/clang/test/Analysis/NewDelete-checker-test.cpp 
b/clang/test/Analysis/NewDelete-checker-test.cpp
index 06754f669b1e6..da0eef7c52bd8 100644
--- a/clang/test/Analysis/NewDelete-checker-test.cpp
+++ b/clang/test/Analysis/NewDelete-checker-test.cpp
@@ -26,9 +26,10 @@
 // RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
 //
 // RUN: %clang_analyze_cc1 -std=c++17 -fblocks -verify %s \
-// RUN:   -verify=expected,leak \
+// RUN:   -verify=expected,leak,inspection \
 // RUN:   -analyzer-checker=core \
-// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks
+// RUN:   -analyzer-checker=cplusplus.NewDeleteLeaks \
+// RUN:   -analyzer-checker=debug.ExprInspection
 
 #include "Inputs/system-header-simulator-cxx.h"
 
@@ -63,6 +64,39 @@ void testGlobalNoThrowPlacementExprNewBeforeOverload() {
   int *p = new(std::nothrow) int;
 } // leak-warning{{Potential leak of memory pointed to by 'p'}}
 
+//- Standard pointer placement operators
+void testGlobalPointerPlacementNew() {
+  int i;
+  void *p1 = operator new(0, &i); // no leak: placement new never allocates
+  void *p2 = operator new[](0, &i); // no leak
+  int *p3 = new(&i) int; // no leak
+  int *p4 = new(&i) int[0]; // no leak
+}
+
+template
+void clang_analyzer_dump(T x);
+
+void testPlacementNewBufValue() {
+  int i = 10;
+  int *p = new(&i) int;
+  clang_analyzer_dump(p); // inspection-warning{{&i}}
+  clang_analyzer_dump(*p); // inspection-warning{{10}}
+}
+
+void testPlacementNewBufValueExplicitOp() {
+  int i = 10;
+  int *p = (int*)operator new(sizeof(int), &i);
+  clang_analyzer_dump(p); // inspection-warning{{&i}}
+  clang_analyzer_dump(*p); // inspection-warning{{10}}
+}
+
+void testPlacementArrNewBufValueExplicitArrOp() {
+  int i = 10;
+  int *p = (int*)operator new[](sizeof(int), &i);
+  clang_analyzer_dump(p); // inspection-warning{{&i}}
+  cl

[clang] [CIR] Add support for __builtin_assume (PR #144376)

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

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


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


[clang] Inject compilation command into __cli_ global variable (PR #144622)

2025-06-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (Pavithra029)


Changes



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


1 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+100) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c005d3322ed7a..577cb6f0abd2c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1472,6 +1472,106 @@ void CodeGenModule::Release() {
   }
 }
   }
+  
+  // 1. Get source file name
+  /*  std::string FileName = getModule().getSourceFileName(); // like "foo.c"
+llvm::StringRef BaseName = llvm::sys::path::filename(FileName);
+
+// 2. Create variable name like __cli_foo_c
+std::string VarName = "__cli_" + BaseName.str();
+std::replace(VarName.begin(), VarName.end(), '.', '_');
+
+// 3. Get the compilation command line from options
+std::string CmdLineStr;
+for (const std::string &Arg : CodeGenOpts.CommandLineArgs) {
+CmdLineStr += Arg + " ";
+}
+
+// 4. Create LLVM IR string global
+llvm::Constant *CmdStr = 
llvm::ConstantDataArray::getString(getLLVMContext(), CmdLineStr, true);
+// 1. Prepare internal string global variable
+auto *GV = new llvm::GlobalVariable(
+getModule(),
+CmdStr->getType(),
+true,
+llvm::GlobalValue::InternalLinkage,
+CmdStr,
+VarName + ".data"
+);
+GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
+// 2. Create external pointer global pointing to internal string
+llvm::Constant *Zero = 
llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 0);
+llvm::Constant *Indices[] = {Zero, Zero};
+llvm::Constant *PtrToStr = 
llvm::ConstantExpr::getGetElementPtr(CmdStr->getType(), GV, Indices);
+
+auto *ExternGV = new llvm::GlobalVariable(
+getModule(),
+PtrToStr->getType(),
+true,
+llvm::GlobalValue::ExternalLinkage,
+PtrToStr,
+VarName
+);
+ExternGV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+(void)ExternGV;
+llvm::errs() << "✅ Emitting __cli global variable!\n";
+
+  */
+  
+  // === BEGIN: Emit global __cli_ variable ===
+
+std::string FileName = getModule().getSourceFileName();
+llvm::StringRef BaseName = llvm::sys::path::filename(FileName);
+std::string VarName = "__cli_" + BaseName.str();
+std::replace(VarName.begin(), VarName.end(), '.', '_');
+
+// Join command line args into one string
+std::string CmdLineStr;
+for (const std::string &Arg : CodeGenOpts.CommandLineArgs) {
+CmdLineStr += Arg + " ";
+}
+
+// Step 1: Create string constant (char[] data)
+llvm::Constant *CmdStr = llvm::ConstantDataArray::getString(getLLVMContext(), 
CmdLineStr, true);
+
+// Step 2: Emit internal variable: @__cli_foo_c.data
+auto *DataGV = new llvm::GlobalVariable(
+getModule(),
+CmdStr->getType(), // [N x i8]
+true, // constant
+llvm::GlobalValue::InternalLinkage,
+CmdStr,
+VarName + ".data"
+);
+DataGV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
+
+// Step 3: Pointer to string
+llvm::Constant *PtrToStr = llvm::ConstantExpr::getPointerCast(
+DataGV, 
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(getLLVMContext()))
+);
+
+
+// Step 4: Remove dummy external if exists
+if (auto *Old = getModule().getNamedGlobal(VarName)) {
+Old->eraseFromParent();
+}
+
+// ✅ Step 5: Emit the real global variable
+auto *FinalGV = new llvm::GlobalVariable(
+getModule(),
+PtrToStr->getType(),   // i8*
+true, // constant
+llvm::GlobalValue::ExternalLinkage,   // important: this makes it 
visible!
+PtrToStr,
+VarName
+);
+//FinalGV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
+
+llvm::errs() << "✅ Emitting " << VarName << " global variable!\n";
+
+// === END ===
+
 }
 
 void CodeGenModule::EmitOpenCLMetadata() {

``




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


[clang] Inject compilation command into __cli_ global variable (PR #144622)

2025-06-17 Thread via cfe-commits

https://github.com/Pavithra029 created 
https://github.com/llvm/llvm-project/pull/144622

None

>From d41ac68039e6d654249fbeceb3b77c4b6780f9c0 Mon Sep 17 00:00:00 2001
From: pavithra 
Date: Wed, 18 Jun 2025 05:50:13 +0530
Subject: [PATCH] Inject compilation command into __cli_ global variable

---
 clang/lib/CodeGen/CodeGenModule.cpp | 100 
 1 file changed, 100 insertions(+)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c005d3322ed7a..577cb6f0abd2c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1472,6 +1472,106 @@ void CodeGenModule::Release() {
   }
 }
   }
+  
+  // 1. Get source file name
+  /*  std::string FileName = getModule().getSourceFileName(); // like "foo.c"
+llvm::StringRef BaseName = llvm::sys::path::filename(FileName);
+
+// 2. Create variable name like __cli_foo_c
+std::string VarName = "__cli_" + BaseName.str();
+std::replace(VarName.begin(), VarName.end(), '.', '_');
+
+// 3. Get the compilation command line from options
+std::string CmdLineStr;
+for (const std::string &Arg : CodeGenOpts.CommandLineArgs) {
+CmdLineStr += Arg + " ";
+}
+
+// 4. Create LLVM IR string global
+llvm::Constant *CmdStr = 
llvm::ConstantDataArray::getString(getLLVMContext(), CmdLineStr, true);
+// 1. Prepare internal string global variable
+auto *GV = new llvm::GlobalVariable(
+getModule(),
+CmdStr->getType(),
+true,
+llvm::GlobalValue::InternalLinkage,
+CmdStr,
+VarName + ".data"
+);
+GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
+// 2. Create external pointer global pointing to internal string
+llvm::Constant *Zero = 
llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 0);
+llvm::Constant *Indices[] = {Zero, Zero};
+llvm::Constant *PtrToStr = 
llvm::ConstantExpr::getGetElementPtr(CmdStr->getType(), GV, Indices);
+
+auto *ExternGV = new llvm::GlobalVariable(
+getModule(),
+PtrToStr->getType(),
+true,
+llvm::GlobalValue::ExternalLinkage,
+PtrToStr,
+VarName
+);
+ExternGV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+(void)ExternGV;
+llvm::errs() << "✅ Emitting __cli global variable!\n";
+
+  */
+  
+  // === BEGIN: Emit global __cli_ variable ===
+
+std::string FileName = getModule().getSourceFileName();
+llvm::StringRef BaseName = llvm::sys::path::filename(FileName);
+std::string VarName = "__cli_" + BaseName.str();
+std::replace(VarName.begin(), VarName.end(), '.', '_');
+
+// Join command line args into one string
+std::string CmdLineStr;
+for (const std::string &Arg : CodeGenOpts.CommandLineArgs) {
+CmdLineStr += Arg + " ";
+}
+
+// Step 1: Create string constant (char[] data)
+llvm::Constant *CmdStr = llvm::ConstantDataArray::getString(getLLVMContext(), 
CmdLineStr, true);
+
+// Step 2: Emit internal variable: @__cli_foo_c.data
+auto *DataGV = new llvm::GlobalVariable(
+getModule(),
+CmdStr->getType(), // [N x i8]
+true, // constant
+llvm::GlobalValue::InternalLinkage,
+CmdStr,
+VarName + ".data"
+);
+DataGV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
+
+// Step 3: Pointer to string
+llvm::Constant *PtrToStr = llvm::ConstantExpr::getPointerCast(
+DataGV, 
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(getLLVMContext()))
+);
+
+
+// Step 4: Remove dummy external if exists
+if (auto *Old = getModule().getNamedGlobal(VarName)) {
+Old->eraseFromParent();
+}
+
+// ✅ Step 5: Emit the real global variable
+auto *FinalGV = new llvm::GlobalVariable(
+getModule(),
+PtrToStr->getType(),   // i8*
+true, // constant
+llvm::GlobalValue::ExternalLinkage,   // important: this makes it 
visible!
+PtrToStr,
+VarName
+);
+//FinalGV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
+
+llvm::errs() << "✅ Emitting " << VarName << " global variable!\n";
+
+// === END ===
+
 }
 
 void CodeGenModule::EmitOpenCLMetadata() {

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


[clang] Inject compilation command into __cli_ global variable (PR #144622)

2025-06-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Pavithra029)


Changes



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


1 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+100) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c005d3322ed7a..577cb6f0abd2c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1472,6 +1472,106 @@ void CodeGenModule::Release() {
   }
 }
   }
+  
+  // 1. Get source file name
+  /*  std::string FileName = getModule().getSourceFileName(); // like "foo.c"
+llvm::StringRef BaseName = llvm::sys::path::filename(FileName);
+
+// 2. Create variable name like __cli_foo_c
+std::string VarName = "__cli_" + BaseName.str();
+std::replace(VarName.begin(), VarName.end(), '.', '_');
+
+// 3. Get the compilation command line from options
+std::string CmdLineStr;
+for (const std::string &Arg : CodeGenOpts.CommandLineArgs) {
+CmdLineStr += Arg + " ";
+}
+
+// 4. Create LLVM IR string global
+llvm::Constant *CmdStr = 
llvm::ConstantDataArray::getString(getLLVMContext(), CmdLineStr, true);
+// 1. Prepare internal string global variable
+auto *GV = new llvm::GlobalVariable(
+getModule(),
+CmdStr->getType(),
+true,
+llvm::GlobalValue::InternalLinkage,
+CmdStr,
+VarName + ".data"
+);
+GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+
+// 2. Create external pointer global pointing to internal string
+llvm::Constant *Zero = 
llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 0);
+llvm::Constant *Indices[] = {Zero, Zero};
+llvm::Constant *PtrToStr = 
llvm::ConstantExpr::getGetElementPtr(CmdStr->getType(), GV, Indices);
+
+auto *ExternGV = new llvm::GlobalVariable(
+getModule(),
+PtrToStr->getType(),
+true,
+llvm::GlobalValue::ExternalLinkage,
+PtrToStr,
+VarName
+);
+ExternGV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+(void)ExternGV;
+llvm::errs() << "✅ Emitting __cli global variable!\n";
+
+  */
+  
+  // === BEGIN: Emit global __cli_ variable ===
+
+std::string FileName = getModule().getSourceFileName();
+llvm::StringRef BaseName = llvm::sys::path::filename(FileName);
+std::string VarName = "__cli_" + BaseName.str();
+std::replace(VarName.begin(), VarName.end(), '.', '_');
+
+// Join command line args into one string
+std::string CmdLineStr;
+for (const std::string &Arg : CodeGenOpts.CommandLineArgs) {
+CmdLineStr += Arg + " ";
+}
+
+// Step 1: Create string constant (char[] data)
+llvm::Constant *CmdStr = llvm::ConstantDataArray::getString(getLLVMContext(), 
CmdLineStr, true);
+
+// Step 2: Emit internal variable: @__cli_foo_c.data
+auto *DataGV = new llvm::GlobalVariable(
+getModule(),
+CmdStr->getType(), // [N x i8]
+true, // constant
+llvm::GlobalValue::InternalLinkage,
+CmdStr,
+VarName + ".data"
+);
+DataGV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
+
+// Step 3: Pointer to string
+llvm::Constant *PtrToStr = llvm::ConstantExpr::getPointerCast(
+DataGV, 
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(getLLVMContext()))
+);
+
+
+// Step 4: Remove dummy external if exists
+if (auto *Old = getModule().getNamedGlobal(VarName)) {
+Old->eraseFromParent();
+}
+
+// ✅ Step 5: Emit the real global variable
+auto *FinalGV = new llvm::GlobalVariable(
+getModule(),
+PtrToStr->getType(),   // i8*
+true, // constant
+llvm::GlobalValue::ExternalLinkage,   // important: this makes it 
visible!
+PtrToStr,
+VarName
+);
+//FinalGV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
+
+llvm::errs() << "✅ Emitting " << VarName << " global variable!\n";
+
+// === END ===
+
 }
 
 void CodeGenModule::EmitOpenCLMetadata() {

``




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


[clang] Inject compilation command into __cli_ global variable (PR #144622)

2025-06-17 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [Sema][ObjC] Loosen restrictions on reinterpret_cast involving indirect ARC-managed pointers (PR #144458)

2025-06-17 Thread Akira Hatanaka via cfe-commits

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

>From 180213a360c7b25784f84ada7112b30ee0bd1212 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Fri, 13 Jun 2025 15:01:26 -0700
Subject: [PATCH 1/5] [Sema][ObjC] Loosen restrictions on reinterpret_cast
 involving indirect ARC-managed pointers

Allow using reinterpret_cast for conversions between indirect ARC
pointers and other pointer types.

rdar://152905399
---
 clang/include/clang/Sema/SemaObjC.h  |  3 ++-
 clang/lib/Sema/SemaCast.cpp  | 11 +++
 clang/lib/Sema/SemaExprObjC.cpp  | 14 ++
 clang/test/SemaObjCXX/arc-type-conversion.mm | 14 --
 4 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Sema/SemaObjC.h 
b/clang/include/clang/Sema/SemaObjC.h
index b629c6d291402..ed08ff0acf89d 100644
--- a/clang/include/clang/Sema/SemaObjC.h
+++ b/clang/include/clang/Sema/SemaObjC.h
@@ -812,7 +812,8 @@ class SemaObjC : public SemaBase {
   CheckedConversionKind CCK,
   bool Diagnose = true,
   bool DiagnoseCFAudited = false,
-  BinaryOperatorKind Opc = BO_PtrMemD);
+  BinaryOperatorKind Opc = BO_PtrMemD,
+  bool IsReinterpretCast = false);
 
   Expr *stripARCUnbridgedCast(Expr *e);
   void diagnoseARCUnbridgedCast(Expr *e);
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 14e16bc39eb3a..e15a43c116516 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -161,12 +161,14 @@ namespace {
   Self.CheckCastAlign(SrcExpr.get(), DestType, OpRange);
 }
 
-void checkObjCConversion(CheckedConversionKind CCK) {
+void checkObjCConversion(CheckedConversionKind CCK,
+ bool IsReinterpretCast = false) {
   assert(Self.getLangOpts().allowsNonTrivialObjCLifetimeQualifiers());
 
   Expr *src = SrcExpr.get();
-  if (Self.ObjC().CheckObjCConversion(OpRange, DestType, src, CCK) ==
-  SemaObjC::ACR_unbridged)
+  if (Self.ObjC().CheckObjCConversion(
+  OpRange, DestType, src, CCK, true, false, BO_PtrMemD,
+  IsReinterpretCast) == SemaObjC::ACR_unbridged)
 IsARCUnbridgedCast = true;
   SrcExpr = src;
 }
@@ -1263,7 +1265,8 @@ void CastOperation::CheckReinterpretCast() {
 
   if (isValidCast(tcr)) {
 if (Self.getLangOpts().allowsNonTrivialObjCLifetimeQualifiers())
-  checkObjCConversion(CheckedConversionKind::OtherCast);
+  checkObjCConversion(CheckedConversionKind::OtherCast,
+  /*IsReinterpretCast=*/true);
 DiagnoseReinterpretUpDownCast(Self, SrcExpr.get(), DestType, OpRange);
 
 if (unsigned DiagID = checkCastFunctionType(Self, SrcExpr, DestType))
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 3505d9f38d23c..59a2e660364de 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -4390,7 +4390,7 @@ SemaObjC::ARCConversionResult
 SemaObjC::CheckObjCConversion(SourceRange castRange, QualType castType,
   Expr *&castExpr, CheckedConversionKind CCK,
   bool Diagnose, bool DiagnoseCFAudited,
-  BinaryOperatorKind Opc) {
+  BinaryOperatorKind Opc, bool IsReinterpretCast) {
   ASTContext &Context = getASTContext();
   QualType castExprType = castExpr->getType();
 
@@ -4450,13 +4450,19 @@ SemaObjC::CheckObjCConversion(SourceRange castRange, 
QualType castType,
   // must be explicit.
   // Allow conversions between pointers to lifetime types and coreFoundation
   // pointers too, but only when the conversions are explicit.
+  // Allow conversions requested with a reinterpret_cast that converts an
+  // expression of type T* to type U*.
   if (exprACTC == ACTC_indirectRetainable &&
   (castACTC == ACTC_voidPtr ||
-   (castACTC == ACTC_coreFoundation && SemaRef.isCast(CCK
+   (castACTC == ACTC_coreFoundation && SemaRef.isCast(CCK)) ||
+   (IsReinterpretCast && (effCastType->isPointerType() ||
+  effCastType->isObjCObjectPointerType()
 return ACR_okay;
   if (castACTC == ACTC_indirectRetainable &&
-  (exprACTC == ACTC_voidPtr || exprACTC == ACTC_coreFoundation) &&
-  SemaRef.isCast(CCK))
+  (((exprACTC == ACTC_voidPtr || exprACTC == ACTC_coreFoundation) &&
+SemaRef.isCast(CCK)) ||
+   (IsReinterpretCast && (castExprType->isPointerType() ||
+  castExprType->isObjCObjectPointerType()
 return ACR_okay;
 
   switch (ARCCastChecker(Context, exprACTC, castACTC, false).Visit(castExpr)) {
diff --git a/clang/test/SemaObjCXX/arc-type-conversion.mm 
b/

[clang] [llvm] Add support for Windows Secure Hot-Patching (PR #138972)

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


@@ -0,0 +1,21 @@
+// This verifies that hotpatch function attributes are correctly propagated 
when compiling directly to OBJ.
+//
+// RUN: echo this_gets_hotpatched > %t.patch-functions.txt
+// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /Z7 
-fms-secure-hotpatch-functions-file=%t.patch-functions.txt /Fo%t.obj %s
+// RUN: llvm-readobj --codeview %t.obj | FileCheck %s

efriedma-quic wrote:

This test requires the x86 backend; please move the tests to 
clang/test/CodeGen/X86/ .

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


[clang] [llvm] Add support for Windows Secure Hot-Patching (PR #138972)

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


@@ -0,0 +1,38 @@
+; This tests directly annotating a function with 
marked_for_windows_hot_patching.
+;
+; RUN: llc -mtriple=x86_64-windows < %s | FileCheck %s

efriedma-quic wrote:

If you put the tests in test/CodeGen/Generic, the test runner will try to run 
them even if the x86 backend isn't built.  Please move the tests to 
test/CodeGen/X86.  (Alternatively, you could add a REQUIRES line, but that 
doesn't seem appropriate here.)

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


[clang] [llvm] Add support for Windows Secure Hot-Patching (PR #138972)

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


@@ -389,6 +389,17 @@ def CoroDestroyOnlyWhenComplete : 
EnumAttr<"coro_only_destroy_when_complete", In
 /// pipeline to perform elide on the call or invoke instruction.
 def CoroElideSafe : EnumAttr<"coro_elide_safe", IntersectPreserve, [FnAttr]>;
 
+/// Function is marked for Windows Hot Patching
+def MarkedForWindowsSecureHotPatching
+: EnumAttr<"marked_for_windows_hot_patching", IntersectPreserve, [FnAttr]>;
+
+/// Global variable should not be accessed through a "__ref_" global variable 
in
+/// a hot patching function This attribute is applied to the global variable
+/// decl, not the hotpatched function.
+def AllowDirectAccessInHotPatchFunction
+: EnumAttr<"allow_direct_access_in_hot_patch_function",
+   IntersectPreserve, [FnAttr]>;

efriedma-quic wrote:

Do we really need to allocate enum values for this?  Would a string attribute 
be sufficient?  The primary benefit of using EnumAttr over StrBoolAttr is that 
it's a bit faster to query... but we store the attributes as a bit array, so 
it's taking up space for everyone.

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


[clang] [llvm] Add support for Windows Secure Hot-Patching (PR #138972)

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

efriedma-quic wrote:

For the constant expression handling stuff, I think you have the basic 
framework working correctly; if we run into additional issues, I'm happy to 
leave handling them for followups.

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


[clang] abbdd16 - [llvm] minor fixes for clang-cl Windows DLL build (#144386)

2025-06-17 Thread via cfe-commits

Author: Andrew Rogers
Date: 2025-06-17T17:21:40-07:00
New Revision: abbdd1670d8b12dd72ec353b14e256619ff4694b

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

LOG: [llvm] minor fixes for clang-cl Windows DLL build (#144386)

## Purpose

This patch makes a minor changes to LLVM and Clang so that LLVM can be
built as a Windows DLL with `clang-cl`. These changes were not required
for building a Windows DLL with MSVC.

## Background

The Windows DLL effort is tracked in #109483. Additional context is
provided in [this
discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307),
and documentation for `LLVM_ABI` and related annotations is found in the
LLVM repo
[here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst).

## Overview
Specific changes made in this patch:
- Remove `constexpr` fields that reference DLL exported symbols. These
symbols cannot be resolved at compile time when building a Windows DLL
using `clang-cl`, so they cannot be `constexpr`. Instead, they are made
`const` and initialized in the implementation file rather than at
declaration in the header.
- Annotate symbols now defined out-of-line with `LLVM_ABI` so they are
exported when building as a shared library.
- Explicitly add default copy assignment operator for `ELFFile` to
resolve a compiler warning.

## Validation

Local builds and tests to validate cross-platform compatibility. This
included llvm, clang, and lldb on the following configurations:

- Windows with MSVC
- Windows with Clang
- Linux with GCC
- Linux with Clang
- Darwin with Clang

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
llvm/include/llvm/BinaryFormat/Dwarf.h
llvm/include/llvm/Object/ELF.h
llvm/lib/BinaryFormat/Dwarf.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp 
b/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
index 836fc375809ad..f965bfb590d80 100644
--- a/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
+++ b/clang/lib/StaticAnalyzer/Core/Z3CrosscheckVisitor.cpp
@@ -92,7 +92,7 @@ void Z3CrosscheckVisitor::finalizeVisitor(BugReporterContext 
&BRC,
   };
 
   auto AttemptOnce = [&](const llvm::SMTSolverRef &Solver) -> Z3Result {
-constexpr auto getCurrentTime = llvm::TimeRecord::getCurrentTime;
+auto getCurrentTime = llvm::TimeRecord::getCurrentTime;
 unsigned InitialRLimit = GetUsedRLimit(Solver);
 double Start = getCurrentTime(/*Start=*/true).getWallTime();
 std::optional IsSAT = Solver->check();

diff  --git a/llvm/include/llvm/BinaryFormat/Dwarf.h 
b/llvm/include/llvm/BinaryFormat/Dwarf.h
index 2ead62025efa7..231b7ac17d75f 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -1191,32 +1191,32 @@ template  struct EnumTraits : public 
std::false_type {};
 
 template <> struct EnumTraits : public std::true_type {
   static constexpr char Type[3] = "AT";
-  static constexpr StringRef (*StringFn)(unsigned) = &AttributeString;
+  LLVM_ABI static StringRef (*const StringFn)(unsigned);
 };
 
 template <> struct EnumTraits : public std::true_type {
   static constexpr char Type[5] = "FORM";
-  static constexpr StringRef (*StringFn)(unsigned) = &FormEncodingString;
+  LLVM_ABI static StringRef (*const StringFn)(unsigned);
 };
 
 template <> struct EnumTraits : public std::true_type {
   static constexpr char Type[4] = "IDX";
-  static constexpr StringRef (*StringFn)(unsigned) = &IndexString;
+  LLVM_ABI static StringRef (*const StringFn)(unsigned);
 };
 
 template <> struct EnumTraits : public std::true_type {
   static constexpr char Type[4] = "TAG";
-  static constexpr StringRef (*StringFn)(unsigned) = &TagString;
+  LLVM_ABI static StringRef (*const StringFn)(unsigned);
 };
 
 template <> struct EnumTraits : public std::true_type {
   static constexpr char Type[4] = "LNS";
-  static constexpr StringRef (*StringFn)(unsigned) = &LNStandardString;
+  LLVM_ABI static StringRef (*const StringFn)(unsigned);
 };
 
 template <> struct EnumTraits : public std::true_type {
   static constexpr char Type[3] = "OP";
-  static constexpr StringRef (*StringFn)(unsigned) = &OperationEncodingString;
+  LLVM_ABI static StringRef (*const StringFn)(unsigned);
 };
 
 inline uint64_t computeTombstoneAddress(uint8_t AddressByteSize) {

diff  --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index a0dc522e13cab..8d7545144dfd9 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -256,8 +256,10 @@ class ELFFile {
 public:
   LLVM_ELF_IMPORT_TYPES_ELFT(ELFT)
 
-  // Default ctor required to instantiate the template for DLL export.
+  // Default ctor and copy assignment operator required to instantia

[clang] [llvm] [llvm] minor fixes for clang-cl Windows DLL build (PR #144386)

2025-06-17 Thread Saleem Abdulrasool via cfe-commits

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


[clang] [llvm] [llvm] minor fixes for clang-cl Windows DLL build (PR #144386)

2025-06-17 Thread Saleem Abdulrasool via cfe-commits

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

It is odd to me that this works with `cl`, I think that the clang semantics are 
technically correct. But, when in Rome 

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


[clang] [llvm] [llvm] minor fixes for clang-cl Windows DLL build (PR #144386)

2025-06-17 Thread Andrew Rogers via cfe-commits

andrurogerz wrote:

> I think that the clang semantics are technically correct

Yes,  agreed. And in case it wasn't clear, this is `clang` behavior and is not 
specific to `clang-cl`.

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


[clang] 8ddada4 - [RISCV] Add Andes XAndesVBFHCvt (Andes Vector BFLOAT16 Conversion) extension (#144320)

2025-06-17 Thread via cfe-commits

Author: Jim Lin
Date: 2025-06-18T09:17:46+08:00
New Revision: 8ddada41df0488358373cff1d31a47e5ef4961e0

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

LOG: [RISCV] Add Andes XAndesVBFHCvt (Andes Vector BFLOAT16 Conversion) 
extension (#144320)

The spec can be found at:
https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

This patch only supports assembler. The instructions are similar to
`Zvfbfmin` and the only difference with `Zvfbfmin` is that
`XAndesVBFHCvt` doesn't have mask variant.

Added: 
llvm/test/MC/RISCV/xandesvbfhcvt-valid.s

Modified: 
clang/test/Driver/print-supported-extensions-riscv.c
clang/test/Preprocessor/riscv-target-features-andes.c
llvm/docs/RISCVUsage.rst
llvm/docs/ReleaseNotes.md
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrInfoXAndes.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/CodeGen/RISCV/features-info.ll
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index e1f5a7a0105d7..5008c2b7f789d 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -159,6 +159,7 @@
 // CHECK-NEXT: svpbmt   1.0   'Svpbmt' (Page-Based Memory 
Types)
 // CHECK-NEXT: svvptc   1.0   'Svvptc' (Obviating 
Memory-Management Instructions after Marking PTEs Valid)
 // CHECK-NEXT: xandesperf   5.0   'XAndesPerf' (Andes 
Performance Extension)
+// CHECK-NEXT: xandesvbfhcvt5.0   'XAndesVBFHCvt' (Andes 
Vector BFLOAT16 Conversion Extension)
 // CHECK-NEXT: xandesvdot   5.0   'XAndesVDot' (Andes Vector 
Dot Product Extension)
 // CHECK-NEXT: xandesvpackfph   5.0   'XAndesVPackFPH' (Andes 
Vector Packed FP16 Extension)
 // CHECK-NEXT: xcvalu   1.0   'XCValu' (CORE-V ALU 
Operations)

diff  --git a/clang/test/Preprocessor/riscv-target-features-andes.c 
b/clang/test/Preprocessor/riscv-target-features-andes.c
index 3cd9b04354132..c66d4427b5cf2 100644
--- a/clang/test/Preprocessor/riscv-target-features-andes.c
+++ b/clang/test/Preprocessor/riscv-target-features-andes.c
@@ -15,6 +15,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESPERF %s
 // CHECK-XANDESPERF: __riscv_xandesperf  500{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_xandesvbfhcvt -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESVBFHCVT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_xandesvbfhcvt -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESVBFHCVT %s
+// CHECK-XANDESVBFHCVT: __riscv_xandesvbfhcvt  500{{$}}
+
 // RUN: %clang --target=riscv32 \
 // RUN:   -march=rv32i_xandesvpackfph -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESVPACKFPH %s

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index aadda309feab0..81684ba30f12c 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -513,6 +513,9 @@ The current vendor extensions supported are:
 ``XAndesPerf``
   LLVM implements `version 5.0.0 of the Andes Performance Extension 
specification 
`__
 by Andes Technology. All instructions are prefixed with `nds.` as described in 
the specification.
 
+``XAndesVBFHCvt``
+  LLVM implements `version 5.0.0 of the Andes Vector BFLOAT16 Conversion 
Extension specification 
`__
 by Andes Technology. All instructions are prefixed with `nds.` as described in 
the specification.
+
 ``XAndesVPackFPH``
   LLVM implements `version 5.0.0 of the Andes Vector Packed FP16 Extension 
specification 
`__
 by Andes Technology. All instructions are prefixed with `nds.` as described in 
the specification.
 

diff  --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 5c9ed181af59e..0395f43c61953 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -210,6 +210,7 @@ Changes to the RISC-V Backend
 * The `Shlcofideleg` extension was added.
 * `-mcpu=sifive-x390` was added.
 * `-mtune=andes-45-series` was added.
+* Adds assembler support for the Andes `XAndesvbfhcvt` (Andes Vector BFLOAT16 
Conversion extension).
 
 Changes to the WebAssemb

[clang] [llvm] [RISCV] Add Andes XAndesVBFHCvt (Andes Vector BFLOAT16 Conversion) extension (PR #144320)

2025-06-17 Thread Jim Lin via cfe-commits

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


[clang] [llvm] [RISCV] Add Andes XAndesVBFHCvt (Andes Vector BFLOAT16 Conversion) extension (PR #144320)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `arc-builder` running on 
`arc-worker` while building `clang,llvm` at step 6 
"test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: Preprocessor/riscv-target-features-andes.c' 
FAILED 
Exit Code: 2

Command Output (stderr):
--
/buildbot/worker/arc-folder/build/bin/clang --target=riscv32-unknown-linux-gnu 
-march=rv32i -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
-o - | /buildbot/worker/arc-folder/build/bin/FileCheck 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 # RUN: at line 1
+ /buildbot/worker/arc-folder/build/bin/clang 
--target=riscv32-unknown-linux-gnu -march=rv32i -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 -o -
+ /buildbot/worker/arc-folder/build/bin/FileCheck 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
/buildbot/worker/arc-folder/build/bin/clang --target=riscv64-unknown-linux-gnu 
-march=rv64i -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
-o - | /buildbot/worker/arc-folder/build/bin/FileCheck 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 # RUN: at line 3
+ /buildbot/worker/arc-folder/build/bin/clang 
--target=riscv64-unknown-linux-gnu -march=rv64i -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 -o -
+ /buildbot/worker/arc-folder/build/bin/FileCheck 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
/buildbot/worker/arc-folder/build/bin/clang --target=riscv32
-march=rv32i_xandesperf -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
-o - | /buildbot/worker/arc-folder/build/bin/FileCheck 
--check-prefix=CHECK-XANDESPERF 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 # RUN: at line 10
+ /buildbot/worker/arc-folder/build/bin/clang --target=riscv32 
-march=rv32i_xandesperf -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 -o -
+ /buildbot/worker/arc-folder/build/bin/FileCheck 
--check-prefix=CHECK-XANDESPERF 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
/buildbot/worker/arc-folder/build/bin/clang --target=riscv64
-march=rv64i_xandesperf -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
-o - | /buildbot/worker/arc-folder/build/bin/FileCheck 
--check-prefix=CHECK-XANDESPERF 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 # RUN: at line 13
+ /buildbot/worker/arc-folder/build/bin/clang --target=riscv64 
-march=rv64i_xandesperf -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 -o -
+ /buildbot/worker/arc-folder/build/bin/FileCheck 
--check-prefix=CHECK-XANDESPERF 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
/buildbot/worker/arc-folder/build/bin/clang --target=riscv32
-march=rv32i_xandesvbfhcvt -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
-o - | /buildbot/worker/arc-folder/build/bin/FileCheck 
--check-prefix=CHECK-XANDESVBFHCVT 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 # RUN: at line 18
+ /buildbot/worker/arc-folder/build/bin/clang --target=riscv32 
-march=rv32i_xandesvbfhcvt -E -dM 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
 -o -
+ /buildbot/worker/arc-folder/build/bin/FileCheck 
--check-prefix=CHECK-XANDESVBFHCVT 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c
clang: error: invalid arch name 'rv32i_xandesvbfhcvt', unsupported non-standard 
user-level extension 'xandesvbfhcvt'
FileCheck error: '' is empty.
FileCheck command line:  /buildbot/worker/arc-folder/build/bin/FileCheck 
--check-prefix=CHECK-XANDESVBFHCVT 
/buildbot/worker/arc-folder/llvm-project/clang/test/Preprocessor/riscv-target-features-andes.c

--




```



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


[clang] [Sema][ObjC] Loosen restrictions on reinterpret_cast involving indirect ARC-managed pointers (PR #144458)

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

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

Thanks, LGTM.

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


[clang] let Neon builtin function accept a const variable (PR #144625)

2025-06-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (scout-zeng)


Changes

`FORCE_INLINE __m128i _mm_sll_epi64(__m128i a, __m128i count)
{
long long c = count.vect_s64[0];
const int mc = c;
__m128i result_m128i;
if (likely(c >= 0 && c < 64)) {
result_m128i.vect_s64 = vshlq_n_s64(a.vect_s64, mc);
} else {
result_m128i.vect_s64 = vdupq_n_s64(0);
} 
return result_m128i;
}`
vshlq_n_s64 is an Neon intrinsics, 2nd parameter of this function needs a const 
int, however it failed in current CLANG Latest version. This patch used to 
support this feature which make Neon intrinsics can receive a const int 
variable instead of literal.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+4-3) 


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 69276ce418fa6..f9fc0ff536254 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5666,11 +5666,12 @@ bool Sema::BuiltinConstantArg(CallExpr *TheCall, int 
ArgNum,
 
   if (Arg->isTypeDependent() || Arg->isValueDependent()) return false;
 
-  std::optional R;
-  if (!(R = Arg->getIntegerConstantExpr(Context)))
+  Expr::EvalResult evalRes;
+  if (!Arg->EvaluateAsInt(evalRes, Context)) {
 return Diag(TheCall->getBeginLoc(), diag::err_constant_integer_arg_type)
<< FDecl->getDeclName() << Arg->getSourceRange();
-  Result = *R;
+  }
+  Result = evalRes.Val.getInt();
   return false;
 }
 

``




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


[clang] let Neon builtin function accept a const variable (PR #144625)

2025-06-17 Thread via cfe-commits

https://github.com/scout-zeng created 
https://github.com/llvm/llvm-project/pull/144625

`FORCE_INLINE __m128i _mm_sll_epi64(__m128i a, __m128i count)
{
long long c = count.vect_s64[0];
const int mc = c;
__m128i result_m128i;
if (likely(c >= 0 && c < 64)) {
result_m128i.vect_s64 = vshlq_n_s64(a.vect_s64, mc);
} else {
result_m128i.vect_s64 = vdupq_n_s64(0);
} 
return result_m128i;
}`
vshlq_n_s64 is an Neon intrinsics, 2nd parameter of this function needs a const 
int, however it failed in current CLANG Latest version. This patch used to 
support this feature which make Neon intrinsics can receive a const int 
variable instead of literal.

>From e6a654421ae7047844f8bf31d369fe720a53e1a9 Mon Sep 17 00:00:00 2001
From: haozen 
Date: Wed, 18 Jun 2025 09:48:58 +0800
Subject: [PATCH] Summary: builtin function can accept a constant variable.

---
 clang/lib/Sema/SemaChecking.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 69276ce418fa6..f9fc0ff536254 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5666,11 +5666,12 @@ bool Sema::BuiltinConstantArg(CallExpr *TheCall, int 
ArgNum,
 
   if (Arg->isTypeDependent() || Arg->isValueDependent()) return false;
 
-  std::optional R;
-  if (!(R = Arg->getIntegerConstantExpr(Context)))
+  Expr::EvalResult evalRes;
+  if (!Arg->EvaluateAsInt(evalRes, Context)) {
 return Diag(TheCall->getBeginLoc(), diag::err_constant_integer_arg_type)
<< FDecl->getDeclName() << Arg->getSourceRange();
-  Result = *R;
+  }
+  Result = evalRes.Val.getInt();
   return false;
 }
 

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


[clang] let Neon builtin function accept a const variable (PR #144625)

2025-06-17 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] let Neon builtin function accept a const variable (PR #144625)

2025-06-17 Thread via cfe-commits

scout-zeng wrote:

@efriedma-quic Hi Eli, if there is any problem, please let me know.

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


[clang] [CIR][NFCI] Represent Complex RValues As Single Value (PR #144519)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-arm64-windows-msvc` 
running on `linaro-armv8-windows-msvc-04` while building `clang` at step 6 
"test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'LLVM-Unit :: 
Testing/Support/./TestingSupportTests.exe/0/3' FAILED 
Script(shard):
--
GTEST_OUTPUT=json:C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\unittests\Testing\Support\.\TestingSupportTests.exe-LLVM-Unit-11216-0-3.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=3 GTEST_SHARD_INDEX=0 
C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\unittests\Testing\Support\.\TestingSupportTests.exe
--

Script:
--
C:\Users\tcwg\llvm-worker\clang-arm64-windows-msvc\build\unittests\Testing\Support\.\TestingSupportTests.exe
 --gtest_filter=TempPathTest.TempDir
--
C:/Users/tcwg/llvm-worker/clang-arm64-windows-msvc/llvm-project/llvm/unittests/Testing/Support/TempPathTest.cpp(40):
 error: Value of: sys::fs::exists(Path)
  Actual: true
Expected: false


C:/Users/tcwg/llvm-worker/clang-arm64-windows-msvc/llvm-project/llvm/unittests/Testing/Support/TempPathTest.cpp:40
Value of: sys::fs::exists(Path)
  Actual: true
Expected: false






```



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


[clang] [clang][PAC] Support trivially_relocating polymorphic objects (PR #144420)

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

rjmccall wrote:

I've been informed that I've misunderstood the nature of "trivial relocation" — 
it is not a "trivial" operation in the usual sense of triviality, it's just an 
operation that (1) can be done primitively by the compiler and (2) cannot fail. 
That addresses my concern, because we can certainly implement that for 
polymorphic classes.

I think we should make a point of implementing this for address-discriminated 
`__ptrauth` qualifiers before we release it, because changing the type trait in 
a future release will be an ABI break.

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


[clang] 3f33c84 - [clang] Add release note for int->enum conversion change. (#144407)

2025-06-17 Thread via cfe-commits

Author: Eli Friedman
Date: 2025-06-17T15:27:41-07:00
New Revision: 3f33c8482fc0b8dd0d2596262ebd0ed73d41665d

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

LOG: [clang] Add release note for int->enum conversion change. (#144407)

This seems to be having some practical impact, so we should let people
know.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6f28dbd03ca2a..12816eed2e8b5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -65,8 +65,10 @@ C++ Specific Potentially Breaking Changes
   standard library already have their own bespoke builtins.
 - A workaround for libstdc++4.7 has been removed. Note that 4.8.3 remains the 
oldest
   supported libstdc++ version.
-
 - Added ``!nonnull/!align`` metadata to load of references for better codegen.
+- Checking for int->enum conversions in constant expressions is more strict;
+  in particular, ``const E x = (E)-1;`` is not treated as a constant if it's
+  out of range. This impacts old versions of Boost.  (#GH143034)
 
 ABI Changes in This Version
 ---



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


[clang] [clang] Add release note for int->enum conversion change. (PR #144407)

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

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


[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #121829)

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

lenary wrote:

Nice, I can navigate that UI.

Looks like a similar thing that I fixed-forward, but this time with a different 
unwind library, but clang isn't very happy with mixing unwind libraries anyway.

I think I'll leave this to @quic-garvgupt to fix, using the info from your link.

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


[clang] [clang-tools-extra] [llvm] [clang] Simplify device kernel attributes (PR #137882)

2025-06-17 Thread Alexey Bader via cfe-commits


@@ -80,12 +80,19 @@ unsigned 
CodeGenTypes::ClangCallConvToLLVMCallConv(CallingConv CC) {
 return llvm::CallingConv::AArch64_VectorCall;
   case CC_AArch64SVEPCS:
 return llvm::CallingConv::AArch64_SVE_VectorCall;
-  case CC_AMDGPUKernelCall:
-return llvm::CallingConv::AMDGPU_KERNEL;
   case CC_SpirFunction:
 return llvm::CallingConv::SPIR_FUNC;
-  case CC_OpenCLKernel:
-return CGM.getTargetCodeGenInfo().getOpenCLKernelCallingConv();
+  case CC_DeviceKernel: {
+if (CGM.getLangOpts().OpenCL)
+  return CGM.getTargetCodeGenInfo().getOpenCLKernelCallingConv();
+if (CGM.getTriple().isSPIROrSPIRV())
+  return llvm::CallingConv::SPIR_KERNEL;
+if (CGM.getTriple().isAMDGPU())
+  return llvm::CallingConv::AMDGPU_KERNEL;
+if (CGM.getTriple().isNVPTX())
+  return llvm::CallingConv::PTX_Kernel;
+llvm_unreachable("Unknown kernel calling convention");
+  }

bader wrote:

@sarnex,
IMHO, the implementation of `CC_DeviceKernel` case should look like:

```c++
  case CC_DeviceKernel:
return CGM.getTargetCodeGenInfo().getDeviceKernelCallingConv();
```
SPIR/SPIR-V/NVPTX/AMDGPU targets should define target specific calling 
convention.

i.e. getOpenCLKernelCallingConv -> getDeviceKernelCallingConv.


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


[clang] [clang] Remove separate evaluation step for static class member init. (PR #142713)

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

efriedma-quic wrote:

Ping

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


[clang] [clang] Remove separate evaluation step for static class member init. (PR #142713)

2025-06-17 Thread Richard Smith via cfe-commits

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

LGTM

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


[clang] [clang] Register all LLVM targets in AllClangUnitTest main (PR #144428)

2025-06-17 Thread Reid Kleckner via cfe-commits


@@ -0,0 +1,24 @@
+//===- clang/unittests/AllClangUnitTests.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/TargetSelect.h"
+#include "gtest/gtest.h"
+
+// This custom main entry point for the AllClangUnitTests binary registers all
+// tests on startup, so the tests don't become sensitive to target registration
+// within the test suite.
+int main(int argc, char **argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+  llvm::cl::ParseCommandLineOptions(argc, argv);
+
+  llvm::InitializeAllTargets();

rnk wrote:

Done, sorry, I copied this from 
[`driver.cpp`](https://github.com/llvm/llvm-project/blob/main/clang/tools/driver/driver.cpp#L246),
 so I didn't get all this goop.

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


[clang-tools-extra] [clang-doc] mangle specialization file names (PR #144617)

2025-06-17 Thread Erick Velez via cfe-commits

https://github.com/evelez7 created 
https://github.com/llvm/llvm-project/pull/144617

None

>From bd5747e542e23078a98a830da191e5f1f72bd85b Mon Sep 17 00:00:00 2001
From: Erick Velez 
Date: Tue, 17 Jun 2025 15:11:02 -0700
Subject: [PATCH] [clang-doc] mangle specialization file names

---
 clang-tools-extra/clang-doc/BitcodeReader.cpp |  9 +
 clang-tools-extra/clang-doc/BitcodeWriter.cpp |  7 ++-
 clang-tools-extra/clang-doc/BitcodeWriter.h   |  1 +
 clang-tools-extra/clang-doc/JSONGenerator.cpp |  9 -
 clang-tools-extra/clang-doc/Representation.h  |  3 +++
 clang-tools-extra/clang-doc/Serialize.cpp |  8 
 .../json/specialization-mangled-name.cpp  | 15 +++
 7 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-doc/json/specialization-mangled-name.cpp

diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 35058abab0663..9227cf2bf51a2 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -83,6 +83,13 @@ static llvm::Error decodeRecord(const Record &R, 
std::optional &Field,
   return llvm::Error::success();
 }
 
+static llvm::Error decodeRecord(const Record &R,
+std::optional> &Field,
+llvm::StringRef Blob) {
+  Field.emplace(Blob);
+  return llvm::Error::success();
+}
+
 static llvm::Error decodeRecord(const Record &R, InfoType &Field,
 llvm::StringRef Blob) {
   switch (auto IT = static_cast(R[0])) {
@@ -379,6 +386,8 @@ static llvm::Error parseRecord(const Record &R, unsigned ID,
TemplateSpecializationInfo *I) {
   if (ID == TEMPLATE_SPECIALIZATION_OF)
 return decodeRecord(R, I->SpecializationOf, Blob);
+  if (ID == TEMPLATE_SPECIALIZATION_MANGLED_NAME)
+return decodeRecord(R, I->MangledName, Blob);
   return llvm::createStringError(llvm::inconvertibleErrorCode(),
  "invalid field for TemplateParamInfo");
 }
diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp 
b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index f8a6859169b01..e2c58731fbc67 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -202,6 +202,8 @@ static const llvm::IndexedMap
   {TEMPLATE_PARAM_CONTENTS, {"Contents", &genStringAbbrev}},
   {TEMPLATE_SPECIALIZATION_OF,
{"SpecializationOf", &genSymbolIdAbbrev}},
+  {TEMPLATE_SPECIALIZATION_MANGLED_NAME,
+   {"MangledName", &genStringAbbrev}},
   {TYPEDEF_USR, {"USR", &genSymbolIdAbbrev}},
   {TYPEDEF_NAME, {"Name", &genStringAbbrev}},
   {TYPEDEF_DEFLOCATION, {"DefLocation", &genLocationAbbrev}},
@@ -263,7 +265,8 @@ static const std::vector>>
 // Template Blocks.
 {BI_TEMPLATE_BLOCK_ID, {}},
 {BI_TEMPLATE_PARAM_BLOCK_ID, {TEMPLATE_PARAM_CONTENTS}},
-{BI_TEMPLATE_SPECIALIZATION_BLOCK_ID, {TEMPLATE_SPECIALIZATION_OF}}};
+{BI_TEMPLATE_SPECIALIZATION_BLOCK_ID,
+ {TEMPLATE_SPECIALIZATION_OF, TEMPLATE_SPECIALIZATION_MANGLED_NAME}}};
 
 // AbbreviationMap
 
@@ -638,6 +641,8 @@ void ClangDocBitcodeWriter::emitBlock(const TemplateInfo 
&T) {
 void ClangDocBitcodeWriter::emitBlock(const TemplateSpecializationInfo &T) {
   StreamSubBlockGuard Block(Stream, BI_TEMPLATE_SPECIALIZATION_BLOCK_ID);
   emitRecord(T.SpecializationOf, TEMPLATE_SPECIALIZATION_OF);
+  if (T.MangledName)
+emitRecord(T.MangledName->str(), TEMPLATE_SPECIALIZATION_MANGLED_NAME);
   for (const auto &P : T.Params)
 emitBlock(P);
 }
diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.h 
b/clang-tools-extra/clang-doc/BitcodeWriter.h
index e33a1aece883c..c0b879af59194 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.h
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.h
@@ -131,6 +131,7 @@ enum RecordId {
   REFERENCE_FIELD,
   TEMPLATE_PARAM_CONTENTS,
   TEMPLATE_SPECIALIZATION_OF,
+  TEMPLATE_SPECIALIZATION_MANGLED_NAME,
   TYPEDEF_USR,
   TYPEDEF_NAME,
   TYPEDEF_DEFLOCATION,
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp 
b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 0f7cbafcf5135..ca56e669038b4 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -491,7 +491,14 @@ Error JSONGenerator::generateDocs(
   CreatedDirs.insert(Path);
 }
 
-sys::path::append(Path, Info->getFileBaseName() + ".json");
+SmallString<16> FileBaseName = Info->getFileBaseName();
+if (Info->IT == InfoType::IT_record) {
+  if (auto Template = static_cast(Info)->Template;
+  Template && Template->Specialization &&
+  Template->Specialization->MangledName)
+FileBaseName = Template->Specialization->MangledName.value();
+}
+sys::path::append(P

[clang-tools-extra] [clang-doc] mangle specialization file names (PR #144617)

2025-06-17 Thread Erick Velez via cfe-commits

evelez7 wrote:

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




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


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


[clang] [AArch64] Add option -msve-streaming-vector-bits= . (PR #144611)

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

https://github.com/efriedma-quic created 
https://github.com/llvm/llvm-project/pull/144611

This is similar to -msve-vector-bits, but for streaming mode: it constrains the 
legal values of "vscale", allowing optimizations based on that constraint.

This also fixes conversions between SVE vectors and fixed-width vectors in 
streaming functions with -msve-vector-bits and
-msve-streaming-vector-bits.

This currently doesn't touch the __ARM_FEATURE_SVE_BITS define or the 
arm_sve_vector_bits attribute.

>From c28804a471a9fe6be24479ffbfd7d4aa6c774125 Mon Sep 17 00:00:00 2001
From: Eli Friedman 
Date: Tue, 17 Jun 2025 11:48:47 -0700
Subject: [PATCH] [AArch64] Add option -msve-streaming-vector-bits= .

This is similar to -msve-vector-bits, but for streaming mode: it
constrains the legal values of "vscale", allowing optimizations based on
that constraint.

This also fixes conversions between SVE vectors and fixed-width vectors
in streaming functions with -msve-vector-bits and
-msve-streaming-vector-bits.

This currently doesn't touch the __ARM_FEATURE_SVE_BITS define or the
arm_sve_vector_bits attribute.
---
 clang/include/clang/AST/ASTContext.h  |  9 --
 clang/include/clang/Basic/LangOptions.def |  3 +
 clang/include/clang/Driver/Options.td | 19 
 clang/include/clang/Sema/SemaARM.h|  9 ++
 clang/lib/AST/ASTContext.cpp  | 81 
 clang/lib/Basic/Targets/AArch64.cpp   |  8 +-
 clang/lib/Driver/ToolChains/Clang.cpp | 29 --
 clang/lib/Frontend/CompilerInvocation.cpp |  5 +
 clang/lib/Sema/SemaARM.cpp| 97 +++
 clang/lib/Sema/SemaChecking.cpp   | 16 +--
 clang/lib/Sema/SemaExpr.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   |  9 +-
 .../arm-sve-vector-bits-vscale-range.c| 58 ---
 clang/test/Driver/aarch64-sve-vector-bits.c   |  4 +
 ...rch64-streaming-sve-vector-conversions.cpp | 53 ++
 15 files changed, 277 insertions(+), 128 deletions(-)
 create mode 100644 
clang/test/SemaCXX/aarch64-streaming-sve-vector-conversions.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3abb49312255a..64d4c5547341e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2486,15 +2486,6 @@ class ASTContext : public RefCountedBase {
   /// types.
   bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
 
-  /// Return true if the given types are an SVE builtin and a VectorType that
-  /// is a fixed-length representation of the SVE builtin for a specific
-  /// vector-length.
-  bool areCompatibleSveTypes(QualType FirstType, QualType SecondType);
-
-  /// Return true if the given vector types are lax-compatible SVE vector 
types,
-  /// false otherwise.
-  bool areLaxCompatibleSveTypes(QualType FirstType, QualType SecondType);
-
   /// Return true if the given types are an RISC-V vector builtin type and a
   /// VectorType that is a fixed-length representation of the RISC-V vector
   /// builtin type for a specific vector-length.
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 789761c1f3647..8054be1bb4e88 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -503,6 +503,9 @@ LANGOPT(OmitVTableRTTI, 1, 0,
 LANGOPT(VScaleMin, 32, 0, "Minimum vscale value")
 LANGOPT(VScaleMax, 32, 0, "Maximum vscale value")
 
+LANGOPT(VScaleStreamingMin, 32, 0, "Minimum streaming vscale value")
+LANGOPT(VScaleStreamingMax, 32, 0, "Maximum streaming vscale value")
+
 ENUM_LANGOPT(ExtendIntArgs, ExtendArgsKind, 1, ExtendArgsKind::ExtendTo32,
  "Controls how scalar integer arguments are extended in calls "
  "to unprototyped and varargs functions")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 152df89118a6a..2e8d5b18483d7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5173,6 +5173,14 @@ def msve_vector_bits_EQ : Joined<["-"], 
"msve-vector-bits=">, Group,
   HelpText<"Specify the size in bits of an SVE vector register. Defaults to 
the"
" vector length agnostic value of \"scalable\". (AArch64 only)">;
+def msve_streaming_vector_bits_EQ
+: Joined<["-"], "msve-streaming-vector-bits=">,
+  Group,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<
+  "Specify the size in bits of an SVE vector register in streaming "
+  "mode. Defaults to the vector length agnostic value of "
+  "\"scalable\". (AArch64 only)">;
 } // let Flags = [TargetSpecific]
 
 def mvscale_min_EQ : Joined<["-"], "mvscale-min=">,
@@ -5184,6 +5192,17 @@ def mvscale_max_EQ : Joined<["-"], "mvscale-max=">,
   HelpText<"Specify the vscale maximum. Defaults to the"
" vector length agnostic value of \"0\". (

[clang] [llvm] [WIP][llvm] Flag to forcibly outline fixed point mul/div intrinsics (PR #144612)

2025-06-17 Thread via cfe-commits

https://github.com/PiJoules created 
https://github.com/llvm/llvm-project/pull/144612

This saves about 3kB on embedded project.

>From 9f179e644ddadba15f51d45479b20744b66f6291 Mon Sep 17 00:00:00 2001
From: Leonard Chan 
Date: Tue, 17 Jun 2025 15:06:10 -0700
Subject: [PATCH] [WIP][llvm] Flag to forcibly outline fixed point mul/div
 intrinsics

This saves about 3kB on embedded project.
---
 clang/include/clang/Basic/CodeGenOptions.def |  3 +
 clang/include/clang/Driver/Options.td|  9 +++
 clang/lib/CodeGen/CGExprScalar.cpp   |  8 +-
 clang/lib/Driver/ToolChains/Clang.cpp|  3 +
 llvm/include/llvm/IR/FixedPointBuilder.h | 78 +---
 5 files changed, 89 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index e5566a540dc65..6cf06196bd2d5 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -483,6 +483,9 @@ CODEGENOPT(StaticClosure, 1, 0)
 /// Assume that UAVs/SRVs may alias
 CODEGENOPT(ResMayAlias, 1, 0)
 
+/// Outline fixed point multiplication and division intrinsics.
+CODEGENOPT(OutlineFixedPointMulDiv, 1, 0)
+
 /// Controls how unwind v2 (epilog) information should be generated for x64
 /// Windows.
 ENUM_CODEGENOPT(WinX64EHUnwindV2, llvm::WinX64EHUnwindV2Mode,
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 72d564e1ba0be..899b563f97bba 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2741,6 +2741,15 @@ defm strict_float_cast_overflow : 
BoolFOption<"strict-float-cast-overflow",
 " of the target's native float-to-int conversion instructions">,
   PosFlag>;
 
+defm outline_fixed_point_mul_div_intrinsics
+: BoolFOption<
+  "outline-fixed-point-mul-div-intrinsics",
+  CodeGenOpts<"OutlineFixedPointMulDiv">, DefaultFalse,
+  NegFlag,
+  PosFlag,
+  BothFlags<[], [ClangOption, CC1Option],
+"the fixed point multiplication and division intrinsics">>;
+
 defm protect_parens : BoolFOption<"protect-parens",
   LangOpts<"ProtectParens">, DefaultFalse,
   PosFlagrender(Args, CmdArgs);
 
diff --git a/llvm/include/llvm/IR/FixedPointBuilder.h 
b/llvm/include/llvm/IR/FixedPointBuilder.h
index 1a22dd6b60936..ec983c96ab7b8 100644
--- a/llvm/include/llvm/IR/FixedPointBuilder.h
+++ b/llvm/include/llvm/IR/FixedPointBuilder.h
@@ -132,6 +132,44 @@ template  class FixedPointBuilder {
 return Type::getFloatingPointTy(Ty->getContext(), *FloatSema);
   }
 
+  static SmallString<16> GetOutlinedFuncName(StringRef OpName, bool Saturated,
+ unsigned Scale) {
+SmallString<16> OutlinedFuncName("__outlined_");
+OutlinedFuncName += OpName;
+OutlinedFuncName += "_fix";
+if (Saturated)
+  OutlinedFuncName += "_sat";
+OutlinedFuncName += "_";
+OutlinedFuncName += std::to_string(Scale);
+return OutlinedFuncName;
+  }
+
+  Value *CallFixedPointIntrinsicWrapper(Intrinsic::ID IID,
+StringRef OutlinedFuncName,
+Value *WideLHS, Value *WideRHS,
+unsigned Scale) {
+Module *M = B.GetInsertBlock()->getParent()->getParent();
+FunctionCallee Callee =
+M->getOrInsertFunction(OutlinedFuncName, WideLHS->getType(),
+   WideLHS->getType(), WideRHS->getType());
+Function *OutlinedFunc = cast(Callee.getCallee());
+if (OutlinedFunc->empty()) {
+  BasicBlock *BB =
+  BasicBlock::Create(M->getContext(), "entry", OutlinedFunc);
+  IRBuilder<> Builder(BB);
+  Value *V = Builder.CreateIntrinsic(IID, {WideLHS->getType()},
+ {OutlinedFunc->getArg(0),
+  OutlinedFunc->getArg(1),
+  Builder.getInt32(Scale)});
+  Builder.CreateRet(V);
+
+  Comdat *C = M->getOrInsertComdat(OutlinedFuncName);
+  OutlinedFunc->setComdat(C);
+  OutlinedFunc->addFnAttr(Attribute::NoInline);
+}
+return B.CreateCall(Callee, {WideLHS, WideRHS});
+  }
+
 public:
   FixedPointBuilder(IRBuilderTy &Builder) : B(Builder) {}
 
@@ -285,8 +323,8 @@ template  class FixedPointBuilder {
   /// \p LHSSema - The semantic of the left hand side
   /// \p RHS - The right hand side
   /// \p RHSSema - The semantic of the right hand side
-  Value *CreateMul(Value *LHS, const FixedPointSemantics &LHSSema,
-   Value *RHS, const FixedPointSemantics &RHSSema) {
+  Value *CreateMul(Value *LHS, const FixedPointSemantics &LHSSema, Value *RHS,
+   const FixedPointSemantics &RHSSema, bool Outlined = false) {
 auto CommonSema = getCommonBinopSemantic(LHSSema, RHSSema);
 bool UseSigned = CommonSema.isSigned() || Com

[clang] [llvm] [SROA] Vector promote some memsets (PR #133301)

2025-06-17 Thread Shilei Tian via cfe-commits

shiltian wrote:

> I assume AMDGPU does not support unaligned loads

We do support unaligned access IIUC, and it is actually required by HSA ABI. CC 
@arsenm 

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


[clang] [AArch64] Add option -msve-streaming-vector-bits= . (PR #144611)

2025-06-17 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-backend-arm

Author: Eli Friedman (efriedma-quic)


Changes

This is similar to -msve-vector-bits, but for streaming mode: it constrains the 
legal values of "vscale", allowing optimizations based on that constraint.

This also fixes conversions between SVE vectors and fixed-width vectors in 
streaming functions with -msve-vector-bits and
-msve-streaming-vector-bits.

This currently doesn't touch the __ARM_FEATURE_SVE_BITS define or the 
arm_sve_vector_bits attribute.

---

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


15 Files Affected:

- (modified) clang/include/clang/AST/ASTContext.h (-9) 
- (modified) clang/include/clang/Basic/LangOptions.def (+3) 
- (modified) clang/include/clang/Driver/Options.td (+19) 
- (modified) clang/include/clang/Sema/SemaARM.h (+9) 
- (modified) clang/lib/AST/ASTContext.cpp (-81) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+7-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+21-8) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+5) 
- (modified) clang/lib/Sema/SemaARM.cpp (+97) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+8-8) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+3-2) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+5-4) 
- (modified) clang/test/CodeGen/arm-sve-vector-bits-vscale-range.c (+43-15) 
- (modified) clang/test/Driver/aarch64-sve-vector-bits.c (+4) 
- (added) clang/test/SemaCXX/aarch64-streaming-sve-vector-conversions.cpp (+53) 


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3abb49312255a..64d4c5547341e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2486,15 +2486,6 @@ class ASTContext : public RefCountedBase {
   /// types.
   bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
 
-  /// Return true if the given types are an SVE builtin and a VectorType that
-  /// is a fixed-length representation of the SVE builtin for a specific
-  /// vector-length.
-  bool areCompatibleSveTypes(QualType FirstType, QualType SecondType);
-
-  /// Return true if the given vector types are lax-compatible SVE vector 
types,
-  /// false otherwise.
-  bool areLaxCompatibleSveTypes(QualType FirstType, QualType SecondType);
-
   /// Return true if the given types are an RISC-V vector builtin type and a
   /// VectorType that is a fixed-length representation of the RISC-V vector
   /// builtin type for a specific vector-length.
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 789761c1f3647..8054be1bb4e88 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -503,6 +503,9 @@ LANGOPT(OmitVTableRTTI, 1, 0,
 LANGOPT(VScaleMin, 32, 0, "Minimum vscale value")
 LANGOPT(VScaleMax, 32, 0, "Maximum vscale value")
 
+LANGOPT(VScaleStreamingMin, 32, 0, "Minimum streaming vscale value")
+LANGOPT(VScaleStreamingMax, 32, 0, "Maximum streaming vscale value")
+
 ENUM_LANGOPT(ExtendIntArgs, ExtendArgsKind, 1, ExtendArgsKind::ExtendTo32,
  "Controls how scalar integer arguments are extended in calls "
  "to unprototyped and varargs functions")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 152df89118a6a..2e8d5b18483d7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5173,6 +5173,14 @@ def msve_vector_bits_EQ : Joined<["-"], 
"msve-vector-bits=">, Group,
   HelpText<"Specify the size in bits of an SVE vector register. Defaults to 
the"
" vector length agnostic value of \"scalable\". (AArch64 only)">;
+def msve_streaming_vector_bits_EQ
+: Joined<["-"], "msve-streaming-vector-bits=">,
+  Group,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<
+  "Specify the size in bits of an SVE vector register in streaming "
+  "mode. Defaults to the vector length agnostic value of "
+  "\"scalable\". (AArch64 only)">;
 } // let Flags = [TargetSpecific]
 
 def mvscale_min_EQ : Joined<["-"], "mvscale-min=">,
@@ -5184,6 +5192,17 @@ def mvscale_max_EQ : Joined<["-"], "mvscale-max=">,
   HelpText<"Specify the vscale maximum. Defaults to the"
" vector length agnostic value of \"0\". (AArch64/RISC-V only)">,
   MarshallingInfoInt>;
+def mvscale_streaming_min_EQ
+: Joined<["-"], "mvscale-streaming-min=">,
+  Visibility<[CC1Option, FC1Option]>,
+  HelpText<"Specify the vscale minimum. Defaults to \"1\". (AArch64 
only)">,
+  MarshallingInfoInt>;
+def mvscale_streaming_max_EQ
+: Joined<["-"], "mvscale-streaming-max=">,
+  Visibility<[CC1Option, FC1Option]>,
+  HelpText<"Specify the vscale maximum. Defaults to the"
+   " vector length agnostic value of \"0\". (AArch64 only)">,
+  M

[clang] [AArch64] Add option -msve-streaming-vector-bits= . (PR #144611)

2025-06-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: Eli Friedman (efriedma-quic)


Changes

This is similar to -msve-vector-bits, but for streaming mode: it constrains the 
legal values of "vscale", allowing optimizations based on that constraint.

This also fixes conversions between SVE vectors and fixed-width vectors in 
streaming functions with -msve-vector-bits and
-msve-streaming-vector-bits.

This currently doesn't touch the __ARM_FEATURE_SVE_BITS define or the 
arm_sve_vector_bits attribute.

---

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


15 Files Affected:

- (modified) clang/include/clang/AST/ASTContext.h (-9) 
- (modified) clang/include/clang/Basic/LangOptions.def (+3) 
- (modified) clang/include/clang/Driver/Options.td (+19) 
- (modified) clang/include/clang/Sema/SemaARM.h (+9) 
- (modified) clang/lib/AST/ASTContext.cpp (-81) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+7-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+21-8) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+5) 
- (modified) clang/lib/Sema/SemaARM.cpp (+97) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+8-8) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+3-2) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+5-4) 
- (modified) clang/test/CodeGen/arm-sve-vector-bits-vscale-range.c (+43-15) 
- (modified) clang/test/Driver/aarch64-sve-vector-bits.c (+4) 
- (added) clang/test/SemaCXX/aarch64-streaming-sve-vector-conversions.cpp (+53) 


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3abb49312255a..64d4c5547341e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2486,15 +2486,6 @@ class ASTContext : public RefCountedBase {
   /// types.
   bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
 
-  /// Return true if the given types are an SVE builtin and a VectorType that
-  /// is a fixed-length representation of the SVE builtin for a specific
-  /// vector-length.
-  bool areCompatibleSveTypes(QualType FirstType, QualType SecondType);
-
-  /// Return true if the given vector types are lax-compatible SVE vector 
types,
-  /// false otherwise.
-  bool areLaxCompatibleSveTypes(QualType FirstType, QualType SecondType);
-
   /// Return true if the given types are an RISC-V vector builtin type and a
   /// VectorType that is a fixed-length representation of the RISC-V vector
   /// builtin type for a specific vector-length.
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 789761c1f3647..8054be1bb4e88 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -503,6 +503,9 @@ LANGOPT(OmitVTableRTTI, 1, 0,
 LANGOPT(VScaleMin, 32, 0, "Minimum vscale value")
 LANGOPT(VScaleMax, 32, 0, "Maximum vscale value")
 
+LANGOPT(VScaleStreamingMin, 32, 0, "Minimum streaming vscale value")
+LANGOPT(VScaleStreamingMax, 32, 0, "Maximum streaming vscale value")
+
 ENUM_LANGOPT(ExtendIntArgs, ExtendArgsKind, 1, ExtendArgsKind::ExtendTo32,
  "Controls how scalar integer arguments are extended in calls "
  "to unprototyped and varargs functions")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 152df89118a6a..2e8d5b18483d7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5173,6 +5173,14 @@ def msve_vector_bits_EQ : Joined<["-"], 
"msve-vector-bits=">, Group,
   HelpText<"Specify the size in bits of an SVE vector register. Defaults to 
the"
" vector length agnostic value of \"scalable\". (AArch64 only)">;
+def msve_streaming_vector_bits_EQ
+: Joined<["-"], "msve-streaming-vector-bits=">,
+  Group,
+  Visibility<[ClangOption, FlangOption]>,
+  HelpText<
+  "Specify the size in bits of an SVE vector register in streaming "
+  "mode. Defaults to the vector length agnostic value of "
+  "\"scalable\". (AArch64 only)">;
 } // let Flags = [TargetSpecific]
 
 def mvscale_min_EQ : Joined<["-"], "mvscale-min=">,
@@ -5184,6 +5192,17 @@ def mvscale_max_EQ : Joined<["-"], "mvscale-max=">,
   HelpText<"Specify the vscale maximum. Defaults to the"
" vector length agnostic value of \"0\". (AArch64/RISC-V only)">,
   MarshallingInfoInt>;
+def mvscale_streaming_min_EQ
+: Joined<["-"], "mvscale-streaming-min=">,
+  Visibility<[CC1Option, FC1Option]>,
+  HelpText<"Specify the vscale minimum. Defaults to \"1\". (AArch64 
only)">,
+  MarshallingInfoInt>;
+def mvscale_streaming_max_EQ
+: Joined<["-"], "mvscale-streaming-max=">,
+  Visibility<[CC1Option, FC1Option]>,
+  HelpText<"Specify the vscale maximum. Defaults to the"
+   " vector length agnostic value of \"0\". (AArch64 only)">,
+  MarshallingInfoInt>;
 
 def msi

[clang] [llvm] [SROA] Vector promote some memsets (PR #133301)

2025-06-17 Thread Nikita Popov via cfe-commits

nikic wrote:

On x86, what we actually end up doing is to combine those to unaligned i64 
loads (see https://godbolt.org/z/P5z674x4r), which is probably the best outcome 
if they are supported. I assume AMDGPU does not support unaligned loads, and 
that's why you want to have single element loads that get inserted into a 
vector and then perform sub-vector extracts on it?

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


[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #121829)

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

lenary wrote:

Do the fuchsia builders actually produce output on a failure? We seem to just 
get exit code 1, but no indication of what filecheck had problems with.

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


[clang] [llvm] Revert "[RISCV] Remove B and Zbc extension from Andes series cpus." (PR #144402)

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

lenary wrote:

We probably need to file an infrastructure ticket to get to the bottom of this 
issue. I've seen the same issues @mshockwave has seen.

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


[clang] [Driver] Add support for GCC installation detection in Baremetal toolchain (PR #121829)

2025-06-17 Thread Daniel Thornburgh via cfe-commits

mysterymath wrote:

> Do the fuchsia builders actually produce output on a failure? We seem to just 
> get exit code 1, but no indication of what filecheck had problems with.

They do; here's a link! Let me know if you have an problems with the Web UI; I 
can paste things here if so.
https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8711783358287375697/overview

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


[clang-tools-extra] [clang-doc] mangle specialization file names (PR #144617)

2025-06-17 Thread Erick Velez via cfe-commits

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


[clang] [clang] Register all LLVM targets in AllClangUnitTest main (PR #144428)

2025-06-17 Thread Reid Kleckner via cfe-commits

https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/144428

>From afb050103754e6b4656c68da8ddfb6b1a4e03e5d Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Mon, 16 Jun 2025 20:08:12 +
Subject: [PATCH 1/3] [clang] Register all LLVM targets in AllClangUnitTest
 main

Addresses feedback in 
https://github.com/llvm/llvm-project/pull/134196#issuecomment-2970715875

Makes the tests less sensitive to target registration from unrelated
test fixtures by registering everything up front.
---
 clang/unittests/AllClangUnitTests.cpp | 24 
 clang/unittests/CMakeLists.txt|  1 +
 2 files changed, 25 insertions(+)
 create mode 100644 clang/unittests/AllClangUnitTests.cpp

diff --git a/clang/unittests/AllClangUnitTests.cpp 
b/clang/unittests/AllClangUnitTests.cpp
new file mode 100644
index 0..1726cabc8107c
--- /dev/null
+++ b/clang/unittests/AllClangUnitTests.cpp
@@ -0,0 +1,24 @@
+//===- clang/unittests/AllClangUnitTests.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/TargetSelect.h"
+
+// This custom main entry point for the AllClangUnitTests binary registers all
+// tests on startup, so the tests don't become sensitive to target registration
+// within the test suite.
+int main(int argc, char **argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+  llvm::cl::ParseCommandLineOptions(argc, argv);
+
+  llvm::InitializeAllTargets();
+  llvm::InitializeAllTargetMCs();
+
+  return RUN_ALL_TESTS();
+}
diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index aef28f914b640..54c781a35c20c 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -117,6 +117,7 @@ get_property(LINK_LIBS GLOBAL PROPERTY 
CLANG_UNITTEST_LINK_LIBS)
 get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
 add_distinct_clang_unittest(AllClangUnitTests
   ${SRCS}
+  AllClangUnitTests.cpp
   CLANG_LIBS
   ${CLANG_LIBS}
   LINK_LIBS

>From f5accc33950191c2e6eebe8327e247e2a4177d3e Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Mon, 16 Jun 2025 20:15:11 +
Subject: [PATCH 2/3] reorder headers to pacify format checker

---
 clang/unittests/AllClangUnitTests.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/AllClangUnitTests.cpp 
b/clang/unittests/AllClangUnitTests.cpp
index 1726cabc8107c..d1c8da12d5c84 100644
--- a/clang/unittests/AllClangUnitTests.cpp
+++ b/clang/unittests/AllClangUnitTests.cpp
@@ -6,9 +6,9 @@
 //
 
//===--===//
 
-#include "gtest/gtest.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/TargetSelect.h"
+#include "gtest/gtest.h"
 
 // This custom main entry point for the AllClangUnitTests binary registers all
 // tests on startup, so the tests don't become sensitive to target registration

>From 1f57ce24f87a22a2975beb928892f4aa6b983f81 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Tue, 17 Jun 2025 23:37:25 +
Subject: [PATCH 3/3] Add additional target registration hooks to match cc1

---
 clang/unittests/AllClangUnitTests.cpp | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/clang/unittests/AllClangUnitTests.cpp 
b/clang/unittests/AllClangUnitTests.cpp
index d1c8da12d5c84..279e51b41d5bf 100644
--- a/clang/unittests/AllClangUnitTests.cpp
+++ b/clang/unittests/AllClangUnitTests.cpp
@@ -17,8 +17,14 @@ int main(int argc, char **argv) {
   ::testing::InitGoogleTest(&argc, argv);
   llvm::cl::ParseCommandLineOptions(argc, argv);
 
+  // Initialize all levels of target components. Keep this in sync with
+  // cc1_main.
+  llvm::InitializeAllTargetInfos();
   llvm::InitializeAllTargets();
   llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmPrinters();
+  llvm::InitializeAllAsmParsers();
+
 
   return RUN_ALL_TESTS();
 }

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


[clang] [clang] Register all LLVM targets in AllClangUnitTest main (PR #144428)

2025-06-17 Thread Reid Kleckner via cfe-commits

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


[clang] [llvm] [SROA] Vector promote some memsets (PR #133301)

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

arsenm wrote:

> and that's why you want to have single element loads that get inserted into a 
> vector and then perform sub-vector extracts on it?

We care about eliminate stack usage at any cost. Big load are always better, 
even if not naturally aligned. When we do care about alignment, we only care 
about align > 4, we don't care about the actual type alignment.



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


[clang] [clang] Register all LLVM targets in AllClangUnitTest main (PR #144428)

2025-06-17 Thread Reid Kleckner via cfe-commits

https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/144428

>From afb050103754e6b4656c68da8ddfb6b1a4e03e5d Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Mon, 16 Jun 2025 20:08:12 +
Subject: [PATCH 1/4] [clang] Register all LLVM targets in AllClangUnitTest
 main

Addresses feedback in 
https://github.com/llvm/llvm-project/pull/134196#issuecomment-2970715875

Makes the tests less sensitive to target registration from unrelated
test fixtures by registering everything up front.
---
 clang/unittests/AllClangUnitTests.cpp | 24 
 clang/unittests/CMakeLists.txt|  1 +
 2 files changed, 25 insertions(+)
 create mode 100644 clang/unittests/AllClangUnitTests.cpp

diff --git a/clang/unittests/AllClangUnitTests.cpp 
b/clang/unittests/AllClangUnitTests.cpp
new file mode 100644
index 0..1726cabc8107c
--- /dev/null
+++ b/clang/unittests/AllClangUnitTests.cpp
@@ -0,0 +1,24 @@
+//===- clang/unittests/AllClangUnitTests.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "gtest/gtest.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/TargetSelect.h"
+
+// This custom main entry point for the AllClangUnitTests binary registers all
+// tests on startup, so the tests don't become sensitive to target registration
+// within the test suite.
+int main(int argc, char **argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+  llvm::cl::ParseCommandLineOptions(argc, argv);
+
+  llvm::InitializeAllTargets();
+  llvm::InitializeAllTargetMCs();
+
+  return RUN_ALL_TESTS();
+}
diff --git a/clang/unittests/CMakeLists.txt b/clang/unittests/CMakeLists.txt
index aef28f914b640..54c781a35c20c 100644
--- a/clang/unittests/CMakeLists.txt
+++ b/clang/unittests/CMakeLists.txt
@@ -117,6 +117,7 @@ get_property(LINK_LIBS GLOBAL PROPERTY 
CLANG_UNITTEST_LINK_LIBS)
 get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
 add_distinct_clang_unittest(AllClangUnitTests
   ${SRCS}
+  AllClangUnitTests.cpp
   CLANG_LIBS
   ${CLANG_LIBS}
   LINK_LIBS

>From f5accc33950191c2e6eebe8327e247e2a4177d3e Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Mon, 16 Jun 2025 20:15:11 +
Subject: [PATCH 2/4] reorder headers to pacify format checker

---
 clang/unittests/AllClangUnitTests.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/AllClangUnitTests.cpp 
b/clang/unittests/AllClangUnitTests.cpp
index 1726cabc8107c..d1c8da12d5c84 100644
--- a/clang/unittests/AllClangUnitTests.cpp
+++ b/clang/unittests/AllClangUnitTests.cpp
@@ -6,9 +6,9 @@
 //
 
//===--===//
 
-#include "gtest/gtest.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/TargetSelect.h"
+#include "gtest/gtest.h"
 
 // This custom main entry point for the AllClangUnitTests binary registers all
 // tests on startup, so the tests don't become sensitive to target registration

>From 1f57ce24f87a22a2975beb928892f4aa6b983f81 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Tue, 17 Jun 2025 23:37:25 +
Subject: [PATCH 3/4] Add additional target registration hooks to match cc1

---
 clang/unittests/AllClangUnitTests.cpp | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/clang/unittests/AllClangUnitTests.cpp 
b/clang/unittests/AllClangUnitTests.cpp
index d1c8da12d5c84..279e51b41d5bf 100644
--- a/clang/unittests/AllClangUnitTests.cpp
+++ b/clang/unittests/AllClangUnitTests.cpp
@@ -17,8 +17,14 @@ int main(int argc, char **argv) {
   ::testing::InitGoogleTest(&argc, argv);
   llvm::cl::ParseCommandLineOptions(argc, argv);
 
+  // Initialize all levels of target components. Keep this in sync with
+  // cc1_main.
+  llvm::InitializeAllTargetInfos();
   llvm::InitializeAllTargets();
   llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmPrinters();
+  llvm::InitializeAllAsmParsers();
+
 
   return RUN_ALL_TESTS();
 }

>From 5d9b64763f367f5fe0b5544ea50705e6872d2386 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Tue, 17 Jun 2025 23:48:56 +
Subject: [PATCH 4/4] pacify formatter

---
 clang/unittests/AllClangUnitTests.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/unittests/AllClangUnitTests.cpp 
b/clang/unittests/AllClangUnitTests.cpp
index 279e51b41d5bf..71d3ec32aa054 100644
--- a/clang/unittests/AllClangUnitTests.cpp
+++ b/clang/unittests/AllClangUnitTests.cpp
@@ -25,6 +25,5 @@ int main(int argc, char **argv) {
   llvm::InitializeAllAsmPrinters();
   llvm::InitializeAllAsmParsers();
 
-
   return RUN_ALL_TESTS();
 }

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

[clang] [clang] Register all LLVM targets in AllClangUnitTest main (PR #144428)

2025-06-17 Thread Reid Kleckner via cfe-commits


@@ -0,0 +1,24 @@
+//===- clang/unittests/AllClangUnitTests.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/TargetSelect.h"
+#include "gtest/gtest.h"
+
+// This custom main entry point for the AllClangUnitTests binary registers all
+// tests on startup, so the tests don't become sensitive to target registration
+// within the test suite.
+int main(int argc, char **argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+  llvm::cl::ParseCommandLineOptions(argc, argv);
+
+  llvm::InitializeAllTargets();

rnk wrote:

Done, sorry, I copied this from 
[driver.cpp](https://github.com/llvm/llvm-project/blob/main/clang/tools/driver/driver.cpp#L246),
 so I didn't get all this goop.

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


[clang] [clang] Register all LLVM targets in AllClangUnitTest main (PR #144428)

2025-06-17 Thread Reid Kleckner via cfe-commits


@@ -117,6 +117,7 @@ get_property(LINK_LIBS GLOBAL PROPERTY 
CLANG_UNITTEST_LINK_LIBS)
 get_property(LLVM_COMPONENTS GLOBAL PROPERTY CLANG_UNITTEST_LLVM_COMPONENTS)
 add_distinct_clang_unittest(AllClangUnitTests
   ${SRCS}
+  AllClangUnitTests.cpp

rnk wrote:

I spot checked two other unit tests that have custom mains, and they don't do 
anything special:
1. llvm-cfi-verify 
[main](https://github.com/llvm/llvm-project/blob/main/llvm/unittests/tools/llvm-cfi-verify/FileAnalysis.cpp#L1096)
 , 
[cmake](https://github.com/llvm/llvm-project/blob/main/llvm/unittests/tools/llvm-cfi-verify/CMakeLists.txt#L14)
2. LiveIntervalTest 
[main](https://github.com/llvm/llvm-project/blob/main/llvm/unittests/MI/LiveIntervalTest.cpp#L933),
 
[cmake](https://github.com/llvm/llvm-project/blob/main/llvm/unittests/MI/CMakeLists.txt#L13)

I think archive semantics are pretty portable between platforms, so I think 
this just works. The sources used to build the unit test executable override 
the main provided by the gtest library.

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


[clang] [llvm] [SROA] Vector promote some memsets (PR #133301)

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

arsenm wrote:

> We do support unaligned access IIUC, and it is actually required by HSA ABI. 
> CC @arsenm

Unaligned access has been supported since almost always. There's just a mode 
control for it, you can disable it in the driver though 



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


[clang] f2d2c99 - [clang] Remove separate evaluation step for static class member init. (#142713)

2025-06-17 Thread via cfe-commits

Author: Eli Friedman
Date: 2025-06-17T16:43:55-07:00
New Revision: f2d2c99866dfd133e7b9c98b1d4983c6bce33d67

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

LOG: [clang] Remove separate evaluation step for static class member init. 
(#142713)

We already evaluate the initializers for all global variables, as
required by the standard. Leverage that evaluation instead of trying to
separately validate static class members.

This has a few benefits:

- Improved diagnostics; we now get notes explaining what failed to
evaluate.
- Improved correctness: is_constant_evaluated is handled correctly.

The behavior follows the proposed resolution for CWG1721.

Fixes #88462. Fixes #99680.

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
clang/test/SemaCXX/class.cpp
clang/test/SemaCXX/cxx0x-class.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/test/SemaTemplate/instantiate-static-var.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 02ac898a2b702..1bf72e5bb7b9d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13963,31 +13963,10 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
 
 // We allow integer constant expressions in all cases.
 } else if (DclT->isIntegralOrEnumerationType()) {
-  // Check whether the expression is a constant expression.
-  SourceLocation Loc;
   if (getLangOpts().CPlusPlus11 && DclT.isVolatileQualified())
 // In C++11, a non-constexpr const static data member with an
 // in-class initializer cannot be volatile.
 Diag(VDecl->getLocation(), diag::err_in_class_initializer_volatile);
-  else if (Init->isValueDependent())
-; // Nothing to check.
-  else if (Init->isIntegerConstantExpr(Context, &Loc))
-; // Ok, it's an ICE!
-  else if (Init->getType()->isScopedEnumeralType() &&
-   Init->isCXX11ConstantExpr(Context))
-; // Ok, it is a scoped-enum constant expression.
-  else if (Init->isEvaluatable(Context)) {
-// If we can constant fold the initializer through heroics, accept it,
-// but report this as a use of an extension for -pedantic.
-Diag(Loc, diag::ext_in_class_initializer_non_constant)
-  << Init->getSourceRange();
-  } else {
-// Otherwise, this is some crazy unknown case.  Report the issue at the
-// location provided by the isIntegerConstantExpr failed check.
-Diag(Loc, diag::err_in_class_initializer_non_constant)
-  << Init->getSourceRange();
-VDecl->setInvalidDecl();
-  }
 
 // We allow foldable floating-point constants as an extension.
 } else if (DclT->isFloatingType()) { // also permits complex, which is ok
@@ -14715,6 +14694,17 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
   // Compute and cache the constant value, and remember that we have a
   // constant initializer.
   if (HasConstInit) {
+if (var->isStaticDataMember() && !var->isInline() &&
+var->getLexicalDeclContext()->isRecord() &&
+type->isIntegralOrEnumerationType()) {
+  // In C++98, in-class initialization for a static data member must
+  // be an integer constant expression.
+  SourceLocation Loc;
+  if (!Init->isIntegerConstantExpr(Context, &Loc)) {
+Diag(Loc, diag::ext_in_class_initializer_non_constant)
+<< Init->getSourceRange();
+  }
+}
 (void)var->checkForConstantInitialization(Notes);
 Notes.clear();
   } else if (CacheCulprit) {
@@ -14750,6 +14740,13 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
   << Attr->getRange() << Attr->isConstinit();
   for (auto &it : Notes)
 Diag(it.first, it.second);
+} else if (var->isStaticDataMember() && !var->isInline() &&
+   var->getLexicalDeclContext()->isRecord()) {
+  Diag(var->getLocation(), diag::err_in_class_initializer_non_constant)
+  << Init->getSourceRange();
+  for (auto &it : Notes)
+Diag(it.first, it.second);
+  var->setInvalidDecl();
 } else if (IsGlobal &&
!getDiagnostics().isIgnored(diag::warn_global_constructor,
var->getLocation())) {

diff  --git a/clang/test/SemaCXX/builtin-is-constant-evaluated.cpp 
b/clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
index c775fe71069df..66981acf87a8a 100644
--- a/clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
+++ b/clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
@@ -154,3 +154,17 @@ namespace narrowing {
 // expected-not

[clang] [Clang] include attribute scope in diagnostics (PR #144619)

2025-06-17 Thread Oleksandr T. via cfe-commits

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


[clang] [clang] Remove separate evaluation step for static class member init. (PR #142713)

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

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


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

2025-06-17 Thread Daniil Kovalev via cfe-commits


@@ -93,6 +98,13 @@ class _LIBUNWIND_HIDDEN Registers_x86 {
   uint32_t  getEDI() const { return _registers.__edi; }
   void  setEDI(uint32_t value) { _registers.__edi = value; }
 
+  typedef uint32_t reg_t;
+  typedef uint32_t link_reg_t;
+  void loadAndAuthenticateLinkRegister(reg_t srcLinkRegister,

kovdan01 wrote:

Since `loadAndAuthenticateLinkRegister` is used in UnwindCursor.hpp as a member 
function of a `registers` object (having template registers class type), we 
should probably consider one of the following options.

1. Define `loadAndAuthenticateLinkRegister` for all the register classes. As 
far as I can see now, your patch contains definitions for x86, x86_64, ppc, 
arm64 and arm, but we also have mips, risc-v, ...
2. Only limit this function to arm64 and do not expose that to register classes 
for other architectures. In this case, you'll probably need to insert checks 
like `__has_feature(...)` in UnwindCursor.hpp and add special logic in these 
cases.
 
I personally prefer the 2nd option. It's not very nice, but IMHO this is better 
than adding a placeholder function for all the architectures.

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


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

2025-06-17 Thread Daniil Kovalev via cfe-commits


@@ -83,7 +83,13 @@ __llvm_profile_iterate_data(const __llvm_profile_data *Data) 
{
 /* This method is only used in value profiler mock testing.  */
 COMPILER_RT_VISIBILITY void *
 __llvm_get_function_addr(const __llvm_profile_data *Data) {
-  return Data->FunctionPointer;
+  void *FP = Data->FunctionPointer;
+#if __has_feature(ptrauth_calls)
+  // This is only used for tests where we compare against what happens to be
+  // signed pointers.
+  FP = ptrauth_sign_unauthenticated(FP, VALID_CODE_KEY, 0);

kovdan01 wrote:

`VALID_CODE_KEY` is not defined, have you forgotten that? In some tests, there 
is `#define VALID_CODE_KEY 0` definition.

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


  1   2   3   >