[clang] bc546ca - [clang][NFC] Clean up ASTContext.cpp (#140847)

2025-05-21 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-05-21T09:09:41+02:00
New Revision: bc546cabe5381c3f047dcb8004cdf3cf81c10461

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

LOG: [clang][NFC] Clean up ASTContext.cpp (#140847)

Use BuiltinType::{isInteger,isSignedInteger,isUnsignedInteger} instead
of doing the comparisons here.

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 5c8c0e1cf1d00..9f098edfc08ae 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -8583,8 +8583,7 @@ bool IsEnumDeclScoped(EnumDecl *);
 
 inline bool Type::isIntegerType() const {
   if (const auto *BT = dyn_cast(CanonicalType))
-return BT->getKind() >= BuiltinType::Bool &&
-   BT->getKind() <= BuiltinType::Int128;
+return BT->isInteger();
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
 // FIXME: In C++, enum types are never integer types.
@@ -8658,8 +8657,7 @@ inline bool Type::isScalarType() const {
 
 inline bool Type::isIntegralOrEnumerationType() const {
   if (const auto *BT = dyn_cast(CanonicalType))
-return BT->getKind() >= BuiltinType::Bool &&
-   BT->getKind() <= BuiltinType::Int128;
+return BT->isInteger();
 
   // Check for a complete enum type; incomplete enum types are not properly an
   // enumeration type in the sense required here.

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 5d7a4bef8d995..ccacaf29e001f 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2108,8 +2108,7 @@ bool Type::hasIntegerRepresentation() const {
 /// \returns true if the type is considered an integral type, false otherwise.
 bool Type::isIntegralType(const ASTContext &Ctx) const {
   if (const auto *BT = dyn_cast(CanonicalType))
-return BT->getKind() >= BuiltinType::Bool &&
-   BT->getKind() <= BuiltinType::Int128;
+return BT->isInteger();
 
   // Complete enum types are integral in C.
   if (!Ctx.getLangOpts().CPlusPlus)
@@ -2121,8 +2120,7 @@ bool Type::isIntegralType(const ASTContext &Ctx) const {
 
 bool Type::isIntegralOrUnscopedEnumerationType() const {
   if (const auto *BT = dyn_cast(CanonicalType))
-return BT->getKind() >= BuiltinType::Bool &&
-   BT->getKind() <= BuiltinType::Int128;
+return BT->isInteger();
 
   if (isBitIntType())
 return true;
@@ -2211,10 +2209,8 @@ bool Type::isUnicodeCharacterType() const {
 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
 /// an enum decl which has a signed representation
 bool Type::isSignedIntegerType() const {
-  if (const auto *BT = dyn_cast(CanonicalType)) {
-return BT->getKind() >= BuiltinType::Char_S &&
-   BT->getKind() <= BuiltinType::Int128;
-  }
+  if (const auto *BT = dyn_cast(CanonicalType))
+return BT->isSignedInteger();
 
   if (const EnumType *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
@@ -2232,15 +2228,12 @@ bool Type::isSignedIntegerType() const {
 }
 
 bool Type::isSignedIntegerOrEnumerationType() const {
-  if (const auto *BT = dyn_cast(CanonicalType)) {
-return BT->getKind() >= BuiltinType::Char_S &&
-   BT->getKind() <= BuiltinType::Int128;
-  }
+  if (const auto *BT = dyn_cast(CanonicalType))
+return BT->isSignedInteger();
 
-  if (const auto *ET = dyn_cast(CanonicalType)) {
-if (ET->getDecl()->isComplete())
-  return ET->getDecl()->getIntegerType()->isSignedIntegerType();
-  }
+  if (const auto *ET = dyn_cast(CanonicalType);
+  ET && ET->getDecl()->isComplete())
+return ET->getDecl()->getIntegerType()->isSignedIntegerType();
 
   if (const auto *IT = dyn_cast(CanonicalType))
 return IT->isSigned();
@@ -2261,10 +2254,8 @@ bool Type::hasSignedIntegerRepresentation() const {
 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
 /// decl which has an unsigned representation
 bool Type::isUnsignedIntegerType() const {
-  if (const auto *BT = dyn_cast(CanonicalType)) {
-return BT->getKind() >= BuiltinType::Bool &&
-   BT->getKind() <= BuiltinType::UInt128;
-  }
+  if (const auto *BT = dyn_cast(CanonicalType))
+return BT->isUnsignedInteger();
 
   if (const auto *ET = dyn_cast(CanonicalType)) {
 // Incomplete enum types are not treated as integer types.
@@ -2282,15 +2273,12 @@ bool Type::isUnsignedIntegerType() const {
 }
 
 bool Type::isUnsignedIntegerOrEnumerationType() const {
-  if (const auto *BT = dyn_cast(CanonicalType)) {
-return BT->getKind() >= BuiltinType::Bool &&
-   BT->getKind() <= BuiltinType::UInt128;
-  }
+  if (const auto

[clang] [clang][NFC] Clean up ASTContext.cpp (PR #140847)

2025-05-21 Thread Timm Baeder via cfe-commits

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


[clang] [Clang] Fix a regression introduced by #140576 (PR #140859)

2025-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

Lambda bodies should not be treated as subexpressions of the enclosing scope.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaExpr.cpp (+2-3) 
- (modified) clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp (+8) 


``diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b18e83b605e4f..5e06c4bf89766 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1,13 +1,12 @@ void Sema::PushExpressionEvaluationContextForFunction(
 Current.InImmediateEscalatingFunctionContext =
 getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
 
-if (isLambdaMethod(FD)) {
-  Current.InDiscardedStatement = Parent.isDiscardedStatementContext();
+if (isLambdaMethod(FD))
   Current.InImmediateFunctionContext =
   FD->isConsteval() ||
   (isLambdaMethod(FD) && (Parent.isConstantEvaluated() ||
   Parent.isImmediateFunctionContext()));
-} else {
+else
   Current.InImmediateFunctionContext = FD->isConsteval();
 }
   }
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
index 20125cc5d4a9c..054defc3470e7 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -208,6 +208,14 @@ void test() {
 
 }
 }
+
+void regression() {
+  if constexpr (false) {
+auto lam = []() { return 0; };
+1 | lam();
+  }
+}
+
 }
 
 #endif

``




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


[clang] [Clang] Fix a regression introduced by #140576 (PR #140859)

2025-05-21 Thread via cfe-commits

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

Lambda bodies should not be treated as subexpressions of the enclosing scope.

>From f5e126d72bf6516ed36cfddce862af858968310f Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 21 May 2025 09:12:52 +0200
Subject: [PATCH] [Clang] Fix a regression introduced by #140576

Lambda bodies should not be treated as subexpressions of the
enclosing scope.
---
 clang/lib/Sema/SemaExpr.cpp | 5 ++---
 clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp | 8 
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b18e83b605e4f..5e06c4bf89766 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1,13 +1,12 @@ void Sema::PushExpressionEvaluationContextForFunction(
 Current.InImmediateEscalatingFunctionContext =
 getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
 
-if (isLambdaMethod(FD)) {
-  Current.InDiscardedStatement = Parent.isDiscardedStatementContext();
+if (isLambdaMethod(FD))
   Current.InImmediateFunctionContext =
   FD->isConsteval() ||
   (isLambdaMethod(FD) && (Parent.isConstantEvaluated() ||
   Parent.isImmediateFunctionContext()));
-} else {
+else
   Current.InImmediateFunctionContext = FD->isConsteval();
 }
   }
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
index 20125cc5d4a9c..054defc3470e7 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -208,6 +208,14 @@ void test() {
 
 }
 }
+
+void regression() {
+  if constexpr (false) {
+auto lam = []() { return 0; };
+1 | lam();
+  }
+}
+
 }
 
 #endif

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


[clang] [llvm] [UBSan] Implement src:*=sanitize for UBSan (PR #140529)

2025-05-21 Thread Vitaly Buka via cfe-commits


@@ -63,6 +63,11 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, 
unsigned LineNumber,
.moveInto(Pair.first))
   return Err;
 Pair.second = LineNumber;
+  } else {

vitalybuka wrote:

Please move llvm/lib/Support/SpecialCaseList.cpp and 
llvm/unittests/Support/SpecialCaseListTest.cpp into a separate list

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


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-21 Thread Nicolas van Kempen via cfe-commits


@@ -39,23 +38,6 @@ class UseTrailingReturnTypeCheck : public ClangTidyCheck {
 
 private:
   Preprocessor *PP = nullptr;

nicovank wrote:

Is this field still needed now?

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


[clang] d50c85d - [analyzer][NFC] Move PrettyStackTraceLocationContext into dispatchWorkItem (#140035)

2025-05-21 Thread via cfe-commits

Author: Balázs Benics
Date: 2025-05-21T08:10:35+02:00
New Revision: d50c85df255c6f0ba195bcf3f9c5236120e3984d

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

LOG: [analyzer][NFC] Move PrettyStackTraceLocationContext into dispatchWorkItem 
(#140035)

[analyzer][NFC] Move PrettyStackTraceLocationContext into
dispatchWorkItem

This change helps with ensuring that the abstract machine call stack is
only dumped exactly once no matter what checker callback we have the
crash in.

Note that `check::EndAnalysis` callbacks are resolved outside of
`dispatchWorkItem`, but that's the only checker callback that is outside
of `dispatchWorkItem`.

CPP-6476

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 2e6631f2f620c..8cc086a12ad70 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -12,6 +12,7 @@
 
//===--===//
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h"
+#include "PrettyStackTraceLocationContext.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Stmt.h"
@@ -216,6 +217,7 @@ void CoreEngine::dispatchWorkItem(ExplodedNode *Pred, 
ProgramPoint Loc,
   llvm::TimeTraceScope tcs{timeTraceScopeName(Loc), [Loc, Pred]() {
  return timeTraceMetadata(Pred, Loc);
}};
+  PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
   // Dispatch on the location type.
   switch (Loc.getKind()) {
 case ProgramPoint::BlockEdgeKind:

diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index ebad83dad0c8f..1afd4b52eb354 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -968,7 +968,6 @@ void ExprEngine::processEndWorklist() {
 
 void ExprEngine::processCFGElement(const CFGElement E, ExplodedNode *Pred,
unsigned StmtIdx, NodeBuilderContext *Ctx) {
-  PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
   currStmtIdx = StmtIdx;
   currBldrCtx = Ctx;
 
@@ -2541,7 +2540,6 @@ static const LocationContext 
*getInlinedLocationContext(ExplodedNode *Node,
 void ExprEngine::processCFGBlockEntrance(const BlockEdge &L,
  NodeBuilderWithSinks &nodeBuilder,
  ExplodedNode *Pred) {
-  PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
   // If we reach a loop which has a known bound (and meets
   // other constraints) then consider completely unrolling it.
   if(AMgr.options.ShouldUnrollLoops) {
@@ -2808,8 +2806,6 @@ void ExprEngine::processBranch(
 std::optional IterationsCompletedInLoop) {
   assert((!Condition || !isa(Condition)) &&
  "CXXBindTemporaryExprs are handled by processBindTemporary.");
-  const LocationContext *LCtx = Pred->getLocationContext();
-  PrettyStackTraceLocationContext StackCrashInfo(LCtx);
   currBldrCtx = &BldCtx;
 
   // Check for NULL conditions; e.g. "for(;;)"
@@ -2935,13 +2931,9 @@ void ExprEngine::processBranch(
 REGISTER_TRAIT_WITH_PROGRAMSTATE(InitializedGlobalsSet,
  llvm::ImmutableSet)
 
-void ExprEngine::processStaticInitializer(const DeclStmt *DS,
-  NodeBuilderContext &BuilderCtx,
-  ExplodedNode *Pred,
-  ExplodedNodeSet &Dst,
-  const CFGBlock *DstT,
-  const CFGBlock *DstF) {
-  PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
+void ExprEngine::processStaticInitializer(
+const DeclStmt *DS, NodeBuilderContext &BuilderCtx, ExplodedNode *Pred,
+ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF) {
   currBldrCtx = &BuilderCtx;
 
   const auto *VD = cast(DS->getSingleDecl());
@@ -3064,9 +3056,6 @@ void ExprEngine::processEndOfFunction(NodeBuilderContext& 
BC,
   assert(areAllObjectsFullyConstructed(Pred->getState(),
Pred->getLocationContext(),
Pred->getStackFrame()->getParent()));
-
-  PrettyStackTraceLocationContext CrashInfo(Pred->getLocationContext());
-
   ExplodedNodeSet Dst;
   if (Pred->getLocationContext()->inTopFrame()) {
 // Remove dead symbo

[clang] [analyzer][NFC] Move PrettyStackTraceLocationContext into dispatchWorkItem (PR #140035)

2025-05-21 Thread Balázs Benics via cfe-commits

https://github.com/balazs-benics-sonarsource closed 
https://github.com/llvm/llvm-project/pull/140035
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Fix a regression introduced by #140576 (PR #140859)

2025-05-21 Thread via cfe-commits

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

>From 1e7330b89327ea02271d54349ab3b01b8a495805 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 21 May 2025 09:12:52 +0200
Subject: [PATCH] [Clang] Fix a regression introduced by #140576

Lambda bodies should not be treated as subexpressions of the
enclosing scope.
---
 clang/lib/Sema/SemaExpr.cpp | 6 ++
 clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp | 8 
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b18e83b605e4f..66dac21bf5818 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1,15 +1,13 @@ void Sema::PushExpressionEvaluationContextForFunction(
 Current.InImmediateEscalatingFunctionContext =
 getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
 
-if (isLambdaMethod(FD)) {
-  Current.InDiscardedStatement = Parent.isDiscardedStatementContext();
+if (isLambdaMethod(FD))
   Current.InImmediateFunctionContext =
   FD->isConsteval() ||
   (isLambdaMethod(FD) && (Parent.isConstantEvaluated() ||
   Parent.isImmediateFunctionContext()));
-} else {
+else
   Current.InImmediateFunctionContext = FD->isConsteval();
-}
   }
 }
 
diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
index 20125cc5d4a9c..ac21e36daf870 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -208,6 +208,14 @@ void test() {
 
 }
 }
+
+void regression() {
+  if constexpr (false) {
+auto lam = []() { return 0; };
+1 | lam(); // expected-warning {{unused}}
+  }
+}
+
 }
 
 #endif

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


[clang-tools-extra] 5bd3c44 - [clang-tools-extra] Remove redundant control flow statements (NFC) (#140846)

2025-05-21 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-21T00:29:17-07:00
New Revision: 5bd3c44b79d2ebfe3def8f5476c07689e6f76839

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

LOG: [clang-tools-extra] Remove redundant control flow statements (NFC) 
(#140846)

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
index e0b9939681794..b4a157c153bb9 100644
--- a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
@@ -70,7 +70,6 @@ static void cleanInitialValue(DiagnosticBuilder &Diag,
 return;
   Diag << FixItHint::CreateRemoval(EqualLoc)
<< FixItHint::CreateRemoval(InitExprRange);
-  return;
 }
 
 namespace {

diff  --git a/clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp 
b/clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp
index 724160dbfb7ca..eadf03b3abe24 100644
--- a/clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ProjectAwareIndexTests.cpp
@@ -49,7 +49,6 @@ TEST(ProjectAware, Test) {
   C.Index.External.Location = "test";
   WithContextValue With(Config::Key, std::move(C));
   EXPECT_THAT(match(*Idx, Req), ElementsAre("1"));
-  return;
 }
 
 TEST(ProjectAware, CreatedOnce) {
@@ -80,7 +79,6 @@ TEST(ProjectAware, CreatedOnce) {
   match(*Idx, Req);
   // It is cached afterwards.
   EXPECT_EQ(InvocationCount, 1U);
-  return;
 }
 } // namespace clangd
 } // namespace clang



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


[clang] f4cebe5 - [Clang] Fix a regression introduced by #140576 (#140859)

2025-05-21 Thread via cfe-commits

Author: cor3ntin
Date: 2025-05-21T10:18:14+02:00
New Revision: f4cebe5d73c24ab53917bd58aedc9db892a164ae

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

LOG: [Clang] Fix a regression introduced by #140576 (#140859)

Lambda bodies should not be treated as subexpressions of the enclosing
scope.

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b18e83b605e4f..66dac21bf5818 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1,15 +1,13 @@ void Sema::PushExpressionEvaluationContextForFunction(
 Current.InImmediateEscalatingFunctionContext =
 getLangOpts().CPlusPlus20 && FD->isImmediateEscalating();
 
-if (isLambdaMethod(FD)) {
-  Current.InDiscardedStatement = Parent.isDiscardedStatementContext();
+if (isLambdaMethod(FD))
   Current.InImmediateFunctionContext =
   FD->isConsteval() ||
   (isLambdaMethod(FD) && (Parent.isConstantEvaluated() ||
   Parent.isImmediateFunctionContext()));
-} else {
+else
   Current.InImmediateFunctionContext = FD->isConsteval();
-}
   }
 }
 

diff  --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
index 20125cc5d4a9c..ac21e36daf870 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -208,6 +208,14 @@ void test() {
 
 }
 }
+
+void regression() {
+  if constexpr (false) {
+auto lam = []() { return 0; };
+1 | lam(); // expected-warning {{unused}}
+  }
+}
+
 }
 
 #endif



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


[clang] [Clang] Fix a regression introduced by #140576 (PR #140859)

2025-05-21 Thread via cfe-commits

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


[clang] WIP [clang] Recursively instantiate constexpr template functions. (PR #140865)

2025-05-21 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/140865

See https://github.com/llvm/llvm-project/issues/120108

TODO: test the patch

>From 31b94099a420dc9606c84771e9ba6365fadafe20 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 21 May 2025 10:14:28 +0200
Subject: [PATCH] [clang] Recursively instantiate constexpr template functions.

---
 clang/lib/Sema/SemaExpr.cpp   |  2 +-
 .../instantiate-pure-virtual-function.cpp | 11 +--
 clang/unittests/Support/TimeProfilerTest.cpp  |  2 +-
 3 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 2c81f7c583eb6..d2149bdbac054 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18485,7 +18485,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
 // Do not defer instantiations of constexpr functions, to avoid the
 // expression evaluator needing to call back into Sema if it sees a
 // call to such a function.
-InstantiateFunctionDefinition(PointOfInstantiation, Func);
+InstantiateFunctionDefinition(PointOfInstantiation, Func, true);
   else {
 Func->setInstantiationIsPending(true);
 PendingInstantiations.push_back(
diff --git a/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp 
b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
index caec42b6b77f9..adb0f3310ff68 100644
--- a/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -43,18 +43,9 @@ namespace non_pure_virtual_function {
 constexpr void foo(const T &) { bar(1); }
 
 virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
-// expected-note@-1 {{forward declaration of template entity is here}}
-// expected-note@-2 {{forward declaration of template entity is here}}
-// expected-note@-3 {{forward declaration of template entity is here}}
   };
 
-  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
-// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
-// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
-// expected-note@-3 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
-// expected-note@-4 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
-// expected-note@-5 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
-// expected-note@-6 {{used here}}
+  template  class D : public B { // expected-note@ {{used here}}
 
   public:
 constexpr void bar(unsigned int) override { }
diff --git a/clang/unittests/Support/TimeProfilerTest.cpp 
b/clang/unittests/Support/TimeProfilerTest.cpp
index 7698742426dfc..49a24bb62bdb0 100644
--- a/clang/unittests/Support/TimeProfilerTest.cpp
+++ b/clang/unittests/Support/TimeProfilerTest.cpp
@@ -332,8 +332,8 @@ Frontend (test.cc)
 | | InstantiateFunction (fooA, a.h:7)
 | | | InstantiateFunction (fooB, b.h:8)
 | | | | DeferInstantiation (fooC)
+| | | | InstantiateFunction (fooC, b.h:3)
 | | | DeferInstantiation (fooMTA)
-| | | InstantiateFunction (fooC, b.h:3)
 | | | InstantiateFunction (fooMTA, a.h:4)
 )",
 buildTraceGraph(Json));

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


[clang] [Clang][Sema] Reject array prvalue operands (PR #140702)

2025-05-21 Thread via cfe-commits


@@ -7639,6 +7639,8 @@ def warn_param_mismatched_alignment : Warning<
 
 def err_objc_object_assignment : Error<
   "cannot assign to class object (%0 invalid)">;
+def err_typecheck_array_prvalue_operand : Error<
+  "array prvalue is not permitted">;

languagelawyer wrote:

But the operator is pointed at by the `^` mark, like
```
test.cxx:13:23: error: array prvalue is not permitted
   13 | ((int []){ 1, 2, 3}) + 0;
  |  ^
```

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


[clang] [Clang][Sema] Reject array prvalue operands (PR #140702)

2025-05-21 Thread via cfe-commits

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


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

2025-05-21 Thread Walter J.T.V via cfe-commits

eZWALT wrote:

> @alexey-bataev It’s true that NumGeneratedLoops is used throughout the 
> existing OpenMP loop transformation infrastructure. While in some cases its 
> usage could potentially be replaced by NumGeneratedLoopNests (especially when 
> only checking for values like 0 or 1), the two variables convey distinct 
> semantic information.
> 
> NumGeneratedLoops refers to the number of individual loops produced, while 
> NumGeneratedLoopNests captures the structure of nested loops. For current and 
> future transformations, having access to both could be important for 
> representing complex constructs accurately.
> 
> Removing NumGeneratedLoops would require changes across the loop 
> transformations logic it's not clear the benefit would justify that cost, 
> particularly given the potential utility of retaining this semantic 
> distinction.I’m not 100% certain all current transformations depend on that 
> level of detail, but I believe it’s valuable to preserve until proven 
> otherwise.

I've identified a case where `NumGeneratedLoops` is necessary and cannot be 
replaced by `NumGeneratedLoopNests`: the `permutation` clause of the 
`interchange` directive, e.g., permutation(2,1,...). In this transformation, 
we’re not interested in the number of top-level loop nests, but rather in how 
many individual loops exist within a single top-level nest, and how to reorder 
them. Let me know if i have clarified your doubts or if you want more examples, 
sometimes this kind of details are somewhat difficult to explain easily. 

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


[libclc] 80913b4 - [libclc][NFC] Reuse inc file for OpenCL frexp decl

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

Author: Fraser Cormack
Date: 2025-05-21T10:19:31+01:00
New Revision: 80913b44a41ae0bbfbfee0c7b15cfa5a20e445d8

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

LOG: [libclc][NFC] Reuse inc file for OpenCL frexp decl

Added: 


Modified: 
libclc/opencl/include/clc/opencl/math/frexp.h

Removed: 
libclc/opencl/include/clc/opencl/math/frexp.inc



diff  --git a/libclc/opencl/include/clc/opencl/math/frexp.h 
b/libclc/opencl/include/clc/opencl/math/frexp.h
index a03aefbf60899..796acca1cb75a 100644
--- a/libclc/opencl/include/clc/opencl/math/frexp.h
+++ b/libclc/opencl/include/clc/opencl/math/frexp.h
@@ -6,5 +6,8 @@
 //
 
//===--===//
 
-#define __CLC_BODY 
+#define __CLC_FUNCTION frexp
+#define __CLC_BODY 
 #include 
+
+#undef __CLC_FUNCTION

diff  --git a/libclc/opencl/include/clc/opencl/math/frexp.inc 
b/libclc/opencl/include/clc/opencl/math/frexp.inc
deleted file mode 100644
index 620db60636107..0
--- a/libclc/opencl/include/clc/opencl/math/frexp.inc
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--===//
-//
-// 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
-//
-//===--===//
-
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE frexp(__CLC_GENTYPE x,
-global __CLC_INTN *iptr);
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE frexp(__CLC_GENTYPE x,
-local __CLC_INTN *iptr);
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE frexp(__CLC_GENTYPE x,
-private __CLC_INTN *iptr);



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


[clang] [WIP][C++20][Modules] Lazily, but fully load 'HeaderFileInfo' table into memory. (PR #140867)

2025-05-21 Thread Michael Park via cfe-commits

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


[clang] [ClangTool] Use CC1Option flag resource-dir in injectResourceDir (PR #140870)

2025-05-21 Thread Wenju He via cfe-commits

https://github.com/wenju-he created 
https://github.com/llvm/llvm-project/pull/140870

This PR fixes ClangTool error in -cc1 mode:
error: unknown argument: '-resource-dir=

>From f5e675f17ea737b0668e626f34d013153368425e Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Wed, 21 May 2025 02:08:34 -0700
Subject: [PATCH] [ClangTool] Use CC1Option flag resource-dir in
 injectResourceDir

This PR fixes ClangTool error in -cc1 mode:
error: unknown argument: '-resource-dir=
---
 clang/lib/Tooling/Tooling.cpp   |  8 +---
 clang/unittests/Tooling/ToolingTest.cpp | 19 +++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 3c72f52040142..87a984672662b 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -510,9 +510,11 @@ static void injectResourceDir(CommandLineArguments &Args, 
const char *Argv0,
   return;
 
   // If there's no override in place add our resource dir.
-  Args = getInsertArgumentAdjuster(
-  ("-resource-dir=" + CompilerInvocation::GetResourcesPath(Argv0, 
MainAddr))
-  .c_str())(Args, "");
+  CommandLineArguments Extra = {
+  "-resource-dir", CompilerInvocation::GetResourcesPath(Argv0, MainAddr)};
+
+  Args =
+  getInsertArgumentAdjuster(Extra, ArgumentInsertPosition::END)(Args, "");
 }
 
 int ClangTool::run(ToolAction *Action) {
diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 8cdfffb54390e..07104ccf9835f 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -771,6 +771,25 @@ TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
   EXPECT_EQ(0, Tool.run(Action.get()));
 }
 
+// Check -cc1 command doesn't crash.
+TEST(ClangToolTest, CC1Arg) {
+  FixedCompilationDatabase Compilations("/", {"-cc1"});
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+
+  InMemoryFileSystem->addFile(
+  "a.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int main() {}"));
+
+  ClangTool Tool(Compilations, std::vector(1, "a.cpp"),
+ std::make_shared(), 
OverlayFileSystem);
+  std::unique_ptr Action(
+  newFrontendActionFactory());
+  EXPECT_EQ(0, Tool.run(Action.get()));
+}
+
 // Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
 TEST(ClangToolTest, StripDependencyFileAdjuster) {
   FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});

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


[clang] [Clang][AArch64]Add FP8 ACLE macros implementation (PR #140591)

2025-05-21 Thread via cfe-commits

https://github.com/CarolineConcatto updated 
https://github.com/llvm/llvm-project/pull/140591

>From 22e44648ce4ec1c747406f7d98ae7c736d0e441c Mon Sep 17 00:00:00 2001
From: CarolineConcatto 
Date: Mon, 19 May 2025 18:21:28 +
Subject: [PATCH 1/2] [Clang][AArch64]Add FP8 ACLE macros implementation

This patch implements the macros described in the ACLE[1]

[1] 
https://github.com/ARM-software/acle/blob/main/main/acle.md#modal-8-bit-floating-point-extensions
---
 clang/lib/Basic/Targets/AArch64.cpp   | 59 +++
 clang/lib/Basic/Targets/AArch64.h |  9 +++
 .../Preprocessor/aarch64-target-features.c| 31 ++
 3 files changed, 99 insertions(+)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index e1f6c7b834dc7..7267b17704a41 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -596,6 +596,33 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasSMEB16B16)
 Builder.defineMacro("__ARM_FEATURE_SME_B16B16", "1");
 
+  if (HasFP8)
+Builder.defineMacro("__ARM_FEATURE_FP8", "1");
+
+  if (HasFP8FMA)
+Builder.defineMacro("__ARM_FEATURE_FP8FMA", "1");
+
+  if (HasFP8DOT2)
+Builder.defineMacro("__ARM_FEATURE_FP8DOT2", "1");
+
+  if (HasFP8DOT4)
+Builder.defineMacro("__ARM_FEATURE_FP8DOT4", "1");
+
+  if (HasSSVE_FP8DOT2)
+Builder.defineMacro("__ARM_FEATURE_SSVE_FP8DOT2", "1");
+
+  if (HasSSVE_FP8DOT4)
+Builder.defineMacro("__ARM_FEATURE_SSVE_FP8DOT4", "1");
+
+  if (HasSSVE_FP8FMA)
+Builder.defineMacro("__ARM_FEATURE_SSVE_FP8FMA", "1");
+
+  if (HasSME_F8F32)
+Builder.defineMacro("__ARM_FEATURE_SME_F8F32", "1");
+
+  if (HasSME_F8F16)
+Builder.defineMacro("__ARM_FEATURE_SME_F8F16", "1");
+
   if (HasCRC)
 Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
 
@@ -885,6 +912,15 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) 
const {
   .Cases("ls64", "ls64_v", "ls64_accdata", HasLS64)
   .Case("wfxt", HasWFxT)
   .Case("rcpc3", HasRCPC3)
+  .Case("fp8", HasFP8)
+  .Case("fp8fma", HasFP8FMA)
+  .Case("fp8dot2", HasFP8DOT2)
+  .Case("fp8dot4", HasFP8DOT4)
+  .Case("ssve-fp8dot2", HasSSVE_FP8DOT2)
+  .Case("ssve-fp8dot4", HasSSVE_FP8DOT4)
+  .Case("ssve-fp8fma", HasSSVE_FP8FMA)
+  .Case("sme-f8f32", HasSME_F8F32)
+  .Case("sme-f8f16", HasSME_F8F16)
   .Default(false);
 }
 
@@ -1046,6 +1082,29 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasSVEB16B16 = true;
   HasSMEB16B16 = true;
 }
+
+if (Feature == "+fp8")
+  HasFP8 = true;
+if (Feature == "+fp8fma")
+  HasFP8FMA = true;
+if (Feature == "+fp8dot2")
+  HasFP8DOT2 = true;
+if (Feature == "+fp8dot4")
+  HasFP8DOT4 = true;
+if (Feature == "+ssve-fp8dot2")
+  HasSSVE_FP8DOT2 = true;
+if (Feature == "+ssve-fp8dot4")
+  HasSSVE_FP8DOT4 = true;
+if (Feature == "+ssve-fp8fma")
+  HasSSVE_FP8FMA = true;
+if (Feature == "+sme-f8f32") {
+  HasSME2 = true;
+  HasSME_F8F32 = true;
+}
+if (Feature == "+sme-f8f16") {
+  HasSME2 = true;
+  HasSME_F8F16 = true;
+}
 if (Feature == "+sb")
   HasSB = true;
 if (Feature == "+predres")
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 6eeac69af20df..7230f22d5bb86 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -106,6 +106,15 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool HasSMEF16F16 = false;
   bool HasSMEB16B16 = false;
   bool HasSME2p1 = false;
+  bool HasFP8 = false;
+  bool HasFP8FMA = false;
+  bool HasFP8DOT2 = false;
+  bool HasFP8DOT4 = false;
+  bool HasSSVE_FP8DOT2 = false;
+  bool HasSSVE_FP8DOT4 = false;
+  bool HasSSVE_FP8FMA = false;
+  bool HasSME_F8F32 = false;
+  bool HasSME_F8F16 = false;
   bool HasSB = false;
   bool HasPredRes = false;
   bool HasSSBS = false;
diff --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index 3f801c4344940..52045d216262f 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -744,3 +744,34 @@
 // CHECK-SMEB16B16: __ARM_FEATURE_SME2 1
 // CHECK-SMEB16B16: __ARM_FEATURE_SME_B16B16 1
 // CHECK-SMEB16B16: __ARM_FEATURE_SVE_B16B16 1
+//
+//  RUN: %clang --target=aarch64 -march=armv9-a+fp8 -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-FP8 %s
+// CHECK-FP8: __ARM_FEATURE_FP8 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+fp8fma -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-FP8FMA %s
+// CHECK-FP8FMA: __ARM_FEATURE_FP8FMA 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+fp8dot2 -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-FP8DOT2 %s
+// CHECK-FP8DOT2: __ARM_FEATURE_FP8DOT2 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+fp8dot4 -x c

[clang] [ClangTool] Use CC1Option flag resource-dir in injectResourceDir (PR #140870)

2025-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Wenju He (wenju-he)


Changes

This PR fixes ClangTool error in -cc1 mode:
error: unknown argument: '-resource-dir=

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


2 Files Affected:

- (modified) clang/lib/Tooling/Tooling.cpp (+5-3) 
- (modified) clang/unittests/Tooling/ToolingTest.cpp (+19) 


``diff
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 3c72f52040142..87a984672662b 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -510,9 +510,11 @@ static void injectResourceDir(CommandLineArguments &Args, 
const char *Argv0,
   return;
 
   // If there's no override in place add our resource dir.
-  Args = getInsertArgumentAdjuster(
-  ("-resource-dir=" + CompilerInvocation::GetResourcesPath(Argv0, 
MainAddr))
-  .c_str())(Args, "");
+  CommandLineArguments Extra = {
+  "-resource-dir", CompilerInvocation::GetResourcesPath(Argv0, MainAddr)};
+
+  Args =
+  getInsertArgumentAdjuster(Extra, ArgumentInsertPosition::END)(Args, "");
 }
 
 int ClangTool::run(ToolAction *Action) {
diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 8cdfffb54390e..07104ccf9835f 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -771,6 +771,25 @@ TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
   EXPECT_EQ(0, Tool.run(Action.get()));
 }
 
+// Check -cc1 command doesn't crash.
+TEST(ClangToolTest, CC1Arg) {
+  FixedCompilationDatabase Compilations("/", {"-cc1"});
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+
+  InMemoryFileSystem->addFile(
+  "a.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int main() {}"));
+
+  ClangTool Tool(Compilations, std::vector(1, "a.cpp"),
+ std::make_shared(), 
OverlayFileSystem);
+  std::unique_ptr Action(
+  newFrontendActionFactory());
+  EXPECT_EQ(0, Tool.run(Action.get()));
+}
+
 // Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
 TEST(ClangToolTest, StripDependencyFileAdjuster) {
   FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});

``




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


[clang] [ClangTool] Use CC1Option flag resource-dir in injectResourceDir (PR #140870)

2025-05-21 Thread Wenju He via cfe-commits

https://github.com/wenju-he updated 
https://github.com/llvm/llvm-project/pull/140870

>From f5e675f17ea737b0668e626f34d013153368425e Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Wed, 21 May 2025 02:08:34 -0700
Subject: [PATCH 1/2] [ClangTool] Use CC1Option flag resource-dir in
 injectResourceDir

This PR fixes ClangTool error in -cc1 mode:
error: unknown argument: '-resource-dir=
---
 clang/lib/Tooling/Tooling.cpp   |  8 +---
 clang/unittests/Tooling/ToolingTest.cpp | 19 +++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 3c72f52040142..87a984672662b 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -510,9 +510,11 @@ static void injectResourceDir(CommandLineArguments &Args, 
const char *Argv0,
   return;
 
   // If there's no override in place add our resource dir.
-  Args = getInsertArgumentAdjuster(
-  ("-resource-dir=" + CompilerInvocation::GetResourcesPath(Argv0, 
MainAddr))
-  .c_str())(Args, "");
+  CommandLineArguments Extra = {
+  "-resource-dir", CompilerInvocation::GetResourcesPath(Argv0, MainAddr)};
+
+  Args =
+  getInsertArgumentAdjuster(Extra, ArgumentInsertPosition::END)(Args, "");
 }
 
 int ClangTool::run(ToolAction *Action) {
diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 8cdfffb54390e..07104ccf9835f 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -771,6 +771,25 @@ TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
   EXPECT_EQ(0, Tool.run(Action.get()));
 }
 
+// Check -cc1 command doesn't crash.
+TEST(ClangToolTest, CC1Arg) {
+  FixedCompilationDatabase Compilations("/", {"-cc1"});
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+
+  InMemoryFileSystem->addFile(
+  "a.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int main() {}"));
+
+  ClangTool Tool(Compilations, std::vector(1, "a.cpp"),
+ std::make_shared(), 
OverlayFileSystem);
+  std::unique_ptr Action(
+  newFrontendActionFactory());
+  EXPECT_EQ(0, Tool.run(Action.get()));
+}
+
 // Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
 TEST(ClangToolTest, StripDependencyFileAdjuster) {
   FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});

>From 9d8ce5cf034a9ff7bf427fb76126c1f7b1af300c Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Wed, 21 May 2025 02:12:23 -0700
Subject: [PATCH 2/2] update comment

---
 clang/unittests/Tooling/ToolingTest.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 07104ccf9835f..9969656b00956 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -771,7 +771,7 @@ TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
   EXPECT_EQ(0, Tool.run(Action.get()));
 }
 
-// Check -cc1 command doesn't crash.
+// Check -cc1 command doesn't fail.
 TEST(ClangToolTest, CC1Arg) {
   FixedCompilationDatabase Compilations("/", {"-cc1"});
   llvm::IntrusiveRefCntPtr OverlayFileSystem(

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


[clang] [Clang][Sema] Reject array prvalue operands (PR #140702)

2025-05-21 Thread via cfe-commits


@@ -7639,6 +7639,8 @@ def warn_param_mismatched_alignment : Warning<
 
 def err_objc_object_assignment : Error<
   "cannot assign to class object (%0 invalid)">;
+def err_typecheck_array_prvalue_operand : Error<
+  "array prvalue is not permitted">;

Sirraide wrote:

Hmm, in that case, maybe just ‘operand cannot be an array prvalue’. I would 
prefer at least including the word ‘operand’ so it’s clear that the problem is 
that you’re passing an array prvalue to this operator, because at the moment 
the diagnostic makes it sound like array prvalues aren’t permitted *at all*.

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


[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)

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

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

Previously the OpenCL address space overloads of remquo would call into the one 
and only 'private' CLC remquo. This was an outlier compared with the other 
pointer-argumented maths builtins.

This commit moves the definitions of all address space overloads to the CLC 
library to give more control over each address space to CLC implementers.

There are some minor changes to the generated bytecode but it's simply moving 
IR instructions around.

>From 3e070b23eea6ac3a9514d0cd5c9785e220d5f5e1 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 21 May 2025 10:39:12 +0100
Subject: [PATCH] [libclc] Move all remquo address spaces to CLC library

Previously the OpenCL address space overloads of remquo would call into
the one and only 'private' CLC remquo. This was an outlier compared with
the other pointer-argumented maths builtins.

This commit moves the definitions of all address space overloads to the
CLC library to give more control over each address space to CLC
implementers.

There are some minor changes to the generated bytecode but it's simply
moving IR instructions around.
---
 libclc/clc/include/clc/math/clc_remquo.h  |   4 +-
 libclc/clc/include/clc/math/remquo_decl.inc   |   8 +-
 libclc/clc/lib/generic/math/clc_remquo.cl | 266 +
 libclc/clc/lib/generic/math/clc_remquo.inc| 271 ++
 .../opencl/include/clc/opencl/math/remquo.h   |  12 -
 libclc/opencl/lib/generic/math/remquo.cl  |  12 -
 libclc/opencl/lib/generic/math/remquo.inc |  17 +-
 7 files changed, 300 insertions(+), 290 deletions(-)
 create mode 100644 libclc/clc/lib/generic/math/clc_remquo.inc

diff --git a/libclc/clc/include/clc/math/clc_remquo.h 
b/libclc/clc/include/clc/math/clc_remquo.h
index 5dea818013c68..48a8844a6e384 100644
--- a/libclc/clc/include/clc/math/clc_remquo.h
+++ b/libclc/clc/include/clc/math/clc_remquo.h
@@ -10,12 +10,10 @@
 #define __CLC_MATH_CLC_REMQUO_H__
 
 #define __CLC_FUNCTION __clc_remquo
-
 #define __CLC_BODY 
-#define __CLC_ADDRESS_SPACE private
+
 #include 
 
-#undef __CLC_ADDRESS_SPACE
 #undef __CLC_FUNCTION
 
 #endif // __CLC_MATH_CLC_REMQUO_H__
diff --git a/libclc/clc/include/clc/math/remquo_decl.inc 
b/libclc/clc/include/clc/math/remquo_decl.inc
index ecd703042a964..0b650795909b0 100644
--- a/libclc/clc/include/clc/math/remquo_decl.inc
+++ b/libclc/clc/include/clc/math/remquo_decl.inc
@@ -7,4 +7,10 @@
 
//===--===//
 
 _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
-__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q);
+__CLC_GENTYPE x, __CLC_GENTYPE y, private __CLC_INTN *q);
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
+__CLC_GENTYPE x, __CLC_GENTYPE y, global __CLC_INTN *q);
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
+__CLC_GENTYPE x, __CLC_GENTYPE y, local __CLC_INTN *q);
diff --git a/libclc/clc/lib/generic/math/clc_remquo.cl 
b/libclc/clc/lib/generic/math/clc_remquo.cl
index 9fa94c1c290b8..2f3b6f0339e17 100644
--- a/libclc/clc/lib/generic/math/clc_remquo.cl
+++ b/libclc/clc/lib/generic/math/clc_remquo.cl
@@ -18,262 +18,14 @@
 #include 
 #include 
 
-_CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y,
-  __private int *quo) {
-  x = __clc_flush_denormal_if_not_supported(x);
-  y = __clc_flush_denormal_if_not_supported(y);
-  int ux = __clc_as_int(x);
-  int ax = ux & EXSIGNBIT_SP32;
-  float xa = __clc_as_float(ax);
-  int sx = ux ^ ax;
-  int ex = ax >> EXPSHIFTBITS_SP32;
+#define __CLC_ADDRESS_SPACE private
+#include 
+#undef __CLC_ADDRESS_SPACE
 
-  int uy = __clc_as_int(y);
-  int ay = uy & EXSIGNBIT_SP32;
-  float ya = __clc_as_float(ay);
-  int sy = uy ^ ay;
-  int ey = ay >> EXPSHIFTBITS_SP32;
+#define __CLC_ADDRESS_SPACE global
+#include 
+#undef __CLC_ADDRESS_SPACE
 
-  float xr = __clc_as_float(0x3f80 | (ax & 0x007f));
-  float yr = __clc_as_float(0x3f80 | (ay & 0x007f));
-  int c;
-  int k = ex - ey;
-
-  uint q = 0;
-
-  while (k > 0) {
-c = xr >= yr;
-q = (q << 1) | c;
-xr -= c ? yr : 0.0f;
-xr += xr;
---k;
-  }
-
-  c = xr > yr;
-  q = (q << 1) | c;
-  xr -= c ? yr : 0.0f;
-
-  int lt = ex < ey;
-
-  q = lt ? 0 : q;
-  xr = lt ? xa : xr;
-  yr = lt ? ya : yr;
-
-  c = (yr < 2.0f * xr) | ((yr == 2.0f * xr) & ((q & 0x1) == 0x1));
-  xr -= c ? yr : 0.0f;
-  q += c;
-
-  float s = __clc_as_float(ey << EXPSHIFTBITS_SP32);
-  xr *= lt ? 1.0f : s;
-
-  int qsgn = sx == sy ? 1 : -1;
-  int quot = (q & 0x7f) * qsgn;
-
-  c = ax == ay;
-  quot = c ? qsgn : quot;
-  xr = c ? 0.0f : xr;
-
-  xr = __clc_as_float(sx ^ __clc_as_int(xr));
-
-  c = ax > PINFBITPATT_SP32 | ay > PINFBITPATT_SP32 | ax == PINFBITPATT_SP32 |
-  ay == 0;
-  quot = c ? 0 : quot;
-  xr = c ? __clc_as_float(QNANBITPATT_SP32) : xr;
-
-  *quo = quot;
-
-  return xr;
-}
-// 

[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)

2025-05-21 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions inc,cl,h -- 
libclc/clc/lib/generic/math/clc_remquo.inc 
libclc/clc/include/clc/math/clc_remquo.h 
libclc/clc/include/clc/math/remquo_decl.inc 
libclc/clc/lib/generic/math/clc_remquo.cl 
libclc/opencl/include/clc/opencl/math/remquo.h 
libclc/opencl/lib/generic/math/remquo.cl 
libclc/opencl/lib/generic/math/remquo.inc
``





View the diff from clang-format here.


``diff
diff --git a/libclc/clc/include/clc/math/remquo_decl.inc 
b/libclc/clc/include/clc/math/remquo_decl.inc
index 0b6507959..7f2af2915 100644
--- a/libclc/clc/include/clc/math/remquo_decl.inc
+++ b/libclc/clc/include/clc/math/remquo_decl.inc
@@ -6,11 +6,14 @@
 //
 
//===--===//
 
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
-__CLC_GENTYPE x, __CLC_GENTYPE y, private __CLC_INTN *q);
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
+ __CLC_GENTYPE y,
+ private __CLC_INTN *q);
 
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
-__CLC_GENTYPE x, __CLC_GENTYPE y, global __CLC_INTN *q);
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
+ __CLC_GENTYPE y,
+ global __CLC_INTN *q);
 
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
-__CLC_GENTYPE x, __CLC_GENTYPE y, local __CLC_INTN *q);
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
+ __CLC_GENTYPE y,
+ local __CLC_INTN *q);
diff --git a/libclc/clc/lib/generic/math/clc_remquo.inc 
b/libclc/clc/lib/generic/math/clc_remquo.inc
index 7563bae24..28f51c4e2 100644
--- a/libclc/clc/lib/generic/math/clc_remquo.inc
+++ b/libclc/clc/lib/generic/math/clc_remquo.inc
@@ -218,7 +218,7 @@ _CLC_DEF _CLC_OVERLOAD double __clc_remquo(double x, double 
y,
   quo = c ? 0 : quo;
   ret = c ? x : ret;
 
-  c &= (yexp<1023 & 2.0 * dx> dy) | (dx > 0.5 * dy);
+  c &= (yexp < 1023 & 2.0 * dx > dy) | (dx > 0.5 * dy);
   quo = c ? qsgn : quo;
   // we could use a conversion here instead since qsgn = +-1
   p = qsgn == 1 ? -1.0 : 1.0;

``




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


[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)

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

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/140871

>From 3e070b23eea6ac3a9514d0cd5c9785e220d5f5e1 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 21 May 2025 10:39:12 +0100
Subject: [PATCH 1/2] [libclc] Move all remquo address spaces to CLC library

Previously the OpenCL address space overloads of remquo would call into
the one and only 'private' CLC remquo. This was an outlier compared with
the other pointer-argumented maths builtins.

This commit moves the definitions of all address space overloads to the
CLC library to give more control over each address space to CLC
implementers.

There are some minor changes to the generated bytecode but it's simply
moving IR instructions around.
---
 libclc/clc/include/clc/math/clc_remquo.h  |   4 +-
 libclc/clc/include/clc/math/remquo_decl.inc   |   8 +-
 libclc/clc/lib/generic/math/clc_remquo.cl | 266 +
 libclc/clc/lib/generic/math/clc_remquo.inc| 271 ++
 .../opencl/include/clc/opencl/math/remquo.h   |  12 -
 libclc/opencl/lib/generic/math/remquo.cl  |  12 -
 libclc/opencl/lib/generic/math/remquo.inc |  17 +-
 7 files changed, 300 insertions(+), 290 deletions(-)
 create mode 100644 libclc/clc/lib/generic/math/clc_remquo.inc

diff --git a/libclc/clc/include/clc/math/clc_remquo.h 
b/libclc/clc/include/clc/math/clc_remquo.h
index 5dea818013c68..48a8844a6e384 100644
--- a/libclc/clc/include/clc/math/clc_remquo.h
+++ b/libclc/clc/include/clc/math/clc_remquo.h
@@ -10,12 +10,10 @@
 #define __CLC_MATH_CLC_REMQUO_H__
 
 #define __CLC_FUNCTION __clc_remquo
-
 #define __CLC_BODY 
-#define __CLC_ADDRESS_SPACE private
+
 #include 
 
-#undef __CLC_ADDRESS_SPACE
 #undef __CLC_FUNCTION
 
 #endif // __CLC_MATH_CLC_REMQUO_H__
diff --git a/libclc/clc/include/clc/math/remquo_decl.inc 
b/libclc/clc/include/clc/math/remquo_decl.inc
index ecd703042a964..0b650795909b0 100644
--- a/libclc/clc/include/clc/math/remquo_decl.inc
+++ b/libclc/clc/include/clc/math/remquo_decl.inc
@@ -7,4 +7,10 @@
 
//===--===//
 
 _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
-__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q);
+__CLC_GENTYPE x, __CLC_GENTYPE y, private __CLC_INTN *q);
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
+__CLC_GENTYPE x, __CLC_GENTYPE y, global __CLC_INTN *q);
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
+__CLC_GENTYPE x, __CLC_GENTYPE y, local __CLC_INTN *q);
diff --git a/libclc/clc/lib/generic/math/clc_remquo.cl 
b/libclc/clc/lib/generic/math/clc_remquo.cl
index 9fa94c1c290b8..2f3b6f0339e17 100644
--- a/libclc/clc/lib/generic/math/clc_remquo.cl
+++ b/libclc/clc/lib/generic/math/clc_remquo.cl
@@ -18,262 +18,14 @@
 #include 
 #include 
 
-_CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y,
-  __private int *quo) {
-  x = __clc_flush_denormal_if_not_supported(x);
-  y = __clc_flush_denormal_if_not_supported(y);
-  int ux = __clc_as_int(x);
-  int ax = ux & EXSIGNBIT_SP32;
-  float xa = __clc_as_float(ax);
-  int sx = ux ^ ax;
-  int ex = ax >> EXPSHIFTBITS_SP32;
+#define __CLC_ADDRESS_SPACE private
+#include 
+#undef __CLC_ADDRESS_SPACE
 
-  int uy = __clc_as_int(y);
-  int ay = uy & EXSIGNBIT_SP32;
-  float ya = __clc_as_float(ay);
-  int sy = uy ^ ay;
-  int ey = ay >> EXPSHIFTBITS_SP32;
+#define __CLC_ADDRESS_SPACE global
+#include 
+#undef __CLC_ADDRESS_SPACE
 
-  float xr = __clc_as_float(0x3f80 | (ax & 0x007f));
-  float yr = __clc_as_float(0x3f80 | (ay & 0x007f));
-  int c;
-  int k = ex - ey;
-
-  uint q = 0;
-
-  while (k > 0) {
-c = xr >= yr;
-q = (q << 1) | c;
-xr -= c ? yr : 0.0f;
-xr += xr;
---k;
-  }
-
-  c = xr > yr;
-  q = (q << 1) | c;
-  xr -= c ? yr : 0.0f;
-
-  int lt = ex < ey;
-
-  q = lt ? 0 : q;
-  xr = lt ? xa : xr;
-  yr = lt ? ya : yr;
-
-  c = (yr < 2.0f * xr) | ((yr == 2.0f * xr) & ((q & 0x1) == 0x1));
-  xr -= c ? yr : 0.0f;
-  q += c;
-
-  float s = __clc_as_float(ey << EXPSHIFTBITS_SP32);
-  xr *= lt ? 1.0f : s;
-
-  int qsgn = sx == sy ? 1 : -1;
-  int quot = (q & 0x7f) * qsgn;
-
-  c = ax == ay;
-  quot = c ? qsgn : quot;
-  xr = c ? 0.0f : xr;
-
-  xr = __clc_as_float(sx ^ __clc_as_int(xr));
-
-  c = ax > PINFBITPATT_SP32 | ay > PINFBITPATT_SP32 | ax == PINFBITPATT_SP32 |
-  ay == 0;
-  quot = c ? 0 : quot;
-  xr = c ? __clc_as_float(QNANBITPATT_SP32) : xr;
-
-  *quo = quot;
-
-  return xr;
-}
-// remquo signature is special, we don't have macro for this
-#define __VEC_REMQUO(TYPE, VEC_SIZE, HALF_VEC_SIZE)
\
-  _CLC_DEF _CLC_OVERLOAD TYPE##VEC_SIZE __clc_remquo(  
\
-  TYPE##VEC_SIZE x, TYPE##VEC_SIZE y, __private int##VEC_SIZE *quo) {  
\
-int##HALF_VEC_SIZE lo, hi; 
\
-TYPE##VEC_SIZE ret;   

[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)

2025-05-21 Thread Matt Arsenault via cfe-commits

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


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


[clang] [Clang][Sema] Reject array prvalue operands (PR #140702)

2025-05-21 Thread Yanzuo Liu via cfe-commits


@@ -7639,6 +7639,8 @@ def warn_param_mismatched_alignment : Warning<
 
 def err_objc_object_assignment : Error<
   "cannot assign to class object (%0 invalid)">;
+def err_typecheck_array_prvalue_operand : Error<
+  "array prvalue is not permitted">;

zwuis wrote:

> But the operator is pointed at by `^`

This part can be removed by using `-fno-caret-diagnostics` command line option. 
In this case, the diagnostic is as followed:

```txt
test.cxx:13:23: error: array prvalue is not permitted
```

Users may get confused.

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


[clang] [Driver][X86] Add -m[no-]apxf to m_x86_Features_Group (PR #140874)

2025-05-21 Thread Feng Zou via cfe-commits

https://github.com/fzou1 created 
https://github.com/llvm/llvm-project/pull/140874

This is to expose these options to clang-cl on Windows. And add help text for 
these options.

>From d683302d4768dfb5c618aa1b09553f3b22142aed Mon Sep 17 00:00:00 2001
From: Feng Zou 
Date: Tue, 20 May 2025 22:10:07 +0800
Subject: [PATCH] [Driver][X86] Add -m[no-]apxf to m_x86_Features_Group

This is to expose these options to clang-cl on Windows.
And add help text for these options.
---
 clang/include/clang/Driver/Options.td |  9 +++--
 clang/test/Driver/cl-x86-flags.c  | 50 +++
 2 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9a4253113488d..ead729342173b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6679,8 +6679,13 @@ def mapx_features_EQ : CommaJoined<["-"], 
"mapx-features=">, Group, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">,  Visibility<[ClangOption, 
CLOption, FlangOption]>;
 def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
 HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">, Visibility<[ClangOption, 
CLOption, FlangOption]>;
-def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>;
-def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>;
+def mapxf : Flag<["-"], "mapxf">, Alias,
+AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>,
+Group, HelpText<"Enable all features of 
APX">;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias,
+   
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>,
+   Group,
+   HelpText<"Disable all features of APX">;
 def mapx_inline_asm_use_gpr32 : Flag<["-"], "mapx-inline-asm-use-gpr32">, 
Group,
 HelpText<"Enable use of GPR32 in inline 
assembly for APX">;
 } // let Flags = [TargetSpecific]
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 51b16f0ce3546..23fe96d604604 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -135,3 +135,53 @@
 
 void f(void) {
 }
+
+
+// RUN: not %clang_cl -### --target=i386 -mapx-features=ndd %s 2>&1 | 
FileCheck --check-prefix=NON-APX %s
+// RUN: not %clang_cl -### --target=i386 -mapxf %s 2>&1 | FileCheck 
--check-prefix=NON-APX %s
+// RUN: %clang_cl -### --target=i386 -mno-apxf %s 2>&1 > /dev/null
+// NON-APX:  error: unsupported option '-mapx-features=|-mapxf' for target 
'i386'
+// NON-APX-NOT:  error: {{.*}} -mapx-features=
+
+// RUN: %clang_cl -target x86_64-pc-windows -mapxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=APXF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mno-apxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=NO-APXF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mno-apxf -mapxf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=APXF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapxf -mno-apxf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NO-APXF %s
+//
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" 
"-target-feature" "+nf" "-target-feature" "+cf" "-target-feature" "+zu"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx" "-target-feature" "-ndd" "-target-feature" "-ccmp" 
"-target-feature" "-nf" "-target-feature" "-cf" "-target-feature" "-zu"
+
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=egpr %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=EGPR %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=push2pop2 %s -### 
-o %t.o 2>&1 | FileCheck -check-prefix=PUSH2POP2 %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=ppx %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=PPX %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=ndd %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NDD %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=ccmp %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=CCMP %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=nf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=cf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=CF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=zu %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=ZU %s
+// EGPR: "-target-feature" "+egpr"
+// PUSH2POP2: "-target-feature" "+push2pop2"
+// PPX: "-target-feature" "+ppx"
+// NDD: "-target-feature" "+ndd"
+// CCMP: "-target-feature" "+ccmp"
+// NF: "-target-feature" "+nf"
+// CF: "-target-feature" "+cf"
+// ZU: "-target-feature" "+zu"
+
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=egpr,ndd %s -### 

[clang] [Driver][X86] Add -m[no-]apxf to m_x86_Features_Group (PR #140874)

2025-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Feng Zou (fzou1)


Changes

This is to expose these options to clang-cl on Windows. And add help text for 
these options.

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


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+7-2) 
- (modified) clang/test/Driver/cl-x86-flags.c (+50) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9a4253113488d..ead729342173b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6679,8 +6679,13 @@ def mapx_features_EQ : CommaJoined<["-"], 
"mapx-features=">, Group, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">,  Visibility<[ClangOption, 
CLOption, FlangOption]>;
 def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
 HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">, Visibility<[ClangOption, 
CLOption, FlangOption]>;
-def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>;
-def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>;
+def mapxf : Flag<["-"], "mapxf">, Alias,
+AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>,
+Group, HelpText<"Enable all features of 
APX">;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias,
+   
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>,
+   Group,
+   HelpText<"Disable all features of APX">;
 def mapx_inline_asm_use_gpr32 : Flag<["-"], "mapx-inline-asm-use-gpr32">, 
Group,
 HelpText<"Enable use of GPR32 in inline 
assembly for APX">;
 } // let Flags = [TargetSpecific]
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 51b16f0ce3546..23fe96d604604 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -135,3 +135,53 @@
 
 void f(void) {
 }
+
+
+// RUN: not %clang_cl -### --target=i386 -mapx-features=ndd %s 2>&1 | 
FileCheck --check-prefix=NON-APX %s
+// RUN: not %clang_cl -### --target=i386 -mapxf %s 2>&1 | FileCheck 
--check-prefix=NON-APX %s
+// RUN: %clang_cl -### --target=i386 -mno-apxf %s 2>&1 > /dev/null
+// NON-APX:  error: unsupported option '-mapx-features=|-mapxf' for target 
'i386'
+// NON-APX-NOT:  error: {{.*}} -mapx-features=
+
+// RUN: %clang_cl -target x86_64-pc-windows -mapxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=APXF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mno-apxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=NO-APXF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mno-apxf -mapxf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=APXF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapxf -mno-apxf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NO-APXF %s
+//
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" 
"-target-feature" "+nf" "-target-feature" "+cf" "-target-feature" "+zu"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx" "-target-feature" "-ndd" "-target-feature" "-ccmp" 
"-target-feature" "-nf" "-target-feature" "-cf" "-target-feature" "-zu"
+
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=egpr %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=EGPR %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=push2pop2 %s -### 
-o %t.o 2>&1 | FileCheck -check-prefix=PUSH2POP2 %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=ppx %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=PPX %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=ndd %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NDD %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=ccmp %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=CCMP %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=nf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=cf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=CF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=zu %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=ZU %s
+// EGPR: "-target-feature" "+egpr"
+// PUSH2POP2: "-target-feature" "+push2pop2"
+// PPX: "-target-feature" "+ppx"
+// NDD: "-target-feature" "+ndd"
+// CCMP: "-target-feature" "+ccmp"
+// NF: "-target-feature" "+nf"
+// CF: "-target-feature" "+cf"
+// ZU: "-target-feature" "+zu"
+
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=egpr,ndd %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=egpr 
-mapx-features=ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang_cl -target x86_64-pc-windows -mn

[clang] [Driver][X86] Add -m[no-]apxf to m_x86_Features_Group (PR #140874)

2025-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Feng Zou (fzou1)


Changes

This is to expose these options to clang-cl on Windows. And add help text for 
these options.

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


2 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+7-2) 
- (modified) clang/test/Driver/cl-x86-flags.c (+50) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9a4253113488d..ead729342173b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6679,8 +6679,13 @@ def mapx_features_EQ : CommaJoined<["-"], 
"mapx-features=">, Group, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">,  Visibility<[ClangOption, 
CLOption, FlangOption]>;
 def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
 HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">, Visibility<[ClangOption, 
CLOption, FlangOption]>;
-def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>;
-def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>;
+def mapxf : Flag<["-"], "mapxf">, Alias,
+AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>,
+Group, HelpText<"Enable all features of 
APX">;
+def mno_apxf : Flag<["-"], "mno-apxf">, Alias,
+   
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf","zu"]>,
+   Group,
+   HelpText<"Disable all features of APX">;
 def mapx_inline_asm_use_gpr32 : Flag<["-"], "mapx-inline-asm-use-gpr32">, 
Group,
 HelpText<"Enable use of GPR32 in inline 
assembly for APX">;
 } // let Flags = [TargetSpecific]
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 51b16f0ce3546..23fe96d604604 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -135,3 +135,53 @@
 
 void f(void) {
 }
+
+
+// RUN: not %clang_cl -### --target=i386 -mapx-features=ndd %s 2>&1 | 
FileCheck --check-prefix=NON-APX %s
+// RUN: not %clang_cl -### --target=i386 -mapxf %s 2>&1 | FileCheck 
--check-prefix=NON-APX %s
+// RUN: %clang_cl -### --target=i386 -mno-apxf %s 2>&1 > /dev/null
+// NON-APX:  error: unsupported option '-mapx-features=|-mapxf' for target 
'i386'
+// NON-APX-NOT:  error: {{.*}} -mapx-features=
+
+// RUN: %clang_cl -target x86_64-pc-windows -mapxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=APXF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mno-apxf %s -### -o %t.o 2>&1 | 
FileCheck -check-prefix=NO-APXF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mno-apxf -mapxf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=APXF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapxf -mno-apxf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NO-APXF %s
+//
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" 
"-target-feature" "+nf" "-target-feature" "+cf" "-target-feature" "+zu"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx" "-target-feature" "-ndd" "-target-feature" "-ccmp" 
"-target-feature" "-nf" "-target-feature" "-cf" "-target-feature" "-zu"
+
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=egpr %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=EGPR %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=push2pop2 %s -### 
-o %t.o 2>&1 | FileCheck -check-prefix=PUSH2POP2 %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=ppx %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=PPX %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=ndd %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NDD %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=ccmp %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=CCMP %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=nf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=NF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=cf %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=CF %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=zu %s -### -o %t.o 
2>&1 | FileCheck -check-prefix=ZU %s
+// EGPR: "-target-feature" "+egpr"
+// PUSH2POP2: "-target-feature" "+push2pop2"
+// PPX: "-target-feature" "+ppx"
+// NDD: "-target-feature" "+ndd"
+// CCMP: "-target-feature" "+ccmp"
+// NF: "-target-feature" "+nf"
+// CF: "-target-feature" "+cf"
+// ZU: "-target-feature" "+zu"
+
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=egpr,ndd %s -### -o 
%t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang_cl -target x86_64-pc-windows -mapx-features=egpr 
-mapx-features=ndd %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR-NDD %s
+// RUN: %clang_cl -target x86_64-pc-windows -mno-apx-f

[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)

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

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/140871

>From 3e070b23eea6ac3a9514d0cd5c9785e220d5f5e1 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 21 May 2025 10:39:12 +0100
Subject: [PATCH 1/3] [libclc] Move all remquo address spaces to CLC library

Previously the OpenCL address space overloads of remquo would call into
the one and only 'private' CLC remquo. This was an outlier compared with
the other pointer-argumented maths builtins.

This commit moves the definitions of all address space overloads to the
CLC library to give more control over each address space to CLC
implementers.

There are some minor changes to the generated bytecode but it's simply
moving IR instructions around.
---
 libclc/clc/include/clc/math/clc_remquo.h  |   4 +-
 libclc/clc/include/clc/math/remquo_decl.inc   |   8 +-
 libclc/clc/lib/generic/math/clc_remquo.cl | 266 +
 libclc/clc/lib/generic/math/clc_remquo.inc| 271 ++
 .../opencl/include/clc/opencl/math/remquo.h   |  12 -
 libclc/opencl/lib/generic/math/remquo.cl  |  12 -
 libclc/opencl/lib/generic/math/remquo.inc |  17 +-
 7 files changed, 300 insertions(+), 290 deletions(-)
 create mode 100644 libclc/clc/lib/generic/math/clc_remquo.inc

diff --git a/libclc/clc/include/clc/math/clc_remquo.h 
b/libclc/clc/include/clc/math/clc_remquo.h
index 5dea818013c68..48a8844a6e384 100644
--- a/libclc/clc/include/clc/math/clc_remquo.h
+++ b/libclc/clc/include/clc/math/clc_remquo.h
@@ -10,12 +10,10 @@
 #define __CLC_MATH_CLC_REMQUO_H__
 
 #define __CLC_FUNCTION __clc_remquo
-
 #define __CLC_BODY 
-#define __CLC_ADDRESS_SPACE private
+
 #include 
 
-#undef __CLC_ADDRESS_SPACE
 #undef __CLC_FUNCTION
 
 #endif // __CLC_MATH_CLC_REMQUO_H__
diff --git a/libclc/clc/include/clc/math/remquo_decl.inc 
b/libclc/clc/include/clc/math/remquo_decl.inc
index ecd703042a964..0b650795909b0 100644
--- a/libclc/clc/include/clc/math/remquo_decl.inc
+++ b/libclc/clc/include/clc/math/remquo_decl.inc
@@ -7,4 +7,10 @@
 
//===--===//
 
 _CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
-__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q);
+__CLC_GENTYPE x, __CLC_GENTYPE y, private __CLC_INTN *q);
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
+__CLC_GENTYPE x, __CLC_GENTYPE y, global __CLC_INTN *q);
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
+__CLC_GENTYPE x, __CLC_GENTYPE y, local __CLC_INTN *q);
diff --git a/libclc/clc/lib/generic/math/clc_remquo.cl 
b/libclc/clc/lib/generic/math/clc_remquo.cl
index 9fa94c1c290b8..2f3b6f0339e17 100644
--- a/libclc/clc/lib/generic/math/clc_remquo.cl
+++ b/libclc/clc/lib/generic/math/clc_remquo.cl
@@ -18,262 +18,14 @@
 #include 
 #include 
 
-_CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y,
-  __private int *quo) {
-  x = __clc_flush_denormal_if_not_supported(x);
-  y = __clc_flush_denormal_if_not_supported(y);
-  int ux = __clc_as_int(x);
-  int ax = ux & EXSIGNBIT_SP32;
-  float xa = __clc_as_float(ax);
-  int sx = ux ^ ax;
-  int ex = ax >> EXPSHIFTBITS_SP32;
+#define __CLC_ADDRESS_SPACE private
+#include 
+#undef __CLC_ADDRESS_SPACE
 
-  int uy = __clc_as_int(y);
-  int ay = uy & EXSIGNBIT_SP32;
-  float ya = __clc_as_float(ay);
-  int sy = uy ^ ay;
-  int ey = ay >> EXPSHIFTBITS_SP32;
+#define __CLC_ADDRESS_SPACE global
+#include 
+#undef __CLC_ADDRESS_SPACE
 
-  float xr = __clc_as_float(0x3f80 | (ax & 0x007f));
-  float yr = __clc_as_float(0x3f80 | (ay & 0x007f));
-  int c;
-  int k = ex - ey;
-
-  uint q = 0;
-
-  while (k > 0) {
-c = xr >= yr;
-q = (q << 1) | c;
-xr -= c ? yr : 0.0f;
-xr += xr;
---k;
-  }
-
-  c = xr > yr;
-  q = (q << 1) | c;
-  xr -= c ? yr : 0.0f;
-
-  int lt = ex < ey;
-
-  q = lt ? 0 : q;
-  xr = lt ? xa : xr;
-  yr = lt ? ya : yr;
-
-  c = (yr < 2.0f * xr) | ((yr == 2.0f * xr) & ((q & 0x1) == 0x1));
-  xr -= c ? yr : 0.0f;
-  q += c;
-
-  float s = __clc_as_float(ey << EXPSHIFTBITS_SP32);
-  xr *= lt ? 1.0f : s;
-
-  int qsgn = sx == sy ? 1 : -1;
-  int quot = (q & 0x7f) * qsgn;
-
-  c = ax == ay;
-  quot = c ? qsgn : quot;
-  xr = c ? 0.0f : xr;
-
-  xr = __clc_as_float(sx ^ __clc_as_int(xr));
-
-  c = ax > PINFBITPATT_SP32 | ay > PINFBITPATT_SP32 | ax == PINFBITPATT_SP32 |
-  ay == 0;
-  quot = c ? 0 : quot;
-  xr = c ? __clc_as_float(QNANBITPATT_SP32) : xr;
-
-  *quo = quot;
-
-  return xr;
-}
-// remquo signature is special, we don't have macro for this
-#define __VEC_REMQUO(TYPE, VEC_SIZE, HALF_VEC_SIZE)
\
-  _CLC_DEF _CLC_OVERLOAD TYPE##VEC_SIZE __clc_remquo(  
\
-  TYPE##VEC_SIZE x, TYPE##VEC_SIZE y, __private int##VEC_SIZE *quo) {  
\
-int##HALF_VEC_SIZE lo, hi; 
\
-TYPE##VEC_SIZE ret;   

[clang] [Clang][AArch64]Add FP8 ACLE macros implementation (PR #140591)

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


@@ -744,3 +744,38 @@
 // CHECK-SMEB16B16: __ARM_FEATURE_SME2 1
 // CHECK-SMEB16B16: __ARM_FEATURE_SME_B16B16 1
 // CHECK-SMEB16B16: __ARM_FEATURE_SVE_B16B16 1
+//
+//  RUN: %clang --target=aarch64 -march=armv9-a+fp8 -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-FP8 %s
+// CHECK-FP8: __ARM_FEATURE_FP8 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+fp8fma -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-FP8FMA %s
+// CHECK-FP8FMA: __ARM_FEATURE_FP8 1
+// CHECK-FP8FMA: __ARM_FEATURE_FP8FMA 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+fp8dot2 -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-FP8DOT2 %s
+// CHECK-FP8DOT2: __ARM_FEATURE_FP8 1
+// CHECK-FP8DOT2: __ARM_FEATURE_FP8DOT2 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+fp8dot4 -x c -E -dM %s -o - | 
FileCheck --check-prefix=CHECK-FP8DOT4 %s
+// CHECK-FP8DOT4: __ARM_FEATURE_FP8 1
+// CHECK-FP8DOT4: __ARM_FEATURE_FP8DOT4 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+ssve-fp8dot2 -x c -E -dM %s -o 
- | FileCheck --check-prefix=CHECK-SSVE-FP8DOT2 %s
+// CHECK-SSVE-FP8DOT2: __ARM_FEATURE_SME2 1
+// CHECK-SSVE-FP8DOT2: __ARM_FEATURE_SSVE_FP8DOT2 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+ssve-fp8dot4 -x c -E -dM %s -o 
- | FileCheck --check-prefix=CHECK-SSVE-FP8DOT4 %s
+// CHECK-SSVE-FP8DOT4: __ARM_FEATURE_SME2 1
+// CHECK-SSVE-FP8DOT4: __ARM_FEATURE_SSVE_FP8DOT4 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+ssve-fp8fma -x c -E -dM %s -o - 
| FileCheck --check-prefix=CHECK-SSVE-FP8FMA %s
+// CHECK-SSVE-FP8FMA: __ARM_FEATURE_SME2 1
+// CHECK-SSVE-FP8FMA: __ARM_FEATURE_SSVE_FP8FMA 1

paulwalker-arm wrote:

Can the three `_ssve-fp8...` options also check for `__ARM_FEATURE_FP8`?

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


[clang] [Clang][AArch64]Add FP8 ACLE macros implementation (PR #140591)

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

https://github.com/paulwalker-arm commented:

Last question but otherwise this looks good to me.

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


[clang] [Clang][AArch64]Add FP8 ACLE macros implementation (PR #140591)

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

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


[clang] [Clang][Sema] Reject array prvalue operands (PR #140702)

2025-05-21 Thread via cfe-commits


@@ -7639,6 +7639,8 @@ def warn_param_mismatched_alignment : Warning<
 
 def err_objc_object_assignment : Error<
   "cannot assign to class object (%0 invalid)">;
+def err_typecheck_array_prvalue_operand : Error<
+  "array prvalue is not permitted">;

languagelawyer wrote:

@zwuis is `"operand cannot be an array prvalue"` ok? Comparing to an existing 
error:
```c++
IA{ 1, 2, 3 } + 0.;
IA{ 1, 2, 3 } + 0;
```
```
test.cxx:5:16: error: invalid operands to binary expression ('int[3]' and 
'double')
test.cxx:6:16: error: operand cannot be an array prvalue
```

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


[clang] [analyzer] Add previous CFG block to BlockEntrance ProgramPoints (PR #140861)

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

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


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


[clang] [CIR] Add support for recursive record layouts (PR #140811)

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

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


[clang] [CIR] Add support for recursive record layouts (PR #140811)

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

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

lgtm

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


[clang] [analyzer] Add previous CFG block to BlockEntrance ProgramPoints (PR #140861)

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

https://github.com/NagyDonat commented:

LGTM, straightforward simple extension.

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


[clang-tools-extra] [clang-tools-extra] Remove redundant control flow statements (NFC) (PR #140846)

2025-05-21 Thread Kazu Hirata via cfe-commits

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


[clang] [analyzer] Add previous CFG block to BlockEntrance ProgramPoints (PR #140861)

2025-05-21 Thread Balázs Benics via cfe-commits

balazs-benics-sonarsource wrote:

/cc @necto 

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


[clang] [analyzer] Add previous CFG block to BlockEntrance ProgramPoints (PR #140861)

2025-05-21 Thread Balázs Benics via cfe-commits

https://github.com/balazs-benics-sonarsource created 
https://github.com/llvm/llvm-project/pull/140861

This helps to gain contextual information about how we entered a CFG block.

The `noexprcrash.c` test probably changed due to the fact that now 
BlockEntrance ProgramPoint Profile also hashes the pointer of the previous CFG 
block. I didn't investigate.

CPP-6483

From 1378271ee639bf3307cb373f07f730978373be7b Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Thu, 15 May 2025 15:21:48 +0200
Subject: [PATCH] [analyzer] Add previous CFG block to BlockEntrance
 ProgramPoints

This helps to gain contextual information about how we entered
a CFG block.

The `noexprcrash.c` test probably changed due to the fact that now
BlockEntrance ProgramPoint Profile also hashes the pointer of the
previous CFG block. I didn't investigate.

CPP-6483
---
 clang/include/clang/Analysis/ProgramPoint.h| 18 --
 clang/lib/StaticAnalyzer/Core/CoreEngine.cpp   |  2 +-
 .../Analysis/exploration_order/noexprcrash.c   | 11 ++-
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Analysis/ProgramPoint.h 
b/clang/include/clang/Analysis/ProgramPoint.h
index c40aa3d8ffb72..096ad48a42984 100644
--- a/clang/include/clang/Analysis/ProgramPoint.h
+++ b/clang/include/clang/Analysis/ProgramPoint.h
@@ -224,10 +224,14 @@ class ProgramPoint {
 
 class BlockEntrance : public ProgramPoint {
 public:
-  BlockEntrance(const CFGBlock *B, const LocationContext *L,
-const ProgramPointTag *tag = nullptr)
-: ProgramPoint(B, BlockEntranceKind, L, tag) {
-assert(B && "BlockEntrance requires non-null block");
+  BlockEntrance(const CFGBlock *PrevBlock, const CFGBlock *CurrBlock,
+const LocationContext *L, const ProgramPointTag *Tag = nullptr)
+  : ProgramPoint(CurrBlock, PrevBlock, BlockEntranceKind, L, Tag) {
+assert(CurrBlock && "BlockEntrance requires non-null block");
+  }
+
+  const CFGBlock *getPreviousBlock() const {
+return reinterpret_cast(getData2());
   }
 
   const CFGBlock *getBlock() const {
@@ -760,13 +764,15 @@ template <> struct DenseMapInfo {
 static inline clang::ProgramPoint getEmptyKey() {
   uintptr_t x =
reinterpret_cast(DenseMapInfo::getEmptyKey()) & ~0x7;
-  return clang::BlockEntrance(reinterpret_cast(x), nullptr);
+  return clang::BlockEntrance(nullptr, reinterpret_cast(x),
+  nullptr);
 }
 
 static inline clang::ProgramPoint getTombstoneKey() {
   uintptr_t x =
reinterpret_cast(DenseMapInfo::getTombstoneKey()) & ~0x7;
-  return clang::BlockEntrance(reinterpret_cast(x), nullptr);
+  return clang::BlockEntrance(nullptr, reinterpret_cast(x),
+  nullptr);
 }
 
 static unsigned getHashValue(const clang::ProgramPoint &Loc) {
diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 8cc086a12ad70..bedb11f8b94a5 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -315,7 +315,7 @@ void CoreEngine::HandleBlockEdge(const BlockEdge &L, 
ExplodedNode *Pred) {
 
   // Call into the ExprEngine to process entering the CFGBlock.
   ExplodedNodeSet dstNodes;
-  BlockEntrance BE(Blk, Pred->getLocationContext());
+  BlockEntrance BE(L.getSrc(), L.getDst(), Pred->getLocationContext());
   NodeBuilderWithSinks nodeBuilder(Pred, dstNodes, BuilderCtx, BE);
   ExprEng.processCFGBlockEntrance(L, nodeBuilder, Pred);
 
diff --git a/clang/test/Analysis/exploration_order/noexprcrash.c 
b/clang/test/Analysis/exploration_order/noexprcrash.c
index 75c2f0e6798a3..427c669783374 100644
--- a/clang/test/Analysis/exploration_order/noexprcrash.c
+++ b/clang/test/Analysis/exploration_order/noexprcrash.c
@@ -1,17 +1,18 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
-analyzer-config exploration_strategy=unexplored_first %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
-analyzer-config exploration_strategy=dfs %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
-verify=common,ufirst -analyzer-config exploration_strategy=unexplored_first %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
-verify=common,dfs -analyzer-config exploration_strategy=dfs %s
 
 extern void clang_analyzer_eval(int);
 
 typedef struct { char a; } b;
 int c(b* input) {
-int x = (input->a ?: input) ? 1 : 0; // expected-warning{{pointer/integer 
type mismatch}}
+int x = (input->a ?: input) ? 1 : 0; // common-warning{{pointer/integer 
type mismatch}}
 if (input->a) {
   // FIXME: The value should actually be "TRUE",
   // but is incorrect due to a bug.
-  clang_analyzer_eval(x); // expected-warning{{FALSE}}
+  // dfs-warning@+1 {{FALSE}} ufirst-warning@+1 {{TRUE}}
+  clang_analyzer_eval(x);
 } else {
-  clang_analyzer_eval(x); // expected-warning{{TRUE}}
+ 

[clang] [analyzer] Add previous CFG block to BlockEntrance ProgramPoints (PR #140861)

2025-05-21 Thread via cfe-commits

llvmbot wrote:




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

Author: Balázs Benics (balazs-benics-sonarsource)


Changes

This helps to gain contextual information about how we entered a CFG block.

The `noexprcrash.c` test probably changed due to the fact that now 
BlockEntrance ProgramPoint Profile also hashes the pointer of the previous CFG 
block. I didn't investigate.

CPP-6483

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


3 Files Affected:

- (modified) clang/include/clang/Analysis/ProgramPoint.h (+12-6) 
- (modified) clang/lib/StaticAnalyzer/Core/CoreEngine.cpp (+1-1) 
- (modified) clang/test/Analysis/exploration_order/noexprcrash.c (+6-5) 


``diff
diff --git a/clang/include/clang/Analysis/ProgramPoint.h 
b/clang/include/clang/Analysis/ProgramPoint.h
index c40aa3d8ffb72..096ad48a42984 100644
--- a/clang/include/clang/Analysis/ProgramPoint.h
+++ b/clang/include/clang/Analysis/ProgramPoint.h
@@ -224,10 +224,14 @@ class ProgramPoint {
 
 class BlockEntrance : public ProgramPoint {
 public:
-  BlockEntrance(const CFGBlock *B, const LocationContext *L,
-const ProgramPointTag *tag = nullptr)
-: ProgramPoint(B, BlockEntranceKind, L, tag) {
-assert(B && "BlockEntrance requires non-null block");
+  BlockEntrance(const CFGBlock *PrevBlock, const CFGBlock *CurrBlock,
+const LocationContext *L, const ProgramPointTag *Tag = nullptr)
+  : ProgramPoint(CurrBlock, PrevBlock, BlockEntranceKind, L, Tag) {
+assert(CurrBlock && "BlockEntrance requires non-null block");
+  }
+
+  const CFGBlock *getPreviousBlock() const {
+return reinterpret_cast(getData2());
   }
 
   const CFGBlock *getBlock() const {
@@ -760,13 +764,15 @@ template <> struct DenseMapInfo {
 static inline clang::ProgramPoint getEmptyKey() {
   uintptr_t x =
reinterpret_cast(DenseMapInfo::getEmptyKey()) & ~0x7;
-  return clang::BlockEntrance(reinterpret_cast(x), nullptr);
+  return clang::BlockEntrance(nullptr, reinterpret_cast(x),
+  nullptr);
 }
 
 static inline clang::ProgramPoint getTombstoneKey() {
   uintptr_t x =
reinterpret_cast(DenseMapInfo::getTombstoneKey()) & ~0x7;
-  return clang::BlockEntrance(reinterpret_cast(x), nullptr);
+  return clang::BlockEntrance(nullptr, reinterpret_cast(x),
+  nullptr);
 }
 
 static unsigned getHashValue(const clang::ProgramPoint &Loc) {
diff --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 8cc086a12ad70..bedb11f8b94a5 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -315,7 +315,7 @@ void CoreEngine::HandleBlockEdge(const BlockEdge &L, 
ExplodedNode *Pred) {
 
   // Call into the ExprEngine to process entering the CFGBlock.
   ExplodedNodeSet dstNodes;
-  BlockEntrance BE(Blk, Pred->getLocationContext());
+  BlockEntrance BE(L.getSrc(), L.getDst(), Pred->getLocationContext());
   NodeBuilderWithSinks nodeBuilder(Pred, dstNodes, BuilderCtx, BE);
   ExprEng.processCFGBlockEntrance(L, nodeBuilder, Pred);
 
diff --git a/clang/test/Analysis/exploration_order/noexprcrash.c 
b/clang/test/Analysis/exploration_order/noexprcrash.c
index 75c2f0e6798a3..427c669783374 100644
--- a/clang/test/Analysis/exploration_order/noexprcrash.c
+++ b/clang/test/Analysis/exploration_order/noexprcrash.c
@@ -1,17 +1,18 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
-analyzer-config exploration_strategy=unexplored_first %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
-analyzer-config exploration_strategy=dfs %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
-verify=common,ufirst -analyzer-config exploration_strategy=unexplored_first %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
-verify=common,dfs -analyzer-config exploration_strategy=dfs %s
 
 extern void clang_analyzer_eval(int);
 
 typedef struct { char a; } b;
 int c(b* input) {
-int x = (input->a ?: input) ? 1 : 0; // expected-warning{{pointer/integer 
type mismatch}}
+int x = (input->a ?: input) ? 1 : 0; // common-warning{{pointer/integer 
type mismatch}}
 if (input->a) {
   // FIXME: The value should actually be "TRUE",
   // but is incorrect due to a bug.
-  clang_analyzer_eval(x); // expected-warning{{FALSE}}
+  // dfs-warning@+1 {{FALSE}} ufirst-warning@+1 {{TRUE}}
+  clang_analyzer_eval(x);
 } else {
-  clang_analyzer_eval(x); // expected-warning{{TRUE}}
+  clang_analyzer_eval(x); // common-warning{{TRUE}}
 }
 return x;
 }

``




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


[clang] [libc] [llvm] [clang] Make __builtin_expf constexpr. (PR #140841)

2025-05-21 Thread Alexey Samsonov via cfe-commits


@@ -33,7 +33,7 @@ to learn about the defaults for your platform and target.
 * **"general" options**
 - ``LIBC_ADD_NULL_CHECKS``: Add nullptr checks in the library's 
implementations to some functions for which passing nullptr is undefined 
behavior.
 * **"math" options**
-- ``LIBC_CONF_FREXP_INF_NAN_EXPONENT``: The value written back to the 
second parameter when calling frexp/frexpf/frexpl` with `+/-Inf`/`NaN` is 
unspecified.  Configure an explicit exp value for Inf/NaN inputs.
+- ``LIBC_CONF_FREXP_INF_NAN_EXPONENT``: The value written back to the 
second parameter when calling frexp/frexpf/frexpl` with `+/-Inf`/`NaN` is 
unspecified.  Configue an explicit exp value for Inf/NaN inputs.

vonosmas wrote:

Does this reverts a landed fix to docs?

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


[clang] [llvm] [RISCV] Add Andes A25/AX25 processor definition (PR #140681)

2025-05-21 Thread Jim Lin via cfe-commits


@@ -648,6 +648,38 @@ def RP2350_HAZARD3 : RISCVProcessorModel<"rp2350-hazard3",
   FeatureStdExtZcb,
   FeatureStdExtZcmp]>;
 
+def ANDES_A25 : RISCVProcessorModel<"andes-a25",
+NoSchedModel,
+[Feature32Bit,
+ FeatureStdExtI,
+ FeatureStdExtZicsr,
+ FeatureStdExtZifencei,
+ FeatureStdExtM,
+ FeatureStdExtA,
+ FeatureStdExtF,
+ FeatureStdExtD,
+ FeatureStdExtC,
+ FeatureStdExtZba,
+ FeatureStdExtZbb,
+ FeatureStdExtZbc,
+ FeatureStdExtZbs]>;

tclin914 wrote:

Done.

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


[clang] Fixed issue #128882: don't warn if 1st argument to 'getcwd' is NULL (PR #135720)

2025-05-21 Thread Balázs Kéri via cfe-commits


@@ -105,9 +105,6 @@ void errno_getcwd(char *Buf, size_t Sz) {
 clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
 clang_analyzer_eval(Path == NULL); // expected-warning{{TRUE}}
 if (errno) {}  // no warning
-  } else if (Path == NULL) {
-clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
-if (errno) {}  // no warning

balazske wrote:

I think the following tests would be good in the llvm main branch:
```c
void errno_getcwd_buf_nonnull(char *Buf, size_t Sz) {
  if (Buf == NULL)
return;
  char *Path = getcwd(Buf, Sz);
  if (Sz == 0) {
clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
clang_analyzer_eval(Path == NULL); // expected-warning{{TRUE}}
if (errno) {}  // no warning
  } else if (Path == NULL) {
clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
if (errno) {}  // no warning
  } else {
clang_analyzer_eval(Path == Buf);  // expected-warning{{TRUE}}
if (errno) {}  // expected-warning{{An undefined value 
may be read from 'errno'}}
  }
}

void errno_getcwd_buf_null() {
  // POSIX does not mention this case but many implementations (Linux, FreeBSD) 
work this way.
  char *Path = getcwd(NULL, 1);
  if (Path == NULL) {
clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
if (errno) {}  // no warning
  } else {
if (errno) {}  // expected-warning{{An undefined value 
may be read from 'errno'}}
  }
}
```
I can add the patch for this in the next few days.

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


[clang] [clang][bytecode] Initialize global strings via memcpy (PR #140789)

2025-05-21 Thread Timm Baeder via cfe-commits

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


[clang] [llvm] [RISCV] Add Andes A25/AX25 processor definition (PR #140681)

2025-05-21 Thread Jim Lin via cfe-commits


@@ -648,6 +648,38 @@ def RP2350_HAZARD3 : RISCVProcessorModel<"rp2350-hazard3",
   FeatureStdExtZcb,
   FeatureStdExtZcmp]>;
 
+def ANDES_A25 : RISCVProcessorModel<"andes-a25",
+NoSchedModel,
+[Feature32Bit,
+ FeatureStdExtI,
+ FeatureStdExtZicsr,
+ FeatureStdExtZifencei,
+ FeatureStdExtM,
+ FeatureStdExtA,
+ FeatureStdExtF,
+ FeatureStdExtD,
+ FeatureStdExtC,
+ FeatureStdExtZba,
+ FeatureStdExtZbb,
+ FeatureStdExtZbc,
+ FeatureStdExtZbs]>;
+
+def ANDES_AX25 : RISCVProcessorModel<"andes-ax25",
+ NoSchedModel,
+ [Feature64Bit,
+  FeatureStdExtI,
+  FeatureStdExtZicsr,
+  FeatureStdExtZifencei,
+  FeatureStdExtM,
+  FeatureStdExtA,
+  FeatureStdExtF,
+  FeatureStdExtD,
+  FeatureStdExtC,
+  FeatureStdExtZba,
+  FeatureStdExtZbb,
+  FeatureStdExtZbc,
+  FeatureStdExtZbs]>;

tclin914 wrote:

Done.

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


[clang] [NVPTX] Support the OpenCL generic addrspace feature by default (PR #137940)

2025-05-21 Thread Sven van Haastregt via cfe-commits


@@ -170,6 +170,8 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public 
TargetInfo {
 Opts["cl_khr_global_int32_extended_atomics"] = true;
 Opts["cl_khr_local_int32_base_atomics"] = true;
 Opts["cl_khr_local_int32_extended_atomics"] = true;
+
+Opts["__opencl_c_generic_address_space"] = true;

svenvh wrote:

This is target specific, so I agree with @frasercrmck 's reasoning and would 
say it's fine as is.

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


[clang] [NVPTX] Support the OpenCL generic addrspace feature by default (PR #137940)

2025-05-21 Thread Matt Arsenault via cfe-commits

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


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


[clang] [Clang] Fix a regression introduced by #140576 (PR #140859)

2025-05-21 Thread Daniel Bertalan via cfe-commits

BertalanD wrote:

Thank you; this fixes our build!

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


[clang] [llvm] [UBSan] Implement src:*=sanitize for UBSan (PR #140529)

2025-05-21 Thread Vitaly Buka via cfe-commits


@@ -103,6 +101,22 @@ supported sanitizers.
 char c = toobig; // also not instrumented
   }
 
+Conflicting entries are resolved by the latest entry, which takes precedence.

vitalybuka wrote:

If multiple entries match the source, than the latest entry takes the 
precedence.

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


[clang-tools-extra] [clang-tools-extra] Remove redundant control flow statements (NFC) (PR #140846)

2025-05-21 Thread Matt Arsenault via cfe-commits

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


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


[clang-tools-extra] [clang-doc] fix names of conversions for template parameters (PR #140856)

2025-05-21 Thread Erick Velez via cfe-commits

evelez7 wrote:

Should note that #59812 also mentions the `requires` clause being omitted but 
that should be addressed by a different issue/patch because that will be 
applicable to all function types.

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


[clang-tools-extra] [clang-doc] fix names of conversions for template parameters (PR #140856)

2025-05-21 Thread Erick Velez via cfe-commits

https://github.com/evelez7 created 
https://github.com/llvm/llvm-project/pull/140856

Fixes #59812

The names of conversion functions of template type parameters were being 
emitted as "type-parameter-N-M". Now we check if the conversion type is a 
TemplateTypeParmType and reconstruct the source name.

>From e25581d28ecda89fe4e550da71e668b6ae749804 Mon Sep 17 00:00:00 2001
From: Erick Velez 
Date: Tue, 20 May 2025 23:26:02 -0700
Subject: [PATCH] [clang-doc] fix conversion names of dependent types

Fixes #59812

The names of conversion functions of template type parameters were
being emitted as "type-parameter-N-M". Now we check if the conversion
type is a TemplateTypeParmType and reconstruct the source name.
---
 clang-tools-extra/clang-doc/Serialize.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 18db427b5239e..585a46112d43d 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -525,7 +525,13 @@ template 
 static void populateInfo(Info &I, const T *D, const FullComment *C,
  bool &IsInAnonymousNamespace) {
   I.USR = getUSRForDecl(D);
-  I.Name = D->getNameAsString();
+  auto ConversionDecl = dyn_cast_or_null(D);
+  if (ConversionDecl && ConversionDecl->getConversionType()
+.getTypePtr()
+->isTemplateTypeParmType())
+I.Name = "operator " + ConversionDecl->getConversionType().getAsString();
+  else
+I.Name = D->getNameAsString();
   populateParentNamespaces(I.Namespace, D, IsInAnonymousNamespace);
   if (C) {
 I.Description.emplace_back();

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


[clang-tools-extra] [clang-tools-extra] Remove redundant control flow statements (NFC) (PR #140846)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-quick` 
running on `linaro-clang-aarch64-quick` while building `clang-tools-extra` at 
step 5 "ninja check 1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'lit :: timeout-hang.py' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 13
not env -u FILECHECK_OPTS "/usr/bin/python3.10" 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical Inputs/timeout-hang/run-nonexistent.txt  --timeout=1 --param 
external=0 | "/usr/bin/python3.10" 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/timeout-hang.py
 1
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3.10 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/llvm/utils/lit/lit.py -j1 
--order=lexical Inputs/timeout-hang/run-nonexistent.txt --timeout=1 --param 
external=0
# .---command stderr
# | lit.py: 
/home/tcwg-buildbot/worker/clang-aarch64-quick/llvm/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 1 seconds was requested on the command line. Forcing 
timeout to be 1 seconds.
# `-
# executed command: /usr/bin/python3.10 
/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/utils/lit/tests/timeout-hang.py
 1
# .---command stdout
# | Testing took as long or longer than timeout
# `-
# error: command failed with exit status: 1

--




```



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


[clang] [clang][NFC] Clean up ASTContext.cpp (PR #140847)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `publish-sphinx-docs` 
running on `as-worker-4` while building `clang` at step 6 "Publish 
docs-llvm-html".

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


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

```
Step 6 (Publish docs-llvm-html) failure: 'rsync -vrl ...' (failure)
ssh: connect to host lists.llvm.org port 22: Connection timed out
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]
Step 7 (Publish docs-clang-html) failure: 'rsync -vrl ...' (failure)
ssh: connect to host lists.llvm.org port 22: Connection timed out
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]

```



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


[clang] [Clang] Fix a regression introduced by #140576 (PR #140859)

2025-05-21 Thread Hans Wennborg via cfe-commits

zmodem wrote:

Ours too :-)

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


[clang] [llvm] [RISCV] Add Andes A25/AX25 processor definition (PR #140681)

2025-05-21 Thread Jim Lin via cfe-commits

https://github.com/tclin914 updated 
https://github.com/llvm/llvm-project/pull/140681

>From 98bdcfd0b57b482f31be098e069e610897cc1425 Mon Sep 17 00:00:00 2001
From: Jim Lin 
Date: Tue, 20 May 2025 10:13:26 +0800
Subject: [PATCH 1/4] [RISCV] Add Andes A25/AX25 processor definition

Andes A25/AX25 are 32/64bit, 5-stage pipeline, linux-capable
CPUs that implement the RV[32|64]IMAFDC_Zba_Zbb_Zbc_Zbs ISA extensions.
They are developed by Andes Technology https://www.andestech.com, a RISC-V IP 
provider.

The overviews for A25/AX25:
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-a25/
https://www.andestech.com/en/products-solutions/andescore-processors/riscv-ax25/

Scheduling model will be implemented in a later PR.
---
 clang/test/Driver/riscv-cpus.c| 36 +++
 .../test/Misc/target-invalid-cpu-note/riscv.c | 12 ---
 llvm/docs/ReleaseNotes.md |  1 +
 llvm/lib/Target/RISCV/RISCVProcessors.td  | 32 +
 4 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index dacdb03fd09d9..cebf41aa626a7 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -699,6 +699,42 @@
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=syntacore-scr7 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR7 %s
 // MTUNE-SYNTACORE-SCR7: "-tune-cpu" "syntacore-scr7"
 
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=andes-a25 | FileCheck 
-check-prefix=MCPU-ANDES-A25 %s
+// MCPU-ANDES-A25: "-target-cpu" "andes-a25"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+m"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+a"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+f"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+d"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+c"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+zicsr"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+zifencei"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+zba"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+zbb"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+zbc"
+// MCPU-ANDES-A25-SAME: "-target-feature" "+zbs"
+// MCPU-ANDES-A25-SAME: "-target-abi" "ilp32d"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=andes-a25 | FileCheck 
-check-prefix=MTUNE-ANDES-A25 %s
+// MTUNE-ANDES-A25: "-tune-cpu" "andes-a25"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=andes-ax25 | FileCheck 
-check-prefix=MCPU-ANDES-AX25 %s
+// MCPU-ANDES-AX25: "-target-cpu" "andes-ax25"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+m"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+a"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+f"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+d"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+c"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+zicsr"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+zifencei"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+zba"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+zbb"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+zbc"
+// MCPU-ANDES-AX25-SAME: "-target-feature" "+zbs"
+// MCPU-ANDES-AX25-SAME: "-target-abi" "lp64d"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=andes-ax25 | FileCheck 
-check-prefix=MTUNE-ANDES-AX25 %s
+// MTUNE-ANDES-AX25: "-tune-cpu" "andes-ax25"
+
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=andes-n45 | FileCheck 
-check-prefix=MCPU-ANDES-N45 %s
 // MCPU-ANDES-N45: "-target-cpu" "andes-n45"
 // MCPU-ANDES-N45-SAME: "-target-feature" "+m"
diff --git a/clang/test/Misc/target-invalid-cpu-note/riscv.c 
b/clang/test/Misc/target-invalid-cpu-note/riscv.c
index b4e83e59d296f..c57bde8aa531a 100644
--- a/clang/test/Misc/target-invalid-cpu-note/riscv.c
+++ b/clang/test/Misc/target-invalid-cpu-note/riscv.c
@@ -5,7 +5,8 @@
 // RUN: not %clang_cc1 -triple riscv32 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV32
 // RISCV32: error: unknown target CPU 'not-a-cpu'
 // RISCV32-NEXT: note: valid target CPU values are:
-// RISCV32-SAME: {{^}} andes-a45
+// RISCV32-SAME: {{^}} andes-a25
+// RISCV32-SAME: {{^}}, andes-a45
 // RISCV32-SAME: {{^}}, andes-n45
 // RISCV32-SAME: {{^}}, generic-rv32
 // RISCV32-SAME: {{^}}, rocket-rv32
@@ -26,7 +27,8 @@
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
 // RISCV64-NEXT: note: valid target CPU values are:
-// RISCV64-SAME: {{^}} andes-ax45
+// RISCV64-SAME: {{^}} andes-ax25
+// RISCV64-SAME: {{^}}, andes-ax45
 // RISCV64-SAME: {{^}}, andes-nx45
 // RISCV64-SAME: {{^}}, generic-rv64
 // RISCV64-SAME: {{^}}, mips-p8700
@@ -57,7 +59,8 @@
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
 // TUNE-RISCV32-NEXT: note: valid target CPU values are:
-// TUNE-RISCV32-SAME: {{^}} andes-a45
+// TUNE-RISCV32-SAME: 

[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (PR #140753)

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

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


[clang] [libcxx] [Clang] Add __builtin_invoke and use it in libc++ (PR #116709)

2025-05-21 Thread Nikolas Klauser via cfe-commits

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

>From e0bb550672326e21a556ac727f2e2a6ef65f0469 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 1 Oct 2024 11:08:02 +0200
Subject: [PATCH 1/5] [Clang] Add __builtin_invoke and recognize std::invoke as
 a builtin

---
 clang/include/clang/Basic/Builtins.td |   6 +
 clang/include/clang/Sema/Sema.h   |   9 +
 clang/lib/Parse/ParseDeclCXX.cpp  |  24 +--
 clang/lib/Sema/SemaChecking.cpp   |  97 +++
 clang/lib/Sema/SemaExprCXX.cpp| 105 ++--
 clang/test/CodeGenCXX/builtin-invoke.cpp  |  61 +++
 clang/test/SemaCXX/builtin-invoke.cpp | 133 +++
 libcxx/include/__type_traits/invoke.h | 155 ++
 .../__type_traits/is_core_convertible.h   |  11 ++
 9 files changed, 499 insertions(+), 102 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/builtin-invoke.cpp
 create mode 100644 clang/test/SemaCXX/builtin-invoke.cpp

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 187d3b5ed24a7..58cc35088c40a 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4272,6 +4272,12 @@ def MoveIfNsoexcept : CxxLibBuiltin<"utility"> {
   let Namespace = "std";
 }
 
+def Invoke : Builtin {
+  let Spellings = ["__builtin_invoke"];
+  let Attributes = [CustomTypeChecking, Constexpr];
+  let Prototype = "void(...)";
+}
+
 def Annotation : Builtin {
   let Spellings = ["__builtin_annotation"];
   let Attributes = [NoThrow, CustomTypeChecking];
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5ec67087aeea4..22d66e8688906 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2594,6 +2594,8 @@ class Sema final : public SemaBase {
SourceLocation BuiltinLoc,
SourceLocation RParenLoc);
 
+  ExprResult BuiltinInvoke(CallExpr *TheCall);
+
   static StringRef GetFormatStringTypeName(FormatStringType FST);
   static FormatStringType GetFormatStringType(StringRef FormatFlavor);
   static FormatStringType GetFormatStringType(const FormatAttr *Format);
@@ -15220,11 +15222,18 @@ class Sema final : public SemaBase {
SourceLocation Loc);
   QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind,
   SourceLocation Loc);
+
+  QualType BuiltinRemoveCVRef(QualType BaseType, SourceLocation Loc) {
+return BuiltinRemoveReference(BaseType, UTTKind::RemoveCVRef, Loc);
+  }
+
   QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind,
   SourceLocation Loc);
   QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind,
SourceLocation Loc);
 
+  bool BuiltinIsBaseOf(SourceLocation RhsTLoc, QualType LhsT, QualType RhsT);
+
   /// Ensure that the type T is a literal type.
   ///
   /// This routine checks whether the type @p T is a literal type. If @p T is 
an
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 316bc30edf1f0..aeb1112bad8b4 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1611,29 +1611,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   Tok.isOneOf(
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) tok::kw___##Trait,
 #include "clang/Basic/TransformTypeTraits.def"
-  tok::kw___is_abstract,
-  tok::kw___is_aggregate,
-  tok::kw___is_arithmetic,
-  tok::kw___is_array,
-  tok::kw___is_assignable,
-  tok::kw___is_base_of,
-  tok::kw___is_bounded_array,
-  tok::kw___is_class,
-  tok::kw___is_complete_type,
-  tok::kw___is_compound,
-  tok::kw___is_const,
-  tok::kw___is_constructible,
-  tok::kw___is_convertible,
-  tok::kw___is_convertible_to,
-  tok::kw___is_destructible,
-  tok::kw___is_empty,
-  tok::kw___is_enum,
-  tok::kw___is_floating_point,
-  tok::kw___is_final,
-  tok::kw___is_function,
-  tok::kw___is_fundamental,
-  tok::kw___is_integral,
-  tok::kw___is_interface_class,
+  tok::kw___is_convertible, // Last use in libc++ was removed in 
925a11a
   tok::kw___is_literal,
   tok::kw___is_lvalue_expr,
   tok::kw___is_lvalue_reference,
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a960b9931ddfd..26579de25bdf0 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2368,6 +2368,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, 
unsigned BuiltinID,
 return BuiltinShuffleVector(TheCall);
 // TheCall will be freed by the smart pointer here, but that's fine, s

[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

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

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

LGTM!

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


[clang] [clang-tools-extra] [clang-include-cleaner] Make cleanup attr report expr location (PR #140233)

2025-05-21 Thread kadir çetinkaya via cfe-commits

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


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


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

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


@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =

carlosgalvezp wrote:

Ok! I think this change would have been better to do in #135383, where it 
clearly shows that you need 2 different error messages. 

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


[clang] [clang-tools-extra] [clang-include-cleaner] Make cleanup attr report expr location (PR #140233)

2025-05-21 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet commented:

LG for include-cleaner changes.

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


[clang-tools-extra] 64dcf78 - [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests (#140753)

2025-05-21 Thread via cfe-commits

Author: Baranov Victor
Date: 2025-05-21T10:34:45+02:00
New Revision: 64dcf7893554b44b2a79d23ea0b21d6f3fc2e38f

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

LOG: [clang-tidy][NFC] Refactor `modernize-pass-by-value` check code and tests 
(#140753)

- Deleted unused includes
- Deleted useless braces
- Modernized tests to use `CHECK-MESSAGES-NOT` and `CHECK-FIXES-NOT` for
better readability and maintainability

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
index 7a9d04bfa8ba1..35f90fb8da15b 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -166,9 +166,8 @@ static bool hasRValueOverload(const CXXConstructorDecl 
*Ctor,
   };
 
   for (const auto *Candidate : Record->ctors()) {
-if (IsRValueOverload(Candidate)) {
+if (IsRValueOverload(Candidate))
   return true;
-}
   }
   return false;
 }

diff  --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h 
b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
index c7677edc37dc4..b586b8d5fbf66 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.h
@@ -12,8 +12,6 @@
 #include "../ClangTidyCheck.h"
 #include "../utils/IncludeInserter.h"
 
-#include 
-
 namespace clang::tidy::modernize {
 
 class PassByValueCheck : public ClangTidyCheck {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
index c0ebaebe4ccf6..be33988607b27 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/pass-by-value.cpp
@@ -32,7 +32,6 @@ struct A {
 Movable GlobalObj;
 struct B {
   B(const Movable &M) : M(GlobalObj) {}
-  // CHECK-FIXES: B(const Movable &M) : M(GlobalObj) {}
   Movable M;
 };
 
@@ -40,11 +39,9 @@ struct B {
 struct C {
   // Tests extra-reference in body.
   C(const Movable &M) : M(M) { this->i = M.a; }
-  // CHECK-FIXES: C(const Movable &M) : M(M) { this->i = M.a; }
 
   // Tests extra-reference in init-list.
   C(const Movable &M, int) : M(M), i(M.a) {}
-  // CHECK-FIXES: C(const Movable &M, int) : M(M), i(M.a) {}
   Movable M;
   int i;
 };
@@ -70,7 +67,6 @@ struct E {
 // Test with object that can't be moved.
 struct F {
   F(const NotMovable &NM) : NM(NM) {}
-  // CHECK-FIXES: F(const NotMovable &NM) : NM(NM) {}
   NotMovable NM;
 };
 
@@ -112,7 +108,6 @@ struct I {
 // Test that templates aren't modified.
 template  struct J {
   J(const T &M) : M(M) {}
-  // CHECK-FIXES: J(const T &M) : M(M) {}
   T M;
 };
 J j1(Movable());
@@ -129,13 +124,11 @@ struct MovableTemplateT
 template 
 struct J2 {
   J2(const MovableTemplateT& A);
-  // CHECK-FIXES: J2(const MovableTemplateT& A);
   MovableTemplateT M;
 };
 
 template 
 J2::J2(const MovableTemplateT& A) : M(A) {}
-// CHECK-FIXES: J2::J2(const MovableTemplateT& A) : M(A) {}
 J2 j3(MovableTemplateT{});
 
 struct K_Movable {
@@ -182,7 +175,6 @@ struct O {
 // Test with a const-value parameter.
 struct P {
   P(const Movable M) : M(M) {}
-  // CHECK-FIXES: P(const Movable M) : M(M) {}
   Movable M;
 };
 
@@ -215,7 +207,6 @@ struct R {
 // Test with rvalue parameter.
 struct S {
   S(Movable &&M) : M(M) {}
-  // CHECK-FIXES: S(Movable &&M) : M(M) {}
   Movable M;
 };
 
@@ -225,13 +216,11 @@ template  struct array { T A[N]; };
 // cause problems with performance-move-const-arg, as it will revert it.
 struct T {
   T(array a) : a_(a) {}
-  // CHECK-FIXES: T(array a) : a_(a) {}
   array a_;
 };
 
 struct U {
   U(const POD &M) : M(M) {}
-  // CHECK-FIXES: U(const POD &M) : M(M) {}
   POD M;
 };
 



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


[clang] [Clang] Fix a regression introduced by #140576 (PR #140859)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime-2` running on `rocm-worker-hw-02` while building 
`clang` at step 6 "test-openmp".

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


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

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libarcher :: races/critical-unrelated.c' FAILED 

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 13
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang 
-fopenmp  -gdwarf-4 -O1 -fsanitize=thread  -I 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests
 -I 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
-Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
   
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/critical-unrelated.c
 -o 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/critical-unrelated.c.tmp
 -latomic && env 
TSAN_OPTIONS='ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1'
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/deflake.bash
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/critical-unrelated.c.tmp
 2>&1 | tee 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/critical-unrelated.c.tmp.log
 | 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/FileCheck
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/critical-unrelated.c
# executed command: 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang 
-fopenmp -gdwarf-4 -O1 -fsanitize=thread -I 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests
 -I 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
-Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/critical-unrelated.c
 -o 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/critical-unrelated.c.tmp
 -latomic
# note: command had no output on stdout or stderr
# executed command: env 
TSAN_OPTIONS=ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/deflake.bash
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/critical-unrelated.c.tmp
# note: command had no output on stdout or stderr
# executed command: tee 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/critical-unrelated.c.tmp.log
# note: command had no output on stdout or stderr
# executed command: 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/FileCheck
 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/critical-unrelated.c
# note: command had no output on stdout or stderr
# RUN: at line 14
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/./bin/clang 
-fopenmp  -gdwarf-4 -O1 -fsanitize=thread  -I 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests
 -I 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 
-Wl,-rpath,/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
   
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/openmp/tools/archer/tests/races/critical-unrelated.c
 -o 
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-bins/openmp/tools/archer/tests/races/Output/critical-unrelated.c.tmp
 -latomic && env ARCHER_OPTIONS="ignore_serial=1 report_data_leak=1" env 
TSAN_OPTIONS='ignore_noninstrumented_modules=0:ignore_noninstrumented_modules=1'
 
/home/botworker/builds/ope

[clang] [WIP][C++20][Modules] Lazily, but fully load 'HeaderFileInfo' table into memory. (PR #140867)

2025-05-21 Thread Michael Park via cfe-commits

https://github.com/mpark created 
https://github.com/llvm/llvm-project/pull/140867

This is a WIP prototype in trying to solve #140860.

The approach explored here is to fully load the on-disk hash tables in each of 
the PCMs into memory, so that we perform `N` (# of includes) hash table 
look-ups, rather than `N` (# of includes) * `M` (# of loaded modules) look-ups.

The behavior is still somewhat lazy, where the loading doesn't happen until the 
first `GetHeaderFileInfo` request. We keep track of the modules that have 
already been processed, so that only newly added modules get added to the 
in-memory hash table.

The following test case takes **14s** before this change, and **0.18s** with 
the change.

```bash
#/usr/bin/env bash

CLANG=${CLANG:-clang++}
NUM_MODULES=${NUM_MODULES:-1000}
NUM_HEADERS=${NUM_HEADERS:-1}

mkdir build && cd build

for i in $(seq 1 $NUM_MODULES); do > m${i}.h; done
seq 1 $NUM_MODULES | xargs -I {} -P $(nproc) bash -c "$CLANG -std=c++20 
-fmodule-header m{}.h"

for i in $(seq 1 $NUM_HEADERS); do > h${i}.h; done

> a.cpp
for i in $(seq 1 $NUM_MODULES); do echo "import \"m${i}.h\";" >> a.cpp; done
for i in $(seq 1 $NUM_HEADERS); do echo "#include \"h${i}.h\"" >> a.cpp; done
echo "int main() {}" >> a.cpp

time $CLANG -std=c++20 -Wno-experimental-header-units -E a.cpp -o /dev/null \
$(for i in $(seq 1 $NUM_MODULES); do echo -n "-fmodule-file=m${i}.pcm "; 
done)
```

Theoretically, this would do more work in scenarios where there are only a few 
modules, each with large header search tables. I tested this out with another 
script. This time, it produces 10 header units, each with 10,000 header 
includes in each of them. The main file `import`s the 10 header units. This 
loads 100,010 entries into the in-memory hash table, but still only takes 
**0.15s**. However, I'm not sure whether this would be acceptable, and if not, 
what might be a better strategy here.

```
#/usr/bin/env bash

CLANG=${CLANG:-clang++}
NUM_MODULES=${NUM_MODULES:-10}
NUM_HEADERS=${NUM_HEADERS:-1}

mkdir build && cd build

for i in $(seq 1 $NUM_MODULES)
do
> m${i}.h
for j in $(seq 1 $NUM_HEADERS)
do
> h${i}-${j}.h
echo "#include \"h${i}-${j}.h\"" >> m${i}.h
done
done
seq 1 $NUM_MODULES | xargs -I {} -P $(nproc) bash -c "$CLANG -std=c++20 
-fmodule-header m{}.h"

> a.cpp
for i in $(seq 1 $NUM_MODULES); do echo "import \"m${i}.h\";" >> a.cpp; done

time $CLANG -std=c++20 -Wno-experimental-header-units -E a.cpp -o /dev/null \
$(for i in $(seq 1 $NUM_MODULES); do echo -n "-fmodule-file=m${i}.pcm "; 
done)
```

## Other Considerations
- I've also tried doing the preloading at load time, the way we do for source 
locations and interesting identifiers in 
[ASTReader::ReadAST](https://github.com/llvm/llvm-project/blob/dec214d5c638302b92fa1cfe0582531cd58a7f6d/clang/lib/Serialization/ASTReader.cpp#L4800).
 This works just as well, it's slightly more eager than the approach taken 
here, but the effect is similar.
- I tried using 
[`MultiOnDiskHashTable`](https://github.com/llvm/llvm-project/blob/dec214d5c638302b92fa1cfe0582531cd58a7f6d/clang/lib/Serialization/MultiOnDiskHashTable.h#L40)
 to pull together all of the hash tables, since it would handle merging and 
loading into memory for performance reasons. It turns out to be kind of a pain 
to use with `HeaderFileInfoTrait`. More importantly, we can't really afford to 
key by the internal key type since that only hashes on the size of the file and 
the hash collision gets pretty bad. Moreover, the merging and condensing 
strategy seems rather simple.

>From eed4b121bfcf9fee63538710b1958a3044358c63 Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Tue, 20 May 2025 17:18:36 -0700
Subject: [PATCH] Lazily, but fully load 'HeaderFileInfo' table into memory.

---
 clang/include/clang/Serialization/ASTReader.h |  4 +
 clang/lib/Serialization/ASTReader.cpp | 79 +++
 clang/lib/Serialization/ASTReaderInternals.h  |  3 +-
 3 files changed, 53 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 57b0266af26bb..9b63ad1a7cde7 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -654,6 +654,10 @@ class ASTReader
   /// Map from the TU to its lexical contents from each module file.
   std::vector> TULexicalDecls;
 
+  unsigned HeaderFileInfoIdx = 0;
+
+  llvm::DenseMap HeaderFileInfoLookup;
+
   /// Map from a DeclContext to its lookup tables.
   llvm::DenseMap Lookups;
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index d068f5e163176..15ea6b25d1d92 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4155,6 +4155,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
   if (Record[0]) {
 F.HeaderFileInfoTable = HeaderFileInfoLookupTable::Create(
 (co

[libclc] [libclc] Re-use shuffle_decl.inc in OpenCL shuffle2 declaration (PR #140679)

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


@@ -6,41 +6,14 @@
 //
 
//===--===//
 
-#define _CLC_SHUFFLE2_DECL(TYPE, MASKTYPE, RETTYPE)
\
-  _CLC_OVERLOAD _CLC_DECL RETTYPE shuffle2(TYPE x, TYPE y, MASKTYPE mask);
+#define __CLC_FUNCTION shuffle2
 
-// Return type is same base type as the input type, with the same vector size 
as
-// the mask. Elements in the mask must be the same size (number of bits) as the
-// input value. E.g. char8 ret = shuffle2(char2 x, char2 y, uchar8 mask);
+// Integer-type decls
+#define __CLC_BODY 

frasercrmck wrote:

no worries

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


[clang] [WIP][C++20][Modules] Lazily, but fully load 'HeaderFileInfo' table into memory. (PR #140867)

2025-05-21 Thread Michael Park via cfe-commits

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


[clang] [WIP][C++20][Modules] Lazily, but fully load 'HeaderFileInfo' table into memory. (PR #140867)

2025-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Michael Park (mpark)


Changes

This is a WIP prototype in trying to solve #140860.

The approach explored here is to fully load the on-disk hash tables in each of 
the PCMs into memory, so that we perform `N` (# of includes) hash table 
look-ups, rather than `N` (# of includes) * `M` (# of loaded modules) look-ups.

The behavior is still somewhat lazy, where the loading doesn't happen until the 
first `GetHeaderFileInfo` request. We keep track of the modules that have 
already been processed, so that only newly added modules get added to the 
in-memory hash table.

The following test case takes **14s** before this change, and **0.18s** with 
the change.

```bash
#/usr/bin/env bash

CLANG=${CLANG:-clang++}
NUM_MODULES=${NUM_MODULES:-1000}
NUM_HEADERS=${NUM_HEADERS:-1}

mkdir build && cd build

for i in $(seq 1 $NUM_MODULES); do > m${i}.h; done
seq 1 $NUM_MODULES | xargs -I {} -P $(nproc) bash -c "$CLANG -std=c++20 
-fmodule-header m{}.h"

for i in $(seq 1 $NUM_HEADERS); do > h${i}.h; done

> a.cpp
for i in $(seq 1 $NUM_MODULES); do echo "import \"m${i}.h\";" >> a.cpp; 
done
for i in $(seq 1 $NUM_HEADERS); do echo "#include \"h${i}.h\"" >> a.cpp; 
done
echo "int main() {}" >> a.cpp

time $CLANG -std=c++20 -Wno-experimental-header-units -E a.cpp -o /dev/null \
$(for i in $(seq 1 $NUM_MODULES); do echo -n "-fmodule-file=m${i}.pcm "; 
done)
```

Theoretically, this would do more work in scenarios where there are only a few 
modules, each with large header search tables. I tested this out with another 
script. This time, it produces 10 header units, each with 10,000 header 
includes in each of them. The main file `import`s the 10 header units. This 
loads 100,010 entries into the in-memory hash table, but still only takes 
**0.15s**. However, I'm not sure whether this would be acceptable, and if not, 
what might be a better strategy here.

```
#/usr/bin/env bash

CLANG=${CLANG:-clang++}
NUM_MODULES=${NUM_MODULES:-10}
NUM_HEADERS=${NUM_HEADERS:-1}

mkdir build && cd build

for i in $(seq 1 $NUM_MODULES)
do
> m${i}.h
for j in $(seq 1 $NUM_HEADERS)
do
> h${i}-${j}.h
echo "#include \"h${i}-${j}.h\"" >> m${i}.h
done
done
seq 1 $NUM_MODULES | xargs -I {} -P $(nproc) bash -c "$CLANG -std=c++20 
-fmodule-header m{}.h"

> a.cpp
for i in $(seq 1 $NUM_MODULES); do echo "import \"m${i}.h\";" >> a.cpp; 
done

time $CLANG -std=c++20 -Wno-experimental-header-units -E a.cpp -o /dev/null \
$(for i in $(seq 1 $NUM_MODULES); do echo -n "-fmodule-file=m${i}.pcm "; 
done)
```

## Other Considerations
- I've also tried doing the preloading at load time, the way we do for source 
locations and interesting identifiers in 
[ASTReader::ReadAST](https://github.com/llvm/llvm-project/blob/dec214d5c638302b92fa1cfe0582531cd58a7f6d/clang/lib/Serialization/ASTReader.cpp#L4800).
 This works just as well, it's slightly more eager than the approach taken 
here, but the effect is similar.
- I tried using 
[`MultiOnDiskHashTable`](https://github.com/llvm/llvm-project/blob/dec214d5c638302b92fa1cfe0582531cd58a7f6d/clang/lib/Serialization/MultiOnDiskHashTable.h#L40)
 to pull together all of the hash tables, since it would handle merging and 
loading into memory for performance reasons. It turns out to be kind of a pain 
to use with `HeaderFileInfoTrait`. More importantly, we can't really afford to 
key by the internal key type since that only hashes on the size of the file and 
the hash collision gets pretty bad. Moreover, the merging and condensing 
strategy seems rather simple.

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


3 Files Affected:

- (modified) clang/include/clang/Serialization/ASTReader.h (+4) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+48-31) 
- (modified) clang/lib/Serialization/ASTReaderInternals.h (+1-2) 


``diff
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 57b0266af26bb..9b63ad1a7cde7 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -654,6 +654,10 @@ class ASTReader
   /// Map from the TU to its lexical contents from each module file.
   std::vector> TULexicalDecls;
 
+  unsigned HeaderFileInfoIdx = 0;
+
+  llvm::DenseMap HeaderFileInfoLookup;
+
   /// Map from a DeclContext to its lookup tables.
   llvm::DenseMap Lookups;
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index d068f5e163176..15ea6b25d1d92 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4155,6 +4155,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
   if (Record[0]) {
 F.HeaderFileInfoTable = HeaderFileInfoLookupTable::Create(
 (const unsigned char *)F.HeaderFileInfoTableData + Record[0],
+(const unsigned char *)F.HeaderFileInfoTableData + 
sizeof(uint32_t)

[libclc] [libclc] Re-use shuffle_decl.inc in OpenCL shuffle2 declaration (PR #140679)

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

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


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


[libclc] e70568e - [libclc] Re-use shuffle_decl.inc in OpenCL shuffle2 declaration (#140679)

2025-05-21 Thread via cfe-commits

Author: Wenju He
Date: 2025-05-21T09:49:24+01:00
New Revision: e70568e28e1118f5da003959d91ff61967d8ba37

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

LOG: [libclc] Re-use shuffle_decl.inc in OpenCL shuffle2 declaration (#140679)

Also internalize __clc_get_el_* symbols in clc_shuffle2. llvm-diff shows
no change to amdgcn--amdhsa.bc.

Added: 


Modified: 
libclc/clc/lib/generic/misc/clc_shuffle.cl
libclc/clc/lib/generic/misc/clc_shuffle2.cl
libclc/opencl/include/clc/opencl/misc/shuffle2.h

Removed: 




diff  --git a/libclc/clc/lib/generic/misc/clc_shuffle.cl 
b/libclc/clc/lib/generic/misc/clc_shuffle.cl
index 626a94df08131..f02e7aec9a0b8 100644
--- a/libclc/clc/lib/generic/misc/clc_shuffle.cl
+++ b/libclc/clc/lib/generic/misc/clc_shuffle.cl
@@ -52,7 +52,7 @@
 return VAR.sF;
 
 #define _CLC_GET_ELEMENT_DEFINE(ARGTYPE, ARGSIZE, IDXTYPE) 
\
-  inline ARGTYPE __clc_get_el_##ARGTYPE##ARGSIZE##_##IDXTYPE(  
\
+  _CLC_INLINE ARGTYPE __clc_get_el_##ARGTYPE##ARGSIZE##_##IDXTYPE( 
\
   ARGTYPE##ARGSIZE x, IDXTYPE idx) {   
\
 switch (idx) { _CLC_ELEMENT_CASES##ARGSIZE(x) default : return 0; }
\
   }

diff  --git a/libclc/clc/lib/generic/misc/clc_shuffle2.cl 
b/libclc/clc/lib/generic/misc/clc_shuffle2.cl
index 3626e67423193..db97f7c5cf960 100644
--- a/libclc/clc/lib/generic/misc/clc_shuffle2.cl
+++ b/libclc/clc/lib/generic/misc/clc_shuffle2.cl
@@ -52,9 +52,8 @@
 return VAR.sF;
 
 #define _CLC_GET_ELEMENT_DEFINE(ARGTYPE, ARGSIZE, IDXTYPE) 
\
-  __attribute__((always_inline)) ARGTYPE   
\
-  __clc_get_el_##ARGTYPE##ARGSIZE##_##IDXTYPE( 
\
-  ARGTYPE##ARGSIZE x, ARGTYPE##ARGSIZE y, IDXTYPE idx) {   
\
+  _CLC_INLINE ARGTYPE __clc_get_el_##ARGTYPE##ARGSIZE##_##IDXTYPE( 
\
+  ARGTYPE##ARGSIZE x, ARGTYPE##ARGSIZE y, IDXTYPE idx) {   
\
 if (idx < ARGSIZE) 
\
   switch (idx) { _CLC_ELEMENT_CASES##ARGSIZE(x) default : return 0; }  
\
 else   
\

diff  --git a/libclc/opencl/include/clc/opencl/misc/shuffle2.h 
b/libclc/opencl/include/clc/opencl/misc/shuffle2.h
index fa33f6058d583..91548ad784fbb 100644
--- a/libclc/opencl/include/clc/opencl/misc/shuffle2.h
+++ b/libclc/opencl/include/clc/opencl/misc/shuffle2.h
@@ -6,41 +6,14 @@
 //
 
//===--===//
 
-#define _CLC_SHUFFLE2_DECL(TYPE, MASKTYPE, RETTYPE)
\
-  _CLC_OVERLOAD _CLC_DECL RETTYPE shuffle2(TYPE x, TYPE y, MASKTYPE mask);
+#define __CLC_FUNCTION shuffle2
 
-// Return type is same base type as the input type, with the same vector size 
as
-// the mask. Elements in the mask must be the same size (number of bits) as the
-// input value. E.g. char8 ret = shuffle2(char2 x, char2 y, uchar8 mask);
+// Integer-type decls
+#define __CLC_BODY 
+#include 
 
-#define _CLC_VECTOR_SHUFFLE2_MASKSIZE(INBASE, INTYPE, MASKTYPE)
\
-  _CLC_SHUFFLE2_DECL(INTYPE, MASKTYPE##2, INBASE##2)   
\
-  _CLC_SHUFFLE2_DECL(INTYPE, MASKTYPE##4, INBASE##4)   
\
-  _CLC_SHUFFLE2_DECL(INTYPE, MASKTYPE##8, INBASE##8)   
\
-  _CLC_SHUFFLE2_DECL(INTYPE, MASKTYPE##16, INBASE##16)
+// Floating-point decls
+#define __CLC_BODY 
+#include 
 
-#define _CLC_VECTOR_SHUFFLE2_INSIZE(TYPE, MASKTYPE)
\
-  _CLC_VECTOR_SHUFFLE2_MASKSIZE(TYPE, TYPE##2, MASKTYPE)   
\
-  _CLC_VECTOR_SHUFFLE2_MASKSIZE(TYPE, TYPE##4, MASKTYPE)   
\
-  _CLC_VECTOR_SHUFFLE2_MASKSIZE(TYPE, TYPE##8, MASKTYPE)   
\
-  _CLC_VECTOR_SHUFFLE2_MASKSIZE(TYPE, TYPE##16, MASKTYPE)
-
-_CLC_VECTOR_SHUFFLE2_INSIZE(char, uchar)
-_CLC_VECTOR_SHUFFLE2_INSIZE(short, ushort)
-_CLC_VECTOR_SHUFFLE2_INSIZE(int, uint)
-_CLC_VECTOR_SHUFFLE2_INSIZE(long, ulong)
-_CLC_VECTOR_SHUFFLE2_INSIZE(uchar, uchar)
-_CLC_VECTOR_SHUFFLE2_INSIZE(ushort, ushort)
-_CLC_VECTOR_SHUFFLE2_INSIZE(uint, uint)
-_CLC_VECTOR_SHUFFLE2_INSIZE(ulong, ulong)
-_CLC_VECTOR_SHUFFLE2_INSIZE(float, uint)
-#ifdef cl_khr_fp64
-_CLC_VECTOR_SHUFFLE2_INSIZE(double, ulong)
-#endif
-#ifdef cl_khr_fp16
-_CLC_VECTOR_SHUFFLE2_INSIZE(half, ushort)
-#endif
-
-#undef _CLC_SHUFFLE_DECL
-#undef _CLC_VECTOR_SHUFFLE2_MASKSIZE
-#undef _CLC_VECTOR_SHUFFLE2_INSIZE
+#undef __CLC_FUNCTION



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

[clang] [WIP][C++20][Modules] Lazily, but fully load 'HeaderFileInfo' table into memory. (PR #140867)

2025-05-21 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- 
clang/include/clang/Serialization/ASTReader.h 
clang/lib/Serialization/ASTReader.cpp 
clang/lib/Serialization/ASTReaderInternals.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 15ea6b25d..f90f4b979 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -6864,14 +6864,15 @@ static void mergeHeaderFileInfo(HeaderFileInfo &HFI,
 HeaderFileInfo ASTReader::GetHeaderFileInfo(FileEntryRef FE) {
   for (auto Iter = ModuleMgr.begin() + HeaderFileInfoIdx, End = 
ModuleMgr.end();
Iter != End; ++Iter) {
-if (auto *Table =
-static_cast(Iter->HeaderFileInfoTable)) {
-  auto& Info = Table->getInfoObj();
+if (auto *Table = static_cast(
+Iter->HeaderFileInfoTable)) {
+  auto &Info = Table->getInfoObj();
   for (auto Iter = Table->data_begin(), End = Table->data_end();
Iter != End; ++Iter) {
 const auto *Item = Iter.getItem();
 // Determine the length of the key and the data.
-const auto& [KeyLen, DataLen] = 
HeaderFileInfoTrait::ReadKeyDataLength(Item);
+const auto &[KeyLen, DataLen] =
+HeaderFileInfoTrait::ReadKeyDataLength(Item);
 // Read the key.
 const auto &Key = Info.ReadKey(Item, KeyLen);
 if (auto EKey = Info.getFile(Key)) {

``




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


[libclc] [libclc] Re-use shuffle_decl.inc in OpenCL shuffle2 declaration (PR #140679)

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

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


[clang-tools-extra] [clang-tools-extra] Add include mappings for getopt.h (PR #140726)

2025-05-21 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

unfortunately neither is used by include-cleaner. we only support mappings for 
c++ STL, through 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
 and friends.

we didn't want to add any system specific libraries, especially based on file 
path mappings, because some of these are platform-specific and dependent on the 
version of the library. Hence we were worried about accuracy.

you can use `-ignore-headers` to prevent analysis for such headers (e.g. 
`-ignore-headers=/usr/lib/.*`), or we might actually be more clever in 
include-cleaner and try to disable these based on system-headerness of a 
header, but that's also a losing battle since people can have various include 
search paths in their command line.

(still happy to land this once you ack the message though, as it should be an 
improvement for other tools)

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


[clang-tools-extra] [clang-tools-extra] Add include mappings for getopt.h (PR #140726)

2025-05-21 Thread Daan De Meyer via cfe-commits

DaanDeMeyer wrote:

> unfortunately neither is used by include-cleaner. we only support mappings 
> for c++ STL, through 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Tooling/Inclusions/Stdlib/StdSymbolMap.inc
>  and friends.
> 
> we didn't want to add any system specific libraries, especially based on file 
> path mappings, because some of these are platform-specific and dependent on 
> the version of the library. Hence we were worried about accuracy.
> 
> you can use `-ignore-headers` to prevent analysis for such headers (e.g. 
> `-ignore-headers=/usr/lib/.*`), or we might actually be more clever in 
> include-cleaner and try to disable these based on system-headerness of a 
> header, but that's also a losing battle since people can have various include 
> search paths in their command line.
> 
> (still happy to land this once you ack the message though, as it should be an 
> improvement for other tools)

Sure, makes sense to me, but yeah, this will still be useful for other tools, 
so feel free to land.

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


[clang] [NVPTX] Support the OpenCL generic addrspace feature by default (PR #137940)

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


@@ -170,6 +170,8 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public 
TargetInfo {
 Opts["cl_khr_global_int32_extended_atomics"] = true;
 Opts["cl_khr_local_int32_base_atomics"] = true;
 Opts["cl_khr_local_int32_extended_atomics"] = true;
+
+Opts["__opencl_c_generic_address_space"] = true;

frasercrmck wrote:

Thanks, all.

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


[clang] [WIP][C++20][Modules] Lazily, but fully load 'HeaderFileInfo' table into memory. (PR #140867)

2025-05-21 Thread Michael Park via cfe-commits

https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/140867

>From 1013ab2297935cc3a7eccf8a812984d9b454a27f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Tue, 20 May 2025 17:18:36 -0700
Subject: [PATCH] Lazily, but fully load 'HeaderFileInfo' table into memory.

---
 clang/include/clang/Serialization/ASTReader.h |  4 +
 clang/lib/Serialization/ASTReader.cpp | 80 ---
 clang/lib/Serialization/ASTReaderInternals.h  |  3 +-
 3 files changed, 54 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 57b0266af26bb..9b63ad1a7cde7 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -654,6 +654,10 @@ class ASTReader
   /// Map from the TU to its lexical contents from each module file.
   std::vector> TULexicalDecls;
 
+  unsigned HeaderFileInfoIdx = 0;
+
+  llvm::DenseMap HeaderFileInfoLookup;
+
   /// Map from a DeclContext to its lookup tables.
   llvm::DenseMap Lookups;
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index d068f5e163176..93766be18f775 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4155,6 +4155,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
   if (Record[0]) {
 F.HeaderFileInfoTable = HeaderFileInfoLookupTable::Create(
 (const unsigned char *)F.HeaderFileInfoTableData + Record[0],
+(const unsigned char *)F.HeaderFileInfoTableData + 
sizeof(uint32_t),
 (const unsigned char *)F.HeaderFileInfoTableData,
 HeaderFileInfoTrait(*this, F));
 
@@ -6831,43 +6832,60 @@ std::optional 
ASTReader::isPreprocessedEntityInFileID(unsigned Index,
 return false;
 }
 
-namespace {
-
-  /// Visitor used to search for information about a header file.
-  class HeaderFileInfoVisitor {
-  FileEntryRef FE;
-std::optional HFI;
-
-  public:
-explicit HeaderFileInfoVisitor(FileEntryRef FE) : FE(FE) {}
-
-bool operator()(ModuleFile &M) {
-  HeaderFileInfoLookupTable *Table
-= static_cast(M.HeaderFileInfoTable);
-  if (!Table)
-return false;
+static void mergeHeaderFileInfoModuleBits(HeaderFileInfo &HFI,
+  bool isModuleHeader,
+  bool isTextualModuleHeader) {
+  HFI.isModuleHeader |= isModuleHeader;
+  if (HFI.isModuleHeader)
+HFI.isTextualModuleHeader = false;
+  else
+HFI.isTextualModuleHeader |= isTextualModuleHeader;
+}
 
-  // Look in the on-disk hash table for an entry for this file name.
-  HeaderFileInfoLookupTable::iterator Pos = Table->find(FE);
-  if (Pos == Table->end())
-return false;
+/// Merge the header file info provided by \p OtherHFI into the current
+/// header file info (\p HFI)
+static void mergeHeaderFileInfo(HeaderFileInfo &HFI,
+const HeaderFileInfo &OtherHFI) {
+  assert(OtherHFI.External && "expected to merge external HFI");
 
-  HFI = *Pos;
-  return true;
-}
+  HFI.isImport |= OtherHFI.isImport;
+  HFI.isPragmaOnce |= OtherHFI.isPragmaOnce;
+  mergeHeaderFileInfoModuleBits(HFI, OtherHFI.isModuleHeader,
+OtherHFI.isTextualModuleHeader);
 
-std::optional getHeaderFileInfo() const { return HFI; }
-  };
+  if (!HFI.LazyControllingMacro.isValid())
+HFI.LazyControllingMacro = OtherHFI.LazyControllingMacro;
 
-} // namespace
+  HFI.DirInfo = OtherHFI.DirInfo;
+  HFI.External = (!HFI.IsValid || HFI.External);
+  HFI.IsValid = true;
+}
 
 HeaderFileInfo ASTReader::GetHeaderFileInfo(FileEntryRef FE) {
-  HeaderFileInfoVisitor Visitor(FE);
-  ModuleMgr.visit(Visitor);
-  if (std::optional HFI = Visitor.getHeaderFileInfo())
-  return *HFI;
-
-  return HeaderFileInfo();
+  for (auto Iter = ModuleMgr.begin() + HeaderFileInfoIdx, End = 
ModuleMgr.end();
+   Iter != End; ++Iter) {
+if (auto *Table = static_cast(
+Iter->HeaderFileInfoTable)) {
+  auto &Info = Table->getInfoObj();
+  for (auto Iter = Table->data_begin(), End = Table->data_end();
+   Iter != End; ++Iter) {
+const auto *Item = Iter.getItem();
+// Determine the length of the key and the data.
+const auto& [KeyLen, DataLen] =
+HeaderFileInfoTrait::ReadKeyDataLength(Item);
+// Read the key.
+const auto &Key = Info.ReadKey(Item, KeyLen);
+if (auto EKey = Info.getFile(Key)) {
+  auto Data = Info.ReadData(Key, Item + KeyLen, DataLen);
+  auto [Iter, Inserted] = HeaderFileInfoLookup.try_emplace(*EKey, 
Data);
+  if (!Inserted)
+mergeHeaderFileInfo(Iter->second, Data);
+}
+  }
+}
+  }
+  HeaderFileInfoIdx = ModuleMgr.size();
+  return HeaderFileInfoLookup.lookup(FE);
 }
 
 void ASTReader::ReadPragmaDiagnosticMappings(D

[clang] [NVPTX] Support the OpenCL generic addrspace feature by default (PR #137940)

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

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


[clang] 6553dc3 - [NVPTX] Support the OpenCL generic addrspace feature by default (#137940)

2025-05-21 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-05-21T09:55:11+01:00
New Revision: 6553dc30b8e760ae8e11f6c1d635c34d0232e2c3

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

LOG: [NVPTX] Support the OpenCL generic addrspace feature by default (#137940)

As best as I can see, all NVPTX architectures support the generic
address space.

I note there's a FIXME in the target's address space map about 'generic'
still having to be added to the target but we haven't observed any
issues with it downstream. The generic address space is mapped to the
same target address space as default/private (0), but this isn't
necessarily a problem for users.

Added: 


Modified: 
clang/lib/Basic/Targets/NVPTX.h
clang/test/Misc/nvptx.languageOptsOpenCL.cl

Removed: 




diff  --git a/clang/lib/Basic/Targets/NVPTX.h b/clang/lib/Basic/Targets/NVPTX.h
index dc1ecc30980b7..fbb46001b0f90 100644
--- a/clang/lib/Basic/Targets/NVPTX.h
+++ b/clang/lib/Basic/Targets/NVPTX.h
@@ -170,6 +170,8 @@ class LLVM_LIBRARY_VISIBILITY NVPTXTargetInfo : public 
TargetInfo {
 Opts["cl_khr_global_int32_extended_atomics"] = true;
 Opts["cl_khr_local_int32_base_atomics"] = true;
 Opts["cl_khr_local_int32_extended_atomics"] = true;
+
+Opts["__opencl_c_generic_address_space"] = true;
   }
 
   const llvm::omp::GV &getGridValue() const override {

diff  --git a/clang/test/Misc/nvptx.languageOptsOpenCL.cl 
b/clang/test/Misc/nvptx.languageOptsOpenCL.cl
index f479dddffb3ab..2610cfafc257b 100644
--- a/clang/test/Misc/nvptx.languageOptsOpenCL.cl
+++ b/clang/test/Misc/nvptx.languageOptsOpenCL.cl
@@ -132,3 +132,11 @@
 #pragma OPENCL EXTENSION cl_khr_subgroups: enable
 // expected-warning@-1{{unsupported OpenCL extension 'cl_khr_subgroups' - 
ignoring}}
 
+#if (__OPENCL_C_VERSION__ >= 300)
+#ifndef __opencl_c_generic_address_space
+#error "Missing __opencl_c_generic_address_space define"
+#else
+#error "Incorrect __opencl_c_generic_address_space define"
+#endif
+#pragma OPENCL EXTENSION __opencl_c_generic_address_space: enable
+#endif



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


[clang] [Modules] Don't fail when an unused textual header is missing. (PR #138227)

2025-05-21 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

> What is your timeframe for stopping putting the same header ("wrap_foo.h") 
> into multiple modules? If you do that it was never guaranteed which module 
> would be used for a header. I'm willing to unblock you but I'd like to know 
> if you are committed to fixing the issue in the module maps.

I don't think we can ever get rid of that pattern and we will keep relying on 
Clang supporting this. I am sure there are ways to meet both your needs and our 
needs.

To reiterate, Clang supports having the same header in multiple module maps and 
we don't view our current setup as having at a high level. I just want to 
explicit that our stance is that there are no issues that need "fixing in the 
module maps".
Relying on Clang picking a header from a module when it's available is also 
something we'd like to keep.

How we achieve this today is shaky (relying on availability doesn't look 
right), but we absolutely need:
- to allow multiple modules own the same header,
- whenever resolving module for the header, pick one that has the header as 
modular over textual.

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


[clang] [WIP][C++20][Modules] Lazily, but fully load 'HeaderFileInfo' table into memory. (PR #140867)

2025-05-21 Thread Michael Park via cfe-commits

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


[clang] [WIP][C++20][Modules] Lazily, but fully load 'HeaderFileInfo' table into memory. (PR #140867)

2025-05-21 Thread Michael Park via cfe-commits

https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/140867

>From a82059f4e0953e327353f383c9728ef4a7a6eaac Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Tue, 20 May 2025 17:18:36 -0700
Subject: [PATCH] Lazily, but fully load 'HeaderFileInfo' table into memory.

---
 clang/include/clang/Serialization/ASTReader.h |  4 +
 clang/lib/Serialization/ASTReader.cpp | 80 ---
 clang/lib/Serialization/ASTReaderInternals.h  |  3 +-
 3 files changed, 54 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 57b0266af26bb..9b63ad1a7cde7 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -654,6 +654,10 @@ class ASTReader
   /// Map from the TU to its lexical contents from each module file.
   std::vector> TULexicalDecls;
 
+  unsigned HeaderFileInfoIdx = 0;
+
+  llvm::DenseMap HeaderFileInfoLookup;
+
   /// Map from a DeclContext to its lookup tables.
   llvm::DenseMap Lookups;
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index d068f5e163176..f90f4b9798e35 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -4155,6 +4155,7 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
   if (Record[0]) {
 F.HeaderFileInfoTable = HeaderFileInfoLookupTable::Create(
 (const unsigned char *)F.HeaderFileInfoTableData + Record[0],
+(const unsigned char *)F.HeaderFileInfoTableData + 
sizeof(uint32_t),
 (const unsigned char *)F.HeaderFileInfoTableData,
 HeaderFileInfoTrait(*this, F));
 
@@ -6831,43 +6832,60 @@ std::optional 
ASTReader::isPreprocessedEntityInFileID(unsigned Index,
 return false;
 }
 
-namespace {
-
-  /// Visitor used to search for information about a header file.
-  class HeaderFileInfoVisitor {
-  FileEntryRef FE;
-std::optional HFI;
-
-  public:
-explicit HeaderFileInfoVisitor(FileEntryRef FE) : FE(FE) {}
-
-bool operator()(ModuleFile &M) {
-  HeaderFileInfoLookupTable *Table
-= static_cast(M.HeaderFileInfoTable);
-  if (!Table)
-return false;
+static void mergeHeaderFileInfoModuleBits(HeaderFileInfo &HFI,
+  bool isModuleHeader,
+  bool isTextualModuleHeader) {
+  HFI.isModuleHeader |= isModuleHeader;
+  if (HFI.isModuleHeader)
+HFI.isTextualModuleHeader = false;
+  else
+HFI.isTextualModuleHeader |= isTextualModuleHeader;
+}
 
-  // Look in the on-disk hash table for an entry for this file name.
-  HeaderFileInfoLookupTable::iterator Pos = Table->find(FE);
-  if (Pos == Table->end())
-return false;
+/// Merge the header file info provided by \p OtherHFI into the current
+/// header file info (\p HFI)
+static void mergeHeaderFileInfo(HeaderFileInfo &HFI,
+const HeaderFileInfo &OtherHFI) {
+  assert(OtherHFI.External && "expected to merge external HFI");
 
-  HFI = *Pos;
-  return true;
-}
+  HFI.isImport |= OtherHFI.isImport;
+  HFI.isPragmaOnce |= OtherHFI.isPragmaOnce;
+  mergeHeaderFileInfoModuleBits(HFI, OtherHFI.isModuleHeader,
+OtherHFI.isTextualModuleHeader);
 
-std::optional getHeaderFileInfo() const { return HFI; }
-  };
+  if (!HFI.LazyControllingMacro.isValid())
+HFI.LazyControllingMacro = OtherHFI.LazyControllingMacro;
 
-} // namespace
+  HFI.DirInfo = OtherHFI.DirInfo;
+  HFI.External = (!HFI.IsValid || HFI.External);
+  HFI.IsValid = true;
+}
 
 HeaderFileInfo ASTReader::GetHeaderFileInfo(FileEntryRef FE) {
-  HeaderFileInfoVisitor Visitor(FE);
-  ModuleMgr.visit(Visitor);
-  if (std::optional HFI = Visitor.getHeaderFileInfo())
-  return *HFI;
-
-  return HeaderFileInfo();
+  for (auto Iter = ModuleMgr.begin() + HeaderFileInfoIdx, End = 
ModuleMgr.end();
+   Iter != End; ++Iter) {
+if (auto *Table = static_cast(
+Iter->HeaderFileInfoTable)) {
+  auto &Info = Table->getInfoObj();
+  for (auto Iter = Table->data_begin(), End = Table->data_end();
+   Iter != End; ++Iter) {
+const auto *Item = Iter.getItem();
+// Determine the length of the key and the data.
+const auto &[KeyLen, DataLen] =
+HeaderFileInfoTrait::ReadKeyDataLength(Item);
+// Read the key.
+const auto &Key = Info.ReadKey(Item, KeyLen);
+if (auto EKey = Info.getFile(Key)) {
+  auto Data = Info.ReadData(Key, Item + KeyLen, DataLen);
+  auto [Iter, Inserted] = HeaderFileInfoLookup.try_emplace(*EKey, 
Data);
+  if (!Inserted)
+mergeHeaderFileInfo(Iter->second, Data);
+}
+  }
+}
+  }
+  HeaderFileInfoIdx = ModuleMgr.size();
+  return HeaderFileInfoLookup.lookup(FE);
 }
 
 void ASTReader::ReadPragmaDiagnosticMappings(D

[clang] [CIR] Upstream support for string literals (PR #140796)

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


@@ -136,6 +139,14 @@ class CIRGenModule : public CIRGenTypeCache {
   getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty = {},
  ForDefinition_t isForDefinition = NotForDefinition);
 
+  /// Return a constant array for the given string.
+  mlir::Attribute getConstantArrayFromStringLiteral(const StringLiteral *e);
+
+  /// Return a global symbol reference to a constant array for the given string
+  /// literal.
+  cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *S,
+  llvm::StringRef Name = ".str");

xlauko wrote:

```suggestion
  cir::GlobalOp getGlobalForStringLiteral(const StringLiteral *s,
  llvm::StringRef name = ".str");
```

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


[libclc] 0bc7f41 - [libclc] Move all remquo address spaces to CLC library (#140871)

2025-05-21 Thread via cfe-commits

Author: Fraser Cormack
Date: 2025-05-21T11:26:04+01:00
New Revision: 0bc7f41db8f3761f144679e014463aeff29fdbc5

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

LOG: [libclc] Move all remquo address spaces to CLC library (#140871)

Previously the OpenCL address space overloads of remquo would call into
the one and only 'private' CLC remquo. This was an outlier compared with
the other pointer-argumented maths builtins.

This commit moves the definitions of all address space overloads to the
CLC library to give more control over each address space to CLC
implementers.

There are some minor changes to the generated bytecode but it's simply
moving IR instructions around.

Added: 
libclc/clc/lib/generic/math/clc_remquo.inc

Modified: 
libclc/clc/include/clc/math/clc_remquo.h
libclc/clc/include/clc/math/remquo_decl.inc
libclc/clc/lib/generic/math/clc_remquo.cl
libclc/opencl/include/clc/opencl/math/remquo.h
libclc/opencl/lib/generic/math/remquo.cl
libclc/opencl/lib/generic/math/remquo.inc

Removed: 




diff  --git a/libclc/clc/include/clc/math/clc_remquo.h 
b/libclc/clc/include/clc/math/clc_remquo.h
index 5dea818013c68..48a8844a6e384 100644
--- a/libclc/clc/include/clc/math/clc_remquo.h
+++ b/libclc/clc/include/clc/math/clc_remquo.h
@@ -10,12 +10,10 @@
 #define __CLC_MATH_CLC_REMQUO_H__
 
 #define __CLC_FUNCTION __clc_remquo
-
 #define __CLC_BODY 
-#define __CLC_ADDRESS_SPACE private
+
 #include 
 
-#undef __CLC_ADDRESS_SPACE
 #undef __CLC_FUNCTION
 
 #endif // __CLC_MATH_CLC_REMQUO_H__

diff  --git a/libclc/clc/include/clc/math/remquo_decl.inc 
b/libclc/clc/include/clc/math/remquo_decl.inc
index ecd703042a964..7f2af2915b9f8 100644
--- a/libclc/clc/include/clc/math/remquo_decl.inc
+++ b/libclc/clc/include/clc/math/remquo_decl.inc
@@ -6,5 +6,14 @@
 //
 
//===--===//
 
-_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(
-__CLC_GENTYPE x, __CLC_GENTYPE y, __CLC_ADDRESS_SPACE __CLC_INTN *q);
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
+ __CLC_GENTYPE y,
+ private __CLC_INTN *q);
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
+ __CLC_GENTYPE y,
+ global __CLC_INTN *q);
+
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x,
+ __CLC_GENTYPE y,
+ local __CLC_INTN *q);

diff  --git a/libclc/clc/lib/generic/math/clc_remquo.cl 
b/libclc/clc/lib/generic/math/clc_remquo.cl
index 9fa94c1c290b8..2f3b6f0339e17 100644
--- a/libclc/clc/lib/generic/math/clc_remquo.cl
+++ b/libclc/clc/lib/generic/math/clc_remquo.cl
@@ -18,262 +18,14 @@
 #include 
 #include 
 
-_CLC_DEF _CLC_OVERLOAD float __clc_remquo(float x, float y,
-  __private int *quo) {
-  x = __clc_flush_denormal_if_not_supported(x);
-  y = __clc_flush_denormal_if_not_supported(y);
-  int ux = __clc_as_int(x);
-  int ax = ux & EXSIGNBIT_SP32;
-  float xa = __clc_as_float(ax);
-  int sx = ux ^ ax;
-  int ex = ax >> EXPSHIFTBITS_SP32;
+#define __CLC_ADDRESS_SPACE private
+#include 
+#undef __CLC_ADDRESS_SPACE
 
-  int uy = __clc_as_int(y);
-  int ay = uy & EXSIGNBIT_SP32;
-  float ya = __clc_as_float(ay);
-  int sy = uy ^ ay;
-  int ey = ay >> EXPSHIFTBITS_SP32;
+#define __CLC_ADDRESS_SPACE global
+#include 
+#undef __CLC_ADDRESS_SPACE
 
-  float xr = __clc_as_float(0x3f80 | (ax & 0x007f));
-  float yr = __clc_as_float(0x3f80 | (ay & 0x007f));
-  int c;
-  int k = ex - ey;
-
-  uint q = 0;
-
-  while (k > 0) {
-c = xr >= yr;
-q = (q << 1) | c;
-xr -= c ? yr : 0.0f;
-xr += xr;
---k;
-  }
-
-  c = xr > yr;
-  q = (q << 1) | c;
-  xr -= c ? yr : 0.0f;
-
-  int lt = ex < ey;
-
-  q = lt ? 0 : q;
-  xr = lt ? xa : xr;
-  yr = lt ? ya : yr;
-
-  c = (yr < 2.0f * xr) | ((yr == 2.0f * xr) & ((q & 0x1) == 0x1));
-  xr -= c ? yr : 0.0f;
-  q += c;
-
-  float s = __clc_as_float(ey << EXPSHIFTBITS_SP32);
-  xr *= lt ? 1.0f : s;
-
-  int qsgn = sx == sy ? 1 : -1;
-  int quot = (q & 0x7f) * qsgn;
-
-  c = ax == ay;
-  quot = c ? qsgn : quot;
-  xr = c ? 0.0f : xr;
-
-  xr = __clc_as_float(sx ^ __clc_as_int(xr));
-
-  c = ax > PINFBITPATT_SP32 | ay > PINFBITPATT_SP32 | ax == PINFBITPATT_SP32 |
-  ay == 0;
-  quot = c ? 0 : quot;
-  xr = c ? __clc_as_float(QNANBITPATT_SP32) : xr;
-
-  *quo = quot;
-
-  return xr;
-}
-// remquo signature is special, we don't have macro for this
-#define __VEC_REMQUO(TYPE, VEC_SIZE, HA

[libclc] [libclc] Move all remquo address spaces to CLC library (PR #140871)

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

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


[clang] [Clang][Sema] Reject array prvalue operands (PR #140702)

2025-05-21 Thread Yanzuo Liu via cfe-commits


@@ -7639,6 +7639,8 @@ def warn_param_mismatched_alignment : Warning<
 
 def err_objc_object_assignment : Error<
   "cannot assign to class object (%0 invalid)">;
+def err_typecheck_array_prvalue_operand : Error<
+  "array prvalue is not permitted">;

zwuis wrote:

> is `"operand cannot be an array prvalue"` ok?

This is ok to me.


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


[clang] [NFC] Ubsan a few corner cases for `=sanitize` (PR #140855)

2025-05-21 Thread Qinkun Bao via cfe-commits

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


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


[clang] bdc1296 - [NFC] Ubsan a few corner cases for `=sanitize` (#140855)

2025-05-21 Thread via cfe-commits

Author: Vitaly Buka
Date: 2025-05-21T06:42:25-04:00
New Revision: bdc1296de4cdccfba001416f96ce42b63082220a

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

LOG: [NFC] Ubsan a few corner cases for `=sanitize` (#140855)

Added: 


Modified: 
clang/test/CodeGen/ubsan-src-ignorelist-category.test

Removed: 




diff  --git a/clang/test/CodeGen/ubsan-src-ignorelist-category.test 
b/clang/test/CodeGen/ubsan-src-ignorelist-category.test
index 556b17d7b6ad9..2f196fb126fe7 100644
--- a/clang/test/CodeGen/ubsan-src-ignorelist-category.test
+++ b/clang/test/CodeGen/ubsan-src-ignorelist-category.test
@@ -8,6 +8,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict2 -emit-llvm %t/test1.c -o - 
| FileCheck %s --check-prefixes=CHECK1,IGNORE
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict3 -emit-llvm %t/test1.c -o - 
| FileCheck %s --check-prefixes=CHECK1,IGNORE
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict4 -emit-llvm %t/test1.c -o - 
| FileCheck %s --check-prefixes=CHECK1,IGNORE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict5 -emit-llvm %t/test1.c -o - 
| FileCheck %s --check-prefixes=CHECK1,IGNORE
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict6 -emit-llvm %t/test1.c -o - 
| FileCheck %s --check-prefixes=CHECK1,IGNORE
 
 
 // Verify ubsan only emits checks for files in the allowlist
@@ -38,6 +40,18 @@ src:*/test1.c=sanitize
 src:*/test1.c
 src:*/test1.c=sanitize
 
+//--- src.ignorelist.contradict5
+src:*
+src:*/te*t1.c
+src:*/tes*1.c=sanitize
+src:*/test1.c
+
+//--- src.ignorelist.contradict6
+src:*
+src:*/tes*1.c=sanitize
+src:*/te*t1.c
+src:*/t*st1.c=sanitize
+
 //--- test1.c
 // CHECK1-LABEL: define dso_local i32 @add
 int add(int a, int b) {



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


[clang] [NFC] Ubsan a few corner cases for `=sanitize` (PR #140855)

2025-05-21 Thread Qinkun Bao via cfe-commits

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


[clang] [llvm] [llvm][DebugInfo][clang] Finalize all declaration subprograms in DIBuilder::finalize() (PR #139914)

2025-05-21 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

Gentle ping

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


[libclc] [libclc] Support the generic address space (PR #137183)

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


@@ -23,4 +23,20 @@
 #define _CLC_DEF __attribute__((always_inline))
 #endif
 
+#if __OPENCL_C_VERSION__ == CL_VERSION_2_0 ||  
\
+(__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && 
\
+ defined(__opencl_c_generic_address_space))
+#define _CLC_GENERIC_AS_SUPPORTED 1
+// Note that we hard-code the assumption that a non-distinct address space 
means
+// that the target maps the generic address space to the private address space.
+#ifdef __CLC_DISTINCT_GENERIC_ADDRSPACE__
+#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 1
+#else
+#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
+#endif
+#else

frasercrmck wrote:

I've updated the PR. It's mostly to keep it up to date with the changes that 
have landed in clang, so we can remove the CMake logic.

As part of this, CMake now passes in the private and generic address space 
values based on the target via macro defs. The clcfunc.h header now checks for 
equality of the two values before deciding whether the 'distinct' generic 
address space is supported. I haven't changed the names of the macros out of 
simplicity, but also in part because I'd prefer if the check was done once 
centrally so users can rely on a simple `#if/#else` when it comes to 
defining/declaring builtins.

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


[libclc] [libclc] Support the generic address space (PR #137183)

2025-05-21 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions inc,h,cl -- 
libclc/clc/include/clc/clcfunc.h libclc/clc/include/clc/math/remquo_decl.inc 
libclc/clc/include/clc/math/unary_decl_with_int_ptr.inc 
libclc/clc/include/clc/math/unary_decl_with_ptr.inc 
libclc/clc/include/clc/math/unary_def_with_int_ptr.inc 
libclc/clc/include/clc/math/unary_def_with_ptr.inc 
libclc/clc/lib/generic/math/clc_fract.inc 
libclc/clc/lib/generic/math/clc_frexp.cl 
libclc/clc/lib/generic/math/clc_modf.inc 
libclc/clc/lib/generic/math/clc_remquo.cl 
libclc/clc/lib/generic/math/clc_sincos.inc 
libclc/opencl/include/clc/opencl/math/remquo.h 
libclc/opencl/include/clc/opencl/shared/vload.h 
libclc/opencl/include/clc/opencl/shared/vstore.h 
libclc/opencl/lib/clspv/shared/vstore_half.inc 
libclc/opencl/lib/generic/math/remquo.inc 
libclc/opencl/lib/generic/shared/vload.cl 
libclc/opencl/lib/generic/shared/vload_half.inc 
libclc/opencl/lib/generic/shared/vstore.cl 
libclc/opencl/lib/generic/shared/vstore_half.inc
``





View the diff from clang-format here.


``diff
diff --git a/libclc/clc/lib/generic/math/clc_frexp.cl 
b/libclc/clc/lib/generic/math/clc_frexp.cl
index 041caec5a..7ff292ebb 100644
--- a/libclc/clc/lib/generic/math/clc_frexp.cl
+++ b/libclc/clc/lib/generic/math/clc_frexp.cl
@@ -6,8 +6,8 @@
 //
 
//===--===//
 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 

``




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


[libclc] [libclc] Support the generic address space (PR #137183)

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


@@ -420,12 +420,37 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
   -D${CLC_TARGET_DEFINE}
   # All libclc builtin libraries see CLC headers
   -I${CMAKE_CURRENT_SOURCE_DIR}/clc/include
+  # Error on undefined macros
+  -Werror=undef
 )
 
 if( NOT "${cpu}" STREQUAL "" )
   list( APPEND build_flags -mcpu=${cpu} )
 endif()
 
+# Generic address space support.
+# Note: when declaring builtins, we must consider that even if a target
+# formally/nominally supports the generic address space, in practice that
+# target may map it to the same target address space as another address
+# space (often the private one). In such cases we must be careful not to
+# multiply-define a builtin in a single target address space, as it would
+# result in a mangling clash.
+# For this reason we must consider the target support of the generic
+# address space separately from the *implementation* decision about whether
+# to declare certain builtins in that address space.
+# FIXME: Shouldn't clang automatically enable this extension based on the
+# target?

frasercrmck wrote:

With #137940 we can remove this CMake logic, thanks all!

One result of #137636 is that (I believe) because of the default AMDGPU devices 
we compile libclc for, the generic address space isn't being enabled by default 
for any AMDGPU target in this PR. Should we perhaps be building libclc for a 
newer AMDGCN device? It should be at least GFX700 for generic address space 
support.

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


[libclc] [libclc] Support the generic address space (PR #137183)

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

https://github.com/frasercrmck updated 
https://github.com/llvm/llvm-project/pull/137183

>From fcae18dd0b4af6f7517ba8eda368374fa693a5f9 Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Thu, 24 Apr 2025 11:24:30 +0100
Subject: [PATCH 1/6] [libclc] Support the generic address space

This commit provides definitions of builtins with the generic address
space.

It is assumed that all current libclc targets can support the generic
address space.

One concept to consider is the difference between supporting the generic
address space from the user's perspective, and the requirement for
libclc as a compiler implementation detail to define separate generic
address space builtins. In practice a target (like NVPTX) might
notionally support the generic address space, but it's mapped to the
same LLVM target address space as the private address space. Therefore
libclc may not define both private and generic overloads of the same
builtin. We track these two concepts separately, and make the assumption
that if the generic address space does clash with another, it's with the
private one.
---
 libclc/CMakeLists.txt | 25 +++
 libclc/clc/include/clc/clcfunc.h  | 16 
 .../clc/math/unary_decl_with_int_ptr.inc  |  4 +++
 .../include/clc/math/unary_decl_with_ptr.inc  |  5 
 .../clc/math/unary_def_with_int_ptr.inc   |  7 ++
 .../include/clc/math/unary_def_with_ptr.inc   |  7 ++
 libclc/clc/lib/generic/math/clc_frexp.cl  |  7 ++
 libclc/clc/lib/generic/math/clc_modf.inc  |  4 +++
 libclc/clc/lib/generic/math/clc_sincos.inc|  3 +++
 .../opencl/include/clc/opencl/math/remquo.h   |  7 ++
 .../opencl/include/clc/opencl/shared/vload.h  | 16 +++-
 .../opencl/include/clc/opencl/shared/vstore.h | 16 +++-
 .../opencl/lib/clspv/shared/vstore_half.inc   |  6 +
 libclc/opencl/lib/generic/math/remquo.inc |  7 ++
 libclc/opencl/lib/generic/shared/vload.cl | 11 +++-
 .../opencl/lib/generic/shared/vload_half.inc  |  6 +
 libclc/opencl/lib/generic/shared/vstore.cl| 11 +++-
 .../opencl/lib/generic/shared/vstore_half.inc |  7 ++
 18 files changed, 161 insertions(+), 4 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 70b11df3b3142..b8eddb92f3bf5 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -420,12 +420,37 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
   -D${CLC_TARGET_DEFINE}
   # All libclc builtin libraries see CLC headers
   -I${CMAKE_CURRENT_SOURCE_DIR}/clc/include
+  # Error on undefined macros
+  -Werror=undef
 )
 
 if( NOT "${cpu}" STREQUAL "" )
   list( APPEND build_flags -mcpu=${cpu} )
 endif()
 
+# Generic address space support.
+# Note: when declaring builtins, we must consider that even if a target
+# formally/nominally supports the generic address space, in practice that
+# target may map it to the same target address space as another address
+# space (often the private one). In such cases we must be careful not to
+# multiply-define a builtin in a single target address space, as it would
+# result in a mangling clash.
+# For this reason we must consider the target support of the generic
+# address space separately from the *implementation* decision about whether
+# to declare certain builtins in that address space.
+# FIXME: Shouldn't clang automatically enable this extension based on the
+# target?
+list( APPEND build_flags "-Xclang" 
"-cl-ext=+__opencl_c_generic_address_space" )
+# Note: we assume that if there is no distinct generic address space, it
+# maps to the private address space.
+set ( has_distinct_generic_addrspace TRUE )
+if( ARCH STREQUAL nvptx OR ARCH STREQUAL nvptx64 )
+  set ( has_distinct_generic_addrspace FALSE )
+endif()
+if( has_distinct_generic_addrspace )
+  list( APPEND build_flags -D__CLC_DISTINCT_GENERIC_ADDRSPACE__ )
+endif()
+
 set( clc_build_flags ${build_flags} -DCLC_INTERNAL )
 
 add_libclc_builtin_set(
diff --git a/libclc/clc/include/clc/clcfunc.h b/libclc/clc/include/clc/clcfunc.h
index 7c5b31e77a024..e333fe863f990 100644
--- a/libclc/clc/include/clc/clcfunc.h
+++ b/libclc/clc/include/clc/clcfunc.h
@@ -23,4 +23,20 @@
 #define _CLC_DEF __attribute__((always_inline))
 #endif
 
+#if __OPENCL_C_VERSION__ == CL_VERSION_2_0 ||  
\
+(__OPENCL_C_VERSION__ >= CL_VERSION_3_0 && 
\
+ defined(__opencl_c_generic_address_space))
+#define _CLC_GENERIC_AS_SUPPORTED 1
+// Note that we hard-code the assumption that a non-distinct address space 
means
+// that the target maps the generic address space to the private address space.
+#ifdef __CLC_DISTINCT_GENERIC_ADDRSPACE__
+#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 1
+#else
+#define _CLC_DISTINCT_GENERIC_AS_SUPPORTED 0
+#endif
+#else
+#define _CLC_GENERIC_AS_SUPPORT

[clang-tools-extra] [clang-tidy] Added check 'bugprone-function-visibility-change' (PR #140086)

2025-05-21 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/140086

From 65d44a4eb9621e49a96f1ac43e5a1bbd6691dc13 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Thu, 15 May 2025 17:41:16 +0200
Subject: [PATCH 1/3] [clang-tidy] Added check
 'bugprone-function-visibility-change'

---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../FunctionVisibilityChangeCheck.cpp |  74 ++
 .../bugprone/FunctionVisibilityChangeCheck.h  |  33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../bugprone/function-visibility-change.rst   |  43 
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../bugprone/function-visibility-change.cpp   | 234 ++
 8 files changed, 394 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/function-visibility-change.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/function-visibility-change.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index b780a85bdf3fe..7cf58c5218969 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -30,6 +30,7 @@
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "ForwardingReferenceOverloadCheck.h"
+#include "FunctionVisibilityChangeCheck.h"
 #include "ImplicitWideningOfMultiplicationResultCheck.h"
 #include "InaccurateEraseCheck.h"
 #include "IncDecInConditionsCheck.h"
@@ -143,6 +144,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-forward-declaration-namespace");
 CheckFactories.registerCheck(
 "bugprone-forwarding-reference-overload");
+CheckFactories.registerCheck(
+"bugprone-function-visibility-change");
 CheckFactories.registerCheck(
 "bugprone-implicit-widening-of-multiplication-result");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index e310ea9c94543..b4f7ba76f4cee 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   ForwardingReferenceOverloadCheck.cpp
+  FunctionVisibilityChangeCheck.cpp
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.cpp
new file mode 100644
index 0..7ea4ed20705ed
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/FunctionVisibilityChangeCheck.cpp
@@ -0,0 +1,74 @@
+//===--- FunctionVisibilityChangeCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "FunctionVisibilityChangeCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void FunctionVisibilityChangeCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxMethodDecl(
+  ofClass(cxxRecordDecl().bind("class")),
+  
forEachOverridden(cxxMethodDecl(ofClass(cxxRecordDecl().bind("base")))
+.bind("base_func")))
+  .bind("func"),
+  this);
+}
+
+void FunctionVisibilityChangeCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MatchedFunction = Result.Nodes.getNodeAs("func");
+  const auto *ParentClass = Result.Nodes.getNodeAs("class");
+  const auto *OverriddenFunction =
+  Result.Nodes.getNodeAs("base_func");
+  const auto *BaseClass = Result.Nodes.getNodeAs("base");
+
+  if (!MatchedFunction->isCanonicalDecl())
+return;
+
+  AccessSpecifier ActualAccess = MatchedFunction->getAccess();
+  AccessSpecifier OverriddenAccess = OverriddenFunction->getAccess();
+
+  CXXBasePaths Paths;
+  if (!ParentClass->isDerivedFrom(BaseClass, Paths))
+return;
+  const CXXBaseSpecifier *InheritanceWithStrictVisibility = nullptr;
+  for (const CXXBasePath &Path : Paths) {
+for (auto Elem : Path) {
+  if (Elem.Base->getAccessSpecifier() > OverriddenAccess) {
+OverriddenAccess = Elem

[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)

2025-05-21 Thread Walter J.T.V via cfe-commits


@@ -14175,27 +14222,350 @@ bool SemaOpenMP::checkTransformableLoopNest(
 return false;
   },
   [&OriginalInits](OMPLoopBasedDirective *Transform) {
-Stmt *DependentPreInits;
-if (auto *Dir = dyn_cast(Transform))
-  DependentPreInits = Dir->getPreInits();
-else if (auto *Dir = dyn_cast(Transform))
-  DependentPreInits = Dir->getPreInits();
-else if (auto *Dir = dyn_cast(Transform))
-  DependentPreInits = Dir->getPreInits();
-else if (auto *Dir = dyn_cast(Transform))
-  DependentPreInits = Dir->getPreInits();
-else if (auto *Dir = dyn_cast(Transform))
-  DependentPreInits = Dir->getPreInits();
-else
-  llvm_unreachable("Unhandled loop transformation");
-
-appendFlattenedStmtList(OriginalInits.back(), DependentPreInits);
+updatePreInits(Transform, OriginalInits);
   });
   assert(OriginalInits.back().empty() && "No preinit after innermost loop");
   OriginalInits.pop_back();
   return Result;
 }
 
+// Counts the total number of nested loops, including the outermost loop (the
+// original loop). PRECONDITION of this visitor is that it must be invoked from
+// the original loop to be analyzed. The traversal is stop for Decl's and
+// Expr's given that they may contain inner loops that must not be counted.
+//
+// Example AST structure for the code:
+//
+// int main() {
+// #pragma omp fuse
+// {
+// for (int i = 0; i < 100; i++) {<-- Outer loop
+// []() {
+// for(int j = 0; j < 100; j++) {}  <-- NOT A LOOP
+// };
+// for(int j = 0; j < 5; ++j) {}<-- Inner loop
+// }
+// for (int r = 0; i < 100; i++) {<-- Outer loop
+// struct LocalClass {
+// void bar() {
+// for(int j = 0; j < 100; j++) {}  <-- NOT A LOOP
+// }
+// };
+// for(int k = 0; k < 10; ++k) {}<-- Inner loop
+// {x = 5; for(k = 0; k < 10; ++k) x += k; x}; <-- NOT A LOOP
+// }
+// }
+// }
+// Result: Loop 'i' contains 2 loops, Loop 'r' also contains 2 loops
+class NestedLoopCounterVisitor : public DynamicRecursiveASTVisitor {
+private:
+  unsigned NestedLoopCount = 0;
+
+public:
+  explicit NestedLoopCounterVisitor() {}
+
+  unsigned getNestedLoopCount() const { return NestedLoopCount; }
+
+  bool VisitForStmt(ForStmt *FS) override {
+++NestedLoopCount;
+return true;
+  }
+
+  bool VisitCXXForRangeStmt(CXXForRangeStmt *FRS) override {
+++NestedLoopCount;
+return true;
+  }
+
+  bool TraverseStmt(Stmt *S) override {
+if (!S)
+  return true;
+
+// Skip traversal of all expressions, including special cases like
+// LambdaExpr, StmtExpr, BlockExpr, and RequiresExpr. These expressions
+// may contain inner statements (and even loops), but they are not part
+// of the syntactic body of the surrounding loop structure.
+//  Therefore must not be counted
+if (isa(S))
+  return true;
+
+// Only recurse into CompoundStmt (block {}) and loop bodies
+if (isa(S) || isa(S) || isa(S)) {
+  return DynamicRecursiveASTVisitor::TraverseStmt(S);
+}
+
+// Stop traversal of the rest of statements, that break perfect
+// loop nesting, such as control flow (IfStmt, SwitchStmt...)
+return true;
+  }
+
+  bool TraverseDecl(Decl *D) override {
+// Stop in the case of finding a declaration, it is not important
+// in order to find nested loops (Possible CXXRecordDecl, RecordDecl,
+// FunctionDecl...)
+return true;
+  }
+};
+
+bool SemaOpenMP::analyzeLoopSequence(
+Stmt *LoopSeqStmt, unsigned &LoopSeqSize, unsigned &NumLoops,
+SmallVectorImpl &LoopHelpers,
+SmallVectorImpl &ForStmts,
+SmallVectorImpl> &OriginalInits,
+SmallVectorImpl> &TransformsPreInits,
+SmallVectorImpl> &LoopSequencePreInits,
+SmallVectorImpl &LoopCategories, ASTContext &Context,
+OpenMPDirectiveKind Kind) {
+
+  VarsWithInheritedDSAType TmpDSA;
+  QualType BaseInductionVarType;
+  // Helper Lambda to handle storing initialization and body statements for 
both
+  // ForStmt and CXXForRangeStmt and checks for any possible mismatch between
+  // induction variables types
+  auto storeLoopStatements = [&OriginalInits, &ForStmts, &BaseInductionVarType,
+  this, &Context](Stmt *LoopStmt) {
+if (auto *For = dyn_cast(LoopStmt)) {
+  OriginalInits.back().push_back(For->getInit());
+  ForStmts.push_back(For);
+  // Extract induction variable
+  if (auto *InitStmt = dyn_cast_or_null(For->getInit())) {
+if (auto *InitDecl = dyn_cast(InitStmt->getSingleDecl())) {
+  QualType InductionVarType = InitDecl->getType().getCanonicalType();
+
+  // Compare with first loop type
+  if (BaseInductionVarType.isNull()) {
+BaseInductionVarType = InductionVarT

[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)

2025-05-21 Thread Walter J.T.V via cfe-commits


@@ -11516,6 +11516,21 @@ def note_omp_implicit_dsa : Note<
   "implicitly determined as %0">;
 def err_omp_loop_var_dsa : Error<
   "loop iteration variable in the associated loop of 'omp %1' directive may 
not be %0, predetermined as %2">;
+def warn_omp_different_loop_ind_var_types : Warning <
+  "loop sequence following '#pragma omp %0' contains induction variables of 
differing types: %1 and %2">,

eZWALT wrote:

How could it be? The iteration var type is dependent on the original iteration 
variable type, therefore making it possible for fusion to loop multiple loops 
with different induction variable types given that i dont emit an error but 
rather a warning. But i dont really see how NumIterations could be the limiting 
factor here, could you please explain me?  

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


  1   2   3   4   5   >