[clang] [clang][RISCV] Handle target features correctly in CheckBuiltinFunctionCall (PR #141548)

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

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


[clang] 88aa5cb - [clang][RISCV] Handle target features correctly in CheckBuiltinFunctionCall (#141548)

2025-06-01 Thread via cfe-commits

Author: Brandon Wu
Date: 2025-06-01T17:57:08+08:00
New Revision: 88aa5cbbda67857891a740dd8326f6f45f4eb6fd

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

LOG: [clang][RISCV] Handle target features correctly in 
CheckBuiltinFunctionCall (#141548)

Currently we only check the required features passed by command line
arguments.
We also need to check the features passed by using target features.

Added: 
clang/test/Sema/zvk-target-attributes.c

Modified: 
clang/lib/Sema/SemaRISCV.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index 830df05c9f042..ac88f5e059b7b 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -545,8 +545,10 @@ bool SemaRISCV::CheckLMUL(CallExpr *TheCall, unsigned 
ArgNum) {
  << Arg->getSourceRange();
 }
 
-static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, CallExpr *TheCall,
-Sema &S, QualType Type, int EGW) {
+static bool CheckInvalidVLENandLMUL(const TargetInfo &TI,
+llvm::StringMap &FunctionFeatureMap,
+CallExpr *TheCall, Sema &S, QualType Type,
+int EGW) {
   assert((EGW == 128 || EGW == 256) && "EGW can only be 128 or 256 bits");
 
   // LMUL * VLEN >= EGW
@@ -567,7 +569,7 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, 
CallExpr *TheCall,
   // Vscale is VLEN/RVVBitsPerBlock.
   unsigned MinRequiredVLEN = VScaleFactor * llvm::RISCV::RVVBitsPerBlock;
   std::string RequiredExt = "zvl" + std::to_string(MinRequiredVLEN) + "b";
-  if (!TI.hasFeature(RequiredExt))
+  if (!TI.hasFeature(RequiredExt) && !FunctionFeatureMap.lookup(RequiredExt))
 return S.Diag(TheCall->getBeginLoc(),
   diag::err_riscv_type_requires_extension)
<< Type << RequiredExt;
@@ -579,6 +581,10 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
  unsigned BuiltinID,
  CallExpr *TheCall) {
   ASTContext &Context = getASTContext();
+  const FunctionDecl *FD = SemaRef.getCurFunctionDecl();
+  llvm::StringMap FunctionFeatureMap;
+  Context.getFunctionFeatureMap(FunctionFeatureMap, FD);
+
   // vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, vmulhsu.vv, vmulhsu.vx,
   // vsmul.vv, vsmul.vx are not included for EEW=64 in Zve64*.
   switch (BuiltinID) {
@@ -635,10 +641,6 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
 ASTContext::BuiltinVectorTypeInfo Info = Context.getBuiltinVectorTypeInfo(
 TheCall->getType()->castAs());
 
-const FunctionDecl *FD = SemaRef.getCurFunctionDecl();
-llvm::StringMap FunctionFeatureMap;
-Context.getFunctionFeatureMap(FunctionFeatureMap, FD);
-
 if (Context.getTypeSize(Info.ElementType) == 64 && !TI.hasFeature("v") &&
 !FunctionFeatureMap.lookup("v"))
   return Diag(TheCall->getBeginLoc(),
@@ -714,20 +716,24 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
   case RISCVVector::BI__builtin_rvv_vsm4k_vi_tu: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
 QualType Arg1Type = TheCall->getArg(1)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
-   CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg1Type, 128) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 128) ||
+   CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg1Type, 128) ||
SemaRef.BuiltinConstantArgRange(TheCall, 2, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vsm3c_vi_tu:
   case RISCVVector::BI__builtin_rvv_vsm3c_vi: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 256) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 256) ||
SemaRef.BuiltinConstantArgRange(TheCall, 2, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vaeskf1_vi:
   case RISCVVector::BI__builtin_rvv_vsm4k_vi: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 128) ||
SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vaesdf_vv:
@@ -754,8 +760,10 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
   case RISCVVector::BI__builtin_rvv_vsm4r_vs_tu: {
 QualT

[libcxx] [libunwind] [llvm] [libc++] Upgrade to GCC 15 (PR #138293)

2025-06-01 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/138293

>From 29273cf49b2cae51f6eee43970deb547272eb97f Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 2 May 2025 17:24:13 +0200
Subject: [PATCH] [libc++] Upgrade to GCC 15

---
 .github/workflows/libcxx-build-and-test.yaml  |  8 +--
 libcxx/docs/index.rst |  2 +-
 .../alg.contains/ranges.contains.pass.cpp |  4 +-
 .../equality_comparable.compile.pass.cpp  |  6 ++
 .../equality_comparable_with.compile.pass.cpp | 15 +
 .../totally_ordered.compile.pass.cpp  |  3 +
 .../totally_ordered_with.compile.pass.cpp | 10 +++
 .../new.delete.array/new.size.except.pass.cpp |  3 +
 .../new.delete.array/new.size.pass.cpp|  3 +
 .../new.size_align.except.pass.cpp|  3 +
 .../new.delete.array/new.size_align.pass.cpp  |  3 +
 .../new.size.except.pass.cpp  |  3 +
 .../new.delete.single/new.size.pass.cpp   |  3 +
 .../new.size_align.except.pass.cpp|  3 +
 .../new.delete.single/new.size_align.pass.cpp |  3 +
 .../ctor_func.pass.cpp|  3 +
 .../param_ctor_func.pass.cpp  |  3 +
 .../range.lazy.split/general.pass.cpp | 12 
 .../monadic/transform.pass.cpp|  4 +-
 .../monadic/transform_error.pass.cpp  |  4 +-
 .../monadic/transform_error.pass.cpp  |  4 +-
 .../formatter.char_array.pass.cpp |  2 +-
 .../meta/meta.rel/is_virtual_base_of.pass.cpp |  7 ++
 ...ass.cpp => dependent_return_type.pass.cpp} |  3 +
 .../is_implicit_lifetime.pass.cpp |  2 +-
 .../make_optional_explicit.pass.cpp   |  3 +
 ...ptional_explicit_initializer_list.pass.cpp |  3 +
 .../tuple.tuple/tuple.cnstr/PR31384.pass.cpp  |  2 +-
 libunwind/cmake/config-ix.cmake   | 65 ---
 libunwind/src/CMakeLists.txt  | 12 
 30 files changed, 108 insertions(+), 93 deletions(-)
 rename 
libcxx/test/std/utilities/meta/meta.unary/{dependent_return_type.compile.pass.cpp
 => dependent_return_type.pass.cpp} (96%)

diff --git a/.github/workflows/libcxx-build-and-test.yaml 
b/.github/workflows/libcxx-build-and-test.yaml
index 80f2432b78dea..f0bdf6c0b5899 100644
--- a/.github/workflows/libcxx-build-and-test.yaml
+++ b/.github/workflows/libcxx-build-and-test.yaml
@@ -52,8 +52,8 @@ jobs:
 cxx: [ 'clang++-21' ]
 include:
   - config: 'generic-gcc'
-cc: 'gcc-14'
-cxx: 'g++-14'
+cc: 'gcc-15'
+cxx: 'g++-15'
 steps:
   - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 
v4.2.2
   - name: ${{ matrix.config }}.${{ matrix.cxx }}
@@ -92,8 +92,8 @@ jobs:
 cxx: [ 'clang++-21' ]
 include:
   - config: 'generic-gcc-cxx11'
-cc: 'gcc-14'
-cxx: 'g++-14'
+cc: 'gcc-15'
+cxx: 'g++-15'
   - config: 'generic-cxx26'
 cc: 'clang-20'
 cxx: 'clang++-20'
diff --git a/libcxx/docs/index.rst b/libcxx/docs/index.rst
index a8b0d5ce1ee97..44737b379f189 100644
--- a/libcxx/docs/index.rst
+++ b/libcxx/docs/index.rst
@@ -134,7 +134,7 @@ Compiler VersionsRestrictions   
Support policy
 Clang19, 20, 21-git latest two stable 
releases per `LLVM's release page `_ and the 
development version
 AppleClang   15 latest stable 
release per `Xcode's release page 
`_
 Open XL  17.1.3 (AIX)   latest stable 
release per `Open XL's documentation page 
`_
-GCC  14  In C++11 or later only latest stable 
release per `GCC's release page `_
+GCC  15  In C++11 or later only latest stable 
release per `GCC's release page `_
  === == 
=
 
 Libc++ also supports common platforms and architectures:
diff --git 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
index 08d8e119a4d24..1e89cd272e643 100644
--- 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
+++ 
b/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
@@ -195,7 +195,7 @@ constexpr bool test() {
   std::string a[] = {str1, str1, str, str1, str1};
   auto whole =
   std::ranges::subrange(forward_iterator(std::move_iterator(a)), 
forward_iterator(std::move_iterator(a + 5)));
-  bool ret = std::ranges::contains(whole.begin(), whole.end(), "hello 
world", [&](const s

[clang] [clang] Fix bad error recovery when classes are defined inside template (PR #142278)

2025-06-01 Thread Artyom Zabroda via cfe-commits


@@ -220,6 +220,14 @@ static ExprResult EvaluateAtomicConstraint(
 if (Inst.isInvalid())
   return ExprError();
 
+if (const TemplateTypeParmType *TTPT =
+
dyn_cast(AtomicExpr->getType().getDesugaredType(S.Context)))
 {
+  TemplateTypeParmDecl *TTPD = TTPT->getDecl();
+  if (TTPD->isInvalidDecl()) {
+return ExprError();
+  }
+}
+

ArtyomZabroda wrote:

I don't understand how changing TTPDecl->setTypeForDecl to int can solve the 
issue for constraints. If I remove the check for invalid decl that I've made in 
EvaluateAtomicConstraint and set the type to int for the TemplateTypeParmDecl 
as you suggested, then the same errors pop up in the compiler. I'm not 
confident with the codebase yet, so maybe I've missed something, but I can't 
see any code in CheckInstantiatedFunctionTemplateConstraints and functions 
inside of it that checks dependence of a type inside TemplateTypeParmDecl 
before substituting an argument.

https://github.com/llvm/llvm-project/pull/142278
___
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-01 Thread Samarth Narang via cfe-commits

https://github.com/snarang181 edited 
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] [clang-tidy] Added Conflicting Global Accesses checker (PR #130421)

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

ConcreteCactus wrote:

Hi Everyone,
I fixed a crash in the ExecutionVisitor. It wasn't checking whether the 
definition of a class exists before trying to recurse into the destructor.

Can I get a re-review on this PR? I think I addressed most of the comments.

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


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

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

https://github.com/snarang181 converted_to_draft 
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] [Clang][WIP] Normalize constraints before checking for satisfaction (PR #141776)

2025-06-01 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/include/clang/AST/ASTConcept.h clang/include/clang/AST/TemplateBase.h 
clang/include/clang/Sema/Sema.h clang/include/clang/Sema/SemaConcept.h 
clang/include/clang/Sema/Template.h clang/lib/AST/ASTConcept.cpp 
clang/lib/AST/ASTContext.cpp clang/lib/Sema/SemaConcept.cpp 
clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaExprCXX.cpp 
clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaTemplateDeduction.cpp 
clang/lib/Sema/SemaTemplateInstantiate.cpp 
clang/lib/Sema/SemaTemplateVariadic.cpp clang/lib/Sema/TreeTransform.h 
clang/lib/Serialization/ASTWriterStmt.cpp clang/test/CXX/drs/cwg25xx.cpp 
clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp 
clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp 
clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp
 clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp 
clang/test/SemaCXX/cxx23-assume.cpp clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
clang/test/SemaCXX/invalid-requirement-requires-expr.cpp 
clang/test/SemaCXX/overload-resolution-deferred-templates.cpp 
clang/test/SemaTemplate/concepts-recovery-expr.cpp 
clang/test/SemaTemplate/concepts.cpp 
clang/test/SemaTemplate/instantiate-abbreviated-template.cpp 
clang/test/SemaTemplate/instantiate-expanded-type-constraint.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 279d999a5..2de0eceff 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -534,12 +534,12 @@ static bool calculateConstraintSatisfaction(
   if (!NumExpansions)
 return false;
 
-  if(*NumExpansions == 0) {
+  if (*NumExpansions == 0) {
 Satisfaction.IsSatisfied = Conjunction;
 return true;
   }
 
-  //bool HasAnyFailed = false;
+  // bool HasAnyFailed = false;
   for (unsigned I = 0; I < *NumExpansions; I++) {
 Sema::ArgPackSubstIndexRAII SubstIndex(S, I);
 Satisfaction.IsSatisfied = false;
@@ -550,7 +550,8 @@ static bool calculateConstraintSatisfaction(
 if (!Success)
   return false;
 if (!Conjunction && Satisfaction.IsSatisfied) {
-  Satisfaction.Details.erase(Satisfaction.Details.begin() + 
EffectiveDetailEndIndex,
+  Satisfaction.Details.erase(Satisfaction.Details.begin() +
+ EffectiveDetailEndIndex,
  Satisfaction.Details.end());
   break;
 }
@@ -655,10 +656,11 @@ static bool calculateConstraintSatisfaction(
   Satisfaction.IsSatisfied = false;
 
   Ok = calculateConstraintSatisfaction(S, Constraint.getRHS(), Template,
- TemplateNameLoc, MLTAL, Satisfaction,
- PackSubstitutionIndex);
-  if(Ok && Satisfaction.IsSatisfied && !Satisfaction.ContainsErrors)
-Satisfaction.Details.erase(Satisfaction.Details.begin() + 
EffectiveDetailEndIndex,
+   TemplateNameLoc, MLTAL, Satisfaction,
+   PackSubstitutionIndex);
+  if (Ok && Satisfaction.IsSatisfied && !Satisfaction.ContainsErrors)
+Satisfaction.Details.erase(Satisfaction.Details.begin() +
+   EffectiveDetailEndIndex,
Satisfaction.Details.end());
   return Ok;
 }
@@ -1314,9 +1316,10 @@ static void diagnoseUnsatisfiedRequirement(Sema &S,
concepts::NestedRequirement *Req,
bool First) {
   DiagnoseUnsatisfiedConstraint(S, Req->getConstraintSatisfaction().records(),
-Req->hasInvalidConstraint() ? SourceLocation() 
:
-Req->getConstraintExpr()->getExprLoc(), First,
-Req);
+Req->hasInvalidConstraint()
+? SourceLocation()
+: Req->getConstraintExpr()->getExprLoc(),
+First, Req);
 }
 
 static void diagnoseWellFormedUnsatisfiedConstraintExpr(Sema &S,

``




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


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

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;
+int b = (a++) - a; // This is flagged by -Wunsequenced.
+
+However global variables allow for more complex scenarios that
+-Wunsequenced doesn't detect. E.g. ::
+
+int globalVar = 0;
+
+int incFun() {
+  globalVar++;
+  return globalVar;
+}
+
+int main() {
+  return globalVar + incFun(); // This is not detected by -Wunsequenced.
+}
+
+This checker attempts to detect such cases. It recurses into functions that are
+inside the same translation unit. It also attempts not to flag cases that are
+already covered by -Wunsequenced. Global unions and structs are also handled.
+For example::
+
+typedef struct {
+int A;
+float B;
+} IntAndFloat;
+
+IntAndFloat GlobalIF;
+
+int globalIFGetSum() {
+int sum = GlobalIF.A + (int)GlobalIF.B;
+GlobalIF = (IntAndFloat){};
+return sum;
+}
+
+int main() {
+// The following printf could give different results on different
+// compilers.
+printf("sum: %i, int: %i", globalIFGetSum(), GlobalIF.A);
+}
+
+Options
+---
+
+.. option:: HandleMutableFunctionParametersAsWrites
+
+It's possible to enable handling mutable reference and pointer function
+parameters as writes using the HandleMutableFunctionParametersAsWrites
+option. For example:
+
+void func(int& a);
+
+int globalVar;
+func(globalVar); // <- this could be a write to globalVar.
+
+This option is disabled by default.

vbvictor wrote:

```suggestion
Default value is `false`.
```

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


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

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;
+int b = (a++) - a; // This is flagged by -Wunsequenced.
+
+However global variables allow for more complex scenarios that
+-Wunsequenced doesn't detect. E.g. ::
+
+int globalVar = 0;
+
+int incFun() {
+  globalVar++;
+  return globalVar;
+}
+
+int main() {
+  return globalVar + incFun(); // This is not detected by -Wunsequenced.
+}
+
+This checker attempts to detect such cases. It recurses into functions that are
+inside the same translation unit. It also attempts not to flag cases that are
+already covered by -Wunsequenced. Global unions and structs are also handled.
+For example::
+
+typedef struct {
+int A;
+float B;
+} IntAndFloat;
+
+IntAndFloat GlobalIF;
+
+int globalIFGetSum() {
+int sum = GlobalIF.A + (int)GlobalIF.B;
+GlobalIF = (IntAndFloat){};
+return sum;
+}
+
+int main() {
+// The following printf could give different results on different
+// compilers.
+printf("sum: %i, int: %i", globalIFGetSum(), GlobalIF.A);
+}
+
+Options
+---
+
+.. option:: HandleMutableFunctionParametersAsWrites
+
+It's possible to enable handling mutable reference and pointer function
+parameters as writes using the HandleMutableFunctionParametersAsWrites
+option. For example:
+
+void func(int& a);

vbvictor wrote:

ditto code-block

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


[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Mike Crowe (mikecrowe)


Changes

These checks previously failed with absl::StrFormat and absl::PrintF etc. with:

 Unable to use 'std::format' instead of 'StrFormat' because first
 argument is not a narrow string literal [modernize-use-std-format]

because FormatStringConverter was rejecting the format string if it had already 
converted into a different type. Fix the tests so that they check this case 
properly by accepting string_view rather than const char
* and fix the check so that these tests pass. Update the existing tests that 
checked for the error message that can no longer happen.

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

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


6 Files Affected:

- (modified) clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp 
(+2-6) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+10) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp 
(+11-6) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp (+2-2) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp 
(+3-2) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp 
(+16-9) 


``diff
diff --git a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp 
b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
index 7f4ccca84faa5..e1c1bee97f6d4 100644
--- a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
@@ -207,13 +207,9 @@ FormatStringConverter::FormatStringConverter(
   ArgsOffset(FormatArgOffset + 1), LangOpts(LO) {
   assert(ArgsOffset <= NumArgs);
   FormatExpr = llvm::dyn_cast(
-  Args[FormatArgOffset]->IgnoreImplicitAsWritten());
+  Args[FormatArgOffset]->IgnoreUnlessSpelledInSource());
 
-  if (!FormatExpr || !FormatExpr->isOrdinary()) {
-// Function must have a narrow string literal as its first argument.
-conversionNotPossible("first argument is not a narrow string literal");
-return;
-  }
+  assert(FormatExpr && FormatExpr->isOrdinary());
 
   if (const std::optional MaybeMacroName =
   formatStringContainsUnreplaceableMacro(Call, FormatExpr, SM, PP);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e0f81a032c38d..3bd601ebdb580 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -232,10 +232,20 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-std-print
+  ` check to correctly match
+  when the format string is converted to a different type by an implicit
+  constructor call.
+
 - Improved :doc:`modernize-use-std-numbers
   ` check to support math
   functions of different precisions.
 
+- Improved :doc:`modernize-use-std-format
+  ` check to correctly match
+  when the format string is converted to a different type by an implicit
+  constructor call.
+
 - Improved :doc:`performance-move-const-arg
   ` check by fixing false
   negatives on ternary operators calling ``std::move``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
index 7da0bb02ad766..0f3458e61856a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
@@ -2,7 +2,7 @@
 // RUN:   -std=c++20 %s modernize-use-std-format %t --  \
 // RUN:   -config="{CheckOptions: { \
 // RUN:  modernize-use-std-format.StrictMode: true, \
-// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; bad_format_type_strprintf', \
+// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; any_format_type_strprintf', \
 // RUN:  modernize-use-std-format.ReplacementFormatFunction: 
'fmt::format', \
 // RUN:  modernize-use-std-format.FormatHeader: '' \
 // RUN:}}"  \
@@ -10,7 +10,7 @@
 // RUN: %check_clang_tidy -check-suffixes=,NOTSTRICT\
 // RUN:   -std=c++20 %s modernize-use-std-format %t --  \
 // RUN:   -config="{CheckOptions: { \
-// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; bad_format_type_strprintf', \
+// RUN:  modernize-use-std-format.St

[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe created 
https://github.com/llvm/llvm-project/pull/142312

These checks previously failed with absl::StrFormat and absl::PrintF etc. with:

 Unable to use 'std::format' instead of 'StrFormat' because first
 argument is not a narrow string literal [modernize-use-std-format]

because FormatStringConverter was rejecting the format string if it had already 
converted into a different type. Fix the tests so that they check this case 
properly by accepting string_view rather than const char
* and fix the check so that these tests pass. Update the existing tests that 
checked for the error message that can no longer happen.

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

>From 929c892a18e57d0371adab5c8ab9aa55dce3f192 Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Thu, 29 May 2025 21:19:11 +0100
Subject: [PATCH] [clang-tidy] modernize-use-std-print,format: Fix checks with
 Abseil functions

These checks previously failed with absl::StrFormat and absl::PrintF
etc. with:

 Unable to use 'std::format' instead of 'StrFormat' because first
 argument is not a narrow string literal [modernize-use-std-format]

because FormatStringConverter was rejecting the format string if it had
already converted into a different type. Fix the tests so that they
check this case properly by accepting string_view rather than const char
* and fix the check so that these tests pass. Update the existing tests
that checked for the error message that can no longer happen.

Fixes: https://github.com/llvm/llvm-project/issues/129484
---
 .../utils/FormatStringConverter.cpp   |  8 ++
 clang-tools-extra/docs/ReleaseNotes.rst   | 10 
 .../modernize/use-std-format-custom.cpp   | 17 -
 .../checkers/modernize/use-std-format.cpp |  4 +--
 .../checkers/modernize/use-std-print-absl.cpp |  5 ++--
 .../modernize/use-std-print-custom.cpp| 25 ---
 6 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp 
b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
index 7f4ccca84faa5..e1c1bee97f6d4 100644
--- a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
@@ -207,13 +207,9 @@ FormatStringConverter::FormatStringConverter(
   ArgsOffset(FormatArgOffset + 1), LangOpts(LO) {
   assert(ArgsOffset <= NumArgs);
   FormatExpr = llvm::dyn_cast(
-  Args[FormatArgOffset]->IgnoreImplicitAsWritten());
+  Args[FormatArgOffset]->IgnoreUnlessSpelledInSource());
 
-  if (!FormatExpr || !FormatExpr->isOrdinary()) {
-// Function must have a narrow string literal as its first argument.
-conversionNotPossible("first argument is not a narrow string literal");
-return;
-  }
+  assert(FormatExpr && FormatExpr->isOrdinary());
 
   if (const std::optional MaybeMacroName =
   formatStringContainsUnreplaceableMacro(Call, FormatExpr, SM, PP);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e0f81a032c38d..3bd601ebdb580 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -232,10 +232,20 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-std-print
+  ` check to correctly match
+  when the format string is converted to a different type by an implicit
+  constructor call.
+
 - Improved :doc:`modernize-use-std-numbers
   ` check to support math
   functions of different precisions.
 
+- Improved :doc:`modernize-use-std-format
+  ` check to correctly match
+  when the format string is converted to a different type by an implicit
+  constructor call.
+
 - Improved :doc:`performance-move-const-arg
   ` check by fixing false
   negatives on ternary operators calling ``std::move``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
index 7da0bb02ad766..0f3458e61856a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
@@ -2,7 +2,7 @@
 // RUN:   -std=c++20 %s modernize-use-std-format %t --  \
 // RUN:   -config="{CheckOptions: { \
 // RUN:  modernize-use-std-format.StrictMode: true, \
-// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; bad_format_type_strprintf', \
+// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; any_format_type_strprintf', \
 // RUN:  modernize-use-std-format.ReplacementFormatFunction: 
'fmt::for

[clang] 2a19efe - [Serialization] Remove unused includes (NFC) (#142300)

2025-06-01 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-06-01T08:10:01-07:00
New Revision: 2a19efe7fe8adcb5d89d3587ee23d9f954b11896

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

LOG: [Serialization] Remove unused includes (NFC) (#142300)

These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.

Added: 


Modified: 
clang/lib/Serialization/ASTCommon.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/Serialization/ModuleManager.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTCommon.cpp 
b/clang/lib/Serialization/ASTCommon.cpp
index 07d3918b144ac..097da3668857c 100644
--- a/clang/lib/Serialization/ASTCommon.cpp
+++ b/clang/lib/Serialization/ASTCommon.cpp
@@ -15,10 +15,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Serialization/ASTDeserializationListener.h"
-#include "clang/Serialization/ModuleFile.h"
 #include "llvm/Support/DJB.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8d2f105b2dec3..352ccc07fb462 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -47,7 +47,6 @@
 #include "clang/Basic/DiagnosticIDs.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/DiagnosticSema.h"
-#include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/FileSystemOptions.h"
 #include "clang/Basic/IdentifierTable.h"
@@ -64,7 +63,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/SourceManagerInternals.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/Basic/Stack.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Basic/TokenKinds.h"
@@ -97,32 +95,26 @@
 #include "clang/Serialization/SerializationDiagnostic.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APInt.h"
-#include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/FloatingPointMode.h"
 #include "llvm/ADT/FoldingSet.h"
-#include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/Sequence.h"
 #include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Bitstream/BitstreamReader.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/DJB.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/LEB128.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index e84932c765663..fb31613ded655 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -49,7 +49,6 @@
 #include "clang/Basic/PragmaKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "clang/Basic/Stack.h"
 #include "clang/Sema/IdentifierResolver.h"
 #include "clang/Serialization/ASTBitCodes.h"
 #include "clang/Serialization/ASTRecordReader.h"
@@ -57,12 +56,10 @@
 #include "clang/Serialization/ModuleFile.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Bitstream/BitstreamReader.h"
-#include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include 

diff  --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index f327a7b355868..f1bb33a19107e 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -41,23 +41,18 @@
 #include "clang/Basic/CapturedStmt.h"
 #include "clang/Basic/ExpressionTraits.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/Lambda.h"
 #include "clang/Basic/Lang

[clang] [Serialization] Remove unused includes (NFC) (PR #142300)

2025-06-01 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata closed 
https://github.com/llvm/llvm-project/pull/142300
___
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-01 Thread Samarth Narang via cfe-commits

https://github.com/snarang181 ready_for_review 
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] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,32 @@
+.. title:: clang-tidy - performance-lost-std-move
+
+performance-lost-std-move
+=
+
+Warns if copy constructor is used instead of std::move() and suggests a fix.
+It honours cycles, lambdas, and unspecified call order in compound expressions.
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ f(x);  // warning: Could be std::move() [performance-lost-std-move]
+   }
+
+It finds the last local variable usage, and if it is a copy, emits a warning.
+The check is based on pure AST matching and doesn't take into account any data 
flow information.
+Thus, it doesn't catch assign-after-copy cases.
+Also it doesn't notice variable references "behind the scenes":
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ auto &y = x;
+ f(x);  // emits a warning...
+ y.f();  // ...but it is still used
+   }

vbvictor wrote:

I strongly oppose this design decision. In this check we should minimize the 
number of false-positives (and not leave any known false-positives). It's 
better to have false-negatives than false-positives, so an easy solution to 
this case could be:
If the variable is binded to a reference then we can not emit a warning.

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


[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread Mike Crowe via cfe-commits

mikecrowe wrote:

Thanks to @gle8098 who suggested the fix for this.

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


[libcxx] [libunwind] [llvm] [libc++] Upgrade to GCC 15 (PR #138293)

2025-06-01 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/138293

>From 68a5c9df4e5dc4599a97ccd24b95708ac0e0a327 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 2 May 2025 17:24:13 +0200
Subject: [PATCH] [libc++] Upgrade to GCC 15

---
 .github/workflows/libcxx-build-and-test.yaml  |  8 +--
 libcxx/docs/index.rst |  2 +-
 libcxx/src/experimental/time_zone.cpp |  5 ++
 .../alg.contains/ranges.contains.pass.cpp |  4 +-
 .../equality_comparable.compile.pass.cpp  |  6 ++
 .../equality_comparable_with.compile.pass.cpp | 15 +
 .../totally_ordered.compile.pass.cpp  |  3 +
 .../totally_ordered_with.compile.pass.cpp | 10 +++
 .../new.delete.array/new.size.except.pass.cpp |  3 +
 .../new.delete.array/new.size.pass.cpp|  3 +
 .../new.size_align.except.pass.cpp|  3 +
 .../new.delete.array/new.size_align.pass.cpp  |  3 +
 .../new.size.except.pass.cpp  |  3 +
 .../new.delete.single/new.size.pass.cpp   |  3 +
 .../new.size_align.except.pass.cpp|  3 +
 .../new.delete.single/new.size_align.pass.cpp |  3 +
 .../ctor_func.pass.cpp|  3 +
 .../param_ctor_func.pass.cpp  |  3 +
 .../range.lazy.split/general.pass.cpp | 12 
 .../monadic/transform.pass.cpp|  4 +-
 .../monadic/transform_error.pass.cpp  |  4 +-
 .../monadic/transform_error.pass.cpp  |  4 +-
 .../formatter.char_array.pass.cpp |  2 +-
 .../meta/meta.rel/is_virtual_base_of.pass.cpp |  7 ++
 ...ass.cpp => dependent_return_type.pass.cpp} |  3 +
 .../is_implicit_lifetime.pass.cpp |  2 +-
 .../make_optional_explicit.pass.cpp   |  3 +
 ...ptional_explicit_initializer_list.pass.cpp |  3 +
 .../tuple.tuple/tuple.cnstr/PR31384.pass.cpp  |  2 +-
 libunwind/cmake/config-ix.cmake   | 65 ---
 libunwind/src/CMakeLists.txt  | 12 
 31 files changed, 113 insertions(+), 93 deletions(-)
 rename 
libcxx/test/std/utilities/meta/meta.unary/{dependent_return_type.compile.pass.cpp
 => dependent_return_type.pass.cpp} (96%)

diff --git a/.github/workflows/libcxx-build-and-test.yaml 
b/.github/workflows/libcxx-build-and-test.yaml
index 80f2432b78dea..f0bdf6c0b5899 100644
--- a/.github/workflows/libcxx-build-and-test.yaml
+++ b/.github/workflows/libcxx-build-and-test.yaml
@@ -52,8 +52,8 @@ jobs:
 cxx: [ 'clang++-21' ]
 include:
   - config: 'generic-gcc'
-cc: 'gcc-14'
-cxx: 'g++-14'
+cc: 'gcc-15'
+cxx: 'g++-15'
 steps:
   - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 
v4.2.2
   - name: ${{ matrix.config }}.${{ matrix.cxx }}
@@ -92,8 +92,8 @@ jobs:
 cxx: [ 'clang++-21' ]
 include:
   - config: 'generic-gcc-cxx11'
-cc: 'gcc-14'
-cxx: 'g++-14'
+cc: 'gcc-15'
+cxx: 'g++-15'
   - config: 'generic-cxx26'
 cc: 'clang-20'
 cxx: 'clang++-20'
diff --git a/libcxx/docs/index.rst b/libcxx/docs/index.rst
index a8b0d5ce1ee97..44737b379f189 100644
--- a/libcxx/docs/index.rst
+++ b/libcxx/docs/index.rst
@@ -134,7 +134,7 @@ Compiler VersionsRestrictions   
Support policy
 Clang19, 20, 21-git latest two stable 
releases per `LLVM's release page `_ and the 
development version
 AppleClang   15 latest stable 
release per `Xcode's release page 
`_
 Open XL  17.1.3 (AIX)   latest stable 
release per `Open XL's documentation page 
`_
-GCC  14  In C++11 or later only latest stable 
release per `GCC's release page `_
+GCC  15  In C++11 or later only latest stable 
release per `GCC's release page `_
  === == 
=
 
 Libc++ also supports common platforms and architectures:
diff --git a/libcxx/src/experimental/time_zone.cpp 
b/libcxx/src/experimental/time_zone.cpp
index 289164ab12036..cb587d53633c5 100644
--- a/libcxx/src/experimental/time_zone.cpp
+++ b/libcxx/src/experimental/time_zone.cpp
@@ -29,6 +29,11 @@
 // These quirks often use a 12h interval; this is the scan interval of zdump,
 // which implies there are no sys_info objects with a duration of less than 
12h.
 
+// Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120502
+#ifdef _LIBCPP_COMPILER_GCC
+#  pragma GCC optimize("-O0")
+#endif
+
 #include 
 #include 
 #include 
diff --git 
a/libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains.pass.cpp
 
b/libcxx/

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

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

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

>From 725dd21adcd2f776b2e6adc648e3038812059bf3 Mon Sep 17 00:00:00 2001
From: Samarth Narang 
Date: Sat, 31 May 2025 10:05:52 -0400
Subject: [PATCH 1/6] [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 f8e338eb7c6ed..2e5d402106547 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -315,8 +315,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-tools-extra] Refactor clang doc comment structure (PR #142273)

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

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

>From cd99fbe06a384db3775d1fc8c923275df07d4db3 Mon Sep 17 00:00:00 2001
From: Samarth Narang 
Date: Sat, 31 May 2025 10:05:52 -0400
Subject: [PATCH 1/7] [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 f8e338eb7c6ed..2e5d402106547 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -315,8 +315,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] [clang] Fix bad error recovery when classes are defined inside template (PR #142278)

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


@@ -220,6 +220,14 @@ static ExprResult EvaluateAtomicConstraint(
 if (Inst.isInvalid())
   return ExprError();
 
+if (const TemplateTypeParmType *TTPT =
+
dyn_cast(AtomicExpr->getType().getDesugaredType(S.Context)))
 {
+  TemplateTypeParmDecl *TTPD = TTPT->getDecl();
+  if (TTPD->isInvalidDecl()) {
+return ExprError();
+  }
+}
+

mizvekov wrote:

If you change the type for the TTPDecl to int, then that changes the type 
produced whenever a typename lookup is performed for that template parameter 
name, and the TTPDecl essentially becomes unreachable within the program. So 
any users of T wouldn't be able to figure out there was a template parameter 
there, and should see no dependency.

I suspect you might not be changing the type early enough, the type should be 
changed as soon as we figure out we are getting into a struct definition, 
before the template parameter could be used as a base class, inside an 
attribute, or in the class body.

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


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

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

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

None

>From c8f62770b164216bd67810a1035996180ec6c3d8 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Sun, 1 Jun 2025 15:44:37 +
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 | 708 ++
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |   8 +
 clang/test/Sema/warn-lifetime-safety.cpp  | 120 +++
 llvm/include/llvm/ADT/ImmutableMap.h  |   2 +-
 6 files changed, 851 insertions(+), 1 deletion(-)
 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.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..5b33d582f7278
--- /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..1124badcd9e2c
--- /dev/null
+++ b/clang/lib/Analysis/LifetimeSafety.cpp
@@ -0,0 +1,708 @@
+#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/Support/Debug.h"
+#include 
+
+namespace clang {
+namespace {
+
+constexpr char kLifetimeFacts[] = "LifetimeFacts";
+constexpr char kLifetimeDataflow[] = "LifetimeDataflow";
+
+/// TODO: Why do we need this?
+struct Point {
+  const clang::CFGBlock *Block;
+  // Index into Block->Elements().
+  // Value is Block->size() if it's a point *after* the last element / before
+  // terminator.
+  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;
+  }
+};
+
+struct Path {
+  llvm::PointerUnion Ptr;
+
+  enum class Kind : uint8_t {
+StackVariableAddress,
+HeapAllocationAddress,
+FieldAddress,
+ArrayElementAddress,
+TemporaryObjectAddress,
+StaticOrGlobalAddress,
+StringLiteralAddress
+  };
+
+  Kind PathKind;
+
+  Path(llvm::PointerUnion P,
+   Kind K)
+  : Ptr(P), PathKind(K) {}
+  /// TODO: Add accessors or other methods as needed
+};
+
+using LoanID = uint32_t;
+using OriginID = uint32_t;
+
+struct LoanInfo {
+  /// TODO: Represent opaque loans.
+  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 };
+
+struct OriginInfo {
+  OriginID ID;
+  OriginKind Kind;
+  /// TODO: Finalise this representation. Maybe
+  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) {}
+};
+
+enum class FactKind : uint8_t { Issue, Expire, AssignOrigin, ReturnOfOrigin };
+
+class LoanManager {
+public:
+  LoanManager() = default;
+
+  LoanID getNextLoanID() { return NextLoanIDVal++; }
+
+  LoanInfo &addLoanInfo(LoanID id, Path path, SourceLocation loc) {
+AllLoans.emplace_back(id, path, loc);
+return AllLoans.back();
+  }
+
+  const LoanInfo *getLoanInfo(LoanID id) const {
+if (id < AllLoans.size())
+  return &AllLoans[id]

[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,32 @@
+.. title:: clang-tidy - performance-lost-std-move
+
+performance-lost-std-move
+=
+
+Warns if copy constructor is used instead of std::move() and suggests a fix.
+It honours cycles, lambdas, and unspecified call order in compound expressions.
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ f(x);  // warning: Could be std::move() [performance-lost-std-move]
+   }
+
+It finds the last local variable usage, and if it is a copy, emits a warning.
+The check is based on pure AST matching and doesn't take into account any data 
flow information.

EugeneZelenko wrote:

Please follow 80-characters limit.

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


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-01 Thread Fangrui Song via cfe-commits

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


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


[clang] [llvm] Remove Native Client support (PR #133661)

2025-06-01 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> Thanks for working on this! This will be the first time I'm not going to 
> oppose an effort to remove Native Client support 🎉 Although I am going to ask 
> you to wait a couple of months to land it, until we finally turn it off for 
> good and start deleting the support code from Chromium. This is planned after 
> the M139 branch in late June. I will also give this a good review.

I hope this remains on schedule. I want to remove AlignedBundling support from 
MCAssembler; its presence has made improving fragment relaxation within the 
assembler exceptionally difficult.

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


[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread Baranov Victor via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,32 @@
+.. title:: clang-tidy - performance-lost-std-move
+
+performance-lost-std-move
+=
+
+Warns if copy constructor is used instead of std::move() and suggests a fix.
+It honours cycles, lambdas, and unspecified call order in compound expressions.
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ f(x);  // warning: Could be std::move() [performance-lost-std-move]
+   }
+
+It finds the last local variable usage, and if it is a copy, emits a warning.
+The check is based on pure AST matching and doesn't take into account any data 
flow information.
+Thus, it doesn't catch assign-after-copy cases.
+Also it doesn't notice variable references "behind the scenes":
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ auto &y = x;
+ f(x);  // emits a warning...
+ y.f();  // ...but it is still used
+   }

vbvictor wrote:

We can distinguish cases where a variable was an initializer to `VarDecl` of 
type `X&` and where the variable was used as a function parameter as 
`DeclRefExpr`, https://godbolt.org/z/brKdcsn61.
Even if this can't be fixed, I think it's better to skip cases than have 
false-positives for this check.

In your 3-liner example, it may be easy to spot a false-positive, but if `void 
g(X x)` is 100+ lines long it will be hard to verify correctness. Thought 
`clang-static-analyzer` may [find ](https://godbolt.org/z/d7ed3jYca) these 
cases, not everyone use it.

May other reviews share their opinions.

https://github.com/llvm/llvm-project/pull/139525
___
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-01 Thread Henrich Lauko via cfe-commits


@@ -0,0 +1,21 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the CIR dialect attributes constraints.
+//
+//===--===//
+
+#ifndef CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
+#define CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
+
+include "clang/CIR/Dialect/IR/CIRAttrs.td"
+include "mlir/IR/CommonAttrConstraints.td"
+
+def CIR_IntArrayAttr : TypedArrayAttrBase;

xlauko wrote:

You cannot include CIRAttrs.td here as it will eventually create circular 
dependency.

To constrain on `IntAttr` add `CIR_AnyIntAttr see following suggestion:

```suggestion
include "mlir/IR/CommonAttrConstraints.td"

class CIR_IsAttrPred : CPred<"::mlir::isa<" # attr # ">($_self)">;

class CIR_AttrConstraintBase
: AttrConstraint, summary>;

//===--===//
// IntAttr constraints
//===--===//

def CIR_AnyIntAttr : CIR_AttrConstraintBase<"::cir::IntAttr", "integer 
attribute">;

//===--===//
// ArrayAttr constraints
//===--===//

def CIR_IntArrayAttr : TypedArrayAttrBase;
```

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] [CIR] Upstream ShuffleOp for VectorType (PR #142288)

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

https://github.com/xlauko edited 
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] [CIR] Add initial support for bitfields in structs (PR #142041)

2025-06-01 Thread via cfe-commits


@@ -14,6 +14,105 @@
 
 namespace clang::CIRGen {
 
+/// Record with information about how a bitfield should be accessed. This is
+/// very similar to what LLVM codegen does, once CIR evolves it's possible we
+/// can use a more higher level representation.
+///
+/// Often we lay out a sequence of bitfields as a contiguous sequence of bits.
+/// When the AST record layout does this, we represent it in CIR as a
+/// `!cir.record` type, which directly reflects the structure's layout,
+/// including bitfield packing and padding, using CIR types such as
+/// `!cir.bool`, `!s8i`, `!u16i`.
+///
+/// To access a particular bitfield in CIR, we use the operations
+/// `cir.get_bitfield` (`GetBitfieldOp`) or `cir.set_bitfield`
+/// (`SetBitfieldOp`). These operations rely on the `bitfield_info`
+/// attribute, which provides detailed metadata required for access,
+/// such as the size and offset of the bitfield, the type and size of
+/// the underlying storage, and whether the value is signed.
+/// The CIRGenRecordLayout also has a bitFields map which encodes which
+/// byte-sequence this bitfield falls within. Let's assume the following C
+/// struct:
+///
+///   struct S {
+/// char a, b, c;
+/// unsigned bits : 3;
+/// unsigned more_bits : 4;
+/// unsigned still_more_bits : 7;
+///   };
+///
+/// This will end up as the following cir.record. The first array is the
+/// bitfield, and the second is the padding out to a 4-byte alignment.
+///
+///   !rec_S = !cir.record}>
+///
+/// When generating code to access more_bits, we'll generate something
+/// essentially like this:
+///
+///   #bfi_more_bits = #cir.bitfield_info
+///
+///   cir.func @store_field() {
+/// %0 = cir.alloca !rec_S, !cir.ptr, ["s"] {alignment = 4 : i64}
+/// %1 = cir.const #cir.int<2> : !s32i
+/// %2 = cir.cast(integral, %1 : !s32i), !u32i
+/// %3 = cir.get_member %0[4] {name = "more_bits"} : !cir.ptr ->
+/// !cir.ptr

Andres-Salamanca wrote:

sorry, when I was writing this, I was running some tests and forgot to revert 
the struct back to match what the comment was describing. Thanks for catching 
that

https://github.com/llvm/llvm-project/pull/142041
___
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-01 Thread Henrich Lauko via cfe-commits

https://github.com/xlauko edited 
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] [CIR] Upstream ShuffleOp for VectorType (PR #142288)

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


@@ -2156,6 +2157,52 @@ def VecCmpOp : CIR_Op<"vec.cmp", [Pure, 
SameTypeOperands]> {
   }];
 }
 
+//===--===//
+// VecShuffleOp
+//===--===//
+
+// TODO: Create an interface that both VecShuffleOp and VecShuffleDynamicOp
+// implement.  This could be useful for passes that don't care how the vector
+// shuffle was specified.
+
+def VecShuffleOp : CIR_Op<"vec.shuffle",
+   [Pure, AllTypesMatch<["vec1", "vec2"]>]> {
+  let summary = "Combine two vectors using indices passed as constant 
integers";
+  let description = [{
+The `cir.vec.shuffle` operation implements the documented form of Clang's
+__builtin_shufflevector, where the indices of the shuffled result are

xlauko wrote:

```suggestion
`__builtin_shufflevector`, where the indices of the shuffled result are
```

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-tools-extra] Refactor clang doc comment structure (PR #142273)

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

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

>From cd99fbe06a384db3775d1fc8c923275df07d4db3 Mon Sep 17 00:00:00 2001
From: Samarth Narang 
Date: Sat, 31 May 2025 10:05:52 -0400
Subject: [PATCH 1/8] [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 f8e338eb7c6ed..2e5d402106547 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -315,8 +315,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-tools-extra] Refactor clang doc comment structure (PR #142273)

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


@@ -26,6 +26,66 @@
 namespace clang {
 namespace doc {
 
+CommentKind stringToCommentKind(llvm::StringRef KindStr) {
+  if (KindStr == "FullComment")
+return CommentKind::CK_FullComment;

snarang181 wrote:

Updated the function to do a `StringMap` lookup. 

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] [clang-tidy] Add performance-bool-bitwise-operation check (PR #142324)

2025-06-01 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread Fabian Keßler via cfe-commits


@@ -0,0 +1,32 @@
+.. title:: clang-tidy - performance-lost-std-move
+
+performance-lost-std-move
+=
+
+Warns if copy constructor is used instead of std::move() and suggests a fix.
+It honours cycles, lambdas, and unspecified call order in compound expressions.
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ f(x);  // warning: Could be std::move() [performance-lost-std-move]
+   }
+
+It finds the last local variable usage, and if it is a copy, emits a warning.
+The check is based on pure AST matching and doesn't take into account any data 
flow information.
+Thus, it doesn't catch assign-after-copy cases.
+Also it doesn't notice variable references "behind the scenes":
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ auto &y = x;
+ f(x);  // emits a warning...
+ y.f();  // ...but it is still used
+   }

Febbe wrote:

> The problem is that any binding to a reference should skip the check. E.g.
> 
> ```
> void f(X);
> void g(X&);
> 
> void func(X x) {
>   g(x); // reference is created, we may not move from x anymore
>   f(x); // no fix
> }
> ```
> 
> I'm afraid too many cases are skipped due to this problem.

Would it be a compromise to enable this via an option that is disabled by 
default?
Also, disable automatic fixes for those cases, so every change has to be done 
on purpose?

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


[clang] [clang][AIX] Fix -print-runtime-dir fallback on AIX (PR #141439)

2025-06-01 Thread Jake Egan via cfe-commits


@@ -933,11 +933,16 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   if (auto Path = getPathForTriple(T))
 return *Path;
 
-  if (T.isOSAIX() && T.getEnvironment() == Triple::UnknownEnvironment) {
-// Strip unknown environment from the triple.
-const llvm::Triple AIXTriple(
-llvm::Triple(T.getArchName(), T.getVendorName(),
- llvm::Triple::getOSTypeName(T.getOS(;
+  if (T.isOSAIX()) {
+llvm::Triple AIXTriple;
+if (T.getEnvironment() == Triple::UnknownEnvironment) {
+  // Strip unknown environment from the triple.

jakeegan wrote:

The reason I moved "Strip the OS version from the triple" a level higher is so 
it doesn't have to be repeated twice. But I'm fine with either way. I updated 
the PR as you said

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


[clang] [clang-format] Handle token-pasted function decl names (PR #142251)

2025-06-01 Thread Pierre Jolivet via cfe-commits

prj- wrote:

@owenca, this introduced multiple regressions (or maybe they are all the same), 
I do believe.
```diff
diff --git a/include/petsc/private/hashmap.h b/include/petsc/private/hashmap.h
index c48d69d73ce..265a968a95c 100644
--- a/include/petsc/private/hashmap.h
+++ b/include/petsc/private/hashmap.h
@@ -37,3 +37,3 @@ M*/
 #define PETSC_HASH_MAP_DECL(HashT, KeyType, ValType) \
-  typedef kh_##HashT##_t   *Petsc##HashT; \
+  typedef kh_##HashT##_t *Petsc##   HashT; \
   static inline PETSC_UNUSED PetscErrorCode Petsc##HashT##Create(Petsc##HashT 
*); \
diff --git a/include/petsc/private/logimpl.h b/include/petsc/private/logimpl.h
index 6645e51af15..59333efff6a 100644
--- a/include/petsc/private/logimpl.h
+++ b/include/petsc/private/logimpl.h
@@ -13,3 +13,3 @@
 #define PETSC_LOG_RESIZABLE_ARRAY(Container, Entry, Key, Constructor, 
Destructor, Equal) \
-  typedef struct _n_PetscLog##Container*PetscLog##Container; \
+  typedef struct _n_PetscLog##Container *PetscLog##Container; \
   static inline PETSC_UNUSED PetscErrorCode PetscLog##Container##Create(int, 
PetscLog##Container *); \
diff --git a/src/dm/impls/plex/plexgmsh.c b/src/dm/impls/plex/plexgmsh.c
index faa5033598d..662c1981f80 100644
--- a/src/dm/impls/plex/plexgmsh.c
+++ b/src/dm/impls/plex/plexgmsh.c
@@ -10,3 +10,3 @@
 static int Gmsh_LexOrder_##T##_##p[GmshNumNodes_##T(p)] = {-1}; \
-int   *lex  = 
Gmsh_LexOrder_##T##_##p; \
+int *lex= 
Gmsh_LexOrder_##T##_##p; \
 if (lex[0] == -1) (void)GmshLexOrder_##T(p, lex, 0); \
```
A reproducer is attached (`clang-format-21 --style=file:clang-format.txt 
foo.txt`), let me know if you want me to open an issue. 
[clang-format.txt](https://github.com/user-attachments/files/20545076/clang-format.txt)
  [foo.txt](https://github.com/user-attachments/files/20545081/foo.txt)

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


[clang] [PAuth] Use different discriminators for __int128_t / __uint128_t / _BitInt(n) (PR #140276)

2025-06-01 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,c -- 
clang/lib/AST/ASTContext.cpp clang/lib/Driver/ToolChains/Clang.cpp 
clang/lib/Frontend/CompilerInvocation.cpp 
clang/test/CodeGen/ptrauth-function-type-discriminator.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index cdf239e37..f6a06e291 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3402,7 +3402,8 @@ static void encodeTypeForFunctionPointerAuth(const 
ASTContext &Ctx,
   case Type::BitInt:
 if (Ctx.getLangOpts().PointerAuthFunctionTypeDiscrimination128) {
   const auto *BtTy = T->castAs();
-  OS << "D" << (BtTy->isUnsigned() ? "U" : "B") << BtTy->getNumBits() << 
"_";
+  OS << "D" << (BtTy->isUnsigned() ? "U" : "B") << BtTy->getNumBits()
+ << "_";
 } else
   OS << "?";
 return;
@@ -3414,14 +3415,16 @@ static void encodeTypeForFunctionPointerAuth(const 
ASTContext &Ctx,
 #define SIGNED_TYPE(Id, SingletonId)   
\
   case BuiltinType::Id:
\
 OS << (Kind == BuiltinType::Int128 &&  
\
-   Ctx.getLangOpts().PointerAuthFunctionTypeDiscrimination128 ?
\
-   "n" : "i"); 
\
+   Ctx.getLangOpts().PointerAuthFunctionTypeDiscrimination128  
\
+   ? "n"   
\
+   : "i"); 
\
 return;
 #define UNSIGNED_TYPE(Id, SingletonId) 
\
   case BuiltinType::Id:
\
 OS << (Kind == BuiltinType::UInt128 && 
\
-   Ctx.getLangOpts().PointerAuthFunctionTypeDiscrimination128 ?
\
-   "o" : "i"); 
\
+   Ctx.getLangOpts().PointerAuthFunctionTypeDiscrimination128  
\
+   ? "o"   
\
+   : "i"); 
\
 return;
 #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define BUILTIN_TYPE(Id, SingletonId)

``




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


[clang] [PAuth] Use different discriminators for __int128_t / __uint128_t / _BitInt(n) (PR #140276)

2025-06-01 Thread Anton Korobeynikov via cfe-commits

https://github.com/asl updated https://github.com/llvm/llvm-project/pull/140276

>From 21d2b2da72d9e8f3994cb913a86c093212bb8711 Mon Sep 17 00:00:00 2001
From: Anton Korobeynikov 
Date: Fri, 16 May 2025 19:25:57 +0300
Subject: [PATCH 1/2] [PAuth] Use different discriminators for __int128_t /
 __uint128_t / _BitInt(n) compared to other integer types when computing
 function pointer type discriminator.

These parameter types have different parameter passing ABI as compared to
ordinary integer types (e.g. require 2 registers instead of 1) and therefore
this parameter passing difference could potentially be exploited should function
pointer is substituted.
---
 clang/lib/AST/ASTContext.cpp  | 14 ++---
 .../ptrauth-function-type-discriminator.c | 31 +++
 2 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5044d7c33ec3c..3991c67036576 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3395,21 +3395,27 @@ static void encodeTypeForFunctionPointerAuth(const 
ASTContext &Ctx,
 
   // Don't bother discriminating based on these types.
   case Type::Pipe:
-  case Type::BitInt:
   case Type::ConstantMatrix:
 OS << "?";
 return;
 
+  case Type::BitInt: {
+const auto *BtTy = T->castAs();
+OS << "D" << (BtTy->isUnsigned() ? "U" : "B") << BtTy->getNumBits() << "_";
+return;
+  }
+
   case Type::Builtin: {
 const auto *BTy = T->castAs();
-switch (BTy->getKind()) {
+const auto Kind = BTy->getKind();
+switch (Kind) {
 #define SIGNED_TYPE(Id, SingletonId)   
\
   case BuiltinType::Id:
\
-OS << "i"; 
\
+OS << (Kind == BuiltinType::Int128 ? "n" : "i");   
\
 return;
 #define UNSIGNED_TYPE(Id, SingletonId) 
\
   case BuiltinType::Id:
\
-OS << "i"; 
\
+OS << (Kind == BuiltinType::UInt128 ? "o" : "i");  
\
 return;
 #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define BUILTIN_TYPE(Id, SingletonId)
diff --git a/clang/test/CodeGen/ptrauth-function-type-discriminator.c 
b/clang/test/CodeGen/ptrauth-function-type-discriminator.c
index 0952c1abf6c07..9bf4a8874c3c3 100644
--- a/clang/test/CodeGen/ptrauth-function-type-discriminator.c
+++ b/clang/test/CodeGen/ptrauth-function-type-discriminator.c
@@ -65,6 +65,37 @@ void (*fptr3)(void) = 
__builtin_ptrauth_sign_constant(&external_function, 2, 26)
 // CHECK: @fptr4 = global ptr ptrauth (ptr @external_function, i32 2, i64 26, 
ptr @fptr4)
 void (*fptr4)(void) = __builtin_ptrauth_sign_constant(&external_function, 2, 
__builtin_ptrauth_blend_discriminator(&fptr4, 26));
 
+extern void external_function_int(int);
+extern void external_function_char(char);
+extern void external_function_i128(__int128_t);
+extern void external_function_u128(__uint128_t);
+extern void external_function_b128(_BitInt(128));
+extern void external_function_b8(_BitInt(8));
+
+// Check discriminators of functions taking integer type arguments:
+
+//  - Builtin integer types should be discriminated equally (so, pointer to
+//  function taking int argument should accept function taking char argument
+//  - _BitInt types are guaranteed distinct and therefore should be 
discriminated
+//  differently
+//  - __int128_t / __uint128_t are passed differently than char / int / long
+//  (require two registers instead of one) and therefore should be 
discriminated
+//  differently.
+
+// CHECK: @fptr5 = global ptr ptrauth (ptr @external_function_int, i32 0, i64 
2712)
+// CHECK: @fptr6 = global ptr ptrauth (ptr @external_function_char, i32 0, i64 
2712)
+void (*fptr5)(int) = external_function_int;
+void (*fptr6)(char) = external_function_char;
+
+// CHECK: @fptr7 = global ptr ptrauth (ptr @external_function_i128, i32 0, i64 
23141)
+// CHECK: @fptr8 = global ptr ptrauth (ptr @external_function_u128, i32 0, i64 
45743)
+// CHECK: @fptr9 = global ptr ptrauth (ptr @external_function_b128, i32 0, i64 
17854)
+// CHECK: @fptr10 = global ptr ptrauth (ptr @external_function_b8, i32 0, i64 
26383)
+void (*fptr7)(__int128_t) = external_function_i128;
+void (*fptr8)(__uint128_t) = external_function_u128;
+void (*fptr9)(_BitInt(128)) = external_function_b128;
+void (*fptr10)(_BitInt(8)) = external_function_b8;
+
 // CHECK-LABEL: define{{.*}} void @test_call()
 void test_call() {
   // CHECK:  [[T0:%.*]] = load ptr, ptr @fnptr,

>From f89e872d240bd7f926d88b29741826643ed6c611 Mon Sep 17 00:00:00 2001
From: Anton Korobeynikov 
Date: Sun, 1 Jun 2025 23:55:32 -0700
Subject: [PATCH 2/2] Make type discrimination of 128-bit types optional

---
 clang/include/cla

[clang] [clang-format] Correctly annotate token-pasted function decl names (PR #142337)

2025-06-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fix #142178

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


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+2) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+7) 


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index da1b6dd5254b8..da279d07b5918 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3848,6 +3848,8 @@ static bool isFunctionDeclarationName(const LangOptions 
&LangOpts,
   } else {
 if (Current.isNot(TT_StartOfName) || Current.NestingLevel != 0)
   return false;
+while (Next && Next->startsSequence(tok::hashhash, tok::identifier))
+  Next = Next->Next->Next;
 for (; Next; Next = Next->Next) {
   if (Next->is(TT_TemplateOpener) && Next->MatchingParen) {
 Next = Next->MatchingParen;
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 1a5ed4b9040c2..9637085c70502 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2257,6 +2257,13 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsFunctionDeclarationNames) {
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_FunctionDeclarationLParen);
 
+  Tokens = annotate("#define FUNC(foo, bar) \\\n"
+"  auto foo##bar() -> Type {}");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_paren, TT_FunctionDeclarationLParen);
+  EXPECT_TOKEN(Tokens[14], tok::arrow, TT_TrailingReturnArrow);
+
   Tokens = annotate("int iso_time(time_t);");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);

``




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


[clang] [clang][AIX] Fix -print-runtime-dir fallback on AIX (PR #141439)

2025-06-01 Thread Jake Egan via cfe-commits

https://github.com/jakeegan updated 
https://github.com/llvm/llvm-project/pull/141439

>From b044f81c6d1ed67ce7ee27bce7a62d36b3841bad Mon Sep 17 00:00:00 2001
From: Jake Egan 
Date: Sun, 25 May 2025 19:40:59 -0400
Subject: [PATCH 1/4] Fix rt dir fallback

---
 clang/lib/Driver/ToolChain.cpp| 23 ++-
 clang/test/Driver/aix-print-runtime-dir.c |  9 -
 2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ce302b308fd19..2cf0030d4b97b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -933,11 +933,16 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   if (auto Path = getPathForTriple(T))
 return *Path;
 
-  if (T.isOSAIX() && T.getEnvironment() == Triple::UnknownEnvironment) {
-// Strip unknown environment from the triple.
-const llvm::Triple AIXTriple(
-llvm::Triple(T.getArchName(), T.getVendorName(),
- llvm::Triple::getOSTypeName(T.getOS(;
+  if (T.isOSAIX()) {
+llvm::Triple AIXTriple;
+if (T.getEnvironment() == Triple::UnknownEnvironment) {
+  // Strip unknown environment from the triple.
+  AIXTriple = llvm::Triple(T.getArchName(), T.getVendorName(),
+ llvm::Triple::getOSTypeName(T.getOS()));
+} else {
+  // Get the triple without the OS version.
+  AIXTriple = getTripleWithoutOSVersion();
+}
 if (auto Path = getPathForTriple(AIXTriple))
   return *Path;
   }
@@ -987,14 +992,6 @@ std::optional ToolChain::getRuntimePath() 
const {
   if (Triple.isOSDarwin())
 return {};
 
-  // For AIX, get the triple without the OS version.
-  if (Triple.isOSAIX()) {
-const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion();
-llvm::sys::path::append(P, TripleWithoutVersion.str());
-if (getVFS().exists(P))
-  return std::string(P);
-return {};
-  }
   llvm::sys::path::append(P, Triple.str());
   return std::string(P);
 }
diff --git a/clang/test/Driver/aix-print-runtime-dir.c 
b/clang/test/Driver/aix-print-runtime-dir.c
index ef133728d731f..4740129442540 100644
--- a/clang/test/Driver/aix-print-runtime-dir.c
+++ b/clang/test/Driver/aix-print-runtime-dir.c
@@ -1,13 +1,5 @@
 // Test output of -print-runtime-dir on AIX
 
-// RUN: %clang -print-runtime-dir --target=powerpc-ibm-aix \
-// RUN:-resource-dir=%S/Inputs/resource_dir \
-// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
-
-// RUN: %clang -print-runtime-dir --target=powerpc64-ibm-aix \
-// RUN:-resource-dir=%S/Inputs/resource_dir \
-// RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
-
 // RUN: %clang -print-runtime-dir --target=powerpc-ibm-aix \
 // RUN:-resource-dir=%S/Inputs/resource_dir_with_per_target_subdir\
 // RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR32-PER-TARGET %s
@@ -24,7 +16,6 @@
 // RUN:-resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN:  | FileCheck --check-prefix=PRINT-RUNTIME-DIR64-UNKNOWN-ENV %s 
 
-// PRINT-RUNTIME-DIR: lib{{/|\\}}aix{{$}}
 // PRINT-RUNTIME-DIR32-PER-TARGET: lib{{/|\\}}powerpc-ibm-aix{{$}}
 // PRINT-RUNTIME-DIR64-PER-TARGET: lib{{/|\\}}powerpc64-ibm-aix{{$}}
 // PRINT-RUNTIME-DIR32-UNKNOWN-ENV: lib{{/|\\}}powerpc-ibm-aix

>From 8b8f30e4ba7c9d9794dc35d55ab28df0e64ada80 Mon Sep 17 00:00:00 2001
From: Jake Egan 
Date: Sun, 25 May 2025 21:01:52 -0400
Subject: [PATCH 2/4] Fix formatting

---
 clang/lib/Driver/ToolChain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 2cf0030d4b97b..024d2534dd248 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -938,7 +938,7 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
 if (T.getEnvironment() == Triple::UnknownEnvironment) {
   // Strip unknown environment from the triple.
   AIXTriple = llvm::Triple(T.getArchName(), T.getVendorName(),
- llvm::Triple::getOSTypeName(T.getOS()));
+   llvm::Triple::getOSTypeName(T.getOS()));
 } else {
   // Get the triple without the OS version.
   AIXTriple = getTripleWithoutOSVersion();

>From 59a9976ef5468f49f9af57fae11100347db3590c Mon Sep 17 00:00:00 2001
From: Jake Egan 
Date: Mon, 26 May 2025 12:00:19 -0400
Subject: [PATCH 3/4] Move comment to apply to whole if statement

---
 clang/lib/Driver/ToolChain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 024d2534dd248..d3e5c3d69ecae 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -934,13 +934,13 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
 return *Path;
 
   if (T.isOSAIX()) {
+// Strip the OS version from the triple on AIX.
 llvm::Triple AIXTriple;
 if (T.getEnvir

[clang] [flang] [llvm] [TargetVerifier][AMDGPU] Add TargetVerifier. (PR #123609)

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


@@ -0,0 +1,170 @@
+//===-- AMDGPUTargetVerifier.cpp - AMDGPU ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines target verifier interfaces that can be used for some
+// validation of input to the system, and for checking that transformations
+// haven't done something bad. In contrast to the Verifier or Lint, the
+// TargetVerifier looks for constructions invalid to a particular target
+// machine.
+//
+// To see what specifically is checked, look at an individual backend's
+// TargetVerifier.
+//
+//===--===//
+
+#include "AMDGPU.h"
+
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/IntrinsicsAMDGPU.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Support/Debug.h"
+
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+// Check - We know that cond should be true, if not print an error message.
+#define Check(C, ...)  
\
+  do { 
\
+if (!(C)) {
\
+  TargetVerify::checkFailed(__VA_ARGS__);  
\
+}  
\
+  } while (false)
+
+namespace llvm {
+
+class AMDGPUTargetVerify : public TargetVerify {
+public:
+  AMDGPUTargetVerify(Module *Mod) : TargetVerify(Mod) {}
+  bool run(Function &F) override;
+};
+
+static bool isShader(CallingConv::ID CC) {
+  switch (CC) {
+  case CallingConv::AMDGPU_VS:
+  case CallingConv::AMDGPU_LS:
+  case CallingConv::AMDGPU_HS:
+  case CallingConv::AMDGPU_ES:
+  case CallingConv::AMDGPU_GS:
+  case CallingConv::AMDGPU_PS:
+  case CallingConv::AMDGPU_CS_Chain:
+  case CallingConv::AMDGPU_CS_ChainPreserve:
+  case CallingConv::AMDGPU_CS:
+return true;
+  default:
+return false;
+  }
+}
+
+bool AMDGPUTargetVerify::run(Function &F) {
+  // Ensure shader calling convention returns void
+  if (isShader(F.getCallingConv()))
+Check(F.getReturnType() == Type::getVoidTy(F.getContext()),
+  "Shaders must return void");
+
+  for (auto &BB : F) {
+
+for (auto &I : BB) {
+
+  if (auto *CI = dyn_cast(&I)) {
+// Ensure no kernel to kernel calls.
+CallingConv::ID CalleeCC = CI->getCallingConv();
+if (CalleeCC == CallingConv::AMDGPU_KERNEL) {
+  CallingConv::ID CallerCC =
+  CI->getParent()->getParent()->getCallingConv();
+  Check(CallerCC != CallingConv::AMDGPU_KERNEL,

shiltian wrote:

I think I already disallow this in the IR verifier.

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


[clang] [flang] [llvm] [TargetVerifier][AMDGPU] Add TargetVerifier. (PR #123609)

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


@@ -0,0 +1,170 @@
+//===-- AMDGPUTargetVerifier.cpp - AMDGPU ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines target verifier interfaces that can be used for some
+// validation of input to the system, and for checking that transformations
+// haven't done something bad. In contrast to the Verifier or Lint, the
+// TargetVerifier looks for constructions invalid to a particular target
+// machine.
+//
+// To see what specifically is checked, look at an individual backend's
+// TargetVerifier.
+//
+//===--===//
+
+#include "AMDGPU.h"
+
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/IntrinsicsAMDGPU.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Support/Debug.h"
+
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+// Check - We know that cond should be true, if not print an error message.
+#define Check(C, ...)  
\
+  do { 
\
+if (!(C)) {
\
+  TargetVerify::checkFailed(__VA_ARGS__);  
\
+}  
\
+  } while (false)
+
+namespace llvm {
+
+class AMDGPUTargetVerify : public TargetVerify {
+public:
+  AMDGPUTargetVerify(Module *Mod) : TargetVerify(Mod) {}
+  bool run(Function &F) override;
+};
+
+static bool isShader(CallingConv::ID CC) {
+  switch (CC) {
+  case CallingConv::AMDGPU_VS:
+  case CallingConv::AMDGPU_LS:
+  case CallingConv::AMDGPU_HS:
+  case CallingConv::AMDGPU_ES:
+  case CallingConv::AMDGPU_GS:
+  case CallingConv::AMDGPU_PS:
+  case CallingConv::AMDGPU_CS_Chain:
+  case CallingConv::AMDGPU_CS_ChainPreserve:
+  case CallingConv::AMDGPU_CS:
+return true;
+  default:
+return false;
+  }
+}
+
+bool AMDGPUTargetVerify::run(Function &F) {
+  // Ensure shader calling convention returns void
+  if (isShader(F.getCallingConv()))

shiltian wrote:

Based on previous discussion with @arsenm , this check should go to the IR 
verifier.

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


[clang] [RISCV] Add pre-defined macro tests for Andes vendor extension. NFC. (PR #141172)

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

tclin914 wrote:

Kindly ping.

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


[clang] [Clang][FMV] Stop emitting implicit default version using target_clones. (PR #141808)

2025-06-01 Thread Piyou Chen via cfe-commits

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

RISC-V part LGTM.

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


[clang] [RISCV] Add pre-defined macro tests for Andes vendor extension. NFC. (PR #141172)

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

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


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


[clang] [RISCV] Add pre-defined macro tests for Andes vendor extension. NFC. (PR #141172)

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

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

>From 036a3bd7024fe358d670b49d1d62bfe3cc0bc6d4 Mon Sep 17 00:00:00 2001
From: Jim Lin 
Date: Thu, 22 May 2025 15:05:30 +0800
Subject: [PATCH] [RISCV] Add pre-defined macro tests for Andes vendor
 extension. NFC.

---
 .../riscv-target-features-andes.c | 32 +++
 1 file changed, 32 insertions(+)
 create mode 100644 clang/test/Preprocessor/riscv-target-features-andes.c

diff --git a/clang/test/Preprocessor/riscv-target-features-andes.c 
b/clang/test/Preprocessor/riscv-target-features-andes.c
new file mode 100644
index 0..3cd9b04354132
--- /dev/null
+++ b/clang/test/Preprocessor/riscv-target-features-andes.c
@@ -0,0 +1,32 @@
+// RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -E -dM %s \
+// RUN:   -o - | FileCheck %s
+// RUN: %clang --target=riscv64-unknown-linux-gnu -march=rv64i -E -dM %s \
+// RUN:   -o - | FileCheck %s
+
+// CHECK-NOT: __riscv_xandesperf {{.*$}}
+// CHECK-NOT: __riscv_xandesvpackfph {{.*$}}
+// CHECK-NOT: __riscv_xandesvdot {{.*$}}
+
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_xandesperf -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESPERF %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_xandesperf -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESPERF %s
+// CHECK-XANDESPERF: __riscv_xandesperf  500{{$}}
+
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_xandesvpackfph -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESVPACKFPH %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_xandesvpackfph -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESVPACKFPH %s
+// CHECK-XANDESVPACKFPH: __riscv_xandesvpackfph  500{{$}}
+
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_xandesvdot -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESVDOT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_xandesvdot -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-XANDESVDOT %s
+// CHECK-XANDESVDOT: __riscv_xandesvdot  500{{$}}

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


[clang] c5cce48 - Revert "[clang-format] Handle token-pasted function decl names (#142251)"

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

Author: Owen Pan
Date: 2025-06-01T23:32:00-07:00
New Revision: c5cce4861cb011d10af7f6afba4176682f5f862f

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

LOG: Revert "[clang-format] Handle token-pasted function decl names (#142251)"

This reverts commit 29f79ea3c59649f7686a09845665660c25ca3f9b which caused a 
regression.

See https://github.com/llvm/llvm-project/pull/142251#issuecomment-2928718530.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 52100d195fe7a..da1b6dd5254b8 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3976,13 +3976,8 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
Tok; Tok = Tok->Next) {
 if (Tok->is(TT_StartOfName))
   SeenName = true;
-const auto *Previous = Tok->Previous;
-if (Previous->EndsCppAttributeGroup) {
+if (Tok->Previous->EndsCppAttributeGroup)
   AfterLastAttribute = Tok;
-} else if (Line.InMacroBody &&
-   Previous->endsSequence(tok::hashhash, TT_StartOfName)) {
-  Tok->setType(TT_StartOfName);
-}
 if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
 IsCtorOrDtor ||
 isFunctionDeclarationName(LangOpts, *Tok, Line, ClosingParen)) {

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ba6a9f813f052..1a5ed4b9040c2 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2257,13 +2257,6 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsFunctionDeclarationNames) {
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_FunctionDeclarationLParen);
 
-  Tokens = annotate("#define FUNC(foo, bar) \\\n"
-"  auto foo##bar() -> Type {}");
-  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
-  EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
-  EXPECT_TOKEN(Tokens[12], tok::l_paren, TT_FunctionDeclarationLParen);
-  EXPECT_TOKEN(Tokens[14], tok::arrow, TT_TrailingReturnArrow);
-
   Tokens = annotate("int iso_time(time_t);");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);



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


[clang] [Clang][OpenMP][LoopTransformations] Fix incorrect number of generated loops for Tile and Reverse directives (PR #140532)

2025-06-01 Thread Walter J.T.V via cfe-commits

eZWALT wrote:

gentle ping :)


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


[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread Vasiliy Kulikov via cfe-commits

https://github.com/segoon updated 
https://github.com/llvm/llvm-project/pull/139525

>From 3abbce9f817f6d09f9a5b7549a8122c80821eaf8 Mon Sep 17 00:00:00 2001
From: Vasily Kulikov 
Date: Mon, 12 May 2025 13:05:43 +0300
Subject: [PATCH 01/16] [clang-tidy] Add check performance-lost-std-move

---
 .../clang-tidy/performance/CMakeLists.txt |   1 +
 .../performance/LostStdMoveCheck.cpp  |  96 
 .../clang-tidy/performance/LostStdMoveCheck.h |  37 ++
 .../performance/PerformanceTidyModule.cpp |   2 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/performance/lost-std-move.rst  |  14 +++
 .../checkers/performance/lost-std-move.cpp| 108 ++
 8 files changed, 264 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/performance/lost-std-move.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/performance/lost-std-move.cpp

diff --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index 81128ff086021..333abd10a583a 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -12,6 +12,7 @@ add_clang_library(clangTidyPerformanceModule
   InefficientAlgorithmCheck.cpp
   InefficientStringConcatenationCheck.cpp
   InefficientVectorOperationCheck.cpp
+  LostStdMoveCheck.cpp
   MoveConstArgCheck.cpp
   MoveConstructorInitCheck.cpp
   NoAutomaticMoveCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp
new file mode 100644
index 0..26148e1d26de9
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/LostStdMoveCheck.cpp
@@ -0,0 +1,96 @@
+//===--- LostStdMoveCheck.cpp - clang-tidy 
===//
+//
+// 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 "LostStdMoveCheck.h"
+#include "../utils/DeclRefExprUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+using utils::decl_ref_expr::allDeclRefExprs;
+
+AST_MATCHER(CXXRecordDecl, hasTrivialMoveConstructor) {
+  return Node.hasDefinition() && Node.hasTrivialMoveConstructor();
+}
+
+void LostStdMoveCheck::registerMatchers(MatchFinder *Finder) {
+  auto returnParent =
+  hasParent(expr(hasParent(cxxConstructExpr(hasParent(returnStmt());
+
+  Finder->addMatcher(
+  declRefExpr(
+  // not "return x;"
+  unless(returnParent),
+
+  unless(hasType(namedDecl(hasName("::std::string_view",
+
+  // non-trivial type
+  hasType(hasCanonicalType(hasDeclaration(cxxRecordDecl(,
+
+  // non-trivial X(X&&)
+  unless(hasType(hasCanonicalType(
+  hasDeclaration(cxxRecordDecl(hasTrivialMoveConstructor()),
+
+  // Not in a cycle
+  unless(hasAncestor(forStmt())), unless(hasAncestor(doStmt())),
+  unless(hasAncestor(whileStmt())),
+
+  // only non-X&
+  unless(hasDeclaration(
+  varDecl(hasType(qualType(lValueReferenceType()),
+
+  hasDeclaration(
+  varDecl(hasAncestor(functionDecl().bind("func"))).bind("decl")),
+
+  hasParent(expr(hasParent(cxxConstructExpr())).bind("use_parent")))
+  .bind("use"),
+  this);
+}
+
+const Expr *LostStdMoveCheck::getLastVarUsage(const VarDecl &Var,
+  const Decl &Func,
+  ASTContext &Context) {
+  auto Exprs = allDeclRefExprs(Var, Func, Context);
+
+  const Expr *LastExpr = nullptr;
+  for (const auto &Expr : Exprs) {
+if (!LastExpr)
+  LastExpr = Expr;
+
+if (LastExpr->getBeginLoc() < Expr->getBeginLoc())
+  LastExpr = Expr;
+  }
+
+  return LastExpr;
+}
+
+void LostStdMoveCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedDecl = Result.Nodes.getNodeAs("decl");
+  const auto *MatchedFunc = Result.Nodes.getNodeAs("func");
+  const auto *MatchedUse = Result.Nodes.getNodeAs("use");
+  const auto *MatchedUseCall = Result.Nodes.getNodeAs("use_parent");
+
+  if (MatchedUseCall)
+return;
+
+  const auto *LastUsage =
+  getLastVarUsage(*MatchedDecl, *MatchedFunc, *Result.Context);
+  if (LastUsage == nullptr)
+return;
+
+  if (LastUsage->getBeginLoc() > MatchedUse->getBeginLoc()) {
+// "use" is not the last refe

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

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.

vbvictor wrote:

"conflicting" may not be very meaningful in this description, maybe use 
"unsequenced" just as in compiler flag?

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


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

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;
+int b = (a++) - a; // This is flagged by -Wunsequenced.
+
+However global variables allow for more complex scenarios that
+-Wunsequenced doesn't detect. E.g. ::
+
+int globalVar = 0;

vbvictor wrote:

ditto code-block

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


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

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -151,6 +157,14 @@ New checks
 New check aliases
 ^
 
+- New `cert-exp30-c ` alias for 

vbvictor wrote:

Please create entries in `docs/` folder for these aliases, they should have 
filling like this:
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/docs/clang-tidy/checks/cert/con54-cpp.rst


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


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

2025-06-01 Thread Baranov Victor via cfe-commits

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


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

2025-06-01 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor commented:

Mostly left comments in docs about general improvements. Didn't look closely at 
the code, but here are some general recommendations that you should do before 
major review:

There are a lot of new code that is relatively hard to review, you should try 
to follow [LLVM coding 
guidelines](https://llvm.org/docs/CodingStandards.html#style-issues), most 
importantly these:
- [Don’t Use Braces on Simple Single-Statement Bodies of if/else/loop 
Statements](https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements)
 (many violations, with this fix the code should become smaller by line count, 
thus easier to review)
- [Use range-based for loops wherever 
possible](https://llvm.org/docs/CodingStandards.html#use-range-based-for-loops-wherever-possible)

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


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

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;
+int b = (a++) - a; // This is flagged by -Wunsequenced.
+
+However global variables allow for more complex scenarios that
+-Wunsequenced doesn't detect. E.g. ::
+
+int globalVar = 0;
+
+int incFun() {
+  globalVar++;
+  return globalVar;
+}
+
+int main() {
+  return globalVar + incFun(); // This is not detected by -Wunsequenced.
+}
+
+This checker attempts to detect such cases. It recurses into functions that are
+inside the same translation unit. It also attempts not to flag cases that are
+already covered by -Wunsequenced. Global unions and structs are also handled.
+For example::
+
+typedef struct {
+int A;
+float B;
+} IntAndFloat;
+
+IntAndFloat GlobalIF;
+
+int globalIFGetSum() {
+int sum = GlobalIF.A + (int)GlobalIF.B;
+GlobalIF = (IntAndFloat){};
+return sum;
+}
+
+int main() {
+// The following printf could give different results on different
+// compilers.
+printf("sum: %i, int: %i", globalIFGetSum(), GlobalIF.A);
+}
+
+Options
+---
+
+.. option:: HandleMutableFunctionParametersAsWrites
+
+It's possible to enable handling mutable reference and pointer function
+parameters as writes using the HandleMutableFunctionParametersAsWrites
+option. For example:

vbvictor wrote:

This option need some rephrasing and clarification IMO.
It should be something like:
"When \`true\`, treat calls of functions that accept a mutable reference or a 
pointer as a write to the variable that was passed to the function."
I'm not totally satisfied with my wording, but I tried to eliminate this 
ambiguity: 
What does "handling parameters as writes" mean here? Especially word "handling".

Also, give an example of some real code that doesn't get flagged without this 
option and gets flagged with the option enabled.

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


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

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;

vbvictor wrote:

use `.. code-block:: c++` for c++ code-blocks in docs

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


[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,32 @@
+.. title:: clang-tidy - performance-lost-std-move
+
+performance-lost-std-move
+=
+
+Warns if copy constructor is used instead of std::move() and suggests a fix.
+It honours cycles, lambdas, and unspecified call order in compound expressions.
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ f(x);  // warning: Could be std::move() [performance-lost-std-move]
+   }
+
+It finds the last local variable usage, and if it is a copy, emits a warning.
+The check is based on pure AST matching and doesn't take into account any data 
flow information.
+Thus, it doesn't catch assign-after-copy cases.
+Also it doesn't notice variable references "behind the scenes":
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ auto &y = x;
+ f(x);  // emits a warning...
+ y.f();  // ...but it is still used
+   }
+
+Such rare cases should be silenced using `// NOLINT`.

EugeneZelenko wrote:

Should general functionality be mentioned?

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


[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,186 @@
+//===--- LostStdMoveCheck.cpp - clang-tidy 
===//
+//
+// 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 "LostStdMoveCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+template 
+void extractNodesByIdTo(ArrayRef Matches, StringRef ID,
+llvm::SmallPtrSet &Nodes) {
+  for (const BoundNodes &Match : Matches)
+Nodes.insert(Match.getNodeAs(ID));
+}
+
+static llvm::SmallPtrSet
+allDeclRefExprsHonourLambda(const VarDecl &VarDecl, const Decl &Decl,
+ASTContext &Context) {
+  auto Matches = match(
+  decl(forEachDescendant(
+  declRefExpr(to(varDecl(equalsNode(&VarDecl))),
+

EugeneZelenko wrote:

Excessive newline. Same in other places.

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


[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread via cfe-commits


@@ -136,6 +136,12 @@ New checks
   Finds unintended character output from ``unsigned char`` and ``signed char``
   to an ``ostream``.
 
+- New :doc:`performance-lost-std-move
+  ` check.
+
+  Warns if copy constructor is used instead of std::move() and suggests a fix.

EugeneZelenko wrote:

```suggestion
  Warns if copy constructor is used instead of ``std::move()`` and suggests a 
fix.
```

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


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

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;
+int b = (a++) - a; // This is flagged by -Wunsequenced.
+
+However global variables allow for more complex scenarios that
+-Wunsequenced doesn't detect. E.g. ::
+
+int globalVar = 0;
+
+int incFun() {
+  globalVar++;
+  return globalVar;
+}
+
+int main() {
+  return globalVar + incFun(); // This is not detected by -Wunsequenced.
+}
+
+This checker attempts to detect such cases. It recurses into functions that are
+inside the same translation unit. It also attempts not to flag cases that are
+already covered by -Wunsequenced. Global unions and structs are also handled.
+For example::
+
+typedef struct {

vbvictor wrote:

ditto code-block

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


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

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.

vbvictor wrote:

I think you should not explicitly exclude cases that are covered by 
"-Wunsequenced". It's okay for check to have duplicate functionality with 
compiler flags. Moreover, for gcc there is "-Wsequence-point" and we don't know 
to what extent "-Wunsequenced" can find bugs, so It's better just to mention 
that functionality of this check may overlap with existing compiler flags such 
as "-Wunsequenced", "-Wsequence-point".

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


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

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;
+int b = (a++) - a; // This is flagged by -Wunsequenced.
+
+However global variables allow for more complex scenarios that
+-Wunsequenced doesn't detect. E.g. ::
+
+int globalVar = 0;
+
+int incFun() {
+  globalVar++;
+  return globalVar;
+}
+
+int main() {
+  return globalVar + incFun(); // This is not detected by -Wunsequenced.
+}
+
+This checker attempts to detect such cases. It recurses into functions that are
+inside the same translation unit. It also attempts not to flag cases that are
+already covered by -Wunsequenced. Global unions and structs are also handled.
+For example::
+
+typedef struct {
+int A;
+float B;
+} IntAndFloat;
+
+IntAndFloat GlobalIF;
+
+int globalIFGetSum() {
+int sum = GlobalIF.A + (int)GlobalIF.B;
+GlobalIF = (IntAndFloat){};
+return sum;
+}
+
+int main() {
+// The following printf could give different results on different
+// compilers.
+printf("sum: %i, int: %i", globalIFGetSum(), GlobalIF.A);
+}
+
+Options
+---
+
+.. option:: HandleMutableFunctionParametersAsWrites
+
+It's possible to enable handling mutable reference and pointer function
+parameters as writes using the HandleMutableFunctionParametersAsWrites

EugeneZelenko wrote:

```suggestion
parameters as writes using the `HandleMutableFunctionParametersAsWrites`
```

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


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

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;
+int b = (a++) - a; // This is flagged by -Wunsequenced.
+
+However global variables allow for more complex scenarios that
+-Wunsequenced doesn't detect. E.g. ::

EugeneZelenko wrote:

```suggestion
`-Wunsequenced` doesn't detect. E.g. ::
```

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


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

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;
+int b = (a++) - a; // This is flagged by -Wunsequenced.
+
+However global variables allow for more complex scenarios that
+-Wunsequenced doesn't detect. E.g. ::
+
+int globalVar = 0;
+
+int incFun() {
+  globalVar++;
+  return globalVar;
+}
+
+int main() {
+  return globalVar + incFun(); // This is not detected by -Wunsequenced.
+}
+
+This checker attempts to detect such cases. It recurses into functions that are

EugeneZelenko wrote:

```suggestion
This check attempts to detect such cases. It recurses into functions that are
```

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


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

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,

EugeneZelenko wrote:

```suggestion
unspecified order. This check is similar to the `-Wunsequenced` Clang warning,
```

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


[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,32 @@
+.. title:: clang-tidy - performance-lost-std-move
+
+performance-lost-std-move
+=
+
+Warns if copy constructor is used instead of std::move() and suggests a fix.

EugeneZelenko wrote:

```suggestion
Warns if copy constructor is used instead of ``std::move()`` and suggests a fix.
```

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


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

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.
+
+Modifying twice or reading and modifying a memory location without a
+defined sequence of the operations is either undefined behavior or has
+unspecified order. This checker is similar to the -Wunsequenced clang warning,
+however it only looks at global variables and therefore can find conflicting
+actions recursively inside functions as well.
+
+For example::
+
+int a = 0;
+int b = (a++) - a; // This is flagged by -Wunsequenced.
+
+However global variables allow for more complex scenarios that
+-Wunsequenced doesn't detect. E.g. ::
+
+int globalVar = 0;
+
+int incFun() {
+  globalVar++;
+  return globalVar;
+}
+
+int main() {
+  return globalVar + incFun(); // This is not detected by -Wunsequenced.
+}
+
+This checker attempts to detect such cases. It recurses into functions that are
+inside the same translation unit. It also attempts not to flag cases that are
+already covered by -Wunsequenced. Global unions and structs are also handled.

EugeneZelenko wrote:

```suggestion
already covered by `-Wunsequenced`. Global unions and structs are also handled.
```

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


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

2025-06-01 Thread via cfe-commits


@@ -0,0 +1,72 @@
+.. title:: clang-tidy - bugprone-conflicting-global-accesses
+
+bugprone-conflicting-global-accesses
+
+
+Finds conflicting accesses on global variables.

EugeneZelenko wrote:

Please synchronize first statement with Release Notes.

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


[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -9,15 +9,16 @@
 
 #include 
 #include 
+#include 
 
 namespace absl
 {
 // Use const char * for the format since the real type is hard to mock up.

vbvictor wrote:

Unnecessary comment for now?

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


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-01 Thread Abid Qadeer via cfe-commits

https://github.com/abidh updated 
https://github.com/llvm/llvm-project/pull/140556

>From 5d20af48673adebc2ab3e1a6c8442f67d84f1847 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Mon, 19 May 2025 15:21:25 +0100
Subject: [PATCH 1/8] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS.

This PR add functionality to change flang command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to
what `CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but
I am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
---
 clang/include/clang/Driver/Driver.h |  2 +-
 clang/lib/Driver/Driver.cpp |  4 ++--
 clang/tools/driver/driver.cpp   |  2 +-
 flang/test/Driver/fcc_override.f90  | 12 
 flang/tools/flang-driver/driver.cpp |  7 +++
 5 files changed, 23 insertions(+), 4 deletions(-)
 create mode 100644 flang/test/Driver/fcc_override.f90

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index b463dc2a93550..7ca848f11b561 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -879,7 +879,7 @@ llvm::Error expandResponseFiles(SmallVectorImpl &Args,
 /// See applyOneOverrideOption.
 void applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideOpts,
-  llvm::StringSet<> &SavedStrings,
+  llvm::StringSet<> &SavedStrings, StringRef EnvVar,
   raw_ostream *OS = nullptr);
 
 } // end namespace driver
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a648cc928afdc..a8fea35926a0d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -7289,7 +7289,7 @@ static void applyOneOverrideOption(raw_ostream &OS,
 void driver::applyOverrideOptions(SmallVectorImpl &Args,
   const char *OverrideStr,
   llvm::StringSet<> &SavedStrings,
-  raw_ostream *OS) {
+  StringRef EnvVar, raw_ostream *OS) {
   if (!OS)
 OS = &llvm::nulls();
 
@@ -7298,7 +7298,7 @@ void driver::applyOverrideOptions(SmallVectorImpl &Args,
 OS = &llvm::nulls();
   }
 
-  *OS << "### CCC_OVERRIDE_OPTIONS: " << OverrideStr << "\n";
+  *OS << "### " << EnvVar << ": " << OverrideStr << "\n";
 
   // This does not need to be efficient.
 
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 82f47ab973064..81964c65c2892 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -305,7 +305,7 @@ int clang_main(int Argc, char **Argv, const 
llvm::ToolContext &ToolContext) {
   if (const char *OverrideStr = ::getenv("CCC_OVERRIDE_OPTIONS")) {
 // FIXME: Driver shouldn't take extra initial argument.
 driver::applyOverrideOptions(Args, OverrideStr, SavedStrings,
- &llvm::errs());
+ "CCC_OVERRIDE_OPTIONS", &llvm::errs());
   }
 
   std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes);
diff --git a/flang/test/Driver/fcc_override.f90 
b/flang/test/Driver/fcc_override.f90
new file mode 100644
index 0..55a07803fdde5
--- /dev/null
+++ b/flang/test/Driver/fcc_override.f90
@@ -0,0 +1,12 @@
+! RUN: env FCC_OVERRIDE_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa 
Omagic ^-###  " %flang -target x86_64-unknown-linux-gnu %s -O2 b -O3 2>&1 | 
FileCheck %s
+! RUN: env FCC_OVERRIDE_OPTIONS="x-Werror +-g" %flang -target 
x86_64-unknown-linux-gnu -Werror %s -c -### 2>&1 | FileCheck %s 
-check-prefix=RM-WERROR
+
+! CHECK: "-fc1"
+! CHECK-NOT: "-Oignore"
+! CHECK: "-Omagic"
+! CHECK-NOT: "-Oignore"
+
+! RM-WERROR: ### FCC_OVERRIDE_OPTIONS: x-Werror +-g
+! RM-WERROR-NEXT: ### Deleting argument -Werror
+! RM-WERROR-NEXT: ### Adding argument -g at end
+! RM-WERROR-NOT: "-Werror"
diff --git a/flang/tools/flang-driver/driver.cpp 
b/flang/tools/flang-driver/driver.cpp
index ed52988feaa59..ad0efa3279cef 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -111,6 +111,13 @@ int main(int argc, const char **argv) {
 }
   }
 
+  llvm::StringSet<> SavedStrings;
+  // Handle FCC_OVERRIDE_OPTIONS, used for editing a command line behind the
+  // scenes.
+  if (const char *OverrideStr = ::getenv("FCC_OVERRIDE_OPTIONS"))
+clang::driver::applyOverrideOptions(args, OverrideStr, SavedStrings,
+"FCC_OVERRIDE_OPTIONS", &llvm::errs());
+
   // Not in the frontend mode - continue in the compiler driver mode.
 
   // Create DiagnosticsEngine for the compiler driver

>From d1f2c9b8abd2690612a4b886a7a85b8e7f57d359 Mon Sep 17 00:00:00 2001
From: Abid Qadeer 
Date: Thu, 29 May 2025 11:05:57 +0100
Subject:

[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-01 Thread Abid Qadeer via cfe-commits


@@ -614,3 +614,30 @@ nvfortran defines `-fast` as
  - `-Mcache_align`: there is no equivalent flag in Flang or Clang.
  - `-Mflushz`: flush-to-zero mode - when `-ffast-math` is specified, Flang will
link to `crtfastmath.o` to ensure denormal numbers are flushed to zero.
+
+
+## FCC_OVERRIDE_OPTIONS
+
+The environment variable `FCC_OVERRIDE_OPTIONS` can be used to edit flang's
+command line arguments. The value of this variable is a space-separated list of
+edits to perform. The edits are applied in the order in which they appear in
+`FCC_OVERRIDE_OPTIONS`. Each edit should be one of the following forms:
+
+- `#`: Silence information about the changes to the command line arguments.
+
+- `^FOO`: Add `FOO` as a new argument at the beginning of the command line.

abidh wrote:

I have added "right after the name of the compiler executable" in both places. 
Hopefully that is enough to make it clear.

https://github.com/llvm/llvm-project/pull/140556
___
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-01 Thread Amr Hesham via cfe-commits


@@ -2156,6 +2156,50 @@ def VecCmpOp : CIR_Op<"vec.cmp", [Pure, 
SameTypeOperands]> {
   }];
 }
 
+//===--===//
+// VecShuffleOp
+//===--===//
+
+// TODO: Create an interface that both VecShuffleOp and VecShuffleDynamicOp
+// implement.  This could be useful for passes that don't care how the vector
+// shuffle was specified.
+
+def VecShuffleOp : CIR_Op<"vec.shuffle",
+   [Pure, AllTypesMatch<["vec1", "vec2"]>]> {
+  let summary = "Combine two vectors using indices passed as constant 
integers";
+  let description = [{
+The `cir.vec.shuffle` operation implements the documented form of Clang's
+__builtin_shufflevector, where the indices of the shuffled result are
+integer constants.
+
+The two input vectors, which must have the same type, are concatenated.
+Each of the integer constant arguments is interpreted as an index into that
+concatenated vector, with a value of -1 meaning that the result value
+doesn't matter. The result vector, which must have the same element type as
+the input vectors and the same number of elements as the list of integer
+constant indices, is constructed by taking the elements at the given
+indices from the concatenated vector.
+
+```mlir
+%new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<2 x !s32i>)
+[#cir.int<3> : !s64i, #cir.int<1> : !s64i] : !cir.vector<2 x !s32i>
+```
+  }];
+
+  let arguments = (ins
+CIR_VectorType:$vec1,
+CIR_VectorType:$vec2,
+TypedArrayAttrBase:$indices

AmrDeveloper wrote:

My idea was to move the constraints `mlir::isa` from the verifier 
to the td, so i used IntAttr, i move it to `CIRAttrConstraints.td` and check 
the other options too

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-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread Mike Crowe via cfe-commits


@@ -16,8 +16,8 @@
 
 namespace absl
 {
-template 
-std::string StrFormat(const S &format, const Args&... args);
+template 
+std::string StrFormat(const std::string &format, const Args&... args);

mikecrowe wrote:

`std::string` probably works just as well but I ought to be consistent so I'll 
change it.

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


[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread Mike Crowe via cfe-commits


@@ -9,15 +9,16 @@
 
 #include 
 #include 
+#include 
 
 namespace absl
 {
 // Use const char * for the format since the real type is hard to mock up.

mikecrowe wrote:

It should really say `std::string_view`, but the same is true in other files 
which lack the comment, so I might as well remove it as you suggest.

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


[clang] [flang] [flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (PR #140556)

2025-06-01 Thread Abid Qadeer via cfe-commits


@@ -614,3 +614,30 @@ nvfortran defines `-fast` as
  - `-Mcache_align`: there is no equivalent flag in Flang or Clang.
  - `-Mflushz`: flush-to-zero mode - when `-ffast-math` is specified, Flang will
link to `crtfastmath.o` to ensure denormal numbers are flushed to zero.
+
+
+## FCC_OVERRIDE_OPTIONS

abidh wrote:

I will add clang documentation in a separate PR. The `FCC_OVERRIDE_OPTIONS` one 
can then probably just refer to it.

https://github.com/llvm/llvm-project/pull/140556
___
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-01 Thread Paul Kirth via cfe-commits


@@ -26,6 +26,66 @@
 namespace clang {
 namespace doc {
 
+CommentKind stringToCommentKind(llvm::StringRef KindStr) {
+  if (KindStr == "FullComment")
+return CommentKind::CK_FullComment;

ilovepi wrote:

IDK if the huge set of conditionals is great. There are a lot of options here, 
even in C++17 (though 20 or 23 would add more).  The simplest is to have a 
const table of string literals with some static asserts about the enum value 
range and the size of the table (e.g. the number of elements in the enum 
matches the array bounds.

It may be worth seeing how tablegen handles this, since I think it generates a 
large number of such conversions. There are also data structures in ADT that 
could help. I know we have a suffix tree, and a number of map types.

That said StringMap seems preferable over the number of string comparisons 
happening here, so if we can't do something clever w/ constexpr or templates 
(even then I wouldn't want anything *too* complicated), lets make this a const 
initialized StringMap, and just do the lookup.

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-01 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi edited 
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] [CIR] Upstream ShuffleOp for VectorType (PR #142288)

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

AmrDeveloper wrote:

> Quoiting the docs: the result of `__builtin_shufflevector` is a vector with 
> the same element type as `vec1` and `vec2` but that has an element count 
> equal to the number of indices specified.

Thank you, i will put it back to the description

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-tools-extra] Refactor clang doc comment structure (PR #142273)

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

https://github.com/ilovepi commented:

I'll take another pass later in the week, but here are some initial 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] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe updated 
https://github.com/llvm/llvm-project/pull/142312

>From b334ec47c79098f7b370bdba0bcc0bbaced1f96d Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Thu, 29 May 2025 21:19:11 +0100
Subject: [PATCH 1/3] [clang-tidy] modernize-use-std-print,format: Fix checks
 with Abseil functions

These checks previously failed with absl::StrFormat and absl::PrintF
etc. with:

 Unable to use 'std::format' instead of 'StrFormat' because first
 argument is not a narrow string literal [modernize-use-std-format]

because FormatStringConverter was rejecting the format string if it had
already converted into a different type. Fix the tests so that they
check this case properly by accepting string_view rather than const char
* and fix the check so that these tests pass. Update the existing tests
that checked for the error message that can no longer happen.

Fixes: https://github.com/llvm/llvm-project/issues/129484
---
 .../utils/FormatStringConverter.cpp   |  8 ++
 clang-tools-extra/docs/ReleaseNotes.rst   | 10 
 .../modernize/use-std-format-custom.cpp   | 17 -
 .../checkers/modernize/use-std-format.cpp |  4 +--
 .../checkers/modernize/use-std-print-absl.cpp |  5 ++--
 .../modernize/use-std-print-custom.cpp| 25 ---
 6 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp 
b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
index 7f4ccca84faa5..e1c1bee97f6d4 100644
--- a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
@@ -207,13 +207,9 @@ FormatStringConverter::FormatStringConverter(
   ArgsOffset(FormatArgOffset + 1), LangOpts(LO) {
   assert(ArgsOffset <= NumArgs);
   FormatExpr = llvm::dyn_cast(
-  Args[FormatArgOffset]->IgnoreImplicitAsWritten());
+  Args[FormatArgOffset]->IgnoreUnlessSpelledInSource());
 
-  if (!FormatExpr || !FormatExpr->isOrdinary()) {
-// Function must have a narrow string literal as its first argument.
-conversionNotPossible("first argument is not a narrow string literal");
-return;
-  }
+  assert(FormatExpr && FormatExpr->isOrdinary());
 
   if (const std::optional MaybeMacroName =
   formatStringContainsUnreplaceableMacro(Call, FormatExpr, SM, PP);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e0f81a032c38d..69527f78eb8a9 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -232,10 +232,20 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-std-format
+  ` check to correctly match
+  when the format string is converted to a different type by an implicit
+  constructor call.
+
 - Improved :doc:`modernize-use-std-numbers
   ` check to support math
   functions of different precisions.
 
+- Improved :doc:`modernize-use-std-print
+  ` check to correctly match
+  when the format string is converted to a different type by an implicit
+  constructor call.
+
 - Improved :doc:`performance-move-const-arg
   ` check by fixing false
   negatives on ternary operators calling ``std::move``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
index 7da0bb02ad766..0f3458e61856a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
@@ -2,7 +2,7 @@
 // RUN:   -std=c++20 %s modernize-use-std-format %t --  \
 // RUN:   -config="{CheckOptions: { \
 // RUN:  modernize-use-std-format.StrictMode: true, \
-// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; bad_format_type_strprintf', \
+// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; any_format_type_strprintf', \
 // RUN:  modernize-use-std-format.ReplacementFormatFunction: 
'fmt::format', \
 // RUN:  modernize-use-std-format.FormatHeader: '' \
 // RUN:}}"  \
@@ -10,7 +10,7 @@
 // RUN: %check_clang_tidy -check-suffixes=,NOTSTRICT\
 // RUN:   -std=c++20 %s modernize-use-std-format %t --  \
 // RUN:   -config="{CheckOptions: { \
-// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; bad_format_type_strprintf', \
+// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; myn

[clang-tools-extra] [clang-tidy] Add check performance-lost-std-move (PR #139525)

2025-06-01 Thread Vasiliy Kulikov via cfe-commits


@@ -0,0 +1,32 @@
+.. title:: clang-tidy - performance-lost-std-move
+
+performance-lost-std-move
+=
+
+Warns if copy constructor is used instead of std::move() and suggests a fix.
+It honours cycles, lambdas, and unspecified call order in compound expressions.
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ f(x);  // warning: Could be std::move() [performance-lost-std-move]
+   }
+
+It finds the last local variable usage, and if it is a copy, emits a warning.
+The check is based on pure AST matching and doesn't take into account any data 
flow information.
+Thus, it doesn't catch assign-after-copy cases.
+Also it doesn't notice variable references "behind the scenes":
+
+.. code-block:: c++
+
+   void f(X);
+
+   void g(X x) {
+ auto &y = x;
+ f(x);  // emits a warning...
+ y.f();  // ...but it is still used
+   }

segoon wrote:

The problem is that any binding to a reference should skip the check. E.g.
```
void f(X);
void g(X&);

void func(X x) {
  g(x); // reference is created, we may not move from x anymore
  f(x); // no fix
}
```
I'm afraid too many cases are skipped due to this problem.

https://github.com/llvm/llvm-project/pull/139525
___
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-01 Thread Amr Hesham via cfe-commits

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

>From 1080f1cb13950b3fbeb1536227ee61e2ade9eac7 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 31 May 2025 19:53:56 +0200
Subject: [PATCH 1/2] [CIR] Upstream ShuffleOp for VectorType

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 44 +++
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp| 21 +++--
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 24 ++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 18 
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h   | 10 +
 clang/test/CIR/CodeGen/vector-ext.cpp | 25 +++
 clang/test/CIR/CodeGen/vector.cpp | 27 +++-
 clang/test/CIR/IR/invalid-vector.cir  | 38 
 8 files changed, 203 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 07851610a2abd..c176719941fc6 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2156,6 +2156,50 @@ def VecCmpOp : CIR_Op<"vec.cmp", [Pure, 
SameTypeOperands]> {
   }];
 }
 
+//===--===//
+// VecShuffleOp
+//===--===//
+
+// TODO: Create an interface that both VecShuffleOp and VecShuffleDynamicOp
+// implement.  This could be useful for passes that don't care how the vector
+// shuffle was specified.
+
+def VecShuffleOp : CIR_Op<"vec.shuffle",
+   [Pure, AllTypesMatch<["vec1", "vec2"]>]> {
+  let summary = "Combine two vectors using indices passed as constant 
integers";
+  let description = [{
+The `cir.vec.shuffle` operation implements the documented form of Clang's
+__builtin_shufflevector, where the indices of the shuffled result are
+integer constants.
+
+The two input vectors, which must have the same type, are concatenated.
+Each of the integer constant arguments is interpreted as an index into that
+concatenated vector, with a value of -1 meaning that the result value
+doesn't matter. The result vector, which must have the same element type as
+the input vectors and the same number of elements as the list of integer
+constant indices, is constructed by taking the elements at the given
+indices from the concatenated vector.
+
+```mlir
+%new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<2 x !s32i>)
+[#cir.int<3> : !s64i, #cir.int<1> : !s64i] : !cir.vector<2 x !s32i>
+```
+  }];
+
+  let arguments = (ins
+CIR_VectorType:$vec1,
+CIR_VectorType:$vec2,
+TypedArrayAttrBase:$indices
+  );
+
+  let results = (outs CIR_VectorType:$result);
+  let assemblyFormat = [{
+`(` $vec1 `,` $vec2 `:` qualified(type($vec1)) `)` $indices `:`
+ qualified(type($result)) attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 
//===--===//
 // VecShuffleDynamicOp
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 8448c164a5e58..4b7dd75457d6a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -180,9 +180,24 @@ class ScalarExprEmitter : public 
StmtVisitor {
   cgf.getLoc(e->getSourceRange()), inputVec, indexVec);
 }
 
-cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
-   "ShuffleVectorExpr with indices");
-return {};
+mlir::Value vec1 = Visit(e->getExpr(0));
+mlir::Value vec2 = Visit(e->getExpr(1));
+
+// The documented form of __builtin_shufflevector, where the indices are
+// a variable number of integer constants. The constants will be stored
+// in an ArrayAttr.
+SmallVector indices;
+for (unsigned i = 2; i < e->getNumSubExprs(); ++i) {
+  indices.push_back(
+  cir::IntAttr::get(cgf.builder.getSInt64Ty(),
+e->getExpr(i)
+->EvaluateKnownConstInt(cgf.getContext())
+.getSExtValue()));
+}
+
+return cgf.builder.create(
+cgf.getLoc(e->getSourceRange()), cgf.convertType(e->getType()), vec1,
+vec2, cgf.builder.getArrayAttr(indices));
   }
 
   mlir::Value VisitConvertVectorExpr(ConvertVectorExpr *e) {
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 36f050de9f8bb..8ca150cba975c 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -21,6 +21,7 @@
 #include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
 #include "clang/CIR/Dialect/IR/CIROpsEnums.cpp.inc"
 #include "clang/CIR/MissingFeatures.h"
+
 #include 
 
 using namespace mlir;
@@

[clang] [CIR] Implement folder for VecShuffleDynamicOp (PR #142315)

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

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

This change adds a folder for the VecShuffleDynamicOp

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

>From a2eaa7f28e912f6aa0df909995ec2daf665fbf4d Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sun, 1 Jun 2025 19:07:56 +0200
Subject: [PATCH] [CIR] Implement folder for VecShuffleDynamicOp

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  1 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 32 +++
 .../Dialect/Transforms/CIRCanonicalize.cpp|  6 ++--
 .../vector-shuffle-dynamic-fold.cir   | 18 +++
 4 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CIR/Transforms/vector-shuffle-dynamic-fold.cir

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 07851610a2abd..4442c3a5607ae 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2188,6 +2188,7 @@ def VecShuffleDynamicOp : CIR_Op<"vec.shuffle.dynamic",
   }];
 
   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 36f050de9f8bb..90b32950e4774 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1579,6 +1579,38 @@ OpFoldResult cir::VecExtractOp::fold(FoldAdaptor 
adaptor) {
 // VecShuffleDynamicOp
 
//===--===//
 
+OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute vec = adaptor.getVec();
+  mlir::Attribute indices = adaptor.getIndices();
+  if (mlir::isa_and_nonnull(vec) &&
+  mlir::isa_and_nonnull(indices)) {
+auto vecAttr = mlir::cast(vec);
+auto indicesAttr = mlir::cast(indices);
+auto vecTy = cast(vecAttr.getType());
+
+mlir::ArrayAttr vecElts = vecAttr.getElts();
+mlir::ArrayAttr indicesElts = indicesAttr.getElts();
+
+const uint64_t numElements = vecElts.size();
+
+SmallVector elements;
+elements.reserve(numElements);
+
+const uint64_t maskBits = llvm::NextPowerOf2(numElements - 1) - 1;
+for (uint64_t i = 0; i < numElements; i++) {
+  cir::IntAttr idxAttr = mlir::cast(indicesElts[i]);
+  uint64_t idxValue = idxAttr.getUInt();
+  uint64_t newIdx = idxValue & maskBits;
+  elements.push_back(vecElts[newIdx]);
+}
+
+return cir::ConstVectorAttr::get(
+vecTy, mlir::ArrayAttr::get(getContext(), elements));
+  }
+
+  return {};
+}
+
 LogicalResult cir::VecShuffleDynamicOp::verify() {
   // The number of elements in the two input vectors must match.
   if (getVec().getType().getSize() !=
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp 
b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index fb000adee04c6..7d03e374c27e8 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 and VecExtractOp are here to perform a manual `fold` in
-// applyOpPatternsGreedily.
+// CastOp, UnaryOp, VecExtractOp and VecShuffleDynamicOp are here to 
perform
+// a manual `fold` in applyOpPatternsGreedily.
 if (isa(op))
+VecExtractOp, VecShuffleDynamicOp>(op))
   ops.push_back(op);
   });
 
diff --git a/clang/test/CIR/Transforms/vector-shuffle-dynamic-fold.cir 
b/clang/test/CIR/Transforms/vector-shuffle-dynamic-fold.cir
new file mode 100644
index 0..db5d6bff04d5b
--- /dev/null
+++ b/clang/test/CIR/Transforms/vector-shuffle-dynamic-fold.cir
@@ -0,0 +1,18 @@
+// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
+
+!s32i = !cir.int
+
+module {
+  cir.func @fold_shuffle_dynamic_vector_op_test() {
+%alloca = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr>, ["r", init]
+%vec = 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>
+%indices = cir.const #cir.const_vector<[#cir.int<8> : !s32i, #cir.int<7> : 
!s32i, #cir.int<6> : !s32i, #cir.int<5> : !s32i]> : !cir.vector<4 x !s32i>
+%new_vec = cir.vec.shuffle.dynamic %vec : !cir.vector<4 x !s32i>, %indices 
: !cir.vector<4 x !s32i>
+cir.store align(16) %new_vec, %alloca : !cir.vector<4 x !s32i>, 
!cir.ptr>
+cir.return
+  }
+
+  // CHECK: %[[NEW_VEC:.*]] = cir.const #cir.const_vector<[#cir.int<1> : 
!s32i, #cir.int<4> : !s32i, #cir.int<3> : !s32i, #cir.int<2> : !s32i]> : 
!cir.vector<4 x !s32i>
+}
+
+

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lis

[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread Baranov Victor via cfe-commits


@@ -16,8 +16,8 @@
 
 namespace absl
 {
-template 
-std::string StrFormat(const S &format, const Args&... args);
+template 
+std::string StrFormat(const std::string &format, const Args&... args);

vbvictor wrote:

Shouldn't this also be a `std::string_view`?
```suggestion
std::string StrFormat(const std::string_view &format, const Args&... args);
```

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


[clang] [CIR] Implement folder for VecShuffleDynamicOp (PR #142315)

2025-06-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds a folder for the VecShuffleDynamicOp

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

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


4 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+1) 
- (modified) clang/lib/CIR/Dialect/IR/CIRDialect.cpp (+32) 
- (modified) clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp (+3-3) 
- (added) clang/test/CIR/Transforms/vector-shuffle-dynamic-fold.cir (+18) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 07851610a2abd..4442c3a5607ae 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2188,6 +2188,7 @@ def VecShuffleDynamicOp : CIR_Op<"vec.shuffle.dynamic",
   }];
 
   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 36f050de9f8bb..90b32950e4774 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -1579,6 +1579,38 @@ OpFoldResult cir::VecExtractOp::fold(FoldAdaptor 
adaptor) {
 // VecShuffleDynamicOp
 
//===--===//
 
+OpFoldResult cir::VecShuffleDynamicOp::fold(FoldAdaptor adaptor) {
+  mlir::Attribute vec = adaptor.getVec();
+  mlir::Attribute indices = adaptor.getIndices();
+  if (mlir::isa_and_nonnull(vec) &&
+  mlir::isa_and_nonnull(indices)) {
+auto vecAttr = mlir::cast(vec);
+auto indicesAttr = mlir::cast(indices);
+auto vecTy = cast(vecAttr.getType());
+
+mlir::ArrayAttr vecElts = vecAttr.getElts();
+mlir::ArrayAttr indicesElts = indicesAttr.getElts();
+
+const uint64_t numElements = vecElts.size();
+
+SmallVector elements;
+elements.reserve(numElements);
+
+const uint64_t maskBits = llvm::NextPowerOf2(numElements - 1) - 1;
+for (uint64_t i = 0; i < numElements; i++) {
+  cir::IntAttr idxAttr = mlir::cast(indicesElts[i]);
+  uint64_t idxValue = idxAttr.getUInt();
+  uint64_t newIdx = idxValue & maskBits;
+  elements.push_back(vecElts[newIdx]);
+}
+
+return cir::ConstVectorAttr::get(
+vecTy, mlir::ArrayAttr::get(getContext(), elements));
+  }
+
+  return {};
+}
+
 LogicalResult cir::VecShuffleDynamicOp::verify() {
   // The number of elements in the two input vectors must match.
   if (getVec().getType().getSize() !=
diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp 
b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
index fb000adee04c6..7d03e374c27e8 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 and VecExtractOp are here to perform a manual `fold` in
-// applyOpPatternsGreedily.
+// CastOp, UnaryOp, VecExtractOp and VecShuffleDynamicOp are here to 
perform
+// a manual `fold` in applyOpPatternsGreedily.
 if (isa(op))
+VecExtractOp, VecShuffleDynamicOp>(op))
   ops.push_back(op);
   });
 
diff --git a/clang/test/CIR/Transforms/vector-shuffle-dynamic-fold.cir 
b/clang/test/CIR/Transforms/vector-shuffle-dynamic-fold.cir
new file mode 100644
index 0..db5d6bff04d5b
--- /dev/null
+++ b/clang/test/CIR/Transforms/vector-shuffle-dynamic-fold.cir
@@ -0,0 +1,18 @@
+// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
+
+!s32i = !cir.int
+
+module {
+  cir.func @fold_shuffle_dynamic_vector_op_test() {
+%alloca = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr>, ["r", init]
+%vec = 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>
+%indices = cir.const #cir.const_vector<[#cir.int<8> : !s32i, #cir.int<7> : 
!s32i, #cir.int<6> : !s32i, #cir.int<5> : !s32i]> : !cir.vector<4 x !s32i>
+%new_vec = cir.vec.shuffle.dynamic %vec : !cir.vector<4 x !s32i>, %indices 
: !cir.vector<4 x !s32i>
+cir.store align(16) %new_vec, %alloca : !cir.vector<4 x !s32i>, 
!cir.ptr>
+cir.return
+  }
+
+  // CHECK: %[[NEW_VEC:.*]] = cir.const #cir.const_vector<[#cir.int<1> : 
!s32i, #cir.int<4> : !s32i, #cir.int<3> : !s32i, #cir.int<2> : !s32i]> : 
!cir.vector<4 x !s32i>
+}
+
+

``




https://github.com/llvm/llvm-project/pull/142315
___
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-01 Thread Henrich Lauko via cfe-commits


@@ -0,0 +1,21 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the CIR dialect attributes constraints.
+//
+//===--===//
+
+#ifndef CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
+#define CLANG_CIR_DIALECT_IRCIRATTRCONSTRAINTS_TD_

xlauko wrote:

```suggestion
#define CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD
```

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] [CIR] Upstream ShuffleOp for VectorType (PR #142288)

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

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

>From 1080f1cb13950b3fbeb1536227ee61e2ade9eac7 Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Sat, 31 May 2025 19:53:56 +0200
Subject: [PATCH 1/3] [CIR] Upstream ShuffleOp for VectorType

---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  | 44 +++
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp| 21 +++--
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   | 24 ++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 18 
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h   | 10 +
 clang/test/CIR/CodeGen/vector-ext.cpp | 25 +++
 clang/test/CIR/CodeGen/vector.cpp | 27 +++-
 clang/test/CIR/IR/invalid-vector.cir  | 38 
 8 files changed, 203 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 07851610a2abd..c176719941fc6 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2156,6 +2156,50 @@ def VecCmpOp : CIR_Op<"vec.cmp", [Pure, 
SameTypeOperands]> {
   }];
 }
 
+//===--===//
+// VecShuffleOp
+//===--===//
+
+// TODO: Create an interface that both VecShuffleOp and VecShuffleDynamicOp
+// implement.  This could be useful for passes that don't care how the vector
+// shuffle was specified.
+
+def VecShuffleOp : CIR_Op<"vec.shuffle",
+   [Pure, AllTypesMatch<["vec1", "vec2"]>]> {
+  let summary = "Combine two vectors using indices passed as constant 
integers";
+  let description = [{
+The `cir.vec.shuffle` operation implements the documented form of Clang's
+__builtin_shufflevector, where the indices of the shuffled result are
+integer constants.
+
+The two input vectors, which must have the same type, are concatenated.
+Each of the integer constant arguments is interpreted as an index into that
+concatenated vector, with a value of -1 meaning that the result value
+doesn't matter. The result vector, which must have the same element type as
+the input vectors and the same number of elements as the list of integer
+constant indices, is constructed by taking the elements at the given
+indices from the concatenated vector.
+
+```mlir
+%new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<2 x !s32i>)
+[#cir.int<3> : !s64i, #cir.int<1> : !s64i] : !cir.vector<2 x !s32i>
+```
+  }];
+
+  let arguments = (ins
+CIR_VectorType:$vec1,
+CIR_VectorType:$vec2,
+TypedArrayAttrBase:$indices
+  );
+
+  let results = (outs CIR_VectorType:$result);
+  let assemblyFormat = [{
+`(` $vec1 `,` $vec2 `:` qualified(type($vec1)) `)` $indices `:`
+ qualified(type($result)) attr-dict
+  }];
+  let hasVerifier = 1;
+}
+
 
//===--===//
 // VecShuffleDynamicOp
 
//===--===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 8448c164a5e58..4b7dd75457d6a 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -180,9 +180,24 @@ class ScalarExprEmitter : public 
StmtVisitor {
   cgf.getLoc(e->getSourceRange()), inputVec, indexVec);
 }
 
-cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
-   "ShuffleVectorExpr with indices");
-return {};
+mlir::Value vec1 = Visit(e->getExpr(0));
+mlir::Value vec2 = Visit(e->getExpr(1));
+
+// The documented form of __builtin_shufflevector, where the indices are
+// a variable number of integer constants. The constants will be stored
+// in an ArrayAttr.
+SmallVector indices;
+for (unsigned i = 2; i < e->getNumSubExprs(); ++i) {
+  indices.push_back(
+  cir::IntAttr::get(cgf.builder.getSInt64Ty(),
+e->getExpr(i)
+->EvaluateKnownConstInt(cgf.getContext())
+.getSExtValue()));
+}
+
+return cgf.builder.create(
+cgf.getLoc(e->getSourceRange()), cgf.convertType(e->getType()), vec1,
+vec2, cgf.builder.getArrayAttr(indices));
   }
 
   mlir::Value VisitConvertVectorExpr(ConvertVectorExpr *e) {
diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 36f050de9f8bb..8ca150cba975c 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -21,6 +21,7 @@
 #include "clang/CIR/Dialect/IR/CIROpsDialect.cpp.inc"
 #include "clang/CIR/Dialect/IR/CIROpsEnums.cpp.inc"
 #include "clang/CIR/MissingFeatures.h"
+
 #include 
 
 using namespace mlir;
@@

[clang] [Serialization] Remove unused includes (NFC) (PR #142300)

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

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


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


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

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

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

Please wait for @owenca or @mydeveloperday.

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


[clang] [llvm] [WIP] ABI Lowering Library (PR #140112)

2025-06-01 Thread via cfe-commits

https://github.com/vortex73 updated 
https://github.com/llvm/llvm-project/pull/140112

>From 322c1cfb925f3073f3d3b30abe1b2e35ae7745f3 Mon Sep 17 00:00:00 2001
From: Narayan Sreekumar 
Date: Thu, 15 May 2025 23:13:50 +0530
Subject: [PATCH 1/5] [LLVM ABI] The Typesystem

---
 llvm/include/llvm/ABI/Types.h | 121 ++
 1 file changed, 121 insertions(+)
 create mode 100644 llvm/include/llvm/ABI/Types.h

diff --git a/llvm/include/llvm/ABI/Types.h b/llvm/include/llvm/ABI/Types.h
new file mode 100644
index 0..443a6c1eab4e7
--- /dev/null
+++ b/llvm/include/llvm/ABI/Types.h
@@ -0,0 +1,121 @@
+#ifndef LLVM_ABI_TYPES_H
+#define LLVM_ABI_TYPES_H
+
+#include 
+#include 
+#include 
+
+namespace llvm {
+namespace abi {
+
+enum class TypeKind {
+  Void,
+  Integer,
+  Float,
+  Pointer,
+  Array,
+  Vector,
+  Struct,
+  Union,
+  Function
+};
+class Type {
+protected:
+  TypeKind Kind;
+  uint64_t SizeInBits;
+  uint64_t AlignInBits;
+  bool IsExplicitlyAligned;
+
+  Type(TypeKind K, uint64_t Size, uint64_t Align, bool ExplicitAlign = false)
+  : Kind(K), SizeInBits(Size), AlignInBits(Align),
+IsExplicitlyAligned(ExplicitAlign) {}
+
+public:
+  virtual ~Type() = default;
+
+  TypeKind getKind() const { return Kind; }
+  uint64_t getSizeInBits() const { return SizeInBits; }
+  uint64_t getAlignInBits() const { return AlignInBits; }
+  bool hasExplicitAlignment() const { return IsExplicitlyAligned; }
+
+  void setExplicitAlignment(uint64_t Align) {
+AlignInBits = Align;
+IsExplicitlyAligned = true;
+  }
+
+  bool isVoid() const { return Kind == TypeKind::Void; }
+  bool isInteger() const { return Kind == TypeKind::Integer; }
+  bool isFloat() const { return Kind == TypeKind::Float; }
+  bool isPointer() const { return Kind == TypeKind::Pointer; }
+  bool isArray() const { return Kind == TypeKind::Array; }
+  bool isVector() const { return Kind == TypeKind::Vector; }
+  bool isStruct() const { return Kind == TypeKind::Struct; }
+  bool isUnion() const { return Kind == TypeKind::Union; }
+  bool isFunction() const { return Kind == TypeKind::Function; }
+
+  static bool classof(const Type *) { return true; }
+};
+class VoidType : public Type {
+public:
+  VoidType() : Type(TypeKind::Void, 0, 0) {}
+
+  static bool classof(const Type *T) { return T->getKind() == TypeKind::Void; }
+};
+
+class IntegerType : public Type {
+private:
+  bool IsSigned;
+  bool IsAltRepresentation;
+  std::string TypeName;
+
+public:
+  IntegerType(uint64_t BitWidth, uint64_t Align, bool Signed,
+  bool AltRep = false, const std::string &Name = "")
+  : Type(TypeKind::Integer, BitWidth, Align), IsSigned(Signed),
+IsAltRepresentation(AltRep), TypeName(Name) {}
+
+  bool isSigned() const { return IsSigned; }
+  bool isAltRepresentation() const { return IsAltRepresentation; }
+  const std::string &getTypeName() const { return TypeName; }
+
+  static bool classof(const Type *T) {
+return T->getKind() == TypeKind::Integer;
+  }
+};
+class FloatType : public Type {
+private:
+  std::string TypeName;
+
+public:
+  FloatType(uint64_t BitWidth, uint64_t Align, const std::string &Name)
+  : Type(TypeKind::Float, BitWidth, Align), TypeName(Name) {}
+
+  const std::string &getTypeName() const { return TypeName; }
+
+  static bool classof(const Type *T) { return T->getKind() == TypeKind::Float; 
}
+};
+class PointerType : public Type {
+private:
+  std::unique_ptr PointeeType;
+  bool IsConst;
+  bool IsVolatile;
+
+public:
+  PointerType(std::unique_ptr Pointee, uint64_t Size, uint64_t Align,
+  bool Const = false, bool Volatile = false)
+  : Type(TypeKind::Pointer, Size, Align), PointeeType(std::move(Pointee)),
+IsConst(Const), IsVolatile(Volatile) {}
+
+  const Type *getPointeeType() const { return PointeeType.get(); }
+  bool isConst() const { return IsConst; }
+  bool isVolatile() const { return IsVolatile; }
+
+  static bool classof(const Type *T) {
+return T->getKind() == TypeKind::Pointer;
+  }
+};
+
+} // namespace abi
+} // namespace llvm
+
+#endif

>From 0858b1f327c7a49c2e2825124a8d5cabbd8654fd Mon Sep 17 00:00:00 2001
From: Narayan Sreekumar 
Date: Fri, 23 May 2025 17:53:53 +0530
Subject: [PATCH 2/5] [LLVMABI] API for Creating types

---
 llvm/include/llvm/ABI/Types.h | 244 +-
 1 file changed, 213 insertions(+), 31 deletions(-)

diff --git a/llvm/include/llvm/ABI/Types.h b/llvm/include/llvm/ABI/Types.h
index 443a6c1eab4e7..84cb586832dbd 100644
--- a/llvm/include/llvm/ABI/Types.h
+++ b/llvm/include/llvm/ABI/Types.h
@@ -1,9 +1,9 @@
 #ifndef LLVM_ABI_TYPES_H
 #define LLVM_ABI_TYPES_H
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Allocator.h"
 #include 
-#include 
-#include 
 
 namespace llvm {
 namespace abi {
@@ -19,6 +19,7 @@ enum class TypeKind {
   Union,
   Function
 };
+
 class Type {
 protected:
   TypeKind Kind;
@@ -31,8 +32,6 @@ class Type {
 IsExplicitlyAligned(ExplicitAli

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

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


@@ -2156,6 +2156,50 @@ def VecCmpOp : CIR_Op<"vec.cmp", [Pure, 
SameTypeOperands]> {
   }];
 }
 
+//===--===//
+// VecShuffleOp
+//===--===//
+
+// TODO: Create an interface that both VecShuffleOp and VecShuffleDynamicOp
+// implement.  This could be useful for passes that don't care how the vector
+// shuffle was specified.
+
+def VecShuffleOp : CIR_Op<"vec.shuffle",
+   [Pure, AllTypesMatch<["vec1", "vec2"]>]> {
+  let summary = "Combine two vectors using indices passed as constant 
integers";
+  let description = [{
+The `cir.vec.shuffle` operation implements the documented form of Clang's
+__builtin_shufflevector, where the indices of the shuffled result are
+integer constants.
+
+The two input vectors, which must have the same type, are concatenated.
+Each of the integer constant arguments is interpreted as an index into that
+concatenated vector, with a value of -1 meaning that the result value
+doesn't matter. The result vector, which must have the same element type as
+the input vectors and the same number of elements as the list of integer
+constant indices, is constructed by taking the elements at the given
+indices from the concatenated vector.
+
+```mlir
+%new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<2 x !s32i>)
+[#cir.int<3> : !s64i, #cir.int<1> : !s64i] : !cir.vector<2 x !s32i>
+```
+  }];
+
+  let arguments = (ins
+CIR_VectorType:$vec1,
+CIR_VectorType:$vec2,
+TypedArrayAttrBase:$indices

xlauko wrote:

Any reason for them to be cir::IntAttr? why not just use `DenseI64ArrayAttr`, 
maybe even `DenseI32ArrayAttr` would be sufficient?

Also if we decide to use `TypedArrayAttrBase;
```

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] [CIR] Upstream ShuffleOp for VectorType (PR #142288)

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

https://github.com/xlauko edited 
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] [CIR] Upstream ShuffleOp for VectorType (PR #142288)

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


@@ -2156,6 +2156,50 @@ def VecCmpOp : CIR_Op<"vec.cmp", [Pure, 
SameTypeOperands]> {
   }];
 }
 
+//===--===//
+// VecShuffleOp
+//===--===//
+
+// TODO: Create an interface that both VecShuffleOp and VecShuffleDynamicOp
+// implement.  This could be useful for passes that don't care how the vector
+// shuffle was specified.
+
+def VecShuffleOp : CIR_Op<"vec.shuffle",
+   [Pure, AllTypesMatch<["vec1", "vec2"]>]> {
+  let summary = "Combine two vectors using indices passed as constant 
integers";
+  let description = [{
+The `cir.vec.shuffle` operation implements the documented form of Clang's
+__builtin_shufflevector, where the indices of the shuffled result are
+integer constants.
+
+The two input vectors, which must have the same type, are concatenated.
+Each of the integer constant arguments is interpreted as an index into that
+concatenated vector, with a value of -1 meaning that the result value
+doesn't matter. The result vector, which must have the same element type as
+the input vectors and the same number of elements as the list of integer
+constant indices, is constructed by taking the elements at the given
+indices from the concatenated vector.
+
+```mlir
+%new_vec = cir.vec.shuffle(%vec_1, %vec_2 : !cir.vector<2 x !s32i>)
+[#cir.int<3> : !s64i, #cir.int<1> : !s64i] : !cir.vector<2 x !s32i>
+```
+  }];
+
+  let arguments = (ins
+CIR_VectorType:$vec1,
+CIR_VectorType:$vec2,
+TypedArrayAttrBase:$indices

xlauko wrote:

There will be soon `CIRAttrConstraints.td` file soon (or you can add it) where 
this kind of constraint should be placed later.

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] [llvm] [WIP] ABI Lowering Library (PR #140112)

2025-06-01 Thread via cfe-commits

https://github.com/vortex73 updated 
https://github.com/llvm/llvm-project/pull/140112

>From 322c1cfb925f3073f3d3b30abe1b2e35ae7745f3 Mon Sep 17 00:00:00 2001
From: Narayan Sreekumar 
Date: Thu, 15 May 2025 23:13:50 +0530
Subject: [PATCH 1/5] [LLVM ABI] The Typesystem

---
 llvm/include/llvm/ABI/Types.h | 121 ++
 1 file changed, 121 insertions(+)
 create mode 100644 llvm/include/llvm/ABI/Types.h

diff --git a/llvm/include/llvm/ABI/Types.h b/llvm/include/llvm/ABI/Types.h
new file mode 100644
index 0..443a6c1eab4e7
--- /dev/null
+++ b/llvm/include/llvm/ABI/Types.h
@@ -0,0 +1,121 @@
+#ifndef LLVM_ABI_TYPES_H
+#define LLVM_ABI_TYPES_H
+
+#include 
+#include 
+#include 
+
+namespace llvm {
+namespace abi {
+
+enum class TypeKind {
+  Void,
+  Integer,
+  Float,
+  Pointer,
+  Array,
+  Vector,
+  Struct,
+  Union,
+  Function
+};
+class Type {
+protected:
+  TypeKind Kind;
+  uint64_t SizeInBits;
+  uint64_t AlignInBits;
+  bool IsExplicitlyAligned;
+
+  Type(TypeKind K, uint64_t Size, uint64_t Align, bool ExplicitAlign = false)
+  : Kind(K), SizeInBits(Size), AlignInBits(Align),
+IsExplicitlyAligned(ExplicitAlign) {}
+
+public:
+  virtual ~Type() = default;
+
+  TypeKind getKind() const { return Kind; }
+  uint64_t getSizeInBits() const { return SizeInBits; }
+  uint64_t getAlignInBits() const { return AlignInBits; }
+  bool hasExplicitAlignment() const { return IsExplicitlyAligned; }
+
+  void setExplicitAlignment(uint64_t Align) {
+AlignInBits = Align;
+IsExplicitlyAligned = true;
+  }
+
+  bool isVoid() const { return Kind == TypeKind::Void; }
+  bool isInteger() const { return Kind == TypeKind::Integer; }
+  bool isFloat() const { return Kind == TypeKind::Float; }
+  bool isPointer() const { return Kind == TypeKind::Pointer; }
+  bool isArray() const { return Kind == TypeKind::Array; }
+  bool isVector() const { return Kind == TypeKind::Vector; }
+  bool isStruct() const { return Kind == TypeKind::Struct; }
+  bool isUnion() const { return Kind == TypeKind::Union; }
+  bool isFunction() const { return Kind == TypeKind::Function; }
+
+  static bool classof(const Type *) { return true; }
+};
+class VoidType : public Type {
+public:
+  VoidType() : Type(TypeKind::Void, 0, 0) {}
+
+  static bool classof(const Type *T) { return T->getKind() == TypeKind::Void; }
+};
+
+class IntegerType : public Type {
+private:
+  bool IsSigned;
+  bool IsAltRepresentation;
+  std::string TypeName;
+
+public:
+  IntegerType(uint64_t BitWidth, uint64_t Align, bool Signed,
+  bool AltRep = false, const std::string &Name = "")
+  : Type(TypeKind::Integer, BitWidth, Align), IsSigned(Signed),
+IsAltRepresentation(AltRep), TypeName(Name) {}
+
+  bool isSigned() const { return IsSigned; }
+  bool isAltRepresentation() const { return IsAltRepresentation; }
+  const std::string &getTypeName() const { return TypeName; }
+
+  static bool classof(const Type *T) {
+return T->getKind() == TypeKind::Integer;
+  }
+};
+class FloatType : public Type {
+private:
+  std::string TypeName;
+
+public:
+  FloatType(uint64_t BitWidth, uint64_t Align, const std::string &Name)
+  : Type(TypeKind::Float, BitWidth, Align), TypeName(Name) {}
+
+  const std::string &getTypeName() const { return TypeName; }
+
+  static bool classof(const Type *T) { return T->getKind() == TypeKind::Float; 
}
+};
+class PointerType : public Type {
+private:
+  std::unique_ptr PointeeType;
+  bool IsConst;
+  bool IsVolatile;
+
+public:
+  PointerType(std::unique_ptr Pointee, uint64_t Size, uint64_t Align,
+  bool Const = false, bool Volatile = false)
+  : Type(TypeKind::Pointer, Size, Align), PointeeType(std::move(Pointee)),
+IsConst(Const), IsVolatile(Volatile) {}
+
+  const Type *getPointeeType() const { return PointeeType.get(); }
+  bool isConst() const { return IsConst; }
+  bool isVolatile() const { return IsVolatile; }
+
+  static bool classof(const Type *T) {
+return T->getKind() == TypeKind::Pointer;
+  }
+};
+
+} // namespace abi
+} // namespace llvm
+
+#endif

>From 0858b1f327c7a49c2e2825124a8d5cabbd8654fd Mon Sep 17 00:00:00 2001
From: Narayan Sreekumar 
Date: Fri, 23 May 2025 17:53:53 +0530
Subject: [PATCH 2/5] [LLVMABI] API for Creating types

---
 llvm/include/llvm/ABI/Types.h | 244 +-
 1 file changed, 213 insertions(+), 31 deletions(-)

diff --git a/llvm/include/llvm/ABI/Types.h b/llvm/include/llvm/ABI/Types.h
index 443a6c1eab4e7..84cb586832dbd 100644
--- a/llvm/include/llvm/ABI/Types.h
+++ b/llvm/include/llvm/ABI/Types.h
@@ -1,9 +1,9 @@
 #ifndef LLVM_ABI_TYPES_H
 #define LLVM_ABI_TYPES_H
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Allocator.h"
 #include 
-#include 
-#include 
 
 namespace llvm {
 namespace abi {
@@ -19,6 +19,7 @@ enum class TypeKind {
   Union,
   Function
 };
+
 class Type {
 protected:
   TypeKind Kind;
@@ -31,8 +32,6 @@ class Type {
 IsExplicitlyAligned(ExplicitAli

[clang] [llvm] [WIP] ABI Lowering Library (PR #140112)

2025-06-01 Thread via cfe-commits

https://github.com/vortex73 updated 
https://github.com/llvm/llvm-project/pull/140112

>From 322c1cfb925f3073f3d3b30abe1b2e35ae7745f3 Mon Sep 17 00:00:00 2001
From: Narayan Sreekumar 
Date: Thu, 15 May 2025 23:13:50 +0530
Subject: [PATCH 1/5] [LLVM ABI] The Typesystem

---
 llvm/include/llvm/ABI/Types.h | 121 ++
 1 file changed, 121 insertions(+)
 create mode 100644 llvm/include/llvm/ABI/Types.h

diff --git a/llvm/include/llvm/ABI/Types.h b/llvm/include/llvm/ABI/Types.h
new file mode 100644
index 0..443a6c1eab4e7
--- /dev/null
+++ b/llvm/include/llvm/ABI/Types.h
@@ -0,0 +1,121 @@
+#ifndef LLVM_ABI_TYPES_H
+#define LLVM_ABI_TYPES_H
+
+#include 
+#include 
+#include 
+
+namespace llvm {
+namespace abi {
+
+enum class TypeKind {
+  Void,
+  Integer,
+  Float,
+  Pointer,
+  Array,
+  Vector,
+  Struct,
+  Union,
+  Function
+};
+class Type {
+protected:
+  TypeKind Kind;
+  uint64_t SizeInBits;
+  uint64_t AlignInBits;
+  bool IsExplicitlyAligned;
+
+  Type(TypeKind K, uint64_t Size, uint64_t Align, bool ExplicitAlign = false)
+  : Kind(K), SizeInBits(Size), AlignInBits(Align),
+IsExplicitlyAligned(ExplicitAlign) {}
+
+public:
+  virtual ~Type() = default;
+
+  TypeKind getKind() const { return Kind; }
+  uint64_t getSizeInBits() const { return SizeInBits; }
+  uint64_t getAlignInBits() const { return AlignInBits; }
+  bool hasExplicitAlignment() const { return IsExplicitlyAligned; }
+
+  void setExplicitAlignment(uint64_t Align) {
+AlignInBits = Align;
+IsExplicitlyAligned = true;
+  }
+
+  bool isVoid() const { return Kind == TypeKind::Void; }
+  bool isInteger() const { return Kind == TypeKind::Integer; }
+  bool isFloat() const { return Kind == TypeKind::Float; }
+  bool isPointer() const { return Kind == TypeKind::Pointer; }
+  bool isArray() const { return Kind == TypeKind::Array; }
+  bool isVector() const { return Kind == TypeKind::Vector; }
+  bool isStruct() const { return Kind == TypeKind::Struct; }
+  bool isUnion() const { return Kind == TypeKind::Union; }
+  bool isFunction() const { return Kind == TypeKind::Function; }
+
+  static bool classof(const Type *) { return true; }
+};
+class VoidType : public Type {
+public:
+  VoidType() : Type(TypeKind::Void, 0, 0) {}
+
+  static bool classof(const Type *T) { return T->getKind() == TypeKind::Void; }
+};
+
+class IntegerType : public Type {
+private:
+  bool IsSigned;
+  bool IsAltRepresentation;
+  std::string TypeName;
+
+public:
+  IntegerType(uint64_t BitWidth, uint64_t Align, bool Signed,
+  bool AltRep = false, const std::string &Name = "")
+  : Type(TypeKind::Integer, BitWidth, Align), IsSigned(Signed),
+IsAltRepresentation(AltRep), TypeName(Name) {}
+
+  bool isSigned() const { return IsSigned; }
+  bool isAltRepresentation() const { return IsAltRepresentation; }
+  const std::string &getTypeName() const { return TypeName; }
+
+  static bool classof(const Type *T) {
+return T->getKind() == TypeKind::Integer;
+  }
+};
+class FloatType : public Type {
+private:
+  std::string TypeName;
+
+public:
+  FloatType(uint64_t BitWidth, uint64_t Align, const std::string &Name)
+  : Type(TypeKind::Float, BitWidth, Align), TypeName(Name) {}
+
+  const std::string &getTypeName() const { return TypeName; }
+
+  static bool classof(const Type *T) { return T->getKind() == TypeKind::Float; 
}
+};
+class PointerType : public Type {
+private:
+  std::unique_ptr PointeeType;
+  bool IsConst;
+  bool IsVolatile;
+
+public:
+  PointerType(std::unique_ptr Pointee, uint64_t Size, uint64_t Align,
+  bool Const = false, bool Volatile = false)
+  : Type(TypeKind::Pointer, Size, Align), PointeeType(std::move(Pointee)),
+IsConst(Const), IsVolatile(Volatile) {}
+
+  const Type *getPointeeType() const { return PointeeType.get(); }
+  bool isConst() const { return IsConst; }
+  bool isVolatile() const { return IsVolatile; }
+
+  static bool classof(const Type *T) {
+return T->getKind() == TypeKind::Pointer;
+  }
+};
+
+} // namespace abi
+} // namespace llvm
+
+#endif

>From 0858b1f327c7a49c2e2825124a8d5cabbd8654fd Mon Sep 17 00:00:00 2001
From: Narayan Sreekumar 
Date: Fri, 23 May 2025 17:53:53 +0530
Subject: [PATCH 2/5] [LLVMABI] API for Creating types

---
 llvm/include/llvm/ABI/Types.h | 244 +-
 1 file changed, 213 insertions(+), 31 deletions(-)

diff --git a/llvm/include/llvm/ABI/Types.h b/llvm/include/llvm/ABI/Types.h
index 443a6c1eab4e7..84cb586832dbd 100644
--- a/llvm/include/llvm/ABI/Types.h
+++ b/llvm/include/llvm/ABI/Types.h
@@ -1,9 +1,9 @@
 #ifndef LLVM_ABI_TYPES_H
 #define LLVM_ABI_TYPES_H
 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Support/Allocator.h"
 #include 
-#include 
-#include 
 
 namespace llvm {
 namespace abi {
@@ -19,6 +19,7 @@ enum class TypeKind {
   Union,
   Function
 };
+
 class Type {
 protected:
   TypeKind Kind;
@@ -31,8 +32,6 @@ class Type {
 IsExplicitlyAligned(ExplicitAli

[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe updated 
https://github.com/llvm/llvm-project/pull/142312

>From b334ec47c79098f7b370bdba0bcc0bbaced1f96d Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Thu, 29 May 2025 21:19:11 +0100
Subject: [PATCH] [clang-tidy] modernize-use-std-print,format: Fix checks with
 Abseil functions

These checks previously failed with absl::StrFormat and absl::PrintF
etc. with:

 Unable to use 'std::format' instead of 'StrFormat' because first
 argument is not a narrow string literal [modernize-use-std-format]

because FormatStringConverter was rejecting the format string if it had
already converted into a different type. Fix the tests so that they
check this case properly by accepting string_view rather than const char
* and fix the check so that these tests pass. Update the existing tests
that checked for the error message that can no longer happen.

Fixes: https://github.com/llvm/llvm-project/issues/129484
---
 .../utils/FormatStringConverter.cpp   |  8 ++
 clang-tools-extra/docs/ReleaseNotes.rst   | 10 
 .../modernize/use-std-format-custom.cpp   | 17 -
 .../checkers/modernize/use-std-format.cpp |  4 +--
 .../checkers/modernize/use-std-print-absl.cpp |  5 ++--
 .../modernize/use-std-print-custom.cpp| 25 ---
 6 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp 
b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
index 7f4ccca84faa5..e1c1bee97f6d4 100644
--- a/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
@@ -207,13 +207,9 @@ FormatStringConverter::FormatStringConverter(
   ArgsOffset(FormatArgOffset + 1), LangOpts(LO) {
   assert(ArgsOffset <= NumArgs);
   FormatExpr = llvm::dyn_cast(
-  Args[FormatArgOffset]->IgnoreImplicitAsWritten());
+  Args[FormatArgOffset]->IgnoreUnlessSpelledInSource());
 
-  if (!FormatExpr || !FormatExpr->isOrdinary()) {
-// Function must have a narrow string literal as its first argument.
-conversionNotPossible("first argument is not a narrow string literal");
-return;
-  }
+  assert(FormatExpr && FormatExpr->isOrdinary());
 
   if (const std::optional MaybeMacroName =
   formatStringContainsUnreplaceableMacro(Call, FormatExpr, SM, PP);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e0f81a032c38d..69527f78eb8a9 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -232,10 +232,20 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-std-format
+  ` check to correctly match
+  when the format string is converted to a different type by an implicit
+  constructor call.
+
 - Improved :doc:`modernize-use-std-numbers
   ` check to support math
   functions of different precisions.
 
+- Improved :doc:`modernize-use-std-print
+  ` check to correctly match
+  when the format string is converted to a different type by an implicit
+  constructor call.
+
 - Improved :doc:`performance-move-const-arg
   ` check by fixing false
   negatives on ternary operators calling ``std::move``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
index 7da0bb02ad766..0f3458e61856a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
@@ -2,7 +2,7 @@
 // RUN:   -std=c++20 %s modernize-use-std-format %t --  \
 // RUN:   -config="{CheckOptions: { \
 // RUN:  modernize-use-std-format.StrictMode: true, \
-// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; bad_format_type_strprintf', \
+// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; any_format_type_strprintf', \
 // RUN:  modernize-use-std-format.ReplacementFormatFunction: 
'fmt::format', \
 // RUN:  modernize-use-std-format.FormatHeader: '' \
 // RUN:}}"  \
@@ -10,7 +10,7 @@
 // RUN: %check_clang_tidy -check-suffixes=,NOTSTRICT\
 // RUN:   -std=c++20 %s modernize-use-std-format %t --  \
 // RUN:   -config="{CheckOptions: { \
-// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynamespace::strprintf2; bad_format_type_strprintf', \
+// RUN:  modernize-use-std-format.StrFormatLikeFunctions: 
'::strprintf; mynames

[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread via cfe-commits


@@ -232,10 +232,20 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-std-print

EugeneZelenko wrote:

Please keep alphabetical order (by check name) in this list.

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


[clang-tools-extra] [clang-tidy] modernize-use-std-print, format: Fix checks with Abseil functions (PR #142312)

2025-06-01 Thread Mike Crowe via cfe-commits


@@ -232,10 +232,20 @@ Changes in existing checks
   matched scenarios of ``find`` and ``rfind`` methods and fixing false
   positives when those methods were called with 3 arguments.
 
+- Improved :doc:`modernize-use-std-print

mikecrowe wrote:

Arggh, I edited the wrong copy. You'll notice that they are exactly the wrong 
way around. :( Fixed now. Thanks.

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


  1   2   >