[clang] Fix incorrect array initialization with string literal (fixes #112189) (PR #156846)

2025-09-06 Thread via cfe-commits


@@ -168,16 +168,95 @@ bool Sema::IsStringInit(Expr *Init, const ArrayType *AT) {
   return ::IsStringInit(Init, AT, Context) == SIF_None;
 }
 
+static StringLiteral *CloneStringLiteral(const StringLiteral *SL,
+ ASTContext &C) {
+  SourceLocation *SLocs = new (C) SourceLocation[SL->getNumConcatenated()];
+  std::copy(SL->tokloc_begin(), SL->tokloc_end(), SLocs);
+  return StringLiteral::Create(
+  C, SL->getBytes(), SL->getKind(), SL->isPascal(), SL->getType(),
+  ArrayRef(SLocs, SL->getNumConcatenated()));
+}
+
+// Exactly follow `IgnoreParensSingleStep` (`AST/IgnoreExpr.h`)
+// We only clone those subexpressions which `IgnoreParensSingleStep` drills 
down
+// to.
+static Expr *CloneDrilled(Expr *E, ASTContext &C) {
+  if (auto *SL = dyn_cast(E)) {
+return CloneStringLiteral(SL, C);
+  }
+
+  if (auto *PE = dyn_cast(E)) {
+return new (C) ParenExpr(PE->getBeginLoc(), PE->getEndLoc(),
+ CloneDrilled(PE->getSubExpr(), C));
+  }
+
+  if (auto *UO = dyn_cast(E)) {
+if (UO->getOpcode() == UO_Extension) {
+  return UnaryOperator::Create(
+  C, CloneDrilled(UO->getSubExpr(), C), UO_Extension, UO->getType(),
+  UO->getValueKind(), UO->getObjectKind(), UO->getBeginLoc(),
+  UO->canOverflow(), UO->getFPOptionsOverride());
+}
+  }
+
+  else if (auto *GSE = dyn_cast(E)) {
+if (!GSE->isResultDependent()) {
+  ArrayRef GSEAEs = GSE->getAssocExprs();
+  Expr **NewGSEAEs = new (C) Expr *[GSEAEs.size()];
+  std::copy(GSEAEs.begin(), GSEAEs.end(), NewGSEAEs);
+  NewGSEAEs[GSE->getResultIndex()] = CloneDrilled(GSE->getResultExpr(), C);
+
+#define CREATE_GSE(ctrl)   
\
+  GenericSelectionExpr::Create(
\
+  C, GSE->getGenericLoc(), ctrl, GSE->getAssocTypeSourceInfos(),   
\
+  ArrayRef(NewGSEAEs, GSEAEs.size()), GSE->getDefaultLoc(),
\
+  GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(), 
\
+  GSE->getResultIndex())
+
+  return GSE->isExprPredicate() ? CREATE_GSE(GSE->getControllingExpr())
+: CREATE_GSE(GSE->getControllingType());
+#undef CREATE_GSE
+}
+  }
+
+  else if (auto *CE = dyn_cast(E)) {
+if (!CE->isConditionDependent()) {
+  // Drills to `CE->getChosenSubExpr()`
+  const bool isCondTrue = CE->isConditionTrue();
+  return new (C)
+  ChooseExpr(CE->getBeginLoc(), CE->getCond(),
+ isCondTrue ? CloneDrilled(CE->getLHS(), C) : CE->getLHS(),
+ isCondTrue ? CE->getRHS() : CloneDrilled(CE->getRHS(), C),
+ CE->getType(), CE->getValueKind(), CE->getObjectKind(),
+ CE->getRParenLoc(), CE->isConditionTrue());
+}
+  }
+
+  else if (auto *PE = dyn_cast(E)) {
+if (PE->isTransparent() && PE->getFunctionName()) {
+  return PredefinedExpr::Create(
+  C, PE->getLocation(), PE->getType(), PE->getIdentKind(),
+  PE->isTransparent(), CloneStringLiteral(PE->getFunctionName(), C));
+}
+  }
+
+  return E;
+}
+
 /// Update the type of a string literal, including any surrounding parentheses,
 /// to match the type of the object which it is initializing.
-static void updateStringLiteralType(Expr *E, QualType Ty) {
+static Expr *updateStringLiteralType(Expr *E, QualType Ty, Sema &S) {
+  Expr *ENew = CloneDrilled(E, S.Context);
+  E = ENew;
+
   while (true) {
 E->setType(Ty);
 E->setValueKind(VK_PRValue);
 if (isa(E) || isa(E))
   break;
 E = IgnoreParensSingleStep(E);
   }
+  return ENew;

awson wrote:

Nope.

We need to keep `ENew` for return.

`E` drills down to innermost string literal.

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


[clang-tools-extra] [Clang-Tidy] Add google-runtime-float Clang-Tidy check (PR #156763)

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


@@ -0,0 +1,34 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_FLOATTYPESCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_FLOATTYPESCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::google::runtime {

vbvictor wrote:

Sure, we can rename in another PR.

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


[clang-tools-extra] [clang-tidy] Support find for string-like classes in readability-container-contains (PR #157243)

2025-09-06 Thread via cfe-commits


@@ -114,29 +112,39 @@ void ContainerContainsCheck::check(const 
MatchFinder::MatchResult &Result) {
  "only one of PositiveComparison or NegativeComparison should be set");
   bool Negated = NegativeComparison != nullptr;
   const auto *Comparison = Negated ? NegativeComparison : PositiveComparison;
+  const StringRef ContainsFunName =
+  Result.Nodes.getNodeAs("contains_fun")->getName();
+  const Expr *SearchExpr = Call->getArg(0)->IgnoreParenImpCasts();
 
   // Diagnose the issue.
-  auto Diag =
-  diag(Call->getExprLoc(), "use 'contains' to check for membership");
+  auto Diag = diag(Call->getExprLoc(), "use '%0' to check for membership")
+  << ContainsFunName;
 
   // Don't fix it if it's in a macro invocation. Leave fixing it to the user.
   SourceLocation FuncCallLoc = Comparison->getEndLoc();
   if (!FuncCallLoc.isValid() || FuncCallLoc.isMacroID())
 return;
 
-  // Create the fix it.
-  const auto *Member = cast(Call->getCallee());
-  Diag << FixItHint::CreateReplacement(
-  Member->getMemberNameInfo().getSourceRange(), "contains");
-  SourceLocation ComparisonBegin = Comparison->getSourceRange().getBegin();
-  SourceLocation ComparisonEnd = Comparison->getSourceRange().getEnd();
-  SourceLocation CallBegin = Call->getSourceRange().getBegin();
-  SourceLocation CallEnd = Call->getSourceRange().getEnd();
+  const auto SearchExprText = Lexer::getSourceText(

EugeneZelenko wrote:

Please do not use `auto` unless type explicitly stated in same statement or 
iterator.

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


[clang-tools-extra] [clang-tidy] Support find for string-like classes in readability-container-contains (PR #157243)

2025-09-06 Thread via cfe-commits


@@ -230,6 +230,10 @@ Changes in existing checks
   ` check to
   avoid false positives on pure virtual member functions.
 
+- Fixed false negatives on string and string-like types in

EugeneZelenko wrote:

Please follow format of other similar statements.

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


[clang] [clang-tools-extra] [compiler-rt] [flang] [libcxx] [libcxxabi] [lld] [lldb] [llvm] [Inclusive Language] migrate "sanity" checks to "soundness" checks (PR #156995)

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

cor3ntin wrote:

As @philnik777 said, regardless of outcome on the RFC, please split in multiple 
PR (one per subproject), once consensus is reached on the RFC.

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


[clang-tools-extra] Add bugprone-loop-variable-copied-then-modified clang-tidy check. (PR #157213)

2025-09-06 Thread Yanzuo Liu via cfe-commits

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


[clang-tools-extra] Add bugprone-loop-variable-copied-then-modified clang-tidy check. (PR #157213)

2025-09-06 Thread via cfe-commits


@@ -0,0 +1,100 @@
+
+//===--===//
+//
+// 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 "LoopVariableCopiedThenModifiedCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/TypeTraits.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
+#include "clang/Basic/Diagnostic.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+LoopVariableCopiedThenModifiedCheck::LoopVariableCopiedThenModifiedCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreInexpensiveVariables(
+  Options.get("IgnoreInexpensiveVariables", false)) {}
+
+void LoopVariableCopiedThenModifiedCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreInexpensiveVariables", 
IgnoreInexpensiveVariables);
+}
+
+void LoopVariableCopiedThenModifiedCheck::registerMatchers(
+MatchFinder *Finder) {
+  auto HasReferenceOrPointerTypeOrIsAllowed = hasType(qualType(
+  unless(hasCanonicalType(anyOf(referenceType(), pointerType());
+  auto IteratorReturnsValueType = cxxOperatorCallExpr(
+  hasOverloadedOperatorName("*"),
+  callee(
+  cxxMethodDecl(returns(unless(hasCanonicalType(referenceType()));
+  auto NotConstructedByCopy = cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(unless(isCopyConstructor();
+  auto ConstructedByConversion = 
cxxMemberCallExpr(callee(cxxConversionDecl()));
+  auto LoopVar =
+  varDecl(HasReferenceOrPointerTypeOrIsAllowed,
+  unless(hasInitializer(expr(hasDescendant(expr(
+  anyOf(materializeTemporaryExpr(), IteratorReturnsValueType,
+NotConstructedByCopy, ConstructedByConversion)));
+  Finder->addMatcher(
+  traverse(TK_AsIs,
+   cxxForRangeStmt(hasLoopVariable(LoopVar.bind("loopVar")))
+   .bind("forRange")),
+  this);
+}
+
+void LoopVariableCopiedThenModifiedCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *Var = Result.Nodes.getNodeAs("loopVar");
+  if (Var->getBeginLoc().isMacroID())
+return;
+  std::optional Expensive =
+  utils::type_traits::isExpensiveToCopy(Var->getType(), *Result.Context);
+  if ((!Expensive || !*Expensive) && IgnoreInexpensiveVariables)
+return;
+  const auto *ForRange = Result.Nodes.getNodeAs("forRange");
+  if (copiedLoopVarIsMutated(*Var, *ForRange, *Result.Context))
+return;
+}
+
+bool LoopVariableCopiedThenModifiedCheck::copiedLoopVarIsMutated(
+const VarDecl &LoopVar, const CXXForRangeStmt &ForRange,
+ASTContext &Context) {
+
+  std::string hintstring = "";
+
+  if (ExprMutationAnalyzer(*ForRange.getBody(), Context).isMutated(&LoopVar)) {
+if (isa(LoopVar.getType())) {
+  hintstring = "const auto&";
+} else {
+  std::string CanonicalTypeStr =

EugeneZelenko wrote:

```suggestion
  const std::string CanonicalTypeStr =
```

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


[clang] [C++20][Modules] Fix merging of anonymous members of class templates. (PR #155948)

2025-09-06 Thread Michael Park via cfe-commits

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


[clang] [AArch64] Enable out-of-line atomics by default (PR #157241)

2025-09-06 Thread Brad Smith via cfe-commits

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


[clang] [clang][bytecode] Remove unused reportOverflow() (PR #157225)

2025-09-06 Thread Timm Baeder via cfe-commits

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

None

>From 7010319b83f42a9d54ebfef6798dd1a19cddc5a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 6 Sep 2025 06:55:58 +0200
Subject: [PATCH] [clang][bytecode] Remove unused reportOverflow()

---
 clang/lib/AST/ByteCode/InterpState.cpp | 6 --
 clang/lib/AST/ByteCode/InterpState.h   | 3 ---
 2 files changed, 9 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpState.cpp 
b/clang/lib/AST/ByteCode/InterpState.cpp
index 6b0e72095dc55..131d84b300953 100644
--- a/clang/lib/AST/ByteCode/InterpState.cpp
+++ b/clang/lib/AST/ByteCode/InterpState.cpp
@@ -73,12 +73,6 @@ void InterpState::cleanup() {
 
 Frame *InterpState::getCurrentFrame() { return Current; }
 
-bool InterpState::reportOverflow(const Expr *E, const llvm::APSInt &Value) {
-  QualType Type = E->getType();
-  CCEDiag(E, diag::note_constexpr_overflow) << Value << Type;
-  return noteUndefinedBehavior();
-}
-
 void InterpState::deallocate(Block *B) {
   assert(B);
   assert(!B->isDynamic());
diff --git a/clang/lib/AST/ByteCode/InterpState.h 
b/clang/lib/AST/ByteCode/InterpState.h
index e4d1dc64ff01b..e095908bce986 100644
--- a/clang/lib/AST/ByteCode/InterpState.h
+++ b/clang/lib/AST/ByteCode/InterpState.h
@@ -90,9 +90,6 @@ class InterpState final : public State, public SourceMapper {
   bool hasPriorDiagnostic() override { return Parent.hasPriorDiagnostic(); }
   bool noteSideEffect() override { return Parent.noteSideEffect(); }
 
-  /// Reports overflow and return true if evaluation should continue.
-  bool reportOverflow(const Expr *E, const llvm::APSInt &Value);
-
   /// Deallocates a pointer.
   void deallocate(Block *B);
 

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


[clang] Fix incorrect array initialization with string literal (fixes #112189) (PR #156846)

2025-09-06 Thread via cfe-commits

https://github.com/awson updated 
https://github.com/llvm/llvm-project/pull/156846

>From 5585fdea6e545aebc3ee9919c5da74e2e7397a35 Mon Sep 17 00:00:00 2001
From: awson 
Date: Fri, 5 Sep 2025 06:45:53 +0300
Subject: [PATCH] `updateStringLiteralType` recursively clones subexpressions
 which types it modifies.

Done as a separate static function and not inlined directly into the 
`updateStringLiteralType` function for maintainability.
---
 clang/lib/Sema/SemaInit.cpp | 121 +++-
 clang/test/SemaCXX/GH112189.cpp |  41 +++
 2 files changed, 143 insertions(+), 19 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH112189.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c97129336736b..162ed8d54093e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -168,9 +168,87 @@ bool Sema::IsStringInit(Expr *Init, const ArrayType *AT) {
   return ::IsStringInit(Init, AT, Context) == SIF_None;
 }
 
+static StringLiteral *CloneStringLiteral(const StringLiteral *SL,
+ ASTContext &C) {
+  SourceLocation *SLocs = new (C) SourceLocation[SL->getNumConcatenated()];
+  std::copy(SL->tokloc_begin(), SL->tokloc_end(), SLocs);
+  return StringLiteral::Create(
+  C, SL->getBytes(), SL->getKind(), SL->isPascal(), SL->getType(),
+  ArrayRef(SLocs, SL->getNumConcatenated()));
+}
+
+// Exactly follow `IgnoreParensSingleStep` (`AST/IgnoreExpr.h`)
+// We only clone those subexpressions which `IgnoreParensSingleStep` drills 
down
+// to.
+static Expr *CloneDrilled(Expr *E, ASTContext &C) {
+  if (auto *SL = dyn_cast(E)) {
+return CloneStringLiteral(SL, C);
+  }
+
+  if (auto *PE = dyn_cast(E)) {
+return new (C) ParenExpr(PE->getBeginLoc(), PE->getEndLoc(),
+ CloneDrilled(PE->getSubExpr(), C));
+  }
+
+  if (auto *UO = dyn_cast(E)) {
+if (UO->getOpcode() == UO_Extension) {
+  return UnaryOperator::Create(
+  C, CloneDrilled(UO->getSubExpr(), C), UO_Extension, UO->getType(),
+  UO->getValueKind(), UO->getObjectKind(), UO->getBeginLoc(),
+  UO->canOverflow(), UO->getFPOptionsOverride());
+}
+  }
+
+  else if (auto *GSE = dyn_cast(E)) {
+if (!GSE->isResultDependent()) {
+  ArrayRef GSEAEs = GSE->getAssocExprs();
+  Expr **NewGSEAEs = new (C) Expr *[GSEAEs.size()];
+  std::copy(GSEAEs.begin(), GSEAEs.end(), NewGSEAEs);
+  NewGSEAEs[GSE->getResultIndex()] = CloneDrilled(GSE->getResultExpr(), C);
+
+#define CREATE_GSE(ctrl)   
\
+  GenericSelectionExpr::Create(
\
+  C, GSE->getGenericLoc(), ctrl, GSE->getAssocTypeSourceInfos(),   
\
+  ArrayRef(NewGSEAEs, GSEAEs.size()), GSE->getDefaultLoc(),
\
+  GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(), 
\
+  GSE->getResultIndex())
+
+  return GSE->isExprPredicate() ? CREATE_GSE(GSE->getControllingExpr())
+: CREATE_GSE(GSE->getControllingType());
+#undef CREATE_GSE
+}
+  }
+
+  else if (auto *CE = dyn_cast(E)) {
+if (!CE->isConditionDependent()) {
+  // Drills to `CE->getChosenSubExpr()`
+  const bool isCondTrue = CE->isConditionTrue();
+  return new (C)
+  ChooseExpr(CE->getBeginLoc(), CE->getCond(),
+ isCondTrue ? CloneDrilled(CE->getLHS(), C) : CE->getLHS(),
+ isCondTrue ? CE->getRHS() : CloneDrilled(CE->getRHS(), C),
+ CE->getType(), CE->getValueKind(), CE->getObjectKind(),
+ CE->getRParenLoc(), CE->isConditionTrue());
+}
+  }
+
+  else if (auto *PE = dyn_cast(E)) {
+if (PE->isTransparent() && PE->getFunctionName()) {
+  return PredefinedExpr::Create(
+  C, PE->getLocation(), PE->getType(), PE->getIdentKind(),
+  PE->isTransparent(), CloneStringLiteral(PE->getFunctionName(), C));
+}
+  }
+
+  return E;
+}
+
 /// Update the type of a string literal, including any surrounding parentheses,
 /// to match the type of the object which it is initializing.
-static void updateStringLiteralType(Expr *E, QualType Ty) {
+static Expr *updateStringLiteralType(Expr *E, QualType Ty, Sema &S) {
+  Expr *ENew = CloneDrilled(E, S.Context);
+  E = ENew;
+
   while (true) {
 E->setType(Ty);
 E->setValueKind(VK_PRValue);
@@ -178,6 +256,7 @@ static void updateStringLiteralType(Expr *E, QualType Ty) {
   break;
 E = IgnoreParensSingleStep(E);
   }
+  return ENew;
 }
 
 /// Fix a compound literal initializing an array so it's correctly marked
@@ -209,9 +288,9 @@ static bool initializingConstexprVariable(const 
InitializedEntity &Entity) {
 static void CheckC23ConstexprInitStringLiteral(const StringLiteral *SE,
Sema &SemaRef, QualType &TT);
 
-static void CheckStringInit(Expr *Str, QualType &DeclT, con

[clang] [clang] Move two flags from EvalInfo to State (PR #157046)

2025-09-06 Thread Timm Baeder via cfe-commits

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


[clang] [clang][analyzer] Add checker 'core.NullPointerArithm' (PR #157129)

2025-09-06 Thread Balazs Benics via cfe-commits


@@ -379,6 +386,111 @@ void DereferenceChecker::checkBind(SVal L, SVal V, const 
Stmt *S,
   C.addTransition(State, this);
 }
 
+void DereferenceChecker::checkPreStmt(const BinaryOperator *Op,
+  CheckerContext &C) const {
+  if (!Op->isAdditiveOp())
+return;
+  const Expr *E1 = Op->getLHS();
+  const Expr *E2 = Op->getRHS();
+  QualType T1 = E1->getType().getCanonicalType();
+  QualType T2 = E2->getType().getCanonicalType();
+  if (T1->isIntegerType() && T2->isIntegerType())
+return;
+  if (!T1->isPointerType() && !T1->isIntegerType() && !T2->isPointerType() &&
+  !T2->isIntegerType())
+return;
+
+  ProgramStateRef State = C.getState();
+  SVal V1 = State->getSVal(E1, C.getLocationContext());
+  SVal V2 = State->getSVal(E2, C.getLocationContext());
+  if (V1.isUndef() || V2.isUndef())
+return;
+
+  ConditionTruthVal V1IsNull = State->isNull(V1);
+  ConditionTruthVal V2IsNull = State->isNull(V2);
+  bool IsConstrained = true;
+
+  // Check cases 'NULL + x' and 'NULL - x'
+  if (T1->isPointerType() && T2->isIntegerType()) {
+if (!V1IsNull.isConstrainedTrue() || V2IsNull.isConstrainedTrue())
+  return;
+IsConstrained = V2IsNull.isConstrainedFalse();
+  }
+
+  // Check case 'x + NULL'
+  if (T1->isIntegerType() && T2->isPointerType()) {
+if (V1IsNull.isConstrainedTrue() || !V2IsNull.isConstrainedTrue())
+  return;
+IsConstrained = V1IsNull.isConstrainedFalse();
+  }
+
+  // Check case 'NULL - p' or 'p - NULL'
+  if (T1->isPointerType() && T2->isPointerType()) {
+if (!V1IsNull.isConstrainedTrue() && !V2IsNull.isConstrainedTrue())
+  return;
+if (V1IsNull.isConstrainedTrue() && V2IsNull.isConstrainedTrue())
+  return;
+IsConstrained =
+V1IsNull.isConstrainedFalse() || V2IsNull.isConstrainedFalse();
+  }
+
+  SmallString<100> Buf;
+  llvm::raw_svector_ostream Out(Buf);
+  SmallVector Ranges;
+
+  auto AddSubExprStr = [&](const Expr *E, bool IsPointer,
+   ConditionTruthVal IsNull) {
+if (IsNull.isConstrainedTrue()) {
+  if (IsPointer)
+Out << "null pointer";
+  else
+Out << "zero";
+} else {
+  if (!IsNull.isConstrainedFalse())
+Out << "probably ";
+  if (IsPointer)
+Out << "non-null pointer";
+  else
+Out << "nonzero integer value";
+}
+if (IsPointer)
+  AddDerefSource(Out, Ranges, E, State.get(), C.getLocationContext(),
+ false);
+  };
+
+  if (Op->getOpcode() == BO_Add)
+Out << "Addition of a ";
+  else
+Out << "Subtraction of a ";
+  AddSubExprStr(E1, T1->isPointerType(), V1IsNull);
+  Out << " and a ";
+  AddSubExprStr(E2, T2->isPointerType(), V2IsNull);
+
+  if (IsConstrained)
+Out << " results ";
+  else
+Out << " may result ";
+  Out << "in undefined behavior";

steakhal wrote:

I really wish we could simplify this. It's generally hard to predict the 
possible result string patterns due to the control-flow and stateful nature of 
such code.
I'd recommend thinking about how to make it more declarative.
For example, having ternaries usually makes the code terser, hence easier to 
put together the pieces.
Even better, having a string table, and just selecting the relevant pattern and 
filling the details using llvm::formatv.
Or something along the way.

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


[clang] [clang][analyzer] Add checker 'core.NullPointerArithm' (PR #157129)

2025-09-06 Thread Balazs Benics via cfe-commits


@@ -379,6 +386,111 @@ void DereferenceChecker::checkBind(SVal L, SVal V, const 
Stmt *S,
   C.addTransition(State, this);
 }
 
+void DereferenceChecker::checkPreStmt(const BinaryOperator *Op,
+  CheckerContext &C) const {
+  if (!Op->isAdditiveOp())
+return;
+  const Expr *E1 = Op->getLHS();
+  const Expr *E2 = Op->getRHS();
+  QualType T1 = E1->getType().getCanonicalType();
+  QualType T2 = E2->getType().getCanonicalType();
+  if (T1->isIntegerType() && T2->isIntegerType())
+return;
+  if (!T1->isPointerType() && !T1->isIntegerType() && !T2->isPointerType() &&
+  !T2->isIntegerType())
+return;
+
+  ProgramStateRef State = C.getState();
+  SVal V1 = State->getSVal(E1, C.getLocationContext());
+  SVal V2 = State->getSVal(E2, C.getLocationContext());
+  if (V1.isUndef() || V2.isUndef())
+return;
+
+  ConditionTruthVal V1IsNull = State->isNull(V1);
+  ConditionTruthVal V2IsNull = State->isNull(V2);
+  bool IsConstrained = true;
+
+  // Check cases 'NULL + x' and 'NULL - x'
+  if (T1->isPointerType() && T2->isIntegerType()) {
+if (!V1IsNull.isConstrainedTrue() || V2IsNull.isConstrainedTrue())
+  return;
+IsConstrained = V2IsNull.isConstrainedFalse();
+  }
+
+  // Check case 'x + NULL'
+  if (T1->isIntegerType() && T2->isPointerType()) {
+if (V1IsNull.isConstrainedTrue() || !V2IsNull.isConstrainedTrue())
+  return;
+IsConstrained = V1IsNull.isConstrainedFalse();
+  }
+
+  // Check case 'NULL - p' or 'p - NULL'
+  if (T1->isPointerType() && T2->isPointerType()) {
+if (!V1IsNull.isConstrainedTrue() && !V2IsNull.isConstrainedTrue())
+  return;
+if (V1IsNull.isConstrainedTrue() && V2IsNull.isConstrainedTrue())
+  return;
+IsConstrained =
+V1IsNull.isConstrainedFalse() || V2IsNull.isConstrainedFalse();
+  }
+
+  SmallString<100> Buf;
+  llvm::raw_svector_ostream Out(Buf);

steakhal wrote:

We will anyways convert to std::string, so we could just use that as a buffer 
in the first place.

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


[clang] [clang] Detect int-to-float narrowing when the back-conversion is unspecified (PR #157174)

2025-09-06 Thread via cfe-commits

https://github.com/camc updated https://github.com/llvm/llvm-project/pull/157174

>From 73696f81166f958e212c5ea314528791c5201565 Mon Sep 17 00:00:00 2001
From: camc <69519329+c...@users.noreply.github.com>
Date: Fri, 5 Sep 2025 20:47:06 +
Subject: [PATCH] [clang] Detect int-to-float narrowing when backconversion is
 unspecified

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaOverload.cpp| 10 ++
 .../test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp |  2 ++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8720262c33959..bd1f536f33404 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,8 @@ Bug Fixes in This Version
 - Builtin elementwise operators now accept vector arguments that have different
   qualifiers on their elements. For example, vector of 4 ``const float`` values
   and vector of 4 ``float`` values. (#GH155405)
+- Fix the check for narrowing int-to-float conversions, so that they are 
detected in
+  cases where converting the float back to an integer is undefined behaviour.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 14fa8478fe317..71d23906f2b17 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -412,10 +412,12 @@ NarrowingKind 
StandardConversionSequence::getNarrowingKind(
 // And back.
 llvm::APSInt ConvertedValue = *IntConstantValue;
 bool ignored;
-Result.convertToInteger(ConvertedValue,
-llvm::APFloat::rmTowardZero, &ignored);
-// If the resulting value is different, this was a narrowing 
conversion.
-if (*IntConstantValue != ConvertedValue) {
+llvm::APFloat::opStatus fs = Result.convertToInteger(
+ConvertedValue, llvm::APFloat::rmTowardZero, &ignored);
+// If the converted-back integer has unspecified value, or if the
+// resulting value is different, this was a narrowing conversion.
+if (fs == llvm::APFloat::opInvalidOp ||
+*IntConstantValue != ConvertedValue) {
   ConstantValue = APValue(*IntConstantValue);
   ConstantType = Initializer->getType();
   return NK_Constant_Narrowing;
diff --git a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp 
b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
index 2bceb3e267790..5bb4708f869f8 100644
--- a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
@@ -137,6 +137,8 @@ void int_to_float() {
   Agg f7 = {12345678};  // OK (exactly fits in a float)
   Agg f8 = {EnumVal};  // OK
   Agg f9 = {123456789};  // expected-error {{ cannot be narrowed }} 
expected-note {{silence}}
+  Agg f10 = {2147483646}; // expected-error {{constant expression 
evaluates to 2147483646 which cannot be narrowed to type 'float'}} 
expected-note {{silence}}
+  Agg f11 = {2147483647}; // expected-error {{constant expression 
evaluates to 2147483647 which cannot be narrowed to type 'float'}} 
expected-note {{silence}}
 
   Agg ce1 = { Convert(123456789) }; // expected-error {{constant 
expression evaluates to 123456789 which cannot be narrowed to type 'float'}} 
expected-note {{silence}}
   Agg ce2 = { ConvertVar() }; // expected-error 
{{non-constant-expression cannot be narrowed from type 'long long' to 
'double'}} expected-note {{silence}}

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


[clang] [clang][analyzer] Add checker 'core.NullPointerArithm' (PR #157129)

2025-09-06 Thread Balazs Benics via cfe-commits


@@ -379,6 +386,111 @@ void DereferenceChecker::checkBind(SVal L, SVal V, const 
Stmt *S,
   C.addTransition(State, this);
 }
 
+void DereferenceChecker::checkPreStmt(const BinaryOperator *Op,
+  CheckerContext &C) const {
+  if (!Op->isAdditiveOp())
+return;
+  const Expr *E1 = Op->getLHS();
+  const Expr *E2 = Op->getRHS();
+  QualType T1 = E1->getType().getCanonicalType();
+  QualType T2 = E2->getType().getCanonicalType();
+  if (T1->isIntegerType() && T2->isIntegerType())
+return;
+  if (!T1->isPointerType() && !T1->isIntegerType() && !T2->isPointerType() &&
+  !T2->isIntegerType())
+return;
+
+  ProgramStateRef State = C.getState();
+  SVal V1 = State->getSVal(E1, C.getLocationContext());
+  SVal V2 = State->getSVal(E2, C.getLocationContext());
+  if (V1.isUndef() || V2.isUndef())
+return;
+
+  ConditionTruthVal V1IsNull = State->isNull(V1);
+  ConditionTruthVal V2IsNull = State->isNull(V2);
+  bool IsConstrained = true;
+
+  // Check cases 'NULL + x' and 'NULL - x'
+  if (T1->isPointerType() && T2->isIntegerType()) {
+if (!V1IsNull.isConstrainedTrue() || V2IsNull.isConstrainedTrue())
+  return;
+IsConstrained = V2IsNull.isConstrainedFalse();
+  }
+
+  // Check case 'x + NULL'
+  if (T1->isIntegerType() && T2->isPointerType()) {
+if (V1IsNull.isConstrainedTrue() || !V2IsNull.isConstrainedTrue())
+  return;
+IsConstrained = V1IsNull.isConstrainedFalse();
+  }
+
+  // Check case 'NULL - p' or 'p - NULL'
+  if (T1->isPointerType() && T2->isPointerType()) {
+if (!V1IsNull.isConstrainedTrue() && !V2IsNull.isConstrainedTrue())
+  return;
+if (V1IsNull.isConstrainedTrue() && V2IsNull.isConstrainedTrue())
+  return;
+IsConstrained =
+V1IsNull.isConstrainedFalse() || V2IsNull.isConstrainedFalse();
+  }
+
+  SmallString<100> Buf;
+  llvm::raw_svector_ostream Out(Buf);
+  SmallVector Ranges;
+
+  auto AddSubExprStr = [&](const Expr *E, bool IsPointer,
+   ConditionTruthVal IsNull) {
+if (IsNull.isConstrainedTrue()) {
+  if (IsPointer)
+Out << "null pointer";
+  else
+Out << "zero";
+} else {
+  if (!IsNull.isConstrainedFalse())
+Out << "probably ";
+  if (IsPointer)
+Out << "non-null pointer";
+  else
+Out << "nonzero integer value";
+}
+if (IsPointer)
+  AddDerefSource(Out, Ranges, E, State.get(), C.getLocationContext(),
+ false);
+  };
+
+  if (Op->getOpcode() == BO_Add)
+Out << "Addition of a ";
+  else
+Out << "Subtraction of a ";
+  AddSubExprStr(E1, T1->isPointerType(), V1IsNull);
+  Out << " and a ";
+  AddSubExprStr(E2, T2->isPointerType(), V2IsNull);
+
+  if (IsConstrained)
+Out << " results ";
+  else
+Out << " may result ";
+  Out << "in undefined behavior";
+
+  ExplodedNode *N = C.generateErrorNode(State);
+  if (!N)
+return;
+  auto BR = std::make_unique(NullPointerArithmBug,
+ Buf.str(), N);
+
+  if (T1->isPointerType())
+bugreporter::trackExpressionValue(N, E1, *BR);
+  if (T2->isPointerType())
+bugreporter::trackExpressionValue(N, E2, *BR);
+
+  for (SmallVectorImpl::iterator I = Ranges.begin(),
+  E = Ranges.end();
+   I != E; ++I)
+BR->addRange(*I);

steakhal wrote:

Why not a ranged-for here?

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


[clang] [Headers][X86] Add constexpr support for some AVX[512] intrinsics. (PR #157260)

2025-09-06 Thread via cfe-commits

https://github.com/moorabbit created 
https://github.com/llvm/llvm-project/pull/157260

The following AVX[512] intrinsics are now constexpr:
- `_mm_cvtepi64_pd`
- `_mm_mask_cvtepi64_pd`
- `_mm_maskz_cvtepi64_pd`
- `_mm_cvtepu64_pd`
- `_mm_mask_cvtepu64_pd`
- `_mm_maskz_cvtepu64_pd`
- `_mm256_cvtepi64_pd`
- `_mm256_mask_cvtepi64_pd`
- `_mm256_maskz_cvtepi64_pd`
- `_mm256_cvtepu64_pd`
- `_mm256_mask_cvtepu64_pd`
- `_mm256_maskz_cvtepu64_pd`
- `_mm256_cvtepi64_ps`
- `_mm256_mask_cvtepi64_ps`
- `_mm256_maskz_cvtepi64_ps`
- `_mm256_cvtepu64_ps`
- `_mm256_mask_cvtepu64_ps`
- `_mm256_maskz_cvtepu64_ps`
- `_mm_cvtepi16_ph`
- `_mm_mask_cvtepi16_ph`
- `_mm_maskz_cvtepi16_ph`
- `_mm_set1_ph`
- `_mm_cvtepu16_ph`
- `_mm_mask_cvtepu16_ph`
- `_mm_maskz_cvtepu16_ph`
- `_mm256_cvtepi16_ph`
- `_mm256_mask_cvtepi16_ph`
- `_mm256_set1_ph`

This PR is part 3 [[part 1](https://github.com/llvm/llvm-project/pull/156187) - 
[part 2](https://github.com/llvm/llvm-project/pull/156567)] of a series of PRs 
fixing #155798

>From 6a3ea1634162fa90e3b2deacb1b0ff7a1a907359 Mon Sep 17 00:00:00 2001
From: moorabbit 
Date: Thu, 4 Sep 2025 16:03:54 -0400
Subject: [PATCH 01/29] _mm_cvtepi64_pd

---
 clang/lib/Headers/avx512vldqintrin.h | 4 ++--
 clang/test/CodeGen/X86/avx512vldq-builtins.c | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/avx512vldqintrin.h 
b/clang/lib/Headers/avx512vldqintrin.h
index e93eb10c31ce2..1de8235baef7b 100644
--- a/clang/lib/Headers/avx512vldqintrin.h
+++ b/clang/lib/Headers/avx512vldqintrin.h
@@ -462,8 +462,8 @@ _mm256_maskz_cvtps_epu64 (__mmask8 __U, __m128 __A) {
 (__mmask8) __U);
 }
 
-static __inline__ __m128d __DEFAULT_FN_ATTRS128
-_mm_cvtepi64_pd (__m128i __A) {
+static __inline__ __m128d __DEFAULT_FN_ATTRS128_CONSTEXPR
+_mm_cvtepi64_pd(__m128i __A) {
   return (__m128d)__builtin_convertvector((__v2di)__A, __v2df);
 }
 
diff --git a/clang/test/CodeGen/X86/avx512vldq-builtins.c 
b/clang/test/CodeGen/X86/avx512vldq-builtins.c
index e1e8916bf60b3..a8f059e0a2556 100644
--- a/clang/test/CodeGen/X86/avx512vldq-builtins.c
+++ b/clang/test/CodeGen/X86/avx512vldq-builtins.c
@@ -440,6 +440,8 @@ __m128d test_mm_cvtepi64_pd(__m128i __A) {
   return _mm_cvtepi64_pd(__A); 
 }
 
+TEST_CONSTEXPR(match_m128d(_mm_cvtepi64_pd((__m128i)(__v2di){-1, -1}), -1.0, 
-1.0));
+
 __m128d test_mm_mask_cvtepi64_pd(__m128d __W, __mmask8 __U, __m128i __A) {
   // CHECK-LABEL: test_mm_mask_cvtepi64_pd
   // CHECK: sitofp <2 x i64> %{{.*}} to <2 x double>

>From c62d8629138f684a892f1335143b3efd72cc3a90 Mon Sep 17 00:00:00 2001
From: moorabbit 
Date: Thu, 4 Sep 2025 16:09:34 -0400
Subject: [PATCH 02/29] _mm_mask_cvtepi64_pd

---
 clang/lib/Headers/avx512vldqintrin.h | 4 ++--
 clang/test/CodeGen/X86/avx512vldq-builtins.c | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/avx512vldqintrin.h 
b/clang/lib/Headers/avx512vldqintrin.h
index 1de8235baef7b..3732ba566020a 100644
--- a/clang/lib/Headers/avx512vldqintrin.h
+++ b/clang/lib/Headers/avx512vldqintrin.h
@@ -467,8 +467,8 @@ _mm_cvtepi64_pd(__m128i __A) {
   return (__m128d)__builtin_convertvector((__v2di)__A, __v2df);
 }
 
-static __inline__ __m128d __DEFAULT_FN_ATTRS128
-_mm_mask_cvtepi64_pd (__m128d __W, __mmask8 __U, __m128i __A) {
+static __inline__ __m128d __DEFAULT_FN_ATTRS128_CONSTEXPR
+_mm_mask_cvtepi64_pd(__m128d __W, __mmask8 __U, __m128i __A) {
   return (__m128d)__builtin_ia32_selectpd_128((__mmask8)__U,
   (__v2df)_mm_cvtepi64_pd(__A),
   (__v2df)__W);
diff --git a/clang/test/CodeGen/X86/avx512vldq-builtins.c 
b/clang/test/CodeGen/X86/avx512vldq-builtins.c
index a8f059e0a2556..05632b83b0d55 100644
--- a/clang/test/CodeGen/X86/avx512vldq-builtins.c
+++ b/clang/test/CodeGen/X86/avx512vldq-builtins.c
@@ -449,6 +449,8 @@ __m128d test_mm_mask_cvtepi64_pd(__m128d __W, __mmask8 __U, 
__m128i __A) {
   return _mm_mask_cvtepi64_pd(__W, __U, __A); 
 }
 
+TEST_CONSTEXPR(match_m128d(_mm_mask_cvtepi64_pd((__m128d){-777.0, -777.0}, 
/*01=*/0x1, (__m128i)(__v2di){-1, -1}), -1.0, -777.0));
+
 __m128d test_mm_maskz_cvtepi64_pd(__mmask8 __U, __m128i __A) {
   // CHECK-LABEL: test_mm_maskz_cvtepi64_pd
   // CHECK: sitofp <2 x i64> %{{.*}} to <2 x double>

>From a6a93ba68fd536e96a3219b9e8d79350b35ff2ac Mon Sep 17 00:00:00 2001
From: moorabbit 
Date: Thu, 4 Sep 2025 16:12:08 -0400
Subject: [PATCH 03/29] _mm_maskz_cvtepi64_pd

---
 clang/lib/Headers/avx512vldqintrin.h | 4 ++--
 clang/test/CodeGen/X86/avx512vldq-builtins.c | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/avx512vldqintrin.h 
b/clang/lib/Headers/avx512vldqintrin.h
index 3732ba566020a..e38014914f336 100644
--- a/clang/lib/Headers/avx512vldqintrin.h
+++ b/clang/lib/Headers/avx512vldqintrin.h
@@ -474,8 +474,8 @@ _mm_mask_cvtepi64_pd(__m128d __W, __mmask8 __U, __m128i 
__A) {
  

[clang] [Headers][X86] Add constexpr support for some AVX[512] intrinsics. (PR #157260)

2025-09-06 Thread via cfe-commits

https://github.com/moorabbit updated 
https://github.com/llvm/llvm-project/pull/157260

>From 6a3ea1634162fa90e3b2deacb1b0ff7a1a907359 Mon Sep 17 00:00:00 2001
From: moorabbit 
Date: Thu, 4 Sep 2025 16:03:54 -0400
Subject: [PATCH 01/30] _mm_cvtepi64_pd

---
 clang/lib/Headers/avx512vldqintrin.h | 4 ++--
 clang/test/CodeGen/X86/avx512vldq-builtins.c | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/avx512vldqintrin.h 
b/clang/lib/Headers/avx512vldqintrin.h
index e93eb10c31ce2..1de8235baef7b 100644
--- a/clang/lib/Headers/avx512vldqintrin.h
+++ b/clang/lib/Headers/avx512vldqintrin.h
@@ -462,8 +462,8 @@ _mm256_maskz_cvtps_epu64 (__mmask8 __U, __m128 __A) {
 (__mmask8) __U);
 }
 
-static __inline__ __m128d __DEFAULT_FN_ATTRS128
-_mm_cvtepi64_pd (__m128i __A) {
+static __inline__ __m128d __DEFAULT_FN_ATTRS128_CONSTEXPR
+_mm_cvtepi64_pd(__m128i __A) {
   return (__m128d)__builtin_convertvector((__v2di)__A, __v2df);
 }
 
diff --git a/clang/test/CodeGen/X86/avx512vldq-builtins.c 
b/clang/test/CodeGen/X86/avx512vldq-builtins.c
index e1e8916bf60b3..a8f059e0a2556 100644
--- a/clang/test/CodeGen/X86/avx512vldq-builtins.c
+++ b/clang/test/CodeGen/X86/avx512vldq-builtins.c
@@ -440,6 +440,8 @@ __m128d test_mm_cvtepi64_pd(__m128i __A) {
   return _mm_cvtepi64_pd(__A); 
 }
 
+TEST_CONSTEXPR(match_m128d(_mm_cvtepi64_pd((__m128i)(__v2di){-1, -1}), -1.0, 
-1.0));
+
 __m128d test_mm_mask_cvtepi64_pd(__m128d __W, __mmask8 __U, __m128i __A) {
   // CHECK-LABEL: test_mm_mask_cvtepi64_pd
   // CHECK: sitofp <2 x i64> %{{.*}} to <2 x double>

>From c62d8629138f684a892f1335143b3efd72cc3a90 Mon Sep 17 00:00:00 2001
From: moorabbit 
Date: Thu, 4 Sep 2025 16:09:34 -0400
Subject: [PATCH 02/30] _mm_mask_cvtepi64_pd

---
 clang/lib/Headers/avx512vldqintrin.h | 4 ++--
 clang/test/CodeGen/X86/avx512vldq-builtins.c | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/avx512vldqintrin.h 
b/clang/lib/Headers/avx512vldqintrin.h
index 1de8235baef7b..3732ba566020a 100644
--- a/clang/lib/Headers/avx512vldqintrin.h
+++ b/clang/lib/Headers/avx512vldqintrin.h
@@ -467,8 +467,8 @@ _mm_cvtepi64_pd(__m128i __A) {
   return (__m128d)__builtin_convertvector((__v2di)__A, __v2df);
 }
 
-static __inline__ __m128d __DEFAULT_FN_ATTRS128
-_mm_mask_cvtepi64_pd (__m128d __W, __mmask8 __U, __m128i __A) {
+static __inline__ __m128d __DEFAULT_FN_ATTRS128_CONSTEXPR
+_mm_mask_cvtepi64_pd(__m128d __W, __mmask8 __U, __m128i __A) {
   return (__m128d)__builtin_ia32_selectpd_128((__mmask8)__U,
   (__v2df)_mm_cvtepi64_pd(__A),
   (__v2df)__W);
diff --git a/clang/test/CodeGen/X86/avx512vldq-builtins.c 
b/clang/test/CodeGen/X86/avx512vldq-builtins.c
index a8f059e0a2556..05632b83b0d55 100644
--- a/clang/test/CodeGen/X86/avx512vldq-builtins.c
+++ b/clang/test/CodeGen/X86/avx512vldq-builtins.c
@@ -449,6 +449,8 @@ __m128d test_mm_mask_cvtepi64_pd(__m128d __W, __mmask8 __U, 
__m128i __A) {
   return _mm_mask_cvtepi64_pd(__W, __U, __A); 
 }
 
+TEST_CONSTEXPR(match_m128d(_mm_mask_cvtepi64_pd((__m128d){-777.0, -777.0}, 
/*01=*/0x1, (__m128i)(__v2di){-1, -1}), -1.0, -777.0));
+
 __m128d test_mm_maskz_cvtepi64_pd(__mmask8 __U, __m128i __A) {
   // CHECK-LABEL: test_mm_maskz_cvtepi64_pd
   // CHECK: sitofp <2 x i64> %{{.*}} to <2 x double>

>From a6a93ba68fd536e96a3219b9e8d79350b35ff2ac Mon Sep 17 00:00:00 2001
From: moorabbit 
Date: Thu, 4 Sep 2025 16:12:08 -0400
Subject: [PATCH 03/30] _mm_maskz_cvtepi64_pd

---
 clang/lib/Headers/avx512vldqintrin.h | 4 ++--
 clang/test/CodeGen/X86/avx512vldq-builtins.c | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/avx512vldqintrin.h 
b/clang/lib/Headers/avx512vldqintrin.h
index 3732ba566020a..e38014914f336 100644
--- a/clang/lib/Headers/avx512vldqintrin.h
+++ b/clang/lib/Headers/avx512vldqintrin.h
@@ -474,8 +474,8 @@ _mm_mask_cvtepi64_pd(__m128d __W, __mmask8 __U, __m128i 
__A) {
   (__v2df)__W);
 }
 
-static __inline__ __m128d __DEFAULT_FN_ATTRS128
-_mm_maskz_cvtepi64_pd (__mmask8 __U, __m128i __A) {
+static __inline__ __m128d __DEFAULT_FN_ATTRS128_CONSTEXPR
+_mm_maskz_cvtepi64_pd(__mmask8 __U, __m128i __A) {
   return (__m128d)__builtin_ia32_selectpd_128((__mmask8)__U,
   (__v2df)_mm_cvtepi64_pd(__A),
   (__v2df)_mm_setzero_pd());
diff --git a/clang/test/CodeGen/X86/avx512vldq-builtins.c 
b/clang/test/CodeGen/X86/avx512vldq-builtins.c
index 05632b83b0d55..2dd0b255a5a60 100644
--- a/clang/test/CodeGen/X86/avx512vldq-builtins.c
+++ b/clang/test/CodeGen/X86/avx512vldq-builtins.c
@@ -458,6 +458,8 @@ __m128d test_mm_maskz_cvtepi64_pd(__mmask8 __U, __m128i 
__A) {
   return _mm_maskz_cvtepi64_pd(__U, __A); 
 }
 
+TEST_CONSTEXPR(match_m128d(_mm_maskz_cvtepi64_pd(/*01=*/0x1, 
(__m128i)

[clang] 6e52283 - [clang] VectorExprEvaluator::VisitCallExpr - use APSInt callback instead of repeated switch statement (#157137)

2025-09-06 Thread via cfe-commits

Author: Simon Pilgrim
Date: 2025-09-06T12:24:22Z
New Revision: 6e52283e819c57abde861491858a154d6ab26d3d

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

LOG: [clang] VectorExprEvaluator::VisitCallExpr - use APSInt callback instead 
of repeated switch statement (#157137)

Create a EvaluateBinOpExpr helper that each related group of elementwise
binop builtins can use with their own custom callback, to help reduce
the amount of duplication and avoid too much code bloat as more builtins
are added.

This also handles builtins which have a elementwise LHS operand and a
scalar RHS operand.

Similar to #155891 which did the same thing for the new ByteCode eval.

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 662b2392e9253..ca930737474df 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11597,6 +11597,38 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
   if (!IsConstantEvaluatedBuiltinCall(E))
 return ExprEvaluatorBaseTy::VisitCallExpr(E);
 
+  auto EvaluateBinOpExpr =
+  [&](llvm::function_ref Fn) {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+auto *DestTy = E->getType()->castAs();
+QualType DestEltTy = DestTy->getElementType();
+bool DestUnsigned = DestEltTy->isUnsignedIntegerOrEnumerationType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+if (SourceRHS.isInt()) {
+  const APSInt &RHS = SourceRHS.getInt();
+  for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+const APSInt &LHS = SourceLHS.getVectorElt(EltNum).getInt();
+ResultElements.push_back(
+APValue(APSInt(Fn(LHS, RHS), DestUnsigned)));
+  }
+} else {
+  for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+const APSInt &LHS = SourceLHS.getVectorElt(EltNum).getInt();
+const APSInt &RHS = SourceRHS.getVectorElt(EltNum).getInt();
+ResultElements.push_back(
+APValue(APSInt(Fn(LHS, RHS), DestUnsigned)));
+  }
+}
+return Success(APValue(ResultElements.data(), SourceLen), E);
+  };
+
   switch (E->getBuiltinCallee()) {
   default:
 return false;
@@ -11653,27 +11685,30 @@ bool VectorExprEvaluator::VisitCallExpr(const 
CallExpr *E) {
   }
 
   case Builtin::BI__builtin_elementwise_add_sat:
+return EvaluateBinOpExpr([](const APSInt &LHS, const APSInt &RHS) {
+  return LHS.isSigned() ? LHS.sadd_sat(RHS) : LHS.uadd_sat(RHS);
+});
+
   case Builtin::BI__builtin_elementwise_sub_sat:
+return EvaluateBinOpExpr([](const APSInt &LHS, const APSInt &RHS) {
+  return LHS.isSigned() ? LHS.ssub_sat(RHS) : LHS.usub_sat(RHS);
+});
+
   case clang::X86::BI__builtin_ia32_pmulhuw128:
   case clang::X86::BI__builtin_ia32_pmulhuw256:
   case clang::X86::BI__builtin_ia32_pmulhuw512:
+return EvaluateBinOpExpr(llvm::APIntOps::mulhu);
+
   case clang::X86::BI__builtin_ia32_pmulhw128:
   case clang::X86::BI__builtin_ia32_pmulhw256:
   case clang::X86::BI__builtin_ia32_pmulhw512:
+return EvaluateBinOpExpr(llvm::APIntOps::mulhs);
+
   case clang::X86::BI__builtin_ia32_psllv2di:
   case clang::X86::BI__builtin_ia32_psllv4di:
   case clang::X86::BI__builtin_ia32_psllv4si:
   case clang::X86::BI__builtin_ia32_psllv8si:
   case clang::X86::BI__builtin_ia32_psllv16si:
-  case clang::X86::BI__builtin_ia32_psrav4si:
-  case clang::X86::BI__builtin_ia32_psrav8si:
-  case clang::X86::BI__builtin_ia32_psrav16si:
-  case clang::X86::BI__builtin_ia32_psrlv2di:
-  case clang::X86::BI__builtin_ia32_psrlv4di:
-  case clang::X86::BI__builtin_ia32_psrlv4si:
-  case clang::X86::BI__builtin_ia32_psrlv8si:
-  case clang::X86::BI__builtin_ia32_psrlv16si:
-
   case clang::X86::BI__builtin_ia32_psllwi128:
   case clang::X86::BI__builtin_ia32_pslldi128:
   case clang::X86::BI__builtin_ia32_psllqi128:
@@ -11683,17 +11718,16 @@ bool VectorExprEvaluator::VisitCallExpr(const 
CallExpr *E) {
   case clang::X86::BI__builtin_ia32_psllwi512:
   case clang::X86::BI__builtin_ia32_pslldi512:
   case clang::X86::BI__builtin_ia32_psllqi512:
+return EvaluateBinOpExpr([](const APSInt &LHS, const APSInt &RHS) {
+  if (RHS.uge(LHS.getBitWidth())) {
+return APInt::getZero(LHS.getBitWidth());
+  }
+  return LHS.shl(RHS.getZExtValue());
+});
 
-  case clang::X86::BI__builtin_ia32_psrlwi128:
-  case clang::X86::BI__builtin_ia32_psrldi128:

[clang] [Headers][X86] Add constexpr support for some AVX[512] intrinsics. (PR #157260)

2025-09-06 Thread via cfe-commits

moorabbit wrote:

@RKSimon PTAL when you can. Thx!

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


[clang-tools-extra] [clang-tidy] Support find for string-like classes in readability-container-contains (PR #157243)

2025-09-06 Thread via cfe-commits

llvmbot wrote:




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

Author: Nicolas van Kempen (nicovank)


Changes


Fix #109327. Small parts taken from #110351.

Removed the type checking between `contains` and `count`/`find` arguments for 
simplicity. Because of overloads, this type-checking is tricky. The same 
strategy is used in `modernize-use-starts-ends-with`.

Ended up copying over the FixIt logic from `modernize-use-starts-ends-with`, I 
think it's the simplest. Open to other suggestions.

Since this may introduce false positives in (bad readability) edge cases, I 
tested this change on several major C++ projects, and didn't find any new build 
or test failures introduced by this change (some errors due to C++23 upgrade, 
unrelated). Tested projects:
 1. kitware/cmake
 2. dolphin-emu/dolphin
 3. blender/blender
 4. opencv/opencv

Co-authored-by: dl8sd11 


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


5 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp (+52-44) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst 
(+1) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string 
(+11) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp 
(+47-17) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index fb68c7d334b7f..6157a7121f1e5 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -9,47 +9,43 @@
 #include "ContainerContainsCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
-  const auto HasContainsMatchingParamType = hasMethod(
-  cxxMethodDecl(isConst(), parameterCountIs(1), returns(booleanType()),
-hasName("contains"), unless(isDeleted()), isPublic(),
-hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-equalsBoundNode("parameterType"));
+  const auto Literal0 = integerLiteral(equals(0));
+  const auto Literal1 = integerLiteral(equals(1));
+
+  const auto ClassWithContains = cxxRecordDecl(
+  hasMethod(cxxMethodDecl(isConst(), parameterCountIs(1), isPublic(),
+  unless(isDeleted()), returns(booleanType()),
+  hasAnyName("contains", "Contains"))
+.bind("contains_fun")));
 
   const auto CountCall =
-  cxxMemberCallExpr(
-  argumentCountIs(1),
-  callee(cxxMethodDecl(
-  hasName("count"),
-  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-  type().bind("parameterType",
-  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
+  cxxMemberCallExpr(argumentCountIs(1),
+callee(cxxMethodDecl(hasAnyName("count", "Count"),
+ ofClass(ClassWithContains
   .bind("call");
 
   const auto FindCall =
-  cxxMemberCallExpr(
-  argumentCountIs(1),
-  callee(cxxMethodDecl(
-  hasName("find"),
-  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-  type().bind("parameterType",
-  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
+  // Either one argument, or assume the second argument is the position to
+  // start searching from.
+  cxxMemberCallExpr(anyOf(argumentCountIs(1),
+  cxxMemberCallExpr(argumentCountIs(2),
+hasArgument(1, Literal0))),
+callee(cxxMethodDecl(hasAnyName("find", "Find"),
+ ofClass(ClassWithContains
   .bind("call");
 
   const auto EndCall = cxxMemberCallExpr(
-  argumentCountIs(0),
-  callee(
-  cxxMethodDecl(hasName("end"),
-// In the matchers below, FindCall should always appear
-// before EndCall so 'parameterType' is properly bound.
-
ofClass(cxxRecordDecl(HasContainsMatchingParamType);
+  argumentCountIs(0), callee(cxxMethodDecl(hasAnyName("end", "End"),
+   ofClass(ClassWithContains;
 
-  const auto Literal0 = integerLiteral(equals(0));
-  const auto Literal1 = integerLiteral(equals(1));
+  const auto StringNpos = anyOf(declRefExpr(to(varDecl(hasName("npos"

[clang] 54ed459 - [HLSL] Add copy assignment and construtor to resource types (#156075)

2025-09-06 Thread via cfe-commits

Author: Steven Perron
Date: 2025-09-06T11:50:03Z
New Revision: 54ed459e3ed83bcc6570b885e9c9e65ab65dae75

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

LOG: [HLSL] Add copy assignment and construtor to resource types (#156075)

The wrapper used to hold the handle for resource type has just the
default copy constructor and assignment operator. This causes clang to
insert memcpys when it does an assignment of a resource type. The
memcpy then cause optimizations to fail when the memcpy is turned into a
load and store of an i64.

To fix this, we should define copying of a resource type by adding the
operator= and copy constructor.

Partially fixes #154669

Added: 


Modified: 
clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h
clang/lib/Sema/HLSLExternalSemaSource.cpp
clang/test/AST/HLSL/ByteAddressBuffers-AST.hlsl
clang/test/AST/HLSL/StructuredBuffers-AST.hlsl
clang/test/AST/HLSL/TypedBuffers-AST.hlsl
clang/test/CodeGenHLSL/builtins/hlsl_resource_t.hlsl
clang/test/CodeGenHLSL/debug/rwbuffer_debug_info.hlsl
clang/test/CodeGenHLSL/implicit-norecurse-attrib.hlsl
clang/test/CodeGenHLSL/resources/res-array-local-multi-dim.hlsl
clang/test/CodeGenHLSL/resources/res-array-local1.hlsl
clang/test/CodeGenHLSL/resources/res-array-local3.hlsl
clang/test/SemaHLSL/Language/InitLists.hlsl

Removed: 




diff  --git a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp 
b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
index 7830cdd18c6cd..b8591b0fe475a 100644
--- a/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
+++ b/clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp
@@ -156,6 +156,10 @@ struct BuiltinTypeMethodBuilder {
   BuiltinTypeDeclBuilder &finalize();
   Expr *getResourceHandleExpr();
 
+  template 
+  BuiltinTypeMethodBuilder &getResourceHandle(T ResourceRecord);
+  BuiltinTypeMethodBuilder &returnThis();
+
 private:
   void createDecl();
 
@@ -332,7 +336,7 @@ Expr 
*BuiltinTypeMethodBuilder::convertPlaceholder(PlaceHolder PH) {
   return DeclRefExpr::Create(
   AST, NestedNameSpecifierLoc(), SourceLocation(), ParamDecl, false,
   DeclarationNameInfo(ParamDecl->getDeclName(), SourceLocation()),
-  ParamDecl->getType(), VK_PRValue);
+  ParamDecl->getType().getNonReferenceType(), VK_PRValue);
 }
 
 BuiltinTypeMethodBuilder::BuiltinTypeMethodBuilder(BuiltinTypeDeclBuilder &DB,
@@ -431,6 +435,31 @@ Expr *BuiltinTypeMethodBuilder::getResourceHandleExpr() {
 OK_Ordinary);
 }
 
+template 
+BuiltinTypeMethodBuilder &
+BuiltinTypeMethodBuilder::getResourceHandle(T ResourceRecord) {
+  ensureCompleteDecl();
+
+  Expr *ResourceExpr = convertPlaceholder(ResourceRecord);
+
+  ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
+  FieldDecl *HandleField = DeclBuilder.getResourceHandleField();
+  MemberExpr *HandleExpr = MemberExpr::CreateImplicit(
+  AST, ResourceExpr, /*IsArrow=*/false, HandleField, 
HandleField->getType(),
+  VK_LValue, OK_Ordinary);
+  StmtsList.push_back(HandleExpr);
+  return *this;
+}
+
+BuiltinTypeMethodBuilder &BuiltinTypeMethodBuilder::returnThis() {
+  ASTContext &AST = DeclBuilder.SemaRef.getASTContext();
+  CXXThisExpr *ThisExpr = CXXThisExpr::Create(
+  AST, SourceLocation(), Method->getFunctionObjectParameterType(),
+  /*IsImplicit=*/true);
+  StmtsList.push_back(ThisExpr);
+  return *this;
+}
+
 template 
 BuiltinTypeMethodBuilder &
 BuiltinTypeMethodBuilder::callBuiltin(StringRef BuiltinName,
@@ -676,6 +705,45 @@ 
BuiltinTypeDeclBuilder::addHandleConstructorFromImplicitBinding() {
   .finalize();
 }
 
+BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addCopyConstructor() {
+  if (Record->isCompleteDefinition())
+return *this;
+
+  ASTContext &AST = SemaRef.getASTContext();
+  QualType RecordType = AST.getCanonicalTagType(Record);
+  QualType ConstRecordType = RecordType.withConst();
+  QualType ConstRecordRefType = AST.getLValueReferenceType(ConstRecordType);
+
+  using PH = BuiltinTypeMethodBuilder::PlaceHolder;
+
+  return BuiltinTypeMethodBuilder(*this, /*Name=*/"", AST.VoidTy,
+  /*IsConst=*/false, /*IsCtor=*/true)
+  .addParam("other", ConstRecordRefType)
+  .getResourceHandle(PH::_0)
+  .assign(PH::Handle, PH::LastStmt)
+  .finalize();
+}
+
+BuiltinTypeDeclBuilder &BuiltinTypeDeclBuilder::addCopyAssignmentOperator() {
+  if (Record->isCompleteDefinition())
+return *this;
+
+  ASTContext &AST = SemaRef.getASTContext();
+  QualType RecordType = AST.getCanonicalTagType(Record);
+  QualType ConstRecordType = RecordType.withConst();
+  QualType ConstRecordRefType = AST.getLValueReferenceType(ConstRecordType);
+  QualType RecordRefType = AST.getLValueReferenceType(Rec

[clang-tools-extra] d27fae7 - [clang-tidy] Add new check 'llvm-use-ranges' (#152047)

2025-09-06 Thread via cfe-commits

Author: Baranov Victor
Date: 2025-09-06T16:50:02+03:00
New Revision: d27fae73b17c34cbbd55e6f0ab4fea3f960be6f0

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

LOG: [clang-tidy] Add new check 'llvm-use-ranges' (#152047)

First iteration of the check, mostly reused logic from
https://github.com/llvm/llvm-project/pull/97764 without adding any
LLVM-specific iterator-methods.
Successfully run on `LLVM` codebase with ~100 findings and a couple of
odd FPs: when we have `std::sort(this->begin(), this->end())` or
`std::sort(begin(), end())`.
I didn't fix this cases since it will be a separate task for the core
`utils::UseRangesCheck`.

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

-

Co-authored-by: EugeneZelenko 

Added: 
clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp
clang-tools-extra/clang-tidy/llvm/UseRangesCheck.h
clang-tools-extra/docs/clang-tidy/checks/llvm/use-ranges.rst
clang-tools-extra/test/clang-tidy/checkers/llvm/use-ranges.cpp

Modified: 
clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
index 41386cdb55b1f..78ef0444305ff 100644
--- a/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
@@ -12,6 +12,7 @@ add_clang_library(clangTidyLLVMModule STATIC
   PreferStaticOverAnonymousNamespaceCheck.cpp
   TwineLocalCheck.cpp
   UseNewMLIROpBuilderCheck.cpp
+  UseRangesCheck.cpp
 
   LINK_LIBS
   clangTidy

diff  --git a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp 
b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
index c7c61fd1649cc..c1f78caf44d16 100644
--- a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
@@ -19,6 +19,7 @@
 #include "PreferStaticOverAnonymousNamespaceCheck.h"
 #include "TwineLocalCheck.h"
 #include "UseNewMLIROpBuilderCheck.h"
+#include "UseRangesCheck.h"
 
 namespace clang::tidy {
 namespace llvm_check {
@@ -43,6 +44,7 @@ class LLVMModule : public ClangTidyModule {
 CheckFactories.registerCheck("llvm-twine-local");
 CheckFactories.registerCheck(
 "llvm-use-new-mlir-op-builder");
+CheckFactories.registerCheck("llvm-use-ranges");
   }
 
   ClangTidyOptions getModuleOptions() override {

diff  --git a/clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp
new file mode 100644
index 0..4afab488b7dcc
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp
@@ -0,0 +1,97 @@
+//===--- UseRangesCheck.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 "UseRangesCheck.h"
+
+namespace clang::tidy::llvm_check {
+
+namespace {
+
+class StdToLLVMReplacer : public utils::UseRangesCheck::Replacer {
+public:
+  explicit StdToLLVMReplacer(
+  ArrayRef Signatures)
+  : Signatures(Signatures) {}
+
+  ArrayRef
+  getReplacementSignatures() const override {
+return Signatures;
+  }
+
+  std::optional
+  getReplaceName(const NamedDecl &OriginalName) const override {
+return ("llvm::" + OriginalName.getName()).str();
+  }
+
+  std::optional
+  getHeaderInclusion(const NamedDecl &) const override {
+return "llvm/ADT/STLExtras.h";
+  }
+
+private:
+  ArrayRef Signatures;
+};
+
+} // namespace
+
+utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
+  ReplacerMap Results;
+
+  static const Signature SingleSig = {{0}};
+  static const Signature TwoSig = {{0}, {2}};
+
+  const auto AddStdToLLVM =
+  [&Results](llvm::IntrusiveRefCntPtr Replacer,
+ std::initializer_list Names) {
+for (const auto &Name : Names) {
+  Results.try_emplace(("::std::" + Name).str(), Replacer);
+}
+  };
+
+  // Single range algorithms
+  AddStdToLLVM(llvm::makeIntrusiveRefCnt(SingleSig),
+   {"all_of",  "any_of",
+"none_of", "for_each",
+"find","find_if",
+"find_if_not", "fill",
+"count",   "count_if",
+"copy","copy_if",
+"transform",   "replace",
+"remove_if",   "stable_sort",
+"partition",   "partition_point

[clang] Fix incorrect array initialization with string literal (fixes #112189) (PR #156846)

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


@@ -168,16 +168,95 @@ bool Sema::IsStringInit(Expr *Init, const ArrayType *AT) {
   return ::IsStringInit(Init, AT, Context) == SIF_None;
 }
 
+static StringLiteral *CloneStringLiteral(const StringLiteral *SL,
+ ASTContext &C) {
+  SourceLocation *SLocs = new (C) SourceLocation[SL->getNumConcatenated()];
+  std::copy(SL->tokloc_begin(), SL->tokloc_end(), SLocs);
+  return StringLiteral::Create(
+  C, SL->getBytes(), SL->getKind(), SL->isPascal(), SL->getType(),
+  ArrayRef(SLocs, SL->getNumConcatenated()));
+}
+
+// Exactly follow `IgnoreParensSingleStep` (`AST/IgnoreExpr.h`)
+// We only clone those subexpressions which `IgnoreParensSingleStep` drills 
down
+// to.
+static Expr *CloneDrilled(Expr *E, ASTContext &C) {
+  if (auto *SL = dyn_cast(E)) {
+return CloneStringLiteral(SL, C);
+  }
+
+  if (auto *PE = dyn_cast(E)) {
+return new (C) ParenExpr(PE->getBeginLoc(), PE->getEndLoc(),
+ CloneDrilled(PE->getSubExpr(), C));
+  }
+
+  if (auto *UO = dyn_cast(E)) {
+if (UO->getOpcode() == UO_Extension) {
+  return UnaryOperator::Create(
+  C, CloneDrilled(UO->getSubExpr(), C), UO_Extension, UO->getType(),
+  UO->getValueKind(), UO->getObjectKind(), UO->getBeginLoc(),
+  UO->canOverflow(), UO->getFPOptionsOverride());
+}
+  }
+
+  else if (auto *GSE = dyn_cast(E)) {
+if (!GSE->isResultDependent()) {
+  ArrayRef GSEAEs = GSE->getAssocExprs();
+  Expr **NewGSEAEs = new (C) Expr *[GSEAEs.size()];
+  std::copy(GSEAEs.begin(), GSEAEs.end(), NewGSEAEs);
+  NewGSEAEs[GSE->getResultIndex()] = CloneDrilled(GSE->getResultExpr(), C);
+
+#define CREATE_GSE(ctrl)   
\
+  GenericSelectionExpr::Create(
\
+  C, GSE->getGenericLoc(), ctrl, GSE->getAssocTypeSourceInfos(),   
\
+  ArrayRef(NewGSEAEs, GSEAEs.size()), GSE->getDefaultLoc(),
\
+  GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(), 
\
+  GSE->getResultIndex())
+
+  return GSE->isExprPredicate() ? CREATE_GSE(GSE->getControllingExpr())
+: CREATE_GSE(GSE->getControllingType());
+#undef CREATE_GSE
+}
+  }
+
+  else if (auto *CE = dyn_cast(E)) {
+if (!CE->isConditionDependent()) {
+  // Drills to `CE->getChosenSubExpr()`
+  const bool isCondTrue = CE->isConditionTrue();
+  return new (C)
+  ChooseExpr(CE->getBeginLoc(), CE->getCond(),
+ isCondTrue ? CloneDrilled(CE->getLHS(), C) : CE->getLHS(),
+ isCondTrue ? CE->getRHS() : CloneDrilled(CE->getRHS(), C),
+ CE->getType(), CE->getValueKind(), CE->getObjectKind(),
+ CE->getRParenLoc(), CE->isConditionTrue());
+}
+  }
+
+  else if (auto *PE = dyn_cast(E)) {
+if (PE->isTransparent() && PE->getFunctionName()) {
+  return PredefinedExpr::Create(
+  C, PE->getLocation(), PE->getType(), PE->getIdentKind(),
+  PE->isTransparent(), CloneStringLiteral(PE->getFunctionName(), C));
+}
+  }
+
+  return E;
+}
+
 /// Update the type of a string literal, including any surrounding parentheses,
 /// to match the type of the object which it is initializing.
-static void updateStringLiteralType(Expr *E, QualType Ty) {
+static Expr *updateStringLiteralType(Expr *E, QualType Ty, Sema &S) {
+  Expr *ENew = CloneDrilled(E, S.Context);
+  E = ENew;
+
   while (true) {
 E->setType(Ty);
 E->setValueKind(VK_PRValue);
 if (isa(E) || isa(E))
   break;
 E = IgnoreParensSingleStep(E);
   }
+  return ENew;

cor3ntin wrote:

That should be E, right?

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


[clang] [clang] Detect int-to-float narrowing when the back-conversion is unspecified (PR #157174)

2025-09-06 Thread Yanzuo Liu via cfe-commits


@@ -412,10 +412,12 @@ NarrowingKind 
StandardConversionSequence::getNarrowingKind(
 // And back.
 llvm::APSInt ConvertedValue = *IntConstantValue;
 bool ignored;
-Result.convertToInteger(ConvertedValue,
-llvm::APFloat::rmTowardZero, &ignored);
-// If the resulting value is different, this was a narrowing 
conversion.
-if (*IntConstantValue != ConvertedValue) {
+llvm::APFloat::opStatus fs = Result.convertToInteger(

zwuis wrote:

Use camel case. See 
.

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


[clang-tools-extra] bbbba4e - [clang-tidy] Remove global options IgnoreMacros and StrictMode (#157049)

2025-09-06 Thread via cfe-commits

Author: Carlos Galvez
Date: 2025-09-06T12:41:34+02:00
New Revision: a4e82699a70f0473786eeb93e88af109eec7

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

LOG: [clang-tidy] Remove global options IgnoreMacros and StrictMode (#157049)

They had been marked as deprecated since clang-tidy-20. After 2
releases, it's now time to fully remove support for them.

Fixes #156885

Co-authored-by: Carlos Gálvez 

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp
clang-tools-extra/clang-tidy/misc/UnusedParametersCheck.cpp
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp

clang-tools-extra/clang-tidy/performance/InefficientStringConcatenationCheck.cpp
clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.h
clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp
clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.h

clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.h
clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/readability/function-cognitive-complexity-flags.cpp

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/key-dict/.clang-tidy
clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp

Removed: 

clang-tools-extra/test/clang-tidy/infrastructure/deprecation-global-option.cpp



diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 341343e90822b..88abcb6946779 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -62,11 +62,6 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
   return std::nullopt;
 }
 
-static const llvm::StringSet<> DeprecatedGlobalOptions{
-"StrictMode",
-"IgnoreMacros",
-};
-
 static ClangTidyOptions::OptionMap::const_iterator
 findPriorityOption(const ClangTidyOptions::OptionMap &Options,
StringRef NamePrefix, StringRef LocalName,
@@ -78,13 +73,6 @@ findPriorityOption(const ClangTidyOptions::OptionMap 
&Options,
   }
   auto IterLocal = Options.find((NamePrefix + LocalName).str());
   auto IterGlobal = Options.find(LocalName);
-  // FIXME: temporary solution for deprecation warnings, should be removed
-  // after 22.x. Warn configuration deps on deprecation global options.
-  if (IterLocal == Options.end() && IterGlobal != Options.end() &&
-  DeprecatedGlobalOptions.contains(LocalName))
-Context->configurationDiag(
-"global option '%0' is deprecated, please use '%1%0' instead.")
-<< LocalName << NamePrefix;
   if (IterLocal == Options.end())
 return IterGlobal;
   if (IterGlobal == Options.end())

diff  --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index b843e317c471d..15e7b53ed5be0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -32,7 +32,7 @@ AST_MATCHER(Decl,

[clang] [clang][bytecode] Remove unused reportOverflow() (PR #157225)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-fast` running on `sanitizer-buildbot4` while building 
`clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:74:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 92670 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80..
FAIL: LLVM :: 
ExecutionEngine/JITLink/x86-64/MachO_archive_load_hidden_expect_failure.s 
(49892 of 92670)
 TEST 'LLVM :: 
ExecutionEngine/JITLink/x86-64/MachO_archive_load_hidden_expect_failure.s' 
FAILED 
Exit Code: 1

Command Output (stderr):
--
rm -rf 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failure.s.tmp
 && mkdir -p 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failure.s.tmp
 # RUN: at line 1
+ rm -rf 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failure.s.tmp
+ mkdir -p 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failure.s.tmp
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc 
-triple x86_64-apple-macosx10.9 -filetype=obj-o 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failure.s.tmp/MachO_extra_def_strong.o
 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/Inputs/MachO_extra_def_strong.s
 # RUN: at line 2
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-mc 
-triple x86_64-apple-macosx10.9 -filetype=obj -o 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failure.s.tmp/MachO_extra_def_strong.o
 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/Inputs/MachO_extra_def_strong.s
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-ar crs 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failure.s.tmp/libExtraDef.a
 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failure.s.tmp/MachO_extra_def_strong.o
 # RUN: at line 4
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/llvm-ar 
crs 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failure.s.tmp/libExtraDef.a
 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_archive_load_hidden_expect_failu

[clang-tools-extra] [clang-tidy] Add new '-hide-progress' option to tidy-scripts for suppressing progress information (PR #154416)

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

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

>From 0f0db33a875736a5a0527695316c6820a65ad529 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Fri, 29 Aug 2025 17:32:50 +0300
Subject: [PATCH 1/2] [clang-tidy] Add new -hide-progress option to
 tidy-scripts for suppressing progress information

---
 .../clang-tidy/tool/clang-tidy-diff.py| 11 +--
 .../clang-tidy/tool/run-clang-tidy.py | 29 ---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../hide-progress-flag-scripts.cpp| 24 +++
 4 files changed, 55 insertions(+), 13 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/hide-progress-flag-scripts.cpp

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index d7899e0a18d0c..b4b4648e765cf 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -258,6 +258,11 @@ def main():
 help="Upgrades clang-tidy warnings to errors. Same format as 
'-checks'.",
 default="",
 )
+parser.add_argument(
+"-hide-progress",
+action="store_true",
+help="Hide progress",
+)
 
 clang_tidy_args = []
 argv = sys.argv[1:]
@@ -312,7 +317,8 @@ def main():
 if max_task_count == 0:
 max_task_count = multiprocessing.cpu_count()
 max_task_count = min(len(lines_by_file), max_task_count)
-print(f"Running clang-tidy in {max_task_count} threads...")
+if not args.hide_progress:
+print(f"Running clang-tidy in {max_task_count} threads...")
 
 combine_fixes = False
 export_fixes_dir = None
@@ -408,7 +414,8 @@ def main():
 return_code = 1
 
 if combine_fixes:
-print("Writing fixes to " + args.export_fixes + " ...")
+if not args.hide_progress:
+print(f"Writing fixes to {args.export_fixes} ...")
 try:
 merge_replacement_files(export_fixes_dir, args.export_fixes)
 except:
diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 670e0a2c7678a..a722e20a81c68 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -576,6 +576,11 @@ async def main() -> None:
 action="store_true",
 help="Enable per-check timing profiles, and print a report",
 )
+parser.add_argument(
+"-hide-progress",
+action="store_true",
+help="Hide progress",
+)
 args = parser.parse_args()
 
 db_path = "compile_commands.json"
@@ -681,13 +686,11 @@ async def main() -> None:
 file_name_re = re.compile("|".join(args.files))
 files = {f for f in files if file_name_re.search(f)}
 
-print(
-f"Running clang-tidy in {max_task} threads for",
-len(files),
-"files out of",
-number_files_in_database,
-"in compilation database ...",
-)
+if not args.hide_progress:
+print(
+f"Running clang-tidy in {max_task} threads for {len(files)} files "
+f"out of {number_files_in_database} in compilation database ..."
+)
 
 returncode = 0
 semaphore = asyncio.Semaphore(max_task)
@@ -716,13 +719,15 @@ async def main() -> None:
 result.stderr += f"{result.filename}: terminated by signal 
{-result.returncode}\n"
 progress = f"[{i + 1: >{len(f'{len(files)}')}}/{len(files)}]"
 runtime = f"[{result.elapsed:.1f}s]"
-print(f"{progress}{runtime} {' '.join(result.invocation)}")
+if not args.hide_progress:
+print(f"{progress}{runtime} {' '.join(result.invocation)}")
 if result.stdout:
 print(result.stdout, end=("" if result.stderr else "\n"))
 if result.stderr:
 print(result.stderr)
 except asyncio.CancelledError:
-print("\nCtrl-C detected, goodbye.")
+if not args.hide_progress:
+print("\nCtrl-C detected, goodbye.")
 for task in tasks:
 task.cancel()
 if delete_fixes_dir:
@@ -742,7 +747,8 @@ async def main() -> None:
 print("No profiling data found.")
 
 if combine_fixes:
-print(f"Writing fixes to {args.export_fixes} ...")
+if not args.hide_progress:
+print(f"Writing fixes to {args.export_fixes} ...")
 try:
 assert export_fixes_dir
 merge_replacement_files(export_fixes_dir, args.export_fixes)
@@ -752,7 +758,8 @@ async def main() -> None:
 returncode = 1
 
 if args.fix:
-print("Applying fixes ...")
+if not args.hide_progress:
+print("Applying fixes ...")
 try:
 assert export_fixes_dir
 apply_fixes(args, clang_apply_replacements_binary, 

[clang-tools-extra] Reland "[clangd] Add feature modules registry" (PR #154836)

2025-09-06 Thread Aleksandr Platonov via cfe-commits

https://github.com/ArcsinX updated 
https://github.com/llvm/llvm-project/pull/154836

>From 27b44cefdc1ea4b373f8e990bc1fea05fc278701 Mon Sep 17 00:00:00 2001
From: Aleksandr Platonov 
Date: Thu, 21 Aug 2025 22:51:41 +0300
Subject: [PATCH 1/3] [clangd] Introduce feature modules registry This patch
 adds feature modules registry, which allows to discover registered feature
 modules and add them into the clangd's feature module set

---
 clang-tools-extra/clangd/FeatureModule.cpp   | 15 +++
 clang-tools-extra/clangd/FeatureModule.h | 17 ++---
 clang-tools-extra/clangd/tool/ClangdMain.cpp |  5 +
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clangd/FeatureModule.cpp 
b/clang-tools-extra/clangd/FeatureModule.cpp
index 872cea1443789..38461e3db4e6b 100644
--- a/clang-tools-extra/clangd/FeatureModule.cpp
+++ b/clang-tools-extra/clangd/FeatureModule.cpp
@@ -22,6 +22,10 @@ FeatureModule::Facilities &FeatureModule::facilities() {
   return *Fac;
 }
 
+void FeatureModuleSet::add(std::unique_ptr M) {
+  Modules.push_back(std::move(M));
+}
+
 bool FeatureModuleSet::addImpl(void *Key, std::unique_ptr M,
const char *Source) {
   if (!Map.try_emplace(Key, M.get()).second) {
@@ -33,5 +37,16 @@ bool FeatureModuleSet::addImpl(void *Key, 
std::unique_ptr M,
   return true;
 }
 
+FeatureModuleSet FeatureModuleSet::fromRegistry() {
+  FeatureModuleSet ModuleSet;
+  for (FeatureModuleRegistry::entry E : FeatureModuleRegistry::entries()) {
+vlog("Adding feature module '{0}' ({1})", E.getName(), E.getDesc());
+ModuleSet.add(E.instantiate());
+  }
+  return ModuleSet;
+}
+
 } // namespace clangd
 } // namespace clang
+
+LLVM_INSTANTIATE_REGISTRY(clang::clangd::FeatureModuleRegistry)
diff --git a/clang-tools-extra/clangd/FeatureModule.h 
b/clang-tools-extra/clangd/FeatureModule.h
index 7b6883507be3f..ee65aa8a59ed2 100644
--- a/clang-tools-extra/clangd/FeatureModule.h
+++ b/clang-tools-extra/clangd/FeatureModule.h
@@ -15,6 +15,7 @@
 #include "llvm/ADT/FunctionExtras.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/JSON.h"
+#include "llvm/Support/Registry.h"
 #include 
 #include 
 #include 
@@ -143,9 +144,14 @@ class FeatureModule {
 
 /// A FeatureModuleSet is a collection of feature modules installed in clangd.
 ///
-/// Modules can be looked up by type, or used via the FeatureModule interface.
-/// This allows individual modules to expose a public API.
-/// For this reason, there can be only one feature module of each type.
+/// Modules added with explicit type specification can be looked up by type, or
+/// used via the FeatureModule interface. This allows individual modules to
+/// expose a public API. For this reason, there can be only one feature module
+/// of each type.
+///
+/// Modules added using a base class pointer can be used only via the
+/// FeatureModule interface and can't be looked up by type, thus custom public
+/// API (if provided by the module) can't be used.
 ///
 /// The set owns the modules. It is itself owned by main, not ClangdServer.
 class FeatureModuleSet {
@@ -164,6 +170,8 @@ class FeatureModuleSet {
 public:
   FeatureModuleSet() = default;
 
+  static FeatureModuleSet fromRegistry();
+
   using iterator = llvm::pointee_iterator;
   using const_iterator =
   llvm::pointee_iterator;
@@ -172,6 +180,7 @@ class FeatureModuleSet {
   const_iterator begin() const { return const_iterator(Modules.begin()); }
   const_iterator end() const { return const_iterator(Modules.end()); }
 
+  void add(std::unique_ptr M);
   template  bool add(std::unique_ptr M) {
 return addImpl(&ID::Key, std::move(M), LLVM_PRETTY_FUNCTION);
   }
@@ -185,6 +194,8 @@ class FeatureModuleSet {
 
 template  int FeatureModuleSet::ID::Key;
 
+using FeatureModuleRegistry = llvm::Registry;
+
 } // namespace clangd
 } // namespace clang
 #endif
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index f287439f10cab..1856d4f47ffc5 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -13,6 +13,7 @@
 #include "Config.h"
 #include "ConfigProvider.h"
 #include "Feature.h"
+#include "FeatureModule.h"
 #include "IncludeCleaner.h"
 #include "PathMapping.h"
 #include "Protocol.h"
@@ -1017,6 +1018,10 @@ clangd accepts flags on the commandline, and in the 
CLANGD_FLAGS environment var
: static_cast(ErrorResultCode::CheckFailed);
   }
 
+  FeatureModuleSet ModuleSet = FeatureModuleSet::fromRegistry();
+  if (ModuleSet.begin() != ModuleSet.end())
+Opts.FeatureModules = &ModuleSet;
+
   // Initialize and run ClangdLSPServer.
   // Change stdin to binary to not lose \r\n on windows.
   llvm::sys::ChangeStdinToBinary();

>From c0961a4094a355539989fc4ed54bdfda1fb3047c Mon Sep 17 00:00:00 2001
From: Aleksandr Platonov 
Date: Wed, 27 Aug 2025 23:23:06 +0300
Subject: [PATCH 2/3] Add feature modules regist

[clang] fd7f464 - [clang] Polymorphic Cleanup type is moved despite not being POD types (#156607)

2025-09-06 Thread via cfe-commits

Author: Oliver Hunt
Date: 2025-09-06T01:26:28-07:00
New Revision: fd7f464333b9d0c46c716520aa5332881f4a9608

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

LOG: [clang] Polymorphic Cleanup type is moved despite not being POD types 
(#156607)

Clang as a number of Cleanup types used in exception handling, these are
presumed to be POD types that can be memmoved as needed, however this is
not correct by default on platforms with pointer authentication that
make vtable pointers address discriminated.

This PR mitigates this problem by introducing a
LLVM_MOVABLE_POLYMORPHIC_TYPE macro that can be used to annotate
polymorphic types that are required to be movable, to override the use
of address discrimination of the vtable pointer.

Added: 


Modified: 
clang/lib/CIR/CodeGen/EHScopeStack.h
clang/lib/CodeGen/EHScopeStack.h
llvm/include/llvm/Support/Compiler.h

Removed: 




diff  --git a/clang/lib/CIR/CodeGen/EHScopeStack.h 
b/clang/lib/CIR/CodeGen/EHScopeStack.h
index 47478f6cf4bb3..c87a6ef9660ad 100644
--- a/clang/lib/CIR/CodeGen/EHScopeStack.h
+++ b/clang/lib/CIR/CodeGen/EHScopeStack.h
@@ -90,7 +90,7 @@ class EHScopeStack {
   ///
   /// Cleanup implementations should generally be declared in an
   /// anonymous namespace.
-  class Cleanup {
+  class LLVM_MOVABLE_POLYMORPHIC_TYPE Cleanup {
 // Anchor the construction vtable.
 virtual void anchor();
 

diff  --git a/clang/lib/CodeGen/EHScopeStack.h 
b/clang/lib/CodeGen/EHScopeStack.h
index 54f6ceaa52b95..2dcb75556c4e5 100644
--- a/clang/lib/CodeGen/EHScopeStack.h
+++ b/clang/lib/CodeGen/EHScopeStack.h
@@ -143,7 +143,7 @@ class EHScopeStack {
   ///
   /// Cleanup implementations should generally be declared in an
   /// anonymous namespace.
-  class alignas(uint64_t) Cleanup {
+  class LLVM_MOVABLE_POLYMORPHIC_TYPE alignas(uint64_t) Cleanup {
 // Anchor the construction vtable.
 virtual void anchor();
 

diff  --git a/llvm/include/llvm/Support/Compiler.h 
b/llvm/include/llvm/Support/Compiler.h
index 297d3e9b04095..56f498a36ae52 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -706,6 +706,15 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
 #define LLVM_PREFERRED_TYPE(T)
 #endif
 
+#if LLVM_HAS_CPP_ATTRIBUTE(clang::ptrauth_vtable_pointer) &&   
\
+(defined(__PTRAUTH__) || __has_feature(ptrauth_calls))
+#define LLVM_MOVABLE_POLYMORPHIC_TYPE  
\
+  [[clang::ptrauth_vtable_pointer(default_key, no_address_discrimination,  
\
+  default_extra_discrimination)]]
+#else
+#define LLVM_MOVABLE_POLYMORPHIC_TYPE
+#endif
+
 /// \macro LLVM_VIRTUAL_ANCHOR_FUNCTION
 /// This macro is used to adhere to LLVM's policy that each class with a vtable
 /// must have at least one out-of-line virtual function. This macro allows us



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


[clang] [clang] Look through parens around reinterpret_cast to emit a warning (PR #157033)

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

https://github.com/shafik commented:

Please add a release note.

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


[clang] [HLSL] Fix deprecation warnings in HLSL (PR #153310)

2025-09-06 Thread Chris B via cfe-commits

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


[clang-tools-extra] [clang-tidy] Support find for string-like classes in readability-container-contains (PR #157243)

2025-09-06 Thread Nicolas van Kempen via cfe-commits

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


Fix #109327. Small parts taken from #110351.

Removed the type checking between `contains` and `count`/`find` arguments for 
simplicity. Because of overloads, this type-checking is tricky. The same 
strategy is used in `modernize-use-starts-ends-with`.

Ended up copying over the FixIt logic from `modernize-use-starts-ends-with`, I 
think it's the simplest. Open to other suggestions.

Since this may introduce false positives in (bad readability) edge cases, I 
tested this change on several major C++ projects, and didn't find any new build 
or test failures introduced by this change (some errors due to C++23 upgrade, 
unrelated). Tested projects:
 1. kitware/cmake
 2. dolphin-emu/dolphin
 3. blender/blender
 4. opencv/opencv

Co-authored-by: dl8sd11 


>From df3cc51488f7da416b227ca12dcecb0a90fd Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Fri, 5 Sep 2025 21:48:13 -0400
Subject: [PATCH] [clang-tidy] Support find for string-like classes in
 readability-container-contains

Fix #109327. Small parts taken from #110351.

Removed the type checking between `contains` and `count`/`find` arguments for 
simplicity. Because of overloads, this type-checking is tricky. The same 
strategy is used in `modernize-use-starts-ends-with`.

Ended up copying over the FixIt logic from `modernize-use-starts-ends-with`, I 
think it's the simplest. Open to other suggestions.

Since this may introduce false positives in (bad readability) edge cases, I 
tested this change on several major C++ projects, and didn't find any new build 
or test failures introduced by this change (some errors due to C++23 upgrade, 
unrelated). Tested projects:
 1. kitware/cmake
 2. dolphin-emu/dolphin
 3. blender/blender
 4. opencv/opencv

Co-authored-by: dl8sd11 
---
 .../readability/ContainerContainsCheck.cpp| 96 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +
 .../checks/readability/container-contains.rst |  1 +
 .../clang-tidy/checkers/Inputs/Headers/string | 11 +++
 .../readability/container-contains.cpp| 64 +
 5 files changed, 115 insertions(+), 61 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index fb68c7d334b7f..6157a7121f1e5 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -9,47 +9,43 @@
 #include "ContainerContainsCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
-  const auto HasContainsMatchingParamType = hasMethod(
-  cxxMethodDecl(isConst(), parameterCountIs(1), returns(booleanType()),
-hasName("contains"), unless(isDeleted()), isPublic(),
-hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-equalsBoundNode("parameterType"));
+  const auto Literal0 = integerLiteral(equals(0));
+  const auto Literal1 = integerLiteral(equals(1));
+
+  const auto ClassWithContains = cxxRecordDecl(
+  hasMethod(cxxMethodDecl(isConst(), parameterCountIs(1), isPublic(),
+  unless(isDeleted()), returns(booleanType()),
+  hasAnyName("contains", "Contains"))
+.bind("contains_fun")));
 
   const auto CountCall =
-  cxxMemberCallExpr(
-  argumentCountIs(1),
-  callee(cxxMethodDecl(
-  hasName("count"),
-  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-  type().bind("parameterType",
-  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
+  cxxMemberCallExpr(argumentCountIs(1),
+callee(cxxMethodDecl(hasAnyName("count", "Count"),
+ ofClass(ClassWithContains
   .bind("call");
 
   const auto FindCall =
-  cxxMemberCallExpr(
-  argumentCountIs(1),
-  callee(cxxMethodDecl(
-  hasName("find"),
-  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-  type().bind("parameterType",
-  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
+  // Either one argument, or assume the second argument is the position to
+  // start searching from.
+  cxxMemberCallExpr(anyOf(argumentCountIs(1),
+  cxxMemberCallExpr(argumentCountIs(2),
+hasArgument(1, Literal0))),
+callee(cxxMethodDecl(hasAnyName("find", "Find"),
+  

[clang] Fix incorrect array initialization with string literal (fixes #112189) (PR #156846)

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


@@ -168,16 +168,95 @@ bool Sema::IsStringInit(Expr *Init, const ArrayType *AT) {
   return ::IsStringInit(Init, AT, Context) == SIF_None;
 }
 
+static StringLiteral *CloneStringLiteral(const StringLiteral *SL,
+ ASTContext &C) {
+  SourceLocation *SLocs = new (C) SourceLocation[SL->getNumConcatenated()];
+  std::copy(SL->tokloc_begin(), SL->tokloc_end(), SLocs);
+  return StringLiteral::Create(
+  C, SL->getBytes(), SL->getKind(), SL->isPascal(), SL->getType(),
+  ArrayRef(SLocs, SL->getNumConcatenated()));
+}
+
+// Exactly follow `IgnoreParensSingleStep` (`AST/IgnoreExpr.h`)
+// We only clone those subexpressions which `IgnoreParensSingleStep` drills 
down
+// to.
+static Expr *CloneDrilled(Expr *E, ASTContext &C) {
+  if (auto *SL = dyn_cast(E)) {
+return CloneStringLiteral(SL, C);
+  }
+
+  if (auto *PE = dyn_cast(E)) {
+return new (C) ParenExpr(PE->getBeginLoc(), PE->getEndLoc(),
+ CloneDrilled(PE->getSubExpr(), C));
+  }
+
+  if (auto *UO = dyn_cast(E)) {
+if (UO->getOpcode() == UO_Extension) {
+  return UnaryOperator::Create(
+  C, CloneDrilled(UO->getSubExpr(), C), UO_Extension, UO->getType(),
+  UO->getValueKind(), UO->getObjectKind(), UO->getBeginLoc(),
+  UO->canOverflow(), UO->getFPOptionsOverride());
+}
+  }
+
+  else if (auto *GSE = dyn_cast(E)) {
+if (!GSE->isResultDependent()) {
+  ArrayRef GSEAEs = GSE->getAssocExprs();
+  Expr **NewGSEAEs = new (C) Expr *[GSEAEs.size()];
+  std::copy(GSEAEs.begin(), GSEAEs.end(), NewGSEAEs);
+  NewGSEAEs[GSE->getResultIndex()] = CloneDrilled(GSE->getResultExpr(), C);
+
+#define CREATE_GSE(ctrl)   
\
+  GenericSelectionExpr::Create(
\
+  C, GSE->getGenericLoc(), ctrl, GSE->getAssocTypeSourceInfos(),   
\
+  ArrayRef(NewGSEAEs, GSEAEs.size()), GSE->getDefaultLoc(),
\
+  GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(), 
\
+  GSE->getResultIndex())
+
+  return GSE->isExprPredicate() ? CREATE_GSE(GSE->getControllingExpr())
+: CREATE_GSE(GSE->getControllingType());
+#undef CREATE_GSE

cor3ntin wrote:

Lets use a lambda or a function here

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


[clang] [C++20][Modules] Fix merging of anonymous members of class templates. (PR #155948)

2025-09-06 Thread Michael Park via cfe-commits

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


[clang] [HLSL] Add copy assignment and construtor to resource types (PR #156075)

2025-09-06 Thread Steven Perron via cfe-commits

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


[clang-tools-extra] [clang-tidy] Support find for string-like classes in readability-container-contains (PR #157243)

2025-09-06 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank updated 
https://github.com/llvm/llvm-project/pull/157243

>From 95171f2b3163e13db197f98cdd977d977219b0a4 Mon Sep 17 00:00:00 2001
From: Nicolas van Kempen 
Date: Sat, 6 Sep 2025 10:42:12 -0400
Subject: [PATCH] [clang-tidy] Support find for string-like classes in
 readability-container-contains

Fix #109327. Small parts taken from #110351.

Removed the type checking between `contains` and `count`/`find` arguments for 
simplicity. Because of overloads, this type-checking is tricky. The same 
strategy is used in `modernize-use-starts-ends-with`.

Ended up copying over the FixIt logic from `modernize-use-starts-ends-with`, I 
think it's the simplest. Open to other suggestions.

Since this may introduce false positives in (bad readability) edge cases, I 
tested this change on several major C++ projects, and didn't find any new build 
or test failures introduced by this change (some errors due to C++23 upgrade, 
unrelated). Tested projects:
 1. kitware/cmake
 2. dolphin-emu/dolphin
 3. blender/blender
 4. opencv/opencv

Co-authored-by: dl8sd11 
---
 .../readability/ContainerContainsCheck.cpp| 96 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +
 .../checks/readability/container-contains.rst |  1 +
 .../clang-tidy/checkers/Inputs/Headers/string | 11 +++
 .../readability/container-contains.cpp| 64 +
 5 files changed, 115 insertions(+), 61 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index fb68c7d334b7f..628cf895a3612 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -9,47 +9,43 @@
 #include "ContainerContainsCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
-  const auto HasContainsMatchingParamType = hasMethod(
-  cxxMethodDecl(isConst(), parameterCountIs(1), returns(booleanType()),
-hasName("contains"), unless(isDeleted()), isPublic(),
-hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-equalsBoundNode("parameterType"));
+  const auto Literal0 = integerLiteral(equals(0));
+  const auto Literal1 = integerLiteral(equals(1));
+
+  const auto ClassWithContains = cxxRecordDecl(
+  hasMethod(cxxMethodDecl(isConst(), parameterCountIs(1), isPublic(),
+  unless(isDeleted()), returns(booleanType()),
+  hasAnyName("contains", "Contains"))
+.bind("contains_fun")));
 
   const auto CountCall =
-  cxxMemberCallExpr(
-  argumentCountIs(1),
-  callee(cxxMethodDecl(
-  hasName("count"),
-  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-  type().bind("parameterType",
-  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
+  cxxMemberCallExpr(argumentCountIs(1),
+callee(cxxMethodDecl(hasAnyName("count", "Count"),
+ ofClass(ClassWithContains
   .bind("call");
 
   const auto FindCall =
-  cxxMemberCallExpr(
-  argumentCountIs(1),
-  callee(cxxMethodDecl(
-  hasName("find"),
-  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-  type().bind("parameterType",
-  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
+  // Either one argument, or assume the second argument is the position to
+  // start searching from.
+  cxxMemberCallExpr(anyOf(argumentCountIs(1),
+  cxxMemberCallExpr(argumentCountIs(2),
+hasArgument(1, Literal0))),
+callee(cxxMethodDecl(hasAnyName("find", "Find"),
+ ofClass(ClassWithContains
   .bind("call");
 
   const auto EndCall = cxxMemberCallExpr(
-  argumentCountIs(0),
-  callee(
-  cxxMethodDecl(hasName("end"),
-// In the matchers below, FindCall should always appear
-// before EndCall so 'parameterType' is properly bound.
-
ofClass(cxxRecordDecl(HasContainsMatchingParamType);
+  argumentCountIs(0), callee(cxxMethodDecl(hasAnyName("end", "End"),
+   ofClass(ClassWithContains;
 
-  const auto Literal0 = integerLiteral(equals(0));
-  const auto Literal1 = integerLiteral(equals(1));
+  const auto StringNpos = anyOf(declRefExpr(to(varDecl(has

[clang-tools-extra] [clang-tidy] Remove global options IgnoreMacros and StrictMode (PR #157049)

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

https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/157049

>From dc9f561223c1f1031196b34adaf30080130c6bc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Fri, 5 Sep 2025 08:09:21 +
Subject: [PATCH] [clang-tidy] Remove global options IgnoreMacros and
 StrictMode

They had been marked as deprecated since clang-tidy-20. After 2
releases, it's now time to fully remove support for them.

Fixes #156885
---
 clang-tools-extra/clang-tidy/ClangTidyCheck.cpp  | 12 
 .../clang-tidy/bugprone/ArgumentCommentCheck.cpp |  2 +-
 .../clang-tidy/bugprone/LambdaFunctionNameCheck.cpp  |  3 +--
 .../clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp |  2 +-
 .../cppcoreguidelines/AvoidDoWhileCheck.cpp  |  2 +-
 .../cppcoreguidelines/ProTypeConstCastCheck.cpp  |  2 +-
 .../ProTypeStaticCastDowncastCheck.cpp   |  2 +-
 .../clang-tidy/misc/UnusedParametersCheck.cpp|  2 +-
 .../clang-tidy/modernize/MakeSmartPtrCheck.cpp   |  2 +-
 .../clang-tidy/modernize/TypeTraitsCheck.cpp |  2 +-
 .../clang-tidy/modernize/UseBoolLiteralsCheck.cpp|  2 +-
 .../modernize/UseDefaultMemberInitCheck.cpp  |  2 +-
 .../modernize/UseDesignatedInitializersCheck.cpp |  3 +--
 .../clang-tidy/modernize/UseEqualsDefaultCheck.cpp   |  2 +-
 .../clang-tidy/modernize/UseEqualsDeleteCheck.cpp|  2 +-
 .../clang-tidy/modernize/UseStdFormatCheck.cpp   |  2 +-
 .../clang-tidy/modernize/UseStdPrintCheck.cpp|  2 +-
 .../clang-tidy/modernize/UseUsingCheck.cpp   |  2 +-
 .../InefficientStringConcatenationCheck.cpp  |  2 +-
 .../clang-tidy/readability/AvoidConstParamsInDecls.h |  2 +-
 .../readability/AvoidReturnWithVoidValueCheck.cpp|  5 ++---
 .../clang-tidy/readability/ConstReturnTypeCheck.h|  2 +-
 .../InconsistentDeclarationParameterNameCheck.h  |  2 +-
 .../clang-tidy/readability/RedundantCastingCheck.cpp |  2 +-
 .../readability/RedundantDeclarationCheck.cpp|  2 +-
 .../readability/RedundantInlineSpecifierCheck.h  |  2 +-
 .../readability/RedundantSmartptrGetCheck.h  |  2 +-
 .../readability/UppercaseLiteralSuffixCheck.cpp  |  2 +-
 .../clangd/unittests/ConfigCompileTests.cpp  |  6 +-
 .../clangd/unittests/ConfigYAMLTests.cpp |  4 +---
 clang-tools-extra/docs/ReleaseNotes.rst  |  5 +
 .../function-cognitive-complexity-flags.cpp  |  9 -
 .../Inputs/config-files/4/44/.clang-tidy |  2 +-
 .../Inputs/config-files/4/key-dict/.clang-tidy   |  3 +--
 .../infrastructure/deprecation-global-option.cpp |  3 ---
 .../test/clang-tidy/infrastructure/verify-config.cpp |  6 ++
 36 files changed, 39 insertions(+), 70 deletions(-)
 delete mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/deprecation-global-option.cpp

diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 341343e90822b..88abcb6946779 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -62,11 +62,6 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
   return std::nullopt;
 }
 
-static const llvm::StringSet<> DeprecatedGlobalOptions{
-"StrictMode",
-"IgnoreMacros",
-};
-
 static ClangTidyOptions::OptionMap::const_iterator
 findPriorityOption(const ClangTidyOptions::OptionMap &Options,
StringRef NamePrefix, StringRef LocalName,
@@ -78,13 +73,6 @@ findPriorityOption(const ClangTidyOptions::OptionMap 
&Options,
   }
   auto IterLocal = Options.find((NamePrefix + LocalName).str());
   auto IterGlobal = Options.find(LocalName);
-  // FIXME: temporary solution for deprecation warnings, should be removed
-  // after 22.x. Warn configuration deps on deprecation global options.
-  if (IterLocal == Options.end() && IterGlobal != Options.end() &&
-  DeprecatedGlobalOptions.contains(LocalName))
-Context->configurationDiag(
-"global option '%0' is deprecated, please use '%1%0' instead.")
-<< LocalName << NamePrefix;
   if (IterLocal == Options.end())
 return IterGlobal;
   if (IterGlobal == Options.end())
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index b843e317c471d..15e7b53ed5be0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -32,7 +32,7 @@ AST_MATCHER(Decl, isFromStdNamespaceOrSystemHeader) {
 ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
+  StrictMode(Options.get("StrictMode", false)),
   IgnoreSingleArgument(Options.get("IgnoreSingleArgument", fals

[clang] [AArch64] Enable out-of-line atomics by default (PR #157241)

2025-09-06 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated 
https://github.com/llvm/llvm-project/pull/157241

>From 09aad599911545813df9ed898546660eaf008f82 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 6 Sep 2025 03:43:30 -0400
Subject: [PATCH] [AArch64] Enable out-of-line atomics by default

---
 clang/include/clang/Driver/ToolChain.h |  6 --
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  2 +-
 clang/lib/Driver/ToolChains/Fuchsia.h  |  5 -
 clang/lib/Driver/ToolChains/Haiku.h|  5 -
 clang/lib/Driver/ToolChains/Linux.cpp  | 13 -
 clang/lib/Driver/ToolChains/Linux.h|  2 --
 clang/lib/Driver/ToolChains/Managarm.h |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.h  |  5 -
 8 files changed, 1 insertion(+), 42 deletions(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 1425714d34110..b5943317fc243 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -564,12 +564,6 @@ class ToolChain {
   virtual UnwindTableLevel
   getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const;
 
-  /// Test whether this toolchain supports outline atomics by default.
-  virtual bool
-  IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const {
-return false;
-  }
-
   /// Test whether this toolchain defaults to PIC.
   virtual bool isPICDefault() const = 0;
 
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 299422328aecf..809bf8db357c5 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -3054,7 +3054,7 @@ void tools::addOutlineAtomicsArgs(const Driver &D, const 
ToolChain &TC,
 CmdArgs.push_back("-outline-atomics");
   }
 }
-  } else if (Triple.isAArch64() && TC.IsAArch64OutlineAtomicsDefault(Args)) {
+  } else if (Triple.isAArch64()) {
 CmdArgs.push_back("-target-feature");
 CmdArgs.push_back("+outline-atomics");
   }
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.h 
b/clang/lib/Driver/ToolChains/Fuchsia.h
index 619968f585024..fd9a317a7b5d2 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.h
+++ b/clang/lib/Driver/ToolChains/Fuchsia.h
@@ -90,11 +90,6 @@ class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
   GetRuntimeLibType(const llvm::opt::ArgList &Args) const override;
   CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const 
override;
 
-  bool IsAArch64OutlineAtomicsDefault(
-  const llvm::opt::ArgList &Args) const override {
-return true;
-  }
-
   void
   addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
 llvm::opt::ArgStringList &CC1Args,
diff --git a/clang/lib/Driver/ToolChains/Haiku.h 
b/clang/lib/Driver/ToolChains/Haiku.h
index b4b14cf0aeb99..edebf5c49187b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.h
+++ b/clang/lib/Driver/ToolChains/Haiku.h
@@ -56,11 +56,6 @@ class LLVM_LIBRARY_VISIBILITY Haiku : public Generic_ELF {
   const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const override;
 
-  bool IsAArch64OutlineAtomicsDefault(
-  const llvm::opt::ArgList &Args) const override {
-return true;
-  }
-
   SanitizerMask getSupportedSanitizers() const override;
   unsigned GetDefaultDwarfVersion() const override { return 4; }
 
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 16e35b08cfbd6..944e8f08d8859 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -772,19 +772,6 @@ bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) 
const {
  getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE();
 }
 
-bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const {
-  // Outline atomics for AArch64 are supported by compiler-rt
-  // and libgcc since 9.3.1
-  assert(getTriple().isAArch64() && "expected AArch64 target!");
-  ToolChain::RuntimeLibType RtLib = GetRuntimeLibType(Args);
-  if (RtLib == ToolChain::RLT_CompilerRT)
-return true;
-  assert(RtLib == ToolChain::RLT_Libgcc && "unexpected runtime library type!");
-  if (GCCInstallation.getVersion().isOlderThan(9, 3, 1))
-return false;
-  return true;
-}
-
 bool Linux::IsMathErrnoDefault() const {
   if (getTriple().isAndroid() || getTriple().isMusl())
 return false;
diff --git a/clang/lib/Driver/ToolChains/Linux.h 
b/clang/lib/Driver/ToolChains/Linux.h
index 2eb2d05786fe3..87833106e1e0e 100644
--- a/clang/lib/Driver/ToolChains/Linux.h
+++ b/clang/lib/Driver/ToolChains/Linux.h
@@ -46,8 +46,6 @@ class LLVM_LIBRARY_VISIBILITY Linux : public Generic_ELF {
   RuntimeLibType GetDefaultRuntimeLibType() const override;
   unsigned GetDefaultDwarfVersion() const override;
   CXXStdlibType GetDefaultCXXStdlibType() const override;
-  bool
-  IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const 
override;
   bool isPIEDefault(const

[clang] [AArch64] Enable out-of-line atomics by default (PR #157241)

2025-09-06 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 origin/main HEAD --extensions cpp,h -- 
clang/include/clang/Driver/ToolChain.h 
clang/lib/Driver/ToolChains/CommonArgs.cpp 
clang/lib/Driver/ToolChains/Fuchsia.h clang/lib/Driver/ToolChains/Haiku.h 
clang/lib/Driver/ToolChains/Linux.cpp clang/lib/Driver/ToolChains/Linux.h 
clang/lib/Driver/ToolChains/Managarm.h clang/lib/Driver/ToolChains/OpenBSD.h
``

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/Linux.h 
b/clang/lib/Driver/ToolChains/Linux.h
index 14a6e9e87..031a3ecfa 100644
--- a/clang/lib/Driver/ToolChains/Linux.h
+++ b/clang/lib/Driver/ToolChains/Linux.h
@@ -46,8 +46,7 @@ public:
   RuntimeLibType GetDefaultRuntimeLibType() const override;
   unsigned GetDefaultDwarfVersion() const override;
   CXXStdlibType GetDefaultCXXStdlibType() const override;
-  bool
-  bool isPIEDefault(const llvm::opt::ArgList &Args) const override;
+  bool bool isPIEDefault(const llvm::opt::ArgList &Args) const override;
   bool IsMathErrnoDefault() const override;
   SanitizerMask getSupportedSanitizers() const override;
   void addProfileRTLibs(const llvm::opt::ArgList &Args,

``




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


[clang-tools-extra] [Clang-Tidy] Add google-runtime-float Clang-Tidy check (PR #156763)

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


@@ -11,6 +11,7 @@ add_clang_library(clangTidyGoogleModule STATIC
   DefaultArgumentsCheck.cpp
   ExplicitConstructorCheck.cpp
   ExplicitMakePairCheck.cpp
+  FloatTypesCheck.cpp

vbvictor wrote:

Sure, but I don't see any benefits in keeping them consistent.

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


[clang] [Driver] Enable outline atomics for NetBSD/aarch64 (PR #156143)

2025-09-06 Thread Brad Smith via cfe-commits

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


[clang] 5c8c59d - [clang][bytecode] Remove unused reportOverflow() (#157225)

2025-09-06 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-09-06T07:25:53+02:00
New Revision: 5c8c59d7926289c5a98e127d5a1dc8c3951845e4

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

LOG: [clang][bytecode] Remove unused reportOverflow() (#157225)

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpState.cpp
clang/lib/AST/ByteCode/InterpState.h

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpState.cpp 
b/clang/lib/AST/ByteCode/InterpState.cpp
index 6b0e72095dc55..131d84b300953 100644
--- a/clang/lib/AST/ByteCode/InterpState.cpp
+++ b/clang/lib/AST/ByteCode/InterpState.cpp
@@ -73,12 +73,6 @@ void InterpState::cleanup() {
 
 Frame *InterpState::getCurrentFrame() { return Current; }
 
-bool InterpState::reportOverflow(const Expr *E, const llvm::APSInt &Value) {
-  QualType Type = E->getType();
-  CCEDiag(E, diag::note_constexpr_overflow) << Value << Type;
-  return noteUndefinedBehavior();
-}
-
 void InterpState::deallocate(Block *B) {
   assert(B);
   assert(!B->isDynamic());

diff  --git a/clang/lib/AST/ByteCode/InterpState.h 
b/clang/lib/AST/ByteCode/InterpState.h
index e4d1dc64ff01b..e095908bce986 100644
--- a/clang/lib/AST/ByteCode/InterpState.h
+++ b/clang/lib/AST/ByteCode/InterpState.h
@@ -90,9 +90,6 @@ class InterpState final : public State, public SourceMapper {
   bool hasPriorDiagnostic() override { return Parent.hasPriorDiagnostic(); }
   bool noteSideEffect() override { return Parent.noteSideEffect(); }
 
-  /// Reports overflow and return true if evaluation should continue.
-  bool reportOverflow(const Expr *E, const llvm::APSInt &Value);
-
   /// Deallocates a pointer.
   void deallocate(Block *B);
 



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


[clang-tools-extra] [Clang-Tidy] Add google-runtime-float Clang-Tidy check (PR #156763)

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


@@ -0,0 +1,39 @@
+// RUN: %check_clang_tidy %s google-runtime-float %t
+
+long double foo;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'long double' type is not portable 
and should not be used [google-runtime-float]
+
+typedef long double MyLongDouble;
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'long double' type is not portable 
and should not be used [google-runtime-float]
+
+typedef long double MyOtherLongDouble; // NOLINT
+
+template 
+void tmpl() { T i; }
+
+long volatile double v = 10;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'volatile long double' type is not 
portable and should not be used [google-runtime-float]
+
+long double h(long const double aaa, long double bbb = 0.5L) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'long double' type is not 
portable and should not be used [google-runtime-float]
+  // CHECK-MESSAGES: :[[@LINE-2]]:15: warning: 'const long double' type is not 
portable and should not be used [google-runtime-float]
+  // CHECK-MESSAGES: :[[@LINE-3]]:38: warning: 'long double' type is not 
portable and should not be used [google-runtime-float]
+  // CHECK-MESSAGES: :[[@LINE-4]]:56: warning: 'long double' type from literal 
suffix 'L' is not portable and should not be used [google-runtime-float]
+  double x = 0.1;
+  double y = 0.2L;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'long double' type from literal 
suffix 'L' is not portable and should not be used [google-runtime-float]
+#define ldtype long double
+  ldtype z;
+  tmpl();
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'long double' type is not 
portable and should not be used [google-runtime-float]
+  return 0;
+}
+
+struct S{};
+constexpr S operator"" _baz(unsigned long long) {
+  long double j;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'long double' type is not 
portable and should not be used [google-runtime-float]
+  MyOtherLongDouble x;
+  return S{};
+}
+

vbvictor wrote:

Can we add test for `long int a = 1L` (to check that we don't warn on "long 
literal")

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


[clang-tools-extra] [clang-tidy] Support find for string-like classes in readability-container-contains (PR #157243)

2025-09-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Nicolas van Kempen (nicovank)


Changes


Fix #109327. Small parts taken from #110351.

Removed the type checking between `contains` and `count`/`find` arguments for 
simplicity. Because of overloads, this type-checking is tricky. The same 
strategy is used in `modernize-use-starts-ends-with`.

Ended up copying over the FixIt logic from `modernize-use-starts-ends-with`, I 
think it's the simplest. Open to other suggestions.

Since this may introduce false positives in (bad readability) edge cases, I 
tested this change on several major C++ projects, and didn't find any new build 
or test failures introduced by this change (some errors due to C++23 upgrade, 
unrelated). Tested projects:
 1. kitware/cmake
 2. dolphin-emu/dolphin
 3. blender/blender
 4. opencv/opencv

Co-authored-by: dl8sd11 


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


5 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp (+52-44) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/readability/container-contains.rst 
(+1) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string 
(+11) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp 
(+47-17) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
index fb68c7d334b7f..6157a7121f1e5 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp
@@ -9,47 +9,43 @@
 #include "ContainerContainsCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
-  const auto HasContainsMatchingParamType = hasMethod(
-  cxxMethodDecl(isConst(), parameterCountIs(1), returns(booleanType()),
-hasName("contains"), unless(isDeleted()), isPublic(),
-hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-equalsBoundNode("parameterType"));
+  const auto Literal0 = integerLiteral(equals(0));
+  const auto Literal1 = integerLiteral(equals(1));
+
+  const auto ClassWithContains = cxxRecordDecl(
+  hasMethod(cxxMethodDecl(isConst(), parameterCountIs(1), isPublic(),
+  unless(isDeleted()), returns(booleanType()),
+  hasAnyName("contains", "Contains"))
+.bind("contains_fun")));
 
   const auto CountCall =
-  cxxMemberCallExpr(
-  argumentCountIs(1),
-  callee(cxxMethodDecl(
-  hasName("count"),
-  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-  type().bind("parameterType",
-  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
+  cxxMemberCallExpr(argumentCountIs(1),
+callee(cxxMethodDecl(hasAnyName("count", "Count"),
+ ofClass(ClassWithContains
   .bind("call");
 
   const auto FindCall =
-  cxxMemberCallExpr(
-  argumentCountIs(1),
-  callee(cxxMethodDecl(
-  hasName("find"),
-  hasParameter(0, hasType(hasUnqualifiedDesugaredType(
-  type().bind("parameterType",
-  ofClass(cxxRecordDecl(HasContainsMatchingParamType)
+  // Either one argument, or assume the second argument is the position to
+  // start searching from.
+  cxxMemberCallExpr(anyOf(argumentCountIs(1),
+  cxxMemberCallExpr(argumentCountIs(2),
+hasArgument(1, Literal0))),
+callee(cxxMethodDecl(hasAnyName("find", "Find"),
+ ofClass(ClassWithContains
   .bind("call");
 
   const auto EndCall = cxxMemberCallExpr(
-  argumentCountIs(0),
-  callee(
-  cxxMethodDecl(hasName("end"),
-// In the matchers below, FindCall should always appear
-// before EndCall so 'parameterType' is properly bound.
-
ofClass(cxxRecordDecl(HasContainsMatchingParamType);
+  argumentCountIs(0), callee(cxxMethodDecl(hasAnyName("end", "End"),
+   ofClass(ClassWithContains;
 
-  const auto Literal0 = integerLiteral(equals(0));
-  const auto Literal1 = integerLiteral(equals(1));
+  const auto StringNpos = anyOf(declRefExpr(to(varDecl(hasName("npos",
+

[clang] [Clang-Repl] Sinking RemoteJITUtils into Interpreter class(Refactoring) (PR #155140)

2025-09-06 Thread Abhinav Kumar via cfe-commits


@@ -275,10 +331,10 @@ int main(int argc, const char **argv) {
 if (!CudaPath.empty())
   CB.SetCudaSDK(CudaPath);
 
-if (OffloadArch.empty()) {
-  OffloadArch = "sm_35";
+if (::OffloadArch.empty()) {
+  ::OffloadArch = "sm_35";
 }
-CB.SetOffloadArch(OffloadArch);
+CB.SetOffloadArch(::OffloadArch);

kr-2003 wrote:

.

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


[clang] [clang] VectorExprEvaluator::VisitCallExpr - use APSInt callback instead of repeated switch statement (PR #157137)

2025-09-06 Thread Simon Pilgrim via cfe-commits

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


[clang] Fix incorrect array initialization with string literal (fixes #112189) (PR #156846)

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


@@ -168,16 +168,95 @@ bool Sema::IsStringInit(Expr *Init, const ArrayType *AT) {
   return ::IsStringInit(Init, AT, Context) == SIF_None;
 }
 
+static StringLiteral *CloneStringLiteral(const StringLiteral *SL,
+ ASTContext &C) {
+  SourceLocation *SLocs = new (C) SourceLocation[SL->getNumConcatenated()];
+  std::copy(SL->tokloc_begin(), SL->tokloc_end(), SLocs);
+  return StringLiteral::Create(
+  C, SL->getBytes(), SL->getKind(), SL->isPascal(), SL->getType(),
+  ArrayRef(SLocs, SL->getNumConcatenated()));
+}
+
+// Exactly follow `IgnoreParensSingleStep` (`AST/IgnoreExpr.h`)
+// We only clone those subexpressions which `IgnoreParensSingleStep` drills 
down
+// to.
+static Expr *CloneDrilled(Expr *E, ASTContext &C) {
+  if (auto *SL = dyn_cast(E)) {
+return CloneStringLiteral(SL, C);
+  }
+
+  if (auto *PE = dyn_cast(E)) {
+return new (C) ParenExpr(PE->getBeginLoc(), PE->getEndLoc(),
+ CloneDrilled(PE->getSubExpr(), C));
+  }
+
+  if (auto *UO = dyn_cast(E)) {
+if (UO->getOpcode() == UO_Extension) {
+  return UnaryOperator::Create(
+  C, CloneDrilled(UO->getSubExpr(), C), UO_Extension, UO->getType(),
+  UO->getValueKind(), UO->getObjectKind(), UO->getBeginLoc(),
+  UO->canOverflow(), UO->getFPOptionsOverride());
+}
+  }
+
+  else if (auto *GSE = dyn_cast(E)) {
+if (!GSE->isResultDependent()) {
+  ArrayRef GSEAEs = GSE->getAssocExprs();
+  Expr **NewGSEAEs = new (C) Expr *[GSEAEs.size()];
+  std::copy(GSEAEs.begin(), GSEAEs.end(), NewGSEAEs);
+  NewGSEAEs[GSE->getResultIndex()] = CloneDrilled(GSE->getResultExpr(), C);
+
+#define CREATE_GSE(ctrl)   
\
+  GenericSelectionExpr::Create(
\
+  C, GSE->getGenericLoc(), ctrl, GSE->getAssocTypeSourceInfos(),   
\
+  ArrayRef(NewGSEAEs, GSEAEs.size()), GSE->getDefaultLoc(),
\
+  GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(), 
\
+  GSE->getResultIndex())
+
+  return GSE->isExprPredicate() ? CREATE_GSE(GSE->getControllingExpr())
+: CREATE_GSE(GSE->getControllingType());
+#undef CREATE_GSE
+}
+  }
+
+  else if (auto *CE = dyn_cast(E)) {
+if (!CE->isConditionDependent()) {
+  // Drills to `CE->getChosenSubExpr()`
+  const bool isCondTrue = CE->isConditionTrue();
+  return new (C)
+  ChooseExpr(CE->getBeginLoc(), CE->getCond(),
+ isCondTrue ? CloneDrilled(CE->getLHS(), C) : CE->getLHS(),
+ isCondTrue ? CE->getRHS() : CloneDrilled(CE->getRHS(), C),
+ CE->getType(), CE->getValueKind(), CE->getObjectKind(),
+ CE->getRParenLoc(), CE->isConditionTrue());
+}
+  }
+
+  else if (auto *PE = dyn_cast(E)) {
+if (PE->isTransparent() && PE->getFunctionName()) {
+  return PredefinedExpr::Create(
+  C, PE->getLocation(), PE->getType(), PE->getIdentKind(),
+  PE->isTransparent(), CloneStringLiteral(PE->getFunctionName(), C));
+}
+  }
+
+  return E;
+}
+
 /// Update the type of a string literal, including any surrounding parentheses,
 /// to match the type of the object which it is initializing.
-static void updateStringLiteralType(Expr *E, QualType Ty) {
+static Expr *updateStringLiteralType(Expr *E, QualType Ty, Sema &S) {
+  Expr *ENew = CloneDrilled(E, S.Context);
+  E = ENew;

cor3ntin wrote:

```suggestion
  E = CloneDrilled(E, S.Context);
```

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


[clang] [clang][analyzer] Add checker 'core.NullPointerArithm' (PR #157129)

2025-09-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)


Changes



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


6 Files Affected:

- (modified) clang/docs/analyzer/checkers.rst (+41) 
- (modified) clang/include/clang/StaticAnalyzer/Checkers/Checkers.td (+5) 
- (modified) clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp (+132-12) 
- (modified) clang/test/Analysis/analyzer-enabled-checkers.c (+1) 
- (added) clang/test/Analysis/null-pointer-arithm.c (+76) 
- (modified) clang/test/Analysis/std-c-library-functions-arg-enabled-checkers.c 
(+1) 


``diff
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index b2effadacf9f1..b3982391358c6 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -205,6 +205,47 @@ pointers with a specified address space. If the option is 
set to false, then
 reports from the specific x86 address spaces 256, 257 and 258 are still
 suppressed, but null dereferences from other address spaces are reported.
 
+.. _core-NullPointerArithm:
+
+core.NullPointerArithm (C, C++)
+"""
+Check for undefined arithmetic operations with null pointers.
+
+The checker can detect the following cases:
+
+  - `p + x` and `x + p` where `p` is a null pointer and `x` is a nonzero 
integer
+value.
+  - `p - x` where `p` is a null pointer and `x` is a nonzero integer
+value.
+  - `p1` - `p2` where one of `p1` and `p2` is null and the other a non-null
+pointer.
+
+Result of these operations is undefined according to the standard.
+
+.. code-block:: c
+
+ void test1(int *p, int offset) {
+   if (p)
+ return;
+
+   int *p1 = p + offset; // warn: 'p' is null, 'offset' can be likely non-zero
+ }
+
+ void test2(int *p, int offset) {
+   if (p) { ... }
+   if (offset == 0)
+ return;
+
+   int *p1 = p - offset; // warn: 'p' can be null, 'offset' is non-zero
+ }
+
+ void test3(char *p1, char *p2) {
+   if (p1)
+ return;
+
+   int a = p1 - p2; // warn: 'p1' is null, 'p2' can be likely non-null
+ }
+
 .. _core-StackAddressEscape:
 
 core.StackAddressEscape (C)
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 73f702de581d9..a6f504c7edcb0 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -216,6 +216,11 @@ def NullDereferenceChecker
   HelpText<"Check for dereferences of null pointers">,
   Documentation;
 
+def NullPointerArithmChecker
+: Checker<"NullPointerArithm">,
+  HelpText<"Check for undefined arithmetic operations on null pointers">,
+  Documentation;
+
 def NonNullParamChecker : Checker<"NonNullParamChecker">,
   HelpText<"Check for null pointers passed as arguments to a function whose "
"arguments are references or marked with the 'nonnull' attribute">,
diff --git a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
index 395d724cdfd11..ee37af9ed0c3d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp
@@ -39,9 +39,10 @@ class DerefBugType : public BugType {
 
 class DereferenceChecker
 : public CheckerFamily,
EventDispatcher> {
-  void reportBug(const DerefBugType &BT, ProgramStateRef State, const Stmt *S,
- CheckerContext &C) const;
+  void reportDerefBug(const DerefBugType &BT, ProgramStateRef State,
+  const Stmt *S, CheckerContext &C) const;
 
   bool suppressReport(CheckerContext &C, const Expr *E) const;
 
@@ -50,6 +51,7 @@ class DereferenceChecker
  CheckerContext &C) const;
   void checkBind(SVal L, SVal V, const Stmt *S, bool AtDeclInit,
  CheckerContext &C) const;
+  void checkPreStmt(const BinaryOperator *Op, CheckerContext &C) const;
 
   static void AddDerefSource(raw_ostream &os,
  SmallVectorImpl &Ranges,
@@ -57,7 +59,7 @@ class DereferenceChecker
  const LocationContext *LCtx,
  bool loadedFrom = false);
 
-  CheckerFrontend NullDerefChecker, FixedDerefChecker;
+  CheckerFrontend NullDerefChecker, FixedDerefChecker, 
NullPointerArithmChecker;
   const DerefBugType NullBug{&NullDerefChecker, "Dereference of null pointer",
  "a null pointer dereference",
  "a dereference of a null pointer"};
@@ -72,6 +74,9 @@ class DereferenceChecker
   const DerefBugType FixedAddressBug{&FixedDerefChecker,
  "Dereference of a fixed address",
  "a dereference of a fixed address"};
+  const BugType NullPointerArithmBug{
+  &NullPointerArithmChecker,
+  "Possible undefined arithmet

[clang] [clang][bytecode] Remove unused reportOverflow() (PR #157225)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-android` running on `sanitizer-buildbot-android` while 
building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[   OK ] AddressSanitizer.AtoiAndFriendsOOBTest (2286 ms)
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (12 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (225 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (43 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (118 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (8 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (127 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (100 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN  ] AddressSanitizer.LongDoubleNegativeTest
[   OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[--] 19 tests from AddressSanitizer (28254 ms total)

[--] Global test environment tear-down
[==] 22 tests from 2 test suites ran. (28256 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

Step 24 (run instrumented asan tests 
[aarch64/aosp_coral-userdebug/AOSP.MASTER]) failure: run instrumented asan 
tests [aarch64/aosp_coral-userdebug/AOSP.MASTER] (failure)
...
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (7 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (333 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (25 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (248 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (20 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (264 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (296 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] Add

[clang-tools-extra] [Clang-Tidy] Add google-runtime-float Clang-Tidy check (PR #156763)

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


@@ -0,0 +1,34 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_FLOATTYPESCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_FLOATTYPESCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::google::runtime {
+
+/// Finds usages of `long double` and suggests against their use due to lack
+/// of portability.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/google/runtime-float.html
+class RuntimeFloatCheck : public ClangTidyCheck {
+public:
+  RuntimeFloatCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {

vbvictor wrote:

I've checked this pattern occurs in other checks. I'm okay with keeping as is 
and rework later.

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


[clang] [compiler-rt] [clang-repl] Reimplement value printing using MemoryAccess to support in-process and out-of-process (PR #156649)

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


@@ -267,92 +267,156 @@ std::string Interpreter::ValueDataToString(const Value 
&V) const {
   return "{ error: unknown builtin type '" + std::to_string(BT->getKind()) 
+
  " '}";
 case clang::BuiltinType::Bool:
-  SS << ((V.getBool()) ? "true" : "false");
-  return Str;
-case clang::BuiltinType::Char_S:
-  SS << '\'' << V.getChar_S() << '\'';
-  return Str;
-case clang::BuiltinType::SChar:
-  SS << '\'' << V.getSChar() << '\'';
-  return Str;
-case clang::BuiltinType::Char_U:
-  SS << '\'' << V.getChar_U() << '\'';
-  return Str;
-case clang::BuiltinType::UChar:
-  SS << '\'' << V.getUChar() << '\'';
+  SS << ((B.as()) ? "true" : "false");
   return Str;
 case clang::BuiltinType::Short:
-  SS << V.getShort();
+  SS << B.as();

vgvassilev wrote:

Why we have to cast the data when we know its type? If that's needed for 
out-of-process where the host and target architectures do not match, we should 
probably somehow do it in a separate facility because `getX` is much faster on 
matching architectures.

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


[clang] Fix incorrect array initialization with string literal (fixes #112189) (PR #156846)

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


@@ -168,16 +168,95 @@ bool Sema::IsStringInit(Expr *Init, const ArrayType *AT) {
   return ::IsStringInit(Init, AT, Context) == SIF_None;
 }
 
+static StringLiteral *CloneStringLiteral(const StringLiteral *SL,
+ ASTContext &C) {
+  SourceLocation *SLocs = new (C) SourceLocation[SL->getNumConcatenated()];
+  std::copy(SL->tokloc_begin(), SL->tokloc_end(), SLocs);
+  return StringLiteral::Create(
+  C, SL->getBytes(), SL->getKind(), SL->isPascal(), SL->getType(),
+  ArrayRef(SLocs, SL->getNumConcatenated()));
+}
+
+// Exactly follow `IgnoreParensSingleStep` (`AST/IgnoreExpr.h`)
+// We only clone those subexpressions which `IgnoreParensSingleStep` drills 
down
+// to.
+static Expr *CloneDrilled(Expr *E, ASTContext &C) {

cor3ntin wrote:

Can we find a better name? `CloneEnclosedStringLiteral` or smth?

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


[clang-tools-extra] [clang-tidy] Add new alias 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c' (PR #157285)

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

https://github.com/vbvictor created 
https://github.com/llvm/llvm-project/pull/157285

My goal is to place all implementation of `cert` checks into `bugprone` or 
other modules. It's hard for the user to understand what `cert-err34-c` means, 
so we should always have human-readable alias for `cert` checks.

Essentially, this renaming can give "free checks" because people tend to just 
[disable cert 
checks](https://github.com/search?q=-cert-*+path%3A**%2F.clang-tidy&type=code), 
despite most of them are regular `bugprone` checks that can give benefits for 
every project.

>From d94e0b12914e64a851f5a41cd5bbfb982ed285de Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Sat, 6 Sep 2025 19:16:53 +0300
Subject: [PATCH] [clang-tidy] Add new alias
 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c'

---
 .../bugprone/BugproneTidyModule.cpp   |  3 ++
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 ...ncheckedStringToNumberConversionCheck.cpp} | 14 
 .../UncheckedStringToNumberConversionCheck.h  | 35 +++
 .../clang-tidy/cert/CERTTidyModule.cpp|  6 ++--
 .../clang-tidy/cert/CMakeLists.txt|  1 -
 .../clang-tidy/cert/StrToNumCheck.h   | 31 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../unchecked-string-to-number-conversion.rst | 31 
 .../docs/clang-tidy/checks/cert/err34-c.rst   | 28 +++
 .../docs/clang-tidy/checks/list.rst   |  5 +--
 .../unchecked-string-to-number-conversion.c}  | 34 +-
 ...unchecked-string-to-number-conversion.cpp} | 14 
 13 files changed, 118 insertions(+), 89 deletions(-)
 rename clang-tools-extra/clang-tidy/{cert/StrToNumCheck.cpp => 
bugprone/UncheckedStringToNumberConversionCheck.cpp} (95%)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.h
 delete mode 100644 clang-tools-extra/clang-tidy/cert/StrToNumCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst
 rename clang-tools-extra/test/clang-tidy/checkers/{cert/err34-c.c => 
bugprone/unchecked-string-to-number-conversion.c} (77%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cert/err34-c.cpp => 
bugprone/unchecked-string-to-number-conversion.cpp} (77%)

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 824ebdfbd00dc..fe261e729539c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -89,6 +89,7 @@
 #include "ThrowKeywordMissingCheck.h"
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
+#include "UncheckedStringToNumberConversionCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
@@ -261,6 +262,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-too-small-loop-variable");
 CheckFactories.registerCheck(
 "bugprone-unchecked-optional-access");
+CheckFactories.registerCheck(
+"bugprone-unchecked-string-to-number-conversion");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 59928e5e47a09..46bc8efd44bc5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -91,6 +91,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   ThrowKeywordMissingCheck.cpp
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
+  UncheckedStringToNumberConversionCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
similarity index 95%
rename from clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
rename to 
clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
index 95536bb1cfdb2..d1e7b895f9a35 100644
--- a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
@@ -1,4 +1,4 @@
-//===-- StrToNumCheck.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.
@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-#include "StrToNumCheck.h"
+#include 

[clang-tools-extra] [clang-tidy] Add new alias 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c' (PR #157285)

2025-09-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Baranov Victor (vbvictor)


Changes

My goal is to place all implementation of `cert` checks into `bugprone` or 
other modules. It's hard for the user to understand what `cert-err34-c` means, 
so we should always have human-readable alias for `cert` checks.

Essentially, this renaming can give "free checks" because people tend to just 
[disable cert 
checks](https://github.com/search?q=-cert-*+path%3A**%2F.clang-tidy&type=code),
 despite most of them are regular `bugprone` checks that can give benefits for 
every project.

---

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


13 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+3) 
- (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1) 
- (renamed) 
clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
 (+8-6) 
- (added) 
clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.h 
(+35) 
- (modified) clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp (+4-2) 
- (modified) clang-tools-extra/clang-tidy/cert/CMakeLists.txt (-1) 
- (removed) clang-tools-extra/clang-tidy/cert/StrToNumCheck.h (-31) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst
 (+31) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/cert/err34-c.rst (+5-23) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+3-2) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-string-to-number-conversion.c
 (+17-17) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-string-to-number-conversion.cpp
 (+7-7) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 824ebdfbd00dc..fe261e729539c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -89,6 +89,7 @@
 #include "ThrowKeywordMissingCheck.h"
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
+#include "UncheckedStringToNumberConversionCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
@@ -261,6 +262,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-too-small-loop-variable");
 CheckFactories.registerCheck(
 "bugprone-unchecked-optional-access");
+CheckFactories.registerCheck(
+"bugprone-unchecked-string-to-number-conversion");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 59928e5e47a09..46bc8efd44bc5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -91,6 +91,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   ThrowKeywordMissingCheck.cpp
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
+  UncheckedStringToNumberConversionCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
similarity index 95%
rename from clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
rename to 
clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
index 95536bb1cfdb2..d1e7b895f9a35 100644
--- a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
@@ -1,4 +1,4 @@
-//===-- StrToNumCheck.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.
@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-#include "StrToNumCheck.h"
+#include "UncheckedStringToNumberConversionCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/FormatString.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -15,9 +15,10 @@
 
 using namespace clang::ast_matchers;
 
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
 
-void StrToNumCheck::registerMatchers(MatchFinder *Finder) {
+void UncheckedStringToNumberConversionCheck::registerMatchers(
+MatchFinder *Finder) {
   // Match any function call to the C

[clang-tools-extra] dc81dcf - [clang-tidy] Add new '-hide-progress' option to tidy-scripts for suppressing progress information (#154416)

2025-09-06 Thread via cfe-commits

Author: Baranov Victor
Date: 2025-09-06T19:36:22+03:00
New Revision: dc81dcf8b40870e8917c01d58b7eb1f82caa795e

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

LOG: [clang-tidy] Add new '-hide-progress' option to tidy-scripts for 
suppressing progress information (#154416)

Progress information bloated output, now `run-clang-tidy` emits **only**
actual diagnostics, which makes reading its output significantly easier.

-

Co-authored-by: Victor Chernyakin 

Added: 

clang-tools-extra/test/clang-tidy/infrastructure/hide-progress-flag-scripts.cpp

Modified: 
clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
index d7899e0a18d0c..b4b4648e765cf 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
@@ -258,6 +258,11 @@ def main():
 help="Upgrades clang-tidy warnings to errors. Same format as 
'-checks'.",
 default="",
 )
+parser.add_argument(
+"-hide-progress",
+action="store_true",
+help="Hide progress",
+)
 
 clang_tidy_args = []
 argv = sys.argv[1:]
@@ -312,7 +317,8 @@ def main():
 if max_task_count == 0:
 max_task_count = multiprocessing.cpu_count()
 max_task_count = min(len(lines_by_file), max_task_count)
-print(f"Running clang-tidy in {max_task_count} threads...")
+if not args.hide_progress:
+print(f"Running clang-tidy in {max_task_count} threads...")
 
 combine_fixes = False
 export_fixes_dir = None
@@ -408,7 +414,8 @@ def main():
 return_code = 1
 
 if combine_fixes:
-print("Writing fixes to " + args.export_fixes + " ...")
+if not args.hide_progress:
+print(f"Writing fixes to {args.export_fixes} ...")
 try:
 merge_replacement_files(export_fixes_dir, args.export_fixes)
 except:

diff  --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index 670e0a2c7678a..a722e20a81c68 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -576,6 +576,11 @@ async def main() -> None:
 action="store_true",
 help="Enable per-check timing profiles, and print a report",
 )
+parser.add_argument(
+"-hide-progress",
+action="store_true",
+help="Hide progress",
+)
 args = parser.parse_args()
 
 db_path = "compile_commands.json"
@@ -681,13 +686,11 @@ async def main() -> None:
 file_name_re = re.compile("|".join(args.files))
 files = {f for f in files if file_name_re.search(f)}
 
-print(
-f"Running clang-tidy in {max_task} threads for",
-len(files),
-"files out of",
-number_files_in_database,
-"in compilation database ...",
-)
+if not args.hide_progress:
+print(
+f"Running clang-tidy in {max_task} threads for {len(files)} files "
+f"out of {number_files_in_database} in compilation database ..."
+)
 
 returncode = 0
 semaphore = asyncio.Semaphore(max_task)
@@ -716,13 +719,15 @@ async def main() -> None:
 result.stderr += f"{result.filename}: terminated by signal 
{-result.returncode}\n"
 progress = f"[{i + 1: >{len(f'{len(files)}')}}/{len(files)}]"
 runtime = f"[{result.elapsed:.1f}s]"
-print(f"{progress}{runtime} {' '.join(result.invocation)}")
+if not args.hide_progress:
+print(f"{progress}{runtime} {' '.join(result.invocation)}")
 if result.stdout:
 print(result.stdout, end=("" if result.stderr else "\n"))
 if result.stderr:
 print(result.stderr)
 except asyncio.CancelledError:
-print("\nCtrl-C detected, goodbye.")
+if not args.hide_progress:
+print("\nCtrl-C detected, goodbye.")
 for task in tasks:
 task.cancel()
 if delete_fixes_dir:
@@ -742,7 +747,8 @@ async def main() -> None:
 print("No profiling data found.")
 
 if combine_fixes:
-print(f"Writing fixes to {args.export_fixes} ...")
+if not args.hide_progress:
+print(f"Writing fixes to {args.export_fixes} ...")
 try:
 assert export_fixes_dir
 merge_replacement_files(export_fixes_dir, args.export_fixes)
@@ -752,7 +758,8 @@ async def main() -> None:
 returncode = 1
 
 if args.fix:
-

[clang] Revert "[clang][Modules] Reporting Errors for Duplicating Link Declar… (PR #157154)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-hwasan` running on `sanitizer-buildbot12` 
while building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:74:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 90425 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: lld :: MachO/read-workers.s (90170 of 90425)
 TEST 'lld :: MachO/read-workers.s' FAILED 

Exit Code: -6

Command Output (stdout):
--
# RUN: at line 2
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-mc
 -filetype=obj -triple=x86_64-apple-darwin 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/lld/test/MachO/read-workers.s
 -o 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/lld/test/MachO/Output/read-workers.s.tmp.o
# executed command: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-mc
 -filetype=obj -triple=x86_64-apple-darwin 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/lld/test/MachO/read-workers.s
 -o 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/lld/test/MachO/Output/read-workers.s.tmp.o
# note: command had no output on stdout or stderr
# RUN: at line 5
ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk
 -lSystem -fatal_warnings --read-workers=0 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/lld/test/MachO/Output/read-workers.s.tmp.o
 -o /dev/null
# executed command: ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 
-syslibroot 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk
 -lSystem -fatal_warnings --read-workers=0 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/lld/test/MachO/Output/read-workers.s.tmp.o
 -o /dev/null
# note: command had no output on stdout or stderr
# RUN: at line 6
ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk
 -lSystem -fatal_warnings --read-workers=1 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/lld/test/MachO/Output/read-workers.s.tmp.o
 -o /dev/null
# executed command: ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 
-syslibroot 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk
 -lSystem -fatal_warnings --read-workers=1 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/tools/lld/test/MachO/Output/read-workers.s.tmp.o
 -o /dev/null
# note: command had no 

[clang-tools-extra] [clang-tidy] Add new alias 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c' (PR #157285)

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


@@ -0,0 +1,35 @@
+//===--===//

vbvictor wrote:

This file is mostly copypaste from `StrToNumCheck.h`

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


[clang] [NFC] Change const char* to StringRef (PR #154179)

2025-09-06 Thread Chris B via cfe-commits

https://github.com/llvm-beanz updated 
https://github.com/llvm/llvm-project/pull/154179

>From c7387c59564afc43e5371f604f3d31bd27783c78 Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Mon, 18 Aug 2025 13:08:01 -0500
Subject: [PATCH 1/2] [NFC] Change const char* to StringRef

This API takes a const char* with a default nullptr value and immdiately
passes it down to an API taking a StringRef. All of the places this is
called from are either using compile time string literals, the default
argument, or string objects that have known length. Discarding the
length known from a calling API to just have to strlen it to call the
next layer down that requires a StringRef is a bit silly, so this change
updates CodeGenModule::GetAddrOfConstantCString to use StringRef instead
of const char* for the GlobalName parameter.

It might be worth also replacing the first parameter with an llvm ADT
type that avoids allocation, but that change would have wider impact so
we should consider it separately.
---
 clang/lib/CodeGen/CGCUDANV.cpp  | 2 +-
 clang/lib/CodeGen/CGExpr.cpp| 4 ++--
 clang/lib/CodeGen/CGObjCGNU.cpp | 2 +-
 clang/lib/CodeGen/CodeGenModule.cpp | 5 +
 clang/lib/CodeGen/CodeGenModule.h   | 2 +-
 5 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 5090a0559eab2..cb16fe1b36c68 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -94,7 +94,7 @@ class CGNVCUDARuntime : public CGCUDARuntime {
   /// where the C code specifies const char*.
   llvm::Constant *makeConstantString(const std::string &Str,
  const std::string &Name = "") {
-return CGM.GetAddrOfConstantCString(Str, Name.c_str()).getPointer();
+return CGM.GetAddrOfConstantCString(Str, Name).getPointer();
   }
 
   /// Helper function which generates an initialized constant array from Str,
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 26fba751e6f9d..eb61e16ea4b06 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3513,11 +3513,11 @@ LValue CodeGenFunction::EmitPredefinedLValue(const 
PredefinedExpr *E) {
   CGM.getCXXABI().getMangleContext().getBlockId(BD, true);
   if (Discriminator)
 Name += "_" + Twine(Discriminator + 1).str();
-  auto C = CGM.GetAddrOfConstantCString(Name, GVName.c_str());
+  auto C = CGM.GetAddrOfConstantCString(Name, GVName);
   return MakeAddrLValue(C, E->getType(), AlignmentSource::Decl);
 } else {
   auto C =
-  CGM.GetAddrOfConstantCString(std::string(FnName), GVName.c_str());
+  CGM.GetAddrOfConstantCString(std::string(FnName), GVName);
   return MakeAddrLValue(C, E->getType(), AlignmentSource::Decl);
 }
   }
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index e4147de8fc639..06643d4bdc211 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -195,7 +195,7 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Helper function that generates a constant string and returns a pointer to
   /// the start of the string.  The result of this function can be used 
anywhere
   /// where the C code specifies const char*.
-  llvm::Constant *MakeConstantString(StringRef Str, const char *Name = "") {
+  llvm::Constant *MakeConstantString(StringRef Str, StringRef Name = "") {
 ConstantAddress Array =
 CGM.GetAddrOfConstantCString(std::string(Str), Name);
 return Array.getPointer();
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index f1ddaa875f3e4..d9c52c0849400 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6927,7 +6927,7 @@ 
CodeGenModule::GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *E) {
 /// the literal and a terminating '\0' character.
 /// The result has pointer to array type.
 ConstantAddress CodeGenModule::GetAddrOfConstantCString(
-const std::string &Str, const char *GlobalName) {
+const std::string &Str, StringRef GlobalName) {
   StringRef StrWithNull(Str.c_str(), Str.size() + 1);
   CharUnits Alignment = getContext().getAlignOfGlobalVarInChars(
   getContext().CharTy, /*VD=*/nullptr);
@@ -6947,9 +6947,6 @@ ConstantAddress CodeGenModule::GetAddrOfConstantCString(
 }
   }
 
-  // Get the default prefix if a name wasn't specified.
-  if (!GlobalName)
-GlobalName = ".str";
   // Create a global variable for this.
   auto GV = GenerateStringLiteral(C, llvm::GlobalValue::PrivateLinkage, *this,
   GlobalName, Alignment);
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index b4b3a17662045..86e6be48a044d 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1188,7 +1188,7 @@ class CodeGenModule : public CodeGenTypeCache {
   /// created).
   Con

[clang] [llvm] Make sanitizer special case list slash-agnostic (PR #149886)

2025-09-06 Thread James Y Knight via cfe-commits


@@ -231,6 +233,10 @@ bool GlobPattern::SubGlobPattern::match(StringRef Str) 
const {
 ++S;
 continue;
   }
+} else if (IsSlashAgnostic && *P == '/' && (*S == '/' || *S == '\\')) {

jyknight wrote:

`*S == '/'` is redundant here and can be removed; it'd be handled in the next 
clause anyhow.

For completeness, it may make sense on windows to also match `\\` against `/`. 
Then we can document as "now treats forward and backward slashes as equivalent 
when matching paths"

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


[clang] [llvm] Make sanitizer special case list slash-agnostic (PR #149886)

2025-09-06 Thread James Y Knight via cfe-commits


@@ -57,9 +59,12 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, 
unsigned LineNumber,
   auto Glob = std::make_unique();
   Glob->Name = Pattern.str();
   Glob->LineNo = LineNumber;
+  // Backslashes are valid in posix-style filenames.
+  bool IsSlashAgnostic = Triple(sys::getDefaultTargetTriple()).isOSWindows();

jyknight wrote:

Because we're talking about source files being read by the compiler, the 
interpretation of paths should be based on whether the compiler is built for 
and running on windows -- not based on what target the compiler defaults to 
build code for. 

You could detect that with `#ifdef _WIN32`. But even better is to use the 
abstraction `llvm::sys::path::is_style_windows(llvm::sys::path::native)`, which 
does the same, but in a more self-documenting manner.

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


[clang] [llvm] Make sanitizer special case list slash-agnostic (PR #149886)

2025-09-06 Thread James Y Knight via cfe-commits


@@ -57,9 +59,12 @@ Error SpecialCaseList::Matcher::insert(StringRef Pattern, 
unsigned LineNumber,
   auto Glob = std::make_unique();
   Glob->Name = Pattern.str();
   Glob->LineNo = LineNumber;
+  // Backslashes are valid in posix-style filenames.
+  bool IsSlashAgnostic = Triple(sys::getDefaultTargetTriple()).isOSWindows();
   // We must be sure to use the string in `Glob` rather than the provided
   // reference which could be destroyed before match() is called
-  if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024)
+  if (auto Err = GlobPattern::create(Glob->Name, /*MaxSubPatterns=*/1024,
+ /*IsSlashAgnostic=*/IsSlashAgnostic)

jyknight wrote:

Oh...also, we should really only apply special handling to filenames, not other 
kinds of strings. Perhaps "SpecialCaseList::inSection" needs a bool for whether 
to use filename matching semantics?

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


[clang] [Headers][X86] Allow AVX512 integer min/max mask/maskz variants intrinsics to be used in constexpr (PR #156901)

2025-09-06 Thread Bhasawut Singhaphan via cfe-commits

markbhasawut wrote:

Thank you for reviewing! @RKSimon 

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


[clang-tools-extra] [clang-tidy] Add new alias 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c' (PR #157285)

2025-09-06 Thread via cfe-commits


@@ -166,6 +166,10 @@ New checks
 New check aliases
 ^
 
+- New alias :doc:`bugprone-unchecked-string-to-number-conversion

EugeneZelenko wrote:

Opposite is true according to implementation. May be entry in renamed checks?

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


[clang-tools-extra] [clang-tidy] Add new alias 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c' (PR #157285)

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

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


[clang-tools-extra] [clang-tidy] Add new alias 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c' (PR #157285)

2025-09-06 Thread via cfe-commits


@@ -0,0 +1,31 @@
+.. title:: clang-tidy - bugprone-unchecked-string-to-number-conversion
+
+bugprone-unchecked-string-to-number-conversion
+=

EugeneZelenko wrote:

```suggestion
bugprone-unchecked-string-to-number-conversion
==
```

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


[clang] [llvm] [clang] Polymorphic Cleanup type is moved despite not being POD types (PR #156607)

2025-09-06 Thread Oliver Hunt via cfe-commits

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


[clang-tools-extra] Add bugprone-loop-variable-copied-then-modified clang-tidy check. (PR #157213)

2025-09-06 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,80 @@
+
+//===--===//
+//
+// 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 "LoopVariableCopiedThenModifiedCheck.h"
+#include "../utils/Matchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
+#include "clang/Basic/Diagnostic.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void LoopVariableCopiedThenModifiedCheck::registerMatchers(MatchFinder 
*Finder) {
+  auto HasReferenceOrPointerTypeOrIsAllowed = hasType(qualType(
+  unless(hasCanonicalType(anyOf(referenceType(), pointerType());
+  auto IteratorReturnsValueType = cxxOperatorCallExpr(
+  hasOverloadedOperatorName("*"),
+  callee(
+  cxxMethodDecl(returns(unless(hasCanonicalType(referenceType()));
+  auto NotConstructedByCopy = cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(unless(isCopyConstructor();
+  auto ConstructedByConversion = 
cxxMemberCallExpr(callee(cxxConversionDecl()));
+  auto LoopVar =
+  varDecl(HasReferenceOrPointerTypeOrIsAllowed,
+  unless(hasInitializer(expr(hasDescendant(expr(
+  anyOf(materializeTemporaryExpr(), IteratorReturnsValueType,
+NotConstructedByCopy, ConstructedByConversion)));
+  Finder->addMatcher(
+  traverse(TK_AsIs,
+   cxxForRangeStmt(hasLoopVariable(LoopVar.bind("loopVar")))
+   .bind("forRange")),

zwuis wrote:

`TK_AsIs` is the default traverse mode. We can write `Matcher` instead of 
`traverse(TK_AsIs, Matcher)`.

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


[clang-tools-extra] Add bugprone-loop-variable-copied-then-modified clang-tidy check. (PR #157213)

2025-09-06 Thread via cfe-commits


@@ -0,0 +1,47 @@
+.. title:: clang-tidy - bugprone-loop-variable-copied-then-modified
+
+bugprone-loop-variable-copied-then-modified
+===
+
+Warns when a loop variable is copied and subsequently modified.
+
+This pattern is considered bugprone because, frequently, programmers do not
+realize that they are modifying a *copy* rather than an underlying value,
+resulting in subtly erroneous code.
+
+For instance, the following code attempts to null out a value in a map, but 
only
+succeeds in 
+
+.. code-block:: c++
+
+  for (auto target : target_map) {
+target.value = nullptr;
+  }
+
+The programmer is likely to have intended this code instead:
+
+.. code-block:: c++
+
+  for (const auto& target : target_map) {
+target.value = nullptr;
+  }
+
+This warning can be suppressed in one of two ways:
+  - In cases where the programmer did not intend to create a copy, they can
+convert the loop variable to a const reference. A FixIt message will

EugeneZelenko wrote:

```suggestion
convert the loop variable to a ``const`` reference. A fix-it message will
```

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


[clang-tools-extra] Add bugprone-loop-variable-copied-then-modified clang-tidy check. (PR #157213)

2025-09-06 Thread via cfe-commits


@@ -0,0 +1,47 @@
+.. title:: clang-tidy - bugprone-loop-variable-copied-then-modified
+
+bugprone-loop-variable-copied-then-modified
+===
+
+Warns when a loop variable is copied and subsequently modified.
+
+This pattern is considered bugprone because, frequently, programmers do not
+realize that they are modifying a *copy* rather than an underlying value,
+resulting in subtly erroneous code.
+
+For instance, the following code attempts to null out a value in a map, but 
only
+succeeds in 
+
+.. code-block:: c++
+
+  for (auto target : target_map) {
+target.value = nullptr;
+  }
+
+The programmer is likely to have intended this code instead:
+
+.. code-block:: c++
+
+  for (const auto& target : target_map) {
+target.value = nullptr;
+  }
+
+This warning can be suppressed in one of two ways:
+  - In cases where the programmer did not intend to create a copy, they can
+convert the loop variable to a const reference. A FixIt message will
+provide a naive suggestion of how to achieve this, which works in most
+cases.
+  - In cases where the intent is in fact to modify a copy, they may perform the
+copy inside the body of the loop, and perform whatever operations they like
+on that copy.
+
+This is a conservative check: in cases where it cannot be determined at compile
+time whether or not a particular function modifies the variable, it assumes a
+modification has ocurred and warns accordingly. However, in such cases, the
+warning will still be suppressed by doing one of the actions described above.
+
+.. option:: IgnoreInexpensiveVariables
+
+   When `true`, this check will only alert on types that are expensive to copy.
+   This will lead to fewer "false" positives, but will also overlook some
+   instances where there may be an actual bug.

EugeneZelenko wrote:

Please add default value.

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


[clang] f58844b - [clang] Move two flags from EvalInfo to State (#157046)

2025-09-06 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-09-06T06:16:15+02:00
New Revision: f58844b6b6a3b596e116ef669efc8c8aa72cc737

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

LOG: [clang] Move two flags from EvalInfo to State (#157046)

Instead of relaying from InterpState to the parent state (which is an
EvalInfo), just save the variables in State instead, so both subclasses
have access to it.

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpState.cpp
clang/lib/AST/ByteCode/InterpState.h
clang/lib/AST/ByteCode/State.h
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpState.cpp 
b/clang/lib/AST/ByteCode/InterpState.cpp
index 4bafb89741857..6b0e72095dc55 100644
--- a/clang/lib/AST/ByteCode/InterpState.cpp
+++ b/clang/lib/AST/ByteCode/InterpState.cpp
@@ -20,13 +20,21 @@ using namespace clang::interp;
 InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
  Context &Ctx, SourceMapper *M)
 : Parent(Parent), M(M), P(P), Stk(Stk), Ctx(Ctx), BottomFrame(*this),
-  Current(&BottomFrame) {}
+  Current(&BottomFrame) {
+  CheckingPotentialConstantExpression =
+  Parent.CheckingPotentialConstantExpression;
+  CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
+}
 
 InterpState::InterpState(State &Parent, Program &P, InterpStack &Stk,
  Context &Ctx, const Function *Func)
 : Parent(Parent), M(nullptr), P(P), Stk(Stk), Ctx(Ctx),
   BottomFrame(*this, Func, nullptr, CodePtr(), Func->getArgSize()),
-  Current(&BottomFrame) {}
+  Current(&BottomFrame) {
+  CheckingPotentialConstantExpression =
+  Parent.CheckingPotentialConstantExpression;
+  CheckingForUndefinedBehavior = Parent.CheckingForUndefinedBehavior;
+}
 
 bool InterpState::inConstantContext() const {
   if (ConstantContextOverride)

diff  --git a/clang/lib/AST/ByteCode/InterpState.h 
b/clang/lib/AST/ByteCode/InterpState.h
index 1e4c0701723c6..e4d1dc64ff01b 100644
--- a/clang/lib/AST/ByteCode/InterpState.h
+++ b/clang/lib/AST/ByteCode/InterpState.h
@@ -70,18 +70,12 @@ class InterpState final : public State, public SourceMapper 
{
   ASTContext &getASTContext() const override { return Parent.getASTContext(); }
 
   // Forward status checks and updates to the walker.
-  bool checkingForUndefinedBehavior() const override {
-return Parent.checkingForUndefinedBehavior();
-  }
   bool keepEvaluatingAfterFailure() const override {
 return Parent.keepEvaluatingAfterFailure();
   }
   bool keepEvaluatingAfterSideEffect() const override {
 return Parent.keepEvaluatingAfterSideEffect();
   }
-  bool checkingPotentialConstantExpression() const override {
-return Parent.checkingPotentialConstantExpression();
-  }
   bool noteUndefinedBehavior() override {
 return Parent.noteUndefinedBehavior();
   }

diff  --git a/clang/lib/AST/ByteCode/State.h b/clang/lib/AST/ByteCode/State.h
index 6fc33222ac956..387ce396a7235 100644
--- a/clang/lib/AST/ByteCode/State.h
+++ b/clang/lib/AST/ByteCode/State.h
@@ -59,8 +59,6 @@ class State {
 public:
   virtual ~State();
 
-  virtual bool checkingForUndefinedBehavior() const = 0;
-  virtual bool checkingPotentialConstantExpression() const = 0;
   virtual bool noteUndefinedBehavior() = 0;
   virtual bool keepEvaluatingAfterFailure() const = 0;
   virtual bool keepEvaluatingAfterSideEffect() const = 0;
@@ -75,6 +73,16 @@ class State {
   virtual unsigned getCallStackDepth() = 0;
   virtual bool noteSideEffect() = 0;
 
+  /// Are we checking whether the expression is a potential constant
+  /// expression?
+  bool checkingPotentialConstantExpression() const {
+return CheckingPotentialConstantExpression;
+  }
+  /// Are we checking an expression for overflow?
+  bool checkingForUndefinedBehavior() const {
+return CheckingForUndefinedBehavior;
+  }
+
 public:
   State() = default;
   /// Diagnose that the evaluation could not be folded (FF => FoldFailure)
@@ -128,6 +136,19 @@ class State {
   /// constant value.
   bool InConstantContext = false;
 
+  /// Whether we're checking that an expression is a potential constant
+  /// expression. If so, do not fail on constructs that could become constant
+  /// later on (such as a use of an undefined global).
+  bool CheckingPotentialConstantExpression = false;
+
+  /// Whether we're checking for an expression that has undefined behavior.
+  /// If so, we will produce warnings if we encounter an operation that is
+  /// always undefined.
+  ///
+  /// Note that we still need to evaluate the expression normally when this
+  /// is set; this is used when evaluating ICEs in C.
+  bool CheckingForUndefinedBehavior = false;
+
 private:
   void addCallStack(unsigned Limit);
 

diff  --git a/clang/lib/AST/Expr

[clang] 9da02e7 - Revert "[clang][Modules] Reporting Errors for Duplicating Link Declar… (#157154)

2025-09-06 Thread via cfe-commits

Author: Qiongsi Wu
Date: 2025-09-06T08:50:21-07:00
New Revision: 9da02e7521da1d2024fbac62b5d9995a1edefc7a

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

LOG: Revert "[clang][Modules] Reporting Errors for Duplicating Link Declar… 
(#157154)

…ations in `modulemap`s (#148959)"

This reverts commit 538e9e8ebd09233b3900ed2dfd23e4e1ca5c9fc0 for two
reasons.

1. Link decls in submodules can make sense even if the submodule is not
explicit. We need to review the error check. This PR reverts the check
so we still allow link decls in submodules.
2. It is not a fatal error to have duplicating link decls. The linker
deduplicates them anyways.

rdar://159467837

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/ModuleMapFile.cpp

Removed: 
clang/test/ClangScanDeps/link-libraries-diag-dup.c



diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index c03c4033cd3a6..c7fe6e1db6d1f 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -912,11 +912,6 @@ def err_mmap_nested_submodule_id : Error<
   "qualified module name can only be used to define modules at the top level">;
 def err_mmap_expected_feature : Error<"expected a feature name">;
 def err_mmap_expected_attribute : Error<"expected an attribute name">;
-def warn_mmap_link_redeclaration : Warning<"redeclaration of link library 
'%0'">,
-  InGroup>, DefaultError;
-def note_mmap_prev_link_declaration : Note<"previously declared here">;
-def err_mmap_submodule_link_decl
-: Error<"link declaration is not allowed in submodules">;
 def warn_mmap_unknown_attribute : Warning<"unknown attribute '%0'">,
   InGroup;
 def warn_mmap_mismatched_private_submodule : Warning<

diff  --git a/clang/lib/Lex/ModuleMapFile.cpp b/clang/lib/Lex/ModuleMapFile.cpp
index f0cd9d2bee82a..183e919d14c22 100644
--- a/clang/lib/Lex/ModuleMapFile.cpp
+++ b/clang/lib/Lex/ModuleMapFile.cpp
@@ -118,8 +118,7 @@ struct ModuleMapFileParser {
   std::optional parseExcludeDecl(clang::SourceLocation 
LeadingLoc);
   std::optional
   parseUmbrellaDirDecl(SourceLocation UmbrellaLoc);
-  std::optional
-  parseLinkDecl(llvm::StringMap &SeenLinkDecl, bool Allowed);
+  std::optional parseLinkDecl();
 
   SourceLocation consumeToken();
   void skipUntil(MMToken::TokenKind K);
@@ -326,7 +325,6 @@ std::optional 
ModuleMapFileParser::parseModuleDecl(bool TopLevel) {
   SourceLocation LBraceLoc = consumeToken();
 
   bool Done = false;
-  llvm::StringMap SeenLinkDecl;
   do {
 std::optional SubDecl;
 switch (Tok.Kind) {
@@ -407,9 +405,7 @@ std::optional 
ModuleMapFileParser::parseModuleDecl(bool TopLevel) {
   break;
 
 case MMToken::LinkKeyword:
-  // Link decls are only allowed in top level modules or explicit
-  // submodules.
-  SubDecl = parseLinkDecl(SeenLinkDecl, TopLevel || MDecl.Explicit);
+  SubDecl = parseLinkDecl();
   break;
 
 default:
@@ -826,8 +822,7 @@ 
ModuleMapFileParser::parseUmbrellaDirDecl(clang::SourceLocation UmbrellaLoc) {
 ///
 ///   module-declaration:
 /// 'link' 'framework'[opt] string-literal
-std::optional ModuleMapFileParser::parseLinkDecl(
-llvm::StringMap &SeenLinkDecl, bool Allowed) {
+std::optional ModuleMapFileParser::parseLinkDecl() {
   assert(Tok.is(MMToken::LinkKeyword));
   LinkDecl LD;
   LD.Location = consumeToken();
@@ -843,33 +838,12 @@ std::optional 
ModuleMapFileParser::parseLinkDecl(
   if (!Tok.is(MMToken::StringLiteral)) {
 Diags.Report(Tok.getLocation(), diag::err_mmap_expected_library_name)
 << LD.Framework << SourceRange(LD.Location);
-consumeToken();
 HadError = true;
 return std::nullopt;
   }
 
-  StringRef Library = Tok.getString();
-
-  LD.Library = Library;
+  LD.Library = Tok.getString();
   consumeToken();
-
-  // Make sure we eat all the tokens when we report the errors so parsing
-  // can continue.
-  if (!Allowed) {
-Diags.Report(LD.Location, diag::err_mmap_submodule_link_decl);
-HadError = true;
-return std::nullopt;
-  }
-
-  auto [It, Inserted] =
-  SeenLinkDecl.insert(std::make_pair(Library, LD.Location));
-  if (!Inserted) {
-Diags.Report(LD.Location, diag::warn_mmap_link_redeclaration) << Library;
-Diags.Report(It->second, diag::note_mmap_prev_link_declaration);
-HadError = true;
-return std::nullopt;
-  }
-
   return std::move(LD);
 }
 

diff  --git a/clang/test/ClangScanDeps/link-libraries-diag-dup.c 
b/clang/test/ClangScanDeps/link-libraries-diag-dup.c
deleted file mode 100644
index e6612ca7bd216..0
--- a/clang/test/ClangScanDeps/link-libraries-diag-dup.c
+++ /dev/null
@@ -1,57 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir %t
-// RUN: split-

[clang] Revert "[clang][Modules] Reporting Errors for Duplicating Link Declar… (PR #157154)

2025-09-06 Thread Qiongsi Wu via cfe-commits

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


[clang] [llvm] Enable fexec-charset option (PR #138895)

2025-09-06 Thread Hubert Tong via cfe-commits

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


[clang] [Headers][X86] Add constexpr support for some AVX[512] intrinsics. (PR #157260)

2025-09-06 Thread via cfe-commits

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


[clang] [clang] Detect int-to-float narrowing when the back-conversion is unspecified (PR #157174)

2025-09-06 Thread Yanzuo Liu via cfe-commits


@@ -308,6 +308,8 @@ Bug Fixes in This Version
 - Builtin elementwise operators now accept vector arguments that have different
   qualifiers on their elements. For example, vector of 4 ``const float`` values
   and vector of 4 ``float`` values. (#GH155405)
+- Fix the check for narrowing int-to-float conversions, so that they are 
detected in
+  cases where converting the float back to an integer is undefined behaviour.

zwuis wrote:

Add reference to the issue fixed by this patch like other entries.

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


[clang] [clang] Detect int-to-float narrowing when the back-conversion is unspecified (PR #157174)

2025-09-06 Thread via cfe-commits

https://github.com/camc updated https://github.com/llvm/llvm-project/pull/157174

>From 73696f81166f958e212c5ea314528791c5201565 Mon Sep 17 00:00:00 2001
From: camc <69519329+c...@users.noreply.github.com>
Date: Fri, 5 Sep 2025 20:47:06 +
Subject: [PATCH 1/2] [clang] Detect int-to-float narrowing when backconversion
 is unspecified

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaOverload.cpp| 10 ++
 .../test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp |  2 ++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8720262c33959..bd1f536f33404 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -308,6 +308,8 @@ Bug Fixes in This Version
 - Builtin elementwise operators now accept vector arguments that have different
   qualifiers on their elements. For example, vector of 4 ``const float`` values
   and vector of 4 ``float`` values. (#GH155405)
+- Fix the check for narrowing int-to-float conversions, so that they are 
detected in
+  cases where converting the float back to an integer is undefined behaviour.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 14fa8478fe317..71d23906f2b17 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -412,10 +412,12 @@ NarrowingKind 
StandardConversionSequence::getNarrowingKind(
 // And back.
 llvm::APSInt ConvertedValue = *IntConstantValue;
 bool ignored;
-Result.convertToInteger(ConvertedValue,
-llvm::APFloat::rmTowardZero, &ignored);
-// If the resulting value is different, this was a narrowing 
conversion.
-if (*IntConstantValue != ConvertedValue) {
+llvm::APFloat::opStatus fs = Result.convertToInteger(
+ConvertedValue, llvm::APFloat::rmTowardZero, &ignored);
+// If the converted-back integer has unspecified value, or if the
+// resulting value is different, this was a narrowing conversion.
+if (fs == llvm::APFloat::opInvalidOp ||
+*IntConstantValue != ConvertedValue) {
   ConstantValue = APValue(*IntConstantValue);
   ConstantType = Initializer->getType();
   return NK_Constant_Narrowing;
diff --git a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp 
b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
index 2bceb3e267790..5bb4708f869f8 100644
--- a/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
@@ -137,6 +137,8 @@ void int_to_float() {
   Agg f7 = {12345678};  // OK (exactly fits in a float)
   Agg f8 = {EnumVal};  // OK
   Agg f9 = {123456789};  // expected-error {{ cannot be narrowed }} 
expected-note {{silence}}
+  Agg f10 = {2147483646}; // expected-error {{constant expression 
evaluates to 2147483646 which cannot be narrowed to type 'float'}} 
expected-note {{silence}}
+  Agg f11 = {2147483647}; // expected-error {{constant expression 
evaluates to 2147483647 which cannot be narrowed to type 'float'}} 
expected-note {{silence}}
 
   Agg ce1 = { Convert(123456789) }; // expected-error {{constant 
expression evaluates to 123456789 which cannot be narrowed to type 'float'}} 
expected-note {{silence}}
   Agg ce2 = { ConvertVar() }; // expected-error 
{{non-constant-expression cannot be narrowed from type 'long long' to 
'double'}} expected-note {{silence}}

>From fbdca7670295a662c81a76fb74406e7be338d20c Mon Sep 17 00:00:00 2001
From: camc <69519329+c...@users.noreply.github.com>
Date: Sat, 6 Sep 2025 13:12:30 +
Subject: [PATCH 2/2] Address comments

---
 clang/docs/ReleaseNotes.rst | 2 +-
 clang/lib/Sema/SemaOverload.cpp | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bd1f536f33404..dc5f8c59fddc8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -309,7 +309,7 @@ Bug Fixes in This Version
   qualifiers on their elements. For example, vector of 4 ``const float`` values
   and vector of 4 ``float`` values. (#GH155405)
 - Fix the check for narrowing int-to-float conversions, so that they are 
detected in
-  cases where converting the float back to an integer is undefined behaviour.
+  cases where converting the float back to an integer is undefined behaviour 
(#GH157067).
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 71d23906f2b17..941542247e240 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -412,11 +412,11 @@ NarrowingKind 
StandardConversionSequence::getNarrowingKind(
 // And back.
 llvm::APSInt ConvertedValue = *IntConstantValue;
   

[clang] [llvm] Enable fexec-charset option (PR #138895)

2025-09-06 Thread Hubert Tong via cfe-commits


@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple s390x-none-zos -fexec-charset 
IBM-1047 -o - | FileCheck %s
+// RUN: %clang %s -emit-llvm -S -target s390x-ibm-zos -o - | FileCheck %s
+
+const char *UpperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+// CHECK: 
c"\C1\C2\C3\C4\C5\C6\C7\C8\C9\D1\D2\D3\D4\D5\D6\D7\D8\D9\E2\E3\E4\E5\E6\E7\E8\E9\00"
+
+const char *LowerCaseLetters = "abcdefghijklmnopqrstuvwxyz";
+//CHECK: 
c"\81\82\83\84\85\86\87\88\89\91\92\93\94\95\96\97\98\99\A2\A3\A4\A5\A6\A7\A8\A9\00"
+
+const char *Digits = "0123456789";
+// CHECK: c"\F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\00"
+
+const char *SpecialCharacters = " .<(+|&!$*);^-/,%%_>`:#@=";
+// CHECK: c"@KLMNOPZ[\\]^_`akllmnyz{|~\00"
+
+const char *EscapeCharacters = "\a\b\f\n\r\t\v\\\'\"\?";
+//CHECK: c"/\16\0C\15\0D\05\0B\E0}\7Fo\00"
+
+const char *InvalidEscape = "\y\z";
+//CHECK: c"oo\00"
+
+const char *HexCharacters = "\x12\x13\x14";
+//CHECK: c"\12\13\14\00"
+
+const char *OctalCharacters = "\141\142\143";
+//CHECK: c"abc\00"
+
+const char singleChar = 'a';

hubert-reinterpretcast wrote:

Shouldn't the single-char check use a value that uses more than one byte in the 
internal encoding (but is a single byte in the literal encoding)?

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


[clang-tools-extra] [clang-tidy] Rename 'cert-err34-c' to 'bugprone-unchecked-string-to-number-conversion' (PR #157285)

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

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

>From d94e0b12914e64a851f5a41cd5bbfb982ed285de Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Sat, 6 Sep 2025 19:16:53 +0300
Subject: [PATCH 1/2] [clang-tidy] Add new alias
 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c'

---
 .../bugprone/BugproneTidyModule.cpp   |  3 ++
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 ...ncheckedStringToNumberConversionCheck.cpp} | 14 
 .../UncheckedStringToNumberConversionCheck.h  | 35 +++
 .../clang-tidy/cert/CERTTidyModule.cpp|  6 ++--
 .../clang-tidy/cert/CMakeLists.txt|  1 -
 .../clang-tidy/cert/StrToNumCheck.h   | 31 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../unchecked-string-to-number-conversion.rst | 31 
 .../docs/clang-tidy/checks/cert/err34-c.rst   | 28 +++
 .../docs/clang-tidy/checks/list.rst   |  5 +--
 .../unchecked-string-to-number-conversion.c}  | 34 +-
 ...unchecked-string-to-number-conversion.cpp} | 14 
 13 files changed, 118 insertions(+), 89 deletions(-)
 rename clang-tools-extra/clang-tidy/{cert/StrToNumCheck.cpp => 
bugprone/UncheckedStringToNumberConversionCheck.cpp} (95%)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.h
 delete mode 100644 clang-tools-extra/clang-tidy/cert/StrToNumCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst
 rename clang-tools-extra/test/clang-tidy/checkers/{cert/err34-c.c => 
bugprone/unchecked-string-to-number-conversion.c} (77%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cert/err34-c.cpp => 
bugprone/unchecked-string-to-number-conversion.cpp} (77%)

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 824ebdfbd00dc..fe261e729539c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -89,6 +89,7 @@
 #include "ThrowKeywordMissingCheck.h"
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
+#include "UncheckedStringToNumberConversionCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
@@ -261,6 +262,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-too-small-loop-variable");
 CheckFactories.registerCheck(
 "bugprone-unchecked-optional-access");
+CheckFactories.registerCheck(
+"bugprone-unchecked-string-to-number-conversion");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 59928e5e47a09..46bc8efd44bc5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -91,6 +91,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   ThrowKeywordMissingCheck.cpp
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
+  UncheckedStringToNumberConversionCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
similarity index 95%
rename from clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
rename to 
clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
index 95536bb1cfdb2..d1e7b895f9a35 100644
--- a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
@@ -1,4 +1,4 @@
-//===-- StrToNumCheck.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.
@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-#include "StrToNumCheck.h"
+#include "UncheckedStringToNumberConversionCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/FormatString.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -15,9 +15,10 @@
 
 using namespace clang::ast_matchers;
 
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
 
-void StrToNumCheck::registerMatchers(MatchFinder *Finder) {
+void UncheckedStringToNumberConversionCheck::registerMatchers(
+MatchFinder *Finder) {
   // Match any function call to the C stand

[clang-tools-extra] [clang-tidy] Rename 'cert-err34-c' to 'bugprone-unchecked-string-to-number-conversion' (PR #157285)

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

vbvictor wrote:

> The commit message title can be a bit misleading, I read it as "create a new 
> alias in bugprone, which points to the cert check", but in reality the 
> intention is the other way around, alias from bugprone to cert.

Yeah, it was tricky to write. I hope "rename" would be more clear

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


[clang-tools-extra] [clang-tidy] Rename 'cert-err34-c' to 'bugprone-unchecked-string-to-number-conversion' (PR #157285)

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

vbvictor wrote:

FYI, I created a tracking-progress issue 
https://github.com/llvm/llvm-project/issues/157287.

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


[clang-tools-extra] [clang-tidy] Rename 'cert-err34-c' to 'bugprone-unchecked-string-to-number-conversion' (PR #157285)

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

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


[clang] [clang] Allow attributes in constructor argument list in pre-C++11 (PR #157300)

2025-09-06 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [clang] Allow attributes in constructor argument list in pre-C++11 (PR #157300)

2025-09-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (camc)


Changes

Resolves GH-156809

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


1 Files Affected:

- (modified) clang/lib/Parse/ParseDecl.cpp (+1-1) 


``diff
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 10355bb874762..62ea148701dee 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -6007,7 +6007,7 @@ bool Parser::isConstructorDeclarator(bool IsUnqualified, 
bool DeductionGuide,
 
   // A C++11 attribute here signals that we have a constructor, and is an
   // attribute on the first constructor parameter.
-  if (getLangOpts().CPlusPlus11 &&
+  if (getLangOpts().CPlusPlus &&
   isCXX11AttributeSpecifier(/*Disambiguate*/ false,
 /*OuterMightBeMessageSend*/ true) !=
   CXX11AttributeKind::NotAttributeSpecifier) {

``




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


[clang-tools-extra] [clang-tidy] Rename 'cert-err34-c' to 'bugprone-unchecked-string-to-number-conversion' (PR #157285)

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

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


[clang-tools-extra] [clang-tidy] Rename 'cert-err34-c' to 'bugprone-unchecked-string-to-number-conversion' (PR #157285)

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

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

>From d94e0b12914e64a851f5a41cd5bbfb982ed285de Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Sat, 6 Sep 2025 19:16:53 +0300
Subject: [PATCH 1/2] [clang-tidy] Add new alias
 'bugprone-unchecked-string-to-number-conversion' for 'cert-err34-c'

---
 .../bugprone/BugproneTidyModule.cpp   |  3 ++
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 ...ncheckedStringToNumberConversionCheck.cpp} | 14 
 .../UncheckedStringToNumberConversionCheck.h  | 35 +++
 .../clang-tidy/cert/CERTTidyModule.cpp|  6 ++--
 .../clang-tidy/cert/CMakeLists.txt|  1 -
 .../clang-tidy/cert/StrToNumCheck.h   | 31 
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../unchecked-string-to-number-conversion.rst | 31 
 .../docs/clang-tidy/checks/cert/err34-c.rst   | 28 +++
 .../docs/clang-tidy/checks/list.rst   |  5 +--
 .../unchecked-string-to-number-conversion.c}  | 34 +-
 ...unchecked-string-to-number-conversion.cpp} | 14 
 13 files changed, 118 insertions(+), 89 deletions(-)
 rename clang-tools-extra/clang-tidy/{cert/StrToNumCheck.cpp => 
bugprone/UncheckedStringToNumberConversionCheck.cpp} (95%)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.h
 delete mode 100644 clang-tools-extra/clang-tidy/cert/StrToNumCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/unchecked-string-to-number-conversion.rst
 rename clang-tools-extra/test/clang-tidy/checkers/{cert/err34-c.c => 
bugprone/unchecked-string-to-number-conversion.c} (77%)
 rename clang-tools-extra/test/clang-tidy/checkers/{cert/err34-c.cpp => 
bugprone/unchecked-string-to-number-conversion.cpp} (77%)

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 824ebdfbd00dc..fe261e729539c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -89,6 +89,7 @@
 #include "ThrowKeywordMissingCheck.h"
 #include "TooSmallLoopVariableCheck.h"
 #include "UncheckedOptionalAccessCheck.h"
+#include "UncheckedStringToNumberConversionCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
@@ -261,6 +262,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-too-small-loop-variable");
 CheckFactories.registerCheck(
 "bugprone-unchecked-optional-access");
+CheckFactories.registerCheck(
+"bugprone-unchecked-string-to-number-conversion");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 59928e5e47a09..46bc8efd44bc5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -91,6 +91,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   ThrowKeywordMissingCheck.cpp
   TooSmallLoopVariableCheck.cpp
   UncheckedOptionalAccessCheck.cpp
+  UncheckedStringToNumberConversionCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
   UndelegatedConstructorCheck.cpp
   UnhandledExceptionAtNewCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
similarity index 95%
rename from clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
rename to 
clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
index 95536bb1cfdb2..d1e7b895f9a35 100644
--- a/clang-tools-extra/clang-tidy/cert/StrToNumCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedStringToNumberConversionCheck.cpp
@@ -1,4 +1,4 @@
-//===-- StrToNumCheck.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.
@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-#include "StrToNumCheck.h"
+#include "UncheckedStringToNumberConversionCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/FormatString.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -15,9 +15,10 @@
 
 using namespace clang::ast_matchers;
 
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
 
-void StrToNumCheck::registerMatchers(MatchFinder *Finder) {
+void UncheckedStringToNumberConversionCheck::registerMatchers(
+MatchFinder *Finder) {
   // Match any function call to the C stand

[clang] [llvm] [RISCV] Implement MC support for Zvfofp8min extension (PR #157014)

2025-09-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Jim Lin (tclin914)


Changes

This patch adds MC support for Zvfofp8min
https://github.com/aswaterman/riscv-misc/blob/main/isa/zvfofp8min.adoc.

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


15 Files Affected:

- (modified) clang/test/Driver/print-supported-extensions-riscv.c (+1) 
- (modified) clang/test/Preprocessor/riscv-target-features.c (+9) 
- (modified) llvm/docs/RISCVUsage.rst (+1) 
- (modified) llvm/docs/ReleaseNotes.md (+1) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+16-3) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.td (+1) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td (+2-1) 
- (added) llvm/lib/Target/RISCV/RISCVInstrInfoZvfofp8min.td (+26) 
- (modified) llvm/lib/TargetParser/RISCVTargetParser.cpp (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+4) 
- (modified) llvm/test/CodeGen/RISCV/features-info.ll (+1) 
- (modified) llvm/test/MC/RISCV/attribute-arch.s (+3) 
- (modified) llvm/test/MC/RISCV/rvv/zvfbfmin.s (+4-4) 
- (added) llvm/test/MC/RISCV/rvv/zvfofp8min.s (+36) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+1) 


``diff
diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 3fa5ef9afd143..b8e7724a9602a 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -216,6 +216,7 @@
 // CHECK-NEXT: zalasr   0.1   'Zalasr' (Load-Acquire and 
Store-Release Instructions)
 // CHECK-NEXT: zvbc32e  0.7   'Zvbc32e' (Vector Carryless 
Multiplication with 32-bits elements)
 // CHECK-NEXT: zvfbfa   0.1   'Zvfbfa' (Additional BF16 
vector compute support)
+// CHECK-NEXT: zvfofp8min   0.21  'Zvfofp8min' (Vector OFP8 
Converts)
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: zvqdotq  0.0   'Zvqdotq' (Vector quad 
widening 4D Dot Product)
 // CHECK-NEXT: svukte   0.3   'Svukte' 
(Address-Independent Latency of User-Mode Faults to Supervisor Addresses)
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 204c9851e680c..962375de398dc 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -178,6 +178,7 @@
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvbc32e {{.*$}}
 // CHECK-NOT: __riscv_zvfbfa {{.*$}}
+// CHECK-NOT: __riscv_zvfofp8min {{.*$}}
 // CHECK-NOT: __riscv_zvfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zvfbfwma {{.*$}}
 // CHECK-NOT: __riscv_zvkgs {{.*$}}
@@ -1560,6 +1561,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVFBFA-EXT %s
 // CHECK-ZVFBFA-EXT: __riscv_zvfbfa 1000{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32ifzvfofp8min0p21 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVFOFP8MIN-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64ifzvfofp8min0p21 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZVFOFP8MIN-EXT %s
+// CHECK-ZVFOFP8MIN-EXT: __riscv_zvfofp8min 21000{{$}}
+
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32i_zve32x_zvbc32e0p7 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVBC32E-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index d6c7b46485ccf..5d2824d797182 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -236,6 +236,7 @@ on support follow.
  ``Zvfbfwma``  Supported
  ``Zvfh``  Supported
  ``Zvfhmin``   Supported
+ ``Zvfofp8min``Assembly Support
  ``Zvkb``  Supported
  ``Zvkg``  Supported (`See note <#riscv-vector-crypto-note>`__)
  ``Zvkn``  Supported (`See note <#riscv-vector-crypto-note>`__)
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index ff92d7390ecfd..84d68691b33de 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -120,6 +120,7 @@ Changes to the RISC-V Backend
   using `$x` with an architecture string suffix is not yet supported.
 * Ssctr and Smctr extensions are no longer experimental.
 * Add support for Zvfbfa (Additional BF16 vector compute support)
+* Add support for Zvfofp8min (OFP8 conversion extension)
 
 Changes to the WebAssembly Backend
 --
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index fa8272b239d99..ca94fa7a84d35 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -689,9 +689,6 @@ def HasStdExtZvfbfa : 
Predicate<"Subtarget->hasStdExtZvfbfa()">,
 
 def FeatureStdE

[clang] [Headers][X86] Allow AVX512 integer min/max mask/maskz variants intrinsics to be used in constexpr (PR #156901)

2025-09-06 Thread Simon Pilgrim via cfe-commits

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


[clang-tools-extra] Add bugprone-loop-variable-copied-then-modified clang-tidy check. (PR #157213)

2025-09-06 Thread Yanzuo Liu via cfe-commits

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


[clang] Fix GH112189 (PR #156846)

2025-09-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (awson)


Changes

Following [the suggestion of @zygoloid](https://github.com/llvm/llvm-project/issues/112189#issuecomment-3172788105)
 `updateStringLiteralType` now recursively clones subexpressions which types it 
modifies.

Done as a separate static function and not inlined directly into the 
`updateStringLiteralType` function for maintainability.

I probably should have done this for the dependent case only, but the function 
is buried deep in the call stack and I didn't bother.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaInit.cpp (+97-14) 
- (added) clang/test/SemaCXX/GH112189.cpp (+41) 


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index c97129336736b..b1cffe062d0a7 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -168,9 +168,85 @@ bool Sema::IsStringInit(Expr *Init, const ArrayType *AT) {
   return ::IsStringInit(Init, AT, Context) == SIF_None;
 }
 
+static StringLiteral *CloneStringLiteral(const StringLiteral *SL,
+ ASTContext &C) {
+  return StringLiteral::Create(C, SL->getString(), SL->getKind(),
+   SL->isPascal(), SL->getType(),
+   SL->getBeginLoc());
+}
+
+// Exactly follow `IgnoreParensSingleStep` (`AST/IgnoreExpr.h`)
+// We only clone those subexpressions which `IgnoreParensSingleStep` drills 
down
+// to.
+static Expr *CloneDrilled(Expr *E, ASTContext &C) {
+  if (auto *SL = dyn_cast(E)) {
+return CloneStringLiteral(SL, C);
+  }
+
+  if (auto *PE = dyn_cast(E)) {
+return new (C) ParenExpr(PE->getBeginLoc(), PE->getEndLoc(),
+ CloneDrilled(PE->getSubExpr(), C));
+  }
+
+  if (auto *UO = dyn_cast(E)) {
+if (UO->getOpcode() == UO_Extension) {
+  return UnaryOperator::Create(
+  C, CloneDrilled(UO->getSubExpr(), C), UO_Extension, UO->getType(),
+  UO->getValueKind(), UO->getObjectKind(), UO->getBeginLoc(),
+  UO->canOverflow(), UO->getFPOptionsOverride());
+}
+  }
+
+  else if (auto *GSE = dyn_cast(E)) {
+if (!GSE->isResultDependent()) {
+  ArrayRef GSEAEs = GSE->getAssocExprs();
+  Expr **NewGSEAEs = new (C) Expr *[GSEAEs.size()];
+  std::copy(GSEAEs.begin(), GSEAEs.end(), NewGSEAEs);
+  NewGSEAEs[GSE->getResultIndex()] = CloneDrilled(GSE->getResultExpr(), C);
+
+#define CREATE_GSE(ctrl)   
\
+  GenericSelectionExpr::Create(
\
+  C, GSE->getGenericLoc(), ctrl, GSE->getAssocTypeSourceInfos(),   
\
+  ArrayRef(NewGSEAEs, GSEAEs.size()), GSE->getDefaultLoc(),
\
+  GSE->getRParenLoc(), GSE->containsUnexpandedParameterPack(), 
\
+  GSE->getResultIndex())
+
+  return GSE->isExprPredicate() ? CREATE_GSE(GSE->getControllingExpr())
+: CREATE_GSE(GSE->getControllingType());
+#undef CREATE_GSE
+}
+  }
+
+  else if (auto *CE = dyn_cast(E)) {
+if (!CE->isConditionDependent()) {
+  // Drills to `CE->getChosenSubExpr()`
+  const bool isCondTrue = CE->isConditionTrue();
+  return new (C)
+  ChooseExpr(CE->getBeginLoc(), CE->getCond(),
+ isCondTrue ? CloneDrilled(CE->getLHS(), C) : CE->getLHS(),
+ isCondTrue ? CE->getRHS() : CloneDrilled(CE->getRHS(), C),
+ CE->getType(), CE->getValueKind(), CE->getObjectKind(),
+ CE->getRParenLoc(), CE->isConditionTrue());
+}
+  }
+
+  else if (auto *PE = dyn_cast(E)) {
+if (PE->isTransparent() && PE->getFunctionName()) {
+  return PredefinedExpr::Create(
+  C, PE->getLocation(), PE->getType(), PE->getIdentKind(),
+  PE->isTransparent(), CloneStringLiteral(PE->getFunctionName(), C));
+}
+  }
+
+  return E;
+}
+
 /// Update the type of a string literal, including any surrounding parentheses,
 /// to match the type of the object which it is initializing.
-static void updateStringLiteralType(Expr *E, QualType Ty) {
+static Expr *updateStringLiteralType(Expr *E, QualType Ty, Sema &S) {
+  Expr *ENew = CloneDrilled(E, S.Context);
+  E = ENew;
+
   while (true) {
 E->setType(Ty);
 E->setValueKind(VK_PRValue);
@@ -178,6 +254,7 @@ static void updateStringLiteralType(Expr *E, QualType Ty) {
   break;
 E = IgnoreParensSingleStep(E);
   }
+  return ENew;
 }
 
 /// Fix a compound literal initializing an array so it's correctly marked
@@ -209,7 +286,7 @@ static bool initializingConstexprVariable(const 
InitializedEntity &Entity) {
 static void CheckC23ConstexprInitStringLiteral(const StringLiteral *SE,
Sema &SemaRef, QualType &TT);
 
-static void CheckStringInit(Expr *Str, QualType &DeclT, const ArrayType *AT,
+stat

[clang] [Clang][bytecode] Add interp__builtin_elementwise_triop_fp to handle general 3-operand floating point intrinsics (PR #157106)

2025-09-06 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon updated 
https://github.com/llvm/llvm-project/pull/157106

>From 4d6078f92740efa3f109b85492f43b8fadd39b03 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim 
Date: Fri, 5 Sep 2025 14:32:07 +0100
Subject: [PATCH 1/2] [Clang][bytecode] Add
 interp__builtin_elementwise_triop_fp to handle general 3-operand floating
 point intrinsics

Refactor interp__builtin_elementwise_fma into something similar to 
interp__builtin_elementwise_triop with a callback function argument to allow 
reuse with other intrinsics

This will allow reuse with some upcoming x86 intrinsics
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 713895b191c88..c0937ecb683bf 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2736,12 +2736,14 @@ static bool interp__builtin_ia32_pmul(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
-static bool interp__builtin_elementwise_fma(InterpState &S, CodePtr OpPC,
-const CallExpr *Call) {
+static bool interp__builtin_elementwise_triop_fp(
+InterpState &S, CodePtr OpPC, const CallExpr *Call,
+llvm::function_ref
+Fn) {
   assert(Call->getNumArgs() == 3);
 
   FPOptions FPO = Call->getFPFeaturesInEffect(S.Ctx.getLangOpts());
-  llvm::RoundingMode RM = getRoundingMode(FPO);
   const QualType Arg1Type = Call->getArg(0)->getType();
   const QualType Arg2Type = Call->getArg(1)->getType();
   const QualType Arg3Type = Call->getArg(2)->getType();
@@ -2756,8 +2758,7 @@ static bool interp__builtin_elementwise_fma(InterpState 
&S, CodePtr OpPC,
 const Floating &Z = S.Stk.pop();
 const Floating &Y = S.Stk.pop();
 const Floating &X = S.Stk.pop();
-APFloat F = X.getAPFloat();
-F.fusedMultiplyAdd(Y.getAPFloat(), Z.getAPFloat(), RM);
+APFloat F = Fn(X.getAPFloat(), Y.getAPFloat(), Z.getAPFloat(), FPO);
 Floating Result = S.allocFloat(X.getSemantics());
 Result.copy(F);
 S.Stk.push(Result);
@@ -2788,8 +2789,8 @@ static bool interp__builtin_elementwise_fma(InterpState 
&S, CodePtr OpPC,
 APFloat X = VX.elem(I).getAPFloat();
 APFloat Y = VY.elem(I).getAPFloat();
 APFloat Z = VZ.elem(I).getAPFloat();
-(void)X.fusedMultiplyAdd(Y, Z, RM);
-Dst.elem(I) = Floating(X);
+APFloat F = Fn(X, Y, Z, FPO);
+Dst.elem(I) = Floating(F);
   }
   Dst.initializeAllElements();
   return true;
@@ -3410,7 +3411,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const CallExpr *Call,
 return interp__builtin_ia32_pmul(S, OpPC, Call, BuiltinID);
 
   case Builtin::BI__builtin_elementwise_fma:
-return interp__builtin_elementwise_fma(S, OpPC, Call);
+return interp__builtin_elementwise_triop_fp(
+S, OpPC, Call,
+[](const APFloat &X, const APFloat &Y, const APFloat &Z,
+   const FPOptions &FPO) {
+  APFloat F = X;
+  F.fusedMultiplyAdd(Y, Z, getRoundingMode(FPO));
+  return F;
+});
 
   case X86::BI__builtin_ia32_selectb_128:
   case X86::BI__builtin_ia32_selectb_256:

>From d970c40289896ad388d08eb46e7aebf423a63ded Mon Sep 17 00:00:00 2001
From: Simon Pilgrim 
Date: Fri, 5 Sep 2025 15:15:27 +0100
Subject: [PATCH 2/2] interp__builtin_elementwise_triop_fp - just pass
 RoundingMode not all FPOptions

---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index c0937ecb683bf..65c1761792de4 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2739,11 +2739,12 @@ static bool interp__builtin_ia32_pmul(InterpState &S, 
CodePtr OpPC,
 static bool interp__builtin_elementwise_triop_fp(
 InterpState &S, CodePtr OpPC, const CallExpr *Call,
 llvm::function_ref
+   const APFloat &, llvm::RoundingMode)>
 Fn) {
   assert(Call->getNumArgs() == 3);
 
   FPOptions FPO = Call->getFPFeaturesInEffect(S.Ctx.getLangOpts());
+  llvm::RoundingMode RM = getRoundingMode(FPO);
   const QualType Arg1Type = Call->getArg(0)->getType();
   const QualType Arg2Type = Call->getArg(1)->getType();
   const QualType Arg3Type = Call->getArg(2)->getType();
@@ -2758,7 +2759,7 @@ static bool interp__builtin_elementwise_triop_fp(
 const Floating &Z = S.Stk.pop();
 const Floating &Y = S.Stk.pop();
 const Floating &X = S.Stk.pop();
-APFloat F = Fn(X.getAPFloat(), Y.getAPFloat(), Z.getAPFloat(), FPO);
+APFloat F = Fn(X.getAPFloat(), Y.getAPFloat(), Z.getAPFloat(), RM);
 Floating Result = S.allocFloat(X.getSemantics());
 Result.copy(F);
 S.Stk.push(Result);
@@ -2789,7 +2790,7 @@ static bool interp__builtin_elementwise_triop_fp(
 APFloat X = VX.elem(I).getAPFloat();
 

[clang-tools-extra] Add bugprone-loop-variable-copied-then-modified clang-tidy check. (PR #157213)

2025-09-06 Thread Yanzuo Liu via cfe-commits


@@ -0,0 +1,100 @@
+
+//===--===//
+//
+// 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 "LoopVariableCopiedThenModifiedCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/TypeTraits.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
+#include "clang/Basic/Diagnostic.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+LoopVariableCopiedThenModifiedCheck::LoopVariableCopiedThenModifiedCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreInexpensiveVariables(
+  Options.get("IgnoreInexpensiveVariables", false)) {}
+
+void LoopVariableCopiedThenModifiedCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreInexpensiveVariables", 
IgnoreInexpensiveVariables);
+}
+
+void LoopVariableCopiedThenModifiedCheck::registerMatchers(
+MatchFinder *Finder) {
+  auto HasReferenceOrPointerTypeOrIsAllowed = hasType(qualType(
+  unless(hasCanonicalType(anyOf(referenceType(), pointerType());
+  auto IteratorReturnsValueType = cxxOperatorCallExpr(
+  hasOverloadedOperatorName("*"),
+  callee(
+  cxxMethodDecl(returns(unless(hasCanonicalType(referenceType()));
+  auto NotConstructedByCopy = cxxConstructExpr(
+  hasDeclaration(cxxConstructorDecl(unless(isCopyConstructor();
+  auto ConstructedByConversion = 
cxxMemberCallExpr(callee(cxxConversionDecl()));
+  auto LoopVar =
+  varDecl(HasReferenceOrPointerTypeOrIsAllowed,
+  unless(hasInitializer(expr(hasDescendant(expr(
+  anyOf(materializeTemporaryExpr(), IteratorReturnsValueType,
+NotConstructedByCopy, ConstructedByConversion)));
+  Finder->addMatcher(
+  traverse(TK_AsIs,
+   cxxForRangeStmt(hasLoopVariable(LoopVar.bind("loopVar")))
+   .bind("forRange")),
+  this);
+}
+
+void LoopVariableCopiedThenModifiedCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *Var = Result.Nodes.getNodeAs("loopVar");
+  if (Var->getBeginLoc().isMacroID())
+return;
+  std::optional Expensive =
+  utils::type_traits::isExpensiveToCopy(Var->getType(), *Result.Context);
+  if ((!Expensive || !*Expensive) && IgnoreInexpensiveVariables)
+return;
+  const auto *ForRange = Result.Nodes.getNodeAs("forRange");
+  if (copiedLoopVarIsMutated(*Var, *ForRange, *Result.Context))
+return;
+}

zwuis wrote:

Variable is not needed. We can discard the result.

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


[clang] [HLSL] Add copy assignment and construtor to resource types (PR #156075)

2025-09-06 Thread Steven Perron via cfe-commits

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


[clang] [llvm] [RISCV] Support ZVqdot Codegen and C intrinsics (PR #154915)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-android` running on `sanitizer-buildbot-android` while 
building `clang,llvm` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[   OK ] AddressSanitizer.AtoiAndFriendsOOBTest (2299 ms)
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (11 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (193 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (49 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (123 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (7 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (114 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (132 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN  ] AddressSanitizer.LongDoubleNegativeTest
[   OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[--] 19 tests from AddressSanitizer (28151 ms total)

[--] Global test environment tear-down
[==] 22 tests from 2 test suites ran. (28185 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

Step 24 (run instrumented asan tests 
[aarch64/aosp_coral-userdebug/AOSP.MASTER]) failure: run instrumented asan 
tests [aarch64/aosp_coral-userdebug/AOSP.MASTER] (failure)
...
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (8 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (324 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (54 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (196 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (16 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (281 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (263 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED 

[clang] [lldb] [clang][Expr] Teach IgnoreUnlessSpelledInSource about implicit calls to std::get free function (PR #122265)

2025-09-06 Thread Michael Buch via cfe-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/122265

>From a9e13ad8d2a7a95d431dddcced611bea1e83b99a Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Thu, 9 Jan 2025 10:01:31 +
Subject: [PATCH 01/10] [clang][DebugInfo] Expand detection of structured
 bindings to account for std::get free function

When we generate the debug-info for a `VarDecl` we try
to determine whether it was introduced as part of a structure
binding (aka a "holding var"). If it was,
we don't mark it as `artificial`.

The heuristic to determine a holding var uses
`IgnoreUnlessSpelledInSource` to unwrap the `VarDecl` initializer
until we hit a `DeclRefExpr` that refers to a `Decomposition`.
For "tuple-like decompositions", Clang will generate a call to
a `template Foo get(Bar)` function that retrieves the
`Ith` element from the tuple-like structure. If that function is a
member function, we get an AST that looks as follows:
```
VarDecl implicit used z1 'std::tuple_element<0, B>::type &&' cinit
`-ExprWithCleanups  'int' xvalue
  `-MaterializeTemporaryExpr  'int' xvalue extended by Var 0x11d110cf8 
'z1' 'std::tuple_element<0, B>::type &&'
`-CXXMemberCallExpr  'int'
  `-MemberExpr  '' .get 0x11d104390
`-ImplicitCastExpr  'B' xvalue 
  `-DeclRefExpr  'B' lvalue Decomposition 0x11d1100a8 '' 'B'
```
`IgnoreUnlessSpelledInSource` happily unwraps this down to the
`DeclRefExpr`. However, when the `get` helper is a free function
(which it is for `std::pair` in libc++ for example), then the AST
is:
```
VarDecl col:16 implicit used k 'std::tuple_element<0, const std::tuple>::type &' cinit
`-CallExpr  'const typename tuple_element<0UL, tuple>::type':'const int' lvalue adl
  |-ImplicitCastExpr  'const typename tuple_element<0UL, tuple>::type &(*)(const tuple &) noexcept' 
  | `-DeclRefExpr  'const typename tuple_element<0UL, tuple>::type &(const tuple &) noexcept' lvalue Function 0x1210262d8 
'get' 'const typename tuple_element<0UL, tuple>::type &(const 
tuple &) noexcept' (FunctionTemplate 0x11d068088 'get')
  `-DeclRefExpr  'const std::tuple' lvalue Decomposition 
0x121021518 '' 'const std::tuple &'
```
`IgnoreUnlessSpelledInSource` doesn't unwrap this `CallExpr`, so we
incorrectly mark the binding as `artificial` in debug-info.

This patch adjusts our heuristic to account for `CallExpr` nodes.

Fixes https://github.com/llvm/llvm-project/issues/122028
---
 clang/lib/CodeGen/CGDebugInfo.cpp | 28 ++-
 .../test/DebugInfo/CXX/structured-binding.cpp | 27 +++
 .../TestStructuredBinding.py  | 11 +++
 .../API/lang/cpp/structured-binding/main.cpp  | 81 +--
 4 files changed, 140 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0385dbdac869b..4b0f2bce457df 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -87,12 +87,38 @@ static bool IsDecomposedVarDecl(VarDecl const *VD) {
   if (!Init)
 return false;
 
+  Init = Init->IgnoreUnlessSpelledInSource();
+  if (!Init)
+return false;
+
+  // For tuple-like decompositions, if the `get` function
+  // is not a member of the decomposed type, but instead a
+  // free function (e.g., how std::get is specialized for
+  // std::pair), then the initializer is a `CallExpr` and
+  // we need to dig into the argument before unwrapping it
+  // with IgnoreUnlessSpelledInSource.
+  if (auto const *CE = llvm::dyn_cast(Init)) {
+if (CE->getNumArgs() == 0)
+  return false;
+
+// The first argument will be the type we're decomposing.
+// Technically the getter could have more than 1 argument
+// (e.g., if they're defaulted arguments), but we don't care
+// about them because we just need to check whether the
+// first argument is a DecompositionDecl.
+auto const *Arg = CE->getArg(0);
+if (!Arg)
+  return false;
+
+Init = Arg;
+  }
+
   auto const *RefExpr =
   llvm::dyn_cast_or_null(Init->IgnoreUnlessSpelledInSource());
   if (!RefExpr)
 return false;
 
-  return llvm::dyn_cast_or_null(RefExpr->getDecl());
+  return llvm::isa_and_nonnull(RefExpr->getDecl());
 }
 
 /// Returns true if \ref VD is a compiler-generated variable
diff --git a/clang/test/DebugInfo/CXX/structured-binding.cpp 
b/clang/test/DebugInfo/CXX/structured-binding.cpp
index 8032ce85c9e25..7d4919ad52bc7 100644
--- a/clang/test/DebugInfo/CXX/structured-binding.cpp
+++ b/clang/test/DebugInfo/CXX/structured-binding.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -emit-llvm -debug-info-kind=standalone -triple 
%itanium_abi_triple %s -o - | FileCheck %s --implicit-check-not="call void 
@llvm.dbg.declare"
 
+// CHECK: define noundef i32 @_Z1fv
 // CHECK: #dbg_declare(ptr %{{[a-z]+}}, ![[VAR_0:[0-9]+]], !DIExpression(),
 // CHECK: #dbg_declare(ptr %{{[0-9]+}}, ![[VAR_1:[0-9]+]], !DIExpression(),
 // CHECK: #dbg_declare(ptr %{{[0-9]+}}, ![[VAR_2:[0-9]+]], 
!DIExpression(DW_OP_plus_uconst, 4),
@@ -1

[clang] [CIR] Add support for delegating constructors with VTT args (PR #156970)

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

https://github.com/andykaylor updated 
https://github.com/llvm/llvm-project/pull/156970

>From 6a4aa7928818708adfb0fa1edeaa7db87825e4ad Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Wed, 3 Sep 2025 15:47:38 -0700
Subject: [PATCH 1/2] [CIR] Add support for delegating constructors with VTT
 args

This adds support for handling delegating constructors with VTT arguments.
---
 clang/lib/CIR/CodeGen/CIRGenClass.cpp  |   5 +-
 clang/test/CIR/CodeGen/delegating-ctor.cpp | 263 +
 2 files changed, 265 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenClass.cpp 
b/clang/lib/CIR/CodeGen/CIRGenClass.cpp
index c3ebab135d85d..ecfcd9f820a22 100644
--- a/clang/lib/CIR/CodeGen/CIRGenClass.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenClass.cpp
@@ -820,9 +820,8 @@ mlir::Value CIRGenFunction::getVTTParameter(GlobalDecl gd, 
bool forVirtualBase,
   uint64_t subVTTIndex;
 
   if (delegating) {
-cgm.errorNYI(rd->getSourceRange(),
- "getVTTParameter: delegating constructor");
-return {};
+// If this is a delegating constructor call, just load the VTT.
+return loadCXXVTT();
   } else if (rd == base) {
 // If the record matches the base, this is the complete ctor/dtor
 // variant calling the base variant in a class with virtual bases.
diff --git a/clang/test/CIR/CodeGen/delegating-ctor.cpp 
b/clang/test/CIR/CodeGen/delegating-ctor.cpp
index a9cfc5d02173d..290ab55e8cb26 100644
--- a/clang/test/CIR/CodeGen/delegating-ctor.cpp
+++ b/clang/test/CIR/CodeGen/delegating-ctor.cpp
@@ -70,3 +70,266 @@ DelegatingWithZeroing::DelegatingWithZeroing(int) : 
DelegatingWithZeroing() {}
 // OGCG:   store i32 %[[I_ARG]], ptr %[[I_ADDR]]
 // OGCG:   %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]]
 // OGCG:   call void @llvm.memset.p0.i64(ptr align 4 %[[THIS]], i8 0, i64 4, 
i1 false)
+
+void other();
+
+class Base {
+public:
+  Base() { squawk(); }
+
+  virtual void squawk();
+};
+
+class Derived : public virtual Base {
+public:
+  Derived();
+  Derived(const void *inVoid);
+
+  virtual void squawk();
+};
+
+Derived::Derived() : Derived(nullptr) { other(); }
+Derived::Derived(const void *inVoid) { squawk(); }
+
+// Note: OGCG emits the constructors in a different order.
+// OGCG: define {{.*}} void @_ZN7DerivedC2Ev(ptr {{.*}} %[[THIS_ARG:.*]], ptr 
{{.*}} %[[VTT_ARG:.*]])
+// OGCG:   %[[THIS_ADDR:.*]] = alloca ptr
+// OGCG:   %[[VTT_ADDR:.*]] = alloca ptr
+// OGCG:   store ptr %[[THIS_ARG]], ptr %[[THIS_ADDR]]
+// OGCG:   store ptr %[[VTT_ARG]], ptr %[[VTT_ADDR]]
+// OGCG:   %[[THIS:.*]] = load ptr, ptr %[[THIS_ADDR]]
+// OGCG:   %[[VTT:.*]] = load ptr, ptr %[[VTT_ADDR]]
+// OGCG:   call void @_ZN7DerivedC2EPKv(ptr {{.*}} %[[THIS]], ptr {{.*}} 
%[[VTT]], ptr {{.*}} null)
+// OGCG:   call void @_Z5otherv()
+// OGCG:   ret void
+
+// CIR:  cir.func {{.*}} @_ZN7DerivedC2EPKv(
+// CIR-SAME:   %[[THIS_ARG:.*]]: !cir.ptr
+// CIR-SAME:   %[[VTT_ARG:.*]]: !cir.ptr>
+// CIR-SAME:   %[[INVOID_ARG:.*]]: !cir.ptr
+// CIR:%[[THIS_ADDR:.*]] = cir.alloca {{.*}} ["this", init]
+// CIR:%[[VTT_ADDR:.*]] = cir.alloca {{.*}} ["vtt", init]
+// CIR:%[[INVOID_ADDR:.*]] = cir.alloca {{.*}} ["inVoid", init]
+// CIR:cir.store %[[THIS_ARG]], %[[THIS_ADDR]]
+// CIR:cir.store %[[VTT_ARG]], %[[VTT_ADDR]]
+// CIR:cir.store %[[INVOID_ARG]], %[[INVOID_ADDR]]
+// CIR:%[[THIS:.*]] = cir.load %[[THIS_ADDR]]
+// CIR:%[[VTT:.*]] = cir.load{{.*}} %[[VTT_ADDR]]
+// CIR:%[[VPTR_GLOBAL_ADDR:.*]] = cir.vtt.address_point %[[VTT]] : 
!cir.ptr>, offset = 0 -> !cir.ptr>
+// CIR:%[[VPTR_PTR:.*]] = cir.cast(bitcast, %[[VPTR_GLOBAL_ADDR]] : 
!cir.ptr>), !cir.ptr
+// CIR:%[[VPTR:.*]] = cir.load{{.*}} %[[VPTR_PTR]] : 
!cir.ptr, !cir.vptr
+// CIR:%[[VPTR_ADDR:.*]] = cir.vtable.get_vptr %[[THIS]] : 
!cir.ptr -> !cir.ptr
+// CIR:cir.store{{.*}} %[[VPTR]], %[[VPTR_ADDR]] : !cir.vptr, 
!cir.ptr
+// CIR:%[[VPTR_BASE_ADDR:.*]] = cir.vtt.address_point %[[VTT]] : 
!cir.ptr>, offset = 1 -> !cir.ptr>
+// CIR:%[[VPTR_BASE_PTR:.*]] = cir.cast(bitcast, %[[VPTR_BASE_ADDR]] : 
!cir.ptr>), !cir.ptr
+// CIR:%[[VPTR_BASE:.*]] = cir.load{{.*}} %[[VPTR_BASE_PTR]] : 
!cir.ptr, !cir.vptr
+// CIR:%[[VPTR_DERIVED_ADDR:.*]] = cir.vtable.get_vptr %[[THIS]] : 
!cir.ptr -> !cir.ptr
+// CIR:%[[VPTR_DERIVED:.*]] = cir.load{{.*}} %[[VPTR_DERIVED_ADDR]] : 
!cir.ptr, !cir.vptr
+// CIR:%[[VPTR_DERIVED_AS_I8PTR:.*]] = cir.cast(bitcast, 
%[[VPTR_DERIVED]] : !cir.vptr), !cir.ptr
+// CIR:%[[BASE_LOC_OFFSET:.*]] = cir.const #cir.int<-32> : !s64i
+// CIR:%[[BASE_OFFSET_PTR:.*]] = 
cir.ptr_stride(%[[VPTR_DERIVED_AS_I8PTR]] : !cir.ptr, 
%[[BASE_LOC_OFFSET]] : !s64i), !cir.ptr
+// CIR:%[[BASE_OFFSET_I64PTR:.*]] = cir.cast(bitcast, 
%[[BASE_OFFSET_PTR]] : !cir.ptr), !cir.ptr
+// CIR:%[[BASE_OFFSET:.*]] = cir.load{{.*}} %[[BASE_OFFSET_I64PTR]] : 
!cir.ptr, !s64i
+// CIR: 

[clang-tools-extra] Add bugprone-loop-variable-copied-then-modified clang-tidy check. (PR #157213)

2025-09-06 Thread via cfe-commits


@@ -0,0 +1,39 @@
+

EugeneZelenko wrote:

```suggestion
```

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


[clang] [analyzer] Improve handling of placement new in `PointerArith` (PR #155855)

2025-09-06 Thread Arseniy Zaostrovnykh via cfe-commits
Alejandro =?utf-8?q?=C3=81lvarez_Ayll=C3=B3n?=,
Alejandro =?utf-8?q?=C3=81lvarez_Ayll=C3=B3n?=,
Alejandro =?utf-8?q?=C3=81lvarez_Ayll=C3=B3n?=
Message-ID:
In-Reply-To: 


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


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


[clang] [Clang][bytecode] Add interp__builtin_elementwise_triop_fp to handle general 3-operand floating point intrinsics (PR #157106)

2025-09-06 Thread Timm Baeder via cfe-commits

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


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


[clang] [clang] Allow attributes in constructor argument list in pre-C++11 (PR #157300)

2025-09-06 Thread via cfe-commits

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


  1   2   >