[PATCH] D157179: [clang-format] Currectly handle PCIS_CurrentLine with no column limit

2023-08-05 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157179

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7758,6 +7758,13 @@
"(a),\n"
"b(b) {}",
Style);
+
+  Style = getLLVMStyleWithColumns(0);
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
+  verifyFormat("Foo(Bar bar, Baz baz) : bar(bar), baz(baz) {}", Style);
+  verifyNoChange("Foo(Bar bar, Baz baz)\n"
+ ": bar(bar), baz(baz) {}",
+ Style);
 }
 
 TEST_F(FormatTest, AllowAllArgumentsOnNextLine) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1437,6 +1437,7 @@
 if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack) {
   CurrentState.AvoidBinPacking = true;
   CurrentState.BreakBeforeParameter =
+  Style.ColumnLimit > 0 &&
   Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine &&
   Style.PackConstructorInitializers != FormatStyle::PCIS_NextLineOnly;
 } else {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7758,6 +7758,13 @@
"(a),\n"
"b(b) {}",
Style);
+
+  Style = getLLVMStyleWithColumns(0);
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
+  verifyFormat("Foo(Bar bar, Baz baz) : bar(bar), baz(baz) {}", Style);
+  verifyNoChange("Foo(Bar bar, Baz baz)\n"
+ ": bar(bar), baz(baz) {}",
+ Style);
 }
 
 TEST_F(FormatTest, AllowAllArgumentsOnNextLine) {
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1437,6 +1437,7 @@
 if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack) {
   CurrentState.AvoidBinPacking = true;
   CurrentState.BreakBeforeParameter =
+  Style.ColumnLimit > 0 &&
   Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine &&
   Style.PackConstructorInitializers != FormatStyle::PCIS_NextLineOnly;
 } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157180: [clang-tidy] Exclude class/struct scope variables from cppcoreguidelines-avoid-non-const-global-variables

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp, ccotter.
Herald added subscribers: shchenz, kbarton, xazax.hun, nemanjai.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Ignore static variables declared within the scope of class/struct.
Those variables should be covered by I.3 rule.

Fixes: #47384


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157180

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
@@ -236,3 +236,17 @@
 nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
   }
 }
+
+// CHECKING AGAINST FALSE POSITIVES INSIDE STRUCT SCOPE /
+struct StructWithStatic {
+  static DummyStruct nonConstDummyStructInstance;
+  static int value;
+  static int* valuePtr;
+  static int& valueRef;
+};
+
+DummyStruct StructWithStatic::nonConstDummyStructInstance;
+int StructWithStatic::value = 0;
+int* StructWithStatic::valuePtr = &StructWithStatic::value;
+int& StructWithStatic::valueRef = StructWithStatic::value;
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,11 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`cppcoreguidelines-avoid-non-const-global-variables
+  ` check
+  to ignore ``static`` variables declared within the scope of
+  ``class``/``struct``.
+
 Removed checks
 ^^
 
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
@@ -15,25 +15,24 @@
 
 namespace clang::tidy::cppcoreguidelines {
 
-namespace {
-AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
-} // namespace
-
 void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
+  auto GlobalContext =
+  varDecl(hasGlobalStorage(),
+  hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(;
+
   auto GlobalVariable = varDecl(
-  hasGlobalStorage(),
+  GlobalContext,
   unless(anyOf(
-  isLocalVarDecl(), isConstexpr(), hasType(isConstQualified()),
+  isConstexpr(), hasType(isConstQualified()),
   hasType(referenceType(); // References can't be changed, only the
// data they reference can be changed.
 
   auto GlobalReferenceToNonConst =
-  varDecl(hasGlobalStorage(), hasType(referenceType()),
+  varDecl(GlobalContext, hasType(referenceType()),
   unless(hasType(references(qualType(isConstQualified());
 
-  auto GlobalPointerToNonConst =
-  varDecl(hasGlobalStorage(),
-  hasType(pointerType(pointee(unless(isConstQualified());
+  auto GlobalPointerToNonConst = varDecl(
+  GlobalContext, 
hasType(pointerType(pointee(unless(isConstQualified());
 
   Finder->addMatcher(GlobalVariable.bind("non-const_variable"), this);
   
Finder->addMatcher(GlobalReferenceToNonConst.bind("indirection_to_non-const"),


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
@@ -236,3 +236,17 @@
 nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
   }
 }
+
+// CHECKING AGAINST FALSE POSITIVES INSIDE STRUCT SCOPE /
+struct StructWithStatic {
+  static DummyStruct nonConstDummyStructInstance;
+  static int value;
+  static int* valuePtr;
+  static int& valueRef;
+};
+
+DummyStruct StructWithStatic::nonConstDummyStructInstance;
+int StructWithStatic::value = 0;
+int* StructWithStatic::valuePtr = &StructWithStatic::value;
+int& StructWithStatic::valueRef = StructWithStatic::value;
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
==

[PATCH] D157181: [clang-tidy] Re-add cppcoreguidelines-macro-to-enum alias

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp.
Herald added subscribers: jeroen.dobbelaere, shchenz, kbarton, xazax.hun, 
nemanjai.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Looks like somewere in clang-16 this alias were removed,
even that is mention in clang-tidy 15 release notes.

Fixes: #64342


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157181

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp


Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/MacroToEnumCheck.h"
 #include "../modernize/UseDefaultMemberInitCheck.h"
 #include "../modernize/UseOverrideCheck.h"
 #include "../performance/NoexceptDestructorCheck.h"
@@ -77,6 +78,8 @@
 "cppcoreguidelines-init-variables");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
+CheckFactories.registerCheck(
+"cppcoreguidelines-macro-to-enum");
 CheckFactories.registerCheck(
 "cppcoreguidelines-macro-usage");
 CheckFactories.registerCheck(


Index: clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/MacroToEnumCheck.h"
 #include "../modernize/UseDefaultMemberInitCheck.h"
 #include "../modernize/UseOverrideCheck.h"
 #include "../performance/NoexceptDestructorCheck.h"
@@ -77,6 +78,8 @@
 "cppcoreguidelines-init-variables");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
+CheckFactories.registerCheck(
+"cppcoreguidelines-macro-to-enum");
 CheckFactories.registerCheck(
 "cppcoreguidelines-macro-usage");
 CheckFactories.registerCheck(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157182: [clang-tidy][NFC] Update documentation for hicpp-avoid-goto

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Add info in check list that hicpp-avoid-goto is actually
a alias to cppcoreguidelines-avoid-goto.

Fixes: #64337


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157182

Files:
  clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst


Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -241,7 +241,6 @@
`google-runtime-int `_,
`google-runtime-operator `_,
`google-upgrade-googletest-case `_, 
"Yes"
-   `hicpp-avoid-goto `_,
`hicpp-exception-baseclass `_,
`hicpp-multiway-paths-covered `_,
`hicpp-no-assembler `_,
@@ -503,6 +502,7 @@
`google-readability-function-size 
`_, `readability-function-size 
`_,
`google-readability-namespace-comments 
`_, `llvm-namespace-comment 
`_,
`hicpp-avoid-c-arrays `_, 
`modernize-avoid-c-arrays `_,
+   `hicpp-avoid-goto `_, cppcoreguidelines-avoid-goto 
`_,
`hicpp-braces-around-statements `_, 
`readability-braces-around-statements 
`_, "Yes"
`hicpp-deprecated-headers `_, 
`modernize-deprecated-headers `_, "Yes"
`hicpp-explicit-conversions `_, 
`google-explicit-constructor `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
+++ clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
@@ -1,4 +1,6 @@
 .. title:: clang-tidy - hicpp-avoid-goto
+.. meta::
+   :http-equiv=refresh: 5;URL=../cppcoreguidelines/avoid-goto.html
 
 hicpp-avoid-goto
 


Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -241,7 +241,6 @@
`google-runtime-int `_,
`google-runtime-operator `_,
`google-upgrade-googletest-case `_, "Yes"
-   `hicpp-avoid-goto `_,
`hicpp-exception-baseclass `_,
`hicpp-multiway-paths-covered `_,
`hicpp-no-assembler `_,
@@ -503,6 +502,7 @@
`google-readability-function-size `_, `readability-function-size `_,
`google-readability-namespace-comments `_, `llvm-namespace-comment `_,
`hicpp-avoid-c-arrays `_, `modernize-avoid-c-arrays `_,
+   `hicpp-avoid-goto `_, cppcoreguidelines-avoid-goto `_,
`hicpp-braces-around-statements `_, `readability-braces-around-statements `_, "Yes"
`hicpp-deprecated-headers `_, `modernize-deprecated-headers `_, "Yes"
`hicpp-explicit-conversions `_, `google-explicit-constructor `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
+++ clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
@@ -1,4 +1,6 @@
 .. title:: clang-tidy - hicpp-avoid-goto
+.. meta::
+   :http-equiv=refresh: 5;URL=../cppcoreguidelines/avoid-goto.html
 
 hicpp-avoid-goto
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157185: [clang-tidy] Fix false-positives in performanc-noexcept-swap

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp, AMS21.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Enforce a stricter match with the swap function signature, eliminating 
false-positives.

Fixes: #64303


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157185

Files:
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
@@ -201,3 +201,17 @@
 template 
 void swap(OK21 &, OK21 &) 
noexcept(noexcept(TemplateNoexceptWithInt::f()));
 void swap(OK21 &, OK21 &) 
noexcept(noexcept(TemplateNoexceptWithInt::f()));
+
+namespace PR64303 {
+  void swap();
+  void swap(int&, bool&);
+  void swap(int&, int&, int&);
+  void swap(int&);
+
+  struct Test {
+void swap();
+void swap(Test&, Test&);
+void swap(int&);
+static void swap(int&, int&);
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`performanc-noexcept-swap
+  ` check to enforce a stricter
+  match with the swap function signature, eliminating false-positives.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
@@ -17,8 +17,26 @@
 namespace clang::tidy::performance {
 
 void NoexceptSwapCheck::registerMatchers(MatchFinder *Finder) {
+
   Finder->addMatcher(
-  functionDecl(unless(isDeleted()), 
hasName("swap")).bind(BindFuncDeclName),
+  functionDecl(
+  unless(isDeleted()), hasName("swap"),
+  anyOf(
+  cxxMethodDecl(
+  parameterCountIs(1U),
+  hasParameter(0,
+   hasType(qualType(hasCanonicalType(qualType(
+   unless(isConstQualified()),
+   references(namedDecl().bind("class"))),
+  ofClass(equalsBoundNode("class"))),
+  allOf(unless(cxxMethodDecl()), parameterCountIs(2U),
+hasParameter(0, hasType(qualType(hasCanonicalType(
+qualType(unless(isConstQualified()),
+ references(qualType()))
+.bind("type"),
+hasParameter(1, hasType(qualType(hasCanonicalType(
+
qualType(equalsBoundNode("type")
+  .bind(BindFuncDeclName),
   this);
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
@@ -201,3 +201,17 @@
 template 
 void swap(OK21 &, OK21 &) noexcept(noexcept(TemplateNoexceptWithInt::f()));
 void swap(OK21 &, OK21 &) noexcept(noexcept(TemplateNoexceptWithInt::f()));
+
+namespace PR64303 {
+  void swap();
+  void swap(int&, bool&);
+  void swap(int&, int&, int&);
+  void swap(int&);
+
+  struct Test {
+void swap();
+void swap(Test&, Test&);
+void swap(int&);
+static void swap(int&, int&);
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`performanc-noexcept-swap
+  ` check to enforce a stricter
+  match with the swap function signature, eliminating false-positives.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
@@ -17,8 +17,26 @@
 namespace clang::tidy::perfor

[PATCH] D157188: [clang-tidy] Add bugprone-new-bool-conversion

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Detects cases where the result of a new expression is used as a bool.

Fixes: #64461


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157188

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NewBoolConversionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NewBoolConversionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/new-bool-conversion.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/new-bool-conversion.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/new-bool-conversion.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/new-bool-conversion.cpp
@@ -0,0 +1,38 @@
+// RUN: %check_clang_tidy %s bugprone-new-bool-conversion %t
+
+void takeBool(bool);
+
+void testImplicit() {
+  takeBool(new int);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+  takeBool(new bool);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+
+  bool value;
+
+  value = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+  value = new bool;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+}
+
+void testExplicit() {
+  takeBool(static_cast(new int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+  takeBool(static_cast(new bool));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+}
+
+void testNegation() {
+  takeBool(!new bool);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+  takeBool(!new int);
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+
+  bool value;
+
+  value = !new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+  value = !new bool;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or memory leaks [bugprone-new-bool-conversion]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -107,6 +107,7 @@
`bugprone-multi-level-implicit-pointer-conversion `_,
`bugprone-multiple-new-in-one-expression `_,
`bugprone-multiple-statement-macro `_,
+   `bugprone-new-bool-conversion `_,
`bugprone-no-escape `_,
`bugprone-non-zero-enum-to-bool-conversion `_,
`bugprone-not-null-terminated-result `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/new-bool-conversion.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/new-bool-conversion.rst
@@ -0,0 +1,44 @@
+.. title:: clang-tidy - bugprone-new-bool-conversion
+
+bugprone-new-bool-conversion
+
+
+Detects cases where the result of a new expression is used as a ``bool``.
+
+In C++, the new expression dynamically allocates memory on the heap and returns
+a pointer to the newly created object. However, when developers inadvertently
+use this pointer directly as a boolean value, either through implicit or
+explicit conversion, a hidden problem emerges. The crux of the issue lies in
+the fact that any non

[PATCH] D157190: [clang-tidy] Fixed false-negative in readability-identifier-naming

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: carlosgalvezp, njames93.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Issue were cased by checking if canonical declaration of record is a
definition. Unfortunetly when forward declarations were used, it were
not a definition. Changed to use hasDefinition instead.

Fixes: #64463


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157190

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -707,3 +707,13 @@
 task ImplicitDeclTest(async_obj &a_object) {
   co_await a_object;  // CHECK-MESSAGES-NOT: warning: invalid case style for 
local variable
 }
+
+// Test scenario when canonical declaration will be a forward declaration
+class class_with_forward_decl;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 
'class_with_forward_decl' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl;
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl {
+class class_with_forward_decl {
+  int __value;
+};
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved the :doc:`readability-identifier-naming
+  ` check to emit proper
+  warnings when a type forward declaration precedes its definition.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1137,14 +1137,10 @@
   }
 
   if (const auto *Decl = dyn_cast(D)) {
-if (Decl->isAnonymousStructOrUnion())
+if (Decl->isAnonymousStructOrUnion() || !Decl->hasDefinition())
   return SK_Invalid;
 
-if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
-  return SK_Invalid;
-
-if (Decl->hasDefinition() && Decl->isAbstract() &&
-NamingStyles[SK_AbstractClass])
+if (Decl->isAbstract() && NamingStyles[SK_AbstractClass])
   return SK_AbstractClass;
 
 if (Decl->isStruct() && NamingStyles[SK_Struct])


Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -707,3 +707,13 @@
 task ImplicitDeclTest(async_obj &a_object) {
   co_await a_object;  // CHECK-MESSAGES-NOT: warning: invalid case style for local variable
 }
+
+// Test scenario when canonical declaration will be a forward declaration
+class class_with_forward_decl;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for class 'class_with_forward_decl' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl;
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl {
+class class_with_forward_decl {
+  int __value;
+};
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved the :doc:`readability-identifier-naming
+  ` check to emit proper
+  warnings when a type forward declaration precedes its definition.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1137,14 +1137,10 @@
   }
 
   if (const auto *Decl = dyn_cast(D)) {
-if (Decl->isAnonymousStructOrUnion())
+if (Decl->isAnonymousStructOrUnion() || !Decl->hasDefinition())
   return SK_Invalid;
 
-if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
-  return SK_Invalid;
-
-if (Decl->hasDefinition() && Decl->isAbstra

[PATCH] D157190: [clang-tidy] Fixed false-negative in readability-identifier-naming

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 547475.
PiotrZSL edited the summary of this revision.
PiotrZSL added a comment.

Properly handle situation when class is forward-declared as struct.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157190/new/

https://reviews.llvm.org/D157190

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -707,3 +707,13 @@
 task ImplicitDeclTest(async_obj &a_object) {
   co_await a_object;  // CHECK-MESSAGES-NOT: warning: invalid case style for 
local variable
 }
+
+// Test scenario when canonical declaration will be a forward declaration
+struct class_with_forward_decl;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for class 
'class_with_forward_decl' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}struct CClassWithForwardDecl;
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl {
+class class_with_forward_decl {
+  int __value;
+};
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved the :doc:`readability-identifier-naming
+  ` check to emit proper
+  warnings when a type forward declaration precedes its definition.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1140,30 +1140,28 @@
 if (Decl->isAnonymousStructOrUnion())
   return SK_Invalid;
 
-if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
-  return SK_Invalid;
-
-if (Decl->hasDefinition() && Decl->isAbstract() &&
-NamingStyles[SK_AbstractClass])
-  return SK_AbstractClass;
+if (const auto *Definition = Decl->getDefinition()) {
+  if (Definition->isAbstract() && NamingStyles[SK_AbstractClass])
+return SK_AbstractClass;
 
-if (Decl->isStruct() && NamingStyles[SK_Struct])
-  return SK_Struct;
+  if (Definition->isStruct() && NamingStyles[SK_Struct])
+return SK_Struct;
 
-if (Decl->isStruct() && NamingStyles[SK_Class])
-  return SK_Class;
+  if (Definition->isStruct() && NamingStyles[SK_Class])
+return SK_Class;
 
-if (Decl->isClass() && NamingStyles[SK_Class])
-  return SK_Class;
+  if (Definition->isClass() && NamingStyles[SK_Class])
+return SK_Class;
 
-if (Decl->isClass() && NamingStyles[SK_Struct])
-  return SK_Struct;
+  if (Definition->isClass() && NamingStyles[SK_Struct])
+return SK_Struct;
 
-if (Decl->isUnion() && NamingStyles[SK_Union])
-  return SK_Union;
+  if (Definition->isUnion() && NamingStyles[SK_Union])
+return SK_Union;
 
-if (Decl->isEnum() && NamingStyles[SK_Enum])
-  return SK_Enum;
+  if (Definition->isEnum() && NamingStyles[SK_Enum])
+return SK_Enum;
+}
 
 return SK_Invalid;
   }


Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -707,3 +707,13 @@
 task ImplicitDeclTest(async_obj &a_object) {
   co_await a_object;  // CHECK-MESSAGES-NOT: warning: invalid case style for local variable
 }
+
+// Test scenario when canonical declaration will be a forward declaration
+struct class_with_forward_decl;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for class 'class_with_forward_decl' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}struct CClassWithForwardDecl;
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl {
+class class_with_forward_decl {
+  int __value;
+};
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved the :doc:`readability-identifier-naming
+  ` check to emit proper
+  warnings when a

[PATCH] D156993: [clang] Error on substitution failure within lambda body inside a requires-expression

2023-08-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156993/new/

https://reviews.llvm.org/D156993

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


[PATCH] D157191: Improve dumps of attributes

2023-08-05 Thread Giuliano Belinassi via Phabricator via cfe-commits
giulianobelinassi created this revision.
Herald added subscribers: s.egerton, simoncook, asb.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
giulianobelinassi requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, wangpc, jplehr, sstefan1.
Herald added a project: clang.

Clang has several cases where __attribute__ dumpings gets into
undesired places, or even is completely incorrect.

Therefore, this commit improves many cases, as listed below:

1- Variable with attributes have its attribute dumped before its value.

input:

  int var __attribute__((unused)) = 0;

output before this commit:

  int var = 0 __attribute__((unused)); // Compilation error.

after this patch:

  int var __attribute__((unused)) = 0;

2- __declspec attributes are dumped on the left side of the declaration,

  as recommended by MSVC docs:

input:

  __declspec(thread) int var = 0;

output before this commit:

  int var __declspec(thread) = 0;

output after this commit:

  __declspec(thread) int var = 0;

3- Functions with body has its attributes dumped on the right side of

  the declaration instead of left side when possible.  The point of
  this is to (1) avoid attribute placement confusion in K&R C
  functions and (2) keep compatibility with GCC.

input

  int f(void) __attribute__((unused)) {}

output before this commit:

  int f(void) __attribute__((unused)) {}

output after this commit:

  __attribute__((unused)) int f(void) {}

The interesting case is with input:

  int f(i) int i __attribute__((unused)); {}

output before this commit (incorrect):

  int f(i) __attribute__((unused)) int i; {}

output after this commit (correct)

  int f(i) int i __attribute__((unused));

And in cases where the attribute is not accepted on the left side of
the declaration is output on the right side of the declaration:

intput:

  int f(int i) __attribute__((diagnose_if(i < 0, "oh no", "warning"))) {}

output before and after this commit:

  int f(int i) __attribute__((diagnose_if(i < 0, "oh no", "warning"))) {}

The reason behind thius is because GCC does not accept diagnose_if and
i must be declared in order to be referenced in this attribute.

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

Signed-off-by: Giuliano Belinassi 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157191

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/CMakeLists.txt
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-attr-knr.c
  clang/test/AST/ast-print-attr.c
  clang/test/AST/ast-print-pragmas.cpp
  clang/test/Analysis/blocks.mm
  clang/test/OpenMP/assumes_codegen.cpp
  clang/test/OpenMP/assumes_print.cpp
  clang/test/OpenMP/assumes_template_print.cpp
  clang/test/OpenMP/declare_simd_ast_print.cpp
  clang/test/Sema/attr-print.c
  clang/test/SemaCXX/attr-print.cpp
  clang/test/SemaCXX/cxx11-attr-print.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -39,6 +39,8 @@
 void EmitClangAttrClass(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 void EmitClangAttrImpl(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 void EmitClangAttrList(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitClangAttrPrintList(const std::string &FieldName,
+llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 void EmitClangAttrSubjectMatchRuleList(llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
 void EmitClangAttrPCHRead(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -31,6 +31,8 @@
   GenClangAttrSubjectMatchRulesParserStringSwitches,
   GenClangAttrImpl,
   GenClangAttrList,
+  GenClangAttrCanPrintLeftList,
+  GenClangAttrMustPrintLeftList,
   GenClangAttrDocTable,
   GenClangAttrSubjectMatchRuleList,
   GenClangAttrPCHRead,
@@ -127,6 +129,14 @@
"Generate clang attribute implementations"),
 clEnumValN(GenClangAttrList, "gen-clang-attr-list",
"Generate a clang attribute list"),
+clEnumValN(GenClangAttrCanPrintLeftList,
+   "gen-clang-attr-can-print-left-list",
+   "Generate list of attributes that can be printed on left "
+   "side of a decl"),
+clEnumValN(GenClangAttrMustPrintLeftList,
+   "gen-clang-attr-must-print-left-list",
+   "Generate list of attributes that must be printed on left "
+   "side of a decl"),
 clEnumValN(GenCl

[PATCH] D157191: Improve dumps of attributes

2023-08-05 Thread Giuliano Belinassi via Phabricator via cfe-commits
giulianobelinassi abandoned this revision.
giulianobelinassi added a comment.

This was open by mistake.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157191/new/

https://reviews.llvm.org/D157191

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


[PATCH] D141714: Fix ast print of variables with attributes

2023-08-05 Thread Giuliano Belinassi via Phabricator via cfe-commits
giulianobelinassi updated this revision to Diff 547477.
giulianobelinassi added a comment.
Herald added subscribers: wangpc, s.egerton, simoncook, asb.

- Use tblgen to generate table of attributes that can or must be print on the 
left side of the Decl.
- Use LLVM_MARK_AS_BITMASK_ENUM on AttrPrintLoc enum.
- Print attributes of declarations contatining parenthesis ctors on the left 
side. Improves the case:

  StructWithCopyConstructor s __attribute__((blocks("byref")))(5)

  now printing:

  __attribute__((blocks("byref"))) StructWithCopyConstructor s(5)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141714/new/

https://reviews.llvm.org/D141714

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/CMakeLists.txt
  clang/lib/AST/DeclPrinter.cpp
  clang/test/AST/ast-print-attr-knr.c
  clang/test/AST/ast-print-attr.c
  clang/test/AST/ast-print-pragmas.cpp
  clang/test/Analysis/blocks.mm
  clang/test/OpenMP/assumes_codegen.cpp
  clang/test/OpenMP/assumes_print.cpp
  clang/test/OpenMP/assumes_template_print.cpp
  clang/test/OpenMP/declare_simd_ast_print.cpp
  clang/test/Sema/attr-print.c
  clang/test/SemaCXX/attr-print.cpp
  clang/test/SemaCXX/cxx11-attr-print.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -39,6 +39,8 @@
 void EmitClangAttrClass(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 void EmitClangAttrImpl(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 void EmitClangAttrList(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+void EmitClangAttrPrintList(const std::string &FieldName,
+llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 void EmitClangAttrSubjectMatchRuleList(llvm::RecordKeeper &Records,
llvm::raw_ostream &OS);
 void EmitClangAttrPCHRead(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -31,6 +31,8 @@
   GenClangAttrSubjectMatchRulesParserStringSwitches,
   GenClangAttrImpl,
   GenClangAttrList,
+  GenClangAttrCanPrintLeftList,
+  GenClangAttrMustPrintLeftList,
   GenClangAttrDocTable,
   GenClangAttrSubjectMatchRuleList,
   GenClangAttrPCHRead,
@@ -127,6 +129,14 @@
"Generate clang attribute implementations"),
 clEnumValN(GenClangAttrList, "gen-clang-attr-list",
"Generate a clang attribute list"),
+clEnumValN(GenClangAttrCanPrintLeftList,
+   "gen-clang-attr-can-print-left-list",
+   "Generate list of attributes that can be printed on left "
+   "side of a decl"),
+clEnumValN(GenClangAttrMustPrintLeftList,
+   "gen-clang-attr-must-print-left-list",
+   "Generate list of attributes that must be printed on left "
+   "side of a decl"),
 clEnumValN(GenClangAttrDocTable, "gen-clang-attr-doc-table",
"Generate a table of attribute documentation"),
 clEnumValN(GenClangAttrSubjectMatchRuleList,
@@ -269,11 +279,14 @@
"Generate riscv_vector_builtin_cg.inc for clang"),
 clEnumValN(GenRISCVVectorBuiltinSema, "gen-riscv-vector-builtin-sema",
"Generate riscv_vector_builtin_sema.inc for clang"),
-clEnumValN(GenRISCVSiFiveVectorBuiltins, "gen-riscv-sifive-vector-builtins",
+clEnumValN(GenRISCVSiFiveVectorBuiltins,
+   "gen-riscv-sifive-vector-builtins",
"Generate riscv_sifive_vector_builtins.inc for clang"),
-clEnumValN(GenRISCVSiFiveVectorBuiltinCG, "gen-riscv-sifive-vector-builtin-codegen",
+clEnumValN(GenRISCVSiFiveVectorBuiltinCG,
+   "gen-riscv-sifive-vector-builtin-codegen",
"Generate riscv_sifive_vector_builtin_cg.inc for clang"),
-clEnumValN(GenRISCVSiFiveVectorBuiltinSema, "gen-riscv-sifive-vector-builtin-sema",
+clEnumValN(GenRISCVSiFiveVectorBuiltinSema,
+   "gen-riscv-sifive-vector-builtin-sema",
"Generate riscv_sifive_vector_builtin_sema.inc for clang"),
 clEnumValN(GenAttrDocs, "gen-attr-docs",
"Generate attribute documentation"),
@@ -315,6 +328,12 @@
   case GenClangAttrList:
 EmitClangAttrList(Records, OS);
 break;
+  case GenClangAttrCanPrintLeftList:
+EmitClangAttrPrintList("CanPrintOnLeftSide", Records, OS);
+break;
+  case GenClangAttrMustPrintLeftList:
+EmitClangAttrPrintList("MustPrintOnLeftSide", Records, OS);
+break;
 

[PATCH] D141714: Fix ast print of variables with attributes

2023-08-05 Thread Giuliano Belinassi via Phabricator via cfe-commits
giulianobelinassi added a comment.

Hello,

It took me a while, but here it is the newer version of the patch with the 
tablegen stuff. Please reach to me if something needs to be changed in this 
regard.

This also improves the readability of declarations of variables that have a 
parenthesis constructor (like the __block case).

Thanks,
Giuliano.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141714/new/

https://reviews.llvm.org/D141714

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


[PATCH] D140828: [C++] Implement "Deducing this" (P0847R7)

2023-08-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Interesting case that crashes the compiler, stack overflow

  cpp
  struct T{};
  struct C {
  operator T (this int);
  operator int();
  };
  
  void foo(C c) {
 T d = c;
  }

Not completely sure that this is supposed to be covered by 
https://eel.is/c++draft/class.conv#general-4


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140828/new/

https://reviews.llvm.org/D140828

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


[PATCH] D157188: [clang-tidy] Add bugprone-new-bool-conversion

2023-08-05 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Shouldn't C-style allocation be checked too? Same for custom allocators via 
configuration option.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157188/new/

https://reviews.llvm.org/D157188

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


[PATCH] D157188: [clang-tidy] Add bugprone-new-bool-conversion

2023-08-05 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Same for file, threads and other resources allocation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157188/new/

https://reviews.llvm.org/D157188

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2023-08-05 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 547483.
ccotter added a comment.

- Check nullptr
- Add tests for rbegin/crbegin


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140760/new/

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-reverse.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-reverse.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-reverse.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-reverse.cpp
@@ -40,6 +40,8 @@
 // Make sure no header is included in this example
 // CHECK-FIXES-CUSTOM-NO-HEADER-NOT: #include
 
+namespace ADL {
+
 template 
 struct Reversable {
   using iterator = T *;
@@ -61,6 +63,28 @@
   const_iterator crend() const;
 };
 
+template 
+constexpr auto rbegin(C& c) -> decltype(c.rbegin()) { return c.rbegin(); }
+template 
+constexpr auto rend(C& c) -> decltype(c.rend()) { return c.rend(); }
+template 
+constexpr auto rbegin(const C& c) -> decltype(c.rbegin()) { return c.rbegin(); }
+template 
+constexpr auto rend(const C& c) -> decltype(c.rend()) { return c.rend(); }
+
+template 
+constexpr auto crbegin(C& c) -> decltype(c.crbegin());
+template 
+constexpr auto crend(C& c) -> decltype(c.crend());
+template 
+constexpr auto crbegin(const C& c) -> decltype(c.crbegin());
+template 
+constexpr auto crend(const C& c) -> decltype(c.crend());
+
+} // namespace ADL
+
+using ADL::Reversable;
+
 template 
 void observe(const T &);
 template 
@@ -85,6 +109,24 @@
   //   CHECK-FIXES-NEXT:   observe(Number);
   //   CHECK-FIXES-NEXT: }
 
+  for (auto I = rbegin(Numbers), E = rend(Numbers); I != E; ++I) {
+observe(*I);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES-RANGES: for (int Number : std::ranges::reverse_view(Numbers)) {
+  // CHECK-FIXES-CUSTOM: for (int Number : llvm::reverse(Numbers)) {
+  //   CHECK-FIXES-NEXT:   observe(Number);
+  //   CHECK-FIXES-NEXT: }
+
+  for (auto I = crbegin(Numbers), E = crend(Numbers); I != E; ++I) {
+observe(*I);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES-RANGES: for (int Number : std::ranges::reverse_view(Numbers)) {
+  // CHECK-FIXES-CUSTOM: for (int Number : llvm::reverse(Numbers)) {
+  //   CHECK-FIXES-NEXT:   observe(Number);
+  //   CHECK-FIXES-NEXT: }
+
   // Ensure these bad loops aren't transformed.
   for (auto I = Numbers.rbegin(), E = Numbers.end(); I != E; ++I) {
 observe(*I);
@@ -112,4 +154,13 @@
   // CHECK-FIXES-CUSTOM: for (int Number : llvm::reverse(Numbers)) {
   //   CHECK-FIXES-NEXT:   observe(Number);
   //   CHECK-FIXES-NEXT: }
+
+  for (auto I = rbegin(Numbers), E = rend(Numbers); I != E; ++I) {
+mutate(*I);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES-RANGES: for (int & Number : std::ranges::reverse_view(Numbers)) {
+  // CHECK-FIXES-CUSTOM: for (int & Number : llvm::reverse(Numbers)) {
+  //   CHECK-FIXES-NEXT:   mutate(Number);
+  //   CHECK-FIXES-NEXT: }
 }
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
@@ -5,6 +5,22 @@
 // CHECK-FIXES-NOT: for ({{.*[^:]:[^:].*}})
 // CHECK-MESSAGES-NOT: modernize-loop-convert
 
+namespace somenamespace {
+  template  auto begin(T& t) -> decltype(t.begin());
+  template  auto begin(const T& t) -> decltype(t.begin());
+  template  auto end(T& t) -> decltype(t.end());
+  template  auto end(const T& t) -> decltype(t.end());
+  template  auto size(const T& t) -> decltype(t.size());
+} // namespace somenamespace
+
+struct SomeClass {
+  template  static auto begin(T& t) -> decltype(t.begin());
+  template  static auto begin(const T& t) -> decltype(t.begin());
+  template  static auto end(T& t) -> decltype(t.end());
+  template  static auto end(const T& t) -> decltype(t.end());
+  template  static auto size(const T& t) -> decltype(t.size());
+};
+
 namespace Negative {
 
 const int N = 6;
@@ -92,7 +108,7 @@
   }
 }
 
-}
+} // namespace Negative
 
 namespace NegativeIterator {
 
@@ -103,6 +119,10 @@
 struct BadBeginEnd : T {
   iterator notBegin();
   iterator notEnd();
+  iterat

[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2023-08-05 Thread Chris Cotter via Phabricator via cfe-commits
ccotter marked 3 inline comments as done.
ccotter added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp:484
 }
 
 // Tests to verify the proper use of auto where the init variable type and the

PiotrZSL wrote:
> Please add test with rbegin/rend
Will do.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140760/new/

https://reviews.llvm.org/D140760

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


[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-05 Thread QuillPusher via Phabricator via cfe-commits
QuillPusher accepted this revision.
QuillPusher added a comment.
This revision is now accepted and ready to land.

Thanks for the updates, look OK to me


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156858/new/

https://reviews.llvm.org/D156858

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


[PATCH] D157188: [clang-tidy] Add bugprone-new-bool-conversion

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

In D157188#4563105 , @Eugene.Zelenko 
wrote:

> Shouldn't C-style allocation be checked too? Same for custom allocators via 
> configuration option.

In theory it could, but in such case name of check would need to change...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157188/new/

https://reviews.llvm.org/D157188

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140760/new/

https://reviews.llvm.org/D140760

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


[PATCH] D157188: [clang-tidy] Add bugprone-new-bool-conversion

2023-08-05 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In D157188#4563139 , @PiotrZSL wrote:

> In D157188#4563105 , 
> @Eugene.Zelenko wrote:
>
>> Shouldn't C-style allocation be checked too? Same for custom allocators via 
>> configuration option.
>
> In theory it could, but in such case name of check would need to change...

Something like `bugprone-resource-bool-conversion` should be generic enough.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157188/new/

https://reviews.llvm.org/D157188

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


[PATCH] D157182: [clang-tidy][NFC] Update documentation for hicpp-avoid-goto

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157182/new/

https://reviews.llvm.org/D157182

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


[PATCH] D157181: [clang-tidy] Re-add cppcoreguidelines-macro-to-enum alias

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

Strange, it seems the alias was never fully added?
https://reviews.llvm.org/D117522


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157181/new/

https://reviews.llvm.org/D157181

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


[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D145138#4561799 , @PiotrZSL wrote:

> Test are failing, and I do not think that converting c-strings into 
> std::array is a good idea

+1, they should typically be `char const*` instead.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145138/new/

https://reviews.llvm.org/D145138

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


[PATCH] D157178: [clang-tidy] Fix inline namespaces in llvm-namespace-comment

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157178/new/

https://reviews.llvm.org/D157178

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


[PATCH] D157180: [clang-tidy] Exclude class/struct scope variables from cppcoreguidelines-avoid-non-const-global-variables

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157180/new/

https://reviews.llvm.org/D157180

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


[PATCH] D157185: [clang-tidy] Fix false-positives in performanc-noexcept-swap

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp:22
   Finder->addMatcher(
-  functionDecl(unless(isDeleted()), 
hasName("swap")).bind(BindFuncDeclName),
+  functionDecl(
+  unless(isDeleted()), hasName("swap"),

Would be good to add a small comment summarizing what signatures this block of 
code matches, for easier readability.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157185/new/

https://reviews.llvm.org/D157185

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


[PATCH] D157190: [clang-tidy] Fixed false-negative in readability-identifier-naming

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM, minor question that can be fixed post-review unless you want to discuss 
further!




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp:716
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl {
+class class_with_forward_decl {
+  int __value;

Nit: shouldn't we use also `struct` here? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157190/new/

https://reviews.llvm.org/D157190

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


[PATCH] D157190: [clang-tidy] Fixed false-negative in readability-identifier-naming

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp:716
+// CHECK-FIXES: {{^}}class CClassWithForwardDecl {
+class class_with_forward_decl {
+  int __value;

carlosgalvezp wrote:
> Nit: shouldn't we use also `struct` here? 
No, thats on prupose. I wanted to test also in same place that style is taken 
from definition, not forward declaration, can add some comment, and "public:"


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157190/new/

https://reviews.llvm.org/D157190

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


[PATCH] D157181: [clang-tidy] Re-add cppcoreguidelines-macro-to-enum alias

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

In D157181#4563147 , @carlosgalvezp 
wrote:

> Strange, it seems the alias was never fully added?
> https://reviews.llvm.org/D117522

Looks like, still I dont know what to do with release notes, add alias "again" 
there, dont change it, or mention that there were bug.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157181/new/

https://reviews.llvm.org/D157181

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


[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-05 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

I want to clarify: We offer two features: 1. capture the execution results and 
bring it back to the compiled program. 2. dump the captured value (value 
printing/automatic printf) and all the parsing, ast transform and balabala, 
these are all implementation details. The doc looks fine but may need a bit of 
restructuring. I'd suggest you split them into:

1. what do we offer? what are the new features? why are they important? The two 
I mentioned above
2. how these are implemented? what does the underhood look like? annotation 
token, code synthesis, etc...
3. further information, RFC and etc...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156858/new/

https://reviews.llvm.org/D156858

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


[PATCH] D157181: [clang-tidy] Re-add cppcoreguidelines-macro-to-enum alias

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D157181#4563170 , @PiotrZSL wrote:

> In D157181#4563147 , @carlosgalvezp 
> wrote:
>
>> Strange, it seems the alias was never fully added?
>> https://reviews.llvm.org/D117522
>
> Looks like, still I dont know what to do with release notes, add alias 
> "again" there, dont change it, or mention that there were bug.

I think adding it again is fine.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157181/new/

https://reviews.llvm.org/D157181

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


[clang-tools-extra] 36daf35 - Add missing clangSerialization dependency for include-cleaner unittests

2023-08-05 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2023-08-05T17:13:08+01:00
New Revision: 36daf3532d91bb3e61d631edceea77ebb8417801

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

LOG: Add missing clangSerialization dependency for include-cleaner unittests

Added: 


Modified: 
clang-tools-extra/include-cleaner/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
index 89b55f4c7b1907..1e89534b511161 100644
--- a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -25,6 +25,7 @@ clang_target_link_libraries(ClangIncludeCleanerTests
   clangFrontend
   clangFormat
   clangLex
+  clangSerialization
   clangToolingInclusionsStdlib
   )
 



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


[PATCH] D157174: [clang][Interp] Convert logical binop operands to bool

2023-08-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 547495.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157174/new/

https://reviews.llvm.org/D157174

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/c.c

Index: clang/test/AST/Interp/c.c
===
--- clang/test/AST/Interp/c.c
+++ clang/test/AST/Interp/c.c
@@ -7,6 +7,7 @@
 _Static_assert(0 != 1, "");
 _Static_assert(1.0 == 1.0, ""); // pedantic-ref-warning {{not an integer constant expression}} \
 // pedantic-expected-warning {{not an integer constant expression}}
+_Static_assert(1 && 1.0, "");
 _Static_assert( (5 > 4) + (3 > 2) == 2, "");
 
 /// FIXME: Should also be rejected in the new interpreter
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -480,18 +480,19 @@
   BinaryOperatorKind Op = E->getOpcode();
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
+  std::optional T = classify(E->getType());
 
   if (Op == BO_LOr) {
 // Logical OR. Visit LHS and only evaluate RHS if LHS was FALSE.
 LabelTy LabelTrue = this->getLabel();
 LabelTy LabelEnd = this->getLabel();
 
-if (!this->visit(LHS))
+if (!this->visitBool(LHS))
   return false;
 if (!this->jumpTrue(LabelTrue))
   return false;
 
-if (!this->visit(RHS))
+if (!this->visitBool(RHS))
   return false;
 if (!this->jump(LabelEnd))
   return false;
@@ -501,35 +502,36 @@
 this->fallthrough(LabelEnd);
 this->emitLabel(LabelEnd);
 
-if (DiscardResult)
-  return this->emitPopBool(E);
-
-return true;
-  }
-
-  // Logical AND.
-  // Visit LHS. Only visit RHS if LHS was TRUE.
-  LabelTy LabelFalse = this->getLabel();
-  LabelTy LabelEnd = this->getLabel();
+  } else {
+assert(Op == BO_LAnd);
+// Logical AND.
+// Visit LHS. Only visit RHS if LHS was TRUE.
+LabelTy LabelFalse = this->getLabel();
+LabelTy LabelEnd = this->getLabel();
 
-  if (!this->visit(LHS))
-return false;
-  if (!this->jumpFalse(LabelFalse))
-return false;
+if (!this->visitBool(LHS))
+  return false;
+if (!this->jumpFalse(LabelFalse))
+  return false;
 
-  if (!this->visit(RHS))
-return false;
-  if (!this->jump(LabelEnd))
-return false;
+if (!this->visitBool(RHS))
+  return false;
+if (!this->jump(LabelEnd))
+  return false;
 
-  this->emitLabel(LabelFalse);
-  this->emitConstBool(false, E);
-  this->fallthrough(LabelEnd);
-  this->emitLabel(LabelEnd);
+this->emitLabel(LabelFalse);
+this->emitConstBool(false, E);
+this->fallthrough(LabelEnd);
+this->emitLabel(LabelEnd);
+  }
 
   if (DiscardResult)
 return this->emitPopBool(E);
 
+  // For C, cast back to integer type.
+  assert(T);
+  if (T != PT_Bool)
+return this->emitCast(PT_Bool, *T, E);
   return true;
 }
 
@@ -902,17 +904,9 @@
   LabelTy LabelEnd = this->getLabel();   // Label after the operator.
   LabelTy LabelFalse = this->getLabel(); // Label for the false expr.
 
-  if (!this->visit(Condition))
+  if (!this->visitBool(Condition))
 return false;
 
-  // C special case: Convert to bool because our jump ops need that.
-  // TODO: We probably want this to be done in visitBool().
-  if (std::optional CondT = classify(Condition->getType());
-  CondT && CondT != PT_Bool) {
-if (!this->emitCast(*CondT, PT_Bool, E))
-  return false;
-  }
-
   if (!this->jumpFalse(LabelFalse))
 return false;
 
@@ -1650,11 +1644,29 @@
 
 template 
 bool ByteCodeExprGen::visitBool(const Expr *E) {
-  if (std::optional T = classify(E->getType())) {
-return visit(E);
-  } else {
-return this->bail(E);
+  std::optional T = classify(E->getType());
+  if (!T)
+return false;
+
+  if (!this->visit(E))
+return false;
+
+  if (T == PT_Bool)
+return true;
+
+  // Convert pointers to bool.
+  if (T == PT_Ptr || T == PT_FnPtr) {
+if (!this->emitNull(*T, E))
+  return false;
+return this->emitNE(*T, E);
   }
+
+  // Or Floats.
+  if (T == PT_Float)
+return this->emitCastFloatingIntegralBool(E);
+
+  // Or anything else we can.
+  return this->emitCast(*T, PT_Bool, E);
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

2023-08-05 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky added a comment.

In D156693#4560110 , @balazske wrote:

> The summary tells nothing about what is the real problem to fix here. In the 
> lit test I see that an error message is displayed, this causes the test 
> failure. The problem is that the structural equivalence check is not good for 
> this special case. The imported AST contains a class template specialization 
> for `A`, in this specialization the friend class template `A` has a previous 
> decl that points to the original friend class template that is in a 
> `ClassTemplateDecl`. In the specialization the "depth" of template arguments 
> is 0, but in the original template it is 1 (the "to" code at import contains 
> only the "original template", no specialization). This difference in the 
> "depth" causes the type mismatch when the specialization is imported.
> AST dump of this code can show the problem:
>
>   template
>   class A;
>   
>   template
>   class A {
>   public:
> template
> friend class A;
>   
> A(T x):x(x){}
>   
>   private:
> T x;
>   };
>   
>   A a1(0);
>
> It is really interesting that at friend templates the depth is 1 but friend 
> declarations point to objects outside the class, so really the depth should 
> not increase in a friend template from this point of view. But this is an AST 
> issue.

Depth of specialization friend template is 0 while it is 1 in class declaration 
 is reasonable, because after template class specialization there not exists 
template parameter and the friend template becomes outermost scope, thus depth 
is 0. Thanks to the different of depth causes the non equivalence of the two 
'NonTypeTemplateParm', I think there should ignore comparing the depth in this 
special case to make two types equivalence.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156693/new/

https://reviews.llvm.org/D156693

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


[PATCH] D157078: [include-cleaner] Handle files with unnamed buffers

2023-08-05 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

In D157078#4562788 , @tylanphear 
wrote:

> Seeing the link error downstream. I think clangSerialization needs to be 
> added to the link libraries.

Should be fixed by 36daf3532d91bb 



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157078/new/

https://reviews.llvm.org/D157078

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


[PATCH] D157195: [Clang] Fix the do while statement disappearing in AST when an error occurs in the conditional expression of the do while statement

2023-08-05 Thread Yurong via Phabricator via cfe-commits
yronglin created this revision.
Herald added a project: All.
yronglin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Signed-off-by: yrong 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157195

Files:
  clang/lib/Parse/ParseStmt.cpp
  clang/test/AST/ast-dump-recovery.cpp
  clang/test/SemaCXX/constexpr-function-recovery-crash.cpp


Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===
--- clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -78,6 +78,9 @@
 constexpr int test12() { return "wrong"; } // expected-error {{cannot 
initialize return object of type 'int'}}
 constexpr int force12 = test12();  // expected-error {{must be 
initialized by a constant}}
 
+constexpr int test13() { do {} while (a < 10); return 0; }   // expected-error 
{{use of undeclared identifier}}
+static_assert(test13());  // expected-error {{static assertion expression is 
not an integral constant expression}}
+
 #define TEST_EVALUATE(Name, X) \
   constexpr int testEvaluate##Name() { \
 X return 0;\
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -420,3 +420,15 @@
   // CHECK:  RecoveryExpr {{.*}} '' contains-errors lvalue
   // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *'
 }
+
+void RecoveryToDoWhileStmtCond() {
+  // CHECK:   FunctionDecl {{.*}} RecoveryToDoWhileStmtCond
+  // CHECK:   `-DoStmt {{.*}}
+  // CHECK-NEXT:|-CompoundStmt {{.*}}
+  // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors 
'<'
+  // CHECK-NEXT:  |-BinaryOperator {{.*}} '' 
contains-errors '+'
+  // CHECK-NEXT:  | |-RecoveryExpr {{.*}} '' 
contains-errors lvalue
+  // CHECK-NEXT:  | `-IntegerLiteral {{.*}} 'int' 1
+  // CHECK-NEXT:  `-IntegerLiteral {{.*}} 'int' 10
+  do {} while (some_invalid_val + 1 < 10);
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1894,7 +1894,8 @@
   ExprResult Cond = ParseExpression();
   // Correct the typos in condition before closing the scope.
   if (Cond.isUsable())
-Cond = Actions.CorrectDelayedTyposInExpr(Cond);
+Cond = Actions.CorrectDelayedTyposInExpr(Cond, /*InitDecl*/ nullptr,
+ /*RecoveryUncorrectedTypos*/ 
true);
   else {
 if (!Tok.isOneOf(tok::r_paren, tok::r_square, tok::r_brace))
   SkipUntil(tok::semi);


Index: clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
===
--- clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
+++ clang/test/SemaCXX/constexpr-function-recovery-crash.cpp
@@ -78,6 +78,9 @@
 constexpr int test12() { return "wrong"; } // expected-error {{cannot initialize return object of type 'int'}}
 constexpr int force12 = test12();  // expected-error {{must be initialized by a constant}}
 
+constexpr int test13() { do {} while (a < 10); return 0; }   // expected-error {{use of undeclared identifier}}
+static_assert(test13());  // expected-error {{static assertion expression is not an integral constant expression}}
+
 #define TEST_EVALUATE(Name, X) \
   constexpr int testEvaluate##Name() { \
 X return 0;\
Index: clang/test/AST/ast-dump-recovery.cpp
===
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -420,3 +420,15 @@
   // CHECK:  RecoveryExpr {{.*}} '' contains-errors lvalue
   // CHECK-NEXT: `-DeclRefExpr {{.*}} 'foo' 'int *'
 }
+
+void RecoveryToDoWhileStmtCond() {
+  // CHECK:   FunctionDecl {{.*}} RecoveryToDoWhileStmtCond
+  // CHECK:   `-DoStmt {{.*}}
+  // CHECK-NEXT:|-CompoundStmt {{.*}}
+  // CHECK-NEXT:`-BinaryOperator {{.*}} '' contains-errors '<'
+  // CHECK-NEXT:  |-BinaryOperator {{.*}} '' contains-errors '+'
+  // CHECK-NEXT:  | |-RecoveryExpr {{.*}} '' contains-errors lvalue
+  // CHECK-NEXT:  | `-IntegerLiteral {{.*}} 'int' 1
+  // CHECK-NEXT:  `-IntegerLiteral {{.*}} 'int' 10
+  do {} while (some_invalid_val + 1 < 10);
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1894,7 +1894,8 @@
   ExprResult Cond = ParseExpression();
   // Correct the typos in condition before closing the scope.
   if (Cond.isUsable())
-Cond = Actions.CorrectDelayedTyposInExpr(Cond);
+Cond = Actions.CorrectDelayedTyposInExpr(Cond, /*InitDecl*/ nullptr,
+  

[clang-tools-extra] 166372e - [clang-tidy] Fix inline namespaces in llvm-namespace-comment

2023-08-05 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-08-05T16:47:48Z
New Revision: 166372e0bd2db5de459fc9d4be7ea9873ce983f4

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

LOG: [clang-tidy] Fix inline namespaces in llvm-namespace-comment

Provide fixes for inline namespaces in the same format as clang-format.

Fixes: #56804

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D157178

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
index ad2d396311ed21..21e3bd08255d98 100644
--- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -23,9 +23,10 @@ namespace clang::tidy::readability {
 NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
-  "namespace( +([a-zA-Z0-9_:]+))?\\.? *(\\*/)?$",
-  llvm::Regex::IgnoreCase),
+  NamespaceCommentPattern(
+  "^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
+  "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$",
+  llvm::Regex::IgnoreCase),
   ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
   SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
 
@@ -67,8 +68,10 @@ getNamespaceNameAsWritten(SourceLocation &Loc, const 
SourceManager &Sources,
 } else if (Nesting == 0) {
   if (T->is(tok::raw_identifier)) {
 StringRef ID = T->getRawIdentifier();
-if (ID != "namespace" && ID != "inline")
+if (ID != "namespace")
   Result.append(std::string(ID));
+if (ID == "inline")
+  Result.append(" ");
   } else if (T->is(tok::coloncolon)) {
 Result.append("::");
   } else { // Any other kind of token is unexpected here.

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ba3a5d4a127653..a88df4d9f8909b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@ Changes in existing checks
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`llvm-namespace-comment
+  ` check to provide fixes for
+  ``inline`` namespaces in the same format as :program:`clang-format`.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
index e4626020ebaab9..f8c3ce5a5ee3c1 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
@@ -7,11 +7,39 @@ namespace 
/*comment1*/n3/*comment2*/::/*comment3*/inline/*comment4*/n4/*comment5
 void f();
 
 
-// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::n4' not terminated 
with
-// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::n4' starts here
+// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::inline n4' not 
terminated with
+// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::inline n4' starts here
 // CHECK-MESSAGES: :[[@LINE+2]]:2: warning: namespace 'n1::n2' not terminated 
with a closing comment [google-readability-namespace-comments]
 // CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'n1::n2' starts here
 }}
-// CHECK-FIXES: }  // namespace n3::n4
+// CHECK-FIXES: }  // namespace n3::inline n4
 // CHECK-FIXES: }  // namespace n1::n2
 
+namespace n7::inline n8 {
+// make namespace above 10 lines
+
+
+
+
+
+
+
+
+
+
+} // namespace n7::inline n8
+
+namespace n9::inline n10 {
+// make namespace above 10 lines
+
+
+
+
+
+
+
+
+
+
+} // namespace n9::n10
+// CHECK-MESSAGES: :[[@LINE-1]]:2: warning: namespace 'n9::inline n10' ends 
with a comment that refers to a wrong namespace 'n9::n10' 
[google-readability-namespace-comments]



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


[clang-tools-extra] ee2b765 - [clang-tidy][NFC] Update documentation for hicpp-avoid-goto

2023-08-05 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-08-05T16:47:49Z
New Revision: ee2b765cdd5ba28055fde25487139f2f1f7c6fb2

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

LOG: [clang-tidy][NFC] Update documentation for hicpp-avoid-goto

Add info in check list that hicpp-avoid-goto is actually
a alias to cppcoreguidelines-avoid-goto.

Fixes: #64337

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D157182

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
index ab36dc37a2be0a..f543f616feba07 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
@@ -1,4 +1,6 @@
 .. title:: clang-tidy - hicpp-avoid-goto
+.. meta::
+   :http-equiv=refresh: 5;URL=../cppcoreguidelines/avoid-goto.html
 
 hicpp-avoid-goto
 

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 48147eadd8df67..51736febb8792f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -241,7 +241,6 @@ Clang-Tidy Checks
`google-runtime-int `_,
`google-runtime-operator `_,
`google-upgrade-googletest-case `_, 
"Yes"
-   `hicpp-avoid-goto `_,
`hicpp-exception-baseclass `_,
`hicpp-multiway-paths-covered `_,
`hicpp-no-assembler `_,
@@ -503,6 +502,7 @@ Clang-Tidy Checks
`google-readability-function-size 
`_, `readability-function-size 
`_,
`google-readability-namespace-comments 
`_, `llvm-namespace-comment 
`_,
`hicpp-avoid-c-arrays `_, 
`modernize-avoid-c-arrays `_,
+   `hicpp-avoid-goto `_, cppcoreguidelines-avoid-goto 
`_,
`hicpp-braces-around-statements `_, 
`readability-braces-around-statements 
`_, "Yes"
`hicpp-deprecated-headers `_, 
`modernize-deprecated-headers `_, "Yes"
`hicpp-explicit-conversions `_, 
`google-explicit-constructor `_, "Yes"



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


[PATCH] D157178: [clang-tidy] Fix inline namespaces in llvm-namespace-comment

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG166372e0bd2d: [clang-tidy] Fix inline namespaces in 
llvm-namespace-comment (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157178/new/

https://reviews.llvm.org/D157178

Files:
  clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
@@ -7,11 +7,39 @@
 void f();
 
 
-// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::n4' not terminated 
with
-// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::n4' starts here
+// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::inline n4' not 
terminated with
+// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::inline n4' starts here
 // CHECK-MESSAGES: :[[@LINE+2]]:2: warning: namespace 'n1::n2' not terminated 
with a closing comment [google-readability-namespace-comments]
 // CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'n1::n2' starts here
 }}
-// CHECK-FIXES: }  // namespace n3::n4
+// CHECK-FIXES: }  // namespace n3::inline n4
 // CHECK-FIXES: }  // namespace n1::n2
 
+namespace n7::inline n8 {
+// make namespace above 10 lines
+
+
+
+
+
+
+
+
+
+
+} // namespace n7::inline n8
+
+namespace n9::inline n10 {
+// make namespace above 10 lines
+
+
+
+
+
+
+
+
+
+
+} // namespace n9::n10
+// CHECK-MESSAGES: :[[@LINE-1]]:2: warning: namespace 'n9::inline n10' ends 
with a comment that refers to a wrong namespace 'n9::n10' 
[google-readability-namespace-comments]
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,10 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`llvm-namespace-comment
+  ` check to provide fixes for
+  ``inline`` namespaces in the same format as :program:`clang-format`.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -23,9 +23,10 @@
 NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  NamespaceCommentPattern("^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
-  "namespace( +([a-zA-Z0-9_:]+))?\\.? *(\\*/)?$",
-  llvm::Regex::IgnoreCase),
+  NamespaceCommentPattern(
+  "^/[/*] *(end (of )?)? *(anonymous|unnamed)? *"
+  "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$",
+  llvm::Regex::IgnoreCase),
   ShortNamespaceLines(Options.get("ShortNamespaceLines", 1u)),
   SpacesBeforeComments(Options.get("SpacesBeforeComments", 1u)) {}
 
@@ -67,8 +68,10 @@
 } else if (Nesting == 0) {
   if (T->is(tok::raw_identifier)) {
 StringRef ID = T->getRawIdentifier();
-if (ID != "namespace" && ID != "inline")
+if (ID != "namespace")
   Result.append(std::string(ID));
+if (ID == "inline")
+  Result.append(" ");
   } else if (T->is(tok::coloncolon)) {
 Result.append("::");
   } else { // Any other kind of token is unexpected here.


Index: clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-c++17.cpp
@@ -7,11 +7,39 @@
 void f();
 
 
-// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::n4' not terminated with
-// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::n4' starts here
+// CHECK-MESSAGES: :[[@LINE+4]]:1: warning: namespace 'n3::inline n4' not terminated with
+// CHECK-MESSAGES: :[[@LINE-7]]:23: note: namespace 'n3::inline n4' starts here
 // CHECK-MESSAGES: :[[@LINE+2]]:2: warning: namespace 'n1::n2' not terminated with a closing comment [google-readability-namespace-comments]
 // CHECK-MESSAGES: :[[@LINE-10]]:11: note: namespace 'n1::n2' starts here
 }}
-// CHECK-FIXES: }  // namespace n3::n4
+// C

[clang-tools-extra] 3e2ed57 - [clang-tidy] Exclude class/struct scope variables from cppcoreguidelines-avoid-non-const-global-variables

2023-08-05 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-08-05T16:47:49Z
New Revision: 3e2ed5701b7e0a5f5b2f0d248fe82f78e0e07267

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

LOG: [clang-tidy] Exclude class/struct scope variables from 
cppcoreguidelines-avoid-non-const-global-variables

Ignore static variables declared within the scope of class/struct.
Those variables should be covered by I.3 rule.

Fixes: #47384

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D157180

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
index db723b144c140e..ee17b0e0142882 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
@@ -15,25 +15,24 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
-namespace {
-AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
-} // namespace
-
 void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
+  auto GlobalContext =
+  varDecl(hasGlobalStorage(),
+  hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(;
+
   auto GlobalVariable = varDecl(
-  hasGlobalStorage(),
+  GlobalContext,
   unless(anyOf(
-  isLocalVarDecl(), isConstexpr(), hasType(isConstQualified()),
+  isConstexpr(), hasType(isConstQualified()),
   hasType(referenceType(); // References can't be changed, only the
// data they reference can be changed.
 
   auto GlobalReferenceToNonConst =
-  varDecl(hasGlobalStorage(), hasType(referenceType()),
+  varDecl(GlobalContext, hasType(referenceType()),
   unless(hasType(references(qualType(isConstQualified());
 
-  auto GlobalPointerToNonConst =
-  varDecl(hasGlobalStorage(),
-  hasType(pointerType(pointee(unless(isConstQualified());
+  auto GlobalPointerToNonConst = varDecl(
+  GlobalContext, 
hasType(pointerType(pointee(unless(isConstQualified());
 
   Finder->addMatcher(GlobalVariable.bind("non-const_variable"), this);
   
Finder->addMatcher(GlobalReferenceToNonConst.bind("indirection_to_non-const"),

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a88df4d9f8909b..59ec57b6db4ade 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,11 @@ Changes in existing checks
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`cppcoreguidelines-avoid-non-const-global-variables
+  ` check
+  to ignore ``static`` variables declared within the scope of
+  ``class``/``struct``.
+
 - Improved :doc:`llvm-namespace-comment
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
index 5b1c004837e7fd..3ca1029433d229 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
@@ -236,3 +236,17 @@ int main() {
 nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
   }
 }
+
+// CHECKING AGAINST FALSE POSITIVES INSIDE STRUCT SCOPE /
+struct StructWithStatic {
+  static DummyStruct nonConstDummyStructInstance;
+  static int value;
+  static int* valuePtr;
+  static int& valueRef;
+};
+
+DummyStruct StructWithStatic::nonConstDummyStructInstance;
+int StructWithStatic::value = 0;
+int* StructWithStatic::valuePtr = &StructWithStatic::value;
+int& StructWithStatic::valueRef = StructWithStatic::value;
+



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


[PATCH] D157182: [clang-tidy][NFC] Update documentation for hicpp-avoid-goto

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee2b765cdd5b: [clang-tidy][NFC] Update documentation for 
hicpp-avoid-goto (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157182/new/

https://reviews.llvm.org/D157182

Files:
  clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst


Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -241,7 +241,6 @@
`google-runtime-int `_,
`google-runtime-operator `_,
`google-upgrade-googletest-case `_, 
"Yes"
-   `hicpp-avoid-goto `_,
`hicpp-exception-baseclass `_,
`hicpp-multiway-paths-covered `_,
`hicpp-no-assembler `_,
@@ -503,6 +502,7 @@
`google-readability-function-size 
`_, `readability-function-size 
`_,
`google-readability-namespace-comments 
`_, `llvm-namespace-comment 
`_,
`hicpp-avoid-c-arrays `_, 
`modernize-avoid-c-arrays `_,
+   `hicpp-avoid-goto `_, cppcoreguidelines-avoid-goto 
`_,
`hicpp-braces-around-statements `_, 
`readability-braces-around-statements 
`_, "Yes"
`hicpp-deprecated-headers `_, 
`modernize-deprecated-headers `_, "Yes"
`hicpp-explicit-conversions `_, 
`google-explicit-constructor `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
+++ clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
@@ -1,4 +1,6 @@
 .. title:: clang-tidy - hicpp-avoid-goto
+.. meta::
+   :http-equiv=refresh: 5;URL=../cppcoreguidelines/avoid-goto.html
 
 hicpp-avoid-goto
 


Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -241,7 +241,6 @@
`google-runtime-int `_,
`google-runtime-operator `_,
`google-upgrade-googletest-case `_, "Yes"
-   `hicpp-avoid-goto `_,
`hicpp-exception-baseclass `_,
`hicpp-multiway-paths-covered `_,
`hicpp-no-assembler `_,
@@ -503,6 +502,7 @@
`google-readability-function-size `_, `readability-function-size `_,
`google-readability-namespace-comments `_, `llvm-namespace-comment `_,
`hicpp-avoid-c-arrays `_, `modernize-avoid-c-arrays `_,
+   `hicpp-avoid-goto `_, cppcoreguidelines-avoid-goto `_,
`hicpp-braces-around-statements `_, `readability-braces-around-statements `_, "Yes"
`hicpp-deprecated-headers `_, `modernize-deprecated-headers `_, "Yes"
`hicpp-explicit-conversions `_, `google-explicit-constructor `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
+++ clang-tools-extra/docs/clang-tidy/checks/hicpp/avoid-goto.rst
@@ -1,4 +1,6 @@
 .. title:: clang-tidy - hicpp-avoid-goto
+.. meta::
+   :http-equiv=refresh: 5;URL=../cppcoreguidelines/avoid-goto.html
 
 hicpp-avoid-goto
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157180: [clang-tidy] Exclude class/struct scope variables from cppcoreguidelines-avoid-non-const-global-variables

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3e2ed5701b7e: [clang-tidy] Exclude class/struct scope 
variables from cppcoreguidelines-avoid… (authored by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D157180?vs=547457&id=547499#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157180/new/

https://reviews.llvm.org/D157180

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
@@ -236,3 +236,17 @@
 nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
   }
 }
+
+// CHECKING AGAINST FALSE POSITIVES INSIDE STRUCT SCOPE /
+struct StructWithStatic {
+  static DummyStruct nonConstDummyStructInstance;
+  static int value;
+  static int* valuePtr;
+  static int& valueRef;
+};
+
+DummyStruct StructWithStatic::nonConstDummyStructInstance;
+int StructWithStatic::value = 0;
+int* StructWithStatic::valuePtr = &StructWithStatic::value;
+int& StructWithStatic::valueRef = StructWithStatic::value;
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -163,6 +163,11 @@
   `, so that it does not warn
   on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`cppcoreguidelines-avoid-non-const-global-variables
+  ` check
+  to ignore ``static`` variables declared within the scope of
+  ``class``/``struct``.
+
 - Improved :doc:`llvm-namespace-comment
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
@@ -15,25 +15,24 @@
 
 namespace clang::tidy::cppcoreguidelines {
 
-namespace {
-AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
-} // namespace
-
 void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
+  auto GlobalContext =
+  varDecl(hasGlobalStorage(),
+  hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(;
+
   auto GlobalVariable = varDecl(
-  hasGlobalStorage(),
+  GlobalContext,
   unless(anyOf(
-  isLocalVarDecl(), isConstexpr(), hasType(isConstQualified()),
+  isConstexpr(), hasType(isConstQualified()),
   hasType(referenceType(); // References can't be changed, only the
// data they reference can be changed.
 
   auto GlobalReferenceToNonConst =
-  varDecl(hasGlobalStorage(), hasType(referenceType()),
+  varDecl(GlobalContext, hasType(referenceType()),
   unless(hasType(references(qualType(isConstQualified());
 
-  auto GlobalPointerToNonConst =
-  varDecl(hasGlobalStorage(),
-  hasType(pointerType(pointee(unless(isConstQualified());
+  auto GlobalPointerToNonConst = varDecl(
+  GlobalContext, 
hasType(pointerType(pointee(unless(isConstQualified());
 
   Finder->addMatcher(GlobalVariable.bind("non-const_variable"), this);
   
Finder->addMatcher(GlobalReferenceToNonConst.bind("indirection_to_non-const"),


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-non-const-global-variables.cpp
@@ -236,3 +236,17 @@
 nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
   }
 }
+
+// CHECKING AGAINST FALSE POSITIVES INSIDE STRUCT SCOPE /
+struct StructWithStatic {
+  static DummyStruct nonConstDummyStructInstance;
+  static int value;
+  static int* valuePtr;
+  static int& valueRef;
+};
+
+DummyStruct StructWithStatic::nonConstDummyStructInstance;
+int StructWithStatic::value = 0;
+int* StructWithStatic::valuePtr = &StructWithStatic::value;
+int& StructWithStatic::valueRef = StructWithStatic::value;
+
Index: clang-tools-extra/docs/Rele

[PATCH] D156693: [clang][ASTImporter]Skip check friend template declaration in VisitClassTemplateDecl

2023-08-05 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky updated this revision to Diff 547501.
jcsxky edited the summary of this revision.
jcsxky added a comment.

update diff: ignore compare depth in friend class template


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156693/new/

https://reviews.llvm.org/D156693

Files:
  clang/include/clang/AST/ASTStructuralEquivalence.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4212,6 +4212,57 @@
   EXPECT_TRUE(Imported->getPreviousDecl());
 }
 
+TEST_P(ImportFriendClasses, SkipFriendTemplateDeclaration) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x)  :x(x) {}
+
+  private:
+T x;
+  };
+  )",
+  Lang_CXX11);
+
+  auto *Fwd = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("A")));
+  Decl *FromTU = getTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x) : x(x) {}
+
+  private:
+T x;
+  };
+
+  A a1(0);
+  )",
+  Lang_CXX11, "input1.cc");
+  auto *Definition = FirstDeclMatcher().match(
+  FromTU, classTemplateDecl(hasName("A")));
+  auto *Template = Import(Definition, Lang_CXX11);
+  EXPECT_TRUE(Template);
+  auto *TemplateClass = cast(Template);
+  EXPECT_EQ(Fwd->getTemplatedDecl()->getTypeForDecl(),
+TemplateClass->getTemplatedDecl()->getTypeForDecl());
+}
+
 TEST_P(ImportFriendClasses,
ImportOfClassTemplateDefinitionShouldConnectToFwdFriend) {
   Decl *ToTU = getToTuDecl(
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1092,7 +1092,7 @@
   case Type::TemplateTypeParm: {
 const auto *Parm1 = cast(T1);
 const auto *Parm2 = cast(T2);
-if (Parm1->getDepth() != Parm2->getDepth())
+if (!Context.IgnoreDepth && Parm1->getDepth() != Parm2->getDepth())
   return false;
 if (Parm1->getIndex() != Parm2->getIndex())
   return false;
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -34,6 +34,7 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -506,7 +507,8 @@
 template 
 bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
 
-bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true);
+bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
+   bool IgnoreDepth = true);
 ExpectedDecl VisitDecl(Decl *D);
 ExpectedDecl VisitImportDecl(ImportDecl *D);
 ExpectedDecl VisitEmptyDecl(EmptyDecl *D);
@@ -2243,7 +2245,8 @@
 : StructuralEquivalenceKind::Default;
 }
 
-bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) {
+bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
+bool IgnoreDepth) {
   // Eliminate a potential failure point where we attempt to re-import
   // something we're trying to import while completing ToRecord.
   Decl *ToOrigin = Importer.GetOriginalDecl(To);
@@ -2254,7 +2257,7 @@
   StructuralEquivalenceContext Ctx(
   Importer.getFromContext(), Importer.getToContext(),
   Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer),
-  false, Complain);
+  false, Complain, false, IgnoreDepth);
   return Ctx.IsEquivalent(From, To);
 }
 
@@ -5822,7 +5825,7 @@
 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
   continue;
 
-if (IsStructuralMatch(D, FoundTemplate)) {
+if (IsStructuralMatch(D, FoundTemplate, true, true)) {
   ClassTemplateDecl *TemplateWithDef =
   getTemplateDefinition(FoundTemplate);
   if (D->isThisDeclarationADefinition() && TemplateWithDef)
Index: clang/include/clang/AST/ASTStructuralEquivalence.h
===
--- clang/include/clang/AST/ASTStructuralEquivalence.h
+++ clang/include/clang/AST/ASTStructuralEquivalence.h
@@ -69,15 +69,19 @@
   /// \c true if the last diagnostic came from ToCtx.
   bool LastDiagFromC2 = false;
 
+  /// Whether to igno

[PATCH] D154646: Fix some typos in comments: evalute -> evaluate (NFC)

2023-08-05 Thread Tianlan Zhou via Phabricator via cfe-commits
SuperSodaSea added a comment.

I don't have commit access, so if anyone could help commit this patch for me, I 
would appreciate it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154646/new/

https://reviews.llvm.org/D154646

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


[PATCH] D157078: [include-cleaner] Handle files with unnamed buffers

2023-08-05 Thread Tyler Lanphear via Phabricator via cfe-commits
tylanphear added a comment.

In D157078#4563212 , @RKSimon wrote:

> In D157078#4562788 , @tylanphear 
> wrote:
>
>> Seeing the link error downstream. I think clangSerialization needs to be 
>> added to the link libraries.
>
> Should be fixed by 36daf3532d91bb 
> 

Perfect. Thanks for the quick fix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157078/new/

https://reviews.llvm.org/D157078

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


[PATCH] D157185: [clang-tidy] Fix false-positives in performanc-noexcept-swap

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 547502.
PiotrZSL added a comment.

Rebase, add comments, make more strict for method (must be non-const)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157185/new/

https://reviews.llvm.org/D157185

Files:
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
@@ -201,3 +201,17 @@
 template 
 void swap(OK21 &, OK21 &) 
noexcept(noexcept(TemplateNoexceptWithInt::f()));
 void swap(OK21 &, OK21 &) 
noexcept(noexcept(TemplateNoexceptWithInt::f()));
+
+namespace PR64303 {
+  void swap();
+  void swap(int&, bool&);
+  void swap(int&, int&, int&);
+  void swap(int&);
+
+  struct Test {
+void swap();
+void swap(Test&, Test&);
+void swap(int&);
+static void swap(int&, int&);
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -172,6 +172,10 @@
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
 
+- Improved :doc:`performanc-noexcept-swap
+  ` check to enforce a stricter
+  match with the swap function signature, eliminating false-positives.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
@@ -17,9 +17,30 @@
 namespace clang::tidy::performance {
 
 void NoexceptSwapCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  functionDecl(unless(isDeleted()), 
hasName("swap")).bind(BindFuncDeclName),
-  this);
+
+  // Match non-const method with single argument that is non-const reference to
+  // a class type that owns method and return void void Class::swap(Class&)
+  auto MethodMatcher = cxxMethodDecl(
+  parameterCountIs(1U), unless(isConst()), returns(voidType()),
+  hasParameter(0, hasType(qualType(hasCanonicalType(
+  qualType(unless(isConstQualified()),
+   references(namedDecl().bind("class"))),
+  ofClass(equalsBoundNode("class")));
+
+  // Match function with 2 arguments, both are non-const references to same 
type
+  // and return void void swap(Type&, Type&)
+  auto FunctionMatcher = allOf(
+  unless(cxxMethodDecl()), parameterCountIs(2U), returns(voidType()),
+  hasParameter(
+  0, hasType(qualType(hasCanonicalType(
+ qualType(unless(isConstQualified()), references(qualType()))
+ .bind("type"),
+  hasParameter(1, hasType(qualType(hasCanonicalType(
+  qualType(equalsBoundNode("type")));
+  Finder->addMatcher(functionDecl(unless(isDeleted()), hasName("swap"),
+  anyOf(MethodMatcher, FunctionMatcher))
+ .bind(BindFuncDeclName),
+ this);
 }
 
 DiagnosticBuilder


Index: clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
@@ -201,3 +201,17 @@
 template 
 void swap(OK21 &, OK21 &) noexcept(noexcept(TemplateNoexceptWithInt::f()));
 void swap(OK21 &, OK21 &) noexcept(noexcept(TemplateNoexceptWithInt::f()));
+
+namespace PR64303 {
+  void swap();
+  void swap(int&, bool&);
+  void swap(int&, int&, int&);
+  void swap(int&);
+
+  struct Test {
+void swap();
+void swap(Test&, Test&);
+void swap(int&);
+static void swap(int&, int&);
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -172,6 +172,10 @@
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
 
+- Improved :doc:`performanc-noexcept-swap
+  ` check to enforce a stricter
+  match with the swap function signature, eliminating false-positives.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
===
--- clang-tools-extra/clang-tidy/perform

[PATCH] D157190: [clang-tidy] Fixed false-negative in readability-identifier-naming

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 547503.
PiotrZSL added a comment.

Rebase + make tests more simple


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157190/new/

https://reviews.llvm.org/D157190

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -707,3 +707,19 @@
 task ImplicitDeclTest(async_obj &a_object) {
   co_await a_object;  // CHECK-MESSAGES-NOT: warning: invalid case style for 
local variable
 }
+
+// Test scenario when canonical declaration will be a forward declaration
+struct ForwardDeclStruct;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 
'ForwardDeclStruct' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}struct forward_decl_struct;
+// CHECK-FIXES: {{^}}struct forward_decl_struct {
+struct ForwardDeclStruct {
+};
+
+struct forward_declared_as_struct;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for class 
'forward_declared_as_struct' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}struct CForwardDeclaredAsStruct;
+// CHECK-FIXES: {{^}}class CForwardDeclaredAsStruct {
+class forward_declared_as_struct {
+};
+
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -172,6 +172,10 @@
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
 
+- Improved the :doc:`readability-identifier-naming
+  ` check to emit proper
+  warnings when a type forward declaration precedes its definition.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1140,30 +1140,28 @@
 if (Decl->isAnonymousStructOrUnion())
   return SK_Invalid;
 
-if (!Decl->getCanonicalDecl()->isThisDeclarationADefinition())
-  return SK_Invalid;
-
-if (Decl->hasDefinition() && Decl->isAbstract() &&
-NamingStyles[SK_AbstractClass])
-  return SK_AbstractClass;
+if (const auto *Definition = Decl->getDefinition()) {
+  if (Definition->isAbstract() && NamingStyles[SK_AbstractClass])
+return SK_AbstractClass;
 
-if (Decl->isStruct() && NamingStyles[SK_Struct])
-  return SK_Struct;
+  if (Definition->isStruct() && NamingStyles[SK_Struct])
+return SK_Struct;
 
-if (Decl->isStruct() && NamingStyles[SK_Class])
-  return SK_Class;
+  if (Definition->isStruct() && NamingStyles[SK_Class])
+return SK_Class;
 
-if (Decl->isClass() && NamingStyles[SK_Class])
-  return SK_Class;
+  if (Definition->isClass() && NamingStyles[SK_Class])
+return SK_Class;
 
-if (Decl->isClass() && NamingStyles[SK_Struct])
-  return SK_Struct;
+  if (Definition->isClass() && NamingStyles[SK_Struct])
+return SK_Struct;
 
-if (Decl->isUnion() && NamingStyles[SK_Union])
-  return SK_Union;
+  if (Definition->isUnion() && NamingStyles[SK_Union])
+return SK_Union;
 
-if (Decl->isEnum() && NamingStyles[SK_Enum])
-  return SK_Enum;
+  if (Definition->isEnum() && NamingStyles[SK_Enum])
+return SK_Enum;
+}
 
 return SK_Invalid;
   }


Index: clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -707,3 +707,19 @@
 task ImplicitDeclTest(async_obj &a_object) {
   co_await a_object;  // CHECK-MESSAGES-NOT: warning: invalid case style for local variable
 }
+
+// Test scenario when canonical declaration will be a forward declaration
+struct ForwardDeclStruct;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for struct 'ForwardDeclStruct' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}struct forward_decl_struct;
+// CHECK-FIXES: {{^}}struct forward_decl_struct {
+struct ForwardDeclStruct {
+};
+
+struct forward_declared_as_struct;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: invalid case style for class 'forward_declared_as_struct' [readability-identifier-naming]
+// CHECK-FIXES: {{^}}struct CForwardDeclaredAsStruct;
+/

[PATCH] D157181: [clang-tidy] Re-add cppcoreguidelines-macro-to-enum alias

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 547504.
PiotrZSL added a comment.

Add release notes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157181/new/

https://reviews.llvm.org/D157181

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -156,6 +156,10 @@
 New check aliases
 ^
 
+- New alias :doc:`cppcoreguidelines-macro-to-enum
+  ` to 
:doc:`modernize-macro-to-enum
+  ` was added.
+
 Changes in existing checks
 ^^
 
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/MacroToEnumCheck.h"
 #include "../modernize/UseDefaultMemberInitCheck.h"
 #include "../modernize/UseOverrideCheck.h"
 #include "../performance/NoexceptDestructorCheck.h"
@@ -77,6 +78,8 @@
 "cppcoreguidelines-init-variables");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
+CheckFactories.registerCheck(
+"cppcoreguidelines-macro-to-enum");
 CheckFactories.registerCheck(
 "cppcoreguidelines-macro-usage");
 CheckFactories.registerCheck(


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -156,6 +156,10 @@
 New check aliases
 ^
 
+- New alias :doc:`cppcoreguidelines-macro-to-enum
+  ` to :doc:`modernize-macro-to-enum
+  ` was added.
+
 Changes in existing checks
 ^^
 
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/MacroToEnumCheck.h"
 #include "../modernize/UseDefaultMemberInitCheck.h"
 #include "../modernize/UseOverrideCheck.h"
 #include "../performance/NoexceptDestructorCheck.h"
@@ -77,6 +78,8 @@
 "cppcoreguidelines-init-variables");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
+CheckFactories.registerCheck(
+"cppcoreguidelines-macro-to-enum");
 CheckFactories.registerCheck(
 "cppcoreguidelines-macro-usage");
 CheckFactories.registerCheck(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156693: [clang][ASTImporter]Skip check friend template depth

2023-08-05 Thread Qizhi Hu via Phabricator via cfe-commits
jcsxky updated this revision to Diff 547505.
jcsxky added a comment.

clean unittest


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156693/new/

https://reviews.llvm.org/D156693

Files:
  clang/include/clang/AST/ASTStructuralEquivalence.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4212,6 +4212,56 @@
   EXPECT_TRUE(Imported->getPreviousDecl());
 }
 
+TEST_P(ImportFriendClasses, SkipFriendTemplateDeclaration) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x)  :x(x) {}
+
+  private:
+T x;
+  };
+  )",
+  Lang_CXX11);
+
+  auto *Fwd = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("A")));
+  Decl *FromTU = getTuDecl(
+  R"(
+  template 
+  class A;
+
+  template 
+  class A {
+  public:
+template 
+friend class A;
+
+A(T x) : x(x) {}
+
+  private:
+T x;
+  };
+
+  A a1(0);
+  )",
+  Lang_CXX11, "input1.cc");
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, classTemplateDecl(hasName("A")));
+  auto *ToA = Import(FromA, Lang_CXX11);
+  EXPECT_TRUE(ToA);
+  EXPECT_EQ(Fwd->getTemplatedDecl()->getTypeForDecl(),
+ToA->getTemplatedDecl()->getTypeForDecl());
+}
+
 TEST_P(ImportFriendClasses,
ImportOfClassTemplateDefinitionShouldConnectToFwdFriend) {
   Decl *ToTU = getToTuDecl(
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1092,7 +1092,7 @@
   case Type::TemplateTypeParm: {
 const auto *Parm1 = cast(T1);
 const auto *Parm2 = cast(T2);
-if (Parm1->getDepth() != Parm2->getDepth())
+if (!Context.IgnoreDepth && Parm1->getDepth() != Parm2->getDepth())
   return false;
 if (Parm1->getIndex() != Parm2->getIndex())
   return false;
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -34,6 +34,7 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -506,7 +507,8 @@
 template 
 bool hasSameVisibilityContextAndLinkage(T *Found, T *From);
 
-bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true);
+bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
+   bool IgnoreDepth = true);
 ExpectedDecl VisitDecl(Decl *D);
 ExpectedDecl VisitImportDecl(ImportDecl *D);
 ExpectedDecl VisitEmptyDecl(EmptyDecl *D);
@@ -2243,7 +2245,8 @@
 : StructuralEquivalenceKind::Default;
 }
 
-bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain) {
+bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
+bool IgnoreDepth) {
   // Eliminate a potential failure point where we attempt to re-import
   // something we're trying to import while completing ToRecord.
   Decl *ToOrigin = Importer.GetOriginalDecl(To);
@@ -2254,7 +2257,7 @@
   StructuralEquivalenceContext Ctx(
   Importer.getFromContext(), Importer.getToContext(),
   Importer.getNonEquivalentDecls(), getStructuralEquivalenceKind(Importer),
-  false, Complain);
+  false, Complain, false, IgnoreDepth);
   return Ctx.IsEquivalent(From, To);
 }
 
@@ -5822,7 +5825,7 @@
 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
   continue;
 
-if (IsStructuralMatch(D, FoundTemplate)) {
+if (IsStructuralMatch(D, FoundTemplate, true, true)) {
   ClassTemplateDecl *TemplateWithDef =
   getTemplateDefinition(FoundTemplate);
   if (D->isThisDeclarationADefinition() && TemplateWithDef)
Index: clang/include/clang/AST/ASTStructuralEquivalence.h
===
--- clang/include/clang/AST/ASTStructuralEquivalence.h
+++ clang/include/clang/AST/ASTStructuralEquivalence.h
@@ -69,15 +69,19 @@
   /// \c true if the last diagnostic came from ToCtx.
   bool LastDiagFromC2 = false;
 
+  /// Whether to ignore comparing the depth of NonTypeParmDecl
+  bool IgnoreDepth;
+
   StructuralEquivalenceContext(
   ASTContext &FromCtx, ASTContext &ToCtx,
   llvm::DenseSet> &NonEqu

[PATCH] D156858: Add Documentation for Execution Results Handling in Clang-REPL

2023-08-05 Thread QuillPusher via Phabricator via cfe-commits
QuillPusher requested changes to this revision.
QuillPusher added a comment.
This revision now requires changes to proceed.

Thanks @junaire for the clarification, following is the updated document 
structure:

1. Capture Execution Results
  - How the Feature works
  - more details
  - Implementation Details

2. Dump Captured Execution Results¶
  - How- the Feature works
  - more details
  - Implementation Details

@Krishna-13-cyber Please use the attached file named 
ExecutionResultsHandling.rst as the latest doc, so Jun can review the updated 
document.

F28589747: ExecutionResultsHandling.rst 




Comment at: clang/docs/ClangRepl.rst:217-232
 
+Execution Results Handling in Clang-Repl
+
+
+:doc:`ExecutionResultsHandling` features discussed below help extend the 
Clang-REPL 
+functionality by creating an interface between the execution results of a 
+program and the compiled program.

Execution Results Handling in Clang-Repl
===

:doc:`ExecutionResultsHandling` helps extend the Clang-REPL functionality by 
creating an interface between the execution results of a program and the 
compiled 
program. Following are its main components:

1 - **Capture Execution Results**: This feature helps capture the execution 
results 
of a program and bring them back to the compiled program.

2 - **Dump Captured Execution Results**: This feature helps create a temporary 
dump 
for Value Printing/Automatic Printf, that is, to display the value and type of 
the captured data.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156858/new/

https://reviews.llvm.org/D156858

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


[clang] 58a71c6 - [clang-format] Handle "// clang-format on" for SeparateDefinitionBlocks

2023-08-05 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-08-05T12:31:27-07:00
New Revision: 58a71c66db85f65bb6cdefe314f62318b95e9fc4

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

LOG: [clang-format] Handle "// clang-format on" for SeparateDefinitionBlocks

Fixes 63393.

Differential Revision: https://reviews.llvm.org/D156971

Added: 


Modified: 
clang/lib/Format/DefinitionBlockSeparator.cpp
clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/DefinitionBlockSeparator.cpp 
b/clang/lib/Format/DefinitionBlockSeparator.cpp
index 576c6597b27afe..8fb6f55f629edd 100644
--- a/clang/lib/Format/DefinitionBlockSeparator.cpp
+++ b/clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -143,8 +143,10 @@ void DefinitionBlockSeparator::separateBlocks(
   if (LikelyDefinition(OperateLine))
 return false;
 
-  if (OperateLine->First->is(tok::comment))
+  if (const auto *Tok = OperateLine->First;
+  Tok->is(tok::comment) && !isClangFormatOn(Tok->TokenText)) {
 return true;
+  }
 
   // A single line identifier that is not in the last line.
   if (OperateLine->First->is(tok::identifier) &&

diff  --git a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp 
b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
index 45dd2fdc46b68f..5cf4edcbdf2e5a 100644
--- a/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ b/clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -283,6 +283,15 @@ TEST_F(DefinitionBlockSeparatorTest, 
UntouchBlockStartStyle) {
 TEST_F(DefinitionBlockSeparatorTest, Always) {
   FormatStyle Style = getLLVMStyle();
   Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always;
+
+  verifyFormat("// clang-format off\n"
+   "template\n"
+   "concept C = not A>;\n"
+   "// clang-format on\n"
+   "\n"
+   "struct E {};",
+   Style);
+
   std::string Prefix = "namespace {\n";
   std::string Infix = "\n"
   "// Enum test1\n"



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


[PATCH] D156971: [clang-format] Handle "// clang-format on" for SeparateDefinitionBlocks

2023-08-05 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG58a71c66db85: [clang-format] Handle "// clang-format 
on" for SeparateDefinitionBlocks (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156971/new/

https://reviews.llvm.org/D156971

Files:
  clang/lib/Format/DefinitionBlockSeparator.cpp
  clang/unittests/Format/DefinitionBlockSeparatorTest.cpp


Index: clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
===
--- clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -283,6 +283,15 @@
 TEST_F(DefinitionBlockSeparatorTest, Always) {
   FormatStyle Style = getLLVMStyle();
   Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always;
+
+  verifyFormat("// clang-format off\n"
+   "template\n"
+   "concept C = not A>;\n"
+   "// clang-format on\n"
+   "\n"
+   "struct E {};",
+   Style);
+
   std::string Prefix = "namespace {\n";
   std::string Infix = "\n"
   "// Enum test1\n"
Index: clang/lib/Format/DefinitionBlockSeparator.cpp
===
--- clang/lib/Format/DefinitionBlockSeparator.cpp
+++ clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -143,8 +143,10 @@
   if (LikelyDefinition(OperateLine))
 return false;
 
-  if (OperateLine->First->is(tok::comment))
+  if (const auto *Tok = OperateLine->First;
+  Tok->is(tok::comment) && !isClangFormatOn(Tok->TokenText)) {
 return true;
+  }
 
   // A single line identifier that is not in the last line.
   if (OperateLine->First->is(tok::identifier) &&


Index: clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
===
--- clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
+++ clang/unittests/Format/DefinitionBlockSeparatorTest.cpp
@@ -283,6 +283,15 @@
 TEST_F(DefinitionBlockSeparatorTest, Always) {
   FormatStyle Style = getLLVMStyle();
   Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always;
+
+  verifyFormat("// clang-format off\n"
+   "template\n"
+   "concept C = not A>;\n"
+   "// clang-format on\n"
+   "\n"
+   "struct E {};",
+   Style);
+
   std::string Prefix = "namespace {\n";
   std::string Infix = "\n"
   "// Enum test1\n"
Index: clang/lib/Format/DefinitionBlockSeparator.cpp
===
--- clang/lib/Format/DefinitionBlockSeparator.cpp
+++ clang/lib/Format/DefinitionBlockSeparator.cpp
@@ -143,8 +143,10 @@
   if (LikelyDefinition(OperateLine))
 return false;
 
-  if (OperateLine->First->is(tok::comment))
+  if (const auto *Tok = OperateLine->First;
+  Tok->is(tok::comment) && !isClangFormatOn(Tok->TokenText)) {
 return true;
+  }
 
   // A single line identifier that is not in the last line.
   if (OperateLine->First->is(tok::identifier) &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D88299: [clang-format] Add MacroUnexpander.

2023-08-05 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.

@klimek can you have a look at 
https://github.com/llvm/llvm-project/issues/64275?




Comment at: clang/lib/Format/MacroCallReconstructor.cpp:223
+  }
+  assert(!ActiveExpansions.empty());
+  if (ActiveExpansions.back().SpelledI != ActiveExpansions.back().SpelledE) {

This fails as reported in https://github.com/llvm/llvm-project/issues/64275.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88299/new/

https://reviews.llvm.org/D88299

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2023-08-05 Thread Chris Cotter via Phabricator via cfe-commits
ccotter marked an inline comment as done.
ccotter added a comment.

All done on my end - @PiotrZSL if you're good would you mind landing this for 
me?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140760/new/

https://reviews.llvm.org/D140760

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


[PATCH] D154550: [clang-format] Allow empty loops on a single line.

2023-08-05 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added a comment.

In D154550#4562061 , @owenpan wrote:

> In D154550#4529346 , @gedare wrote:
>
>> In D154550#4526386 , @owenpan 
>> wrote:
>>
>>> Like `while (a);`, `while (a) {}` is also an empty loop, so `NonEmpty` is 
>>> misleading if it excludes the former but not the latter. IMO we should just 
>>> fix the bug without extending the option because any loop with a 
>>> single-statement body is a short loop.
>>
>> Agreed, except that many style guides (notably, K&R, LLVM, and Google) treat 
>> these two cases differently.
>
> LLVM doesn't merge short loops. Google uses `{}` instead of `;` whereas AFAIK 
> K&R does the opposite. I don't know of any major style that requires breaking 
> before the null statement and merging the empty block.

https://google.github.io/styleguide/cppguide.html#Formatting_Looping_Branching

Empty loop bodies should use either an empty pair of braces or continue with no 
braces, rather than a single semicolon.

  while (condition) {}  // Good - `{}` indicates no logic.
  while (condition) {
// Comments are okay, too
  }
  while (condition) continue;  // Good - `continue` indicates no logic.
  while (condition);  // Bad - looks like part of `do-while` loop.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154550/new/

https://reviews.llvm.org/D154550

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


[PATCH] D157057: [clang-tidy] Implement cppcoreguidelines CP.52

2023-08-05 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp:24-26
+  hasType(recordDecl(hasAnyName(
+  "::std::unique_lock", "::std::lock_guard",
+  "::std::scoped_lock", 
"::std::shared_lock"

PiotrZSL wrote:
> add configuration option for lock types, many big project got own types or 
> wrappers.
I was just thinking about this case...my code base had its own lock types that 
I would want to be able to include.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157057/new/

https://reviews.llvm.org/D157057

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


[PATCH] D154550: [clang-format] Allow empty loops on a single line.

2023-08-05 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added a comment.

In D154550#4562061 , @owenpan wrote:

> In D154550#4529346 , @gedare wrote:
>
>> In D154550#4526386 , @owenpan 
>> wrote:
>>
>>> Like `while (a);`, `while (a) {}` is also an empty loop, so `NonEmpty` is 
>>> misleading if it excludes the former but not the latter. IMO we should just 
>>> fix the bug without extending the option because any loop with a 
>>> single-statement body is a short loop.
>>
>> Agreed, except that many style guides (notably, K&R, LLVM, and Google) treat 
>> these two cases differently.
>
> LLVM doesn't merge short loops. Google uses `{}` instead of `;` whereas AFAIK 
> K&R does the opposite. I don't know of any major style that requires breaking 
> before the null statement and merging the empty block.

Got it. I can prepare a change to merge null as a short loop. I will get back 
to this in a couple weeks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154550/new/

https://reviews.llvm.org/D154550

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


[PATCH] D157197: [clang][CodeGen][OpenMP] Fix if-clause for 'target teams loop'

2023-08-05 Thread David Pagan via Phabricator via cfe-commits
ddpagan created this revision.
ddpagan added a reviewer: ABataev.
ddpagan added projects: clang, OpenMP.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
ddpagan requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, jplehr, sstefan1.

When emitting parallel region for 'target teams distribute parallel for' 
expansion of 'target teams loop', ignore if-clause as anything specified
should apply to target region only.

Updated test results for OpenMP/target_teams_generic_loop_if_codegen.cpp


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157197

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp

Index: clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
===
--- clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
+++ clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
@@ -695,7 +695,6 @@
 // CHECK1-NEXT:[[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[I:%.*]] = alloca i32, align 4
-// CHECK1-NEXT:[[DOTBOUND_ZERO_ADDR:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
 // CHECK1-NEXT:store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
 // CHECK1-NEXT:store i32 0, ptr [[DOTOMP_COMB_LB]], align 4
@@ -729,16 +728,12 @@
 // CHECK1-NEXT:[[TMP8:%.*]] = zext i32 [[TMP7]] to i64
 // CHECK1-NEXT:[[TMP9:%.*]] = load i32, ptr [[DOTOMP_COMB_UB]], align 4
 // CHECK1-NEXT:[[TMP10:%.*]] = zext i32 [[TMP9]] to i64
-// CHECK1-NEXT:call void @__kmpc_serialized_parallel(ptr @[[GLOB3]], i32 [[TMP1]])
-// CHECK1-NEXT:[[TMP11:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
-// CHECK1-NEXT:store i32 0, ptr [[DOTBOUND_ZERO_ADDR]], align 4
-// CHECK1-NEXT:call void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_main_l83.omp_outlined.omp_outlined(ptr [[TMP11]], ptr [[DOTBOUND_ZERO_ADDR]], i64 [[TMP8]], i64 [[TMP10]]) #[[ATTR2]]
-// CHECK1-NEXT:call void @__kmpc_end_serialized_parallel(ptr @[[GLOB3]], i32 [[TMP1]])
+// CHECK1-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB3]], i32 2, ptr @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_main_l83.omp_outlined.omp_outlined, i64 [[TMP8]], i64 [[TMP10]])
 // CHECK1-NEXT:br label [[OMP_INNER_FOR_INC:%.*]]
 // CHECK1:   omp.inner.for.inc:
-// CHECK1-NEXT:[[TMP12:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
-// CHECK1-NEXT:[[TMP13:%.*]] = load i32, ptr [[DOTOMP_STRIDE]], align 4
-// CHECK1-NEXT:[[ADD:%.*]] = add nsw i32 [[TMP12]], [[TMP13]]
+// CHECK1-NEXT:[[TMP11:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
+// CHECK1-NEXT:[[TMP12:%.*]] = load i32, ptr [[DOTOMP_STRIDE]], align 4
+// CHECK1-NEXT:[[ADD:%.*]] = add nsw i32 [[TMP11]], [[TMP12]]
 // CHECK1-NEXT:store i32 [[ADD]], ptr [[DOTOMP_IV]], align 4
 // CHECK1-NEXT:br label [[OMP_INNER_FOR_COND]]
 // CHECK1:   omp.inner.for.end:
@@ -847,7 +842,6 @@
 // CHECK1-NEXT:[[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[I:%.*]] = alloca i32, align 4
-// CHECK1-NEXT:[[DOTBOUND_ZERO_ADDR:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
 // CHECK1-NEXT:store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
 // CHECK1-NEXT:store i64 [[DOTCAPTURE_EXPR_]], ptr [[DOTCAPTURE_EXPR__ADDR]], align 8
@@ -882,25 +876,12 @@
 // CHECK1-NEXT:[[TMP8:%.*]] = zext i32 [[TMP7]] to i64
 // CHECK1-NEXT:[[TMP9:%.*]] = load i32, ptr [[DOTOMP_COMB_UB]], align 4
 // CHECK1-NEXT:[[TMP10:%.*]] = zext i32 [[TMP9]] to i64
-// CHECK1-NEXT:[[TMP11:%.*]] = load i8, ptr [[DOTCAPTURE_EXPR__ADDR]], align 1
-// CHECK1-NEXT:[[TOBOOL:%.*]] = trunc i8 [[TMP11]] to i1
-// CHECK1-NEXT:br i1 [[TOBOOL]], label [[OMP_IF_THEN:%.*]], label [[OMP_IF_ELSE:%.*]]
-// CHECK1:   omp_if.then:
 // CHECK1-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB3]], i32 2, ptr @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_main_l90.omp_outlined.omp_outlined, i64 [[TMP8]], i64 [[TMP10]])
-// CHECK1-NEXT:br label [[OMP_IF_END:%.*]]
-// CHECK1:   omp_if.else:
-// CHECK1-NEXT:call void @__kmpc_serialized_parallel(ptr @[[GLOB3]], i32 [[TMP1]])
-// CHECK1-NEXT:[[TMP12:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
-// CHECK1-NEXT:store i32 0, ptr [[DOTBOUND_ZERO_ADDR]], align 4
-// CHECK1-NEXT:call void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_main_l90.omp_outlined.omp_outlined(ptr [[TMP12]], ptr [[DOTBOUND_ZERO_ADDR]], i64 [[TMP8]], i64 [[TMP10]]) #[[ATTR2]]
-// CHECK1-NEXT:call void @__kmpc_end_serialized_parallel(ptr @[[GLOB3]], i32 [[TMP1]])
-// CHECK1-NEXT:br label

[PATCH] D157140: [clang][Sema][OpenMP] Fix capture region for 'target teams loop'

2023-08-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:15410
   break;
+case OMPD_target_teams_loop:
+  // This is equivalent to 'target teams distribute parallel for' with

Need to have capture region for parallel, no?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157140/new/

https://reviews.llvm.org/D157140

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


[PATCH] D157197: [clang][CodeGen][OpenMP] Fix if-clause for 'target teams loop'

2023-08-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Add the reference to openmp spec


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157197/new/

https://reviews.llvm.org/D157197

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


[PATCH] D140760: [clang-tidy] Support begin/end free functions in modernize-loop-convert

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6a1f8ef8a7aa: [clang-tidy] Support begin/end free functions 
in modernize-loop-convert (authored by ccotter, committed by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D140760?vs=547483&id=547509#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140760/new/

https://reviews.llvm.org/D140760

Files:
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-reverse.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-reverse.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-reverse.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-reverse.cpp
@@ -40,6 +40,8 @@
 // Make sure no header is included in this example
 // CHECK-FIXES-CUSTOM-NO-HEADER-NOT: #include
 
+namespace ADL {
+
 template 
 struct Reversable {
   using iterator = T *;
@@ -61,6 +63,28 @@
   const_iterator crend() const;
 };
 
+template 
+constexpr auto rbegin(C& c) -> decltype(c.rbegin()) { return c.rbegin(); }
+template 
+constexpr auto rend(C& c) -> decltype(c.rend()) { return c.rend(); }
+template 
+constexpr auto rbegin(const C& c) -> decltype(c.rbegin()) { return c.rbegin(); }
+template 
+constexpr auto rend(const C& c) -> decltype(c.rend()) { return c.rend(); }
+
+template 
+constexpr auto crbegin(C& c) -> decltype(c.crbegin());
+template 
+constexpr auto crend(C& c) -> decltype(c.crend());
+template 
+constexpr auto crbegin(const C& c) -> decltype(c.crbegin());
+template 
+constexpr auto crend(const C& c) -> decltype(c.crend());
+
+} // namespace ADL
+
+using ADL::Reversable;
+
 template 
 void observe(const T &);
 template 
@@ -85,6 +109,24 @@
   //   CHECK-FIXES-NEXT:   observe(Number);
   //   CHECK-FIXES-NEXT: }
 
+  for (auto I = rbegin(Numbers), E = rend(Numbers); I != E; ++I) {
+observe(*I);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES-RANGES: for (int Number : std::ranges::reverse_view(Numbers)) {
+  // CHECK-FIXES-CUSTOM: for (int Number : llvm::reverse(Numbers)) {
+  //   CHECK-FIXES-NEXT:   observe(Number);
+  //   CHECK-FIXES-NEXT: }
+
+  for (auto I = crbegin(Numbers), E = crend(Numbers); I != E; ++I) {
+observe(*I);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES-RANGES: for (int Number : std::ranges::reverse_view(Numbers)) {
+  // CHECK-FIXES-CUSTOM: for (int Number : llvm::reverse(Numbers)) {
+  //   CHECK-FIXES-NEXT:   observe(Number);
+  //   CHECK-FIXES-NEXT: }
+
   // Ensure these bad loops aren't transformed.
   for (auto I = Numbers.rbegin(), E = Numbers.end(); I != E; ++I) {
 observe(*I);
@@ -112,4 +154,13 @@
   // CHECK-FIXES-CUSTOM: for (int Number : llvm::reverse(Numbers)) {
   //   CHECK-FIXES-NEXT:   observe(Number);
   //   CHECK-FIXES-NEXT: }
+
+  for (auto I = rbegin(Numbers), E = rend(Numbers); I != E; ++I) {
+mutate(*I);
+  }
+  // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: use range-based for loop instead
+  // CHECK-FIXES-RANGES: for (int & Number : std::ranges::reverse_view(Numbers)) {
+  // CHECK-FIXES-CUSTOM: for (int & Number : llvm::reverse(Numbers)) {
+  //   CHECK-FIXES-NEXT:   mutate(Number);
+  //   CHECK-FIXES-NEXT: }
 }
Index: clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp
@@ -5,6 +5,22 @@
 // CHECK-FIXES-NOT: for ({{.*[^:]:[^:].*}})
 // CHECK-MESSAGES-NOT: modernize-loop-convert
 
+namespace somenamespace {
+  template  auto begin(T& t) -> decltype(t.begin());
+  template  auto begin(const T& t) -> decltype(t.begin());
+  template  auto end(T& t) -> decltype(t.end());
+  template  auto end(const T& t) -> decltype(t.end());
+  template  auto size(const T& t) -> decltype(t.size());
+} // namespace somenamespace
+
+struct SomeClass {
+  template  static auto begin(T& t) -> decltype(t.begin());
+  template  static auto begin(const T& t) -> decltype(t.begin());
+  template  static auto end(T& t) -> decltype(t.end());
+  template  static auto end(const T& t) -> decltype(t.end());
+  template  static auto size(const T& t) -> decltype(t.size());
+};
+
 namespace Negative {
 
 const int N = 6;
@@

[clang-tools-extra] 6a1f8ef - [clang-tidy] Support begin/end free functions in modernize-loop-convert

2023-08-05 Thread Piotr Zegar via cfe-commits

Author: Chris Cotter
Date: 2023-08-05T20:55:48Z
New Revision: 6a1f8ef8a7aaefea80ef0bc7c6c462a96215b50e

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

LOG: [clang-tidy] Support begin/end free functions in modernize-loop-convert

The modernize-loop-convert check will now match iterator based loops
that call the free functions 'begin'/'end', as well as matching the
free function 'size' on containers.

Test plan: Added unit test cases matching free function calls on
containers, and a single negative test case for length() which is not
supported.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D140760

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/loop-convert.rst

clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/loop-convert/structures.h
clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-basic.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-negative.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize/loop-convert-reverse.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 618d1860ff8bd0..dc3b0f70fb8add 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -17,11 +17,13 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 #include 
+#include 
 #include 
 
 using namespace clang::ast_matchers;
@@ -66,6 +68,15 @@ static const char EndCallName[] = "endCall";
 static const char EndVarName[] = "endVar";
 static const char DerefByValueResultName[] = "derefByValueResult";
 static const char DerefByRefResultName[] = "derefByRefResult";
+static const llvm::StringSet<> MemberNames{"begin",   "cbegin", "rbegin",
+   "crbegin", "end","cend",
+   "rend","crend",  "size"};
+static const llvm::StringSet<> ADLNames{"begin",   "cbegin", "rbegin",
+"crbegin", "end","cend",
+"rend","crend",  "size"};
+static const llvm::StringSet<> StdNames{
+"std::begin", "std::cbegin", "std::rbegin", "std::crbegin", "std::end",
+"std::cend",  "std::rend",   "std::crend",  "std::size"};
 
 static const StatementMatcher integerComparisonMatcher() {
   return expr(ignoringParenImpCasts(
@@ -129,6 +140,10 @@ StatementMatcher makeArrayLoopMatcher() {
 ///e = createIterator(); it != e; ++it) { ... }
 ///   for (containerType::iterator it = container.begin();
 ///it != anotherContainer.end(); ++it) { ... }
+///   for (containerType::iterator it = begin(container),
+///e = end(container); it != e; ++it) { ... }
+///   for (containerType::iterator it = std::begin(container),
+///e = std::end(container); it != e; ++it) { ... }
 /// \endcode
 /// The following string identifiers are bound to the parts of the AST:
 ///   InitVarName: 'it' (as a VarDecl)
@@ -137,6 +152,8 @@ StatementMatcher makeArrayLoopMatcher() {
 /// EndVarName: 'e' (as a VarDecl)
 ///   In the second example only:
 /// EndCallName: 'container.end()' (as a CXXMemberCallExpr)
+///   In the third/fourth examples:
+/// 'end(container)' or 'std::end(container)' (as a CallExpr)
 ///
 /// Client code will need to make sure that:
 ///   - The two containers on which 'begin' and 'end' are called are the same.
@@ -144,13 +161,22 @@ StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
 
   auto BeginNameMatcher = IsReverse ? hasAnyName("rbegin", "crbegin")
 : hasAnyName("begin", "cbegin");
+  auto BeginNameMatcherStd = IsReverse
+ ? hasAnyName("::std::rbegin", 
"::std::crbegin")
+ : hasAnyName("::std::begin", "::std::cbegin");
 
   auto EndNameMatcher =
   IsReverse ? hasAnyName("rend", "crend") : hasAnyName("end", "cend");
+  auto EndNameMatcherStd = IsReverse ? hasAnyName("::std::rend", 
"::std::crend")
+ : hasAnyName("::std::end", "::std::cend");
 
   StatementMatcher BeginCallMatcher =
-  cxxMemberCallExpr(argumentCountIs(0),
-callee(cxxMethodDecl(BeginNameMatcher)))
+  expr(anyOf(cxxMemberCallExpr(argumentCountIs(0),
+   callee(cxxMetho

[PATCH] D157188: [clang-tidy] Add bugprone-new-bool-conversion

2023-08-05 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added a comment.

In D157188#4563143 , @Eugene.Zelenko 
wrote:

> In D157188#4563139 , @PiotrZSL 
> wrote:
>
>> In D157188#4563105 , 
>> @Eugene.Zelenko wrote:
>>
>>> Shouldn't C-style allocation be checked too? Same for custom allocators via 
>>> configuration option.
>>
>> In theory it could, but in such case name of check would need to change...
>
> Something like `bugprone-resource-bool-conversion` should be generic enough.

Maybe `bugprone-allocation-bool-conversion`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157188/new/

https://reviews.llvm.org/D157188

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


[PATCH] D157197: [clang][CodeGen][OpenMP] Fix if-clause for 'target teams loop'

2023-08-05 Thread David Pagan via Phabricator via cfe-commits
ddpagan updated this revision to Diff 547515.
ddpagan added a comment.

Added reference to relevant portion of the OpenMP 5.2 specification.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157197/new/

https://reviews.llvm.org/D157197

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp

Index: clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
===
--- clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
+++ clang/test/OpenMP/target_teams_generic_loop_if_codegen.cpp
@@ -695,7 +695,6 @@
 // CHECK1-NEXT:[[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[I:%.*]] = alloca i32, align 4
-// CHECK1-NEXT:[[DOTBOUND_ZERO_ADDR:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
 // CHECK1-NEXT:store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
 // CHECK1-NEXT:store i32 0, ptr [[DOTOMP_COMB_LB]], align 4
@@ -729,16 +728,12 @@
 // CHECK1-NEXT:[[TMP8:%.*]] = zext i32 [[TMP7]] to i64
 // CHECK1-NEXT:[[TMP9:%.*]] = load i32, ptr [[DOTOMP_COMB_UB]], align 4
 // CHECK1-NEXT:[[TMP10:%.*]] = zext i32 [[TMP9]] to i64
-// CHECK1-NEXT:call void @__kmpc_serialized_parallel(ptr @[[GLOB3]], i32 [[TMP1]])
-// CHECK1-NEXT:[[TMP11:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
-// CHECK1-NEXT:store i32 0, ptr [[DOTBOUND_ZERO_ADDR]], align 4
-// CHECK1-NEXT:call void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_main_l83.omp_outlined.omp_outlined(ptr [[TMP11]], ptr [[DOTBOUND_ZERO_ADDR]], i64 [[TMP8]], i64 [[TMP10]]) #[[ATTR2]]
-// CHECK1-NEXT:call void @__kmpc_end_serialized_parallel(ptr @[[GLOB3]], i32 [[TMP1]])
+// CHECK1-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB3]], i32 2, ptr @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_main_l83.omp_outlined.omp_outlined, i64 [[TMP8]], i64 [[TMP10]])
 // CHECK1-NEXT:br label [[OMP_INNER_FOR_INC:%.*]]
 // CHECK1:   omp.inner.for.inc:
-// CHECK1-NEXT:[[TMP12:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
-// CHECK1-NEXT:[[TMP13:%.*]] = load i32, ptr [[DOTOMP_STRIDE]], align 4
-// CHECK1-NEXT:[[ADD:%.*]] = add nsw i32 [[TMP12]], [[TMP13]]
+// CHECK1-NEXT:[[TMP11:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
+// CHECK1-NEXT:[[TMP12:%.*]] = load i32, ptr [[DOTOMP_STRIDE]], align 4
+// CHECK1-NEXT:[[ADD:%.*]] = add nsw i32 [[TMP11]], [[TMP12]]
 // CHECK1-NEXT:store i32 [[ADD]], ptr [[DOTOMP_IV]], align 4
 // CHECK1-NEXT:br label [[OMP_INNER_FOR_COND]]
 // CHECK1:   omp.inner.for.end:
@@ -847,7 +842,6 @@
 // CHECK1-NEXT:[[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:[[I:%.*]] = alloca i32, align 4
-// CHECK1-NEXT:[[DOTBOUND_ZERO_ADDR:%.*]] = alloca i32, align 4
 // CHECK1-NEXT:store ptr [[DOTGLOBAL_TID_]], ptr [[DOTGLOBAL_TID__ADDR]], align 8
 // CHECK1-NEXT:store ptr [[DOTBOUND_TID_]], ptr [[DOTBOUND_TID__ADDR]], align 8
 // CHECK1-NEXT:store i64 [[DOTCAPTURE_EXPR_]], ptr [[DOTCAPTURE_EXPR__ADDR]], align 8
@@ -882,25 +876,12 @@
 // CHECK1-NEXT:[[TMP8:%.*]] = zext i32 [[TMP7]] to i64
 // CHECK1-NEXT:[[TMP9:%.*]] = load i32, ptr [[DOTOMP_COMB_UB]], align 4
 // CHECK1-NEXT:[[TMP10:%.*]] = zext i32 [[TMP9]] to i64
-// CHECK1-NEXT:[[TMP11:%.*]] = load i8, ptr [[DOTCAPTURE_EXPR__ADDR]], align 1
-// CHECK1-NEXT:[[TOBOOL:%.*]] = trunc i8 [[TMP11]] to i1
-// CHECK1-NEXT:br i1 [[TOBOOL]], label [[OMP_IF_THEN:%.*]], label [[OMP_IF_ELSE:%.*]]
-// CHECK1:   omp_if.then:
 // CHECK1-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB3]], i32 2, ptr @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_main_l90.omp_outlined.omp_outlined, i64 [[TMP8]], i64 [[TMP10]])
-// CHECK1-NEXT:br label [[OMP_IF_END:%.*]]
-// CHECK1:   omp_if.else:
-// CHECK1-NEXT:call void @__kmpc_serialized_parallel(ptr @[[GLOB3]], i32 [[TMP1]])
-// CHECK1-NEXT:[[TMP12:%.*]] = load ptr, ptr [[DOTGLOBAL_TID__ADDR]], align 8
-// CHECK1-NEXT:store i32 0, ptr [[DOTBOUND_ZERO_ADDR]], align 4
-// CHECK1-NEXT:call void @{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}_main_l90.omp_outlined.omp_outlined(ptr [[TMP12]], ptr [[DOTBOUND_ZERO_ADDR]], i64 [[TMP8]], i64 [[TMP10]]) #[[ATTR2]]
-// CHECK1-NEXT:call void @__kmpc_end_serialized_parallel(ptr @[[GLOB3]], i32 [[TMP1]])
-// CHECK1-NEXT:br label [[OMP_IF_END]]
-// CHECK1:   omp_if.end:
 // CHECK1-NEXT:br label [[OMP_INNER_FOR_INC:%.*]]
 // CHECK1:   omp.inner.for.inc:
-// CHECK1-NEXT:[[TMP13:%.*]] = load i32, ptr [[DOTOMP_IV]], align 4
-// CHECK1-NEXT:[[TMP14:%.*]] = load i32, ptr [[DOTOMP_STRIDE]], align 4
-// CHECK1-NEXT:[[ADD:%.*]] = add nsw i32 [[TMP13]], [[TMP14]]
+// CHECK1-NEXT:[[TMP11:%.*]] = load i32, pt

[PATCH] D157197: [clang][CodeGen][OpenMP] Fix if-clause for 'target teams loop'

2023-08-05 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:1564
+  // Any if-clause associated with expansion for 'target teams loop' should
+  // apply to target region only. OpenMP 5.2 [3.4, if Clause, Semantics, 15-18]
+  if (S.getDirectiveKind() != OMPD_target_teams_loop)

I don't see this statement in the standard


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157197/new/

https://reviews.llvm.org/D157197

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


[PATCH] D157200: [clang][Interp] Visit Logical-not operand as bool

2023-08-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The `invBool` op here expects a bool operand, but in C, the operand might be of 
a different type (usually int).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157200

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/c.c


Index: clang/test/AST/Interp/c.c
===
--- clang/test/AST/Interp/c.c
+++ clang/test/AST/Interp/c.c
@@ -9,6 +9,8 @@
 // pedantic-expected-warning {{not an integer 
constant expression}}
 _Static_assert(1 && 1.0, "");
 _Static_assert( (5 > 4) + (3 > 2) == 2, "");
+_Static_assert(!!1.0, "");
+_Static_assert(!!1, "");
 
 /// FIXME: Should also be rejected in the new interpreter
 int a = (1 == 1 ? 5 : 3);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2481,10 +2481,18 @@
 return this->emitStore(*T, E);
   }
   case UO_LNot: // !x
-if (!this->visit(SubExpr))
+if (DiscardResult)
+  return this->discard(SubExpr);
+
+if (!this->visitBool(SubExpr))
   return false;
-// The Inv doesn't change anything, so skip it if we don't need the result.
-return DiscardResult ? this->emitPop(*T, E) : this->emitInvBool(E);
+
+if (!this->emitInvBool(E))
+  return false;
+
+if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
+  return this->emitCast(PT_Bool, ET, E);
+return true;
   case UO_Minus: // -x
 if (!this->visit(SubExpr))
   return false;


Index: clang/test/AST/Interp/c.c
===
--- clang/test/AST/Interp/c.c
+++ clang/test/AST/Interp/c.c
@@ -9,6 +9,8 @@
 // pedantic-expected-warning {{not an integer constant expression}}
 _Static_assert(1 && 1.0, "");
 _Static_assert( (5 > 4) + (3 > 2) == 2, "");
+_Static_assert(!!1.0, "");
+_Static_assert(!!1, "");
 
 /// FIXME: Should also be rejected in the new interpreter
 int a = (1 == 1 ? 5 : 3);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2481,10 +2481,18 @@
 return this->emitStore(*T, E);
   }
   case UO_LNot: // !x
-if (!this->visit(SubExpr))
+if (DiscardResult)
+  return this->discard(SubExpr);
+
+if (!this->visitBool(SubExpr))
   return false;
-// The Inv doesn't change anything, so skip it if we don't need the result.
-return DiscardResult ? this->emitPop(*T, E) : this->emitInvBool(E);
+
+if (!this->emitInvBool(E))
+  return false;
+
+if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
+  return this->emitCast(PT_Bool, ET, E);
+return true;
   case UO_Minus: // -x
 if (!this->visit(SubExpr))
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157197: [clang][CodeGen][OpenMP] Fix if-clause for 'target teams loop'

2023-08-05 Thread David Pagan via Phabricator via cfe-commits
ddpagan added inline comments.



Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:1564
+  // Any if-clause associated with expansion for 'target teams loop' should
+  // apply to target region only. OpenMP 5.2 [3.4, if Clause, Semantics, 15-18]
+  if (S.getDirectiveKind() != OMPD_target_teams_loop)

ABataev wrote:
> I don't see this statement in the standard
Sorry for that confusion on my part, Alexey. You're correct. I'll change this 
to the proper spec phrasing and resubmit.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157197/new/

https://reviews.llvm.org/D157197

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


[clang-tools-extra] 3d80103 - [clang-tidy][NFC] Fix link in documentation

2023-08-05 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-08-06T05:16:22Z
New Revision: 3d8010363895bd063a2d33172a07985b4c9b97ee

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

LOG: [clang-tidy][NFC] Fix link in documentation

Fix link to cppcoreguidelines-avoid-goto in doc.

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 51736febb8792f..2e2fe0dfa51fe8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -502,7 +502,7 @@ Clang-Tidy Checks
`google-readability-function-size 
`_, `readability-function-size 
`_,
`google-readability-namespace-comments 
`_, `llvm-namespace-comment 
`_,
`hicpp-avoid-c-arrays `_, 
`modernize-avoid-c-arrays `_,
-   `hicpp-avoid-goto `_, cppcoreguidelines-avoid-goto 
`_,
+   `hicpp-avoid-goto `_, `cppcoreguidelines-avoid-goto 
`_,
`hicpp-braces-around-statements `_, 
`readability-braces-around-statements 
`_, "Yes"
`hicpp-deprecated-headers `_, 
`modernize-deprecated-headers `_, "Yes"
`hicpp-explicit-conversions `_, 
`google-explicit-constructor `_, "Yes"



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


[PATCH] D157185: [clang-tidy] Fix false-positives in performanc-noexcept-swap

2023-08-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp:31
+  // Match function with 2 arguments, both are non-const references to same 
type
+  // and return void void swap(Type&, Type&)
+  auto FunctionMatcher = allOf(

Duplicate void, remove



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp:215
+void swap(int&);
+static void swap(int&, int&);
+  };

Could we also test:

`friend void swap(T&, T&)`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157185/new/

https://reviews.llvm.org/D157185

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


[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-05 Thread Yichi Lee via Phabricator via cfe-commits
yichi170 created this revision.
Herald added a project: All.
yichi170 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157201

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExpr.cpp


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16692,6 +16692,10 @@
 if (!MemberDecl) {
   if ((IndirectMemberDecl = R.getAsSingle()))
 MemberDecl = IndirectMemberDecl->getAnonField();
+
+  IdentifierInfo *II = RD->getIdentifier();
+  if (II == OC.U.IdentInfo && OC.isQualifier)
+continue;
 }
 
 if (!MemberDecl) {
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2641,10 +2641,13 @@
 
 // FIXME: This loop leaks the index expressions on error.
 while (true) {
-  if (Tok.is(tok::period)) {
+  if (Tok.is(tok::period) || Tok.is(tok::coloncolon)) {
 // offsetof-member-designator: offsetof-member-designator '.' 
identifier
+if (Tok.is(tok::coloncolon))
+  Comps.back().isQualifier = true;
 Comps.push_back(Sema::OffsetOfComponent());
 Comps.back().isBrackets = false;
+Comps.back().isQualifier = false;
 Comps.back().LocStart = ConsumeToken();
 
 if (Tok.isNot(tok::identifier)) {
@@ -2661,6 +2664,7 @@
 // offsetof-member-designator: offsetof-member-design '[' expression 
']'
 Comps.push_back(Sema::OffsetOfComponent());
 Comps.back().isBrackets = true;
+Comps.back().isQualifier = false;
 BalancedDelimiterTracker ST(*this, tok::l_square);
 ST.consumeOpen();
 Comps.back().LocStart = ST.getOpenLocation();
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -6036,6 +6036,7 @@
   struct OffsetOfComponent {
 SourceLocation LocStart, LocEnd;
 bool isBrackets;  // true if [expr], false if .ident
+bool isQualifier;
 union {
   IdentifierInfo *IdentInfo;
   Expr *E;


Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16692,6 +16692,10 @@
 if (!MemberDecl) {
   if ((IndirectMemberDecl = R.getAsSingle()))
 MemberDecl = IndirectMemberDecl->getAnonField();
+
+  IdentifierInfo *II = RD->getIdentifier();
+  if (II == OC.U.IdentInfo && OC.isQualifier)
+continue;
 }
 
 if (!MemberDecl) {
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2641,10 +2641,13 @@
 
 // FIXME: This loop leaks the index expressions on error.
 while (true) {
-  if (Tok.is(tok::period)) {
+  if (Tok.is(tok::period) || Tok.is(tok::coloncolon)) {
 // offsetof-member-designator: offsetof-member-designator '.' identifier
+if (Tok.is(tok::coloncolon))
+  Comps.back().isQualifier = true;
 Comps.push_back(Sema::OffsetOfComponent());
 Comps.back().isBrackets = false;
+Comps.back().isQualifier = false;
 Comps.back().LocStart = ConsumeToken();
 
 if (Tok.isNot(tok::identifier)) {
@@ -2661,6 +2664,7 @@
 // offsetof-member-designator: offsetof-member-design '[' expression ']'
 Comps.push_back(Sema::OffsetOfComponent());
 Comps.back().isBrackets = true;
+Comps.back().isQualifier = false;
 BalancedDelimiterTracker ST(*this, tok::l_square);
 ST.consumeOpen();
 Comps.back().LocStart = ST.getOpenLocation();
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -6036,6 +6036,7 @@
   struct OffsetOfComponent {
 SourceLocation LocStart, LocEnd;
 bool isBrackets;  // true if [expr], false if .ident
+bool isQualifier;
 union {
   IdentifierInfo *IdentInfo;
   Expr *E;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

You're missing tests.




Comment at: clang/lib/Sema/SemaExpr.cpp:16696-16697
+
+  IdentifierInfo *II = RD->getIdentifier();
+  if (II == OC.U.IdentInfo && OC.isQualifier)
+continue;




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157201/new/

https://reviews.llvm.org/D157201

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


[PATCH] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Thanks a lot for working on this. Can you add tests (to 
`clang/test/SemaCXX/offsetof.cpp`)?
The change will also need an entry in `clang/docs/ReleaseNotes.rst` , in the 
"C++ Language Changes"  section


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157201/new/

https://reviews.llvm.org/D157201

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


[PATCH] D157188: [clang-tidy] Add bugprone-allocation-bool-conversion

2023-08-05 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 547523.
PiotrZSL retitled this revision from "[clang-tidy] Add 
bugprone-new-bool-conversion" to "[clang-tidy] Add 
bugprone-allocation-bool-conversion".
PiotrZSL edited the summary of this revision.
PiotrZSL added a comment.

Change check anme, add configuration option.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157188/new/

https://reviews.llvm.org/D157188

Files:
  clang-tools-extra/clang-tidy/bugprone/AllocationBoolConversionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/AllocationBoolConversionCheck.h
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/allocation-bool-conversion.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/allocation-bool-conversion.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/allocation-bool-conversion.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/allocation-bool-conversion.cpp
@@ -0,0 +1,97 @@
+// RUN: %check_clang_tidy %s bugprone-allocation-bool-conversion %t  -- -config="{CheckOptions: { bugprone-allocation-bool-conversion.portability-restrict-system-includes.AllocationFunctions: 'malloc;allocate;custom' }}"
+
+void takeBool(bool);
+void* operator new(unsigned long count);
+void *malloc(unsigned long size);
+
+template
+struct Allocator {
+  typedef T* pointer;
+  pointer allocate(unsigned long n, const void* hint = 0);
+};
+
+void* custom();
+void* negative();
+
+static Allocator allocator;
+
+void testImplicit() {
+  takeBool(negative());
+
+  takeBool(new int);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  takeBool(new bool);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  takeBool(operator new(10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: result of the 'operator new' call is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  takeBool(malloc(10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: result of the 'malloc' call is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  takeBool(allocator.allocate(1U));
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: result of the 'allocate' call is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+
+  takeBool(custom());
+
+  bool value;
+
+  value = negative();
+
+  value = new int;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  value = new bool;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  value = operator new(10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: result of the 'operator new' call is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  value = malloc(10);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: result of the 'malloc' call is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  value = allocator.allocate(1U);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: result of the 'allocate' call is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  value = custom();
+}
+
+void testExplicit() {
+  takeBool(static_cast(negative()));
+
+  takeBool(static_cast(new int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  takeBool(static_cast(new bool));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: result of the 'new' expression is being used as a boolean value, which may lead to unintended behavior or resource leaks [bugprone-allocation-bool-conversion]
+  takeBool(static_cast(operator new(10)));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: result of the 'operator new' call is being used as a boolean value, which may lead to unintended behav