[clang] [Clang] Improve subsumption. (PR #132849)

2025-03-26 Thread via cfe-commits

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

>From b5b5275093f6942238536834c6508551f7ceffd8 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sun, 16 Mar 2025 23:34:19 +0100
Subject: [PATCH 01/10] [Clang] Improve subsumption.

The main goal of this patch is to improve the
performance of concept subsumption by

 - Making sure literal (atomic) clauses are de-duplicated
   (Whether 2 atomic constraint is established during the
initial normal form production).
 - Eagerly removing redundant clauses.

This should minimize the risks of exponentially-large
that can be produced by a naive {C,D}NF transformation.

While at it, I restructured that part of the code to be a bit
clearer.

Subsumption of fold expanded constraint is also cached.

---

Note that removing redundant clauses (even naively)
seems to be necessary and sufficient to have acceptable performance
on anything that could be construed as reasonable code.

Ultimately, the number of clauses is always going to be fairly
small (but $2^{fairly\ small}$ is quickly fairly large..).

I went too far in the rabbit hole of Tseitin transformations etc,
which was much faster but would then require to check satisfiabiliy
to establish subsumption between some constraints (although it was
good enough to pass all but ones of our tests...).

It doesn't help that the C++ standard has a very specific
definition of subsumption that is really more of an implication...

While that sort of musing is fascinating, it was ultimately a fool's
errand, at least until such time that there is more motivation for
a SAT solver in clang (clang-tidy can after all use z3!).

Here be dragons.

Fixes #122581
---
 clang/docs/ReleaseNotes.rst |   1 +
 clang/include/clang/Sema/SemaConcept.h  | 225 +-
 clang/lib/Sema/SemaConcept.cpp  | 452 +++-
 clang/test/SemaCXX/concepts-subsumption.cpp | 194 +
 4 files changed, 636 insertions(+), 236 deletions(-)
 create mode 100644 clang/test/SemaCXX/concepts-subsumption.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2f15c90ab1583..05bde5c9cc1d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -358,6 +358,7 @@ Bug Fixes to C++ Support
 - Fixed a Clang regression in C++20 mode where unresolved dependent call 
expressions were created inside non-dependent contexts (#GH122892)
 - Clang now emits the ``-Wunused-variable`` warning when some structured 
bindings are unused
   and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
+- Clang no longer crash when establishing subsumption between some constraint 
expressions. (#GH122581)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 5c599a70532f6..87fee1678fb05 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -14,13 +14,14 @@
 #define LLVM_CLANG_SEMA_SEMACONCEPT_H
 #include "clang/AST/ASTConcept.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/Expr.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include 
-#include 
 #include 
 
 namespace clang {
@@ -56,49 +57,10 @@ struct alignas(ConstraintAlignment) AtomicConstraint {
 }
 return true;
   }
-
-  bool subsumes(ASTContext &C, const AtomicConstraint &Other) const {
-// C++ [temp.constr.order] p2
-//   - an atomic constraint A subsumes another atomic constraint B
-// if and only if the A and B are identical [...]
-//
-// C++ [temp.constr.atomic] p2
-//   Two atomic constraints are identical if they are formed from the
-//   same expression and the targets of the parameter mappings are
-//   equivalent according to the rules for expressions [...]
-
-// We do not actually substitute the parameter mappings into the
-// constraint expressions, therefore the constraint expressions are
-// the originals, and comparing them will suffice.
-if (ConstraintExpr != Other.ConstraintExpr)
-  return false;
-
-// Check that the parameter lists are identical
-return hasMatchingParameterMapping(C, Other);
-  }
 };
 
-struct alignas(ConstraintAlignment) FoldExpandedConstraint;
-
-using NormalFormConstraint =
-llvm::PointerUnion;
-struct NormalizedConstraint;
-using NormalForm =
-llvm::SmallVector, 4>;
-
-// A constraint is in conjunctive normal form when it is a conjunction of
-// clauses where each clause is a disjunction of atomic constraints. For atomic
-// constraints A, B, and C, the constraint A  ∧ (B  ∨ C) is in conjunctive
-// normal form.
-NormalForm makeCNF(const NormalizedConstraint &Normalized);
-
-// A constraint is in disjunctive norma

[clang] [llvm] [AArch64] Add FEAT_FPAC to Grace (PR #133054)

2025-03-26 Thread Sjoerd Meijer via cfe-commits


@@ -1067,7 +1067,8 @@ def ProcessorFeatures {
  FeatureDotProd, FeatureFPARMv8, 
FeatureMatMulInt8,
  FeatureSSBS, FeatureCCIDX,
  FeatureJS, FeatureLSE, FeatureRAS, 
FeatureRCPC, FeatureRDM];
-  list Grace = !listconcat(NeoverseV2, [FeatureSVE2SM4, 
FeatureSVEAES, FeatureSVE2SHA3]);
+  list Grace = !listconcat(NeoverseV2, [FeatureSVE2SM4, 
FeatureSVEAES, FeatureSVE2SHA3,
+  FeatureFPAC]);

sjoerdmeijer wrote:

Thanks for spotting this, I think you're right.  I got confused with 
"supported", thinking about this architecturally, but this is in the V2 TRM, so 
all V2 cores implement this. I will move this to the V2.

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


[clang] [llvm] [AArch64] Add FEAT_FPAC to Grace (PR #133054)

2025-03-26 Thread David Green via cfe-commits


@@ -1067,7 +1067,8 @@ def ProcessorFeatures {
  FeatureDotProd, FeatureFPARMv8, 
FeatureMatMulInt8,
  FeatureSSBS, FeatureCCIDX,
  FeatureJS, FeatureLSE, FeatureRAS, 
FeatureRCPC, FeatureRDM];
-  list Grace = !listconcat(NeoverseV2, [FeatureSVE2SM4, 
FeatureSVEAES, FeatureSVE2SHA3]);
+  list Grace = !listconcat(NeoverseV2, [FeatureSVE2SM4, 
FeatureSVEAES, FeatureSVE2SHA3,
+  FeatureFPAC]);

davemgreen wrote:

Yeah that sounds good - there are a number of other cores that have it but are 
not marked, but I don't have a list. The features was added after the cores 
were added and it didn't add them to all. Adding for V2 is a good start.

It can change the way PACBTI is emitted, I believe to make it more efficient 
and shouldn't be an issue so long as the instructions do throw exceptions.

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


[clang] 0bc2c5b - Reapply "[clang][bytecode] Implement __builtin_{wcscmp,wcsncmp} (#132… (#132963)

2025-03-26 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-26T08:19:31+01:00
New Revision: 0bc2c5b2a4ca49011db27f7e8632d5d5ebc0ef5d

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

LOG: Reapply "[clang][bytecode] Implement __builtin_{wcscmp,wcsncmp} (#132… 
(#132963)

…723)"

This reverts commit 1e2ad6793ac205607e7c809283cf69e1cc36a69a.


Fix the previous commit on big-endian hosts by _not_ falling through to
the `uint8_t` code path.

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index d7de4c09e2614..4d125e4c202d2 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -212,11 +212,13 @@ static bool interp__builtin_strcmp(InterpState &S, 
CodePtr OpPC,
   const Pointer &A = getParam(Frame, 0);
   const Pointer &B = getParam(Frame, 1);
 
-  if (ID == Builtin::BIstrcmp || ID == Builtin::BIstrncmp)
+  if (ID == Builtin::BIstrcmp || ID == Builtin::BIstrncmp ||
+  ID == Builtin::BIwcscmp || ID == Builtin::BIwcsncmp)
 diagnoseNonConstexprBuiltin(S, OpPC, ID);
 
   uint64_t Limit = ~static_cast(0);
-  if (ID == Builtin::BIstrncmp || ID == Builtin::BI__builtin_strncmp)
+  if (ID == Builtin::BIstrncmp || ID == Builtin::BI__builtin_strncmp ||
+  ID == Builtin::BIwcsncmp || ID == Builtin::BI__builtin_wcsncmp)
 Limit = peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)))
 .getZExtValue();
 
@@ -231,12 +233,22 @@ static bool interp__builtin_strcmp(InterpState &S, 
CodePtr OpPC,
   if (A.isDummy() || B.isDummy())
 return false;
 
+  bool IsWide = ID == Builtin::BIwcscmp || ID == Builtin::BIwcsncmp ||
+ID == Builtin::BI__builtin_wcscmp ||
+ID == Builtin::BI__builtin_wcsncmp;
   assert(A.getFieldDesc()->isPrimitiveArray());
   assert(B.getFieldDesc()->isPrimitiveArray());
 
+  assert(getElemType(A).getTypePtr() == getElemType(B).getTypePtr());
+  PrimType ElemT = *S.getContext().classify(getElemType(A));
+
+  auto returnResult = [&](int V) -> bool {
+pushInteger(S, V, Call->getType());
+return true;
+  };
+
   unsigned IndexA = A.getIndex();
   unsigned IndexB = B.getIndex();
-  int32_t Result = 0;
   uint64_t Steps = 0;
   for (;; ++IndexA, ++IndexB, ++Steps) {
 
@@ -248,22 +260,33 @@ static bool interp__builtin_strcmp(InterpState &S, 
CodePtr OpPC,
 !CheckRange(S, OpPC, PB, AK_Read)) {
   return false;
 }
+
+if (IsWide) {
+  INT_TYPE_SWITCH(ElemT, {
+T CA = PA.deref();
+T CB = PB.deref();
+if (CA > CB)
+  return returnResult(1);
+else if (CA < CB)
+  return returnResult(-1);
+else if (CA.isZero() || CB.isZero())
+  return returnResult(0);
+  });
+  continue;
+}
+
 uint8_t CA = PA.deref();
 uint8_t CB = PB.deref();
 
-if (CA > CB) {
-  Result = 1;
-  break;
-} else if (CA < CB) {
-  Result = -1;
-  break;
-}
+if (CA > CB)
+  return returnResult(1);
+else if (CA < CB)
+  return returnResult(-1);
 if (CA == 0 || CB == 0)
-  break;
+  return returnResult(0);
   }
 
-  pushInteger(S, Result, Call->getType());
-  return true;
+  return returnResult(0);
 }
 
 static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
@@ -2120,6 +2143,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
   case Builtin::BIstrcmp:
   case Builtin::BI__builtin_strncmp:
   case Builtin::BIstrncmp:
+  case Builtin::BI__builtin_wcsncmp:
+  case Builtin::BIwcsncmp:
+  case Builtin::BI__builtin_wcscmp:
+  case Builtin::BIwcscmp:
 if (!interp__builtin_strcmp(S, OpPC, Frame, F, Call))
   return false;
 break;

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 828822375e95e..8408286314bb8 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -28,6 +28,8 @@ extern "C" {
   extern char *strchr(const char *s, int c);
   extern wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n);
   extern wchar_t *wcschr(const wchar_t *s, wchar_t c);
+  extern int wcscmp(const wchar_t *s1, const wchar_t *s2);
+  extern int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n);
 }
 
 namespace strcmp {
@@ -72,6 +74,50 @@ namespace strcmp {
   static_assert(__builtin_strncmp("abab\0banana", "abab\0canada", 100) == 0);
 }
 
+namespace WcsCmp {
+  constexpr wchar_t kFoobar[6] = {L'f',L'o',L'o',L'b',L'a',L'r'};
+  constexpr wchar_t kFoobazfoobar[12] = 
{L'f',L'o',L'o',L'b',L'a',L'z',L'f',L'o',L'o',L'b',L'a',L'r'};
+
+  static_assert(_

[clang] [RFC][clang] Fix for regression #130917 (PR #132214)

2025-03-26 Thread Dmitry Polukhin via cfe-commits

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


[clang] [clang][bytecode] Print more info in Block::dump() (PR #133062)

2025-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Disasm.cpp (+8) 


``diff
diff --git a/clang/lib/AST/ByteCode/Disasm.cpp 
b/clang/lib/AST/ByteCode/Disasm.cpp
index 85fc30482b003..12c434029562d 100644
--- a/clang/lib/AST/ByteCode/Disasm.cpp
+++ b/clang/lib/AST/ByteCode/Disasm.cpp
@@ -383,11 +383,19 @@ LLVM_DUMP_METHOD void Block::dump(llvm::raw_ostream &OS) 
const {
   for (const Pointer *P = Pointers; P; P = P->Next) {
 ++NPointers;
   }
+  OS << "  EvalID: " << EvalID << '\n';
+  OS << "  DeclID: ";
+  if (DeclID)
+OS << *DeclID << '\n';
+  else
+OS << "-\n";
   OS << "  Pointers: " << NPointers << "\n";
   OS << "  Dead: " << IsDead << "\n";
   OS << "  Static: " << IsStatic << "\n";
   OS << "  Extern: " << IsExtern << "\n";
   OS << "  Initialized: " << IsInitialized << "\n";
+  OS << "  Weak: " << IsWeak << "\n";
+  OS << "  Dynamic: " << IsDynamic << "\n";
 }
 
 LLVM_DUMP_METHOD void EvaluationResult::dump() const {

``




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


[clang] [Docs] Document freestanding requirements (PR #132232)

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


@@ -1073,6 +1073,29 @@ inputs. Here is some example of ``$``-prefixed options:
 Language and Target-Independent Features
 
 
+Freestanding Builds
+---
+Passing the ``-ffreestanding`` flag causes Clang to build for a freestanding
+(rather than a hosted) environment. The flag has the following effects:
+
+* the ``__STDC_HOSTED__`` predefined macro will expand to ``0``,
+* builtin functions are disabled (``-fno-builtins``),
+* unwind tables are disabled (``fno-asynchronous-unwind-tables 
-fno-unwind-tables``),
+* allows ``main`` to be used as a regular function, and
+* removes implicit system header search paths and link libraries.

efriedma-quic wrote:

I don't see any code in clang that "removes implicit system header search paths 
and link libraries" if you pass -ffreestanding.  Can someone point me to it?

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


[clang] [flang] [llvm] [AMDGPU] Add "lds-buffer-load-insts" attribute for all targets < gfx11 (PR #133055)

2025-03-26 Thread Jay Foad via cfe-commits
Juan Manuel Martinez =?utf-8?q?Caamaño?= 
Message-ID:
In-Reply-To: 


jayfoad wrote:

At the hardware level, GFX11 removed the ability for buffer, **scratch** and 
**global** instructions to return directly to LDS. So can we use one attribute 
that covers all three of those?

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


[clang] [clang] Placement new error when modifying consts (PR #132460)

2025-03-26 Thread marius doerner via cfe-commits

https://github.com/mariusdr created 
https://github.com/llvm/llvm-project/pull/132460

Closes #131432

Raise an error when placement new is used to modify a const-qualified variable 
in a constexpr function. 

Note that diag::note_constexpr_modify_const_type is used since the it is also 
raised when the sample program is compiled with 
'-fexperimental-new-constant-interpreter'.

>From d4af25b14fb21f50c3771cce4595ca5c1bb920a7 Mon Sep 17 00:00:00 2001
From: marius doerner 
Date: Fri, 21 Mar 2025 20:19:57 +0100
Subject: [PATCH] [clang] Placement new error when modifying consts

Raise an error when placement new is used to modify a const-qualified
variable in a constexpr function.
---
 clang/lib/AST/ExprConstant.cpp|  9 ++
 clang/test/AST/ByteCode/placement-new.cpp | 39 +++
 2 files changed, 48 insertions(+)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 92a28897cf3ee..b4fc3d4471064 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10415,7 +10415,16 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const 
CXXNewExpr *E) {
 
   typedef bool result_type;
   bool failed() { return false; }
+  bool checkConst(QualType QT) {
+if (QT.isConstQualified()) {
+  Info.FFDiag(E, diag::note_constexpr_modify_const_type) << QT;
+  return false;
+}
+return true;
+  }
   bool found(APValue &Subobj, QualType SubobjType) {
+if (!checkConst(SubobjType))
+  return false;
 // FIXME: Reject the cases where [basic.life]p8 would not permit the
 // old name of the object to be used to name the new object.
 unsigned SubobjectSize = 1;
diff --git a/clang/test/AST/ByteCode/placement-new.cpp 
b/clang/test/AST/ByteCode/placement-new.cpp
index c353162a7aab0..9b12c9f2b1714 100644
--- a/clang/test/AST/ByteCode/placement-new.cpp
+++ b/clang/test/AST/ByteCode/placement-new.cpp
@@ -376,3 +376,42 @@ constexpr int N = [] // expected-error {{must be 
initialized by a constant expre
 return s.a[0];
 }();
 #endif
+
+constexpr int modify_const_variable() {
+  const int a = 10;
+  new ((int *)&a) int(12); // both-note {{modification of object of 
const-qualified type 'const int' is not allowed in a constant expression}}
+  return a;
+}
+static_assert(modify_const_variable()); // both-error {{not an integral 
constant expression}} \
+// both-note {{in call to}}
+
+typedef const int T0;
+typedef T0 T1;
+constexpr T1 modify_const_variable_td() {
+  T1 a = 10;
+  new ((int *)&a) int(12); // both-note {{modification of object of 
const-qualified type 'T1' (aka 'const int') is not allowed in a constant 
expression}}
+  return a;
+}
+static_assert(modify_const_variable_td()); // both-error {{not an integral 
constant expression}} \
+   // both-note {{in call to}}
+
+template
+constexpr T modify_const_variable_tmpl() {
+  T a = 10;
+  new ((int *)&a) int(12); // both-note {{modification of object of 
const-qualified type 'const int' is not allowed in a constant expression}}
+  return a;
+}
+static_assert(modify_const_variable_tmpl()); // both-error {{not an 
integral constant expression}} \
+// both-note {{in call 
to}}
+
+namespace ModifyMutableMember {
+  struct S {
+mutable int a {10};
+  };
+  constexpr int modify_mutable_member() {
+const S s;
+new ((int *)&s.a) int(12);
+return s.a;
+  }
+  static_assert(modify_mutable_member() == 12);
+}

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


[clang] [clang][bytecode] Fix zero-init of atomic floating point objects (PR #132782)

2025-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

We can't pass the AtomicType along to ASTContext::getFloatTypeSemantics.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3) 
- (modified) clang/test/AST/ByteCode/floats.cpp (+4-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 943e4302a0398..5242a524308a8 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4033,6 +4033,9 @@ template  bool 
Compiler::visitBool(const Expr *E) {
 template 
 bool Compiler::visitZeroInitializer(PrimType T, QualType QT,
  const Expr *E) {
+  if (const auto *AT = QT->getAs())
+QT = AT->getValueType();
+
   switch (T) {
   case PT_Bool:
 return this->emitZeroBool(E);
diff --git a/clang/test/AST/ByteCode/floats.cpp 
b/clang/test/AST/ByteCode/floats.cpp
index 45c31c759e47f..930921d0eee1f 100644
--- a/clang/test/AST/ByteCode/floats.cpp
+++ b/clang/test/AST/ByteCode/floats.cpp
@@ -175,7 +175,10 @@ namespace ZeroInit {
   static_assert(a.f == 0.0f, "");
 
   constexpr A b{12};
-  static_assert(a.f == 0.0, "");
+  static_assert(b.f == 0.0, "");
+
+  constexpr A<_Atomic(float)> c{12};
+  static_assert(c.f == 0.0, "");
 };
 
 namespace LongDouble {

``




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


[clang] cca0f81 - [PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994) (#132802)

2025-03-26 Thread via cfe-commits

Author: Paul Schwabauer
Date: 2025-03-25T13:24:21+08:00
New Revision: cca0f8113e2f9a1bd662c62dd3ff7e1fa197e6b5

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

LOG: [PATCH] [clang][modules] Fix serialization and de-serialization of PCH 
module file refs  (#105994) (#132802)

The File ID is incorrectly calculated, resulting in an out-of-bounds
access. The test code is more complex because the File fetching only
happens in specific scenarios.

-

Co-authored-by: ShaderKeeper 
Co-authored-by: Chuanqi Xu 

Added: 
clang/test/Modules/MixedModulePrecompile.cpp

Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 2728e93c69516..0cd2cedb48dd9 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -9613,9 +9613,9 @@ ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &M, 
unsigned ID) const {
 return I == GlobalSubmoduleMap.end() ? nullptr : I->second;
   } else {
 // It's a prefix (preamble, PCH, ...). Look it up by index.
-unsigned IndexFromEnd = ID >> 1;
+   int IndexFromEnd = static_cast(ID >> 1);
 assert(IndexFromEnd && "got reference to unknown module file");
-return getModuleManager().pch_modules().end()[-IndexFromEnd];
+return 
getModuleManager().pch_modules().end()[-static_cast(IndexFromEnd)];
   }
 }
 
@@ -9633,7 +9633,7 @@ unsigned ASTReader::getModuleFileID(ModuleFile *M) {
   auto PCHModules = getModuleManager().pch_modules();
   auto I = llvm::find(PCHModules, M);
   assert(I != PCHModules.end() && "emitting reference to unknown file");
-  return (I - PCHModules.end()) << 1;
+  return std::distance(I, PCHModules.end()) << 1;
 }
 
 std::optional ASTReader::getSourceDescriptor(unsigned ID) 
{

diff  --git a/clang/test/Modules/MixedModulePrecompile.cpp 
b/clang/test/Modules/MixedModulePrecompile.cpp
new file mode 100644
index 0..473817ef71de6
--- /dev/null
+++ b/clang/test/Modules/MixedModulePrecompile.cpp
@@ -0,0 +1,63 @@
+// Tests mixed usage of precompiled headers and modules.
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -x c++-header -emit-pch %t/a.hpp \
+// RUN: -o %t/a.pch
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part1.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part1.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part2.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part2.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part3.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part3.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part4.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Part4.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface \
+// RUN: -fmodule-file=mod:part1=%t/Part1.pcm \
+// RUN: -fmodule-file=mod:part2=%t/Part2.pcm \
+// RUN: -fmodule-file=mod:part3=%t/Part3.pcm \
+// RUN: -fmodule-file=mod:part4=%t/Part4.pcm \
+// RUN: %t/Mod.cppm \
+// RUN: -include-pch %t/a.pch -o %t/Mod.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj \
+// RUN: -main-file-name Mod.cppm \
+// RUN: -fmodule-file=mod:part1=%t/Part1.pcm \
+// RUN: -fmodule-file=mod:part2=%t/Part2.pcm \
+// RUN: -fmodule-file=mod:part3=%t/Part3.pcm \
+// RUN: -fmodule-file=mod:part4=%t/Part4.pcm \
+// RUN: -x pcm %t/Mod.pcm \
+// RUN: -include-pch %t/a.pch -o %t/Mod.o
+
+
+//--- a.hpp
+#pragma once
+
+class a {
+  virtual ~a();
+  a() {}
+};
+
+//--- Part1.cppm
+export module mod:part1;
+
+//--- Part2.cppm
+export module mod:part2;
+
+//--- Part3.cppm
+export module mod:part3;
+
+//--- Part4.cppm
+export module mod:part4;
+
+//--- Mod.cppm
+export module mod;
+export import :part1;
+export import :part2;
+export import :part3;
+export import :part4;
+



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


[clang] [clang-tools-extra] Reland: [clang] NFC: Clear some uses of MemberPointerType::getClass (PR #132317)

2025-03-26 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

The reduced test case:
```
template 
struct A;
template 
struct A {};
template 
void e(T) {
  A f;
}
struct S {
  struct C {
void h(int &, S *);
  };
  void i() { e(&C::h); }
};
```

https://gcc.godbolt.org/z/8Pq9EWbTv

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


[clang] [clang][analyzer] Ignore unnamed bitfields in UninitializedObjectChecker (PR #132427)

2025-03-26 Thread Abhinav Kumar via cfe-commits

https://github.com/kr-2003 updated 
https://github.com/llvm/llvm-project/pull/132427

>From 72aafcc255bbcfccb3fa5317e260faf97a3dfed5 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Fri, 21 Mar 2025 20:45:11 +0530
Subject: [PATCH 1/4] [clang][analyzer] Removed warnings for unnamed bitfields

---
 .../UninitializedObject/UninitializedObjectChecker.cpp| 4 
 1 file changed, 4 insertions(+)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index 6e1222fedad3e..bf954c3711309 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -332,6 +332,10 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 }
 
 if (isPrimitiveType(T)) {
+  if (I->isUnnamedBitField()) {
+IsAnyFieldInitialized = true;
+continue;
+  }
   if (isPrimitiveUninit(V)) {
 if (addFieldToUninits(LocalChain.add(RegularField(FR
   ContainsUninitField = true;

>From ff01085e3e7aaab4a5dd54e69b3f5be19d43001f Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Fri, 21 Mar 2025 22:46:33 +0530
Subject: [PATCH 2/4] removed IsAnyFieldInitialized after isUnnamedBitField

---
 .../Checkers/UninitializedObject/UninitializedObjectChecker.cpp  | 1 -
 1 file changed, 1 deletion(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index bf954c3711309..bf7759975b3ec 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -333,7 +333,6 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 
 if (isPrimitiveType(T)) {
   if (I->isUnnamedBitField()) {
-IsAnyFieldInitialized = true;
 continue;
   }
   if (isPrimitiveUninit(V)) {

>From fdff9198f3355ff2f27da5f8682875ba500cbeb9 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Sat, 22 Mar 2025 03:34:17 +0530
Subject: [PATCH 3/4] added regression tests for unnamed bitfield

---
 .../Analysis/cxx-uninitialized-object.cpp | 21 +++
 1 file changed, 21 insertions(+)

diff --git a/clang/test/Analysis/cxx-uninitialized-object.cpp 
b/clang/test/Analysis/cxx-uninitialized-object.cpp
index e3fa8ae8d7f29..43b1628388509 100644
--- a/clang/test/Analysis/cxx-uninitialized-object.cpp
+++ b/clang/test/Analysis/cxx-uninitialized-object.cpp
@@ -1182,3 +1182,24 @@ void fComplexTest() {
   // TODO: we should emit a warning for x2.x and x2.y.
   ComplexUninitTest x2;
 }
+
+struct PaddingBitfieldTest {
+  int a;
+  long long : 7; // padding, previously flagged as uninitialized
+  PaddingBitfieldTest(int a) : a(a) {}
+};
+
+void fPaddingBitfieldTest() {
+  PaddingBitfieldTest pb(42);
+  // no-warning: Unnamed bitfield is now ignored, fixing false positive
+}
+
+struct NamedBitfieldTest {
+  int b; 
+  long long named : 7; // expected-note{{uninitialized field 'this->named'}}
+  NamedBitfieldTest(int b) : b(b) {} // expected-warning{{1 uninitialized 
field at the end of the constructor call}}
+};
+
+void fNamedBitfieldTest() {
+  NamedBitfieldTest nb(42); 
+}

>From 1dcddea465721ad58fe69a749c8b6e570d727d57 Mon Sep 17 00:00:00 2001
From: kr-2003 
Date: Wed, 26 Mar 2025 15:45:16 +0530
Subject: [PATCH 4/4] checking unnamed bitfield

---
 .../UninitializedObject/UninitializedObjectChecker.cpp | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index bf7759975b3ec..98b0fbeb72fbb 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -291,7 +291,9 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 
   // Are all of this non-union's fields initialized?
   for (const FieldDecl *I : RD->fields()) {
-
+if (I->isUnnamedBitField()) {
+  continue;
+}
 const auto FieldVal =
 State->getLValue(I, loc::MemRegionVal(R)).castAs();
 const auto *FR = FieldVal.getRegionAs();
@@ -332,9 +334,6 @@ bool FindUninitializedFields::isNonUnionUninit(const 
TypedValueRegion *R,
 }
 
 if (isPrimitiveType(T)) {
-  if (I->isUnnamedBitField()) {
-continue;
-  }
   if (isPrimitiveUninit(V)) {
 if (addFieldToUninits(LocalChain.add(RegularField(FR
   ContainsUninitField = true;

___
cfe-commits mailing lis

[clang] [llvm] [AArch64] Add FEAT_FPAC to Neoverse V2 (PR #133054)

2025-03-26 Thread Ricardo Jesus via cfe-commits

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


[clang] [llvm] [HLSL] Implement the `smoothstep` intrinsic (PR #132288)

2025-03-26 Thread Steven Perron via cfe-commits

https://github.com/s-perron approved this pull request.

The SPV code looks good to me. I just want one small suggestion.

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


[clang] [llvm] [HLSL] Implement the `smoothstep` intrinsic (PR #132288)

2025-03-26 Thread Steven Perron via cfe-commits


@@ -0,0 +1,60 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-unknown %s -o - | 
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - 
-filetype=obj | spirv-val %}

s-perron wrote:

I would like to start having the validation step to include the target 
environment. This will give more robust testing.
```suggestion
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - 
-filetype=obj | spirv-val --target-env vulkan1.2 %}

```

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


[clang] [llvm] [flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX (PR #131041)

2025-03-26 Thread Daniel Chen via cfe-commits

DanielCChen wrote:

@Meinersbur @MaskRay and all other reviewers,

PR #132821 enables `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON` on AIX. As a result, 
I no longer need  to "force" AIX to use `os_dirname` for flang-rt. 

The change in this PR is intact because I re-used the same code to handle the 
option either ON or OFF.

I updated the description of this PR to reflect that.

I will undo PR #130875 and add a LIT test to this PR as soon as PR #132821 
lands. 

Sorry about the change or direction.

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


[clang] [flang] [llvm] [AMDGPU] Add "lds-buffer-load-insts" attribute for all targets < gfx11 (PR #133055)

2025-03-26 Thread Juan Manuel Martinez Caamaño via cfe-commits

jmmartinez wrote:

> > Global load lds is available on gfx9 and gfx10.
> > However, the __builtin_amdgcn_global_load_lds builtin is restricted to 
> > platforms with the attribute gfx940-insts; while it could be available on 
> > gfx90a for example.
> 
> This doesn't sound right, it was new in 940. I also do not see it on gfx10

I saw it on 
https://github.com/llvm/llvm-project/blob/1b07e865a1f9da64c75cc409a969b108b201fe80/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.global.load.lds.ll
 . I haven't went through the docs.

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


[clang] [llvm] [WIP] Clang ABI Types (PR #133080)

2025-03-26 Thread via cfe-commits

https://github.com/easyonaadit updated 
https://github.com/llvm/llvm-project/pull/133080

>From 16f156dbd83fe0b272f9d485584b1fb9d9a04015 Mon Sep 17 00:00:00 2001
From: easyonaadit 
Date: Fri, 21 Mar 2025 11:37:31 +0530
Subject: [PATCH 1/2] temp commit have annotated the code with some parts of
 understanding.

---
 LLVMABI/CGFunctionInfo.h | 841 +++
 clang/include/clang/CodeGen/CGFunctionInfo.h |   2 +-
 clang/lib/CodeGen/ABIInfoImpl.cpp|   2 +-
 clang/lib/CodeGen/CGCall.cpp |  18 +-
 clang/lib/CodeGen/CodeGenAction.cpp  |   2 +-
 clang/lib/CodeGen/CodeGenModule.cpp  |   6 +-
 clang/lib/CodeGen/ModuleBuilder.cpp  |   2 +-
 clang/lib/CodeGen/Targets/AMDGPU.cpp |   2 +-
 clang/lib/Parse/ParseAST.cpp |  10 +-
 clang/lib/Parse/Parser.cpp   |   2 +-
 llvm/include/llvm/ADT/FoldingSet.h   |   2 +-
 11 files changed, 865 insertions(+), 24 deletions(-)
 create mode 100644 LLVMABI/CGFunctionInfo.h

diff --git a/LLVMABI/CGFunctionInfo.h b/LLVMABI/CGFunctionInfo.h
new file mode 100644
index 0..91276e743a8c6
--- /dev/null
+++ b/LLVMABI/CGFunctionInfo.h
@@ -0,0 +1,841 @@
+//==-- CGFunctionInfo.h - Representation of function argument/return types 
-==//
+//
+// 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
+//
+//===--===//
+//
+// Defines CGFunctionInfo and associated types used in representing the
+// LLVM source types and ABI-coerced types for function arguments and
+// return values.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H
+#define LLVM_CLANG_CODEGEN_CGFUNCTIONINFO_H
+
+#include "clang/AST/CanonicalType.h"
+#include "clang/AST/CharUnits.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Type.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/TrailingObjects.h"
+#include 
+
+namespace clang {
+namespace CodeGen {
+
+/// ABIArgInfo - Helper class to encapsulate information about how a
+/// specific C type should be passed to or returned from a function.
+class ABIArgInfo {
+public:
+  enum Kind : uint8_t {
+/// Direct - Pass the argument directly using the normal converted LLVM
+/// type, or by coercing to another specified type stored in
+/// 'CoerceToType').  If an offset is specified (in UIntData), then the
+/// argument passed is offset by some number of bytes in the memory
+/// representation. A dummy argument is emitted before the real argument
+/// if the specified type stored in "PaddingType" is not zero.
+Direct,
+
+/// Extend - Valid only for integer argument types. Same as 'direct'
+/// but also emit a zero/sign extension attribute.
+Extend,
+
+/// Indirect - Pass the argument indirectly via a hidden pointer with the
+/// specified alignment (0 indicates default alignment) and address space.
+Indirect,
+
+/// IndirectAliased - Similar to Indirect, but the pointer may be to an
+/// object that is otherwise referenced.  The object is known to not be
+/// modified through any other references for the duration of the call, and
+/// the callee must not itself modify the object.  Because C allows
+/// parameter variables to be modified and guarantees that they have unique
+/// addresses, the callee must defensively copy the object into a local
+/// variable if it might be modified or its address might be compared.
+/// Since those are uncommon, in principle this convention allows programs
+/// to avoid copies in more situations.  However, it may introduce *extra*
+/// copies if the callee fails to prove that a copy is unnecessary and the
+/// caller naturally produces an unaliased object for the argument.
+IndirectAliased,
+
+/// Ignore - Ignore the argument (treat as void). Useful for void and
+/// empty structs.
+Ignore,
+
+/// Expand - Only valid for aggregate argument types. The structure should
+/// be expanded into consecutive arguments for its constituent fields.
+/// Currently expand is only allowed on structures whose fields
+/// are all scalar types or are themselves expandable types.
+Expand,
+
+/// CoerceAndExpand - Only valid for aggregate argument types. The
+/// structure should be expanded into consecutive arguments corresponding
+/// to the non-array elements of the type stored in CoerceToType.
+/// Array elements in the type are assumed to be padding and skipped.
+CoerceAndExpand,
+
+/// InAlloca - Pass the argument directly using the LLVM inalloca 
attribute.
+/// This is similar to indirect with byval, except it only applies to
+//

[clang] [HLSL][NFC] Refactor HLSLExternalSemaSource (PR #131032)

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

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/131032

>From 7ebfc826ca27c71ef80f4a1b38b2d3a2e155b777 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 12 Mar 2025 14:09:24 -0700
Subject: [PATCH 1/5] [HLSL][NFC] Refactoring HLSLExternalSemaSource

Moving builder classes into separate files 
`HLSLBuiltinTypeDeclBuilder.cpp`/`.h` and changing a some 
`HLSLExternalSemaSource` methods to private.

This is a prep work before we start adding more builtin types and methods, like 
textures or resource constructors. For example constructors could make use of 
the `BuiltinTypeMethodBuilder`, but this helper class was defined in 
`HLSLExternalSemaSource.cpp` after the method that creates a constructor. 
Rather than reshuffling the code one big source file I am moving the builders 
into a separate cpp & header file and placing the helper classes declarations 
up top.

Currently the new header only exposes `BuiltinTypeDeclBuilder` to 
`HLSLExternalSemaSource`. In the future but we might decide to expose more 
helper classes as needed.
---
 .../clang/Sema/HLSLExternalSemaSource.h   |  15 +-
 clang/lib/Sema/CMakeLists.txt |   1 +
 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 782 ++
 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h   |  97 +++
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 750 +
 5 files changed, 890 insertions(+), 755 deletions(-)
 create mode 100644 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
 create mode 100644 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h

diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
index 3c7495e66055d..9c1b16ba3950c 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -21,20 +21,15 @@ class NamespaceDecl;
 class Sema;
 
 class HLSLExternalSemaSource : public ExternalSemaSource {
+private:
   Sema *SemaPtr = nullptr;
   NamespaceDecl *HLSLNamespace = nullptr;
 
   using CompletionFunction = std::function;
   llvm::DenseMap Completions;
 
-  void defineHLSLVectorAlias();
-  void defineTrivialHLSLTypes();
-  void defineHLSLTypesWithForwardDeclarations();
-
-  void onCompletion(CXXRecordDecl *Record, CompletionFunction Fn);
-
 public:
-  ~HLSLExternalSemaSource() override;
+  ~HLSLExternalSemaSource() override {}
 
   /// Initialize the semantic source with the Sema instance
   /// being used to perform semantic analysis on the abstract syntax
@@ -47,6 +42,12 @@ class HLSLExternalSemaSource : public ExternalSemaSource {
   using ExternalASTSource::CompleteType;
   /// Complete an incomplete HLSL builtin type
   void CompleteType(TagDecl *Tag) override;
+
+private:
+  void defineTrivialHLSLTypes();
+  void defineHLSLVectorAlias();
+  void defineHLSLTypesWithForwardDeclarations();
+  void onCompletion(CXXRecordDecl *Record, CompletionFunction Fn);
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 1a351684d133e..d3fe80f659f69 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangSema
   DeclSpec.cpp
   DelayedDiagnostic.cpp
   HeuristicResolver.cpp
+  HLSLBuiltinTypeDeclBuilder.cpp
   HLSLExternalSemaSource.cpp
   IdentifierResolver.cpp
   JumpDiagnostics.cpp
diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp 
b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
new file mode 100644
index 0..db0ed3434d837
--- /dev/null
+++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
@@ -0,0 +1,782 @@
+//===--- HLSLBuiltinTypeDeclBuilder.cpp - HLSL Builtin Type Decl Builder 
--===//
+//
+// 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 "HLSLBuiltinTypeDeclBuilder.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaHLSL.h"
+#include "llvm/ADT/SmallVector.h"
+
+using namespace llvm::hlsl;
+
+namespace clang {
+
+namespace hlsl {
+
+namespace {
+
+static FunctionDecl *lookupBuiltinFunction(Sema &S, StringRef Name) {
+  IdentifierInfo &II =
+  S.getASTContext().Idents.get(Name, tok::TokenKind::identifier);
+  DeclarationNameInfo NameInfo =
+  DeclarationNameInfo(DeclarationName(&II), SourceLocation());
+  LookupResult R(S, NameInfo, Sema::LookupOrdinaryName);
+  // AllowBuiltinCreation is false but LookupDirect will create
+  // the builtin wh

[clang] [clang][DependencyScanning] Track dependencies from prebuilt modules to determine IsInStableDir (PR #132237)

2025-03-26 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/132237

>From ccbcd77e5bd6712531a23bcd79fc9380fdc3d9bf Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 12 Mar 2025 21:26:36 -0700
Subject: [PATCH 1/3] [clang][DependencyScanning] Track dependencies from
 prebuilt modules to determine IsInStableDir

When a module is being scanned, it can depend on modules that have
already been built from a pch dependency. When this happens, the
pcm files are reused for the module dependencies. When this is the case,
check if input files recorded from the PCMs come from the provided stable 
directories transitively,
since the scanner will not have access to the full set of file dependencies 
from prebuilt modules.
---
 clang/include/clang/Serialization/ASTReader.h |  11 ++
 .../DependencyScanning/ModuleDepCollector.h   |  59 +-
 clang/lib/Serialization/ASTReader.cpp |   6 +-
 .../DependencyScanningWorker.cpp  | 111 +++---
 .../DependencyScanning/ModuleDepCollector.cpp |  89 --
 .../prebuilt-modules-in-stable-dirs.c |  24 +++-
 6 files changed, 233 insertions(+), 67 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 2779b3d1cf2ea..9e360c9409b89 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -237,6 +237,17 @@ class ASTReaderListener {
 return true;
   }
 
+  /// Overloaded member function of \c visitInputFile that should
+  /// be defined when the input file contains both the virtual and external
+  /// paths, for example when deserializing input files from AST files.
+  ///
+  /// \returns true to continue receiving the next input file, false to stop.
+  virtual bool visitInputFile(StringRef FilenameAsRequested, StringRef 
Filename,
+  bool isSystem, bool isOverridden,
+  bool isExplicitModule) {
+return true;
+  }
+
   /// Returns true if this \c ASTReaderListener wants to receive the
   /// imports of the AST file via \c visitImport, false otherwise.
   virtual bool needsImportVisitation() const { return false; }
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 422202caddfd4..95fcb25aca450 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -33,6 +33,7 @@ namespace dependencies {
 
 class DependencyActionController;
 class DependencyConsumer;
+class PrebuiltModuleASTAttrs;
 
 /// Modular dependency that has already been built prior to the dependency 
scan.
 struct PrebuiltModuleDep {
@@ -46,6 +47,47 @@ struct PrebuiltModuleDep {
 ModuleMapFile(M->PresumedModuleMapFile) {}
 };
 
+/// Attributes loaded from AST files of prebuilt modules collected prior to
+/// ModuleDepCollector creation.
+using PrebuiltModulesAttrsMap = llvm::StringMap;
+class PrebuiltModuleASTAttrs {
+public:
+  /// When a module is discovered to not be in stable directories, traverse &
+  /// update all modules that depend on it.
+  void
+  updateDependentsNotInStableDirs(PrebuiltModulesAttrsMap &PrebuiltModulesMap);
+
+  /// Read-only access to whether the module is made up of dependencies in
+  /// stable directories.
+  bool isInStableDir() const { return IsInStableDirs; }
+
+  /// Read-only access to vfs map files.
+  const llvm::StringSet<> &getVFS() const { return VFSMap; }
+
+  /// Update the VFSMap to the one discovered from serializing the AST file.
+  void setVFS(llvm::StringSet<> &&VFS) { VFSMap = std::move(VFS); }
+
+  /// Add a direct dependent module file, so it can be updated if the current
+  /// module is from stable directores.
+  void addDependent(StringRef ModuleFile) {
+ModuleFileDependents.insert(ModuleFile);
+  }
+
+  /// Update whether the prebuilt module resolves entirely in a stable
+  /// directories.
+  void setInStableDir(bool V = false) {
+// Cannot reset attribute once it's false.
+if (!IsInStableDirs)
+  return;
+IsInStableDirs = V;
+  }
+
+private:
+  llvm::StringSet<> VFSMap;
+  bool IsInStableDirs = true;
+  std::set ModuleFileDependents;
+};
+
 /// This is used to identify a specific module.
 struct ModuleID {
   /// The name of the module. This may include `:` for C++20 module partitions,
@@ -170,8 +212,6 @@ struct ModuleDeps {
   BuildInfo;
 };
 
-using PrebuiltModuleVFSMapT = llvm::StringMap>;
-
 class ModuleDepCollector;
 
 /// Callback that records textual includes and direct modular includes/imports
@@ -241,7 +281,7 @@ class ModuleDepCollector final : public DependencyCollector 
{
  CompilerInstance &ScanInstance, DependencyConsumer &C,
  DependencyActionController &Controller,
  CompilerInvocation OriginalCI,

[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)

2025-03-26 Thread Paul Kirth via cfe-commits

ilovepi wrote:

> Should I modify `HTMLGeneratorTest.cpp` to test `RepositoryLinePrefix`?
> 
> https://github.com/llvm/llvm-project/blob/7a370748c0928b9ccfe26127e54eb3c1a1827d75/clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp#L179

You can, but please make that its own test.

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


[clang] [flang] [llvm] [AMDGPU] Add "lds-buffer-load-insts" attribute for all targets < gfx11 (PR #133055)

2025-03-26 Thread Matt Arsenault via cfe-commits
Juan Manuel Martinez =?utf-8?q?Caamaño?= 
Message-ID:
In-Reply-To: 


arsenm wrote:

> Global load lds is available on gfx9 and gfx10. 
> However, the __builtin_amdgcn_global_load_lds builtin is restricted to 
> platforms with the attribute gfx940-insts; while it could be available on 
> gfx90a for example.

This doesn't sound right, it was new in 940. I also do not see it on gfx10



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


[libclc] [libclc] Fix commands in compile_to_bc are executed sequentially (PR #130755)

2025-03-26 Thread Fraser Cormack via cfe-commits


@@ -256,19 +261,25 @@ function(add_libclc_builtin_set)
 
 get_filename_component( file_dir ${file} DIRECTORY )
 
+string( REPLACE "/" "-" replaced ${file} )
+set( tgt compile_tgt-${ARG_ARCH_SUFFIX}${replaced})
+
 compile_to_bc(
+  TARGET ${tgt}
   TRIPLE ${ARG_TRIPLE}
   INPUT ${input_file}
   OUTPUT ${output_file}
   EXTRA_OPTS -fno-builtin -nostdlib
 "${ARG_COMPILE_FLAGS}" -I${CMAKE_CURRENT_SOURCE_DIR}/${file_dir}
   DEPENDENCIES ${input_file_dep}
 )
+list( APPEND compile_tgts ${tgt} )
 
 # Collect all files originating in LLVM IR separately
 get_filename_component( file_ext ${file} EXT )
 if( ${file_ext} STREQUAL ".ll" )
   list( APPEND bytecode_ir_files ${output_file} )
+  list( APPEND compile_tgts ${tgt}-as )

frasercrmck wrote:

See above - we wouldn't need this case if we could rely on a consistent target 
name.

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


[clang-tools-extra] [clang-tidy] do not diagnose array types within implicit instantiations of a template (PR #132924)

2025-03-26 Thread St. Muench via cfe-commits

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


[clang] c3e08c8 - [HLSL] Add new double overloads for math builtins (#132979)

2025-03-26 Thread via cfe-commits

Author: Sarah Spall
Date: 2025-03-26T07:54:13-07:00
New Revision: c3e08c8f07ded9ef0d1ad2f3fb04e98d839479b1

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

LOG: [HLSL] Add new double overloads for math builtins (#132979)

Add double overloads which cast the double to a float and call the float
builtin.
Makes these double overloads conditional on hlsl version 202x or
earlier.
Add tests
Closes #128228

Added: 


Modified: 
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Headers/hlsl.h
clang/lib/Headers/hlsl/hlsl_compat_overloads.h
clang/test/CodeGenHLSL/builtins/acos.hlsl
clang/test/CodeGenHLSL/builtins/asin.hlsl
clang/test/CodeGenHLSL/builtins/atan.hlsl
clang/test/CodeGenHLSL/builtins/atan2.hlsl
clang/test/CodeGenHLSL/builtins/ceil.hlsl
clang/test/CodeGenHLSL/builtins/cos.hlsl
clang/test/CodeGenHLSL/builtins/cosh.hlsl
clang/test/CodeGenHLSL/builtins/degrees.hlsl
clang/test/CodeGenHLSL/builtins/exp.hlsl
clang/test/CodeGenHLSL/builtins/exp2.hlsl
clang/test/CodeGenHLSL/builtins/floor.hlsl
clang/test/CodeGenHLSL/builtins/frac.hlsl
clang/test/CodeGenHLSL/builtins/isinf.hlsl
clang/test/CodeGenHLSL/builtins/lerp.hlsl
clang/test/CodeGenHLSL/builtins/log.hlsl
clang/test/CodeGenHLSL/builtins/log10.hlsl
clang/test/CodeGenHLSL/builtins/log2.hlsl
clang/test/CodeGenHLSL/builtins/normalize.hlsl
clang/test/CodeGenHLSL/builtins/pow.hlsl
clang/test/CodeGenHLSL/builtins/radians.hlsl
clang/test/CodeGenHLSL/builtins/round.hlsl
clang/test/CodeGenHLSL/builtins/rsqrt.hlsl
clang/test/CodeGenHLSL/builtins/sin.hlsl
clang/test/CodeGenHLSL/builtins/sinh.hlsl
clang/test/CodeGenHLSL/builtins/sqrt.hlsl
clang/test/CodeGenHLSL/builtins/step.hlsl
clang/test/CodeGenHLSL/builtins/tan.hlsl
clang/test/CodeGenHLSL/builtins/tanh.hlsl
clang/test/CodeGenHLSL/builtins/trunc.hlsl

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 1a816cb6269d4..0b54665501c76 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -394,6 +394,10 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
 // HLSL Version
 Builder.defineMacro("__HLSL_VERSION",
 Twine((unsigned)LangOpts.getHLSLVersion()));
+Builder.defineMacro("__HLSL_202x",
+Twine((unsigned)LangOptions::HLSLLangStd::HLSL_202x));
+Builder.defineMacro("__HLSL_202y",
+Twine((unsigned)LangOptions::HLSLLangStd::HLSL_202y));
 
 if (LangOpts.NativeHalfType)
   Builder.defineMacro("__HLSL_ENABLE_16_BIT", "1");

diff  --git a/clang/lib/Headers/hlsl.h b/clang/lib/Headers/hlsl.h
index d233f6092ffcd..b494b4d0f78bb 100644
--- a/clang/lib/Headers/hlsl.h
+++ b/clang/lib/Headers/hlsl.h
@@ -22,7 +22,9 @@
 
 // HLSL standard library function declarations/definitions.
 #include "hlsl/hlsl_alias_intrinsics.h"
+#if __HLSL_VERSION <= __HLSL_202x
 #include "hlsl/hlsl_compat_overloads.h"
+#endif
 #include "hlsl/hlsl_intrinsics.h"
 
 #if defined(__clang__)

diff  --git a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h 
b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
index aff514ef74208..d8dac0a3942ad 100644
--- a/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
+++ b/clang/lib/Headers/hlsl/hlsl_compat_overloads.h
@@ -16,6 +16,70 @@ namespace hlsl {
 // unsigned integer and floating point. Keeping this ordering consistent will
 // help keep this file manageable as it grows.
 
+#define _DXC_COMPAT_UNARY_DOUBLE_OVERLOADS(fn) 
\
+  constexpr float fn(double V) { return fn((float)V); }
\
+  constexpr float2 fn(double2 V) { return fn((float2)V); } 
\
+  constexpr float3 fn(double3 V) { return fn((float3)V); } 
\
+  constexpr float4 fn(double4 V) { return fn((float4)V); }
+
+#define _DXC_COMPAT_BINARY_DOUBLE_OVERLOADS(fn)
\
+  constexpr float fn(double V1, double V2) {   
\
+return fn((float)V1, (float)V2);   
\
+  }
\
+  constexpr float2 fn(double2 V1, double2 V2) {
\
+return fn((float2)V1, (float2)V2); 
\
+  }
\
+  constexpr float3 fn(double3 V1, double3 V2) {
\
+return fn((float3)V1, (float3)V2); 
\
+  }  

[clang] 529c5b7 - [flang] Add -f[no-]slp-vectorize flags (#132801)

2025-03-26 Thread via cfe-commits

Author: Kajetan Puchalski
Date: 2025-03-26T16:10:35Z
New Revision: 529c5b71c608c18141432e6fd0ae89242d5f309d

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

LOG: [flang] Add -f[no-]slp-vectorize flags (#132801)

Add -f[no-]slp-vectorize to the flang driver.
Add corresponding -fvectorize-slp to the flang frontend.

Enable -fslp-vectorize at -O2 and higher in flang to match the current
behaviour in clang.

-

Signed-off-by: Kajetan Puchalski 

Added: 
flang/test/Driver/slp-vectorize.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CodeGenOptions.def
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 59a57c83c6b89..ca56ed264e1d6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4030,13 +4030,14 @@ def fvectorize : Flag<["-"], "fvectorize">, 
Group,
 def fno_vectorize : Flag<["-"], "fno-vectorize">, Group;
 def : Flag<["-"], "ftree-vectorize">, Alias;
 def : Flag<["-"], "fno-tree-vectorize">, Alias;
-}
 
 def fslp_vectorize : Flag<["-"], "fslp-vectorize">, Group,
   HelpText<"Enable the superword-level parallelism vectorization passes">;
 def fno_slp_vectorize : Flag<["-"], "fno-slp-vectorize">, Group;
 def : Flag<["-"], "ftree-slp-vectorize">, Alias;
 def : Flag<["-"], "fno-tree-slp-vectorize">, Alias;
+}
+
 def Wlarge_by_value_copy_def : Flag<["-"], "Wlarge-by-value-copy">,
   HelpText<"Warn if a function definition returns or accepts an object larger "
"in bytes than a given value">, Flags<[HelpHidden]>;
@@ -7384,6 +7385,9 @@ def mlink_bitcode_file
 def vectorize_loops : Flag<["-"], "vectorize-loops">,
   HelpText<"Run the Loop vectorization passes">,
   MarshallingInfoFlag>;
+def vectorize_slp : Flag<["-"], "vectorize-slp">,
+  HelpText<"Run the SLP vectorization passes">,
+  MarshallingInfoFlag>;
 } // let Visibility = [CC1Option, FC1Option]
 
 let Visibility = [CC1Option] in {
@@ -7499,9 +7503,6 @@ defm link_builtin_bitcode_postopt: 
BoolMOption<"link-builtin-bitcode-postopt",
   PosFlag,
   NegFlag>;
-def vectorize_slp : Flag<["-"], "vectorize-slp">,
-  HelpText<"Run the SLP vectorization passes">,
-  MarshallingInfoFlag>;
 def linker_option : Joined<["--"], "linker-option=">,
   HelpText<"Add linker option">,
   MarshallingInfoStringVector>;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 7aa2b32acc235..e1e8f57dd6455 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7597,24 +7597,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm,
  options::OPT_fno_gnu_inline_asm);
 
-  // Enable vectorization per default according to the optimization level
-  // selected. For optimization levels that want vectorization we use the alias
-  // option to simplify the hasFlag logic.
-  bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false);
-  OptSpecifier VectorizeAliasOption =
-  EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;
-  if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption,
-   options::OPT_fno_vectorize, EnableVec))
-CmdArgs.push_back("-vectorize-loops");
-
-  // -fslp-vectorize is enabled based on the optimization level selected.
-  bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true);
-  OptSpecifier SLPVectAliasOption =
-  EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
-  if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,
-   options::OPT_fno_slp_vectorize, EnableSLPVec))
-CmdArgs.push_back("-vectorize-slp");
-
+  handleVectorizeLoopsArgs(Args, CmdArgs);
+  handleVectorizeSLPArgs(Args, CmdArgs);
   ParseMPreferVectorWidth(D, Args, CmdArgs);
 
   Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7f04bcab9cd80..1945c95458c54 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -3171,3 +3171,23 @@ bool tools::shouldEnableVectorizerAtOLevel(const ArgList 
&Args, bool isSlpVec) {
 
   return false;
 }
+
+void tools::handleVectorizeLoopsArgs(const ArgList &Args,
+ ArgStringList &CmdArgs) {
+  bool EnableVec = shouldEnableVectorizerAtOLev

[clang] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-26 Thread Tom Eccles via cfe-commits

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


[clang] [Docs] Document freestanding requirements (PR #132232)

2025-03-26 Thread Aaron Ballman via cfe-commits


@@ -1073,6 +1073,28 @@ inputs. Here is some example of ``$``-prefixed options:
 Language and Target-Independent Features
 
 
+Freestanding Builds
+---
+Passing the ``-ffreestanding`` flag causes Clang to build for a freestanding
+(rather than a hosted) environment. The flag has the following effects:
+
+* the ``__STDC_HOSTED__`` predefined macro will expand to ``0``,
+* builtin functions are disabled (``-fno-builtins``),
+* unwind tables are disabled (``fno-asynchronous-unwind-tables 
-fno-unwind-tables``), and
+* allows ``main`` to be used as a regular symbol.
+
+A freestanding environment is not one which has no C standard library support.

AaronBallman wrote:

I've updated the wording along the lines of what @jyknight proposed.

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


[clang] [NFC][clang] Remove superfluous header files after refactor in #132252 (PR #132495)

2025-03-26 Thread Jonathan Thackray via cfe-commits

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


[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)

2025-03-26 Thread Paul Schwabauer via cfe-commits

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


[clang] [llvm] [clang][CodeGen] Generate follow-up metadata for loops in correct format (PR #131985)

2025-03-26 Thread Michael Kruse via cfe-commits

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

LGTM, great work!

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


[clang] [llvm] [clang][CodeGen] Generate follow-up metadata for loops in correct format (PR #131985)

2025-03-26 Thread Michael Kruse via cfe-commits


@@ -44,23 +44,19 @@ MDNode *LoopInfo::createPipeliningMetadata(const 
LoopAttributes &Attrs,
   else if (Attrs.PipelineInitiationInterval != 0)
 Enabled = true;
 
+  SmallVector Args;
+  Args.append(LoopProperties.begin(), LoopProperties.end());
+
   if (Enabled != true) {
-SmallVector NewLoopProperties;
 if (Enabled == false) {
-  NewLoopProperties.append(LoopProperties.begin(), LoopProperties.end());
-  NewLoopProperties.push_back(
+  Args.push_back(
   MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.pipeline.disable"),
 ConstantAsMetadata::get(ConstantInt::get(
 llvm::Type::getInt1Ty(Ctx), 1))}));
-  LoopProperties = NewLoopProperties;

Meinersbur wrote:

I think this is because by design `pipeline` is always the last transformation 
(it is implemented in the back-end, after all the IR optimization passes, there 
can be no transformation after this).

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


[clang] [llvm] [clang][CodeGen] Generate follow-up metadata for loops in correct format (PR #131985)

2025-03-26 Thread Michael Kruse via cfe-commits


@@ -44,23 +44,19 @@ MDNode *LoopInfo::createPipeliningMetadata(const 
LoopAttributes &Attrs,
   else if (Attrs.PipelineInitiationInterval != 0)
 Enabled = true;
 
+  SmallVector Args;
+  Args.append(LoopProperties.begin(), LoopProperties.end());
+
   if (Enabled != true) {
-SmallVector NewLoopProperties;
 if (Enabled == false) {
-  NewLoopProperties.append(LoopProperties.begin(), LoopProperties.end());

Meinersbur wrote:

This line was not executed when `Enabled == std::nullop`, so 
`llvm.mustprogress` (`[[MP]]`) from `LoopProperties` is never added. Should 
have been added unconditionally.

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


[clang] [CIR] Upstream zero init for global variables (PR #133100)

2025-03-26 Thread Amr Hesham via cfe-commits


@@ -67,6 +67,40 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return create(loc, attr.getType(), attr);
   }
 
+  mlir::TypedAttr getConstNullPtrAttr(mlir::Type t) {
+assert(mlir::isa(t) && "expected cir.ptr");
+return getConstPtrAttr(t, 0);
+  }
+
+  mlir::TypedAttr getZeroAttr(mlir::Type t) {
+return cir::ZeroAttr::get(getContext(), t);
+  }
+
+  mlir::TypedAttr getZeroInitAttr(mlir::Type ty) {

AmrDeveloper wrote:

We need to update this function in the incubator to add the missing types 
@andykaylor 

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


[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)

2025-03-26 Thread Paul Kirth via cfe-commits

ilovepi wrote:

The failures on the presubmit bot look unrelated, but you need to update your 
branch, since it looks like the base revision is broken.

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


[clang] [llvm] [clang][CodeGen] Generate follow-up metadata for loops in correct format (PR #131985)

2025-03-26 Thread Michael Kruse via cfe-commits


@@ -170,11 +161,10 @@ LoopInfo::createUnrollAndJamMetadata(const LoopAttributes 
&Attrs,
   MDNode::get(Ctx, MDString::get(Ctx, 
"llvm.loop.unroll_and_jam.disable")));
 
   bool FollowupHasTransforms = false;
-  MDNode *Followup = createPartialUnrollMetadata(Attrs, FollowupLoopProperties,
- FollowupHasTransforms);
+  SmallVector Followup = createPartialUnrollMetadata(
+  Attrs, FollowupLoopProperties, FollowupHasTransforms);
 
   SmallVector Args;
-  Args.push_back(nullptr);

Meinersbur wrote:

That is correct

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


[clang] [llvm] [clang][CodeGen] Generate follow-up metadata for loops in correct format (PR #131985)

2025-03-26 Thread Michael Kruse via cfe-commits

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


[clang] [clang][modules] Lazily load by name lookups in module maps (PR #132853)

2025-03-26 Thread Jan Svoboda via cfe-commits


@@ -373,10 +373,10 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, 
StringRef SearchName,
 SmallString<128> NestedModuleMapDirName;
 NestedModuleMapDirName = Dir.getDirRef()->getName();
 llvm::sys::path::append(NestedModuleMapDirName, ModuleName);
-if (loadModuleMapFile(NestedModuleMapDirName, IsSystem,
-  /*IsFramework*/false) == LMM_NewlyLoaded){
+if (parseModuleMapFile(NestedModuleMapDirName, IsSystem,
+   /*IsFramework*/ false) == MMR_NewlyProcessed) {
   // If we just loaded a module map file, look for the module again.

jansvoboda11 wrote:

```suggestion
  // If we just parsed a module map file, look for the module again.
```

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


[clang] [CIR] Add BinOpOverflowOp and basic pointer arithmetic support (PR #133118)

2025-03-26 Thread Morris Hafner via cfe-commits

mmha wrote:

cc @andykaylor @erichkeane @dkolsen-pgi 

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


[clang] [alpha.webkit.RawPtrRefMemberChecker] The checker doesn't warn Objective-C types in ivars. (PR #132833)

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

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

This PR fixes the bug that we weren't generating warnings when a raw poiner is 
used to point to a NS type in Objective-C ivars. Also fix the bug that we 
weren't suppressing this warning in system headers.

>From ca50deea7d8096b065d2bf7aa5e007afc8f0a954 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Mon, 24 Mar 2025 14:22:28 -0700
Subject: [PATCH] [alpha.webkit.RawPtrRefMemberChecker] The checker doesn't
 warn Objective-C types in ivars.

This PR fixes the bug that we weren't generating warnings when a raw poiner is 
used to
point to a NS type in Objective-C ivars. Also fix the bug that we weren't 
suppressing this
warning in system headers.
---
 .../Checkers/WebKit/RawPtrRefMemberChecker.cpp   | 10 ++
 .../Analysis/Checkers/WebKit/mock-system-header.h| 11 +++
 .../Analysis/Checkers/WebKit/unretained-members.mm   | 12 +++-
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index dc4e2c7d168fb..6d20869043358 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -111,6 +111,8 @@ class RawPtrRefMemberChecker
   }
 
   void visitObjCDecl(const ObjCContainerDecl *CD) const {
+if (BR->getSourceManager().isInSystemHeader(CD->getLocation()))
+  return;
 if (auto *ID = dyn_cast(CD)) {
   for (auto *Ivar : ID->ivars())
 visitIvarDecl(CD, Ivar);
@@ -133,6 +135,14 @@ class RawPtrRefMemberChecker
   std::optional IsCompatible = isPtrCompatible(QT, IvarCXXRD);
   if (IsCompatible && *IsCompatible)
 reportBug(Ivar, IvarType, IvarCXXRD, CD);
+} else {
+  std::optional IsCompatible = isPtrCompatible(QT, nullptr);
+  auto *PointeeType = IvarType->getPointeeType().getTypePtrOrNull();
+  if (IsCompatible && *IsCompatible) {
+auto *Desugared = PointeeType->getUnqualifiedDesugaredType();
+if (auto *ObjCType = dyn_cast_or_null(Desugared))
+  reportBug(Ivar, IvarType, ObjCType->getDecl(), CD);
+  }
 }
   }
 
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-system-header.h 
b/clang/test/Analysis/Checkers/WebKit/mock-system-header.h
index e993fd697ffab..b377f5098c002 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-system-header.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-system-header.h
@@ -29,3 +29,14 @@ enum os_log_type_t : uint8_t {
 typedef struct os_log_s *os_log_t;
 os_log_t os_log_create(const char *subsystem, const char *category);
 void os_log_msg(os_log_t oslog, os_log_type_t type, const char *msg, ...);
+
+typedef const struct __attribute__((objc_bridge(NSString))) __CFString * 
CFStringRef;
+
+#ifdef __OBJC__
+@class NSString;
+@interface SystemObject : NSObject {
+  NSString *ns_string;
+  CFStringRef cf_string;
+}
+@end
+#endif
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm 
b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
index e068a583c18c5..79f7a05caa1be 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
@@ -1,7 +1,8 @@
 // RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.NoUnretainedMemberChecker -verify %s
 
 #include "objc-mock-types.h"
-
+#include "mock-system-header.h"
+#if 0
 namespace members {
 
   struct Foo {
@@ -58,3 +59,12 @@ void forceTmplToInstantiate(FooTmpl) {}
 
   void forceTmplToInstantiate(RefPtr) {}
 }
+#endif
+
+@interface AnotherObject : NSObject {
+  NSString *ns_string;
+  // expected-warning@-1{{Instance variable 'ns_string' in 'AnotherObject' is 
a raw pointer to retainable type 'NSString'; member variables must be a 
RetainPtr}}
+  CFStringRef cf_string;
+  // expected-warning@-1{{Instance variable 'cf_string' in 'AnotherObject' is 
a retainable type 'CFStringRef'; member variables must be a RetainPtr}}
+}
+@end

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


[clang] [HLSL][NFC] Use method builder to create default resource constructor (PR #131384)

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

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/131384

>From 7ebfc826ca27c71ef80f4a1b38b2d3a2e155b777 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Wed, 12 Mar 2025 14:09:24 -0700
Subject: [PATCH 1/6] [HLSL][NFC] Refactoring HLSLExternalSemaSource

Moving builder classes into separate files 
`HLSLBuiltinTypeDeclBuilder.cpp`/`.h` and changing a some 
`HLSLExternalSemaSource` methods to private.

This is a prep work before we start adding more builtin types and methods, like 
textures or resource constructors. For example constructors could make use of 
the `BuiltinTypeMethodBuilder`, but this helper class was defined in 
`HLSLExternalSemaSource.cpp` after the method that creates a constructor. 
Rather than reshuffling the code one big source file I am moving the builders 
into a separate cpp & header file and placing the helper classes declarations 
up top.

Currently the new header only exposes `BuiltinTypeDeclBuilder` to 
`HLSLExternalSemaSource`. In the future but we might decide to expose more 
helper classes as needed.
---
 .../clang/Sema/HLSLExternalSemaSource.h   |  15 +-
 clang/lib/Sema/CMakeLists.txt |   1 +
 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp | 782 ++
 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h   |  97 +++
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 750 +
 5 files changed, 890 insertions(+), 755 deletions(-)
 create mode 100644 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
 create mode 100644 clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h

diff --git a/clang/include/clang/Sema/HLSLExternalSemaSource.h 
b/clang/include/clang/Sema/HLSLExternalSemaSource.h
index 3c7495e66055d..9c1b16ba3950c 100644
--- a/clang/include/clang/Sema/HLSLExternalSemaSource.h
+++ b/clang/include/clang/Sema/HLSLExternalSemaSource.h
@@ -21,20 +21,15 @@ class NamespaceDecl;
 class Sema;
 
 class HLSLExternalSemaSource : public ExternalSemaSource {
+private:
   Sema *SemaPtr = nullptr;
   NamespaceDecl *HLSLNamespace = nullptr;
 
   using CompletionFunction = std::function;
   llvm::DenseMap Completions;
 
-  void defineHLSLVectorAlias();
-  void defineTrivialHLSLTypes();
-  void defineHLSLTypesWithForwardDeclarations();
-
-  void onCompletion(CXXRecordDecl *Record, CompletionFunction Fn);
-
 public:
-  ~HLSLExternalSemaSource() override;
+  ~HLSLExternalSemaSource() override {}
 
   /// Initialize the semantic source with the Sema instance
   /// being used to perform semantic analysis on the abstract syntax
@@ -47,6 +42,12 @@ class HLSLExternalSemaSource : public ExternalSemaSource {
   using ExternalASTSource::CompleteType;
   /// Complete an incomplete HLSL builtin type
   void CompleteType(TagDecl *Tag) override;
+
+private:
+  void defineTrivialHLSLTypes();
+  void defineHLSLVectorAlias();
+  void defineHLSLTypesWithForwardDeclarations();
+  void onCompletion(CXXRecordDecl *Record, CompletionFunction Fn);
 };
 
 } // namespace clang
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 1a351684d133e..d3fe80f659f69 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangSema
   DeclSpec.cpp
   DelayedDiagnostic.cpp
   HeuristicResolver.cpp
+  HLSLBuiltinTypeDeclBuilder.cpp
   HLSLExternalSemaSource.cpp
   IdentifierResolver.cpp
   JumpDiagnostics.cpp
diff --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp 
b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
new file mode 100644
index 0..db0ed3434d837
--- /dev/null
+++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
@@ -0,0 +1,782 @@
+//===--- HLSLBuiltinTypeDeclBuilder.cpp - HLSL Builtin Type Decl Builder 
--===//
+//
+// 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 "HLSLBuiltinTypeDeclBuilder.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaHLSL.h"
+#include "llvm/ADT/SmallVector.h"
+
+using namespace llvm::hlsl;
+
+namespace clang {
+
+namespace hlsl {
+
+namespace {
+
+static FunctionDecl *lookupBuiltinFunction(Sema &S, StringRef Name) {
+  IdentifierInfo &II =
+  S.getASTContext().Idents.get(Name, tok::TokenKind::identifier);
+  DeclarationNameInfo NameInfo =
+  DeclarationNameInfo(DeclarationName(&II), SourceLocation());
+  LookupResult R(S, NameInfo, Sema::LookupOrdinaryName);
+  // AllowBuiltinCreation is false but LookupDirect will create
+  // the builtin wh

[clang] [Docs] Document freestanding requirements (PR #132232)

2025-03-26 Thread Aaron Ballman via cfe-commits


@@ -534,11 +534,6 @@ C23 implementation status
   Clang 16
 
 
-
-  String functions for freestanding implementations
-  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2524.htm";>N2524
-  No
-

AaronBallman wrote:

N2359 applies to the compiler because it introduces new potentially reserved 
identifiers we may want to diagnose and it changes behavior of limits.h which 
Clang provides.

N2951 applies to the compiler because it imposes some requirements on 
freestanding regarding `FENV_ACCESS`. It's questionable whether this one 
belongs on the list or not. It's marked as "Unknown" currently because I've not 
spent the time trying to figure out whether we have anything to do here or not.

But yes, cleaning these up in a later PR is a good idea. FWIW, I've been 
removing ones as I realize they don't impact the compiler.

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


[clang] [llvm] [AArch64] Add FEAT_FPAC to Neoverse V2 (PR #133054)

2025-03-26 Thread Sjoerd Meijer via cfe-commits

https://github.com/sjoerdmeijer updated 
https://github.com/llvm/llvm-project/pull/133054

>From b1619f7b2835acafb4d76e6a16e678b17ddbe8b3 Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer 
Date: Wed, 26 Mar 2025 04:38:48 -0700
Subject: [PATCH] [AArch64] Add FEAT_FPAC to Neoverse V2

This feature is supported in Grace, but wasn't specified in the CPU
definition.
---
 clang/test/Driver/aarch64-mcpu-native.c| 1 +
 clang/test/Driver/print-enabled-extensions/aarch64-grace.c | 3 ++-
 .../test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c | 1 +
 llvm/lib/Target/AArch64/AArch64Processors.td   | 2 +-
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/aarch64-mcpu-native.c 
b/clang/test/Driver/aarch64-mcpu-native.c
index 2e7fc2c5adc45..a349a8e9827b8 100644
--- a/clang/test/Driver/aarch64-mcpu-native.c
+++ b/clang/test/Driver/aarch64-mcpu-native.c
@@ -22,6 +22,7 @@
 // CHECK-FEAT-NV2:FEAT_FHM   
Enable FP16 FML instructions
 // CHECK-FEAT-NV2:FEAT_FP
Enable Armv8.0-A Floating Point Extensions
 // CHECK-FEAT-NV2:FEAT_FP16  
Enable half-precision floating-point data processing
+// CHECK-FEAT-NV2:FEAT_FPAC  
Enable Armv8.3-A Pointer Authentication Faulting enhancement
 // CHECK-FEAT-NV2:FEAT_FRINTTS   
Enable FRInt[32|64][Z|X] instructions that round a floating-point number to an 
integer (in FP format) forcing it to fit into a 32- or 64-bit int
 // CHECK-FEAT-NV2:FEAT_FlagM 
Enable Armv8.4-A Flag Manipulation instructions
 // CHECK-FEAT-NV2:FEAT_FlagM2
Enable alternative NZCV format for floating point comparisons
diff --git a/clang/test/Driver/print-enabled-extensions/aarch64-grace.c 
b/clang/test/Driver/print-enabled-extensions/aarch64-grace.c
index fde6aee468cdc..739d86f1fae0f 100644
--- a/clang/test/Driver/print-enabled-extensions/aarch64-grace.c
+++ b/clang/test/Driver/print-enabled-extensions/aarch64-grace.c
@@ -21,6 +21,7 @@
 // CHECK-NEXT: FEAT_FHM   
Enable FP16 FML instructions
 // CHECK-NEXT: FEAT_FP
Enable Armv8.0-A Floating Point Extensions
 // CHECK-NEXT: FEAT_FP16  
Enable half-precision floating-point data processing
+// CHECK-NEXT: FEAT_FPAC  
Enable Armv8.3-A Pointer Authentication Faulting enhancement
 // CHECK-NEXT: FEAT_FRINTTS   
Enable FRInt[32|64][Z|X] instructions that round a floating-point number to an 
integer (in FP format) forcing it to fit into a 32- or 64-bit int
 // CHECK-NEXT: FEAT_FlagM 
Enable Armv8.4-A Flag Manipulation instructions
 // CHECK-NEXT: FEAT_FlagM2
Enable alternative NZCV format for floating point comparisons
@@ -59,4 +60,4 @@
 // CHECK-NEXT: FEAT_TRBE  
Enable Trace Buffer Extension
 // CHECK-NEXT: FEAT_TRF   
Enable Armv8.4-A Trace extension
 // CHECK-NEXT: FEAT_UAO   
Enable Armv8.2-A UAO PState
-// CHECK-NEXT: FEAT_VHE   
Enable Armv8.1-A Virtual Host extension
\ No newline at end of file
+// CHECK-NEXT: FEAT_VHE   
Enable Armv8.1-A Virtual Host extension
diff --git a/clang/test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c 
b/clang/test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c
index b11acdd34ee6d..6c2c2e3b0feb6 100644
--- a/clang/test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c
+++ b/clang/test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c
@@ -20,6 +20,7 @@
 // CHECK-NEXT: FEAT_FHM   
Enable FP16 FML instructions
 // CHECK-NEXT: FEAT_FP
Enable Armv8.0-A Floating Point Extensions
 // CHECK-NEXT: FEAT_FP16  
Enable half-precision floating-point data processing
+// CHECK-NEXT: FEAT_FPAC  
Enable Armv8.3-A Pointer Authentication Faulting enhancement
 // CHECK-NEXT: FEAT_FRINTTS   
Enable FRInt[32|64][Z|X] instructions that round a floating-point number to an 
integer (in FP format) forcing it to fit into a 32- or 64-bit int
 // CHECK-NEXT: FEAT_FlagM 
Enable Armv8.4-A Flag Manip

[clang-tools-extra] [clang-tidy] support query based custom check (PR #131804)

2025-03-26 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

> It would feel safer if the custom check was passed via command-line instead, 
> similar to --config

good point. should we only support command line for this feature? for me it is 
enough.

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


[clang] [llvm] cuda clang: Fix argument order for __reduce_max_sync (PR #132881)

2025-03-26 Thread Austin Schuh via cfe-commits

AustinSchuh wrote:

> @AustinSchuh would you like me to merge the change for you, once the checks 
> are done?

That would be wonderful.  I don't know how to merge it (happy to learn, but I 
suspect I won't do it more than a couple of times)

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


[clang] [C2y] Implement WG14 N3369 and N3469 (_Countof) (PR #133125)

2025-03-26 Thread James Y Knight via cfe-commits


@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c2y -pedantic -Wall -Wno-comment -verify 
%s
+
+/* WG14 N3369: Clang 21
+ * _Lengthof operator
+ *
+ * Adds an operator to get the length of an array. Note that WG14 N3469 renamed
+ * this operator to _Countof.
+ */
+
+int global_array[12];
+
+void test_parsing_failures() {
+  (void)_Countof; // expected-error {{expected expression}}
+  (void)_Countof(;// expected-error {{expected expression}}
+  (void)_Countof();   // expected-error {{expected expression}}
+  (void)_Countof int; // expected-error {{expected expression}}
+}
+
+void test_semantic_failures() {
+  (void)_Countof(1); // expected-error {{'_Countof' requires an 
argument of array type; 'int' invalid}}
+  int non_array;
+  (void)_Countof non_array;  // expected-error {{'_Countof' requires an 
argument of array type; 'int' invalid}}  
+  (void)_Countof(int);   // expected-error {{'_Countof' requires an 
argument of array type; 'int' invalid}}  
+}
+
+void test_constant_expression_behavior(int n) {
+  static_assert(_Countof(global_array) == 12);
+  static_assert(_Countof global_array == 12);  
+  static_assert(_Countof(int[12]) == 12);
+
+  // Use of a VLA makes it not a constant expression, same as with sizeof.
+  int array[n];
+  static_assert(_Countof(array)); // expected-error {{static assertion 
expression is not an integral constant expression}}
+  static_assert(sizeof(array));   // expected-error {{static assertion 
expression is not an integral constant expression}}
+  static_assert(_Countof(int[n]));// expected-error {{static assertion 
expression is not an integral constant expression}}
+  static_assert(sizeof(int[n]));  // expected-error {{static assertion 
expression is not an integral constant expression}}
+  
+  // Constant folding works the same way as sizeof, too.
+  const int m = 12;
+  int other_array[m];
+  static_assert(sizeof(other_array));   // expected-error {{static assertion 
expression is not an integral constant expression}}
+  static_assert(_Countof(other_array)); // expected-error {{static assertion 
expression is not an integral constant expression}}
+  static_assert(sizeof(int[m]));// expected-error {{static assertion 
expression is not an integral constant expression}}
+  static_assert(_Countof(int[m]));  // expected-error {{static assertion 
expression is not an integral constant expression}}
+  
+  // Note that this applies to each array dimension.
+  int another_array[n][7];
+  static_assert(_Countof(another_array)); // expected-error {{static assertion 
expression is not an integral constant expression}}
+  static_assert(_Countof(*another_array) == 7);
+}
+
+void test_with_function_param(int array[12], int (*array_ptr)[12]) {

jyknight wrote:

I presume `void fn(int array[static 12])` also doesn't work, as it also doesn't 
get an array type then (which always seemed really odd to me but _shrug_.)

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


[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

2025-03-26 Thread Morris Hafner via cfe-commits


@@ -170,7 +170,7 @@ mlir::Value CIRGenFunction::evaluateExprAsBool(const Expr 
*e) {
   SourceLocation loc = e->getExprLoc();
 
   assert(!cir::MissingFeatures::pgoUse());
-  if (const MemberPointerType *MPT = e->getType()->getAs()) 
{
+  if (e->getType()->getAs()) {

mmha wrote:

I wonder why `getAs` is not `[[nodiscard]]` but hey it's not so no new warning 
here.

(Maybe `isa` is still better?)

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


[clang-tools-extra] [NFC][clang-tidy] Add type annotations to check_clang_tidy (PR #133140)

2025-03-26 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank created 
https://github.com/llvm/llvm-project/pull/133140


I'm looking to make some changes in this file, start by typing it.

```
> python3 -m mypy --strict clang-tools-extra/test/clang-tidy/check_clang_tidy.py
Success: no issues found in 1 source file
```


>From ba588182eef99ec987f8fb65ffcc749ebfd51024 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Wed, 26 Mar 2025 14:28:31 -0400
Subject: [PATCH] [NFC][clang-tidy] Add type annotations to check_clang_tidy

I'm looking to make some changes in this file, start by typing it.

```
> python3 -m mypy --strict clang-tools-extra/test/clang-tidy/check_clang_tidy.py
Success: no issues found in 1 source file
```
---
 .../test/clang-tidy/check_clang_tidy.py   | 39 ++-
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 5e39c05f76d86..e148b67dd15b7 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -48,15 +48,16 @@
 import re
 import subprocess
 import sys
+from typing import List, Tuple
 
 
-def write_file(file_name, text):
+def write_file(file_name: str, text: str) -> None:
 with open(file_name, "w", encoding="utf-8") as f:
 f.write(text)
 f.truncate()
 
 
-def try_run(args, raise_error=True):
+def try_run(args: List[str], raise_error: bool = True) -> str:
 try:
 process_output = subprocess.check_output(args, 
stderr=subprocess.STDOUT).decode(
 errors="ignore"
@@ -71,12 +72,12 @@ def try_run(args, raise_error=True):
 
 # This class represents the appearance of a message prefix in a file.
 class MessagePrefix:
-def __init__(self, label):
+def __init__(self, label: str):
 self.has_message = False
-self.prefixes = []
+self.prefixes: List[str] = []
 self.label = label
 
-def check(self, file_check_suffix, input_text):
+def check(self, file_check_suffix: str, input_text: str) -> bool:
 self.prefix = self.label + file_check_suffix
 self.has_message = self.prefix in input_text
 if self.has_message:
@@ -85,7 +86,7 @@ def check(self, file_check_suffix, input_text):
 
 
 class CheckRunner:
-def __init__(self, args, extra_args):
+def __init__(self, args: argparse.Namespace, extra_args: List[str]):
 self.resource_dir = args.resource_dir
 self.assume_file_name = args.assume_filename
 self.input_file_name = args.input_file_name
@@ -143,11 +144,11 @@ def __init__(self, args, extra_args):
 if self.resource_dir is not None:
 self.clang_extra_args.append("-resource-dir=%s" % 
self.resource_dir)
 
-def read_input(self):
+def read_input(self) -> None:
 with open(self.input_file_name, "r", encoding="utf-8") as input_file:
 self.input_text = input_file.read()
 
-def get_prefixes(self):
+def get_prefixes(self) -> None:
 for suffix in self.check_suffix:
 if suffix and not re.match("^[A-Z0-9\\-]+$", suffix):
 sys.exit(
@@ -189,7 +190,7 @@ def get_prefixes(self):
 )
 assert expect_diagnosis or self.expect_no_diagnosis
 
-def prepare_test_inputs(self):
+def prepare_test_inputs(self) -> None:
 # Remove the contents of the CHECK lines to avoid CHECKs matching on
 # themselves.  We need to keep the comments to preserve line numbers 
while
 # avoiding empty lines which could potentially trigger 
formatting-related
@@ -198,7 +199,7 @@ def prepare_test_inputs(self):
 write_file(self.temp_file_name, cleaned_test)
 write_file(self.original_file_name, cleaned_test)
 
-def run_clang_tidy(self):
+def run_clang_tidy(self) -> str:
 args = (
 [
 "clang-tidy",
@@ -238,11 +239,11 @@ def run_clang_tidy(self):
 
print("--")
 return clang_tidy_output
 
-def check_no_diagnosis(self, clang_tidy_output):
+def check_no_diagnosis(self, clang_tidy_output: str) -> None:
 if clang_tidy_output != "":
 sys.exit("No diagnostics were expected, but found the ones above")
 
-def check_fixes(self):
+def check_fixes(self) -> None:
 if self.has_check_fixes:
 try_run(
 [
@@ -254,7 +255,7 @@ def check_fixes(self):
 ]
 )
 
-def check_messages(self, clang_tidy_output):
+def check_messages(self, clang_tidy_output: str) -> None:
 if self.has_check_messages:
 messages_file = self.temp_file_name + ".msg"
 write_file(messages_file, clang_tidy_output)
@@ -268,7 +269,7 @@ def check_messages(self, clang_tidy_output):
 ]
 )
 
-def check_notes(self, clang_tidy_output):
+def check_

[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

2025-03-26 Thread Morris Hafner via cfe-commits

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

LGTM, just a few nits.

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


[clang-tools-extra] [NFC][clang-tidy] Add type annotations to check_clang_tidy (PR #133140)

2025-03-26 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tidy

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

Author: Nicolas van Kempen (nicovank)


Changes


I'm looking to make some changes in this file, start by typing it.

```
> python3 -m mypy --strict 
clang-tools-extra/test/clang-tidy/check_clang_tidy.py
Success: no issues found in 1 source file
```


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


1 Files Affected:

- (modified) clang-tools-extra/test/clang-tidy/check_clang_tidy.py (+20-19) 


``diff
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py 
b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index 5e39c05f76d86..e148b67dd15b7 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -48,15 +48,16 @@
 import re
 import subprocess
 import sys
+from typing import List, Tuple
 
 
-def write_file(file_name, text):
+def write_file(file_name: str, text: str) -> None:
 with open(file_name, "w", encoding="utf-8") as f:
 f.write(text)
 f.truncate()
 
 
-def try_run(args, raise_error=True):
+def try_run(args: List[str], raise_error: bool = True) -> str:
 try:
 process_output = subprocess.check_output(args, 
stderr=subprocess.STDOUT).decode(
 errors="ignore"
@@ -71,12 +72,12 @@ def try_run(args, raise_error=True):
 
 # This class represents the appearance of a message prefix in a file.
 class MessagePrefix:
-def __init__(self, label):
+def __init__(self, label: str):
 self.has_message = False
-self.prefixes = []
+self.prefixes: List[str] = []
 self.label = label
 
-def check(self, file_check_suffix, input_text):
+def check(self, file_check_suffix: str, input_text: str) -> bool:
 self.prefix = self.label + file_check_suffix
 self.has_message = self.prefix in input_text
 if self.has_message:
@@ -85,7 +86,7 @@ def check(self, file_check_suffix, input_text):
 
 
 class CheckRunner:
-def __init__(self, args, extra_args):
+def __init__(self, args: argparse.Namespace, extra_args: List[str]):
 self.resource_dir = args.resource_dir
 self.assume_file_name = args.assume_filename
 self.input_file_name = args.input_file_name
@@ -143,11 +144,11 @@ def __init__(self, args, extra_args):
 if self.resource_dir is not None:
 self.clang_extra_args.append("-resource-dir=%s" % 
self.resource_dir)
 
-def read_input(self):
+def read_input(self) -> None:
 with open(self.input_file_name, "r", encoding="utf-8") as input_file:
 self.input_text = input_file.read()
 
-def get_prefixes(self):
+def get_prefixes(self) -> None:
 for suffix in self.check_suffix:
 if suffix and not re.match("^[A-Z0-9\\-]+$", suffix):
 sys.exit(
@@ -189,7 +190,7 @@ def get_prefixes(self):
 )
 assert expect_diagnosis or self.expect_no_diagnosis
 
-def prepare_test_inputs(self):
+def prepare_test_inputs(self) -> None:
 # Remove the contents of the CHECK lines to avoid CHECKs matching on
 # themselves.  We need to keep the comments to preserve line numbers 
while
 # avoiding empty lines which could potentially trigger 
formatting-related
@@ -198,7 +199,7 @@ def prepare_test_inputs(self):
 write_file(self.temp_file_name, cleaned_test)
 write_file(self.original_file_name, cleaned_test)
 
-def run_clang_tidy(self):
+def run_clang_tidy(self) -> str:
 args = (
 [
 "clang-tidy",
@@ -238,11 +239,11 @@ def run_clang_tidy(self):
 
print("--")
 return clang_tidy_output
 
-def check_no_diagnosis(self, clang_tidy_output):
+def check_no_diagnosis(self, clang_tidy_output: str) -> None:
 if clang_tidy_output != "":
 sys.exit("No diagnostics were expected, but found the ones above")
 
-def check_fixes(self):
+def check_fixes(self) -> None:
 if self.has_check_fixes:
 try_run(
 [
@@ -254,7 +255,7 @@ def check_fixes(self):
 ]
 )
 
-def check_messages(self, clang_tidy_output):
+def check_messages(self, clang_tidy_output: str) -> None:
 if self.has_check_messages:
 messages_file = self.temp_file_name + ".msg"
 write_file(messages_file, clang_tidy_output)
@@ -268,7 +269,7 @@ def check_messages(self, clang_tidy_output):
 ]
 )
 
-def check_notes(self, clang_tidy_output):
+def check_notes(self, clang_tidy_output: str) -> None:
 if self.has_check_notes:
 notes_file = self.temp_file_name + ".notes"
 filtered_output = [
@@ -287,7 +288,7 @@ def check_notes(self, clang_tidy_output):
 ]
 )
 
-def run(self):
+def run(se

[clang] [libclang/python] Add equality comparison operators for File (PR #130383)

2025-03-26 Thread Aaron Ballman via cfe-commits


@@ -16,3 +17,76 @@ def test_file(self):
 self.assertEqual(str(file), "t.c")
 self.assertEqual(file.name, "t.c")
 self.assertEqual(repr(file), "")
+
+def test_file_eq(self):
+path = os.path.join(inputs_dir, "hello.cpp")
+header_path = os.path.join(inputs_dir, "header3.h")
+tu = TranslationUnit.from_source(path)
+file1 = File.from_name(tu, path)
+file2 = File.from_name(tu, header_path)
+file2_2 = File.from_name(tu, header_path)
+
+self.assertEqual(file1, file1)
+self.assertEqual(file2, file2_2)
+self.assertNotEqual(file1, file2)
+self.assertNotEqual(file1, "t.c")
+
+def test_file_eq_failing(self):
+index = Index.create()
+tu = index.parse(
+"t.c",
+unsaved_files=[
+("t.c", "int a = 729;"),
+("s.c", "int a = 729;"),
+],
+)
+file1 = File.from_name(tu, "t.c")
+file2 = File.from_name(tu, "s.c")
+# FIXME: These files are not supposed to be equal
+self.assertEqual(file1, file2)
+
+def test_file_eq_failing_2(self):
+index = Index.create()
+tu = index.parse(
+"t.c",
+unsaved_files=[
+("t.c", "int a = 729;"),
+("s.c", "int a = 728;"),
+],
+)
+file1 = File.from_name(tu, "t.c")
+file2 = File.from_name(tu, "s.c")
+# FIXME: These files are not supposed to be equal
+self.assertEqual(file1, file2)
+
+def test_file_eq_failing_3(self):
+index = Index.create()
+tu = index.parse(
+"t.c",
+unsaved_files=[
+("t.c", '#include "a.c"\n#include "b.c";'),
+("a.c", "int a = 729;"),
+("b.c", "int b = 729;"),
+],
+)
+file1 = File.from_name(tu, "t.c")
+file2 = File.from_name(tu, "a.c")
+file3 = File.from_name(tu, "b.c")
+# FIXME: These files are not supposed to be equal
+self.assertEqual(file2, file3)
+self.assertEqual(file1, file2)
+self.assertEqual(file1, file3)
+
+def test_file_eq_failing_4(self):
+path = os.path.join(inputs_dir, "testfile.c")
+path_a = os.path.join(inputs_dir, "a.inc")
+path_b = os.path.join(inputs_dir, "b.inc")
+tu = TranslationUnit.from_source(path)
+print(tu.spelling, tu.cursor.spelling)
+file1 = File.from_name(tu, path)
+file2 = File.from_name(tu, path_a)
+file3 = File.from_name(tu, path_b)
+# FIXME: These files are not supposed to be equal
+self.assertEqual(file2, file3)
+self.assertEqual(file1, file2)
+self.assertEqual(file1, file3)

AaronBallman wrote:

I think this might be a bug here: 
https://github.com/llvm/llvm-project/blob/1b07e865a1f9da64c75cc409a969b108b201fe80/clang/tools/libclang/CIndex.cpp#L5173

For starters, `FileEntryRef` has an equality operator: 
https://github.com/llvm/llvm-project/blob/1b07e865a1f9da64c75cc409a969b108b201fe80/clang/include/clang/Basic/FileEntry.h#L89
 so it's worth seeing if using that gives the correct behavior.

But also, you can use `FileManager::getNoncachedStatValue` to get a 
`vfs::Status` object on which you can call `equivalent()` to test for 
equivalency, so it's worth seeing if that gives the correct behavior.

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


[clang] [CIR] Upstream zero init for global variables (PR #133100)

2025-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds zero initialization for global variables

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


7 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h (+34) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+5-2) 
- (modified) clang/test/CIR/CodeGen/array.cpp (+4-4) 
- (modified) clang/test/CIR/Lowering/array.cpp (+4-4) 
- (modified) clang/test/CIR/Lowering/global-var-simple.cpp (+28-30) 
- (modified) clang/test/CIR/Lowering/hello.c (+1-1) 
- (modified) clang/test/CIR/global-var-simple.cpp (+26-26) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h 
b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
index ac7658276ec37..eb07acb16ed50 100644
--- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
+++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
@@ -67,6 +67,40 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
 return create(loc, attr.getType(), attr);
   }
 
+  mlir::TypedAttr getConstNullPtrAttr(mlir::Type t) {
+assert(mlir::isa(t) && "expected cir.ptr");
+return getConstPtrAttr(t, 0);
+  }
+
+  mlir::TypedAttr getZeroAttr(mlir::Type t) {
+return cir::ZeroAttr::get(getContext(), t);
+  }
+
+  mlir::TypedAttr getZeroInitAttr(mlir::Type ty) {
+if (mlir::isa(ty))
+  return cir::IntAttr::get(ty, 0);
+if (auto fltType = mlir::dyn_cast(ty))
+  return cir::FPAttr::getZero(fltType);
+if (auto fltType = mlir::dyn_cast(ty))
+  return cir::FPAttr::getZero(fltType);
+if (auto fltType = mlir::dyn_cast(ty))
+  return cir::FPAttr::getZero(fltType);
+if (auto fltType = mlir::dyn_cast(ty))
+  return cir::FPAttr::getZero(fltType);
+if (auto fltType = mlir::dyn_cast(ty))
+  return cir::FPAttr::getZero(fltType);
+if (auto fltType = mlir::dyn_cast(ty))
+  return cir::FPAttr::getZero(fltType);
+if (auto arrTy = mlir::dyn_cast(ty))
+  return getZeroAttr(arrTy);
+if (auto ptrTy = mlir::dyn_cast(ty))
+  return getConstNullPtrAttr(ptrTy);
+if (mlir::isa(ty)) {
+  return getCIRBoolAttr(false);
+}
+llvm_unreachable("Zero initializer for given type is NYI");
+  }
+
   cir::ConstantOp getBool(bool state, mlir::Location loc) {
 return create(loc, getBoolTy(), getCIRBoolAttr(state));
   }
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp 
b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 9776a4e09f9e0..2a37d6c7d1888 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -140,17 +140,20 @@ void CIRGenModule::emitGlobalVarDefinition(const 
clang::VarDecl *vd,
 // certain constant expressions is implemented for now.
 const VarDecl *initDecl;
 const Expr *initExpr = vd->getAnyInitializer(initDecl);
+mlir::Attribute initializer;
 if (initExpr) {
-  mlir::Attribute initializer;
   if (APValue *value = initDecl->evaluateValue()) {
 ConstantEmitter emitter(*this);
 initializer = emitter.tryEmitPrivateForMemory(*value, astTy);
   } else {
 errorNYI(initExpr->getSourceRange(), "non-constant initializer");
   }
-  varOp.setInitialValueAttr(initializer);
+} else {
+  initializer = builder.getZeroInitAttr(convertType(astTy));
 }
 
+varOp.setInitialValueAttr(initializer);
+
 // Set CIR's linkage type as appropriate.
 cir::GlobalLinkageKind linkage =
 getCIRLinkageVarDefinition(vd, /*IsConstant=*/false);
diff --git a/clang/test/CIR/CodeGen/array.cpp b/clang/test/CIR/CodeGen/array.cpp
index a59880352e050..1e74275eab058 100644
--- a/clang/test/CIR/CodeGen/array.cpp
+++ b/clang/test/CIR/CodeGen/array.cpp
@@ -1,16 +1,16 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir 
-emit-cir %s -o - 2>&1 | FileCheck %s
 
 int a[10];
-// CHECK: cir.global external @a : !cir.array
+// CHECK: cir.global external @a = #cir.zero : !cir.array
 
 int aa[10][5];
-// CHECK: cir.global external @aa : !cir.array x 10>
+// CHECK: cir.global external @aa = #cir.zero : !cir.array x 10>
 
 extern int b[10];
-// CHECK: cir.global external @b : !cir.array
+// CHECK: cir.global external @b = #cir.zero : !cir.array
 
 extern int bb[10][5];
-// CHECK: cir.global external @bb : !cir.array x 10>
+// CHECK: cir.global external @bb = #cir.zero : !cir.array x 10>
 
 int c[10] = {};
 // CHECK: cir.global external @c = #cir.zero : !cir.array
diff --git a/clang/test/CIR/Lowering/array.cpp 
b/clang/test/CIR/Lowering/array.cpp
index 763980b9124a3..4fb996aefe79e 100644
--- a/clang/test/CIR/Lowering/array.cpp
+++ b/clang/test/CIR/Lowering/array.cpp
@@ -1,16 +1,16 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir 
-emit-llvm %s -o - 2>&1 | FileCheck %s
 
 int a[10];
-// CHECK: @a = external dso_local global [10 x i32]
+// CHECK: @a = dso_local global [10 x i32] zeroinitial

[clang] [clang][DependencyScanning] Track dependencies from prebuilt modules to determine IsInStableDir (PR #132237)

2025-03-26 Thread Cyndy Ishida via cfe-commits


@@ -5834,9 +5834,13 @@ bool ASTReader::readASTFileControlBlock(
   break;
 case INPUT_FILE:
   bool Overridden = static_cast(Record[3]);
+  size_t FilenameLen = ModuleDir.size() + Record[7] + 1;
   auto Filename = ResolveImportedPath(PathBuf, Blob, ModuleDir);
+  StringRef FilenameAsRequested = Filename->substr(0, FilenameLen);
+  StringRef ExternalFilename = Filename->substr(FilenameLen);

cyndyishida wrote:

Applied your suggestion except for calling `ResolveImportedPath` on both parts 
of the substring. Let me know if I am missing something, but the external path 
should always be absolute, so I think it would be unnecessary. It also reduces 
some logic of needing to copy strings since  

> The return value must go out of scope before the next call to \c 
> ResolveImportedPath.

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


[clang] [Serialization] Fix lazy template loading (PR #133057)

2025-03-26 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

> @ilya-biryukov, would you mind giving this PR a test on your infrastructure 
> and if it works maybe share some performance results?

Sure, let me try kicking it off. Note that our infrastructure is much better at 
detecting the compilations timing out than providing proper benchmarking at 
scale (there are a few targeted benchmarks too, though).
That means we're good and detecting big regressions, but won't be able to 
provide very reliable performance measurements.

I'll try to give you what we have, though.

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


[clang] [CIR] Add BinOpOverflowOp and basic pointer arithmetic support (PR #133118)

2025-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Morris Hafner (mmha)


Changes

This was part of #132420 originally but split off to reduce the diff 
size.

This patch adds support for overflowing binary operators and all the plumbing 
required for pointer arithmetic except for the actual Ops (`PtrDiffOp` and 
`PtrStrideOp` - we emit dummy values instead).

---

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


8 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+59) 
- (modified) clang/include/clang/CIR/MissingFeatures.h (+1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+122-3) 
- (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (+10) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+118) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h (+22) 
- (modified) clang/test/CIR/CodeGen/binop.cpp (+10) 
- (added) clang/test/CIR/Lowering/binop-overflow.cir (+63) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 455cc2b8b0277..3d49f88b032cb 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -889,6 +889,65 @@ def BinOp : CIR_Op<"binop", [Pure,
   let hasVerifier = 1;
 }
 
+
+//===--===//
+// BinOpOverflowOp
+//===--===//
+
+def BinOpOverflowKind : I32EnumAttr<
+"BinOpOverflowKind",
+"checked binary arithmetic operation kind",
+[BinOpKind_Add, BinOpKind_Sub, BinOpKind_Mul]> {
+  let cppNamespace = "::cir";
+}
+
+def BinOpOverflowOp : CIR_Op<"binop.overflow", [Pure, SameTypeOperands]> {
+  let summary = "Perform binary integral arithmetic with overflow checking";
+  let description = [{
+`cir.binop.overflow` performs binary arithmetic operations with overflow
+checking on integral operands.
+
+The `kind` argument specifies the kind of arithmetic operation to perform.
+It can be either `add`, `sub`, or `mul`. The `lhs` and `rhs` arguments
+specify the input operands of the arithmetic operation. The types of `lhs`
+and `rhs` must be the same.
+
+`cir.binop.overflow` produces two SSA values. `result` is the result of the
+arithmetic operation truncated to its specified type. `overflow` is a
+boolean value indicating whether overflow happens during the operation.
+
+The exact semantic of this operation is as follows:
+
+  - `lhs` and `rhs` are promoted to an imaginary integral type that has
+infinite precision.
+  - The arithmetic operation is performed on the promoted operands.
+  - The infinite-precision result is truncated to the type of `result`. The
+truncated result is assigned to `result`.
+  - If the truncated result is equal to the un-truncated result, `overflow`
+is assigned to false. Otherwise, `overflow` is assigned to true.
+  }];
+
+  let arguments = (ins Arg:$kind,
+   CIR_IntType:$lhs, CIR_IntType:$rhs);
+  let results = (outs CIR_IntType:$result, CIR_BoolType:$overflow);
+
+  let assemblyFormat = [{
+`(` $kind `,` $lhs `,` $rhs `)` `:` type($lhs) `,`
+`(` type($result) `,` type($overflow) `)`
+attr-dict
+  }];
+
+  let builders = [
+OpBuilder<(ins "cir::IntType":$resultTy,
+   "cir::BinOpOverflowKind":$kind,
+   "mlir::Value":$lhs,
+   "mlir::Value":$rhs), [{
+  auto overflowTy = cir::BoolType::get($_builder.getContext());
+  build($_builder, $_state, resultTy, overflowTy, kind, lhs, rhs);
+}]>
+  ];
+}
+
 
//===--===//
 // GlobalOp
 
//===--===//
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 3a102d90aba8f..338006b351da0 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -109,6 +109,7 @@ struct MissingFeatures {
   static bool cgFPOptionsRAII() { return false; }
   static bool metaDataNode() { return false; }
   static bool fastMathFlags() { return false; }
+  static bool vlas() { return false; }
 
   // Missing types
   static bool dataMemberType() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 52bd3b2933744..6e1f5aa0dc600 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -936,8 +936,107 @@ getUnwidenedIntegerType(const ASTContext &astContext, 
const Expr *e) {
 static mlir::Value emitPointerArithmetic(CIRGenFunction &cgf,
  const BinOpInfo &op,

[clang] [CIR] Add BinOpOverflowOp and basic pointer arithmetic support (PR #133118)

2025-03-26 Thread Morris Hafner via cfe-commits


@@ -1117,6 +1118,122 @@ mlir::LogicalResult 
CIRToLLVMBinOpLowering::matchAndRewrite(
   return mlir::LogicalResult::success();
 }
 
+mlir::LogicalResult CIRToLLVMBinOpOverflowOpLowering::matchAndRewrite(
+cir::BinOpOverflowOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+  mlir::Location loc = op.getLoc();
+  BinOpOverflowKind arithKind = op.getKind();
+  IntType operandTy = op.getLhs().getType();
+  IntType resultTy = op.getResult().getType();
+
+  EncompassedTypeInfo encompassedTyInfo =
+  computeEncompassedTypeWidth(operandTy, resultTy);
+  mlir::IntegerType encompassedLLVMTy =
+  rewriter.getIntegerType(encompassedTyInfo.width);
+
+  mlir::Value lhs = adaptor.getLhs();
+  mlir::Value rhs = adaptor.getRhs();
+  if (operandTy.getWidth() < encompassedTyInfo.width) {
+if (operandTy.isSigned()) {
+  lhs = rewriter.create(loc, encompassedLLVMTy, lhs);
+  rhs = rewriter.create(loc, encompassedLLVMTy, rhs);
+} else {
+  lhs = rewriter.create(loc, encompassedLLVMTy, lhs);
+  rhs = rewriter.create(loc, encompassedLLVMTy, rhs);
+}
+  }
+
+  std::string intrinName = getLLVMIntrinName(arithKind, encompassedTyInfo.sign,
+ encompassedTyInfo.width);
+  auto intrinNameAttr = mlir::StringAttr::get(op.getContext(), intrinName);
+
+  mlir::IntegerType overflowLLVMTy = rewriter.getI1Type();
+  auto intrinRetTy = mlir::LLVM::LLVMStructType::getLiteral(
+  rewriter.getContext(), {encompassedLLVMTy, overflowLLVMTy});
+
+  auto callLLVMIntrinOp = rewriter.create(
+  loc, intrinRetTy, intrinNameAttr, mlir::ValueRange{lhs, rhs});
+  mlir::Value intrinRet = callLLVMIntrinOp.getResult(0);
+
+  mlir::Value result = rewriter
+   .create(
+   loc, intrinRet, ArrayRef{0})
+   .getResult();
+  mlir::Value overflow = rewriter
+ .create(
+ loc, intrinRet, ArrayRef{1})
+ .getResult();
+
+  if (resultTy.getWidth() < encompassedTyInfo.width) {
+mlir::Type resultLLVMTy = getTypeConverter()->convertType(resultTy);
+auto truncResult =
+rewriter.create(loc, resultLLVMTy, result);
+
+// Extend the truncated result back to the encompassing type to check for
+// any overflows during the truncation.
+mlir::Value truncResultExt;
+if (resultTy.isSigned())
+  truncResultExt = rewriter.create(
+  loc, encompassedLLVMTy, truncResult);
+else
+  truncResultExt = rewriter.create(
+  loc, encompassedLLVMTy, truncResult);
+auto truncOverflow = rewriter.create(
+loc, mlir::LLVM::ICmpPredicate::ne, truncResultExt, result);
+
+result = truncResult;
+overflow = rewriter.create(loc, overflow, truncOverflow);
+  }
+
+  mlir::Type boolLLVMTy =
+  getTypeConverter()->convertType(op.getOverflow().getType());
+  if (boolLLVMTy != rewriter.getI1Type())
+overflow = rewriter.create(loc, boolLLVMTy, overflow);
+
+  rewriter.replaceOp(op, mlir::ValueRange{result, overflow});
+
+  return mlir::success();
+}
+
+std::string CIRToLLVMBinOpOverflowOpLowering::getLLVMIntrinName(
+cir::BinOpOverflowKind opKind, bool isSigned, unsigned width) {
+  // The intrinsic name is `@llvm.{s|u}{opKind}.with.overflow.i{width}`
+
+  std::string name = "llvm.";

mmha wrote:

I wonder if this should use `llvm::raw_string_ostream` or `Twine`.

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


[clang] [CIR] Add BinOpOverflowOp and basic pointer arithmetic support (PR #133118)

2025-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Morris Hafner (mmha)


Changes

This was part of #132420 originally but split off to reduce the diff 
size.

This patch adds support for overflowing binary operators and all the plumbing 
required for pointer arithmetic except for the actual Ops (`PtrDiffOp` and 
`PtrStrideOp` - we emit dummy values instead).

---

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


8 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+59) 
- (modified) clang/include/clang/CIR/MissingFeatures.h (+1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+122-3) 
- (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (+10) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+118) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h (+22) 
- (modified) clang/test/CIR/CodeGen/binop.cpp (+10) 
- (added) clang/test/CIR/Lowering/binop-overflow.cir (+63) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 455cc2b8b0277..3d49f88b032cb 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -889,6 +889,65 @@ def BinOp : CIR_Op<"binop", [Pure,
   let hasVerifier = 1;
 }
 
+
+//===--===//
+// BinOpOverflowOp
+//===--===//
+
+def BinOpOverflowKind : I32EnumAttr<
+"BinOpOverflowKind",
+"checked binary arithmetic operation kind",
+[BinOpKind_Add, BinOpKind_Sub, BinOpKind_Mul]> {
+  let cppNamespace = "::cir";
+}
+
+def BinOpOverflowOp : CIR_Op<"binop.overflow", [Pure, SameTypeOperands]> {
+  let summary = "Perform binary integral arithmetic with overflow checking";
+  let description = [{
+`cir.binop.overflow` performs binary arithmetic operations with overflow
+checking on integral operands.
+
+The `kind` argument specifies the kind of arithmetic operation to perform.
+It can be either `add`, `sub`, or `mul`. The `lhs` and `rhs` arguments
+specify the input operands of the arithmetic operation. The types of `lhs`
+and `rhs` must be the same.
+
+`cir.binop.overflow` produces two SSA values. `result` is the result of the
+arithmetic operation truncated to its specified type. `overflow` is a
+boolean value indicating whether overflow happens during the operation.
+
+The exact semantic of this operation is as follows:
+
+  - `lhs` and `rhs` are promoted to an imaginary integral type that has
+infinite precision.
+  - The arithmetic operation is performed on the promoted operands.
+  - The infinite-precision result is truncated to the type of `result`. The
+truncated result is assigned to `result`.
+  - If the truncated result is equal to the un-truncated result, `overflow`
+is assigned to false. Otherwise, `overflow` is assigned to true.
+  }];
+
+  let arguments = (ins Arg:$kind,
+   CIR_IntType:$lhs, CIR_IntType:$rhs);
+  let results = (outs CIR_IntType:$result, CIR_BoolType:$overflow);
+
+  let assemblyFormat = [{
+`(` $kind `,` $lhs `,` $rhs `)` `:` type($lhs) `,`
+`(` type($result) `,` type($overflow) `)`
+attr-dict
+  }];
+
+  let builders = [
+OpBuilder<(ins "cir::IntType":$resultTy,
+   "cir::BinOpOverflowKind":$kind,
+   "mlir::Value":$lhs,
+   "mlir::Value":$rhs), [{
+  auto overflowTy = cir::BoolType::get($_builder.getContext());
+  build($_builder, $_state, resultTy, overflowTy, kind, lhs, rhs);
+}]>
+  ];
+}
+
 
//===--===//
 // GlobalOp
 
//===--===//
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 3a102d90aba8f..338006b351da0 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -109,6 +109,7 @@ struct MissingFeatures {
   static bool cgFPOptionsRAII() { return false; }
   static bool metaDataNode() { return false; }
   static bool fastMathFlags() { return false; }
+  static bool vlas() { return false; }
 
   // Missing types
   static bool dataMemberType() { return false; }
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 52bd3b2933744..6e1f5aa0dc600 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -936,8 +936,107 @@ getUnwidenedIntegerType(const ASTContext &astContext, 
const Expr *e) {
 static mlir::Value emitPointerArithmetic(CIRGenFunction &cgf,
  const BinOpInfo &op,
  

[clang] [CLANG][CUDA] Enable alignas after GNU attributes (PR #133105)

2025-03-26 Thread via cfe-commits

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


[clang] [flang] [flang] Expose -m32 and -m64 options (PR #132409)

2025-03-26 Thread Jean-Didier PAILLEUX via cfe-commits


@@ -4671,14 +4671,14 @@ def EB : Flag<["-"], "EB">, Alias;
 def m16 : Flag<["-"], "m16">, Group, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>;
 def m32 : Flag<["-"], "m32">, Group, Flags<[NoXarchOption]>,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;

JDPailleux wrote:

In that case I'll remove it for Flang.

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


[clang] [MS][clang] Add support for vector deleting destructors (PR #126240)

2025-03-26 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

I also noticed that removing -DU_STATIC_IMPLEMENTATION macro passing fixes the 
crash.

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


[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)

2025-03-26 Thread Mohamed Emad via cfe-commits

https://github.com/hulxv updated 
https://github.com/llvm/llvm-project/pull/131280

>From bf9bd4156cb7f652c9cf0477f537e5c58b470448 Mon Sep 17 00:00:00 2001
From: hulxv 
Date: Fri, 14 Mar 2025 07:39:15 +0200
Subject: [PATCH 01/17] [clang-doc] [feat] add `--repository-line-prefix`
 argument (fix #59814)

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 66 ---
 clang-tools-extra/clang-doc/MDGenerator.cpp   |  7 +-
 .../clang-doc/Representation.cpp  |  4 ++
 clang-tools-extra/clang-doc/Representation.h  |  5 +-
 .../clang-doc/tool/ClangDocMain.cpp   | 13 ++--
 5 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 18a0de826630c..967275f93193b 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -491,9 +491,9 @@ genReferencesBlock(const std::vector &References,
   return Out;
 }
 
-static std::unique_ptr
-writeFileDefinition(const Location &L,
-std::optional RepositoryUrl = std::nullopt) {
+static std::unique_ptr writeFileDefinition(
+const Location &L, std::optional RepositoryUrl = std::nullopt,
+std::optional RepositoryLinePrefix = std::nullopt) {
   if (!L.IsFileInRootDir && !RepositoryUrl)
 return std::make_unique(
 HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
@@ -514,17 +514,21 @@ writeFileDefinition(const Location &L,
   Node->Children.emplace_back(std::make_unique("Defined at line "));
   auto LocNumberNode =
   std::make_unique(HTMLTag::TAG_A, std::to_string(L.LineNumber));
-  // The links to a specific line in the source code use the github /
-  // googlesource notation so it won't work for all hosting pages.
-  // FIXME: we probably should have a configuration setting for line number
-  // rendering in the HTML. For example, GitHub uses #L22, while googlesource
-  // uses #22 for line numbers.
-  LocNumberNode->Attributes.emplace_back(
-  "href", (FileURL + "#" + std::to_string(L.LineNumber)).str());
+
+  std::string LineAnchor = "#";
+
+  if (RepositoryLinePrefix)
+LineAnchor += RepositoryLinePrefix.value().str();
+
+  LineAnchor += std::to_string(L.LineNumber);
+
+  LocNumberNode->Attributes.emplace_back("href", (FileURL + LineAnchor).str());
   Node->Children.emplace_back(std::move(LocNumberNode));
   Node->Children.emplace_back(std::make_unique(" of file "));
+
   auto LocFileNode = std::make_unique(
   HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
+
   LocFileNode->Attributes.emplace_back("href", std::string(FileURL));
   Node->Children.emplace_back(std::move(LocFileNode));
   return Node;
@@ -750,11 +754,15 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
   Out.emplace_back(std::move(Table));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(
-  writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
@@ -799,11 +807,15 @@ genHTML(const FunctionInfo &I, const ClangDocContext 
&CDCtx,
   FunctionHeader->Children.emplace_back(std::make_unique(")"));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(writeFileDefinition(
-  *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
@@ -866,11 +878,15 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const 
ClangDocContext &CDCtx,
   Out.emplace_back(std::make_unique(HTMLTag::TAG_H1, InfoTitle));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(writeFileDefinition(
-  *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
diff --git a/clang-tools-extra/clang-doc/MDGenerator.cpp 
b/clang-too

[clang] [llvm] [flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX (PR #131041)

2025-03-26 Thread Daniel Chen via cfe-commits

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


[clang] [flang] [flang] Expose -m32 and -m64 options (PR #132409)

2025-03-26 Thread Jean-Didier PAILLEUX via cfe-commits


@@ -0,0 +1,6 @@
+! Check support of -m32 and -m64.

JDPailleux wrote:

Yes, of course

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


[clang] [CIR] Implement lowering of int-to-bool casts (PR #132996)

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

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


[clang] [clang] fix deduction of member pointers with dependent named classes (PR #133113)

2025-03-26 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/133113

>From 322838fdee8b751582e90d34b367d7877ee1dbf7 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 26 Mar 2025 12:26:40 -0300
Subject: [PATCH] [clang] fix deduction of member pointers with dependent named
 classes

This fixes a regression when interpreting a nested name specifier
for deduction purposes in member pointers.

This introduces a helper for fully translating a nested name specifier into a
type.

Other existing potential users will be deduplicated by using this helper
in subsequent patches.

This regression was introduced here: 
https://github.com/llvm/llvm-project/pull/130537
and was reported here: 
https://github.com/llvm/llvm-project/pull/132401#issuecomment-2751489581

No release notes, since the regression was never released.
---
 clang/include/clang/AST/NestedNameSpecifier.h |  5 ++
 clang/lib/AST/NestedNameSpecifier.cpp | 46 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 34 +-
 clang/test/SemaCXX/member-pointer.cpp | 43 +
 .../SemaTemplate/instantiation-backtrace.cpp  |  6 +--
 5 files changed, 119 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/AST/NestedNameSpecifier.h 
b/clang/include/clang/AST/NestedNameSpecifier.h
index 051d632f1cdf9..273e73e7c1e95 100644
--- a/clang/include/clang/AST/NestedNameSpecifier.h
+++ b/clang/include/clang/AST/NestedNameSpecifier.h
@@ -201,6 +201,11 @@ class NestedNameSpecifier : public llvm::FoldingSetNode {
 return nullptr;
   }
 
+  /// Fully translate this nested name specifier to a type.
+  /// Unlike getAsType, this will convert this entire nested
+  /// name specifier chain into its equivalent type.
+  const Type *translateToType(const ASTContext &Context) const;
+
   NestedNameSpecifierDependence getDependence() const;
 
   /// Whether this nested name specifier refers to a dependent
diff --git a/clang/lib/AST/NestedNameSpecifier.cpp 
b/clang/lib/AST/NestedNameSpecifier.cpp
index a256a87695afc..206e462a58a79 100644
--- a/clang/lib/AST/NestedNameSpecifier.cpp
+++ b/clang/lib/AST/NestedNameSpecifier.cpp
@@ -245,6 +245,52 @@ bool NestedNameSpecifier::containsErrors() const {
   return getDependence() & NestedNameSpecifierDependence::Error;
 }
 
+const Type *
+NestedNameSpecifier::translateToType(const ASTContext &Context) const {
+  NestedNameSpecifier *Prefix = getPrefix();
+  switch (getKind()) {
+  case SpecifierKind::Identifier:
+return Context
+.getDependentNameType(ElaboratedTypeKeyword::None, Prefix,
+  getAsIdentifier())
+.getTypePtr();
+  case SpecifierKind::TypeSpec:
+  case SpecifierKind::TypeSpecWithTemplate: {
+const Type *T = getAsType();
+switch (T->getTypeClass()) {
+case Type::DependentTemplateSpecialization: {
+  const auto *DT = cast(T);
+  // FIXME: The type node can't represent the template keyword.
+  return Context
+  .getDependentTemplateSpecializationType(ElaboratedTypeKeyword::None,
+  Prefix, DT->getIdentifier(),
+  DT->template_arguments())
+  .getTypePtr();
+}
+case Type::Record:
+case Type::TemplateSpecialization:
+case Type::Using:
+case Type::Enum:
+case Type::Typedef:
+case Type::UnresolvedUsing:
+  return Context
+  .getElaboratedType(ElaboratedTypeKeyword::None, Prefix,
+ QualType(T, 0))
+  .getTypePtr();
+default:
+  assert(Prefix == nullptr && "unexpected type with elaboration");
+  return T;
+}
+  }
+  case SpecifierKind::Global:
+  case SpecifierKind::Namespace:
+  case SpecifierKind::NamespaceAlias:
+  case SpecifierKind::Super:
+// These are not representable as types.
+return nullptr;
+  }
+}
+
 /// Print this nested name specifier to the given output
 /// stream.
 void NestedNameSpecifier::print(raw_ostream &OS, const PrintingPolicy &Policy,
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 410b5a2c83e8d..4f6383a40f457 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2127,19 +2127,29 @@ static TemplateDeductionResult 
DeduceTemplateArgumentsByTypeMatch(
   /*DeducedFromArrayBound=*/false, HasDeducedAnyParam);
   Result != TemplateDeductionResult::Success)
 return Result;
-  const Type *QP = MPP->getQualifier()->getAsType(),
- *QA = MPA->getQualifier()->getAsType();
-  CXXRecordDecl *ClsP = MPP->getMostRecentCXXRecordDecl(),
-*ClsA = MPA->getMostRecentCXXRecordDecl();
-  // FIXME: Don't drop the rest of the prefixes here.
-  QualType P = !ClsP || declaresSameEntity(QP->getAsCXXRecordDecl(), ClsP)
-   ? QualType(QP, 0)
-   : S.Cont

[clang] [clang][modules] Lazily load by name lookups in module maps (PR #132853)

2025-03-26 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 commented:

This now makes much more sense after the renames from the prep-commit. There 
are still some naming inconsistencies, though. For example 
`ModuleMap::loadModuleMapFile()` both **parses** and loads a module map file, 
but `ModuleMap::findOrLoadModule()` expects the module map file to be already 
parsed and only loads the module. I think there's value in making this 
distinction more explicit. Maybe we could say that loading a module/module map 
file consists of parsing and _materializing_? No we can consistently name 
functions that do one, the other, or both.

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


[clang] [clang] fix deduction of member pointers with dependent named classes (PR #133113)

2025-03-26 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/133113

>From d1831e84e62f5a100de193619cbfdf9a1d403674 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 26 Mar 2025 12:26:40 -0300
Subject: [PATCH] [clang] fix deduction of member pointers with dependent named
 classes

This fixes a regression when interpreting a nested name specifier
for deduction purposes in member pointers.

This introduces a helper for fully translating a nested name specifier into a
type.

This regression was introduced here: 
https://github.com/llvm/llvm-project/pull/130537
and was reported here: 
https://github.com/llvm/llvm-project/pull/132401#issuecomment-2751489581

No release notes, since the regression was never released.
---
 clang/include/clang/AST/NestedNameSpecifier.h |  5 ++
 clang/lib/AST/NestedNameSpecifier.cpp | 46 +++
 clang/lib/Sema/SemaExprCXX.cpp| 26 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 34 +-
 clang/test/SemaCXX/member-pointer.cpp | 43 +
 .../SemaTemplate/instantiation-backtrace.cpp  |  6 +--
 6 files changed, 122 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/AST/NestedNameSpecifier.h 
b/clang/include/clang/AST/NestedNameSpecifier.h
index 051d632f1cdf9..273e73e7c1e95 100644
--- a/clang/include/clang/AST/NestedNameSpecifier.h
+++ b/clang/include/clang/AST/NestedNameSpecifier.h
@@ -201,6 +201,11 @@ class NestedNameSpecifier : public llvm::FoldingSetNode {
 return nullptr;
   }
 
+  /// Fully translate this nested name specifier to a type.
+  /// Unlike getAsType, this will convert this entire nested
+  /// name specifier chain into its equivalent type.
+  const Type *translateToType(const ASTContext &Context) const;
+
   NestedNameSpecifierDependence getDependence() const;
 
   /// Whether this nested name specifier refers to a dependent
diff --git a/clang/lib/AST/NestedNameSpecifier.cpp 
b/clang/lib/AST/NestedNameSpecifier.cpp
index a256a87695afc..206e462a58a79 100644
--- a/clang/lib/AST/NestedNameSpecifier.cpp
+++ b/clang/lib/AST/NestedNameSpecifier.cpp
@@ -245,6 +245,52 @@ bool NestedNameSpecifier::containsErrors() const {
   return getDependence() & NestedNameSpecifierDependence::Error;
 }
 
+const Type *
+NestedNameSpecifier::translateToType(const ASTContext &Context) const {
+  NestedNameSpecifier *Prefix = getPrefix();
+  switch (getKind()) {
+  case SpecifierKind::Identifier:
+return Context
+.getDependentNameType(ElaboratedTypeKeyword::None, Prefix,
+  getAsIdentifier())
+.getTypePtr();
+  case SpecifierKind::TypeSpec:
+  case SpecifierKind::TypeSpecWithTemplate: {
+const Type *T = getAsType();
+switch (T->getTypeClass()) {
+case Type::DependentTemplateSpecialization: {
+  const auto *DT = cast(T);
+  // FIXME: The type node can't represent the template keyword.
+  return Context
+  .getDependentTemplateSpecializationType(ElaboratedTypeKeyword::None,
+  Prefix, DT->getIdentifier(),
+  DT->template_arguments())
+  .getTypePtr();
+}
+case Type::Record:
+case Type::TemplateSpecialization:
+case Type::Using:
+case Type::Enum:
+case Type::Typedef:
+case Type::UnresolvedUsing:
+  return Context
+  .getElaboratedType(ElaboratedTypeKeyword::None, Prefix,
+ QualType(T, 0))
+  .getTypePtr();
+default:
+  assert(Prefix == nullptr && "unexpected type with elaboration");
+  return T;
+}
+  }
+  case SpecifierKind::Global:
+  case SpecifierKind::Namespace:
+  case SpecifierKind::NamespaceAlias:
+  case SpecifierKind::Super:
+// These are not representable as types.
+return nullptr;
+  }
+}
+
 /// Print this nested name specifier to the given output
 /// stream.
 void NestedNameSpecifier::print(raw_ostream &OS, const PrintingPolicy &Policy,
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 856b505e92214..b2310628adc64 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -60,30 +60,10 @@ ParsedType Sema::getInheritingConstructorName(CXXScopeSpec 
&SS,
   SourceLocation NameLoc,
   const IdentifierInfo &Name) {
   NestedNameSpecifier *NNS = SS.getScopeRep();
+  if (const IdentifierInfo *II = NNS->getAsIdentifier())
+assert(II == &Name && "not a constructor name");
 
-  // Convert the nested-name-specifier into a type.
-  QualType Type;
-  switch (NNS->getKind()) {
-  case NestedNameSpecifier::TypeSpec:
-  case NestedNameSpecifier::TypeSpecWithTemplate:
-Type = QualType(NNS->getAsType(), 0);
-break;
-
-  case NestedNameSpecifier::Identifier:
-// Strip off the last layer of the nested-name-specifier and build a
-// typena

[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

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

https://github.com/andykaylor created 
https://github.com/llvm/llvm-project/pull/133134

This fixes unused variable warnings that have crept into the ClangIR code. In 
some cases the variable will be needed later, but all unused variables are 
being removed here. They can be reintroduced when they are needed.

>From a94a54044a18c8608567a0988a30eae4d4d61aab Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Wed, 26 Mar 2025 10:52:32 -0700
Subject: [PATCH] [CIR][NFC] Fix warnings in ClangIR code

This fixes unused variable warnings that have crept into the ClangIR code.
In some cases the variable will be needed later, but all unused variables
are being removed here. They can be reintroduced when they are needed.
---
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  2 +-
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp|  3 +--
 clang/lib/CIR/CodeGen/CIRGenFunction.h|  4 
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 20 ++-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h   |  7 ++-
 5 files changed, 6 insertions(+), 30 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 8fd09b4cfefeb..f01e03a89981d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -170,7 +170,7 @@ mlir::Value CIRGenFunction::evaluateExprAsBool(const Expr 
*e) {
   SourceLocation loc = e->getExprLoc();
 
   assert(!cir::MissingFeatures::pgoUse());
-  if (const MemberPointerType *MPT = e->getType()->getAs()) 
{
+  if (e->getType()->getAs()) {
 cgm.errorNYI(e->getSourceRange(),
  "evaluateExprAsBool: member pointer type");
 return createDummyValue(getLoc(loc), boolTy);
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 52bd3b2933744..2cf92dfbf3a5b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -1366,8 +1366,7 @@ mlir::Value 
ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
   const mlir::Location loc = cgf.getLoc(e->getSourceRange());
   if (auto kind = e->getKind();
   kind == UETT_SizeOf || kind == UETT_DataSizeOf) {
-if (const VariableArrayType *variableArrTy =
-cgf.getContext().getAsVariableArrayType(typeToSize)) {
+if (cgf.getContext().getAsVariableArrayType(typeToSize)) {
   cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
  "sizeof operator for VariableArrayType",
  e->getStmtClassName());
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h 
b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index cc04610f23fcb..99cc20126e360 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -367,10 +367,6 @@ class CIRGenFunction : public CIRGenTypeCache {
 // class is upstreamed.
 CIRGenFunction &cgf;
 
-// Block containing cleanup code for things initialized in this lexical
-// context (scope).
-mlir::Block *cleanupBlock = nullptr;
-
 // Points to the scope entry block. This is useful, for instance, for
 // helping to insert allocas before finalizing any recursive CodeGen from
 // switches.
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index a16840cc6bfef..69303a41f2246 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -126,21 +126,6 @@ static mlir::Value 
emitToMemory(mlir::ConversionPatternRewriter &rewriter,
   return value;
 }
 
-static mlir::Value
-emitCirAttrToMemory(mlir::Operation *parentOp, mlir::Attribute attr,
-mlir::ConversionPatternRewriter &rewriter,
-const mlir::TypeConverter *converter,
-mlir::DataLayout const &dataLayout) {
-
-  mlir::Value loweredValue =
-  lowerCirAttrAsValue(parentOp, attr, rewriter, converter);
-  if (auto boolAttr = mlir::dyn_cast(attr)) {
-return emitToMemory(rewriter, dataLayout, boolAttr.getType(), 
loweredValue);
-  }
-
-  return loweredValue;
-}
-
 mlir::LLVM::Linkage convertLinkage(cir::GlobalLinkageKind linkage) {
   using CIR = cir::GlobalLinkageKind;
   using LLVM = mlir::LLVM::Linkage;
@@ -261,7 +246,7 @@ mlir::Value 
CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
   mlir::Location loc = parentOp->getLoc();
   mlir::Value result;
 
-  if (auto zeros = attr.getTrailingZerosNum()) {
+  if (attr.hasTrailingZeros()) {
 mlir::Type arrayTy = attr.getType();
 result = rewriter.create(
 loc, converter->convertType(arrayTy));
@@ -1251,13 +1236,12 @@ void ConvertCIRToLLVMPass::runOnOperation() {
   patterns.add(converter, patterns.getContext(), dl);
   patterns.add(converter, patterns.getContext(), 
dl);
   patterns.add(converter, patterns.getContext(), dl);
-  patterns.add(converter, patterns.getContext(),
-

[clang] [C2y] Implement WG14 N3369 and N3469 (_Countof) (PR #133125)

2025-03-26 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Although C++ might have good alternatives, that's not so helpful for C 
> headers being included from C++ that might end up using this (e.g. some 
> static inline function in a system header). (i.e. if it's not too much effort 
> to do, I would encourage exposing it in C++)

We can contrive reasons to expose this in C++, and it would be a conforming 
extension there, but I'm still not convinced that's a good idea. Historically, 
many of the things we expose from C into C++ have some really rough edges we 
mostly ignore, like VLAs, _Complex vs std::complex, etc and I'd like to break 
that cycle by not exposing everything to both languages just because we can. 
I'm not strongly opposed in this case, but I'd still rather wait for a real 
world use case beyond "it could be used there" before we expose it to C++.

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


[clang] [CLANG] Enable alignas after GNU attributes (PR #133107)

2025-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Denis.G (DenisGZM)


Changes

Enable parsing alignas attribute after GNU attributes, before ParseDeclaration

This might be useful for cuda code where __shared__ and other specificators may 
be mixed with align.

I'd be glad to see if there are any better places or other technique to process 
this attribute without interrupting current flow of parsing.

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


2 Files Affected:

- (modified) clang/lib/Parse/ParseStmt.cpp (+5) 
- (added) clang/test/SemaCUDA/cuda-attr-order.cu (+15) 


``diff
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 150b2879fc94f..33b9f63bcfa08 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -296,6 +296,11 @@ StmtResult 
Parser::ParseStatementOrDeclarationAfterAttributes(
 goto Retry;
   }
 
+  case tok::kw_alignas: {
+ParseAlignmentSpecifier(CXX11Attrs);
+goto Retry;
+  }
+
   case tok::kw_template: {
 SourceLocation DeclEnd;
 ParseTemplateDeclarationOrSpecialization(DeclaratorContext::Block, DeclEnd,
diff --git a/clang/test/SemaCUDA/cuda-attr-order.cu 
b/clang/test/SemaCUDA/cuda-attr-order.cu
new file mode 100644
index 0..d3bf5b014d1c6
--- /dev/null
+++ b/clang/test/SemaCUDA/cuda-attr-order.cu
@@ -0,0 +1,15 @@
+// Verify that we can parse a simple CUDA file with different attributes order.
+// RUN: %clang_cc1 "-triple" "nvptx-nvidia-cuda"  -fsyntax-only -verify %s
+// expected-no-diagnostics
+#include "Inputs/cuda.h"
+
+struct alignas(16) float4 {
+float x, y, z, w;
+};
+
+__attribute__((device)) float func() {
+__shared__ alignas(alignof(float4)) float As[4][4];  // Both combinations
+alignas(alignof(float4)) __shared__  float Bs[4][4]; // must be legal
+
+return As[0][0] + Bs[0][0];
+}

``




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


[clang] [clang-tools-extra] Reland: [clang] NFC: Clear some uses of MemberPointerType::getClass (PR #132317)

2025-03-26 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

> @alexfh Are you sure the original crashes were due to #132977 ?

I thought so, but your explanation below also seems reasonable. I can try to 
verify.

> Looking at the patch, it seems unlikely it could cause a crash in itself.
> 
> What I think happened is that your compilation proceeded further along and 
> encountered the other crash, which was a regression introduced by a different 
> commit, which had been reported even before that last commit was landed.
> 
> It's certainly possible to revert this commit, however there are a lot of 
> dependent patches by this point, and I think this last crash is isolated 
> enough to point into #132401 instead of this commit.



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


[clang] [PATCH] [clang][frontend] Fix AllocKind retrieving for `CXXConstructorDecl` refs #132794 (PR #133077)

2025-03-26 Thread Paul Schwabauer via cfe-commits

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


[clang] [clang] Update Mach-O ptrauth driver defaults (PR #132834)

2025-03-26 Thread Francis Visoiu Mistrih via cfe-commits

francisvm wrote:

> Looks like @ahmedbougacha might be out. @francisvm, could you take a look?

@rjmccall / @jroelofs might be able to help!

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


[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

2025-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Andy Kaylor (andykaylor)


Changes

This fixes unused variable warnings that have crept into the ClangIR code. In 
some cases the variable will be needed later, but all unused variables are 
being removed here. They can be reintroduced when they are needed.

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


5 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+1-1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+1-2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (-4) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+2-18) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h (+2-5) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 8fd09b4cfefeb..f01e03a89981d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -170,7 +170,7 @@ mlir::Value CIRGenFunction::evaluateExprAsBool(const Expr 
*e) {
   SourceLocation loc = e->getExprLoc();
 
   assert(!cir::MissingFeatures::pgoUse());
-  if (const MemberPointerType *MPT = e->getType()->getAs()) 
{
+  if (e->getType()->getAs()) {
 cgm.errorNYI(e->getSourceRange(),
  "evaluateExprAsBool: member pointer type");
 return createDummyValue(getLoc(loc), boolTy);
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 52bd3b2933744..2cf92dfbf3a5b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -1366,8 +1366,7 @@ mlir::Value 
ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
   const mlir::Location loc = cgf.getLoc(e->getSourceRange());
   if (auto kind = e->getKind();
   kind == UETT_SizeOf || kind == UETT_DataSizeOf) {
-if (const VariableArrayType *variableArrTy =
-cgf.getContext().getAsVariableArrayType(typeToSize)) {
+if (cgf.getContext().getAsVariableArrayType(typeToSize)) {
   cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
  "sizeof operator for VariableArrayType",
  e->getStmtClassName());
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h 
b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index cc04610f23fcb..99cc20126e360 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -367,10 +367,6 @@ class CIRGenFunction : public CIRGenTypeCache {
 // class is upstreamed.
 CIRGenFunction &cgf;
 
-// Block containing cleanup code for things initialized in this lexical
-// context (scope).
-mlir::Block *cleanupBlock = nullptr;
-
 // Points to the scope entry block. This is useful, for instance, for
 // helping to insert allocas before finalizing any recursive CodeGen from
 // switches.
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index a16840cc6bfef..69303a41f2246 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -126,21 +126,6 @@ static mlir::Value 
emitToMemory(mlir::ConversionPatternRewriter &rewriter,
   return value;
 }
 
-static mlir::Value
-emitCirAttrToMemory(mlir::Operation *parentOp, mlir::Attribute attr,
-mlir::ConversionPatternRewriter &rewriter,
-const mlir::TypeConverter *converter,
-mlir::DataLayout const &dataLayout) {
-
-  mlir::Value loweredValue =
-  lowerCirAttrAsValue(parentOp, attr, rewriter, converter);
-  if (auto boolAttr = mlir::dyn_cast(attr)) {
-return emitToMemory(rewriter, dataLayout, boolAttr.getType(), 
loweredValue);
-  }
-
-  return loweredValue;
-}
-
 mlir::LLVM::Linkage convertLinkage(cir::GlobalLinkageKind linkage) {
   using CIR = cir::GlobalLinkageKind;
   using LLVM = mlir::LLVM::Linkage;
@@ -261,7 +246,7 @@ mlir::Value 
CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
   mlir::Location loc = parentOp->getLoc();
   mlir::Value result;
 
-  if (auto zeros = attr.getTrailingZerosNum()) {
+  if (attr.hasTrailingZeros()) {
 mlir::Type arrayTy = attr.getType();
 result = rewriter.create(
 loc, converter->convertType(arrayTy));
@@ -1251,13 +1236,12 @@ void ConvertCIRToLLVMPass::runOnOperation() {
   patterns.add(converter, patterns.getContext(), dl);
   patterns.add(converter, patterns.getContext(), 
dl);
   patterns.add(converter, patterns.getContext(), dl);
-  patterns.add(converter, patterns.getContext(),
-dl);
   patterns.add<
   // clang-format off
CIRToLLVMBinOpLowering,
CIRToLLVMBrCondOpLowering,
CIRToLLVMBrOpLowering,
+   CIRToLLVMConstantOpLowering,
CIRToLLVMFuncOpLowering,
CIRToLLVMTrapOpLowering,
   

[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

2025-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangir

Author: Andy Kaylor (andykaylor)


Changes

This fixes unused variable warnings that have crept into the ClangIR code. In 
some cases the variable will be needed later, but all unused variables are 
being removed here. They can be reintroduced when they are needed.

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


5 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+1-1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp (+1-2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (-4) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+2-18) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h (+2-5) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 8fd09b4cfefeb..f01e03a89981d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -170,7 +170,7 @@ mlir::Value CIRGenFunction::evaluateExprAsBool(const Expr 
*e) {
   SourceLocation loc = e->getExprLoc();
 
   assert(!cir::MissingFeatures::pgoUse());
-  if (const MemberPointerType *MPT = e->getType()->getAs()) 
{
+  if (e->getType()->getAs()) {
 cgm.errorNYI(e->getSourceRange(),
  "evaluateExprAsBool: member pointer type");
 return createDummyValue(getLoc(loc), boolTy);
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 52bd3b2933744..2cf92dfbf3a5b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -1366,8 +1366,7 @@ mlir::Value 
ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
   const mlir::Location loc = cgf.getLoc(e->getSourceRange());
   if (auto kind = e->getKind();
   kind == UETT_SizeOf || kind == UETT_DataSizeOf) {
-if (const VariableArrayType *variableArrTy =
-cgf.getContext().getAsVariableArrayType(typeToSize)) {
+if (cgf.getContext().getAsVariableArrayType(typeToSize)) {
   cgf.getCIRGenModule().errorNYI(e->getSourceRange(),
  "sizeof operator for VariableArrayType",
  e->getStmtClassName());
diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h 
b/clang/lib/CIR/CodeGen/CIRGenFunction.h
index cc04610f23fcb..99cc20126e360 100644
--- a/clang/lib/CIR/CodeGen/CIRGenFunction.h
+++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h
@@ -367,10 +367,6 @@ class CIRGenFunction : public CIRGenTypeCache {
 // class is upstreamed.
 CIRGenFunction &cgf;
 
-// Block containing cleanup code for things initialized in this lexical
-// context (scope).
-mlir::Block *cleanupBlock = nullptr;
-
 // Points to the scope entry block. This is useful, for instance, for
 // helping to insert allocas before finalizing any recursive CodeGen from
 // switches.
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index a16840cc6bfef..69303a41f2246 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -126,21 +126,6 @@ static mlir::Value 
emitToMemory(mlir::ConversionPatternRewriter &rewriter,
   return value;
 }
 
-static mlir::Value
-emitCirAttrToMemory(mlir::Operation *parentOp, mlir::Attribute attr,
-mlir::ConversionPatternRewriter &rewriter,
-const mlir::TypeConverter *converter,
-mlir::DataLayout const &dataLayout) {
-
-  mlir::Value loweredValue =
-  lowerCirAttrAsValue(parentOp, attr, rewriter, converter);
-  if (auto boolAttr = mlir::dyn_cast(attr)) {
-return emitToMemory(rewriter, dataLayout, boolAttr.getType(), 
loweredValue);
-  }
-
-  return loweredValue;
-}
-
 mlir::LLVM::Linkage convertLinkage(cir::GlobalLinkageKind linkage) {
   using CIR = cir::GlobalLinkageKind;
   using LLVM = mlir::LLVM::Linkage;
@@ -261,7 +246,7 @@ mlir::Value 
CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
   mlir::Location loc = parentOp->getLoc();
   mlir::Value result;
 
-  if (auto zeros = attr.getTrailingZerosNum()) {
+  if (attr.hasTrailingZeros()) {
 mlir::Type arrayTy = attr.getType();
 result = rewriter.create(
 loc, converter->convertType(arrayTy));
@@ -1251,13 +1236,12 @@ void ConvertCIRToLLVMPass::runOnOperation() {
   patterns.add(converter, patterns.getContext(), dl);
   patterns.add(converter, patterns.getContext(), 
dl);
   patterns.add(converter, patterns.getContext(), dl);
-  patterns.add(converter, patterns.getContext(),
-dl);
   patterns.add<
   // clang-format off
CIRToLLVMBinOpLowering,
CIRToLLVMBrCondOpLowering,
CIRToLLVMBrOpLowering,
+   CIRToLLVMConstantOpLowering,
CIRToLLVMFuncOpLowering,
CIRToLLVMTrapOpLowering,
 

[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

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

andykaylor wrote:

@mmha 

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


[clang] [clang-format] Allow `Language: Cpp` for C files (PR #133033)

2025-03-26 Thread Björn Schäpers via cfe-commits

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


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


[clang] [Clang][Driver] Override complex number calculation method by -fno-fa… (PR #132680)

2025-03-26 Thread via cfe-commits


@@ -177,14 +177,45 @@
 // RUN: %clang -### -target x86_64 -ffast-math -fcomplex-arithmetic=basic -c 
%s 2>&1 \
 // RUN:   | FileCheck --check-prefix=BASIC %s
 
-// BASIC: -complex-range=basic
-// FULL: -complex-range=full
-// PRMTD: -complex-range=promoted
-// BASIC-NOT: -complex-range=improved
-// CHECK-NOT: -complex-range=basic
-// IMPRVD: -complex-range=improved
-// IMPRVD-NOT: -complex-range=basic
-// CHECK-NOT: -complex-range=improved
+// RUN: %clang -### -target x86_64 -fcx-limited-range -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN21 %s
+
+// RUN: %clang -### -Werror -target x86_64 -fno-cx-limited-range 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -target x86_64 -fcx-fortran-rules -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN22 %s
+
+// RUN: %clang -### -Werror -target x86_64 -fno-cx-fortran-rules 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -Werror -target x86_64 -ffast-math -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -target x86_64 -fcomplex-arithmetic=basic -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN23 %s
+
+// RUN: %clang -### -target x86_64 -fcomplex-arithmetic=promoted 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN24 %s
+
+// RUN: %clang -### -target x86_64 -fcomplex-arithmetic=improved 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN25 %s
+
+// RUN: %clang -### -Werror -target x86_64 -fcomplex-arithmetic=full 
-fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -target x86_64 -ffp-model=aggressive -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN23 %s
+
+// RUN: %clang -### -target x86_64 -ffp-model=fast -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL,WARN24 %s
+
+// RUN: %clang -### -Werror -target x86_64 -ffp-model=precise -fno-fast-math \
+// RUN: -c %s 2>&1 | FileCheck --check-prefixes=FULL %s
+
+// RUN: %clang -### -Werror -target x86_64 -ffp-model=strict -fno-fast-math \

s-watanabe314 wrote:

I added test cases.

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


[libclc] [libclc] Fix commands in compile_to_bc are executed sequentially (PR #130755)

2025-03-26 Thread Fraser Cormack via cfe-commits


@@ -63,13 +65,15 @@ function(compile_to_bc)
   ${ARG_DEPENDENCIES}
 DEPFILE ${ARG_OUTPUT}.d
   )
+  add_custom_target( ${ARG_TARGET} DEPENDS ${ARG_OUTPUT}${TMP_SUFFIX} )

frasercrmck wrote:

I don't think the (possibly) "temp" output (in the case of `.ll` files) should 
be given the honour of the `ARG_TARGET` target. The final output of this 
function should unconditionally have `ARG_TARGET`. That saves doing `-as` 
workarounds in other parts of the code. The `TARGET` name the user passes 
should be definitive, in other words.

Do we strictly need a target for the intermediate step too? If we do, we could 
have `${ARG_TARGET}${TMP_SUFFIX}` here. Then non-IR files get `ARG_TARGET` 
target, and then in the IR block below we create `ARG_TARGET` for that case.

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


[libclc] [libclc] Fix commands in compile_to_bc are executed sequentially (PR #130755)

2025-03-26 Thread Fraser Cormack via cfe-commits


@@ -283,7 +294,7 @@ function(add_libclc_builtin_set)
 
   set( builtins_comp_lib_tgt builtins.comp.${ARG_ARCH_SUFFIX} )
   add_custom_target( ${builtins_comp_lib_tgt}
-DEPENDS ${bytecode_files}
+DEPENDS ${compile_tgts}

frasercrmck wrote:

Do we not need to depend on the targets *and* the files? CMake dependencies are 
strange.

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


[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

2025-03-26 Thread Morris Hafner via cfe-commits


@@ -1251,13 +1236,12 @@ void ConvertCIRToLLVMPass::runOnOperation() {
   patterns.add(converter, patterns.getContext(), dl);
   patterns.add(converter, patterns.getContext(), 
dl);
   patterns.add(converter, patterns.getContext(), dl);
-  patterns.add(converter, patterns.getContext(),
-dl);
   patterns.add<
   // clang-format off
CIRToLLVMBinOpLowering,
CIRToLLVMBrCondOpLowering,
CIRToLLVMBrOpLowering,
+   CIRToLLVMConstantOpLowering,

mmha wrote:

The comment right above says we'd like to keep these patterns separate because 
their signature is going to change in the future. That's still the case here.

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


[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

2025-03-26 Thread Morris Hafner via cfe-commits


@@ -1366,8 +1366,7 @@ mlir::Value 
ScalarExprEmitter::VisitUnaryExprOrTypeTraitExpr(
   const mlir::Location loc = cgf.getLoc(e->getSourceRange());
   if (auto kind = e->getKind();
   kind == UETT_SizeOf || kind == UETT_DataSizeOf) {
-if (const VariableArrayType *variableArrTy =
-cgf.getContext().getAsVariableArrayType(typeToSize)) {
+if (cgf.getContext().getAsVariableArrayType(typeToSize)) {

mmha wrote:

Same here.

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


[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

2025-03-26 Thread Morris Hafner via cfe-commits

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


[clang] Update OpenMPSupport.rst (PR #133138)

2025-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (CatherineMoore)


Changes

Document wip for ref modifier for map clauses in C++ implementation of OpenMP 
6.0

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


1 Files Affected:

- (modified) clang/docs/OpenMPSupport.rst (+1-1) 


``diff
diff --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 83d90ffef6bc7..892a2dc9e157a 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -454,7 +454,7 @@ implementation.
 
+-+---+---+--+
 | Clarifications to implicit reductions   | 
:none:`unclaimed` | :none:`unclaimed` | 
 |
 
+-+---+---+--+
-| ref modifier for map clauses| 
:none:`unclaimed` | :none:`unclaimed` | 
 |
+| ref modifier for map clauses| :none:`wip`
 | :none:`unclaimed` |  
|
 
+-+---+---+--+
 | map-type modifiers in arbitrary position| 
:none:`unclaimed` | :none:`unclaimed` | 
 |
 
+-+---+---+--+

``




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


[clang-tools-extra] [clang-tidy][misc-const-correctness] fix fp when using const array type. (PR #133018)

2025-03-26 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/133018

>From c2defc601e2d8e42130600802ff330a0feb8b52a Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 25 Mar 2025 23:31:38 +
Subject: [PATCH 1/3] [clang-tidy][misc-const-correctness] fix fp when using
 const array type.

Fixed: #132931
const array is immutable in C/C++ language design, we don't need to
check constness for it.
---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp | 6 +-
 clang-tools-extra/docs/ReleaseNotes.rst   | 3 ++-
 .../clang-tidy/checkers/misc/const-correctness-values.cpp | 8 
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 50e6722badf50..13eba246faf56 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -89,6 +89,8 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
   const auto ConstReference = hasType(references(isConstQualified()));
   const auto RValueReference = hasType(
   referenceType(anyOf(rValueReferenceType(), 
unless(isSpelledAsLValue();
+  const auto ConstArrayType =
+  hasType(arrayType(hasElementType(isConstQualified(;
 
   const auto TemplateType = anyOf(
   hasType(hasCanonicalType(templateTypeParmType())),
@@ -115,7 +117,7 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
   // Example: `int i = 10` would match `int i`.
   const auto LocalValDecl = varDecl(
   isLocal(), hasInitializer(anything()),
-  unless(anyOf(ConstType, ConstReference, TemplateType,
+  unless(anyOf(ConstType, ConstReference, ConstArrayType, TemplateType,
hasInitializer(isInstantiationDependent()), 
AutoTemplateType,
RValueReference, FunctionPointerRef,
hasType(cxxRecordDecl(isLambda())), isImplicit(),
@@ -161,6 +163,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   VariableCategory VC = VariableCategory::Value;
   const QualType VT = Variable->getType();
+  VT->dump();
   if (VT->isReferenceType()) {
 VC = VariableCategory::Reference;
   } else if (VT->isPointerType()) {
@@ -169,6 +172,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (ArrayT->getElementType()->isPointerType())
   VC = VariableCategory::Pointer;
   }
+  llvm::errs() << (int)VC << "\n";
 
   auto CheckValue = [&]() {
 // The scope is only registered if the analysis shall be run.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index aa85105918ecf..7bbf2190ee262 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -146,7 +146,8 @@ Changes in existing checks
   `AllowedTypes`, that excludes specified types from const-correctness
   checking and fixing false positives when modifying variant by ``operator[]``
   with template in parameters and supporting to check pointee mutation by
-  `AnalyzePointers` option.
+  `AnalyzePointers` option and fixing false positives when using const array
+  type.
 
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 4cf78aeef5bd4..a80e1e1af1870 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -1007,3 +1007,11 @@ template  void f() {
   x[T{}] = 3;
 }
 } // namespace gh127776_false_positive
+
+namespace gh132931_false_positive {
+using T = const int;
+void valid(int i) {
+  const int arr0[] = {1, 2, 3};
+  T arr1[] = {1, 2, 3};
+}
+} // namespace gh132931_false_positive

>From 166e4578536884a1ec7a97efabfd5d64e14895ba Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 27 Mar 2025 02:13:13 +0800
Subject: [PATCH 2/3] Update
 clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp

---
 clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 13eba246faf56..ca04c83280412 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -172,7 +172,6 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (ArrayT->getElementType()->isPointerType())
   VC = VariableCategory::Pointer;
   }
-  llvm::errs() << (int)VC << "\n";
 
   auto CheckValue = [&]() {
 // The scope is only registered if the analysis 

[clang] Update OpenMPSupport.rst (PR #133138)

2025-03-26 Thread via cfe-commits

https://github.com/CatherineMoore created 
https://github.com/llvm/llvm-project/pull/133138

Document wip for ref modifier for map clauses in C++ implementation of OpenMP 
6.0

>From ee53cc39ca84a4cece5b01502fbd778282a051c8 Mon Sep 17 00:00:00 2001
From: CatherineMoore 
Date: Wed, 26 Mar 2025 14:11:24 -0400
Subject: [PATCH] Update OpenMPSupport.rst

---
 clang/docs/OpenMPSupport.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 83d90ffef6bc7..892a2dc9e157a 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -454,7 +454,7 @@ implementation.
 
+-+---+---+--+
 | Clarifications to implicit reductions   | 
:none:`unclaimed` | :none:`unclaimed` | 
 |
 
+-+---+---+--+
-| ref modifier for map clauses| 
:none:`unclaimed` | :none:`unclaimed` | 
 |
+| ref modifier for map clauses| :none:`wip`
 | :none:`unclaimed` |  
|
 
+-+---+---+--+
 | map-type modifiers in arbitrary position| 
:none:`unclaimed` | :none:`unclaimed` | 
 |
 
+-+---+---+--+

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


[clang-tools-extra] [clang-tidy][misc-const-correctness] fix fp when using const array type. (PR #133018)

2025-03-26 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/133018

>From c2defc601e2d8e42130600802ff330a0feb8b52a Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 25 Mar 2025 23:31:38 +
Subject: [PATCH 1/2] [clang-tidy][misc-const-correctness] fix fp when using
 const array type.

Fixed: #132931
const array is immutable in C/C++ language design, we don't need to
check constness for it.
---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp | 6 +-
 clang-tools-extra/docs/ReleaseNotes.rst   | 3 ++-
 .../clang-tidy/checkers/misc/const-correctness-values.cpp | 8 
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 50e6722badf50..13eba246faf56 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -89,6 +89,8 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
   const auto ConstReference = hasType(references(isConstQualified()));
   const auto RValueReference = hasType(
   referenceType(anyOf(rValueReferenceType(), 
unless(isSpelledAsLValue();
+  const auto ConstArrayType =
+  hasType(arrayType(hasElementType(isConstQualified(;
 
   const auto TemplateType = anyOf(
   hasType(hasCanonicalType(templateTypeParmType())),
@@ -115,7 +117,7 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
   // Example: `int i = 10` would match `int i`.
   const auto LocalValDecl = varDecl(
   isLocal(), hasInitializer(anything()),
-  unless(anyOf(ConstType, ConstReference, TemplateType,
+  unless(anyOf(ConstType, ConstReference, ConstArrayType, TemplateType,
hasInitializer(isInstantiationDependent()), 
AutoTemplateType,
RValueReference, FunctionPointerRef,
hasType(cxxRecordDecl(isLambda())), isImplicit(),
@@ -161,6 +163,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   VariableCategory VC = VariableCategory::Value;
   const QualType VT = Variable->getType();
+  VT->dump();
   if (VT->isReferenceType()) {
 VC = VariableCategory::Reference;
   } else if (VT->isPointerType()) {
@@ -169,6 +172,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (ArrayT->getElementType()->isPointerType())
   VC = VariableCategory::Pointer;
   }
+  llvm::errs() << (int)VC << "\n";
 
   auto CheckValue = [&]() {
 // The scope is only registered if the analysis shall be run.
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index aa85105918ecf..7bbf2190ee262 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -146,7 +146,8 @@ Changes in existing checks
   `AllowedTypes`, that excludes specified types from const-correctness
   checking and fixing false positives when modifying variant by ``operator[]``
   with template in parameters and supporting to check pointee mutation by
-  `AnalyzePointers` option.
+  `AnalyzePointers` option and fixing false positives when using const array
+  type.
 
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 4cf78aeef5bd4..a80e1e1af1870 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -1007,3 +1007,11 @@ template  void f() {
   x[T{}] = 3;
 }
 } // namespace gh127776_false_positive
+
+namespace gh132931_false_positive {
+using T = const int;
+void valid(int i) {
+  const int arr0[] = {1, 2, 3};
+  T arr1[] = {1, 2, 3};
+}
+} // namespace gh132931_false_positive

>From 166e4578536884a1ec7a97efabfd5d64e14895ba Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 27 Mar 2025 02:13:13 +0800
Subject: [PATCH 2/2] Update
 clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp

---
 clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 13eba246faf56..ca04c83280412 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -172,7 +172,6 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (ArrayT->getElementType()->isPointerType())
   VC = VariableCategory::Pointer;
   }
-  llvm::errs() << (int)VC << "\n";
 
   auto CheckValue = [&]() {
 // The scope is only registered if the analysis 

[clang-tools-extra] [clang-tidy][misc-const-correctness] fix fp when using const array type. (PR #133018)

2025-03-26 Thread Congcong Cai via cfe-commits


@@ -161,6 +163,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   VariableCategory VC = VariableCategory::Value;
   const QualType VT = Variable->getType();
+  VT->dump();

HerrCai0907 wrote:

```suggestion
```


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


[clang-tools-extra] [clang-tidy][misc-const-correctness] fix fp when using const array type. (PR #133018)

2025-03-26 Thread Congcong Cai via cfe-commits


@@ -169,6 +172,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult &Result) {
 if (ArrayT->getElementType()->isPointerType())
   VC = VariableCategory::Pointer;
   }
+  llvm::errs() << (int)VC << "\n";

HerrCai0907 wrote:

```suggestion
```


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


[clang] [llvm] [AArch64] Add FEAT_FPAC to Grace (PR #133054)

2025-03-26 Thread Ricardo Jesus via cfe-commits

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


[clang] Remove duplicate API (PR #132776)

2025-03-26 Thread via cfe-commits

https://github.com/Jugst3r updated 
https://github.com/llvm/llvm-project/pull/132776

>From a298a398accfe663cdbf34fd81e17188aadaee9b Mon Sep 17 00:00:00 2001
From: Matthieu Eyraud 
Date: Mon, 24 Mar 2025 14:38:50 +
Subject: [PATCH] Remove duplicate API

And adapt the existing code to account for the comments made when
introducing the duplicate API.

Note that this introduces a retro-incompatibility with LLVM 19.
---
 clang/bindings/python/clang/cindex.py   |   4 +-
 clang/include/clang-c/Index.h   | 122 +++-
 clang/tools/c-index-test/c-index-test.c |   6 +-
 clang/tools/libclang/CIndex.cpp |  37 ++-
 clang/tools/libclang/libclang.map   |   6 --
 5 files changed, 46 insertions(+), 129 deletions(-)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index e881bf131d6c4..49fd572c04883 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1876,7 +1876,7 @@ def binary_operator(self):
 """
 
 if not hasattr(self, "_binopcode"):
-self._binopcode = conf.lib.clang_Cursor_getBinaryOpcode(self)
+self._binopcode = 
(conf.lib.clang_getCursorBinaryOperatorKind(self))
 
 return BinaryOperator.from_id(self._binopcode)
 
@@ -4043,7 +4043,7 @@ def set_property(self, property, value):
 ("clang_Cursor_getTemplateArgumentType", [Cursor, c_uint], Type),
 ("clang_Cursor_getTemplateArgumentValue", [Cursor, c_uint], c_longlong),
 ("clang_Cursor_getTemplateArgumentUnsignedValue", [Cursor, c_uint], 
c_ulonglong),
-("clang_Cursor_getBinaryOpcode", [Cursor], c_int),
+("clang_getCursorBinaryOperatorKind", [Cursor], c_int),
 ("clang_Cursor_getBriefCommentText", [Cursor], _CXString),
 ("clang_Cursor_getRawCommentText", [Cursor], _CXString),
 ("clang_Cursor_getOffsetOfField", [Cursor], c_longlong),
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 38e2417dcd181..dbb49d181d684 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3839,59 +3839,6 @@ enum CX_StorageClass {
   CX_SC_Register
 };
 
-/**
- * Represents a specific kind of binary operator which can appear at a cursor.
- */
-enum CX_BinaryOperatorKind {
-  CX_BO_Invalid = 0,
-  CX_BO_PtrMemD = 1,
-  CX_BO_PtrMemI = 2,
-  CX_BO_Mul = 3,
-  CX_BO_Div = 4,
-  CX_BO_Rem = 5,
-  CX_BO_Add = 6,
-  CX_BO_Sub = 7,
-  CX_BO_Shl = 8,
-  CX_BO_Shr = 9,
-  CX_BO_Cmp = 10,
-  CX_BO_LT = 11,
-  CX_BO_GT = 12,
-  CX_BO_LE = 13,
-  CX_BO_GE = 14,
-  CX_BO_EQ = 15,
-  CX_BO_NE = 16,
-  CX_BO_And = 17,
-  CX_BO_Xor = 18,
-  CX_BO_Or = 19,
-  CX_BO_LAnd = 20,
-  CX_BO_LOr = 21,
-  CX_BO_Assign = 22,
-  CX_BO_MulAssign = 23,
-  CX_BO_DivAssign = 24,
-  CX_BO_RemAssign = 25,
-  CX_BO_AddAssign = 26,
-  CX_BO_SubAssign = 27,
-  CX_BO_ShlAssign = 28,
-  CX_BO_ShrAssign = 29,
-  CX_BO_AndAssign = 30,
-  CX_BO_XorAssign = 31,
-  CX_BO_OrAssign = 32,
-  CX_BO_Comma = 33,
-  CX_BO_LAST = CX_BO_Comma
-};
-
-/**
- * \brief Returns the operator code for the binary operator.
- */
-CINDEX_LINKAGE enum CX_BinaryOperatorKind
-clang_Cursor_getBinaryOpcode(CXCursor C);
-
-/**
- * \brief Returns a string containing the spelling of the binary operator.
- */
-CINDEX_LINKAGE CXString
-clang_Cursor_getBinaryOpcodeStr(enum CX_BinaryOperatorKind Op);
-
 /**
  * Returns the storage class for a function or variable declaration.
  *
@@ -6671,73 +6618,74 @@ CINDEX_LINKAGE unsigned clang_visitCXXMethods(CXType T, 
CXFieldVisitor visitor,
  */
 enum CXBinaryOperatorKind {
   /** This value describes cursors which are not binary operators. */
-  CXBinaryOperator_Invalid,
+  CXBinaryOperator_Invalid = 0,
   /** C++ Pointer - to - member operator. */
-  CXBinaryOperator_PtrMemD,
+  CXBinaryOperator_PtrMemD = 1,
   /** C++ Pointer - to - member operator. */
-  CXBinaryOperator_PtrMemI,
+  CXBinaryOperator_PtrMemI = 2,
   /** Multiplication operator. */
-  CXBinaryOperator_Mul,
+  CXBinaryOperator_Mul = 3,
   /** Division operator. */
-  CXBinaryOperator_Div,
+  CXBinaryOperator_Div = 4,
   /** Remainder operator. */
-  CXBinaryOperator_Rem,
+  CXBinaryOperator_Rem = 5,
   /** Addition operator. */
-  CXBinaryOperator_Add,
+  CXBinaryOperator_Add = 6,
   /** Subtraction operator. */
-  CXBinaryOperator_Sub,
+  CXBinaryOperator_Sub = 7,
   /** Bitwise shift left operator. */
-  CXBinaryOperator_Shl,
+  CXBinaryOperator_Shl = 8,
   /** Bitwise shift right operator. */
-  CXBinaryOperator_Shr,
+  CXBinaryOperator_Shr = 9,
   /** C++ three-way comparison (spaceship) operator. */
-  CXBinaryOperator_Cmp,
+  CXBinaryOperator_Cmp = 10,
   /** Less than operator. */
-  CXBinaryOperator_LT,
+  CXBinaryOperator_LT = 11,
   /** Greater than operator. */
-  CXBinaryOperator_GT,
+  CXBinaryOperator_GT = 12,
   /** Less or equal operator. */
-  CXBinaryOperator_LE,
+  CXBinaryOperator_LE = 13,
   /** Greater or equal operator. */
-  CXBinaryOperator_GE,
+  CXBinaryOperator_GE =

[clang] [CIR][NFC] Organize emit functions in CIRGenFunction.h (PR #133017)

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

xlauko wrote:

LGTM with minor nits

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


[clang] [llvm] cuda clang: Fix argument order for __reduce_max_sync (PR #132881)

2025-03-26 Thread Durgadoss R via cfe-commits

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

The latest changes LGTM

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


[clang] [Clang] Improve subsumption. (PR #132849)

2025-03-26 Thread via cfe-commits


@@ -2001,3 +1932,260 @@ NormalizedConstraint::getFoldExpandedConstraint() const 
{
  "getFoldExpandedConstraint called on non-fold-expanded constraint.");
   return cast(Constraint);
 }
+
+//
+//
+//  Subsumption ---
+//
+//
+
+template <> struct llvm::DenseMapInfo {
+
+  static FoldingSetNodeID getEmptyKey() {
+FoldingSetNodeID ID;
+ID.AddInteger(std::numeric_limits::max());
+return ID;
+  }
+
+  static FoldingSetNodeID getTombstoneKey() {
+FoldingSetNodeID ID;
+for (unsigned I = 0; I < sizeof(ID) / sizeof(unsigned); ++I) {
+  ID.AddInteger(std::numeric_limits::max());
+}
+return ID;
+  }
+
+  static unsigned getHashValue(const FoldingSetNodeID &Val) {
+return Val.ComputeHash();
+  }
+
+  static bool isEqual(const FoldingSetNodeID &LHS,
+  const FoldingSetNodeID &RHS) {
+return LHS == RHS;
+  }
+};
+
+SubsumptionChecker::SubsumptionChecker(Sema &SemaRef,
+   SubsumptionCallable Callable)
+: SemaRef(SemaRef), Callable(Callable), NextID(1) {}
+
+uint16_t SubsumptionChecker::getNewLiteralId() {
+  assert((unsigned(NextID) + 1 < std::numeric_limits::max()) &&
+ "too many constraints!");
+  return NextID++;
+}
+
+auto SubsumptionChecker::find(AtomicConstraint *Ori) -> Literal {
+  auto &Elems = AtomicMap[Ori->ConstraintExpr];
+  // C++ [temp.constr.order] p2
+  //   - an atomic constraint A subsumes another atomic constraint B
+  // if and only if the A and B are identical [...]
+  //
+  // C++ [temp.constr.atomic] p2
+  //   Two atomic constraints are identical if they are formed from the
+  //   same expression and the targets of the parameter mappings are
+  //   equivalent according to the rules for expressions [...]
+
+  // Because subsumption of atomic constraints is an identity
+  // relationship that does not require further analysis
+  // We cache the results such that if an atomic constraint literal
+  // subsumes another, their literal will be the same
+
+  llvm::FoldingSetNodeID ID;
+  const auto &Mapping = Ori->ParameterMapping;
+  ID.AddBoolean(Mapping.has_value());
+  if (Mapping) {
+for (unsigned I = 0, S = Mapping->size(); I < S; ++I) {
+  SemaRef.getASTContext()
+  .getCanonicalTemplateArgument((*Mapping)[I].getArgument())
+  .Profile(ID, SemaRef.getASTContext());
+}
+  }
+  auto It = Elems.find(ID);
+  if (It == Elems.end()) {
+It =
+Elems
+.insert({ID, MappedAtomicConstraint{Ori, Literal{getNewLiteralId(),
+ 
Literal::Atomic}}})
+.first;
+ReverseMap[It->second.ID.Value] = Ori;
+  }
+  return It->getSecond().ID;
+}
+
+auto SubsumptionChecker::find(FoldExpandedConstraint *Ori) -> Literal {
+  auto &Elems = FoldMap[Ori->Pattern];
+
+  FoldExpendedConstraintKey K;
+  K.Kind = Ori->Kind;
+
+  auto It = llvm::find_if(Elems, [&K](const FoldExpendedConstraintKey &Other) {
+return K.Kind == Other.Kind;
+  });
+  if (It == Elems.end()) {
+K.ID = {getNewLiteralId(), Literal::FoldExpanded};
+It = Elems.insert(Elems.end(), std::move(K));
+ReverseMap[It->ID.Value] = Ori;
+  }
+  return It->ID;
+}
+
+auto SubsumptionChecker::CNF(const NormalizedConstraint &C) -> CNFFormula {
+  return SubsumptionChecker::Normalize(C);
+}
+auto SubsumptionChecker::DNF(const NormalizedConstraint &C) -> DNFFormula {
+  return SubsumptionChecker::Normalize(C);
+}
+
+///
+/// \brief SubsumptionChecker::Normalize
+///
+/// Normalize a formula to Conjunctive Normal Form or
+/// Disjunctive normal form.
+///
+/// Each Atomic (and Fold Expanded) constraint gets represented by
+/// a single id to reduce space.
+///
+/// To minimize risks of exponential blow up, if two atomic
+/// constraints subsumes each other (same constraint and mapping),
+/// they are represented by the same literal.
+///
+template 
+FormulaType SubsumptionChecker::Normalize(const NormalizedConstraint &NC) {
+  FormulaType Res;
+
+  auto Add = [&, this](Clause C) {
+// Sort each clause and remove duplicates for faster comparisons
+std::sort(C.begin(), C.end());
+C.erase(std::unique(C.begin(), C.end()), C.end());
+AddUniqueClauseToFormula(Res, std::move(C));
+  };
+
+  if (NC.isAtomic())
+return {{find(NC.getAtomicConstraint())}};
+
+  if (NC.isFoldExpanded())
+return {{find(NC.getFoldExpandedConstraint())}};
+
+  FormulaType Left, Right;
+  SemaRef.runWithSufficientStackSpace(SourceLocation(), [&] {
+Left = Normalize(NC.getLHS());
+Right = Normalize(NC.getRHS());
+  });
+
+  if (NC.getCompoundKind() == FormulaType::Kind) {
+Res = std::move(Left);
+Res.reserve(Left.size() + Right.size());
+std::for_each(std::make_move_iterator(Right.begin()),
+  std::make_move_iterator(Right.end()), Add);
+return Res;
+  }
+
+  Res.reserve(Left.size() * Right.size());
+  for (const au

[clang] [Clang] Improve subsumption. (PR #132849)

2025-03-26 Thread via cfe-commits


@@ -2001,3 +1932,260 @@ NormalizedConstraint::getFoldExpandedConstraint() const 
{
  "getFoldExpandedConstraint called on non-fold-expanded constraint.");
   return cast(Constraint);
 }
+
+//
+//
+//  Subsumption ---
+//
+//
+
+template <> struct llvm::DenseMapInfo {
+
+  static FoldingSetNodeID getEmptyKey() {
+FoldingSetNodeID ID;
+ID.AddInteger(std::numeric_limits::max());
+return ID;
+  }
+
+  static FoldingSetNodeID getTombstoneKey() {
+FoldingSetNodeID ID;
+for (unsigned I = 0; I < sizeof(ID) / sizeof(unsigned); ++I) {
+  ID.AddInteger(std::numeric_limits::max());
+}
+return ID;
+  }
+
+  static unsigned getHashValue(const FoldingSetNodeID &Val) {
+return Val.ComputeHash();
+  }
+
+  static bool isEqual(const FoldingSetNodeID &LHS,
+  const FoldingSetNodeID &RHS) {
+return LHS == RHS;
+  }
+};
+
+SubsumptionChecker::SubsumptionChecker(Sema &SemaRef,
+   SubsumptionCallable Callable)
+: SemaRef(SemaRef), Callable(Callable), NextID(1) {}
+
+uint16_t SubsumptionChecker::getNewLiteralId() {
+  assert((unsigned(NextID) + 1 < std::numeric_limits::max()) &&
+ "too many constraints!");
+  return NextID++;
+}
+
+auto SubsumptionChecker::find(AtomicConstraint *Ori) -> Literal {
+  auto &Elems = AtomicMap[Ori->ConstraintExpr];
+  // C++ [temp.constr.order] p2
+  //   - an atomic constraint A subsumes another atomic constraint B
+  // if and only if the A and B are identical [...]
+  //
+  // C++ [temp.constr.atomic] p2
+  //   Two atomic constraints are identical if they are formed from the
+  //   same expression and the targets of the parameter mappings are
+  //   equivalent according to the rules for expressions [...]
+
+  // Because subsumption of atomic constraints is an identity
+  // relationship that does not require further analysis
+  // We cache the results such that if an atomic constraint literal
+  // subsumes another, their literal will be the same
+
+  llvm::FoldingSetNodeID ID;
+  const auto &Mapping = Ori->ParameterMapping;
+  ID.AddBoolean(Mapping.has_value());
+  if (Mapping) {
+for (unsigned I = 0, S = Mapping->size(); I < S; ++I) {
+  SemaRef.getASTContext()
+  .getCanonicalTemplateArgument((*Mapping)[I].getArgument())
+  .Profile(ID, SemaRef.getASTContext());
+}
+  }
+  auto It = Elems.find(ID);
+  if (It == Elems.end()) {
+It =
+Elems
+.insert({ID, MappedAtomicConstraint{Ori, Literal{getNewLiteralId(),
+ 
Literal::Atomic}}})
+.first;
+ReverseMap[It->second.ID.Value] = Ori;
+  }

cor3ntin wrote:

That would be quite nice indeed, but that does not exist yet!

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


[clang] [llvm] [AArch64] Add FEAT_FPAC to Neoverse V2 (PR #133054)

2025-03-26 Thread Sjoerd Meijer via cfe-commits

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


[clang] [llvm] [AArch64] Add FEAT_FPAC to Grace (PR #133054)

2025-03-26 Thread Sjoerd Meijer via cfe-commits

https://github.com/sjoerdmeijer updated 
https://github.com/llvm/llvm-project/pull/133054

>From a65f5c9b7937b21bdf43dea532e951b3ce462ec5 Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer 
Date: Wed, 26 Mar 2025 01:38:46 -0700
Subject: [PATCH] [AArch64] Add FEAT_FPAC to Neoverse V2

This feature is supported in Grace, but wasn't specified in the CPU
definition.
---
 clang/test/Driver/aarch64-mcpu-native.c| 1 +
 clang/test/Driver/print-enabled-extensions/aarch64-grace.c | 3 ++-
 .../test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c | 1 +
 llvm/lib/Target/AArch64/AArch64Processors.td   | 3 ++-
 4 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/aarch64-mcpu-native.c 
b/clang/test/Driver/aarch64-mcpu-native.c
index 2e7fc2c5adc45..a349a8e9827b8 100644
--- a/clang/test/Driver/aarch64-mcpu-native.c
+++ b/clang/test/Driver/aarch64-mcpu-native.c
@@ -22,6 +22,7 @@
 // CHECK-FEAT-NV2:FEAT_FHM   
Enable FP16 FML instructions
 // CHECK-FEAT-NV2:FEAT_FP
Enable Armv8.0-A Floating Point Extensions
 // CHECK-FEAT-NV2:FEAT_FP16  
Enable half-precision floating-point data processing
+// CHECK-FEAT-NV2:FEAT_FPAC  
Enable Armv8.3-A Pointer Authentication Faulting enhancement
 // CHECK-FEAT-NV2:FEAT_FRINTTS   
Enable FRInt[32|64][Z|X] instructions that round a floating-point number to an 
integer (in FP format) forcing it to fit into a 32- or 64-bit int
 // CHECK-FEAT-NV2:FEAT_FlagM 
Enable Armv8.4-A Flag Manipulation instructions
 // CHECK-FEAT-NV2:FEAT_FlagM2
Enable alternative NZCV format for floating point comparisons
diff --git a/clang/test/Driver/print-enabled-extensions/aarch64-grace.c 
b/clang/test/Driver/print-enabled-extensions/aarch64-grace.c
index fde6aee468cdc..739d86f1fae0f 100644
--- a/clang/test/Driver/print-enabled-extensions/aarch64-grace.c
+++ b/clang/test/Driver/print-enabled-extensions/aarch64-grace.c
@@ -21,6 +21,7 @@
 // CHECK-NEXT: FEAT_FHM   
Enable FP16 FML instructions
 // CHECK-NEXT: FEAT_FP
Enable Armv8.0-A Floating Point Extensions
 // CHECK-NEXT: FEAT_FP16  
Enable half-precision floating-point data processing
+// CHECK-NEXT: FEAT_FPAC  
Enable Armv8.3-A Pointer Authentication Faulting enhancement
 // CHECK-NEXT: FEAT_FRINTTS   
Enable FRInt[32|64][Z|X] instructions that round a floating-point number to an 
integer (in FP format) forcing it to fit into a 32- or 64-bit int
 // CHECK-NEXT: FEAT_FlagM 
Enable Armv8.4-A Flag Manipulation instructions
 // CHECK-NEXT: FEAT_FlagM2
Enable alternative NZCV format for floating point comparisons
@@ -59,4 +60,4 @@
 // CHECK-NEXT: FEAT_TRBE  
Enable Trace Buffer Extension
 // CHECK-NEXT: FEAT_TRF   
Enable Armv8.4-A Trace extension
 // CHECK-NEXT: FEAT_UAO   
Enable Armv8.2-A UAO PState
-// CHECK-NEXT: FEAT_VHE   
Enable Armv8.1-A Virtual Host extension
\ No newline at end of file
+// CHECK-NEXT: FEAT_VHE   
Enable Armv8.1-A Virtual Host extension
diff --git a/clang/test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c 
b/clang/test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c
index b11acdd34ee6d..6c2c2e3b0feb6 100644
--- a/clang/test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c
+++ b/clang/test/Driver/print-enabled-extensions/aarch64-neoverse-v2.c
@@ -20,6 +20,7 @@
 // CHECK-NEXT: FEAT_FHM   
Enable FP16 FML instructions
 // CHECK-NEXT: FEAT_FP
Enable Armv8.0-A Floating Point Extensions
 // CHECK-NEXT: FEAT_FP16  
Enable half-precision floating-point data processing
+// CHECK-NEXT: FEAT_FPAC  
Enable Armv8.3-A Pointer Authentication Faulting enhancement
 // CHECK-NEXT: FEAT_FRINTTS   
Enable FRInt[32|64][Z|X] instructions that round a floating-point number to an 
integer (in FP format) forcing it to fit into a 32- or 64-bit int
 // CHECK-NEXT: FEAT_FlagM 
Enable Armv8.4-A Flag Mani

[clang] [Clang] Improve subsumption. (PR #132849)

2025-03-26 Thread via cfe-commits


@@ -0,0 +1,194 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+namespace A {
+template 
+concept C = true;
+
+template 
+requires C && C
+void f() {}
+
+template 
+requires C && true
+void f() {}
+
+template <>
+void f();
+}
+
+namespace B {
+template 
+concept A = true;
+template 
+concept B = true;
+
+template 
+requires (A && B)
+constexpr int f() { return 0; }
+
+template 
+requires (A || B)
+constexpr int f() { return 1; }
+
+static_assert(f() == 0);
+}
+
+namespace GH122581 {
+// Test that producing a Conjunctive Normal Form
+// does not blow up exponentially.
+// i.e, this should terminate reasonably quickly
+// within a small memory footprint
+template  concept C0 = true;
+template  concept C1 = true;
+template  concept C2 = true;
+template  concept C3 = true;
+template  concept C4 = true;
+
+template 
+concept majority5 =
+(C0 && C1 && C2) ||
+(C0 && C1 && C3) ||
+(C0 && C1 && C4) ||
+(C0 && C2 && C3) ||
+(C0 && C2 && C4) ||
+(C0 && C3 && C4) ||
+(C1 && C2 && C3) ||
+(C1 && C2 && C4) ||
+(C1 && C3 && C4) ||
+(C2 && C3 && C4);
+
+template concept Y = C0 && majority5;
+template concept Z = Y && C1;
+
+constexpr int foo(majority5 auto x) { return 10; }
+constexpr int foo(Y auto y) { return 20; }
+constexpr int foo(Z auto y) { return 30; }
+static_assert(foo(0) == 30);
+}
+
+namespace WhateverThisIs {
+template  concept C0 = true;
+template  concept C1 = true;
+template  concept C2 = true;
+template  concept C3 = true;
+template  concept C4 = true;
+
+template 
+concept X =
+(C0 || C1 || C2) &&
+(C0 || C1 || C3) &&
+(C0 || C1 || C4) &&
+(C0 || C2 || C3) &&
+(C0 || C2 || C4) &&
+(C0 || C3 || C4) &&
+(C1 || C2 || C3) &&
+(C1 || C2 || C4) &&
+(C1 || C3 || C4) &&
+(C2 || C3 || C4);
+
+template concept Y = C0 && X;
+
+template concept Z = Y && C1;
+
+constexpr int foo(X auto x) { return 10; }
+constexpr int foo(Y auto y) { return 20; }
+constexpr int foo(Z auto y) { return 30; }
+
+static_assert(foo(0) == 30);
+}
+
+namespace WAT{
+template
+concept Z0 = true;
+
+template
+concept Z1 = true;
+
+template
+concept Z2 = true;
+
+template
+concept Z3 = true;
+
+template
+concept Z4 = true;
+
+template
+concept Z5 = true;
+
+template
+concept Z6 = true;
+
+template
+concept Z7 = true;
+
+template
+concept Z8 = true;
+
+template
+concept Z9 = true;
+
+template 
+concept X =

cor3ntin wrote:

I added comments / more tests / cleaned the test file

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


[clang] [Clang] Improve subsumption. (PR #132849)

2025-03-26 Thread via cfe-commits


@@ -2001,3 +1932,260 @@ NormalizedConstraint::getFoldExpandedConstraint() const 
{
  "getFoldExpandedConstraint called on non-fold-expanded constraint.");
   return cast(Constraint);
 }
+
+//
+//
+//  Subsumption ---
+//
+//
+
+template <> struct llvm::DenseMapInfo {
+
+  static FoldingSetNodeID getEmptyKey() {
+FoldingSetNodeID ID;
+ID.AddInteger(std::numeric_limits::max());
+return ID;
+  }
+
+  static FoldingSetNodeID getTombstoneKey() {
+FoldingSetNodeID ID;
+for (unsigned I = 0; I < sizeof(ID) / sizeof(unsigned); ++I) {
+  ID.AddInteger(std::numeric_limits::max());
+}
+return ID;
+  }
+
+  static unsigned getHashValue(const FoldingSetNodeID &Val) {
+return Val.ComputeHash();
+  }
+
+  static bool isEqual(const FoldingSetNodeID &LHS,
+  const FoldingSetNodeID &RHS) {
+return LHS == RHS;
+  }
+};
+
+SubsumptionChecker::SubsumptionChecker(Sema &SemaRef,
+   SubsumptionCallable Callable)
+: SemaRef(SemaRef), Callable(Callable), NextID(1) {}
+
+uint16_t SubsumptionChecker::getNewLiteralId() {
+  assert((unsigned(NextID) + 1 < std::numeric_limits::max()) &&
+ "too many constraints!");
+  return NextID++;
+}
+
+auto SubsumptionChecker::find(AtomicConstraint *Ori) -> Literal {
+  auto &Elems = AtomicMap[Ori->ConstraintExpr];
+  // C++ [temp.constr.order] p2
+  //   - an atomic constraint A subsumes another atomic constraint B
+  // if and only if the A and B are identical [...]
+  //
+  // C++ [temp.constr.atomic] p2
+  //   Two atomic constraints are identical if they are formed from the
+  //   same expression and the targets of the parameter mappings are
+  //   equivalent according to the rules for expressions [...]
+
+  // Because subsumption of atomic constraints is an identity
+  // relationship that does not require further analysis
+  // We cache the results such that if an atomic constraint literal
+  // subsumes another, their literal will be the same
+
+  llvm::FoldingSetNodeID ID;
+  const auto &Mapping = Ori->ParameterMapping;
+  ID.AddBoolean(Mapping.has_value());
+  if (Mapping) {
+for (unsigned I = 0, S = Mapping->size(); I < S; ++I) {
+  SemaRef.getASTContext()
+  .getCanonicalTemplateArgument((*Mapping)[I].getArgument())
+  .Profile(ID, SemaRef.getASTContext());
+}
+  }
+  auto It = Elems.find(ID);
+  if (It == Elems.end()) {
+It =
+Elems
+.insert({ID, MappedAtomicConstraint{Ori, Literal{getNewLiteralId(),
+ 
Literal::Atomic}}})
+.first;
+ReverseMap[It->second.ID.Value] = Ori;
+  }
+  return It->getSecond().ID;
+}
+
+auto SubsumptionChecker::find(FoldExpandedConstraint *Ori) -> Literal {
+  auto &Elems = FoldMap[Ori->Pattern];
+
+  FoldExpendedConstraintKey K;
+  K.Kind = Ori->Kind;
+
+  auto It = llvm::find_if(Elems, [&K](const FoldExpendedConstraintKey &Other) {
+return K.Kind == Other.Kind;
+  });
+  if (It == Elems.end()) {
+K.ID = {getNewLiteralId(), Literal::FoldExpanded};
+It = Elems.insert(Elems.end(), std::move(K));
+ReverseMap[It->ID.Value] = Ori;
+  }
+  return It->ID;
+}
+
+auto SubsumptionChecker::CNF(const NormalizedConstraint &C) -> CNFFormula {
+  return SubsumptionChecker::Normalize(C);
+}
+auto SubsumptionChecker::DNF(const NormalizedConstraint &C) -> DNFFormula {
+  return SubsumptionChecker::Normalize(C);
+}
+
+///
+/// \brief SubsumptionChecker::Normalize
+///
+/// Normalize a formula to Conjunctive Normal Form or
+/// Disjunctive normal form.
+///
+/// Each Atomic (and Fold Expanded) constraint gets represented by
+/// a single id to reduce space.
+///
+/// To minimize risks of exponential blow up, if two atomic
+/// constraints subsumes each other (same constraint and mapping),
+/// they are represented by the same literal.
+///
+template 
+FormulaType SubsumptionChecker::Normalize(const NormalizedConstraint &NC) {
+  FormulaType Res;
+
+  auto Add = [&, this](Clause C) {
+// Sort each clause and remove duplicates for faster comparisons
+std::sort(C.begin(), C.end());
+C.erase(std::unique(C.begin(), C.end()), C.end());
+AddUniqueClauseToFormula(Res, std::move(C));
+  };
+
+  if (NC.isAtomic())
+return {{find(NC.getAtomicConstraint())}};
+
+  if (NC.isFoldExpanded())
+return {{find(NC.getFoldExpandedConstraint())}};
+
+  FormulaType Left, Right;
+  SemaRef.runWithSufficientStackSpace(SourceLocation(), [&] {
+Left = Normalize(NC.getLHS());
+Right = Normalize(NC.getRHS());
+  });
+
+  if (NC.getCompoundKind() == FormulaType::Kind) {
+Res = std::move(Left);
+Res.reserve(Left.size() + Right.size());
+std::for_each(std::make_move_iterator(Right.begin()),
+  std::make_move_iterator(Right.end()), Add);
+return Res;
+  }
+
+  Res.reserve(Left.size() * Right.size());
+  for (const au

  1   2   3   4   5   6   >