[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-01-11 Thread Younan Zhang via cfe-commits

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


[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)

2025-01-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `premerge-monolithic-linux` 
running on `premerge-linux-1` while building `clang` at step 7 
"test-build-unified-tree-check-all".

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


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

```
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: 
SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /build/buildbot/premerge-monolithic-linux/build/bin/clang -cc1 
-internal-isystem 
/build/buildbot/premerge-monolithic-linux/build/lib/clang/20/include 
-nostdsysteminc -triple x86_64-linux-gnu -std=c++17 -fsyntax-only 
-fsycl-is-device -verify 
/build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp
+ /build/buildbot/premerge-monolithic-linux/build/bin/clang -cc1 
-internal-isystem 
/build/buildbot/premerge-monolithic-linux/build/lib/clang/20/include 
-nostdsysteminc -triple x86_64-linux-gnu -std=c++17 -fsyntax-only 
-fsycl-is-device -verify 
/build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp
error: 'expected-error' diagnostics expected but not seen: 
  File 
/build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp
 Line 173 (directive at 
/build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp:172):
 'sycl_kernel_entry_point' attribute only applies to functions
error: 'expected-error' diagnostics seen but not expected: 
  File 
/build/buildbot/premerge-monolithic-linux/llvm-project/clang/test/SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp
 Line 173: an attribute list cannot appear here
2 errors generated.

--




```



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


[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-01-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/122423

>From d40a80859eafe96bdc99957db2aebb70db407e67 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 10 Jan 2025 09:46:24 +0800
Subject: [PATCH 1/5] Reapply "[Clang] Implement CWG2369 "Ordering between
 constraints and substitution"" (#122130)

This reverts commit 3972ed57088f6515b787d7d38dec03dc74e51827.
---
 clang/include/clang/Sema/Sema.h   |  22 +++-
 clang/include/clang/Sema/Template.h   |   6 +
 clang/lib/Sema/SemaConcept.cpp|  47 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  49 +---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp |   8 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 115 --
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/CXX/drs/cwg23xx.cpp|  29 +
 clang/test/CXX/drs/cwg26xx.cpp|   2 +-
 clang/test/CXX/drs/cwg27xx.cpp|  20 +++
 .../expr.prim.req/nested-requirement.cpp  |   2 +-
 .../constrant-satisfaction-conversions.cpp|   6 +-
 .../SemaCXX/concept-crash-on-diagnostic.cpp   |   2 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |   2 +-
 clang/test/SemaCXX/cxx23-assume.cpp   |   6 +-
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp   |   2 +-
 clang/test/SemaCXX/lambda-unevaluated.cpp |   4 +-
 .../SemaTemplate/concepts-recursive-inst.cpp  |   4 +-
 .../SemaTemplate/cxx2a-constraint-exprs.cpp   |   2 +-
 clang/test/SemaTemplate/deduction-guide.cpp   |   5 -
 .../nested-implicit-deduction-guides.cpp  |   8 +-
 clang/www/cxx_dr_status.html  |   8 +-
 22 files changed, 289 insertions(+), 62 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a41f16f6dc8c9b..18fd95f77ec227 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13062,6 +13062,7 @@ class Sema final : public SemaBase {
   ///
   /// \param SkipForSpecialization when specified, any template specializations
   /// in a traversal would be ignored.
+  ///
   /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
   /// when encountering a specialized member function template, rather than
   /// returning immediately.
@@ -13073,6 +13074,17 @@ class Sema final : public SemaBase {
   bool SkipForSpecialization = false,
   bool ForDefaultArgumentSubstitution = false);
 
+  /// Apart from storing the result to \p Result, this behaves the same as
+  /// another overload.
+  void getTemplateInstantiationArgs(
+  MultiLevelTemplateArgumentList &Result, const NamedDecl *D,
+  const DeclContext *DC = nullptr, bool Final = false,
+  std::optional> Innermost = std::nullopt,
+  bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
+  bool ForConstraintInstantiation = false,
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
+
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
   class SynthesizedFunctionScope {
@@ -13342,7 +13354,7 @@ class Sema final : public SemaBase {
   ExprResult
   SubstConstraintExpr(Expr *E,
   const MultiLevelTemplateArgumentList &TemplateArgs);
-  // Unlike the above, this does not evaluates constraints.
+  // Unlike the above, this does not evaluate constraints.
   ExprResult SubstConstraintExprWithoutSatisfaction(
   Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs);
 
@@ -14463,10 +14475,10 @@ class Sema final : public SemaBase {
   const MultiLevelTemplateArgumentList &TemplateArgs,
   SourceRange TemplateIDRange);
 
-  bool CheckInstantiatedFunctionTemplateConstraints(
-  SourceLocation PointOfInstantiation, FunctionDecl *Decl,
-  ArrayRef TemplateArgs,
-  ConstraintSatisfaction &Satisfaction);
+  bool CheckFunctionTemplateConstraints(SourceLocation PointOfInstantiation,
+FunctionDecl *Decl,
+ArrayRef 
TemplateArgs,
+ConstraintSatisfaction &Satisfaction);
 
   /// \brief Emit diagnostics explaining why a constraint expression was deemed
   /// unsatisfied.
diff --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 9800f75f676aaf..59a0575ca98036 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -522,6 +522,12 @@ enum class TemplateSubstitutionKind : char {
 llvm::PointerUnion *
 findInstantiationOf(const Decl *D);
 
+/// Similar to \p findInstantiationOf(), but it wouldn't assert if the
+/// instantiation was not found within the current instantiation scope. 
This
+/// is helpful for on-demand declaration instantiation.
+llvm::PointerUnion *
+findInstantiationUnsafe(const Decl *D);
+
 void InstantiatedLocal(const Decl *D, Decl *Inst

[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-01-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/122423

>From d40a80859eafe96bdc99957db2aebb70db407e67 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 10 Jan 2025 09:46:24 +0800
Subject: [PATCH 1/6] Reapply "[Clang] Implement CWG2369 "Ordering between
 constraints and substitution"" (#122130)

This reverts commit 3972ed57088f6515b787d7d38dec03dc74e51827.
---
 clang/include/clang/Sema/Sema.h   |  22 +++-
 clang/include/clang/Sema/Template.h   |   6 +
 clang/lib/Sema/SemaConcept.cpp|  47 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  49 +---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp |   8 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 115 --
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/CXX/drs/cwg23xx.cpp|  29 +
 clang/test/CXX/drs/cwg26xx.cpp|   2 +-
 clang/test/CXX/drs/cwg27xx.cpp|  20 +++
 .../expr.prim.req/nested-requirement.cpp  |   2 +-
 .../constrant-satisfaction-conversions.cpp|   6 +-
 .../SemaCXX/concept-crash-on-diagnostic.cpp   |   2 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |   2 +-
 clang/test/SemaCXX/cxx23-assume.cpp   |   6 +-
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp   |   2 +-
 clang/test/SemaCXX/lambda-unevaluated.cpp |   4 +-
 .../SemaTemplate/concepts-recursive-inst.cpp  |   4 +-
 .../SemaTemplate/cxx2a-constraint-exprs.cpp   |   2 +-
 clang/test/SemaTemplate/deduction-guide.cpp   |   5 -
 .../nested-implicit-deduction-guides.cpp  |   8 +-
 clang/www/cxx_dr_status.html  |   8 +-
 22 files changed, 289 insertions(+), 62 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a41f16f6dc8c9b..18fd95f77ec227 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13062,6 +13062,7 @@ class Sema final : public SemaBase {
   ///
   /// \param SkipForSpecialization when specified, any template specializations
   /// in a traversal would be ignored.
+  ///
   /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
   /// when encountering a specialized member function template, rather than
   /// returning immediately.
@@ -13073,6 +13074,17 @@ class Sema final : public SemaBase {
   bool SkipForSpecialization = false,
   bool ForDefaultArgumentSubstitution = false);
 
+  /// Apart from storing the result to \p Result, this behaves the same as
+  /// another overload.
+  void getTemplateInstantiationArgs(
+  MultiLevelTemplateArgumentList &Result, const NamedDecl *D,
+  const DeclContext *DC = nullptr, bool Final = false,
+  std::optional> Innermost = std::nullopt,
+  bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
+  bool ForConstraintInstantiation = false,
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
+
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
   class SynthesizedFunctionScope {
@@ -13342,7 +13354,7 @@ class Sema final : public SemaBase {
   ExprResult
   SubstConstraintExpr(Expr *E,
   const MultiLevelTemplateArgumentList &TemplateArgs);
-  // Unlike the above, this does not evaluates constraints.
+  // Unlike the above, this does not evaluate constraints.
   ExprResult SubstConstraintExprWithoutSatisfaction(
   Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs);
 
@@ -14463,10 +14475,10 @@ class Sema final : public SemaBase {
   const MultiLevelTemplateArgumentList &TemplateArgs,
   SourceRange TemplateIDRange);
 
-  bool CheckInstantiatedFunctionTemplateConstraints(
-  SourceLocation PointOfInstantiation, FunctionDecl *Decl,
-  ArrayRef TemplateArgs,
-  ConstraintSatisfaction &Satisfaction);
+  bool CheckFunctionTemplateConstraints(SourceLocation PointOfInstantiation,
+FunctionDecl *Decl,
+ArrayRef 
TemplateArgs,
+ConstraintSatisfaction &Satisfaction);
 
   /// \brief Emit diagnostics explaining why a constraint expression was deemed
   /// unsatisfied.
diff --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 9800f75f676aaf..59a0575ca98036 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -522,6 +522,12 @@ enum class TemplateSubstitutionKind : char {
 llvm::PointerUnion *
 findInstantiationOf(const Decl *D);
 
+/// Similar to \p findInstantiationOf(), but it wouldn't assert if the
+/// instantiation was not found within the current instantiation scope. 
This
+/// is helpful for on-demand declaration instantiation.
+llvm::PointerUnion *
+findInstantiationUnsafe(const Decl *D);
+
 void InstantiatedLocal(const Decl *D, Decl *Inst

[clang-tools-extra] ae9bf17 - [clang-tidy] remove never used IgnoreCase in option (#122573)

2025-01-11 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-01-11T22:46:04+08:00
New Revision: ae9bf17697d2245be707e93125f18d09eaf77aa9

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

LOG: [clang-tidy] remove never used IgnoreCase in option (#122573)

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 4aa9fe228ee793..341343e90822b8 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -163,9 +163,10 @@ void ClangTidyCheck::OptionsView::store(
   store(Options, LocalName, Value ? StringRef("true") : StringRef("false"));
 }
 
-std::optional ClangTidyCheck::OptionsView::getEnumInt(
-StringRef LocalName, ArrayRef Mapping, bool CheckGlobal,
-bool IgnoreCase) const {
+std::optional
+ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
+ArrayRef Mapping,
+bool CheckGlobal) const {
   if (!CheckGlobal && Context->getOptionsCollector())
 Context->getOptionsCollector()->insert((NamePrefix + LocalName).str());
   auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix,
@@ -178,12 +179,10 @@ std::optional 
ClangTidyCheck::OptionsView::getEnumInt(
   StringRef Closest;
   unsigned EditDistance = 3;
   for (const auto &NameAndEnum : Mapping) {
-if (IgnoreCase) {
-  if (Value.equals_insensitive(NameAndEnum.second))
-return NameAndEnum.first;
-} else if (Value == NameAndEnum.second) {
+if (Value == NameAndEnum.second) {
   return NameAndEnum.first;
-} else if (Value.equals_insensitive(NameAndEnum.second)) {
+}
+if (Value.equals_insensitive(NameAndEnum.second)) {
   Closest = NameAndEnum.second;
   EditDistance = 0;
   continue;

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index 7427aa9bf48f89..037526a0bd9af7 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -333,9 +333,9 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 /// supply the mapping required to convert between ``T`` and a string.
 template 
 std::enable_if_t, std::optional>
-get(StringRef LocalName, bool IgnoreCase = false) const {
+get(StringRef LocalName) const {
   if (std::optional ValueOr =
-  getEnumInt(LocalName, typeEraseMapping(), false, IgnoreCase))
+  getEnumInt(LocalName, typeEraseMapping(), false))
 return static_cast(*ValueOr);
   return std::nullopt;
 }
@@ -353,9 +353,9 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 /// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
 /// supply the mapping required to convert between ``T`` and a string.
 template 
-std::enable_if_t, T> get(StringRef LocalName, T Default,
-   bool IgnoreCase = false) const {
-  return get(LocalName, IgnoreCase).value_or(Default);
+std::enable_if_t, T> get(StringRef LocalName,
+   T Default) const {
+  return get(LocalName).value_or(Default);
 }
 
 /// Read a named option from the ``Context`` and parse it as an
@@ -373,9 +373,9 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 /// supply the mapping required to convert between ``T`` and a string.
 template 
 std::enable_if_t, std::optional>
-getLocalOrGlobal(StringRef LocalName, bool IgnoreCase = false) const {
+getLocalOrGlobal(StringRef LocalName) const {
   if (std::optional ValueOr =
-  getEnumInt(LocalName, typeEraseMapping(), true, IgnoreCase))
+  getEnumInt(LocalName, typeEraseMapping(), true))
 return static_cast(*ValueOr);
   return std::nullopt;
 }
@@ -394,10 +394,9 @@ class ClangTidyCheck : public 
ast_matchers::MatchFinder::MatchCallback {
 /// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
 /// supply the mapping required to convert between ``T`` and a string.
 template 
-std::enable_if_t, T>
-getLocalOrGlobal(StringRef LocalName, T Default,
- bool IgnoreCase = false) const {
-  return getLocalOrGlobal(LocalName, IgnoreCase).value_or(Default);
+std::enable_if_t, T> getLocalOrGlobal(StringRef 
LocalName,
+T Default) con

[clang-tools-extra] [clang-tidy] remove never used IgnoreCase in option (PR #122573)

2025-01-11 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy] fix incorrect configuration file path resolving when file paths contain `..` (PR #121323)

2025-01-11 Thread Congcong Cai via cfe-commits

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

>From 896db4495ff2c29c2e623d92e004ef64f49c8dd0 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 30 Dec 2024 16:38:29 +0800
Subject: [PATCH] [clang-tidy] fix incorrect configuration file path resolving
 when file paths contain `..`

`makeAbsolute` will not normalize path. When getting parent folder, `..` will 
go into the subfolder instead of the parent folder.
---
 .../clang-tidy/ClangTidyOptions.cpp   | 32 ---
 .../clang-tidy/ClangTidyOptions.h |  4 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++
 .../Inputs/normalized-path/code.cpp   |  0
 .../normalized-path/error-config/.clang-tidy  |  1 +
 .../infrastructure/normalized-path.test   |  3 ++
 6 files changed, 32 insertions(+), 11 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/normalized-path/code.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/normalized-path/error-config/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/normalized-path.test

diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 445c7f85c900c6..1ad278e5d9a795 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -12,6 +12,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/Path.h"
@@ -298,12 +299,11 @@ ConfigOptionsProvider::getRawOptions(llvm::StringRef 
FileName) {
   if (ConfigOptions.InheritParentConfig.value_or(false)) {
 LLVM_DEBUG(llvm::dbgs()
<< "Getting options for file " << FileName << "...\n");
-assert(FS && "FS must be set.");
 
-llvm::SmallString<128> AbsoluteFilePath(FileName);
-
-if (!FS->makeAbsolute(AbsoluteFilePath)) {
-  addRawFileOptions(AbsoluteFilePath, RawOptions);
+llvm::ErrorOr> AbsoluteFilePath =
+getNormalizedAbsolutePath(FileName);
+if (AbsoluteFilePath) {
+  addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
 }
   }
   RawOptions.emplace_back(ConfigOptions,
@@ -334,6 +334,17 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
   OverrideOptions(std::move(OverrideOptions)),
   ConfigHandlers(std::move(ConfigHandlers)) {}
 
+llvm::ErrorOr>
+FileOptionsBaseProvider::getNormalizedAbsolutePath(llvm::StringRef Path) {
+  assert(FS && "FS must be set.");
+  llvm::SmallString<128> NormalizedAbsolutePath = {Path};
+  std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
+  if (Err)
+return Err;
+  llvm::sys::path::remove_dots(NormalizedAbsolutePath, 
/*remove_dot_dot=*/true);
+  return NormalizedAbsolutePath;
+}
+
 void FileOptionsBaseProvider::addRawFileOptions(
 llvm::StringRef AbsolutePath, std::vector &CurOptions) {
   auto CurSize = CurOptions.size();
@@ -396,16 +407,15 @@ std::vector
 FileOptionsProvider::getRawOptions(StringRef FileName) {
   LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
   << "...\n");
-  assert(FS && "FS must be set.");
-
-  llvm::SmallString<128> AbsoluteFilePath(FileName);
 
-  if (FS->makeAbsolute(AbsoluteFilePath))
+  llvm::ErrorOr> AbsoluteFilePath =
+  getNormalizedAbsolutePath(FileName);
+  if (!AbsoluteFilePath)
 return {};
 
   std::vector RawOptions =
-  DefaultOptionsProvider::getRawOptions(AbsoluteFilePath.str());
-  addRawFileOptions(AbsoluteFilePath, RawOptions);
+  DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
+  addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
   OptionsSource CommandLineOptions(OverrideOptions,
OptionsSourceTypeCheckCommandLineOption);
 
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 85d5a02ebbc1bc..95abe932d56ccf 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
 
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorOr.h"
@@ -237,6 +238,9 @@ class FileOptionsBaseProvider : public 
DefaultOptionsProvider {
   void addRawFileOptions(llvm::StringRef AbsolutePath,
  std::vector &CurOptions);
 
+  llvm::ErrorOr>
+  getNormalizedAbsolutePath(llvm::StringRef AbsolutePath);
+
   /// Try to read configuration files from \p Directory using registered
   /// \c ConfigHandlers.
   std::optional tryReadConfigFile(llvm::StringRef Directory);
diff --git a/clang-tools-extra/docs/

[clang-tools-extra] [clang-tidy] fix incorrect configuration file path resolving when file paths contain `..` (PR #121323)

2025-01-11 Thread Congcong Cai via cfe-commits

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

>From 896db4495ff2c29c2e623d92e004ef64f49c8dd0 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 30 Dec 2024 16:38:29 +0800
Subject: [PATCH 1/2] [clang-tidy] fix incorrect configuration file path
 resolving when file paths contain `..`

`makeAbsolute` will not normalize path. When getting parent folder, `..` will 
go into the subfolder instead of the parent folder.
---
 .../clang-tidy/ClangTidyOptions.cpp   | 32 ---
 .../clang-tidy/ClangTidyOptions.h |  4 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++
 .../Inputs/normalized-path/code.cpp   |  0
 .../normalized-path/error-config/.clang-tidy  |  1 +
 .../infrastructure/normalized-path.test   |  3 ++
 6 files changed, 32 insertions(+), 11 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/normalized-path/code.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/normalized-path/error-config/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/normalized-path.test

diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 445c7f85c900c6..1ad278e5d9a795 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -12,6 +12,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/Path.h"
@@ -298,12 +299,11 @@ ConfigOptionsProvider::getRawOptions(llvm::StringRef 
FileName) {
   if (ConfigOptions.InheritParentConfig.value_or(false)) {
 LLVM_DEBUG(llvm::dbgs()
<< "Getting options for file " << FileName << "...\n");
-assert(FS && "FS must be set.");
 
-llvm::SmallString<128> AbsoluteFilePath(FileName);
-
-if (!FS->makeAbsolute(AbsoluteFilePath)) {
-  addRawFileOptions(AbsoluteFilePath, RawOptions);
+llvm::ErrorOr> AbsoluteFilePath =
+getNormalizedAbsolutePath(FileName);
+if (AbsoluteFilePath) {
+  addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
 }
   }
   RawOptions.emplace_back(ConfigOptions,
@@ -334,6 +334,17 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
   OverrideOptions(std::move(OverrideOptions)),
   ConfigHandlers(std::move(ConfigHandlers)) {}
 
+llvm::ErrorOr>
+FileOptionsBaseProvider::getNormalizedAbsolutePath(llvm::StringRef Path) {
+  assert(FS && "FS must be set.");
+  llvm::SmallString<128> NormalizedAbsolutePath = {Path};
+  std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
+  if (Err)
+return Err;
+  llvm::sys::path::remove_dots(NormalizedAbsolutePath, 
/*remove_dot_dot=*/true);
+  return NormalizedAbsolutePath;
+}
+
 void FileOptionsBaseProvider::addRawFileOptions(
 llvm::StringRef AbsolutePath, std::vector &CurOptions) {
   auto CurSize = CurOptions.size();
@@ -396,16 +407,15 @@ std::vector
 FileOptionsProvider::getRawOptions(StringRef FileName) {
   LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
   << "...\n");
-  assert(FS && "FS must be set.");
-
-  llvm::SmallString<128> AbsoluteFilePath(FileName);
 
-  if (FS->makeAbsolute(AbsoluteFilePath))
+  llvm::ErrorOr> AbsoluteFilePath =
+  getNormalizedAbsolutePath(FileName);
+  if (!AbsoluteFilePath)
 return {};
 
   std::vector RawOptions =
-  DefaultOptionsProvider::getRawOptions(AbsoluteFilePath.str());
-  addRawFileOptions(AbsoluteFilePath, RawOptions);
+  DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
+  addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
   OptionsSource CommandLineOptions(OverrideOptions,
OptionsSourceTypeCheckCommandLineOption);
 
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 85d5a02ebbc1bc..95abe932d56ccf 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
 
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorOr.h"
@@ -237,6 +238,9 @@ class FileOptionsBaseProvider : public 
DefaultOptionsProvider {
   void addRawFileOptions(llvm::StringRef AbsolutePath,
  std::vector &CurOptions);
 
+  llvm::ErrorOr>
+  getNormalizedAbsolutePath(llvm::StringRef AbsolutePath);
+
   /// Try to read configuration files from \p Directory using registered
   /// \c ConfigHandlers.
   std::optional tryReadConfigFile(llvm::StringRef Directory);
diff --git a/clang-tools-extra/d

[clang-tools-extra] [clang-tidy] fix incorrect configuration file path resolving when file paths contain `..` (PR #121323)

2025-01-11 Thread Congcong Cai via cfe-commits


@@ -117,6 +117,11 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise
   happening on certain platforms when interrupting the script.
 
+- Improved :program:`clang-tidy` by accepting parameters file in command line.
+

HerrCai0907 wrote:

```suggestion
```

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


[clang-tools-extra] 0249554 - [clang-tidy] fix incorrect configuration file path resolving when file paths contain `..` (#121323)

2025-01-11 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-01-11T22:51:47+08:00
New Revision: 0249554ee1ac49e6f1d93fa78a55971fc706f635

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

LOG: [clang-tidy] fix incorrect configuration file path resolving when file 
paths contain `..` (#121323)

`makeAbsolute` will not normalize path. When getting parent folder, `..`
will go into the subfolder instead of the parent folder.

Added: 

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/normalized-path/code.cpp

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/normalized-path/error-config/.clang-tidy
clang-tools-extra/test/clang-tidy/infrastructure/normalized-path.test

Modified: 
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/clang-tidy/ClangTidyOptions.h
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index e1d5df75f3e5aa..8bac6f161fa05b 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -12,6 +12,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBufferRef.h"
 #include "llvm/Support/Path.h"
@@ -298,12 +299,11 @@ ConfigOptionsProvider::getRawOptions(llvm::StringRef 
FileName) {
   if (ConfigOptions.InheritParentConfig.value_or(false)) {
 LLVM_DEBUG(llvm::dbgs()
<< "Getting options for file " << FileName << "...\n");
-assert(FS && "FS must be set.");
 
-llvm::SmallString<128> AbsoluteFilePath(FileName);
-
-if (!FS->makeAbsolute(AbsoluteFilePath)) {
-  addRawFileOptions(AbsoluteFilePath, RawOptions);
+llvm::ErrorOr> AbsoluteFilePath =
+getNormalizedAbsolutePath(FileName);
+if (AbsoluteFilePath) {
+  addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
 }
   }
   RawOptions.emplace_back(ConfigOptions,
@@ -334,6 +334,17 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
   OverrideOptions(std::move(OverrideOptions)),
   ConfigHandlers(std::move(ConfigHandlers)) {}
 
+llvm::ErrorOr>
+FileOptionsBaseProvider::getNormalizedAbsolutePath(llvm::StringRef Path) {
+  assert(FS && "FS must be set.");
+  llvm::SmallString<128> NormalizedAbsolutePath = {Path};
+  std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
+  if (Err)
+return Err;
+  llvm::sys::path::remove_dots(NormalizedAbsolutePath, 
/*remove_dot_dot=*/true);
+  return NormalizedAbsolutePath;
+}
+
 void FileOptionsBaseProvider::addRawFileOptions(
 llvm::StringRef AbsolutePath, std::vector &CurOptions) {
   auto CurSize = CurOptions.size();
@@ -397,16 +408,15 @@ std::vector
 FileOptionsProvider::getRawOptions(StringRef FileName) {
   LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
   << "...\n");
-  assert(FS && "FS must be set.");
-
-  llvm::SmallString<128> AbsoluteFilePath(FileName);
 
-  if (FS->makeAbsolute(AbsoluteFilePath))
+  llvm::ErrorOr> AbsoluteFilePath =
+  getNormalizedAbsolutePath(FileName);
+  if (!AbsoluteFilePath)
 return {};
 
   std::vector RawOptions =
-  DefaultOptionsProvider::getRawOptions(AbsoluteFilePath.str());
-  addRawFileOptions(AbsoluteFilePath, RawOptions);
+  DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
+  addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
   OptionsSource CommandLineOptions(OverrideOptions,
OptionsSourceTypeCheckCommandLineOption);
 

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 568f60cf98b21f..dd78c570d25d9b 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
 
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorOr.h"
@@ -237,6 +238,9 @@ class FileOptionsBaseProvider : public 
DefaultOptionsProvider {
   void addRawFileOptions(llvm::StringRef AbsolutePath,
  std::vector &CurOptions);
 
+  llvm::ErrorOr>
+  getNormalizedAbsolutePath(llvm::StringRef AbsolutePath);
+
   /// Try to read configuration files from \p Directory using registered
   /// \c ConfigHandlers.
   std::optional tryReadConfigFile(llvm::StringRef Directory);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index d75a276729c581..9818ec9603bbc0 100

[clang-tools-extra] [clang-tidy] fix incorrect configuration file path resolving when file paths contain `..` (PR #121323)

2025-01-11 Thread Congcong Cai via cfe-commits

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


[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-01-11 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add `performance-explicit-move-constructor` check (PR #122599)

2025-01-11 Thread via cfe-commits

https://github.com/dodicidodici updated 
https://github.com/llvm/llvm-project/pull/122599

>From 2f1627ee62c041d98cbc51b08aebf2dd2dbe5455 Mon Sep 17 00:00:00 2001
From: dodicidodici 
Date: Fri, 10 Jan 2025 19:05:09 +0100
Subject: [PATCH 1/6] add `performance-explicit-move-constructor` check

---
 .../ExplicitMoveConstructorCheck.cpp  | 72 +++
 .../ExplicitMoveConstructorCheck.h| 33 +
 2 files changed, 105 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h

diff --git 
a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
new file mode 100644
index 00..631ed363566c65
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
@@ -0,0 +1,72 @@
+//===--- ExplicitMoveConstructorCheck.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 "ExplicitMoveConstructorCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+static SourceRange findExplicitToken(const CXXConstructorDecl *Ctor,
+ const SourceManager &Source,
+ const LangOptions &LangOpts) {
+  SourceLocation CurrentLoc = Ctor->getBeginLoc();
+  SourceLocation EndLoc = Ctor->getEndLoc();
+  Token Tok;
+
+  do {
+const bool failed = Lexer::getRawToken(CurrentLoc, Tok, Source, LangOpts);
+
+if (failed)
+  return {};
+
+if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "explicit")
+  return {Tok.getLocation(), Tok.getEndLoc()};
+
+CurrentLoc = Tok.getEndLoc();
+  } while (Tok.isNot(tok::eof) && CurrentLoc < EndLoc);
+
+  return {};
+}
+
+void ExplicitMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxRecordDecl(
+  has(cxxConstructorDecl(isMoveConstructor(), isExplicit())
+  .bind("move-ctor")),
+  has(cxxConstructorDecl(isCopyConstructor(), unless(isDeleted()))
+  .bind("copy-ctor"))),
+  this);
+}
+
+void ExplicitMoveConstructorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MoveCtor =
+  Result.Nodes.getNodeAs("move-ctor");
+  const auto *CopyCtor =
+  Result.Nodes.getNodeAs("copy-ctor");
+
+  if (!MoveCtor || !CopyCtor)
+return;
+
+  auto Diag = diag(
+  MoveCtor->getLocation(),
+  "copy constructor may be called instead of explicit move constructor");
+  SourceRange ExplicitTokenRange =
+  findExplicitToken(MoveCtor, *Result.SourceManager, getLangOpts());
+
+  if (ExplicitTokenRange.isInvalid())
+return;
+
+  Diag << FixItHint::CreateRemoval(
+  CharSourceRange::getCharRange(ExplicitTokenRange));
+}
+
+} // namespace clang::tidy::performance
diff --git 
a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h 
b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
new file mode 100644
index 00..9ae071a20a9eef
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
@@ -0,0 +1,33 @@
+//===--- ExplicitMoveConstructorCheck.h - clang-tidy *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_EXPLICITMOVECONSTRUCTORCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_EXPLICITMOVECONSTRUCTORCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::performance {
+
+/// Find classes that define an explicit move constructor and a (non-deleted) 
copy constructor.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/performance/explicit-move-constructor.html
+class ExplicitMoveConstructorCheck : public ClangTidyCheck {
+public:
+  ExplicitMoveConstructorCheck(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 {
+return LangOpts.CPlusPlus;
+

[clang-tools-extra] [clang-tidy] Add an option to exclude files not present in the compile database (PR #120348)

2025-01-11 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
212cba0ef37dd3b2a253c063240370de42fc67c1...834789678bf967e79c29041452bc96832592de36
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
``





View the diff from darker here.


``diff
--- clang-tidy-diff.py  2025-01-11 08:49:47.00 +
+++ clang-tidy-diff.py  2025-01-11 17:07:31.260596 +
@@ -124,14 +124,16 @@
 # Empty the file:
 open(mergefile, "w").close()
 
 
 def get_compiling_files(args):
-""" Read a compile_commands.json database and return a set of file paths 
"""
+"""Read a compile_commands.json database and return a set of file paths"""
 current_dir = Path.cwd()
-compile_commands_json = (current_dir / args.build_path) if args.build_path 
else current_dir
-compile_commands_json = (compile_commands_json / "compile_commands.json")
+compile_commands_json = (
+(current_dir / args.build_path) if args.build_path else current_dir
+)
+compile_commands_json = compile_commands_json / "compile_commands.json"
 files = set()
 with open(compile_commands_json) as db_file:
 db_json = json.load(db_file)
 for entry in db_json:
 if "file" not in entry:
@@ -284,11 +286,14 @@
 else:
 if not re.match("^%s$" % args.iregex, filename, re.IGNORECASE):
 continue
 
 # Skip any files not in the compiling list
-if compiling_files is not None and (Path.cwd() / filename) not in 
compiling_files:
+if (
+compiling_files is not None
+and (Path.cwd() / filename) not in compiling_files
+):
 continue
 
 match = re.search(r"^@@.*\+(\d+)(,(\d+))?", line)
 if match:
 start_line = int(match.group(1))

``




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


[clang] [clang-tools-extra] [libcxx] [llvm] [libc++][ranges] P2542R8: Implement `views::concat` (PR #120920)

2025-01-11 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja edited 
https://github.com/llvm/llvm-project/pull/120920
___
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 an option to exclude files not present in the compile database (PR #120348)

2025-01-11 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

feel free to ping me when you want to merge it.

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


[clang-tools-extra] [clangd] Support .clangd command line modifications for C++ modules (PR #122606)

2025-01-11 Thread Petr Polezhaev via cfe-commits

https://github.com/petr-polezhaev created 
https://github.com/llvm/llvm-project/pull/122606

Tunnels `Manger` object into the `ScanningAllProjectModules` so it can be used 
to perform necessary command-line modifications (which also adds `--resources` 
path previously added there explicitly). This allows using the experimental C++ 
modules support with gcc.

This was discussed in the issue with @ChuanqiXu9 and @kadircet

Closes #112635

>From 0813476d626e21828f73e9f9a3a3561becd37277 Mon Sep 17 00:00:00 2001
From: Petr Polezhaev 
Date: Sat, 11 Jan 2025 21:21:16 +0300
Subject: [PATCH] [clangd] Support .clangd command line modifications in
 ScanningAllProjectModules

---
 .../clangd/GlobalCompilationDatabase.cpp  | 11 -
 .../clangd/GlobalCompilationDatabase.h|  3 ++
 clang-tools-extra/clangd/ProjectModules.h |  7 +++
 .../clangd/ScanningProjectModules.cpp | 39 +--
 .../unittests/PrerequisiteModulesTest.cpp | 49 +--
 5 files changed, 90 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 71e97ac4efd673..ea2ff3d604efbc 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -830,6 +830,16 @@ bool OverlayCDB::setCompileCommand(PathRef File,
   return true;
 }
 
+std::unique_ptr
+OverlayCDB::getProjectModules(PathRef File) const {
+  auto MDB = DelegatingCDB::getProjectModules(File);
+  MDB->setCommandProvider([&Mangler = Mangler](tooling::CompileCommand 
&Command,
+   PathRef CommandPath) {
+Mangler(Command, CommandPath);
+  });
+  return std::move(MDB);
+}
+
 DelegatingCDB::DelegatingCDB(const GlobalCompilationDatabase *Base)
 : Base(Base) {
   if (Base)
@@ -874,6 +884,5 @@ bool DelegatingCDB::blockUntilIdle(Deadline D) const {
 return true;
   return Base->blockUntilIdle(D);
 }
-
 } // namespace clangd
 } // namespace clang
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.h 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
index f8349c6efecb01..1d636d73664bee 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.h
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
@@ -209,6 +209,9 @@ class OverlayCDB : public DelegatingCDB {
   setCompileCommand(PathRef File,
 std::optional CompilationCommand);
 
+  std::unique_ptr
+  getProjectModules(PathRef File) const override;
+
 private:
   mutable std::mutex Mutex;
   llvm::StringMap Commands; /* GUARDED_BY(Mut) */
diff --git a/clang-tools-extra/clangd/ProjectModules.h 
b/clang-tools-extra/clangd/ProjectModules.h
index 3b9b564a87da01..6830d44919fa81 100644
--- a/clang-tools-extra/clangd/ProjectModules.h
+++ b/clang-tools-extra/clangd/ProjectModules.h
@@ -9,8 +9,10 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
 
+#include "support/Function.h"
 #include "support/Path.h"
 #include "support/ThreadsafeFS.h"
+#include "clang/Tooling/CompilationDatabase.h"
 
 #include 
 
@@ -36,11 +38,16 @@ namespace clangd {
 /// `[:partition-name]`. So module names covers 
partitions.
 class ProjectModules {
 public:
+  using CommandProvider =
+  llvm::unique_function;
+
   virtual std::vector getRequiredModules(PathRef File) = 0;
   virtual PathRef
   getSourceForModuleName(llvm::StringRef ModuleName,
  PathRef RequiredSrcFile = PathRef()) = 0;
 
+  virtual void setCommandProvider(CommandProvider Provider) {}
+
   virtual ~ProjectModules() = default;
 };
 
diff --git a/clang-tools-extra/clangd/ScanningProjectModules.cpp 
b/clang-tools-extra/clangd/ScanningProjectModules.cpp
index 92f75ef7d5c25a..6f098c18cd80a0 100644
--- a/clang-tools-extra/clangd/ScanningProjectModules.cpp
+++ b/clang-tools-extra/clangd/ScanningProjectModules.cpp
@@ -32,6 +32,9 @@ namespace {
 /// interfere with each other.
 class ModuleDependencyScanner {
 public:
+  using CommandProvider =
+  llvm::unique_function;
+
   ModuleDependencyScanner(
   std::shared_ptr CDB,
   const ThreadsafeFS &TFS)
@@ -48,7 +51,8 @@ class ModuleDependencyScanner {
   };
 
   /// Scanning the single file specified by \param FilePath.
-  std::optional scan(PathRef FilePath);
+  std::optional scan(PathRef FilePath,
+   CommandProvider const &Provider);
 
   /// Scanning every source file in the current project to get the
   ///  to  map.
@@ -57,7 +61,7 @@ class ModuleDependencyScanner {
   /// a global module dependency scanner to monitor every file. Or we
   /// can simply require the build systems (or even the end users)
   /// to provide the map.
-  void globalScan();
+  void globalScan(CommandProvider const &Provider);
 
   /// Get the source file from the module name. Note that the language
   /// guarantees all the module names are un

[clang] [Clang] Add release note for pointer overflow optimization change (PR #122462)

2025-01-11 Thread Hans Wennborg via cfe-commits

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

The current version lgtm by the way

Maybe we should also put a blurb in the main llvm release notes and link to 
this one.

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


[clang-tools-extra] [clangd] Support .clangd command line modifications for C++ modules (PR #122606)

2025-01-11 Thread via cfe-commits

llvmbot wrote:




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

Author: Petr Polezhaev (petr-polezhaev)


Changes

Tunnels `Manger` object into the `ScanningAllProjectModules` so it can be used 
to perform necessary command-line modifications (which also adds `--resources` 
path previously added there explicitly). This allows using the experimental C++ 
modules support with gcc.

This was discussed in the issue with @ChuanqiXu9 and @kadircet

Closes #112635

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


5 Files Affected:

- (modified) clang-tools-extra/clangd/GlobalCompilationDatabase.cpp (+10-1) 
- (modified) clang-tools-extra/clangd/GlobalCompilationDatabase.h (+3) 
- (modified) clang-tools-extra/clangd/ProjectModules.h (+7) 
- (modified) clang-tools-extra/clangd/ScanningProjectModules.cpp (+24-15) 
- (modified) clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp 
(+46-3) 


``diff
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index 71e97ac4efd673..ea2ff3d604efbc 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -830,6 +830,16 @@ bool OverlayCDB::setCompileCommand(PathRef File,
   return true;
 }
 
+std::unique_ptr
+OverlayCDB::getProjectModules(PathRef File) const {
+  auto MDB = DelegatingCDB::getProjectModules(File);
+  MDB->setCommandProvider([&Mangler = Mangler](tooling::CompileCommand 
&Command,
+   PathRef CommandPath) {
+Mangler(Command, CommandPath);
+  });
+  return std::move(MDB);
+}
+
 DelegatingCDB::DelegatingCDB(const GlobalCompilationDatabase *Base)
 : Base(Base) {
   if (Base)
@@ -874,6 +884,5 @@ bool DelegatingCDB::blockUntilIdle(Deadline D) const {
 return true;
   return Base->blockUntilIdle(D);
 }
-
 } // namespace clangd
 } // namespace clang
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.h 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
index f8349c6efecb01..1d636d73664bee 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.h
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.h
@@ -209,6 +209,9 @@ class OverlayCDB : public DelegatingCDB {
   setCompileCommand(PathRef File,
 std::optional CompilationCommand);
 
+  std::unique_ptr
+  getProjectModules(PathRef File) const override;
+
 private:
   mutable std::mutex Mutex;
   llvm::StringMap Commands; /* GUARDED_BY(Mut) */
diff --git a/clang-tools-extra/clangd/ProjectModules.h 
b/clang-tools-extra/clangd/ProjectModules.h
index 3b9b564a87da01..6830d44919fa81 100644
--- a/clang-tools-extra/clangd/ProjectModules.h
+++ b/clang-tools-extra/clangd/ProjectModules.h
@@ -9,8 +9,10 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H
 
+#include "support/Function.h"
 #include "support/Path.h"
 #include "support/ThreadsafeFS.h"
+#include "clang/Tooling/CompilationDatabase.h"
 
 #include 
 
@@ -36,11 +38,16 @@ namespace clangd {
 /// `[:partition-name]`. So module names covers 
partitions.
 class ProjectModules {
 public:
+  using CommandProvider =
+  llvm::unique_function;
+
   virtual std::vector getRequiredModules(PathRef File) = 0;
   virtual PathRef
   getSourceForModuleName(llvm::StringRef ModuleName,
  PathRef RequiredSrcFile = PathRef()) = 0;
 
+  virtual void setCommandProvider(CommandProvider Provider) {}
+
   virtual ~ProjectModules() = default;
 };
 
diff --git a/clang-tools-extra/clangd/ScanningProjectModules.cpp 
b/clang-tools-extra/clangd/ScanningProjectModules.cpp
index 92f75ef7d5c25a..6f098c18cd80a0 100644
--- a/clang-tools-extra/clangd/ScanningProjectModules.cpp
+++ b/clang-tools-extra/clangd/ScanningProjectModules.cpp
@@ -32,6 +32,9 @@ namespace {
 /// interfere with each other.
 class ModuleDependencyScanner {
 public:
+  using CommandProvider =
+  llvm::unique_function;
+
   ModuleDependencyScanner(
   std::shared_ptr CDB,
   const ThreadsafeFS &TFS)
@@ -48,7 +51,8 @@ class ModuleDependencyScanner {
   };
 
   /// Scanning the single file specified by \param FilePath.
-  std::optional scan(PathRef FilePath);
+  std::optional scan(PathRef FilePath,
+   CommandProvider const &Provider);
 
   /// Scanning every source file in the current project to get the
   ///  to  map.
@@ -57,7 +61,7 @@ class ModuleDependencyScanner {
   /// a global module dependency scanner to monitor every file. Or we
   /// can simply require the build systems (or even the end users)
   /// to provide the map.
-  void globalScan();
+  void globalScan(CommandProvider const &Provider);
 
   /// Get the source file from the module name. Note that the language
   /// guarantees all the module names are unique in a valid program.
@@ -69,7 +73,8 @@ class ModuleDependencyScanner {
 
   /// Return the direct r

[clang-tools-extra] [clangd] Support .clangd command line modifications for C++ modules (PR #122606)

2025-01-11 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/122606
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add `performance-explicit-move-constructor` check (PR #122599)

2025-01-11 Thread via cfe-commits

llvmbot wrote:




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

Author: dodicidodici (dodicidodici)


Changes

This patch adds a check that reports classes that define an explicit move 
constructor and a copy constructor.
Closes #121707 

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


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/performance/CMakeLists.txt (+1) 
- (added) 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp (+73) 
- (added) 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h (+33) 
- (modified) clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp 
(+3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/performance/explicit-move-constructor.rst
 (+33) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/performance/explicit-move-constructor.cpp
 (+34) 


``diff
diff --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index c6e547c5089fb0..07f4e84b00bb3e 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
 add_clang_library(clangTidyPerformanceModule STATIC
   AvoidEndlCheck.cpp
   EnumSizeCheck.cpp
+  ExplicitMoveConstructorCheck.cpp
   FasterStringFindCheck.cpp
   ForRangeCopyCheck.cpp
   ImplicitConversionInLoopCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
new file mode 100644
index 00..94f9cebae69506
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
@@ -0,0 +1,73 @@
+//===--- ExplicitMoveConstructorCheck.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 "ExplicitMoveConstructorCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+static SourceRange findExplicitToken(const CXXConstructorDecl *Ctor,
+ const SourceManager &Source,
+ const LangOptions &LangOpts) {
+  SourceLocation CurrentLoc = Ctor->getBeginLoc();
+  SourceLocation EndLoc = Ctor->getEndLoc();
+  Token Tok;
+
+  do {
+const bool failed = Lexer::getRawToken(CurrentLoc, Tok, Source, LangOpts);
+
+if (failed)
+  return {};
+
+if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "explicit")
+  return {Tok.getLocation(), Tok.getEndLoc()};
+
+CurrentLoc = Tok.getEndLoc();
+  } while (Tok.isNot(tok::eof) && CurrentLoc < EndLoc);
+
+  return {};
+}
+
+void ExplicitMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxRecordDecl(
+  has(cxxConstructorDecl(isMoveConstructor(), isExplicit(),
+ unless(isDeleted()))
+  .bind("move-ctor")),
+  has(cxxConstructorDecl(isCopyConstructor(), unless(isDeleted()))
+  .bind("copy-ctor"))),
+  this);
+}
+
+void ExplicitMoveConstructorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MoveCtor =
+  Result.Nodes.getNodeAs("move-ctor");
+  const auto *CopyCtor =
+  Result.Nodes.getNodeAs("copy-ctor");
+
+  if (!MoveCtor || !CopyCtor)
+return;
+
+  auto Diag =
+  diag(MoveCtor->getLocation(),
+   "copy constructor may be called instead of move constructor");
+  SourceRange ExplicitTokenRange =
+  findExplicitToken(MoveCtor, *Result.SourceManager, getLangOpts());
+
+  if (ExplicitTokenRange.isInvalid())
+return;
+
+  Diag << FixItHint::CreateRemoval(
+  CharSourceRange::getCharRange(ExplicitTokenRange));
+}
+
+} // namespace clang::tidy::performance
diff --git 
a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h 
b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
new file mode 100644
index 00..9ae071a20a9eef
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
@@ -0,0 +1,33 @@
+//===--- ExplicitMoveConstructorCheck.h - clang-tidy *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===---

[clang-tools-extra] [clang-tidy] Add `performance-explicit-move-constructor` check (PR #122599)

2025-01-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: dodicidodici (dodicidodici)


Changes

This patch adds a check that reports classes that define an explicit move 
constructor and a copy constructor.
Closes #121707 

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


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/performance/CMakeLists.txt (+1) 
- (added) 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp (+73) 
- (added) 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h (+33) 
- (modified) clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp 
(+3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/performance/explicit-move-constructor.rst
 (+33) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/performance/explicit-move-constructor.cpp
 (+34) 


``diff
diff --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index c6e547c5089fb0..07f4e84b00bb3e 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
 add_clang_library(clangTidyPerformanceModule STATIC
   AvoidEndlCheck.cpp
   EnumSizeCheck.cpp
+  ExplicitMoveConstructorCheck.cpp
   FasterStringFindCheck.cpp
   ForRangeCopyCheck.cpp
   ImplicitConversionInLoopCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
new file mode 100644
index 00..94f9cebae69506
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
@@ -0,0 +1,73 @@
+//===--- ExplicitMoveConstructorCheck.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 "ExplicitMoveConstructorCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+static SourceRange findExplicitToken(const CXXConstructorDecl *Ctor,
+ const SourceManager &Source,
+ const LangOptions &LangOpts) {
+  SourceLocation CurrentLoc = Ctor->getBeginLoc();
+  SourceLocation EndLoc = Ctor->getEndLoc();
+  Token Tok;
+
+  do {
+const bool failed = Lexer::getRawToken(CurrentLoc, Tok, Source, LangOpts);
+
+if (failed)
+  return {};
+
+if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "explicit")
+  return {Tok.getLocation(), Tok.getEndLoc()};
+
+CurrentLoc = Tok.getEndLoc();
+  } while (Tok.isNot(tok::eof) && CurrentLoc < EndLoc);
+
+  return {};
+}
+
+void ExplicitMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxRecordDecl(
+  has(cxxConstructorDecl(isMoveConstructor(), isExplicit(),
+ unless(isDeleted()))
+  .bind("move-ctor")),
+  has(cxxConstructorDecl(isCopyConstructor(), unless(isDeleted()))
+  .bind("copy-ctor"))),
+  this);
+}
+
+void ExplicitMoveConstructorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MoveCtor =
+  Result.Nodes.getNodeAs("move-ctor");
+  const auto *CopyCtor =
+  Result.Nodes.getNodeAs("copy-ctor");
+
+  if (!MoveCtor || !CopyCtor)
+return;
+
+  auto Diag =
+  diag(MoveCtor->getLocation(),
+   "copy constructor may be called instead of move constructor");
+  SourceRange ExplicitTokenRange =
+  findExplicitToken(MoveCtor, *Result.SourceManager, getLangOpts());
+
+  if (ExplicitTokenRange.isInvalid())
+return;
+
+  Diag << FixItHint::CreateRemoval(
+  CharSourceRange::getCharRange(ExplicitTokenRange));
+}
+
+} // namespace clang::tidy::performance
diff --git 
a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h 
b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
new file mode 100644
index 00..9ae071a20a9eef
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
@@ -0,0 +1,33 @@
+//===--- ExplicitMoveConstructorCheck.h - clang-tidy *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--

[clang-tools-extra] [clang-tidy] Add `performance-explicit-move-constructor` check (PR #122599)

2025-01-11 Thread via cfe-commits

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


[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-01-11 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] [clang-tidy] remove never used IgnoreCase in option (PR #122573)

2025-01-11 Thread Piotr Zegar via cfe-commits

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

LGTM

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


[clang] [libclang] Add API to query more information about base classes. (PR #120300)

2025-01-11 Thread Jannick Kremer via cfe-commits

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

Re Python: LGTM!

On a sidenote just fyi, there's no need to amend & forcepush when you adress 
review comments. I know the contributor guide says something about how you 
should have only a single commit when submitting a patch, but that goes only 
for the initial thing (I got confused by this at the start). We squash on merge 
anyways. 

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


[clang] [Clang][NFC] Fix a test failure with mold linker (PR #122587)

2025-01-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/122587

Mold prefers the suffix '$' for symbols like PLT and GOT entries, so exclude 
these symbols as well. Otherwise, this test will fail for developers using 
mold-linked Clang.


>From 19467fe0e48abfe85003ebf80e29a37da853f4e0 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sat, 11 Jan 2025 17:01:16 +0800
Subject: [PATCH] [Clang][NFC] Fix a test failure with mold linker

Mold prefers the suffix '$' for symbols like PLT and GOT entries,
so exclude these symbols as well. Otherwise, this test will fail
for developers using mold-linked Clang
---
 clang/test/LibClang/symbols.test | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/LibClang/symbols.test b/clang/test/LibClang/symbols.test
index fd2ff8bc6cd423..e12b4c9991b811 100644
--- a/clang/test/LibClang/symbols.test
+++ b/clang/test/LibClang/symbols.test
@@ -1,6 +1,6 @@
 # Check that there are no unversioned clang symbols in libclang.so
 RUN: llvm-nm -Dj --defined-only %libclang | grep -v -e '@@LLVM_[0-9]\+$' | not 
grep '^clang'
 
-# Check that here are no local clang_ symbols (ignoring symbols with .cold or
+# Check that there are no local clang_ symbols (ignoring symbols with .cold or
 # .localalias suffxies.)
-RUN: llvm-nm %libclang | not grep '[a-z] clang_[^.]\+$'
+RUN: llvm-nm %libclang | not grep '[a-z] clang_[^.$]\+$'

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-11 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-11 Thread Piotr Zegar via cfe-commits


@@ -301,6 +301,11 @@ Changes in existing checks
   ` check to fix a
   crash when a class is declared but not defined.
 
+- Improved :doc:`modernize-use-integer-sign-comparison
+  ` check to
+  add an option ``ConsideringIntegerSize``, that ignores a comparison between

PiotrZSL wrote:

Consider something in this style:
Improved XYZ check to ignore comparisons between signed wide and unsigned 
narrow integer types, configurable via the `ConsideringIntegerSize` option.

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-11 Thread Piotr Zegar via cfe-commits

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

Few small nits, but functionally ok.

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-11 Thread Piotr Zegar via cfe-commits


@@ -126,6 +126,14 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-uncaught-exceptions");
 CheckFactories.registerCheck("modernize-use-using");
   }
+
+  ClangTidyOptions getModuleOptions() override {
+ClangTidyOptions Options;
+Options.CheckOptions
+["modernize-use-integer-sign-comparison.ConsideringIntegerSize"] =
+"true";
+return Options;
+  }

PiotrZSL wrote:

remove, this is not need as this option is already set in constructor of a check
```suggestion
```

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


[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-11 Thread Piotr Zegar via cfe-commits


@@ -34,3 +34,7 @@ Options
 
   A string specifying which include-style is used, `llvm` or `google`.
   Default is `llvm`.
+
+.. option:: ConsideringIntegerSize
+  Ignores a comparison between a signed wide and an unsigned narrow

PiotrZSL wrote:

i think there should be empty line after option.

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


[clang] [analyzer] Widen loops: Augment assignment note when values invalidated at the start of a loop (PR #122398)

2025-01-11 Thread Balazs Benics via cfe-commits

steakhal wrote:

> I agree that it would make more sense to generalize this beyond loop 
> widening. However, I'm having a hard time understanding how your proposal 
> would fit in to the augmentation of the assignment message like I do in this 
> PR.
> 
> The part I'm most confused about is how would `SymbolInvalidationArtifact` be 
> set/retrieved after invalidation occurs? Would this somehow be tied to 
> symbols created as part of invalidation (like created conjured symbols in 
> `InvalidateRegionsWorker::VisitCluster`) which could then be retrieved via 
> `SI.Value.getAsSymbol()` and casting (speaking from the PoV of 
> `showBRDiagnostics`)? I think I would better understand if you could please 
> provide a small example in the context of diagnostic output. I'm fairly 
> certain I'm lacking understanding of some static analysis design concept 
> that's not making this click in my head...
> 
> Regardless, once I have a better understanding of how your proposal fits in, 
> I'd be happy to give your approach a try with your guidance :).

Let me explain.
So far, in the visitor you want to know if the value of something *before* and 
*after* some invalidation event. In your case you are interested in 
loop-widening invalidations.
So, once you have all these, you formulate a decision if you should add an 
extra note in the BRVisitor.

This is nice and all, but there are a couple of problems with it:
 - Tightly couples the specific invalidation event (loop widening) because you 
had to add a special tag for the node. For other kinds of invalidations we may 
not have a tag, such as manual invalidations using 
`ProgramState::invalidateRegions`. This makes piggibacking on an ProgramPoint 
tag a less elegant solution.
 - You need to do the digging yourself for the values before and after the 
invalidation.

What I proposed in the linked RFC was to have SymExpr kind for representing the 
value of a symbol after some invalidation. It would have everything inside what 
we might need. The value before and after the invalidation (possibly even the 
states themselves), the kind of the invalidation, such as loop-widening or 
anything else.


In the visitor, it would simplify your code to:
```c++
if (const auto *Invalidation = 
dyn_cast_or_null(SI.Value.getAsSymbol())) {
  if (isa(Invalidation->getCause())) {
OS << " (loop-widening invalidated this symbol here)";
  }
}
```

To be transparent, what you do makes sense. Given that this would only affect 
configs explicitly enabling the experimental loop widening, I'm also okay with 
some less elegant solutions of course.

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


[clang-tools-extra] 32bcd41 - [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max (#122296)

2025-01-11 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-01-11T18:48:39+08:00
New Revision: 32bcd41adcc664f6d690efc9b7cd209ac9c65f68

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

LOG: [clang-tidy] use correct template type in ``std::min`` and ``std::max`` 
when operand is integer literal for readability-use-std-min-max (#122296)

When comparing with integer literal, integer promote will happen to
promote type which has less bit width than int to int or unsigned int.
It will let auto-fix provide correct but out of expected fix.

e.g.
```c++
short a;
if ( a > 10 )
  a = 10;
```
will be
```c++
short a;
if ( (int)a > 10 )
  a = (short)10;
```

which will be fixed as
```c++
short a;
a = std::max(a, 10);
```

but actually it can be
```c++
short a;
a = std::max(a, 10);
```

Fixed: #121676

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
index 179173502a8d01..6f6b8a853a91e0 100644
--- a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp
@@ -79,6 +79,27 @@ static QualType getNonTemplateAlias(QualType QT) {
   return QT;
 }
 
+static QualType getReplacementCastType(const Expr *CondLhs, const Expr 
*CondRhs,
+   QualType ComparedType) {
+  QualType LhsType = CondLhs->getType();
+  QualType RhsType = CondRhs->getType();
+  QualType LhsCanonicalType =
+  LhsType.getCanonicalType().getNonReferenceType().getUnqualifiedType();
+  QualType RhsCanonicalType =
+  RhsType.getCanonicalType().getNonReferenceType().getUnqualifiedType();
+  QualType GlobalImplicitCastType;
+  if (LhsCanonicalType != RhsCanonicalType) {
+if (llvm::isa(CondRhs)) {
+  GlobalImplicitCastType = getNonTemplateAlias(LhsType);
+} else if (llvm::isa(CondLhs)) {
+  GlobalImplicitCastType = getNonTemplateAlias(RhsType);
+} else {
+  GlobalImplicitCastType = getNonTemplateAlias(ComparedType);
+}
+  }
+  return GlobalImplicitCastType;
+}
+
 static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs,
  const Expr *AssignLhs,
  const SourceManager &Source,
@@ -92,18 +113,8 @@ static std::string createReplacement(const Expr *CondLhs, 
const Expr *CondRhs,
   const llvm::StringRef AssignLhsStr = Lexer::getSourceText(
   Source.getExpansionRange(AssignLhs->getSourceRange()), Source, LO);
 
-  QualType GlobalImplicitCastType;
-  QualType LhsType = CondLhs->getType()
- .getCanonicalType()
- .getNonReferenceType()
- .getUnqualifiedType();
-  QualType RhsType = CondRhs->getType()
- .getCanonicalType()
- .getNonReferenceType()
- .getUnqualifiedType();
-  if (LhsType != RhsType) {
-GlobalImplicitCastType = getNonTemplateAlias(BO->getLHS()->getType());
-  }
+  QualType GlobalImplicitCastType =
+  getReplacementCastType(CondLhs, CondRhs, BO->getLHS()->getType());
 
   return (AssignLhsStr + " = " + FunctionName +
   (!GlobalImplicitCastType.isNull()

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 9cdad8fb6b58f2..d75a276729c581 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -369,6 +369,10 @@ Changes in existing checks
   ` check to
   remove `->`, when redundant `get()` is removed.
 
+- Improved :doc:`readability-use-std-min-max
+  ` check to use correct 
template
+  type in ``std::min`` and ``std::max`` when operand is integer literal.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp
index 9c0e2eabda348d..35ade8a7c6d37e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp
@@ -252,3 +252,24 @@ void testVectorSizeType() {
   if (value < v.size())
 value = v.size();
 }
+
+namespace gh121676 {
+
+void useLeft() {
+  using U16 = unsigned short;
+  U16 I = 0;
+  // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::max` instead of `<` 
[readability-use-std-min-max]
+  // CHECK-FIXES: I = std::max(I, 16U);
+  if (I < 16U)
+I = 16U;
+}
+void useRight() {
+  using U16 = unsigned

[clang-tools-extra] [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max (PR #122296)

2025-01-11 Thread Congcong Cai via cfe-commits

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


[clang] [clang] fix wrong result of pointers comparison between unknown and stack (PR #122404)

2025-01-11 Thread Balazs Benics via cfe-commits

steakhal wrote:

My current stance is that we should have the memoryspace trait only for 
memregions that have an UnknownSpace memspace, becuase that would be the least 
amount of work. So it would be a hybrid solution.
We have the memspaces as we have today, but for UnknownSpace you would need to 
query the trait if we have more accurate memspace that we somehow inferred.

Basically the contract would be:
Two memregions have the same memspace, if they compare equal, or if any was 
UnknownSpace, then do a lookup in the helper trait to see if we have anything 
for the region. If we do, just use that associated memspace instead of the 
UnknowSpace. Do the same for the other memregion before comparing them.

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


[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-01-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/122423

>From d40a80859eafe96bdc99957db2aebb70db407e67 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 10 Jan 2025 09:46:24 +0800
Subject: [PATCH 1/4] Reapply "[Clang] Implement CWG2369 "Ordering between
 constraints and substitution"" (#122130)

This reverts commit 3972ed57088f6515b787d7d38dec03dc74e51827.
---
 clang/include/clang/Sema/Sema.h   |  22 +++-
 clang/include/clang/Sema/Template.h   |   6 +
 clang/lib/Sema/SemaConcept.cpp|  47 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  49 +---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp |   8 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 115 --
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/CXX/drs/cwg23xx.cpp|  29 +
 clang/test/CXX/drs/cwg26xx.cpp|   2 +-
 clang/test/CXX/drs/cwg27xx.cpp|  20 +++
 .../expr.prim.req/nested-requirement.cpp  |   2 +-
 .../constrant-satisfaction-conversions.cpp|   6 +-
 .../SemaCXX/concept-crash-on-diagnostic.cpp   |   2 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |   2 +-
 clang/test/SemaCXX/cxx23-assume.cpp   |   6 +-
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp   |   2 +-
 clang/test/SemaCXX/lambda-unevaluated.cpp |   4 +-
 .../SemaTemplate/concepts-recursive-inst.cpp  |   4 +-
 .../SemaTemplate/cxx2a-constraint-exprs.cpp   |   2 +-
 clang/test/SemaTemplate/deduction-guide.cpp   |   5 -
 .../nested-implicit-deduction-guides.cpp  |   8 +-
 clang/www/cxx_dr_status.html  |   8 +-
 22 files changed, 289 insertions(+), 62 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a41f16f6dc8c9b..18fd95f77ec227 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13062,6 +13062,7 @@ class Sema final : public SemaBase {
   ///
   /// \param SkipForSpecialization when specified, any template specializations
   /// in a traversal would be ignored.
+  ///
   /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
   /// when encountering a specialized member function template, rather than
   /// returning immediately.
@@ -13073,6 +13074,17 @@ class Sema final : public SemaBase {
   bool SkipForSpecialization = false,
   bool ForDefaultArgumentSubstitution = false);
 
+  /// Apart from storing the result to \p Result, this behaves the same as
+  /// another overload.
+  void getTemplateInstantiationArgs(
+  MultiLevelTemplateArgumentList &Result, const NamedDecl *D,
+  const DeclContext *DC = nullptr, bool Final = false,
+  std::optional> Innermost = std::nullopt,
+  bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
+  bool ForConstraintInstantiation = false,
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
+
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
   class SynthesizedFunctionScope {
@@ -13342,7 +13354,7 @@ class Sema final : public SemaBase {
   ExprResult
   SubstConstraintExpr(Expr *E,
   const MultiLevelTemplateArgumentList &TemplateArgs);
-  // Unlike the above, this does not evaluates constraints.
+  // Unlike the above, this does not evaluate constraints.
   ExprResult SubstConstraintExprWithoutSatisfaction(
   Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs);
 
@@ -14463,10 +14475,10 @@ class Sema final : public SemaBase {
   const MultiLevelTemplateArgumentList &TemplateArgs,
   SourceRange TemplateIDRange);
 
-  bool CheckInstantiatedFunctionTemplateConstraints(
-  SourceLocation PointOfInstantiation, FunctionDecl *Decl,
-  ArrayRef TemplateArgs,
-  ConstraintSatisfaction &Satisfaction);
+  bool CheckFunctionTemplateConstraints(SourceLocation PointOfInstantiation,
+FunctionDecl *Decl,
+ArrayRef 
TemplateArgs,
+ConstraintSatisfaction &Satisfaction);
 
   /// \brief Emit diagnostics explaining why a constraint expression was deemed
   /// unsatisfied.
diff --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 9800f75f676aaf..59a0575ca98036 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -522,6 +522,12 @@ enum class TemplateSubstitutionKind : char {
 llvm::PointerUnion *
 findInstantiationOf(const Decl *D);
 
+/// Similar to \p findInstantiationOf(), but it wouldn't assert if the
+/// instantiation was not found within the current instantiation scope. 
This
+/// is helpful for on-demand declaration instantiation.
+llvm::PointerUnion *
+findInstantiationUnsafe(const Decl *D);
+
 void InstantiatedLocal(const Decl *D, Decl *Inst

[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2025-01-11 Thread via cfe-commits

https://github.com/leijurv updated 
https://github.com/llvm/llvm-project/pull/118046

>From 1caf823165b16f6701993d586df51d5cdbf0885e Mon Sep 17 00:00:00 2001
From: Leijurv 
Date: Fri, 29 Nov 2024 21:54:36 -0600
Subject: [PATCH 1/5] [clang-format] Add BreakBeforeTemplateClose option

---
 clang/docs/ClangFormatStyleOptions.rst |  21 
 clang/docs/ReleaseNotes.rst|   1 +
 clang/include/clang/Format/Format.h|  20 
 clang/lib/Format/ContinuationIndenter.cpp  |  11 ++
 clang/lib/Format/ContinuationIndenter.h|  26 ++--
 clang/lib/Format/Format.cpp|   2 +
 clang/lib/Format/TokenAnnotator.cpp|   2 +-
 clang/unittests/Format/ConfigParseTest.cpp |   1 +
 clang/unittests/Format/FormatTest.cpp  | 131 +
 9 files changed, 206 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4be448171699ca..84ab1b0a2eff61 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3416,6 +3416,27 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _BreakBeforeTemplateClose:
+
+**BreakBeforeTemplateClose** (``Boolean``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  If ``true``, a line break will be placed before the ``>`` in a multiline
+  template declaration.
+
+  .. code-block:: c++
+
+ true:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz
+ >
+
+ false:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz>
+
 .. _BreakBeforeTernaryOperators:
 
 **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e44aefa90ab386..867d4b5d8c3f18 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -976,6 +976,7 @@ clang-format
   ``Never``, and ``true`` to ``Always``.
 - Adds ``RemoveEmptyLinesInUnwrappedLines`` option.
 - Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style.
+- Adds ``BreakBeforeTemplateClose`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..bffd964f6aa8aa 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2248,6 +2248,25 @@ struct FormatStyle {
   /// \version 16
   BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
 
+  /// If ``true``, a line break will be placed before the ``>`` in a multiline
+  /// template declaration.
+  /// \code
+  ///true:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz
+  ///>
+  ///
+  ///false:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz>
+  /// \endcode
+  /// \version 20
+  bool BreakBeforeTemplateClose;
+
   /// If ``true``, ternary operators will be placed after line breaks.
   /// \code
   ///true:
@@ -5184,6 +5203,7 @@ struct FormatStyle {
BreakBeforeBraces == R.BreakBeforeBraces &&
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations 
&&
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
+   BreakBeforeTemplateClose == R.BreakBeforeTemplateClose &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
BreakBinaryOperations == R.BreakBinaryOperations &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index aed86c1fb99551..4c783623afc535 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -406,6 +406,10 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   }
   if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
+  if (CurrentState.BreakBeforeClosingAngle &&
+  Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose) {
+return true;
+  }
   if (Style.Language == FormatStyle::LK_ObjC &&
   Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&
@@ -1234,6 +1238,9 @@ unsigned 
ContinuationIndenter::addTokenOnNewLine(LineState &State,
 Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
   }
 
+  if (PreviousNonComment && PreviousNonComment->is(tok::less))
+CurrentState.BreakBeforeClosingAngle = true;
+
   if (CurrentState.AvoidBinPacking) {
 // If we are breaking after '(', '{', '<', or this is the break after a ':'
 // to start a member initializer list in a constructor, this should not
@@ -1370,6 +1377,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   State.Stack.size() > 1) {
 return State.Stack[State.Stack.size() - 2].Last

[clang-tools-extra] [clang-tidy] Fix modernize-use-integer-sign-comparison comparison (PR #121506)

2025-01-11 Thread Piotr Zegar via cfe-commits


@@ -80,16 +80,19 @@ 
UseIntegerSignComparisonCheck::UseIntegerSignComparisonCheck(
 : ClangTidyCheck(Name, Context),
   IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
utils::IncludeSorter::IS_LLVM),
-  areDiagsSelfContained()) {}
+  areDiagsSelfContained()),
+  ConsideringIntSize(Options.get("ConsideringIntegerSize", true)) {}

PiotrZSL wrote:

use more straightforward option name, like "CheckIntegerSize" or something 
similar.
I just dont like how this "Considering" sounds in context of an option, even 
"Consider" would sound better.

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


[clang-tools-extra] [clang-tidy] fix incorrect configuration file path resolving when file paths contain `..` (PR #121323)

2025-01-11 Thread Piotr Zegar via cfe-commits


@@ -117,6 +117,9 @@ Improvements to clang-tidy
 
 - Improved :program:`clang-tidy` by accepting parameters file in command line.
 
+- Improved :program:`clang-tidy` by fixing incorrect configuration file path

PiotrZSL wrote:

Note: to be honest all those 'Improved' release notes for same program could be 
merged together

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


[clang-tools-extra] 30bb186 - [clang-tidy] Mention std::forward_list in container-size-empty doc (#120701)

2025-01-11 Thread via cfe-commits

Author: Niels Dekker
Date: 2025-01-11T10:15:17+01:00
New Revision: 30bb1863892a235fe1d90eb6b496bd24b0c177d8

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

LOG: [clang-tidy] Mention std::forward_list in container-size-empty doc 
(#120701)

Mentioned `std::forward_list` as example of a container without
`size()`.

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h

clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
index 3aa4bdc496194b..e449686f77566d 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h
@@ -19,10 +19,10 @@ namespace clang::tidy::readability {
 ///
 /// The emptiness of a container should be checked using the `empty()` method
 /// instead of the `size()`/`length()` method. It shows clearer intent to use
-/// `empty()`. Furthermore some containers may implement the `empty()` method
-/// but not implement the `size()` or `length()` method. Using `empty()`
-/// whenever possible makes it easier to switch to another container in the
-/// future.
+/// `empty()`. Furthermore some containers (for example, a `std::forward_list`)
+/// may implement the `empty()` method but not implement the `size()` or
+/// `length()` method. Using `empty()` whenever possible makes it easier to
+/// switch to another container in the future.
 class ContainerSizeEmptyCheck : public ClangTidyCheck {
 public:
   ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context);

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
index 6a007f69767abe..43ad74f60dbe57 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst
@@ -9,9 +9,10 @@ with a call to ``empty()``.
 
 The emptiness of a container should be checked using the ``empty()`` method
 instead of the ``size()``/``length()`` method. It shows clearer intent to use
-``empty()``. Furthermore some containers may implement the ``empty()`` method
-but not implement the ``size()`` or ``length()`` method. Using ``empty()``
-whenever possible makes it easier to switch to another container in the future.
+``empty()``. Furthermore some containers (for example, a ``std::forward_list``)
+may implement the ``empty()`` method but not implement the ``size()`` or
+``length()`` method. Using ``empty()`` whenever possible makes it easier to
+switch to another container in the future.
 
 The check issues warning if a container has ``empty()`` and ``size()`` or
 ``length()`` methods matching following signatures:



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


[clang-tools-extra] [clang-tidy] fix incorrect configuration file path resolving when file paths contain `..` (PR #121323)

2025-01-11 Thread Piotr Zegar via cfe-commits

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

Functionally ok.

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


[clang-tools-extra] [clang-tidy] Mention std::forward_list in container-size-empty doc (PR #120701)

2025-01-11 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add `performance-explicit-move-constructor` check (PR #122599)

2025-01-11 Thread via cfe-commits

https://github.com/dodicidodici created 
https://github.com/llvm/llvm-project/pull/122599

This patch adds a check that reports classes that define an explicit move 
constructor and a copy constructor.
Closes #121707 

>From 2f1627ee62c041d98cbc51b08aebf2dd2dbe5455 Mon Sep 17 00:00:00 2001
From: dodicidodici 
Date: Fri, 10 Jan 2025 19:05:09 +0100
Subject: [PATCH 1/5] add `performance-explicit-move-constructor` check

---
 .../ExplicitMoveConstructorCheck.cpp  | 72 +++
 .../ExplicitMoveConstructorCheck.h| 33 +
 2 files changed, 105 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h

diff --git 
a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
new file mode 100644
index 00..631ed363566c65
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp
@@ -0,0 +1,72 @@
+//===--- ExplicitMoveConstructorCheck.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 "ExplicitMoveConstructorCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::performance {
+
+static SourceRange findExplicitToken(const CXXConstructorDecl *Ctor,
+ const SourceManager &Source,
+ const LangOptions &LangOpts) {
+  SourceLocation CurrentLoc = Ctor->getBeginLoc();
+  SourceLocation EndLoc = Ctor->getEndLoc();
+  Token Tok;
+
+  do {
+const bool failed = Lexer::getRawToken(CurrentLoc, Tok, Source, LangOpts);
+
+if (failed)
+  return {};
+
+if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "explicit")
+  return {Tok.getLocation(), Tok.getEndLoc()};
+
+CurrentLoc = Tok.getEndLoc();
+  } while (Tok.isNot(tok::eof) && CurrentLoc < EndLoc);
+
+  return {};
+}
+
+void ExplicitMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxRecordDecl(
+  has(cxxConstructorDecl(isMoveConstructor(), isExplicit())
+  .bind("move-ctor")),
+  has(cxxConstructorDecl(isCopyConstructor(), unless(isDeleted()))
+  .bind("copy-ctor"))),
+  this);
+}
+
+void ExplicitMoveConstructorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *MoveCtor =
+  Result.Nodes.getNodeAs("move-ctor");
+  const auto *CopyCtor =
+  Result.Nodes.getNodeAs("copy-ctor");
+
+  if (!MoveCtor || !CopyCtor)
+return;
+
+  auto Diag = diag(
+  MoveCtor->getLocation(),
+  "copy constructor may be called instead of explicit move constructor");
+  SourceRange ExplicitTokenRange =
+  findExplicitToken(MoveCtor, *Result.SourceManager, getLangOpts());
+
+  if (ExplicitTokenRange.isInvalid())
+return;
+
+  Diag << FixItHint::CreateRemoval(
+  CharSourceRange::getCharRange(ExplicitTokenRange));
+}
+
+} // namespace clang::tidy::performance
diff --git 
a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h 
b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
new file mode 100644
index 00..9ae071a20a9eef
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
@@ -0,0 +1,33 @@
+//===--- ExplicitMoveConstructorCheck.h - clang-tidy *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_EXPLICITMOVECONSTRUCTORCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_EXPLICITMOVECONSTRUCTORCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::performance {
+
+/// Find classes that define an explicit move constructor and a (non-deleted) 
copy constructor.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/performance/explicit-move-constructor.html
+class ExplicitMoveConstructorCheck : public ClangTidyCheck {
+public:
+  ExplicitMoveConstructorCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Resu

[clang-tools-extra] [clang-tidy] Add `performance-explicit-move-constructor` check (PR #122599)

2025-01-11 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/122599
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Warn when using msan on Android (PR #122540)

2025-01-11 Thread Thurston Dang via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Add `performance-explicit-move-constructor` check (PR #122599)

2025-01-11 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 ac604b2fa6ff0344a555954069721c0db7b874f9 
828461273ea7ac1d38a4d3fe1ff8b810f80472e9 --extensions h,cpp -- 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.cpp 
clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h 
clang-tools-extra/test/clang-tidy/checkers/performance/explicit-move-constructor.cpp
 clang-tools-extra/clang-tidy/performance/PerformanceTidyModule.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h 
b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
index 9ae071a20a..a41304aca0 100644
--- a/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/ExplicitMoveConstructorCheck.h
@@ -13,7 +13,8 @@
 
 namespace clang::tidy::performance {
 
-/// Find classes that define an explicit move constructor and a (non-deleted) 
copy constructor.
+/// Find classes that define an explicit move constructor and a (non-deleted)
+/// copy constructor.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/performance/explicit-move-constructor.html

``




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


[clang-tools-extra] [clang-tidy] Address false positives in misc-redundant-expression checker (PR #121960)

2025-01-11 Thread Piotr Zegar via cfe-commits


@@ -852,6 +877,58 @@ static bool areExprsMacroAndNonMacro(const Expr *&LhsExpr,
 
   return LhsLoc.isMacroID() != RhsLoc.isMacroID();
 }
+
+static bool areExprsSameMacroOrLiteral(const BinaryOperator *BinOp,
+   const ASTContext *Context) {
+
+  if (!BinOp)
+return false;
+
+  const auto *Lhs = BinOp->getLHS();
+  const auto *Rhs = BinOp->getRHS();
+  const SourceManager &SM = Context->getSourceManager();
+
+  SourceRange Lsr = Lhs->getSourceRange();
+  SourceRange Rsr = Rhs->getSourceRange();
+  if (Lsr.getBegin().isMacroID()) {
+// Left is macro so right macro too
+if (Rsr.getBegin().isMacroID()) {
+  // Both sides are macros so they are same macro or literal
+  llvm::StringRef L = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Lsr), SM, LangOptions(), 0);
+  llvm::StringRef R = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(Rsr), SM, LangOptions(), 0);
+  return L.compare(R) == 0;

PiotrZSL wrote:

what with
```
#define getX(x) x
int var = getX(1) > getX( 1);
```

In such case string compare won't work.

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


[clang-tools-extra] [clang-tidy] Address false positives in misc-redundant-expression checker (PR #121960)

2025-01-11 Thread Piotr Zegar via cfe-commits


@@ -747,6 +747,31 @@ static bool areSidesBinaryConstExpressions(const 
BinaryOperator *&BinOp, const A
   return false;
 }
 
+static bool
+areSidesBinaryConstExpressionsOrDefines(const BinaryOperator *&BinOp,
+const ASTContext *AstCtx) {
+  if (areSidesBinaryConstExpressions(BinOp, AstCtx))
+return true;
+
+  const auto *Lhs = BinOp->getLHS();
+  const auto *Rhs = BinOp->getRHS();
+
+  if (!Lhs || !Rhs)
+return false;
+
+  auto IsDefineExpr = [AstCtx](const Expr *E) {
+SourceRange Lsr = E->getSourceRange();
+if (!Lsr.getBegin().isMacroID() || E->isValueDependent() ||
+!E->isIntegerConstantExpr(*AstCtx))
+  return false;
+return true;
+  };
+
+  if (IsDefineExpr(Lhs) || IsDefineExpr(Rhs))
+return true;
+  return false;

PiotrZSL wrote:

```suggestion
  return IsDefineExpr(Lhs) || IsDefineExpr(Rhs);
```

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


[clang-tools-extra] [clang-tidy] Address false positives in misc-redundant-expression checker (PR #121960)

2025-01-11 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Address false positives in misc-redundant-expression checker (PR #121960)

2025-01-11 Thread Piotr Zegar via cfe-commits

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

Overall, may require some small work to make sure that code is straightforward 
and simple.
As for functionality part, still has some gaps or redundant parts, but that is 
not a blocker.

Please try to refactor your changes to be simpler, like function names to 
actually say what they doing.
Missing changes in release notes and check documentation

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


[clang] [Clang][NFC] Fix a test failure with mold linker (PR #122587)

2025-01-11 Thread Younan Zhang via cfe-commits

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


[clang] [Clang][NFC] Fix a test failure with mold linker (PR #122587)

2025-01-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

Mold prefers the suffix '$' for symbols like PLT and GOT entries, so exclude 
these symbols as well. Otherwise, this test will fail for developers using 
mold-linked Clang.

Closes https://github.com/llvm/llvm-project/issues/76982


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


1 Files Affected:

- (modified) clang/test/LibClang/symbols.test (+2-2) 


``diff
diff --git a/clang/test/LibClang/symbols.test b/clang/test/LibClang/symbols.test
index fd2ff8bc6cd423..e12b4c9991b811 100644
--- a/clang/test/LibClang/symbols.test
+++ b/clang/test/LibClang/symbols.test
@@ -1,6 +1,6 @@
 # Check that there are no unversioned clang symbols in libclang.so
 RUN: llvm-nm -Dj --defined-only %libclang | grep -v -e '@@LLVM_[0-9]\+$' | not 
grep '^clang'
 
-# Check that here are no local clang_ symbols (ignoring symbols with .cold or
+# Check that there are no local clang_ symbols (ignoring symbols with .cold or
 # .localalias suffxies.)
-RUN: llvm-nm %libclang | not grep '[a-z] clang_[^.]\+$'
+RUN: llvm-nm %libclang | not grep '[a-z] clang_[^.$]\+$'

``




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


[clang-tools-extra] [clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck (PR #109741)

2025-01-11 Thread Piotr Zegar via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck (PR #109741)

2025-01-11 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck (PR #109741)

2025-01-11 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

> Actually, shouldn't this check instead change an explicit cast for a 
> `CXXParenListExpr` from `static_cast(42)` to `C(42)`

Yes, but that's secondary. As in such case this could be seen as an 
FunctionalCast.



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


[clang-tools-extra] dc2963c - [clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck (#109741)

2025-01-11 Thread via cfe-commits

Author: Tommy Chen
Date: 2025-01-11T11:04:19+01:00
New Revision: dc2963c8d77229ca1b20663beddef2323cc69a88

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

LOG: [clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck 
(#109741)

Exclude CXXParenListInitExpr from RedundantCastingCheck because there
are false positive cases. Currently, we can't think of positive cases
for CXXParenListInitExpr. This can be improved by following the
initListExpr method if we can come up with some positive cases.

Fixes #108846

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
index 4d5adbe02f5256..768540e05c7597 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp
@@ -108,6 +108,10 @@ void RedundantCastingCheck::registerMatchers(MatchFinder 
*Finder) {
 
   auto BitfieldMemberExpr = memberExpr(member(fieldDecl(isBitField(;
 
+  const ast_matchers::internal::VariadicDynCastAllOfMatcher<
+  Stmt, CXXParenListInitExpr>
+  cxxParenListInitExpr; // NOLINT(readability-identifier-naming)
+
   Finder->addMatcher(
   explicitCastExpr(
   unless(hasCastKind(CK_ConstructorConversion)),
@@ -117,6 +121,7 @@ void RedundantCastingCheck::registerMatchers(MatchFinder 
*Finder) {
   hasDestinationType(qualType().bind("dstType")),
   hasSourceExpression(anyOf(
   expr(unless(initListExpr()), unless(BitfieldMemberExpr),
+   unless(cxxParenListInitExpr()),
hasType(qualType().bind("srcType")))
   .bind("source"),
   initListExpr(unless(hasInit(1, expr())),

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 684ba77d8f0f53..9cdad8fb6b58f2 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -360,6 +360,11 @@ Changes in existing checks
   case of the literal suffix in fixes and fixing false positive for implicit
   conversion of comparison result in C23.
 
+- Improved :doc:`readability-redundant-casting
+  ` check
+  by addressing a false positive in aggregate initialization through
+  parenthesized list.
+
 - Improved :doc:`readability-redundant-smartptr-get
   ` check to
   remove `->`, when redundant `get()` is removed.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
index 30cac6bd5cca06..9c3c90bfaf4595 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-casting.cpp
@@ -1,10 +1,18 @@
-// RUN: %check_clang_tidy -std=c++11-or-later %s readability-redundant-casting 
%t -- -- -fno-delayed-template-parsing
-// RUN: %check_clang_tidy -std=c++11-or-later -check-suffix=,MACROS %s 
readability-redundant-casting %t -- \
+// RUN: %check_clang_tidy -std=c++11,c++14,c++17 %s 
readability-redundant-casting %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++11,c++14,c++17 -check-suffix=,MACROS %s 
readability-redundant-casting %t -- \
 // RUN:   -config='{CheckOptions: { 
readability-redundant-casting.IgnoreMacros: false }}' \
 // RUN:   -- -fno-delayed-template-parsing
-// RUN: %check_clang_tidy -std=c++11-or-later -check-suffix=,ALIASES %s 
readability-redundant-casting %t -- \
+// RUN: %check_clang_tidy -std=c++11,c++14,c++17 -check-suffix=,ALIASES %s 
readability-redundant-casting %t -- \
 // RUN:   -config='{CheckOptions: { 
readability-redundant-casting.IgnoreTypeAliases: true }}' \
 // RUN:   -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++20 %s readability-redundant-casting %t -- \
+// RUN:   -- -fno-delayed-template-parsing -D CXX_20=1
+// RUN: %check_clang_tidy -std=c++20 -check-suffix=,MACROS %s 
readability-redundant-casting %t -- \
+// RUN:   -config='{CheckOptions: { 
readability-redundant-casting.IgnoreMacros: false }}' \
+// RUN:   -- -fno-delayed-template-parsing -D CXX_20=1
+// RUN: %check_clang_tidy -std=c++20 -check-suffix=,ALIASES %s 
readability-redundant-casting %t -- \
+// RUN:   -config='{CheckOptions: { 
readability-redundant-casting.IgnoreTypeAliases: true }}' \
+// RUN:   -- -fno-delayed-template-parsing -D CXX_20=1
 
 struct A {};
 struct B : A {};
@@ -57,6 +65,12 @@ void testDiffren

[clang-tools-extra] [clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck (PR #109741)

2025-01-11 Thread via cfe-commits

github-actions[bot] wrote:



@dl8sd11 Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang-tools-extra] [clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck (PR #109741)

2025-01-11 Thread Piotr Zegar via cfe-commits

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


[clang] [Clang][NFC] Fix a test failure with mold linker (PR #122587)

2025-01-11 Thread via cfe-commits

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


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


[clang] a3e62d8 - [AST] Fix a warning

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

Author: Kazu Hirata
Date: 2025-01-11T00:11:42-08:00
New Revision: a3e62d849f07d1e55e6d15465f4f3842ff4b3717

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

LOG: [AST] Fix a warning

This patch fixes:

  clang/unittests/AST/ASTImporterTest.cpp:3397:9: error: unused
  variable 'ToTU' [-Werror,-Wunused-variable]

Added: 


Modified: 
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index ef76ee80d7c7b1..f2bfde9bed3725 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -3394,7 +3394,6 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportBitfields) {
   ASSERT_TRUE(FromF->isBitField());
   ASSERT_EQ(3u, FromF->getBitWidthValue());
   auto *ToField = Import(FromF, Lang_CXX03);
-  auto *ToTU = ToField->getTranslationUnitDecl();
 
   EXPECT_TRUE(ToField->isBitField());
   EXPECT_EQ(3u, ToField->getBitWidthValue());



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


[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-01-11 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/122423

>From d40a80859eafe96bdc99957db2aebb70db407e67 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 10 Jan 2025 09:46:24 +0800
Subject: [PATCH 1/3] Reapply "[Clang] Implement CWG2369 "Ordering between
 constraints and substitution"" (#122130)

This reverts commit 3972ed57088f6515b787d7d38dec03dc74e51827.
---
 clang/include/clang/Sema/Sema.h   |  22 +++-
 clang/include/clang/Sema/Template.h   |   6 +
 clang/lib/Sema/SemaConcept.cpp|  47 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  49 +---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp |   8 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 115 --
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/CXX/drs/cwg23xx.cpp|  29 +
 clang/test/CXX/drs/cwg26xx.cpp|   2 +-
 clang/test/CXX/drs/cwg27xx.cpp|  20 +++
 .../expr.prim.req/nested-requirement.cpp  |   2 +-
 .../constrant-satisfaction-conversions.cpp|   6 +-
 .../SemaCXX/concept-crash-on-diagnostic.cpp   |   2 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |   2 +-
 clang/test/SemaCXX/cxx23-assume.cpp   |   6 +-
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp   |   2 +-
 clang/test/SemaCXX/lambda-unevaluated.cpp |   4 +-
 .../SemaTemplate/concepts-recursive-inst.cpp  |   4 +-
 .../SemaTemplate/cxx2a-constraint-exprs.cpp   |   2 +-
 clang/test/SemaTemplate/deduction-guide.cpp   |   5 -
 .../nested-implicit-deduction-guides.cpp  |   8 +-
 clang/www/cxx_dr_status.html  |   8 +-
 22 files changed, 289 insertions(+), 62 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a41f16f6dc8c9b..18fd95f77ec227 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13062,6 +13062,7 @@ class Sema final : public SemaBase {
   ///
   /// \param SkipForSpecialization when specified, any template specializations
   /// in a traversal would be ignored.
+  ///
   /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
   /// when encountering a specialized member function template, rather than
   /// returning immediately.
@@ -13073,6 +13074,17 @@ class Sema final : public SemaBase {
   bool SkipForSpecialization = false,
   bool ForDefaultArgumentSubstitution = false);
 
+  /// Apart from storing the result to \p Result, this behaves the same as
+  /// another overload.
+  void getTemplateInstantiationArgs(
+  MultiLevelTemplateArgumentList &Result, const NamedDecl *D,
+  const DeclContext *DC = nullptr, bool Final = false,
+  std::optional> Innermost = std::nullopt,
+  bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
+  bool ForConstraintInstantiation = false,
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
+
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
   class SynthesizedFunctionScope {
@@ -13342,7 +13354,7 @@ class Sema final : public SemaBase {
   ExprResult
   SubstConstraintExpr(Expr *E,
   const MultiLevelTemplateArgumentList &TemplateArgs);
-  // Unlike the above, this does not evaluates constraints.
+  // Unlike the above, this does not evaluate constraints.
   ExprResult SubstConstraintExprWithoutSatisfaction(
   Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs);
 
@@ -14463,10 +14475,10 @@ class Sema final : public SemaBase {
   const MultiLevelTemplateArgumentList &TemplateArgs,
   SourceRange TemplateIDRange);
 
-  bool CheckInstantiatedFunctionTemplateConstraints(
-  SourceLocation PointOfInstantiation, FunctionDecl *Decl,
-  ArrayRef TemplateArgs,
-  ConstraintSatisfaction &Satisfaction);
+  bool CheckFunctionTemplateConstraints(SourceLocation PointOfInstantiation,
+FunctionDecl *Decl,
+ArrayRef 
TemplateArgs,
+ConstraintSatisfaction &Satisfaction);
 
   /// \brief Emit diagnostics explaining why a constraint expression was deemed
   /// unsatisfied.
diff --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 9800f75f676aaf..59a0575ca98036 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -522,6 +522,12 @@ enum class TemplateSubstitutionKind : char {
 llvm::PointerUnion *
 findInstantiationOf(const Decl *D);
 
+/// Similar to \p findInstantiationOf(), but it wouldn't assert if the
+/// instantiation was not found within the current instantiation scope. 
This
+/// is helpful for on-demand declaration instantiation.
+llvm::PointerUnion *
+findInstantiationUnsafe(const Decl *D);
+
 void InstantiatedLocal(const Decl *D, Decl *Inst

[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-01-11 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max (PR #122296)

2025-01-11 Thread Piotr Zegar via cfe-commits

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

LGTM.


https://github.com/llvm/llvm-project/pull/122296
___
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 a release note about unchecked-optional-access smart pointer caching (PR #122290)

2025-01-11 Thread Piotr Zegar via cfe-commits


@@ -232,6 +232,10 @@ Changes in existing checks
   ` to support
   `bsl::optional` and `bdlb::NullableValue` from
   _.
+  Fixed false positives from smart pointer accessors repeated in checking
+  ``has_value`` and accessing ``value``, by caching the locations returned
+  by the accessors. The option `IgnoreSmartPointerDereference` should no
+  longer be needed.

PiotrZSL wrote:

"The option `IgnoreSmartPointerDereference` should no longer be needed."
If option is not needed, they maybe could be removed, if still got use outside 
of mentioned scenario, then maybe just say that it no longer needed to cover 
this scenario.

https://github.com/llvm/llvm-project/pull/122290
___
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 a release note about unchecked-optional-access smart pointer caching (PR #122290)

2025-01-11 Thread Piotr Zegar via cfe-commits


@@ -81,10 +81,12 @@ Exception: accessor methods
 
 The check assumes *accessor* methods of a class are stable, with a heuristic to
 determine which methods are accessors. Specifically, parameter-free ``const``
-methods are treated as accessors. Note that this is not guaranteed to be safe
--- but, it is widely used (safely) in practice, and so we have chosen to treat
-it as generally safe. Calls to non ``const`` methods are assumed to modify
-the state of the object and affect the stability of earlier accessor calls.
+methods and smart pointer-like APIs (non ``const`` overloads of ``*`` when
+there is a parallel ``const`` overload) are treated as accessors. Note that
+this is not guaranteed to be safe -- but, it is widely used (safely) in
+practice, and so we have chosen to treat it as generally safe. Calls to non

PiotrZSL wrote:

would be good to remove that " and so we have chosen" when you changing this 
anyway.
Simply to write documentation in a 3th party mode.

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2025-01-11 Thread via cfe-commits

leijurv wrote:

Thank you for the review @owenca 

> I think this should be covered by BlockIndent

My understanding from looking at past PRs to clang-format was that backwards 
compatibility was a top requirement. If I changed the behavior of BlockIndent 
to put the `>` on the next line, that would change a lot of existing 
behavior/codebases/tests.

> Call verifyFormat instead of verifyNoChange whenever possible.

I understand, but, I am testing the case where ColumnLimit = 0. When I call 
`verifyFormat` it removes all the newlines. So I was unable to test the 
behavior in the unconstrained column limit case. Note how I test that you can 
have a `\n` after the `template<`, or not, and this option doesn't force it 
either way.

In the later part of the tests, starting when I change the ColumnLimit to 40, 
note that all of the tests are `verifyFormat` and I don't use `verifyNoChange` 
anymore.

I have removed a few `verifyNoChange` in my last commit.

> Don't end a test case with a newline.
> Capitalize the first word of a comment and end the comment with a . (or : if 
> appropriate).

Sure! Did so in this commit 
https://github.com/llvm/llvm-project/pull/118046/commits/19bc40e7d824804ebcd9839cb2155a704d368e36

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


[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #122588)

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

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/122588

None

>From 7b2b5230116779c07db74056eba6618fdea7f910 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 11 Jan 2025 01:11:22 -0800
Subject: [PATCH] [Sema] Avoid repeated hash lookups (NFC)

---
 clang/lib/Sema/SemaDecl.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8724c20fd7b652..5b7275c316f74a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15868,8 +15868,8 @@ static void diagnoseImplicitlyRetainedSelf(Sema &S) {
   llvm::DenseMap EscapeInfo;
 
   auto IsOrNestedInEscapingBlock = [&](const BlockDecl *BD) {
-if (EscapeInfo.count(BD))
-  return EscapeInfo[BD];
+if (auto It = EscapeInfo.find(BD); It != EscapeInfo.end())
+  return It->second;
 
 bool R = false;
 const BlockDecl *CurBD = BD;

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


[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #122588)

2025-01-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/Sema/SemaDecl.cpp (+2-2) 


``diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8724c20fd7b652..5b7275c316f74a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15868,8 +15868,8 @@ static void diagnoseImplicitlyRetainedSelf(Sema &S) {
   llvm::DenseMap EscapeInfo;
 
   auto IsOrNestedInEscapingBlock = [&](const BlockDecl *BD) {
-if (EscapeInfo.count(BD))
-  return EscapeInfo[BD];
+if (auto It = EscapeInfo.find(BD); It != EscapeInfo.end())
+  return It->second;
 
 bool R = false;
 const BlockDecl *CurBD = BD;

``




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


[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #122588)

2025-01-11 Thread Nikita Popov via cfe-commits

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


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


[clang] [Driver] Warn when using msan on Android (PR #122540)

2025-01-11 Thread Sharjeel Khan via cfe-commits

https://github.com/Sharjeel-Khan updated 
https://github.com/llvm/llvm-project/pull/122540

>From c8d2c210a98fe0c96d758d538d50fcc0ca61a9ff Mon Sep 17 00:00:00 2001
From: Sharjeel Khan 
Date: Fri, 10 Jan 2025 20:07:52 +
Subject: [PATCH 1/3] Warn when using msan on Android

Msan is not supported on Android as mentioned in google/sanitizers#1381.
We proactively give the warning saying it is unsupported to fix 
android/ndk#1958.
---
 clang/lib/Driver/SanitizerArgs.cpp | 10 ++
 clang/test/Driver/fsanitize.c  |  5 +
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index a0d6919c6dc8d0..04b39d29e7342f 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -530,6 +530,16 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   }
   Add &= Supported;
 
+  // Msan is not supported on Android
+  if ((Add & SanitizerKind::Memory) && TC.getTriple().isAndroid()) {
+if (DiagnoseErrors) {
+  D.Diag(diag::warn_drv_unsupported_option_for_target)
+  << "-fsanitize=memory" << Triple.str();
+}
+DiagnosedKinds |= SanitizerKind::Memory;
+Add &= ~SanitizerKind::Memory;
+  }
+
   // Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups
   // so we don't error out if -fno-rtti and -fsanitize=undefined were
   // passed.
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 1d3caec748d77a..55b51ed29b0e65 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -399,6 +399,11 @@
 // RUN: %clang --target=arm-linux-androideabi %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-ANDROID-NO-ASAN
 // CHECK-ANDROID-NO-ASAN: "-mrelocation-model" "pic"
 
+// RUN: %clang --target=aarch64-linux-android -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
+// RUN: %clang --target=i386-linux-android -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
+// RUN: %clang --target=x86_64-linux-android -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN-ANDROID
+// CHECK-MSAN-ANDROID: ignoring '-fsanitize=memory' option as it is not 
currently supported for target
+
 // RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN
 // RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined 
-fsanitize-recover -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-UBSAN
 // RUN: %clang --target=x86_64-linux-gnu %s -fsanitize=undefined 
-fsanitize-recover=all -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-RECOVER-UBSAN

>From 035c7d9936a33926ccca10d9670879d3b913496e Mon Sep 17 00:00:00 2001
From: Sharjeel Khan 
Date: Fri, 10 Jan 2025 22:31:33 +
Subject: [PATCH 2/3] Fixed format for SanitizerArgs

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

diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 04b39d29e7342f..25bfd5eadae8c9 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -534,7 +534,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   if ((Add & SanitizerKind::Memory) && TC.getTriple().isAndroid()) {
 if (DiagnoseErrors) {
   D.Diag(diag::warn_drv_unsupported_option_for_target)
-  << "-fsanitize=memory" << Triple.str();
+  << "-fsanitize=memory" << Triple.str();
 }
 DiagnosedKinds |= SanitizerKind::Memory;
 Add &= ~SanitizerKind::Memory;

>From 3e42b05457a735365ef8e17c4da8e8d3a530c607 Mon Sep 17 00:00:00 2001
From: Sharjeel Khan 
Date: Sat, 11 Jan 2025 20:50:28 +
Subject: [PATCH 3/3] Move the check into Linux.cpp

---
 clang/lib/Driver/SanitizerArgs.cpp| 10 --
 clang/lib/Driver/ToolChains/Linux.cpp |  4 +++-
 clang/test/Driver/fsanitize.c |  8 
 3 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 25bfd5eadae8c9..a0d6919c6dc8d0 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -530,16 +530,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   }
   Add &= Supported;
 
-  // Msan is not supported on Android
-  if ((Add & SanitizerKind::Memory) && TC.getTriple().isAndroid()) {
-if (DiagnoseErrors) {
-  D.Diag(diag::warn_drv_unsupported_option_for_target)
-  << "-fsanitize=memory" << Triple.str();
-}
-DiagnosedKinds |= SanitizerKind::Memory;
-Add &= ~SanitizerKind::Memory;
-  }
-
   // Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups
   // so we don't error out if -fno-rtti and -fsanitize=undefined were
   // passed.
diff --git a/clang/lib/Driver/ToolChains/Li

[clang-tools-extra] 2c7829e - [clang-tidy][doc] combine the clang-tidy itself's change together in release note (#122594)

2025-01-11 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-01-12T06:48:46+08:00
New Revision: 2c7829e676dfd6a33f7c9955ea930f51aca37e20

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

LOG: [clang-tidy][doc] combine the clang-tidy itself's change together in 
release note (#122594)

https://github.com/user-attachments/assets/25433743-2c19-422a-93c5-3edfc1bb7a3f";
/>

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 835a0269a2733c..5c7ba4333e3816 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -108,22 +108,19 @@ Improvements to clang-query
 Improvements to clang-tidy
 --
 
-- Improved :program:`clang-tidy`'s `--verify-config` flag by adding support for
-  the configuration options of the `Clang Static Analyzer Checks
-  `_.
-
-- Improved :program:`clang-tidy` by accepting parameters file in command line.
-
 - Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise
   happening on certain platforms when interrupting the script.
 
-- Improved :program:`clang-tidy` by fixing incorrect configuration file path
-  resolving when file paths contain ``..``.
+- Improved :program:`clang-tidy`:
 
-- Removed :program:`clang-tidy`'s global options for most of checks. All 
options
-  are changed to local options except `IncludeStyle`, `StrictMode` and
-  `IgnoreMacros`. Global scoped `StrictMode` and `IgnoreMacros` are deprecated
-  and will be removed in further releases.
+  - add support for `--verify-config` flag to check the configuration options 
of
+the `Clang Static Analyzer Checks 
`_.
+  - accept parameters file in command line.
+  - fix incorrect configuration file path resolving when file paths contain 
``..``.
+  - remove global options for most of checks. All options are changed to local
+options except `IncludeStyle`, `StrictMode` and `IgnoreMacros`. Global 
scoped
+`StrictMode` and `IgnoreMacros` are deprecated and will be removed in 
further
+releases.
 
 .. csv-table::
   :header: "Check", "Options removed from global option"



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


[clang-tools-extra] [clang-tidy][doc] combine the clang-tidy itself's change together in release note (PR #122594)

2025-01-11 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy][doc] combine the clang-tidy itself's change together in release note (PR #122594)

2025-01-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve-vls` 
running on `linaro-g3-04` while building `clang-tools-extra` at step 6 "build 
stage 1".

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


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

```
Step 6 (build stage 1) failure: 'ninja' (failure)
...
[1718/2034] Building CXX object 
tools/mlir/test/lib/Dialect/Test/CMakeFiles/MLIRTestDialect.dir/TestOps.17.cpp.o
[1719/2034] Building CXX object 
tools/mlir/test/lib/Dialect/Test/CMakeFiles/MLIRTestDialect.dir/TestOps.19.cpp.o
[1720/2034] Building CXX object 
tools/mlir/test/lib/Dialect/Transform/CMakeFiles/MLIRTestTransformDialect.dir/TestTransformDialectExtension.cpp.o
[1721/2034] Linking CXX static library lib/libclangSema.a
[1722/2034] Linking CXX static library lib/libMLIRVectorTestPasses.a
[1723/2034] Linking CXX static library lib/libMLIRTestTransformDialect.a
[1724/2034] Building CXX object 
tools/mlir/test/lib/Dialect/Test/CMakeFiles/MLIRTestDialect.dir/TestOps.16.cpp.o
[1725/2034] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/PrivateReductionUtils.cpp.o
[1726/2034] Linking CXX executable bin/mlir-cpu-runner
[1727/2034] Building CXX object 
tools/mlir/test/lib/Dialect/Test/CMakeFiles/MLIRTestDialect.dir/TestPatterns.cpp.o
command timed out: 1200 seconds without output running [b'ninja'], attempting 
to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1715.428081

```



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


[clang-tools-extra] [clang-tidy][doc] combine the clang-tidy itself's change together in release note (PR #122594)

2025-01-11 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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


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-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 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: 85831 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 
FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/MachO_weak_references.s (52397 of 
85831)
 TEST 'LLVM :: 
ExecutionEngine/JITLink/x86-64/MachO_weak_references.s' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: rm -rf 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
 && mkdir -p 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
+ rm -rf 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
+ mkdir -p 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
RUN: at line 2: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc
 -triple=x86_64-apple-macosx10.9 -filetype=obj -o 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc
 -triple=x86_64-apple-macosx10.9 -filetype=obj -o 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
RUN: at line 3: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-jitlink
 -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 
-check=/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-jitlink
 -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 
-check=/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/J

[clang] [Clang] disallow the use of asterisks preceding constructor and destructor names (PR #122621)

2025-01-11 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/122621

Fixes #121706

>From b2c656afdf99eff52d019b68fcbbc6ce4bbdd7d3 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 12 Jan 2025 00:51:47 +0200
Subject: [PATCH] [Clang] disallow the use of asterisks preceding constructor
 and destructor names

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  4 
 clang/lib/Sema/SemaDeclCXX.cpp   | 13 +
 clang/test/SemaCXX/constructor.cpp   | 10 ++
 clang/test/SemaCXX/destructor.cpp|  7 +++
 5 files changed, 35 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 197b3692b8a181..9e5bbbf6dc055a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -764,6 +764,7 @@ Improvements to Clang's diagnostics
   scope.Unlock();
   require(scope); // Warning!  Requires mu1.
 }
+- Clang now disallows the use of asterisks preceding constructor and 
destructor names (#GH121706).
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d4e897868f1a9a..ec0be4ea8b6ce0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2202,6 +2202,8 @@ def err_invalid_qualified_constructor : Error<
   "'%0' qualifier is not allowed on a constructor">;
 def err_ref_qualifier_constructor : Error<
   "ref-qualifier '%select{&&|&}0' is not allowed on a constructor">;
+def err_invalid_constructor_decl : Error<
+  "invalid constructor declaration">;
 
 def err_constructor_return_type : Error<
   "constructor cannot have a return type">;
@@ -2223,6 +2225,8 @@ def err_destructor_not_member : Error<
 def err_destructor_cannot_be : Error<"destructor cannot be declared '%0'">;
 def err_invalid_qualified_destructor : Error<
   "'%0' qualifier is not allowed on a destructor">;
+def err_invalid_destructor_decl : Error<
+  "invalid destructor declaration">;
 def err_ref_qualifier_destructor : Error<
   "ref-qualifier '%select{&&|&}0' is not allowed on a destructor">;
 def err_destructor_return_type : Error<"destructor cannot have a return type">;
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c4bee44f5ec048..bb6f6e14713d9b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10757,6 +10757,17 @@ static void checkMethodTypeQualifiers(Sema &S, 
Declarator &D, unsigned DiagID) {
   }
 }
 
+static void checkMethodPointerType(Sema &S, Declarator &D, unsigned DiagID) {
+  if (D.getNumTypeObjects() > 0) {
+DeclaratorChunk &Chunk = D.getTypeObject(D.getNumTypeObjects() - 1);
+if (Chunk.Kind == DeclaratorChunk::Pointer) {
+  SourceLocation PointerLoc = Chunk.getSourceRange().getBegin();
+  S.Diag(PointerLoc, DiagID) << Chunk.getSourceRange();
+  D.setInvalidType();
+}
+  }
+}
+
 QualType Sema::CheckConstructorDeclarator(Declarator &D, QualType R,
   StorageClass &SC) {
   bool isVirtual = D.getDeclSpec().isVirtualSpecified();
@@ -10792,6 +10803,7 @@ QualType Sema::CheckConstructorDeclarator(Declarator 
&D, QualType R,
   }
 
   checkMethodTypeQualifiers(*this, D, diag::err_invalid_qualified_constructor);
+  checkMethodPointerType(*this, D, diag::err_invalid_constructor_decl);
 
   // C++0x [class.ctor]p4:
   //   A constructor shall not be declared with a ref-qualifier.
@@ -10958,6 +10970,7 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D, 
QualType R,
   }
 
   checkMethodTypeQualifiers(*this, D, diag::err_invalid_qualified_destructor);
+  checkMethodPointerType(*this, D, diag::err_invalid_destructor_decl);
 
   // C++0x [class.dtor]p2:
   //   A destructor shall not be declared with a ref-qualifier.
diff --git a/clang/test/SemaCXX/constructor.cpp 
b/clang/test/SemaCXX/constructor.cpp
index abd7dbe18a0e6a..c6df7be25c1fac 100644
--- a/clang/test/SemaCXX/constructor.cpp
+++ b/clang/test/SemaCXX/constructor.cpp
@@ -96,3 +96,13 @@ namespace PR38286 {
   template struct C; // expected-note {{non-type declaration found}}
   template C::~C() {} // expected-error {{identifier 'C' after 
'~' in destructor name does not name a type}}
 }
+
+namespace GH121706 {
+struct S {
+  *S();  // expected-error {{invalid constructor declaration}}
+  **S(); // expected-error {{invalid constructor declaration}}
+
+  **S(const S &); // expected-error {{invalid constructor declaration}}
+  *S(S &&);   // expected-error {{invalid constructor declaration}}
+};
+}
diff --git a/clang/test/SemaCXX/destructor.cpp 
b/clang/test/SemaCXX/destructor.cpp
index dfcd1b033af5a2..f188e95c25d174 100644
--- a/clang/test/SemaCXX/destructor.cpp
+++ b/clang/test/SemaCXX/destructor.cpp
@@ -586,4 +586,11 @@ struct Y : X {} y1{ }; // expe

[clang] [Clang] disallow the use of asterisks preceding constructor and destructor names (PR #122621)

2025-01-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #121706

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


5 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+13) 
- (modified) clang/test/SemaCXX/constructor.cpp (+10) 
- (modified) clang/test/SemaCXX/destructor.cpp (+7) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 197b3692b8a181..9e5bbbf6dc055a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -764,6 +764,7 @@ Improvements to Clang's diagnostics
   scope.Unlock();
   require(scope); // Warning!  Requires mu1.
 }
+- Clang now disallows the use of asterisks preceding constructor and 
destructor names (#GH121706).
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d4e897868f1a9a..ec0be4ea8b6ce0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2202,6 +2202,8 @@ def err_invalid_qualified_constructor : Error<
   "'%0' qualifier is not allowed on a constructor">;
 def err_ref_qualifier_constructor : Error<
   "ref-qualifier '%select{&&|&}0' is not allowed on a constructor">;
+def err_invalid_constructor_decl : Error<
+  "invalid constructor declaration">;
 
 def err_constructor_return_type : Error<
   "constructor cannot have a return type">;
@@ -2223,6 +2225,8 @@ def err_destructor_not_member : Error<
 def err_destructor_cannot_be : Error<"destructor cannot be declared '%0'">;
 def err_invalid_qualified_destructor : Error<
   "'%0' qualifier is not allowed on a destructor">;
+def err_invalid_destructor_decl : Error<
+  "invalid destructor declaration">;
 def err_ref_qualifier_destructor : Error<
   "ref-qualifier '%select{&&|&}0' is not allowed on a destructor">;
 def err_destructor_return_type : Error<"destructor cannot have a return type">;
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c4bee44f5ec048..bb6f6e14713d9b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10757,6 +10757,17 @@ static void checkMethodTypeQualifiers(Sema &S, 
Declarator &D, unsigned DiagID) {
   }
 }
 
+static void checkMethodPointerType(Sema &S, Declarator &D, unsigned DiagID) {
+  if (D.getNumTypeObjects() > 0) {
+DeclaratorChunk &Chunk = D.getTypeObject(D.getNumTypeObjects() - 1);
+if (Chunk.Kind == DeclaratorChunk::Pointer) {
+  SourceLocation PointerLoc = Chunk.getSourceRange().getBegin();
+  S.Diag(PointerLoc, DiagID) << Chunk.getSourceRange();
+  D.setInvalidType();
+}
+  }
+}
+
 QualType Sema::CheckConstructorDeclarator(Declarator &D, QualType R,
   StorageClass &SC) {
   bool isVirtual = D.getDeclSpec().isVirtualSpecified();
@@ -10792,6 +10803,7 @@ QualType Sema::CheckConstructorDeclarator(Declarator 
&D, QualType R,
   }
 
   checkMethodTypeQualifiers(*this, D, diag::err_invalid_qualified_constructor);
+  checkMethodPointerType(*this, D, diag::err_invalid_constructor_decl);
 
   // C++0x [class.ctor]p4:
   //   A constructor shall not be declared with a ref-qualifier.
@@ -10958,6 +10970,7 @@ QualType Sema::CheckDestructorDeclarator(Declarator &D, 
QualType R,
   }
 
   checkMethodTypeQualifiers(*this, D, diag::err_invalid_qualified_destructor);
+  checkMethodPointerType(*this, D, diag::err_invalid_destructor_decl);
 
   // C++0x [class.dtor]p2:
   //   A destructor shall not be declared with a ref-qualifier.
diff --git a/clang/test/SemaCXX/constructor.cpp 
b/clang/test/SemaCXX/constructor.cpp
index abd7dbe18a0e6a..c6df7be25c1fac 100644
--- a/clang/test/SemaCXX/constructor.cpp
+++ b/clang/test/SemaCXX/constructor.cpp
@@ -96,3 +96,13 @@ namespace PR38286 {
   template struct C; // expected-note {{non-type declaration found}}
   template C::~C() {} // expected-error {{identifier 'C' after 
'~' in destructor name does not name a type}}
 }
+
+namespace GH121706 {
+struct S {
+  *S();  // expected-error {{invalid constructor declaration}}
+  **S(); // expected-error {{invalid constructor declaration}}
+
+  **S(const S &); // expected-error {{invalid constructor declaration}}
+  *S(S &&);   // expected-error {{invalid constructor declaration}}
+};
+}
diff --git a/clang/test/SemaCXX/destructor.cpp 
b/clang/test/SemaCXX/destructor.cpp
index dfcd1b033af5a2..f188e95c25d174 100644
--- a/clang/test/SemaCXX/destructor.cpp
+++ b/clang/test/SemaCXX/destructor.cpp
@@ -586,4 +586,11 @@ struct Y : X {} y1{ }; // expected-error {{call to 
implicitly-deleted default co
// expected-note {{default constructor of 'Y' is 
implicitly deleted because base class 'X' has no destructor}}
 }
 
+namesp

[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-01-11 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

@mysterymath @zmodem Can you both test this patch on Windows to confirm if it 
resolves issues you've reported? We'd greatly appreciate it!


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


[clang] [Clang] Use `-targets=host-x86_64-unknown-linux-gnu` as bundler target (PR #122627)

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

https://github.com/shiltian created 
https://github.com/llvm/llvm-project/pull/122627

This a prime patch to support generic target when using `--offload-compress`.

>From 95332e05f381f7e80cd1c57420db0c56cf8aedcf Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Sat, 11 Jan 2025 21:24:53 -0500
Subject: [PATCH] [Clang] Use `-targets=host-x86_64-unknown-linux-gnu` as
 bundler target

This a prime patch to support generic target when using `--offload-compress`.
---
 clang/lib/Driver/ToolChains/HIPUtility.cpp|  2 +-
 clang/test/Driver/cuda-arch-translation.cu| 34 +--
 clang/test/Driver/hip-code-object-version.hip |  8 ++---
 clang/test/Driver/hip-target-id.hip   |  6 ++--
 clang/test/Driver/hipspv-toolchain.hip|  2 +-
 clang/test/Driver/linker-wrapper.c|  8 ++---
 .../ClangLinkerWrapper.cpp|  2 +-
 7 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index 3f81c3cb0f80e8..bfb6ec7a010583 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -291,7 +291,7 @@ void HIP::constructHIPFatbinCommand(Compilation &C, const 
JobAction &JA,
 
   // ToDo: Remove the dummy host binary entry which is required by
   // clang-offload-bundler.
-  std::string BundlerTargetArg = "-targets=host-x86_64-unknown-linux";
+  std::string BundlerTargetArg = "-targets=host-x86_64-unknown-linux-gnu";
   // AMDGCN:
   // For code object version 2 and 3, the offload kind in bundle ID is 'hip'
   // for backward compatibility. For code object version 4 and greater, the
diff --git a/clang/test/Driver/cuda-arch-translation.cu 
b/clang/test/Driver/cuda-arch-translation.cu
index a0ae16452692bf..e4f83740a92ebd 100644
--- a/clang/test/Driver/cuda-arch-translation.cu
+++ b/clang/test/Driver/cuda-arch-translation.cu
@@ -81,20 +81,20 @@
 // SM61:--image=profile=sm_61{{.*}}
 // SM62:--image=profile=sm_62{{.*}}
 // SM70:--image=profile=sm_70{{.*}}
-// GFX600:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx600
-// GFX601:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx601
-// GFX602:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx602
-// GFX700:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx700
-// GFX701:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx701
-// GFX702:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx702
-// GFX703:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx703
-// GFX704:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx704
-// GFX705:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx705
-// GFX801:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx801
-// GFX802:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx802
-// GFX803:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx803
-// GFX805:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx805
-// GFX810:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx810
-// GFX900:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx900
-// GFX902:-targets=host-x86_64-unknown-linux,hipv4-amdgcn-amd-amdhsa--gfx902
-// SPIRV:-targets=host-x86_64-unknown-linux,hip-spirv64-amd-amdhsa--amdgcnspirv
+// 
GFX600:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx600
+// 
GFX601:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx601
+// 
GFX602:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx602
+// 
GFX700:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx700
+// 
GFX701:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx701
+// 
GFX702:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx702
+// 
GFX703:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx703
+// 
GFX704:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx704
+// 
GFX705:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx705
+// 
GFX801:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx801
+// 
GFX802:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx802
+// 
GFX803:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx803
+// 
GFX805:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx805
+// 
GFX810:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx810
+// 
GFX900:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx900
+// 
GFX902:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx902
+// 
SPIRV:-targets=host-x86_64-unknown-linux-gnu,hip-spirv64-amd-amdhsa--amdgcnspirv
diff --git a/clang/test/Driver/hip-code-object-version.hip 
b/clang/test/Driver/hip-code-object-version.hip
index 9d0afaeaa967d3..30d8644dff54c6 100644
--- a/clang/test/Driver/hip-code-object-vers

[clang] [Clang] Use `-targets=host-x86_64-unknown-linux-gnu` as bundler target (PR #122627)

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

shiltian wrote:

* **#122627** https://app.graphite.dev/github/pr/llvm/llvm-project/122627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/122627?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[clang] [Driver] Avoid repeated map lookups (NFC) (PR #122625)

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

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


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


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

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


@@ -4493,13 +4493,11 @@ struct FormatStyle {
   bool SpaceBeforeRangeBasedForLoopColon;
 
   /// If ``true``, spaces will be inserted into ``{}``.
-  /// \code
-  ///true:false:
-  ///void f() { }   vs.   void f() {}
-  ///while (true) { } while (true) {}
-  /// \endcode
+  /// This option is **deprecated**. The previous behavior is preserved by 
using
+  /// ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  /// ``SpaceInEmptyBracesOptions`` to ``true``.
   /// \version 10
-  bool SpaceInEmptyBlock;
+  // bool SpaceInEmptyBlock;

owenca wrote:

> I was reviewing this PR and running into some issues related to 
> https://reviews.llvm.org/D68415. I felt that we had to bite the bullet and 
> add a new boolean option like the author did initially.

Actually, we might be able to support the following:
- Always (`WebKit` default)
- Block (`LLVM` default, which would deprecate `SpaceInEmptyBlock`)
- Leave (to be implemented in this patch or a follow-up patch)
- Never (ditto)

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


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

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

owenca wrote:

> rebased but still required to be tested and fix again

See https://github.com/llvm/llvm-project/pull/93634#discussion_r1912374181.

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2025-01-11 Thread via cfe-commits

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2025-01-11 Thread via cfe-commits

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

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


@@ -2252,6 +2252,25 @@ struct FormatStyle {
   /// \version 16
   BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
 
+  /// If ``true``, a line break will be placed before the ``>`` in a multiline
+  /// template declaration.
+  /// \code
+  ///true:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz
+  ///>
+  ///
+  ///false:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz>
+  /// \endcode
+  /// \version 20
+  bool BreakBeforeTemplateClose;

owenca wrote:

```suggestion
  bool BreakBeforeTemplateCloser;
```

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

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


@@ -6,6 +6,275 @@ TEST_F(FormatTest, 
WrapsTemplateDeclarationsWithComments) {
   Style);
 }
 
+TEST_F(FormatTest, BreakBeforeTemplateClose) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
+  // Begin with tests covering the case where there is no constraint on the 
column limit.
+  Style.ColumnLimit = 0;
+  // When BreakBeforeTemplateClose is turned off, the line break that it adds 
shall be removed:
+  verifyFormat("template <\n"
+   "typename Foo,\n"
+   "typename Bar>\n"
+   "void foo() {}",
+   "template <\n"
+   "typename Foo,\n"
+   "typename Bar\n"
+   ">\n"
+   "void foo() {}",
+   Style);
+  Style.BreakBeforeTemplateClose = true;
+  // BreakBeforeTemplateClose should NOT force template declarations onto 
multiple lines.
+  // Use verifyNoChange since ColumnLimit = 0.
+  verifyNoChange("template \n"
+ "void foo() {}",
+ Style);
+  verifyNoChange("template \n"
+ "void foo() {}",
+ Style);
+  // It should allow a line break, even when the typename is short:
+  verifyNoChange("template <\n"
+ "typename Foo\n"
+ ">\n"
+ "void foo() {}",
+ Style);
+  verifyNoChange("template <\n"
+ "typename Foo,\n"
+ "typename Bar\n"
+ ">\n"
+ "void foo() {}",
+ Style);
+  // It should add a line break before > if not already present:
+  verifyFormat("template <\n"
+   "typename Foo\n"
+   ">\n"
+   "void foo() {}",
+   "template <\n"
+   "typename Foo>\n"
+   "void foo() {}",
+   Style);
+  verifyFormat("template <\n"
+   "typename Foo,\n"
+   "typename Bar\n"
+   ">\n"
+   "void foo() {}",
+   "template <\n"
+   "typename Foo,\n"
+   "typename Bar>\n"
+   "void foo() {}",
+   Style);
+  // When within an indent scope, the > should be placed accordingly:
+  verifyFormat("struct Baz {\n"
+   "  template <\n"
+   "  typename Foo,\n"
+   "  typename Bar\n"
+   "  >\n"
+   "  void foo() {}\n"
+   "};",
+   "struct Baz {\n"
+   "  template <\n"
+   "  typename Foo,\n"
+   "  typename Bar>\n"
+   "  void foo() {}\n"
+   "};",
+   Style);
+
+  // Test from issue #80049:
+  verifyFormat(
+  "void foo() {\n"
+  "  using type = std::remove_cv_t<\n"
+  "  add_common_cv_reference<\n"
+  "  std::common_type_t, std::decay_t>,\n"
+  "  T0,\n"
+  "  T1\n"
+  "  >\n"
+  "  >;\n"
+  "}",
+  "void foo() {\n"
+  "  using type = std::remove_cv_t<\n"
+  "  add_common_cv_reference<\n"
+  "  std::common_type_t, std::decay_t>,\n"
+  "  T0,\n"
+  "  T1>>;\n"
+  "}",
+  Style);
+
+  // Test lambda goes to next line:
+  verifyFormat("void foo() {\n"
+   "  auto lambda = []<\n"
+   "typename T\n"
+   ">(T t) {\n"
+   "  };\n"
+   "}",
+   "void foo() {\n"
+   "  auto lambda = []<\n"
+   "  typename T>(T t){\n"
+   "  };\n"
+   "}",
+   Style);
+  // With no column limit, two parameters can go on the same line:
+  verifyFormat("void foo() {\n"
+   "  auto lambda = []<\n"
+   "typename T, typename Foo\n"
+   ">(T t) {\n"
+   "  };\n"
+   "}",
+   "void foo() {\n"
+   "  auto lambda = []<\n"
+   "  typename T, typename Foo>(T t){\n"
+   "  };\n"
+   "}",
+   Style);
+  // Or on different lines:
+  verifyFormat("void foo() {\n"
+   "  auto lambda = []<\n"
+   "typename T,\n"
+   "typename Foo\n"
+   ">(T t) {\n"
+   "  };\n"
+   "}",
+   "void foo() {\n"
+   "  auto lambda = []<\n"
+   "  typename T,\n"
+   "  typename Foo>(T t){\n"
+   "  };\n"
+   "}",
+   Style);
+
+  // Note that this is the same line (no \n):
+  verifyFormat("void foo() {\n"
+   "  auto lambda = []("
+   "Long t) {};\n"
+   "}",
+   Style);
+
+  // Test template usage goes to nex

[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

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


@@ -2252,6 +2252,25 @@ struct FormatStyle {
   /// \version 16
   BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
 
+  /// If ``true``, a line break will be placed before the ``>`` in a multiline
+  /// template declaration.
+  /// \code
+  ///true:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz
+  ///>
+  ///
+  ///false:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz>

owenca wrote:

We should make it an `enum` in order to handle more cases (now or in another 
patch), e.g.:
- Always
- BlockIndent
```
template <
typename Foo, typename Bar,
typename Baz
>
```
- Leave
- Multiline
```
template 
```
- Never

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

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

https://github.com/owenca commented:

You can run `ninja clang-format-check-format` to make sure your patch is 
correctly formatted before pushing.

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

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

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


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

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

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


[clang] [Clang] Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda (PR #122611)

2025-01-11 Thread via cfe-commits

https://github.com/TilakChad updated 
https://github.com/llvm/llvm-project/pull/122611

>From 4e5935f6631f0f0cd828559ec29ed931bc0333d3 Mon Sep 17 00:00:00 2001
From: Tilak Chad 
Date: Sun, 12 Jan 2025 00:03:32 +0545
Subject: [PATCH 1/2] [Clang] Fixed a crash when __PRETTY_FUNCTION__ or
 __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda

---
 clang/lib/AST/Expr.cpp|  7 ++-
 clang/test/SemaCXX/crash-GH121274.cpp | 15 +++
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/crash-GH121274.cpp

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 5331357b5d1fef..0caff41c8a8cf6 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -774,7 +774,12 @@ std::string 
PredefinedExpr::ComputeName(PredefinedIdentKind IK,
 const FunctionDecl *Decl = FD;
 if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern())
   Decl = Pattern;
-const FunctionType *AFT = Decl->getType()->getAs();
+
+const Type *Ty = Decl->getType().getTypePtrOrNull();
+if (!Ty)
+  return "";
+
+const FunctionType *AFT = Ty->getAs();
 const FunctionProtoType *FT = nullptr;
 if (FD->hasWrittenPrototype())
   FT = dyn_cast(AFT);
diff --git a/clang/test/SemaCXX/crash-GH121274.cpp 
b/clang/test/SemaCXX/crash-GH121274.cpp
new file mode 100644
index 00..28677a0949bf9e
--- /dev/null
+++ b/clang/test/SemaCXX/crash-GH121274.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// expected-no-diagnostics
+
+// Do not crash when __PRETTY_FUNCTION__ appears in the trailing return type 
of the lambda
+void foo() {
+   []() -> decltype(static_cast(__PRETTY_FUNCTION__)) {
+   return nullptr;
+   }();
+
+#ifdef MS
+   []() -> decltype(static_cast(__FUNCSIG__)) {
+   return nullptr;
+   }();
+#endif
+}

>From cea9b5dc4b8440d738609abab93eb6fdfd0eead6 Mon Sep 17 00:00:00 2001
From: Tilak Chad 
Date: Sun, 12 Jan 2025 11:47:10 +0545
Subject: [PATCH 2/2] [Clang] Added comment and updated the clang release notes

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/AST/Expr.cpp  | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 197b3692b8a181..a14fb189c8e132 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -926,6 +926,7 @@ Bug Fixes to C++ Support
   (`LWG3929 `__.) (#GH121278)
 - Clang now identifies unexpanded parameter packs within the type constraint 
on a non-type template parameter. (#GH88866)
 - Fixed an issue while resolving type of expression indexing into a pack of 
values of non-dependent type (#GH121242)
+- Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in 
the trailing return type of the lambda (#GH121274)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 0caff41c8a8cf6..b5dfc4bfe6dcb8 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -775,6 +775,9 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind 
IK,
 if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern())
   Decl = Pattern;
 
+// The type may not be fully initialized at this point.
+// For example, in the trailing return type context of the lambda
+// expression.
 const Type *Ty = Decl->getType().getTypePtrOrNull();
 if (!Ty)
   return "";

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


[clang] [Clang] Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda (PR #122611)

2025-01-11 Thread via cfe-commits


@@ -774,7 +774,12 @@ std::string 
PredefinedExpr::ComputeName(PredefinedIdentKind IK,
 const FunctionDecl *Decl = FD;
 if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern())
   Decl = Pattern;
-const FunctionType *AFT = Decl->getType()->getAs();
+
+const Type *Ty = Decl->getType().getTypePtrOrNull();

TilakChad wrote:

Added. 

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


[clang] [Clang] Fixed a crash when __PRETTY_FUNCTION__ or __FUNCSIG__ (clang-cl) appears in the trailing return type of the lambda (PR #122611)

2025-01-11 Thread via cfe-commits

TilakChad wrote:

I've updated the release notes. Thanks for reminding and for the review. 
:smile: 

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2025-01-11 Thread via cfe-commits


@@ -2252,6 +2252,25 @@ struct FormatStyle {
   /// \version 16
   BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
 
+  /// If ``true``, a line break will be placed before the ``>`` in a multiline
+  /// template declaration.
+  /// \code
+  ///true:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz
+  ///>
+  ///
+  ///false:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz>

leijurv wrote:

In my mind that's a bit of a different option. You can see in your examples 
that you're assuming that the `>` goes on the next line, but that's what this 
PR is trying to add support for.

Like, your enum (which is totally reasonable) would switch between:

```
template <
typename Foo, typename Bar,
typename Baz
>
```

versus

```
template 
```

But what I'm currently trying to add support for is:

```
template <
typename Foo, typename Bar,
typename Baz
>

template 
```

versus

```
template <
typename Foo, typename Bar,
typename Baz>

template 
```

So I believe that should be another patch.

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


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

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

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2025-01-11 Thread via cfe-commits

https://github.com/leijurv updated 
https://github.com/llvm/llvm-project/pull/118046

>From 1caf823165b16f6701993d586df51d5cdbf0885e Mon Sep 17 00:00:00 2001
From: Leijurv 
Date: Fri, 29 Nov 2024 21:54:36 -0600
Subject: [PATCH 1/6] [clang-format] Add BreakBeforeTemplateClose option

---
 clang/docs/ClangFormatStyleOptions.rst |  21 
 clang/docs/ReleaseNotes.rst|   1 +
 clang/include/clang/Format/Format.h|  20 
 clang/lib/Format/ContinuationIndenter.cpp  |  11 ++
 clang/lib/Format/ContinuationIndenter.h|  26 ++--
 clang/lib/Format/Format.cpp|   2 +
 clang/lib/Format/TokenAnnotator.cpp|   2 +-
 clang/unittests/Format/ConfigParseTest.cpp |   1 +
 clang/unittests/Format/FormatTest.cpp  | 131 +
 9 files changed, 206 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4be448171699ca..84ab1b0a2eff61 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3416,6 +3416,27 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _BreakBeforeTemplateClose:
+
+**BreakBeforeTemplateClose** (``Boolean``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  If ``true``, a line break will be placed before the ``>`` in a multiline
+  template declaration.
+
+  .. code-block:: c++
+
+ true:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz
+ >
+
+ false:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz>
+
 .. _BreakBeforeTernaryOperators:
 
 **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e44aefa90ab386..867d4b5d8c3f18 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -976,6 +976,7 @@ clang-format
   ``Never``, and ``true`` to ``Always``.
 - Adds ``RemoveEmptyLinesInUnwrappedLines`` option.
 - Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style.
+- Adds ``BreakBeforeTemplateClose`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..bffd964f6aa8aa 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2248,6 +2248,25 @@ struct FormatStyle {
   /// \version 16
   BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
 
+  /// If ``true``, a line break will be placed before the ``>`` in a multiline
+  /// template declaration.
+  /// \code
+  ///true:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz
+  ///>
+  ///
+  ///false:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz>
+  /// \endcode
+  /// \version 20
+  bool BreakBeforeTemplateClose;
+
   /// If ``true``, ternary operators will be placed after line breaks.
   /// \code
   ///true:
@@ -5184,6 +5203,7 @@ struct FormatStyle {
BreakBeforeBraces == R.BreakBeforeBraces &&
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations 
&&
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
+   BreakBeforeTemplateClose == R.BreakBeforeTemplateClose &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
BreakBinaryOperations == R.BreakBinaryOperations &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index aed86c1fb99551..4c783623afc535 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -406,6 +406,10 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   }
   if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
+  if (CurrentState.BreakBeforeClosingAngle &&
+  Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose) {
+return true;
+  }
   if (Style.Language == FormatStyle::LK_ObjC &&
   Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&
@@ -1234,6 +1238,9 @@ unsigned 
ContinuationIndenter::addTokenOnNewLine(LineState &State,
 Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
   }
 
+  if (PreviousNonComment && PreviousNonComment->is(tok::less))
+CurrentState.BreakBeforeClosingAngle = true;
+
   if (CurrentState.AvoidBinPacking) {
 // If we are breaking after '(', '{', '<', or this is the break after a ':'
 // to start a member initializer list in a constructor, this should not
@@ -1370,6 +1377,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   State.Stack.size() > 1) {
 return State.Stack[State.Stack.size() - 2].Last

[clang] [Driver] Avoid repeated map lookups (NFC) (PR #122625)

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

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/122625

None

>From b9a6a99e421170fbc1fb8c6641a83d21dfa0076c Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 11 Jan 2025 17:53:36 -0800
Subject: [PATCH] [Driver] Avoid repeated map lookups (NFC)

---
 clang/lib/Driver/Driver.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4d9492ea08f647..10df730744b089 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2534,8 +2534,8 @@ enum {
 static unsigned PrintActions1(const Compilation &C, Action *A,
   std::map &Ids,
   Twine Indent = {}, int Kind = TopLevelAction) {
-  if (Ids.count(A)) // A was already visited.
-return Ids[A];
+  if (auto It = Ids.find(A); It != Ids.end()) // A was already visited.
+return It->second;
 
   std::string str;
   llvm::raw_string_ostream os(str);

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


[clang] [Driver] Avoid repeated map lookups (NFC) (PR #122625)

2025-01-11 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+2-2) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4d9492ea08f647..10df730744b089 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2534,8 +2534,8 @@ enum {
 static unsigned PrintActions1(const Compilation &C, Action *A,
   std::map &Ids,
   Twine Indent = {}, int Kind = TopLevelAction) {
-  if (Ids.count(A)) // A was already visited.
-return Ids[A];
+  if (auto It = Ids.find(A); It != Ids.end()) // A was already visited.
+return It->second;
 
   std::string str;
   llvm::raw_string_ostream os(str);

``




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


[clang] 4f6fabd - [Driver] Avoid repeated map lookups (NFC) (#122625)

2025-01-11 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-01-11T19:49:59-08:00
New Revision: 4f6fabd11ad1a5de8e066adad28c8da4a615f8bb

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

LOG: [Driver] Avoid repeated map lookups (NFC) (#122625)

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 4d9492ea08f647..10df730744b089 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2534,8 +2534,8 @@ enum {
 static unsigned PrintActions1(const Compilation &C, Action *A,
   std::map &Ids,
   Twine Indent = {}, int Kind = TopLevelAction) {
-  if (Ids.count(A)) // A was already visited.
-return Ids[A];
+  if (auto It = Ids.find(A); It != Ids.end()) // A was already visited.
+return It->second;
 
   std::string str;
   llvm::raw_string_ostream os(str);



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


  1   2   >