[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-25 Thread via cfe-commits

https://github.com/mydeveloperday requested changes to this pull request.

Please fix the spellings

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


[libclc] d46a699 - [libclc] Move asin/acos/atan to the CLC library (#132788)

2025-03-25 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-03-25T09:11:32Z
New Revision: d46a699953210093de55baa8b3be56dae5707082

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

LOG: [libclc] Move asin/acos/atan to the CLC library (#132788)

This commit simultaneously moves these three functions to the CLC
library and optimizing them for vector types by avoiding scalarization.

Added: 
libclc/clc/include/clc/math/clc_acos.h
libclc/clc/include/clc/math/clc_asin.h
libclc/clc/include/clc/math/clc_atan.h
libclc/clc/lib/generic/math/clc_acos.cl
libclc/clc/lib/generic/math/clc_acos.inc
libclc/clc/lib/generic/math/clc_asin.cl
libclc/clc/lib/generic/math/clc_asin.inc
libclc/clc/lib/generic/math/clc_atan.cl
libclc/clc/lib/generic/math/clc_atan.inc

Modified: 
libclc/clc/lib/generic/SOURCES
libclc/generic/lib/math/acos.cl
libclc/generic/lib/math/asin.cl
libclc/generic/lib/math/atan.cl

Removed: 




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

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

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

diff  --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index 490ce5c364465..1001287b3f483 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -17,6 +17,9 @@ integer/clc_rhadd.cl
 integer/clc_rotate.cl
 integer/clc_sub_sat.cl
 integer/clc_upsample.cl
+math/clc_acos.cl
+math/clc_asin.cl
+math/clc_atan.cl
 math/clc_ceil.cl
 math/clc_copysign.cl
 math/clc_fabs.cl

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

diff  --git a/libclc/clc/lib/generic/math/clc_acos.inc 
b/libclc/clc/lib/generic/math/clc_acos.inc
new file mode 100644
index 0..e036a998a65bd
--- /dev/null
+++ b/libclc/clc/lib/generic/math/clc

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

2025-03-25 Thread Nikolas Klauser 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
-

philnik777 wrote:

FWIW we list all the LWG papers and issues in the libc++ docs, and IMO it's 
useful. That makes it clear whether we've considered the paper/issue and what 
our conclusion was. Since most papers by far require changes, it's also really 
not cluttering the list too much.

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] [Clang] Improve subsumption. (PR #132849)

2025-03-25 Thread via cfe-commits


@@ -2001,3 +1932,318 @@ 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, DNFFormula::Kind);
+}
+auto SubsumptionChecker::DNF(const NormalizedConstraint &C) -> DNFFormula {
+  return SubsumptionChecker::Normalize(C, DNFFormula::Kind);
+}
+
+///
+/// \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.
+///
+/// Redundant clauses (ie clauses that are fully subsumed) by other
+/// clauses in the same formula are removed.
+template 
+FormulaType SubsumptionChecker::Normalize(
+const NormalizedConstraint &NC,
+NormalizedConstraint::CompoundConstraintKind ParentKind) {
+  FormulaType Res;
+
+  bool ParentWillDoCrossProduct = ParentKind != FormulaType::Kind;
+
+  auto Add = [&, this](Clause C, bool RemoveRedundantClause) {
+// Sort each clause and remove duplicates for faster comparision
+// Both AddClauseToFormula and IsSuperSet require sorted, uniqued literals.
+std::sort(C.begin(), C.end());
+C.erase(std::unique(C.begin(), C.end()), C.end());
+
+// Because the caller may produce the cross product of the clauses
+// we need to be careful not to remove clauses that could be
+// combined by the parent.
+if (!ParentWillDoCrossProduct && RemoveRedundantClause)
+  AddNonRedundantClauseToFormula(Res, std::move(C));
+else
+  AddUniqueClau

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

2025-03-25 Thread via cfe-commits

https://github.com/Sirraide edited 
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-tools-extra] Reland: [clang] NFC: Clear some uses of MemberPointerType::getClass (PR #132317)

2025-03-25 Thread Mike Hommey via cfe-commits

glandium wrote:

This causes crashes:
```
1.  
/builds/worker/checkouts/gecko/dom/media/webrtc/MediaEngineWebRTC.cpp:48:44: 
current parser token ')'
2.  
/builds/worker/checkouts/gecko/dom/media/webrtc/MediaEngineWebRTC.cpp:31:1: 
parsing namespace 'mozilla'
3.  
/builds/worker/checkouts/gecko/dom/media/webrtc/MediaEngineWebRTC.cpp:42:40: 
parsing function body 'mozilla::MediaEngineWebRTC::MediaEngineWebRTC'
4.  
/builds/worker/checkouts/gecko/dom/media/webrtc/MediaEngineWebRTC.cpp:42:40: in 
compound statement ('{}')
 #0 0x7f1beb652d08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/tmp/llvm/obj-broken/bin/../lib/libLLVM.so.21.0git+0xe96d08)
 #1 0x7f1beb65075e llvm::sys::RunSignalHandlers() 
(/tmp/llvm/obj-broken/bin/../lib/libLLVM.so.21.0git+0xe9475e)
 #2 0x7f1beb6533b1 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x7f1bea25b050 (/lib/x86_64-linux-gnu/libc.so.6+0x3c050)
 #4 0x7f1bf5e57e31 addAssociatedClassesAndNamespaces((anonymous 
namespace)::AssociatedLookup&, clang::CXXRecordDecl*) SemaLookup.cpp:0:0
 #5 0x7f1bf5e45f6a addAssociatedClassesAndNamespaces((anonymous 
namespace)::AssociatedLookup&, clang::QualType) SemaLookup.cpp:0:0
 #6 0x7f1bf5e45c81 
clang::Sema::FindAssociatedClassesAndNamespaces(clang::SourceLocation, 
llvm::ArrayRef, llvm::SmallSetVector&, 
llvm::SmallSetVector&) 
(/tmp/llvm/obj-broken/bin/../lib/libclang-cpp.so.21.0git+0x1ad3c81)
```
I'm running cvise to reduce the source code that leads to this.

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] 822aa5e - [clang][bytecode][NFC] use Field::isUnnamedBitField() directly (#132914)

2025-03-25 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-25T12:32:27+01:00
New Revision: 822aa5ec1afee68fb16457ff06de9111c1b62450

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

LOG: [clang][bytecode][NFC] use Field::isUnnamedBitField() directly (#132914)

Instead of going though Decl.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 5242a524308a8..f2e98218f373b 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1818,7 +1818,7 @@ bool Compiler::visitInitList(ArrayRef Inits,
 for (const Expr *Init : Inits) {
   // Skip unnamed bitfields.
   while (InitIndex < R->getNumFields() &&
- R->getField(InitIndex)->Decl->isUnnamedBitField())
+ R->getField(InitIndex)->isUnnamedBitField())
 ++InitIndex;
 
   if (std::optional T = classify(Init)) {
@@ -4084,7 +4084,7 @@ bool Compiler::visitZeroRecordInitializer(const 
Record *R,
   assert(R);
   // Fields
   for (const Record::Field &Field : R->fields()) {
-if (Field.Decl->isUnnamedBitField())
+if (Field.isUnnamedBitField())
   continue;
 
 const Descriptor *D = Field.Desc;



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


[libclc] [libclc] Move asinpi/acospi/atanpi to the CLC library (PR #132918)

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

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/132918

Similar to d46a6999, this commit simultaneously moves these three functions to 
the CLC library and optimizes them for vector types by avoiding scalarization.

>From 1fb1a82f1dff423d96e803889e831e8aced1aba1 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Tue, 25 Mar 2025 10:50:53 +
Subject: [PATCH] [libclc] Move asinpi/acospi/atanpi to the CLC library

Similar to d46a6999, this commit simultaneously moves these three
functions to the CLC library and optimizes them for vector types by
avoiding scalarization.
---
 libclc/clc/include/clc/math/clc_acospi.h   |  20 +++
 libclc/clc/include/clc/math/clc_asinpi.h   |  20 +++
 libclc/clc/include/clc/math/clc_atanpi.h   |  20 +++
 libclc/clc/lib/generic/SOURCES |   3 +
 libclc/clc/lib/generic/math/clc_acospi.cl  |  19 +++
 libclc/clc/lib/generic/math/clc_acospi.inc | 156 +++
 libclc/clc/lib/generic/math/clc_asinpi.cl  |  19 +++
 libclc/clc/lib/generic/math/clc_asinpi.inc | 156 +++
 libclc/clc/lib/generic/math/clc_atanpi.cl  |  19 +++
 libclc/clc/lib/generic/math/clc_atanpi.inc | 172 +
 libclc/generic/lib/math/acospi.cl  | 158 +--
 libclc/generic/lib/math/asinpi.cl  | 149 +-
 libclc/generic/lib/math/atanpi.cl  | 169 +---
 13 files changed, 616 insertions(+), 464 deletions(-)
 create mode 100644 libclc/clc/include/clc/math/clc_acospi.h
 create mode 100644 libclc/clc/include/clc/math/clc_asinpi.h
 create mode 100644 libclc/clc/include/clc/math/clc_atanpi.h
 create mode 100644 libclc/clc/lib/generic/math/clc_acospi.cl
 create mode 100644 libclc/clc/lib/generic/math/clc_acospi.inc
 create mode 100644 libclc/clc/lib/generic/math/clc_asinpi.cl
 create mode 100644 libclc/clc/lib/generic/math/clc_asinpi.inc
 create mode 100644 libclc/clc/lib/generic/math/clc_atanpi.cl
 create mode 100644 libclc/clc/lib/generic/math/clc_atanpi.inc

diff --git a/libclc/clc/include/clc/math/clc_acospi.h 
b/libclc/clc/include/clc/math/clc_acospi.h
new file mode 100644
index 0..789078d6ccd35
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_acospi.h
@@ -0,0 +1,20 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef __CLC_MATH_CLC_ACOSPI_H__
+#define __CLC_MATH_CLC_ACOSPI_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_acospi
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_ACOSPI_H__
diff --git a/libclc/clc/include/clc/math/clc_asinpi.h 
b/libclc/clc/include/clc/math/clc_asinpi.h
new file mode 100644
index 0..75b6709dd4fd3
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_asinpi.h
@@ -0,0 +1,20 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef __CLC_MATH_CLC_ASINPI_H__
+#define __CLC_MATH_CLC_ASINPI_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_asinpi
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_ASINPI_H__
diff --git a/libclc/clc/include/clc/math/clc_atanpi.h 
b/libclc/clc/include/clc/math/clc_atanpi.h
new file mode 100644
index 0..d22fd9b6c7e21
--- /dev/null
+++ b/libclc/clc/include/clc/math/clc_atanpi.h
@@ -0,0 +1,20 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef __CLC_MATH_CLC_ATANPI_H__
+#define __CLC_MATH_CLC_ATANPI_H__
+
+#define __CLC_BODY 
+#define __CLC_FUNCTION __clc_atanpi
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+
+#endif // __CLC_MATH_CLC_ATANPI_H__
diff --git a/libclc/clc/lib/generic/SOURCES b/libclc/clc/lib/generic/SOURCES
index 1001287b3f483..11069e9b0b952 100644
--- a/libclc/clc/lib/generic/SOURCES
+++ b/libclc/clc/lib/generic/SOURCES
@@ -18,8 +18,11 @@ integer/clc_rotate.cl
 integer/clc_sub_sat.cl
 integer/clc_upsample.cl
 math/clc_acos.cl
+math/clc_acospi.cl
 math/clc_asin.cl
+math/clc_asinpi.cl
 math/clc_atan.cl
+math/clc_atanpi.cl
 math/clc_ceil.cl
 math/clc_copysign.cl
 math/clc_fabs.cl
diff

[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-03-25 Thread Imad Aldij via cfe-commits

https://github.com/imdj created https://github.com/llvm/llvm-project/pull/132919

Remove `[expr.prim.req.nested]` check which restrict that local parameters in 
constraint-expressions can only appear as unevaluated operands. This change 
makes the treatment of examples like `requires` expressions and other constant 
expression contexts uniform, consistent with the adoption of P2280.

References:
- https://cplusplus.github.io/CWG/issues/2517.html
- #132825

>From 0e8e663da86c8fe7007b3967d25081d68457f75a Mon Sep 17 00:00:00 2001
From: Imad Aldij 
Date: Tue, 25 Mar 2025 13:06:19 +0200
Subject: [PATCH] [Clang] Implement CWG2517 Useless restriction on use of
 parameter in constraint-expression

Remove the restriction that local parameters in constraint-expressions can only 
appear as unevaluated operands. This change makes the treatment of examples 
like `requires` expressions and other constant expression contexts uniform, 
consistent with the adoption of P2280.
---
 clang/lib/Sema/SemaExpr.cpp| 11 ---
 clang/test/SemaCXX/constant-expression-p2280r4.cpp | 13 +
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3af6d6c23438f..fa8eeb644c179 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -396,17 +396,6 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
   targetDiag(*Locs.begin(), diag::err_thread_unsupported);
   }
 
-  if (isa(D) && isa(D->getDeclContext()) &&
-  !isUnevaluatedContext()) {
-// C++ [expr.prim.req.nested] p3
-//   A local parameter shall only appear as an unevaluated operand
-//   (Clause 8) within the constraint-expression.
-Diag(Loc, 
diag::err_requires_expr_parameter_referenced_in_evaluated_context)
-<< D;
-Diag(D->getLocation(), diag::note_entity_declared_at) << D;
-return true;
-  }
-
   return false;
 }
 
diff --git a/clang/test/SemaCXX/constant-expression-p2280r4.cpp 
b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
index f22430a0e88a2..9baedd9c6c263 100644
--- a/clang/test/SemaCXX/constant-expression-p2280r4.cpp
+++ b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
@@ -155,6 +155,19 @@ int g() {
 }
 }
 
+namespace GH132825 {
+template concept LargeArray =
+requires (ArrayType my_array) { requires my_array.size() > 5; };
+
+struct Big {
+  constexpr int size() const { return 100; }
+};
+
+void g() {
+  static_assert(LargeArray);
+}
+}
+
 namespace GH128409 {
   int &ff();
   int &x = ff(); // nointerpreter-note {{declared here}}

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


[clang] [flang] [llvm] [Clang][AMDGPU] Expose buffer load lds as a clang builtin (PR #132048)

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


@@ -162,6 +162,8 @@ BUILTIN(__builtin_amdgcn_raw_buffer_load_b64, "V2UiQbiiIi", 
"n")
 BUILTIN(__builtin_amdgcn_raw_buffer_load_b96, "V3UiQbiiIi", "n")
 BUILTIN(__builtin_amdgcn_raw_buffer_load_b128, "V4UiQbiiIi", "n")
 
+TARGET_BUILTIN(__builtin_amdgcn_raw_ptr_buffer_load_lds, "vQbv*3IUiiiIiIi", 
"t", "lds-buffer-load-insts")

jmmartinez wrote:

Before gfx950: 1, 2, or 4.
On gfx950: 12 and 16 are also supported.

The main advantage of taking the size is that it matches the 
`__builtin_amdgcn_global_load_lds` and the LLVM IR intrinsic (I assume we can 
update the later more freely than clang's builtin signatures).

IMHO, having one version per size would have been better.

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


[clang] [clang] Allow parentheses around CTAD declarators (PR #132829)

2025-03-25 Thread via cfe-commits

https://github.com/Sirraide commented:

So the implementation of this seems fine, but looking at how other compilers 
handle this, GCC and MSVC accept this, whereas EDG rejects. I agree w/ the 
comment that that is a bit silly to reject this, but can you check what the 
standard has to say about this? If this is disallowed by the standard, we might 
want to issue an extension warning (disabled by default) here.

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-03-25 Thread Imad Aldij via cfe-commits

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


[clang] [clang][bytecode][NFC] use Field::isUnnamedBitField() directly (PR #132914)

2025-03-25 Thread Timm Baeder via cfe-commits

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


[clang] [clang] Allow parentheses around CTAD declarators (PR #132829)

2025-03-25 Thread via cfe-commits

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

Actually, I just checked #39811, and apparently this was a CWG that has been 
resolved, so in that case this seems fine.

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-03-25 Thread Imad Aldij via cfe-commits

https://github.com/imdj updated https://github.com/llvm/llvm-project/pull/132919

>From 8ed77e7bb4d26ad5b2f87d65c77e3faa4539502c Mon Sep 17 00:00:00 2001
From: Imad Aldij 
Date: Tue, 25 Mar 2025 13:54:49 +0200
Subject: [PATCH] Remove the restriction that local parameters in
 constraint-expressions can only appear as unevaluated operands

---
 clang/lib/Sema/SemaExpr.cpp   | 11 ---
 .../expr.prim/expr.prim.req/nested-requirement.cpp|  7 ---
 2 files changed, 18 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3af6d6c23438f..fa8eeb644c179 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -396,17 +396,6 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
   targetDiag(*Locs.begin(), diag::err_thread_unsupported);
   }
 
-  if (isa(D) && isa(D->getDeclContext()) &&
-  !isUnevaluatedContext()) {
-// C++ [expr.prim.req.nested] p3
-//   A local parameter shall only appear as an unevaluated operand
-//   (Clause 8) within the constraint-expression.
-Diag(Loc, 
diag::err_requires_expr_parameter_referenced_in_evaluated_context)
-<< D;
-Diag(D->getLocation(), diag::note_entity_declared_at) << D;
-return true;
-  }
-
   return false;
 }
 
diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
index 763d983d20f61..eaef4441c10f8 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
@@ -37,13 +37,6 @@ namespace std_example {
   static_assert(D);
   template struct D_check {}; // expected-note{{because 'short' does not 
satisfy 'D'}}
   using dc1 = D_check; // expected-error{{constraints not satisfied for 
class template 'D_check' [with T = short]}}
-
-  template
-  concept C2 = requires (T a) {
-  requires sizeof(a) == 4; // OK
-  requires a == 0; // expected-note{{because 'a == 0' would be invalid: 
constraint variable 'a' cannot be used in an evaluated context}}
-};
-  static_assert(C2); // expected-note{{because 'int' does not satisfy 
'C2'}} expected-error{{static assertion failed}}
 }
 
 template

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


[clang] [clang] Allow parentheses around CTAD declarators (PR #132829)

2025-03-25 Thread via cfe-commits

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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-03-25 Thread Imad Aldij via cfe-commits


@@ -155,6 +155,19 @@ int g() {
 }
 }
 
+namespace GH132825 {

imdj wrote:

Thank you for the feedback. Will do.

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


[clang] [clang] ``noconvergent`` does not affect calls to convergent functions (PR #132701)

2025-03-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sameer Sahasrabuddhe (ssahasra)


Changes

When placed on a function, the ``clang::noconvergent`` attribute ensures that 
the function is not assumed to be convergent. But the same attribute has no 
effect on function calls. A call is convergent if the callee is convergent. 
This is based on the fact that in LLVM, a call always inherits all the 
attributes of the callee. Only ``convergent`` is an attribute in LLVM IR, and 
there is no equivalent of ``clang::noconvergent``.

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


1 Files Affected:

- (modified) clang/include/clang/Basic/AttrDocs.td (+10-10) 


``diff
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a8b588169725a..98d29838dce42 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1658,17 +1658,16 @@ Sample usage:
 def NoConvergentDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
-This attribute prevents a function from being treated as convergent, which
-means that optimizations can only move calls to that function to
-control-equivalent blocks. If a statement is marked as ``noconvergent`` and
-contains calls, it also prevents those calls from being treated as convergent.
-In other words, those calls are not restricted to only being moved to
-control-equivalent blocks.
+This attribute prevents a function from being treated as convergent; when a
+function is marked ``noconvergent``, calls to that function are not
+automatically assumed to be convergent, unless such calls are explicitly marked
+as ``convergent``. If a statement is marked as ``noconvergent``, any calls to
+inline ``asm`` in that statement are no longer treated as convergent.
 
 In languages following SPMD/SIMT programming model, e.g., CUDA/HIP, function
-declarations and calls are treated as convergent by default for correctness.
-This ``noconvergent`` attribute is helpful for developers to prevent them from
-being treated as convergent when it's safe.
+declarations and inline asm calls are treated as convergent by default for
+correctness. This ``noconvergent`` attribute is helpful for developers to
+prevent them from being treated as convergent when it's safe.
 
 .. code-block:: c
 
@@ -1677,7 +1676,8 @@ being treated as convergent when it's safe.
 
   __device__ int example(void) {
 float x;
-[[clang::noconvergent]] x = bar(x);
+[[clang::noconvergent]] x = bar(x); // no effect on convergence
+[[clang::noconvergent]] { asm volatile ("nop"); } // the asm call is 
non-convergent
   }
 
   }];

``




https://github.com/llvm/llvm-project/pull/132701
___
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-25 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 1/4] [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 normal 

[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-03-25 Thread Younan Zhang via cfe-commits


@@ -155,6 +155,19 @@ int g() {
 }
 }
 
+namespace GH132825 {

zyn0217 wrote:

This should go in cwg25xx.cpp, and you should run make_cxx_dr_status to update 
the status page.

Also this needs a release note.


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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-03-25 Thread Younan Zhang via cfe-commits

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


[clang] [clang][analyzer] Correctly handle structured bindings captured by lambda (PR #132579)

2025-03-25 Thread via cfe-commits


@@ -0,0 +1,127 @@
+// RUN: %clang_analyze_cc1 -std=c++20 
-analyzer-checker=core,debug.ExprInspection -analyzer-config 
inline-lambdas=true -verify %s
+
+#include "Inputs/system-header-simulator-cxx.h"
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(int);
+
+void capture_structured_binding_to_array_byref() {
+  int arr[] {5};
+  auto& [i] = arr;
+  [i]() mutable {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+++i;
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+i++;
+  }();
+  clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
+}
+
+void capture_structured_binding_to_array_byvalue() {
+  int arr[] {5};
+  auto [i] = arr;
+  [i]() mutable {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+++i;
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+i++;
+  }();
+  clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
+}
+
+void capture_structured_binding_to_tuple_like_byref() {
+  std::pair p {5, 6};
+  auto& [i, _] = p;
+  [i]() mutable {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+++i;
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+i++;
+  }();
+  clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
+}
+
+void capture_structured_binding_to_tuple_like_byvalue() {
+  std::pair p {5, 6};
+  auto [i, _] = p;
+  [i]() mutable {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+++i;
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+i++;
+  }();
+  clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
+}
+
+struct S { int x; };
+
+void capture_structured_binding_to_data_member_byref() {
+  S s{5};
+  auto& [i] = s;
+  [i]() mutable {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+++i;
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+i++;
+  }();
+  clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
+}
+
+void capture_structured_binding_to_data_member_byvalue() {
+  S s{5};
+  auto [i] = s;
+  [i]() mutable {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+++i;
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+  }();
+  [&i] {
+if (i != 5)
+  clang_analyzer_warnIfReached();
+i++;
+  }();
+  clang_analyzer_eval(i == 6); // expected-warning{{TRUE}}
+}

flovent wrote:

Added in new commit

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


[clang] [clang] Allow parentheses around CTAD declarators (PR #132829)

2025-03-25 Thread via cfe-commits

Sirraide wrote:

CC @Endilll Should this also add a test to 
[cwg23xx.cpp](https://github.com/llvm/llvm-project/blob/main/clang/test/CXX/drs/cwg23xx.cpp)?



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


[clang] [clang] Fix static_cast bypassing access control (PR #132285)

2025-03-25 Thread via cfe-commits

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


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


[clang] [Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (PR #132919)

2025-03-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Imad Aldij (imdj)


Changes

Remove `[expr.prim.req.nested]` check which restrict that local parameters in 
constraint-expressions can only appear as unevaluated operands. This change 
makes the treatment of examples like `requires` expressions and other constant 
expression contexts uniform, consistent with the adoption of P2280.

References:
- https://cplusplus.github.io/CWG/issues/2517.html
- #132825

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaExpr.cpp (-11) 
- (modified) clang/test/SemaCXX/constant-expression-p2280r4.cpp (+13) 


``diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3af6d6c23438f..fa8eeb644c179 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -396,17 +396,6 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, 
ArrayRef Locs,
   targetDiag(*Locs.begin(), diag::err_thread_unsupported);
   }
 
-  if (isa(D) && isa(D->getDeclContext()) &&
-  !isUnevaluatedContext()) {
-// C++ [expr.prim.req.nested] p3
-//   A local parameter shall only appear as an unevaluated operand
-//   (Clause 8) within the constraint-expression.
-Diag(Loc, 
diag::err_requires_expr_parameter_referenced_in_evaluated_context)
-<< D;
-Diag(D->getLocation(), diag::note_entity_declared_at) << D;
-return true;
-  }
-
   return false;
 }
 
diff --git a/clang/test/SemaCXX/constant-expression-p2280r4.cpp 
b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
index f22430a0e88a2..9baedd9c6c263 100644
--- a/clang/test/SemaCXX/constant-expression-p2280r4.cpp
+++ b/clang/test/SemaCXX/constant-expression-p2280r4.cpp
@@ -155,6 +155,19 @@ int g() {
 }
 }
 
+namespace GH132825 {
+template concept LargeArray =
+requires (ArrayType my_array) { requires my_array.size() > 5; };
+
+struct Big {
+  constexpr int size() const { return 100; }
+};
+
+void g() {
+  static_assert(LargeArray);
+}
+}
+
 namespace GH128409 {
   int &ff();
   int &x = ff(); // nointerpreter-note {{declared here}}

``




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


[clang] [clang][analyzer] Correctly handle structured bindings captured by lambda (PR #132579)

2025-03-25 Thread via cfe-commits

https://github.com/flovent updated 
https://github.com/llvm/llvm-project/pull/132579

>From cbd1ab21502db7fec5aa017031ad6ac8eb1edb7c Mon Sep 17 00:00:00 2001
From: flovent 
Date: Sun, 23 Mar 2025 10:32:12 +0800
Subject: [PATCH 1/2] [clang][analyzer] Correctly handle structured bindings
 captured by lambda

---
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |  45 +--
 clang/test/Analysis/issue-91835.cpp   |  15 +++
 .../lambda-capture-structured-binding.cpp | 127 ++
 3 files changed, 175 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/Analysis/issue-91835.cpp
 create mode 100644 clang/test/Analysis/lambda-capture-structured-binding.cpp

diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 318fa3c1caf06..07540af50a288 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3120,16 +3120,10 @@ void ExprEngine::VisitCommonDeclRefExpr(const Expr *Ex, 
const NamedDecl *D,
   ProgramStateRef state = Pred->getState();
   const LocationContext *LCtx = Pred->getLocationContext();
 
-  if (const auto *VD = dyn_cast(D)) {
-// C permits "extern void v", and if you cast the address to a valid type,
-// you can even do things with it. We simply pretend
-assert(Ex->isGLValue() || VD->getType()->isVoidType());
-const LocationContext *LocCtxt = Pred->getLocationContext();
-const Decl *D = LocCtxt->getDecl();
-const auto *MD = dyn_cast_or_null(D);
+  auto resolveAsLambdaCapturedVar =
+  [&](const ValueDecl *VD) -> std::optional> {
+const auto *MD = dyn_cast(LCtx->getDecl());
 const auto *DeclRefEx = dyn_cast(Ex);
-std::optional> VInfo;
-
 if (AMgr.options.ShouldInlineLambdas && DeclRefEx &&
 DeclRefEx->refersToEnclosingVariableOrCapture() && MD &&
 MD->getParent()->isLambda()) {
@@ -3142,13 +3136,23 @@ void ExprEngine::VisitCommonDeclRefExpr(const Expr *Ex, 
const NamedDecl *D,
   // Sema follows a sequence of complex rules to determine whether the
   // variable should be captured.
   if (const FieldDecl *FD = LambdaCaptureFields[VD]) {
-Loc CXXThis =
-svalBuilder.getCXXThis(MD, LocCtxt->getStackFrame());
+Loc CXXThis = svalBuilder.getCXXThis(MD, LCtx->getStackFrame());
 SVal CXXThisVal = state->getSVal(CXXThis);
-VInfo = std::make_pair(state->getLValue(FD, CXXThisVal), 
FD->getType());
+return std::make_pair(state->getLValue(FD, CXXThisVal), FD->getType());
   }
 }
 
+return std::nullopt;
+  };
+
+  if (const auto *VD = dyn_cast(D)) {
+// C permits "extern void v", and if you cast the address to a valid type,
+// you can even do things with it. We simply pretend
+assert(Ex->isGLValue() || VD->getType()->isVoidType());
+const LocationContext *LocCtxt = Pred->getLocationContext();
+std::optional> VInfo =
+resolveAsLambdaCapturedVar(VD);
+
 if (!VInfo)
   VInfo = std::make_pair(state->getLValue(VD, LocCtxt), VD->getType());
 
@@ -3186,6 +3190,23 @@ void ExprEngine::VisitCommonDeclRefExpr(const Expr *Ex, 
const NamedDecl *D,
 return;
   }
   if (const auto *BD = dyn_cast(D)) {
+// Handle structured bindings captured by lambda.
+if (std::optional> VInfo =
+resolveAsLambdaCapturedVar(BD)) {
+  auto [V, T] = VInfo.value();
+
+  if (T->isReferenceType()) {
+if (const MemRegion *R = V.getAsRegion())
+  V = state->getSVal(R);
+else
+  V = UnknownVal();
+  }
+
+  Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V), nullptr,
+ProgramPoint::PostLValueKind);
+  return;
+}
+
 const auto *DD = cast(BD->getDecomposedDecl());
 
 SVal Base = state->getLValue(DD, LCtx);
diff --git a/clang/test/Analysis/issue-91835.cpp 
b/clang/test/Analysis/issue-91835.cpp
new file mode 100644
index 0..fb136ebb6f437
--- /dev/null
+++ b/clang/test/Analysis/issue-91835.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -std=c++20 %s 
-analyzer-checker=core.NullDereference -analyzer-output=text -verify
+
+// expected-no-diagnostics
+
+struct S { int x; };
+
+void f(int x) { (void)x; }
+
+int main()
+{
+S s{42};
+auto& [x] = s;
+auto g = [x](){ f(x); }; // no warning
+g();
+}
\ No newline at end of file
diff --git a/clang/test/Analysis/lambda-capture-structured-binding.cpp 
b/clang/test/Analysis/lambda-capture-structured-binding.cpp
new file mode 100644
index 0..22ca3ee791da7
--- /dev/null
+++ b/clang/test/Analysis/lambda-capture-structured-binding.cpp
@@ -0,0 +1,127 @@
+// RUN: %clang_analyze_cc1 -std=c++20 
-analyzer-checker=core,debug.ExprInspection -analyzer-config 
inline-lambdas=true -verify %s
+
+#include "Inputs/system-header-simulator-cxx.h"
+void clang_analyzer_warnIfReached();
+void clang_analyzer_eval(int);
+
+void capture_structured_binding_to_array_byref() {
+  int arr

[clang] [clang][analyzer] Correctly handle structured bindings captured by lambda (PR #132579)

2025-03-25 Thread via cfe-commits


@@ -0,0 +1,15 @@
+// RUN: %clang_analyze_cc1 -std=c++20 %s 
-analyzer-checker=core.NullDereference -analyzer-output=text -verify
+
+// expected-no-diagnostics
+
+struct S { int x; };
+
+void f(int x) { (void)x; }
+
+int main()
+{
+S s{42};
+auto& [x] = s;
+auto g = [x](){ f(x); }; // no warning
+g();
+}

flovent wrote:

Added in new commit

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

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff c1ed4f642396c1bbea2cc0cd6d2e46ff674145a4 
89d4851dc81ed27706e1c7fd7522c4d5fd4c1074 --extensions h,cpp -- 
clang/test/SemaCXX/concepts-subsumption.cpp 
clang/include/clang/Sema/SemaConcept.h clang/lib/Sema/SemaConcept.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 696fc4b97a..9e61773ea5 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -230,9 +230,8 @@ private:
   DNFFormula DNF(const NormalizedConstraint &C);
 
   template 
-  FormulaType
-  Normalize(const NormalizedConstraint &C,
-bool ParentWillDoCrossProduct);
+  FormulaType Normalize(const NormalizedConstraint &C,
+bool ParentWillDoCrossProduct);
   void AddNonRedundantClauseToFormula(Formula &F, Clause C);
   void AddUniqueClauseToFormula(Formula &F, Clause C);
   bool IsSuperSet(const Clause &A, const Clause &B);
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 5497415680..6acb950d03 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -2031,10 +2031,12 @@ auto SubsumptionChecker::find(FoldExpandedConstraint 
*Ori) -> Literal {
 }
 
 auto SubsumptionChecker::CNF(const NormalizedConstraint &C) -> CNFFormula {
-  return SubsumptionChecker::Normalize(C, 
/*ParentWillDoCrossProduct=*/false);
+  return SubsumptionChecker::Normalize(
+  C, /*ParentWillDoCrossProduct=*/false);
 }
 auto SubsumptionChecker::DNF(const NormalizedConstraint &C) -> DNFFormula {
-  return SubsumptionChecker::Normalize(C, 
/*ParentWillDoCrossProduct=*/false);
+  return SubsumptionChecker::Normalize(
+  C, /*ParentWillDoCrossProduct=*/false);
 }
 
 ///
@@ -2080,8 +2082,12 @@ FormulaType SubsumptionChecker::Normalize(const 
NormalizedConstraint &NC,
 
   FormulaType Left, Right;
   SemaRef.runWithSufficientStackSpace(SourceLocation(), [&] {
-Left  = Normalize(NC.getLHS(), ParentWillDoCrossProduct || 
NC.getCompoundKind() != FormulaType::Kind);
-Right = Normalize(NC.getRHS(), ParentWillDoCrossProduct || 
NC.getCompoundKind() != FormulaType::Kind);
+Left = Normalize(NC.getLHS(), ParentWillDoCrossProduct ||
+   NC.getCompoundKind() !=
+   FormulaType::Kind);
+Right = Normalize(NC.getRHS(), ParentWillDoCrossProduct ||
+NC.getCompoundKind() !=
+FormulaType::Kind);
   });
 
   if (NC.getCompoundKind() == FormulaType::Kind) {

``




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] [flang] [flang] Add -f[no-]slp-vectorize flags (PR #132801)

2025-03-25 Thread Kajetan Puchalski via cfe-commits

https://github.com/mrkajetanp updated 
https://github.com/llvm/llvm-project/pull/132801

>From d9b2a86d01688b69b8f116f6b52caeec8cd6e756 Mon Sep 17 00:00:00 2001
From: Kajetan Puchalski 
Date: Mon, 24 Mar 2025 17:28:03 +
Subject: [PATCH 1/2] [flang] Add -f[no-]slp-vectorize flags

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

Signed-off-by: Kajetan Puchalski 
---
 clang/include/clang/Driver/Options.td   |  9 ++---
 clang/lib/Driver/ToolChains/Flang.cpp   |  8 
 flang/include/flang/Frontend/CodeGenOptions.def |  1 +
 flang/lib/Frontend/CompilerInvocation.cpp   |  3 +++
 flang/lib/Frontend/FrontendActions.cpp  |  1 +
 flang/test/Driver/slp-vectorize.f90 | 10 ++
 6 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Driver/slp-vectorize.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 59a57c83c6b89..a2cdf9f26fcdf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4032,11 +4032,14 @@ def : Flag<["-"], "ftree-vectorize">, Alias;
 def : Flag<["-"], "fno-tree-vectorize">, Alias;
 }
 
+let Visibility = [ClangOption, FlangOption] in {
 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 +7387,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 +7505,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/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 5dbc5cbe77d0a..bb89432d3e58c 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -161,6 +161,14 @@ void Flang::addCodegenOptions(const ArgList &Args,
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");
+
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
 
diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 44cb5a2cdd497..5d6af4271d4f6 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -32,6 +32,7 @@ CODEGENOPT(PrepareForThinLTO , 1, 0) ///< Set when -flto=thin 
is enabled on the
  ///< compile step.
 CODEGENOPT(StackArrays, 1, 0) ///< -fstack-arrays (enable the stack-arrays 
pass)
 CODEGENOPT(VectorizeLoop, 1, 0) ///< Enable loop vectorization.
+CODEGENOPT(VectorizeSLP, 1, 0) ///< Enable SLP vectorization.
 CODEGENOPT(LoopVersioning, 1, 0) ///< Enable loop versioning.
 CODEGENOPT(UnrollLoops, 1, 0) ///< Enable loop unrolling
 CODEGENOPT(AliasAnalysis, 1, 0) ///< Enable alias analysis pass
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index f433ec9966922..652b3d8795ab7 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -246,6 +246,9 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
   if (args.getLastArg(clang::driver::options::OPT_vectorize_loops))
 opts.VectorizeLoop = 1;
 
+  if (args.getLastArg(clang::driver::options::OPT_vectorize_slp))
+opts.VectorizeSLP = 1;
+
   if (args.hasFlag(clang::driver::options::OPT_floop_versioning,
clang::driver::options::OPT_fno_loop_versioning, false))
 opts.LoopVersi

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

2025-03-25 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 1/5] [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 normal 

[clang] [clang] Implement CWG2815 (PR #132778)

2025-03-25 Thread Younan Zhang via cfe-commits


@@ -12529,11 +12529,11 @@ C++ defect report implementation 
status
 Direct or copy initialization for omitted aggregate initializers
 Unknown
   
-  
+  
 https://cplusplus.github.io/CWG/issues/2117.html";>2117
-open
+NAD
 Explicit specializations and constexpr function templates
-Not resolved
+Unknown

zyn0217 wrote:

Can you leave out unrelated changes?
17912~17947 ditto

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


[clang] [clang] Implement CWG2815 (PR #132778)

2025-03-25 Thread Younan Zhang via cfe-commits

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


[clang] [clang] Implement CWG2815 (PR #132778)

2025-03-25 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 commented:

Thanks!

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


[clang] [clang] Implement CWG2815 (PR #132778)

2025-03-25 Thread Younan Zhang via cfe-commits


@@ -5242,10 +5255,12 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
 // FIXME: As a speculative fix to a defect introduced by CWG2352, we rank
 // a reference binding that performs a non-top-level qualification
 // conversion as a qualification conversion, not as an identity conversion.
-ICS.Standard.Third = (RefConv &
-  Sema::ReferenceConversions::NestedQualification)
- ? ICK_Qualification
- : ICK_Identity;
+ICS.Standard.Third =
+(RefConv & Sema::ReferenceConversions::Function)
+? ICK_Function_Conversion
+: (RefConv & Sema::ReferenceConversions::NestedQualification)
+? ICK_Qualification
+: ICK_Identity;

zyn0217 wrote:

This is getting complicated. How about
```cpp
if (RefConv & Sema::ReferenceConversions::Function)
  ICS.Standard.Third = ICK_Function_Conversion;
else if (RefConv & Sema::ReferenceConversions::NestedQualification)
  ICS.Standard.Third = ICK_Qualification;
else
  ICS.Standard.Third = ICK_Qualification

```

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


[clang] [llvm] [AArch64] Add initial support for -mcpu=olympus. (PR #132368)

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

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


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

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


@@ -1,3 +1,4 @@
 Strings
+FunctionDeclarationWithKeywordes

HazardyKnusperkeks wrote:

I think you only need to fix this one?

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


[clang] [clang-format] Fix a regression on annotating template angles (PR #132885)

2025-03-25 Thread via cfe-commits

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


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


[clang-tools-extra] [clang-tidy][C++20] Add support for aggregate types within modernize-use-emplace (PR #131969)

2025-03-25 Thread David Rivera via cfe-commits


@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s modernize-use-emplace %t -- \
+// RUN: %check_clang_tidy %s -std=c++17 modernize-use-emplace %t -- \

RiverDave wrote:

On second thought would this be sufficient for the cases shown above?:
I've noticed that `use-ranges.cpp` uses  a custom suffix bound to a standard
```cpp
// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/
// CHECK-FIXES-CPP23: #include 

```
I could implement cases with designated initializer in a separate  c++20 file.

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


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-25 Thread Eugene Shalygin via cfe-commits

zeule wrote:

> Please fix the spellings

I guess the simplest way would be to rename "FunctionDeclarationWithKeywords" 
(e.g. "KeywordedFunctionDeclaration")? Otherwise I would have to extend the 
logic in `pluralize()` inside `clang/docs/tools/dump_format_style.py`?

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


[clang] [llvm] [MIPS] Define SubTargetFeature for i6500 cpu (PR #132907)

2025-03-25 Thread Mallikarjuna Gouda via cfe-commits

https://github.com/mgoudar created 
https://github.com/llvm/llvm-project/pull/132907

PR #130587 defined same SubTargetFeature for CPUs i6400 and i6500 which 
resulted into following warning when -mcpu=i6500 was used:

+i6500' is not a recognized feature for this target (ignoring feature)

This PR fixes above issue by defining separate SubTargetFeature for i6500.

>From 752aaecc52b78a86a36d84af4ca42d166bcdc28e Mon Sep 17 00:00:00 2001
From: Mallikarjuna Gouda 
Date: Tue, 25 Mar 2025 15:18:52 +0530
Subject: [PATCH] [MIPS] Define SubTargetFeature for i6500 cpu

PR #130587 defined same SubTargetFeature for CPUs i6400 and i6500
which resulted into following warning when -mcpu=i6500 was used:

+i6500' is not a recognized feature for this target (ignoring feature)

This PR fixes above issue by defining separate SubTargetFeature for
i6500.
---
 clang/test/CodeGen/Mips/subtarget-feature-test.c | 6 ++
 llvm/lib/Target/Mips/Mips.td | 8 ++--
 llvm/lib/Target/Mips/MipsSubtarget.h | 2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/Mips/subtarget-feature-test.c

diff --git a/clang/test/CodeGen/Mips/subtarget-feature-test.c 
b/clang/test/CodeGen/Mips/subtarget-feature-test.c
new file mode 100644
index 0..d6a3f08a82de7
--- /dev/null
+++ b/clang/test/CodeGen/Mips/subtarget-feature-test.c
@@ -0,0 +1,6 @@
+// RUN: %clang --target=mips64-linux-gnu -mcpu=i6400 -o %t -c %s 2>&1 | 
FileCheck --allow-empty %s
+// CHECK-NOT: {{.*}} is not a recognized feature for this target
+
+
+// RUN: %clang --target=mips64-linux-gnu -mcpu=i6500 -o %t -c %s 2>&1 | 
FileCheck --allow-empty %s
+// CHECK-NOT: {{.*}} is not a recognized feature for this target
diff --git a/llvm/lib/Target/Mips/Mips.td b/llvm/lib/Target/Mips/Mips.td
index 9159d11fd486f..43a5ae8133d83 100644
--- a/llvm/lib/Target/Mips/Mips.td
+++ b/llvm/lib/Target/Mips/Mips.td
@@ -242,7 +242,11 @@ def ImplP5600 : SubtargetFeature<"p5600", "ProcImpl",
 // same CPU architecture.
 def ImplI6400
 : SubtargetFeature<"i6400", "ProcImpl", "MipsSubtarget::CPU::I6400",
-   "MIPS I6400/I6500 Processors", [FeatureMips64r6]>;
+   "MIPS I6400 Processor", [FeatureMips64r6]>;
+
+def ImplI6500
+: SubtargetFeature<"i6500", "ProcImpl", "MipsSubtarget::CPU::I6500",
+   "MIPS I6500 Processor", [FeatureMips64r6]>;
 
 class Proc Features>
  : ProcessorModel;
@@ -268,7 +272,7 @@ def : Proc<"octeon", [FeatureMips64r2, FeatureCnMips]>;
 def : Proc<"octeon+", [FeatureMips64r2, FeatureCnMips, FeatureCnMipsP]>;
 def : ProcessorModel<"p5600", MipsP5600Model, [ImplP5600]>;
 def : ProcessorModel<"i6400", NoSchedModel, [ImplI6400]>;
-def : ProcessorModel<"i6500", NoSchedModel, [ImplI6400]>;
+def : ProcessorModel<"i6500", NoSchedModel, [ImplI6500]>;
 
 def MipsAsmParser : AsmParser {
   let ShouldEmitMatchRegisterName = 0;
diff --git a/llvm/lib/Target/Mips/MipsSubtarget.h 
b/llvm/lib/Target/Mips/MipsSubtarget.h
index 0c75597d3decf..15127b11d5cdd 100644
--- a/llvm/lib/Target/Mips/MipsSubtarget.h
+++ b/llvm/lib/Target/Mips/MipsSubtarget.h
@@ -43,7 +43,7 @@ class MipsSubtarget : public MipsGenSubtargetInfo {
 Mips3, Mips4, Mips5, Mips64, Mips64r2, Mips64r3, Mips64r5, Mips64r6
   };
 
-  enum class CPU { P5600, I6400 };
+  enum class CPU { P5600, I6400, I6500 };
 
   // Used to avoid printing dsp warnings multiple times.
   static bool DspWarningPrinted;

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


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

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


@@ -1,3 +1,4 @@
 Strings
+FunctionDeclarationWithKeywordes

HazardyKnusperkeks wrote:

Then I'd say we change that. I mean this is the fourth entry to the file and 
apparently it does not match.

https://github.com/llvm/llvm-project/pull/131605
___
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-25 Thread Jonathan Thackray via cfe-commits

jthackray wrote:

> LGTM. Does this actually fix the build time regression from the previous 
> patch?

Apologies for the delay; I wasn't working yesterday.

Using a Graviton c8g.8xlarge instance, with a `ninja` build, I don't see a 
large build time regression. However, this is compiling in parallel, and I 
appreciate that official `llvmbot` builders may be building sequentially, which 
may see them take (wall-clock) longer (even if CPU used time is similar).

Build times are also quite compiler-dependent. GCC takes a _lot_ longer than 
clang, especially for the previously-mentioned RISC-V file 
`riscv_vector_builtin_cg.inc`, about 3.3MB in size, that gets #included.

Using clang 18 to compile a full `ninja` build after a `ninja clean` of the 
entire `llvm-project` source tree:
```
Before CGBuiltin.cpp split:
  real 351.41
  user 10275.13
  sys 471.73

After CGBuiltin.cpp split:
  real 353.28
  user 10342.80
  sys 472.39

After removing superfluous header files:
  real 353.46
  user 10337.66
  sys 474.88
```
i.e. 2 seconds longer build time.

However, with gcc 13 compiling, using `ninja` a full build of `llvm-project`, I 
see:
```
Before CGBuiltin.cpp split:
  real 631.64
  user 11160.92
  sys 685.47

After CGBuiltin.cpp split:
  real 574.28
  user 11214.63
  sys 691.98
```

If only `CGBuiltin.cpp` and `ARM.cpp` is touched/updated, I see a large 
difference (this was what prompted me to investigate originally as I was 
updating ARM intrinsics; it turns out the vast majority of the time is spent 
compiling the RISC-V code (`riscv_vector_builtin_cg.inc`, ~3.3MB in size) which 
was previously #included in `CGBuiltin.cpp`):

```
clang 18 - before CGBuiltin.cpp split:
  real 35.47
  user 39.84
  sys 3.08

clang 18 - after split:
  real 16.00
  user 30.02
  sys 3.44
```
and:
```
gcc 13 - before CGBuiltin.cpp split:
  real 397.02 (yes, it takes 5 minutes on Graviton 4 to recompile CGBuiltin.cpp)
  user 400.35
  sys 5.54

gcc 13 - after split:
  real 49.55
  user 65.88
  sys 5.29
```

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] [NFC][clang] Split clang/lib/CodeGen/CGBuiltin.cpp into target-specific files (PR #132252)

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

jthackray wrote:

@jurahul 

> I see that some of the HLSL builtin code (like `EmitHLSLBuiltinExpr`) ended 
> up in AMDGPU.cpp. Does that seem misplaced?

@jurahul Yes, apologies. Will write another PR to move it.

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


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-25 Thread Eugene Shalygin via cfe-commits


@@ -1,3 +1,4 @@
 Strings
+FunctionDeclarationWithKeywordes

zeule wrote:

Running `clang/docs/tools/dump_format_style.py` generates that entry, I guess 
because of 
[this](https://github.com/llvm/llvm-project/blob/65ad02b882ba545dafbfc195a78e204c218e93ed/clang/docs/tools/dump_format_style.py#L59)
 function.

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


[clang] [llvm] [clang][DebugInfo] Add symbol for debugger with VTable information. (PR #130255)

2025-03-25 Thread Carlos Alberto Enciso via cfe-commits

CarlosAlbertoEnciso wrote:

@clayborg Thanks very much for the extra information.

> FYI: There is already VTable support in our lldb::SBValue class and it is 
> part of the public API in LLDB and doesn't require any of this:
> 
> ```
> $ cat main.cpp
>1  #include 
>2  
>3  class Foo {
>4  public:
>5virtual ~Foo() = default;
>6virtual void Dump() {
>7  puts(__PRETTY_FUNCTION__);
>8}
>9  };
>10 
>11 int main(int argc, const char **argv) {
>12   Foo f;
>13   f.Dump();
>14   return 0;
>15 }
> ```
> 
> Then when you debug:
> 
> ```
> (lldb) script
> Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
> >>> v = lldb.frame.FindVariable('f')
> >>> v.GetVTable()
> vtable for Foo = 0x00014030 {
>   [0] = 0x00013ea4 a.out`Foo::~Foo() at main.cpp:5
>   [1] = 0x00013ef4 a.out`Foo::~Foo() at main.cpp:5
>   [2] = 0x00013e7c a.out`Foo::Dump() at main.cpp:6
> }
> ```
> 
> Doesn't require any debug info.

Just a question: Can that functionality be used before the object is 
constructed?

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


[clang] [llvm] [MIPS] Define SubTargetFeature for i6500 cpu (PR #132907)

2025-03-25 Thread Mallikarjuna Gouda via cfe-commits

https://github.com/mgoudar updated 
https://github.com/llvm/llvm-project/pull/132907

>From 752aaecc52b78a86a36d84af4ca42d166bcdc28e Mon Sep 17 00:00:00 2001
From: Mallikarjuna Gouda 
Date: Tue, 25 Mar 2025 15:18:52 +0530
Subject: [PATCH 1/2] [MIPS] Define SubTargetFeature for i6500 cpu

PR #130587 defined same SubTargetFeature for CPUs i6400 and i6500
which resulted into following warning when -mcpu=i6500 was used:

+i6500' is not a recognized feature for this target (ignoring feature)

This PR fixes above issue by defining separate SubTargetFeature for
i6500.
---
 clang/test/CodeGen/Mips/subtarget-feature-test.c | 6 ++
 llvm/lib/Target/Mips/Mips.td | 8 ++--
 llvm/lib/Target/Mips/MipsSubtarget.h | 2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/Mips/subtarget-feature-test.c

diff --git a/clang/test/CodeGen/Mips/subtarget-feature-test.c 
b/clang/test/CodeGen/Mips/subtarget-feature-test.c
new file mode 100644
index 0..d6a3f08a82de7
--- /dev/null
+++ b/clang/test/CodeGen/Mips/subtarget-feature-test.c
@@ -0,0 +1,6 @@
+// RUN: %clang --target=mips64-linux-gnu -mcpu=i6400 -o %t -c %s 2>&1 | 
FileCheck --allow-empty %s
+// CHECK-NOT: {{.*}} is not a recognized feature for this target
+
+
+// RUN: %clang --target=mips64-linux-gnu -mcpu=i6500 -o %t -c %s 2>&1 | 
FileCheck --allow-empty %s
+// CHECK-NOT: {{.*}} is not a recognized feature for this target
diff --git a/llvm/lib/Target/Mips/Mips.td b/llvm/lib/Target/Mips/Mips.td
index 9159d11fd486f..43a5ae8133d83 100644
--- a/llvm/lib/Target/Mips/Mips.td
+++ b/llvm/lib/Target/Mips/Mips.td
@@ -242,7 +242,11 @@ def ImplP5600 : SubtargetFeature<"p5600", "ProcImpl",
 // same CPU architecture.
 def ImplI6400
 : SubtargetFeature<"i6400", "ProcImpl", "MipsSubtarget::CPU::I6400",
-   "MIPS I6400/I6500 Processors", [FeatureMips64r6]>;
+   "MIPS I6400 Processor", [FeatureMips64r6]>;
+
+def ImplI6500
+: SubtargetFeature<"i6500", "ProcImpl", "MipsSubtarget::CPU::I6500",
+   "MIPS I6500 Processor", [FeatureMips64r6]>;
 
 class Proc Features>
  : ProcessorModel;
@@ -268,7 +272,7 @@ def : Proc<"octeon", [FeatureMips64r2, FeatureCnMips]>;
 def : Proc<"octeon+", [FeatureMips64r2, FeatureCnMips, FeatureCnMipsP]>;
 def : ProcessorModel<"p5600", MipsP5600Model, [ImplP5600]>;
 def : ProcessorModel<"i6400", NoSchedModel, [ImplI6400]>;
-def : ProcessorModel<"i6500", NoSchedModel, [ImplI6400]>;
+def : ProcessorModel<"i6500", NoSchedModel, [ImplI6500]>;
 
 def MipsAsmParser : AsmParser {
   let ShouldEmitMatchRegisterName = 0;
diff --git a/llvm/lib/Target/Mips/MipsSubtarget.h 
b/llvm/lib/Target/Mips/MipsSubtarget.h
index 0c75597d3decf..15127b11d5cdd 100644
--- a/llvm/lib/Target/Mips/MipsSubtarget.h
+++ b/llvm/lib/Target/Mips/MipsSubtarget.h
@@ -43,7 +43,7 @@ class MipsSubtarget : public MipsGenSubtargetInfo {
 Mips3, Mips4, Mips5, Mips64, Mips64r2, Mips64r3, Mips64r5, Mips64r6
   };
 
-  enum class CPU { P5600, I6400 };
+  enum class CPU { P5600, I6400, I6500 };
 
   // Used to avoid printing dsp warnings multiple times.
   static bool DspWarningPrinted;

>From 7d59e510ec1a5e0475918c96cac68699e93a9d90 Mon Sep 17 00:00:00 2001
From: Mallikarjuna Gouda 
Date: Tue, 25 Mar 2025 15:33:00 +0530
Subject: [PATCH 2/2] [MIPS] remove extra line in the test case

---
 clang/test/CodeGen/Mips/subtarget-feature-test.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/test/CodeGen/Mips/subtarget-feature-test.c 
b/clang/test/CodeGen/Mips/subtarget-feature-test.c
index d6a3f08a82de7..7f0b8e7e77135 100644
--- a/clang/test/CodeGen/Mips/subtarget-feature-test.c
+++ b/clang/test/CodeGen/Mips/subtarget-feature-test.c
@@ -1,6 +1,5 @@
 // RUN: %clang --target=mips64-linux-gnu -mcpu=i6400 -o %t -c %s 2>&1 | 
FileCheck --allow-empty %s
 // CHECK-NOT: {{.*}} is not a recognized feature for this target
 
-
 // RUN: %clang --target=mips64-linux-gnu -mcpu=i6500 -o %t -c %s 2>&1 | 
FileCheck --allow-empty %s
 // CHECK-NOT: {{.*}} is not a recognized feature for this target

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


[clang-tools-extra] [clang-tidy] Improve `bugprone-capturing-this-in-member-variable` check: add support of `bind` functions. (PR #132635)

2025-03-25 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor updated 
https://github.com/llvm/llvm-project/pull/132635

>From c91ad611e7a64b08a243a4a7f07a7f51e96b8ac0 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Sun, 23 Mar 2025 23:57:15 +0300
Subject: [PATCH 1/2] [clang-tidy] Add support of `bind` function calls that
 capture `this`

---
 .../CapturingThisInMemberVariableCheck.cpp| 56 +-
 .../CapturingThisInMemberVariableCheck.h  |  1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +-
 .../capturing-this-in-member-variable.rst |  8 +++
 .../capturing-this-in-member-variable.cpp | 58 ++-
 5 files changed, 110 insertions(+), 18 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
index add0576a42c33..c0bcd7698a6ae 100644
--- 
a/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
@@ -64,16 +64,21 @@ AST_MATCHER(CXXRecordDecl, correctHandleCaptureThisLambda) {
 
 constexpr const char *DefaultFunctionWrapperTypes =
 "::std::function;::std::move_only_function;::boost::function";
+constexpr const char *DefaultBindFunctions = "::std::bind;::boost::bind";
 
 CapturingThisInMemberVariableCheck::CapturingThisInMemberVariableCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   FunctionWrapperTypes(utils::options::parseStringList(
-  Options.get("FunctionWrapperTypes", DefaultFunctionWrapperTypes))) {}
+  Options.get("FunctionWrapperTypes", DefaultFunctionWrapperTypes))),
+  BindFunctions(utils::options::parseStringList(
+  Options.get("BindFunctions", DefaultBindFunctions))) {}
 void CapturingThisInMemberVariableCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "FunctionWrapperTypes",
 utils::options::serializeStringList(FunctionWrapperTypes));
+  Options.store(Opts, "BindFunctions",
+utils::options::serializeStringList(BindFunctions));
 }
 
 void CapturingThisInMemberVariableCheck::registerMatchers(MatchFinder *Finder) 
{
@@ -87,33 +92,54 @@ void 
CapturingThisInMemberVariableCheck::registerMatchers(MatchFinder *Finder) {
   // [self = this]
   capturesVar(varDecl(hasInitializer(cxxThisExpr());
   auto IsLambdaCapturingThis =
-  lambdaExpr(hasAnyCapture(CaptureThis.bind("capture"))).bind("lambda");
-  auto IsInitWithLambda =
-  anyOf(IsLambdaCapturingThis,
-cxxConstructExpr(hasArgument(0, IsLambdaCapturingThis)));
+  lambdaExpr(hasAnyCapture(CaptureThis)).bind("lambda");
+
+  auto IsBindCapturingThis =
+  callExpr(
+  callee(functionDecl(matchers::matchesAnyListedName(BindFunctions))
+ .bind("callee")),
+  hasAnyArgument(cxxThisExpr()))
+  .bind("bind");
+
+  auto IsInitWithLambdaOrBind =
+  anyOf(IsLambdaCapturingThis, IsBindCapturingThis,
+cxxConstructExpr(hasArgument(
+0, anyOf(IsLambdaCapturingThis, IsBindCapturingThis;
+
   Finder->addMatcher(
   cxxRecordDecl(
   anyOf(has(cxxConstructorDecl(
 unless(isCopyConstructor()), unless(isMoveConstructor()),
 hasAnyConstructorInitializer(cxxCtorInitializer(
 isMemberInitializer(), forField(IsStdFunctionField),
-withInitializer(IsInitWithLambda),
+withInitializer(IsInitWithLambdaOrBind),
 has(fieldDecl(IsStdFunctionField,
-  hasInClassInitializer(IsInitWithLambda,
+  hasInClassInitializer(IsInitWithLambdaOrBind,
   unless(correctHandleCaptureThisLambda())),
   this);
 }
-
 void CapturingThisInMemberVariableCheck::check(
 const MatchFinder::MatchResult &Result) {
-  const auto *Capture = Result.Nodes.getNodeAs("capture");
-  const auto *Lambda = Result.Nodes.getNodeAs("lambda");
+  const auto EmitDiag = [this](const SourceLocation &Location,
+   const FunctionDecl *Bind) {
+const std::string BindName = Bind ? Bind->getQualifiedNameAsString() : "";
+diag(Location, "'this' captured by a %select{lambda|'%1' call}0 and "
+   "stored in a class member variable; disable implicit class "
+   "copying/moving to prevent potential use-after-free")
+<< (Bind ? 1 : 0) << BindName;
+  };
+
+  if (const auto *Lambda = Result.Nodes.getNodeAs("lambda")) {
+EmitDiag(Lambda->getBeginLoc(), nullptr);
+  } else if (const auto *Bind = Result.Nodes.getNodeAs("bind")) {
+const auto *Callee = Result.Nodes.getNodeAs("callee");
+assert(Callee);
+EmitDiag(Bind->getBeginLoc(), Callee);
+  }
+
   const auto *Field = Result.Nodes.getNodeAs("field");
-  diag(

[clang-tools-extra] [clang-tidy] Improve `bugprone-capturing-this-in-member-variable` check: add support of `bind` functions. (PR #132635)

2025-03-25 Thread Baranov Victor via cfe-commits


@@ -64,16 +64,21 @@ AST_MATCHER(CXXRecordDecl, correctHandleCaptureThisLambda) {
 
 constexpr const char *DefaultFunctionWrapperTypes =
 "::std::function;::std::move_only_function;::boost::function";
+constexpr const char *DefaultBindFunctions = "::std::bind;::boost::bind";

vbvictor wrote:

Done

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


[clang-tools-extra] [clang-doc] Add regression test for test comments in macros (PR #132510)

2025-03-25 Thread via cfe-commits

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


[clang] [RISCV] Make RequiredExtensions for intrinsics scalable to more than 32 extensions. NFC (PR #132895)

2025-03-25 Thread Pengcheng Wang via cfe-commits


@@ -519,6 +517,9 @@ struct RVVIntrinsicRecord {
   // e.g. vadd
   const char *OverloadedName;
 
+  // Required target features for this intrinsic.
+  uint32_t RequiredExtensions[(RVV_REQ_NUM + 31) / 32];

wangpc-pp wrote:

I wonder if we can use `FeatureBitset` here and reuse extension enums so that 
we don't need to define `RVVRequire`.

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


[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

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


@@ -0,0 +1,81 @@
+//===--===//
+//
+// 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 "PassDetail.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Support/LogicalResult.h"
+#include "mlir/Transforms/DialectConversion.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+#include "clang/CIR/Dialect/Passes.h"
+#include "clang/CIR/MissingFeatures.h"
+#include "llvm/Support/TimeProfiler.h"
+
+using namespace mlir;
+using namespace cir;
+
+namespace {
+
+struct HoistAllocasPass : public HoistAllocasBase {
+
+  HoistAllocasPass() = default;
+  void runOnOperation() override;
+};
+
+static void process(mlir::ModuleOp mod, cir::FuncOp func) {
+  if (func.getRegion().empty())
+return;
+
+  // Hoist all static allocas to the entry block.
+  mlir::Block &entryBlock = func.getRegion().front();
+  llvm::SmallVector allocas;
+  func.getBody().walk([&](cir::AllocaOp alloca) {
+if (alloca->getBlock() == &entryBlock)
+  return;
+// Don't hoist allocas with dynamic alloca size.
+assert(!cir::MissingFeatures::opAllocaDynAllocSize());
+allocas.push_back(alloca);
+  });
+  if (allocas.empty())
+return;
+
+  mlir::Operation *insertPoint = &*entryBlock.begin();
+
+  for (cir::AllocaOp alloca : allocas) {
+// Preserving the `const` attribute on hoisted allocas can cause LLVM to
+// incorrectly introduce invariant group metadata in some circumstances.
+// The incubator performs some analysis to determine whether the attribute
+// can be preserved, but it only runs this analysis when optimizations are
+// enabled. Until we start tracking the optimization level, we can just
+// always remove the `const` attribute.
+assert(!cir::MissingFeatures::optInfoAttr());
+if (alloca.getConstant())
+  alloca.setConstant(false);
+
+alloca->moveBefore(insertPoint);
+  }
+}
+
+void HoistAllocasPass::runOnOperation() {
+  llvm::TimeTraceScope scope("Hoist Allocas");
+  llvm::SmallVector ops;
+
+  Operation *op = getOperation();
+  auto mod = mlir::dyn_cast(op);
+  if (!mod)
+mod = op->getParentOfType();
+
+  getOperation()->walk([&](cir::FuncOp op) { process(mod, op); });

xlauko wrote:

There is probably no need to do recursive walk here? @bcardosolopes can 
`cir::FuncOp` have nested `cir::FuncOp`?

If not this should probably be `PreOrder` walk and return `WalkResult::skip()` 
from the lambda to not walk its body.

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


[clang] [RISCV] Make RequiredExtensions for intrinsics scalable to more than 32 extensions. NFC (PR #132895)

2025-03-25 Thread Pengcheng Wang via cfe-commits


@@ -45,7 +45,7 @@ struct SemaRecord {
   unsigned Log2LMULMask;
 
   // Required extensions for this intrinsic.
-  uint32_t RequiredExtensions;
+  uint32_t RequiredExtensions[(RVV_REQ_Experimental + 31) / 32];

wangpc-pp wrote:

RVV_REQ_Experimental->RVV_REQ_NUM?

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


[clang] [flang] [llvm] [Clang][AMDGPU] Expose buffer load lds as a clang builtin (PR #132048)

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


@@ -43,7 +43,7 @@ int bar() { return no_attr() + attr_in_target() + 
attr_not_in_target() + attr_in
 // CHECK-LABEL: @attr_incompatible
 // CHECK-SAME: () #[[ATTR_INCOMPATIBLE:[0-9]+]] {
 
-// CHECK: attributes #[[ATTR_BAR]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
-// CHECK: attributes #[[ATTR_COMPATIBLE]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gws,+image-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
-// CHECK: attributes #[[ATTR_EXTEND]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+extended-image-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gws,+image-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
-// CHECK: attributes #[[ATTR_INCOMPATIBLE]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx90a-insts,+gws,+image-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-gfx9-insts"
 }
+// CHECK: attributes #[[ATTR_BAR]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+lds-buffer-load-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }

jmmartinez wrote:

Thanks I didn't know about it. It improves the situation a bit.

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


[clang] [flang] [llvm] [Clang][AMDGPU] Expose buffer load lds as a clang builtin (PR #132048)

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

jmmartinez wrote:

> > I've also seen that gfx11 seem to have some kind of BUFFER_LOAD_LDS_(SIZE) 
> > instruction (different from the BUFFER_LOAD_(SIZE)_LDS instructions 
> > associated with this builtin).
> > However, I'm not sure they actually exists: we do not have any test where 
> > we generate them and the gfx11 shader manual explicitly says _"Remove 
> > "LOAD_LDS" instructions: buffer_load_lds, scratch_load_lds, 
> > global_load_lds"_
> 
> Sounds like we need to get information from HW folks. :-)

I've asked and there is no buffer_load_lds instruction on gfx11 nor gfx12. I 
guess we can remove them in a separate patch.


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


[clang] [clang][bytecode] Fix base cast of nullptr without descriptor (PR #132909)

2025-03-25 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/132909

The missing descriptor should only happen if the pointer is null pointer.

>From ac98de068f55909a1b8bdd3070de561cd5d913e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 25 Mar 2025 11:15:52 +0100
Subject: [PATCH] [clang][bytecode] Fix base cast of nullptr without descriptor

The missing descriptor should only happen if the pointer is null
pointer.
---
 clang/lib/AST/ByteCode/Pointer.cpp  |  4 
 clang/test/AST/ByteCode/records.cpp | 16 
 2 files changed, 20 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 8abdc54b64677..79b47c26992ae 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -720,6 +720,10 @@ IntPointer IntPointer::atOffset(const ASTContext &ASTCtx,
 
 IntPointer IntPointer::baseCast(const ASTContext &ASTCtx,
 unsigned BaseOffset) const {
+  if (!Desc) {
+assert(Value == 0);
+return *this;
+  }
   const Record *R = Desc->ElemRecord;
   const Descriptor *BaseDesc = nullptr;
 
diff --git a/clang/test/AST/ByteCode/records.cpp 
b/clang/test/AST/ByteCode/records.cpp
index 5d9f1044f206b..da851785323a5 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1771,3 +1771,19 @@ namespace RedeclaredCtor {
   constexpr __sp_mut::__sp_mut(void *p) noexcept : __lx_(p) {}
   constexpr __sp_mut muts = &mut_back[0];
 }
+
+namespace IntegralBaseCast {
+  class A {};
+  class B : public A {};
+  struct S {
+B *a;
+  };
+
+  constexpr int f() {
+S s{};
+A *a = s.a;
+return 0;
+  }
+
+  static_assert(f() == 0, "");
+}

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


[clang] [clang][bytecode] Fix base cast of nullptr without descriptor (PR #132909)

2025-03-25 Thread Timm Baeder via cfe-commits

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


[clang] a29b0d7 - [clang][bytecode] Fix base cast of nullptr without descriptor (#132909)

2025-03-25 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-25T11:37:03+01:00
New Revision: a29b0d74a198a9c91d39b4d9224c242e1a22df18

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

LOG: [clang][bytecode] Fix base cast of nullptr without descriptor (#132909)

The missing descriptor should only happen if the pointer is null
pointer.

Added: 


Modified: 
clang/lib/AST/ByteCode/Pointer.cpp
clang/test/AST/ByteCode/records.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 8abdc54b64677..79b47c26992ae 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -720,6 +720,10 @@ IntPointer IntPointer::atOffset(const ASTContext &ASTCtx,
 
 IntPointer IntPointer::baseCast(const ASTContext &ASTCtx,
 unsigned BaseOffset) const {
+  if (!Desc) {
+assert(Value == 0);
+return *this;
+  }
   const Record *R = Desc->ElemRecord;
   const Descriptor *BaseDesc = nullptr;
 

diff  --git a/clang/test/AST/ByteCode/records.cpp 
b/clang/test/AST/ByteCode/records.cpp
index 5d9f1044f206b..da851785323a5 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1771,3 +1771,19 @@ namespace RedeclaredCtor {
   constexpr __sp_mut::__sp_mut(void *p) noexcept : __lx_(p) {}
   constexpr __sp_mut muts = &mut_back[0];
 }
+
+namespace IntegralBaseCast {
+  class A {};
+  class B : public A {};
+  struct S {
+B *a;
+  };
+
+  constexpr int f() {
+S s{};
+A *a = s.a;
+return 0;
+  }
+
+  static_assert(f() == 0, "");
+}



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


[clang-tools-extra] [clang-tidy] ExprSequence: Handle ternary operators. (PR #132913)

2025-03-25 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle created 
https://github.com/llvm/llvm-project/pull/132913

The first operand in the conditional operator `?:` is sequenced before the 
second or third operand.

This was probably not implemented because it did not fit in the "single 
successor" model of `getSuccessor` (the conditional operator has two 
unsequenced successors). Switch to potentially returning several successors in 
`getSuccessors` and implement the conditional operator.

Add unit tests.

>From ce42967569232f3b01e41cea753de2bf6a8cc684 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Tue, 25 Mar 2025 09:42:53 +
Subject: [PATCH] [clang-tidy] ExprSequence: Handle ternary operators.

The first operand in the conditional operator `?:` is sequenced before
the second or third operand.

This was probably not implemented because it did not fit in the "single
successor" model of `getSuccessor` (the conditional operator has two
unsequenced successors). Switch to potentially returning several
successors in `getSuccessors` and implement the conditional operator.

Add unit tests.
---
 .../clang-tidy/utils/ExprSequence.cpp |  48 +---
 .../clang-tidy/utils/ExprSequence.h   |   9 +-
 .../unittests/clang-tidy/CMakeLists.txt   |   2 +
 .../unittests/clang-tidy/ExprSequenceTest.cpp | 111 ++
 4 files changed, 146 insertions(+), 24 deletions(-)
 create mode 100644 clang-tools-extra/unittests/clang-tidy/ExprSequenceTest.cpp

diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp 
b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
index 145a5fe378b3e..cef70171999b5 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -95,10 +95,16 @@ bool ExprSequence::inSequence(const Stmt *Before, const 
Stmt *After) const {
 
   // If 'After' is in the subtree of the siblings that follow 'Before' in the
   // chain of successors, we know that 'After' is sequenced after 'Before'.
-  for (const Stmt *Successor = getSequenceSuccessor(Before); Successor;
-   Successor = getSequenceSuccessor(Successor)) {
-if (isDescendantOrEqual(After, Successor, Context))
-  return true;
+  {
+SmallVector Stack = {Before};
+while (!Stack.empty()) {
+  const Stmt *Node = Stack.back(); Stack.pop_back();
+  for (const Stmt *Successor : getSequenceSuccessors(Node)) {
+if (isDescendantOrEqual(After, Successor, Context))
+  return true;
+Stack.push_back(Successor);
+  }
+}
   }
 
   SmallVector BeforeParents = getParentStmts(Before, Context);
@@ -166,7 +172,7 @@ bool ExprSequence::potentiallyAfter(const Stmt *After,
   return !inSequence(After, Before);
 }
 
-const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const {
+llvm::SmallVector ExprSequence::getSequenceSuccessors(const 
Stmt *S) const {
   for (const Stmt *Parent : getParentStmts(S, Context)) {
 // If a statement has multiple parents, make sure we're using the parent
 // that lies within the sub-tree under Root.
@@ -176,14 +182,14 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
 if (const auto *BO = dyn_cast(Parent)) {
   // Comma operator: Right-hand side is sequenced after the left-hand side.
   if (BO->getLHS() == S && BO->getOpcode() == BO_Comma)
-return BO->getRHS();
+return {BO->getRHS()};
 } else if (const auto *InitList = dyn_cast(Parent)) {
   // Initializer list: Each initializer clause is sequenced after the
   // clauses that precede it.
   for (const InitListExpr *Form : getAllInitListForms(InitList)) {
 for (unsigned I = 1; I < Form->getNumInits(); ++I) {
   if (Form->getInit(I - 1) == S) {
-return Form->getInit(I);
+return {Form->getInit(I)};
   }
 }
   }
@@ -193,7 +199,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   if (ConstructExpr->isListInitialization()) {
 for (unsigned I = 1; I < ConstructExpr->getNumArgs(); ++I) {
   if (ConstructExpr->getArg(I - 1) == S) {
-return ConstructExpr->getArg(I);
+return {ConstructExpr->getArg(I)};
   }
 }
   }
@@ -203,7 +209,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   const Stmt *Previous = nullptr;
   for (const auto *Child : Compound->body()) {
 if (Previous == S)
-  return Child;
+  return {Child};
 Previous = Child;
   }
 } else if (const auto *TheDeclStmt = dyn_cast(Parent)) {
@@ -214,7 +220,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
 if (const auto *TheVarDecl = dyn_cast(TheDecl)) {
   if (const Expr *Init = TheVarDecl->getInit()) {
 if (PreviousInit == S)
-  return Init;
+  return {Init};
 PreviousInit = Init;
   }
 }
@@ -224,7 +230,

[clang-tools-extra] [clang-tidy] ExprSequence: Handle ternary operators. (PR #132913)

2025-03-25 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/132913

>From dcb97b74e78148e03f7749f436f01d5488c11ae1 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Tue, 25 Mar 2025 09:42:53 +
Subject: [PATCH] [clang-tidy] ExprSequence: Handle ternary operators.

The first operand in the conditional operator `?:` is sequenced before
the second or third operand.

This was probably not implemented because it did not fit in the "single
successor" model of `getSuccessor` (the conditional operator has two
unsequenced successors). Switch to potentially returning several
successors in `getSuccessors` and implement the conditional operator.

Add unit tests.
---
 .../clang-tidy/utils/ExprSequence.cpp |  51 +---
 .../clang-tidy/utils/ExprSequence.h   |   9 +-
 .../unittests/clang-tidy/CMakeLists.txt   |   2 +
 .../unittests/clang-tidy/ExprSequenceTest.cpp | 112 ++
 4 files changed, 150 insertions(+), 24 deletions(-)
 create mode 100644 clang-tools-extra/unittests/clang-tidy/ExprSequenceTest.cpp

diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp 
b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
index 145a5fe378b3e..07a02702f8571 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -95,10 +95,17 @@ bool ExprSequence::inSequence(const Stmt *Before, const 
Stmt *After) const {
 
   // If 'After' is in the subtree of the siblings that follow 'Before' in the
   // chain of successors, we know that 'After' is sequenced after 'Before'.
-  for (const Stmt *Successor = getSequenceSuccessor(Before); Successor;
-   Successor = getSequenceSuccessor(Successor)) {
-if (isDescendantOrEqual(After, Successor, Context))
-  return true;
+  {
+SmallVector Stack = {Before};
+while (!Stack.empty()) {
+  const Stmt *Node = Stack.back();
+  Stack.pop_back();
+  for (const Stmt *Successor : getSequenceSuccessors(Node)) {
+if (isDescendantOrEqual(After, Successor, Context))
+  return true;
+Stack.push_back(Successor);
+  }
+}
   }
 
   SmallVector BeforeParents = getParentStmts(Before, Context);
@@ -166,7 +173,8 @@ bool ExprSequence::potentiallyAfter(const Stmt *After,
   return !inSequence(After, Before);
 }
 
-const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const {
+llvm::SmallVector
+ExprSequence::getSequenceSuccessors(const Stmt *S) const {
   for (const Stmt *Parent : getParentStmts(S, Context)) {
 // If a statement has multiple parents, make sure we're using the parent
 // that lies within the sub-tree under Root.
@@ -176,14 +184,14 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
 if (const auto *BO = dyn_cast(Parent)) {
   // Comma operator: Right-hand side is sequenced after the left-hand side.
   if (BO->getLHS() == S && BO->getOpcode() == BO_Comma)
-return BO->getRHS();
+return {BO->getRHS()};
 } else if (const auto *InitList = dyn_cast(Parent)) {
   // Initializer list: Each initializer clause is sequenced after the
   // clauses that precede it.
   for (const InitListExpr *Form : getAllInitListForms(InitList)) {
 for (unsigned I = 1; I < Form->getNumInits(); ++I) {
   if (Form->getInit(I - 1) == S) {
-return Form->getInit(I);
+return {Form->getInit(I)};
   }
 }
   }
@@ -193,7 +201,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   if (ConstructExpr->isListInitialization()) {
 for (unsigned I = 1; I < ConstructExpr->getNumArgs(); ++I) {
   if (ConstructExpr->getArg(I - 1) == S) {
-return ConstructExpr->getArg(I);
+return {ConstructExpr->getArg(I)};
   }
 }
   }
@@ -203,7 +211,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   const Stmt *Previous = nullptr;
   for (const auto *Child : Compound->body()) {
 if (Previous == S)
-  return Child;
+  return {Child};
 Previous = Child;
   }
 } else if (const auto *TheDeclStmt = dyn_cast(Parent)) {
@@ -214,7 +222,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
 if (const auto *TheVarDecl = dyn_cast(TheDecl)) {
   if (const Expr *Init = TheVarDecl->getInit()) {
 if (PreviousInit == S)
-  return Init;
+  return {Init};
 PreviousInit = Init;
   }
 }
@@ -224,7 +232,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   // body. (We need this rule because these get placed in the same
   // CFGBlock.)
   if (S == ForRange->getLoopVarStmt())
-return ForRange->getBody();
+return {ForRange->getBody()};
 } else if (const auto *TheIfStmt = dyn_cast(Parent)) {
   // If statement:
   // - Sequenc

[clang-tools-extra] [clang-tidy] ExprSequence: Handle ternary operators. (PR #132913)

2025-03-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Clement Courbet (legrosbuffle)


Changes

The first operand in the conditional operator `?:` is sequenced before the 
second or third operand.

This was probably not implemented because it did not fit in the "single 
successor" model of `getSuccessor` (the conditional operator has two 
unsequenced successors). Switch to potentially returning several successors in 
`getSuccessors` and implement the conditional operator.

Add unit tests.

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


4 Files Affected:

- (modified) clang-tools-extra/clang-tidy/utils/ExprSequence.cpp (+29-19) 
- (modified) clang-tools-extra/clang-tidy/utils/ExprSequence.h (+4-5) 
- (modified) clang-tools-extra/unittests/clang-tidy/CMakeLists.txt (+2) 
- (added) clang-tools-extra/unittests/clang-tidy/ExprSequenceTest.cpp (+111) 


``diff
diff --git a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp 
b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
index 145a5fe378b3e..cef70171999b5 100644
--- a/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
@@ -95,10 +95,16 @@ bool ExprSequence::inSequence(const Stmt *Before, const 
Stmt *After) const {
 
   // If 'After' is in the subtree of the siblings that follow 'Before' in the
   // chain of successors, we know that 'After' is sequenced after 'Before'.
-  for (const Stmt *Successor = getSequenceSuccessor(Before); Successor;
-   Successor = getSequenceSuccessor(Successor)) {
-if (isDescendantOrEqual(After, Successor, Context))
-  return true;
+  {
+SmallVector Stack = {Before};
+while (!Stack.empty()) {
+  const Stmt *Node = Stack.back(); Stack.pop_back();
+  for (const Stmt *Successor : getSequenceSuccessors(Node)) {
+if (isDescendantOrEqual(After, Successor, Context))
+  return true;
+Stack.push_back(Successor);
+  }
+}
   }
 
   SmallVector BeforeParents = getParentStmts(Before, Context);
@@ -166,7 +172,7 @@ bool ExprSequence::potentiallyAfter(const Stmt *After,
   return !inSequence(After, Before);
 }
 
-const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const {
+llvm::SmallVector ExprSequence::getSequenceSuccessors(const 
Stmt *S) const {
   for (const Stmt *Parent : getParentStmts(S, Context)) {
 // If a statement has multiple parents, make sure we're using the parent
 // that lies within the sub-tree under Root.
@@ -176,14 +182,14 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
 if (const auto *BO = dyn_cast(Parent)) {
   // Comma operator: Right-hand side is sequenced after the left-hand side.
   if (BO->getLHS() == S && BO->getOpcode() == BO_Comma)
-return BO->getRHS();
+return {BO->getRHS()};
 } else if (const auto *InitList = dyn_cast(Parent)) {
   // Initializer list: Each initializer clause is sequenced after the
   // clauses that precede it.
   for (const InitListExpr *Form : getAllInitListForms(InitList)) {
 for (unsigned I = 1; I < Form->getNumInits(); ++I) {
   if (Form->getInit(I - 1) == S) {
-return Form->getInit(I);
+return {Form->getInit(I)};
   }
 }
   }
@@ -193,7 +199,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   if (ConstructExpr->isListInitialization()) {
 for (unsigned I = 1; I < ConstructExpr->getNumArgs(); ++I) {
   if (ConstructExpr->getArg(I - 1) == S) {
-return ConstructExpr->getArg(I);
+return {ConstructExpr->getArg(I)};
   }
 }
   }
@@ -203,7 +209,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   const Stmt *Previous = nullptr;
   for (const auto *Child : Compound->body()) {
 if (Previous == S)
-  return Child;
+  return {Child};
 Previous = Child;
   }
 } else if (const auto *TheDeclStmt = dyn_cast(Parent)) {
@@ -214,7 +220,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
 if (const auto *TheVarDecl = dyn_cast(TheDecl)) {
   if (const Expr *Init = TheVarDecl->getInit()) {
 if (PreviousInit == S)
-  return Init;
+  return {Init};
 PreviousInit = Init;
   }
 }
@@ -224,7 +230,7 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   // body. (We need this rule because these get placed in the same
   // CFGBlock.)
   if (S == ForRange->getLoopVarStmt())
-return ForRange->getBody();
+return {ForRange->getBody()};
 } else if (const auto *TheIfStmt = dyn_cast(Parent)) {
   // If statement:
   // - Sequence init statement before variable declaration, if present;
@@ -233,30 +239,34 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt 
*S) const {
   //   initialize 

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

2025-03-25 Thread via cfe-commits


@@ -2001,3 +1932,304 @@ NormalizedConstraint::getFoldExpandedConstraint() const 
{
  "getFoldExpandedConstraint called on non-fold-expanded constraint.");
   return cast(Constraint);
 }
+
+//
+//
+// -
+//
+//
+
+/// \name Subsumption

cor3ntin wrote:

Just to separate. I removed the doxygen comment

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][bytecode] Fix zero-init of atomic floating point objects (PR #132782)

2025-03-25 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr closed 
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] [clang][bytecode] Fix base cast of nullptr without descriptor (PR #132909)

2025-03-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

The missing descriptor should only happen if the pointer is null pointer.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Pointer.cpp (+4) 
- (modified) clang/test/AST/ByteCode/records.cpp (+16) 


``diff
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp 
b/clang/lib/AST/ByteCode/Pointer.cpp
index 8abdc54b64677..79b47c26992ae 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -720,6 +720,10 @@ IntPointer IntPointer::atOffset(const ASTContext &ASTCtx,
 
 IntPointer IntPointer::baseCast(const ASTContext &ASTCtx,
 unsigned BaseOffset) const {
+  if (!Desc) {
+assert(Value == 0);
+return *this;
+  }
   const Record *R = Desc->ElemRecord;
   const Descriptor *BaseDesc = nullptr;
 
diff --git a/clang/test/AST/ByteCode/records.cpp 
b/clang/test/AST/ByteCode/records.cpp
index 5d9f1044f206b..da851785323a5 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1771,3 +1771,19 @@ namespace RedeclaredCtor {
   constexpr __sp_mut::__sp_mut(void *p) noexcept : __lx_(p) {}
   constexpr __sp_mut muts = &mut_back[0];
 }
+
+namespace IntegralBaseCast {
+  class A {};
+  class B : public A {};
+  struct S {
+B *a;
+  };
+
+  constexpr int f() {
+S s{};
+A *a = s.a;
+return 0;
+  }
+
+  static_assert(f() == 0, "");
+}

``




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


[clang] [flang] [llvm] [Clang][AMDGPU] Expose buffer load lds as a clang builtin (PR #132048)

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

https://github.com/jmmartinez updated 
https://github.com/llvm/llvm-project/pull/132048

From f7df0f882bb2062fa63111d07aca3c91d0805904 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Thu, 20 Mar 2025 13:23:25 +0100
Subject: [PATCH 1/6] [AMDGPU] Add "lds-buffer-load-insts" attribute for all
 targets < gfx11

This are used to restrict the availability of buffer_load_lds
intrinsics to targets that actually have this instructions.
---
 clang/test/CodeGen/link-builtin-bitcode.c |  8 +--
 .../CodeGenCXX/dynamic-cast-address-space.cpp |  4 +-
 .../CodeGenOpenCL/amdgpu-enqueue-kernel.cl|  6 +-
 clang/test/CodeGenOpenCL/amdgpu-features.cl   | 72 +--
 clang/test/OpenMP/amdgcn-attributes.cpp   |  4 +-
 llvm/lib/Target/AMDGPU/AMDGPU.td  | 16 +++--
 .../AMDGPU/AMDGPUInstructionSelector.cpp  |  2 +-
 llvm/lib/Target/AMDGPU/GCNSubtarget.h |  3 +
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  2 +-
 llvm/lib/TargetParser/TargetParser.cpp|  5 ++
 10 files changed, 68 insertions(+), 54 deletions(-)

diff --git a/clang/test/CodeGen/link-builtin-bitcode.c 
b/clang/test/CodeGen/link-builtin-bitcode.c
index 470180efa4247..7491397152fca 100644
--- a/clang/test/CodeGen/link-builtin-bitcode.c
+++ b/clang/test/CodeGen/link-builtin-bitcode.c
@@ -43,7 +43,7 @@ int bar() { return no_attr() + attr_in_target() + 
attr_not_in_target() + attr_in
 // CHECK-LABEL: @attr_incompatible
 // CHECK-SAME: () #[[ATTR_INCOMPATIBLE:[0-9]+]] {
 
-// CHECK: attributes #[[ATTR_BAR]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
-// CHECK: attributes #[[ATTR_COMPATIBLE]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gws,+image-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
-// CHECK: attributes #[[ATTR_EXTEND]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+extended-image-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gws,+image-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
-// CHECK: attributes #[[ATTR_INCOMPATIBLE]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx90a-insts,+gws,+image-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-gfx9-insts"
 }
+// CHECK: attributes #[[ATTR_BAR]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+lds-buffer-load-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
+// CHECK: attributes #[[ATTR_COMPATIBLE]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gws,+image-insts,+lds-buffer-load-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
+// CHECK: attributes #[[ATTR_EXTEND]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+extended-image-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gws,+image-insts,+lds-buffer-load-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
+// CHECK: attributes #[[ATTR_INCOMPATIBLE]] = { {{.*}} "target-cpu"="gfx90a" 
"target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx90a-insts,+gws,+image-insts,+lds-buffer-load-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-gfx9-insts"
 }
diff --git a/clang/test/CodeGenCXX/dynamic-cast-address-space.cpp 
b/clang/test/Code

[clang] [Driver] Enable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #132821)

2025-03-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Daniel Chen (DanielCChen)


Changes

In the wake of discussion in PR #131200 and internal discussion after, 
we will add support for `LLVM_ENABLE_PER_TARGET_RUNTIME=ON` for AIX instead of 
disable it. I already reverted the change in PR #131200.

The default value of the option is still OFF on AIX.

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


9 Files Affected:

- (modified) clang/include/clang/Driver/ToolChain.h (+3) 
- (modified) clang/lib/Driver/ToolChain.cpp (+22-12) 
- (added) 
clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a () 
- (added) 
clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc64.a 
() 
- (added) 
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc-ibm-aix/libclang_rt.builtins.a
 () 
- (added) 
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc64-ibm-aix/libclang_rt.builtins.a
 () 
- (modified) clang/test/Driver/aix-ld.c (+52) 
- (modified) clang/test/Driver/aix-print-runtime-dir.c (+10) 
- (modified) clang/test/Driver/aix-rtlib.c (+8) 


``diff
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 90004c64a694a..f2e8fa306e3a5 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -519,6 +519,9 @@ class ToolChain {
 StringRef Component,
 FileType Type = ToolChain::FT_Static) 
const;
 
+  // Returns Triple without the OSs version.
+  llvm::Triple getTripleWithoutOSVersion() const;
+
   // Returns the target specific runtime path if it exists.
   std::optional getRuntimePath() const;
 
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 5f75d004eede0..8a922b283daf5 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -779,8 +779,6 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, 
StringRef Component,
 if (Path.empty())
   Path = P;
   }
-  if (getTriple().isOSAIX())
-Path.clear();
 
   // Check the filename for the old layout if the new one does not exist.
   CRTBasename =
@@ -846,6 +844,16 @@ ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir) 
const {
   return std::string(P);
 }
 
+llvm::Triple ToolChain::getTripleWithoutOSVersion() const {
+  return (Triple.hasEnvironment()
+  ? llvm::Triple(Triple.getArchName(), Triple.getVendorName(),
+ llvm::Triple::getOSTypeName(Triple.getOS()),
+ llvm::Triple::getEnvironmentTypeName(
+ Triple.getEnvironment()))
+  : llvm::Triple(Triple.getArchName(), Triple.getVendorName(),
+ llvm::Triple::getOSTypeName(Triple.getOS(;
+}
+
 std::optional
 ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   auto getPathForTriple =
@@ -864,14 +872,7 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   if (T.isOSzOS() &&
   (!T.getOSVersion().empty() || !T.getEnvironmentVersion().empty())) {
 // Build the triple without version information
-const llvm::Triple &TripleWithoutVersion =
-(T.hasEnvironment()
- ? llvm::Triple(
-   T.getArchName(), T.getVendorName(),
-   llvm::Triple::getOSTypeName(T.getOS()),
-   llvm::Triple::getEnvironmentTypeName(T.getEnvironment()))
- : llvm::Triple(T.getArchName(), T.getVendorName(),
-llvm::Triple::getOSTypeName(T.getOS(;
+const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion();
 if (auto Path = getPathForTriple(TripleWithoutVersion))
   return *Path;
   }
@@ -909,9 +910,18 @@ std::optional ToolChain::getRuntimePath() 
const {
   llvm::sys::path::append(P, "lib");
   if (auto Ret = getTargetSubDirPath(P))
 return Ret;
-  // Darwin and AIX does not use per-target runtime directory.
-  if (Triple.isOSDarwin() || Triple.isOSAIX())
+  // Darwin does not use per-target runtime directory.
+  if (Triple.isOSDarwin())
+return {};
+
+  // For AIX, get the triple without the OS version.
+  if (Triple.isOSAIX()) {
+const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion();
+llvm::sys::path::append(P, TripleWithoutVersion.str());
+if (getVFS().exists(P))
+  return std::string(P);
 return {};
+  }
   llvm::sys::path::append(P, Triple.str());
   return std::string(P);
 }
diff --git 
a/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a 
b/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a
new file mode 100644
index 0..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc64.a
 
b/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc64.a
n

[clang] [Driver] Enable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #132821)

2025-03-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Daniel Chen (DanielCChen)


Changes

In the wake of discussion in PR #131200 and internal discussion after, 
we will add support for `LLVM_ENABLE_PER_TARGET_RUNTIME=ON` for AIX instead of 
disable it. I already reverted the change in PR #131200.

The default value of the option is still OFF on AIX.

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


9 Files Affected:

- (modified) clang/include/clang/Driver/ToolChain.h (+3) 
- (modified) clang/lib/Driver/ToolChain.cpp (+22-12) 
- (added) 
clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a () 
- (added) 
clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc64.a 
() 
- (added) 
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc-ibm-aix/libclang_rt.builtins.a
 () 
- (added) 
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc64-ibm-aix/libclang_rt.builtins.a
 () 
- (modified) clang/test/Driver/aix-ld.c (+52) 
- (modified) clang/test/Driver/aix-print-runtime-dir.c (+10) 
- (modified) clang/test/Driver/aix-rtlib.c (+8) 


``diff
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 90004c64a694a..f2e8fa306e3a5 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -519,6 +519,9 @@ class ToolChain {
 StringRef Component,
 FileType Type = ToolChain::FT_Static) 
const;
 
+  // Returns Triple without the OSs version.
+  llvm::Triple getTripleWithoutOSVersion() const;
+
   // Returns the target specific runtime path if it exists.
   std::optional getRuntimePath() const;
 
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 5f75d004eede0..8a922b283daf5 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -779,8 +779,6 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, 
StringRef Component,
 if (Path.empty())
   Path = P;
   }
-  if (getTriple().isOSAIX())
-Path.clear();
 
   // Check the filename for the old layout if the new one does not exist.
   CRTBasename =
@@ -846,6 +844,16 @@ ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir) 
const {
   return std::string(P);
 }
 
+llvm::Triple ToolChain::getTripleWithoutOSVersion() const {
+  return (Triple.hasEnvironment()
+  ? llvm::Triple(Triple.getArchName(), Triple.getVendorName(),
+ llvm::Triple::getOSTypeName(Triple.getOS()),
+ llvm::Triple::getEnvironmentTypeName(
+ Triple.getEnvironment()))
+  : llvm::Triple(Triple.getArchName(), Triple.getVendorName(),
+ llvm::Triple::getOSTypeName(Triple.getOS(;
+}
+
 std::optional
 ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   auto getPathForTriple =
@@ -864,14 +872,7 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   if (T.isOSzOS() &&
   (!T.getOSVersion().empty() || !T.getEnvironmentVersion().empty())) {
 // Build the triple without version information
-const llvm::Triple &TripleWithoutVersion =
-(T.hasEnvironment()
- ? llvm::Triple(
-   T.getArchName(), T.getVendorName(),
-   llvm::Triple::getOSTypeName(T.getOS()),
-   llvm::Triple::getEnvironmentTypeName(T.getEnvironment()))
- : llvm::Triple(T.getArchName(), T.getVendorName(),
-llvm::Triple::getOSTypeName(T.getOS(;
+const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion();
 if (auto Path = getPathForTriple(TripleWithoutVersion))
   return *Path;
   }
@@ -909,9 +910,18 @@ std::optional ToolChain::getRuntimePath() 
const {
   llvm::sys::path::append(P, "lib");
   if (auto Ret = getTargetSubDirPath(P))
 return Ret;
-  // Darwin and AIX does not use per-target runtime directory.
-  if (Triple.isOSDarwin() || Triple.isOSAIX())
+  // Darwin does not use per-target runtime directory.
+  if (Triple.isOSDarwin())
+return {};
+
+  // For AIX, get the triple without the OS version.
+  if (Triple.isOSAIX()) {
+const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion();
+llvm::sys::path::append(P, TripleWithoutVersion.str());
+if (getVFS().exists(P))
+  return std::string(P);
 return {};
+  }
   llvm::sys::path::append(P, Triple.str());
   return std::string(P);
 }
diff --git 
a/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a 
b/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a
new file mode 100644
index 0..e69de29bb2d1d
diff --git 
a/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc64.a
 
b/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerp

[clang] [Driver] Enable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (PR #132821)

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

https://github.com/DanielCChen updated 
https://github.com/llvm/llvm-project/pull/132821

>From be03d5cf608498b11dd274ee6294a0c4e83d4c5e Mon Sep 17 00:00:00 2001
From: Daniel Chen 
Date: Mon, 24 Mar 2025 15:45:33 -0400
Subject: [PATCH] [Driver] Enable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX.

---
 clang/include/clang/Driver/ToolChain.h|  3 ++
 clang/lib/Driver/ToolChain.cpp| 34 +++-
 .../lib/aix/libclang_rt.builtins-powerpc.a|  0
 .../lib/aix/libclang_rt.builtins-powerpc64.a  |  0
 .../powerpc-ibm-aix/libclang_rt.builtins.a|  0
 .../powerpc64-ibm-aix/libclang_rt.builtins.a  |  0
 clang/test/Driver/aix-ld.c| 52 +++
 clang/test/Driver/aix-print-runtime-dir.c | 10 
 clang/test/Driver/aix-rtlib.c |  8 +++
 9 files changed, 95 insertions(+), 12 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a
 create mode 100644 
clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc64.a
 create mode 100644 
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc-ibm-aix/libclang_rt.builtins.a
 create mode 100644 
clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/powerpc64-ibm-aix/libclang_rt.builtins.a

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 90004c64a694a..f2e8fa306e3a5 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -519,6 +519,9 @@ class ToolChain {
 StringRef Component,
 FileType Type = ToolChain::FT_Static) 
const;
 
+  // Returns Triple without the OSs version.
+  llvm::Triple getTripleWithoutOSVersion() const;
+
   // Returns the target specific runtime path if it exists.
   std::optional getRuntimePath() const;
 
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 5f75d004eede0..8a922b283daf5 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -779,8 +779,6 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, 
StringRef Component,
 if (Path.empty())
   Path = P;
   }
-  if (getTriple().isOSAIX())
-Path.clear();
 
   // Check the filename for the old layout if the new one does not exist.
   CRTBasename =
@@ -846,6 +844,16 @@ ToolChain::getFallbackAndroidTargetPath(StringRef BaseDir) 
const {
   return std::string(P);
 }
 
+llvm::Triple ToolChain::getTripleWithoutOSVersion() const {
+  return (Triple.hasEnvironment()
+  ? llvm::Triple(Triple.getArchName(), Triple.getVendorName(),
+ llvm::Triple::getOSTypeName(Triple.getOS()),
+ llvm::Triple::getEnvironmentTypeName(
+ Triple.getEnvironment()))
+  : llvm::Triple(Triple.getArchName(), Triple.getVendorName(),
+ llvm::Triple::getOSTypeName(Triple.getOS(;
+}
+
 std::optional
 ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   auto getPathForTriple =
@@ -864,14 +872,7 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
   if (T.isOSzOS() &&
   (!T.getOSVersion().empty() || !T.getEnvironmentVersion().empty())) {
 // Build the triple without version information
-const llvm::Triple &TripleWithoutVersion =
-(T.hasEnvironment()
- ? llvm::Triple(
-   T.getArchName(), T.getVendorName(),
-   llvm::Triple::getOSTypeName(T.getOS()),
-   llvm::Triple::getEnvironmentTypeName(T.getEnvironment()))
- : llvm::Triple(T.getArchName(), T.getVendorName(),
-llvm::Triple::getOSTypeName(T.getOS(;
+const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion();
 if (auto Path = getPathForTriple(TripleWithoutVersion))
   return *Path;
   }
@@ -909,9 +910,18 @@ std::optional ToolChain::getRuntimePath() 
const {
   llvm::sys::path::append(P, "lib");
   if (auto Ret = getTargetSubDirPath(P))
 return Ret;
-  // Darwin and AIX does not use per-target runtime directory.
-  if (Triple.isOSDarwin() || Triple.isOSAIX())
+  // Darwin does not use per-target runtime directory.
+  if (Triple.isOSDarwin())
+return {};
+
+  // For AIX, get the triple without the OS version.
+  if (Triple.isOSAIX()) {
+const llvm::Triple &TripleWithoutVersion = getTripleWithoutOSVersion();
+llvm::sys::path::append(P, TripleWithoutVersion.str());
+if (getVFS().exists(P))
+  return std::string(P);
 return {};
+  }
   llvm::sys::path::append(P, Triple.str());
   return std::string(P);
 }
diff --git 
a/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a 
b/clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.builtins-powerpc.a
new file mode 100644
index 0..e69de29bb2d1d
diff --git 
a/clang/

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

2025-03-25 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 1/9] [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 normal 

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

2025-03-25 Thread via cfe-commits

YLChenZ wrote:

My proposal is to judge the current `FieldDecl` at the beginning of the loop, 
and if it's a UnamedBitField, just skip it, because at that point the 
UnamedBitField's static check should be passing. If it's a NamedBitField then 
it needs to be initialized to pass the static check (i.e. go deeper to 
determine the type, value or whatever).
```cpp
for (const FieldDecl *I : RD->fields()) {
if (I->isUnnamedBitField()) {   //my proposal 
  continue;  
}
..
if (isPrimitiveType(T)) {
// Skip unnamed bitfields (padding)
if (I->isUnnamedBitField()) {   //his proposal 
continue;
}
..
}
}
```

The current test cases are sufficient. I'm not sure about the answers to the 
other questions.

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


[clang] [lld] [llvm] [NFC] Cleanup in Support headers. (PR #104825)

2025-03-25 Thread Daniil Fukalov via cfe-commits

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


[clang] cuda clang: Add support for CUDA surfaces (PR #132883)

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

https://github.com/AustinSchuh updated 
https://github.com/llvm/llvm-project/pull/132883

>From d8ffb5acbd79869476c91433f85488f3088e38fd Mon Sep 17 00:00:00 2001
From: Austin Schuh 
Date: Mon, 24 Mar 2025 21:42:35 -0700
Subject: [PATCH 1/4] Add support for CUDA surfaces

This adds support for all the surface read and write calls to clang.
It extends the pattern used for textures to surfaces too.

I tested this by generating all the various permutations of the calls
and argument types in a python script, compiling them with both clang
and nvcc, and comparing the generated ptx for equivilence.  They all
agree, ignoring register allocation, and some places where Clang does
different memory writes.  An example kernel is:

__global__ void testKernel(cudaSurfaceObject_t surfObj, int x, float2* result)
{
*result = surf1Dread(surfObj, x, cudaBoundaryModeZero);
}

Signed-off-by: Austin Schuh 
---
 .../Headers/__clang_cuda_runtime_wrapper.h|   1 +
 .../Headers/__clang_cuda_texture_intrinsics.h | 419 +-
 2 files changed, 418 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/__clang_cuda_runtime_wrapper.h 
b/clang/lib/Headers/__clang_cuda_runtime_wrapper.h
index d369c86fe1064..8182c961ec32f 100644
--- a/clang/lib/Headers/__clang_cuda_runtime_wrapper.h
+++ b/clang/lib/Headers/__clang_cuda_runtime_wrapper.h
@@ -386,6 +386,7 @@ __host__ __device__ void __nv_tex_surf_handler(const char 
*name, T *ptr,
 #endif // __cplusplus >= 201103L && CUDA_VERSION >= 9000
 #include "texture_fetch_functions.h"
 #include "texture_indirect_functions.h"
+#include "surface_indirect_functions.h"
 
 // Restore state of __CUDA_ARCH__ and __THROW we had on entry.
 #pragma pop_macro("__CUDA_ARCH__")
diff --git a/clang/lib/Headers/__clang_cuda_texture_intrinsics.h 
b/clang/lib/Headers/__clang_cuda_texture_intrinsics.h
index a71952211237b..2ea83f66036d4 100644
--- a/clang/lib/Headers/__clang_cuda_texture_intrinsics.h
+++ b/clang/lib/Headers/__clang_cuda_texture_intrinsics.h
@@ -28,6 +28,7 @@
 #pragma push_macro("__Args")
 #pragma push_macro("__ID")
 #pragma push_macro("__IDV")
+#pragma push_macro("__OP_TYPE_SURFACE")
 #pragma push_macro("__IMPL_2DGATHER")
 #pragma push_macro("__IMPL_ALIAS")
 #pragma push_macro("__IMPL_ALIASI")
@@ -45,6 +46,64 @@
 #pragma push_macro("__IMPL_SI")
 #pragma push_macro("__L")
 #pragma push_macro("__STRIP_PARENS")
+#pragma push_macro("__SURF_WRITE_V2")
+#pragma push_macro("__SW_ASM_ARGS")
+#pragma push_macro("__SW_ASM_ARGS1")
+#pragma push_macro("__SW_ASM_ARGS2")
+#pragma push_macro("__SW_ASM_ARGS4")
+#pragma push_macro("__SURF_WRITE_V2")
+#pragma push_macro("__SURF_READ_V2")
+#pragma push_macro("__SW_ASM_ARGS")
+#pragma push_macro("__SW_ASM_ARGS1")
+#pragma push_macro("__SW_ASM_ARGS2")
+#pragma push_macro("__SW_ASM_ARGS4")
+#pragma push_macro("__SURF_READ1D");
+#pragma push_macro("__SURF_READ2D");
+#pragma push_macro("__SURF_READ3D");
+#pragma push_macro("__SURF_READ1DLAYERED");
+#pragma push_macro("__SURF_READ2DLAYERED");
+#pragma push_macro("__SURF_READCUBEMAP");
+#pragma push_macro("__SURF_READCUBEMAPLAYERED");
+#pragma push_macro("__1DV1");
+#pragma push_macro("__1DV2");
+#pragma push_macro("__1DV4");
+#pragma push_macro("__2DV1");
+#pragma push_macro("__2DV2");
+#pragma push_macro("__2DV4");
+#pragma push_macro("__1DLAYERV1");
+#pragma push_macro("__1DLAYERV2");
+#pragma push_macro("__1DLAYERV4");
+#pragma push_macro("__3DV1");
+#pragma push_macro("__3DV2");
+#pragma push_macro("__3DV4");
+#pragma push_macro("__2DLAYERV1");
+#pragma push_macro("__2DLAYERV2");
+#pragma push_macro("__2DLAYERV4");
+#pragma push_macro("__CUBEMAPV1");
+#pragma push_macro("__CUBEMAPV2");
+#pragma push_macro("__CUBEMAPV4");
+#pragma push_macro("__CUBEMAPLAYERV1");
+#pragma push_macro("__CUBEMAPLAYERV2");
+#pragma push_macro("__CUBEMAPLAYERV4");
+#pragma push_macro("__SURF_READXD_ALL");
+#pragma push_macro("__SURF_WRITE1D_V2");
+#pragma push_macro("__SURF_WRITE1DLAYERED_V2");
+#pragma push_macro("__SURF_WRITE2D_V2");
+#pragma push_macro("__SURF_WRITE2DLAYERED_V2");
+#pragma push_macro("__SURF_WRITE3D_V2");
+#pragma push_macro("__SURF_CUBEMAPWRITE_V2");
+#pragma push_macro("__SURF_CUBEMAPLAYEREDWRITE_V2");
+#pragma push_macro("__SURF_WRITEXD_V2_ALL");
+#pragma push_macro("__1DV1");
+#pragma push_macro("__1DV2");
+#pragma push_macro("__1DV4");
+#pragma push_macro("__2DV1");
+#pragma push_macro("__2DV2");
+#pragma push_macro("__2DV4");
+#pragma push_macro("__3DV1");
+#pragma push_macro("__3DV2");
+#pragma push_macro("__3DV4");
+
 
 // Put all functions into anonymous namespace so they have internal linkage.
 // The device-only function here must be internal in order to avoid ODR
@@ -186,6 +245,20 @@ template  struct __TypeInfoT {
   using __fetch_t = typename __TypeInfoT<__base_t>::__fetch_t;
 };
 
+// Tag structs to distinguish operation types
+struct __texture_op_tag {};
+struct __surface_op_tag {};
+
+// Template specialization to determine operation type based on tag value
+template 
+struct __op_type

[clang] df01131 - [CIR] Remove failing binop test (#133001)

2025-03-25 Thread via cfe-commits

Author: Andy Kaylor
Date: 2025-03-25T14:41:30-07:00
New Revision: df011313cf14a2a0735ed3c56b70c5a145b23213

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

LOG: [CIR] Remove failing binop test (#133001)

When CIR binop support was commited, it accidentally included a test for
functionality that was removed during the review process
(cir.binop.overflow). This test, of course, fails.

This change removes the failing test. It will be re-added when the
corresponding op is added.

Added: 


Modified: 


Removed: 
clang/test/CIR/Lowering/binop-overflow.cir



diff  --git a/clang/test/CIR/Lowering/binop-overflow.cir 
b/clang/test/CIR/Lowering/binop-overflow.cir
deleted file mode 100644
index 68af70aa6abb6..0
--- a/clang/test/CIR/Lowering/binop-overflow.cir
+++ /dev/null
@@ -1,63 +0,0 @@
-// RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR
-// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu 
--disable-cc-lowering -o -  | FileCheck %s -check-prefix=LLVM
-
-!u32i = !cir.int
-!s32i = !cir.int
-
-module {
-  cir.func @test_add_u32_u32_u32(%lhs: !u32i, %rhs: !u32i, %res: 
!cir.ptr) -> !cir.bool {
-%result, %overflow = cir.binop.overflow(add, %lhs, %rhs) : !u32i, (!u32i, 
!cir.bool)
-cir.store %result, %res : !u32i, !cir.ptr
-cir.return %overflow : !cir.bool
-  }
-
-  //  MLIR: llvm.func @test_add_u32_u32_u32(%[[LHS:.+]]: i32, %[[RHS:.+]]: 
i32, %[[RES_PTR:.+]]: !llvm.ptr) -> i1
-  // MLIR-NEXT:   %[[#INTRIN_RET:]] = llvm.call_intrinsic 
"llvm.uadd.with.overflow.i32"(%[[LHS]], %[[RHS]]) : (i32, i32) -> 
!llvm.struct<(i32, i1)>
-  // MLIR-NEXT:   %[[#RES:]] = llvm.extractvalue %[[#INTRIN_RET]][0] : 
!llvm.struct<(i32, i1)>
-  // MLIR-NEXT:   %[[#OVFL:]] = llvm.extractvalue %[[#INTRIN_RET]][1] : 
!llvm.struct<(i32, i1)>
-  // MLIR-NEXT:   llvm.store %[[#RES]], %[[RES_PTR]] {{.*}} : i32, !llvm.ptr
-  // MLIR-NEXT:   llvm.return %[[#OVFL]] : i1
-  // MLIR-NEXT: }
-
-  //  LLVM: define i1 @test_add_u32_u32_u32(i32 %[[#LHS:]], i32 
%[[#RHS:]], ptr %[[#RES_PTR:]])
-  // LLVM-NEXT:   %[[#INTRIN_RET:]] = call { i32, i1 } 
@llvm.uadd.with.overflow.i32(i32 %[[#LHS]], i32 %[[#RHS]])
-  // LLVM-NEXT:   %[[#RES:]] = extractvalue { i32, i1 } %[[#INTRIN_RET]], 0
-  // LLVM-NEXT:   %[[#OVFL:]] = extractvalue { i32, i1 } %[[#INTRIN_RET]], 1
-  // LLVM-NEXT:   store i32 %[[#RES]], ptr %[[#RES_PTR]], align 4
-  // LLVM-NEXT:   ret i1 %[[#OVFL]]
-  // LLVM-NEXT: }
-
-  cir.func @test_add_u32_u32_i32(%lhs: !u32i, %rhs: !u32i, %res: 
!cir.ptr) -> !cir.bool {
-%result, %overflow = cir.binop.overflow(add, %lhs, %rhs) : !u32i, (!s32i, 
!cir.bool)
-cir.store %result, %res : !s32i, !cir.ptr
-cir.return %overflow : !cir.bool
-  }
-
-  //  MLIR: llvm.func @test_add_u32_u32_i32(%[[LHS:.+]]: i32, %[[RHS:.+]]: 
i32, %[[RES_PTR:.+]]: !llvm.ptr) -> i1
-  // MLIR-NEXT:   %[[#LHS_EXT:]] = llvm.zext %[[LHS]] : i32 to i33
-  // MLIR-NEXT:   %[[#RHS_EXT:]] = llvm.zext %[[RHS]] : i32 to i33
-  // MLIR-NEXT:   %[[#INTRIN_RET:]] = llvm.call_intrinsic 
"llvm.sadd.with.overflow.i33"(%[[#LHS_EXT]], %[[#RHS_EXT]]) : (i33, i33) -> 
!llvm.struct<(i33, i1)>
-  // MLIR-NEXT:   %[[#RES_EXT:]] = llvm.extractvalue %[[#INTRIN_RET]][0] : 
!llvm.struct<(i33, i1)>
-  // MLIR-NEXT:   %[[#ARITH_OVFL:]] = llvm.extractvalue %[[#INTRIN_RET]][1] : 
!llvm.struct<(i33, i1)>
-  // MLIR-NEXT:   %[[#RES:]] = llvm.trunc %[[#RES_EXT]] : i33 to i32
-  // MLIR-NEXT:   %[[#RES_EXT_2:]] = llvm.sext %[[#RES]] : i32 to i33
-  // MLIR-NEXT:   %[[#TRUNC_OVFL:]] = llvm.icmp "ne" %[[#RES_EXT_2]], 
%[[#RES_EXT]] : i33
-  // MLIR-NEXT:   %[[#OVFL:]] = llvm.or %[[#ARITH_OVFL]], %[[#TRUNC_OVFL]]  : 
i1
-  // MLIR-NEXT:   llvm.store %[[#RES]], %[[RES_PTR]] {{.*}} : i32, !llvm.ptr
-  // MLIR-NEXT:   llvm.return %[[#OVFL]] : i1
-  // MLIR-NEXT: }
-
-  //  LLVM: define i1 @test_add_u32_u32_i32(i32 %[[#LHS:]], i32 
%[[#RHS:]], ptr %[[#RES_PTR:]])
-  // LLVM-NEXT:   %[[#LHS_EXT:]] = zext i32 %[[#LHS]] to i33
-  // LLVM-NEXT:   %[[#RHS_EXT:]] = zext i32 %[[#RHS]] to i33
-  // LLVM-NEXT:   %[[#INTRIN_RET:]] = call { i33, i1 } 
@llvm.sadd.with.overflow.i33(i33 %[[#LHS_EXT]], i33 %[[#RHS_EXT]])
-  // LLVM-NEXT:   %[[#RES_EXT:]] = extractvalue { i33, i1 } %[[#INTRIN_RET]], 0
-  // LLVM-NEXT:   %[[#ARITH_OVFL:]] = extractvalue { i33, i1 } 
%[[#INTRIN_RET]], 1
-  // LLVM-NEXT:   %[[#RES:]] = trunc i33 %[[#RES_EXT]] to i32
-  // LLVM-NEXT:   %[[#RES_EXT_2:]] = sext i32 %[[#RES]] to i33
-  // LLVM-NEXT:   %[[#TRUNC_OVFL:]] = icmp ne i33 %[[#RES_EXT_2]], 
%[[#RES_EXT]]
-  // LLVM-NEXT:   %[[#OVFL:]] = or i1 %[[#ARITH_OVFL]], %[[#TRUNC_OVFL]]
-  // LLVM-NEXT:   store i32 %[[#RES]], ptr %[[#RES_PTR]], align 4
-  // LLVM-NEXT:   ret i1 %[[#OVFL]]
-  // LLVM-NEXT: }
-}



_

[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

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


@@ -0,0 +1,81 @@
+//===--===//
+//
+// 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 "PassDetail.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Support/LogicalResult.h"
+#include "mlir/Transforms/DialectConversion.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+#include "clang/CIR/Dialect/Passes.h"
+#include "clang/CIR/MissingFeatures.h"
+#include "llvm/Support/TimeProfiler.h"
+
+using namespace mlir;
+using namespace cir;
+
+namespace {
+
+struct HoistAllocasPass : public HoistAllocasBase {
+
+  HoistAllocasPass() = default;
+  void runOnOperation() override;
+};
+
+static void process(mlir::ModuleOp mod, cir::FuncOp func) {
+  if (func.getRegion().empty())
+return;
+
+  // Hoist all static allocas to the entry block.
+  mlir::Block &entryBlock = func.getRegion().front();
+  llvm::SmallVector allocas;
+  func.getBody().walk([&](cir::AllocaOp alloca) {

andykaylor wrote:

I'll give this a try. The documentation for mlir::Block::walk says that I am 
allowed to erase operations from the block.

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


[clang] [clang-tools-extra] [clang] Consistently use "load" to refer to populating clang::ModuleMap (PR #132970)

2025-03-25 Thread Michael Spencer via cfe-commits

https://github.com/Bigcheese updated 
https://github.com/llvm/llvm-project/pull/132970

>From 1dca90893cd12709f7d3952b68b552fe93b19c5d Mon Sep 17 00:00:00 2001
From: Michael Spencer 
Date: Tue, 25 Mar 2025 11:14:46 -0700
Subject: [PATCH] [clang] Consistently use "load" to refer to populating
 clang::ModuleMap

Now that we have ModuleMapFile.cpp which parses module maps, it's
confusing what ModuleMap::parseModuleMapFile actually does.
HeaderSearch already called this loading a module map, so consistently
use that term in ModuleMap too.

An upcoming patch will allow just parsing a module map without loading
the modules from it.
---
 .../modularize/ModuleAssistant.cpp|  4 +-
 clang/include/clang/Lex/ModuleMap.h   | 20 +++---
 clang/lib/Lex/HeaderSearch.cpp|  4 +-
 clang/lib/Lex/ModuleMap.cpp   | 71 ++-
 4 files changed, 50 insertions(+), 49 deletions(-)

diff --git a/clang-tools-extra/modularize/ModuleAssistant.cpp 
b/clang-tools-extra/modularize/ModuleAssistant.cpp
index c7259d70bd58f..b4ec96617449f 100644
--- a/clang-tools-extra/modularize/ModuleAssistant.cpp
+++ b/clang-tools-extra/modularize/ModuleAssistant.cpp
@@ -129,8 +129,8 @@ Module *Module::findSubModule(llvm::StringRef SubName) {
 // Implementation functions:
 
 // Reserved keywords in module.modulemap syntax.
-// Keep in sync with keywords in module map parser in Lex/ModuleMap.cpp,
-// such as in ModuleMapParser::consumeToken().
+// Keep in sync with keywords in module map parser in Lex/ModuleMapFile.cpp,
+// such as in ModuleMapFileParser::consumeToken().
 static const char *const ReservedNames[] = {
   "config_macros", "export",   "module", "conflict", "framework",
   "requires",  "exclude",  "header", "private",  "explicit",
diff --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index 3baeea08cc0e3..43c3890631bd1 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -43,7 +43,7 @@ class FileManager;
 class HeaderSearch;
 class SourceManager;
 
-/// A mechanism to observe the actions of the module map parser as it
+/// A mechanism to observe the actions of the module map loader as it
 /// reads module map files.
 class ModuleMapCallbacks {
   virtual void anchor();
@@ -195,7 +195,7 @@ class ModuleMap {
   using AdditionalModMapsSet = llvm::DenseSet;
 
 private:
-  friend class ModuleMapParser;
+  friend class ModuleMapLoader;
 
   using HeadersMap = llvm::DenseMap>;
 
@@ -259,9 +259,9 @@ class ModuleMap {
 
   llvm::DenseMap AdditionalModMaps;
 
-  /// Describes whether we haved parsed a particular file as a module
+  /// Describes whether we haved loaded a particular file as a module
   /// map.
-  llvm::DenseMap ParsedModuleMap;
+  llvm::DenseMap LoadedModuleMap;
 
   /// Resolve the given export declaration into an actual export
   /// declaration.
@@ -693,10 +693,10 @@ class ModuleMap {
   void addHeader(Module *Mod, Module::Header Header,
  ModuleHeaderRole Role, bool Imported = false);
 
-  /// Parse the given module map file, and record any modules we
+  /// Load the given module map file, and record any modules we
   /// encounter.
   ///
-  /// \param File The file to be parsed.
+  /// \param File The file to be loaded.
   ///
   /// \param IsSystem Whether this module map file is in a system header
   /// directory, and therefore should be considered a system module.
@@ -713,10 +713,10 @@ class ModuleMap {
   ///that caused us to load this module map file, if any.
   ///
   /// \returns true if an error occurred, false otherwise.
-  bool parseModuleMapFile(FileEntryRef File, bool IsSystem,
-  DirectoryEntryRef HomeDir, FileID ID = FileID(),
-  unsigned *Offset = nullptr,
-  SourceLocation ExternModuleLoc = SourceLocation());
+  bool loadModuleMapFile(FileEntryRef File, bool IsSystem,
+ DirectoryEntryRef HomeDir, FileID ID = FileID(),
+ unsigned *Offset = nullptr,
+ SourceLocation ExternModuleLoc = SourceLocation());
 
   /// Dump the contents of the module map, for debugging purposes.
   void dump();
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index ad9263f2994f2..95f294238a0d4 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1783,7 +1783,7 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, 
bool IsSystem,
   if (!AddResult.second)
 return AddResult.first->second ? LMM_AlreadyLoaded : LMM_InvalidModuleMap;
 
-  if (ModMap.parseModuleMapFile(File, IsSystem, Dir, ID, Offset)) {
+  if (ModMap.loadModuleMapFile(File, IsSystem, Dir, ID, Offset)) {
 LoadedModuleMaps[File] = false;
 return LMM_InvalidModuleMap;
   }
@@ -1791,7 +1791,7 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, 
bool IsSystem,
   // Try to load a corresponding private

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

2025-03-25 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,183 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -O1 -o - | FileCheck %s
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   spirv-unknown-vulkan-compute %s -fnative-half-type \
+// RUN:   -emit-llvm -O1 -o - | FileCheck %s --check-prefix=SPVCHECK
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) half 
@_Z20test_smoothstep_halfDhDhDh(
+// CHECK-SAME: half noundef nofpclass(nan inf) [[MIN:%.*]], half noundef 
nofpclass(nan inf) [[MAX:%.*]], half noundef nofpclass(nan inf) [[X:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half 
[[X]], [[MIN]]
+// CHECK-NEXT:[[SUB1_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half 
[[MAX]], [[MIN]]
+// CHECK-NEXT:[[DIV_I:%.*]] = fdiv reassoc nnan ninf nsz arcp afn half 
[[SUB_I]], [[SUB1_I]]
+// CHECK-NEXT:[[HLSL_SATURATE_I:%.*]] = tail call reassoc nnan ninf nsz 
arcp afn half @llvm.dx.saturate.f16(half [[DIV_I]])
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half 
[[HLSL_SATURATE_I]], 0xH4000
+// CHECK-NEXT:[[SUB2_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn half 
0xH4200, [[MUL_I]]
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn half 
[[HLSL_SATURATE_I]], [[HLSL_SATURATE_I]]
+// CHECK-NEXT:[[MUL4_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn half 
[[TMP0]], [[SUB2_I]]
+// CHECK-NEXT:ret half [[MUL4_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) half 
@_Z20test_smoothstep_halfDhDhDh(
+// SPVCHECK-SAME: half noundef nofpclass(nan inf) [[MIN:%.*]], half noundef 
nofpclass(nan inf) [[MAX:%.*]], half noundef nofpclass(nan inf) [[X:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// SPVCHECK-NEXT:  [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[CONV_I:%.*]] = fpext reassoc nnan ninf nsz arcp afn 
half [[MIN]] to double
+// SPVCHECK-NEXT:[[CONV1_I:%.*]] = fpext reassoc nnan ninf nsz arcp afn 
half [[MAX]] to double
+// SPVCHECK-NEXT:[[CONV2_I:%.*]] = fpext reassoc nnan ninf nsz arcp afn 
half [[X]] to double
+// SPVCHECK-NEXT:[[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf 
nsz arcp afn double @llvm.spv.smoothstep.f64(double [[CONV_I]], double 
[[CONV1_I]], double [[CONV2_I]])
+// SPVCHECK-NEXT:[[CONV3_I:%.*]] = fptrunc reassoc nnan ninf nsz arcp afn 
double [[SPV_SMOOTHSTEP_I]] to half
+// SPVCHECK-NEXT:ret half [[CONV3_I]]
+//
+half test_smoothstep_half(half Min, half Max, half X) { return smoothstep(Min, 
Max, X); }
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <2 x half> 
@_Z21test_smoothstep_half2Dv2_DhS_S_(
+// CHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[MIN:%.*]], <2 x half> 
noundef nofpclass(nan inf) [[MAX:%.*]], <2 x half> noundef nofpclass(nan inf) 
[[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[SUB_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x 
half> [[X]], [[MIN]]
+// CHECK-NEXT:[[SUB1_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x 
half> [[MAX]], [[MIN]]
+// CHECK-NEXT:[[DIV_I:%.*]] = fdiv reassoc nnan ninf nsz arcp afn <2 x 
half> [[SUB_I]], [[SUB1_I]]
+// CHECK-NEXT:[[HLSL_SATURATE_I:%.*]] = tail call reassoc nnan ninf nsz 
arcp afn <2 x half> @llvm.dx.saturate.v2f16(<2 x half> [[DIV_I]])
+// CHECK-NEXT:[[MUL_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x 
half> [[HLSL_SATURATE_I]], splat (half 0xH4000)
+// CHECK-NEXT:[[SUB2_I:%.*]] = fsub reassoc nnan ninf nsz arcp afn <2 x 
half> splat (half 0xH4200), [[MUL_I]]
+// CHECK-NEXT:[[TMP0:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x 
half> [[HLSL_SATURATE_I]], [[HLSL_SATURATE_I]]
+// CHECK-NEXT:[[MUL4_I:%.*]] = fmul reassoc nnan ninf nsz arcp afn <2 x 
half> [[TMP0]], [[SUB2_I]]
+// CHECK-NEXT:ret <2 x half> [[MUL4_I]]
+//
+// SPVCHECK-LABEL: define spir_func noundef nofpclass(nan inf) <2 x half> 
@_Z21test_smoothstep_half2Dv2_DhS_S_(
+// SPVCHECK-SAME: <2 x half> noundef nofpclass(nan inf) [[MIN:%.*]], <2 x 
half> noundef nofpclass(nan inf) [[MAX:%.*]], <2 x half> noundef nofpclass(nan 
inf) [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// SPVCHECK-NEXT:  [[ENTRY:.*:]]
+// SPVCHECK-NEXT:[[SPV_SMOOTHSTEP_I:%.*]] = tail call reassoc nnan ninf 
nsz arcp afn noundef <2 x half> @llvm.spv.smoothstep.v2f16(<2 x half> [[MIN]], 
<2 x half> [[MAX]], <2 x half> [[X]])
+// SPVCHECK-NEXT:ret <2 x half> [[SPV_SMOOTHSTEP_I]]
+//
+half2 test_smoothstep_half2(half2 Min, half2 Max, half2 X) { return 
smoothstep(Min, Max, X); }
+
+// CHECK-LABEL: define noundef nofpclass(nan inf) <3 x half> 
@_Z21test_smoothstep_half3Dv3_DhS_S_(
+// CHECK-SAME: <3 x half> noundef nofpclass(nan inf) [[MIN:%.*]], <3 x half> 
noundef nofpclass(nan inf) [[MAX:%.*]], <3 x hal

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

2025-03-25 Thread Farzon Lotfi via cfe-commits


@@ -0,0 +1,43 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+
+// RUN: %clang_cc1 -O1 -triple spirv-pc-vulkan-compute %s -emit-llvm -o - | 
FileCheck %s
+
+typedef float float2 __attribute__((ext_vector_type(2)));
+typedef float float3 __attribute__((ext_vector_type(3)));
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+// CHECK-LABEL: define spir_func float @test_smoothstep_float(
+// CHECK-SAME: float noundef [[MIN:%.*]], float noundef [[MAX:%.*]], float 
noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[CONV:%.*]] = fpext float [[MIN]] to double
+// CHECK-NEXT:[[CONV1:%.*]] = fpext float [[MAX]] to double
+// CHECK-NEXT:[[CONV2:%.*]] = fpext float [[X]] to double
+// CHECK-NEXT:[[SPV_SMOOTHSTEP:%.*]] = tail call double 
@llvm.spv.smoothstep.f64(double [[CONV]], double [[CONV1]], double [[CONV2]])

farzonl wrote:

should be
`float @llvm.spv.smoothstep.f32(float [[MIN]], float [[Max]], float [[X]])`

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] [clang-tools-extra] Reland: [clang] NFC: Clear some uses of MemberPointerType::getClass (PR #132317)

2025-03-25 Thread Mike Hommey via cfe-commits

glandium wrote:

For the record, my reduced test case is:
```
namespace camera {
template  void GetChildAndCall(MEM_FUN);
struct CamerasChild {
  template 
  void ConnectDeviceListChangeListener(void (This::*)());
};
} // namespace camera
struct MediaEngineWebRTC {
  MediaEngineWebRTC();
};
using camera::CamerasChild;
using camera::GetChildAndCall;
MediaEngineWebRTC::MediaEngineWebRTC() {
  GetChildAndCall(
  &CamerasChild::ConnectDeviceListChangeListener);
}
```
and is fixed by #132977.

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-tools-extra] [clang] Consistently use "load" to refer to populating clang::ModuleMap (PR #132970)

2025-03-25 Thread Michael Spencer via cfe-commits

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


[clang] [webkit.RefCntblBaseVirtualDtor] Add support for NoVirtualDestructorBase. (PR #132497)

2025-03-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

This PR adds the support for WTF::NoVirtualDestructorBase, which signifies to 
the checker that the class is exempt from having a virtual destructor.

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


2 Files Affected:

- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
(+9-1) 
- (modified) 
clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp (+17) 


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index 77520f1f731c1..98c587d62978b 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -202,6 +202,13 @@ class RefCntblBaseVirtualDtorChecker
   if (!C)
 continue;
 
+  bool isExempt = T.getAsString() == "NoVirtualDestructorBase" &&
+  safeGetName(C->getParent()) == "WTF";
+  if (isExempt || ExemptDecls.contains(C)) {
+ExemptDecls.insert(RD);
+continue;
+  }
+
   if (auto *CTSD = dyn_cast(C)) {
 for (auto &Arg : CTSD->getTemplateArgs().asArray()) {
   if (Arg.getKind() != TemplateArgument::Type)
@@ -223,12 +230,13 @@ class RefCntblBaseVirtualDtorChecker
 
   llvm::SetVector Decls;
   llvm::DenseSet CRTPs;
+  llvm::DenseSet ExemptDecls;
 };
 
 LocalVisitor visitor(this);
 visitor.TraverseDecl(const_cast(TUD));
 for (auto *RD : visitor.Decls) {
-  if (visitor.CRTPs.contains(RD))
+  if (visitor.CRTPs.contains(RD) || visitor.ExemptDecls.contains(RD))
 continue;
   visitCXXRecordDecl(RD);
 }
diff --git 
a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp
index 5cf7e7614d06e..fd4144d572e01 100644
--- a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp
@@ -1,5 +1,13 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor 
-verify %s
 
+namespace WTF {
+
+class NoVirtualDestructorBase { };
+
+};
+
+using WTF::NoVirtualDestructorBase;
+
 struct RefCntblBase {
   void ref() {}
   void deref() {}
@@ -19,6 +27,15 @@ struct [[clang::suppress]] SuppressedDerivedWithVirtualDtor 
: RefCntblBase {
   virtual ~SuppressedDerivedWithVirtualDtor() {}
 };
 
+class ClassWithoutVirtualDestructor : public NoVirtualDestructorBase {
+public:
+  void ref() const;
+  void deref() const;
+};
+
+class DerivedClassWithoutVirtualDestructor : public 
ClassWithoutVirtualDestructor {
+};
+
 // FIXME: Support attributes on base specifiers? Currently clang
 // doesn't support such attributes at all, even though it knows
 // how to parse them.

``




https://github.com/llvm/llvm-project/pull/132497
___
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-25 Thread Aaron Ballman via cfe-commits


@@ -1076,13 +1076,11 @@ Language and Target-Independent Features
 Freestanding Builds
 ---
 Passing the ``-ffreestanding`` flag causes Clang to build for a freestanding
-(rather than a hosted) environment. The ``__STDC_HOSTED__`` predefined macro
-will expand to ``0`` in a freestanding environment. In such an environment,
-execution of the program may happen without an operating system and so a
-startup function (e.g., ``main``) may not be automatically called, though file
-scope objects which need to run startup code (constructors in C++,
-``__attribute__((constructor))``, etc) are executed via implementation-defined
-means such as ``__cxx_global_var_init``.
+(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``), and
+* unwind tables are disabled (``fno-asynchronous-unwind-tables 
-fno-unwind-tables``)

AaronBallman wrote:

Yup, I just added that because I missed your comments. :-)

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] [clang][DependencyScanning] Track dependencies from prebuilt modules to determine IsInStableDir (PR #132237)

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

cyndyishida wrote:

ping

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] [llvm] [HLSL] Implement the `smoothstep` intrinsic (PR #132288)

2025-03-25 Thread Farzon Lotfi via cfe-commits


@@ -101,6 +101,52 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(unsigned 
BuiltinID,
 TheCall->setType(RetTy);
 break;
   }
+  case SPIRV::BI__builtin_spirv_smoothstep: {
+if (SemaRef.checkArgCount(TheCall, 3))
+  return true;
+
+// check if the all arguments have floating representation
+ExprResult A = TheCall->getArg(0);

farzonl wrote:

it might be worth looping over the args and checking 
`hasFloatingRepresentation` for each arg to determing which diag to emit. Feel 
free to write a helper if you need it.

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] [compiler-rt] [llvm] [FMV][AArch64] Add feature CSSC and detect on linux platform. (PR #132727)

2025-03-25 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/132727

>From b61d23aa9950d24ca88780fbcc08935447e987fd Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Mon, 24 Mar 2025 12:15:58 +
Subject: [PATCH] [FMV][AArch64] Add feature CSSC and detect on linux platform.

Also removes priority bits for unused features predres and ls64.
---
 clang/test/CodeGen/AArch64/fmv-dependencies.c |   4 +
 clang/test/CodeGen/AArch64/fmv-detection.c| 375 +-
 .../builtins/cpu_model/AArch64CPUFeatures.inc |   2 +-
 .../builtins/cpu_model/aarch64/fmv/mrs.inc|   2 +
 .../lib/builtins/cpu_model/aarch64/hwcap.inc  |   3 +
 .../llvm/TargetParser/AArch64CPUFeatures.inc  |   2 +-
 .../TargetParser/AArch64FeatPriorities.inc|   5 +-
 llvm/lib/Target/AArch64/AArch64FMV.td |   1 +
 8 files changed, 209 insertions(+), 185 deletions(-)

diff --git a/clang/test/CodeGen/AArch64/fmv-dependencies.c 
b/clang/test/CodeGen/AArch64/fmv-dependencies.c
index 7cfab7de41a9d..7aaf143f2afc5 100644
--- a/clang/test/CodeGen/AArch64/fmv-dependencies.c
+++ b/clang/test/CodeGen/AArch64/fmv-dependencies.c
@@ -135,6 +135,9 @@ __attribute__((target_version("sve2-sm4"))) int fmv(void) { 
return 0; }
 // CHECK: define dso_local i32 @fmv._Mwfxt() #[[wfxt:[0-9]+]] {
 __attribute__((target_version("wfxt"))) int fmv(void) { return 0; }
 
+// CHECK: define dso_local i32 @fmv._Mcssc() #[[cssc:[0-9]+]] {
+__attribute__((target_version("cssc"))) int fmv(void) { return 0; }
+
 // CHECK-NOT: define dso_local i32 @fmv._M{{.*}}
 __attribute__((target_version("non_existent_extension"))) int fmv(void);
 
@@ -188,3 +191,4 @@ int caller() {
 // CHECK: attributes #[[sve2_sha3]] = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+outline-atomics,+sha2,+sha3,+sve,+sve2,+sve2-sha3,+v8a"
 // CHECK: attributes #[[sve2_sm4]] = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+outline-atomics,+sm4,+sve,+sve2,+sve2-sm4,+v8a"
 // CHECK: attributes #[[wfxt]] = { {{.*}} 
"target-features"="+fp-armv8,+neon,+outline-atomics,+v8a,+wfxt"
+// CHECK: attributes #[[cssc]] = { {{.*}} 
"target-features"="+cssc,+fp-armv8,+neon,+outline-atomics,+v8a"
diff --git a/clang/test/CodeGen/AArch64/fmv-detection.c 
b/clang/test/CodeGen/AArch64/fmv-detection.c
index 56de8136e55dd..44702a04e532e 100644
--- a/clang/test/CodeGen/AArch64/fmv-detection.c
+++ b/clang/test/CodeGen/AArch64/fmv-detection.c
@@ -13,6 +13,8 @@ __attribute__((target_version("bti"))) int fmv(void) { return 
0; }
 
 __attribute__((target_version("crc"))) int fmv(void) { return 0; }
 
+__attribute__((target_version("cssc"))) int fmv(void) { return 0; }
+
 __attribute__((target_version("dit"))) int fmv(void) { return 0; }
 
 __attribute__((target_version("dotprod"))) int fmv(void) { return 0; }
@@ -93,9 +95,7 @@ __attribute__((target_version("sve2-sm4"))) int fmv(void) { 
return 0; }
 
 __attribute__((target_version("wfxt"))) int fmv(void) { return 0; }
 
-// Test a version with multiple features. [Hint] Use the highest priority
-// feature so that the version remains at the top of the resolver body.
-__attribute__((target_version("mops+fp"))) int fmv(void);
+__attribute__((target_version("cssc+fp"))) int fmv(void);
 
 __attribute__((target_version("default"))) int fmv(void);
 
@@ -125,365 +125,373 @@ int caller() {
 // CHECK-NEXT:  resolver_entry:
 // CHECK-NEXT:call void @__init_cpu_features_resolver()
 // CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 576460752303423744
-// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 576460752303423744
+// CHECK-NEXT:[[TMP1:%.*]] = and i64 [[TMP0]], 2304
+// CHECK-NEXT:[[TMP2:%.*]] = icmp eq i64 [[TMP1]], 2304
 // CHECK-NEXT:[[TMP3:%.*]] = and i1 true, [[TMP2]]
 // CHECK-NEXT:br i1 [[TMP3]], label [[RESOLVER_RETURN:%.*]], label 
[[RESOLVER_ELSE:%.*]]
 // CHECK:   resolver_return:
-// CHECK-NEXT:ret ptr @fmv._MfpMmops
+// CHECK-NEXT:ret ptr @fmv._McsscMfp
 // CHECK:   resolver_else:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 576460752303423488
-// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 576460752303423488
+// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 2048
+// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 2048
 // CHECK-NEXT:[[TMP7:%.*]] = and i1 true, [[TMP6]]
 // CHECK-NEXT:br i1 [[TMP7]], label [[RESOLVER_RETURN1:%.*]], label 
[[RESOLVER_ELSE2:%.*]]
 // CHECK:   resolver_return1:
-// CHECK-NEXT:ret ptr @fmv._Mmops
+// CHECK-NEXT:ret ptr @fmv._Mcssc
 // CHECK:   resolver_else2:
 // CHECK-NEXT:[[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 144119586256651008
-// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 144119586256651008
+// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 5764607523

[clang] [C23] Implement WG14 N3037 (PR #132939)

2025-03-25 Thread Shafik Yaghmour via cfe-commits


@@ -156,11 +158,11 @@ struct StructuralEquivalenceTest : ::testing::Test {
 StructuralEquivalenceContext::NonEquivalentDeclSet NonEquivalentDecls01;
 StructuralEquivalenceContext::NonEquivalentDeclSet NonEquivalentDecls10;
 StructuralEquivalenceContext Ctx01(
-*S0.Context, *S1.Context, NonEquivalentDecls01,
-StructuralEquivalenceKind::Default, false, false);
+S0.Context->getLangOpts(), *S0.Context, *S1.Context,
+NonEquivalentDecls01, StructuralEquivalenceKind::Default, false, 
false);
 StructuralEquivalenceContext Ctx10(
-*S1.Context, *S0.Context, NonEquivalentDecls10,
-StructuralEquivalenceKind::Default, false, false);
+S1.Context->getLangOpts(), *S1.Context, *S0.Context,
+NonEquivalentDecls10, StructuralEquivalenceKind::Default, false, 
false);

shafik wrote:

```suggestion
NonEquivalentDecls10, StructuralEquivalenceKind::Default, 
/*StrictTypeSpelling=*/false, /*Complain=*/false);
```

https://github.com/llvm/llvm-project/pull/132939
___
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-25 Thread St. Muench via cfe-commits

https://github.com/stmuench updated 
https://github.com/llvm/llvm-project/pull/132924

>From 8b720d23c2c2252a709d9fd94a2f2fffe8d3fd87 Mon Sep 17 00:00:00 2001
From: stmuench 
Date: Tue, 25 Mar 2025 12:38:53 +0100
Subject: [PATCH] [clang-tidy] do not diagn. array types in implicit templ.
 instantiations

So far, the clang-tidy check `modernize-avoid-c-arrays` also diagnosed
array types for type template parameters even though no actual array
type got written there but it got deduced to one. In such case, there
is nothing a developer can do at that location to fix the diagnostic.
Since actually, the location where the template got instantiated
would have to be adjusted. And this is in most cases some totally
distant code where implementers of a template do not have access to.
Also adding suppressions to the declaration of the template is not an
option since that would clutter the code unnecessarily and is in many
cases also simply not possible. Hence, we propose to not diagnose any
occurrence of an array type in an implicit instantiation of a template
but rather at the point where template arguments involve array types.
---
 .../modernize/AvoidCArraysCheck.cpp   |  60 ++-
 .../avoid-c-arrays-ignores-strings.cpp|  12 ++
 .../checkers/modernize/avoid-c-arrays.cpp | 159 ++
 3 files changed, 227 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
index 0804aa76d953c..e26b8cf885ea3 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
@@ -39,6 +39,30 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
   return FD ? FD->isMain() : false;
 }
 
+bool isWithinImplicitTemplateInstantiation(const TypeLoc *ArrayType,
+   ASTContext *Context) {
+  const auto IsImplicitTemplateInstantiation = [](const auto *Node) {
+return (Node != nullptr) &&
+   (Node->getTemplateSpecializationKind() == 
TSK_ImplicitInstantiation);
+  };
+
+  auto ParentNodes = Context->getParents(*ArrayType);
+  while (!ParentNodes.empty()) {
+const auto &ParentNode = ParentNodes[0];
+if (IsImplicitTemplateInstantiation(
+ParentNode.template get()) ||
+IsImplicitTemplateInstantiation(
+ParentNode.template get()) ||
+IsImplicitTemplateInstantiation(
+ParentNode.template get())) {
+  return true;
+}
+ParentNodes = Context->getParents(ParentNode);
+  }
+
+  return false;
+}
+
 } // namespace
 
 AvoidCArraysCheck::AvoidCArraysCheck(StringRef Name, ClangTidyContext *Context)
@@ -70,18 +94,45 @@ void AvoidCArraysCheck::registerMatchers(MatchFinder 
*Finder) {
   std::move(IgnoreStringArrayIfNeededMatcher))
   .bind("typeloc"),
   this);
+
+  Finder->addMatcher(templateArgumentLoc(hasTypeLoc(
+ loc(arrayType()).bind("typeloc_in_template_arg"))),
+ this);
 }
 
 void AvoidCArraysCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *ArrayType = Result.Nodes.getNodeAs("typeloc");
+  clang::TypeLoc ArrayTypeLoc{};
+
+  if (const auto *ArrayType = Result.Nodes.getNodeAs("typeloc");
+  ArrayType != nullptr &&
+  not(isWithinImplicitTemplateInstantiation(ArrayType, Result.Context))) {
+ArrayTypeLoc = *ArrayType;
+  }
+
+  if (const auto *ArrayTypeInTemplateArg =
+  Result.Nodes.getNodeAs("typeloc_in_template_arg");
+  ArrayTypeInTemplateArg != nullptr) {
+if (ArrayTypeInTemplateArg->getSourceRange() !=
+ArrayTypeInTemplateArg->getLocalSourceRange()) {
+  // only in case the above condition is fulfilled, we matched a written
+  // array type and not a template type parameter which got deduced to one
+  ArrayTypeLoc = *ArrayTypeInTemplateArg;
+}
+  }
+
+  // check whether the match result is a real array type (based on above 
checks)
+  if (ArrayTypeLoc.isNull()) {
+return;
+  }
+
   const bool IsInParam =
   Result.Nodes.getNodeAs("param_decl") != nullptr;
-  const bool IsVLA = ArrayType->getTypePtr()->isVariableArrayType();
+  const bool IsVLA = ArrayTypeLoc.getTypePtr()->isVariableArrayType();
   enum class RecommendType { Array, Vector, Span };
   llvm::SmallVector RecommendTypes{};
   if (IsVLA) {
 RecommendTypes.push_back("'std::vector'");
-  } else if (ArrayType->getTypePtr()->isIncompleteArrayType() && IsInParam) {
+  } else if (ArrayTypeLoc.getTypePtr()->isIncompleteArrayType() && IsInParam) {
 // in function parameter, we also don't know the size of
 // IncompleteArrayType.
 if (Result.Context->getLangOpts().CPlusPlus20)
@@ -93,7 +144,8 @@ void AvoidCArraysCheck::check(const MatchFinder::MatchResult 
&Result) {
   } else {
 RecommendTypes.push_back("'std::array'");
   }
-  diag(ArrayType->getBeginLoc(),
+
+  diag(ArrayTypeLoc.getBeginLo

[clang] [Clang] Implement the core language parts of P2786 - Trivial relocation (PR #127636)

2025-03-25 Thread Louis Dionne via cfe-commits

https://github.com/ldionne commented:

I would like this patch to also deprecate the old builtin. I think the 
existence of the old builtin is going to cause significant confusion and risk 
introducing bugs. I always imagined that the old builtin would in fact be 
"fixed in place" once the Standard introduced the notion of TR, but I 
understand that introducing the Standard thing as a new name is probably better 
for backwards compatibility reasons. That being said, I would definitely want 
the old one to be deprecated with an explanation the very moment we introduce 
the new, Standards-conforming thing.

https://github.com/llvm/llvm-project/pull/127636
___
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-25 Thread Min-Yih Hsu via cfe-commits

mshockwave wrote:

> If only `CGBuiltin.cpp` and `ARM.cpp` is touched/updated, I see a large 
> difference

This. IMHO I think quality-of-life improvements on incremental build -- 
especially for LLVM developers -- is already a big thing that can justify this 
patch by itself.

Regarding the marginal difference on clean builds: my guess is that compilers 
might spend an even longer time on another source file(s) which dominate the 
total compilation time. 
To find out if this is true, IIRC clang's `-ftime-trace` can breakdown the time 
it spends on each input source files. It requires some data collection from the 
trace file though.

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] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)

2025-03-25 Thread Oliver Hunt via cfe-commits




ojhunt wrote:

No one commented on this test case, but for the record:

* It runs in both ms_bitfields and sane (:D) mode
* The static assertions are used to force struct layout
* We assert the structs are the same size or different sizes depending on 
layout mode, so we can then just ensure the structs with different layouts get 
warnings.

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


[clang] [clang-tools-extra] [clang] Consistently use "load" to refer to populating clang::ModuleMap (PR #132970)

2025-03-25 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`llvm-clang-x86_64-gcc-ubuntu` running on `sie-linux-worker3` while building 
`clang-tools-extra,clang` at step 5 "build-unified-tree".

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


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

```
Step 5 (build-unified-tree) failure: build (failure)
...
203.798 [513/34/400] Building CXX object 
tools/clang/lib/Interpreter/CMakeFiles/obj.clangInterpreter.dir/IncrementalParser.cpp.o
204.042 [512/34/401] Building CXX object 
tools/clang/lib/StaticAnalyzer/Checkers/CMakeFiles/obj.clangStaticAnalyzerCheckers.dir/WebKit/MemoryUnsafeCastChecker.cpp.o
204.813 [511/34/402] Linking CXX executable bin/clang-diff
205.507 [510/34/403] Building CXX object 
tools/clang/tools/extra/modularize/CMakeFiles/modularize.dir/PreprocessorTracker.cpp.o
205.589 [509/34/404] Building CXX object 
tools/clang/lib/Interpreter/CMakeFiles/obj.clangInterpreter.dir/CodeCompletion.cpp.o
206.562 [508/34/405] Building CXX object 
tools/clang/tools/clang-extdef-mapping/CMakeFiles/clang-extdef-mapping.dir/ClangExtDefMapGen.cpp.o
207.142 [507/34/406] Building CXX object 
tools/clang/lib/Interpreter/CMakeFiles/obj.clangInterpreter.dir/InterpreterValuePrinter.cpp.o
208.313 [506/34/407] Building CXX object 
tools/clang/tools/extra/clang-apply-replacements/tool/CMakeFiles/clang-apply-replacements.dir/ClangApplyReplacementsMain.cpp.o
208.383 [505/34/408] Building CXX object 
tools/clang/tools/clang-refactor/CMakeFiles/clang-refactor.dir/ClangRefactor.cpp.o
209.361 [504/34/409] Building CXX object 
tools/clang/tools/extra/modularize/CMakeFiles/modularize.dir/ModularizeUtilities.cpp.o
FAILED: 
tools/clang/tools/extra/modularize/CMakeFiles/modularize.dir/ModularizeUtilities.cpp.o
 
/opt/ccache/bin/g++ -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/tools/clang/tools/extra/modularize
 
-I/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/clang-tools-extra/modularize
 
-I/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/clang/include
 
-I/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/tools/clang/include
 -I/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/include 
-I/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/llvm/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings 
-Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long 
-Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess 
-Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -fdiagnostics-color -ffunction-sections 
-fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 
-DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT 
tools/clang/tools/extra/modularize/CMakeFiles/modularize.dir/ModularizeUtilities.cpp.o
 -MF 
tools/clang/tools/extra/modularize/CMakeFiles/modularize.dir/ModularizeUtilities.cpp.o.d
 -o 
tools/clang/tools/extra/modularize/CMakeFiles/modularize.dir/ModularizeUtilities.cpp.o
 -c 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/clang-tools-extra/modularize/ModularizeUtilities.cpp
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/clang-tools-extra/modularize/ModularizeUtilities.cpp:
 In member function ‘std::error_code 
Modularize::ModularizeUtilities::loadModuleMap(llvm::StringRef)’:
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/clang-tools-extra/modularize/ModularizeUtilities.cpp:293:15:
 error: ‘class clang::ModuleMap’ has no member named ‘parseModuleMapFile’; did 
you mean ‘loadModuleMapFile’?
  293 |   if (ModMap->parseModuleMapFile(ModuleMapEntry, false, Dir)) {
  |   ^~
  |   loadModuleMapFile
209.451 [504/33/410] Building CXX object 
tools/clang/tools/clang-check/CMakeFiles/clang-check.dir/ClangCheck.cpp.o
209.484 [504/32/411] Building CXX object 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/core_main.cpp.o
209.775 [504/31/412] Building CXX object 
tools/clang/tools/extra/clang-reorder-fields/tool/CMakeFiles/clang-reorder-fields.dir/ClangReorderFields.cpp.o
209.928 [504/30/413] Linking CXX executable bin/clang-extdef-mapping
210.696 [504/29/414] Building CXX object 
tools/clang/tools/clang-installapi/CMakeFiles/clang-installapi.dir/ClangInstallAPI.cpp.o
210.888 [504/28/415] Building CXX object 
tools/clang/tools/extra/clang-apply-replacements/CMakeFiles/obj.clangApplyReplacements.dir/lib/Tooling/ApplyReplacements.cpp.o
211.002 [504/27/416] Linking CXX exe

[clang] [clang-tools-extra] [clang] Consistently use "load" to refer to populating clang::ModuleMap (PR #132970)

2025-03-25 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-win` 
running on `sie-win-worker` while building `clang-tools-extra,clang` at step 6 
"build-unified-tree".

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


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

```
Step 6 (build-unified-tree) failure: build (failure)
...
[4105/4859] Building CXX object 
tools\clang\tools\extra\clang-tidy\readability\CMakeFiles\obj.clangTidyReadabilityModule.dir\DeleteNullPointerCheck.cpp.obj
[4106/4859] Building CXX object 
tools\clang\lib\StaticAnalyzer\Checkers\CMakeFiles\obj.clangStaticAnalyzerCheckers.dir\WebKit\RawPtrRefLocalVarsChecker.cpp.obj
[4107/4859] Building CXX object 
tools\clang\tools\extra\clang-reorder-fields\CMakeFiles\obj.clangReorderFields.dir\ReorderFieldsAction.cpp.obj
[4108/4859] Building CXX object 
tools\clang\tools\extra\clang-tidy\readability\CMakeFiles\obj.clangTidyReadabilityModule.dir\EnumInitialValueCheck.cpp.obj
[4109/4859] Building CXX object 
tools\clang\tools\extra\clang-tidy\readability\CMakeFiles\obj.clangTidyReadabilityModule.dir\FunctionCognitiveComplexityCheck.cpp.obj
[4110/4859] Linking CXX static library lib\clangReorderFields.lib
[4111/4859] Building CXX object 
tools\clang\tools\extra\clang-tidy\readability\CMakeFiles\obj.clangTidyReadabilityModule.dir\FunctionSizeCheck.cpp.obj
[4112/4859] Building CXX object 
tools\clang\tools\extra\clang-tidy\readability\CMakeFiles\obj.clangTidyReadabilityModule.dir\IdentifierLengthCheck.cpp.obj
[4113/4859] Building CXX object 
tools\clang\lib\StaticAnalyzer\Checkers\CMakeFiles\obj.clangStaticAnalyzerCheckers.dir\WebKit\ForwardDeclChecker.cpp.obj
[4114/4859] Building CXX object 
tools\clang\tools\extra\modularize\CMakeFiles\modularize.dir\ModularizeUtilities.cpp.obj
FAILED: 
tools/clang/tools/extra/modularize/CMakeFiles/modularize.dir/ModularizeUtilities.cpp.obj
 
C:\bin\ccache.exe 
C:\PROGRA~2\MICROS~1\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\HostX64\x64\cl.exe
  /nologo /TP -DCLANG_BUILD_STATIC -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC 
-DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS 
-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS 
-D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS 
-D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS -Itools\clang\tools\extra\modularize 
-IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\clang-tools-extra\modularize 
-IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\include 
-Itools\clang\include -Iinclude 
-IZ:\b\llvm-clang-x86_64-sie-win\llvm-project\llvm\include /DWIN32 /D_WINDOWS   
/Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 
-wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 
-wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 
-wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 
-wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 
/Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes 
/Fotools\clang\tools\extra\modularize\CMakeFiles\modularize.dir\ModularizeUtilities.cpp.obj
 /Fdtools\clang\tools\extra\modularize\CMakeFiles\modularize.dir\ /FS -c 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang-tools-extra\modularize\ModularizeUtilities.cpp
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang-tools-extra\modularize\ModularizeUtilities.cpp(293):
 error C2039: 'parseModuleMapFile': is not a member of 'clang::ModuleMap'
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\include\clang/Lex/ModuleMap.h(74):
 note: see declaration of 'clang::ModuleMap'
[4115/4859] Building CXX object 
tools\clang\tools\extra\clang-tidy\readability\CMakeFiles\obj.clangTidyReadabilityModule.dir\ImplicitBoolConversionCheck.cpp.obj
[4116/4859] Linking CXX executable bin\clang-import-test.exe
[4117/4859] Building CXX object 
tools\clang\tools\clang-diff\CMakeFiles\clang-diff.dir\ClangDiff.cpp.obj
[4118/4859] Building CXX object 
tools\clang\tools\clang-extdef-mapping\CMakeFiles\clang-extdef-mapping.dir\ClangExtDefMapGen.cpp.obj
[4119/4859] Building CXX object 
tools\clang\tools\clang-check\CMakeFiles\clang-check.dir\ClangCheck.cpp.obj
[4120/4859] Linking CXX executable bin\clang-reorder-fields.exe
[4121/4859] Building CXX object 
tools\clang\tools\extra\clang-apply-replacements\CMakeFiles\obj.clangApplyReplacements.dir\lib\Tooling\ApplyReplacements.cpp.obj
[4122/4859] Building CXX object 
tools\clang\tools\clang-installapi\CMakeFiles\clang-installapi.dir\ClangInstallAPI.cpp.obj
[4123/4859] Building CXX object 
tools\clang\tools\extra\clang-tidy\cppcoreguidelines\CMakeFiles\obj.clangTidyCppCoreGuidelinesModule.dir\InitVariablesCheck.cpp.obj
[4124/4859] Building CXX object 
tools\clang\tools\extra\clang-tidy\cppcoreguidelines\CMakeFiles\obj.clangTidyCppCoreGuidelinesModule.dir\MacroUsageCheck.cpp.obj

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

2025-03-25 Thread Farzon Lotfi via cfe-commits


@@ -322,5 +322,53 @@ reflect(__detail::HLSL_FIXED_VECTOR I,
 __detail::HLSL_FIXED_VECTOR N) {
   return __detail::reflect_vec_impl(I, N);
 }
+
+//===--===//
+// smoothstep builtin
+//===--===//
+
+/// \fn T smoothstep(T Min, T Max, T X)
+/// \brief Returns a smooth Hermite interpolation between 0 and 1, if \a X is 
in
+/// the range [\a Min, \a Max].
+/// \param Min The minimum range of the x parameter.
+/// \param Max The maximum range of the x parameter.
+/// \param X The specified value to be interpolated.
+///
+/// The return value is 0.0 if \a X ≤ \a Min and 1.0 if \a X ≥ \a Max. When \a
+/// Min < \a X < \a Max, the function performs smooth Hermite interpolation
+/// between 0 and 1.
+
+template 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+const inline __detail::enable_if_t<__detail::is_arithmetic::Value &&
+   __detail::is_same::value,
+   T> smoothstep(T Min, T Max, T X) {
+  return __detail::smoothstep_impl(Min, Max, X);
+}
+
+template 
+const inline __detail::enable_if_t<

farzonl wrote:

the clang format seems very different than the half case. See if you can get 
these to look a little closer.

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] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-25 Thread via cfe-commits


@@ -0,0 +1,145 @@
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fcoroutines -fexceptions -Wall -Wpedantic
+
+
+#include "Inputs/std-coroutine.h"
+
+namespace std {
+   template  struct type_identity {
+   typedef T type;
+   };
+   typedef __SIZE_TYPE__ size_t;
+   enum class align_val_t : size_t {};
+}
+
+struct Allocator {};
+
+struct resumable {
+  struct promise_type {
+void *operator new(std::type_identity, std::size_t sz, 
std::align_val_t, int); // #resumable_tan1
+void *operator new(std::type_identity, std::size_t sz, 
std::align_val_t, float); // #resumable_tan2
+void operator delete(std::type_identity, void *, std::size_t 
sz, std::align_val_t); // #resumable_tad1
+template  void operator delete(std::type_identity, void *, 
std::size_t sz, std::align_val_t) = delete; // #resumable_tad2
+
+resumable get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+
+struct resumable2 {
+  struct promise_type {
+template  void *operator 
new(std::type_identity, std::size_t sz, std::align_val_t, 
Args...); // #resumable2_tan1
+void operator delete(std::type_identity, void *, std::size_t 
sz, std::align_val_t); // #resumable2_tad2
+
+resumable2 get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+
+
+struct resumable3 {
+  struct promise_type {
+  // expected-error@-1 {{declaration of type aware 'operator new' in 
'resumable3::promise_type' must have matching type aware 'operator delete'}}
+  // expected-note@#resumable3_tan {{unmatched type aware 'operator new' 
declared here}}
+void *operator new(std::size_t sz, float);
+void *operator new(std::type_identity, std::size_t sz, 
std::align_val_t, float); // #resumable3_tan
+void operator delete(void *);
+
+resumable3 get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+struct resumable4 {
+  struct promise_type {
+// expected-error@-1 {{declaration of type aware 'operator delete' in 
'resumable4::promise_type' must have matching type aware 'operator new'}}
+// expected-note@#resumable4_tad {{unmatched type aware 'operator delete' 
declared here}}
+void *operator new(std::size_t sz, float);
+template  void operator delete(std::type_identity, void *, 
std::size_t, std::align_val_t); // #resumable4_tad
+
+resumable4 get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+struct resumable5 {
+  struct promise_type {
+// expected-error@-1 {{declaration of type aware 'operator delete' in 
'resumable5::promise_type' must have matching type aware 'operator new'}}
+// expected-note@#resumable5_tad {{unmatched type aware 'operator delete' 
declared here}}
+void *operator new(std::size_t sz, float);
+void operator delete(void *);
+template  void operator delete(std::type_identity, void *, 
std::size_t, std::align_val_t); // #resumable5_tad
+
+resumable5 get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+
+resumable f1(int) {
+  // expected-error@-1 {{'operator new' provided by 
'std::coroutine_traits::promise_type' (aka 
'resumable::promise_type') is not usable with the function signature of 'f1'}}
+  // expected-note@-2 {{type aware 'operator new' will not be used for 
coroutine allocation}}
+  // expected-note@#resumable_tan1 {{type aware 'operator new' declared here}}
+  // expected-note@#resumable_tan2 {{type aware 'operator new' declared here}}
+  co_return;
+}
+
+resumable f2(float) {
+  // expected-error@-1 {{'operator new' provided by 
'std::coroutine_traits::promise_type' (aka 
'resumable::promise_type') is not usable with the function signature of 'f2'}}
+  // expected-note@-2 {{type aware 'operator new' will not be used for 
coroutine allocation}}
+  // expected-note@#resumable_tan1 {{type aware 'operator new' declared here}}
+  // expected-note@#resumable_tan2 {{type aware 'operator ne

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

2025-03-25 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/16] [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] [HLSL][NFC] Refactor HLSLExternalSemaSource (PR #131032)

2025-03-25 Thread Ashley Coleman via cfe-commits


@@ -0,0 +1,96 @@
+//===--- HLSLBuiltinTypeDeclBuilder.h - 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
+//
+//===--===//
+//
+//
+//===--===//

V-FEXrt wrote:

this needs an ifdef/pragma once to ensure its not included multiple times right?

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


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

2025-03-25 Thread via cfe-commits


@@ -16298,6 +16396,70 @@ bool Sema::CompleteConstructorCall(CXXConstructorDecl 
*Constructor,
   return Invalid;
 }
 
+bool Sema::isTypeAwareOperatorNewOrDelete(const NamedDecl *ND) const {
+  const FunctionDecl *FnDecl = nullptr;
+  if (auto *FTD = dyn_cast(ND))
+FnDecl = FTD->getTemplatedDecl();
+  else if (auto *FD = dyn_cast(ND))
+FnDecl = FD;
+

cor3ntin wrote:

```suggestion
const FunctionDecl *FnDecl = FD->getAsFunction();
```

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


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

2025-03-25 Thread Jan Svoboda 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);

jansvoboda11 wrote:

Ok, got it.

What's confusing to me is that `Filename` is essentially 
`"/"`, which doesn't mean anything. 
And `ExternalFilename` is just ``, which is unresolved.

Why don't we split `Blob` like we do elsewhere (`Blob.substr(0, 
AsRequestedLength)` and `Blob.substr(AsRequestedLength)`) and call 
`ResolveImportedPath()` on both?

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] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-25 Thread via cfe-commits


@@ -3134,6 +3134,31 @@ bool Type::isStdByteType() const {
   return false;
 }
 
+bool Type::isDestroyingDeleteT() const {
+  auto *RD = getAsCXXRecordDecl();
+  return RD && RD->isInStdNamespace() && RD->getIdentifier() &&
+ RD->getIdentifier()->isStr("destroying_delete_t");
+}
+
+TemplateDecl *Type::getSpecializedTemplateDecl() const {
+  auto UnderlyingType = getCanonicalTypeInternal();
+  if (auto *TST = UnderlyingType->getAs())
+return TST->getTemplateName().getAsTemplateDecl();
+  if (auto *RT = UnderlyingType->getAsCXXRecordDecl()) {
+if (auto *CTSD = dyn_cast(RT))
+  return CTSD->getSpecializedTemplate();
+  }
+  return nullptr;
+}
+
+bool Type::isTypeIdentitySpecialization() const {
+  const TemplateDecl *STDecl = getSpecializedTemplateDecl();
+  if (!STDecl)
+return false;
+  IdentifierInfo *II = STDecl->getIdentifier();
+  return STDecl->isInStdNamespace() && II->isStr("type_identity");
+}
+

cor3ntin wrote:

Never mind, at this point, the identifier name would have been expanded, so we 
actually don't need to mess with the preprocessor. 


So this is fine as it is (I still question whether it is useful to have these 
function types they are only useful in a few places

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


[clang] [C23] Implement WG14 N3037 (PR #132939)

2025-03-25 Thread Shafik Yaghmour via cfe-commits


@@ -2080,9 +2090,9 @@ TEST_F(StructuralEquivalenceCacheTest, TemplateParmDepth) 
{
   EXPECT_FALSE(isInNonEqCache(std::make_pair(NonEqDecl0, NonEqDecl1), true));
 
   StructuralEquivalenceContext Ctx_IgnoreTemplateParmDepth(
-  get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
-  NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false,
-  false, true);
+  get<0>(TU)->getASTContext().getLangOpts(), get<0>(TU)->getASTContext(),
+  get<1>(TU)->getASTContext(), NonEquivalentDecls,
+  StructuralEquivalenceKind::Default, false, false, false, true);

shafik wrote:

```suggestion
  StructuralEquivalenceKind::Default, /*StrictTypeSpelling=*/false, 
/*Complain=*/false, /*ErrorOnTagTypeMismatch=*/false, 
/*IgnoreTemplateParmDepth=*/true);
```

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


[clang] [C23] Implement WG14 N3037 (PR #132939)

2025-03-25 Thread Shafik Yaghmour via cfe-commits


@@ -11432,6 +11433,22 @@ static QualType mergeEnumWithInteger(ASTContext 
&Context, const EnumType *ET,
   return {};
 }
 
+QualType ASTContext::mergeTagTypes(QualType LHS, QualType RHS) {
+  // C17 and earlier and C++ disallow two tag definitions within the same TU
+  // from being compatible.
+  if (LangOpts.CPlusPlus || !LangOpts.C23)
+return {};
+
+  // C23, on the other hand, requires the members to be "the same enough", so
+  // we use a structural equivalence check.
+  StructuralEquivalenceContext::NonEquivalentDeclSet NonEquivalentDecls;
+  StructuralEquivalenceContext Ctx(
+  getLangOpts(), *this, *this, NonEquivalentDecls,
+  StructuralEquivalenceKind::Default, /*StrictTypeSpelling*/ false,
+  /*Complain*/ false, /*ErrorOnTagTypeMismatch*/ true);

shafik wrote:

```suggestion
  StructuralEquivalenceKind::Default, /*StrictTypeSpelling=*/false,
  /*Complain=*/false, /*ErrorOnTagTypeMismatch*=/true);
```

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


[clang] [C23] Implement WG14 N3037 (PR #132939)

2025-03-25 Thread Shafik Yaghmour via cfe-commits


@@ -2003,8 +2012,9 @@ TEST_F(StructuralEquivalenceCacheTest, Cycle) {
   Lang_CXX03);
 
   StructuralEquivalenceContext Ctx(
-  get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
-  NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+  get<0>(TU)->getASTContext().getLangOpts(), get<0>(TU)->getASTContext(),
+  get<1>(TU)->getASTContext(), NonEquivalentDecls,
+  StructuralEquivalenceKind::Default, false, false);

shafik wrote:

```suggestion
  StructuralEquivalenceKind::Default, /*StrictTypeSpelling=*/false, 
/*Complain=*/false);
```

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


  1   2   3   4   5   6   >