[clang] [clang-c] introduce queries on GCC-style inline assembly statements (PR #143424)

2025-06-09 Thread via cfe-commits

https://github.com/dingxiangfei2009 updated 
https://github.com/llvm/llvm-project/pull/143424

>From 2d531acf50a4bdb139736693afd52559830acbbe Mon Sep 17 00:00:00 2001
From: Xiangfei Ding 
Date: Mon, 9 Jun 2025 13:57:18 +
Subject: [PATCH] [clang-c] introduce queries on GCC-style inline assembly
 statements

We strive for exposing such information using existing stable ABIs.
In doing so, queries are limited to what the original source holds
or the LLVM IR `asm` block would expose in connection with attributes
that the queries are concerned.

Signed-off-by: Xiangfei Ding 
---
 clang/include/clang-c/Index.h   |  93 +-
 clang/test/Index/inline-assembly.c  |  48 +
 clang/tools/c-index-test/c-index-test.c |  52 ++
 clang/tools/libclang/CIndex.cpp | 125 ++--
 clang/tools/libclang/libclang.map   |  10 ++
 5 files changed, 320 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/Index/inline-assembly.c

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index e4cb4327fbaac..340d050654a69 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -36,7 +36,7 @@
 #define CINDEX_VERSION_MAJOR 0
 #define CINDEX_VERSION_MINOR 64
 
-#define CINDEX_VERSION_ENCODE(major, minor) (((major)*1) + ((minor)*1))
+#define CINDEX_VERSION_ENCODE(major, minor) (((major) * 1) + ((minor) * 1))
 
 #define CINDEX_VERSION 
\
   CINDEX_VERSION_ENCODE(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR)
@@ -4495,6 +4495,97 @@ CINDEX_LINKAGE CXStringSet 
*clang_Cursor_getCXXManglings(CXCursor);
  */
 CINDEX_LINKAGE CXStringSet *clang_Cursor_getObjCManglings(CXCursor);
 
+/**
+ * @}
+ */
+
+/**
+ * \defgroup CINDEX_MODULE Inline Assembly introspection
+ *
+ * The functions in this group provide access to information about GCC-style
+ * inline assembly statements.
+ *
+ * @{
+ */
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, return the assembly template string.
+ * As per LLVM IR Assembly Template language, template placeholders for
+ * inputs and outputs are either of the form $N where N is a decimal number
+ * as an index into the input-output specification,
+ * or ${N:M} where N is a decimal number also as an index into the
+ * input-output specification and M is the template argument modifier.
+ * The index N in both cases points into the the total inputs and outputs,
+ * or more specifically, into the list of outputs followed by the inputs,
+ * starting from index 0 as the first available template argument.
+ */
+
+CINDEX_LINKAGE CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, check if the assembly block has goto
+ * labels.
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblyHasGoto(CXCursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, count the number of outputs
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumOutputs(CXCursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, count the number of inputs
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumInputs(CXCursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
+ * to the Index-th input.
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor,
+ unsigned Index,
+ CXString *Constraint,
+ CXCursor *Expr);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
+ * to the Index-th output.
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor,
+  unsigned Index,
+  CXString *Constraint,
+  CXCursor *Expr);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, count the clobbers in it.
+ */
+
+unsigned clang_Cursor_getGCCAssemblyNumClobbers(CXCursor Cursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, get the Index-th clobber of it.
+ */
+
+CXString clang_Cursor_getGCCAssemblyClobber(CXCursor Cursor, unsigned Index);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, check if the inline assembly is simple.
+ */
+
+unsigned clang_Cursor_isGCCAssemblySimple(CXCursor Cursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, check if the inline assembly is
+ * `volatile`.
+ */
+
+unsigned clang_Cursor_isGCCAssemblyVolatile(CXCursor Cursor);
+
 /**
  * @}
  */
diff --git a/clang/test/Index/inline-assembly.c 
b/clang/test/Index/inline-assembly.c
new file mode 100644
index 0..2223dd2985f51
--- /dev/null
+++ b/clang/test/Index/inline-assembly.c
@@ -0,0 +1,48 @@
+static void inline_assembly_template_regardless_of_target_machine() {
+int tmp;
+asm volatile (
+

[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-fir-hlfir

Author: Anchu Rajendran S (anchuraj)


Changes

Atomic Control Options are used to specify architectural characteristics to 
help lowering of atomic operations. The options used are: 
`-f[no-]atomic-remote-memory`, `-f[no-]atomic-fine-grained-memory`,
 `-f[no-]atomic-ignore-denormal-mode`.
Legacy option `-m[no-]unsafe-fp-atomics` is aliased to
`-f[no-]ignore-denormal-mode`.
 More details can be found in  
https://github.com/llvm/llvm-project/pull/102569. This PR implements the 
frontend support for these options with OpenMP atomic in flang

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


11 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+11-11) 
- (modified) flang/include/flang/Frontend/TargetOptions.h (+5) 
- (modified) flang/include/flang/Optimizer/Dialect/Support/FIRContext.h (+14) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+12) 
- (modified) flang/lib/Lower/Bridge.cpp (+6) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+6-1) 
- (modified) flang/lib/Optimizer/Dialect/Support/FIRContext.cpp (+40) 
- (added) flang/test/Lower/OpenMP/atomic-control-options.f90 (+37) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPAttrDefs.td (+14) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+5-3) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+9) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fd6deb22d404e..c6d8f9106341a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2299,21 +2299,21 @@ def fsymbol_partition_EQ : Joined<["-"], 
"fsymbol-partition=">, Group,
 
 defm atomic_remote_memory : BoolFOption<"atomic-remote-memory",
   LangOpts<"AtomicRemoteMemory">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " atomic operations on remote memory">>;
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, FlangOption], " atomic operations on remote 
memory">>;
 
 defm atomic_fine_grained_memory : BoolFOption<"atomic-fine-grained-memory",
   LangOpts<"AtomicFineGrainedMemory">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " atomic operations on fine-grained memory">>;
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, FlangOption], " atomic operations on 
fine-grained memory">>;
 
 defm atomic_ignore_denormal_mode : BoolFOption<"atomic-ignore-denormal-mode",
   LangOpts<"AtomicIgnoreDenormalMode">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " atomic operations to ignore denormal mode">>;
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, FlangOption], " atomic operations to ignore 
denormal mode">>;
 
 defm memory_profile : OptInCC1FFlag<"memory-profile", "Enable", "Disable", " 
heap memory profiling">;
 def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
@@ -5270,9 +5270,9 @@ defm amdgpu_precise_memory_op
   " precise memory mode (AMDGPU only)">;
 
 def munsafe_fp_atomics : Flag<["-"], "munsafe-fp-atomics">,
-  Visibility<[ClangOption, CC1Option]>, Alias;
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, 
Alias;
 def mno_unsafe_fp_atomics : Flag<["-"], "mno-unsafe-fp-atomics">,
-  Visibility<[ClangOption]>, Alias;
+  Visibility<[ClangOption, FlangOption]>, 
Alias;
 
 def faltivec : Flag<["-"], "faltivec">, Group;
 def fno_altivec : Flag<["-"], "fno-altivec">, Group;
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index 002d8d158abd4..26256fd775f11 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -53,6 +53,11 @@ class TargetOptions {
 
   /// Print verbose assembly
   bool asmVerbose = false;
+
+  /// Atomic Control Options for AMD GPU
+  bool amdgpuIgnoreDenormalMode = false;
+  bool amdgpuRemoteMemory = false;
+  bool amdgpuFineGrainedMemory = false;
 };
 
 } // end namespace Fortran::frontend
diff --git a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h 
b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
index 2df14f83c11e1..ac563bcc402c7 100644
--- a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
+++ b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
@@ -58,10 +58,24 @@ void setTargetCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
 /// Get the target CPU string from the Module or return a null reference.
 llvm::StringRef getTargetCPU(mlir::ModuleOp mod);
 
+// Setters and Getters for atomic control options
+void setAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
+bool getAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
+void setAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
+bool getAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
+void setAmdgpuRemoteMemory(mlir::ModuleOp mod);
+bool getAmdgpuRemoteMemory(mlir::ModuleOp mod);
+
 /// Set the tune CPU for the module. `cpu` must not be deallocated while
 

[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-driver

Author: Anchu Rajendran S (anchuraj)


Changes

Atomic Control Options are used to specify architectural characteristics to 
help lowering of atomic operations. The options used are: 
`-f[no-]atomic-remote-memory`, `-f[no-]atomic-fine-grained-memory`,
 `-f[no-]atomic-ignore-denormal-mode`.
Legacy option `-m[no-]unsafe-fp-atomics` is aliased to
`-f[no-]ignore-denormal-mode`.
 More details can be found in  
https://github.com/llvm/llvm-project/pull/102569. This PR implements the 
frontend support for these options with OpenMP atomic in flang

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


11 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+11-11) 
- (modified) flang/include/flang/Frontend/TargetOptions.h (+5) 
- (modified) flang/include/flang/Optimizer/Dialect/Support/FIRContext.h (+14) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+12) 
- (modified) flang/lib/Lower/Bridge.cpp (+6) 
- (modified) flang/lib/Lower/OpenMP/OpenMP.cpp (+6-1) 
- (modified) flang/lib/Optimizer/Dialect/Support/FIRContext.cpp (+40) 
- (added) flang/test/Lower/OpenMP/atomic-control-options.f90 (+37) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPAttrDefs.td (+14) 
- (modified) mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td (+5-3) 
- (modified) mlir/test/Dialect/OpenMP/ops.mlir (+9) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fd6deb22d404e..c6d8f9106341a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2299,21 +2299,21 @@ def fsymbol_partition_EQ : Joined<["-"], 
"fsymbol-partition=">, Group,
 
 defm atomic_remote_memory : BoolFOption<"atomic-remote-memory",
   LangOpts<"AtomicRemoteMemory">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " atomic operations on remote memory">>;
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, FlangOption], " atomic operations on remote 
memory">>;
 
 defm atomic_fine_grained_memory : BoolFOption<"atomic-fine-grained-memory",
   LangOpts<"AtomicFineGrainedMemory">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " atomic operations on fine-grained memory">>;
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, FlangOption], " atomic operations on 
fine-grained memory">>;
 
 defm atomic_ignore_denormal_mode : BoolFOption<"atomic-ignore-denormal-mode",
   LangOpts<"AtomicIgnoreDenormalMode">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " atomic operations to ignore denormal mode">>;
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, FlangOption], " atomic operations to ignore 
denormal mode">>;
 
 defm memory_profile : OptInCC1FFlag<"memory-profile", "Enable", "Disable", " 
heap memory profiling">;
 def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
@@ -5270,9 +5270,9 @@ defm amdgpu_precise_memory_op
   " precise memory mode (AMDGPU only)">;
 
 def munsafe_fp_atomics : Flag<["-"], "munsafe-fp-atomics">,
-  Visibility<[ClangOption, CC1Option]>, Alias;
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, 
Alias;
 def mno_unsafe_fp_atomics : Flag<["-"], "mno-unsafe-fp-atomics">,
-  Visibility<[ClangOption]>, Alias;
+  Visibility<[ClangOption, FlangOption]>, 
Alias;
 
 def faltivec : Flag<["-"], "faltivec">, Group;
 def fno_altivec : Flag<["-"], "fno-altivec">, Group;
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index 002d8d158abd4..26256fd775f11 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -53,6 +53,11 @@ class TargetOptions {
 
   /// Print verbose assembly
   bool asmVerbose = false;
+
+  /// Atomic Control Options for AMD GPU
+  bool amdgpuIgnoreDenormalMode = false;
+  bool amdgpuRemoteMemory = false;
+  bool amdgpuFineGrainedMemory = false;
 };
 
 } // end namespace Fortran::frontend
diff --git a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h 
b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
index 2df14f83c11e1..ac563bcc402c7 100644
--- a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
+++ b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
@@ -58,10 +58,24 @@ void setTargetCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
 /// Get the target CPU string from the Module or return a null reference.
 llvm::StringRef getTargetCPU(mlir::ModuleOp mod);
 
+// Setters and Getters for atomic control options
+void setAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
+bool getAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
+void setAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
+bool getAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
+void setAmdgpuRemoteMemory(mlir::ModuleOp mod);
+bool getAmdgpuRemoteMemory(mlir::ModuleOp mod);
+
 /// Set the tune CPU for the module. `cpu` must not be deallocated while
 ///

[clang] [clang][analyzer] Update python dependency versions (PR #143433)

2025-06-09 Thread Balazs Benics via cfe-commits

steakhal wrote:

Are there other vulns affecting the other deps? Or more recent vulns we should 
know about the deps you would touch here?

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


[clang] [clang][analyzer] Update python dependency versions (PR #143433)

2025-06-09 Thread via cfe-commits

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


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


[clang] [Clang][NFC][ByteCode] Initialize Function HasBody in constructor (PR #143443)

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

https://github.com/shafik created 
https://github.com/llvm/llvm-project/pull/143443

Static analysis flagged HasBody as not being initialized during construction. 
It looks like an oversight in: https://github.com/llvm/llvm-project/pull/139671

This would be a lot simpler with C++20 which allows in class initialization of 
bit-fields.

>From cbc3cbb2cb07e9d3196bde17d59fa529889d1303 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Mon, 9 Jun 2025 14:35:31 -0700
Subject: [PATCH] [Clang][NFC][ByteCode] Initialize Function HasBody in
 constructor

Static analysis flagged HasBody as not being initialized during construction.
It looks like an oversight in: https://github.com/llvm/llvm-project/pull/139671

This would be a lot simpler with C++20 which allows in class initialization of
bit-fields.
---
 clang/lib/AST/ByteCode/Function.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Function.cpp 
b/clang/lib/AST/ByteCode/Function.cpp
index 9eb6744ea47ad..0e639df3cafba 100644
--- a/clang/lib/AST/ByteCode/Function.cpp
+++ b/clang/lib/AST/ByteCode/Function.cpp
@@ -23,7 +23,7 @@ Function::Function(Program &P, FunctionDeclTy Source, 
unsigned ArgSize,
   ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
   ParamOffsets(std::move(ParamOffsets)), IsValid(false),
   IsFullyCompiled(false), HasThisPointer(HasThisPointer), HasRVO(HasRVO),
-  Defined(false) {
+  HasBody(false), Defined(false) {
   if (const auto *F = dyn_cast(Source)) {
 Variadic = F->isVariadic();
 Immediate = F->isImmediateFunction();

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


[clang] [clang-c] introduce queries on GCC-style inline assembly statements (PR #143424)

2025-06-09 Thread via cfe-commits

https://github.com/dingxiangfei2009 updated 
https://github.com/llvm/llvm-project/pull/143424

>From 4f9e599067c954a3ed3028efdc2abd72aa2b775f Mon Sep 17 00:00:00 2001
From: Xiangfei Ding 
Date: Mon, 9 Jun 2025 13:57:18 +
Subject: [PATCH] [clang-c] introduce queries on GCC-style inline assembly
 statements

We strive for exposing such information using existing stable ABIs.
In doing so, queries are limited to what the original source holds
or the LLVM IR `asm` block would expose in connection with attributes
that the queries are concerned.

Signed-off-by: Xiangfei Ding 
---
 clang/include/clang-c/Index.h   |  93 +-
 clang/test/Index/inline-assembly.c  |  48 +
 clang/tools/c-index-test/c-index-test.c |  52 ++
 clang/tools/libclang/CIndex.cpp | 125 ++--
 clang/tools/libclang/libclang.map   |  10 ++
 5 files changed, 320 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/Index/inline-assembly.c

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index e4cb4327fbaac..340d050654a69 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -36,7 +36,7 @@
 #define CINDEX_VERSION_MAJOR 0
 #define CINDEX_VERSION_MINOR 64
 
-#define CINDEX_VERSION_ENCODE(major, minor) (((major)*1) + ((minor)*1))
+#define CINDEX_VERSION_ENCODE(major, minor) (((major) * 1) + ((minor) * 1))
 
 #define CINDEX_VERSION 
\
   CINDEX_VERSION_ENCODE(CINDEX_VERSION_MAJOR, CINDEX_VERSION_MINOR)
@@ -4495,6 +4495,97 @@ CINDEX_LINKAGE CXStringSet 
*clang_Cursor_getCXXManglings(CXCursor);
  */
 CINDEX_LINKAGE CXStringSet *clang_Cursor_getObjCManglings(CXCursor);
 
+/**
+ * @}
+ */
+
+/**
+ * \defgroup CINDEX_MODULE Inline Assembly introspection
+ *
+ * The functions in this group provide access to information about GCC-style
+ * inline assembly statements.
+ *
+ * @{
+ */
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, return the assembly template string.
+ * As per LLVM IR Assembly Template language, template placeholders for
+ * inputs and outputs are either of the form $N where N is a decimal number
+ * as an index into the input-output specification,
+ * or ${N:M} where N is a decimal number also as an index into the
+ * input-output specification and M is the template argument modifier.
+ * The index N in both cases points into the the total inputs and outputs,
+ * or more specifically, into the list of outputs followed by the inputs,
+ * starting from index 0 as the first available template argument.
+ */
+
+CINDEX_LINKAGE CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, check if the assembly block has goto
+ * labels.
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblyHasGoto(CXCursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, count the number of outputs
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumOutputs(CXCursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, count the number of inputs
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumInputs(CXCursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
+ * to the Index-th input.
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor,
+ unsigned Index,
+ CXString *Constraint,
+ CXCursor *Expr);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
+ * to the Index-th output.
+ */
+
+CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor,
+  unsigned Index,
+  CXString *Constraint,
+  CXCursor *Expr);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, count the clobbers in it.
+ */
+
+unsigned clang_Cursor_getGCCAssemblyNumClobbers(CXCursor Cursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, get the Index-th clobber of it.
+ */
+
+CXString clang_Cursor_getGCCAssemblyClobber(CXCursor Cursor, unsigned Index);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, check if the inline assembly is simple.
+ */
+
+unsigned clang_Cursor_isGCCAssemblySimple(CXCursor Cursor);
+
+/**
+ * Given a CXCursor_GCCAsmStmt cursor, check if the inline assembly is
+ * `volatile`.
+ */
+
+unsigned clang_Cursor_isGCCAssemblyVolatile(CXCursor Cursor);
+
 /**
  * @}
  */
diff --git a/clang/test/Index/inline-assembly.c 
b/clang/test/Index/inline-assembly.c
new file mode 100644
index 0..2223dd2985f51
--- /dev/null
+++ b/clang/test/Index/inline-assembly.c
@@ -0,0 +1,48 @@
+static void inline_assembly_template_regardless_of_target_machine() {
+int tmp;
+asm volatile (
+

[clang] [Clang][NFC][ByteCode] Initialize Function HasBody in constructor (PR #143443)

2025-06-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)


Changes

Static analysis flagged HasBody as not being initialized during construction. 
It looks like an oversight in: https://github.com/llvm/llvm-project/pull/139671

This would be a lot simpler with C++20 which allows in class initialization of 
bit-fields.

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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Function.cpp (+1-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Function.cpp 
b/clang/lib/AST/ByteCode/Function.cpp
index 9eb6744ea47ad..0e639df3cafba 100644
--- a/clang/lib/AST/ByteCode/Function.cpp
+++ b/clang/lib/AST/ByteCode/Function.cpp
@@ -23,7 +23,7 @@ Function::Function(Program &P, FunctionDeclTy Source, 
unsigned ArgSize,
   ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
   ParamOffsets(std::move(ParamOffsets)), IsValid(false),
   IsFullyCompiled(false), HasThisPointer(HasThisPointer), HasRVO(HasRVO),
-  Defined(false) {
+  HasBody(false), Defined(false) {
   if (const auto *F = dyn_cast(Source)) {
 Variadic = F->isVariadic();
 Immediate = F->isImmediateFunction();

``




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


[clang] [clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp (PR #143236)

2025-06-09 Thread Jorge Gorbe Moya via cfe-commits

slackito wrote:

It seems this change has introduced a bug when formatting multiple files in one 
go. Passing a shorter file after a longer one results in a stale length being 
used. It can be reproduced with trivially short files:

```
$ cat ~/a.cc

$ cat ~/b.cc
// a
$ bin/clang-format ~/b.cc ~/a.cc
// a
error: invalid length 5, offset + length (5) is outside the file.
```

This was supposed to be an NFC change so I'm going to revert the patch while 
the problem gets investigated/fixed.

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


[clang] [clang][analyzer] Update python dependency versions (PR #143433)

2025-06-09 Thread via cfe-commits

llvmbot wrote:




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

Author: Nick Sarnie (sarnex)


Changes

We need to make sure we aren't vulnerable to 
[PYSEC-2020-73](https://osv.dev/vulnerability/PYSEC-2020-73) and 
[PYSEC-2019-41](https://osv.dev/vulnerability/PYSEC-2019-41).

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


1 Files Affected:

- (modified) clang/utils/analyzer/requirements.txt (+2-2) 


``diff
diff --git a/clang/utils/analyzer/requirements.txt 
b/clang/utils/analyzer/requirements.txt
index 8ae8bc88ac191..ed09161e5902e 100644
--- a/clang/utils/analyzer/requirements.txt
+++ b/clang/utils/analyzer/requirements.txt
@@ -1,6 +1,6 @@
 graphviz
 humanize
 matplotlib
-pandas
-psutil
+pandas>=1.0.4
+psutil>=5.6.6
 seaborn

``




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


[clang] [clang][analyzer] Update python dependency versions (PR #143433)

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

sarnex wrote:

For this specific `requirements.txt` file, there are the only two 
vulnerabilities I saw.

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


[clang] [NVPTX] Enable OpenCL 3d_image_writes support (PR #143331)

2025-06-09 Thread Artem Belevich via cfe-commits

Artem-B wrote:

@svenvh appears to be the current maintainer of OpenCL in LLVM.


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


@@ -0,0 +1,287 @@
+//===-- WindowsHotPatch.cpp - Support for Windows hotpatching 
-===//
+//
+// 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
+//
+//===--===//
+//
+// Provides support for the Windows "Secure Hot-Patching" feature.
+//
+// Windows contains technology, called "Secure Hot-Patching" (SHP), for 
securely
+// applying hot-patches to a running system. Hot-patches may be applied to the
+// kernel, kernel-mode components, device drivers, user-mode system services,
+// etc.
+//
+// SHP relies on integration between many tools, including compiler, linker,
+// hot-patch generation tools, and the Windows kernel. This file implements 
that
+// part of the workflow needed in compilers / code generators.
+//
+// SHP is not intended for productivity scenarios such as Edit-and-Continue or
+// interactive development. SHP is intended to minimize downtime during
+// installation of Windows OS patches.
+//
+// In order to work with SHP, LLVM must do all of the following:
+//
+// * On some architectures (X86, AMD64), the function prolog must begin with
+//   hot-patchable instructions. This is handled by the MSVC `/hotpatch` option
+//   and the equivalent `-fms-hotpatch` function. This is necessary because we
+//   generally cannot anticipate which functions will need to be patched in the
+//   future. This option ensures that a function can be hot-patched in the
+//   future, but does not actually generate any hot-patch for it.
+//
+// * For a selected set of functions that are being hot-patched (which are
+//   identified using command-line options), LLVM must generate the
+//   `S_HOTPATCHFUNC` CodeView record (symbol). This record indicates that a
+//   function was compiled with hot-patching enabled.
+//
+//   This implementation uses the `MarkedForWindowsHotPatching` attribute to
+//   annotate those functions that were marked for hot-patching by command-line
+//   parameters. The attribute may be specified by a language front-end by
+//   setting an attribute when a function is created in LLVM IR, or it may be
+//   set by passing LLVM arguments.
+//
+// * For those functions that are hot-patched, LLVM must rewrite references to
+//   global variables so that they are indirected through a `__ref_*` pointer
+//   variable.  For each global variable, that is accessed by a hot-patched
+//   function, e.g. `FOO`, a `__ref_FOO` global pointer variable is created and
+//   all references to the original `FOO` are rewritten as dereferences of the
+//   `__ref_FOO` pointer.
+//
+//   Some globals do not need `__ref_*` indirection. The pointer indirection
+//   behavior can be disabled for these globals by marking them with the
+//   `AllowDirectAccessInHotPatchFunction`.
+//
+// References
+//
+// * "Hotpatching on Windows":
+//   
https://techcommunity.microsoft.com/blog/windowsosplatform/hotpatching-on-windows/2959541
+//
+// * "Hotpatch for Windows client now available":
+//   
https://techcommunity.microsoft.com/blog/windows-itpro-blog/hotpatch-for-windows-client-now-available/4399808
+//
+// * "Get hotpatching for Windows Server":
+//   
https://www.microsoft.com/en-us/windows-server/blog/2025/04/24/tired-of-all-the-restarts-get-hotpatching-for-windows-server/
+//
+//===--===//
+
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/DIBuilder.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "windows-secure-hot-patch"
+
+// A file containing list of mangled function names to mark for hot patching.
+static cl::opt LLVMMSSecureHotPatchFunctionsFile(
+"ms-secure-hotpatch-functions-file", cl::value_desc("filename"),
+cl::desc("A file containing list of mangled function names to mark for "
+ "Windows Secure Hot-Patching"));
+
+// A list of mangled function names to mark for hot patching.
+static cl::list LLVMMSSecureHotPatchFunctionsList(
+"ms-secure-hotpatch-functions-list", cl::value_desc("list"),
+cl::desc("A list of mangled function names to mark for Windows Secure "
+ "Hot-Patching"),
+cl::CommaSeparated);
+
+namespace {
+
+class WindowsSecureHotPatching : public ModulePass {
+  struct GlobalVariableUse {
+GlobalVariable *GV;
+Instruction *User;
+unsigned Op;
+  };
+
+public:
+  static char ID;
+
+  WindowsSecureHotPatching() : ModuleP

[clang] [clang][analyzer] Update python dependency versions (PR #143433)

2025-06-09 Thread Balazs Benics via cfe-commits

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

Thanks for the patch. Merge it at your convinience.

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


[clang] [OpenMP 60] Initial parsing/sema for `need_device_addr` modifier on `adjust_args` clause (PR #143442)

2025-06-09 Thread Fazlay Rabbi via cfe-commits

https://github.com/mdfazlay created 
https://github.com/llvm/llvm-project/pull/143442


Adds initial parsing and semantic analysis for `need_device_addr` modifier on 
`adjust_args` clause.

>From a117e1a3f089b7d92a5df082a2ba584bee57f7d3 Mon Sep 17 00:00:00 2001
From: Fazlay Rabbi 
Date: Mon, 9 Jun 2025 14:12:24 -0700
Subject: [PATCH] [OpenMP 60] Initial parsing/sema for `need_device_addr`
 modifier on `adjust_args` clause

Adds initial parsing and semantic analysis for `need_device_addr`
modifier on `adjust_args` clause.
---
 clang/include/clang/Basic/Attr.td |  1 +
 .../clang/Basic/DiagnosticParseKinds.td   |  5 ++--
 clang/include/clang/Basic/OpenMPKinds.def |  1 +
 clang/include/clang/Sema/SemaOpenMP.h |  1 +
 clang/lib/AST/AttrImpl.cpp|  6 +
 clang/lib/Parse/ParseOpenMP.cpp   | 19 +-
 clang/lib/Sema/SemaOpenMP.cpp |  5 
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 11 ++--
 .../declare_variant_clauses_ast_print.cpp | 26 ---
 .../declare_variant_clauses_messages.cpp  | 24 -
 10 files changed, 71 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f889e41c8699f..c8e6f7aad5459 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4608,6 +4608,7 @@ def OMPDeclareVariant : InheritableAttr {
 OMPTraitInfoArgument<"TraitInfos">,
 VariadicExprArgument<"AdjustArgsNothing">,
 VariadicExprArgument<"AdjustArgsNeedDevicePtr">,
+VariadicExprArgument<"AdjustArgsNeedDeviceAddr">,
 VariadicOMPInteropInfoArgument<"AppendArgs">,
   ];
   let AdditionalMembers = [{
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 3aa36ad59d0b9..64931ae8f72a9 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1581,8 +1581,9 @@ def err_omp_unexpected_append_op : Error<
   "unexpected operation specified in 'append_args' clause, expected 
'interop'">;
 def err_omp_unexpected_execution_modifier : Error<
   "unexpected 'execution' modifier in non-executable context">;
-def err_omp_unknown_adjust_args_op : Error<
-  "incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'">;
+def err_omp_unknown_adjust_args_op
+: Error<"incorrect adjust_args type, expected 'need_device_ptr'%select{|, "
+"'need_device_addr',}0 or 'nothing'">;
 def err_omp_declare_variant_wrong_clause : Error<
   "expected %select{'match'|'match', 'adjust_args', or 'append_args'}0 clause "
   "on 'omp declare variant' directive">;
diff --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index b0de65df7e397..2b1dc1e0121b2 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -214,6 +214,7 @@ OPENMP_ORIGINAL_SHARING_MODIFIER(default)
 // Adjust-op kinds for the 'adjust_args' clause.
 OPENMP_ADJUST_ARGS_KIND(nothing)
 OPENMP_ADJUST_ARGS_KIND(need_device_ptr)
+OPENMP_ADJUST_ARGS_KIND(need_device_addr)
 
 // Binding kinds for the 'bind' clause.
 OPENMP_BIND_KIND(teams)
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 6498390fe96f7..be6bec2068784 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -849,6 +849,7 @@ class SemaOpenMP : public SemaBase {
   FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI,
   ArrayRef AdjustArgsNothing,
   ArrayRef AdjustArgsNeedDevicePtr,
+  ArrayRef AdjustArgsNeedDeviceAddr,
   ArrayRef AppendArgs, SourceLocation AdjustArgsLoc,
   SourceLocation AppendArgsLoc, SourceRange SR);
 
diff --git a/clang/lib/AST/AttrImpl.cpp b/clang/lib/AST/AttrImpl.cpp
index fefb8f55a9ee2..5875a925d3fb0 100644
--- a/clang/lib/AST/AttrImpl.cpp
+++ b/clang/lib/AST/AttrImpl.cpp
@@ -224,6 +224,12 @@ void OMPDeclareVariantAttr::printPrettyPragma(
 PrintExprs(adjustArgsNeedDevicePtr_begin(), adjustArgsNeedDevicePtr_end());
 OS << ")";
   }
+  if (adjustArgsNeedDeviceAddr_size()) {
+OS << " adjust_args(need_device_addr:";
+PrintExprs(adjustArgsNeedDeviceAddr_begin(),
+   adjustArgsNeedDeviceAddr_end());
+OS << ")";
+  }
 
   auto PrintInteropInfo = [&OS](OMPInteropInfo *Begin, OMPInteropInfo *End) {
 for (OMPInteropInfo *I = Begin; I != End; ++I) {
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index e41e5ba8596b9..dd184ba6ac607 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1483,6 +1483,7 @@ void 
Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
   OMPTraitInfo &TI = ASTCtx.getNewOMPTraitInfo();
   SmallVector AdjustNothing;
   SmallVector AdjustNeedDevicePtr;
+  SmallVector AdjustNeedDeviceAddr;
   SmallVector

[clang] [OpenMP 60] Initial parsing/sema for `need_device_addr` modifier on `adjust_args` clause (PR #143442)

2025-06-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fazlay Rabbi (mdfazlay)


Changes


Adds initial parsing and semantic analysis for `need_device_addr` modifier on 
`adjust_args` clause.

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


10 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+1) 
- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+3-2) 
- (modified) clang/include/clang/Basic/OpenMPKinds.def (+1) 
- (modified) clang/include/clang/Sema/SemaOpenMP.h (+1) 
- (modified) clang/lib/AST/AttrImpl.cpp (+6) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+12-7) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+5) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+9-2) 
- (modified) clang/test/OpenMP/declare_variant_clauses_ast_print.cpp (+16-10) 
- (modified) clang/test/OpenMP/declare_variant_clauses_messages.cpp (+17-7) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f889e41c8699f..c8e6f7aad5459 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4608,6 +4608,7 @@ def OMPDeclareVariant : InheritableAttr {
 OMPTraitInfoArgument<"TraitInfos">,
 VariadicExprArgument<"AdjustArgsNothing">,
 VariadicExprArgument<"AdjustArgsNeedDevicePtr">,
+VariadicExprArgument<"AdjustArgsNeedDeviceAddr">,
 VariadicOMPInteropInfoArgument<"AppendArgs">,
   ];
   let AdditionalMembers = [{
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 3aa36ad59d0b9..64931ae8f72a9 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1581,8 +1581,9 @@ def err_omp_unexpected_append_op : Error<
   "unexpected operation specified in 'append_args' clause, expected 
'interop'">;
 def err_omp_unexpected_execution_modifier : Error<
   "unexpected 'execution' modifier in non-executable context">;
-def err_omp_unknown_adjust_args_op : Error<
-  "incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'">;
+def err_omp_unknown_adjust_args_op
+: Error<"incorrect adjust_args type, expected 'need_device_ptr'%select{|, "
+"'need_device_addr',}0 or 'nothing'">;
 def err_omp_declare_variant_wrong_clause : Error<
   "expected %select{'match'|'match', 'adjust_args', or 'append_args'}0 clause "
   "on 'omp declare variant' directive">;
diff --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index b0de65df7e397..2b1dc1e0121b2 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -214,6 +214,7 @@ OPENMP_ORIGINAL_SHARING_MODIFIER(default)
 // Adjust-op kinds for the 'adjust_args' clause.
 OPENMP_ADJUST_ARGS_KIND(nothing)
 OPENMP_ADJUST_ARGS_KIND(need_device_ptr)
+OPENMP_ADJUST_ARGS_KIND(need_device_addr)
 
 // Binding kinds for the 'bind' clause.
 OPENMP_BIND_KIND(teams)
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 6498390fe96f7..be6bec2068784 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -849,6 +849,7 @@ class SemaOpenMP : public SemaBase {
   FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI,
   ArrayRef AdjustArgsNothing,
   ArrayRef AdjustArgsNeedDevicePtr,
+  ArrayRef AdjustArgsNeedDeviceAddr,
   ArrayRef AppendArgs, SourceLocation AdjustArgsLoc,
   SourceLocation AppendArgsLoc, SourceRange SR);
 
diff --git a/clang/lib/AST/AttrImpl.cpp b/clang/lib/AST/AttrImpl.cpp
index fefb8f55a9ee2..5875a925d3fb0 100644
--- a/clang/lib/AST/AttrImpl.cpp
+++ b/clang/lib/AST/AttrImpl.cpp
@@ -224,6 +224,12 @@ void OMPDeclareVariantAttr::printPrettyPragma(
 PrintExprs(adjustArgsNeedDevicePtr_begin(), adjustArgsNeedDevicePtr_end());
 OS << ")";
   }
+  if (adjustArgsNeedDeviceAddr_size()) {
+OS << " adjust_args(need_device_addr:";
+PrintExprs(adjustArgsNeedDeviceAddr_begin(),
+   adjustArgsNeedDeviceAddr_end());
+OS << ")";
+  }
 
   auto PrintInteropInfo = [&OS](OMPInteropInfo *Begin, OMPInteropInfo *End) {
 for (OMPInteropInfo *I = Begin; I != End; ++I) {
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index e41e5ba8596b9..dd184ba6ac607 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1483,6 +1483,7 @@ void 
Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
   OMPTraitInfo &TI = ASTCtx.getNewOMPTraitInfo();
   SmallVector AdjustNothing;
   SmallVector AdjustNeedDevicePtr;
+  SmallVector AdjustNeedDeviceAddr;
   SmallVector AppendArgs;
   SourceLocation AdjustArgsLoc, AppendArgsLoc;
 
@@ -1515,11 +1516,14 @@ void 
Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
 SmallVector Vars;
 IsError = ParseOpenMPVarList(OMPD_declare_variant, OMPC_adjust_args,
 

[clang] [clang][NFC] Remove dead PassTypeToPlacementDelete field (PR #143448)

2025-06-09 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Oliver Hunt (ojhunt)


Changes

The CallDeleteDuringNew::PassTypeToPlacementDelete field became unneeded during 
the many refactorings of P2719 but I didn't actually remove it.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGExprCXX.cpp (-2) 


``diff
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 024254b0affe4..359e30cb8f5cd 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1446,8 +1446,6 @@ namespace {
 unsigned NumPlacementArgs : 30;
 LLVM_PREFERRED_TYPE(AlignedAllocationMode)
 unsigned PassAlignmentToPlacementDelete : 1;
-LLVM_PREFERRED_TYPE(TypeAwareAllocationMode)
-unsigned PassTypeToPlacementDelete : 1;
 const FunctionDecl *OperatorDelete;
 RValueTy TypeIdentity;
 ValueTy Ptr;

``




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


[clang] [clang][NFC] Remove dead PassTypeToPlacementDelete field (PR #143448)

2025-06-09 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt created 
https://github.com/llvm/llvm-project/pull/143448

The CallDeleteDuringNew::PassTypeToPlacementDelete field became unneeded during 
the many refactorings of P2719 but I didn't actually remove it.

>From c1fa0ea448210ab10e71bd7b2f4dc4d575056b39 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Mon, 9 Jun 2025 14:53:17 -0700
Subject: [PATCH] [clang][NFC] Remove dead
 CallDeleteDuringNew::PassTypeToPlacementDelete field

This field became unneeded during the many refactorings of P2719 but
I didn't actually remove it.
---
 clang/lib/CodeGen/CGExprCXX.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 024254b0affe4..359e30cb8f5cd 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1446,8 +1446,6 @@ namespace {
 unsigned NumPlacementArgs : 30;
 LLVM_PREFERRED_TYPE(AlignedAllocationMode)
 unsigned PassAlignmentToPlacementDelete : 1;
-LLVM_PREFERRED_TYPE(TypeAwareAllocationMode)
-unsigned PassTypeToPlacementDelete : 1;
 const FunctionDecl *OperatorDelete;
 RValueTy TypeIdentity;
 ValueTy Ptr;

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-06-09 Thread Oliver Hunt via cfe-commits


@@ -1434,10 +1446,13 @@ namespace {
   QualType ArgType;
 };
 
-unsigned NumPlacementArgs : 31;
-LLVM_PREFERRED_TYPE(bool)
+unsigned NumPlacementArgs : 30;
+LLVM_PREFERRED_TYPE(AlignedAllocationMode)
 unsigned PassAlignmentToPlacementDelete : 1;
+LLVM_PREFERRED_TYPE(TypeAwareAllocationMode)
+unsigned PassTypeToPlacementDelete : 1;

ojhunt wrote:

#143448

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


[clang] [clang] Check constexpr int->enum conversions consistently. (PR #143034)

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


@@ -2513,6 +2513,9 @@ void testValueInRangeOfEnumerationValues() {
   // expected-error@-1 {{constexpr variable 'x2' must be initialized by a 
constant expression}}
   // expected-note@-2 {{integer value 8 is outside the valid range of values 
[-8, 7] for the enumeration type 'E1'}}
   E1 x2b = static_cast(8); // ok, not a constant expression context
+  static_assert(static_cast(8), "");

shafik wrote:

I guess these are the cases my previous checks missed?

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


[clang] [Clang] fix missing source location for ':' error in macro-expanded case statements (PR #143460)

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

https://github.com/efriedma-quic commented:

This seems like a more general issue... some examples:

```
#define D foo bar
enum { D };
```

```
#define D foo bar
void f() { int a[2]; auto [D] = a; }
```

```
#define D  class X;
X D;
```

```
#define D C::{
class C { D }};
```

Can we come up with some kind of generalized solution?

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


[clang] [Clang] fix missing source location for ':' error in macro-expanded case statements (PR #143460)

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

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


[clang] [Clang] fix missing source location for ':' error in macro-expanded case statements (PR #143460)

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


@@ -833,9 +833,23 @@ StmtResult Parser::ParseCaseStatement(ParsedStmtContext 
StmtCtx,
   << FixItHint::CreateReplacement(ColonLoc, ":");
 } else {
   SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
+  SourceLocation ExprLoc =
+  LHS.get() ? LHS.get()->getExprLoc() : SourceLocation();
+
+  if (ExpectedLoc.isInvalid() && ExprLoc.isMacroID()) {
+ExpectedLoc = PP.getSourceManager().getSpellingLoc(ExprLoc);
+  }
+
   Diag(ExpectedLoc, diag::err_expected_after)
   << "'case'" << tok::colon
   << FixItHint::CreateInsertion(ExpectedLoc, ":");
+
+  if (ExprLoc.isMacroID()) {
+Diag(ExprLoc, diag::note_macro_expansion)

efriedma-quic wrote:

We usually let the diagnostic infrastructure generate this sort of note; trying 
to write it out is likely to get it wrong.

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


@@ -0,0 +1,599 @@
+//===-- WindowsHotPatch.cpp - Support for Windows hotpatching 
-===//
+//
+// 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
+//
+//===--===//
+//
+// Provides support for the Windows "Secure Hot-Patching" feature.
+//
+// Windows contains technology, called "Secure Hot-Patching" (SHP), for 
securely
+// applying hot-patches to a running system. Hot-patches may be applied to the
+// kernel, kernel-mode components, device drivers, user-mode system services,
+// etc.
+//
+// SHP relies on integration between many tools, including compiler, linker,
+// hot-patch generation tools, and the Windows kernel. This file implements 
that
+// part of the workflow needed in compilers / code generators.
+//
+// SHP is not intended for productivity scenarios such as Edit-and-Continue or
+// interactive development. SHP is intended to minimize downtime during
+// installation of Windows OS patches.
+//
+// In order to work with SHP, LLVM must do all of the following:
+//
+// * On some architectures (X86, AMD64), the function prolog must begin with
+//   hot-patchable instructions. This is handled by the MSVC `/hotpatch` option
+//   and the equivalent `-fms-hotpatch` function. This is necessary because we
+//   generally cannot anticipate which functions will need to be patched in the
+//   future. This option ensures that a function can be hot-patched in the
+//   future, but does not actually generate any hot-patch for it.
+//
+// * For a selected set of functions that are being hot-patched (which are
+//   identified using command-line options), LLVM must generate the
+//   `S_HOTPATCHFUNC` CodeView record (symbol). This record indicates that a
+//   function was compiled with hot-patching enabled.
+//
+//   This implementation uses the `MarkedForWindowsHotPatching` attribute to
+//   annotate those functions that were marked for hot-patching by command-line
+//   parameters. The attribute may be specified by a language front-end by
+//   setting an attribute when a function is created in LLVM IR, or it may be
+//   set by passing LLVM arguments.
+//
+// * For those functions that are hot-patched, LLVM must rewrite references to
+//   global variables so that they are indirected through a `__ref_*` pointer
+//   variable.  For each global variable, that is accessed by a hot-patched
+//   function, e.g. `FOO`, a `__ref_FOO` global pointer variable is created and
+//   all references to the original `FOO` are rewritten as dereferences of the
+//   `__ref_FOO` pointer.
+//
+//   Some globals do not need `__ref_*` indirection. The pointer indirection
+//   behavior can be disabled for these globals by marking them with the
+//   `AllowDirectAccessInHotPatchFunction`.
+//
+// References
+//
+// * "Hotpatching on Windows":
+//   
https://techcommunity.microsoft.com/blog/windowsosplatform/hotpatching-on-windows/2959541
+//
+// * "Hotpatch for Windows client now available":
+//   
https://techcommunity.microsoft.com/blog/windows-itpro-blog/hotpatch-for-windows-client-now-available/4399808
+//
+// * "Get hotpatching for Windows Server":
+//   
https://www.microsoft.com/en-us/windows-server/blog/2025/04/24/tired-of-all-the-restarts-get-hotpatching-for-windows-server/
+//
+//===--===//
+
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/DIBuilder.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "windows-secure-hot-patch"
+
+// A file containing list of mangled function names to mark for hot patching.
+static cl::opt LLVMMSSecureHotPatchFunctionsFile(
+"ms-secure-hotpatch-functions-file", cl::value_desc("filename"),
+cl::desc("A file containing list of mangled function names to mark for "
+ "Windows Secure Hot-Patching"));
+
+// A list of mangled function names to mark for hot patching.
+static cl::list LLVMMSSecureHotPatchFunctionsList(
+"ms-secure-hotpatch-functions-list", cl::value_desc("list"),
+cl::desc("A list of mangled function names to mark for Windows Secure "
+ "Hot-Patching"),
+cl::CommaSeparated);
+
+namespace {
+
+struct GlobalVariableUse {
+  // GlobalVariable *GV;
+  Instruction *User;
+  unsigned Op;
+};
+
+class WindowsSecureHotPatching : public ModulePass {
+public:
+  static char ID;
+
+  WindowsSecureHotPatching() : ModulePass(ID)

[clang] [Clang][NFC][ByteCode] Initialize Function HasBody in constructor (PR #143443)

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

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


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


[clang] 9a894ae - [clang-format] Parse JSON outermost l_brace as braced list brace (#143327)

2025-06-09 Thread via cfe-commits

Author: Owen Pan
Date: 2025-06-09T20:34:12-07:00
New Revision: 9a894ae794f26cdd0822c4cea99e2486e3523189

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

LOG: [clang-format] Parse JSON outermost l_brace as braced list brace (#143327)

See
https://github.com/llvm/llvm-project/issues/65400#issuecomment-2922181979.

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestRawStrings.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 4e4e48f90a89f..424b6dbc0da79 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -2248,7 +2248,6 @@ unsigned ContinuationIndenter::reformatRawStringLiteral(
   /*Status=*/nullptr);
 
   auto NewCode = applyAllReplacements(RawText, Fixes.first);
-  tooling::Replacements NoFixes;
   if (!NewCode)
 return addMultilineToken(Current, State);
   if (!DryRun) {

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 4acfe0cc50c25..61b84126fe1b9 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -269,7 +269,7 @@ void UnwrappedLineParser::parseFile() {
   bool MustBeDeclaration = !Line->InPPDirective && !Style.isJavaScript();
   ScopedDeclarationState DeclarationState(*Line, DeclarationScopeStack,
   MustBeDeclaration);
-  if (Style.isTextProto())
+  if (Style.isTextProto() || (Style.isJson() && FormatTok->IsFirst))
 parseBracedList();
   else
 parseLevel();

diff  --git a/clang/unittests/Format/FormatTestRawStrings.cpp 
b/clang/unittests/Format/FormatTestRawStrings.cpp
index 3f09c7b6086e5..5e8737d65666a 100644
--- a/clang/unittests/Format/FormatTestRawStrings.cpp
+++ b/clang/unittests/Format/FormatTestRawStrings.cpp
@@ -1002,9 +1002,11 @@ TEST_F(FormatTestRawStrings, Json) {
   };
 
   EXPECT_EQ("json = R\"json({\n"
+"\"foo\": \"bar\",\n"
 "\"str\": \"test\"\n"
 "  })json\";",
 format("json = R\"json({\n"
+   "  \"foo\": \"bar\",\n"
"  \"str\": \"test\"\n"
"})json\";",
Style));

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index d64e34de1fcf4..873c6c492d18c 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -4105,6 +4105,20 @@ TEST_F(TokenAnnotatorTest, BitFieldColon) {
   EXPECT_TOKEN(Tokens[5], tok::colon, TT_BitFieldColon);
 }
 
+TEST_F(TokenAnnotatorTest, JsonCodeInRawString) {
+  auto Tokens = annotate("{\n"
+ "  \"foo\": \"bar\",\n"
+ "  \"str\": \"test\"\n"
+ "}",
+ getLLVMStyle(FormatStyle::LK_Json));
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_brace, TT_DictLiteral);
+  EXPECT_TOKEN(Tokens[1], tok::string_literal, TT_SelectorName);
+  EXPECT_TOKEN(Tokens[2], tok::colon, TT_DictLiteral);
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_SelectorName);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_DictLiteral);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang



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


[clang] Remove delayed typo expressions (PR #143423)

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


@@ -4920,6 +4914,11 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind 
DKind,
 ModifierFound = true;
   } else {
 StepFound = parseStepSize(*this, Data, Kind, Tok.getLocation());
+if (!StepFound) {

shafik wrote:

I am curious why this new code is needed.

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


[clang] Remove delayed typo expressions (PR #143423)

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


@@ -14055,8 +14055,10 @@ FunctionDecl 
*Sema::ResolveSingleFunctionTemplateSpecialization(
 //   specified and it, along with any default template arguments,
 //   identifies a single function template specialization, then the
 //   template-id is an lvalue for the function template specialization.
-FunctionTemplateDecl *FunctionTemplate
-  = cast((*I)->getUnderlyingDecl());
+FunctionTemplateDecl *FunctionTemplate =
+dyn_cast((*I)->getUnderlyingDecl());

shafik wrote:

Curious, why the change to `dyn_cast`?

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


[clang] [clang-format] Parse JSON outermost l_brace as braced list brace (PR #143327)

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

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


[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #143408)

2025-06-09 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 approved this pull request.

LGTM now!

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


[clang] [clang] Use llvm::count (NFC) (PR #143228)

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

https://github.com/shafik commented:

You should always have a summary, for this one it could have simply been 
"replace std::count with llvm::count in Sema::CheckBaseSpecifier"

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


[clang] [Clang] Explain why a type is not replaceable. (PR #143265)

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


@@ -1763,27 +1763,39 @@ def err_user_defined_msg_constexpr : Error<
   "constant expression">;
 
 // Type traits explanations
-def note_unsatisfied_trait : Note<"%0 is not %enum_select{"
-  "%TriviallyRelocatable{trivially 
relocatable}|"
-  "%TriviallyCopyable{trivially copyable}"
-  "}1">;
+def note_unsatisfied_trait
+: Note<"%0 is not %enum_select{"
+   "%TriviallyRelocatable{trivially relocatable}|"
+   "%Replaceable{replaceable}|"
+   "%TriviallyCopyable{trivially copyable}"
+   "}1">;
 
 def note_unsatisfied_trait_reason
 : Note<"because it "
"%enum_select{"
"%Ref{is a reference type}|"
+   "%Const{is const}|"
+   "%Volatile{is volatile}|"
"%HasArcLifetime{has an ARC lifetime qualifier}|"
"%VLA{is a variably-modified type}|"
"%VBase{has a virtual base %1}|"
+   "%NotScalarOrClass{not %select{a|an array of objects of}1 scalar or 
"

shafik wrote:

I don't see a test for the `an array of objects` case

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


[clang] [Sema] Implement fix as suggested by FIXME (PR #143142)

2025-06-09 Thread via cfe-commits

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


[clang] b9d4132 - [clang][CFG] Fix assertion failure in checkIncorrectLogicOperator (#142897)

2025-06-09 Thread via cfe-commits

Author: Ziqing Luo
Date: 2025-06-10T11:54:01+08:00
New Revision: b9d41328c6c60c622fe5737f449e568f1ee4ec8f

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

LOG: [clang][CFG] Fix assertion failure in checkIncorrectLogicOperator (#142897)

`checkIncorrectLogicOperator` checks if an expression, for example `x !=
0 || x != 1.0`, is always true or false by comparing the two literals
`0` and `1.0`. But in case `x` is a 16-bit float, the two literals have
distinct types---16-bit float and double, respectively. Directly
comparing `APValue`s extracted from the two literals results in an
assertion failure because of their distinct types.

This commit fixes the issue by doing a conversion from the "smaller" one
to the "bigger" one. The two literals must be compatible because both of
them are comparing with `x`.

rdar://152456316

Added: 
clang/test/Sema/warn-unreachable_crash.cpp

Modified: 
clang/lib/Analysis/CFG.cpp

Removed: 




diff  --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 7f37a8b18d46e..cf7595952be27 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -1261,6 +1261,28 @@ class CFGBuilder {
 L2Result.Val.getKind() == APValue::Float) {
   llvm::APFloat L1 = L1Result.Val.getFloat();
   llvm::APFloat L2 = L2Result.Val.getFloat();
+  // Note that L1 and L2 do not necessarily have the same type.  For 
example
+  // `x != 0 || x != 1.0`, if `x` is a float16, the two literals `0` and
+  // `1.0` are float16 and double respectively.  In this case, we should do
+  // a conversion before comparing L1 and L2.  Their types must be
+  // compatible since they are comparing with the same DRE.
+  int Order = Context->getFloatingTypeSemanticOrder(NumExpr1->getType(),
+NumExpr2->getType());
+  bool Ignored = false;
+
+  if (Order > 0) {
+// type rank L1 > L2:
+if (llvm::APFloat::opOK !=
+L2.convert(L1.getSemantics(), llvm::APFloat::rmNearestTiesToEven,
+   &Ignored))
+  return {};
+  } else if (Order < 0)
+// type rank L1 < L2:
+if (llvm::APFloat::opOK !=
+L1.convert(L2.getSemantics(), llvm::APFloat::rmNearestTiesToEven,
+   &Ignored))
+  return {};
+
   llvm::APFloat MidValue = L1;
   MidValue.add(L2, llvm::APFloat::rmNearestTiesToEven);
   MidValue.divide(llvm::APFloat(MidValue.getSemantics(), "2.0"),

diff  --git a/clang/test/Sema/warn-unreachable_crash.cpp 
b/clang/test/Sema/warn-unreachable_crash.cpp
new file mode 100644
index 0..628abcc83f810
--- /dev/null
+++ b/clang/test/Sema/warn-unreachable_crash.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -verify -Wunreachable-code %s
+
+// Previously this test will crash
+static void test(__fp16& x) {
+  if (x != 0 || x != 1.0) { // expected-note{{}} no-crash
+  x = 0.9;
+} else
+  x = 0.8; // expected-warning{{code will never be executed}}
+}
+
+static void test2(__fp16& x) {
+  if (x != 1 && x == 1.0) { // expected-note{{}} no-crash
+  x = 0.9; // expected-warning{{code will never be executed}}
+} else
+  x = 0.8;
+}



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


[clang] [clang][CFG] Fix assertion failure in checkIncorrectLogicOperator (PR #142897)

2025-06-09 Thread Ziqing Luo via cfe-commits

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


[clang] 0123ee5 - [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (#143408)

2025-06-09 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2025-06-09T20:55:50-07:00
New Revision: 0123ee51ef3290466c6d743aac2932b23655aa04

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

LOG: [alpha.webkit.NoUnretainedMemberChecker] Recognize 
NS_REQUIRES_PROPERTY_DEFINITIONS (#143408)

Allow @property of a raw pointer when NS_REQUIRES_PROPERTY_DEFINITIONS
is specified on the interface since such an interface does not
automatically synthesize raw pointer ivars.

Also emit a warning for @property(assign) and
@property(unsafe_unretained) under ARC as well as when explicitly
synthesizing a unsafe raw pointer property.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
clang/test/Analysis/Checkers/WebKit/unretained-members-arc.mm
clang/test/Analysis/Checkers/WebKit/unretained-members.mm

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index cd33476344a34..72199af2f80a5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -236,6 +236,7 @@ std::optional isUnchecked(const QualType T) {
 void RetainTypeChecker::visitTranslationUnitDecl(
 const TranslationUnitDecl *TUD) {
   IsARCEnabled = TUD->getLangOpts().ObjCAutoRefCount;
+  DefaultSynthProperties = TUD->getLangOpts().ObjCDefaultSynthProperties;
 }
 
 void RetainTypeChecker::visitTypedef(const TypedefDecl *TD) {

diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index f9fcfe9878d54..3c9560cb8059b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -76,12 +76,14 @@ class RetainTypeChecker {
   llvm::DenseSet CFPointees;
   llvm::DenseSet RecordlessTypes;
   bool IsARCEnabled{false};
+  bool DefaultSynthProperties{true};
 
 public:
   void visitTranslationUnitDecl(const TranslationUnitDecl *);
   void visitTypedef(const TypedefDecl *);
   bool isUnretained(const QualType, bool ignoreARC = false);
   bool isARCEnabled() const { return IsARCEnabled; }
+  bool defaultSynthProperties() const { return DefaultSynthProperties; }
 };
 
 /// \returns true if \p Class is NS or CF objects AND not retained, false if

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index b1350b9093021..8faf6a219450a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -28,6 +28,7 @@ class RawPtrRefMemberChecker
 private:
   BugType Bug;
   mutable BugReporter *BR;
+  mutable llvm::DenseSet IvarDeclsToIgnore;
 
 protected:
   mutable std::optional RTC;
@@ -36,7 +37,8 @@ class RawPtrRefMemberChecker
   RawPtrRefMemberChecker(const char *description)
   : Bug(this, description, "WebKit coding guidelines") {}
 
-  virtual std::optional isUnsafePtr(QualType) const = 0;
+  virtual std::optional isUnsafePtr(QualType,
+  bool ignoreARC = false) const = 0;
   virtual const char *typeName() const = 0;
   virtual const char *invariant() const = 0;
 
@@ -138,6 +140,8 @@ class RawPtrRefMemberChecker
   return;
 }
 if (auto *ID = dyn_cast(CD)) {
+  for (auto *PropImpl : ID->property_impls())
+visitPropImpl(CD, PropImpl);
   for (auto *Ivar : ID->ivars())
 visitIvarDecl(CD, Ivar);
   return;
@@ -148,6 +152,10 @@ class RawPtrRefMemberChecker
  const ObjCIvarDecl *Ivar) const {
 if (BR->getSourceManager().isInSystemHeader(Ivar->getLocation()))
   return;
+
+if (IvarDeclsToIgnore.contains(Ivar))
+  return;
+
 auto QT = Ivar->getType();
 const Type *IvarType = QT.getTypePtrOrNull();
 if (!IvarType)
@@ -157,6 +165,8 @@ class RawPtrRefMemberChecker
 if (!IsUnsafePtr || !*IsUnsafePtr)
   return;
 
+IvarDeclsToIgnore.insert(Ivar);
+
 if (auto *MemberCXXRD = IvarType->getPointeeCXXRecordDecl())
   reportBug(Ivar, IvarType, MemberCXXRD, CD);
 else if (auto *ObjCDecl = getObjCDecl(IvarType))
@@ -167,13 +177,15 @@ class RawPtrRefMemberChecker
  const ObjCPropertyDecl *PD) const {
 if (BR->getSourceManager().isInSystemHeader(PD->getLocation()))
   return;
-auto QT = PD->getType();
-const Type *PropType 

[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #143408)

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

rniwa wrote:

Thank for you all the reviews!

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


[clang] [alpha.webkit.NoUnretainedMemberChecker] Recognize NS_REQUIRES_PROPERTY_DEFINITIONS (PR #143408)

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

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


[clang] [clang-format] Stop moving lambda to new line only to indent it more. (PR #141576)

2025-06-09 Thread via cfe-commits

rmarker wrote:

Ping @owenca, @mydeveloperday.

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


[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)

2025-06-09 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,193 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --output=%t --format=json --executor=standalone %s
+// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.json
+
+struct Foo;
+
+// This is a nice class.
+// It has some nice methods and fields.
+// @brief This is a brief description.
+struct MyClass {
+  int PublicField;
+
+  int myMethod(int MyParam);
+  static void staticMethod();
+  const int& getConst();
+  
+  enum Color {
+RED,
+GREEN,
+BLUE = 5
+  };
+  
+  typedef int MyTypedef;
+  
+  class NestedClass;
+protected:
+  int protectedMethod();
+
+  int ProtectedField;
+};
+
+// CHECK:   {
+// CHECK-NEXT:"Description": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:   "FullComment": {
+// CHECK-NEXT: "Children": [
+// CHECK-NEXT:   {
+// CHECK-NEXT: "ParagraphComment": {
+// CHECK-NEXT:   "Children": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "TextComment": " This is a nice class."
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "TextComment": " It has some nice methods and 
fields."
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "TextComment": ""
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK:   {
+// CHECK-NEXT: "BlockCommandComment": {
+// CHECK-NEXT:   "Children": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "ParagraphComment": {
+// CHECK-NEXT: "Children": [
+// CHECK-NEXT:   { 
+// CHECK-NEXT: "TextComment": " This is a brief 
description." 
+// CHECK-NEXT:   }
+// CHECK:   "Command": "brief"
+// CHECK: "Enums": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Location": {
+// CHECK-NEXT:  "Filename": "{{.*}}class.cpp",
+// CHECK-NEXT:  "LineNumber": 17
+// CHECK-NEXT:},
+// CHECK-NEXT:"Members": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "RED",
+// CHECK-NEXT:"Value": "0"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "GREEN",
+// CHECK-NEXT:"Value": "1"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "BLUE",
+// CHECK-NEXT:"ValueExpr": "5"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"Name": "Color",
+// CHECK-NEXT:"Namespace": [
+// CHECK-NEXT:  "MyClass",
+// CHECK-NEXT:  "GlobalNamespace"
+// CHECK-NEXT:],
+// CHECK-NEXT:"Scoped": false,
+// CHECK-NEXT:"USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// COM:   FIXME: FullName is not emitted correctly.
+// CHECK-NEXT:"FullName": "",
+// CHECK-NEXT:"IsTypedef": false,
+// CHECK-NEXT:"Location": {
+// CHECK-NEXT:  "Filename": "{{.*}}class.cpp",
+// CHECK-NEXT:  "LineNumber": 10
+// CHECK-NEXT:},
+// CHECK-NEXT:"Name": "MyClass",
+// CHECK-NEXT:"Namespace": [
+// CHECK-NEXT:  "GlobalNamespace"
+// CHECK-NEXT:],
+// CHECK-NEXT:   "Path": "GlobalNamespace",
+// CHECK-NEXT:   "ProtectedFunctions": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "IsStatic": false,
+// CHECK-NEXT:   "Name": "protectedMethod",
+// CHECK-NEXT:   "Namespace": [
+// CHECK-NEXT: "MyClass",
+// CHECK-NEXT: "GlobalNamespace"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "ReturnType": {
+// CHECK-NEXT: "IsBuiltIn": false,
+// CHECK-NEXT: "IsTemplate": false,
+// CHECK-NEXT: "Name": "int",
+// CHECK-NEXT: "QualName": "int",
+// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"ProtectedMembers": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "ProtectedField",
+// CHECK-NEXT:"Type": "int"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"PublicFunctions": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"IsStatic": false,
+// CHECK-NEXT:"Name": "myMethod",
+// CHECK-NEXT:"Namespace": [
+// CHECK-NEXT:  "MyClass",
+// CHECK-NEXT:  "GlobalNamespace"
+// CHECK-NEXT:],
+// CHECK-NEXT:"Params": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "MyParam",
+// CHECK-NEXT:"Type": "int"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"ReturnType": {
+// CHECK-NEXT:  "IsBuiltIn": false,
+// CHECK-NEXT:  "IsTemplate": false,
+// CHECK-NEXT:  "Name": "int",
+// CHECK-NEXT:  "QualName": "int",
+// CHECK-NEXT:  "USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:},
+// CHECK-NEXT:"USR": "{{[0-9A-F]*}}"
+

[clang] [llvm][RISCV] Handle required features of intrinsic correctly (PR #143062)

2025-06-09 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [Clang][NFC] Add test for CWG2289 "Uniqueness of structured binding names" (PR #131054)

2025-06-09 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

Ping.

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


[clang] [llvm][RISCV] Handle required features of intrinsic correctly (PR #143062)

2025-06-09 Thread Brandon Wu via cfe-commits


@@ -540,7 +494,7 @@ struct RVVIntrinsicRecord {
   const char *OverloadedName;
 
   // Required target features for this intrinsic.
-  RequiredExtensionBits RequiredExtensions;
+  std::string RequiredExtensions;

4vtomat wrote:

Yeah sure~

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


[clang] [llvm][RISCV] Handle required features of intrinsic correctly (PR #143062)

2025-06-09 Thread Brandon Wu via cfe-commits


@@ -768,35 +768,13 @@ void RVVEmitter::createRVVIntrinsics(
   Log2LMULMask |= 1 << (Log2LMUL + 3);
 
 SR.Log2LMULMask = Log2LMULMask;
-
-for (auto RequiredFeature : RequiredFeatures) {
-  unsigned RequireExt =
-  StringSwitch(RequiredFeature)
-  .Case("RV64", RVV_REQ_RV64)
-  .Case("Zvfhmin", RVV_REQ_Zvfhmin)
-  .Case("Xandesvpackfph", RVV_REQ_Xandesvpackfph)
-  .Case("Xandesvdot", RVV_REQ_Xandesvdot)
-  .Case("Xsfvcp", RVV_REQ_Xsfvcp)
-  .Case("Xsfvfnrclipxfqf", RVV_REQ_Xsfvfnrclipxfqf)
-  .Case("Xsfvfwmaccqqq", RVV_REQ_Xsfvfwmaccqqq)
-  .Case("Xsfvqmaccdod", RVV_REQ_Xsfvqmaccdod)
-  .Case("Xsfvqmaccqoq", RVV_REQ_Xsfvqmaccqoq)
-  .Case("Zvbb", RVV_REQ_Zvbb)
-  .Case("Zvbc", RVV_REQ_Zvbc)
-  .Case("Zvkb", RVV_REQ_Zvkb)
-  .Case("Zvkg", RVV_REQ_Zvkg)
-  .Case("Zvkned", RVV_REQ_Zvkned)
-  .Case("Zvknha", RVV_REQ_Zvknha)
-  .Case("Zvknhb", RVV_REQ_Zvknhb)
-  .Case("Zvksed", RVV_REQ_Zvksed)
-  .Case("Zvksh", RVV_REQ_Zvksh)
-  .Case("Zvfbfwma", RVV_REQ_Zvfbfwma)
-  .Case("Zvfbfmin", RVV_REQ_Zvfbfmin)
-  .Case("Zvfh", RVV_REQ_Zvfh)
-  .Case("Experimental", RVV_REQ_Experimental);
-  SR.RequiredExtensions.set(RequireExt);
+std::string RFs;
+for (unsigned i = 0; i < RequiredFeatures.size(); ++i) {

4vtomat wrote:

Good idea, thanks!


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


[clang] [C++20][Modules] Implement P1857R3 Modules Dependency Discovery (PR #107168)

2025-06-09 Thread Michael Spencer via cfe-commits

Bigcheese wrote:

> @Bigcheese I have a question about `A module directive may only appear as the 
> first preprocessing tokens in a file (excluding the global module 
> fragment.)`. IIUC, as you said in [#90574 
> (comment)](https://github.com/llvm/llvm-project/pull/90574#discussion_r1591569547),
>  this rule intended to prohibit the following code?
> 
> ```c++
> // error: User need to have a `module;` decl before any preprocessor 
> directives.
> #include "foo.h"
> export module M;
> ```

Yes, that's not valid according to to the grammar in 
[[cpp.pre]](https://eel.is/c++draft/cpp.pre).

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


[clang] [llvm][RISCV] Handle required features of intrinsic correctly (PR #143062)

2025-06-09 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/143062

>From fed5d31d4c398c85addf91d1a2f3d15aa3e6d64e Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Thu, 5 Jun 2025 20:36:58 -0700
Subject: [PATCH 1/2] [llvm][RISCV] Handle required features of intrinsic
 correctly

Current approach generates intrinsic records when users specify
corresponding required features by using command line option.
However it's not able to handle features passed by using target
attributes correctly where each function might have different
features.
This patch resolves this by generating all of intrinsic records which
carry the required features in their function declaration using
attribute and check the required extensions in CheckBuiltinFunctionCall.
---
 .../include/clang/Basic/riscv_andes_vector.td |   4 +-
 .../clang/Basic/riscv_sifive_vector.td|  10 +-
 clang/include/clang/Basic/riscv_vector.td | 248 +-
 .../clang/Basic/riscv_vector_common.td|  38 +--
 .../clang/Support/RISCVVIntrinsicUtils.h  |  48 +---
 clang/lib/Sema/SemaRISCV.cpp  |  60 ++---
 clang/lib/Support/RISCVVIntrinsicUtils.cpp|  44 +---
 .../zvfhmin-error.c   |   2 +-
 .../test/Sema/rvv-required-features-invalid.c |  37 ++-
 clang/test/Sema/zvk-invalid-features.c|  58 ++--
 clang/test/Sema/zvk-invalid-zvknha.c  |   8 +-
 clang/test/Sema/zvk-target-attributes.c   |  24 ++
 clang/utils/TableGen/RISCVVEmitter.cpp|  36 +--
 13 files changed, 262 insertions(+), 355 deletions(-)

diff --git a/clang/include/clang/Basic/riscv_andes_vector.td 
b/clang/include/clang/Basic/riscv_andes_vector.td
index 1498ce2dcdf9e..01019cf86d6e3 100644
--- a/clang/include/clang/Basic/riscv_andes_vector.td
+++ b/clang/include/clang/Basic/riscv_andes_vector.td
@@ -30,7 +30,7 @@ multiclass RVVFPMAD {
   }
 }
 
-let RequiredFeatures = ["Xandesvpackfph"],
+let RequiredFeatures = ["xandesvpackfph"],
 UnMaskedPolicyScheme = HasPassthruOperand in {
 let ManualCodegen = [{
   {
@@ -86,7 +86,7 @@ let ManualCodegen = [{
 
 multiclass RVVD4DOT> i_suffixes_prototypes,
 list> l_suffixes_prototypes> {
-  let RequiredFeatures = ["Xandesvdot"],
+  let RequiredFeatures = ["xandesvdot"],
   UnMaskedPolicyScheme = HasPolicyOperand,
   HasMaskedOffOperand = false,
   Log2LMUL = [-1, 0, 1, 2, 3],
diff --git a/clang/include/clang/Basic/riscv_sifive_vector.td 
b/clang/include/clang/Basic/riscv_sifive_vector.td
index f7996f362378a..772fd3ef4201f 100644
--- a/clang/include/clang/Basic/riscv_sifive_vector.td
+++ b/clang/include/clang/Basic/riscv_sifive_vector.td
@@ -50,7 +50,7 @@ multiclass RVVVCIXBuiltinSet range, string 
prototype,
  string suffix = "Uv"> {
   foreach r = range in
 let RequiredFeatures = !if(!and(UseGPR, !eq(r, "l")),
-   ["Xsfvcp", "RV64"], ["Xsfvcp"]) in
+   ["xsfvcp", "64bit"], ["xsfvcp"]) in
   defm : VCIXBuiltinSet;
 }
 
@@ -126,7 +126,7 @@ multiclass RVVVFNRCLIPBuiltinSet;
 defm sf_vqmacc_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
 defm sf_vqmaccus_2x8x2 : RVVVQMACCDODBuiltinSet<[["", "v", 
"vv(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
@@ -134,7 +134,7 @@ let UnMaskedPolicyScheme = HasPolicyOperand in
   }
 
 let UnMaskedPolicyScheme = HasPolicyOperand in
-  let RequiredFeatures = ["Xsfvqmaccqoq"] in {
+  let RequiredFeatures = ["xsfvqmaccqoq"] in {
 defm sf_vqmaccu_4x8x4 : RVVVQMACCQOQBuiltinSet<[["", "w", 
"ww(FixedSEW:8)SUv(FixedSEW:8)Uv"]]>;
 defm sf_vqmacc_4x8x4 : RVVVQMACCQOQBuiltinSet<[["", "w", 
"ww(FixedSEW:8)Sv(FixedSEW:8)v"]]>;
 defm sf_vqmaccus_4x8x4 : RVVVQMACCQOQBuiltinSet<[["", "w", 
"ww(FixedSEW:8)SUv(FixedSEW:8)v"]]>;
@@ -142,10 +142,10 @@ let UnMaskedPolicyScheme = HasPolicyOperand in
   }
 
 let UnMaskedPolicyScheme = HasPolicyOperand in
-  let RequiredFeatures = ["Xsfvfwmaccqqq"] in
+  let RequiredFeatures = ["xsfvfwmaccqqq"] in
 defm sf_vfwmacc_4x4x4 : RVVVFWMACCBuiltinSet<[["", "Fw", "FwFwSvv"]]>;
 
-let UnMaskedPolicyScheme = HasPassthruOperand, RequiredFeatures = 
["Xsfvfnrclipxfqf"] in {
+let UnMaskedPolicyScheme = HasPassthruOperand, RequiredFeatures = 
["xsfvfnrclipxfqf"] in {
 let ManualCodegen = [{
   {
 // LLVM intrinsic
diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index bff8699463c43..3e22bfb330af6 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -117,8 +117,8 @@ multiclass RVVIndexedLoad {
 defvar eew = eew_list[0];
 defvar eew_type = eew_list[1];
 let Name = op # eew # "_v", IRName = op, MaskedIRName = op # "_mask",
-RequiredFeatures = !if(!eq(type, "x"), ["Zvfhmin"],
-   !if(!eq(type, "y"), ["Zvfbfmin"],
+RequiredFeatures = !if(!eq(type, "x"), ["zvfhm

[clang] [llvm][RISCV] Handle required features of intrinsic correctly (PR #143062)

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

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

LGTM

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


[clang-tools-extra] [clangd] [Modules] Fix to correctly handle module dependencies (PR #142828)

2025-06-09 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,96 @@
+# A smoke test to check that a simple dependency chain for modules can work.
+#
+# FIXME: This fails on the Windows ARM64 build server. Not entirely sure why 
as it has been tested on
+#an ARM64 Windows VM and appears to work there.
+# UNSUPPORTED: host=aarch64-pc-windows-msvc
+#
+# RUN: rm -fr %t
+# RUN: mkdir -p %t
+# RUN: split-file %s %t
+#
+# RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > 
%t/compile_commands.json.tmp
+# RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > 
%t/compile_commands.json
+# RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > 
%t/definition.jsonrpc.tmp

ChuanqiXu9 wrote:

@fleeting-xx 

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


[clang] ab954b1 - [clang][NFC] Refactor replaceExternalDecls to use llvm::any_of (#143275)

2025-06-09 Thread via cfe-commits

Author: Samarth Narang
Date: 2025-06-10T10:22:23+08:00
New Revision: ab954b11dbf7c5f0256b5a93b6c221b6e82a4f28

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

LOG: [clang][NFC] Refactor replaceExternalDecls to use llvm::any_of (#143275)

This patch simplifies the declaration replacement logic in
replaceExternalDecls by replacing a manual loop with an idiomatic use of
llvm::any_of. This improves code readability and aligns with common LLVM
coding style.

Added: 


Modified: 
clang/include/clang/AST/DeclContextInternals.h

Removed: 




diff  --git a/clang/include/clang/AST/DeclContextInternals.h 
b/clang/include/clang/AST/DeclContextInternals.h
index b17b7627ac90c..a0f37886cc014 100644
--- a/clang/include/clang/AST/DeclContextInternals.h
+++ b/clang/include/clang/AST/DeclContextInternals.h
@@ -177,13 +177,12 @@ class StoredDeclsList {
   if (ND->isFromASTFile())
 return true;
   // FIXME: Can we get rid of this loop completely?
-  for (NamedDecl *D : Decls)
+  return llvm::any_of(Decls, [ND](NamedDecl *D) {
 // Only replace the local declaration if the external declaration has
-// higher visibilities.
-if (D->getModuleOwnershipKind() <= ND->getModuleOwnershipKind() &&
-D->declarationReplaces(ND, /*IsKnownNewer=*/false))
-  return true;
-  return false;
+// higher visiblities.
+return D->getModuleOwnershipKind() <= ND->getModuleOwnershipKind() &&
+   D->declarationReplaces(ND, /*IsKnownNewer=*/false);
+  });
 });
 
 // Don't have any pending external decls any more.



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


[clang] [clang][NFC] Refactor replaceExternalDecls to use llvm::any_of (PR #143275)

2025-06-09 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang][NFC] Refactor replaceExternalDecls to use llvm::any_of (PR #143275)

2025-06-09 Thread Chuanqi Xu via cfe-commits

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


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


[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)

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

https://github.com/evelez7 updated 
https://github.com/llvm/llvm-project/pull/142483

>From 741dce551684ee5818262ba3f4618ffcfa70a0d6 Mon Sep 17 00:00:00 2001
From: Erick Velez 
Date: Mon, 2 Jun 2025 12:53:36 -0700
Subject: [PATCH 1/7] [clang-doc] add a JSON generator

---
 clang-tools-extra/clang-doc/CMakeLists.txt|   1 +
 clang-tools-extra/clang-doc/Generators.cpp|   2 +
 clang-tools-extra/clang-doc/Generators.h  |   1 +
 clang-tools-extra/clang-doc/JSONGenerator.cpp | 316 ++
 .../clang-doc/tool/ClangDocMain.cpp   |   8 +-
 .../test/clang-doc/json/class.cpp | 183 ++
 6 files changed, 509 insertions(+), 2 deletions(-)
 create mode 100644 clang-tools-extra/clang-doc/JSONGenerator.cpp
 create mode 100644 clang-tools-extra/test/clang-doc/json/class.cpp

diff --git a/clang-tools-extra/clang-doc/CMakeLists.txt 
b/clang-tools-extra/clang-doc/CMakeLists.txt
index 79563c41435eb..5989e5fe60cf3 100644
--- a/clang-tools-extra/clang-doc/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/CMakeLists.txt
@@ -17,6 +17,7 @@ add_clang_library(clangDoc STATIC
   Serialize.cpp
   YAMLGenerator.cpp
   HTMLMustacheGenerator.cpp
+  JSONGenerator.cpp
 
   DEPENDS
   omp_gen
diff --git a/clang-tools-extra/clang-doc/Generators.cpp 
b/clang-tools-extra/clang-doc/Generators.cpp
index a3c2773412cff..3fb5b63c403a7 100644
--- a/clang-tools-extra/clang-doc/Generators.cpp
+++ b/clang-tools-extra/clang-doc/Generators.cpp
@@ -105,5 +105,7 @@ static int LLVM_ATTRIBUTE_UNUSED HTMLGeneratorAnchorDest =
 HTMLGeneratorAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED MHTMLGeneratorAnchorDest =
 MHTMLGeneratorAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED JSONGeneratorAnchorDest =
+JSONGeneratorAnchorSource;
 } // namespace doc
 } // namespace clang
diff --git a/clang-tools-extra/clang-doc/Generators.h 
b/clang-tools-extra/clang-doc/Generators.h
index aee04b9d58d9d..92d3006e6002d 100644
--- a/clang-tools-extra/clang-doc/Generators.h
+++ b/clang-tools-extra/clang-doc/Generators.h
@@ -58,6 +58,7 @@ extern volatile int YAMLGeneratorAnchorSource;
 extern volatile int MDGeneratorAnchorSource;
 extern volatile int HTMLGeneratorAnchorSource;
 extern volatile int MHTMLGeneratorAnchorSource;
+extern volatile int JSONGeneratorAnchorSource;
 
 } // namespace doc
 } // namespace clang
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp 
b/clang-tools-extra/clang-doc/JSONGenerator.cpp
new file mode 100644
index 0..499ca4dd05e6e
--- /dev/null
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -0,0 +1,316 @@
+#include "Generators.h"
+#include "llvm/Support/JSON.h"
+
+using namespace llvm;
+using namespace llvm::json;
+
+static llvm::ExitOnError ExitOnErr;
+
+namespace clang {
+namespace doc {
+
+class JSONGenerator : public Generator {
+public:
+  static const char *Format;
+
+  Error generateDocs(StringRef RootDir,
+ llvm::StringMap> Infos,
+ const ClangDocContext &CDCtx) override;
+  Error createResources(ClangDocContext &CDCtx) override;
+  Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
+   const ClangDocContext &CDCtx) override;
+};
+
+const char *JSONGenerator::Format = "json";
+
+static json::Object serializeLocation(const Location &Loc,
+  std::optional RepositoryUrl) {
+  Object LocationObj = Object();
+  LocationObj["LineNumber"] = Loc.StartLineNumber;
+  LocationObj["Filename"] = Loc.Filename;
+
+  if (!Loc.IsFileInRootDir || !RepositoryUrl)
+return LocationObj;
+  SmallString<128> FileURL(*RepositoryUrl);
+  sys::path::append(FileURL, sys::path::Style::posix, Loc.Filename);
+  FileURL += "#" + std::to_string(Loc.StartLineNumber);
+  LocationObj["FileURL"] = FileURL;
+  return LocationObj;
+}
+
+static json::Value serializeComment(const CommentInfo &Comment) {
+  assert((Comment.Kind == "BlockCommandComment" ||
+  Comment.Kind == "FullComment" || Comment.Kind == "ParagraphComment" 
||
+  Comment.Kind == "TextComment") &&
+ "Unknown Comment type in CommentInfo.");
+
+  Object Obj = Object();
+  json::Value Child = Object();
+
+  // TextComment has no children, so return it.
+  if (Comment.Kind == "TextComment") {
+Obj["TextComment"] = Comment.Text;
+return Obj;
+  }
+
+  // BlockCommandComment needs to generate a Command key.
+  if (Comment.Kind == "BlockCommandComment")
+Child.getAsObject()->insert({"Command", Comment.Name});
+
+  // Use the same handling for everything else.
+  // Only valid for:
+  //  - BlockCommandComment
+  //  - FullComment
+  //  - ParagraphComment
+  json::Value ChildArr = Array();
+  auto &CARef = *ChildArr.getAsArray();
+  CARef.reserve(Comment.Children.size());
+  for (const auto &C : Comment.Children)
+CARef.emplace_back(serializeComment(*C));
+  Child.getAsObject()->insert({"Children", ChildArr});
+  Obj.insert({Comment.Kind, Child});
+  return Obj;
+}
+
+static void serializeCommonA

[clang] Add sycl_external attribute (PR #140282)

2025-06-09 Thread via cfe-commits

https://github.com/schittir updated 
https://github.com/llvm/llvm-project/pull/140282

>From abdbf8905d324f9b935b34bbc97c508ede5ac028 Mon Sep 17 00:00:00 2001
From: "Chittireddy, Sindhu" 
Date: Fri, 16 May 2025 08:51:06 -0700
Subject: [PATCH 1/9] Add sycl_external attribute

---
 clang/include/clang/Basic/Attr.td | 20 ++-
 clang/include/clang/Basic/AttrDocs.td | 11 
 .../clang/Basic/DiagnosticSemaKinds.td|  5 ++
 clang/include/clang/Sema/SemaSYCL.h   |  1 +
 clang/lib/AST/ASTContext.cpp  |  7 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++
 clang/lib/Sema/SemaSYCL.cpp   | 11 
 .../test/SemaSYCL/sycl-external-attribute.cpp | 52 +++
 8 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaSYCL/sycl-external-attribute.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index ccd13a4cca4dd..1c13d0eb23f3b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -143,6 +143,7 @@ def SharedVar : SubsetSubjecthasGlobalStorage()}], "global variables">;
 
+
 def ExternalGlobalVar : SubsetSubjecthasGlobalStorage() &&
S->getStorageClass()!=StorageClass::SC_Static &&
@@ -408,10 +409,14 @@ class SubjectList subjects, SubjectDiag 
diag = WarnDiag,
   string CustomDiag = customDiag;
 }
 
-class LangOpt {
+class LangOpt {
   // The language option to test; ignored when custom code is supplied.
   string Name = name;
 
+  // If set to 1, the attribute is accepted but is silently ignored. This is
+  // useful in multi-compilation situations like SYCL.
+  bit SilentlyIgnore = silentlyIgnore;
+
   // A custom predicate, written as an expression evaluated in a context with
   // "LangOpts" bound.
   code CustomCode = customCode;
@@ -422,6 +427,7 @@ def CUDA : LangOpt<"CUDA">;
 def HIP : LangOpt<"HIP">;
 def SYCLHost : LangOpt<"SYCLIsHost">;
 def SYCLDevice : LangOpt<"SYCLIsDevice">;
+def SilentlyIgnoreSYCLHost : LangOpt<"SYCLIsHost", "", 1>;
 def COnly : LangOpt<"", "!LangOpts.CPlusPlus">;
 def CPlusPlus : LangOpt<"CPlusPlus">;
 def OpenCL : LangOpt<"OpenCL">;
@@ -1545,6 +1551,18 @@ def SYCLKernel : InheritableAttr {
   let Documentation = [SYCLKernelDocs];
 }
 
+def GlobalStorageNonLocalVar : SubsetSubjecthasGlobalStorage() &&
+   !S->isLocalVarDeclOrParm()}],
+ "global variables">;
+
+def SYCLExternal : InheritableAttr {
+  let Spellings = [GNU<"sycl_external">];
+  let Subjects = SubjectList<[Function, GlobalStorageNonLocalVar]>;
+  let LangOpts = [SYCLDevice, SilentlyIgnoreSYCLHost];
+  let Documentation = [SYCLExternalDocs];
+}
+
 def SYCLKernelEntryPoint : InheritableAttr {
   let Spellings = [Clang<"sycl_kernel_entry_point">];
   let Args = [
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 5fb5f16680b41..2eef46a1348f3 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -472,6 +472,17 @@ The SYCL kernel in the previous code sample meets these 
expectations.
   }];
 }
 
+def SYCLExternalDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "sycl_external";
+  let Content = [{
+The ``sycl_external`` attribute (or the ``SYCL_EXTERNAL`` macro) can only be 
applied to
+functions, and indicates that the function must be treated as a device 
function and
+must be emitted even if it has no direct uses from other device functions.
+All ``sycl_external`` function callees implicitly inherit this attribute.
+  }];
+}
+
 def SYCLKernelEntryPointDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3efe9593b8633..9228d388bc10b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12746,6 +12746,11 @@ def err_sycl_special_type_num_init_method : Error<
   "types with 'sycl_special_class' attribute must have one and only one 
'__init' "
   "method defined">;
 
+//SYCL external attribute diagnostics
+def err_sycl_attribute_internal_decl
+: Error<"%0 attribute cannot be applied to a %select{function|variable}1"
+" without external linkage">;
+
 // SYCL kernel entry point diagnostics
 def err_sycl_entry_point_invalid : Error<
   "'sycl_kernel_entry_point' attribute cannot be applied to a"
diff --git a/clang/include/clang/Sema/SemaSYCL.h 
b/clang/include/clang/Sema/SemaSYCL.h
index b47b2f155ef93..099cc56b0ef92 100644
--- a/clang/include/clang/Sema/SemaSYCL.h
+++ b/clang/include/clang/Sema/SemaSYCL.h
@@ -62,6 +62,7 @@ class SemaSYCL : public SemaBase {
ParsedType ParsedTy);
 
   void handleKernelAttr(Decl *D, const ParsedAttr &AL);
+  void handleSY

[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread Anchu Rajendran S via cfe-commits

https://github.com/anchuraj created 
https://github.com/llvm/llvm-project/pull/143441

Atomic Control Options are used to specify architectural characteristics to 
help lowering of atomic operations. The options used are: 
`-f[no-]atomic-remote-memory`, `-f[no-]atomic-fine-grained-memory`,
 `-f[no-]atomic-ignore-denormal-mode`.
Legacy option `-m[no-]unsafe-fp-atomics` is aliased to
`-f[no-]ignore-denormal-mode`.
 More details can be found in  
https://github.com/llvm/llvm-project/pull/102569. This PR implements the 
frontend support for these options with OpenMP atomic in flang

>From 51c6a6a9b1f58f37df3eb1b6988b62f489c8f4b8 Mon Sep 17 00:00:00 2001
From: Anchu Rajendran 
Date: Wed, 4 Jun 2025 15:12:49 -0500
Subject: [PATCH] [flang][flang-driver] atomic control support

---
 clang/include/clang/Driver/Options.td | 22 +-
 flang/include/flang/Frontend/TargetOptions.h  |  5 +++
 .../Optimizer/Dialect/Support/FIRContext.h| 14 +++
 flang/lib/Frontend/CompilerInvocation.cpp | 12 ++
 flang/lib/Lower/Bridge.cpp|  6 +++
 flang/lib/Lower/OpenMP/OpenMP.cpp |  7 +++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 40 +++
 .../Lower/OpenMP/atomic-control-options.f90   | 37 +
 .../mlir/Dialect/OpenMP/OpenMPAttrDefs.td | 14 +++
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td |  8 ++--
 mlir/test/Dialect/OpenMP/ops.mlir |  9 +
 11 files changed, 159 insertions(+), 15 deletions(-)
 create mode 100644 flang/test/Lower/OpenMP/atomic-control-options.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fd6deb22d404e..c6d8f9106341a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2299,21 +2299,21 @@ def fsymbol_partition_EQ : Joined<["-"], 
"fsymbol-partition=">, Group,
 
 defm atomic_remote_memory : BoolFOption<"atomic-remote-memory",
   LangOpts<"AtomicRemoteMemory">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " atomic operations on remote memory">>;
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, FlangOption], " atomic operations on remote 
memory">>;
 
 defm atomic_fine_grained_memory : BoolFOption<"atomic-fine-grained-memory",
   LangOpts<"AtomicFineGrainedMemory">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " atomic operations on fine-grained memory">>;
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, FlangOption], " atomic operations on 
fine-grained memory">>;
 
 defm atomic_ignore_denormal_mode : BoolFOption<"atomic-ignore-denormal-mode",
   LangOpts<"AtomicIgnoreDenormalMode">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " atomic operations to ignore denormal mode">>;
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption, FlangOption], " atomic operations to ignore 
denormal mode">>;
 
 defm memory_profile : OptInCC1FFlag<"memory-profile", "Enable", "Disable", " 
heap memory profiling">;
 def fmemory_profile_EQ : Joined<["-"], "fmemory-profile=">,
@@ -5270,9 +5270,9 @@ defm amdgpu_precise_memory_op
   " precise memory mode (AMDGPU only)">;
 
 def munsafe_fp_atomics : Flag<["-"], "munsafe-fp-atomics">,
-  Visibility<[ClangOption, CC1Option]>, Alias;
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>, 
Alias;
 def mno_unsafe_fp_atomics : Flag<["-"], "mno-unsafe-fp-atomics">,
-  Visibility<[ClangOption]>, Alias;
+  Visibility<[ClangOption, FlangOption]>, 
Alias;
 
 def faltivec : Flag<["-"], "faltivec">, Group;
 def fno_altivec : Flag<["-"], "fno-altivec">, Group;
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index 002d8d158abd4..26256fd775f11 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -53,6 +53,11 @@ class TargetOptions {
 
   /// Print verbose assembly
   bool asmVerbose = false;
+
+  /// Atomic Control Options for AMD GPU
+  bool amdgpuIgnoreDenormalMode = false;
+  bool amdgpuRemoteMemory = false;
+  bool amdgpuFineGrainedMemory = false;
 };
 
 } // end namespace Fortran::frontend
diff --git a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h 
b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
index 2df14f83c11e1..ac563bcc402c7 100644
--- a/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
+++ b/flang/include/flang/Optimizer/Dialect/Support/FIRContext.h
@@ -58,10 +58,24 @@ void setTargetCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
 /// Get the target CPU string from the Module or return a null reference.
 llvm::StringRef getTargetCPU(mlir::ModuleOp mod);
 
+// Setters and Getters for atomic control options
+void setAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
+bool getAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
+void setAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
+bool getAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
+void

[clang] [clang][analyzer] Update python dependency versions (PR #143433)

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

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


[clang] 28b753b - [Clang][NFC] Add nullptr check in InitializationSequence::InitializeFrom (#143067)

2025-06-09 Thread via cfe-commits

Author: Shafik Yaghmour
Date: 2025-06-09T14:28:47-07:00
New Revision: 28b753b185511eaaf98c5dda39bf9e44fa134212

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

LOG: [Clang][NFC] Add nullptr check in InitializationSequence::InitializeFrom 
(#143067)

Static analysis flagged that Var could be nullptr but we were not
checking in the branch and unconditionally dereferences the pointer.

Note, code was added by 576161cb6069

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 5d870f07093ec..da56225b2f926 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6620,7 +6620,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
   // initializer present. However, we only do this for structure types, not
   // union types, because an unitialized field in a union is generally
   // reasonable, especially in C where unions can be used for type punning.
-  if (!Initializer && !Rec->isUnion() && !Rec->isInvalidDecl()) {
+  if (Var && !Initializer && !Rec->isUnion() && !Rec->isInvalidDecl()) {
 if (const FieldDecl *FD = getConstField(Rec)) {
   unsigned DiagID = diag::warn_default_init_const_field_unsafe;
   if (Var->getStorageDuration() == SD_Static ||



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


[clang] [Clang][NFC] Add nullptr check in InitializationSequence::InitializeFrom (PR #143067)

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

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


[clang-tools-extra] [clangd] Add languages as server capabilities (PR #75633)

2025-06-09 Thread Ashley Coleman via cfe-commits

V-FEXrt wrote:

`ServerCapabilities` has this member:
```
 /**
 * Experimental server capabilities.
 */
experimental?: LSPAny;
```

Any reason we wouldn't just use that directly? maybe  

```c++
  llvm::json::Object ServerCaps{
  ...
  {"experimental",
   llvm::json::Object{
   {"languages", {"HLSL"}},
   }},
  ...
  }
```

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


[clang] add6acc - NFC: stray whitespace cleanup from clang/test/SemaCXX/destructor.cpp

2025-06-09 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2025-06-09T19:08:15-03:00
New Revision: add6acc333740542705eedd185f45f69e3d25f30

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

LOG: NFC: stray whitespace cleanup from clang/test/SemaCXX/destructor.cpp

Added: 


Modified: 
clang/test/SemaCXX/destructor.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/destructor.cpp 
b/clang/test/SemaCXX/destructor.cpp
index 589616ef8e437..ed4802943ad3f 100644
--- a/clang/test/SemaCXX/destructor.cpp
+++ b/clang/test/SemaCXX/destructor.cpp
@@ -58,7 +58,7 @@ struct D {
 
 struct D2 {
   void ~D2() { } //  \
-  // expected-error{{destructor cannot have a return type}}  
+  // expected-error{{destructor cannot have a return type}}
 };
 
 
@@ -86,7 +86,7 @@ struct G {
 G::~G() { }
 
 struct H {
-  ~H(void) { } 
+  ~H(void) { }
 };
 
 struct X {};
@@ -103,7 +103,7 @@ namespace PR6421 {
 template
 void foo(T t) // expected-error{{variable has incomplete type}}
 { }
-
+
 void disconnect()
 {
   T* t;
@@ -364,7 +364,7 @@ struct __is_destructor_wellformed {
decltype(_Tp1().~_Tp1())>::type);
   template 
   static __two __test (...);
-  
+
   static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char);
 };
 



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


[clang] Revert "[HIP] use offload wrapper for non-device-only non-rdc (#132869)" (PR #143432)

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

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


[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #143418)

2025-06-09 Thread Cameron McInally via cfe-commits

mcinally wrote:

> Thanks for the changes, Cameron. LGTM.

Thanks! Would you mind merging yet again? I still don't have access yet. 

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


[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)

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


@@ -0,0 +1,193 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --output=%t --format=json --executor=standalone %s
+// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.json
+
+struct Foo;
+
+// This is a nice class.
+// It has some nice methods and fields.
+// @brief This is a brief description.
+struct MyClass {
+  int PublicField;
+
+  int myMethod(int MyParam);
+  static void staticMethod();
+  const int& getConst();
+  
+  enum Color {
+RED,
+GREEN,
+BLUE = 5
+  };
+  
+  typedef int MyTypedef;
+  
+  class NestedClass;
+protected:
+  int protectedMethod();
+
+  int ProtectedField;
+};
+
+// CHECK:   {
+// CHECK-NEXT:"Description": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:   "FullComment": {
+// CHECK-NEXT: "Children": [
+// CHECK-NEXT:   {
+// CHECK-NEXT: "ParagraphComment": {
+// CHECK-NEXT:   "Children": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "TextComment": " This is a nice class."
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "TextComment": " It has some nice methods and 
fields."
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "TextComment": ""
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK:   {
+// CHECK-NEXT: "BlockCommandComment": {
+// CHECK-NEXT:   "Children": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "ParagraphComment": {
+// CHECK-NEXT: "Children": [
+// CHECK-NEXT:   { 
+// CHECK-NEXT: "TextComment": " This is a brief 
description." 
+// CHECK-NEXT:   }
+// CHECK:   "Command": "brief"
+// CHECK: "Enums": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Location": {
+// CHECK-NEXT:  "Filename": "{{.*}}class.cpp",
+// CHECK-NEXT:  "LineNumber": 17
+// CHECK-NEXT:},
+// CHECK-NEXT:"Members": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "RED",
+// CHECK-NEXT:"Value": "0"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "GREEN",
+// CHECK-NEXT:"Value": "1"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "BLUE",
+// CHECK-NEXT:"ValueExpr": "5"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"Name": "Color",
+// CHECK-NEXT:"Namespace": [
+// CHECK-NEXT:  "MyClass",
+// CHECK-NEXT:  "GlobalNamespace"
+// CHECK-NEXT:],
+// CHECK-NEXT:"Scoped": false,
+// CHECK-NEXT:"USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// COM:   FIXME: FullName is not emitted correctly.
+// CHECK-NEXT:"FullName": "",
+// CHECK-NEXT:"IsTypedef": false,
+// CHECK-NEXT:"Location": {
+// CHECK-NEXT:  "Filename": "{{.*}}class.cpp",
+// CHECK-NEXT:  "LineNumber": 10
+// CHECK-NEXT:},
+// CHECK-NEXT:"Name": "MyClass",
+// CHECK-NEXT:"Namespace": [
+// CHECK-NEXT:  "GlobalNamespace"
+// CHECK-NEXT:],
+// CHECK-NEXT:   "Path": "GlobalNamespace",
+// CHECK-NEXT:   "ProtectedFunctions": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "IsStatic": false,
+// CHECK-NEXT:   "Name": "protectedMethod",
+// CHECK-NEXT:   "Namespace": [
+// CHECK-NEXT: "MyClass",
+// CHECK-NEXT: "GlobalNamespace"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "ReturnType": {
+// CHECK-NEXT: "IsBuiltIn": false,
+// CHECK-NEXT: "IsTemplate": false,
+// CHECK-NEXT: "Name": "int",
+// CHECK-NEXT: "QualName": "int",
+// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"ProtectedMembers": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "ProtectedField",
+// CHECK-NEXT:"Type": "int"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"PublicFunctions": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"IsStatic": false,
+// CHECK-NEXT:"Name": "myMethod",
+// CHECK-NEXT:"Namespace": [
+// CHECK-NEXT:  "MyClass",
+// CHECK-NEXT:  "GlobalNamespace"
+// CHECK-NEXT:],
+// CHECK-NEXT:"Params": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "MyParam",
+// CHECK-NEXT:"Type": "int"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"ReturnType": {
+// CHECK-NEXT:  "IsBuiltIn": false,
+// CHECK-NEXT:  "IsTemplate": false,
+// CHECK-NEXT:  "Name": "int",
+// CHECK-NEXT:  "QualName": "int",
+// CHECK-NEXT:  "USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:},
+// CHECK-NEXT:"USR": "{{[0-9A-F]*}}"
+

[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)

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

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


[clang] [Cygwin] va_list must be treated like normal Windows (PR #143115)

2025-06-09 Thread via cfe-commits


@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm < %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-pc-cygwin -emit-llvm < %s | FileCheck %s
+
+// copy ms_abi block only from ../ms_abi.c

jeremyd2019 wrote:

I think the idea was 
```suggestion
```

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


[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)

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

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


[clang] [Sema] Implement fix as suggested by FIXME (PR #143142)

2025-06-09 Thread via cfe-commits

lux-QAQ wrote:

It seems that using manual `delete` may not be the most reasonable approach.
Is there any other feedback or improvements I should make? Or, should we simply 
close this PR now?

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


[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)

2025-06-09 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,175 @@
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+static std::unique_ptr getJSONGenerator() {
+  auto G = doc::findGeneratorByName("json");
+  if (!G)
+return nullptr;
+  return std::move(G.get());
+}
+
+TEST(JSONGeneratorTest, emitRecordJSON) {
+  RecordInfo I;
+  I.Name = "Foo";
+  // FIXME: FullName is not emitted correctly.
+  I.FullName = "";
+  I.IsTypeDef = false;
+  I.Namespace.emplace_back(EmptySID, "GlobalNamespace", 
InfoType::IT_namespace);
+  I.Path = "GlobalNamespace";
+  I.DefLoc = Location(1, 1, "main.cpp");
+  I.TagType = TagTypeKind::Class;
+
+  I.Template = TemplateInfo();
+  I.Template->Params.emplace_back("class T");
+
+  I.Children.Enums.emplace_back();
+  I.Children.Enums.back().Name = "Color";
+  I.Children.Enums.back().Scoped = false;
+  I.Children.Enums.back().Members.emplace_back();
+  I.Children.Enums.back().Members.back().Name = "RED";
+  I.Children.Enums.back().Members.back().Value = "0";
+
+  I.Members.emplace_back(TypeInfo("int"), "X", AccessSpecifier::AS_protected);
+
+  I.Bases.emplace_back(EmptySID, "F", "path/to/F", true,
+   AccessSpecifier::AS_public, true);
+  I.Bases.back().Children.Functions.emplace_back();
+  I.Bases.back().Children.Functions.back().Name = "InheritedFunctionOne";
+  I.Bases.back().Members.emplace_back(TypeInfo("int"), "N",
+  AccessSpecifier::AS_public);
+
+  // F is in the global namespace
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
+  I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record,
+"path::to::G::G", "path/to/G");
+
+  I.Children.Records.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record,
+  "path::to::A::r::ChildStruct", 
"path/to/A/r");
+  I.Children.Functions.emplace_back();
+  I.Children.Functions.back().Name = "OneFunction";
+
+  auto G = getJSONGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+  assert(!Err);
+  std::string Expected = R"raw({
+  "Bases": [
+{
+  "Access": "public",
+  "FullName": "",
+  "IsParent": true,
+  "IsTypedef": false,
+  "IsVirtual": true,
+  "Name": "F",
+  "Path": "path/to/F",
+  "PublicFunctions": [
+{
+  "IsStatic": false,
+  "Name": "InheritedFunctionOne",
+  "ReturnType": {
+"IsBuiltIn": false,
+"IsTemplate": false,
+"Name": "",
+"QualName": "",
+"USR": ""
+  },
+  "USR": ""
+}
+  ],
+  "PublicMembers": [
+{
+  "Name": "N",
+  "Type": "int"
+}
+  ],
+  "TagType": "struct",
+  "USR": ""
+}
+  ],
+  "Enums": [
+{
+  "Members": [
+{
+  "Name": "RED",
+  "Value": "0"
+}
+  ],
+  "Name": "Color",
+  "Scoped": false,
+  "USR": ""
+}
+  ],
+  "FullName": "",
+  "IsTypedef": false,
+  "Location": {
+"Filename": "main.cpp",
+"LineNumber": 1
+  },
+  "Name": "Foo",
+  "Namespace": [
+"GlobalNamespace"
+  ],
+  "Parents": [
+{
+  "Name": "F",
+  "Path": "",
+  "QualName": "",
+  "USR": ""
+}
+  ],
+  "Path": "GlobalNamespace",
+  "ProtectedMembers": [
+{
+  "Name": "X",
+  "Type": "int"
+}
+  ],
+  "PublicFunctions": [
+{
+  "IsStatic": false,
+  "Name": "OneFunction",
+  "ReturnType": {
+"IsBuiltIn": false,
+"IsTemplate": false,
+"Name": "",
+"QualName": "",
+"USR": ""
+  },
+  "USR": ""
+}
+  ],
+  "Records": [
+{
+  "Name": "ChildStruct",
+  "Path": "path/to/A/r",

ilovepi wrote:

I'm guessing the path separator will be an issue on Windows...

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


[clang] f5e499a - Revert "[HIP] use offload wrapper for non-device-only non-rdc (#132869)" (#143432)

2025-06-09 Thread via cfe-commits

Author: Joseph Huber
Date: 2025-06-09T17:18:49-05:00
New Revision: f5e499a3383c1e3b9f60e60151075e8d9c1c3166

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

LOG: Revert "[HIP] use offload wrapper for non-device-only non-rdc (#132869)" 
(#143432)

This breaks a lot of new driver HIP compilation. We should probably
revert this for now until we can make a fixed version.

```c++

static __global__ void print() { printf("%s\n", "foo"); }

void b();

int main() {
  hipLaunchKernelGGL(print, dim3(1), dim3(1), 0, 0);
  auto y = hipDeviceSynchronize();
  b();
}
```
```c++

static __global__ void print() { printf("%s\n", "bar"); }

void b() {
  hipLaunchKernelGGL(print, dim3(1), dim3(1), 0, 0);
  auto y = hipDeviceSynchronize();
}
```
```console
$ clang++ a.hip b.hip --offload-arch=gfx1030 --offload-new-driver
$ ./a.out
foo
foo
```
```console
$ clang++ a.hip b.hip --offload-arch=gfx1030 --offload-new-driver -flto

```

This reverts commit d54c28b9c1396fa92d9347ac1135da7907121cb8.

Added: 


Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/hip-binding.hip
clang/test/Driver/hip-phases.hip
clang/test/Driver/hip-toolchain-no-rdc.hip

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index dd26be74e561b..38f514304df5e 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1280,8 +1280,7 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
 return nullptr;
   }
   if (CGM.getLangOpts().OffloadViaLLVM ||
-  (CGM.getLangOpts().OffloadingNewDriver &&
-   (CGM.getLangOpts().HIP || RelocatableDeviceCode)))
+  (CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
 createOffloadingEntries();
   else
 return makeModuleCtorFunction();

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 73ff7757c3b04..80728daca03c9 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4424,10 +4424,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda));
 
-  bool HIPNoRDC =
-  C.isOffloadingHostKind(Action::OFK_HIP) &&
-  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
-
   // Builder to be used to build offloading actions.
   std::unique_ptr OffloadBuilder =
   !UseNewOffloadingDriver
@@ -4561,7 +4557,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // Check if this Linker Job should emit a static library.
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-} else if ((UseNewOffloadingDriver && !HIPNoRDC) ||
+} else if (UseNewOffloadingDriver ||
Args.hasArg(options::OPT_offload_link)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
   LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
@@ -4872,28 +4868,10 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
const InputTy &Input, StringRef CUID,
Action *HostAction) const {
   // Don't build offloading actions if explicitly disabled or we do not have a
-  // valid source input.
-  if (offloadHostOnly() || !types::isSrcFile(Input.first))
-return HostAction;
-
-  bool HIPNoRDC =
-  C.isOffloadingHostKind(Action::OFK_HIP) &&
-  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
-
-  // For HIP non-rdc non-device-only compilation, create a linker wrapper
-  // action for each host object to link, bundle and wrap device files in
-  // it.
-  if (isa(HostAction) && HIPNoRDC && !offloadDeviceOnly()) {
-ActionList AL{HostAction};
-HostAction = C.MakeAction(AL, types::TY_Object);
-HostAction->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
- /*BoundArch=*/nullptr);
-return HostAction;
-  }
-
-  // Don't build offloading actions if we do not have a compile action. If
-  // preprocessing only ignore embedding.
-  if (!(isa(HostAction) ||
+  // valid source input and compile action to embed it in. If preprocessing 
only
+  // ignore embedding.
+  if (offloadHostOnly() || !types::isSrcFile(Input.first) ||
+  !(isa(HostAction) ||
 getFinalPhase(Args) == phases::Preprocess))
 return HostAction;
 
@@ -4989,12 +4967,12 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
   }
 }
 
-// Compiling HIP in device-only non-RDC mode requires linking each action
-// individually.
+// Compiling HIP in non-RDC mode requires linking each action indi

[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)

2025-06-09 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,193 @@
+// RUN: rm -rf %t && mkdir -p %t
+// RUN: clang-doc --output=%t --format=json --executor=standalone %s
+// RUN: FileCheck %s < %t/GlobalNamespace/MyClass.json
+
+struct Foo;
+
+// This is a nice class.
+// It has some nice methods and fields.
+// @brief This is a brief description.
+struct MyClass {
+  int PublicField;
+
+  int myMethod(int MyParam);
+  static void staticMethod();
+  const int& getConst();
+  
+  enum Color {
+RED,
+GREEN,
+BLUE = 5
+  };
+  
+  typedef int MyTypedef;
+  
+  class NestedClass;
+protected:
+  int protectedMethod();
+
+  int ProtectedField;
+};
+
+// CHECK:   {
+// CHECK-NEXT:"Description": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:   "FullComment": {
+// CHECK-NEXT: "Children": [
+// CHECK-NEXT:   {
+// CHECK-NEXT: "ParagraphComment": {
+// CHECK-NEXT:   "Children": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "TextComment": " This is a nice class."
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "TextComment": " It has some nice methods and 
fields."
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "TextComment": ""
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK:   {
+// CHECK-NEXT: "BlockCommandComment": {
+// CHECK-NEXT:   "Children": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "ParagraphComment": {
+// CHECK-NEXT: "Children": [
+// CHECK-NEXT:   { 
+// CHECK-NEXT: "TextComment": " This is a brief 
description." 
+// CHECK-NEXT:   }
+// CHECK:   "Command": "brief"
+// CHECK: "Enums": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Location": {
+// CHECK-NEXT:  "Filename": "{{.*}}class.cpp",
+// CHECK-NEXT:  "LineNumber": 17
+// CHECK-NEXT:},
+// CHECK-NEXT:"Members": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "RED",
+// CHECK-NEXT:"Value": "0"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "GREEN",
+// CHECK-NEXT:"Value": "1"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "BLUE",
+// CHECK-NEXT:"ValueExpr": "5"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"Name": "Color",
+// CHECK-NEXT:"Namespace": [
+// CHECK-NEXT:  "MyClass",
+// CHECK-NEXT:  "GlobalNamespace"
+// CHECK-NEXT:],
+// CHECK-NEXT:"Scoped": false,
+// CHECK-NEXT:"USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// COM:   FIXME: FullName is not emitted correctly.
+// CHECK-NEXT:"FullName": "",
+// CHECK-NEXT:"IsTypedef": false,
+// CHECK-NEXT:"Location": {
+// CHECK-NEXT:  "Filename": "{{.*}}class.cpp",
+// CHECK-NEXT:  "LineNumber": 10
+// CHECK-NEXT:},
+// CHECK-NEXT:"Name": "MyClass",
+// CHECK-NEXT:"Namespace": [
+// CHECK-NEXT:  "GlobalNamespace"
+// CHECK-NEXT:],
+// CHECK-NEXT:   "Path": "GlobalNamespace",
+// CHECK-NEXT:   "ProtectedFunctions": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "IsStatic": false,
+// CHECK-NEXT:   "Name": "protectedMethod",
+// CHECK-NEXT:   "Namespace": [
+// CHECK-NEXT: "MyClass",
+// CHECK-NEXT: "GlobalNamespace"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "ReturnType": {
+// CHECK-NEXT: "IsBuiltIn": false,
+// CHECK-NEXT: "IsTemplate": false,
+// CHECK-NEXT: "Name": "int",
+// CHECK-NEXT: "QualName": "int",
+// CHECK-NEXT: "USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"ProtectedMembers": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "ProtectedField",
+// CHECK-NEXT:"Type": "int"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"PublicFunctions": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"IsStatic": false,
+// CHECK-NEXT:"Name": "myMethod",
+// CHECK-NEXT:"Namespace": [
+// CHECK-NEXT:  "MyClass",
+// CHECK-NEXT:  "GlobalNamespace"
+// CHECK-NEXT:],
+// CHECK-NEXT:"Params": [
+// CHECK-NEXT:  {
+// CHECK-NEXT:"Name": "MyParam",
+// CHECK-NEXT:"Type": "int"
+// CHECK-NEXT:  }
+// CHECK-NEXT:],
+// CHECK-NEXT:"ReturnType": {
+// CHECK-NEXT:  "IsBuiltIn": false,
+// CHECK-NEXT:  "IsTemplate": false,
+// CHECK-NEXT:  "Name": "int",
+// CHECK-NEXT:  "QualName": "int",
+// CHECK-NEXT:  "USR": "{{[0-9A-F]*}}"
+// CHECK-NEXT:},
+// CHECK-NEXT:"USR": "{{[0-9A-F]*}}"
+

[clang-tools-extra] [clang-doc] add a JSON generator (PR #142483)

2025-06-09 Thread Paul Kirth via cfe-commits

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


[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread Tarun Prabhu via cfe-commits


@@ -58,10 +58,24 @@ void setTargetCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
 /// Get the target CPU string from the Module or return a null reference.
 llvm::StringRef getTargetCPU(mlir::ModuleOp mod);
 
+// Setters and Getters for atomic control options
+void setAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
+bool getAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod);
+void setAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
+bool getAmdgpuFineGrainedMemory(mlir::ModuleOp mod);
+void setAmdgpuRemoteMemory(mlir::ModuleOp mod);
+bool getAmdgpuRemoteMemory(mlir::ModuleOp mod);
+
 /// Set the tune CPU for the module. `cpu` must not be deallocated while
 /// module `mod` is still live.
 void setTuneCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
 
+// set Atomic control options for amd gpu.

tarunprabhu wrote:

Nit
```suggestion
// set atomic control options for amd gpu.
```

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


[clang] [clang] Check constexpr int->enum conversions consistently. (PR #143034)

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


@@ -2513,6 +2513,9 @@ void testValueInRangeOfEnumerationValues() {
   // expected-error@-1 {{constexpr variable 'x2' must be initialized by a 
constant expression}}
   // expected-note@-2 {{integer value 8 is outside the valid range of values 
[-8, 7] for the enumeration type 'E1'}}
   E1 x2b = static_cast(8); // ok, not a constant expression context
+  static_assert(static_cast(8), "");

efriedma-quic wrote:

Yes.  The static_assert case wasn't emitting an error because of the 
`Info.EvalMode == EvalInfo::EM_ConstantExpression` check.   The 
"neg_one_constexpr" case wasn't emitting an error because of the ConstexprVar 
check.

(Looking again, I guess I could have also come up with a separate testcase for 
the InConstantContext check, but I didn't really think too deeply about it.)

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


[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread Tarun Prabhu via cfe-commits


@@ -53,6 +53,11 @@ class TargetOptions {
 
   /// Print verbose assembly
   bool asmVerbose = false;
+
+  /// Atomic Control Options for AMD GPU

tarunprabhu wrote:

Nit
```suggestion
  /// Atomic control options for AMD GPU
```

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


[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread Tarun Prabhu via cfe-commits


@@ -58,10 +58,24 @@ void setTargetCPU(mlir::ModuleOp mod, llvm::StringRef cpu);
 /// Get the target CPU string from the Module or return a null reference.
 llvm::StringRef getTargetCPU(mlir::ModuleOp mod);
 
+// Setters and Getters for atomic control options

tarunprabhu wrote:

Nit:
```suggestion
// Setters and getters for atomic control options
```

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


[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread Tarun Prabhu via cfe-commits


@@ -88,6 +88,46 @@ void fir::setTuneCPU(mlir::ModuleOp mod, llvm::StringRef 
cpu) {
   mod->setAttr(tuneCpuName, mlir::StringAttr::get(ctx, cpu));
 }
 
+static constexpr const char *amdgpuIgnoreDenormalModeName =
+"fir.amdgpu.ignore.denormal.mode";
+void fir::setAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod) {
+  auto *ctx = mod.getContext();
+  mod->setAttr(amdgpuIgnoreDenormalModeName, mlir::UnitAttr::get(ctx));
+}
+
+bool fir::getAmdgpuIgnoreDenormalMode(mlir::ModuleOp mod) {
+  if (auto attr =
+  mod->getAttrOfType(amdgpuIgnoreDenormalModeName))
+return true;
+  return false;
+}
+
+static constexpr const char *amdgpuFineGrainedMemoryName =
+"fir.amdgpu.fine.grained.memory";
+void fir::setAmdgpuFineGrainedMemory(mlir::ModuleOp mod) {
+  auto *ctx = mod.getContext();
+  mod->setAttr(amdgpuFineGrainedMemoryName, mlir::UnitAttr::get(ctx));
+}
+
+bool fir::getAmdgpuFineGrainedMemory(mlir::ModuleOp mod) {
+  if (auto attr =

tarunprabhu wrote:

Would it be correct to use `mod->hasAttrOfType` here? If so, that might be 
clearer since, if I understand this correctly, you are returning `true` if the 
attribute is present and `false` otherwise anyway.

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


[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread Tarun Prabhu via cfe-commits


@@ -54,6 +54,20 @@ def FlagsAttr : OpenMP_Attr<"Flags", "flags"> {
   let assemblyFormat = "`<` struct(params) `>`";
 }
 
+//===--===//
+// AtomicControlAttr
+//===--===//
+
+// Runtime library flags attribute that holds information for lowering to LLVM.

tarunprabhu wrote:

I don't understand what this comment is saying. Could this be made a bit 
clearer?

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


[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu commented:

Thanks for this.

Since you have added both `FlangOption` and `FC1Option` in `Options.td`, could 
you add a test that checks that the option is handled by the main driver as 
well as `fc1`. One that simply checks that the option gets passed down to `fc1` 
from the main driver would be sufficient.

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


[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread Tarun Prabhu via cfe-commits

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


[clang] [compiler-rt] [llvm] [DRAFT][memprof][darwin] Support memprof on Darwin platform and add binary access profile (PR #142884)

2025-06-09 Thread Snehasish Kumar via cfe-commits

snehasish wrote:

> @snehasish thanks for the detailed reply! I will take a closer week through 
> the week and get back to you.
> 
> Btw a quick question, our sister team is actually also interested in 
> supporting memprof for Android platform, i.e. getting the access profile of 
> the Android native libraries (inside an android app apk) during app startup , 
> and then order the data symbols (on ELF i believe it's rodata section) for 
> startup performance win.
> 
> The ordering part I believe they should be able to reuse some of 
> @mingmingl-llvm's work, and the patches I just landed for cstring ordering in 
> lld; but for supporting memprof for android platform, although it should be 
> able to use most of the current linux configurations, android does seem to 
> require some specialization by looking at Asan support for android. Given 
> it's android, wondering is there anyone in Google actually also interested in 
> or working on this? Thanks Sharon

Can you share the improvement in startup time observed on MachO? I can reach 
out to the Android toolchain team to gauge interest.

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


[clang] [compiler-rt] [llvm] [DRAFT][memprof][darwin] Support memprof on Darwin platform and add binary access profile (PR #142884)

2025-06-09 Thread via cfe-commits

SharonXSharon wrote:

> Can you share the improvement in startup time observed on MachO? I can reach 
> out to the Android toolchain team to gauge interest.

@snehasish  thanks!

The improvement in startup performance we observed for iOS apps (MachO) are, 
- socialApp1: for cold starts, we reduced 80ms (3%) of the entire app startup 
time (time to network content) on average; 270ms (6%) reduction p95. From 
another perspective, we reduced 5% of the total major page faults for the 
entire app startup phase.
- socialApp2:  for cold starts, we reduced 54ms from app startup on average, 
which is around 12% of the app's premain startup time. 


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


[clang] [flang] [mlir] [flang][flang-driver] atomic control support (PR #143441)

2025-06-09 Thread Tarun Prabhu via cfe-commits


@@ -2911,8 +2911,13 @@ static void genAtomicUpdateStatement(
   if (rightHandClauseList)
 genOmpAtomicHintAndMemoryOrderClauses(converter, *rightHandClauseList, 
hint,
   memoryOrder);
+  auto module = firOpBuilder.getModule();

tarunprabhu wrote:

Could we use a more concrete type instead of `auto` here

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


[clang-tools-extra] [WIP] Warn about misuse of sizeof operator in loops. (PR #143205)

2025-06-09 Thread Malavika Samak via cfe-commits

https://github.com/malavikasamak updated 
https://github.com/llvm/llvm-project/pull/143205

>From 52e4413ea1e701dfe0b24cf957a26bb72732f066 Mon Sep 17 00:00:00 2001
From: MalavikaSamak 
Date: Wed, 21 May 2025 16:06:44 -0700
Subject: [PATCH 1/3] Place holder message for sizeof operator in loops.

---
 .../bugprone/SizeofExpressionCheck.cpp| 17 +-
 .../bugprone/SizeofExpressionCheck.h  |  1 +
 .../checkers/bugprone/sizeof-expression.cpp   | 31 +++
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index f3d4c2255d86e..ee66a880792b8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -72,7 +72,8 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
   Options.get("WarnOnSizeOfPointerToAggregate", true)),
   WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)),
   WarnOnOffsetDividedBySizeOf(
-  Options.get("WarnOnOffsetDividedBySizeOf", true)) {}
+  Options.get("WarnOnOffsetDividedBySizeOf", true)),
+  WarnOnLoopExprSizeOf(Options.get("WarnOnLoopExprSizeOf", true)) {}
 
 void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -86,6 +87,7 @@ void 
SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "WarnOnSizeOfPointer", WarnOnSizeOfPointer);
   Options.store(Opts, "WarnOnOffsetDividedBySizeOf",
 WarnOnOffsetDividedBySizeOf);
+  Options.store(Opts, "WarnOnLoopExprSizeOf", WarnOnLoopExprSizeOf);
 }
 
 void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -93,6 +95,11 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
   // Some of the checks should not match in template code to avoid false
   // positives if sizeof is applied on template argument.
 
+  auto LoopExpr =
+  [](const ast_matchers::internal::Matcher &InnerMatcher) {
+return stmt(anyOf(forStmt(InnerMatcher), whileStmt(InnerMatcher)));
+  };
+
   const auto IntegerExpr = ignoringParenImpCasts(integerLiteral());
   const auto ConstantExpr = ignoringParenImpCasts(
   anyOf(integerLiteral(), unaryOperator(hasUnaryOperand(IntegerExpr)),
@@ -130,6 +137,11 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
this);
   }
 
+  if (WarnOnLoopExprSizeOf) {
+Finder->addMatcher(
+LoopExpr(has(binaryOperator(has(SizeOfExpr.bind("loop-expr"), 
this);
+  }
+
   // Detect sizeof(kPtr) where kPtr is 'const char* kPtr = "abc"';
   const auto CharPtrType = pointerType(pointee(isAnyCharacter()));
   const auto ConstStrLiteralDecl =
@@ -353,6 +365,9 @@ void SizeofExpressionCheck::check(const 
MatchFinder::MatchResult &Result) {
 diag(E->getBeginLoc(),
  "suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?")
 << E->getSourceRange();
+  } else if (const auto *E = Result.Nodes.getNodeAs("loop-expr")) {
+diag(E->getBeginLoc(), "suspicious usage of 'sizeof' in the loop")
+<< E->getSourceRange();
   } else if (const auto *E = Result.Nodes.getNodeAs("sizeof-pointer")) {
 if (Result.Nodes.getNodeAs("struct-type")) {
   diag(E->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
index fbd62cb80fb2d..f7dccf39687a5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h
@@ -32,6 +32,7 @@ class SizeofExpressionCheck : public ClangTidyCheck {
   const bool WarnOnSizeOfPointerToAggregate;
   const bool WarnOnSizeOfPointer;
   const bool WarnOnOffsetDividedBySizeOf;
+  const bool WarnOnLoopExprSizeOf;
 };
 
 } // namespace clang::tidy::bugprone
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp
index 5e6f394152e9d..52b71277466b1 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp
@@ -164,6 +164,37 @@ int Test2(MyConstChar* A) {
   return sum;
 }
 
+struct A {
+   int array[10];
+};
+
+struct B {
+  struct A a;
+};
+
+int square(int num, struct B b) {
+struct A arr[10];
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: suspicious usage of 'sizeof' 
in the loop [bugprone-sizeof-expression]
+for(int i = 0; i < sizeof(arr); i++) {
+   struct A a = arr[i];
+}
+// CHECK-MESSAGES: :[[@LINE+2]]:24: warning: suspicious usage of 
'sizeof(K)'; did you mean 'K'? [bugprone-sizeof-expression]
+// CHECK-MESSAGES: :[[@LINE+1

[clang] [compiler-rt] [llvm] [DRAFT][memprof][darwin] Support memprof on Darwin platform and add binary access profile (PR #142884)

2025-06-09 Thread Snehasish Kumar via cfe-commits

snehasish wrote:

> > Can you share the improvement in startup time observed on MachO? I can 
> > reach out to the Android toolchain team to gauge interest.
> 
> @snehasish thanks!
> 
> The improvement in startup performance we observed for iOS apps (MachO) are,
> 
> * socialApp1: for cold starts, we reduced 80ms (3%) of the entire app startup 
> time (time to network content) on average; 270ms (6%) reduction p95. From 
> another perspective, we reduced 5% of the total major page faults for the 
> entire app startup phase.
> * socialApp2:  for cold starts, we reduced 54ms from app startup on average, 
> which is around 12% of the app's premain startup time.

Great. For my understanding, the baseline app includes some form of PGO e.g. 
temporal profiling? These numbers are *purely* from static data layout on top 
of the baseline?

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


[clang] [flang] [mlir] [flang] Add support for -mrecip[=] (PR #143418)

2025-06-09 Thread Tarun Prabhu via cfe-commits

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

Thanks for the changes, Cameron. LGTM.

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


[clang] [OpenMP 60] Initial parsing/sema for `need_device_addr` modifier on `adjust_args` clause (PR #143442)

2025-06-09 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/include/clang/Sema/SemaOpenMP.h clang/lib/AST/AttrImpl.cpp 
clang/lib/Parse/ParseOpenMP.cpp clang/lib/Sema/SemaOpenMP.cpp 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
clang/test/OpenMP/declare_variant_clauses_ast_print.cpp 
clang/test/OpenMP/declare_variant_clauses_messages.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index dd184ba6a..a327f7a49 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1563,8 +1563,8 @@ void 
Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
   if (DeclVarData && !TI.Sets.empty())
 Actions.OpenMP().ActOnOpenMPDeclareVariantDirective(
 DeclVarData->first, DeclVarData->second, TI, AdjustNothing,
-AdjustNeedDevicePtr, AdjustNeedDeviceAddr, AppendArgs, AdjustArgsLoc, 
AppendArgsLoc,
-SourceRange(Loc, Tok.getLocation()));
+AdjustNeedDevicePtr, AdjustNeedDeviceAddr, AppendArgs, AdjustArgsLoc,
+AppendArgsLoc, SourceRange(Loc, Tok.getLocation()));
 
   // Skip the last annot_pragma_openmp_end.
   (void)ConsumeAnnotationToken();
@@ -4822,8 +4822,8 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind,
 getLangOpts());
 Data.ExtraModifierLoc = Tok.getLocation();
 if (Data.ExtraModifier == OMPC_ADJUST_ARGS_unknown) {
-  Diag(Tok, diag::err_omp_unknown_adjust_args_op) << (getLangOpts().OpenMP 
>=
-  60 ? 1 : 0);
+  Diag(Tok, diag::err_omp_unknown_adjust_args_op)
+  << (getLangOpts().OpenMP >= 60 ? 1 : 0);
   SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch);
 } else {
   ConsumeToken();

``




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


[clang] 339797d - [clang][analyzer] Update python dependency versions (#143433)

2025-06-09 Thread via cfe-commits

Author: Nick Sarnie
Date: 2025-06-09T21:25:58Z
New Revision: 339797d75b3fd93bdb339c6b4ea826a2eeb32c26

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

LOG: [clang][analyzer] Update python dependency versions (#143433)

We need to make sure we aren't vulnerable to
[PYSEC-2020-73](https://osv.dev/vulnerability/PYSEC-2020-73) and
[PYSEC-2019-41](https://osv.dev/vulnerability/PYSEC-2019-41).

Signed-off-by: Sarnie, Nick 

Added: 


Modified: 
clang/utils/analyzer/requirements.txt

Removed: 




diff  --git a/clang/utils/analyzer/requirements.txt 
b/clang/utils/analyzer/requirements.txt
index 8ae8bc88ac191..ed09161e5902e 100644
--- a/clang/utils/analyzer/requirements.txt
+++ b/clang/utils/analyzer/requirements.txt
@@ -1,6 +1,6 @@
 graphviz
 humanize
 matplotlib
-pandas
-psutil
+pandas>=1.0.4
+psutil>=5.6.6
 seaborn



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


[clang] [clang][analyzer] Update python dependency versions (PR #143433)

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

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


[clang] [clang][analyzer] Update python dependency versions (PR #143433)

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

sarnex wrote:

Thanks for the quick reviews!

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


[clang] [OpenMP 60] Initial parsing/sema for `need_device_addr` modifier on `adjust_args` clause (PR #143442)

2025-06-09 Thread Fazlay Rabbi via cfe-commits

https://github.com/mdfazlay updated 
https://github.com/llvm/llvm-project/pull/143442

>From a117e1a3f089b7d92a5df082a2ba584bee57f7d3 Mon Sep 17 00:00:00 2001
From: Fazlay Rabbi 
Date: Mon, 9 Jun 2025 14:12:24 -0700
Subject: [PATCH 1/2] [OpenMP 60] Initial parsing/sema for `need_device_addr`
 modifier on `adjust_args` clause

Adds initial parsing and semantic analysis for `need_device_addr`
modifier on `adjust_args` clause.
---
 clang/include/clang/Basic/Attr.td |  1 +
 .../clang/Basic/DiagnosticParseKinds.td   |  5 ++--
 clang/include/clang/Basic/OpenMPKinds.def |  1 +
 clang/include/clang/Sema/SemaOpenMP.h |  1 +
 clang/lib/AST/AttrImpl.cpp|  6 +
 clang/lib/Parse/ParseOpenMP.cpp   | 19 +-
 clang/lib/Sema/SemaOpenMP.cpp |  5 
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 11 ++--
 .../declare_variant_clauses_ast_print.cpp | 26 ---
 .../declare_variant_clauses_messages.cpp  | 24 -
 10 files changed, 71 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f889e41c8699f..c8e6f7aad5459 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4608,6 +4608,7 @@ def OMPDeclareVariant : InheritableAttr {
 OMPTraitInfoArgument<"TraitInfos">,
 VariadicExprArgument<"AdjustArgsNothing">,
 VariadicExprArgument<"AdjustArgsNeedDevicePtr">,
+VariadicExprArgument<"AdjustArgsNeedDeviceAddr">,
 VariadicOMPInteropInfoArgument<"AppendArgs">,
   ];
   let AdditionalMembers = [{
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 3aa36ad59d0b9..64931ae8f72a9 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1581,8 +1581,9 @@ def err_omp_unexpected_append_op : Error<
   "unexpected operation specified in 'append_args' clause, expected 
'interop'">;
 def err_omp_unexpected_execution_modifier : Error<
   "unexpected 'execution' modifier in non-executable context">;
-def err_omp_unknown_adjust_args_op : Error<
-  "incorrect adjust_args type, expected 'need_device_ptr' or 'nothing'">;
+def err_omp_unknown_adjust_args_op
+: Error<"incorrect adjust_args type, expected 'need_device_ptr'%select{|, "
+"'need_device_addr',}0 or 'nothing'">;
 def err_omp_declare_variant_wrong_clause : Error<
   "expected %select{'match'|'match', 'adjust_args', or 'append_args'}0 clause "
   "on 'omp declare variant' directive">;
diff --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index b0de65df7e397..2b1dc1e0121b2 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -214,6 +214,7 @@ OPENMP_ORIGINAL_SHARING_MODIFIER(default)
 // Adjust-op kinds for the 'adjust_args' clause.
 OPENMP_ADJUST_ARGS_KIND(nothing)
 OPENMP_ADJUST_ARGS_KIND(need_device_ptr)
+OPENMP_ADJUST_ARGS_KIND(need_device_addr)
 
 // Binding kinds for the 'bind' clause.
 OPENMP_BIND_KIND(teams)
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 6498390fe96f7..be6bec2068784 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -849,6 +849,7 @@ class SemaOpenMP : public SemaBase {
   FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI,
   ArrayRef AdjustArgsNothing,
   ArrayRef AdjustArgsNeedDevicePtr,
+  ArrayRef AdjustArgsNeedDeviceAddr,
   ArrayRef AppendArgs, SourceLocation AdjustArgsLoc,
   SourceLocation AppendArgsLoc, SourceRange SR);
 
diff --git a/clang/lib/AST/AttrImpl.cpp b/clang/lib/AST/AttrImpl.cpp
index fefb8f55a9ee2..5875a925d3fb0 100644
--- a/clang/lib/AST/AttrImpl.cpp
+++ b/clang/lib/AST/AttrImpl.cpp
@@ -224,6 +224,12 @@ void OMPDeclareVariantAttr::printPrettyPragma(
 PrintExprs(adjustArgsNeedDevicePtr_begin(), adjustArgsNeedDevicePtr_end());
 OS << ")";
   }
+  if (adjustArgsNeedDeviceAddr_size()) {
+OS << " adjust_args(need_device_addr:";
+PrintExprs(adjustArgsNeedDeviceAddr_begin(),
+   adjustArgsNeedDeviceAddr_end());
+OS << ")";
+  }
 
   auto PrintInteropInfo = [&OS](OMPInteropInfo *Begin, OMPInteropInfo *End) {
 for (OMPInteropInfo *I = Begin; I != End; ++I) {
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index e41e5ba8596b9..dd184ba6ac607 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1483,6 +1483,7 @@ void 
Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr,
   OMPTraitInfo &TI = ASTCtx.getNewOMPTraitInfo();
   SmallVector AdjustNothing;
   SmallVector AdjustNeedDevicePtr;
+  SmallVector AdjustNeedDeviceAddr;
   SmallVector AppendArgs;
   SourceLocation AdjustArgsLoc, AppendArgsLoc;
 
@@ -1515,11 +1516,14 @@ void 
Parser

[clang] Revert "[HIP] use offload wrapper for non-device-only non-rdc (#132869)" (PR #143432)

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

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

thanks. I will take a look

https://github.com/llvm/llvm-project/pull/143432
___
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-09 Thread Daniel Paoliello via cfe-commits


@@ -0,0 +1,599 @@
+//===-- WindowsHotPatch.cpp - Support for Windows hotpatching 
-===//
+//
+// 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
+//
+//===--===//
+//
+// Provides support for the Windows "Secure Hot-Patching" feature.
+//
+// Windows contains technology, called "Secure Hot-Patching" (SHP), for 
securely
+// applying hot-patches to a running system. Hot-patches may be applied to the
+// kernel, kernel-mode components, device drivers, user-mode system services,
+// etc.
+//
+// SHP relies on integration between many tools, including compiler, linker,
+// hot-patch generation tools, and the Windows kernel. This file implements 
that
+// part of the workflow needed in compilers / code generators.
+//
+// SHP is not intended for productivity scenarios such as Edit-and-Continue or
+// interactive development. SHP is intended to minimize downtime during
+// installation of Windows OS patches.
+//
+// In order to work with SHP, LLVM must do all of the following:
+//
+// * On some architectures (X86, AMD64), the function prolog must begin with
+//   hot-patchable instructions. This is handled by the MSVC `/hotpatch` option
+//   and the equivalent `-fms-hotpatch` function. This is necessary because we
+//   generally cannot anticipate which functions will need to be patched in the
+//   future. This option ensures that a function can be hot-patched in the
+//   future, but does not actually generate any hot-patch for it.
+//
+// * For a selected set of functions that are being hot-patched (which are
+//   identified using command-line options), LLVM must generate the
+//   `S_HOTPATCHFUNC` CodeView record (symbol). This record indicates that a
+//   function was compiled with hot-patching enabled.
+//
+//   This implementation uses the `MarkedForWindowsHotPatching` attribute to
+//   annotate those functions that were marked for hot-patching by command-line
+//   parameters. The attribute may be specified by a language front-end by
+//   setting an attribute when a function is created in LLVM IR, or it may be
+//   set by passing LLVM arguments.
+//
+// * For those functions that are hot-patched, LLVM must rewrite references to
+//   global variables so that they are indirected through a `__ref_*` pointer
+//   variable.  For each global variable, that is accessed by a hot-patched
+//   function, e.g. `FOO`, a `__ref_FOO` global pointer variable is created and
+//   all references to the original `FOO` are rewritten as dereferences of the
+//   `__ref_FOO` pointer.
+//
+//   Some globals do not need `__ref_*` indirection. The pointer indirection
+//   behavior can be disabled for these globals by marking them with the
+//   `AllowDirectAccessInHotPatchFunction`.
+//
+// References
+//
+// * "Hotpatching on Windows":
+//   
https://techcommunity.microsoft.com/blog/windowsosplatform/hotpatching-on-windows/2959541
+//
+// * "Hotpatch for Windows client now available":
+//   
https://techcommunity.microsoft.com/blog/windows-itpro-blog/hotpatch-for-windows-client-now-available/4399808
+//
+// * "Get hotpatching for Windows Server":
+//   
https://www.microsoft.com/en-us/windows-server/blog/2025/04/24/tired-of-all-the-restarts-get-hotpatching-for-windows-server/
+//
+//===--===//
+
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/DIBuilder.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "windows-secure-hot-patch"
+
+// A file containing list of mangled function names to mark for hot patching.
+static cl::opt LLVMMSSecureHotPatchFunctionsFile(
+"ms-secure-hotpatch-functions-file", cl::value_desc("filename"),
+cl::desc("A file containing list of mangled function names to mark for "
+ "Windows Secure Hot-Patching"));
+
+// A list of mangled function names to mark for hot patching.
+static cl::list LLVMMSSecureHotPatchFunctionsList(
+"ms-secure-hotpatch-functions-list", cl::value_desc("list"),
+cl::desc("A list of mangled function names to mark for Windows Secure "
+ "Hot-Patching"),
+cl::CommaSeparated);
+
+namespace {
+
+struct GlobalVariableUse {
+  // GlobalVariable *GV;
+  Instruction *User;
+  unsigned Op;
+};
+
+class WindowsSecureHotPatching : public ModulePass {
+public:
+  static char ID;
+
+  WindowsSecureHotPatching() : ModulePass(ID)

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

2025-06-09 Thread Daniel Paoliello via cfe-commits


@@ -0,0 +1,599 @@
+//===-- WindowsHotPatch.cpp - Support for Windows hotpatching 
-===//
+//
+// 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
+//
+//===--===//
+//
+// Provides support for the Windows "Secure Hot-Patching" feature.
+//
+// Windows contains technology, called "Secure Hot-Patching" (SHP), for 
securely
+// applying hot-patches to a running system. Hot-patches may be applied to the
+// kernel, kernel-mode components, device drivers, user-mode system services,
+// etc.
+//
+// SHP relies on integration between many tools, including compiler, linker,
+// hot-patch generation tools, and the Windows kernel. This file implements 
that
+// part of the workflow needed in compilers / code generators.
+//
+// SHP is not intended for productivity scenarios such as Edit-and-Continue or
+// interactive development. SHP is intended to minimize downtime during
+// installation of Windows OS patches.
+//
+// In order to work with SHP, LLVM must do all of the following:
+//
+// * On some architectures (X86, AMD64), the function prolog must begin with
+//   hot-patchable instructions. This is handled by the MSVC `/hotpatch` option
+//   and the equivalent `-fms-hotpatch` function. This is necessary because we
+//   generally cannot anticipate which functions will need to be patched in the
+//   future. This option ensures that a function can be hot-patched in the
+//   future, but does not actually generate any hot-patch for it.
+//
+// * For a selected set of functions that are being hot-patched (which are
+//   identified using command-line options), LLVM must generate the
+//   `S_HOTPATCHFUNC` CodeView record (symbol). This record indicates that a
+//   function was compiled with hot-patching enabled.
+//
+//   This implementation uses the `MarkedForWindowsHotPatching` attribute to
+//   annotate those functions that were marked for hot-patching by command-line
+//   parameters. The attribute may be specified by a language front-end by
+//   setting an attribute when a function is created in LLVM IR, or it may be
+//   set by passing LLVM arguments.
+//
+// * For those functions that are hot-patched, LLVM must rewrite references to
+//   global variables so that they are indirected through a `__ref_*` pointer
+//   variable.  For each global variable, that is accessed by a hot-patched
+//   function, e.g. `FOO`, a `__ref_FOO` global pointer variable is created and
+//   all references to the original `FOO` are rewritten as dereferences of the
+//   `__ref_FOO` pointer.
+//
+//   Some globals do not need `__ref_*` indirection. The pointer indirection
+//   behavior can be disabled for these globals by marking them with the
+//   `AllowDirectAccessInHotPatchFunction`.
+//
+// References
+//
+// * "Hotpatching on Windows":
+//   
https://techcommunity.microsoft.com/blog/windowsosplatform/hotpatching-on-windows/2959541
+//
+// * "Hotpatch for Windows client now available":
+//   
https://techcommunity.microsoft.com/blog/windows-itpro-blog/hotpatch-for-windows-client-now-available/4399808
+//
+// * "Get hotpatching for Windows Server":
+//   
https://www.microsoft.com/en-us/windows-server/blog/2025/04/24/tired-of-all-the-restarts-get-hotpatching-for-windows-server/
+//
+//===--===//
+
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/DIBuilder.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "windows-secure-hot-patch"
+
+// A file containing list of mangled function names to mark for hot patching.
+static cl::opt LLVMMSSecureHotPatchFunctionsFile(
+"ms-secure-hotpatch-functions-file", cl::value_desc("filename"),
+cl::desc("A file containing list of mangled function names to mark for "
+ "Windows Secure Hot-Patching"));
+
+// A list of mangled function names to mark for hot patching.
+static cl::list LLVMMSSecureHotPatchFunctionsList(
+"ms-secure-hotpatch-functions-list", cl::value_desc("list"),
+cl::desc("A list of mangled function names to mark for Windows Secure "
+ "Hot-Patching"),
+cl::CommaSeparated);
+
+namespace {
+
+struct GlobalVariableUse {
+  // GlobalVariable *GV;
+  Instruction *User;
+  unsigned Op;
+};
+
+class WindowsSecureHotPatching : public ModulePass {
+public:
+  static char ID;
+
+  WindowsSecureHotPatching() : ModulePass(ID)

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

2025-06-09 Thread Daniel Paoliello via cfe-commits

https://github.com/dpaoliello edited 
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-09 Thread Daniel Paoliello via cfe-commits

https://github.com/dpaoliello commented:

Can you please add tests for the constant expression rewriting stuff, and not 
redirecting constant GVs without pointers?

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-09 Thread Daniel Paoliello via cfe-commits


@@ -798,6 +798,8 @@ enum AttributeKindCodes {
   ATTR_KIND_NO_DIVERGENCE_SOURCE = 100,
   ATTR_KIND_SANITIZE_TYPE = 101,
   ATTR_KIND_CAPTURES = 102,
+  ATTR_KIND_ALLOW_DIRECT_ACCESS_IN_HOT_PATCH_FUNCTION = 103,
+  ATTR_KIND_MARKED_FOR_WINDOWS_HOT_PATCHING = 104,

dpaoliello wrote:

For consistency

```suggestion
  ATTR_KIND_MARKED_FOR_WINDOWS_SECURE_HOT_PATCHING = 104,
```

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-09 Thread Daniel Paoliello 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 MarkedForWindowsHotPatching

dpaoliello wrote:

Same here, for consistency, "secure" hot patching

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-09 Thread Daniel Paoliello via cfe-commits


@@ -0,0 +1,599 @@
+//===-- WindowsHotPatch.cpp - Support for Windows hotpatching 
-===//
+//
+// 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
+//
+//===--===//
+//
+// Provides support for the Windows "Secure Hot-Patching" feature.
+//
+// Windows contains technology, called "Secure Hot-Patching" (SHP), for 
securely
+// applying hot-patches to a running system. Hot-patches may be applied to the
+// kernel, kernel-mode components, device drivers, user-mode system services,
+// etc.
+//
+// SHP relies on integration between many tools, including compiler, linker,
+// hot-patch generation tools, and the Windows kernel. This file implements 
that
+// part of the workflow needed in compilers / code generators.
+//
+// SHP is not intended for productivity scenarios such as Edit-and-Continue or
+// interactive development. SHP is intended to minimize downtime during
+// installation of Windows OS patches.
+//
+// In order to work with SHP, LLVM must do all of the following:
+//
+// * On some architectures (X86, AMD64), the function prolog must begin with
+//   hot-patchable instructions. This is handled by the MSVC `/hotpatch` option
+//   and the equivalent `-fms-hotpatch` function. This is necessary because we
+//   generally cannot anticipate which functions will need to be patched in the
+//   future. This option ensures that a function can be hot-patched in the
+//   future, but does not actually generate any hot-patch for it.
+//
+// * For a selected set of functions that are being hot-patched (which are
+//   identified using command-line options), LLVM must generate the
+//   `S_HOTPATCHFUNC` CodeView record (symbol). This record indicates that a
+//   function was compiled with hot-patching enabled.
+//
+//   This implementation uses the `MarkedForWindowsHotPatching` attribute to
+//   annotate those functions that were marked for hot-patching by command-line
+//   parameters. The attribute may be specified by a language front-end by
+//   setting an attribute when a function is created in LLVM IR, or it may be
+//   set by passing LLVM arguments.
+//
+// * For those functions that are hot-patched, LLVM must rewrite references to
+//   global variables so that they are indirected through a `__ref_*` pointer
+//   variable.  For each global variable, that is accessed by a hot-patched
+//   function, e.g. `FOO`, a `__ref_FOO` global pointer variable is created and
+//   all references to the original `FOO` are rewritten as dereferences of the
+//   `__ref_FOO` pointer.
+//
+//   Some globals do not need `__ref_*` indirection. The pointer indirection
+//   behavior can be disabled for these globals by marking them with the
+//   `AllowDirectAccessInHotPatchFunction`.
+//
+// References
+//
+// * "Hotpatching on Windows":
+//   
https://techcommunity.microsoft.com/blog/windowsosplatform/hotpatching-on-windows/2959541
+//
+// * "Hotpatch for Windows client now available":
+//   
https://techcommunity.microsoft.com/blog/windows-itpro-blog/hotpatch-for-windows-client-now-available/4399808
+//
+// * "Get hotpatching for Windows Server":
+//   
https://www.microsoft.com/en-us/windows-server/blog/2025/04/24/tired-of-all-the-restarts-get-hotpatching-for-windows-server/
+//
+//===--===//
+
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/DIBuilder.h"
+#include "llvm/IR/DiagnosticInfo.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/LineIterator.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "windows-secure-hot-patch"
+
+// A file containing list of mangled function names to mark for hot patching.
+static cl::opt LLVMMSSecureHotPatchFunctionsFile(
+"ms-secure-hotpatch-functions-file", cl::value_desc("filename"),
+cl::desc("A file containing list of mangled function names to mark for "
+ "Windows Secure Hot-Patching"));
+
+// A list of mangled function names to mark for hot patching.
+static cl::list LLVMMSSecureHotPatchFunctionsList(
+"ms-secure-hotpatch-functions-list", cl::value_desc("list"),
+cl::desc("A list of mangled function names to mark for Windows Secure "
+ "Hot-Patching"),
+cl::CommaSeparated);
+
+namespace {
+
+struct GlobalVariableUse {
+  // GlobalVariable *GV;
+  Instruction *User;
+  unsigned Op;
+};
+
+class WindowsSecureHotPatching : public ModulePass {
+public:
+  static char ID;
+
+  WindowsSecureHotPatching() : ModulePass(ID)

[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-06-09 Thread Oliver Hunt via cfe-commits


@@ -1434,10 +1446,13 @@ namespace {
   QualType ArgType;
 };
 
-unsigned NumPlacementArgs : 31;
-LLVM_PREFERRED_TYPE(bool)
+unsigned NumPlacementArgs : 30;
+LLVM_PREFERRED_TYPE(AlignedAllocationMode)
 unsigned PassAlignmentToPlacementDelete : 1;
+LLVM_PREFERRED_TYPE(TypeAwareAllocationMode)
+unsigned PassTypeToPlacementDelete : 1;

ojhunt wrote:

sorry this slipped my mind once I had verified it was just dead code instead of 
UB lying in wait.

Will push a PR shortly

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


[clang] [compiler-rt] [llvm] [DRAFT][memprof][darwin] Support memprof on Darwin platform and add binary access profile (PR #142884)

2025-06-09 Thread via cfe-commits

SharonXSharon wrote:

> Great. For my understanding, the baseline app includes some form of PGO e.g. 
> temporal profiling? These numbers are _purely_ from static data layout on top 
> of the baseline?

yes the baseline already includes the temporal profiling thus function 
ordering; the win above is purely from ordering the static data in the app 
binaries. 
In fact, the win theoretically should be even higher than this, because in 
MachO binaries, some data symbol names are not unique at this moment, like the 
objc metadata symbols, so we are not ordering those at this moment. We are 
working on uniquing them so the order_file can identify them. 


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


[clang] [Clang] fix missing source location for ':' error in macro-expanded case statements (PR #143460)

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

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/143460

Fixes #143216

--- 

This patch addresses the issue where diagnostics for `case` statements 
originating from macro expansions lacked source location information when the 
colon `:` was missing.


>From dd4953312066cb63ae1a3882270426c87b1f5b7a Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Tue, 10 Jun 2025 02:47:51 +0300
Subject: [PATCH] [Clang] fix missing source location for ':' error in
 macro-expanded case statements

---
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  1 +
 clang/lib/Parse/ParseStmt.cpp  | 14 ++
 clang/test/Parser/switch-recovery.cpp  | 13 +
 4 files changed, 29 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 322686fce0b04..0ecbb4864050c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -689,6 +689,7 @@ Bug Fixes in This Version
 - Fixed type mismatch error when 'builtin-elementwise-math' arguments have 
different qualifiers, this should be well-formed. (#GH141397)
 - Constant evaluation now correctly runs the destructor of a variable declared 
in
   the second clause of a C-style ``for`` loop. (#GH139818)
+- Fixed incorrect diagnostic location for missing ``:`` in case statements 
expanded from macros. (#GH143216)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 0bd8a423c393e..ee8fc66c1822c 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -83,6 +83,7 @@ let CategoryName = "Parse Issue" in {
 def err_expected : Error<"expected %0">;
 def err_expected_either : Error<"expected %0 or %1">;
 def err_expected_after : Error<"expected %1 after %0">;
+def note_macro_expansion : Note<"expanded from macro '%0'">;
 
 def err_param_redefinition : Error<"redefinition of parameter %0">;
 def warn_method_param_redefinition : Warning<"redefinition of method parameter 
%0">;
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index c788723023c8b..5db6dd36f840b 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -833,9 +833,23 @@ StmtResult Parser::ParseCaseStatement(ParsedStmtContext 
StmtCtx,
   << FixItHint::CreateReplacement(ColonLoc, ":");
 } else {
   SourceLocation ExpectedLoc = PP.getLocForEndOfToken(PrevTokLocation);
+  SourceLocation ExprLoc =
+  LHS.get() ? LHS.get()->getExprLoc() : SourceLocation();
+
+  if (ExpectedLoc.isInvalid() && ExprLoc.isMacroID()) {
+ExpectedLoc = PP.getSourceManager().getSpellingLoc(ExprLoc);
+  }
+
   Diag(ExpectedLoc, diag::err_expected_after)
   << "'case'" << tok::colon
   << FixItHint::CreateInsertion(ExpectedLoc, ":");
+
+  if (ExprLoc.isMacroID()) {
+Diag(ExprLoc, diag::note_macro_expansion)
+<< Lexer::getImmediateMacroNameForDiagnostics(
+   ExprLoc, PP.getSourceManager(), getLangOpts());
+  }
+
   ColonLoc = ExpectedLoc;
 }
 
diff --git a/clang/test/Parser/switch-recovery.cpp 
b/clang/test/Parser/switch-recovery.cpp
index baf703cd03aed..5966b04b3f636 100644
--- a/clang/test/Parser/switch-recovery.cpp
+++ b/clang/test/Parser/switch-recovery.cpp
@@ -229,3 +229,16 @@ void fn1() {
 }
 } // expected-error{{expected statement}}
 }
+
+namespace GH143216 {
+#define FOO 1 case 3: // expected-error {{expected ':' after 'case'}}
+
+int f(int x) {
+  switch (x) {
+  case FOO // expected-note {{expanded from macro 'FOO'}}
+return 0;
+  default:
+return 1;
+  }
+}
+}

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


  1   2   3   4   5   >