[PATCH] D157119: cmake: add missing dependencies on ClangDriverOptions tablegen

2023-08-06 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

I suspect one of your recent changes broke 
https://lab.llvm.org/buildbot/#/builders/168/builds/14944
Can you please take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157119

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


Re: [clang] 3b34d69 - Revert "For #64088: mark vtable as used if we might emit a reference to it."

2023-08-06 Thread David Blaikie via cfe-commits
Ping on this - please always include details on the reason for a revert.

On Tue, Aug 1, 2023 at 10:09 AM Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> This revert reintroduces a wrong-code bug, can you explain what the
> purpose of the revert is?
>
> On Fri, 28 Jul 2023 at 03:50, Dmitry Chernenkov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>>
>> Author: Dmitry Chernenkov
>> Date: 2023-07-28T10:49:53Z
>> New Revision: 3b34d69ac7a643742364be3591b324ddd14ef9aa
>>
>> URL:
>> https://github.com/llvm/llvm-project/commit/3b34d69ac7a643742364be3591b324ddd14ef9aa
>> DIFF:
>> https://github.com/llvm/llvm-project/commit/3b34d69ac7a643742364be3591b324ddd14ef9aa.diff
>>
>> LOG: Revert "For #64088: mark vtable as used if we might emit a reference
>> to it."
>>
>> This reverts commit b6847edfc235829b37dd6d734ef5bbfa0a58b6fc.
>>
>> Added:
>>
>>
>> Modified:
>> clang/lib/Sema/SemaCast.cpp
>> clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>>
>> Removed:
>>
>>
>>
>>
>> 
>> diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
>> index b338d601db7397..d65ecf52c52310 100644
>> --- a/clang/lib/Sema/SemaCast.cpp
>> +++ b/clang/lib/Sema/SemaCast.cpp
>> @@ -935,14 +935,6 @@ void CastOperation::CheckDynamicCast() {
>><< isClangCL;
>>}
>>
>> -  // For a dynamic_cast to a final type, IR generation might emit a
>> reference
>> -  // to the vtable.
>> -  if (DestRecord) {
>> -auto *DestDecl = DestRecord->getAsCXXRecordDecl();
>> -if (DestDecl->isEffectivelyFinal())
>> -  Self.MarkVTableUsed(OpRange.getBegin(), DestDecl);
>> -  }
>> -
>>// Done. Everything else is run-time checks.
>>Kind = CK_Dynamic;
>>  }
>>
>> diff  --git a/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>> b/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>> index bd283e85101b4b..676aa975a72686 100644
>> --- a/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>> +++ b/clang/test/CodeGenCXX/dynamic-cast-exact.cpp
>> @@ -76,12 +76,3 @@ H *exact_multi(A *a) {
>>// CHECK: phi ptr [ %[[RESULT]], %[[LABEL_NOTNULL]] ], [ null,
>> %[[LABEL_FAILED]] ]
>>return dynamic_cast(a);
>>  }
>> -
>> -namespace GH64088 {
>> -  // Ensure we mark the B vtable as used here, because we're going to
>> emit a
>> -  // reference to it.
>> -  // CHECK: define {{.*}} @_ZN7GH640881BD0
>> -  struct A { virtual ~A(); };
>> -  struct B final : A { virtual ~B() = default; };
>> -  B *cast(A *p) { return dynamic_cast(p); }
>> -}
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-06 Thread Sandeep via Phabricator via cfe-commits
sandeepkosuri added a comment.

In D152054#4560353 , @tianshilei1992 
wrote:

> Is this patch to support `thread_limit` on `target` directive on the host?

Yes @tianshilei1992 , It is for host only


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D157251: [X86][regcall] Do not produce @ number suffix if it is regcall4

2023-08-06 Thread Bing Yu via Phabricator via cfe-commits
yubing created this revision.
Herald added a project: All.
yubing 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/D157251

Files:
  clang/lib/AST/Mangle.cpp


Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -212,6 +212,10 @@
   else
 mangleCXXName(GD, Out);
 
+  // do no produce @ suffix if it is regcall4
+  if (getASTContext().getLangOpts().RegCall4)
+return;
+
   const FunctionDecl *FD = cast(D);
   const FunctionType *FT = FD->getType()->castAs();
   const FunctionProtoType *Proto = dyn_cast(FT);


Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -212,6 +212,10 @@
   else
 mangleCXXName(GD, Out);
 
+  // do no produce @ suffix if it is regcall4
+  if (getASTContext().getLangOpts().RegCall4)
+return;
+
   const FunctionDecl *FD = cast(D);
   const FunctionType *FT = FD->getType()->castAs();
   const FunctionProtoType *Proto = dyn_cast(FT);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157249: [clang][ASTImporter] Add import of 'ConvertVectorExpr'

2023-08-06 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added reviewers: balazske, aaron.ballman.
danix800 added a project: clang.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

Add import of `ConvertVectorExpr`.

Depends on https://reviews.llvm.org/D157248


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157249

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -986,6 +986,17 @@
   chooseExpr()));
 }
 
+TEST_P(ASTMatchersTest, ConvertVectorExpr) {
+  EXPECT_TRUE(matches(
+  "typedef double vector4double __attribute__((__vector_size__(32)));"
+  "typedef float  vector4float  __attribute__((__vector_size__(16)));"
+  "vector4float vf;"
+  "void f() { (void)__builtin_convertvector(vf, vector4double); }",
+  convertVectorExpr()));
+  EXPECT_TRUE(notMatches("void f() { (void)__builtin_choose_expr(1, 2, 3); }",
+ convertVectorExpr()));
+}
+
 TEST_P(ASTMatchersTest, GNUNullExpr) {
   if (!GetParam().isCXX()) {
 return;
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1295,6 +1295,29 @@
 ToChooseExpr->isConditionDependent());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportConvertVectorExpr) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  "typedef double v4double __attribute__((__vector_size__(32)));"
+  "typedef float  v4float  __attribute__((__vector_size__(16)));"
+  "v4float vf;"
+  "void declToImport() { (void)__builtin_convertvector(vf, v4double); }",
+  Lang_CXX03, "", Lang_CXX03);
+
+  auto ToResults =
+  match(convertVectorExpr().bind("convert"), To->getASTContext());
+  auto FromResults =
+  match(convertVectorExpr().bind("convert"), From->getASTContext());
+
+  const ConvertVectorExpr *FromConvertVectorExpr =
+  selectFirst("convert", FromResults);
+  ASSERT_TRUE(FromConvertVectorExpr);
+
+  const ConvertVectorExpr *ToConvertVectorExpr =
+  selectFirst("convert", ToResults);
+  ASSERT_TRUE(ToConvertVectorExpr);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -178,6 +178,7 @@
   REGISTER_MATCHER(constantExpr);
   REGISTER_MATCHER(containsDeclaration);
   REGISTER_MATCHER(continueStmt);
+  REGISTER_MATCHER(convertVectorExpr);
   REGISTER_MATCHER(coreturnStmt);
   REGISTER_MATCHER(coroutineBodyStmt);
   REGISTER_MATCHER(coyieldExpr);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -941,6 +941,8 @@
 const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
 const internal::VariadicDynCastAllOfMatcher chooseExpr;
+const internal::VariadicDynCastAllOfMatcher
+convertVectorExpr;
 const internal::VariadicDynCastAllOfMatcher
 coawaitExpr;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -615,6 +615,7 @@
 ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E);
 ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
 ExpectedStmt VisitChooseExpr(ChooseExpr *E);
+ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E);
 ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E);
 ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
 ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E);
@@ -7038,6 +7039,21 @@
  ToRParenLoc, CondIsTrue);
 }
 
+ExpectedStmt ASTNodeImporter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
+  Error Err = Error::success();
+  auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
+  auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
+  auto ToBuiltinLoc = importChecked(Err, 

[PATCH] D153114: [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-08-06 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

@sammccall gentle ping


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

https://reviews.llvm.org/D153114

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


[PATCH] D157248: [clang][ASTMatcher] Add Matcher 'convertVectorExpr'

2023-08-06 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 547625.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157248

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -986,6 +986,17 @@
   chooseExpr()));
 }
 
+TEST_P(ASTMatchersTest, ConvertVectorExpr) {
+  EXPECT_TRUE(matches(
+  "typedef double vector4double __attribute__((__vector_size__(32)));"
+  "typedef float  vector4float  __attribute__((__vector_size__(16)));"
+  "vector4float vf;"
+  "void f() { (void)__builtin_convertvector(vf, vector4double); }",
+  convertVectorExpr()));
+  EXPECT_TRUE(notMatches("void f() { (void)__builtin_choose_expr(1, 2, 3); }",
+ convertVectorExpr()));
+}
+
 TEST_P(ASTMatchersTest, GNUNullExpr) {
   if (!GetParam().isCXX()) {
 return;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -178,6 +178,7 @@
   REGISTER_MATCHER(constantExpr);
   REGISTER_MATCHER(containsDeclaration);
   REGISTER_MATCHER(continueStmt);
+  REGISTER_MATCHER(convertVectorExpr);
   REGISTER_MATCHER(coreturnStmt);
   REGISTER_MATCHER(coroutineBodyStmt);
   REGISTER_MATCHER(coyieldExpr);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -941,6 +941,8 @@
 const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
 const internal::VariadicDynCastAllOfMatcher chooseExpr;
+const internal::VariadicDynCastAllOfMatcher
+convertVectorExpr;
 const internal::VariadicDynCastAllOfMatcher
 coawaitExpr;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2519,6 +2519,10 @@
 extern const internal::VariadicDynCastAllOfMatcher
 chooseExpr;
 
+/// Matches builtin function __builtin_convertvector.
+extern const internal::VariadicDynCastAllOfMatcher
+convertVectorExpr;
+
 /// Matches GNU __null expression.
 extern const internal::VariadicDynCastAllOfMatcher
 gnuNullExpr;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -228,6 +228,7 @@
 
 AST Matchers
 
+- Add ``convertVectorExpr``.
 
 clang-format
 
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -1491,6 +1491,11 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtconvertVectorExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1ConvertVectorExpr.html;>ConvertVectorExpr...
+Matches builtin 
function __builtin_convertvector.
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcoreturnStmtMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CoreturnStmt.html;>CoreturnStmt...
 Matches co_return 
statements.
 


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -986,6 +986,17 @@
   chooseExpr()));
 }
 
+TEST_P(ASTMatchersTest, ConvertVectorExpr) {
+  EXPECT_TRUE(matches(
+  "typedef double vector4double __attribute__((__vector_size__(32)));"
+  "typedef float  vector4float  __attribute__((__vector_size__(16)));"
+  "vector4float vf;"
+  "void f() { (void)__builtin_convertvector(vf, vector4double); }",
+  convertVectorExpr()));
+  EXPECT_TRUE(notMatches("void f() { (void)__builtin_choose_expr(1, 2, 3); }",
+ convertVectorExpr()));
+}
+
 TEST_P(ASTMatchersTest, GNUNullExpr) {
   if (!GetParam().isCXX()) {
 return;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -178,6 +178,7 @@
   

[PATCH] D157248: [clang][ASTMatcher] Add Matcher 'convertVectorExpr'

2023-08-06 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added reviewers: PiotrZSL, aaron.ballman.
danix800 added a project: clang.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

Add Matcher `convertVectorExpr`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157248

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -986,6 +986,17 @@
   chooseExpr()));
 }
 
+TEST_P(ASTMatchersTest, ConvertVectorExpr) {
+  EXPECT_TRUE(matches(
+  "typedef double vector4double __attribute__((__vector_size__(32)));"
+  "typedef float  vector4float  __attribute__((__vector_size__(16)));"
+  "vector4float vf;"
+  "void f() { (void)__builtin_convertvector(vf, vector4double); }",
+  convertVectorExpr()));
+  EXPECT_TRUE(notMatches("void f() { (void)__builtin_choose_expr(1, 2, 3); }",
+ convertVectorExpr()));
+}
+
 TEST_P(ASTMatchersTest, GNUNullExpr) {
   if (!GetParam().isCXX()) {
 return;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -165,6 +165,7 @@
   REGISTER_MATCHER(castExpr);
   REGISTER_MATCHER(characterLiteral);
   REGISTER_MATCHER(chooseExpr);
+  REGISTER_MATCHER(convertVectorExpr);
   REGISTER_MATCHER(classTemplateDecl);
   REGISTER_MATCHER(classTemplatePartialSpecializationDecl);
   REGISTER_MATCHER(classTemplateSpecializationDecl);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -941,6 +941,8 @@
 const internal::VariadicDynCastAllOfMatcher
 cxxNullPtrLiteralExpr;
 const internal::VariadicDynCastAllOfMatcher chooseExpr;
+const internal::VariadicDynCastAllOfMatcher
+convertVectorExpr;
 const internal::VariadicDynCastAllOfMatcher
 coawaitExpr;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2519,6 +2519,10 @@
 extern const internal::VariadicDynCastAllOfMatcher
 chooseExpr;
 
+/// Matches builtin function __builtin_convertvector.
+extern const internal::VariadicDynCastAllOfMatcher
+convertVectorExpr;
+
 /// Matches GNU __null expression.
 extern const internal::VariadicDynCastAllOfMatcher
 gnuNullExpr;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -228,6 +228,7 @@
 
 AST Matchers
 
+- Add ``convertVectorExpr``.
 
 clang-format
 
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -1491,6 +1491,11 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtconvertVectorExprMatcherhttps://clang.llvm.org/doxygen/classclang_1_1ConvertVectorExpr.html;>ConvertVectorExpr...
+Matches builtin 
function __builtin_convertvector.
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>StmtcoreturnStmtMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CoreturnStmt.html;>CoreturnStmt...
 Matches co_return 
statements.
 


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -986,6 +986,17 @@
   chooseExpr()));
 }
 
+TEST_P(ASTMatchersTest, ConvertVectorExpr) {
+  EXPECT_TRUE(matches(
+  "typedef double vector4double __attribute__((__vector_size__(32)));"
+  "typedef float  vector4float  __attribute__((__vector_size__(16)));"
+  "vector4float vf;"
+  "void f() { (void)__builtin_convertvector(vf, vector4double); }",
+  convertVectorExpr()));
+  EXPECT_TRUE(notMatches("void f() { (void)__builtin_choose_expr(1, 2, 3); }",
+ convertVectorExpr()));
+}
+
 TEST_P(ASTMatchersTest, GNUNullExpr) {
   if (!GetParam().isCXX()) {
 return;
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp

[clang-tools-extra] c0abd38 - [clang-tidy] Remove 'const' qualifiers on return types that do nothing

2023-08-06 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2023-08-07T02:55:03+02:00
New Revision: c0abd3814564a568dfc607c216e6407eaa314f46

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

LOG: [clang-tidy] Remove 'const' qualifiers on return types that do nothing

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index dc3b0f70fb8add..c43d46b145a178 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -78,18 +78,18 @@ 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() {
+static StatementMatcher integerComparisonMatcher() {
   return expr(ignoringParenImpCasts(
   declRefExpr(to(varDecl(equalsBoundNode(InitVarName));
 }
 
-static const DeclarationMatcher initToZeroMatcher() {
+static DeclarationMatcher initToZeroMatcher() {
   return varDecl(
  hasInitializer(ignoringParenImpCasts(integerLiteral(equals(0)
   .bind(InitVarName);
 }
 
-static const StatementMatcher incrementVarMatcher() {
+static StatementMatcher incrementVarMatcher() {
   return declRefExpr(to(varDecl(equalsBoundNode(InitVarName;
 }
 



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


[PATCH] D154093: [clang-format] Break long string literals in C#, etc.

2023-08-06 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

@MyDeveloperDay Can you take a look at the last test in 
FormatTestCSharp.Attributes?  I tried to enable breaking string literals by 
default.  The long string got broken.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

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


[PATCH] D154093: [clang-format] Break long string literals in C#, etc.

2023-08-06 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

In D154093#4544496 , @owenpan wrote:

> In D154093#4542339 , @sstwcw wrote:
>
>> @owenpan What do you think about this revision especially the replacement 
>> part?
>
> See D154093#4544495 . Then we can 
> extend it by using `,` instead of `+` for Verilog (plus inserting a pair of 
> braces).

I added support for that.  See the updated description.  It turned out
that because inserting plus signs may involve inserting parentheses, all
the replacement stuff are still needed.  So I didn't split the Verilog
stuff into a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

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


[PATCH] D154093: [clang-format] Break long strings in Verilog

2023-08-06 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 547619.
sstwcw added a comment.

Add support for breaking strings with + in C# and others


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/BreakableToken.cpp
  clang/lib/Format/BreakableToken.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTestCSharp.cpp
  clang/unittests/Format/FormatTestJS.cpp
  clang/unittests/Format/FormatTestJava.cpp
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1815,6 +1815,30 @@
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[5], tok::comma, TT_Unknown);
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
+
+  // String literals in concatenation.
+  Tokens = Annotate("x = {\"\"};");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_StringInConcatenation);
+  Tokens = Annotate("x = {\"\", \"\"};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_StringInConcatenation);
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_StringInConcatenation);
+  Tokens = Annotate("x = '{{\"\"}};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_StringInConcatenation);
+  // Cases where the string should not be annotated that type.  Fix the
+  // `TT_Unknown` if needed in the future.
+  Tokens = Annotate("x = {\"\" == \"\"};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_Unknown);
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_Unknown);
+  Tokens = Annotate("x = {(\"\")};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
+  Tokens = Annotate("x = '{\"\"};");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -1157,6 +1157,66 @@
   verifyFormat("{< Ranges(1, tooling::Range(Offset, Length));
-tooling::Replacements Replaces = reformat(Style, Code, Ranges);
-auto Result = applyAllReplacements(Code, Replaces);
-EXPECT_TRUE(static_cast(Result));
-LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
-return *Result;
-  }
-
-  static std::string
-  format(llvm::StringRef Code,
- const FormatStyle  = getGoogleStyle(FormatStyle::LK_Java)) {
-return format(Code, 0, Code.size(), Style);
+  FormatStyle getDefaultStyle() const override {
+return getGoogleStyle(FormatStyle::LK_Java);
   }
 
   static FormatStyle getStyleWithColumns(unsigned ColumnLimit) {
@@ -41,13 +26,6 @@
 Style.ColumnLimit = ColumnLimit;
 return Style;
   }
-
-  static void verifyFormat(
-  llvm::StringRef Code,
-  const FormatStyle  = getGoogleStyle(FormatStyle::LK_Java)) {
-EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
-  }
 };
 
 TEST_F(FormatTestJava, NoAlternativeOperatorNames) {
@@ -565,9 +543,9 @@
 }
 
 TEST_F(FormatTestJava, BreaksStringLiterals) {
-  // FIXME: String literal breaking is currently disabled for Java and JS, as it
-  // requires strings to be merged using "+" which we don't support.
-  verifyFormat("\"some text other\";", getStyleWithColumns(14));
+  verifyFormat("x = \"some text \"\n"
+   "+ \"other\";",
+   "x = \"some text other\";", getStyleWithColumns(18));
 }
 
 TEST_F(FormatTestJava, AlignsBlockComments) {
@@ -625,5 +603,7 @@
Style);
 }
 
+} // namespace
+} // namespace test
 } // namespace format
-} // end namespace clang
+} // namespace clang
Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -1505,6 +1505,74 @@
 TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat("var literal = 'hello ' +\n"
"'world';");
+
+  // Long strings should be broken.
+  verifyFormat("var literal =\n"
+   "' ' +\n"
+   "'';",
+   "var literal = ' 

[PATCH] D157246: [clang-tidy] Update tests to include C++23 and C++26

2023-08-06 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a project: All.
avogelsgesang requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

This commit changes the `c++xx-or-later` definitions to also include
C++23 and the upcoming C++26.
`readability/container-contains.cpp` to also test newer C++ versions.

Also, this commit adjusts a couple of test cases slightly:

- `container-contains.cpp` now also tests newer C++ versions. Restricting it to 
C++20 was an oversight of mine when originally writing this check.
- `unconventional-assign-operator.cpp`: The `return rhs` raised a "non-const 
lvalue reference to type 'BadReturnStatement' cannot bind to a temporary" error 
in C++23. The issue is circumenvented by writing `return *`.
- `const-correctness-values.cpp` was also running into the same error in C++23. 
The troublesome test cases were moved to a separate file.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157246

Files:
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py
  
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++20 %s readability-container-contains %t
+// RUN: %check_clang_tidy -std=c++20-or-later %s readability-container-contains %t
 
 // Some *very* simplified versions of `map` etc.
 namespace std {
Index: clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp
@@ -45,7 +45,7 @@
   BadArgument& operator=(BadArgument&);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should take 'BadArgument const&', 'BadArgument&&' or 'BadArgument'
   BadArgument& operator=(const BadArgument&&);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should take 'BadAr
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should take 'BadArgument const&', 'BadArgument&&' or 'BadArgument'
 };
 
 struct BadModifier {
@@ -76,7 +76,7 @@
 public:
   BadReturnStatement& operator=(BadReturnStatement&& rhs) {
 n = std::move(rhs.n);
-return rhs;
+return *
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: operator=() should always return '*this'
   }
 
Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -181,14 +181,7 @@
   return _local1;
 }
 
-double _const_ref_return() {
-  double p_local0 = 0.0;
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double' can be declared 'const'
-  // CHECK-FIXES: double const p_local0
-  double np_local0 = 42.42;
-  return np_local0;
-}
-
+// Also see const-correctness-values.cpp-before-cxx23.cpp for `non_const_ref_return` and `return_non_const_pointer_ref`
 const double _ref_return() {
   double p_local0 = 0.0;
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double' can be declared 'const'
@@ -199,11 +192,6 @@
   return p_local1;
 }
 
-double *_non_const_pointer_ref() {
-  double *np_local0 = nullptr;
-  return np_local0;
-}
-
 void overloaded_arguments(const int );
 void overloaded_arguments(int );
 void overloaded_arguments(const int *in);
Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp
@@ -0,0 +1,20 @@
+// RUN: %check_clang_tidy -std=c++11,c++14,c++17,c++20 %s misc-const-correctness %t -- \
+// RUN:   -config="{CheckOptions: [\
+// RUN:   {key: 'misc-const-correctness.TransformValues', value: true}, \
+// RUN:   {key: 'misc-const-correctness.WarnPointersAsValues', value: false}, \
+// RUN:   {key: 'misc-const-correctness.TransformPointersAsValues', value: false}, \
+// RUN:   ]}" -- -fno-delayed-template-parsing
+
+
+double _const_ref_return() {
+  double p_local0 = 0.0;

[PATCH] D157245: [clang/cxx-interop] Teach clang to ignore availability errors that come from CF_OPTIONS

2023-08-06 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: hans.
Herald added a project: All.
thakis requested review of this revision.

This cherry-picks https://github.com/apple/llvm-project/pull/6431
since without it, macOS 14 SDK headers don't compile when targeting
catalyst.

Fixes #64438.



The github issue has all the details: 
https://github.com/llvm/llvm-project/issues/64438

The patch maybe looks a bit eh, but doing something different downstream also 
seems a bit eh. The system headers are precision matched to this patch.

(I'll commit this with @zoecarver as author to not steal attribution )


https://reviews.llvm.org/D157245

Files:
  clang/lib/Sema/SemaAvailability.cpp
  clang/test/SemaCXX/suppress-availability-error-cf-options.cpp


Index: clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+#define CF_OPTIONS(_type, _name) __attribute__((availability(swift, 
unavailable))) _type _name; enum : _name
+
+__attribute__((availability(macOS, unavailable)))
+typedef CF_OPTIONS(unsigned, TestOptions) {
+  x
+};
Index: clang/lib/Sema/SemaAvailability.cpp
===
--- clang/lib/Sema/SemaAvailability.cpp
+++ clang/lib/Sema/SemaAvailability.cpp
@@ -123,6 +123,18 @@
 const NamedDecl *OffendingDecl) {
   assert(K != AR_Available && "Expected an unavailable declaration here!");
 
+  // If this was defined using CF_OPTIONS, etc. then ignore the diagnostic.
+  auto DeclLoc = Ctx->getBeginLoc();
+  // This is only a problem in Foundation's C++ implementation for CF_OPTIONS.
+  if (DeclLoc.isMacroID() && S.getLangOpts().CPlusPlus &&
+  isa(OffendingDecl)) {
+StringRef MacroName = S.getPreprocessor().getImmediateMacroName(DeclLoc);
+if (MacroName == "CF_OPTIONS" || MacroName == "OBJC_OPTIONS" ||
+MacroName == "SWIFT_OPTIONS" || MacroName == "NS_OPTIONS") {
+  return false;
+}
+  }
+
   // Checks if we should emit the availability diagnostic in the context of C.
   auto CheckContext = [&](const Decl *C) {
 if (K == AR_NotYetIntroduced) {


Index: clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/suppress-availability-error-cf-options.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+#define CF_OPTIONS(_type, _name) __attribute__((availability(swift, unavailable))) _type _name; enum : _name
+
+__attribute__((availability(macOS, unavailable)))
+typedef CF_OPTIONS(unsigned, TestOptions) {
+  x
+};
Index: clang/lib/Sema/SemaAvailability.cpp
===
--- clang/lib/Sema/SemaAvailability.cpp
+++ clang/lib/Sema/SemaAvailability.cpp
@@ -123,6 +123,18 @@
 const NamedDecl *OffendingDecl) {
   assert(K != AR_Available && "Expected an unavailable declaration here!");
 
+  // If this was defined using CF_OPTIONS, etc. then ignore the diagnostic.
+  auto DeclLoc = Ctx->getBeginLoc();
+  // This is only a problem in Foundation's C++ implementation for CF_OPTIONS.
+  if (DeclLoc.isMacroID() && S.getLangOpts().CPlusPlus &&
+  isa(OffendingDecl)) {
+StringRef MacroName = S.getPreprocessor().getImmediateMacroName(DeclLoc);
+if (MacroName == "CF_OPTIONS" || MacroName == "OBJC_OPTIONS" ||
+MacroName == "SWIFT_OPTIONS" || MacroName == "NS_OPTIONS") {
+  return false;
+}
+  }
+
   // Checks if we should emit the availability diagnostic in the context of C.
   auto CheckContext = [&](const Decl *C) {
 if (K == AR_NotYetIntroduced) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157238: [clang][ASTImporter] Add import of 'DependentSizedExtVectorType'

2023-08-06 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 547615.
danix800 added a comment.

Apply git-clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157238

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1560,6 +1560,20 @@
  dependentSizedArrayType()));
 }
 
+TEST_P(ASTMatchersTest, DependentSizedExtVectorType) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(matches("template"
+  "class vector {"
+  "  typedef T __attribute__((ext_vector_type(Size))) type;"
+  "};",
+  dependentSizedExtVectorType()));
+  EXPECT_TRUE(
+  notMatches("int a[42]; int b[] = { 2, 3 }; void f() { int c[b[0]]; }",
+ dependentSizedExtVectorType()));
+}
+
 TEST_P(ASTMatchersTest, IncompleteArrayType) {
   EXPECT_TRUE(matches("int a[] = { 2, 3 };", incompleteArrayType()));
   EXPECT_TRUE(matches("void f(int a[]) {}", incompleteArrayType()));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1044,6 +1044,17 @@
  has(fieldDecl(hasType(dependentSizedArrayType(;
 }
 
+TEST_P(ImportExpr, DependentSizedExtVectorType) {
+  MatchVerifier Verifier;
+  testImport("template"
+ "class declToImport {"
+ "  typedef T __attribute__((ext_vector_type(Size))) type;"
+ "};",
+ Lang_CXX03, "", Lang_CXX03, Verifier,
+ classTemplateDecl(has(cxxRecordDecl(
+ has(typedefDecl(hasType(dependentSizedExtVectorType(;
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportUsingPackDecl) {
   Decl *FromTU = getTuDecl(
   "struct A { int operator()() { return 1; } };"
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -260,6 +260,8 @@
  FromAST->getFileManager(), false);
 
 auto FoundNodes = match(SearchMatcher, FromCtx);
+if (FoundNodes.empty())
+  return testing::AssertionFailure() << "No node was found!";
 if (FoundNodes.size() != 1)
   return testing::AssertionFailure()
  << "Multiple potential nodes were found!";
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -227,6 +227,7 @@
   REGISTER_MATCHER(defaultStmt);
   REGISTER_MATCHER(dependentCoawaitExpr);
   REGISTER_MATCHER(dependentSizedArrayType);
+  REGISTER_MATCHER(dependentSizedExtVectorType);
   REGISTER_MATCHER(designatedInitExpr);
   REGISTER_MATCHER(designatorCountIs);
   REGISTER_MATCHER(doStmt);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1046,6 +1046,7 @@
 const AstTypeMatcher
 deducedTemplateSpecializationType;
 const AstTypeMatcher dependentSizedArrayType;
+const AstTypeMatcher dependentSizedExtVectorType;
 const AstTypeMatcher incompleteArrayType;
 const AstTypeMatcher variableArrayType;
 const AstTypeMatcher atomicType;
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -381,7 +381,8 @@
 ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T);
 ExpectedType VisitVariableArrayType(const VariableArrayType *T);
 ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T);
-// FIXME: DependentSizedExtVectorType
+ExpectedType
+VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T);
 ExpectedType VisitVectorType(const VectorType *T);
 ExpectedType VisitExtVectorType(const ExtVectorType *T);
 ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
@@ -1264,6 +1265,18 @@
   T->getIndexTypeCVRQualifiers(), ToBracketsRange);
 }
 
+ExpectedType 

[PATCH] D157237: [clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'

2023-08-06 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D157237#4564148 , @PiotrZSL wrote:

> Matcher registration is missing, verify if it's visible in clang-query.

Fixed. Thanks for reminding!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157237

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


[PATCH] D157237: [clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'

2023-08-06 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 547614.
danix800 added a comment.

Add missing Matcher registration.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157237

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1560,6 +1560,20 @@
  dependentSizedArrayType()));
 }
 
+TEST_P(ASTMatchersTest, DependentSizedExtVectorType) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(matches("template"
+  "class vector {"
+  "  typedef T __attribute__((ext_vector_type(Size))) type;"
+  "};",
+  dependentSizedExtVectorType()));
+  EXPECT_TRUE(
+  notMatches("int a[42]; int b[] = { 2, 3 }; void f() { int c[b[0]]; }",
+ dependentSizedExtVectorType()));
+}
+
 TEST_P(ASTMatchersTest, IncompleteArrayType) {
   EXPECT_TRUE(matches("int a[] = { 2, 3 };", incompleteArrayType()));
   EXPECT_TRUE(matches("void f(int a[]) {}", incompleteArrayType()));
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -227,6 +227,7 @@
   REGISTER_MATCHER(defaultStmt);
   REGISTER_MATCHER(dependentCoawaitExpr);
   REGISTER_MATCHER(dependentSizedArrayType);
+  REGISTER_MATCHER(dependentSizedExtVectorType);
   REGISTER_MATCHER(designatedInitExpr);
   REGISTER_MATCHER(designatorCountIs);
   REGISTER_MATCHER(doStmt);
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1046,6 +1046,7 @@
 const AstTypeMatcher
 deducedTemplateSpecializationType;
 const AstTypeMatcher dependentSizedArrayType;
+const AstTypeMatcher dependentSizedExtVectorType;
 const AstTypeMatcher incompleteArrayType;
 const AstTypeMatcher variableArrayType;
 const AstTypeMatcher atomicType;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6938,6 +6938,21 @@
 ///   matches "T data[Size]"
 extern const AstTypeMatcher dependentSizedArrayType;
 
+/// Matches C++ extended vector type where either the type or size is
+/// dependent.
+///
+/// Given
+/// \code
+///   template
+///   class vector {
+/// typedef T __attribute__((ext_vector_type(Size))) type;
+///   };
+/// \endcode
+/// dependentSizedExtVectorType
+///   matches "T __attribute__((ext_vector_type(Size)))"
+extern const AstTypeMatcher
+dependentSizedExtVectorType;
+
 /// Matches C arrays with unspecified size.
 ///
 /// Given
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -228,6 +228,7 @@
 
 AST Matchers
 
+- Add ``dependentSizedExtVectorType``.
 
 clang-format
 
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -2531,6 +2531,19 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Type.html;>TypedependentSizedExtVectorTypeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1DependentSizedExtVectorType.html;>DependentSizedExtVectorType...
+Matches C++ extended vector type where either the type or size is dependent.
+
+Given
+  templatetypename T, int Size
+  class vector {
+typedef T __attribute__((ext_vector_type(Size))) type;
+  };
+dependentSizedExtVectorType
+  matches "T __attribute__((ext_vector_type(Size)))"
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Type.html;>TypeelaboratedTypeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html;>ElaboratedType...
 Matches types specified with an elaborated type keyword or with a
 qualified name.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157244: [clang-format] Correctly count annoated lines in a namespace body

2023-08-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.h:95
+  size_t size() const {
+int Size = 1;
+for (const auto *Child : Children)

Will fix it before landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157244

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


[PATCH] D157244: [clang-format] Correctly count annoated lines in a namespace body

2023-08-06 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/63882.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157244

Files:
  clang/lib/Format/NamespaceEndCommentsFixer.cpp
  clang/lib/Format/TokenAnnotator.h
  clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp


Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -1376,6 +1376,22 @@
 "int k;\n"
 "}\n",
 Style));
+
+  // The namespace body has 5 unwrapped/annotated lines.
+  const std::string NestedLambdas{"namespace foo {\n"
+  "auto bar = [] {\n" // line 1
+  "  int i;\n"// line 2
+  "  return [] {\n"   // line 3
+  "  int j;"  // line 4
+  "  return 0;\n" // line 5
+  "  };\n"// part of line 3
+  "};\n"  // part of line 1
+  "}"};
+  Style.ShortNamespaceLines = 4;
+  EXPECT_EQ(NestedLambdas + " // namespace foo",
+fixNamespaceEndComments(NestedLambdas, Style));
+  ++Style.ShortNamespaceLines;
+  EXPECT_EQ(NestedLambdas, fixNamespaceEndComments(NestedLambdas, Style));
 }
 
 TEST_F(ShortNamespaceLinesTest, NamespaceAlias) {
Index: clang/lib/Format/TokenAnnotator.h
===
--- clang/lib/Format/TokenAnnotator.h
+++ clang/lib/Format/TokenAnnotator.h
@@ -91,6 +91,13 @@
 }
   }
 
+  size_t size() const {
+int Size = 1;
+for (const auto *Child : Children)
+  Size += Child->size();
+return Size;
+  }
+
   ~AnnotatedLine() {
 for (AnnotatedLine *Child : Children)
   delete Child;
Index: clang/lib/Format/NamespaceEndCommentsFixer.cpp
===
--- clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -359,8 +359,10 @@
 computeEndCommentText(NamespaceName, AddNewline, NamespaceTok,
   Style.SpacesInLineCommentPrefix.Minimum);
 if (!hasEndComment(EndCommentPrevTok)) {
-  bool isShort = I - StartLineIndex <= Style.ShortNamespaceLines + 1;
-  if (!isShort) {
+  unsigned LineCount = 0;
+  for (auto J = StartLineIndex + 1; J < I; ++J)
+LineCount += AnnotatedLines[J]->size();
+  if (LineCount > Style.ShortNamespaceLines) {
 addEndComment(EndCommentPrevTok,
   std::string(Style.SpacesBeforeTrailingComments, ' ') +
   EndCommentText,


Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -1376,6 +1376,22 @@
 "int k;\n"
 "}\n",
 Style));
+
+  // The namespace body has 5 unwrapped/annotated lines.
+  const std::string NestedLambdas{"namespace foo {\n"
+  "auto bar = [] {\n" // line 1
+  "  int i;\n"// line 2
+  "  return [] {\n"   // line 3
+  "  int j;"  // line 4
+  "  return 0;\n" // line 5
+  "  };\n"// part of line 3
+  "};\n"  // part of line 1
+  "}"};
+  Style.ShortNamespaceLines = 4;
+  EXPECT_EQ(NestedLambdas + " // namespace foo",
+fixNamespaceEndComments(NestedLambdas, Style));
+  ++Style.ShortNamespaceLines;
+  EXPECT_EQ(NestedLambdas, fixNamespaceEndComments(NestedLambdas, Style));
 }
 
 TEST_F(ShortNamespaceLinesTest, NamespaceAlias) {
Index: clang/lib/Format/TokenAnnotator.h
===
--- clang/lib/Format/TokenAnnotator.h
+++ clang/lib/Format/TokenAnnotator.h
@@ -91,6 +91,13 @@
 }
   }
 
+  size_t size() const {
+int Size = 1;
+for (const auto *Child : Children)
+  Size += Child->size();
+return Size;
+  }
+
   ~AnnotatedLine() {
 for (AnnotatedLine *Child : Children)
   delete Child;
Index: 

[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-08-06 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added inline comments.



Comment at: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp:56
+using CF = ComplexFloat<1.0f + 3.0fi>;
+using CF = ComplexFloat<3.0fi + 1.0f>;
 

bolshakov-a wrote:
> aaron.ballman wrote:
> > bolshakov-a wrote:
> > > shafik wrote:
> > > > Can we add an enum example e.g.:
> > > > 
> > > > ```
> > > > enum E{ E1, E2};
> > > > template  struct SE {};
> > > > using IPE = SE;
> > > > using IPE = SE;
> > > > 
> > > > ```
> > > What for? Enumerators as non-type template arguments are allowed since 
> > > C++98, AFAIK. And this test is about changes in C++20.
> > Sometimes we're lacking coverage for existing features, so when updating 
> > code in the area, we'll sometimes ask for extra coverage just to be sure 
> > we're not regressing something we think might not have a lot of existing 
> > test coverage.
> `temp_arg_nontype.cpp` test already has some `enum` cases. If a case with 
> type alias should be added, it shoud be added there, not in the 
> `temp_arg_nontype_cxx20.cpp`, I think.
I've just realized that C++98 didn't had type aliases. But `typedef`s should 
probably go as well.


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

https://reviews.llvm.org/D140996

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


[PATCH] D157243: [HIP] Make test rocm-detect.hip more stable

2023-08-06 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGef888bc67c72: [HIP] Make test rocm-detect.hip more stable 
(authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157243

Files:
  
clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_400.bc
  
clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_500.bc
  clang/test/Driver/rocm-detect.hip


Index: clang/test/Driver/rocm-detect.hip
===
--- clang/test/Driver/rocm-detect.hip
+++ clang/test/Driver/rocm-detect.hip
@@ -123,12 +123,12 @@
 
 // HIP-PATH: "-mlink-builtin-bitcode" 
"[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // HIP-PATH: "-idirafter" "[[HIP_PATH:.*/myhip]]/include"
-// HIP-PATH: "-L[[HIP_PATH]]/lib" "-lamdhip64"
+// HIP-PATH: "-L[[HIP_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-PATH: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
 // ROCM-PATH: "-mlink-builtin-bitcode" 
"[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // ROCM-PATH: "-idirafter" "[[ROCM_PATH]]/include"
-// ROCM-PATH: "-L[[ROCM_PATH]]/lib" "-lamdhip64"
+// ROCM-PATH: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0


Index: clang/test/Driver/rocm-detect.hip
===
--- clang/test/Driver/rocm-detect.hip
+++ clang/test/Driver/rocm-detect.hip
@@ -123,12 +123,12 @@
 
 // HIP-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // HIP-PATH: "-idirafter" "[[HIP_PATH:.*/myhip]]/include"
-// HIP-PATH: "-L[[HIP_PATH]]/lib" "-lamdhip64"
+// HIP-PATH: "-L[[HIP_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-PATH: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
 // ROCM-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // ROCM-PATH: "-idirafter" "[[ROCM_PATH]]/include"
-// ROCM-PATH: "-L[[ROCM_PATH]]/lib" "-lamdhip64"
+// ROCM-PATH: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ef888bc - [HIP] Make test rocm-detect.hip more stable

2023-08-06 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-08-06T18:08:09-04:00
New Revision: ef888bc67c726deb8c74ea32e7c8c9ace756b667

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

LOG: [HIP] Make test rocm-detect.hip more stable

Some downstream clang is configured to add -rpath to HIP runtime for ld.
Also clang may use code object version by default.

Make this test result not affected by those.

Reviewed by: Joseph Huber

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

Added: 

clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_400.bc

clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_500.bc

Modified: 
clang/test/Driver/rocm-detect.hip

Removed: 




diff  --git 
a/clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_400.bc
 
b/clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_400.bc
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git 
a/clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_500.bc
 
b/clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_500.bc
new file mode 100644
index 00..e69de29bb2d1d6

diff  --git a/clang/test/Driver/rocm-detect.hip 
b/clang/test/Driver/rocm-detect.hip
index 68a4c201be9a8d..947c4f995be171 100644
--- a/clang/test/Driver/rocm-detect.hip
+++ b/clang/test/Driver/rocm-detect.hip
@@ -123,12 +123,12 @@
 
 // HIP-PATH: "-mlink-builtin-bitcode" 
"[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // HIP-PATH: "-idirafter" "[[HIP_PATH:.*/myhip]]/include"
-// HIP-PATH: "-L[[HIP_PATH]]/lib" "-lamdhip64"
+// HIP-PATH: "-L[[HIP_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-PATH: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
 // ROCM-PATH: "-mlink-builtin-bitcode" 
"[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // ROCM-PATH: "-idirafter" "[[ROCM_PATH]]/include"
-// ROCM-PATH: "-L[[ROCM_PATH]]/lib" "-lamdhip64"
+// ROCM-PATH: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0



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


[PATCH] D157243: [HIP] Make test rocm-detect.hip more stable

2023-08-06 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: MaskRay, jhuber6.
Herald added subscribers: kerbowa, jvesely.
Herald added a project: All.
yaxunl requested review of this revision.

some downstream clang is configured to add -rpath to HIP runtime for ld. Also 
clang may use code object version by default. Make this test result not 
affected by those.


https://reviews.llvm.org/D157243

Files:
  
clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_400.bc
  
clang/test/Driver/Inputs/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/oclc_abi_version_500.bc
  clang/test/Driver/rocm-detect.hip


Index: clang/test/Driver/rocm-detect.hip
===
--- clang/test/Driver/rocm-detect.hip
+++ clang/test/Driver/rocm-detect.hip
@@ -123,12 +123,12 @@
 
 // HIP-PATH: "-mlink-builtin-bitcode" 
"[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // HIP-PATH: "-idirafter" "[[HIP_PATH:.*/myhip]]/include"
-// HIP-PATH: "-L[[HIP_PATH]]/lib" "-lamdhip64"
+// HIP-PATH: "-L[[HIP_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-PATH: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
 // ROCM-PATH: "-mlink-builtin-bitcode" 
"[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // ROCM-PATH: "-idirafter" "[[ROCM_PATH]]/include"
-// ROCM-PATH: "-L[[ROCM_PATH]]/lib" "-lamdhip64"
+// ROCM-PATH: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0


Index: clang/test/Driver/rocm-detect.hip
===
--- clang/test/Driver/rocm-detect.hip
+++ clang/test/Driver/rocm-detect.hip
@@ -123,12 +123,12 @@
 
 // HIP-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // HIP-PATH: "-idirafter" "[[HIP_PATH:.*/myhip]]/include"
-// HIP-PATH: "-L[[HIP_PATH]]/lib" "-lamdhip64"
+// HIP-PATH: "-L[[HIP_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-PATH: ROCm installation search path: [[ROCM_PATH:.*/Inputs/rocm]]
 // ROCM-PATH: "-mlink-builtin-bitcode" "[[ROCM_PATH]]/amdgcn/bitcode/oclc_isa_version_1010.bc"
 // ROCM-PATH: "-idirafter" "[[ROCM_PATH]]/include"
-// ROCM-PATH: "-L[[ROCM_PATH]]/lib" "-lamdhip64"
+// ROCM-PATH: "-L[[ROCM_PATH]]/lib" {{.*}}"-lamdhip64"
 
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
 // ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157239: [clang-tidy] Implement bugprone-incorrect-enable-if

2023-08-06 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst:6
+
+Detects incorrect usages of std::enable_if that don't name the nested 'type'
+type.

Please synchronize with statement in Release Notes after Piotr's comment 
addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157239

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


[PATCH] D157242: [clang-tidy] Exclude delegate constructors in cppcoreguidelines-prefer-member-initializer

2023-08-06 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.

As proposed by check fix would result in compilation error,
lets exclude delegate constructors from being checked.

Fixes: #52818


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157242

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
@@ -563,3 +563,10 @@
 // CHECK-FIXES: ASSIGN_IN_MACRO(n, 0)
   }
 };
+
+struct PR52818  {
+PR52818() : bar(5) {}
+PR52818(int) : PR52818() { bar = 3; }
+
+int bar;
+};
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -172,6 +172,10 @@
   to ignore ``static`` variables declared within the scope of
   ``class``/``struct``.
 
+- Improved :doc:`cppcoreguidelines-prefer-member-initializer
+  ` check to
+  exclude delegate constructors from being checked.
+
 - 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/PreferMemberInitializerCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -141,10 +141,11 @@
 }
 
 void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  cxxConstructorDecl(hasBody(compoundStmt()), unless(isInstantiated()))
-  .bind("ctor"),
-  this);
+  Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
+unless(isInstantiated()),
+unless(isDelegatingConstructor()))
+ .bind("ctor"),
+ this);
 }
 
 void PreferMemberInitializerCheck::check(


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
@@ -563,3 +563,10 @@
 // CHECK-FIXES: ASSIGN_IN_MACRO(n, 0)
   }
 };
+
+struct PR52818  {
+PR52818() : bar(5) {}
+PR52818(int) : PR52818() { bar = 3; }
+
+int bar;
+};
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -172,6 +172,10 @@
   to ignore ``static`` variables declared within the scope of
   ``class``/``struct``.
 
+- Improved :doc:`cppcoreguidelines-prefer-member-initializer
+  ` check to
+  exclude delegate constructors from being checked.
+
 - 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/PreferMemberInitializerCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -141,10 +141,11 @@
 }
 
 void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  cxxConstructorDecl(hasBody(compoundStmt()), unless(isInstantiated()))
-  .bind("ctor"),
-  this);
+  Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
+unless(isInstantiated()),
+unless(isDelegatingConstructor()))
+ .bind("ctor"),
+ this);
 }
 
 void PreferMemberInitializerCheck::check(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157239: [clang-tidy] Implement bugprone-incorrect-enable-if

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

Do you have plans to also detect the bugprone scenario described in the `Notes` 
here?

https://en.cppreference.com/w/cpp/types/enable_if

No need to have it in this patch, but would be good to keep it in mind if we 
want to add it in the future (preferably) or create a separate check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157239

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


[PATCH] D157011: [Clang][Tooling] Accept preprocessed input files

2023-08-06 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith 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/D157011/new/

https://reviews.llvm.org/D157011

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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-08-06 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a added a comment.

Btw, formatting of unrelated lines has leaked into `TemplateBase.h`. Sorry.




Comment at: clang/lib/AST/MicrosoftMangle.cpp:1624-1626
+  return const_cast(
+  V.getLValueBase().dyn_cast());
+}

aaron.ballman wrote:
> Does this work or is the `const_cast` actually required?
No, it doesn't compile, likewise the standard C++ `dynamic_cast` cannot remove 
constness.



Comment at: clang/lib/AST/TemplateBase.cpp:408-409
   case Integral:
-getAsIntegral().Profile(ID);
 getIntegralType().Profile(ID);
+getAsIntegral().Profile(ID);
+break;

aaron.ballman wrote:
> Why did the order of these calls change?
I don't know, it is from 9e08e51a20d0d2. I've tried to invert the order along 
with the order for `StructuralValue`, and all tests have been passed.



Comment at: clang/lib/Sema/SemaOverload.cpp:5983-5985
+  Expr *E = Result.get();
+  if (!isa(E))
+E = ConstantExpr::Create(S.Context, Result.get(), Value);

aaron.ballman wrote:
> I thought we could run into situations where we had a `ConstantExpr` but it 
> did not yet have its result stored in it. Should we assert that isn't the 
> case here?
If I understand correctly, the sole place where `ConstantExpr` is constructed 
which may occur here is `BuildExpressionFromNonTypeTemplateArgumentValue` 
function, and a value is set into it there. Should I add the assertion into 
code?



Comment at: clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp:56
+using CF = ComplexFloat<1.0f + 3.0fi>;
+using CF = ComplexFloat<3.0fi + 1.0f>;
 

aaron.ballman wrote:
> bolshakov-a wrote:
> > shafik wrote:
> > > Can we add an enum example e.g.:
> > > 
> > > ```
> > > enum E{ E1, E2};
> > > template  struct SE {};
> > > using IPE = SE;
> > > using IPE = SE;
> > > 
> > > ```
> > What for? Enumerators as non-type template arguments are allowed since 
> > C++98, AFAIK. And this test is about changes in C++20.
> Sometimes we're lacking coverage for existing features, so when updating code 
> in the area, we'll sometimes ask for extra coverage just to be sure we're not 
> regressing something we think might not have a lot of existing test coverage.
`temp_arg_nontype.cpp` test already has some `enum` cases. If a case with type 
alias should be added, it shoud be added there, not in the 
`temp_arg_nontype_cxx20.cpp`, I think.


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

https://reviews.llvm.org/D140996

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


[PATCH] D157239: [clang-tidy] Implement bugprone-incorrect-enable-if

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



Comment at: clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp:67
+  diag(EnableIf->getBeginLoc(), "incorrect std::enable_if usage detected; use "
+"'typename std::enable_if<...>::type'")
+  << TypenameHint << TypeHint;

PiotrZSL wrote:
> since C++14 we should recommend using enable_if_t
I didn't add replacement logic for C++14 or C++20 since there are separate 
tools for those, and though it'd be cleaner to have independent set of tools 
(e.g., first run bugprone-incorrect-enable-if, then run modernize-type-traits).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157239

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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-08-06 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 547603.
bolshakov-a added a comment.

Fixes after review.


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

https://reviews.llvm.org/D140996

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TemplateArgumentVisitor.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CXX/drs/dr12xx.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp
  clang/test/CodeGenCXX/mangle-template.cpp
  clang/test/CodeGenCXX/template-arguments.cpp
  clang/test/Index/USR/structural-value-tpl-arg.cpp
  clang/test/Modules/odr_hash.cpp
  clang/test/SemaCXX/warn-bool-conversion.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/www/cxx_status.html
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7218,6 +7218,9 @@
 
   case clang::TemplateArgument::Pack:
 return eTemplateArgumentKindPack;
+
+  case clang::TemplateArgument::StructuralValue:
+return eTemplateArgumentKindStructuralValue;
   }
   llvm_unreachable("Unhandled clang::TemplateArgument::ArgKind");
 }
Index: lldb/include/lldb/lldb-enumerations.h
===
--- lldb/include/lldb/lldb-enumerations.h
+++ lldb/include/lldb/lldb-enumerations.h
@@ -856,6 +856,7 @@
   eTemplateArgumentKindExpression,
   eTemplateArgumentKindPack,
   eTemplateArgumentKindNullPtr,
+  eTemplateArgumentKindStructuralValue,
 };
 
 /// Type of match to be performed when looking for a formatter for a data type.
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -626,13 +626,21 @@
 
 
 
-  Class types as non-type template parameters
+  Class types as non-type template parameters
   https://wg21.link/p0732r2;>P0732R2
-  Partial
+  Clang 12
+
+ 
+  Generalized non-type template parameters of scalar type
+  https://wg21.link/p1907r1;>P1907R1
+  
+
+  Clang 18 (Partial)
+  Reference type template arguments referring to instantiation-dependent objects and subobjects
+  (i.e. declared inside a template but neither type- nor value-dependent) aren't fully supported.
+
+  
 
-   
-https://wg21.link/p1907r1;>P1907R1
-  
 
   Destroying operator delete
   https://wg21.link/p0722r3;>P0722R3
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1463,6 +1463,9 @@
 return CXTemplateArgumentKind_NullPtr;
   case TemplateArgument::Integral:
 return CXTemplateArgumentKind_Integral;
+  case TemplateArgument::StructuralValue:
+// FIXME: Expose these values.
+return CXTemplateArgumentKind_Invalid;
   case TemplateArgument::Template:
 return CXTemplateArgumentKind_Template;
   case TemplateArgument::TemplateExpansion:
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1574,6 +1574,11 @@
   return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
 return false;
 
+  case TemplateArgument::StructuralValue:
+if (Expr *E = TAL.getSourceStructuralValueExpression())
+  return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
+return false;
+

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

2023-08-06 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL 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/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] D157239: [clang-tidy] Implement bugprone-incorrect-enable-if

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



Comment at: clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp:57
+
+  const SourceManager  = Result.Context->getSourceManager();
+  SourceLocation RAngleLoc =

Result got source manager
https://clang.llvm.org/doxygen/structclang_1_1ast__matchers_1_1MatchFinder_1_1MatchResult.html



Comment at: 
clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp:61-62
+
+  FixItHint TypenameHint =
+  FixItHint::CreateInsertion(ElaboratedLoc->getBeginLoc(), "typename ");
+  FixItHint TypeHint =

do we still need typename in C++20 in this context ?
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0634r3.html



Comment at: clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp:67
+  diag(EnableIf->getBeginLoc(), "incorrect std::enable_if usage detected; use "
+"'typename std::enable_if<...>::type'")
+  << TypenameHint << TypeHint;

since C++14 we should recommend using enable_if_t



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:129
+
+  Detects incorrect usages of std::enable_if that don't name the nested 'type'
+  type.





Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst:21
+
+  template ::type>
+  void valid_usage() { ... }

shoudnlt be enable_if ?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst:34
+  template >
+  void invalid_usage() { ... }
+

this is valid usage, uses enable_if_t



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst:37
+  // The tool suggests the following replacement for 'invalid_usage':
+  template ::type>
+  void invalid_usage() { ... }

this may not compile, anyway, what if "type" got "type" ?:P



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst:44
+`modernize-type-traits <../modernize/type-traits.html>`_ for another tool
+that will replace ``typename std::enable_if<...>::type`` with
+``std::enable_if_t<...>``, and see

should be suffucient



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst:47
+`modernize-use-constraints <../modernize/use-constraints.html>`_ for another
+tool that replaces ``std::enable_if`` with C++20 constraints. Use these
+newer mechanisms where possible.

maybe "Consider" 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157239

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


[PATCH] D157239: [clang-tidy] Implement bugprone-incorrect-enable-if

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

- Edited wrong file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157239

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-if.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-if.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-if.cpp
@@ -0,0 +1,53 @@
+// RUN: %check_clang_tidy -std=c++11 %s bugprone-incorrect-enable-if %t
+
+// NOLINTBEGIN
+namespace std {
+template  struct enable_if { };
+
+template  struct enable_if { typedef T type; };
+
+template 
+using enable_if_t = typename enable_if::type;
+
+} // namespace std
+// NOLINTEND
+
+template ::type>
+void valid_function1() {}
+
+template ::type = nullptr>
+void valid_function2() {}
+
+template ::type = nullptr>
+struct ValidClass1 {};
+
+template >
+void invalid() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type>
+
+template  >
+void invalid_extra_whitespace() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type >
+
+template >
+void invalid_extra_no_whitespace() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type>
+
+template /*comment3*/>
+void invalid_extra_comment() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type/*comment3*/>
+
+template , typename = std::enable_if>
+void invalid_multiple() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-MESSAGES: [[@LINE-3]]:65: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type, typename = typename std::enable_if::type>
+
+template >
+struct InvalidClass {};
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type>
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
@@ -94,6 +94,7 @@
`bugprone-implicit-widening-of-multiplication-result `_, "Yes"
`bugprone-inaccurate-erase `_, "Yes"
`bugprone-inc-dec-in-conditions `_,
+   `bugprone-incorrect-enable-if `_, "Yes"
`bugprone-incorrect-roundings `_,
`bugprone-infinite-loop `_,
`bugprone-integer-division `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst
@@ -0,0 +1,48 @@
+.. title:: clang-tidy - bugprone-incorrect-enable-if
+
+bugprone-incorrect-enable-if
+
+
+Detects incorrect usages of std::enable_if that don't name the nested 'type'
+type.
+
+In C++11 introduced ``std::enable_if`` as a convenient way to leverage SFINAE.
+One form of using ``std::enable_if`` is to declare an unnamed template type
+parameter with a default type equal to
+``typename std::enable_if::type``. If the author forgets to name
+the nested type ``type``, then the code will always consider the candidate
+template even if the condition is not met.
+
+Below are some examples of code using ``std::enable_if`` correctly and
+incorrect examples that this check flags.
+
+.. code-block:: c++
+
+  template ::type>
+  void valid_usage() { ... }
+
+  template >
+  void valid_usage_with_trait_helpers() { ... }
+
+  // The below code is not a correct application of SFINAE. Even if
+  // T::some_trait is not true, the function will still be considered in the
+  // set of function candidates. It can either incorrectly select the function
+ 

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

2023-08-06 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa0b1c235afab: [clang-format] Currectly handle 
PCIS_CurrentLine with no column limit (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

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


[clang] a0b1c23 - [clang-format] Currectly handle PCIS_CurrentLine with no column limit

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

Author: Owen Pan
Date: 2023-08-06T12:14:23-07:00
New Revision: a0b1c235afab4743cf31e4ac4509120d3c156e60

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

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

Fixes #63519.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 0ca297a5f95768..6b9b5aca7a364a 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1437,6 +1437,7 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState ,
 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 {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 1a1109f281b442..3d20163973d749 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7758,6 +7758,13 @@ TEST_F(FormatTest, 
AllowAllConstructorInitializersOnNextLine) {
"(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) {



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


[PATCH] D157239: [clang-tidy] Implement bugprone-incorrect-enable-if

2023-08-06 Thread Chris Cotter via Phabricator via cfe-commits
ccotter created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
ccotter requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Detects incorrect usages of std::enable_if that don't name the
nested 'type' type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157239

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.h
  clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-if.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-if.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/incorrect-enable-if.cpp
@@ -0,0 +1,53 @@
+// RUN: %check_clang_tidy -std=c++11 %s bugprone-incorrect-enable-if %t
+
+// NOLINTBEGIN
+namespace std {
+template  struct enable_if { };
+
+template  struct enable_if { typedef T type; };
+
+template 
+using enable_if_t = typename enable_if::type;
+
+} // namespace std
+// NOLINTEND
+
+template ::type>
+void valid_function1() {}
+
+template ::type = nullptr>
+void valid_function2() {}
+
+template ::type = nullptr>
+struct ValidClass1 {};
+
+template >
+void invalid() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type>
+
+template  >
+void invalid_extra_whitespace() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type >
+
+template >
+void invalid_extra_no_whitespace() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type>
+
+template /*comment3*/>
+void invalid_extra_comment() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type/*comment3*/>
+
+template , typename = std::enable_if>
+void invalid_multiple() {}
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-MESSAGES: [[@LINE-3]]:65: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type, typename = typename std::enable_if::type>
+
+template >
+struct InvalidClass {};
+// CHECK-MESSAGES: [[@LINE-2]]:23: warning: incorrect std::enable_if usage detected; use 'typename std::enable_if<...>::type' [bugprone-incorrect-enable-if]
+// CHECK-FIXES: template ::type>
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
@@ -94,6 +94,7 @@
`bugprone-implicit-widening-of-multiplication-result `_, "Yes"
`bugprone-inaccurate-erase `_, "Yes"
`bugprone-inc-dec-in-conditions `_,
+   `bugprone-incorrect-enable-if `_, "Yes"
`bugprone-incorrect-roundings `_,
`bugprone-infinite-loop `_,
`bugprone-integer-division `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/incorrect-enable-if.rst
@@ -0,0 +1,48 @@
+.. title:: clang-tidy - bugprone-incorrect-enable-if
+
+bugprone-incorrect-enable-if
+
+
+Detects incorrect usages of std::enable_if that don't name the nested 'type'
+type.
+
+In C++11 introduced ``std::enable_if`` as a convenient way to leverage SFINAE.
+One form of using ``std::enable_if`` is to declare an unnamed template type
+parameter with a default type equal to
+``typename std::enable_if::type``. If the author forgets to name
+the nested type ``type``, then the code will always consider the candidate
+template even if the condition is not met.
+
+Below are some examples of code using ``std::enable_if`` correctly and
+incorrect examples that this check flags.
+
+.. code-block:: c++
+
+  template ::type>
+  void valid_usage() { ... }
+
+  template >
+  

[PATCH] D157205: [clangd] Add hexadecimal member offsets and sizes to hover popup

2023-08-06 Thread tetra via Phabricator via cfe-commits
tetraxile updated this revision to Diff 547595.
tetraxile added a comment.

Thanks for the suggestion SR_team, I've just added that.


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

https://reviews.llvm.org/D157205

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3383,7 +3383,7 @@
 Type: type (aka can_type)
 Value = value
 Offset: 12 (0xc) bytes
-Size: 4 (0x4) bytes (+4 (0x4) bytes padding)
+Size: 4 bytes (+4 bytes padding)
 
 // In test::Bar
 def)",
@@ -3404,8 +3404,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 4 (0x4) bytes and 3 (0x3) bits
-Size: 25 (0x19) bits (+4 (0x4) bits padding)
+Offset: 4 bytes and 3 bits
+Size: 25 (0x19) bits (+4 bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1404,8 +1404,8 @@
 static std::string formatSize(uint64_t SizeInBits) {
   uint64_t Value = SizeInBits % 8 == 0 ? SizeInBits / 8 : SizeInBits;
   const char *Unit = Value != 0 && Value == SizeInBits ? "bit" : "byte";
-  return llvm::formatv("{0} ({0:x}) {1}{2}", Value, Unit, Value == 1 ? "" : 
"s")
-  .str();
+  const char *Fmt = Value >= 10 ? "{0} ({0:x}) {1}{2}" : "{0} {1}{2}";
+  return llvm::formatv(Fmt, Value, Unit, Value == 1 ? "" : "s").str();
 }
 
 // Offsets are shown in bytes + bits, so offsets of different fields


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3383,7 +3383,7 @@
 Type: type (aka can_type)
 Value = value
 Offset: 12 (0xc) bytes
-Size: 4 (0x4) bytes (+4 (0x4) bytes padding)
+Size: 4 bytes (+4 bytes padding)
 
 // In test::Bar
 def)",
@@ -3404,8 +3404,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 4 (0x4) bytes and 3 (0x3) bits
-Size: 25 (0x19) bits (+4 (0x4) bits padding)
+Offset: 4 bytes and 3 bits
+Size: 25 (0x19) bits (+4 bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1404,8 +1404,8 @@
 static std::string formatSize(uint64_t SizeInBits) {
   uint64_t Value = SizeInBits % 8 == 0 ? SizeInBits / 8 : SizeInBits;
   const char *Unit = Value != 0 && Value == SizeInBits ? "bit" : "byte";
-  return llvm::formatv("{0} ({0:x}) {1}{2}", Value, Unit, Value == 1 ? "" : "s")
-  .str();
+  const char *Fmt = Value >= 10 ? "{0} ({0:x}) {1}{2}" : "{0} {1}{2}";
+  return llvm::formatv(Fmt, Value, Unit, Value == 1 ? "" : "s").str();
 }
 
 // Offsets are shown in bytes + bits, so offsets of different fields
___
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-06 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL planned changes to this revision.
PiotrZSL added a comment.

TODO: Fix CI, Add support for allocators that return 'integer', hardcode most 
of functions, change config into AdditionalAllocationFunctions


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] D157237: [clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'

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

Matcher registration is missing, verify if it's visible in clang-query.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157237

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


[PATCH] D157238: [clang][ASTImporter] Add import of 'DependentSizedExtVectorType'

2023-08-06 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added reviewers: Aar454on, balazske.
danix800 added a project: clang.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

Add import of 'DependentSizedExtVectorType'.

Depends on https://reviews.llvm.org/D157237


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157238

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1560,6 +1560,19 @@
  dependentSizedArrayType()));
 }
 
+TEST_P(ASTMatchersTest, DependentSizedExtVectorType) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(matches("template"
+  "class vector {"
+  "  typedef T __attribute__((ext_vector_type(Size))) type;"
+  "};", dependentSizedExtVectorType()));
+  EXPECT_TRUE(
+  notMatches("int a[42]; int b[] = { 2, 3 }; void f() { int c[b[0]]; }",
+ dependentSizedExtVectorType()));
+}
+
 TEST_P(ASTMatchersTest, IncompleteArrayType) {
   EXPECT_TRUE(matches("int a[] = { 2, 3 };", incompleteArrayType()));
   EXPECT_TRUE(matches("void f(int a[]) {}", incompleteArrayType()));
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1044,6 +1044,17 @@
  has(fieldDecl(hasType(dependentSizedArrayType(;
 }
 
+TEST_P(ImportExpr, DependentSizedExtVectorType) {
+  MatchVerifier Verifier;
+  testImport("template"
+ "class declToImport {"
+ "  typedef T __attribute__((ext_vector_type(Size))) type;"
+ "};",
+ Lang_CXX03, "", Lang_CXX03, Verifier,
+ classTemplateDecl(has(cxxRecordDecl(
+ has(typedefDecl(hasType(dependentSizedExtVectorType(;
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportUsingPackDecl) {
   Decl *FromTU = getTuDecl(
   "struct A { int operator()() { return 1; } };"
Index: clang/unittests/AST/ASTImporterFixtures.h
===
--- clang/unittests/AST/ASTImporterFixtures.h
+++ clang/unittests/AST/ASTImporterFixtures.h
@@ -260,6 +260,8 @@
  FromAST->getFileManager(), false);
 
 auto FoundNodes = match(SearchMatcher, FromCtx);
+if (FoundNodes.empty())
+  return testing::AssertionFailure() << "No node was found!";
 if (FoundNodes.size() != 1)
   return testing::AssertionFailure()
  << "Multiple potential nodes were found!";
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1046,6 +1046,7 @@
 const AstTypeMatcher
 deducedTemplateSpecializationType;
 const AstTypeMatcher dependentSizedArrayType;
+const AstTypeMatcher dependentSizedExtVectorType;
 const AstTypeMatcher incompleteArrayType;
 const AstTypeMatcher variableArrayType;
 const AstTypeMatcher atomicType;
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -381,7 +381,8 @@
 ExpectedType VisitIncompleteArrayType(const IncompleteArrayType *T);
 ExpectedType VisitVariableArrayType(const VariableArrayType *T);
 ExpectedType VisitDependentSizedArrayType(const DependentSizedArrayType *T);
-// FIXME: DependentSizedExtVectorType
+ExpectedType
+VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T);
 ExpectedType VisitVectorType(const VectorType *T);
 ExpectedType VisitExtVectorType(const ExtVectorType *T);
 ExpectedType VisitFunctionNoProtoType(const FunctionNoProtoType *T);
@@ -1264,6 +1265,18 @@
   T->getIndexTypeCVRQualifiers(), ToBracketsRange);
 }
 
+ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
+const DependentSizedExtVectorType *T) {
+  Error Err = Error::success();
+  QualType ToElementType = importChecked(Err, T->getElementType());
+  Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
+  SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
+  if (Err)
+return 

[PATCH] D157237: [clang][ASTMatcher] Add Matcher 'dependentSizedExtVectorType'

2023-08-06 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added a project: clang.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

Add Matcher `dependentSizedExtVectorType` for type 
`DependentSizedExtVectorType`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157237

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1560,6 +1560,19 @@
  dependentSizedArrayType()));
 }
 
+TEST_P(ASTMatchersTest, DependentSizedExtVectorType) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(matches("template"
+  "class vector {"
+  "  typedef T __attribute__((ext_vector_type(Size))) 
type;"
+  "};", dependentSizedExtVectorType()));
+  EXPECT_TRUE(
+  notMatches("int a[42]; int b[] = { 2, 3 }; void f() { int c[b[0]]; }",
+ dependentSizedExtVectorType()));
+}
+
 TEST_P(ASTMatchersTest, IncompleteArrayType) {
   EXPECT_TRUE(matches("int a[] = { 2, 3 };", incompleteArrayType()));
   EXPECT_TRUE(matches("void f(int a[]) {}", incompleteArrayType()));
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -1046,6 +1046,7 @@
 const AstTypeMatcher
 deducedTemplateSpecializationType;
 const AstTypeMatcher dependentSizedArrayType;
+const AstTypeMatcher dependentSizedExtVectorType;
 const AstTypeMatcher incompleteArrayType;
 const AstTypeMatcher variableArrayType;
 const AstTypeMatcher atomicType;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6938,6 +6938,21 @@
 ///   matches "T data[Size]"
 extern const AstTypeMatcher dependentSizedArrayType;
 
+/// Matches C++ extended vector type where either the type or size is
+/// dependent.
+///
+/// Given
+/// \code
+///   template
+///   class vector {
+/// typedef T __attribute__((ext_vector_type(Size))) type;
+///   };
+/// \endcode
+/// dependentSizedExtVectorType
+///   matches "T __attribute__((ext_vector_type(Size)))"
+extern const AstTypeMatcher
+dependentSizedExtVectorType;
+
 /// Matches C arrays with unspecified size.
 ///
 /// Given
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -228,6 +228,7 @@
 
 AST Matchers
 
+- Add ``dependentSizedExtVectorType``.
 
 clang-format
 
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -2531,6 +2531,19 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Type.html;>TypedependentSizedExtVectorTypeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1DependentSizedExtVectorType.html;>DependentSizedExtVectorType...
+Matches 
C++ extended vector type where either the type or size is dependent.
+
+Given
+  templatetypename T, int Size
+  class vector {
+typedef T __attribute__((ext_vector_type(Size))) type;
+  };
+dependentSizedExtVectorType
+  matches "T __attribute__((ext_vector_type(Size)))"
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Type.html;>TypeelaboratedTypeMatcherhttps://clang.llvm.org/doxygen/classclang_1_1ElaboratedType.html;>ElaboratedType...
 Matches types 
specified with an elaborated type keyword or with a
 qualified name.


Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1560,6 +1560,19 @@
  dependentSizedArrayType()));
 }
 
+TEST_P(ASTMatchersTest, DependentSizedExtVectorType) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+  EXPECT_TRUE(matches("template"
+  "class vector {"
+  "  typedef T __attribute__((ext_vector_type(Size))) type;"
+  "};", dependentSizedExtVectorType()));
+  EXPECT_TRUE(
+  notMatches("int a[42]; int b[] = { 2, 3 }; void f() { int c[b[0]]; }",
+ dependentSizedExtVectorType()));
+}
+
 TEST_P(ASTMatchersTest, IncompleteArrayType) {
   EXPECT_TRUE(matches("int 

[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-08-06 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 547589.
bolshakov-a added a comment.

Rebased.


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

https://reviews.llvm.org/D140996

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TemplateArgumentVisitor.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CXX/drs/dr12xx.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp
  clang/test/CodeGenCXX/mangle-template.cpp
  clang/test/CodeGenCXX/template-arguments.cpp
  clang/test/Index/USR/structural-value-tpl-arg.cpp
  clang/test/Modules/odr_hash.cpp
  clang/test/SemaCXX/warn-bool-conversion.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/www/cxx_status.html
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7218,6 +7218,9 @@
 
   case clang::TemplateArgument::Pack:
 return eTemplateArgumentKindPack;
+
+  case clang::TemplateArgument::StructuralValue:
+return eTemplateArgumentKindStructuralValue;
   }
   llvm_unreachable("Unhandled clang::TemplateArgument::ArgKind");
 }
Index: lldb/include/lldb/lldb-enumerations.h
===
--- lldb/include/lldb/lldb-enumerations.h
+++ lldb/include/lldb/lldb-enumerations.h
@@ -856,6 +856,7 @@
   eTemplateArgumentKindExpression,
   eTemplateArgumentKindPack,
   eTemplateArgumentKindNullPtr,
+  eTemplateArgumentKindStructuralValue,
 };
 
 /// Type of match to be performed when looking for a formatter for a data type.
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -626,13 +626,21 @@
 
 
 
-  Class types as non-type template parameters
+  Class types as non-type template parameters
   https://wg21.link/p0732r2;>P0732R2
-  Partial
+  Clang 12
+
+ 
+  Generalized non-type template parameters of scalar type
+  https://wg21.link/p1907r1;>P1907R1
+  
+
+  Clang 17 (Partial)
+  Reference type template arguments referring to instantiation-dependent objects and subobjects
+  (i.e. declared inside a template but neither type- nor value-dependent) aren't fully supported.
+
+  
 
-   
-https://wg21.link/p1907r1;>P1907R1
-  
 
   Destroying operator delete
   https://wg21.link/p0722r3;>P0722R3
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1463,6 +1463,9 @@
 return CXTemplateArgumentKind_NullPtr;
   case TemplateArgument::Integral:
 return CXTemplateArgumentKind_Integral;
+  case TemplateArgument::StructuralValue:
+// FIXME: Expose these values.
+return CXTemplateArgumentKind_Invalid;
   case TemplateArgument::Template:
 return CXTemplateArgumentKind_Template;
   case TemplateArgument::TemplateExpansion:
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1574,6 +1574,11 @@
   return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
 return false;
 
+  case TemplateArgument::StructuralValue:
+if (Expr *E = TAL.getSourceStructuralValueExpression())
+  return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
+return false;
+
   case 

[PATCH] D57896: Variable names rule

2023-08-06 Thread Chris Lattner via Phabricator via cfe-commits
lattner added a comment.

I would also love to see this conceptually, but think it will be pretty 
polarizing in the community.  It is worth another RFC thread before investing 
much time in it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57896

___
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-06 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 @Krishna-13-cyber for the prompt changes.

@v.g.vassilev If no further changes are required by @junaire , then this should 
be ready to merge


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-allocation-bool-conversion

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



Comment at: 
clang-tools-extra/clang-tidy/bugprone/AllocationBoolConversionCheck.cpp:25
+  "malloc;calloc;realloc;strdup;fopen;fdopen;freopen;"
+  "opendir;fdopendir;popen;mmap;allocate"))) {}
+

Eugene.Zelenko wrote:
> POSIX `open`, `openat`, `creat`, `pthread_create` should be added too.
Those return integers, not pointers. Check is for pointers only, but probably 
could be extended to integers if we go into this direction.


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-allocation-bool-conversion

2023-08-06 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 547587.
PiotrZSL marked an inline comment as done.
PiotrZSL added a comment.

Formating + fix tests


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,99 @@
+// RUN: %check_clang_tidy %s bugprone-allocation-bool-conversion %t  -- -config="{CheckOptions: { bugprone-allocation-bool-conversion.portability-restrict-system-includes.AllocationFunctions: 'malloc;allocate;custom' }}"
+
+typedef __SIZE_TYPE__ size_t;
+
+void takeBool(bool);
+void* operator new(size_t count);
+void *malloc(size_t size);
+
+template
+struct Allocator {
+  typedef T* pointer;
+  pointer allocate(size_t 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 behavior or resource leaks [bugprone-allocation-bool-conversion]
+  takeBool(static_cast(malloc(10)));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: result of the 

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

2023-08-06 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/AllocationBoolConversionCheck.cpp:25
+  "malloc;calloc;realloc;strdup;fopen;fdopen;freopen;"
+  "opendir;fdopendir;popen;mmap;allocate"))) {}
+

POSIX `open`, `openat`, `creat`, `pthread_create` should be added too.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/AllocationBoolConversionCheck.cpp:60
+ "result of the 'new' expression is being used as a boolean value, "
+ "which "
+ "may lead to unintended behavior or resource leaks");

Should be merged together.


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] D157057: [clang-tidy] Implement cppcoreguidelines CP.52

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

- Use matchesAnyListedName and fix windows build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157057

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp
@@ -0,0 +1,279 @@
+// RUN: %check_clang_tidy -std=c++20 %s cppcoreguidelines-no-suspend-with-lock %t -- -- -fno-delayed-template-parsing
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct coroutine_traits {
+  using promise_type = typename T::promise_type;
+};
+template 
+struct coroutine_handle;
+template <>
+struct coroutine_handle {
+  coroutine_handle() noexcept;
+  coroutine_handle(decltype(nullptr)) noexcept;
+  static constexpr coroutine_handle from_address(void*);
+};
+template 
+struct coroutine_handle {
+  coroutine_handle() noexcept;
+  coroutine_handle(decltype(nullptr)) noexcept;
+  static constexpr coroutine_handle from_address(void*);
+  operator coroutine_handle<>() const noexcept;
+};
+
+template 
+class unique_lock {
+public:
+  unique_lock() noexcept;
+  explicit unique_lock(Mutex );
+  unique_lock& operator=(unique_lock&&);
+  void unlock();
+  Mutex* release() noexcept;
+  Mutex* mutex() const noexcept;
+  void swap(unique_lock& other) noexcept;
+};
+
+class mutex {
+public:
+  mutex() noexcept;
+  ~mutex();
+  mutex(const mutex &) = delete;
+  mutex =(const mutex &) = delete;
+
+  void lock();
+  void unlock();
+};
+} // namespace std
+
+class my_own_mutex {
+public:
+  void lock();
+  void unlock();
+};
+
+struct Awaiter {
+  bool await_ready() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct Coro {
+  struct promise_type {
+Awaiter initial_suspend();
+Awaiter final_suspend() noexcept;
+void return_void();
+Coro get_return_object();
+void unhandled_exception();
+Awaiter yield_value(int);
+  };
+};
+// NOLINTEND
+
+std::mutex mtx;
+std::mutex mtx2;
+
+Coro awaits_with_lock() {
+  std::unique_lock lock(mtx);
+
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+
+  if (true) {
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  if (true) {
+std::unique_lock lock2;
+lock2.unlock();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock2' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+}
+
+Coro awaits_with_lock_in_try() try {
+  std::unique_lock lock(mtx);
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+} catch (...) {}
+
+Coro lock_possibly_unlocked() {
+  // CppCoreGuideline CP.52's enforcement strictly requires flagging
+  // code that suspends while any lock guard is not destructed.
+
+  {
+std::unique_lock lock(mtx);
+lock.unlock();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+lock.release();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+std::unique_lock lock2;
+lock.swap(lock2);
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+std::unique_lock lock2{mtx2};
+lock.swap(lock2);
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+lock = 

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

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



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp:27
+  namesType(templateSpecializationType(hasDeclaration(namedDecl(
+  hasAnyName(utils::options::parseStringList(LockGuards)));
+

consider using matchers::matchesAnyListedName


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] D153701: [WIP][Clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-08-06 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

Sorry for the late reply.  I tried to investigate the memory impact of creating 
these additional materializations by build the whole llvm-project and compare 
the number of `MaterializedTemporaryExpr` created during parsing.

Steps:

1. Add a public member `uint64_t NumMetarilizedTemporaryExpr = 0;` in 
`ASTContext` .
2. Increment the value of `NumMetarilizedTemporaryExpr ` in 
`Sema::CreateMaterializeTemporaryExpr`.
3. Write the `NumMetarilizedTemporaryExpr ` into a text file when `ASTContext` 
destruction, each translation unit will append a line to the file to record the 
value of `NumMetarilizedTemporaryExpr `.
4. Build the entire llvm-project separately using the compiler that creates 
addational materializations and the compiler that doesn't.
5. Sum the numbers produced by each translation unit.

The result is:

The version that create addational materializations: 50740658
The version that does not create addational materializations:  18360888

The gap between these two numbers is very large. So I'think we can create 
additional materializations only within for-range initializers. I'm not sure if 
I can find a way to only create materializes for temporaries that need to have 
an extended lifetime, WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153701

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


[PATCH] D157229: Fix edge case in declare target initializer expression

2023-08-06 Thread Ritanya via Phabricator via cfe-commits
RitanyaB created this revision.
RitanyaB added reviewers: soumitra, sandeepkosuri, koops, ABataev.
Herald added a project: All.
RitanyaB requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This patch adds support for the following edge cases in declare target - 
#pragma omp declare target(variable)
#pragma omp declare target to(variable)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157229

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/declare_target_variables_ast_print.cpp


Index: clang/test/OpenMP/declare_target_variables_ast_print.cpp
===
--- clang/test/OpenMP/declare_target_variables_ast_print.cpp
+++ clang/test/OpenMP/declare_target_variables_ast_print.cpp
@@ -27,6 +27,10 @@
 };
 static target S;
 
+static int var3 = 100;
+static int *ptr_3 = 
+static char c = 'a';
+
 #pragma omp declare target
 int target_var = variable;
 float target_var1 = variable2;
@@ -36,6 +40,9 @@
 declare **obj3 = 
 target *S1 = 
 #pragma omp end declare target
+#pragma omp declare target(ptr_3)
+#pragma omp declare target to(c)
+
 // CHECK: #pragma omp declare target
 // CHECK-NEXT: static int variable = 100;
 // CHECK-NEXT: #pragma omp end declare target
@@ -87,7 +94,15 @@
 // CHECK-NEXT: #pragma omp declare target
 // CHECK-NEXT: static target S;
 // CHECK-NEXT: #pragma omp end declare target
-
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int var3 = 100;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int *ptr_3 = 
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static char c = 'a';
+// CHECK-NEXT: #pragma omp end declare target
 // CHECK-NEXT: #pragma omp declare target
 // CHECK-NEXT: int target_var = variable;
 // CHECK-NEXT: #pragma omp end declare target
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -23102,6 +23102,10 @@
   if (ASTMutationListener *ML = Context.getASTMutationListener())
 ML->DeclarationMarkedOpenMPDeclareTarget(ND, A);
   checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Loc);
+  if (auto *VD = dyn_cast(ND);
+  LangOpts.OpenMP && VD && VD->hasAttr() &&
+  VD->hasGlobalStorage())
+ActOnOpenMPDeclareTargetInitializer(ND);
 }
 
 static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR,


Index: clang/test/OpenMP/declare_target_variables_ast_print.cpp
===
--- clang/test/OpenMP/declare_target_variables_ast_print.cpp
+++ clang/test/OpenMP/declare_target_variables_ast_print.cpp
@@ -27,6 +27,10 @@
 };
 static target S;
 
+static int var3 = 100;
+static int *ptr_3 = 
+static char c = 'a';
+
 #pragma omp declare target
 int target_var = variable;
 float target_var1 = variable2;
@@ -36,6 +40,9 @@
 declare **obj3 = 
 target *S1 = 
 #pragma omp end declare target
+#pragma omp declare target(ptr_3)
+#pragma omp declare target to(c)
+
 // CHECK: #pragma omp declare target
 // CHECK-NEXT: static int variable = 100;
 // CHECK-NEXT: #pragma omp end declare target
@@ -87,7 +94,15 @@
 // CHECK-NEXT: #pragma omp declare target
 // CHECK-NEXT: static target S;
 // CHECK-NEXT: #pragma omp end declare target
-
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int var3 = 100;
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static int *ptr_3 = 
+// CHECK-NEXT: #pragma omp end declare target
+// CHECK-NEXT: #pragma omp declare target
+// CHECK-NEXT: static char c = 'a';
+// CHECK-NEXT: #pragma omp end declare target
 // CHECK-NEXT: #pragma omp declare target
 // CHECK-NEXT: int target_var = variable;
 // CHECK-NEXT: #pragma omp end declare target
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -23102,6 +23102,10 @@
   if (ASTMutationListener *ML = Context.getASTMutationListener())
 ML->DeclarationMarkedOpenMPDeclareTarget(ND, A);
   checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Loc);
+  if (auto *VD = dyn_cast(ND);
+  LangOpts.OpenMP && VD && VD->hasAttr() &&
+  VD->hasGlobalStorage())
+ActOnOpenMPDeclareTargetInitializer(ND);
 }
 
 static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR,
___
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-06 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 547574.
Krishna-13-cyber added a comment.

- Update section of Execution Results Handling in Clang-REPL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156858

Files:
  clang/docs/ClangRepl.rst
  clang/docs/ExecutionResultsHandling.rst
  clang/docs/autoprint.png
  clang/docs/index.rst
  clang/docs/prettyprint.png
  clang/docs/valuesynth.png

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -93,6 +93,7 @@
ClangOffloadBundler
ClangOffloadPackager
ClangRepl
+   ExecutionResultsHandling
 
 Design Documents
 
Index: clang/docs/ExecutionResultsHandling.rst
===
--- /dev/null
+++ clang/docs/ExecutionResultsHandling.rst
@@ -0,0 +1,333 @@
+=
+Execution Results Handling in Clang-REPL
+=
+
+Execution Results Handling features discussed below help extend the Clang-REPL 
+functionality by creating an interface between the execution results of a 
+program and the compiled program.
+
+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. 
+
+
+1. Capture Execution Results
+
+
+In many cases, it is useful to bring back the program execution result to the 
+compiled program. This result can be stored in an object of type **Value**.
+
+How Execution Results are captured (Value Synthesis):
+-
+
+The synthesizer chooses which expression to synthesize, and then it replaces 
+the original expression with the synthesized expression. Depending on the 
+expression type, it may choose to save an object (``LastValue``) of type 'value'
+while allocating memory to it (``SetValueWithAlloc()``), or not (
+``SetValueNoAlloc()``).
+
+.. image:: valuesynth.png
+   :align: center
+   :alt: valuesynth design
+
+Where is the captured result stored?
+
+
+``LastValue`` holds the last result of the value printing. It is a class member 
+because it can be accessed even after subsequent inputs. 
+
+**Note:** If no value printing happens, then it is in an invalid state. 
+
+Improving Efficiency and User Experience
+
+
+The Value object is essentially used to create a mapping between an expression 
+'type' and the 'memory' to be allocated. Built-in types (bool, char, int, 
+float, double, etc.) are simpler, since their memory allocation size is known. 
+In case of objects, a pointer can be saved, since the size of the object is 
+not known.
+
+For further improvement, the underlying Clang Type is also identified. For 
+example, ``X(char, Char_S)``, where ``Char_S`` is the Clang type. Clang types are 
+very efficient, which is important since these will be used in hotspots (high 
+utilization areas of the program). The ``Value.h`` header file has a very low 
+token count and was developed with strict constraints in mind, since it can 
+affect the performance of the interpreter.
+
+This also enables the user to receive the computed 'type' back in their code 
+and then transform the type into something else (e.g., transform a double into 
+a float). Normally, the compiler can handle these conversions transparently, 
+but in interpreter mode, the compiler cannot see all the 'from' and 'to' types,
+so it cannot implicitly do the conversions. So this logic enables providing 
+these conversions on request. 
+
+On-request conversions can help improve the user experience, by allowing 
+conversion to a desired 'to' type, when the 'from' type is unknown or unclear
+
+Significance of this Feature
+
+
+The 'Value' object enables wrapping a memory region that comes from the 
+JIT, and bringing it back to the compiled code (and vice versa). 
+This is a very useful functionality when:
+
+- connecting an interpreter to the compiled code, or
+- connecting an interpreter in another language.
+
+For example, the CPPYY code makes use of this feature to enable running 
+C++ within Python. It enables transporting values/information between C++ 
+and Python.
+
+In a nutshell, this feature enables a new way of developing code, paving the 
+way for language interoperability and easier interactive programming.
+
+Implementation Details
+==
+
+Interpreter as a REPL vs. as a Library
+--
+
+1 - If we're using the interpreter in interactive (REPL) mode, it will dump 
+the 

[PATCH] D155769: [Clang][docs][RFC] Add documentation for C++ Parallel Algorithm Offload

2023-08-06 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx marked an inline comment as done.
AlexVlx added inline comments.



Comment at: clang/docs/StdParSupport.rst:366-367
+
+   Note that this is a temporary, unsafe workaround for a deficiency in the C++
+   Standard.
+

keryell wrote:
> Another way could be to hide somehow a way to select the device in the policy 
> like in https://github.com/KhronosGroup/SyclParallelSTL, which might be 
> something included in your point "4." of "Open Questions / Future 
> Developments".
> Perhaps better than opening the TLS Pandora box?
In hindsight, this was needlessly confusing and relied on an implementation 
detail, therefore the reference was removed. Thank you for pointing that out.


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

https://reviews.llvm.org/D155769

___
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-06 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 547573.
ccotter marked 5 inline comments as done.
ccotter added a comment.

- Add tests, do not inspect instantiations, add option


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157057

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/no-suspend-with-lock.cpp
@@ -0,0 +1,279 @@
+// RUN: %check_clang_tidy -std=c++20 %s cppcoreguidelines-no-suspend-with-lock %t
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct coroutine_traits {
+  using promise_type = typename T::promise_type;
+};
+template 
+struct coroutine_handle;
+template <>
+struct coroutine_handle {
+  coroutine_handle() noexcept;
+  coroutine_handle(decltype(nullptr)) noexcept;
+  static constexpr coroutine_handle from_address(void*);
+};
+template 
+struct coroutine_handle {
+  coroutine_handle() noexcept;
+  coroutine_handle(decltype(nullptr)) noexcept;
+  static constexpr coroutine_handle from_address(void*);
+  operator coroutine_handle<>() const noexcept;
+};
+
+template 
+class unique_lock {
+public:
+  unique_lock() noexcept;
+  explicit unique_lock(Mutex );
+  unique_lock& operator=(unique_lock&&);
+  void unlock();
+  Mutex* release() noexcept;
+  Mutex* mutex() const noexcept;
+  void swap(unique_lock& other) noexcept;
+};
+
+class mutex {
+public:
+  mutex() noexcept;
+  ~mutex();
+  mutex(const mutex &) = delete;
+  mutex =(const mutex &) = delete;
+
+  void lock();
+  void unlock();
+};
+} // namespace std
+
+class my_own_mutex {
+public:
+  void lock();
+  void unlock();
+};
+
+struct Awaiter {
+  bool await_ready() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct Coro {
+  struct promise_type {
+Awaiter initial_suspend();
+Awaiter final_suspend() noexcept;
+void return_void();
+Coro get_return_object();
+void unhandled_exception();
+Awaiter yield_value(int);
+  };
+};
+// NOLINTEND
+
+std::mutex mtx;
+std::mutex mtx2;
+
+Coro awaits_with_lock() {
+  std::unique_lock lock(mtx);
+
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+
+  if (true) {
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  if (true) {
+std::unique_lock lock2;
+lock2.unlock();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock2' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+}
+
+Coro awaits_with_lock_in_try() try {
+  std::unique_lock lock(mtx);
+  co_await Awaiter{};
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+} catch (...) {}
+
+Coro lock_possibly_unlocked() {
+  // CppCoreGuideline CP.52's enforcement strictly requires flagging
+  // code that suspends while any lock guard is not destructed.
+
+  {
+std::unique_lock lock(mtx);
+lock.unlock();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+lock.release();
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+std::unique_lock lock2;
+lock.swap(lock2);
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+std::unique_lock lock2{mtx2};
+lock.swap(lock2);
+co_await Awaiter{};
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: coroutine suspended with lock 'lock' held [cppcoreguidelines-no-suspend-with-lock]
+  }
+
+  {
+std::unique_lock lock(mtx);
+lock = 

[PATCH] D155769: [Clang][docs][RFC] Add documentation for C++ Parallel Algorithm Offload

2023-08-06 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 547572.
AlexVlx added a comment.

Remove confusing guidance around mGPU.


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

https://reviews.llvm.org/D155769

Files:
  clang/docs/StdParSupport.rst
  clang/docs/index.rst

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -47,6 +47,7 @@
OpenCLSupport
OpenMPSupport
SYCLSupport
+   StdParSupport
HIPSupport
HLSL/HLSLDocs
ThinLTO
Index: clang/docs/StdParSupport.rst
===
--- /dev/null
+++ clang/docs/StdParSupport.rst
@@ -0,0 +1,350 @@
+==
+C++ Standard Parallelism Offload Support: Compiler And Runtime
+==
+
+.. contents::
+   :local:
+
+Introduction
+
+
+This document describes the implementation of support for offloading the
+execution of standard C++ algorithms to accelerators that can be targeted via
+HIP. Furthermore, it enumerates restrictions on user defined code, as well as
+the interactions with runtimes.
+
+Algorithm Offload: What, Why, Where
+===
+
+C++17 introduced overloads
+`for most algorithms in the standard library `_
+which allow the user to specify a desired
+`execution policy `_.
+The `parallel_unsequenced_policy `_
+maps relatively well to the execution model of many accelerators, such as GPUs.
+This, coupled with the ubiquity of GPU accelerated algorithm libraries that
+implement most / all corresponding libraries in the standard library
+(e.g. `rocThrust `_), makes
+it feasible to provide seamless accelerator offload for supported algorithms,
+when an accelerated version exists. Thus, it becomes possible to easily access
+the computational resources of an accelerator, via a well specified, familiar,
+algorithmic interface, without having to delve into low-level hardware specific
+details. Putting it all together:
+
+- **What**: standard library algorithms, when invoked with the
+  ``parallel_unsequenced_policy``
+- **Why**: democratise accelerator programming, without loss of user familiarity
+- **Where**: any and all accelerators that can be targeted by Clang/LLVM via HIP
+
+Small Example
+=
+
+Given the following C++ code, which assumes the ``std`` namespace is included:
+
+.. code-block:: C++
+
+   bool has_the_answer(const vector& v) {
+ return find(execution::par_unseq, cbegin(v), cend(v), 42) != cend(v);
+   }
+
+if Clang is invoked with the ``-stdpar --offload-target=foo`` flags, the call to
+``find`` will be offloaded to an accelerator that is part of the ``foo`` target
+family. If either ``foo`` or its runtime environment do not support transparent
+on-demand paging (such as e.g. that provided in Linux via
+`HMM `_), it is necessary to also include
+the ``--stdpar-interpose-alloc`` flag. If the accelerator specific algorithm
+library ``foo`` uses doesn't have an implementation of a particular algorithm,
+execution seamlessly falls back to the host CPU. It is legal to specify multiple
+``--offload-target``s. All the flags we introduce, as well as a thorough view of
+various restrictions and their implications will be provided below.
+
+Implementation - General View
+=
+
+We built support for Algorithm Offload support atop the pre-existing HIP
+infrastructure. More specifically, when one requests offload via ``-stdpar``,
+compilation is switched to HIP compilation, as if ``-x hip`` was specified.
+Similarly, linking is also switched to HIP linking, as if ``--hip-link`` was
+specified. Note that these are implicit, and one should not assume that any
+interop with HIP specific language constructs is available e.g. ``__device__``
+annotations are neither necessary nor guaranteed to work.
+
+Since there are no language restriction mechanisms in place, it is necessary to
+relax HIP language specific semantic checks performed by the FE; they would
+identify otherwise valid, offloadable code, as invalid HIP code. Given that we
+know that the user intended only for certain algorithms to be offloaded, and
+encoded this by specifying the ``parallel_unsequenced_policy``, we rely on a
+pass over IR to clean up any and all code that was not "meant" for offload. If
+requested, allocation interposition is also handled via a separate pass over IR.
+
+To interface with the client HIP runtime, and to forward offloaded algorithm
+invocations to the corresponding accelerator specific library implementation, an
+implementation 

[PATCH] D155775: [Clang][Driver][RFC] Add driver support for C++ Parallel Algorithm Offload

2023-08-06 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 547570.

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

https://reviews.llvm.org/D155775

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/lib/Driver/ToolChains/ROCm.h
  clang/test/Driver/Inputs/stdpar/stdpar_lib.hpp
  clang/test/Driver/stdpar.c

Index: clang/test/Driver/stdpar.c
===
--- /dev/null
+++ clang/test/Driver/stdpar.c
@@ -0,0 +1,18 @@
+// RUN: %clang -### -stdpar --compile %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=STDPAR-MISSING-LIB %s
+// STDPAR-MISSING-LIB: error: cannot find HIP Standard Parallelism Acceleration library; provide it via '--stdpar-path'
+
+// RUN: %clang -### --stdpar --stdpar-path=%S/Inputs/stdpar \
+// RUN:   --stdpar-thrust-path=%S/Inputs/stdpar/thrust \
+// RUN:   --stdpar-prim-path=%S/Inputs/stdpar/prim --compile %s 2>&1 | \
+// RUN:   FileCheck --check-prefix=STDPAR-COMPILE %s
+// STDPAR-COMPILE: "-x" "hip"
+// STDPAR-COMPILE: "-idirafter" "{{.*/thrust}}"
+// STDPAR-COMPILE: "-idirafter" "{{.*/prim}}"
+// STDPAR-COMPILE: "-idirafter" "{{.*/Inputs/stdpar}}"
+// STDPAR-COMPILE: "-include" "stdpar_lib.hpp"
+
+// RUN: touch %t.o
+// RUN: %clang -### -stdpar %t.o 2>&1 | FileCheck --check-prefix=STDPAR-LINK %s
+// STDPAR-LINK: "-rpath"
+// STDPAR-LINK: "-l{{.*hip.*}}"
Index: clang/lib/Driver/ToolChains/ROCm.h
===
--- clang/lib/Driver/ToolChains/ROCm.h
+++ clang/lib/Driver/ToolChains/ROCm.h
@@ -77,6 +77,9 @@
   const Driver 
   bool HasHIPRuntime = false;
   bool HasDeviceLibrary = false;
+  bool HasHIPStdParLibrary = false;
+  bool HasRocThrustLibrary = false;
+  bool HasRocPrimLibrary = false;
 
   // Default version if not detected or specified.
   const unsigned DefaultVersionMajor = 3;
@@ -96,6 +99,13 @@
   std::vector RocmDeviceLibPathArg;
   // HIP runtime path specified by --hip-path.
   StringRef HIPPathArg;
+  // HIP Standard Parallel Algorithm acceleration library specified by
+  // --stdpar-path
+  StringRef HIPStdParPathArg;
+  // rocThrust algorithm library specified by --stdpar-thrust-path
+  StringRef HIPRocThrustPathArg;
+  // rocPrim algorithm library specified by --stdpar-prim-path
+  StringRef HIPRocPrimPathArg;
   // HIP version specified by --hip-version.
   StringRef HIPVersionArg;
   // Wheter -nogpulib is specified.
@@ -180,6 +190,9 @@
   /// Check whether we detected a valid ROCm device library.
   bool hasDeviceLibrary() const { return HasDeviceLibrary; }
 
+  /// Check whether we detected a valid HIP STDPAR Acceleration library.
+  bool hasHIPStdParLibrary() const { return HasHIPStdParLibrary; }
+
   /// Print information about the detected ROCm installation.
   void print(raw_ostream ) const;
 
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -115,6 +115,8 @@
 "--no-undefined",
 "-shared",
 "-plugin-opt=-amdgpu-internalize-symbols"};
+  if (Args.hasArg(options::OPT_stdpar))
+LldArgs.push_back("-plugin-opt=-amdgpu-enable-stdpar");
 
   auto  = getToolChain();
   auto  = TC.getDriver();
@@ -246,6 +248,8 @@
   if (!DriverArgs.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
   false))
 CC1Args.append({"-mllvm", "-amdgpu-internalize-symbols"});
+  if (DriverArgs.hasArgNoClaim(options::OPT_stdpar))
+CC1Args.append({"-mllvm", "-amdgpu-enable-stdpar"});
 
   StringRef MaxThreadsPerBlock =
   DriverArgs.getLastArgValue(options::OPT_gpu_max_threads_per_block_EQ);
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6533,6 +6533,12 @@
 if (Args.hasFlag(options::OPT_fgpu_allow_device_init,
  options::OPT_fno_gpu_allow_device_init, false))
   CmdArgs.push_back("-fgpu-allow-device-init");
+if (Args.hasArg(options::OPT_stdpar)) {
+  CmdArgs.push_back("-stdpar");
+
+  if (Args.hasArg(options::OPT_stdpar_interpose_alloc))
+CmdArgs.push_back("-stdpar-interpose-alloc");
+}
 Args.addOptInFlag(CmdArgs, options::OPT_fhip_kernel_arg_name,
   options::OPT_fno_hip_kernel_arg_name);
   }
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -329,6 +329,19 @@
   RocmDeviceLibPathArg =
   

[PATCH] D156605: [clangd][CodeComplete] Improve FunctionCanBeCall

2023-08-06 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 547569.
zyounan added a comment.

Trigger the build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156605

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp
  clang/unittests/Sema/CodeCompleteTest.cpp

Index: clang/unittests/Sema/CodeCompleteTest.cpp
===
--- clang/unittests/Sema/CodeCompleteTest.cpp
+++ clang/unittests/Sema/CodeCompleteTest.cpp
@@ -60,7 +60,10 @@
 for (unsigned I = 0; I < NumResults; ++I) {
   auto R = Results[I];
   if (R.Kind == CodeCompletionResult::RK_Declaration) {
-if (const auto *FD = llvm::dyn_cast(R.getDeclaration())) {
+auto *ND = R.getDeclaration();
+if (auto *Template = llvm::dyn_cast(ND))
+  ND = Template->getTemplatedDecl();
+if (const auto *FD = llvm::dyn_cast(ND)) {
   CompletedFunctionDecl D;
   D.Name = FD->getNameAsString();
   D.CanBeCall = R.FunctionCanBeCall;
@@ -191,6 +194,10 @@
 struct Foo {
   static int staticMethod();
   int method() const;
+  template 
+  void generic(T);
+  template 
+  static T staticGeneric();
   Foo() {
 this->$canBeCall^
 $canBeCall^
@@ -207,15 +214,25 @@
 struct OtherClass {
   OtherClass() {
 Foo f;
+Derived d;
 f.$canBeCall^
+; // Prevent parsing as 'f.f'
+f.Foo::$canBeCall^
 ::$cannotBeCall^
+;
+d.Foo::$canBeCall^
   }
 };
 
 int main() {
   Foo f;
+  Derived d;
   f.$canBeCall^
+  ; // Prevent parsing as 'f.f'
+  f.Foo::$canBeCall^
   ::$cannotBeCall^
+  ;
+  d.Foo::$canBeCall^
 }
 )cpp");
 
@@ -223,12 +240,16 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(true;
   }
 
   for (const auto  : Code.points("cannotBeCall")) {
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(false;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(false;
   }
 
   // static method can always be a call
@@ -236,6 +257,8 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("staticMethod"), isStatic(true),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("staticGeneric"), isStatic(true),
+canBeCall(true;
   }
 }
 
Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -341,3 +341,14 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:339:10 %s -o - | FileCheck -check-prefix=CHECK-FIELD-DECLARED-VIA-USING %s
   // CHECK-FIELD-DECLARED-VIA-USING: [#int#]field (requires fix-it: {339:8-339:9} to "->")
 }
+
+namespace function_can_be_call {
+  struct S {
+template 
+V foo(T, U);
+  };
+
+  ::f
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:351:7 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s
+  // CHECK_FUNCTION_CAN_BE_CALL: COMPLETION: foo : [#V#]foo<<#typename T#>, <#typename U#>{#, <#typename V#>#}>(<#T#>, <#U#>)
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -338,8 +338,11 @@
   ///
   /// \param InBaseClass whether the result was found in a base
   /// class of the searched context.
+  ///
+  /// \param BaseType the type of expression that precedes the "." or "->"
+  /// in a member access expression.
   void AddResult(Result R, DeclContext *CurContext, NamedDecl *Hiding,
- bool InBaseClass);
+ bool InBaseClass, QualType BaseType);
 
   /// Add a new non-declaration result to this result set.
   void AddResult(Result R);
@@ -1262,7 +1265,8 @@
 }
 
 void ResultBuilder::AddResult(Result R, DeclContext *CurContext,
-  

[PATCH] D155370: [CodeComplete] Improve FunctionCanBeCall

2023-08-06 Thread Younan Zhang via Phabricator via cfe-commits
zyounan abandoned this revision.
zyounan added a comment.

Closing this in favor of D156605 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155370

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


[PATCH] D156605: [CodeComplete] Mark 'Derived().Base::foo()' CanBeCall

2023-08-06 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 547566.
zyounan added a comment.

Merge changes with function templates from D155370 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156605

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/CodeCompletionStrings.h
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/member-access.cpp
  clang/unittests/Sema/CodeCompleteTest.cpp

Index: clang/unittests/Sema/CodeCompleteTest.cpp
===
--- clang/unittests/Sema/CodeCompleteTest.cpp
+++ clang/unittests/Sema/CodeCompleteTest.cpp
@@ -60,7 +60,10 @@
 for (unsigned I = 0; I < NumResults; ++I) {
   auto R = Results[I];
   if (R.Kind == CodeCompletionResult::RK_Declaration) {
-if (const auto *FD = llvm::dyn_cast(R.getDeclaration())) {
+auto *ND = R.getDeclaration();
+if (auto *Template = llvm::dyn_cast(ND))
+  ND = Template->getTemplatedDecl();
+if (const auto *FD = llvm::dyn_cast(ND)) {
   CompletedFunctionDecl D;
   D.Name = FD->getNameAsString();
   D.CanBeCall = R.FunctionCanBeCall;
@@ -191,6 +194,10 @@
 struct Foo {
   static int staticMethod();
   int method() const;
+  template 
+  void generic(T);
+  template 
+  static T staticGeneric();
   Foo() {
 this->$canBeCall^
 $canBeCall^
@@ -207,15 +214,25 @@
 struct OtherClass {
   OtherClass() {
 Foo f;
+Derived d;
 f.$canBeCall^
+; // Prevent parsing as 'f.f'
+f.Foo::$canBeCall^
 ::$cannotBeCall^
+;
+d.Foo::$canBeCall^
   }
 };
 
 int main() {
   Foo f;
+  Derived d;
   f.$canBeCall^
+  ; // Prevent parsing as 'f.f'
+  f.Foo::$canBeCall^
   ::$cannotBeCall^
+  ;
+  d.Foo::$canBeCall^
 }
 )cpp");
 
@@ -223,12 +240,16 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(true;
   }
 
   for (const auto  : Code.points("cannotBeCall")) {
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("method"), isStatic(false),
 canBeCall(false;
+EXPECT_THAT(Results, Contains(AllOf(named("generic"), isStatic(false),
+canBeCall(false;
   }
 
   // static method can always be a call
@@ -236,6 +257,8 @@
 auto Results = CollectCompletedFunctions(Code.code(), P);
 EXPECT_THAT(Results, Contains(AllOf(named("staticMethod"), isStatic(true),
 canBeCall(true;
+EXPECT_THAT(Results, Contains(AllOf(named("staticGeneric"), isStatic(true),
+canBeCall(true;
   }
 }
 
Index: clang/test/CodeCompletion/member-access.cpp
===
--- clang/test/CodeCompletion/member-access.cpp
+++ clang/test/CodeCompletion/member-access.cpp
@@ -341,3 +341,14 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:339:10 %s -o - | FileCheck -check-prefix=CHECK-FIELD-DECLARED-VIA-USING %s
   // CHECK-FIELD-DECLARED-VIA-USING: [#int#]field (requires fix-it: {339:8-339:9} to "->")
 }
+
+namespace function_can_be_call {
+  struct S {
+template 
+V foo(T, U);
+  };
+
+  ::f
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:351:7 %s -o - | FileCheck -check-prefix=CHECK_FUNCTION_CAN_BE_CALL %s
+  // CHECK_FUNCTION_CAN_BE_CALL: COMPLETION: foo : [#V#]foo<<#typename T#>, <#typename U#>{#, <#typename V#>#}>(<#T#>, <#U#>)
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -338,8 +338,11 @@
   ///
   /// \param InBaseClass whether the result was found in a base
   /// class of the searched context.
+  ///
+  /// \param BaseType the type of expression that precedes the "." or "->"
+  /// in a member access expression.
   void AddResult(Result R, DeclContext *CurContext, NamedDecl *Hiding,
- bool InBaseClass);
+ bool InBaseClass, QualType BaseType);
 
   /// Add a new non-declaration result to this result set.
   void AddResult(Result R);
@@ -1262,7 +1265,8 @@
 }
 
 void 

[PATCH] D157227: [Clang] Don't add `undef` for `operator new` under -fno-exceptions.

2023-08-06 Thread DianQK via Phabricator via cfe-commits
DianQK created this revision.
Herald added subscribers: atanasyan, jrtc27.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
DianQK requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang.

The current implementation of `operator new` under -fno-exceptions 
returns`nullptr`.
This is undefined behavior. D150610  may take 
longer to complete.
Removing the undef attribute may be a solution without changing libcxx.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157227

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CodeGen/noundef-analysis.cpp
  clang/test/CodeGenCXX/aix-alignment.cpp
  clang/test/CodeGenCXX/align-avx-complete-objects.cpp
  clang/test/CodeGenCXX/builtin-calling-conv.cpp
  clang/test/CodeGenCXX/builtin-is-constant-evaluated.cpp
  clang/test/CodeGenCXX/builtin-operator-new-delete.cpp
  clang/test/CodeGenCXX/cxx11-initializer-array-new.cpp
  clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp
  clang/test/CodeGenCXX/delete-two-arg.cpp
  clang/test/CodeGenCXX/microsoft-abi-array-cookies.cpp
  clang/test/CodeGenCXX/mips-size_t-ptrdiff_t.cpp
  clang/test/CodeGenCXX/multi-dim-operator-new.cpp
  clang/test/CodeGenCXX/new-alias.cpp
  clang/test/CodeGenCXX/new-array-init.cpp
  clang/test/CodeGenCXX/new-infallible.cpp
  clang/test/CodeGenCXX/new-overflow.cpp
  clang/test/CodeGenCXX/new.cpp
  clang/test/CodeGenCXX/new_hot_cold.cpp
  clang/test/CodeGenCXX/operator-new.cpp
  clang/test/CodeGenCXX/static-init.cpp
  clang/test/CodeGenCoroutines/coro-alloc.cpp
  clang/test/CodeGenCoroutines/coro-gro.cpp
  clang/test/CodeGenCoroutines/coro-gro2.cpp
  clang/test/CodeGenCoroutines/coro-return.cpp
  clang/test/CodeGenObjCXX/arc-new-delete.mm
  clang/test/CodeGenObjCXX/copy.mm
  clang/test/OpenMP/reduction_implicit_map.cpp

Index: clang/test/OpenMP/reduction_implicit_map.cpp
===
--- clang/test/OpenMP/reduction_implicit_map.cpp
+++ clang/test/OpenMP/reduction_implicit_map.cpp
@@ -2101,7 +2101,7 @@
 // CHECK2-NEXT:[[RESULT:%.*]] = alloca i32, align 4
 // CHECK2-NEXT:store i32 0, ptr [[RETVAL]], align 4
 // CHECK2-NEXT:store i32 100, ptr [[SIZE]], align 4
-// CHECK2-NEXT:[[CALL:%.*]] = call noalias noundef nonnull ptr @_Znaj(i32 noundef 400) #[[ATTR10:[0-9]+]]
+// CHECK2-NEXT:[[CALL:%.*]] = call noalias nonnull ptr @_Znaj(i32 noundef 400) #[[ATTR10:[0-9]+]]
 // CHECK2-NEXT:store ptr [[CALL]], ptr [[ARRAY]], align 4
 // CHECK2-NEXT:store i32 0, ptr [[RESULT]], align 4
 // CHECK2-NEXT:[[TMP0:%.*]] = load ptr, ptr [[ARRAY]], align 4
Index: clang/test/CodeGenObjCXX/copy.mm
===
--- clang/test/CodeGenObjCXX/copy.mm
+++ clang/test/CodeGenObjCXX/copy.mm
@@ -11,7 +11,7 @@
   // CHECK:  alloca
   // CHECK-NEXT: getelementptr
   // CHECK-NEXT: store
-  // CHECK-NEXT: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm(
+  // CHECK-NEXT: [[CALL:%.*]] = call noalias nonnull ptr @_Znwm(
   // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(
   // CHECK-NEXT: ret
   A *test(A a) {
Index: clang/test/CodeGenObjCXX/arc-new-delete.mm
===
--- clang/test/CodeGenObjCXX/arc-new-delete.mm
+++ clang/test/CodeGenObjCXX/arc-new-delete.mm
@@ -12,28 +12,28 @@
   // OPT-NEXT: [[T0:%.*]] = call ptr @llvm.objc.retain(ptr [[INVALUE:%.*]])
   // OPT-NEXT: store ptr [[T0]], ptr [[INVALUEADDR]]
 
-  // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
+  // CHECK: [[CALL:%.*]] = call noalias nonnull ptr @_Znwm
   // CHECK-NEXT: store ptr null, ptr
   new strong_id;
-  // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
+  // CHECK: [[CALL:%.*]] = call noalias nonnull ptr @_Znwm
   // UNOPT-NEXT: store ptr null, ptr
   // OPT-NEXT: call ptr @llvm.objc.initWeak(ptr {{.*}}, ptr null)
   new weak_id;
 
-  // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
+  // CHECK: [[CALL:%.*]] = call noalias nonnull ptr @_Znwm
   // CHECK-NEXT: store ptr null, ptr
   new __strong id;
-  // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
+  // CHECK: [[CALL:%.*]] = call noalias nonnull ptr @_Znwm
   // UNOPT-NEXT: store ptr null, ptr
   // OPT-NEXT: call ptr @llvm.objc.initWeak(ptr {{.*}}, ptr null)
   new __weak id;
 
-  // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
+  // CHECK: [[CALL:%.*]] = call noalias nonnull ptr @_Znwm
   // CHECK: call ptr @llvm.objc.retain
   // CHECK: store ptr
   new __strong id(invalue);
 
-  // CHECK: [[CALL:%.*]] = call noalias noundef nonnull ptr @_Znwm
+  // CHECK: [[CALL:%.*]] = call noalias nonnull ptr @_Znwm
   // CHECK: call ptr @llvm.objc.initWeak
   new __weak id(invalue);
 
@@ -44,12 +44,12 @@
 
 // 

[PATCH] D157205: [clangd] Add hexadecimal member offsets and sizes to hover popup

2023-08-06 Thread SR_team via Phabricator via cfe-commits
SR_team added a comment.

Until a 10, we don't have difference between DEC and HEX, may be print only DEC 
in these cases?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157205

___
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-06 Thread Yichi Lee via Phabricator via cfe-commits
yichi170 added inline comments.



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

tbaeder wrote:
> 
I'll fix it along with the ReleaseNotes.


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] D157208: [clang] Fix typos in comments

2023-08-06 Thread Mehmet Eymen Ünay via Phabricator via cfe-commits
Eymay created this revision.
Herald added a project: All.
Eymay 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/D157208

Files:
  clang/include/clang/AST/ASTImporterLookupTable.h
  clang/test/Sema/alloc-align-attr.c


Index: clang/test/Sema/alloc-align-attr.c
===
--- clang/test/Sema/alloc-align-attr.c
+++ clang/test/Sema/alloc-align-attr.c
@@ -17,7 +17,7 @@
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align())); // 
expected-error {{'alloc_align' attribute takes one argument}}
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align(32, 45, 37))); 
// expected-error {{'alloc_align' attribute takes one argument}}
 
-void *passthrought(int a) {
+void *passthrough(int a) {
   return test_ptr_alloc_align(a);
 }
 void *align16(void) {
Index: clang/include/clang/AST/ASTImporterLookupTable.h
===
--- clang/include/clang/AST/ASTImporterLookupTable.h
+++ clang/include/clang/AST/ASTImporterLookupTable.h
@@ -34,7 +34,7 @@
 // Example 2:
 //   // The fwd decl to Foo is not found in the lookupPtr of the DC of the
 //   // translation unit decl.
-//   // Here we could find the node by doing a traverse throught the list of
+//   // Here we could find the node by doing a traverse throughout the list of
 //   // the Decls in the DC, but that would not scale.
 //   struct A { struct Foo *p; };
 // This is a severe problem because the importer decides if it has to create a


Index: clang/test/Sema/alloc-align-attr.c
===
--- clang/test/Sema/alloc-align-attr.c
+++ clang/test/Sema/alloc-align-attr.c
@@ -17,7 +17,7 @@
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align())); // expected-error {{'alloc_align' attribute takes one argument}}
 void *test_no_fn_proto(int x, int y) __attribute__((alloc_align(32, 45, 37))); // expected-error {{'alloc_align' attribute takes one argument}}
 
-void *passthrought(int a) {
+void *passthrough(int a) {
   return test_ptr_alloc_align(a);
 }
 void *align16(void) {
Index: clang/include/clang/AST/ASTImporterLookupTable.h
===
--- clang/include/clang/AST/ASTImporterLookupTable.h
+++ clang/include/clang/AST/ASTImporterLookupTable.h
@@ -34,7 +34,7 @@
 // Example 2:
 //   // The fwd decl to Foo is not found in the lookupPtr of the DC of the
 //   // translation unit decl.
-//   // Here we could find the node by doing a traverse throught the list of
+//   // Here we could find the node by doing a traverse throughout the list of
 //   // the Decls in the DC, but that would not scale.
 //   struct A { struct Foo *p; };
 // This is a severe problem because the importer decides if it has to create a
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D157207: [clangd] Fix typo in comment

2023-08-06 Thread Mehmet Eymen Ünay via Phabricator via cfe-commits
Eymay created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
Eymay requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157207

Files:
  clang-tools-extra/clangd/Protocol.h


Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -592,7 +592,7 @@
 /// Clangd extension: parameters configurable at `initialize` time.
 /// LSP defines this type as `any`.
 struct InitializationOptions {
-  // What we can change throught the didChangeConfiguration request, we can
+  // What we can change through the didChangeConfiguration request, we can
   // also set through the initialize request (initializationOptions field).
   ConfigurationSettings ConfigSettings;
 


Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -592,7 +592,7 @@
 /// Clangd extension: parameters configurable at `initialize` time.
 /// LSP defines this type as `any`.
 struct InitializationOptions {
-  // What we can change throught the didChangeConfiguration request, we can
+  // What we can change through the didChangeConfiguration request, we can
   // also set through the initialize request (initializationOptions field).
   ConfigurationSettings ConfigSettings;
 
___
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-06 Thread Yichi Lee via Phabricator via cfe-commits
yichi170 updated this revision to Diff 547542.
yichi170 added a comment.

[Clang] Support qualified name as member designator in offsetof


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157201

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


Index: clang/test/Sema/offsetof.c
===
--- clang/test/Sema/offsetof.c
+++ clang/test/Sema/offsetof.c
@@ -73,3 +73,8 @@
   return __builtin_offsetof(Array, array[*(int*)0]); // 
expected-warning{{indirection of non-volatile null pointer}} 
expected-note{{__builtin_trap}}
 }
 
+// https://github.com/llvm/llvm-project/issues/64154
+struct X2 { int a; };
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // 
expected-error{{no member named 'X2'}}
+
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/test/Sema/offsetof.c
===
--- clang/test/Sema/offsetof.c
+++ clang/test/Sema/offsetof.c
@@ -73,3 +73,8 @@
   return __builtin_offsetof(Array, array[*(int*)0]); // expected-warning{{indirection of non-volatile null pointer}} expected-note{{__builtin_trap}}
 }
 
+// https://github.com/llvm/llvm-project/issues/64154
+struct X2 { int a; };
+int x2[__builtin_offsetof(struct X2, X2::a) == 0 ? 1 : -1];
+int x3[__builtin_offsetof(struct X2, X2::X2) == 0 ? 1 : -1]; // expected-error{{no member named 'X2'}}
+
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 ']'
 

[clang-tools-extra] 16f6f19 - [clang-tidy][NFC] Update release notes

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

Author: Piotr Zegar
Date: 2023-08-06T09:36:20Z
New Revision: 16f6f1938be6dc582bbfb976603b4e5adfa2302a

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

LOG: [clang-tidy][NFC] Update release notes

Keep release notes in same format, remove the.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 284399afc11352..998242f9a5c4c0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -184,7 +184,7 @@ Changes in existing checks
   ` check to enforce a stricter
   match with the swap function signature, eliminating false-positives.
 
-- Improved the :doc:`readability-identifier-naming
+- Improved :doc:`readability-identifier-naming
   ` check to emit proper
   warnings when a type forward declaration precedes its definition.
 



___
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-06 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2553e2403a33: [clang-tidy] Fix false-positives in 
performanc-noexcept-swap (authored by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D157185?vs=547528=547537#toc

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,20 @@
 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&);
+
+friend void swap(Test&, Test&);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: swap functions should be 
marked noexcept [performance-noexcept-swap]
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -180,6 +180,10 @@
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- Improved :doc:`performanc-noexcept-swap
+  ` check to enforce a stricter
+  match with the swap function signature, eliminating false-positives.
+
 - Improved the :doc:`readability-identifier-naming
   ` check to emit proper
   warnings when a type forward declaration precedes its definition.
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,32 @@
 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.
+  // Matches: 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.
+  // Matches: 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,20 @@
 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&);
+
+friend void swap(Test&, Test&);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: swap functions should be marked noexcept [performance-noexcept-swap]
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst

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

2023-08-06 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2111577d4dfc: [clang-tidy] Fixed false-negative in 
readability-identifier-naming (authored by PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D157190?vs=547503=547536#toc

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 _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
@@ -180,6 +180,10 @@
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- 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 _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;
+// 

[clang-tools-extra] 2553e24 - [clang-tidy] Fix false-positives in performanc-noexcept-swap

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

Author: Piotr Zegar
Date: 2023-08-06T09:23:21Z
New Revision: 2553e2403a33824bea7ca280c9328b0b0acf2836

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

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

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

Fixes: #64303

Reviewed By: carlosgalvezp

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

Added: 


Modified: 
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

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
index 65baebd808f6cf..25a58af74f7ee8 100644
--- a/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
@@ -17,9 +17,32 @@ using namespace clang::ast_matchers;
 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.
+  // Matches: 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.
+  // Matches: 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

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1d006ae3fa16f5..284399afc11352 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -180,6 +180,10 @@ Changes in existing checks
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- Improved :doc:`performanc-noexcept-swap
+  ` check to enforce a stricter
+  match with the swap function signature, eliminating false-positives.
+
 - Improved the :doc:`readability-identifier-naming
   ` check to emit proper
   warnings when a type forward declaration precedes its definition.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
index 11c65906e89682..392b5d17d456e7 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp
@@ -201,3 +201,20 @@ struct OK21 {
 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&);
+
+friend void swap(Test&, Test&);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: swap functions should be 
marked noexcept [performance-noexcept-swap]
+  };
+}



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


[clang-tools-extra] 2111577 - [clang-tidy] Fixed false-negative in readability-identifier-naming

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

Author: Piotr Zegar
Date: 2023-08-06T09:22:31Z
New Revision: 2111577d4dfc1d48b4e2221f84597fa4f54b8cfd

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

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

Issue were cased by checking if canonical declaration of record is a
definition. Unfortunately when forward declarations were used, it were
not a definition.

Fixes: #64463

Reviewed By: carlosgalvezp

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

Added: 


Modified: 
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

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 0e16edc10a9530..d240d8d244ef91 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1140,30 +1140,28 @@ StyleKind IdentifierNamingCheck::findStyleKind(
 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;
   }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1bebc55eec7d08..1d006ae3fa16f5 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -180,6 +180,10 @@ Changes in existing checks
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- Improved the :doc:`readability-identifier-naming
+  ` check to emit proper
+  warnings when a type forward declaration precedes its definition.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
index b506b4bbe01034..a017fc51d4cbf4 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
@@ -707,3 +707,19 @@ struct async_obj {
 task ImplicitDeclTest(async_obj _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 {
+};
+



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


[PATCH] D157205: [clangd] Add hexadecimal member offsets and sizes to hover popup

2023-08-06 Thread tetra via Phabricator via cfe-commits
tetraxile created this revision.
tetraxile added a reviewer: sammccall.
tetraxile added a project: clang-tools-extra.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
tetraxile requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.

This changes the formatting of class/struct member variable byte offsets and 
sizes, as well as class sizes, from just the decimal value, e.g. "Offset: 12 
bytes", to both decimal and hexadecimal, e.g. "Offset: 12 (0xc) bytes".

I'm open to adding a config file option to disable this feature if users want 
to reduce clutter, but I think it'd be unnecessary, as the other lines in the 
hover popup (declaration, type, comment) are already quite a bit longer than 
the offset and size lines.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157205

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3331,7 +3331,7 @@
   },
   R"(class foo
 
-Size: 10 bytes
+Size: 10 (0xa) bytes
 documentation
 
 template  class Foo {})",
@@ -3382,8 +3382,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 12 bytes
-Size: 4 bytes (+4 bytes padding)
+Offset: 12 (0xc) bytes
+Size: 4 (0x4) bytes (+4 (0x4) bytes padding)
 
 // In test::Bar
 def)",
@@ -3404,8 +3404,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 4 bytes and 3 bits
-Size: 25 bits (+4 bits padding)
+Offset: 4 (0x4) bytes and 3 (0x3) bits
+Size: 25 (0x19) bits (+4 (0x4) bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1404,7 +1404,8 @@
 static std::string formatSize(uint64_t SizeInBits) {
   uint64_t Value = SizeInBits % 8 == 0 ? SizeInBits / 8 : SizeInBits;
   const char *Unit = Value != 0 && Value == SizeInBits ? "bit" : "byte";
-  return llvm::formatv("{0} {1}{2}", Value, Unit, Value == 1 ? "" : "s").str();
+  return llvm::formatv("{0} ({0:x}) {1}{2}", Value, Unit, Value == 1 ? "" : 
"s")
+  .str();
 }
 
 // Offsets are shown in bytes + bits, so offsets of different fields


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3331,7 +3331,7 @@
   },
   R"(class foo
 
-Size: 10 bytes
+Size: 10 (0xa) bytes
 documentation
 
 template  class Foo {})",
@@ -3382,8 +3382,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 12 bytes
-Size: 4 bytes (+4 bytes padding)
+Offset: 12 (0xc) bytes
+Size: 4 (0x4) bytes (+4 (0x4) bytes padding)
 
 // In test::Bar
 def)",
@@ -3404,8 +3404,8 @@
 
 Type: type (aka can_type)
 Value = value
-Offset: 4 bytes and 3 bits
-Size: 25 bits (+4 bits padding)
+Offset: 4 (0x4) bytes and 3 (0x3) bits
+Size: 25 (0x19) bits (+4 (0x4) bits padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -1404,7 +1404,8 @@
 static std::string formatSize(uint64_t SizeInBits) {
   uint64_t Value = SizeInBits % 8 == 0 ? SizeInBits / 8 : SizeInBits;
   const char *Unit = Value != 0 && Value == SizeInBits ? "bit" : "byte";
-  return llvm::formatv("{0} {1}{2}", Value, Unit, Value == 1 ? "" : "s").str();
+  return llvm::formatv("{0} ({0:x}) {1}{2}", Value, Unit, Value == 1 ? "" : "s")
+  .str();
 }
 
 // Offsets are shown in bytes + bits, so offsets of different fields
___
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-06 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 547529.
Krishna-13-cyber added a comment.

- Address the comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156858

Files:
  clang/docs/ClangRepl.rst
  clang/docs/ExecutionResultsHandling.rst
  clang/docs/autoprint.png
  clang/docs/index.rst
  clang/docs/prettyprint.png
  clang/docs/valuesynth.png

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -93,6 +93,7 @@
ClangOffloadBundler
ClangOffloadPackager
ClangRepl
+   ExecutionResultsHandling
 
 Design Documents
 
Index: clang/docs/ExecutionResultsHandling.rst
===
--- /dev/null
+++ clang/docs/ExecutionResultsHandling.rst
@@ -0,0 +1,333 @@
+=
+Execution Results Handling in Clang-REPL
+=
+
+Execution Results Handling features discussed below help extend the Clang-REPL 
+functionality by creating an interface between the execution results of a 
+program and the compiled program.
+
+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. 
+
+
+1. Capture Execution Results
+
+
+In many cases, it is useful to bring back the program execution result to the 
+compiled program. This result can be stored in an object of type **Value**.
+
+How Execution Results are captured (Value Synthesis):
+-
+
+The synthesizer chooses which expression to synthesize, and then it replaces 
+the original expression with the synthesized expression. Depending on the 
+expression type, it may choose to save an object (``LastValue``) of type 'value'
+while allocating memory to it (``SetValueWithAlloc()``), or not (
+``SetValueNoAlloc()``).
+
+.. image:: valuesynth.png
+   :align: center
+   :alt: valuesynth design
+
+Where is the captured result stored?
+
+
+``LastValue`` holds the last result of the value printing. It is a class member 
+because it can be accessed even after subsequent inputs. 
+
+**Note:** If no value printing happens, then it is in an invalid state. 
+
+Improving Efficiency and User Experience
+
+
+The Value object is essentially used to create a mapping between an expression 
+'type' and the 'memory' to be allocated. Built-in types (bool, char, int, 
+float, double, etc.) are simpler, since their memory allocation size is known. 
+In case of objects, a pointer can be saved, since the size of the object is 
+not known.
+
+For further improvement, the underlying Clang Type is also identified. For 
+example, ``X(char, Char_S)``, where ``Char_S`` is the Clang type. Clang types are 
+very efficient, which is important since these will be used in hotspots (high 
+utilization areas of the program). The ``Value.h`` header file has a very low 
+token count and was developed with strict constraints in mind, since it can 
+affect the performance of the interpreter.
+
+This also enables the user to receive the computed 'type' back in their code 
+and then transform the type into something else (e.g., transform a double into 
+a float). Normally, the compiler can handle these conversions transparently, 
+but in interpreter mode, the compiler cannot see all the 'from' and 'to' types,
+so it cannot implicitly do the conversions. So this logic enables providing 
+these conversions on request. 
+
+On-request conversions can help improve the user experience, by allowing 
+conversion to a desired 'to' type, when the 'from' type is unknown or unclear
+
+Significance of this Feature
+
+
+The 'Value' object enables wrapping a memory region that comes from the 
+JIT, and bringing it back to the compiled code (and vice versa). 
+This is a very useful functionality when:
+
+- connecting an interpreter to the compiled code, or
+- connecting an interpreter in another language.
+
+For example, the CPPYY code makes use of this feature to enable running 
+C++ within Python. It enables transporting values/information between C++ 
+and Python.
+
+In a nutshell, this feature enables a new way of developing code, paving the 
+way for language interoperability and easier interactive programming.
+
+Implementation Details
+==
+
+Interpreter as a REPL vs. as a Library
+--
+
+1 - If we're using the interpreter in interactive (REPL) mode, it will dump 
+the value (i.e., value printing).
+
+.. 

[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

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

The fuzzer timeouts fail all the time; I usually just assume it's unrelated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

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


[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-08-06 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

I reverted this change because it broke sanitizer buildbots.
https://lab.llvm.org/buildbot/#/builders/19/builds/18369
The cause of the errors here are relatively clear and I can speculatively 
replace `if (std::error_code EC = makeCanonical(Path))` with `if 
(makeCanonical(Path))`

https://lab.llvm.org/buildbot/#/builders/94/builds/15865
https://lab.llvm.org/buildbot/#/builders/240/builds/12947
These 2 are not clear for me, so I'll take time to find the cause.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

___
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-06 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 547528.
PiotrZSL added a comment.

Remove space


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,20 @@
 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&);
+
+friend void swap(Test&, Test&);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: swap functions should be 
marked noexcept [performance-noexcept-swap]
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -176,6 +176,10 @@
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- 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,32 @@
 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.
+  // Matches: 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.
+  // Matches: 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,20 @@
 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&);
+
+friend void swap(Test&, Test&);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: swap functions should be marked noexcept [performance-noexcept-swap]
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -176,6 +176,10 @@
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- Improved :doc:`performanc-noexcept-swap
+  ` check 

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

2023-08-06 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb3700c34aa71: [clang-tidy] Re-add 
cppcoreguidelines-macro-to-enum alias (authored by PiotrZSL).

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


[clang-tools-extra] b3700c3 - [clang-tidy] Re-add cppcoreguidelines-macro-to-enum alias

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

Author: Piotr Zegar
Date: 2023-08-06T08:09:57Z
New Revision: b3700c34aa712fb4034fb2c31b0767993b1a6b7f

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

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

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

Fixes: #64342

Reviewed By: carlosgalvezp

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

Added: 


Modified: 

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

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
index a535e7d0c14fba..fdbf0e11f3f5f8 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ 
b/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 @@ class CppCoreGuidelinesModule : public ClangTidyModule {
 "cppcoreguidelines-init-variables");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
+CheckFactories.registerCheck(
+"cppcoreguidelines-macro-to-enum");
 CheckFactories.registerCheck(
 "cppcoreguidelines-macro-usage");
 CheckFactories.registerCheck(

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ba79e8df786135..1bebc55eec7d08 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -156,6 +156,10 @@ New checks
 New check aliases
 ^
 
+- New alias :doc:`cppcoreguidelines-macro-to-enum
+  ` to 
:doc:`modernize-macro-to-enum
+  ` was added.
+
 Changes in existing checks
 ^^
 



___
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-06 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 547526.
PiotrZSL marked 3 inline comments as done.
PiotrZSL added a comment.

Fix comments + add test with friend


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,20 @@
 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&);
+
+friend void swap(Test&, Test&);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: swap functions should be 
marked noexcept [performance-noexcept-swap]
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -176,6 +176,10 @@
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- 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,32 @@
 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.
+  // Matches: 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.
+  // Matches: 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,20 @@
 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&);
+
+friend void swap(Test&, Test&);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: swap functions should be marked noexcept [performance-noexcept-swap]
+  };
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -176,6 +176,10 @@
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, 

[clang] 18b6f6e - Revert "[Clang][SemaCXX] Add unused warning for variables declared in condition expressions"

2023-08-06 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-08-06T17:02:01+09:00
New Revision: 18b6f6e0c7d0b492e90738d684aeb731754aeaac

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

LOG: Revert "[Clang][SemaCXX] Add unused warning for variables declared in 
condition expressions"

Broke sanitizer buildbot:
https://lab.llvm.org/buildbot/#/builders/240/builds/12947
https://lab.llvm.org/buildbot/#/builders/19/builds/18369

Reverting while I figure out the cause.

This reverts commit bd0ed0abc31fa5a49e87eeca7aa872e7f6e4d1e7.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/warn-unused-variables.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8ff9a019563447..f03e5231215eb2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -121,9 +121,6 @@ Improvements to Clang's diagnostics
 ---
 - Clang constexpr evaluator now prints template arguments when displaying
   template-specialization function calls.
-- Clang now warns on unused variables declared and initialized in condition
-  expressions.
-  (`#61681: `_)
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6ea3b88389735a..a24856b64ec92b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1995,7 +1995,7 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions 
,
   return false;
   } else if (!D->getDeclName()) {
 return false;
-  } else if (D->isReferenced() || (!isa(D) && D->isUsed())) {
+  } else if (D->isReferenced() || D->isUsed()) {
 return false;
   }
 

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index ec7c146f08d2ea..423d5372a6f65a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4015,10 +4015,6 @@ ExprResult Sema::CheckConditionVariable(VarDecl 
*ConditionVar,
   ConditionVar, ConditionVar->getType().getNonReferenceType(), VK_LValue,
   ConditionVar->getLocation());
 
-  // Ensure that `-Wunused-variable` will be emitted for condition variables
-  // that are not referenced later. e.g.: if (int var = init());
-  ConditionVar->setReferenced(/*R=*/false);
-
   switch (CK) {
   case ConditionKind::Boolean:
 return CheckBooleanCondition(StmtLoc, Condition.get());

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 522ec12de3d368..f78d46f5950360 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5352,7 +5352,7 @@ void Sema::BuildVariableInstantiation(
   // will have been deferred.
   if (!NewVar->isInvalidDecl() &&
   NewVar->getDeclContext()->isFunctionOrMethod() &&
-  OldVar->getType()->isDependentType() && !OldVar->isImplicit())
+  OldVar->getType()->isDependentType())
 DiagnoseUnusedDecl(NewVar);
 }
 

diff  --git a/clang/test/SemaCXX/warn-unused-variables.cpp 
b/clang/test/SemaCXX/warn-unused-variables.cpp
index db33086436d3af..4db8bdf12e5de0 100644
--- a/clang/test/SemaCXX/warn-unused-variables.cpp
+++ b/clang/test/SemaCXX/warn-unused-variables.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++14-extensions -Wno-c++17-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify -std=c++11 %s
 template void f() {
   T t;
   t = 17;
@@ -294,115 +294,3 @@ void RAIIWrapperTest() {
 }
 
 } // namespace gh54489
-
-namespace inside_condition {
-  void ifs() {
-if (int hoge = 0) // expected-warning {{unused variable 'hoge'}}
-  return;
-if (const int const_hoge = 0) // expected-warning {{unused variable 
'const_hoge'}}
-  return;
-else if (int fuga = 0)
-  (void)fuga;
-else if (int used = 1; int catched = used) // expected-warning {{unused 
variable 'catched'}}
-  return;
-else if (int refed = 1; int used = refed)
-  (void)used;
-else if (int unused1 = 2; int unused2 = 3) // expected-warning {{unused 
variable 'unused1'}} \
-   // expected-warning {{unused 
variable 'unused2'}}
-  return;
-else if (int unused = 4; int used = 5) // expected-warning {{unused 
variable 'unused'}}
-  (void)used;
-else if (int used = 6; int unused = 7) // expected-warning {{unused 
variable 'unused'}}
-  

[PATCH] D152495: [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-08-06 Thread Takuya Shimizu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbd0ed0abc31f: [Clang][SemaCXX] Add unused warning for 
variables declared in condition… (authored by hazohelet).

Changed prior to commit:
  https://reviews.llvm.org/D152495?vs=540479=547525#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152495

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaCXX/warn-unused-variables.cpp

Index: clang/test/SemaCXX/warn-unused-variables.cpp
===
--- clang/test/SemaCXX/warn-unused-variables.cpp
+++ clang/test/SemaCXX/warn-unused-variables.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++1y-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label -Wno-c++14-extensions -Wno-c++17-extensions -verify -std=c++11 %s
 template void f() {
   T t;
   t = 17;
@@ -294,3 +294,115 @@
 }
 
 } // namespace gh54489
+
+namespace inside_condition {
+  void ifs() {
+if (int hoge = 0) // expected-warning {{unused variable 'hoge'}}
+  return;
+if (const int const_hoge = 0) // expected-warning {{unused variable 'const_hoge'}}
+  return;
+else if (int fuga = 0)
+  (void)fuga;
+else if (int used = 1; int catched = used) // expected-warning {{unused variable 'catched'}}
+  return;
+else if (int refed = 1; int used = refed)
+  (void)used;
+else if (int unused1 = 2; int unused2 = 3) // expected-warning {{unused variable 'unused1'}} \
+   // expected-warning {{unused variable 'unused2'}}
+  return;
+else if (int unused = 4; int used = 5) // expected-warning {{unused variable 'unused'}}
+  (void)used;
+else if (int used = 6; int unused = 7) // expected-warning {{unused variable 'unused'}}
+  (void)used;
+else if (int used1 = 8; int used2 = 9)
+  (void)(used1 + used2);
+else if (auto [a, b] = (int[2]){ 1, 2 }; 1) // expected-warning {{unused variable '[a, b]'}}
+  return;
+else if (auto [a, b] = (int[2]){ 1, 2 }; a)
+  return;
+  }
+
+  void fors() {
+for (int i = 0;int unused = 0;); // expected-warning {{unused variable 'i'}} \
+ // expected-warning {{unused variable 'unused'}}
+for (int i = 0;int used = 0;) // expected-warning {{unused variable 'i'}}
+  (void)used;
+  while(int var = 1) // expected-warning {{unused variable 'var'}}
+return;
+  }
+
+  void whiles() {
+while(int unused = 1) // expected-warning {{unused variable 'unused'}}
+  return;
+while(int used = 1)
+  (void)used;
+  }
+
+
+  void switches() {
+switch(int unused = 1) { // expected-warning {{unused variable 'unused'}}
+  case 1: return;
+}
+switch(constexpr int used = 3; int unused = 4) { // expected-warning {{unused variable 'unused'}}
+  case used: return;
+}
+switch(int used = 3; int unused = 4) { // expected-warning {{unused variable 'unused'}}
+  case 3: (void)used;
+}
+switch(constexpr int used1 = 0; constexpr int used2 = 6) {
+  case (used1+used2): return;
+}
+switch(auto [a, b] = (int[2]){ 1, 2 }; 1) { // expected-warning {{unused variable '[a, b]'}}
+  case 1: return;
+}
+switch(auto [a, b] = (int[2]){ 1, 2 }; b) {
+  case 1: return;
+}
+switch(auto [a, b] = (int[2]){ 1, 2 }; 1) {
+  case 1: (void)a;
+}
+  }
+  template 
+  struct Vector {
+void doIt() {
+  for (auto& e : elements){} // expected-warning {{unused variable 'e'}}
+}
+T elements[10];
+  };
+  void ranged_for() {
+Vectorvector;
+vector.doIt(); // expected-note {{here}}
+  }
+
+
+  struct RAII {
+int 
+RAII(int ) : x(ref) {}
+~RAII() { x = 0;}
+operator int() const { return 1; }
+  };
+  void aggregate() {
+int x = 10;
+int y = 10;
+if (RAII var = x) {}
+for(RAII var = x; RAII var2 = y;) {}
+while (RAII var = x) {}
+switch (RAII var = x) {}
+  }
+
+  struct TrivialDtor{
+int 
+TrivialDtor(int ) : x(ref) { ref = 32; }
+operator int() const { return 1; }
+  };
+  void trivial_dtor() {
+int x = 10;
+int y = 10;
+if (TrivialDtor var = x) {} // expected-warning {{unused variable 'var'}}
+for(TrivialDtor var = x; TrivialDtor var2 = y;) {} // expected-warning {{unused variable 'var'}} \
+ // expected-warning {{unused variable 'var2'}}
+while (TrivialDtor var = x) {} // expected-warning {{unused variable 'var'}}
+switch (TrivialDtor var = x) {} 

[clang] bd0ed0a - [Clang][SemaCXX] Add unused warning for variables declared in condition expressions

2023-08-06 Thread Takuya Shimizu via cfe-commits

Author: Takuya Shimizu
Date: 2023-08-06T16:24:09+09:00
New Revision: bd0ed0abc31fa5a49e87eeca7aa872e7f6e4d1e7

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

LOG: [Clang][SemaCXX] Add unused warning for variables declared in condition 
expressions

This patch marks the declarations with initializations in condition expressions 
such as
if (int var = init) as unreferenced so that -Wunused can warn on them.

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

Reviewed By: cor3ntin
Differential Revision: https://reviews.llvm.org/D152495

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/warn-unused-variables.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f03e5231215eb2..8ff9a019563447 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -121,6 +121,9 @@ Improvements to Clang's diagnostics
 ---
 - Clang constexpr evaluator now prints template arguments when displaying
   template-specialization function calls.
+- Clang now warns on unused variables declared and initialized in condition
+  expressions.
+  (`#61681: `_)
 
 Bug Fixes in This Version
 -

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a24856b64ec92b..6ea3b88389735a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1995,7 +1995,7 @@ static bool ShouldDiagnoseUnusedDecl(const LangOptions 
,
   return false;
   } else if (!D->getDeclName()) {
 return false;
-  } else if (D->isReferenced() || D->isUsed()) {
+  } else if (D->isReferenced() || (!isa(D) && D->isUsed())) {
 return false;
   }
 

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 423d5372a6f65a..ec7c146f08d2ea 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4015,6 +4015,10 @@ ExprResult Sema::CheckConditionVariable(VarDecl 
*ConditionVar,
   ConditionVar, ConditionVar->getType().getNonReferenceType(), VK_LValue,
   ConditionVar->getLocation());
 
+  // Ensure that `-Wunused-variable` will be emitted for condition variables
+  // that are not referenced later. e.g.: if (int var = init());
+  ConditionVar->setReferenced(/*R=*/false);
+
   switch (CK) {
   case ConditionKind::Boolean:
 return CheckBooleanCondition(StmtLoc, Condition.get());

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index f78d46f5950360..522ec12de3d368 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5352,7 +5352,7 @@ void Sema::BuildVariableInstantiation(
   // will have been deferred.
   if (!NewVar->isInvalidDecl() &&
   NewVar->getDeclContext()->isFunctionOrMethod() &&
-  OldVar->getType()->isDependentType())
+  OldVar->getType()->isDependentType() && !OldVar->isImplicit())
 DiagnoseUnusedDecl(NewVar);
 }
 

diff  --git a/clang/test/SemaCXX/warn-unused-variables.cpp 
b/clang/test/SemaCXX/warn-unused-variables.cpp
index 4db8bdf12e5de0..db33086436d3af 100644
--- a/clang/test/SemaCXX/warn-unused-variables.cpp
+++ b/clang/test/SemaCXX/warn-unused-variables.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify %s
-// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++1y-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-variable -Wunused-label 
-Wno-c++14-extensions -Wno-c++17-extensions -verify -std=c++11 %s
 template void f() {
   T t;
   t = 17;
@@ -294,3 +294,115 @@ void RAIIWrapperTest() {
 }
 
 } // namespace gh54489
+
+namespace inside_condition {
+  void ifs() {
+if (int hoge = 0) // expected-warning {{unused variable 'hoge'}}
+  return;
+if (const int const_hoge = 0) // expected-warning {{unused variable 
'const_hoge'}}
+  return;
+else if (int fuga = 0)
+  (void)fuga;
+else if (int used = 1; int catched = used) // expected-warning {{unused 
variable 'catched'}}
+  return;
+else if (int refed = 1; int used = refed)
+  (void)used;
+else if (int unused1 = 2; int unused2 = 3) // expected-warning {{unused 
variable 'unused1'}} \
+   // expected-warning {{unused 
variable 'unused2'}}
+  return;
+else if (int unused = 4; int used = 5) // expected-warning {{unused 
variable 'unused'}}
+  (void)used;
+else if (int used = 6; int unused = 7) // expected-warning 

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

2023-08-06 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 

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

2023-08-06 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] D157201: [Clang] Support qualified name as member designator in offsetof

2023-08-06 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-06 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] D157185: [clang-tidy] Fix false-positives in performanc-noexcept-swap

2023-08-06 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