[clang] [clang-format] Handle requires clause following a pointer type (PR #142893)

2025-06-05 Thread Björn Schäpers via cfe-commits

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

For all sane code this works. Although there are valid codes where a star can 
preceed a requires expression.

https://github.com/llvm/llvm-project/pull/142893
___
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-05 Thread Ziqing Luo via cfe-commits

https://github.com/ziqingluo-90 updated 
https://github.com/llvm/llvm-project/pull/142897

>From 99931f58846f361e409445d06fdfca4f5e7d3bb3 Mon Sep 17 00:00:00 2001
From: Ziqing Luo 
Date: Thu, 5 Jun 2025 12:28:12 +0800
Subject: [PATCH 1/2] [clang][CFG] Fix assertion failure in
 checkIncorrectLogicOperator

`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
---
 clang/lib/Analysis/CFG.cpp | 22 ++
 clang/test/Sema/warn-unreachable_crash.cpp |  8 
 2 files changed, 30 insertions(+)
 create mode 100644 clang/test/Sema/warn-unreachable_crash.cpp

diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 7f37a8b18d46e..c9610cc2888ad 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.
+  int8_t Order = Context->getFloatingTypeOrder(NumExpr1->getType(),
+   NumExpr2->getType());
+  bool convertLoseInfo = false;
+
+  if (Order > 0) {
+// type rank L1 > L2:
+if (L2.convert(L1.getSemantics(), llvm::APFloat::rmNearestTiesToEven,
+   &convertLoseInfo))
+  return {};
+  } else if (Order < 0)
+// type rank L1 < L2:
+if (L1.convert(L2.getSemantics(), llvm::APFloat::rmNearestTiesToEven,
+   &convertLoseInfo))
+  return {};
+  if (convertLoseInfo)
+return {}; // If the conversion loses info, bail
+
   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..7b23f30c6a214
--- /dev/null
+++ b/clang/test/Sema/warn-unreachable_crash.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify -Wunreachable-code %s
+
+static void test(__fp16& x) {
+  if (x != 0 || x != 1.0) { // expected-note{{}}
+  x = 0.9;
+} else
+  x = 0.8; // expected-warning{{code will never be executed}}
+}

>From 1729bb5b4ac8d3711bf1b1cb4451690c4fe461fe Mon Sep 17 00:00:00 2001
From: Ziqing Luo 
Date: Thu, 5 Jun 2025 15:06:13 +0800
Subject: [PATCH 2/2] add test

---
 clang/test/Sema/warn-unreachable_crash.cpp | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang/test/Sema/warn-unreachable_crash.cpp 
b/clang/test/Sema/warn-unreachable_crash.cpp
index 7b23f30c6a214..5fd4cf23744d5 100644
--- a/clang/test/Sema/warn-unreachable_crash.cpp
+++ b/clang/test/Sema/warn-unreachable_crash.cpp
@@ -1,8 +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{{}}
   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{{}}
+  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] [flang] [llvm] Fix and reapply IR PGO support for Flang (PR #142892)

2025-06-05 Thread via cfe-commits

https://github.com/fanju110 updated 
https://github.com/llvm/llvm-project/pull/142892

>From 22ff984bae53f2b51b6046c36077e2eb3a3a2b7c Mon Sep 17 00:00:00 2001
From: fanyikang 
Date: Thu, 5 Jun 2025 11:24:33 +0800
Subject: [PATCH] Fix and reapply IR PGO support for Flang

Fix and reapply IR PGO support for Flang

Co-Authored-By: ict-ql <168183727+ict...@users.noreply.github.com>
Co-Authored-By: Chyaka <52224511+liliumsh...@users.noreply.github.com>
---
 clang/include/clang/Basic/CodeGenOptions.def  |  6 ++-
 clang/include/clang/Basic/CodeGenOptions.h| 22 +++
 clang/include/clang/Basic/ProfileList.h   |  9 ++---
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Basic/ProfileList.cpp   | 20 +-
 clang/lib/CodeGen/BackendUtil.cpp |  9 +
 clang/lib/CodeGen/CodeGenAction.cpp   |  4 +-
 clang/lib/CodeGen/CodeGenFunction.cpp |  3 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  4 ++
 clang/lib/Frontend/CompilerInvocation.cpp |  6 +--
 .../include/flang/Frontend/CodeGenOptions.def |  7 
 flang/include/flang/Frontend/CodeGenOptions.h | 38 +++
 flang/lib/Frontend/CompilerInvocation.cpp | 10 +
 flang/lib/Frontend/FrontendActions.cpp| 26 +
 flang/test/Driver/flang-f-opts.f90|  5 +++
 .../Inputs/gcc-flag-compatibility_IR.proftext | 18 +
 .../gcc-flag-compatibility_IR_entry.proftext  | 11 ++
 flang/test/Profile/gcc-flag-compatibility.f90 | 32 
 .../llvm/Frontend/Driver/CodeGenOptions.h | 11 ++
 llvm/lib/Frontend/Driver/CMakeLists.txt   |  1 +
 llvm/lib/Frontend/Driver/CodeGenOptions.cpp   | 13 +++
 22 files changed, 219 insertions(+), 42 deletions(-)
 create mode 100644 flang/test/Profile/Inputs/gcc-flag-compatibility_IR.proftext
 create mode 100644 
flang/test/Profile/Inputs/gcc-flag-compatibility_IR_entry.proftext
 create mode 100644 flang/test/Profile/gcc-flag-compatibility.f90

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index aad4e107cbeb3..11dad53a52efe 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -223,9 +223,11 @@ AFFECTING_VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os 
(==1) or -Oz (==2) is
 CODEGENOPT(AtomicProfileUpdate , 1, 0) ///< Set -fprofile-update=atomic
 CODEGENOPT(ContinuousProfileSync, 1, 0) ///< Enable continuous instrumentation 
profiling
 /// Choose profile instrumenation kind or no instrumentation.
-ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 4, ProfileNone)
+
+ENUM_CODEGENOPT(ProfileInstr, llvm::driver::ProfileInstrKind, 4, 
llvm::driver::ProfileInstrKind::ProfileNone)
+
 /// Choose profile kind for PGO use compilation.
-ENUM_CODEGENOPT(ProfileUse, ProfileInstrKind, 2, ProfileNone)
+ENUM_CODEGENOPT(ProfileUse, llvm::driver::ProfileInstrKind, 2, 
llvm::driver::ProfileInstrKind::ProfileNone)
 /// Partition functions into N groups and select only functions in group i to 
be
 /// instrumented. Selected group numbers can be 0 to N-1 inclusive.
 VALUE_CODEGENOPT(ProfileTotalFunctionGroups, 32, 1)
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 278803f7bb960..bffbd00b1bd72 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -518,35 +518,41 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   /// Check if Clang profile instrumenation is on.
   bool hasProfileClangInstr() const {
-return getProfileInstr() == ProfileClangInstr;
+return getProfileInstr() ==
+   llvm::driver::ProfileInstrKind::ProfileClangInstr;
   }
 
   /// Check if IR level profile instrumentation is on.
   bool hasProfileIRInstr() const {
-return getProfileInstr() == ProfileIRInstr;
+return getProfileInstr() == llvm::driver::ProfileInstrKind::ProfileIRInstr;
   }
 
   /// Check if CS IR level profile instrumentation is on.
   bool hasProfileCSIRInstr() const {
-return getProfileInstr() == ProfileCSIRInstr;
+return getProfileInstr() ==
+   llvm::driver::ProfileInstrKind::ProfileCSIRInstr;
   }
 
   /// Check if any form of instrumentation is on.
-  bool hasProfileInstr() const { return getProfileInstr() != ProfileNone; }
+  bool hasProfileInstr() const {
+return getProfileInstr() != llvm::driver::ProfileInstrKind::ProfileNone;
+  }
 
   /// Check if Clang profile use is on.
   bool hasProfileClangUse() const {
-return getProfileUse() == ProfileClangInstr;
+return getProfileUse() == 
llvm::driver::ProfileInstrKind::ProfileClangInstr;
   }
 
   /// Check if IR level profile use is on.
   bool hasProfileIRUse() const {
-return getProfileUse() == ProfileIRInstr ||
-   getProfileUse() == ProfileCSIRInstr;
+return getProfileUse() == llvm::driver::ProfileInstrKind::ProfileIRInstr 

[clang] [CIR] Upstream splat op for VectorType (PR #139827)

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

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/139827

>From f43a15892c7f6217be8bb468d4aef15195d8bc74 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Tue, 13 May 2025 21:35:06 +0200
Subject: [PATCH 1/4] [CIR] Upstream splat op for VectorType

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 32 ++
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp|  8 +++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 60 +-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h   | 10 +++
 clang/test/CIR/CodeGen/vector-ext.cpp | 63 +++
 clang/test/CIR/CodeGen/vector.cpp | 63 +++
 clang/test/CIR/IR/vector.cir  | 34 ++
 7 files changed, 268 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 00878f7dd8ed7..b5658c9c02c6c 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2231,4 +2231,36 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
   let hasVerifier = 1;
 }
 
+//===--===//
+// VecSplatOp
+//===--===//
+
+def VecSplatOp : CIR_Op<"vec.splat", [Pure,
+  TypesMatchWith<"type of 'value' matches element type of 'result'", "result",
+ "value", "cast($_self).getElementType()">]> {
+
+  let summary = "Convert a scalar into a vector";
+  let description = [{
+The `cir.vec.splat` operation creates a vector value from a scalar value.
+All elements of the vector have the same value, that of the given scalar.
+
+It's a separate operation from `cir.vec.create` because more
+efficient LLVM IR can be generated for it, and because some optimization 
and
+analysis passes can benefit from knowing that all elements of the vector
+have the same value.
+
+```mlir
+%value = cir.const #cir.int<3> : !s32i
+%value_vec = cir.vec.splat %value : !s32i, !cir.vector<4 x !s32i>
+```
+  }];
+
+  let arguments = (ins CIR_AnyType:$value);
+  let results = (outs CIR_VectorType:$result);
+
+  let assemblyFormat = [{
+$value `:` type($value) `,` qualified(type($result)) attr-dict
+  }];
+}
+
 #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index a7899fccc47fb..cf080516de618 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -1763,6 +1763,14 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr 
*ce) {
   cgf.convertType(destTy));
   }
 
+  case CK_VectorSplat: {
+// Create a vector object and fill all elements with the same scalar value.
+assert(destTy->isVectorType() && "CK_VectorSplat to non-vector type");
+return builder.create(
+cgf.getLoc(subExpr->getSourceRange()), cgf.convertType(destTy),
+Visit(subExpr));
+  }
+
   default:
 cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(),
"CastExpr: ", ce->getCastKindName());
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index bbfd5df925eca..e0569e2244b77 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1731,8 +1731,9 @@ void ConvertCIRToLLVMPass::runOnOperation() {
CIRToLLVMVecExtractOpLowering,
CIRToLLVMVecInsertOpLowering,
CIRToLLVMVecCmpOpLowering,
-   CIRToLLVMVecShuffleDynamicOpLowering,
-   CIRToLLVMVecTernaryOpLowering
+   CIRToLLVMVecSplatOpLowering,
+   CIRToLLVMVecTernaryOpLowering,
+   CIRToLLVMVecShuffleDynamicOpLowering
   // clang-format on
   >(converter, patterns.getContext());
 
@@ -1883,6 +1884,61 @@ mlir::LogicalResult 
CIRToLLVMVecCmpOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMVecSplatOpLowering::matchAndRewrite(
+cir::VecSplatOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+  // Vector splat can be implemented with an `insertelement` and a
+  // `shufflevector`, which is better than an `insertelement` for each
+  // element in the vector. Start with an undef vector. Insert the value into
+  // the first element. Then use a `shufflevector` with a mask of all 0 to
+  // fill out the entire vector with that value.
+  const auto vecTy = mlir::cast(op.getType());
+  const mlir::Type llvmTy = typeConverter->convertType(vecTy);
+  const mlir::Location loc = op.getLoc();
+  const mlir::Value poison = rewriter.create(loc, 
llvmTy);
+
+  const mlir::Value elementValue = adaptor.getValue();
+  if (mlir::isa(elementValue.getDefiningOp())) {

[clang] [CIR] Upstream splat op for VectorType (PR #139827)

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

AmrDeveloper wrote:

> Since #14 was merged, please mirror additional changes from 
> [llvm/clangir#1626](https://github.com/llvm/clangir/pull/1626) before merging.

I mirrored changes related to the Splat op

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


[libclc] 8c3019e - [libclc] Add (fast) normalize to CLC; add half overloads (#139759)

2025-06-05 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-06-05T09:11:36+01:00
New Revision: 8c3019ecf4e849d1a9fc14559f06ac77d911ce13

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

LOG: [libclc] Add (fast) normalize to CLC; add half overloads (#139759)

For simplicity the half overloads just call into the float versions of
the builtin. Otherwise there are no codegen changes to any target.

Added: 
libclc/clc/include/clc/geometric/clc_fast_normalize.h
libclc/clc/include/clc/geometric/clc_normalize.h
libclc/clc/lib/generic/geometric/clc_fast_normalize.cl
libclc/clc/lib/generic/geometric/clc_fast_normalize.inc
libclc/clc/lib/generic/geometric/clc_normalize.cl
libclc/clc/lib/generic/geometric/clc_normalize.inc

Modified: 
libclc/clc/lib/generic/SOURCES
libclc/opencl/lib/generic/geometric/fast_normalize.cl
libclc/opencl/lib/generic/geometric/normalize.cl

Removed: 
libclc/opencl/lib/generic/geometric/fast_normalize.inc



diff  --git a/libclc/clc/include/clc/geometric/clc_fast_normalize.h 
b/libclc/clc/include/clc/geometric/clc_fast_normalize.h
new file mode 100644
index 0..66eed8b83ab18
--- /dev/null
+++ b/libclc/clc/include/clc/geometric/clc_fast_normalize.h
@@ -0,0 +1,22 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef __CLC_GEOMETRIC_CLC_FAST_NORMALIZE_H__
+#define __CLC_GEOMETRIC_CLC_FAST_NORMALIZE_H__
+
+#define __FLOAT_ONLY
+#define __CLC_GEOMETRIC_RET_GENTYPE
+#define __CLC_FUNCTION __clc_fast_normalize
+#define __CLC_BODY 
+#include 
+
+#undef __CLC_FUNCTION
+#undef __CLC_GEOMETRIC_RET_GENTYPE
+#undef __FLOAT_ONLY
+
+#endif // __CLC_GEOMETRIC_CLC_FAST_NORMALIZE_H__

diff  --git a/libclc/clc/include/clc/geometric/clc_normalize.h 
b/libclc/clc/include/clc/geometric/clc_normalize.h
new file mode 100644
index 0..3058a72b2bbbe
--- /dev/null
+++ b/libclc/clc/include/clc/geometric/clc_normalize.h
@@ -0,0 +1,20 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef __CLC_GEOMETRIC_CLC_NORMALIZE_H__
+#define __CLC_GEOMETRIC_CLC_NORMALIZE_H__
+
+#define __CLC_GEOMETRIC_RET_GENTYPE
+#define __CLC_FUNCTION __clc_normalize
+#define __CLC_BODY 
+#include 
+
+#undef __CLC_FUNCTION
+#undef __CLC_GEOMETRIC_RET_GENTYPE
+
+#endif // __CLC_GEOMETRIC_CLC_NORMALIZE_H__

diff  --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index 0b5a805cfc336..d285bbba3dd26 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -9,7 +9,9 @@ geometric/clc_distance.cl
 geometric/clc_dot.cl
 geometric/clc_fast_distance.cl
 geometric/clc_fast_length.cl
+geometric/clc_fast_normalize.cl
 geometric/clc_length.cl
+geometric/clc_normalize.cl
 integer/clc_abs.cl
 integer/clc_abs_
diff .cl
 integer/clc_add_sat.cl

diff  --git a/libclc/clc/lib/generic/geometric/clc_fast_normalize.cl 
b/libclc/clc/lib/generic/geometric/clc_fast_normalize.cl
new file mode 100644
index 0..85684d0f49bc1
--- /dev/null
+++ b/libclc/clc/lib/generic/geometric/clc_fast_normalize.cl
@@ -0,0 +1,15 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+#define __FLOAT_ONLY
+#define __CLC_BODY 
+#include 

diff  --git a/libclc/clc/lib/generic/geometric/clc_fast_normalize.inc 
b/libclc/clc/lib/generic/geometric/clc_fast_normalize.inc
new file mode 100644
index 0..e4c3ab2c5a657
--- /dev/null
+++ b/libclc/clc/lib/generic/geometric/clc_fast_normalize.inc
@@ -0,0 +1,23 @@
+//===--===//
+//
+// 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
+//
+//===-

[clang] [Clang] Set the FTM for trivial relocation (PR #142936)

2025-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)


Changes

The language of side seems fairly stable.
Setting the feature test macro will ease implementation in standard libraries.

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


3 Files Affected:

- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+1-1) 
- (modified) clang/test/Lexer/cxx-features.cpp (+4) 
- (modified) clang/www/cxx_status.html (+1-6) 


``diff
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 69a91eef6aedb..ef1a508a96c35 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -773,7 +773,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
   Builder.defineMacro("__cpp_pack_indexing", "202311L");
   Builder.defineMacro("__cpp_deleted_function", "202403L");
   Builder.defineMacro("__cpp_variadic_friend", "202403L");
-  // Builder.defineMacro("__cpp_trivial_relocatability", "202502L");
+  Builder.defineMacro("__cpp_trivial_relocatability", "202502L");
 
   if (LangOpts.Char8)
 Builder.defineMacro("__cpp_char8_t", "202207L");
diff --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index 8c1867d5c7365..ced5bcaf0db16 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -49,6 +49,10 @@
 #error "wrong value for __cpp_placeholder_variables"
 #endif
 
+#if check(trivial_relocatability, 202502, 202502, 202502, 202502, 202502, 
202502, 202502)
+#error "wrong value for __cpp_trivial_relocatability"
+#endif
+
 // --- C++23 features ---
 
 #if check(auto_cast, 0, 0, 0, 0, 0, 202110, 202110)
diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index dff57689e84b9..cbcf462970b7f 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -280,12 +280,7 @@ C++2c implementation status
  
   Trivial Relocatability
   https://wg21.link/P2786";>P2786R13
-  
-
-  Clang 21 (Partial)
-  The feature test macro (__cpp_trivial_relocatability) has 
not yet been set.
-
-  
+  Clang 21
  
  
   #embed

``




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


[clang] [Clang][Parse][NFC] Use `llvm::function_ref<>` instead of `std::optional>` (PR #142906)

2025-06-05 Thread Corentin Jabot via cfe-commits

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


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


[clang] [AArch64] Change the coercion type of structs with pointer members. (PR #135064)

2025-06-05 Thread David Green via cfe-commits

https://github.com/davemgreen updated 
https://github.com/llvm/llvm-project/pull/135064

>From 6667abfc2191ffca673767c92713f346599f2a35 Mon Sep 17 00:00:00 2001
From: David Green 
Date: Thu, 5 Jun 2025 12:01:08 +0100
Subject: [PATCH] [AArch64] Change the coercion type of structs with pointer
 members.

The aim here is to avoid a ptrtoint->inttoptr round-trip throught the function
argument whilst keeping the calling convention the same. Given a struct which
is <= 128bits in size, which can only contain either 1 or 2 pointers, we
convert to a ptr or [2 x ptr] as opposed to the old coercion that uses i64 or
[2 x i64].
---
 clang/lib/CodeGen/Targets/AArch64.cpp | 28 +++
 .../AArch64/struct-coerce-using-ptr.cpp   | 50 +--
 clang/test/CodeGen/ptrauth-in-c-struct.c  |  2 +-
 .../CodeGenCXX/ptrauth-qualifier-struct.cpp   |  2 +-
 clang/test/CodeGenCXX/trivial_abi.cpp | 13 ++---
 5 files changed, 59 insertions(+), 36 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index a318b619d76a6..3efe6ab4ea9c0 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -487,9 +487,37 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType 
Ty, bool IsVariadicFn,
 }
 Size = llvm::alignTo(Size, Alignment);
 
+// If the Aggregate is made up of pointers, use an array of pointers for 
the
+// coerced type. This prevents having to convert ptr2int->int2ptr through
+// the call, allowing alias analysis to produce better code.
+auto ContainsOnlyPointers = [&](const auto &Self, QualType Ty) {
+  if (isEmptyRecord(getContext(), Ty, true))
+return false;
+  const RecordType *RT = Ty->getAs();
+  if (!RT)
+return false;
+  const RecordDecl *RD = RT->getDecl();
+  if (const CXXRecordDecl *CXXRD = dyn_cast(RD)) {
+for (const auto &I : CXXRD->bases())
+  if (!Self(Self, I.getType()))
+return false;
+  }
+  return all_of(RD->fields(), [&](FieldDecl *FD) {
+QualType FDTy = FD->getType();
+if (FDTy->isArrayType())
+  FDTy = getContext().getBaseElementType(FDTy);
+return (FDTy->isPointerOrReferenceType() &&
+getContext().getTypeSize(FDTy) == 64) ||
+   Self(Self, FDTy);
+  });
+};
+
 // We use a pair of i64 for 16-byte aggregate with 8-byte alignment.
 // For aggregates with 16-byte alignment, we use i128.
 llvm::Type *BaseTy = llvm::Type::getIntNTy(getVMContext(), Alignment);
+if ((Size == 64 || Size == 128) && Alignment == 64 &&
+ContainsOnlyPointers(ContainsOnlyPointers, Ty))
+  BaseTy = llvm::PointerType::getUnqual(getVMContext());
 return ABIArgInfo::getDirect(
 Size == Alignment ? BaseTy
   : llvm::ArrayType::get(BaseTy, Size / Alignment));
diff --git a/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp 
b/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp
index f7a44a5999887..a41f315340b57 100644
--- a/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp
+++ b/clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp
@@ -29,12 +29,11 @@ struct Sp {
 int *x;
 };
 // CHECK-A64-LABEL: define dso_local void @_Z2Tp2Sp(
-// CHECK-A64-SAME: i64 [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64-SAME: ptr [[S_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-A64-NEXT:  [[ENTRY:.*:]]
 // CHECK-A64-NEXT:[[S:%.*]] = alloca [[STRUCT_SP:%.*]], align 8
 // CHECK-A64-NEXT:[[COERCE_DIVE:%.*]] = getelementptr inbounds nuw 
[[STRUCT_SP]], ptr [[S]], i32 0, i32 0
-// CHECK-A64-NEXT:[[COERCE_VAL_IP:%.*]] = inttoptr i64 [[S_COERCE]] to ptr
-// CHECK-A64-NEXT:store ptr [[COERCE_VAL_IP]], ptr [[COERCE_DIVE]], align 8
+// CHECK-A64-NEXT:store ptr [[S_COERCE]], ptr [[COERCE_DIVE]], align 8
 // CHECK-A64-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SP]], 
ptr [[S]], i32 0, i32 0
 // CHECK-A64-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 8
 // CHECK-A64-NEXT:store i32 1, ptr [[TMP0]], align 4
@@ -58,10 +57,10 @@ struct Spp {
 int *x, *y;
 };
 // CHECK-A64-LABEL: define dso_local void @_Z3Tpp3Spp(
-// CHECK-A64-SAME: [2 x i64] [[S_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK-A64-SAME: [2 x ptr] [[S_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-A64-NEXT:  [[ENTRY:.*:]]
 // CHECK-A64-NEXT:[[S:%.*]] = alloca [[STRUCT_SPP:%.*]], align 8
-// CHECK-A64-NEXT:store [2 x i64] [[S_COERCE]], ptr [[S]], align 8
+// CHECK-A64-NEXT:store [2 x ptr] [[S_COERCE]], ptr [[S]], align 8
 // CHECK-A64-NEXT:[[X:%.*]] = getelementptr inbounds nuw [[STRUCT_SPP]], 
ptr [[S]], i32 0, i32 0
 // CHECK-A64-NEXT:[[TMP0:%.*]] = load ptr, ptr [[X]], align 8
 // CHECK-A64-NEXT:store i32 1, ptr [[TMP0]], align 4
@@ -135,10 +134,10 @@ struct Srp {
 int &x, *y;
 };
 // CHECK-A64-LABEL: define dso_local void @_Z3Trp3Srp(
-// CHECK-A64-SAME: [2 x i64] [[S_COERCE:%.*]]) #[[ATTR0]] {
+// C

[clang] [AArch64] Change the coercion type of structs with pointer members. (PR #135064)

2025-06-05 Thread David Green via cfe-commits

davemgreen wrote:

Rebase and ping - it feels like this is a decent compromise for keeping the 
code simple.

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


[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-05 Thread via cfe-commits

https://github.com/MaggieYingYi updated 
https://github.com/llvm/llvm-project/pull/142409

>From c0cc666ab8864b665539a857dbdae6c592266227 Mon Sep 17 00:00:00 2001
From: Ying Yi 
Date: Mon, 2 Jun 2025 10:21:22 +0100
Subject: [PATCH 1/5] [Frontend][PCH]-Add support for ignoring PCH options
 (-ignore-pch).

Visual Studio has an argument to ignore all PCH related switches. clang-cl has 
also support option /Y-. Having the same option in clang would be helpful. This 
commit is to add support for ignoring PCH options (-ignore-pch).
---
 clang/docs/PCHInternals.rst   |  10 ++
 clang/docs/UsersManual.rst|  14 +++
 clang/include/clang/Driver/Options.td |   2 +
 clang/lib/Frontend/CompilerInvocation.cpp |   9 ++
 clang/test/PCH/Inputs/ignored-pch.h   |   6 ++
 clang/test/PCH/ignored-pch.c  | 114 ++
 6 files changed, 155 insertions(+)
 create mode 100644 clang/test/PCH/Inputs/ignored-pch.h
 create mode 100644 clang/test/PCH/ignored-pch.c

diff --git a/clang/docs/PCHInternals.rst b/clang/docs/PCHInternals.rst
index 079fba16711dc..de0b341460cac 100644
--- a/clang/docs/PCHInternals.rst
+++ b/clang/docs/PCHInternals.rst
@@ -31,6 +31,16 @@ option:
 
   $ clang -cc1 -include-pch test.h.pch test.c -o test.s
 
+To ignore PCH options using ``clang -cc1``, use the option `-ignore-pch`:
+
+.. code-block:: bash
+
+  $ clang -cc1 test.h -emit-pch -ignore-pch -o test.h.pch
+  $ clang -cc1 -include-pch test.h.pch -ignore-pch test.c -o test.s
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+
 Design Philosophy
 -
 
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index eb9a812f0c1c9..f12b6b4c02193 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1458,6 +1458,20 @@ will be processed from the PCH file. Otherwise, Clang 
will report an error.
   ``test.h`` since ``test.h`` was included directly in the source file and not
   specified on the command line using ``-include-pch``.
 
+Ignoring a PCH File
+^^^
+
+To ignore a PCH file using Clang, the `-Xclang -ignore-pch` option is passed to
+``clang``:
+
+.. code-block:: console
+
+  $ clang -x c-header test.h -Xclang -ignore-pch -o test.h.pch
+  $ clang -include-pch test.h.pch -Xclang -ignore-pch test.c -o test
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+
 Relocatable PCH Files
 ^
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5ca31c253ed8f..3ed87608bf592 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8127,6 +8127,8 @@ def emit_header_unit : Flag<["-"], "emit-header-unit">,
   HelpText<"Generate C++20 header units from header files">;
 def emit_pch : Flag<["-"], "emit-pch">,
   HelpText<"Generate pre-compiled header file">;
+def ignore_pch : Flag<["-"], "ignore-pch">,
+  HelpText<"Ignore pre-compiled header options">;
 def emit_llvm_only : Flag<["-"], "emit-llvm-only">,
   HelpText<"Build ASTs and convert to LLVM, discarding output">;
 def emit_codegen_only : Flag<["-"], "emit-codegen-only">,
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2c02719121c73..19f81ff2fbe9d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2982,6 +2982,15 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
 #undef FRONTEND_OPTION_WITH_MARSHALLING
 
   Opts.ProgramAction = frontend::ParseSyntaxOnly;
+
+  // If -ignore-pch is used, all pch handling is disabled. clang pch-related
+  // flags are removed.
+  if (Args.hasArg(options::OPT_ignore_pch)) {
+Args.eraseArg(options::OPT_emit_pch);
+Args.eraseArg(options::OPT_include_pch);
+Args.eraseArg(options::OPT_ignore_pch);
+  }
+
   if (const Arg *A = Args.getLastArg(OPT_Action_Group)) {
 OptSpecifier Opt = OptSpecifier(A->getOption().getID());
 std::optional ProgramAction = getFrontendAction(Opt);
diff --git a/clang/test/PCH/Inputs/ignored-pch.h 
b/clang/test/PCH/Inputs/ignored-pch.h
new file mode 100644
index 0..0956f9da1cb16
--- /dev/null
+++ b/clang/test/PCH/Inputs/ignored-pch.h
@@ -0,0 +1,6 @@
+#ifndef IGNORED_PCH_H
+#define IGNORED_PCH_H
+inline int f() {
+  return 42;
+}
+#endif // IGNORED_PCH_H
\ No newline at end of file
diff --git a/clang/test/PCH/ignored-pch.c b/clang/test/PCH/ignored-pch.c
new file mode 100644
index 0..198ad0fde7d05
--- /dev/null
+++ b/clang/test/PCH/ignored-pch.c
@@ -0,0 +1,114 @@
+// RUN: rm -rf %t.pch %t.ll
+// RUN: %clang_cc1 -x c-header %S/Inputs/ignored-pch.h -emit-pch -o %t.pch
+// RUN: %clang_cc1 %s -include-pch %t.pch -emit-llvm -o %t.ll
+// RUN: ls %t.pch | FileCheck --check-prefix=CHECK-PC

[clang] [CIR] Implement folder for VecTernaryOp (PR #142946)

2025-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds a folder for the VecTernaryOp

Issue https://github.com/llvm/llvm-project/issues/136487

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


4 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+2) 
- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+35) 
- (modified) clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp (+3-3) 
- (added) clang/test/CIR/Transforms/vector-ternary-fold.cir (+20) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 00878f7dd8ed7..eb439f7aa1527 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2228,7 +2228,9 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
 `(` $cond `,` $lhs`,` $rhs `)` `:` qualified(type($cond)) `,`
 qualified(type($lhs)) attr-dict
   }];
+
   let hasVerifier = 1;
+  let hasFolder = 1;
 }
 
 #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index fa7fb592a3cd6..f585254d3340b 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1638,6 +1638,41 @@ LogicalResult cir::VecTernaryOp::verify() {
   return success();
 }
 
+OpFoldResult cir::VecTernaryOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute cond = adaptor.getCond();
+  mlir::Attribute lhs = adaptor.getLhs();
+  mlir::Attribute rhs = adaptor.getRhs();
+
+  if (mlir::isa_and_nonnull(cond) &&
+  mlir::isa_and_nonnull(lhs) &&
+  mlir::isa_and_nonnull(rhs)) {
+auto condVec = mlir::cast(cond);
+auto lhsVec = mlir::cast(lhs);
+auto rhsVec = mlir::cast(rhs);
+
+mlir::ArrayAttr condElts = condVec.getElts();
+
+SmallVector elements;
+elements.reserve(condElts.size());
+
+for (const auto &[idx, condAttr] :
+ llvm::enumerate(condElts.getAsRange())) {
+  if (condAttr.getSInt()) {
+elements.push_back(lhsVec.getElts()[idx]);
+continue;
+  }
+
+  elements.push_back(rhsVec.getElts()[idx]);
+}
+
+cir::VectorType vecTy = getLhs().getType();
+return cir::ConstVectorAttr::get(
+vecTy, mlir::ArrayAttr::get(getContext(), elements));
+  }
+
+  return {};
+}
+
 
//===--===//
 // TableGen'd op method definitions
 
//===--===//
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp 
b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index 7d03e374c27e8..aa3e97033cdda 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
@@ -138,10 +138,10 @@ void CIRCanonicalizePass::runOnOperation() {
 assert(!cir::MissingFeatures::complexRealOp());
 assert(!cir::MissingFeatures::complexImagOp());
 assert(!cir::MissingFeatures::callOp());
-// CastOp, UnaryOp, VecExtractOp and VecShuffleDynamicOp are here to 
perform
-// a manual `fold` in applyOpPatternsGreedily.
+// CastOp, UnaryOp, VecExtractOp, VecShuffleDynamicOp and VecTernaryOp are
+// here to perform a manual `fold` in applyOpPatternsGreedily.
 if (isa(op))
+VecExtractOp, VecShuffleDynamicOp, VecTernaryOp>(op))
   ops.push_back(op);
   });
 
diff --git a/clang/test/CIR/Transforms/vector-ternary-fold.cir 
b/clang/test/CIR/Transforms/vector-ternary-fold.cir
new file mode 100644
index 0..f2e18576da74b
--- /dev/null
+++ b/clang/test/CIR/Transforms/vector-ternary-fold.cir
@@ -0,0 +1,20 @@
+// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
+
+!s32i = !cir.int
+
+module {
+  cir.func @vector_ternary_fold_test() -> !cir.vector<4 x !s32i> {
+%cond = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<0> : 
!s32i, #cir.int<1> : !s32i, #cir.int<0> : !s32i]> : !cir.vector<4 x !s32i>
+%lhs = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : 
!s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
+%rhs = cir.const #cir.const_vector<[#cir.int<5> : !s32i, #cir.int<6> : 
!s32i, #cir.int<7> : !s32i, #cir.int<8> : !s32i]> : !cir.vector<4 x !s32i>
+%res = cir.vec.ternary(%cond, %lhs, %rhs) : !cir.vector<4 x !s32i>, 
!cir.vector<4 x !s32i>
+cir.return %res : !cir.vector<4 x !s32i>
+  }
+
+  // [1, 0, 1, 0] ? [1, 2, 3, 4] : [5, 6, 7, 8] Will be fold to [1, 6, 3, 8]
+  // CHECK: cir.func @vector_ternary_fold_test() -> !cir.vector<4 x !s32i> {
+  // CHECK-NEXT: %[[RES:.*]] = cir.const #cir.const_vector<[#cir.int<1> : 
!s32i, #cir.int<6> : !s32i, #cir.int<3> : !s32i, #cir.int<8> : !s32i]> : 
!cir.vector<4 x !s32i>
+  // CHECK-NEXT: cir.return %[[RES]] : !cir.vector<4 x !s32i>
+}
+
+

``




https://github.com/llvm/llvm-project/pull/142946

[clang] [CIR] Implement folder for VecTernaryOp (PR #142946)

2025-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds a folder for the VecTernaryOp

Issue https://github.com/llvm/llvm-project/issues/136487

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


4 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+2) 
- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+35) 
- (modified) clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp (+3-3) 
- (added) clang/test/CIR/Transforms/vector-ternary-fold.cir (+20) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 00878f7dd8ed7..eb439f7aa1527 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2228,7 +2228,9 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
 `(` $cond `,` $lhs`,` $rhs `)` `:` qualified(type($cond)) `,`
 qualified(type($lhs)) attr-dict
   }];
+
   let hasVerifier = 1;
+  let hasFolder = 1;
 }
 
 #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index fa7fb592a3cd6..f585254d3340b 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1638,6 +1638,41 @@ LogicalResult cir::VecTernaryOp::verify() {
   return success();
 }
 
+OpFoldResult cir::VecTernaryOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute cond = adaptor.getCond();
+  mlir::Attribute lhs = adaptor.getLhs();
+  mlir::Attribute rhs = adaptor.getRhs();
+
+  if (mlir::isa_and_nonnull(cond) &&
+  mlir::isa_and_nonnull(lhs) &&
+  mlir::isa_and_nonnull(rhs)) {
+auto condVec = mlir::cast(cond);
+auto lhsVec = mlir::cast(lhs);
+auto rhsVec = mlir::cast(rhs);
+
+mlir::ArrayAttr condElts = condVec.getElts();
+
+SmallVector elements;
+elements.reserve(condElts.size());
+
+for (const auto &[idx, condAttr] :
+ llvm::enumerate(condElts.getAsRange())) {
+  if (condAttr.getSInt()) {
+elements.push_back(lhsVec.getElts()[idx]);
+continue;
+  }
+
+  elements.push_back(rhsVec.getElts()[idx]);
+}
+
+cir::VectorType vecTy = getLhs().getType();
+return cir::ConstVectorAttr::get(
+vecTy, mlir::ArrayAttr::get(getContext(), elements));
+  }
+
+  return {};
+}
+
 
//===--===//
 // TableGen'd op method definitions
 
//===--===//
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp 
b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index 7d03e374c27e8..aa3e97033cdda 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
@@ -138,10 +138,10 @@ void CIRCanonicalizePass::runOnOperation() {
 assert(!cir::MissingFeatures::complexRealOp());
 assert(!cir::MissingFeatures::complexImagOp());
 assert(!cir::MissingFeatures::callOp());
-// CastOp, UnaryOp, VecExtractOp and VecShuffleDynamicOp are here to 
perform
-// a manual `fold` in applyOpPatternsGreedily.
+// CastOp, UnaryOp, VecExtractOp, VecShuffleDynamicOp and VecTernaryOp are
+// here to perform a manual `fold` in applyOpPatternsGreedily.
 if (isa(op))
+VecExtractOp, VecShuffleDynamicOp, VecTernaryOp>(op))
   ops.push_back(op);
   });
 
diff --git a/clang/test/CIR/Transforms/vector-ternary-fold.cir 
b/clang/test/CIR/Transforms/vector-ternary-fold.cir
new file mode 100644
index 0..f2e18576da74b
--- /dev/null
+++ b/clang/test/CIR/Transforms/vector-ternary-fold.cir
@@ -0,0 +1,20 @@
+// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
+
+!s32i = !cir.int
+
+module {
+  cir.func @vector_ternary_fold_test() -> !cir.vector<4 x !s32i> {
+%cond = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<0> : 
!s32i, #cir.int<1> : !s32i, #cir.int<0> : !s32i]> : !cir.vector<4 x !s32i>
+%lhs = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : 
!s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
+%rhs = cir.const #cir.const_vector<[#cir.int<5> : !s32i, #cir.int<6> : 
!s32i, #cir.int<7> : !s32i, #cir.int<8> : !s32i]> : !cir.vector<4 x !s32i>
+%res = cir.vec.ternary(%cond, %lhs, %rhs) : !cir.vector<4 x !s32i>, 
!cir.vector<4 x !s32i>
+cir.return %res : !cir.vector<4 x !s32i>
+  }
+
+  // [1, 0, 1, 0] ? [1, 2, 3, 4] : [5, 6, 7, 8] Will be fold to [1, 6, 3, 8]
+  // CHECK: cir.func @vector_ternary_fold_test() -> !cir.vector<4 x !s32i> {
+  // CHECK-NEXT: %[[RES:.*]] = cir.const #cir.const_vector<[#cir.int<1> : 
!s32i, #cir.int<6> : !s32i, #cir.int<3> : !s32i, #cir.int<8> : !s32i]> : 
!cir.vector<4 x !s32i>
+  // CHECK-NEXT: cir.return %[[RES]] : !cir.vector<4 x !s32i>
+}
+
+

``




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

[clang] [CIR] Implement folder for VecTernaryOp (PR #142946)

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

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

This change adds a folder for the VecTernaryOp

Issue https://github.com/llvm/llvm-project/issues/136487

>From ac8277b48d0affa78f5e5e943e0179c27dd033ec Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Thu, 5 Jun 2025 13:08:57 +0200
Subject: [PATCH] [CIR] Implement folder for VecTernaryOp

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  2 ++
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 35 +++
 .../Dialect/Transforms/CIRCanonicalize.cpp|  6 ++--
 .../CIR/Transforms/vector-ternary-fold.cir| 20 +++
 4 files changed, 60 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CIR/Transforms/vector-ternary-fold.cir

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 00878f7dd8ed7..eb439f7aa1527 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2228,7 +2228,9 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
 `(` $cond `,` $lhs`,` $rhs `)` `:` qualified(type($cond)) `,`
 qualified(type($lhs)) attr-dict
   }];
+
   let hasVerifier = 1;
+  let hasFolder = 1;
 }
 
 #endif // CLANG_CIR_DIALECT_IR_CIROPS_TD
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index fa7fb592a3cd6..f585254d3340b 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1638,6 +1638,41 @@ LogicalResult cir::VecTernaryOp::verify() {
   return success();
 }
 
+OpFoldResult cir::VecTernaryOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute cond = adaptor.getCond();
+  mlir::Attribute lhs = adaptor.getLhs();
+  mlir::Attribute rhs = adaptor.getRhs();
+
+  if (mlir::isa_and_nonnull(cond) &&
+  mlir::isa_and_nonnull(lhs) &&
+  mlir::isa_and_nonnull(rhs)) {
+auto condVec = mlir::cast(cond);
+auto lhsVec = mlir::cast(lhs);
+auto rhsVec = mlir::cast(rhs);
+
+mlir::ArrayAttr condElts = condVec.getElts();
+
+SmallVector elements;
+elements.reserve(condElts.size());
+
+for (const auto &[idx, condAttr] :
+ llvm::enumerate(condElts.getAsRange())) {
+  if (condAttr.getSInt()) {
+elements.push_back(lhsVec.getElts()[idx]);
+continue;
+  }
+
+  elements.push_back(rhsVec.getElts()[idx]);
+}
+
+cir::VectorType vecTy = getLhs().getType();
+return cir::ConstVectorAttr::get(
+vecTy, mlir::ArrayAttr::get(getContext(), elements));
+  }
+
+  return {};
+}
+
 
//===--===//
 // TableGen'd op method definitions
 
//===--===//
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp 
b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index 7d03e374c27e8..aa3e97033cdda 100644
--- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
@@ -138,10 +138,10 @@ void CIRCanonicalizePass::runOnOperation() {
 assert(!cir::MissingFeatures::complexRealOp());
 assert(!cir::MissingFeatures::complexImagOp());
 assert(!cir::MissingFeatures::callOp());
-// CastOp, UnaryOp, VecExtractOp and VecShuffleDynamicOp are here to 
perform
-// a manual `fold` in applyOpPatternsGreedily.
+// CastOp, UnaryOp, VecExtractOp, VecShuffleDynamicOp and VecTernaryOp are
+// here to perform a manual `fold` in applyOpPatternsGreedily.
 if (isa(op))
+VecExtractOp, VecShuffleDynamicOp, VecTernaryOp>(op))
   ops.push_back(op);
   });
 
diff --git a/clang/test/CIR/Transforms/vector-ternary-fold.cir 
b/clang/test/CIR/Transforms/vector-ternary-fold.cir
new file mode 100644
index 0..f2e18576da74b
--- /dev/null
+++ b/clang/test/CIR/Transforms/vector-ternary-fold.cir
@@ -0,0 +1,20 @@
+// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
+
+!s32i = !cir.int
+
+module {
+  cir.func @vector_ternary_fold_test() -> !cir.vector<4 x !s32i> {
+%cond = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<0> : 
!s32i, #cir.int<1> : !s32i, #cir.int<0> : !s32i]> : !cir.vector<4 x !s32i>
+%lhs = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : 
!s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<4 x !s32i>
+%rhs = cir.const #cir.const_vector<[#cir.int<5> : !s32i, #cir.int<6> : 
!s32i, #cir.int<7> : !s32i, #cir.int<8> : !s32i]> : !cir.vector<4 x !s32i>
+%res = cir.vec.ternary(%cond, %lhs, %rhs) : !cir.vector<4 x !s32i>, 
!cir.vector<4 x !s32i>
+cir.return %res : !cir.vector<4 x !s32i>
+  }
+
+  // [1, 0, 1, 0] ? [1, 2, 3, 4] : [5, 6, 7, 8] Will be fold to [1, 6, 3, 8]
+  // CHECK: cir.func @vector_ternary_fold_test() -> !cir.vector<4 x !s32i> {
+  // CHECK-NEXT: %[[RES:.*]] = cir.const #cir.const_vector<[#cir.int<1> : 
!s32i, #cir.int<6> : !s32i, #cir.int<3> : !s32i, #ci

[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-05 Thread via cfe-commits


@@ -3348,6 +3348,9 @@ defm pch_codegen: OptInCC1FFlag<"pch-codegen", "Generate 
", "Do not generate ",
   "code for uses of this PCH that assumes an explicit object file will be 
built for the PCH">;
 defm pch_debuginfo: OptInCC1FFlag<"pch-debuginfo", "Generate ", "Do not 
generate ",
   "debug info for types in an object file built from this PCH and do not 
generate them elsewhere">;
+def ignore_pch : Flag<["-"], "ignore-pch">, Group,
+  Visibility<[ClangOption, CC1Option]>,

MaggieYingYi wrote:

Thanks, fixed in the commit 
https://github.com/MaggieYingYi/llvm-project/commit/8dff812d140fefcda2ff9eb0cbd4aa5b323d7643.

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


[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-05 Thread via cfe-commits


@@ -2982,6 +2982,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
 #undef FRONTEND_OPTION_WITH_MARSHALLING
 
   Opts.ProgramAction = frontend::ParseSyntaxOnly;
+

MaggieYingYi wrote:

https://github.com/MaggieYingYi/llvm-project/commit/8dff812d140fefcda2ff9eb0cbd4aa5b323d7643

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


[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-05 Thread via cfe-commits

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


[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-05 Thread via cfe-commits


@@ -4286,6 +4286,16 @@ void Driver::handleArguments(Compilation &C, 
DerivedArgList &Args,
 YcArg = YuArg = nullptr;
   }
 
+  Arg *IncludePCHArg = Args.getLastArg(options::OPT_include_pch);
+  if (IncludePCHArg && (FinalPhase == phases::Preprocess ||
+Args.hasArg(options::OPT_ignore_pch))) {
+// If only preprocessing or -ignore-pch is used, -include-pch is disabled.
+// Since -emit-pch is CC1option, it will not be added to command argments 
if
+// -ignore-pch is used.
+Args.eraseArg(options::OPT_include_pch);
+IncludePCHArg = nullptr;
+  }

MaggieYingYi wrote:

> Though can you explain why you want to include phases::Preprocess here? 

I borrowed the idea from `clang-cl /Y-`. The code is shown 
[Driver.cpp#L4279](https://github.com/MaggieYingYi/llvm-project/blob/yingyi/main/PCH/clang/lib/Driver/Driver.cpp#L4279).

[Driver/Phases.h#L19](https://github.com/MaggieYingYi/llvm-project/blob/yingyi/main/PCH/clang/include/clang/Driver/Phases.h#L19)
 shows ordered values for successive stages in the compilation process. Since 
preprocess is the stage before precompile, we don't need to include precompiled 
header if the final stage is preprocess. There, phases::Preprocess is added 
here.


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


[libclc] [NFC][libclc] Simplify clc_dot and dot implementation (PR #142922)

2025-06-05 Thread Fraser Cormack via cfe-commits

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

LGTM

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


[clang] [Clang] Set the FTM for trivial relocation (PR #142936)

2025-06-05 Thread Corentin Jabot via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/142936

The language of side seems fairly stable.
Setting the feature test macro will ease implementation in standard libraries.

>From d035db665337550d41cee85bb962943fa6b6c097 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 5 Jun 2025 11:54:32 +0200
Subject: [PATCH] [Clang] Set the FTM for trivial relocation

The language of side seems fairly stable.
Setting the feature test macro will ease implementation in
standard libraries.
---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 +-
 clang/test/Lexer/cxx-features.cpp   | 4 
 clang/www/cxx_status.html   | 7 +--
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 69a91eef6aedb..ef1a508a96c35 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -773,7 +773,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
   Builder.defineMacro("__cpp_pack_indexing", "202311L");
   Builder.defineMacro("__cpp_deleted_function", "202403L");
   Builder.defineMacro("__cpp_variadic_friend", "202403L");
-  // Builder.defineMacro("__cpp_trivial_relocatability", "202502L");
+  Builder.defineMacro("__cpp_trivial_relocatability", "202502L");
 
   if (LangOpts.Char8)
 Builder.defineMacro("__cpp_char8_t", "202207L");
diff --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index 8c1867d5c7365..ced5bcaf0db16 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -49,6 +49,10 @@
 #error "wrong value for __cpp_placeholder_variables"
 #endif
 
+#if check(trivial_relocatability, 202502, 202502, 202502, 202502, 202502, 
202502, 202502)
+#error "wrong value for __cpp_trivial_relocatability"
+#endif
+
 // --- C++23 features ---
 
 #if check(auto_cast, 0, 0, 0, 0, 0, 202110, 202110)
diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index dff57689e84b9..cbcf462970b7f 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -280,12 +280,7 @@ C++2c implementation status
  
   Trivial Relocatability
   https://wg21.link/P2786";>P2786R13
-  
-
-  Clang 21 (Partial)
-  The feature test macro (__cpp_trivial_relocatability) has 
not yet been set.
-
-  
+  Clang 21
  
  
   #embed

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


[clang-tools-extra] Refactor clang doc comment structure (PR #142273)

2025-06-05 Thread Samarth Narang via cfe-commits

https://github.com/snarang181 updated 
https://github.com/llvm/llvm-project/pull/142273

>From 51adbab1511e92c44925d20661ed86d2ab28dca0 Mon Sep 17 00:00:00 2001
From: Samarth Narang 
Date: Sat, 31 May 2025 10:05:52 -0400
Subject: [PATCH 1/9] [clang-doc] Refactor CommentInfo.Kind to use CommentKind
 enum

This patch replaces the raw SmallString<16> `Kind` field in `CommentInfo`
with a strongly typed enum `CommentKind`. This improves type safety,
allows compiler-checked switch handling, and removes the reliance on
string comparisons across the clang-doc codebase.
---
 clang-tools-extra/clang-doc/BitcodeReader.cpp |  9 ++-
 clang-tools-extra/clang-doc/BitcodeWriter.cpp |  3 +-
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 74 ++-
 .../clang-doc/HTMLMustacheGenerator.cpp   | 12 +--
 clang-tools-extra/clang-doc/MDGenerator.cpp   | 59 ++-
 .../clang-doc/Representation.cpp  | 60 +++
 clang-tools-extra/clang-doc/Representation.h  | 33 +++--
 clang-tools-extra/clang-doc/Serialize.cpp |  2 +-
 clang-tools-extra/clang-doc/YAMLGenerator.cpp | 20 -
 9 files changed, 201 insertions(+), 71 deletions(-)

diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 546dd0254ec01..d15ca02c864f6 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -316,8 +316,13 @@ static llvm::Error parseRecord(const Record &R, unsigned 
ID,
 static llvm::Error parseRecord(const Record &R, unsigned ID,
llvm::StringRef Blob, CommentInfo *I) {
   switch (ID) {
-  case COMMENT_KIND:
-return decodeRecord(R, I->Kind, Blob);
+  case COMMENT_KIND: {
+llvm::SmallString<16> KindStr;
+if (llvm::Error Err = decodeRecord(R, KindStr, Blob))
+  return Err;
+I->Kind = stringToCommentKind(KindStr);
+return llvm::Error::success();
+  }
   case COMMENT_TEXT:
 return decodeRecord(R, I->Text, Blob);
   case COMMENT_NAME:
diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp 
b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index f0a445e606bff..efd60fdc2ec76 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -484,8 +484,9 @@ void ClangDocBitcodeWriter::emitBlock(const MemberTypeInfo 
&T) {
 
 void ClangDocBitcodeWriter::emitBlock(const CommentInfo &I) {
   StreamSubBlockGuard Block(Stream, BI_COMMENT_BLOCK_ID);
+  // Handle Kind (enum) separately, since it is not a string. 
+  emitRecord(commentKindToString(I.Kind), COMMENT_KIND);
   for (const auto &L : std::vector>{
-   {I.Kind, COMMENT_KIND},
{I.Text, COMMENT_TEXT},
{I.Name, COMMENT_NAME},
{I.Direction, COMMENT_DIRECTION},
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 93b9279462a89..eb7bfb842589b 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -635,47 +635,53 @@ genHTML(const Index &Index, StringRef InfoPath, bool 
IsOutermostList) {
 }
 
 static std::unique_ptr genHTML(const CommentInfo &I) {
-  if (I.Kind == "FullComment") {
-auto FullComment = std::make_unique(HTMLTag::TAG_DIV);
-for (const auto &Child : I.Children) {
-  std::unique_ptr Node = genHTML(*Child);
-  if (Node)
-FullComment->Children.emplace_back(std::move(Node));
+  switch (I.Kind) {
+case CommentKind::CK_FullComment: {
+  auto FullComment = std::make_unique(HTMLTag::TAG_DIV);
+  for (const auto &Child : I.Children) {
+std::unique_ptr Node = genHTML(*Child);
+if (Node)
+  FullComment->Children.emplace_back(std::move(Node));
+  }
+  return std::move(FullComment);
 }
-return std::move(FullComment);
-  }
 
-  if (I.Kind == "ParagraphComment") {
-auto ParagraphComment = std::make_unique(HTMLTag::TAG_P);
-for (const auto &Child : I.Children) {
-  std::unique_ptr Node = genHTML(*Child);
-  if (Node)
-ParagraphComment->Children.emplace_back(std::move(Node));
+case CommentKind::CK_ParagraphComment: {
+  auto ParagraphComment = std::make_unique(HTMLTag::TAG_P);
+  for (const auto &Child : I.Children) {
+std::unique_ptr Node = genHTML(*Child);
+if (Node)
+  ParagraphComment->Children.emplace_back(std::move(Node));
+  }
+  if (ParagraphComment->Children.empty())
+return nullptr;
+  return std::move(ParagraphComment);
 }
-if (ParagraphComment->Children.empty())
-  return nullptr;
-return std::move(ParagraphComment);
-  }
 
-  if (I.Kind == "BlockCommandComment") {
-auto BlockComment = std::make_unique(HTMLTag::TAG_DIV);
-BlockComment->Children.emplace_back(
-std::make_unique(HTMLTag::TAG_DIV, I.Name));
-for (const auto &Child : I.Children) {
-  std::unique_ptr Node = genHTML(*Child

[clang] [CIR] Upstream global initialization for ComplexType (PR #141369)

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

https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/141369

>From cd8321c18eecd841907969753653548fbe23d76a Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 24 May 2025 14:18:06 +0200
Subject: [PATCH 01/10] [CIR] Upstream global initialization for ComplexType

---
 .../CIR/Dialect/Builder/CIRBaseBuilder.h  |  2 +
 .../include/clang/CIR/Dialect/IR/CIRAttrs.td  | 34 ++
 .../include/clang/CIR/Dialect/IR/CIRTypes.td  | 43 
 clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp  | 27 ++--
 clang/lib/CIR/CodeGen/CIRGenTypes.cpp |  7 ++
 clang/lib/CIR/Dialect/IR/CIRAttrs.cpp | 20 ++
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   |  6 +-
 clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 24 ++-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 65 +++
 clang/test/CIR/CodeGen/complex.cpp| 29 +
 clang/test/CIR/IR/complex.cir | 16 +
 11 files changed, 254 insertions(+), 19 deletions(-)
 create mode 100644 clang/test/CIR/CodeGen/complex.cpp
 create mode 100644 clang/test/CIR/IR/complex.cir

diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index 5cd0caa823ca1..7a5f192618a5d 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -90,6 +90,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
   return cir::IntAttr::get(ty, 0);
 if (cir::isAnyFloatingPointType(ty))
   return cir::FPAttr::getZero(ty);
+if (auto complexType = mlir::dyn_cast(ty))
+  return cir::ZeroAttr::get(complexType);
 if (auto arrTy = mlir::dyn_cast(ty))
   return cir::ZeroAttr::get(arrTy);
 if (auto vecTy = mlir::dyn_cast(ty))
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index ecbced05a5fdd..27a0b4c57ebe4 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -276,6 +276,40 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", 
[TypedAttrInterface]> {
   }];
 }
 
+//===--===//
+// ConstComplexAttr
+//===--===//
+
+def ConstComplexAttr : CIR_Attr<"ConstComplex", "const_complex", 
[TypedAttrInterface]> {
+  let summary = "An attribute that contains a constant complex value";
+  let description = [{
+The `#cir.const_complex` attribute contains a constant value of complex 
number
+type. The `real` parameter gives the real part of the complex number and 
the
+`imag` parameter gives the imaginary part of the complex number.
+
+The `real` and `imag` parameter must be either an IntAttr or an FPAttr that
+contains values of the same CIR type.
+  }];
+
+  let parameters = (ins
+AttributeSelfTypeParameter<"", "cir::ComplexType">:$type,
+"mlir::TypedAttr":$real, "mlir::TypedAttr":$imag);
+
+  let builders = [
+AttrBuilderWithInferredContext<(ins "cir::ComplexType":$type,
+"mlir::TypedAttr":$real,
+"mlir::TypedAttr":$imag), [{
+  return $_get(type.getContext(), type, real, imag);
+}]>,
+  ];
+
+  let genVerifyDecl = 1;
+
+  let assemblyFormat = [{
+`<` qualified($real) `,` qualified($imag) `>`
+  }];
+}
+
 
//===--===//
 // VisibilityAttr
 
//===--===//
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td 
b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index 9c0af8d3eaa5f..e7954bee74e5d 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -161,6 +161,49 @@ def CIR_LongDouble : CIR_FloatType<"LongDouble", 
"long_double"> {
   }];
 }
 
+//===--===//
+// ComplexType
+//===--===//
+
+def CIR_ComplexType : CIR_Type<"Complex", "complex",
+[DeclareTypeInterfaceMethods]> {
+
+  let summary = "CIR complex type";
+  let description = [{
+CIR type that represents a C complex number. `cir.complex` models the C 
type
+`T _Complex`.
+
+The type models complex values, per C99 6.2.5p11. It supports the C99
+complex float types as well as the GCC integer complex extensions.
+
+The parameter `elementType` gives the type of the real and imaginary part 
of
+the complex number. `elementType` must be either a CIR integer type or a 
CIR
+floating-point type.
+  }];
+
+  let parameters = (ins CIR_AnyIntOrFloatType:$elementType);
+
+  let builders = [
+TypeBuilderWithInferredContext<(ins "mlir::Type":$elementType), [{
+

[clang-tools-extra] Refactor clang doc comment structure (PR #142273)

2025-06-05 Thread Samarth Narang via cfe-commits

snarang181 wrote:

Left a reply to this 
[comment](https://github.com/llvm/llvm-project/pull/142273/files#r2125020120) 
@ilovepi. Addressed some other comments. 

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


[clang-tools-extra] Refactor clang doc comment structure (PR #142273)

2025-06-05 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 cpp,h -- 
clang-tools-extra/clang-doc/BitcodeReader.cpp 
clang-tools-extra/clang-doc/BitcodeWriter.cpp 
clang-tools-extra/clang-doc/HTMLGenerator.cpp 
clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp 
clang-tools-extra/clang-doc/MDGenerator.cpp 
clang-tools-extra/clang-doc/Representation.cpp 
clang-tools-extra/clang-doc/Representation.h 
clang-tools-extra/clang-doc/Serialize.cpp 
clang-tools-extra/clang-doc/YAMLGenerator.cpp 
clang-tools-extra/test/clang-doc/templates.cpp 
clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp 
clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp 
clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp 
clang-tools-extra/unittests/clang-doc/MergeTest.cpp 
clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-doc/YAMLGenerator.cpp 
b/clang-tools-extra/clang-doc/YAMLGenerator.cpp
index a9ede885e..897b5d5ae 100644
--- a/clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -65,8 +65,7 @@ template <> struct ScalarEnumerationTraits {
   }
 };
 
-template <>
-struct ScalarEnumerationTraits {
+template <> struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, clang::doc::CommentKind &Value) {
 IO.enumCase(Value, "FullComment", clang::doc::CommentKind::CK_FullComment);
 IO.enumCase(Value, "ParagraphComment",

``




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


[clang-tools-extra] Refactor clang doc comment structure (PR #142273)

2025-06-05 Thread Samarth Narang via cfe-commits

https://github.com/snarang181 updated 
https://github.com/llvm/llvm-project/pull/142273

>From 51adbab1511e92c44925d20661ed86d2ab28dca0 Mon Sep 17 00:00:00 2001
From: Samarth Narang 
Date: Sat, 31 May 2025 10:05:52 -0400
Subject: [PATCH 01/10] [clang-doc] Refactor CommentInfo.Kind to use
 CommentKind enum

This patch replaces the raw SmallString<16> `Kind` field in `CommentInfo`
with a strongly typed enum `CommentKind`. This improves type safety,
allows compiler-checked switch handling, and removes the reliance on
string comparisons across the clang-doc codebase.
---
 clang-tools-extra/clang-doc/BitcodeReader.cpp |  9 ++-
 clang-tools-extra/clang-doc/BitcodeWriter.cpp |  3 +-
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 74 ++-
 .../clang-doc/HTMLMustacheGenerator.cpp   | 12 +--
 clang-tools-extra/clang-doc/MDGenerator.cpp   | 59 ++-
 .../clang-doc/Representation.cpp  | 60 +++
 clang-tools-extra/clang-doc/Representation.h  | 33 +++--
 clang-tools-extra/clang-doc/Serialize.cpp |  2 +-
 clang-tools-extra/clang-doc/YAMLGenerator.cpp | 20 -
 9 files changed, 201 insertions(+), 71 deletions(-)

diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 546dd0254ec01..d15ca02c864f6 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -316,8 +316,13 @@ static llvm::Error parseRecord(const Record &R, unsigned 
ID,
 static llvm::Error parseRecord(const Record &R, unsigned ID,
llvm::StringRef Blob, CommentInfo *I) {
   switch (ID) {
-  case COMMENT_KIND:
-return decodeRecord(R, I->Kind, Blob);
+  case COMMENT_KIND: {
+llvm::SmallString<16> KindStr;
+if (llvm::Error Err = decodeRecord(R, KindStr, Blob))
+  return Err;
+I->Kind = stringToCommentKind(KindStr);
+return llvm::Error::success();
+  }
   case COMMENT_TEXT:
 return decodeRecord(R, I->Text, Blob);
   case COMMENT_NAME:
diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp 
b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index f0a445e606bff..efd60fdc2ec76 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -484,8 +484,9 @@ void ClangDocBitcodeWriter::emitBlock(const MemberTypeInfo 
&T) {
 
 void ClangDocBitcodeWriter::emitBlock(const CommentInfo &I) {
   StreamSubBlockGuard Block(Stream, BI_COMMENT_BLOCK_ID);
+  // Handle Kind (enum) separately, since it is not a string. 
+  emitRecord(commentKindToString(I.Kind), COMMENT_KIND);
   for (const auto &L : std::vector>{
-   {I.Kind, COMMENT_KIND},
{I.Text, COMMENT_TEXT},
{I.Name, COMMENT_NAME},
{I.Direction, COMMENT_DIRECTION},
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 93b9279462a89..eb7bfb842589b 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -635,47 +635,53 @@ genHTML(const Index &Index, StringRef InfoPath, bool 
IsOutermostList) {
 }
 
 static std::unique_ptr genHTML(const CommentInfo &I) {
-  if (I.Kind == "FullComment") {
-auto FullComment = std::make_unique(HTMLTag::TAG_DIV);
-for (const auto &Child : I.Children) {
-  std::unique_ptr Node = genHTML(*Child);
-  if (Node)
-FullComment->Children.emplace_back(std::move(Node));
+  switch (I.Kind) {
+case CommentKind::CK_FullComment: {
+  auto FullComment = std::make_unique(HTMLTag::TAG_DIV);
+  for (const auto &Child : I.Children) {
+std::unique_ptr Node = genHTML(*Child);
+if (Node)
+  FullComment->Children.emplace_back(std::move(Node));
+  }
+  return std::move(FullComment);
 }
-return std::move(FullComment);
-  }
 
-  if (I.Kind == "ParagraphComment") {
-auto ParagraphComment = std::make_unique(HTMLTag::TAG_P);
-for (const auto &Child : I.Children) {
-  std::unique_ptr Node = genHTML(*Child);
-  if (Node)
-ParagraphComment->Children.emplace_back(std::move(Node));
+case CommentKind::CK_ParagraphComment: {
+  auto ParagraphComment = std::make_unique(HTMLTag::TAG_P);
+  for (const auto &Child : I.Children) {
+std::unique_ptr Node = genHTML(*Child);
+if (Node)
+  ParagraphComment->Children.emplace_back(std::move(Node));
+  }
+  if (ParagraphComment->Children.empty())
+return nullptr;
+  return std::move(ParagraphComment);
 }
-if (ParagraphComment->Children.empty())
-  return nullptr;
-return std::move(ParagraphComment);
-  }
 
-  if (I.Kind == "BlockCommandComment") {
-auto BlockComment = std::make_unique(HTMLTag::TAG_DIV);
-BlockComment->Children.emplace_back(
-std::make_unique(HTMLTag::TAG_DIV, I.Name));
-for (const auto &Child : I.Children) {
-  std::unique_ptr Node = genHTML(*Chi

[clang] [llvm] [NFC][LLVM] Refactor IRBuilder::Create{VScale,ElementCount,TypeSize}. (PR #142803)

2025-06-05 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm updated 
https://github.com/llvm/llvm-project/pull/142803

>From 0819cda292ccc0fa7376bb4c78d4884cf5845410 Mon Sep 17 00:00:00 2001
From: Paul Walker 
Date: Wed, 4 Jun 2025 13:06:31 +0100
Subject: [PATCH 1/2] [NFC][LLVM] Refactor
 IRBuilder::Create{VScale,ElementCount,TypeSize}.

CreateVScale took a scaling parameter that had a single use
outside of IRBuilder with all other callers having to create a
redundant ConstantInt. To work round this some code perferred to use
CreateIntrinsic directly.

This patch simplifies CreateVScale to only return a call to the
llvm.vscale() intrinsic and nothing more. As well as simplifying the
existing call sites I've also ported the uses of CreateIntrinsic.

Whilst IRBuilder used CreateVScale's scaling parameter as part of
the implementations of CreateElementCount and CreateTypeSize, I have
follow-on work to switch them to the NUW varaiety and thus they would
stop using CreateVScale's scaling as well. To prepare for this I have
moved the multiplication and constant folding into the implementations
of CreateElementCount and CreateTypeSize.

As a final step I have replaced some callers of CreateVScale with
CreateElementCount where it's clear from the code they wanted the
latter.
---
 clang/lib/CodeGen/TargetBuiltins/ARM.cpp  |  6 +---
 llvm/include/llvm/IR/IRBuilder.h  |  9 +++--
 llvm/lib/CodeGen/ExpandVectorPredication.cpp  |  3 +-
 llvm/lib/IR/IRBuilder.cpp | 33 +++
 .../AArch64/AArch64TargetTransformInfo.cpp|  8 ++---
 .../InstCombine/InstCombineCasts.cpp  | 24 +-
 .../Utils/LowerVectorIntrinsics.cpp   | 16 ++---
 .../Utils/ScalarEvolutionExpander.cpp |  2 +-
 .../Vectorize/LoopIdiomVectorize.cpp  |  2 +-
 llvm/unittests/IR/IRBuilderTest.cpp   |  8 -
 10 files changed, 43 insertions(+), 68 deletions(-)

diff --git a/clang/lib/CodeGen/TargetBuiltins/ARM.cpp 
b/clang/lib/CodeGen/TargetBuiltins/ARM.cpp
index 1cf8f6819b75a..9c77346389e04 100644
--- a/clang/lib/CodeGen/TargetBuiltins/ARM.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/ARM.cpp
@@ -4793,11 +4793,7 @@ Value 
*CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
   case SVE::BI__builtin_sve_svlen_u64: {
 SVETypeFlags TF(Builtin->TypeModifier);
 auto VTy = cast(getSVEType(TF));
-auto *NumEls =
-llvm::ConstantInt::get(Ty, VTy->getElementCount().getKnownMinValue());
-
-Function *F = CGM.getIntrinsic(Intrinsic::vscale, Ty);
-return Builder.CreateMul(NumEls, Builder.CreateCall(F));
+return Builder.CreateElementCount(Ty, VTy->getElementCount());
   }
 
   case SVE::BI__builtin_sve_svtbl2_u8:
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 0db5179c7a3e4..8ed10cb803a9c 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -945,17 +945,16 @@ class IRBuilderBase {
   LLVM_ABI CallInst *CreateGCGetPointerOffset(Value *DerivedPtr,
   const Twine &Name = "");
 
-  /// Create a call to llvm.vscale, multiplied by \p Scaling. The type of 
VScale
-  /// will be the same type as that of \p Scaling.
-  LLVM_ABI Value *CreateVScale(Constant *Scaling, const Twine &Name = "");
+  /// Create a call to llvm.vscale.().
+  LLVM_ABI Value *CreateVScale(Type *Ty, const Twine &Name = "");
 
   /// Create an expression which evaluates to the number of elements in \p EC
   /// at runtime.
-  LLVM_ABI Value *CreateElementCount(Type *DstType, ElementCount EC);
+  LLVM_ABI Value *CreateElementCount(Type *Ty, ElementCount EC);
 
   /// Create an expression which evaluates to the number of units in \p Size
   /// at runtime.  This works for both units of bits and bytes.
-  LLVM_ABI Value *CreateTypeSize(Type *DstType, TypeSize Size);
+  LLVM_ABI Value *CreateTypeSize(Type *Ty, TypeSize Size);
 
   /// Creates a vector of type \p DstType with the linear sequence <0, 1, ...>
   LLVM_ABI Value *CreateStepVector(Type *DstType, const Twine &Name = "");
diff --git a/llvm/lib/CodeGen/ExpandVectorPredication.cpp 
b/llvm/lib/CodeGen/ExpandVectorPredication.cpp
index 1bb0763fcf57b..d8e3f5fbb31de 100644
--- a/llvm/lib/CodeGen/ExpandVectorPredication.cpp
+++ b/llvm/lib/CodeGen/ExpandVectorPredication.cpp
@@ -507,8 +507,7 @@ bool CachingVPExpander::discardEVLParameter(VPIntrinsic 
&VPI) {
 // TODO add caching
 IRBuilder<> Builder(VPI.getParent(), VPI.getIterator());
 Value *FactorConst = Builder.getInt32(StaticElemCount.getKnownMinValue());
-Value *VScale = Builder.CreateIntrinsic(Intrinsic::vscale, Int32Ty, {},
-/*FMFSource=*/nullptr, "vscale");
+Value *VScale = Builder.CreateVScale(Int32Ty, "vscale");
 MaxEVL = Builder.CreateMul(VScale, FactorConst, "scalable_size",
/*NUW*/ true, /*NSW*/ false);
   } else {
diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBu

[clang] Revert "[clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (#142749) (PR #142933)

2025-06-05 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 updated 
https://github.com/llvm/llvm-project/pull/142933

>From ff70ffb72ad5c424b49f41b189699a2dcd69d00c Mon Sep 17 00:00:00 2001
From: anutosh491 
Date: Thu, 5 Jun 2025 14:31:53 +0530
Subject: [PATCH] Revert "[clang-repl] Ensure clang-repl accepts all C keywords
 supported in all language models (#142749)"

This broke CI on platforms such as PPC64LE and AIX due to _Float16 not being 
supported.
We will reintroduce the changes later with proper platform guards and tests.

This reverts commit 7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0.
---
 clang/lib/Parse/ParseTentative.cpp|  2 --
 clang/test/Interpreter/disambiguate-decl-stmt.cpp | 13 -
 2 files changed, 15 deletions(-)

diff --git a/clang/lib/Parse/ParseTentative.cpp 
b/clang/lib/Parse/ParseTentative.cpp
index f50bcd8ea90bb..95cee824c40b7 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1171,7 +1171,6 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext 
AllowImplicitTypename,
   case tok::kw_inline:
   case tok::kw_virtual:
   case tok::kw_explicit:
-  case tok::kw__Noreturn:
 
 // Modules
   case tok::kw___module_private__:
@@ -1226,7 +1225,6 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext 
AllowImplicitTypename,
 // GNU
   case tok::kw_restrict:
   case tok::kw__Complex:
-  case tok::kw__Imaginary:
   case tok::kw___attribute:
   case tok::kw___auto_type:
 return TPResult::True;
diff --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp 
b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
index f2a59c510f9a2..1f4d5e267288b 100644
--- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -102,16 +102,3 @@ __attribute((noreturn)) Attrs2::Attrs2() = default;
 
 // Extra semicolon
 namespace N {};
-
-// Test C keywords supported in all language modes.
-// 
https://clang.llvm.org/docs/LanguageExtensions.html#c-keywords-supported-in-all-language-modes
-
-_Alignas(16) int aligned_var;
-int align = _Alignof(double);
-_Atomic int atomic_var = 0;
-_Complex double complex_val = 1.0 + 2.0i;
-_Float16 f = 1.5;
-_Thread_local int counter = 0;
-_Static_assert(sizeof(int) == 4, "int must be 4 bytes");
-_Imaginary float i = 2.0f; // expected-error {{imaginary types are not 
supported}}
-_Noreturn void noreturn_func() { while (true) {} }
\ No newline at end of file

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


[clang] [llvm] [NFC][LLVM] Refactor IRBuilder::Create{VScale,ElementCount,TypeSize}. (PR #142803)

2025-06-05 Thread Paul Walker via cfe-commits


@@ -4793,11 +4793,7 @@ Value 
*CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID,
   case SVE::BI__builtin_sve_svlen_u64: {
 SVETypeFlags TF(Builtin->TypeModifier);
 auto VTy = cast(getSVEType(TF));

paulwalker-arm wrote:

It turns out `getSVEType()` already returns the correct type to I've remove the 
redundant cast here, plus the one a few lines lower.

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


[clang] [Clang] Fix name lookup of conversion operators (PR #142945)

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

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/142945

(TODO: Add explanation)

Fixes https://github.com/llvm/llvm-project/issues/28181
Fixes https://github.com/llvm/llvm-project/issues/94052

>From cdd6868879abf4b6c991c7f2b3e9cf9673b0570a Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Thu, 5 Jun 2025 18:52:01 +0800
Subject: [PATCH] [Clang] Fix name lookup of conversion operators

(TODO: Add explanation)
---
 clang/include/clang/Parse/Parser.h| 57 ---
 clang/include/clang/Sema/DeclSpec.h   | 23 +---
 clang/include/clang/Sema/Sema.h   |  1 +
 clang/lib/Parse/ParseDecl.cpp | 32 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 10 +++-
 clang/lib/Parse/ParseExpr.cpp |  3 +-
 clang/lib/Parse/ParseExprCXX.cpp  | 42 +-
 clang/lib/Parse/ParseOpenMP.cpp   | 16 +++---
 clang/lib/Parse/ParseStmtAsm.cpp  |  3 +-
 clang/lib/Parse/ParseTemplate.cpp |  1 +
 clang/lib/Parse/Parser.cpp|  9 ++-
 clang/lib/Sema/SemaDecl.cpp   | 20 ---
 clang/lib/Sema/SemaType.cpp   |  4 ++
 .../basic.lookup/basic.lookup.unqual/p5.cpp   | 52 +
 clang/test/CXX/drs/cwg11xx.cpp|  4 +-
 clang/test/CXX/temp/temp.res/p4.cpp   |  2 +-
 clang/unittests/Tooling/TestVisitor.h |  8 +--
 17 files changed, 204 insertions(+), 83 deletions(-)
 create mode 100644 clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p5.cpp

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 98db8201390be..16764b5ba1ad6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -359,7 +359,8 @@ class Parser : public CodeCompletionHandler {
   /// Note that this routine emits an error if you call it with ::new or
   /// ::delete as the current tokens, so only call it in contexts where these
   /// are invalid.
-  bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
+  bool TryAnnotateCXXScopeToken(bool EnteringContext = false,
+ParsedType ObjectType = nullptr);
 
   bool MightBeCXXScopeToken() {
 return getLangOpts().CPlusPlus &&
@@ -1525,8 +1526,10 @@ class Parser : public CodeCompletionHandler {
 DSC_class,  // class context, enables 'friend'
 DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list
 DSC_trailing, // C++11 trailing-type-specifier in a trailing return type
-DSC_alias_declaration,  // C++11 type-specifier-seq in an alias-declaration
-DSC_conv_operator,  // C++ type-specifier-seq in an conversion operator
+DSC_alias_declaration, // C++11 type-specifier-seq in an alias-declaration
+DSC_conv_operator, // C++ type-specifier-seq in an conversion operator
+DSC_conv_operator_in_postfix_expr, // C++ type-specifier-seq which is
+   // referenced in a postfix expression
 DSC_top_level,  // top-level/namespace declaration context
 DSC_template_param, // template parameter context
 DSC_template_arg,   // template argument context
@@ -1554,6 +1557,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_template_type_arg:
 case DeclSpecContext::DSC_type_specifier:
 case DeclSpecContext::DSC_conv_operator:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_trailing:
 case DeclSpecContext::DSC_alias_declaration:
 case DeclSpecContext::DSC_association:
@@ -1605,6 +1609,7 @@ class Parser : public CodeCompletionHandler {
 
 case DeclSpecContext::DSC_trailing:
 case DeclSpecContext::DSC_conv_operator:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_template_arg:
 case DeclSpecContext::DSC_new:
   return AllowDefiningTypeSpec::No;
@@ -1629,6 +1634,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_trailing:
 case DeclSpecContext::DSC_association:
 case DeclSpecContext::DSC_conv_operator:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_template_arg:
 case DeclSpecContext::DSC_new:
 
@@ -1650,6 +1656,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_type_specifier:
 case DeclSpecContext::DSC_association:
 case DeclSpecContext::DSC_conv_operator:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_new:
   return true;
 
@@ -1673,6 +1680,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_trailing:
 case DeclSpecContext::DSC_alias_declaration:
 case DeclSpecContext::DSC_template_param:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_new:
   return Impli

[clang] 419d1c2 - Revert "[clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (#142749) (#142933)

2025-06-05 Thread via cfe-commits

Author: Anutosh Bhat
Date: 2025-06-05T13:55:06+03:00
New Revision: 419d1c2adb93a52bdeba539c3ae763a12208577f

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

LOG: Revert "[clang-repl] Ensure clang-repl accepts all C keywords supported in 
all language models (#142749) (#142933)

This broke CI on platforms such as PPC64LE and AIX due to _Float16 not being 
supported.
We will reintroduce the changes later with proper platform guards and tests.

This reverts commit 7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0.

Added: 


Modified: 
clang/lib/Parse/ParseTentative.cpp
clang/test/Interpreter/disambiguate-decl-stmt.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseTentative.cpp 
b/clang/lib/Parse/ParseTentative.cpp
index f50bcd8ea90bb..95cee824c40b7 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1171,7 +1171,6 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext 
AllowImplicitTypename,
   case tok::kw_inline:
   case tok::kw_virtual:
   case tok::kw_explicit:
-  case tok::kw__Noreturn:
 
 // Modules
   case tok::kw___module_private__:
@@ -1226,7 +1225,6 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext 
AllowImplicitTypename,
 // GNU
   case tok::kw_restrict:
   case tok::kw__Complex:
-  case tok::kw__Imaginary:
   case tok::kw___attribute:
   case tok::kw___auto_type:
 return TPResult::True;

diff  --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp 
b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
index f2a59c510f9a2..1f4d5e267288b 100644
--- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -102,16 +102,3 @@ __attribute((noreturn)) Attrs2::Attrs2() = default;
 
 // Extra semicolon
 namespace N {};
-
-// Test C keywords supported in all language modes.
-// 
https://clang.llvm.org/docs/LanguageExtensions.html#c-keywords-supported-in-all-language-modes
-
-_Alignas(16) int aligned_var;
-int align = _Alignof(double);
-_Atomic int atomic_var = 0;
-_Complex double complex_val = 1.0 + 2.0i;
-_Float16 f = 1.5;
-_Thread_local int counter = 0;
-_Static_assert(sizeof(int) == 4, "int must be 4 bytes");
-_Imaginary float i = 2.0f; // expected-error {{imaginary types are not 
supported}}
-_Noreturn void noreturn_func() { while (true) {} }
\ No newline at end of file



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


[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)

2025-06-05 Thread Thorsten Klein via cfe-commits

https://github.com/thorsten-klein updated 
https://github.com/llvm/llvm-project/pull/124265

>From 9a2171658093b791e08f0f2b93e132be3a4419f5 Mon Sep 17 00:00:00 2001
From: "Klein, Thorsten (GDE-EDSI1)" 
Date: Fri, 24 Jan 2025 13:46:24 +0100
Subject: [PATCH] added option AllowNoNamespaceComments for
 google-readability-namespace-comments

new option AllowOmittingNamespaceComments for
google-readability-namespace-comments is added.

When `true`, the check will accept if no namespace comment is present.
The check will only fail if the specified namespace comment is different
than expected. Defaults to `false`.
---
 .../readability/NamespaceCommentCheck.cpp | 12 -
 .../readability/NamespaceCommentCheck.h   |  1 +
 .../checks/llvm/namespace-comment.rst |  7 +
 ...ace-comments-missing-nested-namespaces.cpp | 23 
 ...readability-namespace-comments-missing.cpp | 27 +++
 5 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-nested-namespaces.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
index 64dc941569a96..12e52d6afad56 100644
--- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name,
   "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$",
   llvm::Regex::IgnoreCase),
   ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)),
-  SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {}
+  SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)),
+  
AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", 
false)) {}
 
 void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines);
   Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments);
+  Options.store(Opts, "AllowOmittingNamespaceComments", 
AllowOmittingNamespaceComments);
 }
 
 void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) {
@@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   SourceRange OldCommentRange(AfterRBrace, AfterRBrace);
   std::string Message = "%0 not terminated with a closing comment";
+  bool hasComment = false;
 
   // Try to find existing namespace closing comment on the same line.
   if (Tok.is(tok::comment) && NextTokenIsOnSameLine) {
@@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
+  hasComment = true;
+
   // Otherwise we need to fix the comment.
   NeedLineBreak = Comment.starts_with("/*");
   OldCommentRange =
@@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const 
MatchFinder::MatchResult &Result) {
   ND->isAnonymousNamespace() ? "anonymous namespace"
  : ("namespace '" + *NamespaceNameAsWritten + 
"'");
 
+  // If no namespace comment is allowed
+  if(!hasComment && AllowOmittingNamespaceComments) {
+return;
+  }
+
   std::string Fix(SpacesBeforeComments, ' ');
   Fix.append("// namespace");
   if (!ND->isAnonymousNamespace())
diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h 
b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h
index 7607d37b1b2fd..8edd77213f779 100644
--- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h
@@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck {
   llvm::Regex NamespaceCommentPattern;
   const unsigned ShortNamespaceLines;
   const unsigned SpacesBeforeComments;
+  const bool AllowOmittingNamespaceComments;
   llvm::SmallVector Ends;
 };
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst 
b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst
index be90260be73af..6e17eac214463 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst
@@ -39,3 +39,10 @@ Options
 
An unsigned integer specifying the number of spaces before the comment
closing a namespace definition. Default is `1U`.
+
+.. option:: AllowOmittingNamespaceComments
+
+   When `true`, the check will accept if no namespace comment is present.
+   The check will only fail if the specified namespace comment is different
+   than expected. Defaults to `false`.
+
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/readabili

[clang] Revert "[clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (#142749) (PR #142933)

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

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


[clang] Revert "[clang-repl] Ensure clang-repl accepts all C keywords supported in all language models (#142749) (PR #142933)

2025-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Anutosh Bhat (anutosh491)


Changes

This reverts commit 7ca7bcb7d8dcf26fc0281697fe47aa6cdb3884c0.



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


2 Files Affected:

- (modified) clang/lib/Parse/ParseTentative.cpp (-2) 
- (modified) clang/test/Interpreter/disambiguate-decl-stmt.cpp (-13) 


``diff
diff --git a/clang/lib/Parse/ParseTentative.cpp 
b/clang/lib/Parse/ParseTentative.cpp
index f50bcd8ea90bb..95cee824c40b7 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1171,7 +1171,6 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext 
AllowImplicitTypename,
   case tok::kw_inline:
   case tok::kw_virtual:
   case tok::kw_explicit:
-  case tok::kw__Noreturn:
 
 // Modules
   case tok::kw___module_private__:
@@ -1226,7 +1225,6 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext 
AllowImplicitTypename,
 // GNU
   case tok::kw_restrict:
   case tok::kw__Complex:
-  case tok::kw__Imaginary:
   case tok::kw___attribute:
   case tok::kw___auto_type:
 return TPResult::True;
diff --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp 
b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
index f2a59c510f9a2..1f4d5e267288b 100644
--- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -102,16 +102,3 @@ __attribute((noreturn)) Attrs2::Attrs2() = default;
 
 // Extra semicolon
 namespace N {};
-
-// Test C keywords supported in all language modes.
-// 
https://clang.llvm.org/docs/LanguageExtensions.html#c-keywords-supported-in-all-language-modes
-
-_Alignas(16) int aligned_var;
-int align = _Alignof(double);
-_Atomic int atomic_var = 0;
-_Complex double complex_val = 1.0 + 2.0i;
-_Float16 f = 1.5;
-_Thread_local int counter = 0;
-_Static_assert(sizeof(int) == 4, "int must be 4 bytes");
-_Imaginary float i = 2.0f; // expected-error {{imaginary types are not 
supported}}
-_Noreturn void noreturn_func() { while (true) {} }
\ No newline at end of file

``




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


[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-05 Thread via cfe-commits


@@ -31,6 +31,16 @@ option:
 
   $ clang -cc1 -include-pch test.h.pch test.c -o test.s
 
+To ignore PCH options, use the option `-ignore-pch`:
+
+.. code-block:: bash
+
+  $ clang -cc1 test.h -emit-pch -ignore-pch -o test.h.pch
+  $ clang -cc1 -include-pch test.h.pch -ignore-pch test.c -o test.s
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+

MaggieYingYi wrote:

Thanks, fixed in the commit 
https://github.com/MaggieYingYi/llvm-project/commit/8dff812d140fefcda2ff9eb0cbd4aa5b323d7643


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


[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-05 Thread via cfe-commits

https://github.com/MaggieYingYi updated 
https://github.com/llvm/llvm-project/pull/142409

>From c0cc666ab8864b665539a857dbdae6c592266227 Mon Sep 17 00:00:00 2001
From: Ying Yi 
Date: Mon, 2 Jun 2025 10:21:22 +0100
Subject: [PATCH 1/6] [Frontend][PCH]-Add support for ignoring PCH options
 (-ignore-pch).

Visual Studio has an argument to ignore all PCH related switches. clang-cl has 
also support option /Y-. Having the same option in clang would be helpful. This 
commit is to add support for ignoring PCH options (-ignore-pch).
---
 clang/docs/PCHInternals.rst   |  10 ++
 clang/docs/UsersManual.rst|  14 +++
 clang/include/clang/Driver/Options.td |   2 +
 clang/lib/Frontend/CompilerInvocation.cpp |   9 ++
 clang/test/PCH/Inputs/ignored-pch.h   |   6 ++
 clang/test/PCH/ignored-pch.c  | 114 ++
 6 files changed, 155 insertions(+)
 create mode 100644 clang/test/PCH/Inputs/ignored-pch.h
 create mode 100644 clang/test/PCH/ignored-pch.c

diff --git a/clang/docs/PCHInternals.rst b/clang/docs/PCHInternals.rst
index 079fba16711dc..de0b341460cac 100644
--- a/clang/docs/PCHInternals.rst
+++ b/clang/docs/PCHInternals.rst
@@ -31,6 +31,16 @@ option:
 
   $ clang -cc1 -include-pch test.h.pch test.c -o test.s
 
+To ignore PCH options using ``clang -cc1``, use the option `-ignore-pch`:
+
+.. code-block:: bash
+
+  $ clang -cc1 test.h -emit-pch -ignore-pch -o test.h.pch
+  $ clang -cc1 -include-pch test.h.pch -ignore-pch test.c -o test.s
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+
 Design Philosophy
 -
 
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index eb9a812f0c1c9..f12b6b4c02193 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1458,6 +1458,20 @@ will be processed from the PCH file. Otherwise, Clang 
will report an error.
   ``test.h`` since ``test.h`` was included directly in the source file and not
   specified on the command line using ``-include-pch``.
 
+Ignoring a PCH File
+^^^
+
+To ignore a PCH file using Clang, the `-Xclang -ignore-pch` option is passed to
+``clang``:
+
+.. code-block:: console
+
+  $ clang -x c-header test.h -Xclang -ignore-pch -o test.h.pch
+  $ clang -include-pch test.h.pch -Xclang -ignore-pch test.c -o test
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+
 Relocatable PCH Files
 ^
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5ca31c253ed8f..3ed87608bf592 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8127,6 +8127,8 @@ def emit_header_unit : Flag<["-"], "emit-header-unit">,
   HelpText<"Generate C++20 header units from header files">;
 def emit_pch : Flag<["-"], "emit-pch">,
   HelpText<"Generate pre-compiled header file">;
+def ignore_pch : Flag<["-"], "ignore-pch">,
+  HelpText<"Ignore pre-compiled header options">;
 def emit_llvm_only : Flag<["-"], "emit-llvm-only">,
   HelpText<"Build ASTs and convert to LLVM, discarding output">;
 def emit_codegen_only : Flag<["-"], "emit-codegen-only">,
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2c02719121c73..19f81ff2fbe9d 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2982,6 +2982,15 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
 #undef FRONTEND_OPTION_WITH_MARSHALLING
 
   Opts.ProgramAction = frontend::ParseSyntaxOnly;
+
+  // If -ignore-pch is used, all pch handling is disabled. clang pch-related
+  // flags are removed.
+  if (Args.hasArg(options::OPT_ignore_pch)) {
+Args.eraseArg(options::OPT_emit_pch);
+Args.eraseArg(options::OPT_include_pch);
+Args.eraseArg(options::OPT_ignore_pch);
+  }
+
   if (const Arg *A = Args.getLastArg(OPT_Action_Group)) {
 OptSpecifier Opt = OptSpecifier(A->getOption().getID());
 std::optional ProgramAction = getFrontendAction(Opt);
diff --git a/clang/test/PCH/Inputs/ignored-pch.h 
b/clang/test/PCH/Inputs/ignored-pch.h
new file mode 100644
index 0..0956f9da1cb16
--- /dev/null
+++ b/clang/test/PCH/Inputs/ignored-pch.h
@@ -0,0 +1,6 @@
+#ifndef IGNORED_PCH_H
+#define IGNORED_PCH_H
+inline int f() {
+  return 42;
+}
+#endif // IGNORED_PCH_H
\ No newline at end of file
diff --git a/clang/test/PCH/ignored-pch.c b/clang/test/PCH/ignored-pch.c
new file mode 100644
index 0..198ad0fde7d05
--- /dev/null
+++ b/clang/test/PCH/ignored-pch.c
@@ -0,0 +1,114 @@
+// RUN: rm -rf %t.pch %t.ll
+// RUN: %clang_cc1 -x c-header %S/Inputs/ignored-pch.h -emit-pch -o %t.pch
+// RUN: %clang_cc1 %s -include-pch %t.pch -emit-llvm -o %t.ll
+// RUN: ls %t.pch | FileCheck --check-prefix=CHECK-PC

[clang] c3b8a15 - [CodeGen] Add TBAA struct path info for array members (#137719)

2025-06-05 Thread via cfe-commits

Author: Bruno De Fraine
Date: 2025-06-05T13:37:18+02:00
New Revision: c3b8a15eab06fceb6f4d0f2a0f505d5290ff208a

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

LOG: [CodeGen] Add TBAA struct path info for array members (#137719)

This enables the LLVM optimizer to view accesses to distinct struct
members as independent, also for array members. For example, the
following two stores no longer alias:

struct S { int a[10]; int b; };
void test(S *p, int i) {
  p->a[i] = ...;
  p->b = ...;
}

Array members were already added to TBAA struct type nodes in commit
57493e29. Here, we extend a path tag for an array subscript expression.

Added: 


Modified: 
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenTBAA.cpp
clang/test/CodeGen/tbaa-array.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index eb569c04b047c..5fc98b6a692cc 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4595,7 +4595,32 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const 
ArraySubscriptExpr *E,
 E->getType(), !getLangOpts().PointerOverflowDefined, SignedIndices,
 E->getExprLoc(), &arrayType, E->getBase());
 EltBaseInfo = ArrayLV.getBaseInfo();
-EltTBAAInfo = CGM.getTBAAInfoForSubobject(ArrayLV, E->getType());
+if (!CGM.getCodeGenOpts().NewStructPathTBAA) {
+  // Since CodeGenTBAA::getTypeInfoHelper only handles array types for
+  // new struct path TBAA, we must a use a plain access.
+  EltTBAAInfo = CGM.getTBAAInfoForSubobject(ArrayLV, E->getType());
+} else if (ArrayLV.getTBAAInfo().isMayAlias()) {
+  EltTBAAInfo = TBAAAccessInfo::getMayAliasInfo();
+} else if (ArrayLV.getTBAAInfo().isIncomplete()) {
+  // The array element is complete, even if the array is not.
+  EltTBAAInfo = CGM.getTBAAAccessInfo(E->getType());
+} else {
+  // The TBAA access info from the array (base) lvalue is ordinary. We will
+  // adapt it to create access info for the element.
+  EltTBAAInfo = ArrayLV.getTBAAInfo();
+
+  // We retain the TBAA struct path (BaseType and Offset members) from the
+  // array. In the TBAA representation, we map any array access to the
+  // element at index 0, as the index is generally a runtime value. This
+  // element has the same offset in the base type as the array itself.
+  // If the array lvalue had no base type, there is no point trying to
+  // generate one, since an array itself is not a valid base type.
+
+  // We also retain the access type from the base lvalue, but the access
+  // size must be updated to the size of an individual element.
+  EltTBAAInfo.Size =
+  getContext().getTypeSizeInChars(E->getType()).getQuantity();
+}
   } else {
 // The base must be a pointer; emit it with an estimate of its alignment.
 Address BaseAddr =

diff  --git a/clang/lib/CodeGen/CodeGenTBAA.cpp 
b/clang/lib/CodeGen/CodeGenTBAA.cpp
index 818b6dabaa144..a02a009158d12 100644
--- a/clang/lib/CodeGen/CodeGenTBAA.cpp
+++ b/clang/lib/CodeGen/CodeGenTBAA.cpp
@@ -130,6 +130,13 @@ static bool TypeHasMayAlias(QualType QTy) {
   return true;
 QTy = TT->desugar();
   }
+
+  // Also consider an array type as may_alias when its element type (at
+  // any level) is marked as such.
+  if (auto *ArrayTy = QTy->getAsArrayTypeUnsafe())
+if (TypeHasMayAlias(ArrayTy->getElementType()))
+  return true;
+
   return false;
 }
 

diff  --git a/clang/test/CodeGen/tbaa-array.cpp 
b/clang/test/CodeGen/tbaa-array.cpp
index 4a6576e2eeb7f..35e525cfa67ca 100644
--- a/clang/test/CodeGen/tbaa-array.cpp
+++ b/clang/test/CodeGen/tbaa-array.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
+// RUN: %clang_cc1 -triple x86_64-linux -O1 %s \
 // RUN: -emit-llvm -o - | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
+// RUN: %clang_cc1 -triple x86_64-linux -O1 %s \
 // RUN: -new-struct-path-tbaa -emit-llvm -o - | \
 // RUN: FileCheck -check-prefix=CHECK-NEW %s
 //
@@ -10,6 +10,12 @@
 struct A { int i; };
 struct B { A a[1]; };
 struct C { int i; int x[3]; };
+struct D { int n; int arr[]; }; // flexible array member
+extern int AA[];// incomplete array type
+
+typedef int __attribute__((may_alias)) aliasing_int;
+typedef int __attribute__((may_alias)) aliasing_array[10];
+struct E { aliasing_int x[4]; aliasing_array y; };
 
 int foo(B *b) {
 // CHECK-LABEL: _Z3fooP1B
@@ -28,16 +34,42 @@ int bar(C *c) {
 
 int bar2(C *c) {
 // CHECK-NEW-LABEL: _Z4bar2P1C
-// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_x:!.*]]
   return c->x[2];
 }
 
 int bar3

[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-05 Thread via cfe-commits


@@ -813,19 +813,19 @@ changes to one object won't affect the others, the 
object's initializer will run
 once per copy, etc.
 
 Specifically, this warning fires when it detects an object which:
-  1. Is defined as ``inline`` in a header file (so it might get compiled into 
multiple libaries), and
-  2. Has external linkage (otherwise it's supposed to be duplicated), and
-  3. Has hidden visibility.
+1. Is defined as ``inline`` in a header file (so it might get compiled into 
multiple libaries), and
+2. Has external linkage (otherwise it's supposed to be duplicated), and
+3. Has hidden visibility.
 
 As well as one of the following:
-  1. The object is mutable, or
-  2. The object's initializer definitely has side effects.
+1. The object is mutable, or
+2. The object's initializer definitely has side effects.
 
 The warning can be resolved by removing one of the conditions above. In rough
 order of preference, this may be done by:
-  1. Marking the object ``const`` (if possible)
-  2. Moving the object's definition to a source file
-  3. Giving the object non-hidden visibility, e.g. using 
``__attribute((visibility("default")))``.
+1. Marking the object ``const`` (if possible)
+2. Moving the object's definition to a source file
+3. Giving the object non-hidden visibility, e.g. using 
``__attribute((visibility("default")))``.

MaggieYingYi wrote:

Reverted in the commit 
https://github.com/MaggieYingYi/llvm-project/commit/5d520aa2157dcd013045c5017404db482f4de1d8.

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


[clang] [CodeGen] Add TBAA struct path info for array members (PR #137719)

2025-06-05 Thread via cfe-commits

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


[clang] [CodeGen] Add TBAA struct path info for array members (PR #137719)

2025-06-05 Thread via cfe-commits

dobbelaj-snps wrote:

> Could someone with commit access please merge this? Thanks!

Done

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


[clang] [clang][python][test] Move python binding tests to lit framework (PR #142948)

2025-06-05 Thread Rainer Orth via cfe-commits

https://github.com/rorth created 
https://github.com/llvm/llvm-project/pull/142948

As discussed in PR #142353, the current testsuite of the `clang` Python 
bindings has several issues:

- It `libclang.so` cannot be loaded into `python` to run the testsuite, the 
whole `ninja check-all` aborts.
- The result of running the testsuite isn't report like the `lit`-based tests, 
rendering them almost invisible.
- The testsuite is disabled in a non-obvious way (`RUN_PYTHON_TESTS`) in 
`tests/CMakeLists.txt`, which again doesn't show up in the test results.

All these issues can be avoided by integrating the Python bindings tests with 
`lit`, which is what this patch does:

- The actual test lives in `clang/test/bindings/python/bindings.sh` and is run 
by `lit`.
- The current `clang/bindings/python/tests` directory (minus the 
now-subperfluous `CMakeLists.txt`) is moved into the same directory.
- The check if `libclang` is loadable (originally from PR #142353) is now 
handled via a new `lit` feature, `libclang-loadable`.
- The various ways to disable the tests have been turned into `XFAIL`s as 
appropriate.  This isn't complete and not completely tested yet.

Tested on `sparc-sun-solaris2.11`, `sparcv9-sun-solaris2.11`, 
`i386-pc-solaris2.11`, `amd64-pc-solaris2.11`, `i686-pc-linux-gnu`, and 
`x86_64-pc-linux-gnu`.

>From e57e53c7e5abdb4c390a04b4ce9084dec9e71dd5 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Thu, 5 Jun 2025 13:40:26 +0200
Subject: [PATCH] [clang][python][test] Move python binding tests to lit
 framework

As discussed in PR #142353, the current testsuite of the `clang` Python
bindings has several issues:

- It `libclang.so` cannot be loaded into `python` to run the testsuite, the
  whole `ninja check-all` aborts.
- The result of running the testsuite isn't report like the `lit`-based
  tests, rendering them almost invisible.
- The testsuite is disabled in a non-obvious way (`RUN_PYTHON_TESTS`) in
  `tests/CMakeLists.txt`, which again doesn't show up in the test results.

All these issues can be avoided by integrating the Python bindings tests
with `lit`, which is what this patch does:

- The actual test lives in `clang/test/bindings/python/bindings.sh` and is
  run by `lit`.
- The current `clang/bindings/python/tests` directory (minus the
  now-subperfluous `CMakeLists.txt`) is moved into the same directory.
- The check if `libclang` is loadable (originally from PR #142353) is now
  handled via a new `lit` feature, `libclang-loadable`.
- The various ways to disable the tests have been turned into `XFAIL`s as
  appropriate.  This isn't complete and not completely tested yet.

Tested on `sparc-sun-solaris2.11`, `sparcv9-sun-solaris2.11`,
`i386-pc-solaris2.11`, `amd64-pc-solaris2.11`, `i686-pc-linux-gnu`, and
`x86_64-pc-linux-gnu`.
---
 clang/CMakeLists.txt  |  1 -
 clang/bindings/python/tests/CMakeLists.txt| 66 ---
 clang/test/bindings/python/bindings.sh| 48 ++
 clang/test/bindings/python/lit.local.cfg  | 22 +++
 .../bindings/python/tests/__init__.py |  0
 .../bindings/python/tests/cindex/INPUTS/a.inc |  0
 .../bindings/python/tests/cindex/INPUTS/b.inc |  0
 .../tests/cindex/INPUTS/compile_commands.json |  0
 .../python/tests/cindex/INPUTS/header1.h  |  0
 .../python/tests/cindex/INPUTS/header2.h  |  0
 .../python/tests/cindex/INPUTS/header3.h  |  0
 .../python/tests/cindex/INPUTS/hello.cpp  |  0
 .../python/tests/cindex/INPUTS/include.cpp|  0
 .../tests/cindex/INPUTS/parse_arguments.c |  0
 .../python/tests/cindex/INPUTS/testfile.c |  0
 .../bindings/python/tests/cindex/__init__.py  |  0
 .../tests/cindex/test_access_specifiers.py|  0
 .../bindings/python/tests/cindex/test_cdb.py  |  0
 .../tests/cindex/test_code_completion.py  |  0
 .../python/tests/cindex/test_comment.py   |  0
 .../python/tests/cindex/test_cursor.py|  0
 .../python/tests/cindex/test_cursor_kind.py   |  0
 .../python/tests/cindex/test_diagnostics.py   |  0
 .../python/tests/cindex/test_enums.py |  0
 .../test_exception_specification_kind.py  |  0
 .../bindings/python/tests/cindex/test_file.py |  0
 .../python/tests/cindex/test_index.py |  0
 .../bindings/python/tests/cindex/test_lib.py  |  0
 .../python/tests/cindex/test_linkage.py   |  0
 .../python/tests/cindex/test_location.py  |  0
 .../python/tests/cindex/test_rewrite.py   |  0
 .../python/tests/cindex/test_source_range.py  |  0
 .../python/tests/cindex/test_tls_kind.py  |  0
 .../python/tests/cindex/test_token_kind.py|  0
 .../python/tests/cindex/test_tokens.py|  0
 .../tests/cindex/test_translation_unit.py |  0
 .../bindings/python/tests/cindex/test_type.py |  0
 .../bindings/python/tests/cindex/util.py  |  0
 38 files changed, 70 insertions(+), 67 deletions(-)
 delete mode 100644 clang/bindings/python/tests/CMakeLists.txt
 create mode 100755 clang/test/bindings/python/bindings.sh
 create 

[clang] [CodeGen] Add TBAA struct path info for array members (PR #137719)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-x86_64-debian` 
running on `lldb-x86_64-debian` while building `clang` at step 6 "test".

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


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

```
Step 6 (test) failure: build (failure)
...
UNSUPPORTED: lldb-shell :: 
ScriptInterpreter/Python/Crashlog/interactive_crashlog_invalid_target.test 
(2980 of 2991)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Lua/watchpoint_callback.test (2981 
of 2991)
UNSUPPORTED: lldb-shell :: 
ScriptInterpreter/Python/Crashlog/last_exception_backtrace_crashlog.test (2982 
of 2991)
UNSUPPORTED: lldb-shell :: Expr/TestEnumExtensibility.m (2983 of 2991)
UNSUPPORTED: lldb-shell :: 
ScriptInterpreter/Lua/breakpoint_oneline_callback.test (2984 of 2991)
UNSUPPORTED: lldb-shell :: Process/Windows/msstl_smoke.cpp (2985 of 2991)
UNSUPPORTED: lldb-shell :: ScriptInterpreter/Lua/command_script_import.test 
(2986 of 2991)
UNSUPPORTED: lldb-shell :: 
ScriptInterpreter/Python/Crashlog/skipped_status_interactive_crashlog.test 
(2987 of 2991)
PASS: lldb-api :: terminal/TestEditlineCompletions.py (2988 of 2991)
UNRESOLVED: lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py (2989 of 2991)
 TEST 'lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py' 
FAILED 
Script:
--
/usr/bin/python3 
/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/dotest.py -u 
CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./lib --env 
LLVM_INCLUDE_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/include --env 
LLVM_TOOLS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./bin --arch x86_64 
--build-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/lldb --compiler 
/home/worker/2.0.1/lldb-x86_64-debian/build/./bin/clang --dsymutil 
/home/worker/2.0.1/lldb-x86_64-debian/build/./bin/dsymutil --make 
/usr/bin/gmake --llvm-tools-dir 
/home/worker/2.0.1/lldb-x86_64-debian/build/./bin --lldb-obj-root 
/home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb --lldb-libs-dir 
/home/worker/2.0.1/lldb-x86_64-debian/build/./lib --cmake-build-type Release -t 
/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/tools/lldb-dap/launch
 -p TestDAP_launch.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 21.0.0git (https://github.com/llvm/llvm-project.git revision 
c3b8a15eab06fceb6f4d0f2a0f505d5290ff208a)
  clang revision c3b8a15eab06fceb6f4d0f2a0f505d5290ff208a
  llvm revision c3b8a15eab06fceb6f4d0f2a0f505d5290ff208a
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
Change dir to: 
/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/tools/lldb-dap/launch
runCmd: settings clear --all

output: 

runCmd: settings set symbols.enable-external-lookup false

output: 

runCmd: settings set target.inherit-tcc true

output: 

runCmd: settings set target.disable-aslr false

output: 

runCmd: settings set target.detach-on-error false

output: 

runCmd: settings set target.auto-apply-fixits false

```



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


[clang] [clang][python][test] Move python binding tests to lit framework (PR #142948)

2025-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rainer Orth (rorth)


Changes

As discussed in PR #142353, the current testsuite of the `clang` Python 
bindings has several issues:

- It `libclang.so` cannot be loaded into `python` to run the testsuite, the 
whole `ninja check-all` aborts.
- The result of running the testsuite isn't report like the `lit`-based tests, 
rendering them almost invisible.
- The testsuite is disabled in a non-obvious way (`RUN_PYTHON_TESTS`) in 
`tests/CMakeLists.txt`, which again doesn't show up in the test results.

All these issues can be avoided by integrating the Python bindings tests with 
`lit`, which is what this patch does:

- The actual test lives in `clang/test/bindings/python/bindings.sh` and is run 
by `lit`.
- The current `clang/bindings/python/tests` directory (minus the 
now-subperfluous `CMakeLists.txt`) is moved into the same directory.
- The check if `libclang` is loadable (originally from PR #142353) is 
now handled via a new `lit` feature, `libclang-loadable`.
- The various ways to disable the tests have been turned into `XFAIL`s as 
appropriate.  This isn't complete and not completely tested yet.

Tested on `sparc-sun-solaris2.11`, `sparcv9-sun-solaris2.11`, 
`i386-pc-solaris2.11`, `amd64-pc-solaris2.11`, `i686-pc-linux-gnu`, and 
`x86_64-pc-linux-gnu`.

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


38 Files Affected:

- (modified) clang/CMakeLists.txt (-1) 
- (removed) clang/bindings/python/tests/CMakeLists.txt (-66) 
- (added) clang/test/bindings/python/bindings.sh (+48) 
- (added) clang/test/bindings/python/lit.local.cfg (+22) 
- (renamed) clang/test/bindings/python/tests/__init__.py () 
- (renamed) clang/test/bindings/python/tests/cindex/INPUTS/a.inc () 
- (renamed) clang/test/bindings/python/tests/cindex/INPUTS/b.inc () 
- (renamed) 
clang/test/bindings/python/tests/cindex/INPUTS/compile_commands.json () 
- (renamed) clang/test/bindings/python/tests/cindex/INPUTS/header1.h () 
- (renamed) clang/test/bindings/python/tests/cindex/INPUTS/header2.h () 
- (renamed) clang/test/bindings/python/tests/cindex/INPUTS/header3.h () 
- (renamed) clang/test/bindings/python/tests/cindex/INPUTS/hello.cpp () 
- (renamed) clang/test/bindings/python/tests/cindex/INPUTS/include.cpp () 
- (renamed) clang/test/bindings/python/tests/cindex/INPUTS/parse_arguments.c () 
- (renamed) clang/test/bindings/python/tests/cindex/INPUTS/testfile.c () 
- (renamed) clang/test/bindings/python/tests/cindex/__init__.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_access_specifiers.py 
() 
- (renamed) clang/test/bindings/python/tests/cindex/test_cdb.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_code_completion.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_comment.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_cursor.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_cursor_kind.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_diagnostics.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_enums.py () 
- (renamed) 
clang/test/bindings/python/tests/cindex/test_exception_specification_kind.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_file.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_index.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_lib.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_linkage.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_location.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_rewrite.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_source_range.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_tls_kind.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_token_kind.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_tokens.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_translation_unit.py () 
- (renamed) clang/test/bindings/python/tests/cindex/test_type.py () 
- (renamed) clang/test/bindings/python/tests/cindex/util.py () 


``diff
diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index ab2ac9bc6b9ad..5111953397d04 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -533,7 +533,6 @@ if( CLANG_INCLUDE_TESTS )
 clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
   )
   add_subdirectory(test)
-  add_subdirectory(bindings/python/tests)
 
   if(CLANG_BUILT_STANDALONE)
 umbrella_lit_testsuite_end(check-all)
diff --git a/clang/bindings/python/tests/CMakeLists.txt 
b/clang/bindings/python/tests/CMakeLists.txt
deleted file mode 100644
index a0ddabc21bb41..0
--- a/clang/bindings/python/tests/CMakeLists.txt
+++ /dev/null
@@ -1,66 +0,0 @@
-# Test target to run Python test suite from main build.
-
-# Avoid configurations including '-include' from interfering with
-# our tests by setting CLANG_NO_DEFAULT_CONFIG.

[clang] [clang][python][test] Check if libclang.so is loadable (PR #142353)

2025-06-05 Thread Rainer Orth via cfe-commits

rorth wrote:

I've now created PR #142948 with an initial implementation of `lit` integration 
of the `clang` Python bindings tests.

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


[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)

2025-06-05 Thread Carlos Galvez via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: %check_clang_tidy %s google-readability-namespace-comments %t 
-std=c++20 \
+// RUN:   '-config={CheckOptions: { \
+// RUN: 
google-readability-namespace-comments.AllowOmittingNamespaceComments: true, \
+// RUN: google-readability-namespace-comments.ShortNamespaceLines: 0, \
+// RUN:   }}'

carlosgalvezp wrote:

I agree with your interpretation, we should not duplicate the main file into 
the option file, but we still need to test the behaviors that we promise. As 
per the docs, we promise 2 behaviors:

-   When `true`, the check will accept if no namespace comment is present.
-   The check will only fail if the specified namespace comment is different
   than expected.

So the tests should reflect those behaviors when the option is True.

I think the newly added test case is fine, can you please add it also to the 
other test file (readability-namespace-comments-missing.cpp) for consistency?

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


[clang] Reapply "[clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #115823)

2025-06-05 Thread Aaron Puchert via cfe-commits


@@ -3918,6 +3918,75 @@ have their lifetimes extended.
   }];
 }
 
+def LifetimeCaptureByDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a 
function
+parameter or implicit object parameter indicates that that objects that are 
referred to
+by that parameter may also be referred to by the capturing entity ``X``.
+
+By default, a reference is considered to refer to its referenced object, a
+pointer is considered to refer to its pointee, a ``std::initializer_list``
+is considered to refer to its underlying array, and aggregates (arrays and
+simple ``struct``\s) are considered to refer to all objects that their
+transitive subobjects refer to.
+
+The capturing entity ``X`` can be one of the following:
+- Another (named) function parameter. 
+  
+  .. code-block:: c++
+
+void addToSet(std::string_view a [[clang::lifetime_capture_by(s)]], 
std::set& s) {
+  s.insert(a);
+}
+
+- ``this`` (in case of member functions).
+  
+  .. code-block:: c++
+
+class S {
+  void addToSet(std::string_view a [[clang::lifetime_capture_by(this)]]) {
+s.insert(a);
+  }
+  std::set s;
+};
+
+- 'global', 'unknown' (without quotes).
+  
+  .. code-block:: c++
+
+std::set s;
+void addToSet(std::string_view a [[clang::lifetime_capture_by(global)]]) {
+  s.insert(a);
+}
+void addSomewhere(std::string_view a 
[[clang::lifetime_capture_by(unknown)]]);
+
+The attribute can be applied to the implicit ``this`` parameter of a member
+function by writing the attribute after the function type:
+
+.. code-block:: c++
+
+  struct S {
+const char *data(std::set& s) [[clang::lifetime_capture_by(s)]] {
+  s.insert(this);
+}
+  };
+
+The attribute supports specifying more than one capturing entities:
+
+.. code-block:: c++
+  
+  void addToSets(std::string_view a [[clang::lifetime_capture_by(s1, s2)]],
+ std::set& s1,
+ std::set& s2) {
+s1.insert(a);
+s2.insert(a);
+  }
+
+.. _`lifetimebound`: 
https://clang.llvm.org/docs/AttributeReference.html#lifetimebound

aaronpuchert wrote:

There is no need for an external link within the same page. In fact, this 
breaks the existing `lifetimebound` anchor. The fix is to simply remove this 
line. (#142967)

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


[clang] Introduce intra-procedural lifetime analysis in Clang (PR #142313)

2025-06-05 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/142313

>From 0cd187b01e61b200d92ca0b640789c1586075142 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 2 Jun 2025 17:53:14 +
Subject: [PATCH] Introduce Intra-procedural lifetime analysis in Clang

---
 .../clang/Analysis/Analyses/LifetimeSafety.h  |  13 +
 clang/lib/Analysis/CMakeLists.txt |   1 +
 clang/lib/Analysis/LifetimeSafety.cpp | 728 ++
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |   8 +
 .../Sema/warn-lifetime-safety-dataflow.cpp| 362 +
 5 files changed, 1112 insertions(+)
 create mode 100644 clang/include/clang/Analysis/Analyses/LifetimeSafety.h
 create mode 100644 clang/lib/Analysis/LifetimeSafety.cpp
 create mode 100644 clang/test/Sema/warn-lifetime-safety-dataflow.cpp

diff --git a/clang/include/clang/Analysis/Analyses/LifetimeSafety.h 
b/clang/include/clang/Analysis/Analyses/LifetimeSafety.h
new file mode 100644
index 0..daf24fff72b9b
--- /dev/null
+++ b/clang/include/clang/Analysis/Analyses/LifetimeSafety.h
@@ -0,0 +1,13 @@
+#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIME_SAFETY_H
+#define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIME_SAFETY_H
+#include "clang/AST/DeclBase.h"
+#include "clang/Analysis/AnalysisDeclContext.h"
+#include "clang/Analysis/CFG.h"
+namespace clang {
+
+void runLifetimeAnalysis(const DeclContext &DC, const CFG &Cfg,
+ AnalysisDeclContext &AC);
+
+} // namespace clang
+
+#endif // LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIME_SAFETY_H
diff --git a/clang/lib/Analysis/CMakeLists.txt 
b/clang/lib/Analysis/CMakeLists.txt
index 8cd3990db4c3e..0523d92480cb3 100644
--- a/clang/lib/Analysis/CMakeLists.txt
+++ b/clang/lib/Analysis/CMakeLists.txt
@@ -21,6 +21,7 @@ add_clang_library(clangAnalysis
   FixitUtil.cpp
   IntervalPartition.cpp
   IssueHash.cpp
+  LifetimeSafety.cpp
   LiveVariables.cpp
   MacroExpansionContext.cpp
   ObjCNoReturn.cpp
diff --git a/clang/lib/Analysis/LifetimeSafety.cpp 
b/clang/lib/Analysis/LifetimeSafety.cpp
new file mode 100644
index 0..8dbb4dc37026c
--- /dev/null
+++ b/clang/lib/Analysis/LifetimeSafety.cpp
@@ -0,0 +1,728 @@
+#include "clang/Analysis/Analyses/LifetimeSafety.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/StmtVisitor.h"
+#include "clang/AST/Type.h"
+#include "clang/Analysis/AnalysisDeclContext.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/DataflowWorklist.h"
+#include "llvm/ADT/ImmutableMap.h"
+#include "llvm/ADT/ImmutableSet.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/TimeProfiler.h"
+#include 
+
+namespace clang {
+namespace {
+
+struct Point {
+  const clang::CFGBlock *Block;
+  /// Index into Block->Elements().
+  unsigned ElementIndex;
+
+  Point(const clang::CFGBlock *B = nullptr, unsigned Idx = 0)
+  : Block(B), ElementIndex(Idx) {}
+
+  bool operator==(const Point &Other) const {
+return Block == Other.Block && ElementIndex == Other.ElementIndex;
+  }
+};
+
+/// Represents the storage location being borrowed, e.g., a specific stack
+/// variable.
+/// TODO: Handle member accesseslike `s.y`.
+struct Path {
+  const clang::ValueDecl *D;
+
+  enum class Kind : uint8_t {
+StackVariable,
+Heap,// TODO: Handle.
+Field,   // TODO: Handle.
+ArrayElement,// TODO: Handle.
+TemporaryObject, // TODO: Handle.
+StaticOrGlobal,  // TODO: Handle.
+  };
+
+  Kind PathKind;
+
+  Path(const clang::ValueDecl *D, Kind K) : D(D), PathKind(K) {}
+};
+
+using LoanID = uint32_t;
+using OriginID = uint32_t;
+
+/// Information about a single borrow, or "Loan". A loan is created when a
+/// reference or pointer is taken.
+struct LoanInfo {
+  /// TODO: Represent opaque loans.
+  /// TODO: Represent nullptr: loans to no path. Accessing it UB! Currently it
+  /// is represented as empty LoanSet
+  LoanID ID;
+  Path SourcePath;
+  SourceLocation IssueLoc;
+
+  LoanInfo(LoanID id, Path path, SourceLocation loc)
+  : ID(id), SourcePath(path), IssueLoc(loc) {}
+};
+
+enum class OriginKind : uint8_t { Variable, ExpressionResult };
+
+/// An Origin is a symbolic identifier that represents the set of possible
+/// loans a pointer-like object could hold at any given time.
+/// TODO: Also represent Origins of complex types (fields, inner types).
+struct OriginInfo {
+  OriginID ID;
+  OriginKind Kind;
+  union {
+const clang::ValueDecl *Decl;
+const clang::Expr *Expression;
+  };
+  OriginInfo(OriginID id, OriginKind kind, const clang::ValueDecl *D)
+  : ID(id), Kind(kind), Decl(D) {}
+  OriginInfo(OriginID id, OriginKind kind, const clang::Expr *E)
+  : ID(id), Kind(kind), Expression(E) {}
+};
+
+class LoanManager {
+public:
+  LoanManager() = default;
+
+  LoanInfo &addLoanInfo(Path path, SourceLocation loc) {
+NextLoanIDVal++;
+AllLoans.emplace_back(NextLoanIDVal

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-06-05 Thread Aaron Ballman via cfe-commits


@@ -4222,6 +4222,11 @@ def warn_fun_requires_lock_precise :
   InGroup, DefaultIgnore;
 def note_found_mutex_near_match : Note<"found near match '%0'">;
 
+// Pedantic thread safety warnings enabled by default
+def warn_thread_reentrant_with_negative_capability : Warning<
+  "%0 is marked reentrant but used as a negative capability; this may be 
contradictory">,
+  InGroup, DefaultIgnore;

AaronBallman wrote:

> Introduce a pedantic warning group, which is enabled by default, to warn 
> about using a reentrant capability as a negative capability: this usage is 
> likely contradictory.

The only attribute in the group is marked `DefaultIgnore`, did you mean to drop 
that?

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


[clang] [llvm] [CodeGen][clang] Use module metadata to mark hotpatchable modules (PR #142969)

2025-06-05 Thread Jacek Caban via cfe-commits

https://github.com/cjacek created 
https://github.com/llvm/llvm-project/pull/142969

None

>From 108b56e9d0fbd522d3ee458405dab43a01b5ebd5 Mon Sep 17 00:00:00 2001
From: Jacek Caban 
Date: Wed, 4 Jun 2025 13:13:06 +0200
Subject: [PATCH] [CodeGen][clang] Use module metadata to mark hotpatchable
 modules

---
 clang/lib/CodeGen/BackendUtil.cpp |  1 -
 clang/lib/CodeGen/CodeGenModule.cpp   |  4 ++
 clang/test/CodeGen/patchable-function-entry.c |  1 +
 llvm/include/llvm/Target/TargetOptions.h  |  5 +-
 llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp |  4 +-
 llvm/test/DebugInfo/PDB/hotpatch.test | 57 +++
 6 files changed, 65 insertions(+), 7 deletions(-)
 create mode 100644 llvm/test/DebugInfo/PDB/hotpatch.test

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index cd5fc48c4a22b..2365f675b2dc3 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -473,7 +473,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
   Options.LoopAlignment = CodeGenOpts.LoopAlignment;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
   Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
-  Options.Hotpatch = CodeGenOpts.HotPatch;
   Options.JMCInstrument = CodeGenOpts.JMCInstrument;
   Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 468fc6e0e5c56..3529a5a70bd45 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1031,6 +1031,10 @@ void CodeGenModule::Release() {
 // Function ID tables for EH Continuation Guard.
 getModule().addModuleFlag(llvm::Module::Warning, "ehcontguard", 1);
   }
+  if (CodeGenOpts.HotPatch) {
+// Note if we are compiling with /hotpatch.
+getModule().addModuleFlag(llvm::Module::Warning, "ms-hotpatch", 1);
+  }
   if (Context.getLangOpts().Kernel) {
 // Note if we are compiling with /kernel.
 getModule().addModuleFlag(llvm::Module::Warning, "ms-kernel", 1);
diff --git a/clang/test/CodeGen/patchable-function-entry.c 
b/clang/test/CodeGen/patchable-function-entry.c
index 2acd748758490..b49f297abf7de 100644
--- a/clang/test/CodeGen/patchable-function-entry.c
+++ b/clang/test/CodeGen/patchable-function-entry.c
@@ -39,3 +39,4 @@ void f(void) {}
 // HOTPATCH: attributes #1 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #2 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #3 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
+// HOTPATCH: !{{.}} = !{i32 2, !"ms-hotpatch", i32 1}
diff --git a/llvm/include/llvm/Target/TargetOptions.h 
b/llvm/include/llvm/Target/TargetOptions.h
index fd8dad4f6f791..25bbb73e9dedc 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -150,7 +150,7 @@ namespace llvm {
   EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
   SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
   ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
-  XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
+  XRayFunctionIndex(true), DebugStrictDwarf(false),
   PPCGenScalarMASSEntries(false), JMCInstrument(false),
   EnableCFIFixup(false), MisExpect(false), 
XCOFFReadOnlyPointers(false),
   VerifyArgABICompliance(true),
@@ -363,9 +363,6 @@ namespace llvm {
 /// By default, it is set to false.
 unsigned DebugStrictDwarf : 1;
 
-/// Emit the hotpatch flag in CodeView debug.
-unsigned Hotpatch : 1;
-
 /// Enables scalar MASS conversions
 unsigned PPCGenScalarMASSEntries : 1;
 
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp 
b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index fc43bc6f7776d..49e26fcec48d6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -846,8 +846,8 @@ void CodeViewDebug::emitCompilerInformation() {
   }
   using ArchType = llvm::Triple::ArchType;
   ArchType Arch = MMI->getModule()->getTargetTriple().getArch();
-  if (Asm->TM.Options.Hotpatch || Arch == ArchType::thumb ||
-  Arch == ArchType::aarch64) {
+  if (Arch == ArchType::thumb || Arch == ArchType::aarch64 ||
+  MMI->getModule()->getModuleFlag("ms-hotpatch")) {
 Flags |= static_cast(CompileSym3Flags::HotPatch);
   }
 
diff --git a/llvm/test/DebugInfo/PDB/hotpatch.test 
b/llvm/test/DebugInfo/PDB/hotpatch.test
new file mode 100644
index 0..7ff15fa3c69a4
--- /dev/null
+++ b/llvm/test/DebugInfo/PDB/hotpatch.test
@@ -0,0 +1,57 @@
+; RUN: llc -filetype=obj -o - %s | llvm-readobj --codeview - | FileCheck %s
+
+; ModuleID = 'a.c'
+source_filename = "a.c"
+target datalayout = 
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S

[clang] [llvm] [CodeGen][clang] Use module metadata to mark hotpatchable modules (PR #142969)

2025-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Jacek Caban (cjacek)


Changes



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


6 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4) 
- (modified) clang/test/CodeGen/patchable-function-entry.c (+1) 
- (modified) llvm/include/llvm/Target/TargetOptions.h (+1-4) 
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (+2-2) 
- (added) llvm/test/DebugInfo/PDB/hotpatch.test (+57) 


``diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index cd5fc48c4a22b..2365f675b2dc3 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -473,7 +473,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
   Options.LoopAlignment = CodeGenOpts.LoopAlignment;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
   Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
-  Options.Hotpatch = CodeGenOpts.HotPatch;
   Options.JMCInstrument = CodeGenOpts.JMCInstrument;
   Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 468fc6e0e5c56..3529a5a70bd45 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1031,6 +1031,10 @@ void CodeGenModule::Release() {
 // Function ID tables for EH Continuation Guard.
 getModule().addModuleFlag(llvm::Module::Warning, "ehcontguard", 1);
   }
+  if (CodeGenOpts.HotPatch) {
+// Note if we are compiling with /hotpatch.
+getModule().addModuleFlag(llvm::Module::Warning, "ms-hotpatch", 1);
+  }
   if (Context.getLangOpts().Kernel) {
 // Note if we are compiling with /kernel.
 getModule().addModuleFlag(llvm::Module::Warning, "ms-kernel", 1);
diff --git a/clang/test/CodeGen/patchable-function-entry.c 
b/clang/test/CodeGen/patchable-function-entry.c
index 2acd748758490..b49f297abf7de 100644
--- a/clang/test/CodeGen/patchable-function-entry.c
+++ b/clang/test/CodeGen/patchable-function-entry.c
@@ -39,3 +39,4 @@ void f(void) {}
 // HOTPATCH: attributes #1 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #2 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #3 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
+// HOTPATCH: !{{.}} = !{i32 2, !"ms-hotpatch", i32 1}
diff --git a/llvm/include/llvm/Target/TargetOptions.h 
b/llvm/include/llvm/Target/TargetOptions.h
index fd8dad4f6f791..25bbb73e9dedc 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -150,7 +150,7 @@ namespace llvm {
   EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
   SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
   ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
-  XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
+  XRayFunctionIndex(true), DebugStrictDwarf(false),
   PPCGenScalarMASSEntries(false), JMCInstrument(false),
   EnableCFIFixup(false), MisExpect(false), 
XCOFFReadOnlyPointers(false),
   VerifyArgABICompliance(true),
@@ -363,9 +363,6 @@ namespace llvm {
 /// By default, it is set to false.
 unsigned DebugStrictDwarf : 1;
 
-/// Emit the hotpatch flag in CodeView debug.
-unsigned Hotpatch : 1;
-
 /// Enables scalar MASS conversions
 unsigned PPCGenScalarMASSEntries : 1;
 
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp 
b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index fc43bc6f7776d..49e26fcec48d6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -846,8 +846,8 @@ void CodeViewDebug::emitCompilerInformation() {
   }
   using ArchType = llvm::Triple::ArchType;
   ArchType Arch = MMI->getModule()->getTargetTriple().getArch();
-  if (Asm->TM.Options.Hotpatch || Arch == ArchType::thumb ||
-  Arch == ArchType::aarch64) {
+  if (Arch == ArchType::thumb || Arch == ArchType::aarch64 ||
+  MMI->getModule()->getModuleFlag("ms-hotpatch")) {
 Flags |= static_cast(CompileSym3Flags::HotPatch);
   }
 
diff --git a/llvm/test/DebugInfo/PDB/hotpatch.test 
b/llvm/test/DebugInfo/PDB/hotpatch.test
new file mode 100644
index 0..7ff15fa3c69a4
--- /dev/null
+++ b/llvm/test/DebugInfo/PDB/hotpatch.test
@@ -0,0 +1,57 @@
+; RUN: llc -filetype=obj -o - %s | llvm-readobj --codeview - | FileCheck %s
+
+; ModuleID = 'a.c'
+source_filename = "a.c"
+target datalayout = 
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc19.33.0"
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local void @test() #0 !dbg !10 {
+entry:
+  ret void, !dbg !13
+}
+
+attribu

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-06-05 Thread Aaron Ballman via cfe-commits

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


[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-06-05 Thread Aaron Ballman via cfe-commits


@@ -7223,4 +7225,10 @@ class TestNegativeWithReentrantMutex {
   }
 };
 
+typedef int __attribute__((capability("role"), reentrant_capability)) 
ThreadRole;
+ThreadRole FlightControl1, FlightControl2;
+void dispatch_log(const char *msg) 
__attribute__((requires_capability(!FlightControl1 && !FlightControl2))) {} // \
+  // expected-warning{{'ThreadRole' (aka 'int') is marked reentrant but used 
as a negative capability; this may be contradictory}} \

AaronBallman wrote:

Oooh, the reason this test passes despite the `DefaultIgnore` is because the 
diagnostic is enabled by `-Wthread-safety` which is the only way to enable any 
thread safety diagnostics.

If we want the diagnostic to be ignored by default, we'd leave the group out of 
`-Wthread-safety` but that could get awkward (what if you enable just the 
pedantic warning and nothing else? ew.)

So I think we should drop the `DefaultIgnore` above to avoid confusion.

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


[clang] [llvm] [CodeGen][clang] Use module metadata to mark hotpatchable modules (PR #142969)

2025-06-05 Thread Jacek Caban via cfe-commits

cjacek wrote:

The main motivation is to enable writing llc-based tests for the emitted 
CodeView data

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


[clang] [llvm] [CodeGen][clang] Use module metadata to mark hotpatchable modules (PR #142969)

2025-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jacek Caban (cjacek)


Changes



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


6 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+4) 
- (modified) clang/test/CodeGen/patchable-function-entry.c (+1) 
- (modified) llvm/include/llvm/Target/TargetOptions.h (+1-4) 
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (+2-2) 
- (added) llvm/test/DebugInfo/PDB/hotpatch.test (+57) 


``diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index cd5fc48c4a22b..2365f675b2dc3 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -473,7 +473,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
   Options.LoopAlignment = CodeGenOpts.LoopAlignment;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
   Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
-  Options.Hotpatch = CodeGenOpts.HotPatch;
   Options.JMCInstrument = CodeGenOpts.JMCInstrument;
   Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 468fc6e0e5c56..3529a5a70bd45 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1031,6 +1031,10 @@ void CodeGenModule::Release() {
 // Function ID tables for EH Continuation Guard.
 getModule().addModuleFlag(llvm::Module::Warning, "ehcontguard", 1);
   }
+  if (CodeGenOpts.HotPatch) {
+// Note if we are compiling with /hotpatch.
+getModule().addModuleFlag(llvm::Module::Warning, "ms-hotpatch", 1);
+  }
   if (Context.getLangOpts().Kernel) {
 // Note if we are compiling with /kernel.
 getModule().addModuleFlag(llvm::Module::Warning, "ms-kernel", 1);
diff --git a/clang/test/CodeGen/patchable-function-entry.c 
b/clang/test/CodeGen/patchable-function-entry.c
index 2acd748758490..b49f297abf7de 100644
--- a/clang/test/CodeGen/patchable-function-entry.c
+++ b/clang/test/CodeGen/patchable-function-entry.c
@@ -39,3 +39,4 @@ void f(void) {}
 // HOTPATCH: attributes #1 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #2 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #3 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
+// HOTPATCH: !{{.}} = !{i32 2, !"ms-hotpatch", i32 1}
diff --git a/llvm/include/llvm/Target/TargetOptions.h 
b/llvm/include/llvm/Target/TargetOptions.h
index fd8dad4f6f791..25bbb73e9dedc 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -150,7 +150,7 @@ namespace llvm {
   EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
   SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
   ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
-  XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
+  XRayFunctionIndex(true), DebugStrictDwarf(false),
   PPCGenScalarMASSEntries(false), JMCInstrument(false),
   EnableCFIFixup(false), MisExpect(false), 
XCOFFReadOnlyPointers(false),
   VerifyArgABICompliance(true),
@@ -363,9 +363,6 @@ namespace llvm {
 /// By default, it is set to false.
 unsigned DebugStrictDwarf : 1;
 
-/// Emit the hotpatch flag in CodeView debug.
-unsigned Hotpatch : 1;
-
 /// Enables scalar MASS conversions
 unsigned PPCGenScalarMASSEntries : 1;
 
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp 
b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index fc43bc6f7776d..49e26fcec48d6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -846,8 +846,8 @@ void CodeViewDebug::emitCompilerInformation() {
   }
   using ArchType = llvm::Triple::ArchType;
   ArchType Arch = MMI->getModule()->getTargetTriple().getArch();
-  if (Asm->TM.Options.Hotpatch || Arch == ArchType::thumb ||
-  Arch == ArchType::aarch64) {
+  if (Arch == ArchType::thumb || Arch == ArchType::aarch64 ||
+  MMI->getModule()->getModuleFlag("ms-hotpatch")) {
 Flags |= static_cast(CompileSym3Flags::HotPatch);
   }
 
diff --git a/llvm/test/DebugInfo/PDB/hotpatch.test 
b/llvm/test/DebugInfo/PDB/hotpatch.test
new file mode 100644
index 0..7ff15fa3c69a4
--- /dev/null
+++ b/llvm/test/DebugInfo/PDB/hotpatch.test
@@ -0,0 +1,57 @@
+; RUN: llc -filetype=obj -o - %s | llvm-readobj --codeview - | FileCheck %s
+
+; ModuleID = 'a.c'
+source_filename = "a.c"
+target datalayout = 
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc19.33.0"
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local void @test() #0 !dbg !10 {
+entry:
+  ret void, !dbg !13
+}
+
+attributes #0 =

[clang] [CIR] Upstream splat op for VectorType (PR #139827)

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


@@ -1883,6 +1884,60 @@ mlir::LogicalResult 
CIRToLLVMVecCmpOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMVecSplatOpLowering::matchAndRewrite(
+cir::VecSplatOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+  // Vector splat can be implemented with an `insertelement` and a
+  // `shufflevector`, which is better than an `insertelement` for each
+  // element in the vector. Start with an undef vector. Insert the value into
+  // the first element. Then use a `shufflevector` with a mask of all 0 to
+  // fill out the entire vector with that value.
+  const auto vecTy = mlir::cast(op.getType());
+  const mlir::Type llvmTy = typeConverter->convertType(vecTy);
+  const mlir::Location loc = op.getLoc();
+  const mlir::Value poison = rewriter.create(loc, 
llvmTy);
+
+  const mlir::Value elementValue = adaptor.getValue();
+  if (mlir::isa(elementValue.getDefiningOp())) {
+// If the splat value is poison, then we can just use poison value
+// for the entire vector.
+rewriter.replaceOp(op, poison);
+return mlir::success();
+  }
+
+  if (auto constValue =
+  dyn_cast(elementValue.getDefiningOp())) {
+if (auto intAttr = dyn_cast(constValue.getValue())) {
+  mlir::DenseIntElementsAttr denseVec = mlir::DenseIntElementsAttr::get(
+  mlir::cast(llvmTy), intAttr.getValue());
+
+  const mlir::Value indexValue = rewriter.create(
+  loc, denseVec.getType(), denseVec);
+  rewriter.replaceOp(op, indexValue);

xlauko wrote:

why not `replaceOpWithNewOp`?

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


[clang] [CIR] Upstream splat op for VectorType (PR #139827)

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


@@ -1883,6 +1884,60 @@ mlir::LogicalResult 
CIRToLLVMVecCmpOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMVecSplatOpLowering::matchAndRewrite(
+cir::VecSplatOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+  // Vector splat can be implemented with an `insertelement` and a
+  // `shufflevector`, which is better than an `insertelement` for each
+  // element in the vector. Start with an undef vector. Insert the value into
+  // the first element. Then use a `shufflevector` with a mask of all 0 to
+  // fill out the entire vector with that value.
+  const auto vecTy = mlir::cast(op.getType());

xlauko wrote:

I believe the cast is no longer needed:
```suggestion
  const cir::VectorType vecTy = op.getType();
```

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


[clang] [llvm] [CodeGen][COFF] Always emit CodeView compiler info when hotpatch option is enabled (PR #142970)

2025-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jacek Caban (cjacek)


Changes

 MSVC always emits minimal CodeView metadata containing compiler information, 
even when debug info is otherwise disabled. While this data is typically not 
meaningful on its own, the linker may use it to detect whether the object file 
was built with hotpatch support. To match this behavior, emit compiler info 
whenever the hotpatch option is enabled.

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


10 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+7-3) 
- (modified) clang/test/CodeGen/patchable-function-entry.c (+2) 
- (modified) llvm/include/llvm/Target/TargetOptions.h (+1-4) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+6-2) 
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (+28-5) 
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h (+3) 
- (added) llvm/test/DebugInfo/PDB/hotpatch-dwarf.c (+59) 
- (added) llvm/test/DebugInfo/PDB/hotpatch-nodebug.c (+57) 
- (added) llvm/test/DebugInfo/PDB/hotpatch.test (+57) 


``diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index cd5fc48c4a22b..2365f675b2dc3 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -473,7 +473,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
   Options.LoopAlignment = CodeGenOpts.LoopAlignment;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
   Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
-  Options.Hotpatch = CodeGenOpts.HotPatch;
   Options.JMCInstrument = CodeGenOpts.JMCInstrument;
   Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 468fc6e0e5c56..ddad9a66766fd 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -408,11 +408,11 @@ CodeGenModule::CodeGenModule(ASTContext &C,
 TBAA.reset(new CodeGenTBAA(Context, getTypes(), TheModule, CodeGenOpts,
getLangOpts()));
 
-  // If debug info or coverage generation is enabled, create the CGDebugInfo
-  // object.
+  // If debug info, coverage generation or hotpatch is enabled, create the
+  // CGDebugInfo object.
   if (CodeGenOpts.getDebugInfo() != llvm::codegenoptions::NoDebugInfo ||
   CodeGenOpts.CoverageNotesFile.size() ||
-  CodeGenOpts.CoverageDataFile.size())
+  CodeGenOpts.CoverageDataFile.size() || CodeGenOpts.HotPatch)
 DebugInfo.reset(new CGDebugInfo(*this));
 
   Block.GlobalUniqueCount = 0;
@@ -1031,6 +1031,10 @@ void CodeGenModule::Release() {
 // Function ID tables for EH Continuation Guard.
 getModule().addModuleFlag(llvm::Module::Warning, "ehcontguard", 1);
   }
+  if (CodeGenOpts.HotPatch) {
+// Note if we are compiling with /hotpatch.
+getModule().addModuleFlag(llvm::Module::Warning, "ms-hotpatch", 1);
+  }
   if (Context.getLangOpts().Kernel) {
 // Note if we are compiling with /kernel.
 getModule().addModuleFlag(llvm::Module::Warning, "ms-kernel", 1);
diff --git a/clang/test/CodeGen/patchable-function-entry.c 
b/clang/test/CodeGen/patchable-function-entry.c
index 2acd748758490..748d5c8bc5ae3 100644
--- a/clang/test/CodeGen/patchable-function-entry.c
+++ b/clang/test/CodeGen/patchable-function-entry.c
@@ -39,3 +39,5 @@ void f(void) {}
 // HOTPATCH: attributes #1 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #2 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #3 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
+// HOTPATCH: !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, 
producer: "clang version 21.0.0git", isOptimized: false, runtimeVersion: 0, 
emissionKind: NoDebug, splitDebugInlining: false, nameTableKind: None)
+// HOTPATCH: !{{.}} = !{i32 2, !"ms-hotpatch", i32 1}
diff --git a/llvm/include/llvm/Target/TargetOptions.h 
b/llvm/include/llvm/Target/TargetOptions.h
index fd8dad4f6f791..25bbb73e9dedc 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -150,7 +150,7 @@ namespace llvm {
   EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
   SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
   ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
-  XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
+  XRayFunctionIndex(true), DebugStrictDwarf(false),
   PPCGenScalarMASSEntries(false), JMCInstrument(false),
   EnableCFIFixup(false), MisExpect(false), 
XCOFFReadOnlyPointers(false),
   VerifyArgABICompliance(true),
@@ -363,9 +363,6 @@ namespace llvm {
 /// By default, it is set to false.
 unsigned DebugStrictDwarf : 1;
 
-/// Em

[clang] [llvm] [CodeGen][COFF] Always emit CodeView compiler info when hotpatch option is enabled (PR #142970)

2025-06-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Jacek Caban (cjacek)


Changes

 MSVC always emits minimal CodeView metadata containing compiler information, 
even when debug info is otherwise disabled. While this data is typically not 
meaningful on its own, the linker may use it to detect whether the object file 
was built with hotpatch support. To match this behavior, emit compiler info 
whenever the hotpatch option is enabled.

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


10 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (-1) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+7-3) 
- (modified) clang/test/CodeGen/patchable-function-entry.c (+2) 
- (modified) llvm/include/llvm/Target/TargetOptions.h (+1-4) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+6-2) 
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp (+28-5) 
- (modified) llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h (+3) 
- (added) llvm/test/DebugInfo/PDB/hotpatch-dwarf.c (+59) 
- (added) llvm/test/DebugInfo/PDB/hotpatch-nodebug.c (+57) 
- (added) llvm/test/DebugInfo/PDB/hotpatch.test (+57) 


``diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index cd5fc48c4a22b..2365f675b2dc3 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -473,7 +473,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
   Options.LoopAlignment = CodeGenOpts.LoopAlignment;
   Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
   Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug;
-  Options.Hotpatch = CodeGenOpts.HotPatch;
   Options.JMCInstrument = CodeGenOpts.JMCInstrument;
   Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
 
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 468fc6e0e5c56..ddad9a66766fd 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -408,11 +408,11 @@ CodeGenModule::CodeGenModule(ASTContext &C,
 TBAA.reset(new CodeGenTBAA(Context, getTypes(), TheModule, CodeGenOpts,
getLangOpts()));
 
-  // If debug info or coverage generation is enabled, create the CGDebugInfo
-  // object.
+  // If debug info, coverage generation or hotpatch is enabled, create the
+  // CGDebugInfo object.
   if (CodeGenOpts.getDebugInfo() != llvm::codegenoptions::NoDebugInfo ||
   CodeGenOpts.CoverageNotesFile.size() ||
-  CodeGenOpts.CoverageDataFile.size())
+  CodeGenOpts.CoverageDataFile.size() || CodeGenOpts.HotPatch)
 DebugInfo.reset(new CGDebugInfo(*this));
 
   Block.GlobalUniqueCount = 0;
@@ -1031,6 +1031,10 @@ void CodeGenModule::Release() {
 // Function ID tables for EH Continuation Guard.
 getModule().addModuleFlag(llvm::Module::Warning, "ehcontguard", 1);
   }
+  if (CodeGenOpts.HotPatch) {
+// Note if we are compiling with /hotpatch.
+getModule().addModuleFlag(llvm::Module::Warning, "ms-hotpatch", 1);
+  }
   if (Context.getLangOpts().Kernel) {
 // Note if we are compiling with /kernel.
 getModule().addModuleFlag(llvm::Module::Warning, "ms-kernel", 1);
diff --git a/clang/test/CodeGen/patchable-function-entry.c 
b/clang/test/CodeGen/patchable-function-entry.c
index 2acd748758490..748d5c8bc5ae3 100644
--- a/clang/test/CodeGen/patchable-function-entry.c
+++ b/clang/test/CodeGen/patchable-function-entry.c
@@ -39,3 +39,5 @@ void f(void) {}
 // HOTPATCH: attributes #1 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #2 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
 // HOTPATCH: attributes #3 = { {{.*}} 
"patchable-function"="prologue-short-redirect"
+// HOTPATCH: !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, 
producer: "clang version 21.0.0git", isOptimized: false, runtimeVersion: 0, 
emissionKind: NoDebug, splitDebugInlining: false, nameTableKind: None)
+// HOTPATCH: !{{.}} = !{i32 2, !"ms-hotpatch", i32 1}
diff --git a/llvm/include/llvm/Target/TargetOptions.h 
b/llvm/include/llvm/Target/TargetOptions.h
index fd8dad4f6f791..25bbb73e9dedc 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -150,7 +150,7 @@ namespace llvm {
   EmitAddrsig(false), BBAddrMap(false), EmitCallSiteInfo(false),
   SupportsDebugEntryValues(false), EnableDebugEntryValues(false),
   ValueTrackingVariableLocations(false), ForceDwarfFrameSection(false),
-  XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false),
+  XRayFunctionIndex(true), DebugStrictDwarf(false),
   PPCGenScalarMASSEntries(false), JMCInstrument(false),
   EnableCFIFixup(false), MisExpect(false), 
XCOFFReadOnlyPointers(false),
   VerifyArgABICompliance(true),
@@ -363,9 +363,6 @@ namespace llvm {
 /// By default, it is set to false.
 unsigned DebugStrictDwarf : 1;
 
-  

[clang] [CIR] Implement folder for VecTernaryOp (PR #142946)

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

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

lgtm

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


[clang] [llvm] [CodeGen][COFF] Always emit CodeView compiler info when hotpatch option is enabled (PR #142970)

2025-06-05 Thread Alexandre Ganea via cfe-commits

aganea wrote:

MSVC emits this debug section at all times (S_OBJNAME and S_COMPILE3). Can't we 
do the same without checking for the `getModuleFlag("ms-hotpatch")` flag?

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


[clang] [analyzer][NFCI] Remove pointless program point tagging (PR #142980)

2025-06-05 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat created 
https://github.com/llvm/llvm-project/pull/142980

Previously some checkers attached explicitly created program point tags to some 
of the exploded graph nodes that they created. In most of the checkers this 
ad-hoc tagging only affected the debug dump of the exploded graph (and they 
weren't too relevant for debugging) so this commit removes them.

There were two checkers where the tagging _did_ have a functional role:
- In `RetainCountChecker` the presence of tags were checked by 
`RefCountReportVisitor`.
- In `DynamicTypePropagation` the checker sometimes wanted to create two 
identical nodes and had to apply an explicit tag on the second one to avoid 
"caching out". In these two situations I preserved the tags but switched to 
using `SimpleProgramPointTag` instead of `CheckerProgramPointTag` because 
`CheckerProgramPointTag` didn't provide enough benefits to justify its 
existence.

Note that this commit depends on the earlier commit "[analyzer] Fix tagging of 
PostAllocatorCall" ec96c0c072ef3f78813c378949c00e1c07aa44e5 and would introduce 
crashes when cherry-picked onto a branch that doesn't contain that commit.

For more details about the background see the discourse thread 
https://discourse.llvm.org/t/role-of-programpointtag-in-the-static-analyzer/

As a tangentially related changes, this commit also adds some comments to 
document the surprising behavior of `CheckerContext::addTransition` and an 
assertion in the constructor of `PathSensitiveBugReport` to get a more readable 
crash dump in the case when the report is constructed with `nullptr` as the 
`ErrorNode`. (This can happen due to "caching out".)

From 86903216dd7b78de8fb40840121c74e688b1437b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Thu, 29 May 2025 14:00:39 +0200
Subject: [PATCH] [analyzer][NFCI] Remove pointless program point tagging

Previously some checkers attached explicitly created program point tags
to some of the exploded graph nodes that they created. In most of the
checkers this ad-hoc tagging only affected the debug dump of the
exploded graph (and they weren't too relevant for debugging) so this
commit removes them.

There were two checkers where the tagging _did_ have a functional role:
- In `RetainCountChecker` the presence of tags were checked by
  `RefCountReportVisitor`.
- In `DynamicTypePropagation` the checker sometimes wanted to create two
  identical nodes and had to apply an explicit tag on the second one to
  avoid "caching out".
In these two situations I preserved the tags but switched to using
`SimpleProgramPointTag` instead of `CheckerProgramPointTag` because
`CheckerProgramPointTag` didn't provide enough benefits to justify its
existence.

Note that this commit depends on the earlier commit "[analyzer] Fix
tagging of PostAllocatorCall" ec96c0c072ef3f78813c378949c00e1c07aa44e5
and would introduce crashes when cherry-picked onto a branch that
doesn't contain that commit.

For more details about the background see the discourse thread
https://discourse.llvm.org/t/role-of-programpointtag-in-the-static-analyzer/

As a tangentially related changes, this commit also adds some comments
to document the surprising behavior of `CheckerContext::addTransition`
and an assertion in the constructor of `PathSensitiveBugReport` to get a
more readable crash dump in the case when the report is constructed with
`nullptr` as the `ErrorNode`. (This can happen due to "caching out".)
---
 .../clang/StaticAnalyzer/Core/Checker.h   | 14 ---
 .../Core/PathSensitive/CheckerContext.h   |  6 +++
 .../Checkers/CallAndMessageChecker.cpp|  7 ++--
 .../Checkers/DynamicTypePropagation.cpp   | 16 ---
 .../Checkers/GenericTaintChecker.cpp  |  3 +-
 .../Checkers/LocalizationChecker.cpp  |  4 +-
 .../Checkers/MPI-Checker/MPIChecker.cpp   |  6 +--
 .../Checkers/MacOSKeychainAPIChecker.cpp  |  3 +-
 .../StaticAnalyzer/Checkers/MallocChecker.cpp |  3 +-
 .../Checkers/NullabilityChecker.cpp   | 13 +++---
 .../RetainCountChecker/RetainCountChecker.cpp | 42 +++
 .../RetainCountChecker/RetainCountChecker.h   | 19 -
 clang/lib/StaticAnalyzer/Core/BugReporter.cpp |  1 +
 clang/lib/StaticAnalyzer/Core/Checker.cpp |  8 
 14 files changed, 56 insertions(+), 89 deletions(-)

diff --git a/clang/include/clang/StaticAnalyzer/Core/Checker.h 
b/clang/include/clang/StaticAnalyzer/Core/Checker.h
index c6866cb561551..31cc095c29bfe 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Checker.h
+++ b/clang/include/clang/StaticAnalyzer/Core/Checker.h
@@ -608,20 +608,6 @@ class EventDispatcher {
   }
 };
 
-/// Tag that can use a checker name as a message provider
-/// (see SimpleProgramPointTag).
-/// FIXME: This is a cargo cult class which is copied into several checkers but
-/// does not provide anything useful.
-/// The only added functionality provided by this class (compared to
-/// SimpleProgramPointTag) is that it 

[clang] [llvm] [CodeGen][COFF] Always emit CodeView compiler info when hotpatch option is enabled (PR #142970)

2025-06-05 Thread Alexandre Ganea via cfe-commits

aganea wrote:

The other a bit related point to this, is perhaps we should re-evaluate 
enabling `/HOTPATCH` at all times on x64 targets, like MSVC. 

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


[clang] [clang] Fixed Constant Evaluation don't Call Destructor (PR #140278)

2025-06-05 Thread via cfe-commits

Mr-Anyone wrote:

@Sirraide I don't have merge access. Could you please merge? Thanks. 

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


[clang] [CIR] Upstream ShuffleOp for VectorType (PR #142288)

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

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

lgtm

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


[clang] Fix error that reference to PointerType is ambiguous in clang/lib/Analysis/UnsafeBufferUsage.cpp (PR #142966)

2025-06-05 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 cpp -- 
clang/lib/Analysis/UnsafeBufferUsage.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index e874a483a..ecd67c19e 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -968,7 +968,8 @@ static bool hasUnsafePrintfStringArg(const CallExpr &Node, 
ASTContext &Ctx,
   if (!FirstParmTy->isPointerType())
 return false; // possibly some user-defined printf function
 
-  QualType FirstPteTy = 
FirstParmTy->castAs()->getPointeeType();
+  QualType FirstPteTy =
+  FirstParmTy->castAs()->getPointeeType();
 
   if (!Ctx.getFILEType()
.isNull() && //`FILE *` must be in the context if it is fprintf
@@ -1052,7 +1053,8 @@ static bool hasUnsafeSnprintfBuffer(const CallExpr &Node,
   if (!FirstParmTy->isPointerType())
 return false; // Not an snprint
 
-  QualType FirstPteTy = 
FirstParmTy->castAs()->getPointeeType();
+  QualType FirstPteTy =
+  FirstParmTy->castAs()->getPointeeType();
   const Expr *Buf = Node.getArg(0), *Size = Node.getArg(1);
 
   if (FirstPteTy.isConstQualified() || !Buf->getType()->isPointerType() ||

``




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


[clang] [llvm] [CodeGen][COFF] Always emit CodeView compiler info when hotpatch option is enabled (PR #142970)

2025-06-05 Thread Jacek Caban via cfe-commits

cjacek wrote:

I think we could emit this unconditionally, but I wasn’t entirely sure, so I 
went with a less invasive change for now. I'll prepare a new version.

In this version, Clang emits a full debug IR, but if we're going to do this by 
default, it probably makes more sense to emit just a minimal `llvm.dbg.cu` when 
debug info isn’t otherwise enabled. I’ve already experimented with that 
approach.

Also, enabling `/HOTPATCH` by default on x64 is an interesting idea. If we 
decide to go that route, then always emitting the compiler info (without 
conditioning) makes even more sense.

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


[clang] [llvm] [AArch64] Add support for -mlong-calls code generation (PR #142982)

2025-06-05 Thread dong jianqiang via cfe-commits

https://github.com/dongjianqiang2 created 
https://github.com/llvm/llvm-project/pull/142982

This patch implements backend support for -mlong-calls on AArch64 targets. When 
enabled, calls to external functions are lowered to an indirect call via an 
address computed using `adrp` and `add` rather than a direct `bl` instruction, 
which is limited to a ±128MB PC-relative offset.

This is particularly useful when code and/or data exceeds the 26-bit immediate 
range of `bl`, such as in large binaries or link-time-optimized builds.

Key changes:
- In SelectionDAG lowering (`LowerCall`), detect `-mlong-calls` and emit:
- `adrp + add` address calculation
- `blr` indirect call instruction

This patch ensures that long-calls are emitted correctly for both GlobalAddress 
and ExternalSymbol call targets.

Tested:
- New codegen tests under `llvm/test/CodeGen/AArch64/aarch64-long-calls.ll`
- Verified `adrp + add + blr` output in `.s` for global and external functions

>From fcf661d89713e589af497b63366ca37db8aad9f9 Mon Sep 17 00:00:00 2001
From: dong jianqiang 
Date: Thu, 5 Jun 2025 22:46:26 +0800
Subject: [PATCH] [AArch64] Add support for -mlong-calls code generation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch implements backend support for -mlong-calls on AArch64 targets.
When enabled, calls to external functions are lowered to an indirect call via
an address computed using `adrp` and `add` rather than a direct `bl` 
instruction,
which is limited to a ±128MB PC-relative offset.

This is particularly useful when code and/or data exceeds the 26-bit immediate
range of `bl`, such as in large binaries or link-time-optimized builds.

Key changes:
- In SelectionDAG lowering (`LowerCall`), detect `-mlong-calls` and emit:
- `adrp + add` address calculation
- `blr` indirect call instruction

This patch ensures that long-calls are emitted correctly for both GlobalAddress
and ExternalSymbol call targets.

Tested:
- New codegen tests under `llvm/test/CodeGen/AArch64/aarch64-long-calls.ll`
- Verified `adrp + add + blr` output in `.s` for global and external functions
---
 clang/lib/Driver/ToolChains/Arch/AArch64.cpp  |  6 +
 llvm/lib/Target/AArch64/AArch64Features.td|  4 +++
 .../Target/AArch64/AArch64ISelLowering.cpp| 13 +++---
 .../CodeGen/AArch64/aarch64-long-calls.ll | 26 +++
 4 files changed, 46 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/aarch64-long-calls.ll

diff --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index eaae9f876e3ad..2463bcdae2f4f 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -466,6 +466,12 @@ void aarch64::getAArch64TargetFeatures(const Driver &D,
 
   if (Args.getLastArg(options::OPT_mno_bti_at_return_twice))
 Features.push_back("+no-bti-at-return-twice");
+
+  if (Arg *A = Args.getLastArg(options::OPT_mlong_calls,
+   options::OPT_mno_long_calls)) {
+if (A->getOption().matches(options::OPT_mlong_calls))
+  Features.push_back("+long-calls");
+  }
 }
 
 void aarch64::setPAuthABIInTriple(const Driver &D, const ArgList &Args,
diff --git a/llvm/lib/Target/AArch64/AArch64Features.td 
b/llvm/lib/Target/AArch64/AArch64Features.td
index 469c76752c78c..5af6ed5f1ffa2 100644
--- a/llvm/lib/Target/AArch64/AArch64Features.td
+++ b/llvm/lib/Target/AArch64/AArch64Features.td
@@ -825,6 +825,10 @@ def FeatureDisableFastIncVL : 
SubtargetFeature<"disable-fast-inc-vl",
"HasDisableFastIncVL", "true",
"Do not prefer INC/DEC, ALL, { 
1, 2, 4 } over ADDVL">;
 
+def FeatureLongCalls : SubtargetFeature<"long-calls", "GenLongCalls", "true",
+"Generate calls via indirect call "
+"instructions">;
+
 
//===--===//
 // Architectures.
 //
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 9f51caef6d228..d6015ccf94afc 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -9286,8 +9286,12 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
   Callee = DAG.getTargetGlobalAddress(CalledGlobal, DL, PtrVT, 0, OpFlags);
   Callee = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, Callee);
 } else {
-  const GlobalValue *GV = G->getGlobal();
-  Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags);
+  if (Subtarget->genLongCalls())
+Callee = getAddr(G, DAG, OpFlags);
+  else {
+const GlobalValue *GV = G->getGlobal();
+Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags);
+  }
 }
   } else if (auto *S = 

[clang] [llvm] [CodeGen][clang] Use module metadata to mark hotpatchable modules (PR #142969)

2025-06-05 Thread Alexandre Ganea via cfe-commits

https://github.com/aganea commented:

This PR will all depend on the course taken on 
https://github.com/llvm/llvm-project/pull/142970

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


[clang] [llvm] Add -funique-source-file-identifier flag. (PR #142901)

2025-06-05 Thread Teresa Johnson via cfe-commits

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


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


[clang] [llvm] [CodeGen][clang] Use module metadata to mark hotpatchable modules (PR #142969)

2025-06-05 Thread Alexandre Ganea via cfe-commits


@@ -0,0 +1,57 @@
+; RUN: llc -filetype=obj -o - %s | llvm-readobj --codeview - | FileCheck %s
+
+; ModuleID = 'a.c'
+source_filename = "a.c"
+target datalayout = 
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc19.33.0"
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local void @test() #0 !dbg !10 {
+entry:
+  ret void, !dbg !13
+}
+
+attributes #0 = { noinline nounwind optnone uwtable 
"min-legal-vector-width"="0" "no-trapping-math"="true" 
"patchable-function"="prologue-short-redirect" 
"stack-protector-buffer-size"="8" "target-cpu"="x86-64" 
"target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
+!llvm.ident = !{!9}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang 
version 21.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: 
FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "a.c", directory: "/tmp", checksumkind: CSK_MD5, 
checksum: "c59e1f6192de3124537b024248301dd1")
+!2 = !{i32 2, !"CodeView", i32 1}
+!3 = !{i32 2, !"ms-hotpatch", i32 1}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 2}
+!6 = !{i32 8, !"PIC Level", i32 2}
+!7 = !{i32 7, !"uwtable", i32 2}
+!8 = !{i32 1, !"MaxTLSAlign", i32 65536}
+!9 = !{!"clang version 21.0.0git"}
+!10 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, type: 
!11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0)
+!11 = !DISubroutineType(types: !12)
+!12 = !{null}
+!13 = !DILocation(line: 1, scope: !10)
+
+; CHECK:  CodeViewDebugInfo [

aganea wrote:

This part of the test seems to be generated by the other PR, not this one 
specifically.

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


[clang] [llvm] [CodeGen][clang] Use module metadata to mark hotpatchable modules (PR #142969)

2025-06-05 Thread Alexandre Ganea via cfe-commits

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


[clang] 1be7c6f - [Clang] Fix constant eval of assignment operators with an explicit object parameter (#142964)

2025-06-05 Thread via cfe-commits

Author: Corentin Jabot
Date: 2025-06-05T19:30:25+02:00
New Revision: 1be7c6fb4018aac76fc3dbdf997bacc727073f08

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

LOG: [Clang] Fix constant eval of assignment operators with an explicit object 
parameter (#142964)

Fixes #142835

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 512071427b65c..747388fb985aa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -830,6 +830,7 @@ Bug Fixes to C++ Support
 - Clang modules now allow a module and its user to 
diff er on TrivialAutoVarInit*
 - Fixed an access checking bug when initializing non-aggregates in default 
arguments (#GH62444), (#GH83608)
 - Fixed a pack substitution bug in deducing class template partial 
specializations. (#GH53609)
+- Fixed a crash when constant evaluating some explicit object member 
assignment operators. (#GH142835)
 
 Bug Fixes to AST Handling
 ^
@@ -1049,7 +1050,7 @@ Sanitizers
 --
 
 - ``-fsanitize=vptr`` is no longer a part of ``-fsanitize=undefined``.
-- Sanitizer ignorelists now support the syntax ``src:*=sanitize``, 
+- Sanitizer ignorelists now support the syntax ``src:*=sanitize``,
   ``type:*=sanitize``, ``fun:*=sanitize``, ``global:*=sanitize``,
   and ``mainfile:*=sanitize``.
 

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index ab964e592de80..78dd9770f65f6 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6549,8 +6549,8 @@ static bool MaybeHandleUnionActiveMemberChange(EvalInfo 
&Info,
 }
 
 static bool EvaluateCallArg(const ParmVarDecl *PVD, const Expr *Arg,
-CallRef Call, EvalInfo &Info,
-bool NonNull = false) {
+CallRef Call, EvalInfo &Info, bool NonNull = false,
+APValue **EvaluatedArg = nullptr) {
   LValue LV;
   // Create the parameter slot and register its destruction. For a vararg
   // argument, create a temporary.
@@ -6570,13 +6570,17 @@ static bool EvaluateCallArg(const ParmVarDecl *PVD, 
const Expr *Arg,
 return false;
   }
 
+  if (EvaluatedArg)
+*EvaluatedArg = &V;
+
   return true;
 }
 
 /// Evaluate the arguments to a function call.
 static bool EvaluateArgs(ArrayRef Args, CallRef Call,
  EvalInfo &Info, const FunctionDecl *Callee,
- bool RightToLeft = false) {
+ bool RightToLeft = false,
+ LValue *ObjectArg = nullptr) {
   bool Success = true;
   llvm::SmallBitVector ForbiddenNullArgs;
   if (Callee->hasAttr()) {
@@ -6599,13 +6603,16 @@ static bool EvaluateArgs(ArrayRef Args, 
CallRef Call,
 const ParmVarDecl *PVD =
 Idx < Callee->getNumParams() ? Callee->getParamDecl(Idx) : nullptr;
 bool NonNull = !ForbiddenNullArgs.empty() && ForbiddenNullArgs[Idx];
-if (!EvaluateCallArg(PVD, Args[Idx], Call, Info, NonNull)) {
+APValue *That = nullptr;
+if (!EvaluateCallArg(PVD, Args[Idx], Call, Info, NonNull, &That)) {
   // If we're checking for a potential constant expression, evaluate all
   // initializers even if some of them fail.
   if (!Info.noteFailure())
 return false;
   Success = false;
 }
+if (PVD && PVD->isExplicitObjectParameter() && That && That->isLValue())
+  ObjectArg->setFrom(Info.Ctx, *That);
   }
   return Success;
 }
@@ -6633,14 +6640,15 @@ static bool handleTrivialCopy(EvalInfo &Info, const 
ParmVarDecl *Param,
 
 /// Evaluate a function call.
 static bool HandleFunctionCall(SourceLocation CallLoc,
-   const FunctionDecl *Callee, const LValue *This,
-   const Expr *E, ArrayRef Args,
-   CallRef Call, const Stmt *Body, EvalInfo &Info,
+   const FunctionDecl *Callee,
+   const LValue *ObjectArg, const Expr *E,
+   ArrayRef Args, CallRef Call,
+   const Stmt *Body, EvalInfo &Info,
APValue &Result, const LValue *ResultSlot) {
   if (!Info.CheckCallLimit(CallLoc))
 return false;
 
-  CallStackFrame Frame(Info, E->getSourceRange(), Callee, This, E, Call);
+  CallStackFrame Frame(Info, E->getSourceRange(), Callee, ObjectArg, E, Call);
 
   // For a trivial copy or move assignment, perform an APValue copy. This is
   // essential for unions, where the operations performed by the assignment
@@ -6653,16 +6661,20 @@ static b

[clang] [Clang] Fix constant eval of assignment operators with an explicit object parameter (PR #142964)

2025-06-05 Thread Corentin Jabot via cfe-commits

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


[clang] Fix an error introduced in #138518 (PR #142988)

2025-06-05 Thread Corentin Jabot via cfe-commits

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

LGTM, thanks!

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


[clang] [Clang] Fix name lookup of conversion operators (PR #142945)

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

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

>From cdd6868879abf4b6c991c7f2b3e9cf9673b0570a Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Thu, 5 Jun 2025 18:52:01 +0800
Subject: [PATCH 1/2] [Clang] Fix name lookup of conversion operators

(TODO: Add explanation)
---
 clang/include/clang/Parse/Parser.h| 57 ---
 clang/include/clang/Sema/DeclSpec.h   | 23 +---
 clang/include/clang/Sema/Sema.h   |  1 +
 clang/lib/Parse/ParseDecl.cpp | 32 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 10 +++-
 clang/lib/Parse/ParseExpr.cpp |  3 +-
 clang/lib/Parse/ParseExprCXX.cpp  | 42 +-
 clang/lib/Parse/ParseOpenMP.cpp   | 16 +++---
 clang/lib/Parse/ParseStmtAsm.cpp  |  3 +-
 clang/lib/Parse/ParseTemplate.cpp |  1 +
 clang/lib/Parse/Parser.cpp|  9 ++-
 clang/lib/Sema/SemaDecl.cpp   | 20 ---
 clang/lib/Sema/SemaType.cpp   |  4 ++
 .../basic.lookup/basic.lookup.unqual/p5.cpp   | 52 +
 clang/test/CXX/drs/cwg11xx.cpp|  4 +-
 clang/test/CXX/temp/temp.res/p4.cpp   |  2 +-
 clang/unittests/Tooling/TestVisitor.h |  8 +--
 17 files changed, 204 insertions(+), 83 deletions(-)
 create mode 100644 clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p5.cpp

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 98db8201390be..16764b5ba1ad6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -359,7 +359,8 @@ class Parser : public CodeCompletionHandler {
   /// Note that this routine emits an error if you call it with ::new or
   /// ::delete as the current tokens, so only call it in contexts where these
   /// are invalid.
-  bool TryAnnotateCXXScopeToken(bool EnteringContext = false);
+  bool TryAnnotateCXXScopeToken(bool EnteringContext = false,
+ParsedType ObjectType = nullptr);
 
   bool MightBeCXXScopeToken() {
 return getLangOpts().CPlusPlus &&
@@ -1525,8 +1526,10 @@ class Parser : public CodeCompletionHandler {
 DSC_class,  // class context, enables 'friend'
 DSC_type_specifier, // C++ type-specifier-seq or C specifier-qualifier-list
 DSC_trailing, // C++11 trailing-type-specifier in a trailing return type
-DSC_alias_declaration,  // C++11 type-specifier-seq in an alias-declaration
-DSC_conv_operator,  // C++ type-specifier-seq in an conversion operator
+DSC_alias_declaration, // C++11 type-specifier-seq in an alias-declaration
+DSC_conv_operator, // C++ type-specifier-seq in an conversion operator
+DSC_conv_operator_in_postfix_expr, // C++ type-specifier-seq which is
+   // referenced in a postfix expression
 DSC_top_level,  // top-level/namespace declaration context
 DSC_template_param, // template parameter context
 DSC_template_arg,   // template argument context
@@ -1554,6 +1557,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_template_type_arg:
 case DeclSpecContext::DSC_type_specifier:
 case DeclSpecContext::DSC_conv_operator:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_trailing:
 case DeclSpecContext::DSC_alias_declaration:
 case DeclSpecContext::DSC_association:
@@ -1605,6 +1609,7 @@ class Parser : public CodeCompletionHandler {
 
 case DeclSpecContext::DSC_trailing:
 case DeclSpecContext::DSC_conv_operator:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_template_arg:
 case DeclSpecContext::DSC_new:
   return AllowDefiningTypeSpec::No;
@@ -1629,6 +1634,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_trailing:
 case DeclSpecContext::DSC_association:
 case DeclSpecContext::DSC_conv_operator:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_template_arg:
 case DeclSpecContext::DSC_new:
 
@@ -1650,6 +1656,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_type_specifier:
 case DeclSpecContext::DSC_association:
 case DeclSpecContext::DSC_conv_operator:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_new:
   return true;
 
@@ -1673,6 +1680,7 @@ class Parser : public CodeCompletionHandler {
 case DeclSpecContext::DSC_trailing:
 case DeclSpecContext::DSC_alias_declaration:
 case DeclSpecContext::DSC_template_param:
+case DeclSpecContext::DSC_conv_operator_in_postfix_expr:
 case DeclSpecContext::DSC_new:
   return ImplicitTypenameContext::Yes;
 
@@ -1826,9 +1834,11 @@ class Parser : public CodeCompletionHandler {
   ParseDeclarationSpecifiers(DeclSpec

[clang] f7a3a5c - [clang] Add regression tests for narrowing with is_constant_evaluated. (#142885)

2025-06-05 Thread via cfe-commits

Author: Eli Friedman
Date: 2025-06-05T09:45:03-07:00
New Revision: f7a3a5c5dc000baa448f1bc6df65601ad91782dd

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

LOG: [clang] Add regression tests for narrowing with is_constant_evaluated. 
(#142885)

As discussed in #142707, in the context of determining whether a
conversion is a narrowing conversion, is_constant_evaluation should be
false, even it's a subexpression of a manifestly constant-evaluated
expression.

Added: 


Modified: 
clang/test/SemaCXX/builtin-is-constant-evaluated.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/builtin-is-constant-evaluated.cpp 
b/clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
index a1c003c85f732..c775fe71069df 100644
--- a/clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
+++ b/clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
@@ -143,3 +143,14 @@ namespace fold_initializer {
   const float A::f = __builtin_is_constant_evaluated();
   static_assert(fold(A::f == 1.0f));
 }
+
+namespace narrowing {
+  struct X { unsigned u; };
+  constexpr int f(X x) {return x.u;}
+  void g() {
+static_assert(f({0xLL + __builtin_is_constant_evaluated()}) == 0);
+f({0x1LL - __builtin_is_constant_evaluated()}); // expected-error 
{{constant expression evaluates to 4294967296}} \
+// expected-warning {{implicit conversion}} \
+// expected-note {{insert an explicit cast to silence this issue}}
+  }
+}



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


[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

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

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

Thanks, LGTM on the implementation.

I have no objections to the flag itself either.

This is missing a Release note, please add it before merging.

CC @ChuanqiXu9 

Please wait at least a couple of days before merging for other comments and 
opinions.

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


[clang] [clang] Add regression tests for narrowing with is_constant_evaluated. (PR #142885)

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

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


[clang] [clang][python][test] Move python binding tests to lit framework (PR #142948)

2025-06-05 Thread David Blaikie via cfe-commits


@@ -0,0 +1,22 @@
+def is_libclang_loadable():
+try:
+sys.path.append(os.path.join(config.clang_src_dir, "bindings/python"))
+from clang.cindex import Config
+conf = Config()
+Config.set_library_path(config.clang_lib_dir)
+conf.lib
+return True
+except Exception as e:
+# Benign error modes.
+if "wrong ELF class: ELFCLASS32" in str(e):
+return False
+elif "No such file or directory" in str(e):
+return False
+# Unknown error modes.
+else:
+return True

dwblaikie wrote:

This seems backwards - (either the implementation or the comment) if the error 
modes are benign, wouldn't that mean it's OK/libclang /is/ loadable?

(& also in general, I'd have thought we'd look for specific error modes we can 
recover from, and anything else means "no recovery" rather than assuming 
anything other than these bad ones are good?)

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


[clang] [llvm] [HLSL][RootSignature] Metadata generation of StaticSampler (PR #142642)

2025-06-05 Thread Deric C. via cfe-commits

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


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


[libclc] 6306f0f - [libclc] Support LLVM_ENABLE_RUNTIMES when building (#141574)

2025-06-05 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-06-05T17:56:21+01:00
New Revision: 6306f0fa21739d426b5ce394b356a482a4f43e98

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

LOG: [libclc] Support LLVM_ENABLE_RUNTIMES when building (#141574)

This commit deprecates the use of LLVM_ENABLE_PROJECTS in favour of
LLVM_ENABLE_RUNTIMES when building libclc.

Alternatively, using -DLLVM_RUNTIME_TARGETS= combined with
-DRUNTIMES__LLVM_ENABLE_RUNTIMES=libclc also gets pretty far but
fails due to zlib problems building the LLVM utility 'prepare_builtins'.
I'm not sure what's going on there but I don't think it's required at
this stage. More work would be required to support that option.

This does nothing to change how the host tools are found in order to be
used to actually build the libclc libraries.

Note that under such a configuration the final libclc builtin libraries
are placed in `/runtimes/runtimes-bins/libclc/`, which differs
from a non-runtimes build. The installation location remains the same.

Fixes #124013.

Added: 


Modified: 
libclc/CMakeLists.txt
llvm/CMakeLists.txt
llvm/runtimes/CMakeLists.txt
runtimes/CMakeLists.txt

Removed: 




diff  --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 2611818ff902f..c98e2043464d9 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -72,7 +72,7 @@ else()
   # Note that we check this later (for both build types) but we can provide a
   # more useful error message when built in-tree. We assume that LLVM tools are
   # always available so don't warn here.
-  if( NOT clang IN_LIST LLVM_ENABLE_PROJECTS )
+  if( NOT LLVM_RUNTIMES_BUILD AND NOT clang IN_LIST LLVM_ENABLE_PROJECTS )
 message(FATAL_ERROR "Clang is not enabled, but is required to build libclc 
in-tree")
   endif()
 

diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 1440646762f62..206f009b45f59 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -141,7 +141,7 @@ endforeach()
 # As we migrate runtimes to using the bootstrapping build, the set of default 
runtimes
 # should grow as we remove those runtimes from LLVM_ENABLE_PROJECTS above.
 set(LLVM_DEFAULT_RUNTIMES "libcxx;libcxxabi;libunwind")
-set(LLVM_SUPPORTED_RUNTIMES 
"libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload;flang-rt")
+set(LLVM_SUPPORTED_RUNTIMES 
"libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;llvm-libgcc;offload;flang-rt;libclc")
 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
   "Semicolon-separated list of runtimes to build, or \"all\" 
(${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")
 if(LLVM_ENABLE_RUNTIMES STREQUAL "all")
@@ -204,6 +204,13 @@ if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
   endif ()
 endif ()
 
+if ("libclc" IN_LIST LLVM_ENABLE_PROJECTS)
+  message(WARNING "Using LLVM_ENABLE_PROJECTS=libclc is deprecated now, and 
will "
+"become a fatal error in the LLVM 21 release.  Please use "
+"-DLLVM_ENABLE_RUNTIMES=libclc or see the instructions at "
+"https://libclc.llvm.org/ for building the runtimes.")
+endif()
+
 # Set a shorthand option to enable the GPU build of the 'libc' project.
 option(LIBC_GPU_BUILD "Enable the 'libc' project targeting the GPU" OFF)
 if(LIBC_GPU_BUILD)

diff  --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index cabadfc9184f8..9f86650ec58d1 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -193,7 +193,7 @@ endif()
 
 function(_get_runtime_name name out_var)
   string(FIND ${name} "lib" idx)
-  if(idx EQUAL 0 AND NOT ${name} STREQUAL "libc")
+  if(idx EQUAL 0 AND NOT (${name} STREQUAL "libc" OR ${name} STREQUAL 
"libclc"))
 string(SUBSTRING ${name} 3 -1 name)
   endif()
   set(${out_var} ${name} PARENT_SCOPE)

diff  --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index 7f1e2ae065d6c..878b2eee38618 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -35,7 +35,7 @@ list(INSERT CMAKE_MODULE_PATH 0
 
 # We order libraries to mirror roughly how they are layered, except that 
compiler-rt can depend
 # on libc++, so we put it after.
-set(LLVM_DEFAULT_RUNTIMES 
"libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;openmp;offload")
+set(LLVM_DEFAULT_RUNTIMES 
"libc;libunwind;libcxxabi;pstl;libcxx;compiler-rt;libclc;openmp;offload")
 set(LLVM_SUPPORTED_RUNTIMES "${LLVM_DEFAULT_RUNTIMES};llvm-libgcc;flang-rt")
 set(LLVM_ENABLE_RUNTIMES "" CACHE STRING
   "Semicolon-separated list of runtimes to build, or \"all\" 
(${LLVM_DEFAULT_RUNTIMES}). Supported runtimes are ${LLVM_SUPPORTED_RUNTIMES}.")



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


[libclc] [llvm] [libclc] Support LLVM_ENABLE_RUNTIMES when building (PR #141574)

2025-06-05 Thread Fraser Cormack via cfe-commits

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


[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

2025-06-05 Thread via cfe-commits

MaggieYingYi wrote:

Thanks @mizvekov. I am away until next Monday. I will add a release note next 
Monday. Many thanks again

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


[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)

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


@@ -3167,3 +3167,30 @@ void tools::handleInterchangeLoopsArgs(const ArgList 
&Args,
options::OPT_fno_loop_interchange, EnableInterchange))
 CmdArgs.push_back("-floop-interchange");
 }
+
+void tools::ParseMPreferVectorWidthOption(clang::DiagnosticsEngine &Diags,
+  const llvm::opt::ArgList &Args,
+  ArgStringList &CmdArgs,
+  bool isCompilerDriver) {
+  // If this was invoked by the Compiler Driver, we pass through the option
+  // as-is. Otherwise, if this is the Frontend Driver, we want just the value.
+  StringRef Out = (isCompilerDriver) ? "-mprefer-vector-width=" : "";
+
+  Arg *A = 
Args.getLastArg(clang::driver::options::OPT_mprefer_vector_width_EQ);
+  if (!A)
+return;
+
+  StringRef Value = A->getValue();
+  unsigned Width;
+
+  // Only "none" and Integer values are accepted by
+  // -mprefer-vector-width=.
+  if (Value != "none" && Value.getAsInteger(10, Width)) {
+Diags.Report(clang::diag::err_drv_invalid_value)
+<< A->getOption().getName() << Value;
+return;
+  }
+
+  CmdArgs.push_back(Args.MakeArgString(Out + Value));

mcinally wrote:

Actually, I take that back. This solution is pretty slick. Sharing an update 
now...

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


[clang] [C23][N3006] Documented behavior of underspecified object declarations (PR #140911)

2025-06-05 Thread Guillot Tony via cfe-commits

https://github.com/to268 updated 
https://github.com/llvm/llvm-project/pull/140911

>From 11832e8337e6785f887a8fafad7af558ff701f71 Mon Sep 17 00:00:00 2001
From: Guillot Tony 
Date: Wed, 21 May 2025 16:58:31 +0200
Subject: [PATCH 1/4] Documented N3006 feature

---
 clang/docs/LanguageExtensions.rst |  48 +
 clang/docs/ReleaseNotes.rst   |   4 +-
 clang/test/C/C23/n3006.c  | 113 ++
 clang/www/c_status.html   |   2 +-
 4 files changed, 165 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/C/C23/n3006.c

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 73544826809c3..6f7138fe595ae 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -6501,3 +6501,51 @@ qualifications.
 Note, Clang does not allow an ``_Atomic`` function type because
 of explicit constraints against atomically qualified (arrays and) function
 types.
+
+
+Underspecified object declarations in C
+===
+
+In C23 (N3006), when an object is declared inside of another object and that
+only exists in the scope of the declaration of the outer object. Clang allows
+underspecified object declarations for structs, unions and enums when valid.
+
+.. code-block:: c
+
+  auto s1 = (struct S1 { int x, y; }){ 1, 2 };
+  auto u1 = (union U1 { int a; double b; }){ .a = 34 };
+  auto e1 = (enum E1 { FOO, BAR }){ BAR };
+
+Note, The ``constexpr`` keyword and getting a struct member that is
+underspecified is also allowed.
+
+.. code-block:: c
+
+  constexpr auto cs1 = (struct S1 { int x, y; }){ 1, 2 };
+  constexpr auto cu1 = (union U1 { int a; double b; }){ .a = 34 };
+  constexpr auto ce1 = (enum E1 { FOO, BAR }){ BAR };
+  int i1 = (struct T { int a, b; }){0, 1}.a;
+  constexpr int ci2 = (struct T2 { int a, b; }){0, 1}.a;
+
+Moreover, some unusual cases are also allowed as described bellow.
+
+.. code-block:: c
+
+  constexpr struct S { int a, b; } y = { 0 };
+  constexpr typeof(struct s *) x = 0;
+  auto so = sizeof(struct S {});
+  auto s = ({struct T { int x; } s = {}; s.x; });
+  constexpr int (*fp)(struct X { int x; } val) = 0;
+  auto v = (void (*)(int y))0;
+
+  constexpr struct {
+  int a;
+  } si = {};
+
+  auto z = ({
+  int a = 12;
+  struct {} s;
+  a;
+  });
+
+All other cases are prohibited by Clang.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 512071427b65c..f88fd13ce8254 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -287,6 +287,8 @@ C23 Feature Support
   directive. Fixes #GH126940.
 - Fixed a crash when a declaration of a ``constexpr`` variable with an invalid
   type. Fixes #GH140887
+- Documented `WG14 N3006 
`_
+  which clarified how Clang is handling underspecified object declarations.
 
 C11 Feature Support
 ^^^
@@ -1049,7 +1051,7 @@ Sanitizers
 --
 
 - ``-fsanitize=vptr`` is no longer a part of ``-fsanitize=undefined``.
-- Sanitizer ignorelists now support the syntax ``src:*=sanitize``, 
+- Sanitizer ignorelists now support the syntax ``src:*=sanitize``,
   ``type:*=sanitize``, ``fun:*=sanitize``, ``global:*=sanitize``,
   and ``mainfile:*=sanitize``.
 
diff --git a/clang/test/C/C23/n3006.c b/clang/test/C/C23/n3006.c
new file mode 100644
index 0..033e0b407e7f5
--- /dev/null
+++ b/clang/test/C/C23/n3006.c
@@ -0,0 +1,113 @@
+// RUN: %clang_cc1 -std=c23 -verify %s
+
+/* WG14 N3006: Yes
+ * Underspecified object declarations
+ */
+
+void struct_test(void) {
+  struct S1 { int x, y; };  // 
expected-note {{field 'x' has type 'int' here}}
+
+  auto normal_struct = (struct S1){ 1, 2 };
+  auto normal_struct2 = (struct S1) { .x = 1, .y = 2 };
+  auto underspecified_struct = (struct S2 { int x, y; }){ 1, 2 };
+  auto underspecified_struct_redef = (struct S1 { char x, y; }){ 'A', 'B'}; // 
expected-error {{type 'struct S1' has incompatible definitions}} \
+   
expected-error {{cannot use 'auto' with array in C}} \
+   
expected-note {{field 'x' has type 'char' here}}
+  auto underspecified_empty_struct = (struct S3 { }){ };
+  auto zero_init_struct = (struct S4 { int x; }){ 0 };
+  int field_struct = (struct S5 { int y; }){ 0 }.y;
+}
+
+void union_test(void) {
+  union U1 { int a; double b; };   
   // expected-note {{field 'a' has type 'int' here}}
+
+  auto normal_union_int = (union U1){ .a = 12 };
+  auto normal_union_double = (union U1){ .b = 2.4 };
+  auto underspecified_union = (union U2 { int a; double b; }){ .a = 34 };
+  auto underspecified_union_redef = (union U1 { char a; double b; }){ .a = 'A' 
}; // expected-error {{type 'union U1' has incomp

[clang] [Clang] Implement CWG2496 (PR #142975)

2025-06-05 Thread Corentin Jabot via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/142975

>From d4294fbb02932ec8b1870ac2960856bbbf299eb5 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 5 Jun 2025 16:15:33 +0200
Subject: [PATCH 1/2] [Clang] Implement CWG2496

https://cplusplus.github.io/CWG/issues/2496.html

We failed to diagnose the following in C++23 mode

```
struct S {
virtual void f(); // expected-note {{previous declaration is here}}
};

struct T : S {
virtual void f() &;
};
```
---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/SemaOverload.cpp |  2 +-
 clang/test/CXX/drs/cwg24xx.cpp  | 20 
 clang/www/cxx_dr_status.html|  2 +-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 512071427b65c..d1ee6de66b4ee 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -155,6 +155,8 @@ Resolutions to C++ Defect Reports
 
 - Implemented `CWG3005 Function parameters should never be name-independent 
`_.
 
+- Implemented `CWG2496 ref-qualifiers and virtual overriding 
`_.
+
 C Language Changes
 --
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 66f84fc67b52f..5a19dacdc4d84 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1490,7 +1490,7 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   auto DiagnoseInconsistentRefQualifiers = [&]() {
-if (SemaRef.LangOpts.CPlusPlus23)
+if (SemaRef.LangOpts.CPlusPlus23 && !UseOverrideRules)
   return false;
 if (OldMethod->getRefQualifier() == NewMethod->getRefQualifier())
   return false;
diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 9c9a3f14b9e8b..05b9a74e292ab 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -215,3 +215,23 @@ void (*q)() throw() = S();
 // since-cxx17-error@-1 {{no viable conversion from 'S' to 'void (*)() 
throw()'}}
 //   since-cxx17-note@#cwg2486-conv {{candidate function}}
 } // namespace cwg2486
+
+
+namespace cwg2496 { // cwg2496: 21
+#if __cplusplus >= 201102L
+struct S {
+virtual void f(); // expected-note {{previous declaration is here}}
+virtual void g() &; // expected-note {{previous declaration is here}}
+virtual void h(); // expected-note {{previous declaration is here}}
+};
+
+struct T : S {
+virtual void f() &;
+// expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&' with a member function without a ref-qualifier}}
+virtual void g();
+// expected-error@-1 {{cannot overload a member function without a 
ref-qualifier with a member function with ref-qualifier '&'}}
+virtual void h() &&;
+// expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&&' with a member function without a ref-qualifier}}
+};
+#endif
+}
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 58286db165077..fe9b571b47261 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -14811,7 +14811,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2496.html";>2496
 CD6
 ref-qualifiers and virtual overriding
-Unknown
+Clang 21
   
   
 https://cplusplus.github.io/CWG/issues/2497.html";>2497

>From 1f2f57051b5f1d8934e5726e16c99ae6b287d8cf Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 5 Jun 2025 19:41:54 +0200
Subject: [PATCH 2/2] more tests

---
 clang/test/CXX/drs/cwg24xx.cpp | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 05b9a74e292ab..a1821e71ff06a 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -220,18 +220,23 @@ void (*q)() throw() = S();
 namespace cwg2496 { // cwg2496: 21
 #if __cplusplus >= 201102L
 struct S {
-virtual void f(); // expected-note {{previous declaration is here}}
-virtual void g() &; // expected-note {{previous declaration is here}}
-virtual void h(); // expected-note {{previous declaration is here}}
+virtual void f(); // #cwg2496-f
+virtual void g() &; // #cwg2496-g
+virtual void h(); // #cwg2496-h
+virtual void i(); // #cwg2496-i
 };
 
 struct T : S {
 virtual void f() &;
 // expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&' with a member function without a ref-qualifier}}
+// expected-note@#cwg2496-f {{previous declaration is here}}
 virtual void g();
 // expected-error@-1 {{cannot overload a member function without a 
ref-qualifier with a member function with ref-qualifier '&'}}
+// expected-n

[clang] [flang] [Driver] Move CommonArgs to a location visible by the Frontend Drivers (PR #142800)

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

https://github.com/mcinally updated 
https://github.com/llvm/llvm-project/pull/142800

>From 918b853de8c43dacebecb42cafa6d3b8fec15b47 Mon Sep 17 00:00:00 2001
From: Cameron McInally 
Date: Tue, 3 Jun 2025 11:12:42 -0700
Subject: [PATCH 1/3] [Driver] Move CommonArgs to a location visible by the
 Frontend Drivers

This patch moves the CommonArgs utilities into a location visible by the
Frontend Drivers, so that the Frontend Drivers may share option parsing code
with the Compiler Driver. This is useful when the Frontend Drivers would like
to verify that their incoming options are well-formed and also not reinvent the
option parsing wheel.

We already see code in the Clang/Flang Drivers that is parsing and verifying its
incoming options. E.g. OPT_ffp_contract. This option is parsed in the Compiler
Driver, Clang Driver, and Flang Driver, all with slightly different parsing
code. It would be nice if the Frontend Drivers were not required to duplicate
this Compiler Driver code. That way there is no maintenace burden on keeping all
these parsing functions in sync.

Along those lines, the Frontend Drivers will now have a useful mechanism to
verify their incoming options are well-formed. Currently, the Frontend Drivers
trust that the Compiler Driver is not passing back junk. In some cases, the
Language Drivers will accept junk with no error at all. E.g.:

  `clang -cc1 -mprefer-vector-width=junk test.c'

With this patch, we'll now be able to tighten up incomming options to the
Frontend drivers in a lightweight way.
---
 .../clang/Driver}/CommonArgs.h|  6 
 clang/lib/Driver/MultilibBuilder.cpp  |  2 +-
 clang/lib/Driver/ToolChain.cpp|  2 +-
 clang/lib/Driver/ToolChains/AIX.cpp   |  2 +-
 clang/lib/Driver/ToolChains/AMDGPU.cpp|  2 +-
 clang/lib/Driver/ToolChains/AVR.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Arch/AArch64.cpp  |  2 +-
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Arch/Mips.cpp |  2 +-
 clang/lib/Driver/ToolChains/Arch/PPC.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp|  2 +-
 clang/lib/Driver/ToolChains/BareMetal.cpp |  2 +-
 clang/lib/Driver/ToolChains/CSKYToolChain.cpp |  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp | 26 ++---
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 29 ++-
 clang/lib/Driver/ToolChains/CrossWindows.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Cuda.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Cygwin.cpp|  2 +-
 clang/lib/Driver/ToolChains/Darwin.cpp|  2 +-
 clang/lib/Driver/ToolChains/DragonFly.cpp |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  2 +-
 clang/lib/Driver/ToolChains/FreeBSD.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Fuchsia.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Gnu.cpp   |  2 +-
 clang/lib/Driver/ToolChains/HIPAMD.cpp|  2 +-
 clang/lib/Driver/ToolChains/HIPSPV.cpp|  2 +-
 clang/lib/Driver/ToolChains/HIPUtility.cpp|  2 +-
 clang/lib/Driver/ToolChains/HLSL.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Haiku.cpp |  2 +-
 clang/lib/Driver/ToolChains/Hexagon.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Hurd.cpp  |  2 +-
 .../lib/Driver/ToolChains/InterfaceStubs.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Linux.cpp |  2 +-
 clang/lib/Driver/ToolChains/MSP430.cpp|  2 +-
 clang/lib/Driver/ToolChains/MSVC.cpp  |  2 +-
 clang/lib/Driver/ToolChains/MinGW.cpp |  2 +-
 clang/lib/Driver/ToolChains/NaCl.cpp  |  2 +-
 clang/lib/Driver/ToolChains/NetBSD.cpp|  2 +-
 clang/lib/Driver/ToolChains/OHOS.cpp  |  2 +-
 clang/lib/Driver/ToolChains/OpenBSD.cpp   |  2 +-
 clang/lib/Driver/ToolChains/PS4CPU.cpp|  2 +-
 .../lib/Driver/ToolChains/RISCVToolchain.cpp  |  2 +-
 clang/lib/Driver/ToolChains/SPIRV.cpp |  2 +-
 clang/lib/Driver/ToolChains/SPIRVOpenMP.cpp   |  2 +-
 clang/lib/Driver/ToolChains/SYCL.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Solaris.cpp   |  2 +-
 clang/lib/Driver/ToolChains/UEFI.cpp  |  2 +-
 clang/lib/Driver/ToolChains/VEToolchain.cpp   |  2 +-
 clang/lib/Driver/ToolChains/WebAssembly.cpp   |  2 +-
 clang/lib/Driver/ToolChains/XCore.cpp |  2 +-
 clang/lib/Driver/ToolChains/ZOS.cpp   |  2 +-
 clang/lib/Driver/XRayArgs.cpp |  2 +-
 .../unittests/Driver/MultilibBuilderTest.cpp  |  2 +-
 clang/unittests/Driver/MultilibTest.cpp   |  2 +-
 flang/lib/Frontend/CompilerInvocation.cpp | 20 +
 flang/test/Driver/prefer-vector-width.f90 |  2 +-
 56 files changed, 96 insertions(+), 89 deletions(-)
 rename clang/{lib/Driver/ToolChains => include/clang/Driver}/CommonArgs.h (98%)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/include/clang/Driver/CommonArgs.h
similarity index 98%
rename from clang/lib/Driver/ToolChains/CommonArgs.h
rename to clang/include/clang/Dr

[clang] [Clang] Implement CWG2496 (PR #142975)

2025-06-05 Thread Corentin Jabot via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/142975

>From d4294fbb02932ec8b1870ac2960856bbbf299eb5 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 5 Jun 2025 16:15:33 +0200
Subject: [PATCH 1/3] [Clang] Implement CWG2496

https://cplusplus.github.io/CWG/issues/2496.html

We failed to diagnose the following in C++23 mode

```
struct S {
virtual void f(); // expected-note {{previous declaration is here}}
};

struct T : S {
virtual void f() &;
};
```
---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/Sema/SemaOverload.cpp |  2 +-
 clang/test/CXX/drs/cwg24xx.cpp  | 20 
 clang/www/cxx_dr_status.html|  2 +-
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 512071427b65c..d1ee6de66b4ee 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -155,6 +155,8 @@ Resolutions to C++ Defect Reports
 
 - Implemented `CWG3005 Function parameters should never be name-independent 
`_.
 
+- Implemented `CWG2496 ref-qualifiers and virtual overriding 
`_.
+
 C Language Changes
 --
 
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 66f84fc67b52f..5a19dacdc4d84 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1490,7 +1490,7 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   auto DiagnoseInconsistentRefQualifiers = [&]() {
-if (SemaRef.LangOpts.CPlusPlus23)
+if (SemaRef.LangOpts.CPlusPlus23 && !UseOverrideRules)
   return false;
 if (OldMethod->getRefQualifier() == NewMethod->getRefQualifier())
   return false;
diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 9c9a3f14b9e8b..05b9a74e292ab 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -215,3 +215,23 @@ void (*q)() throw() = S();
 // since-cxx17-error@-1 {{no viable conversion from 'S' to 'void (*)() 
throw()'}}
 //   since-cxx17-note@#cwg2486-conv {{candidate function}}
 } // namespace cwg2486
+
+
+namespace cwg2496 { // cwg2496: 21
+#if __cplusplus >= 201102L
+struct S {
+virtual void f(); // expected-note {{previous declaration is here}}
+virtual void g() &; // expected-note {{previous declaration is here}}
+virtual void h(); // expected-note {{previous declaration is here}}
+};
+
+struct T : S {
+virtual void f() &;
+// expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&' with a member function without a ref-qualifier}}
+virtual void g();
+// expected-error@-1 {{cannot overload a member function without a 
ref-qualifier with a member function with ref-qualifier '&'}}
+virtual void h() &&;
+// expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&&' with a member function without a ref-qualifier}}
+};
+#endif
+}
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 58286db165077..fe9b571b47261 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -14811,7 +14811,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2496.html";>2496
 CD6
 ref-qualifiers and virtual overriding
-Unknown
+Clang 21
   
   
 https://cplusplus.github.io/CWG/issues/2497.html";>2497

>From 1f2f57051b5f1d8934e5726e16c99ae6b287d8cf Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 5 Jun 2025 19:41:54 +0200
Subject: [PATCH 2/3] more tests

---
 clang/test/CXX/drs/cwg24xx.cpp | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/clang/test/CXX/drs/cwg24xx.cpp b/clang/test/CXX/drs/cwg24xx.cpp
index 05b9a74e292ab..a1821e71ff06a 100644
--- a/clang/test/CXX/drs/cwg24xx.cpp
+++ b/clang/test/CXX/drs/cwg24xx.cpp
@@ -220,18 +220,23 @@ void (*q)() throw() = S();
 namespace cwg2496 { // cwg2496: 21
 #if __cplusplus >= 201102L
 struct S {
-virtual void f(); // expected-note {{previous declaration is here}}
-virtual void g() &; // expected-note {{previous declaration is here}}
-virtual void h(); // expected-note {{previous declaration is here}}
+virtual void f(); // #cwg2496-f
+virtual void g() &; // #cwg2496-g
+virtual void h(); // #cwg2496-h
+virtual void i(); // #cwg2496-i
 };
 
 struct T : S {
 virtual void f() &;
 // expected-error@-1 {{cannot overload a member function with 
ref-qualifier '&' with a member function without a ref-qualifier}}
+// expected-note@#cwg2496-f {{previous declaration is here}}
 virtual void g();
 // expected-error@-1 {{cannot overload a member function without a 
ref-qualifier with a member function with ref-qualifier '&'}}
+// expected-n

[clang] d1b0b4b - Add -funique-source-file-identifier option.

2025-06-05 Thread via cfe-commits

Author: Peter Collingbourne
Date: 2025-06-05T10:52:01-07:00
New Revision: d1b0b4bb4405c144e23be3d5c0459b03f95bd5ac

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

LOG: Add -funique-source-file-identifier option.

This option complements -funique-source-file-names and allows the user
to use a different unique identifier than the source file path.

Reviewers: teresajohnson

Reviewed By: teresajohnson

Pull Request: https://github.com/llvm/llvm-project/pull/142901

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/unique-source-file-names.c
clang/test/Driver/unique-source-file-names.c
llvm/lib/Transforms/Utils/ModuleUtils.cpp
llvm/test/Transforms/ThinLTOBitcodeWriter/unique-source-file-names.ll

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 8c72f95b94095..62844f7e6a2fa 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2300,12 +2300,14 @@ are listed below.
 .. option:: -f[no-]unique-source-file-names
 
When enabled, allows the compiler to assume that each object file
-   passed to the linker has been compiled using a unique source file
-   path. This is useful for reducing link times when doing ThinLTO
-   in combination with whole-program devirtualization or CFI.
+   passed to the linker has a unique identifier. The identifier for
+   an object file is either the source file path or the value of the
+   argument `-funique-source-file-identifier` if specified. This is
+   useful for reducing link times when doing ThinLTO in combination with
+   whole-program devirtualization or CFI.
 
-   The full source path passed to the compiler must be unique. This
-   means that, for example, the following is a usage error:
+   The full source path or identifier passed to the compiler must be
+   unique. This means that, for example, the following is a usage error:
 
.. code-block:: console
 
@@ -2327,6 +2329,11 @@ are listed below.
A misuse of this flag may result in a duplicate symbol error at
link time.
 
+.. option:: -funique-source-file-identifier=IDENTIFIER
+
+   Used with `-funique-source-file-names` to specify a source file
+   identifier.
+
 .. option:: -fforce-emit-vtables
 
In order to improve devirtualization, forces emitting of vtables even in

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index aad4e107cbeb3..fa9474d63ae42 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -278,8 +278,6 @@ CODEGENOPT(SanitizeCfiICallNormalizeIntegers, 1, 0) ///< 
Normalize integer types
 ///< CFI icall function 
signatures
 CODEGENOPT(SanitizeCfiCanonicalJumpTables, 1, 0) ///< Make jump table symbols 
canonical
  ///< instead of creating a 
local jump table.
-CODEGENOPT(UniqueSourceFileNames, 1, 0) ///< Allow the compiler to assume that 
TUs
-///< have unique source file names at 
link time
 CODEGENOPT(SanitizeKcfiArity, 1, 0) ///< Embed arity in KCFI patchable 
function prefix
 CODEGENOPT(SanitizeCoverageType, 2, 0) ///< Type of sanitizer coverage
///< instrumentation.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 278803f7bb960..a77232c281f7f 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -338,6 +338,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
   std::string SymbolPartition;
 
+  /// If non-empty, allow the compiler to assume that the given source file
+  /// identifier is unique at link time.
+  std::string UniqueSourceFileIdentifier;
+
   enum RemarkKind {
 RK_Missing,// Remark argument not present on the command line.
 RK_Enabled,// Remark enabled via '-Rgroup'.

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5ca31c253ed8f..fd6deb22d404e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4204,13 +4204,15 @@ def ftrigraphs : Flag<["-"], "ftrigraphs">, 
Group,
 def fno_trigraphs : Flag<["-"], "fno-trigraphs">, Group,
   HelpText<"Do not process trigraph sequences">,
   Visibility<[ClangOption, CC1Option]>;
-defm unique_source

[clang] [llvm] Add -funique-source-file-identifier option. (PR #142901)

2025-06-05 Thread Peter Collingbourne via cfe-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/142901

>From 74acb06bb339909bc2950cecb95eb61df49c0379 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Wed, 4 Jun 2025 22:37:09 -0700
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6-beta.1
---
 clang/docs/UsersManual.rst  | 17 -
 clang/include/clang/Basic/CodeGenOptions.def|  2 --
 clang/include/clang/Basic/CodeGenOptions.h  |  4 
 clang/include/clang/Driver/Options.td   | 16 +---
 clang/lib/CodeGen/CodeGenModule.cpp |  9 +++--
 clang/lib/Driver/ToolChains/Clang.cpp   | 10 --
 clang/test/CodeGen/unique-source-file-names.c   |  5 +++--
 clang/test/Driver/unique-source-file-names.c| 12 +---
 llvm/lib/Transforms/Utils/ModuleUtils.cpp   | 10 ++
 .../unique-source-file-names.ll |  3 ++-
 10 files changed, 60 insertions(+), 28 deletions(-)

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 8c72f95b94095..62844f7e6a2fa 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2300,12 +2300,14 @@ are listed below.
 .. option:: -f[no-]unique-source-file-names
 
When enabled, allows the compiler to assume that each object file
-   passed to the linker has been compiled using a unique source file
-   path. This is useful for reducing link times when doing ThinLTO
-   in combination with whole-program devirtualization or CFI.
+   passed to the linker has a unique identifier. The identifier for
+   an object file is either the source file path or the value of the
+   argument `-funique-source-file-identifier` if specified. This is
+   useful for reducing link times when doing ThinLTO in combination with
+   whole-program devirtualization or CFI.
 
-   The full source path passed to the compiler must be unique. This
-   means that, for example, the following is a usage error:
+   The full source path or identifier passed to the compiler must be
+   unique. This means that, for example, the following is a usage error:
 
.. code-block:: console
 
@@ -2327,6 +2329,11 @@ are listed below.
A misuse of this flag may result in a duplicate symbol error at
link time.
 
+.. option:: -funique-source-file-identifier=IDENTIFIER
+
+   Used with `-funique-source-file-names` to specify a source file
+   identifier.
+
 .. option:: -fforce-emit-vtables
 
In order to improve devirtualization, forces emitting of vtables even in
diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index aad4e107cbeb3..fa9474d63ae42 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -278,8 +278,6 @@ CODEGENOPT(SanitizeCfiICallNormalizeIntegers, 1, 0) ///< 
Normalize integer types
 ///< CFI icall function 
signatures
 CODEGENOPT(SanitizeCfiCanonicalJumpTables, 1, 0) ///< Make jump table symbols 
canonical
  ///< instead of creating a 
local jump table.
-CODEGENOPT(UniqueSourceFileNames, 1, 0) ///< Allow the compiler to assume that 
TUs
-///< have unique source file names at 
link time
 CODEGENOPT(SanitizeKcfiArity, 1, 0) ///< Embed arity in KCFI patchable 
function prefix
 CODEGENOPT(SanitizeCoverageType, 2, 0) ///< Type of sanitizer coverage
///< instrumentation.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 278803f7bb960..f6a6a7fcfa6d7 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -338,6 +338,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
   std::string SymbolPartition;
 
+  /// If non-empty, allow the compiler to assume that the given source file
+  /// identifier is unique at link time.
+  std::string UniqueSourceFileIdentifier;
+  
   enum RemarkKind {
 RK_Missing,// Remark argument not present on the command line.
 RK_Enabled,// Remark enabled via '-Rgroup'.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5ca31c253ed8f..f04e214066ccb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4204,13 +4204,15 @@ def ftrigraphs : Flag<["-"], "ftrigraphs">, 
Group,
 def fno_trigraphs : Flag<["-"], "fno-trigraphs">, Group,
   HelpText<"Do not process trigraph sequences">,
   Visibility<[ClangOption, CC1Option]>;
-defm unique_source_file_names: BoolOption<"f", "unique-source-file-names",
-  CodeGen

[clang] [llvm] Add -funique-source-file-identifier option. (PR #142901)

2025-06-05 Thread Peter Collingbourne via cfe-commits

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


[clang] [llvm] Add -funique-source-file-identifier option. (PR #142901)

2025-06-05 Thread Peter Collingbourne via cfe-commits


@@ -4204,13 +4204,15 @@ def ftrigraphs : Flag<["-"], "ftrigraphs">, 
Group,
 def fno_trigraphs : Flag<["-"], "fno-trigraphs">, Group,
   HelpText<"Do not process trigraph sequences">,
   Visibility<[ClangOption, CC1Option]>;
-defm unique_source_file_names: BoolOption<"f", "unique-source-file-names",
-  CodeGenOpts<"UniqueSourceFileNames">, DefaultFalse,
-  PosFlag,
-  NegFlag,
-  BothFlags<[], [ClangOption], " the compiler to assume that each translation 
unit has a unique "
-   "source file name at link time">>,
-  Group;
+def funique_source_file_names: Flag<["-"], "funique-source-file-names">, 
Group,
+  HelpText<"Allow the compiler to assume that each translation unit has a 
unique "   
+   "source file identifier (see funique-source-file-identifier) at 
link time">;

pcc wrote:

Done

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


[clang] [llvm] Add -funique-source-file-identifier option. (PR #142901)

2025-06-05 Thread Peter Collingbourne via cfe-commits

https://github.com/pcc closed https://github.com/llvm/llvm-project/pull/142901
___
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-05 Thread Erick Velez via cfe-commits

evelez7 wrote:

> This sounds promising. I'm fine w/ adding a field to track this. BTW, what 
> does clang do? I'm wondering if we should track more than 1-bit of info here.

As far as I can tell, inside the AST Clang makes use of the `isa<>` mechanisms 
(which we could also leverage) or pointer unions like 
https://github.com/llvm/llvm-project/blob/f427d3aa9d43b37e6318677f96262aab73545d57/clang/include/clang/AST/DeclCXX.h#L486-L487

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] [clang] Remove separate evaluation step for static class member init. (PR #142713)

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

https://github.com/shafik commented:

So just to confirm my reading, this is benefiting from 
`CheckCompleteVariableDeclaration` doing:

```cpp
  // Evaluate the initializer to see if it's a constant initializer.
  HasConstInit = var->checkForConstantInitialization(Notes);
```

or is there more?

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


[clang] [CIR] Implement folder for VecTernaryOp (PR #142946)

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


@@ -1638,6 +1638,41 @@ LogicalResult cir::VecTernaryOp::verify() {
   return success();
 }
 
+OpFoldResult cir::VecTernaryOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute cond = adaptor.getCond();
+  mlir::Attribute lhs = adaptor.getLhs();
+  mlir::Attribute rhs = adaptor.getRhs();
+
+  if (mlir::isa_and_nonnull(cond) &&
+  mlir::isa_and_nonnull(lhs) &&
+  mlir::isa_and_nonnull(rhs)) {
+auto condVec = mlir::cast(cond);
+auto lhsVec = mlir::cast(lhs);
+auto rhsVec = mlir::cast(rhs);
+
+mlir::ArrayAttr condElts = condVec.getElts();
+
+SmallVector elements;
+elements.reserve(condElts.size());
+
+for (const auto &[idx, condAttr] :
+ llvm::enumerate(condElts.getAsRange())) {
+  if (condAttr.getSInt()) {
+elements.push_back(lhsVec.getElts()[idx]);
+continue;

andykaylor wrote:

I think this would be more natural as an `if-else` rather than using `continue`.

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


[clang] [CIR] Implement folder for VecTernaryOp (PR #142946)

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

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

This looks good. I just have a few minor suggestions.

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


[clang] [CIR] Implement folder for VecTernaryOp (PR #142946)

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

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

https://github.com/sivadeilra updated 
https://github.com/llvm/llvm-project/pull/138972

>From b12e2fbcb33b685db216a8ff063409c8595ee723 Mon Sep 17 00:00:00 2001
From: Arlie Davis 
Date: Thu, 3 Apr 2025 16:10:50 -0700
Subject: [PATCH] Windows hotpatching support

---
 clang/include/clang/Basic/CodeGenOptions.h|   7 +
 clang/include/clang/Driver/Options.td |  18 ++
 clang/lib/CodeGen/CGCall.cpp  |   7 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  29 ++
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/lib/Driver/ToolChains/Clang.cpp |   8 +
 .../CodeGen/ms-secure-hotpatch-bad-file.c |  16 +
 clang/test/CodeGen/ms-secure-hotpatch-cpp.cpp |  22 ++
 clang/test/CodeGen/ms-secure-hotpatch-lto.c   |  18 ++
 clang/test/CodeGen/ms-secure-hotpatch.c   |  21 ++
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |   2 +
 llvm/include/llvm/CodeGen/Passes.h|   3 +
 .../DebugInfo/CodeView/CodeViewSymbols.def|   2 +
 .../llvm/DebugInfo/CodeView/SymbolRecord.h|  15 +
 llvm/include/llvm/IR/Attributes.td|  11 +
 llvm/include/llvm/InitializePasses.h  |   1 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |   4 +
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |   4 +
 llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp |  24 ++
 llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h   |   2 +
 llvm/lib/CodeGen/CMakeLists.txt   |   1 +
 llvm/lib/CodeGen/TargetPassConfig.cpp |   3 +
 llvm/lib/CodeGen/WindowsSecureHotPatching.cpp | 287 ++
 llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp  |   7 +
 .../CodeView/SymbolRecordMapping.cpp  |   7 +
 llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp   |   5 +
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |   2 +
 .../Generic/ms-secure-hotpatch-attr.ll|  38 +++
 .../Generic/ms-secure-hotpatch-bad-file.ll|  16 +
 ...ms-secure-hotpatch-direct-global-access.ll |  39 +++
 .../ms-secure-hotpatch-functions-file.ll  |  39 +++
 .../ms-secure-hotpatch-functions-list.ll  |  38 +++
 .../llvm-pdbutil/MinimalSymbolDumper.cpp  |   8 +
 33 files changed, 709 insertions(+)
 create mode 100644 clang/test/CodeGen/ms-secure-hotpatch-bad-file.c
 create mode 100644 clang/test/CodeGen/ms-secure-hotpatch-cpp.cpp
 create mode 100644 clang/test/CodeGen/ms-secure-hotpatch-lto.c
 create mode 100644 clang/test/CodeGen/ms-secure-hotpatch.c
 create mode 100644 llvm/lib/CodeGen/WindowsSecureHotPatching.cpp
 create mode 100644 llvm/test/CodeGen/Generic/ms-secure-hotpatch-attr.ll
 create mode 100644 llvm/test/CodeGen/Generic/ms-secure-hotpatch-bad-file.ll
 create mode 100644 
llvm/test/CodeGen/Generic/ms-secure-hotpatch-direct-global-access.ll
 create mode 100644 
llvm/test/CodeGen/Generic/ms-secure-hotpatch-functions-file.ll
 create mode 100644 
llvm/test/CodeGen/Generic/ms-secure-hotpatch-functions-list.ll

diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index a77232c281f7f..17f0a0794616f 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -505,6 +505,13 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   /// A list of functions that are replacable by the loader.
   std::vector LoaderReplaceableFunctionNames;
+  /// The name of a file that contains functions which will be compiled for
+  /// hotpatching. See -fms-secure-hotpatch-functions-file.
+  std::string MSSecureHotPatchFunctionsFile;
+
+  /// A list of functions which will be compiled for hotpatching.
+  /// See -fms-secure-hotpatch-functions-list.
+  std::vector MSSecureHotPatchFunctionsList;
 
 public:
   // Define accessors/mutators for code generation options of enumeration type.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fd6deb22d404e..1180f900ecc1f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3830,6 +3830,24 @@ def fms_hotpatch : Flag<["-"], "fms-hotpatch">, 
Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Ensure that all functions can be hotpatched at runtime">,
   MarshallingInfoFlag>;
+
+// See llvm/lib/CodeGen/WindowsSecureHotPatching.cpp
+def fms_secure_hotpatch_functions_file
+: Joined<["-"], "fms-secure-hotpatch-functions-file=">,
+  Group,
+  Visibility<[ClangOption, CC1Option, CLOption]>,
+  MarshallingInfoString>,
+  HelpText<"Path to a file that contains a list of mangled names of "
+   "functions that should be hot-patched for Windows Secure "
+   "Hot-Patching">;
+def fms_secure_hotpatch_functions_list
+: CommaJoined<["-"], "fms-secure-hotpatch-functions-list=">,
+  Group,
+  Visibility<[ClangOption, CC1Option, CLOption]>,
+  
MarshallingInfoStringVector>,
+  HelpText<"List of mangled symbol names of functions that should be "
+   "hot-patched for Windows Secure Hot-Patching">;
+
 def fp

[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-06-05 Thread Aaron Puchert via cfe-commits


@@ -286,51 +291,76 @@ static bool checkRecordTypeForScopedCapability(Sema &S, 
QualType Ty) {
   return checkRecordDeclForAttr(RT->getDecl());
 }
 
-static bool checkTypedefTypeForCapability(QualType Ty) {
+static std::optional checkTypedefTypeForCapability(QualType Ty) {
   const auto *TD = Ty->getAs();
   if (!TD)
-return false;
+return std::nullopt;
 
   TypedefNameDecl *TN = TD->getDecl();
   if (!TN)
-return false;
+return std::nullopt;
 
-  return TN->hasAttr();
-}
-
-static bool typeHasCapability(Sema &S, QualType Ty) {
-  if (checkTypedefTypeForCapability(Ty))
-return true;
+  if (TN->hasAttr())
+return {TN};
 
-  if (checkRecordTypeForCapability(S, Ty))
-return true;
+  return std::nullopt;
+}
 
-  return false;
+/// Returns capability TypeDecl if defined, nullptr if not yet defined (maybe
+/// capability), and nullopt if it definitely is not a capability.
+static std::optional checkTypeForCapability(Sema &S, QualType Ty) {
+  if (auto TD = checkTypedefTypeForCapability(Ty))
+return TD;
+  if (auto TD = checkRecordTypeForCapability(S, Ty))
+return TD;
+  return std::nullopt;
 }
 
-static bool isCapabilityExpr(Sema &S, const Expr *Ex) {
+static bool validateCapabilityExpr(Sema &S, const ParsedAttr &AL,
+   const Expr *Ex, bool Neg = false) {
   // Capability expressions are simple expressions involving the boolean logic
   // operators &&, || or !, a simple DeclRefExpr, CastExpr or a ParenExpr. Once
   // a DeclRefExpr is found, its type should be checked to determine whether it
   // is a capability or not.
 
   if (const auto *E = dyn_cast(Ex))
-return isCapabilityExpr(S, E->getSubExpr());
+return validateCapabilityExpr(S, AL, E->getSubExpr(), Neg);
   else if (const auto *E = dyn_cast(Ex))
-return isCapabilityExpr(S, E->getSubExpr());
+return validateCapabilityExpr(S, AL, E->getSubExpr(), Neg);
   else if (const auto *E = dyn_cast(Ex)) {
-if (E->getOpcode() == UO_LNot || E->getOpcode() == UO_AddrOf ||
-E->getOpcode() == UO_Deref)
-  return isCapabilityExpr(S, E->getSubExpr());
-return false;
+switch (E->getOpcode()) {
+case UO_LNot:
+  Neg = !Neg;
+  [[fallthrough]];
+case UO_AddrOf:
+case UO_Deref:
+  return validateCapabilityExpr(S, AL, E->getSubExpr(), Neg);
+default:
+  return false;
+}

aaronpuchert wrote:

Hmm, this might not be the best place to put this. There are two different 
mechanisms to generate negative capabilities:
* the supported, but untypical case of a `UnaryOperator`, which basically 
requires the capability to be an integer,
* the more common `CXXOperatorCallExpr`. (Well, at least in C++. Not sure how 
negating a mutex would work in C.)

This code here just checks the type (that's what Sema usually does), and I 
think what we want to check here is better done in `ThreadSafety.cpp`. Once we 
have a `CapabilityExpr` this should be much easier.

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


[clang] Thread Safety Analysis: Warn when using negative reentrant capability (PR #141599)

2025-06-05 Thread Aaron Puchert via cfe-commits

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


  1   2   3   4   5   6   >