[clang-tools-extra] [clang-tidy] Ignore deleted ctor in `bugprone-forwarding-reference-overload` (PR #88138)

2024-04-15 Thread Mike Weller via cfe-commits

https://github.com/MikeWeller updated 
https://github.com/llvm/llvm-project/pull/88138

>From 4cb9527430d3c7f9acc518427a29eae0aa7e00d1 Mon Sep 17 00:00:00 2001
From: Mike Weller 
Date: Tue, 9 Apr 2024 16:03:31 +0100
Subject: [PATCH 1/2] [clang-tidy] Ignore delete ctor in
 `bugprone-forwarding-reference-overload`

Fix `bugprone-forwarding-reference-overload` so it doesn't report a constructor 
that is deleted.
---
 .../bugprone/ForwardingReferenceOverloadCheck.cpp  |  1 +
 .../bugprone/forwarding-reference-overload.cpp | 10 ++
 2 files changed, 11 insertions(+)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index c608fe713f9f5b..e42b40d7b6690e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -73,6 +73,7 @@ void 
ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
   DeclarationMatcher FindOverload =
   cxxConstructorDecl(
   hasParameter(0, ForwardingRefParm),
+  unless(isDeleted()),
   unless(hasAnyParameter(
   // No warning: enable_if as constructor parameter.
   parmVarDecl(hasType(isEnableIf(),
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
index 38b0691bc9f1ec..92dfb718bb51b7 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
@@ -251,3 +251,13 @@ class Test10 {
   Test10(T &&Item, E e)
   : e(e){}
 };
+
+// A deleted ctor cannot hide anything
+class Test11 {
+public:
+  template 
+  Test11(T&&) = delete;
+
+  Test11(const Test11 &) = default;
+  Test11(Test11 &&) = default;
+};

>From 5f4f9c937ce9b2da54bbf303ddfa0d18dc92f4dc Mon Sep 17 00:00:00 2001
From: Mike Weller 
Date: Mon, 15 Apr 2024 08:07:16 +0100
Subject: [PATCH 2/2] Update release notes

---
 clang-tools-extra/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a7193e90c38da2..1a59449fdf7560 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -100,6 +100,7 @@ Improvements to clang-tidy
 - Improved :program:`run-clang-tidy.py` script. Added argument `-source-filter`
   to filter source files from the compilation database, via a RegEx. In a
   similar fashion to what `-header-filter` does for header files.
+- Fixed an issue with `bugprone-forwarding-reference-overload` where it would 
incorrectly flag deleted constructors
 
 New checks
 ^^

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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

2024-04-15 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/88645

>From 07424d8ee99fc418d071960bbdd4185564025139 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sun, 14 Apr 2024 02:41:48 -0400
Subject: [PATCH] [clang][Sema] Preserve the initializer of invalid VarDecls

Fixes https://github.com/clangd/clangd/issues/1821
---
 clang/lib/Sema/JumpDiagnostics.cpp   |  3 ++-
 clang/lib/Sema/SemaDecl.cpp  | 21 -
 clang/test/AST/ast-dump-recovery.cpp |  8 
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index ec3892e92f3c3b..27d5284fdb67e7 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -179,7 +179,8 @@ static ScopePair GetDiagForGotoScopeDecl(Sema &S, const 
Decl *D) {
 }
 
 const Expr *Init = VD->getInit();
-if (S.Context.getLangOpts().CPlusPlus && VD->hasLocalStorage() && Init) {
+if (S.Context.getLangOpts().CPlusPlus && VD->hasLocalStorage() && Init &&
+!Init->containsErrors()) {
   // C++11 [stmt.dcl]p3:
   //   A program that jumps from a point where a variable with automatic
   //   storage duration is not in scope to a point where it is in scope
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9fdd8eb236d1ee..6075624722b1cc 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13435,16 +13435,18 @@ void Sema::checkNonTrivialCUnion(QualType QT, 
SourceLocation Loc,
 void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
   // If there is no declaration, there was an error parsing it.  Just ignore
   // the initializer.
-  if (!RealDecl || RealDecl->isInvalidDecl()) {
+  if (!RealDecl) {
 CorrectDelayedTyposInExpr(Init, dyn_cast_or_null(RealDecl));
 return;
   }
 
   if (CXXMethodDecl *Method = dyn_cast(RealDecl)) {
-// Pure-specifiers are handled in ActOnPureSpecifier.
-Diag(Method->getLocation(), diag::err_member_function_initialization)
-  << Method->getDeclName() << Init->getSourceRange();
-Method->setInvalidDecl();
+if (!Method->isInvalidDecl()) {
+  // Pure-specifiers are handled in ActOnPureSpecifier.
+  Diag(Method->getLocation(), diag::err_member_function_initialization)
+<< Method->getDeclName() << Init->getSourceRange();
+  Method->setInvalidDecl();
+}
 return;
   }
 
@@ -13456,6 +13458,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
 return;
   }
 
+  if (VDecl->isInvalidDecl()) {
+CorrectDelayedTyposInExpr(Init, VDecl);
+ExprResult Recovery =
+CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), {Init});
+if (Expr *E = Recovery.get())
+  VDecl->setInit(E);
+return;
+  }
+
   // WebAssembly tables can't be used to initialise a variable.
   if (Init && !Init->getType().isNull() &&
   Init->getType()->isWebAssemblyTableType()) {
diff --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index cfb013585ad744..77527743fe8577 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -413,6 +413,14 @@ void RecoveryExprForInvalidDecls(Unknown InvalidDecl) {
   // CHECK-NEXT: `-RecoveryExpr {{.*}} ''
 }
 
+void InitializerOfInvalidDecl() {
+  int ValidDecl;
+  Unkown InvalidDecl = ValidDecl;
+  // CHECK:  VarDecl {{.*}} invalid InvalidDecl
+  // CHECK-NEXT: `-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'ValidDecl'
+}
+
 void RecoverToAnInvalidDecl() {
   Unknown* foo; // invalid decl
   goo; // the typo was correct to the invalid foo.

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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

2024-04-15 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> I added a new test case. However, the patch currently fails two existing test 
> cases:
> 
> Clang :: Parser/cxx-class.cpp
> Clang :: SemaCXX/cxx1z-init-statement.cpp
> 
> I will leave the PR as a Draft while I investigate these failures.

The latest version of the patch fixes these failures.

I'm slightly uncertain about the change to `JumpDiagnostics.cpp`, whose purpose 
is to fix the `cxx1z-init-statement.cpp` test failure. 

The affected code looks like this:

```c++
  switch (int x, y = 0; y) { // expected-note 2 {{previous definition is here}}
case 0:
  int x = 0; // expected-error {{redefinition of 'x'}}
case 1:
  int y = 0; // expected-error {{redefinition of 'y'}}
  }
```

and without the `JumpDiagnostics.cpp` change, we get an extra diagnostic:

```
error: cannot jump from switch statement to this case label
5 | case 1:
  | ^
note: jump bypasses variable initialization
4 |   int x = 0; // expected-error {{redefinition of 'x'}}
  |
```

but maybe that's actually fine and we should just update the test to expect 
this diagnostic instead?

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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

2024-04-15 Thread Nathan Ridge via cfe-commits

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


[clang-tools-extra] [clang-tidy] Ignore deleted ctor in `bugprone-forwarding-reference-overload` (PR #88138)

2024-04-15 Thread Mike Weller via cfe-commits

https://github.com/MikeWeller updated 
https://github.com/llvm/llvm-project/pull/88138

>From 483bd05ec3c0575ed6771ef093368d6be19f5d3f Mon Sep 17 00:00:00 2001
From: Mike Weller 
Date: Tue, 9 Apr 2024 16:03:31 +0100
Subject: [PATCH] [clang-tidy] Ignore delete ctor in
 `bugprone-forwarding-reference-overload`

Fix `bugprone-forwarding-reference-overload` so it doesn't report a constructor 
that is deleted.
---
 .../bugprone/ForwardingReferenceOverloadCheck.cpp  |  1 +
 clang-tools-extra/docs/ReleaseNotes.rst|  1 +
 .../bugprone/forwarding-reference-overload.cpp | 10 ++
 3 files changed, 12 insertions(+)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index c608fe713f9f5b..e42b40d7b6690e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -73,6 +73,7 @@ void 
ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
   DeclarationMatcher FindOverload =
   cxxConstructorDecl(
   hasParameter(0, ForwardingRefParm),
+  unless(isDeleted()),
   unless(hasAnyParameter(
   // No warning: enable_if as constructor parameter.
   parmVarDecl(hasType(isEnableIf(),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1405fb0df1f8dd..4e4dd35242478f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -102,6 +102,7 @@ Improvements to clang-tidy
   similar fashion to what `-header-filter` does for header files.
 - Improved :program:`check_clang_tidy.py` script. Added argument 
`-export-fixes`
   to aid in clang-tidy and test development.
+- Fixed an issue with `bugprone-forwarding-reference-overload` where it would 
incorrectly flag deleted constructors
 
 New checks
 ^^
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
index 38b0691bc9f1ec..92dfb718bb51b7 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
@@ -251,3 +251,13 @@ class Test10 {
   Test10(T &&Item, E e)
   : e(e){}
 };
+
+// A deleted ctor cannot hide anything
+class Test11 {
+public:
+  template 
+  Test11(T&&) = delete;
+
+  Test11(const Test11 &) = default;
+  Test11(Test11 &&) = default;
+};

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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

2024-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)


Changes

Fixes https://github.com/clangd/clangd/issues/1821

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


3 Files Affected:

- (modified) clang/lib/Sema/JumpDiagnostics.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+16-5) 
- (modified) clang/test/AST/ast-dump-recovery.cpp (+8) 


``diff
diff --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index ec3892e92f3c3b..27d5284fdb67e7 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -179,7 +179,8 @@ static ScopePair GetDiagForGotoScopeDecl(Sema &S, const 
Decl *D) {
 }
 
 const Expr *Init = VD->getInit();
-if (S.Context.getLangOpts().CPlusPlus && VD->hasLocalStorage() && Init) {
+if (S.Context.getLangOpts().CPlusPlus && VD->hasLocalStorage() && Init &&
+!Init->containsErrors()) {
   // C++11 [stmt.dcl]p3:
   //   A program that jumps from a point where a variable with automatic
   //   storage duration is not in scope to a point where it is in scope
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9fdd8eb236d1ee..6075624722b1cc 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13435,16 +13435,18 @@ void Sema::checkNonTrivialCUnion(QualType QT, 
SourceLocation Loc,
 void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
   // If there is no declaration, there was an error parsing it.  Just ignore
   // the initializer.
-  if (!RealDecl || RealDecl->isInvalidDecl()) {
+  if (!RealDecl) {
 CorrectDelayedTyposInExpr(Init, dyn_cast_or_null(RealDecl));
 return;
   }
 
   if (CXXMethodDecl *Method = dyn_cast(RealDecl)) {
-// Pure-specifiers are handled in ActOnPureSpecifier.
-Diag(Method->getLocation(), diag::err_member_function_initialization)
-  << Method->getDeclName() << Init->getSourceRange();
-Method->setInvalidDecl();
+if (!Method->isInvalidDecl()) {
+  // Pure-specifiers are handled in ActOnPureSpecifier.
+  Diag(Method->getLocation(), diag::err_member_function_initialization)
+<< Method->getDeclName() << Init->getSourceRange();
+  Method->setInvalidDecl();
+}
 return;
   }
 
@@ -13456,6 +13458,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
 return;
   }
 
+  if (VDecl->isInvalidDecl()) {
+CorrectDelayedTyposInExpr(Init, VDecl);
+ExprResult Recovery =
+CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), {Init});
+if (Expr *E = Recovery.get())
+  VDecl->setInit(E);
+return;
+  }
+
   // WebAssembly tables can't be used to initialise a variable.
   if (Init && !Init->getType().isNull() &&
   Init->getType()->isWebAssemblyTableType()) {
diff --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index cfb013585ad744..77527743fe8577 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -413,6 +413,14 @@ void RecoveryExprForInvalidDecls(Unknown InvalidDecl) {
   // CHECK-NEXT: `-RecoveryExpr {{.*}} ''
 }
 
+void InitializerOfInvalidDecl() {
+  int ValidDecl;
+  Unkown InvalidDecl = ValidDecl;
+  // CHECK:  VarDecl {{.*}} invalid InvalidDecl
+  // CHECK-NEXT: `-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'ValidDecl'
+}
+
 void RecoverToAnInvalidDecl() {
   Unknown* foo; // invalid decl
   goo; // the typo was correct to the invalid foo.

``




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


[clang-tools-extra] [clang-tidy] Ignore deleted ctor in `bugprone-forwarding-reference-overload` (PR #88138)

2024-04-15 Thread Mike Weller via cfe-commits

MikeWeller wrote:

Given the small size of the change I just did a rebase and force push to 
resolve conflicts with the release notes.

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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

2024-04-15 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 9617da88ab961145047076c45bb2bb1ac4513634 
07424d8ee99fc418d071960bbdd4185564025139 -- clang/lib/Sema/JumpDiagnostics.cpp 
clang/lib/Sema/SemaDecl.cpp clang/test/AST/ast-dump-recovery.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6075624722..e802d41ddc 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13444,7 +13444,7 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
 if (!Method->isInvalidDecl()) {
   // Pure-specifiers are handled in ActOnPureSpecifier.
   Diag(Method->getLocation(), diag::err_member_function_initialization)
-<< Method->getDeclName() << Init->getSourceRange();
+  << Method->getDeclName() << Init->getSourceRange();
   Method->setInvalidDecl();
 }
 return;

``




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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

2024-04-15 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/88645

>From b43d8ddf8846db8a77d01c9fb2d246a0d0ba2ab2 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Sun, 14 Apr 2024 02:41:48 -0400
Subject: [PATCH] [clang][Sema] Preserve the initializer of invalid VarDecls

Fixes https://github.com/clangd/clangd/issues/1821
---
 clang/lib/Sema/JumpDiagnostics.cpp   |  3 ++-
 clang/lib/Sema/SemaDecl.cpp  | 21 -
 clang/test/AST/ast-dump-recovery.cpp |  8 
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index ec3892e92f3c3b..27d5284fdb67e7 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -179,7 +179,8 @@ static ScopePair GetDiagForGotoScopeDecl(Sema &S, const 
Decl *D) {
 }
 
 const Expr *Init = VD->getInit();
-if (S.Context.getLangOpts().CPlusPlus && VD->hasLocalStorage() && Init) {
+if (S.Context.getLangOpts().CPlusPlus && VD->hasLocalStorage() && Init &&
+!Init->containsErrors()) {
   // C++11 [stmt.dcl]p3:
   //   A program that jumps from a point where a variable with automatic
   //   storage duration is not in scope to a point where it is in scope
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9fdd8eb236d1ee..e802d41ddc1c47 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13435,16 +13435,18 @@ void Sema::checkNonTrivialCUnion(QualType QT, 
SourceLocation Loc,
 void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
   // If there is no declaration, there was an error parsing it.  Just ignore
   // the initializer.
-  if (!RealDecl || RealDecl->isInvalidDecl()) {
+  if (!RealDecl) {
 CorrectDelayedTyposInExpr(Init, dyn_cast_or_null(RealDecl));
 return;
   }
 
   if (CXXMethodDecl *Method = dyn_cast(RealDecl)) {
-// Pure-specifiers are handled in ActOnPureSpecifier.
-Diag(Method->getLocation(), diag::err_member_function_initialization)
-  << Method->getDeclName() << Init->getSourceRange();
-Method->setInvalidDecl();
+if (!Method->isInvalidDecl()) {
+  // Pure-specifiers are handled in ActOnPureSpecifier.
+  Diag(Method->getLocation(), diag::err_member_function_initialization)
+  << Method->getDeclName() << Init->getSourceRange();
+  Method->setInvalidDecl();
+}
 return;
   }
 
@@ -13456,6 +13458,15 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
 return;
   }
 
+  if (VDecl->isInvalidDecl()) {
+CorrectDelayedTyposInExpr(Init, VDecl);
+ExprResult Recovery =
+CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), {Init});
+if (Expr *E = Recovery.get())
+  VDecl->setInit(E);
+return;
+  }
+
   // WebAssembly tables can't be used to initialise a variable.
   if (Init && !Init->getType().isNull() &&
   Init->getType()->isWebAssemblyTableType()) {
diff --git a/clang/test/AST/ast-dump-recovery.cpp 
b/clang/test/AST/ast-dump-recovery.cpp
index cfb013585ad744..77527743fe8577 100644
--- a/clang/test/AST/ast-dump-recovery.cpp
+++ b/clang/test/AST/ast-dump-recovery.cpp
@@ -413,6 +413,14 @@ void RecoveryExprForInvalidDecls(Unknown InvalidDecl) {
   // CHECK-NEXT: `-RecoveryExpr {{.*}} ''
 }
 
+void InitializerOfInvalidDecl() {
+  int ValidDecl;
+  Unkown InvalidDecl = ValidDecl;
+  // CHECK:  VarDecl {{.*}} invalid InvalidDecl
+  // CHECK-NEXT: `-RecoveryExpr {{.*}} '' contains-errors
+  // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'int' lvalue Var {{.*}} 'ValidDecl'
+}
+
 void RecoverToAnInvalidDecl() {
   Unknown* foo; // invalid decl
   goo; // the typo was correct to the invalid foo.

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


[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

2024-04-15 Thread Timm Baeder via cfe-commits


@@ -423,6 +423,10 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now allowed the value of unroll count to be zero in ``#pragma GCC 
unroll`` and ``#pragma unroll``.

tbaederr wrote:

```suggestion
- Clang now allows the value of unroll count to be zero in ``#pragma GCC 
unroll`` and ``#pragma unroll``.
```

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/86912

>From 8e07cbdd0f348484d532d7827e4b4a7888e70978 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 18 Mar 2024 08:36:55 +0800
Subject: [PATCH 1/2] [Modules] No transitive source location change

---
 clang/include/clang/Basic/SourceLocation.h|  1 +
 .../include/clang/Serialization/ASTBitCodes.h | 56 ++--
 clang/include/clang/Serialization/ASTReader.h | 54 +++-
 clang/include/clang/Serialization/ASTWriter.h |  4 +
 .../include/clang/Serialization/ModuleFile.h  |  4 -
 .../Serialization/SourceLocationEncoding.h| 88 +--
 clang/lib/Frontend/ASTUnit.cpp|  2 -
 clang/lib/Serialization/ASTReader.cpp | 84 +++---
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 clang/lib/Serialization/ASTWriter.cpp | 41 +++--
 clang/lib/Serialization/ASTWriterDecl.cpp |  8 +-
 clang/lib/Serialization/ModuleFile.cpp|  1 -
 .../no-transitive-source-location-change.cppm | 69 +++
 clang/test/Modules/pr61067.cppm   | 25 --
 .../SourceLocationEncodingTest.cpp| 12 +--
 15 files changed, 275 insertions(+), 176 deletions(-)
 create mode 100644 clang/test/Modules/no-transitive-source-location-change.cppm

diff --git a/clang/include/clang/Basic/SourceLocation.h 
b/clang/include/clang/Basic/SourceLocation.h
index 00b1e0fa855b7a..7a0f5ba8d1270b 100644
--- a/clang/include/clang/Basic/SourceLocation.h
+++ b/clang/include/clang/Basic/SourceLocation.h
@@ -90,6 +90,7 @@ class SourceLocation {
   friend class ASTWriter;
   friend class SourceManager;
   friend struct llvm::FoldingSetTrait;
+  friend class SourceLocationEncoding;
 
 public:
   using UIntTy = uint32_t;
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index f762116fea956c..f94b32d762effc 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Serialization/SourceLocationEncoding.h"
 #include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/Bitstream/BitCodes.h"
 #include 
@@ -175,45 +176,38 @@ const unsigned int NUM_PREDEF_SUBMODULE_IDS = 1;
 
 /// Source range/offset of a preprocessed entity.
 struct PPEntityOffset {
+  using RawLocEncoding = SourceLocationEncoding::RawLocEncoding;
+
   /// Raw source location of beginning of range.
-  SourceLocation::UIntTy Begin;
+  RawLocEncoding Begin;
 
   /// Raw source location of end of range.
-  SourceLocation::UIntTy End;
+  RawLocEncoding End;
 
   /// Offset in the AST file relative to ModuleFile::MacroOffsetsBase.
   uint32_t BitOffset;
 
-  PPEntityOffset(SourceRange R, uint32_t BitOffset)
-  : Begin(R.getBegin().getRawEncoding()), End(R.getEnd().getRawEncoding()),
-BitOffset(BitOffset) {}
-
-  SourceLocation getBegin() const {
-return SourceLocation::getFromRawEncoding(Begin);
-  }
+  PPEntityOffset(RawLocEncoding Begin, RawLocEncoding End, uint32_t BitOffset)
+  : Begin(Begin), End(End), BitOffset(BitOffset) {}
 
-  SourceLocation getEnd() const {
-return SourceLocation::getFromRawEncoding(End);
-  }
+  RawLocEncoding getBegin() const { return Begin; }
+  RawLocEncoding getEnd() const { return End; }
 };
 
 /// Source range of a skipped preprocessor region
 struct PPSkippedRange {
+  using RawLocEncoding = SourceLocationEncoding::RawLocEncoding;
+
   /// Raw source location of beginning of range.
-  SourceLocation::UIntTy Begin;
+  RawLocEncoding Begin;
   /// Raw source location of end of range.
-  SourceLocation::UIntTy End;
+  RawLocEncoding End;
 
-  PPSkippedRange(SourceRange R)
-  : Begin(R.getBegin().getRawEncoding()), End(R.getEnd().getRawEncoding()) 
{
-  }
+  PPSkippedRange(RawLocEncoding Begin, RawLocEncoding End)
+  : Begin(Begin), End(End) {}
 
-  SourceLocation getBegin() const {
-return SourceLocation::getFromRawEncoding(Begin);
-  }
-  SourceLocation getEnd() const {
-return SourceLocation::getFromRawEncoding(End);
-  }
+  RawLocEncoding getBegin() const { return Begin; }
+  RawLocEncoding getEnd() const { return End; }
 };
 
 /// Offset in the AST file. Use splitted 64-bit integer into low/high
@@ -239,8 +233,10 @@ struct UnderalignedInt64 {
 
 /// Source location and bit offset of a declaration.
 struct DeclOffset {
+  using RawLocEncoding = SourceLocationEncoding::RawLocEncoding;
+
   /// Raw source location.
-  SourceLocation::UIntTy Loc = 0;
+  RawLocEncoding RawLoc = 0;
 
   /// Offset relative to the start of the DECLTYPES_BLOCK block. Keep
   /// structure alignment 32-bit and avoid padding gap because undefined
@@ -248,17 +244,15 @@ struct DeclOffset {
   UnderalignedInt64 BitOffset;
 
   DeclOffset() = default;
-  DeclOffset(SourceLocation Loc, uint64_t BitOffset,
- 

[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -149,14 +157,44 @@ class SourceLocationSequence::State {
   operator SourceLocationSequence *() { return &Seq; }
 };
 
-inline uint64_t SourceLocationEncoding::encode(SourceLocation Loc,
-   SourceLocationSequence *Seq) {
-  return Seq ? Seq->encode(Loc) : encodeRaw(Loc.getRawEncoding());
+inline SourceLocationEncoding::RawLocEncoding
+SourceLocationEncoding::encode(SourceLocation Loc, UIntTy BaseOffset,
+   unsigned BaseModuleFileIndex,
+   SourceLocationSequence *Seq) {
+  // If the source location is a local source location, we can try to optimize
+  // the similar sequences to only record the differences.
+  if (!BaseOffset)
+return Seq ? Seq->encode(Loc) : encodeRaw(Loc.getRawEncoding());
+
+  if (Loc.isInvalid())
+return 0;
+  
+  // Otherwise, the higher bits are used to store the module file index,
+  // so it is meaningless to optimize the source locations into small
+  // integers. Let's try to always use the raw encodings.
+  assert(Loc.getOffset() >= BaseOffset);
+  Loc = Loc.getLocWithOffset(-BaseOffset);
+  RawLocEncoding Encoded = encodeRaw(Loc.getRawEncoding());
+  assert(Encoded < ((RawLocEncoding)1 << 32));

ChuanqiXu9 wrote:

I guess you may refer to the next line and that one is indeed comparing 
unsigned with `(1<<32)`, and I fixed that. This line should be fine since 
Encoded has type `RawLocEncoding `.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -942,6 +942,12 @@ class ASTReader
   /// Sema tracks these to emit deferred diags.
   llvm::SmallSetVector DeclsToCheckForDeferredDiags;
 
+  /// The module files imported by different module files. Indirectly imported
+  /// module files are included too. The information comes from
+  /// ReadModuleOffsetMap(ModuleFile&).
+  mutable llvm::DenseMap>
+  ImportedModuleFiles;

ChuanqiXu9 wrote:

Done in the new commit.

There was a similar member `Imports` in `ModuleFile`, which records the 
directly imported module files from the coding. But, yes, it is good to remove 
the map lookups and let's try to handle the ambiguous by commenting.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -5574,10 +5577,34 @@ void ASTWriter::AddFileID(FileID FID, RecordDataImpl 
&Record) {
   Record.push_back(getAdjustedFileID(FID).getOpaqueValue());
 }
 
+SourceLocationEncoding::RawLocEncoding
+ASTWriter::getRawSourceLocationEncoding(SourceLocation Loc, LocSeq *Seq) {
+  unsigned BaseOffset = 0;
+  unsigned ModuleFileIndex = 0;
+
+  // See SourceLocationEncoding.h for the encoding details.
+  if (Context->getSourceManager().isLoadedSourceLocation(Loc) &&
+  Loc.isValid()) {
+assert(getChain());
+auto SLocMapI = getChain()->GlobalSLocOffsetMap.find(
+SourceManager::MaxLoadedOffset - Loc.getOffset() - 1);
+assert(SLocMapI != getChain()->GlobalSLocOffsetMap.end() &&
+   "Corrupted global sloc offset map");
+ModuleFile *F = SLocMapI->second;
+BaseOffset = F->SLocEntryBaseOffset - 2;
+// 0 means the location is not loaded. So we need to add 1 to the index to
+// make it clear.
+ModuleFileIndex = F->Index + 1;
+assert(&getChain()->getModuleManager()[F->Index] == F);

ChuanqiXu9 wrote:

Yes but I'd like to remain it. The assertions make me feel better.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -2220,40 +2227,47 @@ class ASTReader
 return Sema::AlignPackInfo::getFromRawEncoding(Raw);
   }
 
+  using RawLocEncoding = SourceLocationEncoding::RawLocEncoding;
+
   /// Read a source location from raw form and return it in its
   /// originating module file's source location space.
-  SourceLocation ReadUntranslatedSourceLocation(SourceLocation::UIntTy Raw,
-LocSeq *Seq = nullptr) const {
+  std::pair
+  ReadUntranslatedSourceLocation(RawLocEncoding Raw,
+ LocSeq *Seq = nullptr) const {
 return SourceLocationEncoding::decode(Raw, Seq);
   }
 
   /// Read a source location from raw form.
-  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
-SourceLocation::UIntTy Raw,
-LocSeq *Seq = nullptr) const {
-SourceLocation Loc = ReadUntranslatedSourceLocation(Raw, Seq);
-return TranslateSourceLocation(ModuleFile, Loc);
+  SourceLocation ReadRawSourceLocation(ModuleFile &MF, RawLocEncoding Raw,

ChuanqiXu9 wrote:

Done.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -696,7 +696,7 @@ class ASTReader
   /// Mapping from global submodule IDs to the module file in which the
   /// submodule resides along with the offset that should be added to the
   /// global submodule ID to produce a local ID.
-  GlobalSubmoduleMapType GlobalSubmoduleMap;
+  mutable GlobalSubmoduleMapType GlobalSubmoduleMap;

ChuanqiXu9 wrote:

Oh, I don't know why it remains. Maybe I added during the work progress.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -149,14 +157,44 @@ class SourceLocationSequence::State {
   operator SourceLocationSequence *() { return &Seq; }
 };
 
-inline uint64_t SourceLocationEncoding::encode(SourceLocation Loc,
-   SourceLocationSequence *Seq) {
-  return Seq ? Seq->encode(Loc) : encodeRaw(Loc.getRawEncoding());
+inline SourceLocationEncoding::RawLocEncoding
+SourceLocationEncoding::encode(SourceLocation Loc, UIntTy BaseOffset,
+   unsigned BaseModuleFileIndex,
+   SourceLocationSequence *Seq) {
+  // If the source location is a local source location, we can try to optimize
+  // the similar sequences to only record the differences.
+  if (!BaseOffset)
+return Seq ? Seq->encode(Loc) : encodeRaw(Loc.getRawEncoding());
+
+  if (Loc.isInvalid())
+return 0;
+  
+  // Otherwise, the higher bits are used to store the module file index,
+  // so it is meaningless to optimize the source locations into small
+  // integers. Let's try to always use the raw encodings.
+  assert(Loc.getOffset() >= BaseOffset);
+  Loc = Loc.getLocWithOffset(-BaseOffset);
+  RawLocEncoding Encoded = encodeRaw(Loc.getRawEncoding());
+  assert(Encoded < ((RawLocEncoding)1 << 32));
+
+  assert(BaseModuleFileIndex < ((RawLocEncoding)1 << 32));
+  Encoded |= (RawLocEncoding)BaseModuleFileIndex << 32;

ChuanqiXu9 wrote:

Now I assert it should be less than `(1<<16)`

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


[clang] [clang-tools-extra] [clang analysis] ExprMutationAnalyzer avoid infinite recursion for recursive forwarding reference (PR #87954)

2024-04-15 Thread Congcong Cai via cfe-commits

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

>From 19f66851204547232d586288fba79d8770837350 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 8 Apr 2024 09:20:58 +0800
Subject: [PATCH 1/4] [clang analysis] ExprMutationAnalyzer support recursive
 forwarding reference

Partialy fixes: #60895
---
 .../Analysis/Analyses/ExprMutationAnalyzer.h  | 40 +++
 clang/lib/Analysis/ExprMutationAnalyzer.cpp   | 22 ++
 .../Analysis/ExprMutationAnalyzerTest.cpp | 30 ++
 3 files changed, 77 insertions(+), 15 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h 
b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
index 1ceef944fbc34e..af6106fe303afd 100644
--- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -8,11 +8,10 @@
 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_EXPRMUTATIONANALYZER_H
 #define LLVM_CLANG_ANALYSIS_ANALYSES_EXPRMUTATIONANALYZER_H
 
-#include 
-
 #include "clang/AST/AST.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "llvm/ADT/DenseMap.h"
+#include 
 
 namespace clang {
 
@@ -22,8 +21,15 @@ class FunctionParmMutationAnalyzer;
 /// a given statement.
 class ExprMutationAnalyzer {
 public:
+  friend class FunctionParmMutationAnalyzer;
+  struct Cache {
+llvm::DenseMap>
+FuncParmAnalyzer;
+  };
+
   ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context)
-  : Stm(Stm), Context(Context) {}
+  : ExprMutationAnalyzer(Stm, Context, nullptr) {}
 
   bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; }
   bool isMutated(const Decl *Dec) { return findMutation(Dec) != nullptr; }
@@ -45,6 +51,19 @@ class ExprMutationAnalyzer {
   using MutationFinder = const Stmt *(ExprMutationAnalyzer::*)(const Expr *);
   using ResultMap = llvm::DenseMap;
 
+  ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context, Cache 
*ParentCache)
+  : Stm(Stm), Context(Context) {
+if (ParentCache != nullptr) {
+  CrossAnalysisCache = ParentCache;
+} else {
+  CrossAnalysisCache = std::make_unique();
+}
+  }
+  ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context,
+   std::unique_ptr CrossAnalysisCache)
+  : Stm(Stm), Context(Context),
+CrossAnalysisCache(std::move(CrossAnalysisCache)) {}
+
   const Stmt *findMutationMemoized(const Expr *Exp,
llvm::ArrayRef Finders,
ResultMap &MemoizedResults);
@@ -67,11 +86,15 @@ class ExprMutationAnalyzer {
   const Stmt *findReferenceMutation(const Expr *Exp);
   const Stmt *findFunctionArgMutation(const Expr *Exp);
 
+  Cache *getCache() {
+return std::holds_alternative(CrossAnalysisCache)
+   ? std::get(CrossAnalysisCache)
+   : std::get>(CrossAnalysisCache).get();
+  }
+
   const Stmt &Stm;
   ASTContext &Context;
-  llvm::DenseMap>
-  FuncParmAnalyzer;
+  std::variant> CrossAnalysisCache;
   ResultMap Results;
   ResultMap PointeeResults;
 };
@@ -80,7 +103,10 @@ class ExprMutationAnalyzer {
 // params.
 class FunctionParmMutationAnalyzer {
 public:
-  FunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext &Context);
+  FunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext &Context)
+  : FunctionParmMutationAnalyzer(Func, Context, nullptr) {}
+  FunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext &Context,
+   ExprMutationAnalyzer::Cache 
*CrossAnalysisCache);
 
   bool isMutated(const ParmVarDecl *Parm) {
 return findMutation(Parm) != nullptr;
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index bb042760d297a7..dba6f2a3c02112 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -638,9 +638,10 @@ const Stmt 
*ExprMutationAnalyzer::findFunctionArgMutation(const Expr *Exp) {
   if (!RefType->getPointeeType().getQualifiers() &&
   RefType->getPointeeType()->getAs()) {
 std::unique_ptr &Analyzer =
-FuncParmAnalyzer[Func];
+getCache()->FuncParmAnalyzer[Func];
 if (!Analyzer)
-  Analyzer.reset(new FunctionParmMutationAnalyzer(*Func, Context));
+  Analyzer.reset(
+  new FunctionParmMutationAnalyzer(*Func, Context, getCache()));
 if (Analyzer->findMutation(Parm))
   return Exp;
 continue;
@@ -653,13 +654,15 @@ const Stmt 
*ExprMutationAnalyzer::findFunctionArgMutation(const Expr *Exp) {
 }
 
 FunctionParmMutationAnalyzer::FunctionParmMutationAnalyzer(
-const FunctionDecl &Func, ASTContext &Context)
-: BodyAnalyzer(*Func.getBody(), Context) {
+const FunctionDecl &Func, ASTContext &Context,
+ExprMutationAnalyzer::Cache *CrossAnalysisCache)
+: BodyAnalyzer(*Func.getBody(), Context, Cro

[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -149,14 +157,44 @@ class SourceLocationSequence::State {
   operator SourceLocationSequence *() { return &Seq; }
 };
 
-inline uint64_t SourceLocationEncoding::encode(SourceLocation Loc,
-   SourceLocationSequence *Seq) {
-  return Seq ? Seq->encode(Loc) : encodeRaw(Loc.getRawEncoding());
+inline SourceLocationEncoding::RawLocEncoding
+SourceLocationEncoding::encode(SourceLocation Loc, UIntTy BaseOffset,
+   unsigned BaseModuleFileIndex,
+   SourceLocationSequence *Seq) {
+  // If the source location is a local source location, we can try to optimize
+  // the similar sequences to only record the differences.
+  if (!BaseOffset)
+return Seq ? Seq->encode(Loc) : encodeRaw(Loc.getRawEncoding());
+
+  if (Loc.isInvalid())
+return 0;
+  
+  // Otherwise, the higher bits are used to store the module file index,
+  // so it is meaningless to optimize the source locations into small
+  // integers. Let's try to always use the raw encodings.
+  assert(Loc.getOffset() >= BaseOffset);
+  Loc = Loc.getLocWithOffset(-BaseOffset);
+  RawLocEncoding Encoded = encodeRaw(Loc.getRawEncoding());
+  assert(Encoded < ((RawLocEncoding)1 << 32));
+
+  assert(BaseModuleFileIndex < ((RawLocEncoding)1 << 32));
+  Encoded |= (RawLocEncoding)BaseModuleFileIndex << 32;
+  return Encoded;
 }
-inline SourceLocation
-SourceLocationEncoding::decode(uint64_t Encoded, SourceLocationSequence *Seq) {
-  return Seq ? Seq->decode(Encoded)
- : SourceLocation::getFromRawEncoding(decodeRaw(Encoded));
+inline std::pair
+SourceLocationEncoding::decode(RawLocEncoding Encoded,
+   SourceLocationSequence *Seq) {
+  unsigned ModuleFileIndex = Encoded >> 32;
+
+  if (!ModuleFileIndex)
+return {Seq ? Seq->decode(Encoded)
+ : SourceLocation::getFromRawEncoding(decodeRaw(Encoded)),
+ModuleFileIndex};
+
+  Encoded &= ((RawLocEncoding)1 << 33) - 1;

ChuanqiXu9 wrote:

Done.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -2220,40 +2227,47 @@ class ASTReader
 return Sema::AlignPackInfo::getFromRawEncoding(Raw);
   }
 
+  using RawLocEncoding = SourceLocationEncoding::RawLocEncoding;
+
   /// Read a source location from raw form and return it in its
   /// originating module file's source location space.
-  SourceLocation ReadUntranslatedSourceLocation(SourceLocation::UIntTy Raw,
-LocSeq *Seq = nullptr) const {
+  std::pair
+  ReadUntranslatedSourceLocation(RawLocEncoding Raw,
+ LocSeq *Seq = nullptr) const {
 return SourceLocationEncoding::decode(Raw, Seq);
   }
 
   /// Read a source location from raw form.
-  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
-SourceLocation::UIntTy Raw,
-LocSeq *Seq = nullptr) const {
-SourceLocation Loc = ReadUntranslatedSourceLocation(Raw, Seq);
-return TranslateSourceLocation(ModuleFile, Loc);
+  SourceLocation ReadRawSourceLocation(ModuleFile &MF, RawLocEncoding Raw,
+   LocSeq *Seq = nullptr) const {
+if (!MF.ModuleOffsetMap.empty())
+  ReadModuleOffsetMap(MF);
+
+auto [Loc, ModuleFileIndex] = ReadUntranslatedSourceLocation(Raw, Seq);
+ModuleFile *ModuleFileHomingLoc =

ChuanqiXu9 wrote:

Done.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -4078,8 +4065,8 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const {
   return;

ChuanqiXu9 wrote:

Done.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -2220,40 +2227,47 @@ class ASTReader
 return Sema::AlignPackInfo::getFromRawEncoding(Raw);
   }
 
+  using RawLocEncoding = SourceLocationEncoding::RawLocEncoding;
+
   /// Read a source location from raw form and return it in its
   /// originating module file's source location space.
-  SourceLocation ReadUntranslatedSourceLocation(SourceLocation::UIntTy Raw,
-LocSeq *Seq = nullptr) const {
+  std::pair
+  ReadUntranslatedSourceLocation(RawLocEncoding Raw,
+ LocSeq *Seq = nullptr) const {
 return SourceLocationEncoding::decode(Raw, Seq);
   }
 
   /// Read a source location from raw form.
-  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
-SourceLocation::UIntTy Raw,
-LocSeq *Seq = nullptr) const {
-SourceLocation Loc = ReadUntranslatedSourceLocation(Raw, Seq);
-return TranslateSourceLocation(ModuleFile, Loc);
+  SourceLocation ReadRawSourceLocation(ModuleFile &MF, RawLocEncoding Raw,
+   LocSeq *Seq = nullptr) const {
+if (!MF.ModuleOffsetMap.empty())
+  ReadModuleOffsetMap(MF);
+
+auto [Loc, ModuleFileIndex] = ReadUntranslatedSourceLocation(Raw, Seq);
+ModuleFile *ModuleFileHomingLoc =
+ModuleFileIndex ? ImportedModuleFiles[&MF][ModuleFileIndex - 1] : &MF;

ChuanqiXu9 wrote:

We have a bounds check in the `operator[]` of SmallVector. So I guess it may be 
fine.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits


@@ -2220,40 +2227,47 @@ class ASTReader
 return Sema::AlignPackInfo::getFromRawEncoding(Raw);
   }
 
+  using RawLocEncoding = SourceLocationEncoding::RawLocEncoding;
+
   /// Read a source location from raw form and return it in its
   /// originating module file's source location space.
-  SourceLocation ReadUntranslatedSourceLocation(SourceLocation::UIntTy Raw,
-LocSeq *Seq = nullptr) const {
+  std::pair
+  ReadUntranslatedSourceLocation(RawLocEncoding Raw,
+ LocSeq *Seq = nullptr) const {
 return SourceLocationEncoding::decode(Raw, Seq);
   }
 
   /// Read a source location from raw form.
-  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
-SourceLocation::UIntTy Raw,
-LocSeq *Seq = nullptr) const {
-SourceLocation Loc = ReadUntranslatedSourceLocation(Raw, Seq);
-return TranslateSourceLocation(ModuleFile, Loc);
+  SourceLocation ReadRawSourceLocation(ModuleFile &MF, RawLocEncoding Raw,
+   LocSeq *Seq = nullptr) const {
+if (!MF.ModuleOffsetMap.empty())
+  ReadModuleOffsetMap(MF);
+
+auto [Loc, ModuleFileIndex] = ReadUntranslatedSourceLocation(Raw, Seq);
+ModuleFile *ModuleFileHomingLoc =
+ModuleFileIndex ? ImportedModuleFiles[&MF][ModuleFileIndex - 1] : &MF;
+return TranslateSourceLocation(*ModuleFileHomingLoc, Loc);
   }
 
   /// Translate a source location from another module file's source
   /// location space into ours.
   SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile,
  SourceLocation Loc) const {
-if (!ModuleFile.ModuleOffsetMap.empty())
-  ReadModuleOffsetMap(ModuleFile);
-assert(ModuleFile.SLocRemap.find(Loc.getOffset()) !=
-   ModuleFile.SLocRemap.end() &&
-   "Cannot find offset to remap.");
-SourceLocation::IntTy Remap =
-ModuleFile.SLocRemap.find(Loc.getOffset())->second;
-return Loc.getLocWithOffset(Remap);
+if (Loc.isInvalid())
+  return Loc;
+
+// It implies that the Loc is already translated.
+if (SourceMgr.isLoadedSourceLocation(Loc))
+  return Loc;
+
+return Loc.getLocWithOffset(ModuleFile.SLocEntryBaseOffset - 2);

ChuanqiXu9 wrote:

There are a lot `- 2` in Serialization and SourceManager. I just tried to 
follow that. Sadly I didn't find clear comments explaining this. By reading the 
codes, I think it is trying to skip 2 dummy SLocEntries (the invalid source 
location and invalid expansion location, see `SourceManager::clearIDTables()`) 
since they are not sensitive to the context.

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


[clang] [Modules] No transitive source location change (PR #86912)

2024-04-15 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> I have a few minor comments on the patch. I want to do some additional perf 
> testing on module scanning perf because I'm a bit concerned about the cost of 
> `ASTWriter::getRawSourceLocationEncoding`.

What's the perf results about scanning?

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


[clang-tools-extra] [clang-tidy][NFC] Fix `linuxkernel-must-check-errs` documentation file name (PR #88655)

2024-04-15 Thread Piotr Zegar via cfe-commits


@@ -299,6 +299,10 @@ Miscellaneous
   ``--format`` option is specified. Now :program:`clang-apply-replacements`
   applies formatting only with the option.
 
+- Fixed the :doc:`linuxkernel-must-check-errs
+  ` documentation to 
consistently
+  use the check's proper name.

PiotrZSL wrote:

And none one cared. If you really like to keep it then fine, I'm not pushing 
but usually in change notes we got only changes in checks behaviour.

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


[clang-tools-extra] [clang-tidy] Ignore deleted ctor in `bugprone-forwarding-reference-overload` (PR #88138)

2024-04-15 Thread Piotr Zegar via cfe-commits


@@ -102,6 +102,7 @@ Improvements to clang-tidy
   similar fashion to what `-header-filter` does for header files.
 - Improved :program:`check_clang_tidy.py` script. Added argument 
`-export-fixes`
   to aid in clang-tidy and test development.
+- Fixed an issue with `bugprone-forwarding-reference-overload` where it would 
incorrectly flag deleted constructors

PiotrZSL wrote:

Not here, under `Changes in existing checks` section and follow current format 
there.

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


[clang] [analyzer] Handle builtin functions in MallocChecker (PR #88416)

2024-04-15 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


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


[clang] [llvm] [AArch64] Add intrinsics for 16-bit non-widening FMLA/FMLS (PR #88553)

2024-04-15 Thread Momchil Velikov via cfe-commits

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


[clang] aa27414 - Revert "[C++20] [Modules] Don't import non-inline function bodies even if it is marked as always_inline"

2024-04-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-15T17:06:03+08:00
New Revision: aa2741449c3609b2ae244d8d3f3e14ad16de72e4

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

LOG: Revert "[C++20] [Modules] Don't import non-inline function bodies even if 
it is marked as always_inline"

This reverts commit 1ecbab56dcbb78268c8d19af34a50591f90b12a0.

See the discussion in https://github.com/llvm/llvm-project/issues/86893.

The original commit receives too many complaints. Let's try to
workaround the issue to give better user experiences.

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/module-funcs-from-imports.cppm

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 73a9cb9d6e0424..e44749672d5827 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3952,7 +3952,8 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
   // behavior may break ABI compatibility of the current unit.
   if (const Module *M = F->getOwningModule();
   M && M->getTopLevelModule()->isNamedModule() &&
-  getContext().getCurrentNamedModule() != M->getTopLevelModule())
+  getContext().getCurrentNamedModule() != M->getTopLevelModule() &&
+  !F->hasAttr())
 return false;
 
   if (F->hasAttr())

diff  --git a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm 
b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm
index 8d04328eaf3fea..33cdf437110a9e 100644
--- a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm
+++ b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm
@@ -53,11 +53,11 @@ int use() {
 return exported_func() + always_inline_func();
 }
 
-// Checks that none of the function in the importees
+// Checks that none of the function (except the always_inline_func) in the 
importees
 // are generated in the importer's code.
 // CHECK-O0: define{{.*}}_Z3usev(
 // CHECK-O0: declare{{.*}}_ZW1M13exported_funcv(
-// CHECK-O0: declare{{.*}}_ZW1M18always_inline_funcv(
+// CHECK-O0: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv(
 // CHECK-O0-NOT: func_in_gmf
 // CHECK-O0-NOT: func_in_gmf_not_called
 // CHECK-O0-NOT: non_exported_func
@@ -68,7 +68,7 @@ int use() {
 // O0 to keep consistent ABI.
 // CHECK-O1: define{{.*}}_Z3usev(
 // CHECK-O1: declare{{.*}}_ZW1M13exported_funcv(
-// CHECK-O1: declare{{.*}}_ZW1M18always_inline_funcv(
+// CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv(
 // CHECK-O1-NOT: func_in_gmf
 // CHECK-O1-NOT: func_in_gmf_not_called
 // CHECK-O1-NOT: non_exported_func



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


[clang] [clang][dataflow] Expose fields, globals, and functions referenced. (PR #88534)

2024-04-15 Thread via cfe-commits

martinboehme wrote:

DataflowAnalysisContext.h is starting to accumulate more and more functions 
that serve to extract various types of information from the AST; these aren't 
really related to the `DataflowAnalysisContext`, so I wonder if it's time to 
separate these out into their own header and implementation files?

(I realize that this process started well before this patch, but as the purpose 
of this patch is to move declarations to more suitable places, maybe we should 
use the opportunity to create a more suitable place instead of moving them to 
DataflowAnalysisContext.h, which isn't really a good home for them either.)

The common theme seems to be that these functions / classes all perform some 
operation on the AST, so maybe ASTOperations.h/.cpp? Not really a _great_ name, 
but I think it's still a lot better than putting this all together with the 
`DataflowAnalysisContext`.

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


[clang] [clang][dataflow] Expose fields, globals, and functions referenced. (PR #88534)

2024-04-15 Thread via cfe-commits

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


[clang] [clang][dataflow] Expose fields, globals, and functions referenced. (PR #88534)

2024-04-15 Thread via cfe-commits

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


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


[clang] [clang][dataflow] Expose fields, globals, and functions referenced. (PR #88534)

2024-04-15 Thread via cfe-commits


@@ -62,6 +62,52 @@ FieldSet getObjectFields(QualType Type);
 bool containsSameFields(const FieldSet &Fields,
 const RecordStorageLocation::FieldToLoc &FieldLocs);
 
+/// Returns the fields of a `RecordDecl` that are initialized by an
+/// `InitListExpr`, in the order in which they appear in
+/// `InitListExpr::inits()`.
+/// `Init->getType()` must be a record type.
+std::vector
+getFieldsForInitListExpr(const InitListExpr *InitList);

martinboehme wrote:

This appears to be used only in DataflowEnvironment.cpp -- would suggest simply 
making it a static function there (not exposed in any header).

(I believe it used to be that this was used more widely, but 
`RecordInitListHelper` made that unnecessary, and I didn't notice that when I 
introduced this class?)

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


[clang] [clang][dataflow] Expose fields, globals, and functions referenced. (PR #88534)

2024-04-15 Thread via cfe-commits


@@ -62,6 +62,52 @@ FieldSet getObjectFields(QualType Type);
 bool containsSameFields(const FieldSet &Fields,
 const RecordStorageLocation::FieldToLoc &FieldLocs);
 
+/// Returns the fields of a `RecordDecl` that are initialized by an
+/// `InitListExpr`, in the order in which they appear in
+/// `InitListExpr::inits()`.
+/// `Init->getType()` must be a record type.
+std::vector
+getFieldsForInitListExpr(const InitListExpr *InitList);
+
+/// Helper class for initialization of a record with an `InitListExpr`.
+/// `InitListExpr::inits()` contains the initializers for both the base classes
+/// and the fields of the record; this helper class separates these out into 
two
+/// different lists. In addition, it deals with special cases associated with
+/// unions.
+class RecordInitListHelper {
+public:
+  // `InitList` must have record type.
+  RecordInitListHelper(const InitListExpr *InitList);
+
+  // Base classes with their associated initializer expressions.
+  ArrayRef> base_inits() const {
+return BaseInits;
+  }
+
+  // Fields with their associated initializer expressions.
+  ArrayRef> field_inits() const {
+return FieldInits;
+  }
+
+private:
+  SmallVector> BaseInits;
+  SmallVector> FieldInits;
+
+  // We potentially synthesize an `ImplicitValueInitExpr` for unions. It's a
+  // member variable because we store a pointer to it in `FieldInits`.
+  std::optional ImplicitValueInitForUnion;
+};
+
+struct FieldsGlobalsAndFuncs {

martinboehme wrote:

My vote would be for `Referenced`, and I would also suggest replacing 
`FieldsGlobalsAndFuncs` (which is a name that IIRC has "accreted" over time). 
How about `ReferencedDecls` (and `getReferencedDecls()`), which reads better 
and will remain accurate if we add more types of declarations in the future?

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


[clang] [clang][dataflow] Expose fields, globals, and functions referenced. (PR #88534)

2024-04-15 Thread via cfe-commits


@@ -62,6 +62,52 @@ FieldSet getObjectFields(QualType Type);
 bool containsSameFields(const FieldSet &Fields,
 const RecordStorageLocation::FieldToLoc &FieldLocs);
 
+/// Returns the fields of a `RecordDecl` that are initialized by an
+/// `InitListExpr`, in the order in which they appear in
+/// `InitListExpr::inits()`.
+/// `Init->getType()` must be a record type.
+std::vector
+getFieldsForInitListExpr(const InitListExpr *InitList);
+
+/// Helper class for initialization of a record with an `InitListExpr`.
+/// `InitListExpr::inits()` contains the initializers for both the base classes
+/// and the fields of the record; this helper class separates these out into 
two
+/// different lists. In addition, it deals with special cases associated with
+/// unions.
+class RecordInitListHelper {
+public:
+  // `InitList` must have record type.
+  RecordInitListHelper(const InitListExpr *InitList);
+
+  // Base classes with their associated initializer expressions.
+  ArrayRef> base_inits() const {
+return BaseInits;
+  }
+
+  // Fields with their associated initializer expressions.
+  ArrayRef> field_inits() const {
+return FieldInits;
+  }
+
+private:
+  SmallVector> BaseInits;
+  SmallVector> FieldInits;
+
+  // We potentially synthesize an `ImplicitValueInitExpr` for unions. It's a
+  // member variable because we store a pointer to it in `FieldInits`.
+  std::optional ImplicitValueInitForUnion;
+};
+
+struct FieldsGlobalsAndFuncs {
+  FieldSet Fields;
+  // Globals includes all variables with global storage, notably including
+  // static data members and static variables declared within a function.
+  llvm::DenseSet Globals;
+  llvm::DenseSet Funcs;
+};
+
+FieldsGlobalsAndFuncs getFieldsGlobalsAndFuncs(const FunctionDecl &FD);

martinboehme wrote:

Can you add a short comment for this function?

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


[clang] [clang-tools-extra] [codegen] Emit missing cleanups when an expression contains a branch (PR #80698)

2024-04-15 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

Alternate patch 
https://github.com/llvm/llvm-project/commit/89ba7e183e6e2c64370ed1b963e54c06352211db
 has landed. Closing this as obsolete.

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


[clang] [clang-tools-extra] [codegen] Emit missing cleanups when an expression contains a branch (PR #80698)

2024-04-15 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang-tools-extra] Coro destruct temporary ehcleanup (PR #83224)

2024-04-15 Thread Utkarsh Saxena via cfe-commits

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


[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

2024-04-15 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

This fix is for a wrong refactoring change in 
https://github.com/llvm/llvm-project/commit/89ba7e183e6e2c64370ed1b963e54c06352211db
 and
I would be inclined towards landing this in a few hours to unblock the build 
breakage (if there are no review comments).
CC: @efriedma-quic 


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


[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

2024-04-15 Thread via cfe-commits

cor3ntin wrote:

@usx95 Could you maybe reduce a test from the crash? Thanks!

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


[clang] [clang] Move tailclipping to bitfield allocation (PR #87090)

2024-04-15 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

@rjmccall can you take a look at this? as the description says, this turns out 
to not be NFC, but important on (probably only) LP64 machines.

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


[clang] [llvm] [CLANG][LLVM][AArch64]SME2.1 intrinsics for MOVAZ tile to 2/4 vectors (PR #88710)

2024-04-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-aarch64

Author: None (CarolineConcatto)


Changes

According to the specification in
ARM-software/acle#309 this adds the intrinsics

// Variants are also available for _za8_u8, _za16_s16, _za16_u16, // _za16_f16, 
_za16_bf16, _za32_s32, _za32_u32, _za32_f32, // _za64_s64, _za64_u64 and 
_za64_f64
svint8x2_t svreadz_hor_za8_s8_vg2(uint64_t tile, uint32_t slice) 
__arm_streaming __arm_inout("za");

// Variants are also available for _za8_u8, _za16_s16, _za16_u16, // _za16_f16, 
_za16_bf16, _za32_s32, _za32_u32, _za32_f32, // _za64_s64, _za64_u64 and 
_za64_f64
svint8x4_t svreadz_hor_za8_s8_vg4(uint64_t tile, uint32_t slice) 
__arm_streaming __arm_inout("za");

// Variants are also available for _za8_u8, _za16_s16, _za16_u16, // _za16_f16, 
_za16_bf16, _za32_s32, _za32_u32, _za32_f32, // _za64_s64, _za64_u64 and 
_za64_f64
svint8x2_t svreadz_ver_za8_s8_vg2(uint64_t tile, uint32_t slice) 
__arm_streaming __arm_inout("za");

// Variants are also available for _za8_u8, _za16_s16, _za16_u16, // _za16_f16, 
_za16_bf16, _za32_s32, _za32_u32, _za32_f32, // _za64_s64, _za64_u64 and 
_za64_f64
svint8x4_t svreadz_ver_za8_s8_vg4(uint64_t tile, uint32_t slice) 
__arm_streaming __arm_inout("za");

---

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


9 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+23) 
- (added) clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_movaz.c 
(+1414) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+19-1) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+98-1) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+49) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.h (+3) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+27) 
- (added) llvm/test/CodeGen/AArch64/sme2p1-intrinsics-movaz.ll (+457) 
- (added) llvm/test/CodeGen/AArch64/sme2p1-intrinsics-movaz.s () 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 1ac6d5170ea283..44bb32916d86bb 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -674,3 +674,26 @@ let TargetGuard = "sme2" in {
   def SVLUTI2_LANE_ZT_X2 : Inst<"svluti2_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti2_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_7>]>;
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
+
+multiclass ZAReadz ch> {
+  let TargetGuard = "sme2p1" in {
+def NAME # _H : SInst<"svreadz_hor_" # n_suffix # "_{d}_vg" # vg_num, 
vg_num # "im", t,
+  MergeNone, i_prefix # "_horiz_x" # vg_num,
+  [IsStreaming, IsInOutZA], ch>;
+
+def NAME # _V : SInst<"svreadz_ver_" # n_suffix # "_{d}_vg" # vg_num, 
vg_num # "im", t,
+  MergeNone, i_prefix # "_vert_x" #vg_num,
+  [IsStreaming, IsInOutZA], ch>;
+  }
+}
+
+defm SVREADZ_ZA8_X2  : ZAReadz<"za8",  "2", "cUc",   "aarch64_sme_readz", 
[ImmCheck<0, ImmCheck0_0>]>;
+defm SVREADZ_ZA16_X2 : ZAReadz<"za16", "2", "sUshb", "aarch64_sme_readz", 
[ImmCheck<0, ImmCheck0_1>]>;
+defm SVREADZ_ZA32_X2 : ZAReadz<"za32", "2", "iUif",  "aarch64_sme_readz", 
[ImmCheck<0, ImmCheck0_3>]>;
+defm SVREADZ_ZA64_X2 : ZAReadz<"za64", "2", "lUld",  "aarch64_sme_readz", 
[ImmCheck<0, ImmCheck0_7>]>;
+
+defm SVREADZ_ZA8_X4  : ZAReadz<"za8",  "4", "cUc",   "aarch64_sme_readz", 
[ImmCheck<0, ImmCheck0_0>]>;
+defm SVREADZ_ZA16_X4 : ZAReadz<"za16", "4", "sUshb", "aarch64_sme_readz", 
[ImmCheck<0, ImmCheck0_1>]>;
+defm SVREADZ_ZA32_X4 : ZAReadz<"za32", "4", "iUif",  "aarch64_sme_readz", 
[ImmCheck<0, ImmCheck0_3>]>;
+defm SVREADZ_ZA64_X4 : ZAReadz<"za64", "4", "lUld",  "aarch64_sme_readz", 
[ImmCheck<0, ImmCheck0_7>]>;
+
diff --git a/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_movaz.c 
b/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_movaz.c
new file mode 100644
index 00..2b80c76e3d
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2p1-intrinsics/acle_sme2p1_movaz.c
@@ -0,0 +1,1414 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+ //RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2p1 
-target-feature +bf16 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2p1 
-target-feature +bf16 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -tr

[clang] [ARM64EC] Fix arm_neon.h on ARM64EC. (PR #88572)

2024-04-15 Thread Jacek Caban via cfe-commits

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


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


[clang] [clang] Fix high memory consumption during pack deduction (PR #88637)

2024-04-15 Thread via cfe-commits


@@ -831,7 +831,7 @@ class PackDeductionScope {
 if (IsPartiallyExpanded)
   PackElements += NumPartialPackArgs;
 else if (IsExpanded)
-  PackElements += *FixedNumExpansions;
+  PackElements += FixedNumExpansions.value_or(1);

Sirraide wrote:

> I assumed the template parameter not being a pack is a valid case and not a 
> bug.

Yeah, I’m unfortunately not familiar enough w/ this part of Clang to comment on 
whether that’s the case or not; I’d have to look into this a bit more.

CC @AaronBallman, @erichkeane 

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


[clang] [analyzer] Harden security.cert.env.InvalidPtr checker fn matching (PR #88536)

2024-04-15 Thread via cfe-commits

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

LGTM, thanks for introducing `CDM::CLibrary` in this checker.

However, for the backporting note that this commit depends on two recently 
added commits:
[1] https://github.com/llvm/llvm-project/pull/83432 -- this introduces 
`CDM::CLibrary`
[2] https://github.com/llvm/llvm-project/pull/85791 -- ensures that e.g. 
`std::asctime` is matched by this checker

There were two other related commits, but as far as I understand this commit 
would work without them:
[3] https://github.com/llvm/llvm-project/pull/86536 -- ensures that 
`CDM::CLibrary` doesn't match calls that have more arguments than the expected 
amount
[4] https://github.com/llvm/llvm-project/pull/87764 -- trivial NFC fix of 
buildbot failures caused by [3] 

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


[clang] [analyzer] Harden security.cert.env.InvalidPtr checker fn matching (PR #88536)

2024-04-15 Thread via cfe-commits

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


[clang] Fix objc_sel_{name,types} missing an underscore (PR #88713)

2024-04-15 Thread Jonathan Schleifer via cfe-commits

https://github.com/Midar created https://github.com/llvm/llvm-project/pull/88713

The other places all use the underscore.

This is just a quick drive-by commit, LMK if more is needed.

>From e39e2fc218c588d66937211f98a25eb2acf00a6b Mon Sep 17 00:00:00 2001
From: Jonathan Schleifer 
Date: Mon, 15 Apr 2024 13:36:05 +0200
Subject: [PATCH] Fix objc_sel_{name,types} missing an underscore

The other places all use the underscore.
---
 clang/lib/CodeGen/CGObjCGNU.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4e7f777ba1d916..97df8c5ae18c64 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3873,13 +3873,14 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
 
 for (auto &untypedSel : allSelectors) {
   std::string selNameStr = untypedSel.getAsString();
-  llvm::Constant *selName = ExportUniqueString(selNameStr, 
".objc_sel_name");
+  llvm::Constant *selName = ExportUniqueString(selNameStr,
+".objc_sel_name_");
 
   for (TypedSelector &sel : table[untypedSel]) {
 llvm::Constant *selectorTypeEncoding = NULLPtr;
 if (!sel.first.empty())
   selectorTypeEncoding =
-MakeConstantString(sel.first, ".objc_sel_types");
+MakeConstantString(sel.first, ".objc_sel_types_");
 
 auto selStruct = selectors.beginStruct(selStructTy);
 selStruct.add(selName);

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


[clang] Fix objc_sel_{name,types} missing an underscore (PR #88713)

2024-04-15 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] Fix objc_sel_{name,types} missing an underscore (PR #88713)

2024-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jonathan Schleifer (Midar)


Changes

The other places all use the underscore.

This is just a quick drive-by commit, LMK if more is needed.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+3-2) 


``diff
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4e7f777ba1d916..97df8c5ae18c64 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3873,13 +3873,14 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
 
 for (auto &untypedSel : allSelectors) {
   std::string selNameStr = untypedSel.getAsString();
-  llvm::Constant *selName = ExportUniqueString(selNameStr, 
".objc_sel_name");
+  llvm::Constant *selName = ExportUniqueString(selNameStr,
+".objc_sel_name_");
 
   for (TypedSelector &sel : table[untypedSel]) {
 llvm::Constant *selectorTypeEncoding = NULLPtr;
 if (!sel.first.empty())
   selectorTypeEncoding =
-MakeConstantString(sel.first, ".objc_sel_types");
+MakeConstantString(sel.first, ".objc_sel_types_");
 
 auto selStruct = selectors.beginStruct(selStructTy);
 selStruct.add(selName);

``




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


[clang] 8095b9c - [clang analysis] ExprMutationAnalyzer avoid infinite recursion for recursive forwarding reference (#87954)

2024-04-15 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-04-15T19:38:50+08:00
New Revision: 8095b9ce6bf5831a14c72028920708f38d13d0c3

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

LOG: [clang analysis] ExprMutationAnalyzer avoid infinite recursion for 
recursive forwarding reference (#87954)

Added: 


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

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
clang/lib/Analysis/ExprMutationAnalyzer.cpp
clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1405fb0df1f8dd..de0a7b79bb2cf0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -221,6 +221,10 @@ Changes in existing checks
   ` check by replacing the local
   option `HeaderFileExtensions` by the global option of the same name.
 
+- Improved :doc:`misc-const-correctness
+  ` check by avoiding infinite 
recursion
+  for recursive forwarding reference.
+
 - Improved :doc:`misc-definitions-in-headers
   ` check by replacing the local
   option `HeaderFileExtensions` by the global option of the same name.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
index 9da468128743e9..248374a71dd40b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-templates.cpp
@@ -58,3 +58,18 @@ void concatenate3(Args... args)
 (..., (stream << args));
 }
 } // namespace gh70323
+
+namespace gh60895 {
+
+template  void f1(T &&a);
+template  void f2(T &&a);
+template  void f1(T &&a) { f2(a); }
+template  void f2(T &&a) { f1(a); }
+void f() {
+  int x = 0;
+  // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'x' of type 'int' can be 
declared 'const'
+  // CHECK-FIXES: int const x = 0;
+  f1(x);
+}
+
+} // namespace gh60895

diff  --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h 
b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
index 1ceef944fbc34e..c4e5d0badb8e58 100644
--- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -8,11 +8,10 @@
 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_EXPRMUTATIONANALYZER_H
 #define LLVM_CLANG_ANALYSIS_ANALYSES_EXPRMUTATIONANALYZER_H
 
-#include 
-
 #include "clang/AST/AST.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "llvm/ADT/DenseMap.h"
+#include 
 
 namespace clang {
 
@@ -22,8 +21,15 @@ class FunctionParmMutationAnalyzer;
 /// a given statement.
 class ExprMutationAnalyzer {
 public:
+  friend class FunctionParmMutationAnalyzer;
+  struct Cache {
+llvm::SmallDenseMap>
+FuncParmAnalyzer;
+  };
+
   ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context)
-  : Stm(Stm), Context(Context) {}
+  : ExprMutationAnalyzer(Stm, Context, std::make_shared()) {}
 
   bool isMutated(const Expr *Exp) { return findMutation(Exp) != nullptr; }
   bool isMutated(const Decl *Dec) { return findMutation(Dec) != nullptr; }
@@ -45,6 +51,11 @@ class ExprMutationAnalyzer {
   using MutationFinder = const Stmt *(ExprMutationAnalyzer::*)(const Expr *);
   using ResultMap = llvm::DenseMap;
 
+  ExprMutationAnalyzer(const Stmt &Stm, ASTContext &Context,
+   std::shared_ptr CrossAnalysisCache)
+  : Stm(Stm), Context(Context),
+CrossAnalysisCache(std::move(CrossAnalysisCache)) {}
+
   const Stmt *findMutationMemoized(const Expr *Exp,
llvm::ArrayRef Finders,
ResultMap &MemoizedResults);
@@ -69,9 +80,7 @@ class ExprMutationAnalyzer {
 
   const Stmt &Stm;
   ASTContext &Context;
-  llvm::DenseMap>
-  FuncParmAnalyzer;
+  std::shared_ptr CrossAnalysisCache;
   ResultMap Results;
   ResultMap PointeeResults;
 };
@@ -80,7 +89,12 @@ class ExprMutationAnalyzer {
 // params.
 class FunctionParmMutationAnalyzer {
 public:
-  FunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext &Context);
+  FunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext &Context)
+  : FunctionParmMutationAnalyzer(
+Func, Context, std::make_shared()) {}
+  FunctionParmMutationAnalyzer(
+  const FunctionDecl &Func, ASTContext &Context,
+  std::shared_ptr CrossAnalysisCache);
 
   bool isMutated(const ParmVarDecl *Parm) {
 return findMutation(Parm) != nullptr;

diff  --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMut

[clang] [clang-tools-extra] [clang analysis] ExprMutationAnalyzer avoid infinite recursion for recursive forwarding reference (PR #87954)

2024-04-15 Thread Congcong Cai via cfe-commits

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


[clang] Fix objc_sel_{name,types} missing an underscore (PR #88713)

2024-04-15 Thread Jonathan Schleifer via cfe-commits

https://github.com/Midar updated https://github.com/llvm/llvm-project/pull/88713

>From 8dc7333c0e9c757bba91ebfbe57280ad0635afa9 Mon Sep 17 00:00:00 2001
From: Jonathan Schleifer 
Date: Mon, 15 Apr 2024 13:36:05 +0200
Subject: [PATCH] Fix objc_sel_{name,types} missing an underscore

The other places all use the underscore.

This also makes .objc_sel_name_* consistently private.
---
 clang/lib/CodeGen/CGObjCGNU.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4e7f777ba1d916..d2823b7ee3de46 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3873,13 +3873,14 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
 
 for (auto &untypedSel : allSelectors) {
   std::string selNameStr = untypedSel.getAsString();
-  llvm::Constant *selName = ExportUniqueString(selNameStr, 
".objc_sel_name");
+  llvm::Constant *selName = ExportUniqueString(selNameStr,
+".objc_sel_name_", true);
 
   for (TypedSelector &sel : table[untypedSel]) {
 llvm::Constant *selectorTypeEncoding = NULLPtr;
 if (!sel.first.empty())
   selectorTypeEncoding =
-MakeConstantString(sel.first, ".objc_sel_types");
+MakeConstantString(sel.first, ".objc_sel_types_");
 
 auto selStruct = selectors.beginStruct(selStructTy);
 selStruct.add(selName);

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


[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-04-15 Thread Jonas Hahnfeld via cfe-commits
Stefan =?utf-8?q?Gr=C3=A4nitz?= 
Message-ID:
In-Reply-To: 



@@ -14,7 +14,7 @@ struct A { int a; A(int a) : a(a) {} virtual ~A(); };
 // PartialTranslationUnit.
 inline A::~A() { printf("~A(%d)\n", a); }
 
-// Create one instance with new and delete it.
+// Create one instance with new and delete it. We crash here now:
 A *a1 = new A(1);

hahnjo wrote:

That is with this patch or just current `main`?

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


[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

2024-04-15 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/88670

>From 599283c1845a25afe90163a5f0a7a809c622a521 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Sun, 14 Apr 2024 21:21:21 +
Subject: [PATCH 1/2] Use pushFullExprCleanup for deferred destroy

---
 clang/lib/CodeGen/CGDecl.cpp | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 8bdafa7c569b08..3f05ebb561da57 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2216,8 +2216,11 @@ void CodeGenFunction::pushDestroyAndDeferDeactivation(
 void CodeGenFunction::pushDestroyAndDeferDeactivation(
 CleanupKind cleanupKind, Address addr, QualType type, Destroyer *destroyer,
 bool useEHCleanupForArray) {
-  pushCleanupAndDeferDeactivation(
-  cleanupKind, addr, type, destroyer, useEHCleanupForArray);
+  llvm::Instruction *DominatingIP =
+  Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
+  pushDestroy(cleanupKind, addr, type, destroyer, useEHCleanupForArray);
+  DeferredDeactivationCleanupStack.push_back(
+  {EHStack.stable_begin(), DominatingIP});
 }
 
 void CodeGenFunction::pushStackRestore(CleanupKind Kind, Address SPMem) {

>From a27c77a1506d8044d55eb6961ba69229cb9c1fd7 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 15 Apr 2024 12:41:27 +
Subject: [PATCH 2/2] Add tests

---
 .../CodeGenCXX/destory-with-init-list.cpp | 49 +++
 1 file changed, 49 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/destory-with-init-list.cpp

diff --git a/clang/test/CodeGenCXX/destory-with-init-list.cpp 
b/clang/test/CodeGenCXX/destory-with-init-list.cpp
new file mode 100644
index 00..b9495db3a23d6f
--- /dev/null
+++ b/clang/test/CodeGenCXX/destory-with-init-list.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -emit-llvm -fexceptions -o - %s -triple x86_64-linux-gnu | 
FileCheck -check-prefixes=EH,CHECK %s
+// RUN: %clang_cc1 -emit-llvm -o - %s -triple x86_64-linux-gnu | FileCheck 
-check-prefixes=NOEH,CHECK %s
+namespace std {
+  typedef decltype(sizeof(int)) size_t;
+
+  // libc++'s implementation
+  template 
+  class initializer_list
+  {
+const _E* __begin_;
+size_t__size_;
+initializer_list(const _E* __b, size_t __s);
+  };
+}
+
+class Object {
+public:
+  Object() = default;
+  struct KV;
+  explicit Object(std::initializer_list Properties);
+};
+
+class Value {
+public:
+  Value(std::initializer_list Elements);
+  Value(const char *V);
+  ~Value();
+};
+
+class ObjectKey {
+public:
+  ObjectKey(const char *S);
+  ~ObjectKey();
+};
+
+struct Object::KV {
+  ObjectKey K;
+  Value V;
+};
+
+bool foo();
+void bar() {
+  // Verify we use conditional cleanups.
+  foo() ? Object{{"key1", {"val1", "val2"}}} : Object{{"key2", "val2"}};
+  // CHECK:   cond.true:
+  // EH:invoke void @_ZN9ObjectKeyC1EPKc
+  // NOEH:  call void @_ZN9ObjectKeyC1EPKc
+  // CHECK: store ptr %K, ptr %cond-cleanup.save
+}

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


[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

2024-04-15 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

@cor3ntin Added tests for crash.

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


[clang] [clang][CodeGen] Add AS for Globals to SPIR & SPIRV datalayouts (PR #88455)

2024-04-15 Thread Nathan Gauër via cfe-commits

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


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


[clang] [llvm] [HLSL][SPIRV] Add any intrinsic lowering (PR #88325)

2024-04-15 Thread Nathan Gauër via cfe-commits

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


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


[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

2024-04-15 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang][dataflow] Fix result object location for builtin `<=>`. (PR #88726)

2024-04-15 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/88726

The newly added test causes an assertion failure in `PropagateResultObject()`
without the fix added here.


>From ffdde99a773e732fbc484a5f7647d78d1f15954e Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 15 Apr 2024 12:51:04 +
Subject: [PATCH] [clang][dataflow] Fix result object location for builtin
 `<=>`.

The newly added test causes an assertion failure in `PropagateResultObject()`
without the fix added here.
---
 .../FlowSensitive/DataflowEnvironment.cpp |  5 ++
 .../Analysis/FlowSensitive/TransferTest.cpp   | 52 +++
 2 files changed, 57 insertions(+)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index bea15ce9bd24d1..ee2581143e1141 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -508,6 +508,11 @@ class ResultObjectVisitor : public 
RecursiveASTVisitor {
 isa(E)) {
   return;
 }
+if (auto *Op = dyn_cast(E);
+Op && Op->getOpcode() == BO_Cmp) {
+  // Builtin `<=>` returns a `std::strong_ordering` object.
+  return;
+}
 
 if (auto *InitList = dyn_cast(E)) {
   if (!InitList->isSemanticForm())
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 00dafb2988c690..d8bcc3da4b8b1c 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3098,6 +3098,58 @@ TEST(TransferTest, 
ResultObjectLocationForCXXOperatorCallExpr) {
   });
 }
 
+// Check that the `std::strong_ordering` object returned by builtin `<=>` has a
+// correctly modeled result object location.
+TEST(TransferTest, ResultObjectLocationForBuiltinSpaceshipOperator) {
+  std::string Code = R"(
+namespace std {
+  // This is the minimal definition required to get
+  // `Sema::CheckComparisonCategoryType()` to accept this fake.
+  struct strong_ordering {
+enum class ordering { less, equal, greater };
+ordering o;
+static const strong_ordering less;
+static const strong_ordering equivalent;
+static const strong_ordering equal;
+static const strong_ordering greater;
+  };
+
+  inline constexpr strong_ordering strong_ordering::less =
+{ strong_ordering::ordering::less };
+  inline constexpr strong_ordering strong_ordering::equal =
+{ strong_ordering::ordering::equal };
+  inline constexpr strong_ordering strong_ordering::equivalent =
+{ strong_ordering::ordering::equal };
+  inline constexpr strong_ordering strong_ordering::greater =
+{ strong_ordering::ordering::greater };
+}
+void target(int i, int j) {
+  auto ordering = i <=> j;
+  // [[p]]
+}
+  )";
+  using ast_matchers::binaryOperator;
+  using ast_matchers::hasOperatorName;
+  using ast_matchers::match;
+  using ast_matchers::selectFirst;
+  using ast_matchers::traverse;
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+auto *Spaceship = selectFirst(
+"op",
+match(binaryOperator(hasOperatorName("<=>")).bind("op"), ASTCtx));
+
+EXPECT_EQ(
+&Env.getResultObjectLocation(*Spaceship),
+&getLocForDecl(ASTCtx, Env, "ordering"));
+  },
+  LangStandard::lang_cxx20);
+}
+
 TEST(TransferTest, ResultObjectLocationForStdInitializerListExpr) {
   std::string Code = R"(
 namespace std {

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


[clang] [clang][dataflow] Fix result object location for builtin `<=>`. (PR #88726)

2024-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: None (martinboehme)


Changes

The newly added test causes an assertion failure in `PropagateResultObject()`
without the fix added here.


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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+5) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+52) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index bea15ce9bd24d1..ee2581143e1141 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -508,6 +508,11 @@ class ResultObjectVisitor : public 
RecursiveASTVisitor {
 isa(E)) {
   return;
 }
+if (auto *Op = dyn_cast(E);
+Op && Op->getOpcode() == BO_Cmp) {
+  // Builtin `<=>` returns a `std::strong_ordering` object.
+  return;
+}
 
 if (auto *InitList = dyn_cast(E)) {
   if (!InitList->isSemanticForm())
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 00dafb2988c690..d8bcc3da4b8b1c 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3098,6 +3098,58 @@ TEST(TransferTest, 
ResultObjectLocationForCXXOperatorCallExpr) {
   });
 }
 
+// Check that the `std::strong_ordering` object returned by builtin `<=>` has a
+// correctly modeled result object location.
+TEST(TransferTest, ResultObjectLocationForBuiltinSpaceshipOperator) {
+  std::string Code = R"(
+namespace std {
+  // This is the minimal definition required to get
+  // `Sema::CheckComparisonCategoryType()` to accept this fake.
+  struct strong_ordering {
+enum class ordering { less, equal, greater };
+ordering o;
+static const strong_ordering less;
+static const strong_ordering equivalent;
+static const strong_ordering equal;
+static const strong_ordering greater;
+  };
+
+  inline constexpr strong_ordering strong_ordering::less =
+{ strong_ordering::ordering::less };
+  inline constexpr strong_ordering strong_ordering::equal =
+{ strong_ordering::ordering::equal };
+  inline constexpr strong_ordering strong_ordering::equivalent =
+{ strong_ordering::ordering::equal };
+  inline constexpr strong_ordering strong_ordering::greater =
+{ strong_ordering::ordering::greater };
+}
+void target(int i, int j) {
+  auto ordering = i <=> j;
+  // [[p]]
+}
+  )";
+  using ast_matchers::binaryOperator;
+  using ast_matchers::hasOperatorName;
+  using ast_matchers::match;
+  using ast_matchers::selectFirst;
+  using ast_matchers::traverse;
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+auto *Spaceship = selectFirst(
+"op",
+match(binaryOperator(hasOperatorName("<=>")).bind("op"), ASTCtx));
+
+EXPECT_EQ(
+&Env.getResultObjectLocation(*Spaceship),
+&getLocForDecl(ASTCtx, Env, "ordering"));
+  },
+  LangStandard::lang_cxx20);
+}
+
 TEST(TransferTest, ResultObjectLocationForStdInitializerListExpr) {
   std::string Code = R"(
 namespace std {

``




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


[clang] [clang][dataflow] Fix result object location for builtin `<=>`. (PR #88726)

2024-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes

The newly added test causes an assertion failure in `PropagateResultObject()`
without the fix added here.


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


2 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+5) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+52) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index bea15ce9bd24d1..ee2581143e1141 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -508,6 +508,11 @@ class ResultObjectVisitor : public 
RecursiveASTVisitor {
 isa(E)) {
   return;
 }
+if (auto *Op = dyn_cast(E);
+Op && Op->getOpcode() == BO_Cmp) {
+  // Builtin `<=>` returns a `std::strong_ordering` object.
+  return;
+}
 
 if (auto *InitList = dyn_cast(E)) {
   if (!InitList->isSemanticForm())
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 00dafb2988c690..d8bcc3da4b8b1c 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3098,6 +3098,58 @@ TEST(TransferTest, 
ResultObjectLocationForCXXOperatorCallExpr) {
   });
 }
 
+// Check that the `std::strong_ordering` object returned by builtin `<=>` has a
+// correctly modeled result object location.
+TEST(TransferTest, ResultObjectLocationForBuiltinSpaceshipOperator) {
+  std::string Code = R"(
+namespace std {
+  // This is the minimal definition required to get
+  // `Sema::CheckComparisonCategoryType()` to accept this fake.
+  struct strong_ordering {
+enum class ordering { less, equal, greater };
+ordering o;
+static const strong_ordering less;
+static const strong_ordering equivalent;
+static const strong_ordering equal;
+static const strong_ordering greater;
+  };
+
+  inline constexpr strong_ordering strong_ordering::less =
+{ strong_ordering::ordering::less };
+  inline constexpr strong_ordering strong_ordering::equal =
+{ strong_ordering::ordering::equal };
+  inline constexpr strong_ordering strong_ordering::equivalent =
+{ strong_ordering::ordering::equal };
+  inline constexpr strong_ordering strong_ordering::greater =
+{ strong_ordering::ordering::greater };
+}
+void target(int i, int j) {
+  auto ordering = i <=> j;
+  // [[p]]
+}
+  )";
+  using ast_matchers::binaryOperator;
+  using ast_matchers::hasOperatorName;
+  using ast_matchers::match;
+  using ast_matchers::selectFirst;
+  using ast_matchers::traverse;
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+auto *Spaceship = selectFirst(
+"op",
+match(binaryOperator(hasOperatorName("<=>")).bind("op"), ASTCtx));
+
+EXPECT_EQ(
+&Env.getResultObjectLocation(*Spaceship),
+&getLocForDecl(ASTCtx, Env, "ordering"));
+  },
+  LangStandard::lang_cxx20);
+}
+
 TEST(TransferTest, ResultObjectLocationForStdInitializerListExpr) {
   std::string Code = R"(
 namespace std {

``




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


[clang-tools-extra] [clang-tidy] Ignore deleted ctor in `bugprone-forwarding-reference-overload` (PR #88138)

2024-04-15 Thread Mike Weller via cfe-commits

https://github.com/MikeWeller updated 
https://github.com/llvm/llvm-project/pull/88138

>From 483bd05ec3c0575ed6771ef093368d6be19f5d3f Mon Sep 17 00:00:00 2001
From: Mike Weller 
Date: Tue, 9 Apr 2024 16:03:31 +0100
Subject: [PATCH 1/2] [clang-tidy] Ignore delete ctor in
 `bugprone-forwarding-reference-overload`

Fix `bugprone-forwarding-reference-overload` so it doesn't report a constructor 
that is deleted.
---
 .../bugprone/ForwardingReferenceOverloadCheck.cpp  |  1 +
 clang-tools-extra/docs/ReleaseNotes.rst|  1 +
 .../bugprone/forwarding-reference-overload.cpp | 10 ++
 3 files changed, 12 insertions(+)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index c608fe713f9f5b..e42b40d7b6690e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -73,6 +73,7 @@ void 
ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
   DeclarationMatcher FindOverload =
   cxxConstructorDecl(
   hasParameter(0, ForwardingRefParm),
+  unless(isDeleted()),
   unless(hasAnyParameter(
   // No warning: enable_if as constructor parameter.
   parmVarDecl(hasType(isEnableIf(),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1405fb0df1f8dd..4e4dd35242478f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -102,6 +102,7 @@ Improvements to clang-tidy
   similar fashion to what `-header-filter` does for header files.
 - Improved :program:`check_clang_tidy.py` script. Added argument 
`-export-fixes`
   to aid in clang-tidy and test development.
+- Fixed an issue with `bugprone-forwarding-reference-overload` where it would 
incorrectly flag deleted constructors
 
 New checks
 ^^
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
index 38b0691bc9f1ec..92dfb718bb51b7 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
@@ -251,3 +251,13 @@ class Test10 {
   Test10(T &&Item, E e)
   : e(e){}
 };
+
+// A deleted ctor cannot hide anything
+class Test11 {
+public:
+  template 
+  Test11(T&&) = delete;
+
+  Test11(const Test11 &) = default;
+  Test11(Test11 &&) = default;
+};

>From 49eccb42605236abb56cef2950a6d1a4273b45cb Mon Sep 17 00:00:00 2001
From: Mike Weller 
Date: Mon, 15 Apr 2024 13:55:54 +0100
Subject: [PATCH 2/2] fixup! [clang-tidy] Ignore delete ctor in
 `bugprone-forwarding-reference-overload`

---
 clang-tools-extra/docs/ReleaseNotes.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 4e4dd35242478f..b3d710535f625a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -102,7 +102,6 @@ Improvements to clang-tidy
   similar fashion to what `-header-filter` does for header files.
 - Improved :program:`check_clang_tidy.py` script. Added argument 
`-export-fixes`
   to aid in clang-tidy and test development.
-- Fixed an issue with `bugprone-forwarding-reference-overload` where it would 
incorrectly flag deleted constructors
 
 New checks
 ^^
@@ -287,6 +286,10 @@ Changes in existing checks
   check by resolving fix-it overlaps in template code by disregarding implicit
   instances.
 
+- Improved :doc:`bugprone-forwarding-reference-overload
+  `
+  check to not flag deleted constructors which are unable to hide anything.
+
 Removed checks
 ^^
 

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


[clang-tools-extra] [clang-tidy] Ignore deleted ctor in `bugprone-forwarding-reference-overload` (PR #88138)

2024-04-15 Thread Mike Weller via cfe-commits

MikeWeller wrote:

@PiotrZSL apologies, have put it in the correct location. Is there a way to 
preview/check the `:doc:` thing? I assume there is some kind of 
preprocessor/tool step for this? I copied what the rest are doing and put the 
appropriate section of the 
https://clang.llvm.org/extra/clang-tidy/checks/bugprone/forwarding-reference-overload.html
 URL.

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


[clang] [clang] fix -Wnullability-completeness false-positive in dependent code (PR #88727)

2024-04-15 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall created 
https://github.com/llvm/llvm-project/pull/88727

The intent was that smart-pointers do not participate in completeness
checks, but we failed to capture dependent `unique_ptr`, which is not
a RecordType but a TemplateSpecializationType.


>From f1bea480b599b431f67df432d130e537d32abe86 Mon Sep 17 00:00:00 2001
From: Sam McCall 
Date: Mon, 15 Apr 2024 14:56:33 +0200
Subject: [PATCH] [clang] fix -Wnullability-completeness false-positive in
 dependent code

The intent was that smart-pointers do not participate in completeness
checks, but we failed to capture dependent `unique_ptr`, which is not
a RecordType but a TemplateSpecializationType.
---
 clang/lib/Sema/SemaType.cpp  | 3 ++-
 clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h | 4 
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 404c4e8e31b558..6ac8a9433c701b 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -4728,7 +4728,8 @@ static bool shouldHaveNullability(QualType T) {
  // It's unclear whether the pragma's behavior is useful for C++.
  // e.g. treating type-aliases and template-type-parameters differently
  // from types of declarations can be surprising.
- !isa(T->getCanonicalTypeInternal());
+ !isa(
+ T->getCanonicalTypeInternal());
 }
 
 static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
diff --git a/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h 
b/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h
index a28532e5d71668..5ff974af57f49b 100644
--- a/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h
+++ b/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h
@@ -5,3 +5,7 @@ void f1(int * _Nonnull);
 void f2(Smart); // OK, not required on smart-pointer types
 using Alias = Smart;
 void f3(Alias);
+
+template  class _Nullable SmartTmpl;
+void f2(SmartTmpl);
+template  void f2(SmartTmpl);

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


[clang] [clang] fix -Wnullability-completeness false-positive in dependent code (PR #88727)

2024-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sam McCall (sam-mccall)


Changes

The intent was that smart-pointers do not participate in completeness
checks, but we failed to capture dependent `unique_ptr`, which is not
a RecordType but a TemplateSpecializationType.


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


2 Files Affected:

- (modified) clang/lib/Sema/SemaType.cpp (+2-1) 
- (modified) clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h (+4) 


``diff
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 404c4e8e31b558..6ac8a9433c701b 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -4728,7 +4728,8 @@ static bool shouldHaveNullability(QualType T) {
  // It's unclear whether the pragma's behavior is useful for C++.
  // e.g. treating type-aliases and template-type-parameters differently
  // from types of declarations can be surprising.
- !isa(T->getCanonicalTypeInternal());
+ !isa(
+ T->getCanonicalTypeInternal());
 }
 
 static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
diff --git a/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h 
b/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h
index a28532e5d71668..5ff974af57f49b 100644
--- a/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h
+++ b/clang/test/SemaObjCXX/Inputs/nullability-consistency-smart.h
@@ -5,3 +5,7 @@ void f1(int * _Nonnull);
 void f2(Smart); // OK, not required on smart-pointer types
 using Alias = Smart;
 void f3(Alias);
+
+template  class _Nullable SmartTmpl;
+void f2(SmartTmpl);
+template  void f2(SmartTmpl);

``




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


[clang] [llvm] [ValueTracking] Convert `isKnownNonZero` to use SimplifyQuery (PR #85863)

2024-04-15 Thread Harald van Dijk via cfe-commits


@@ -645,7 +645,7 @@ LazyValueInfoImpl::solveBlockValueImpl(Value *Val, 
BasicBlock *BB) {
   // instruction is placed, even if it could legally be hoisted much higher.
   // That is unfortunate.
   PointerType *PT = dyn_cast(BBI->getType());
-  if (PT && isKnownNonZero(BBI, DL))
+  if (PT && isKnownNonZero(BBI, /*Depth=*/0, DL))

hvdijk wrote:

The fact that this PR changes it so that `isKnownNonZero(BBI, DL)` is valid in 
LLVM 18, used to be valid in LLVM 19, is currently an error in LLVM 19, but 
will become valid in LLVM 19 again is unfortunate and difficult to account for 
in downstream projects. @goldsteinn If you are going to change that, do you 
think it is worth updating downstream code to support the current API, or is 
that change going to go in fast enough that we can just wait?

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


[clang-tools-extra] [clangd] Propagate context into stdlib indexing thread (PR #87611)

2024-04-15 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall commented:

I'm iffy on whether this is semantically right or not, but we need to solve 
this problem somehow, so let's try the most obvious way.

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


[clang-tools-extra] [clangd] Propagate context into stdlib indexing thread (PR #87611)

2024-04-15 Thread Sam McCall via cfe-commits

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


[clang-tools-extra] [clangd] Propagate context into stdlib indexing thread (PR #87611)

2024-04-15 Thread Sam McCall via cfe-commits


@@ -112,7 +112,10 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
  // Index outlives TUScheduler (declared first)
  FIndex(FIndex),
  // shared_ptr extends lifetime
- Stdlib(Stdlib)]() mutable {
+ Stdlib(Stdlib),
+ // We have some FS implementations that rely on infomration in
+ // the context.
+ Ctx(Context::current().clone())]() mutable {

sam-mccall wrote:

this doesn't work - need to actually WithContext it inside the body

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


[clang] [PATCH] [clang-repl] Builtin Type printing in ValuePrinter.cpp (PR #88729)

2024-04-15 Thread via cfe-commits

https://github.com/wlonestar created 
https://github.com/llvm/llvm-project/pull/88729

None

>From c953691de3eda4b72e16d215a6a0e5d230742c59 Mon Sep 17 00:00:00 2001
From: wlonestar <68649094+wlones...@users.noreply.github.com>
Date: Mon, 15 Apr 2024 13:12:55 +
Subject: [PATCH] [PATCH] [clang-repl] Builtin Type printing in
 ValuePrinter.cpp

---
 clang/include/clang/Interpreter/Interpreter.h |   2 +
 clang/include/clang/Interpreter/Value.h   |   8 +-
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/IncrementalParser.h |   1 +
 clang/lib/Interpreter/Interpreter.cpp |   8 +-
 clang/lib/Interpreter/InterpreterUtils.cpp|   2 +-
 clang/lib/Interpreter/InterpreterUtils.h  |   2 +-
 clang/lib/Interpreter/Value.cpp   |  13 +-
 clang/lib/Interpreter/ValuePrinter.cpp| 751 ++
 9 files changed, 779 insertions(+), 9 deletions(-)
 create mode 100644 clang/lib/Interpreter/ValuePrinter.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 970e0245417b51..3be29bd75cfca7 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -149,6 +149,8 @@ class Interpreter {
   CompilerInstance *getCompilerInstance();
   llvm::Expected getExecutionEngine();
 
+  Sema &getSema() const;
+
   llvm::Expected Parse(llvm::StringRef Code);
   llvm::Error Execute(PartialTranslationUnit &T);
   llvm::Error ParseAndExecute(llvm::StringRef Code, Value *V = nullptr);
diff --git a/clang/include/clang/Interpreter/Value.h 
b/clang/include/clang/Interpreter/Value.h
index d70e8f8719026b..186299a84db444 100644
--- a/clang/include/clang/Interpreter/Value.h
+++ b/clang/include/clang/Interpreter/Value.h
@@ -35,6 +35,7 @@
 
 #include "llvm/Support/Compiler.h"
 #include 
+#include 
 
 // NOTE: Since the REPL itself could also include this runtime, extreme caution
 // should be taken when MAKING CHANGES to this file, especially when INCLUDE 
NEW
@@ -117,6 +118,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Value &operator=(Value &&RHS) noexcept;
   ~Value();
 
+  std::string printValueInternal() const;
+
   void printType(llvm::raw_ostream &Out) const;
   void printData(llvm::raw_ostream &Out) const;
   void print(llvm::raw_ostream &Out) const;
@@ -126,7 +129,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
   ASTContext &getASTContext();
   const ASTContext &getASTContext() const;
   Interpreter &getInterpreter();
-  const Interpreter &getInterpreter() const;
+  Interpreter &getInterpreter() const;
   QualType getType() const;
 
   bool isValid() const { return ValueKind != K_Unspecified; }
@@ -136,6 +139,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Kind getKind() const { return ValueKind; }
   void setKind(Kind K) { ValueKind = K; }
   void setOpaqueType(void *Ty) { OpaqueType = Ty; }
+  void setName(std::string name) { Name = name; }
+  std::string getName() const { return Name; }
 
   void *getPtr() const;
   void setPtr(void *Ptr) { Data.m_Ptr = Ptr; }
@@ -197,6 +202,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Storage Data;
   Kind ValueKind = K_Unspecified;
   bool IsManuallyAlloc = false;
+  std::string Name;
 };
 
 template <> inline void *Value::as() const {
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 9065f998f73c47..ea00bdc80f595d 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterUtils.cpp
   Value.cpp
+  ValuePrinter.cpp
 
   DEPENDS
   intrinsics_gen
diff --git a/clang/lib/Interpreter/IncrementalParser.h 
b/clang/lib/Interpreter/IncrementalParser.h
index e13b74c7f65948..c9acc59b1ed602 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -67,6 +67,7 @@ class IncrementalParser {
 
   CompilerInstance *getCI() { return CI.get(); }
   CodeGenerator *getCodeGen() const;
+  Parser &getParser() const { return *P; }
 
   /// Parses incremental input by creating an in-memory file.
   ///\returns a \c PartialTranslationUnit which holds information about the
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index cf31456b6950ac..aa6f6657670bca 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -336,6 +336,8 @@ llvm::Expected 
Interpreter::getExecutionEngine() {
   return IncrExecutor->GetExecutionEngine();
 }
 
+Sema &Interpreter::getSema() const { return getCompilerInstance()->getSema(); }
+
 ASTContext &Interpreter::getASTContext() {
   return getCompilerInstance()->getASTContext();
 }
@@ -427,7 +429,7 @@ llvm::Error Interpreter::Execute(PartialTranslationUnit &T) 
{
 }
 
 llvm::Error Interpreter::ParseAndExecute(llvm::StringRef Code, Value *V) {
-
+  std::string name = Code.str();
   auto PTU = Parse(Code);
   if (!PTU)
 re

[clang] [PATCH] [clang-repl] Builtin Type printing in ValuePrinter.cpp (PR #88729)

2024-04-15 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [llvm] [Clang] Emit DW_TAG_template_alias for template aliases (PR #87623)

2024-04-15 Thread Michael Buch via cfe-commits


@@ -5361,7 +5383,56 @@ static bool IsReconstitutableType(QualType QT) {
   return T.Reconstitutable;
 }
 
-std::string CGDebugInfo::GetName(const Decl *D, bool Qualified) const {
+bool CGDebugInfo::HasReconstitutableArgs(
+ArrayRef Args) const {
+  return llvm::all_of(Args, [&](const TemplateArgument &TA) {
+switch (TA.getKind()) {
+case TemplateArgument::Template:
+  // Easy to reconstitute - the value of the parameter in the debug
+  // info is the string name of the template. (so the template name
+  // itself won't benefit from any name rebuilding, but that's a
+  // representational limitation - maybe DWARF could be
+  // changed/improved to use some more structural representation)
+  return true;
+case TemplateArgument::Declaration:
+  // Reference and pointer non-type template parameters point to
+  // variables, functions, etc and their value is, at best (for
+  // variables) represented as an address - not a reference to the
+  // DWARF describing the variable/function/etc. This makes it hard,
+  // possibly impossible to rebuild the original name - looking up
+  // the address in the executable file's symbol table would be
+  // needed.
+  return false;
+case TemplateArgument::NullPtr:
+  // These could be rebuilt, but figured they're close enough to the
+  // declaration case, and not worth rebuilding.
+  return false;
+case TemplateArgument::Pack:
+  // A pack is invalid if any of the elements of the pack are
+  // invalid.
+  return HasReconstitutableArgs(TA.getPackAsArray());
+case TemplateArgument::Integral:
+  // Larger integers get encoded as DWARF blocks which are a bit
+  // harder to parse back into a large integer, etc - so punting on
+  // this for now. Re-parsing the integers back into APInt is
+  // probably feasible some day.
+  return TA.getAsIntegral().getBitWidth() <= 64 &&
+ IsReconstitutableType(TA.getIntegralType());
+case TemplateArgument::StructuralValue:
+  return false;
+case TemplateArgument::Type:
+  return IsReconstitutableType(TA.getAsType());
+case TemplateArgument::Expression:
+  return IsReconstitutableType(TA.getAsExpr()->getType());
+default:
+  llvm_unreachable("Other, unresolved, template arguments should "
+   "not be seen here");
+}
+  });
+}
+
+std::string CGDebugInfo::GetName(const Decl *D, bool Qualified,
+ const Type *Ty) const {

Michael137 wrote:

Ah thanks for the additional context. Keeping it as is seems fine to me then. I 
don't see a better way to get to template arguments from the alias decl. My 
initial thought of special-casing this in `GetName` isn't necessarily great 
either

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


[clang] [PATCH] [clang-repl] Builtin Type printing in ValuePrinter.cpp (PR #88729)

2024-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: wlonestar (wlonestar)


Changes



---

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


9 Files Affected:

- (modified) clang/include/clang/Interpreter/Interpreter.h (+2) 
- (modified) clang/include/clang/Interpreter/Value.h (+7-1) 
- (modified) clang/lib/Interpreter/CMakeLists.txt (+1) 
- (modified) clang/lib/Interpreter/IncrementalParser.h (+1) 
- (modified) clang/lib/Interpreter/Interpreter.cpp (+6-2) 
- (modified) clang/lib/Interpreter/InterpreterUtils.cpp (+1-1) 
- (modified) clang/lib/Interpreter/InterpreterUtils.h (+1-1) 
- (modified) clang/lib/Interpreter/Value.cpp (+9-4) 
- (added) clang/lib/Interpreter/ValuePrinter.cpp (+751) 


``diff
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 970e0245417b51..3be29bd75cfca7 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -149,6 +149,8 @@ class Interpreter {
   CompilerInstance *getCompilerInstance();
   llvm::Expected getExecutionEngine();
 
+  Sema &getSema() const;
+
   llvm::Expected Parse(llvm::StringRef Code);
   llvm::Error Execute(PartialTranslationUnit &T);
   llvm::Error ParseAndExecute(llvm::StringRef Code, Value *V = nullptr);
diff --git a/clang/include/clang/Interpreter/Value.h 
b/clang/include/clang/Interpreter/Value.h
index d70e8f8719026b..186299a84db444 100644
--- a/clang/include/clang/Interpreter/Value.h
+++ b/clang/include/clang/Interpreter/Value.h
@@ -35,6 +35,7 @@
 
 #include "llvm/Support/Compiler.h"
 #include 
+#include 
 
 // NOTE: Since the REPL itself could also include this runtime, extreme caution
 // should be taken when MAKING CHANGES to this file, especially when INCLUDE 
NEW
@@ -117,6 +118,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Value &operator=(Value &&RHS) noexcept;
   ~Value();
 
+  std::string printValueInternal() const;
+
   void printType(llvm::raw_ostream &Out) const;
   void printData(llvm::raw_ostream &Out) const;
   void print(llvm::raw_ostream &Out) const;
@@ -126,7 +129,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
   ASTContext &getASTContext();
   const ASTContext &getASTContext() const;
   Interpreter &getInterpreter();
-  const Interpreter &getInterpreter() const;
+  Interpreter &getInterpreter() const;
   QualType getType() const;
 
   bool isValid() const { return ValueKind != K_Unspecified; }
@@ -136,6 +139,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Kind getKind() const { return ValueKind; }
   void setKind(Kind K) { ValueKind = K; }
   void setOpaqueType(void *Ty) { OpaqueType = Ty; }
+  void setName(std::string name) { Name = name; }
+  std::string getName() const { return Name; }
 
   void *getPtr() const;
   void setPtr(void *Ptr) { Data.m_Ptr = Ptr; }
@@ -197,6 +202,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Storage Data;
   Kind ValueKind = K_Unspecified;
   bool IsManuallyAlloc = false;
+  std::string Name;
 };
 
 template <> inline void *Value::as() const {
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 9065f998f73c47..ea00bdc80f595d 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterUtils.cpp
   Value.cpp
+  ValuePrinter.cpp
 
   DEPENDS
   intrinsics_gen
diff --git a/clang/lib/Interpreter/IncrementalParser.h 
b/clang/lib/Interpreter/IncrementalParser.h
index e13b74c7f65948..c9acc59b1ed602 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -67,6 +67,7 @@ class IncrementalParser {
 
   CompilerInstance *getCI() { return CI.get(); }
   CodeGenerator *getCodeGen() const;
+  Parser &getParser() const { return *P; }
 
   /// Parses incremental input by creating an in-memory file.
   ///\returns a \c PartialTranslationUnit which holds information about the
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index cf31456b6950ac..aa6f6657670bca 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -336,6 +336,8 @@ llvm::Expected 
Interpreter::getExecutionEngine() {
   return IncrExecutor->GetExecutionEngine();
 }
 
+Sema &Interpreter::getSema() const { return getCompilerInstance()->getSema(); }
+
 ASTContext &Interpreter::getASTContext() {
   return getCompilerInstance()->getASTContext();
 }
@@ -427,7 +429,7 @@ llvm::Error Interpreter::Execute(PartialTranslationUnit &T) 
{
 }
 
 llvm::Error Interpreter::ParseAndExecute(llvm::StringRef Code, Value *V) {
-
+  std::string name = Code.str();
   auto PTU = Parse(Code);
   if (!PTU)
 return PTU.takeError();
@@ -437,10 +439,12 @@ llvm::Error Interpreter::ParseAndExecute(llvm::StringRef 
Code, Value *V) {
 
   if (LastValue.isValid()) {
 if (!V) {
+  LastValue.setName

[clang] [AST][RecoveryExpr] Fix a crash on c89/c90 invalid InitListExpr (#88008) (PR #88014)

2024-04-15 Thread Sam McCall via cfe-commits

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


[clang] [AST][RecoveryExpr] Fix a crash on c89/c90 invalid InitListExpr (#88008) (PR #88014)

2024-04-15 Thread Sam McCall via cfe-commits


@@ -3391,7 +3391,7 @@ class Sema final : public SemaBase {
   bool ConstexprSupported, bool CLinkageMayDiffer);
 
   /// type checking declaration initializers (C99 6.7.8)
-  bool CheckForConstantInitializer(Expr *e, QualType t);
+  bool CheckForConstantInitializer(Expr *Init, unsigned DiagID);

sam-mccall wrote:

you could consider adding a default for DiagID as there's an "obvious" one used 
in most places. Up to you.

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


[clang] [AST][RecoveryExpr] Fix a crash on c89/c90 invalid InitListExpr (#88008) (PR #88014)

2024-04-15 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall approved this pull request.

Thanks, this looks like the right fix, and cleaning up DclT while here makes 
sense.

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


[clang] Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541, #88311)" (PR #88731)

2024-04-15 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/88731

Reapplies #87541 and #88311 (again) addressing the bug which caused expressions 
naming overload sets to be incorrectly rebuilt, as well as the bug which caused 
base class members to always be treated as overload sets.

>From 4640d869aeb83a457b16f553de215e3d106eaa67 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 15 Apr 2024 09:17:39 -0400
Subject: [PATCH] Reapply "[Clang][Sema] Fix crash when 'this' is used in a
 dependent class scope function template specialization that instantiates to a
 static member function (#87541, #88311)"

Reapplies #87541 and #88311 addressing the bug which caused expressions naming
overload sets to be incorrectly rebuilt, as well as the bug which caused
base class members to always be treated as overload sets.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/ExprCXX.h |   3 +-
 clang/include/clang/Sema/Sema.h   |  16 +-
 clang/lib/AST/ASTImporter.cpp |   2 +-
 clang/lib/AST/ExprCXX.cpp |   8 +-
 clang/lib/Sema/SemaCoroutine.cpp  |   4 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaExpr.cpp   |  30 +--
 clang/lib/Sema/SemaExprCXX.cpp|  61 +++---
 clang/lib/Sema/SemaExprMember.cpp |  63 --
 clang/lib/Sema/SemaOpenMP.cpp |   6 +-
 clang/lib/Sema/SemaOverload.cpp   |   3 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |   8 +
 clang/lib/Sema/TreeTransform.h|  75 ---
 .../SemaTemplate/instantiate-using-decl.cpp   |   2 +-
 ...ms-function-specialization-class-scope.cpp | 201 +-
 16 files changed, 371 insertions(+), 115 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index de5fa99bff5dbe..ade8f4e93d5a0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -529,6 +529,8 @@ Bug Fixes to C++ Support
 - Fix an issue caused by not handling invalid cases when substituting into the 
parameter mapping of a constraint. Fixes (#GH86757).
 - Fixed a bug that prevented member function templates of class templates 
declared with a deduced return type
   from being explicitly specialized for a given implicit instantiation of the 
class template.
+- Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
+  that instantiates to a static member function.
 
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index d28e5c3a78ee4b..4d5293566580ae 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3219,7 +3219,8 @@ class UnresolvedLookupExpr final
   Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
  NestedNameSpecifierLoc QualifierLoc,
  const DeclarationNameInfo &NameInfo, bool RequiresADL, bool 
Overloaded,
- UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+ UnresolvedSetIterator Begin, UnresolvedSetIterator End,
+ bool KnownDependent);
 
   // After canonicalization, there may be dependent template arguments in
   // CanonicalConverted But none of Args is dependent. When any of
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6035445e90192..c6e0332c3176b3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5452,7 +5452,8 @@ class Sema final : public SemaBase {
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R,
   bool NeedsADL,
-  bool AcceptInvalidDecl = false);
+  bool AcceptInvalidDecl = false,
+  bool NeedUnresolved = false);
   ExprResult BuildDeclarationNameExpr(
   const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl 
*D,
   NamedDecl *FoundD = nullptr,
@@ -6595,7 +6596,10 @@ class Sema final : public SemaBase {
 SourceLocation RParenLoc);
 
    ActOnCXXThis -  Parse 'this' pointer.
-  ExprResult ActOnCXXThis(SourceLocation loc);
+  ExprResult ActOnCXXThis(SourceLocation Loc);
+
+  /// Check whether the type of 'this' is valid in the current context.
+  bool CheckCXXThisType(SourceLocation Loc, QualType Type);
 
   /// Build a CXXThisExpr and mark it referenced in the current context.
   Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);
@@ -7018,10 +7022,14 @@ class Sema final : public SemaBase {
   ///@{
 
 public:
+  /// Check whether an expression might be an implicit class member access.
+  bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, Look

[clang] Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541, #88311)" (PR #88731)

2024-04-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-coroutines

Author: Krystian Stasiowski (sdkrystian)


Changes

Reapplies #87541 and #88311 (again) addressing the bug which 
caused expressions naming overload sets to be incorrectly rebuilt, as well as 
the bug which caused base class members to always be treated as overload sets.

---

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


16 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/AST/ExprCXX.h (+2-1) 
- (modified) clang/include/clang/Sema/Sema.h (+12-4) 
- (modified) clang/lib/AST/ASTImporter.cpp (+1-1) 
- (modified) clang/lib/AST/ExprCXX.cpp (+5-3) 
- (modified) clang/lib/Sema/SemaCoroutine.cpp (+2-2) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+7-23) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+32-29) 
- (modified) clang/lib/Sema/SemaExprMember.cpp (+49-14) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+4-2) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+8) 
- (modified) clang/lib/Sema/TreeTransform.h (+45-30) 
- (modified) clang/test/SemaTemplate/instantiate-using-decl.cpp (+1-1) 
- (modified) clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp 
(+198-3) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index de5fa99bff5dbe..ade8f4e93d5a0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -529,6 +529,8 @@ Bug Fixes to C++ Support
 - Fix an issue caused by not handling invalid cases when substituting into the 
parameter mapping of a constraint. Fixes (#GH86757).
 - Fixed a bug that prevented member function templates of class templates 
declared with a deduced return type
   from being explicitly specialized for a given implicit instantiation of the 
class template.
+- Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
+  that instantiates to a static member function.
 
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index d28e5c3a78ee4b..4d5293566580ae 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3219,7 +3219,8 @@ class UnresolvedLookupExpr final
   Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
  NestedNameSpecifierLoc QualifierLoc,
  const DeclarationNameInfo &NameInfo, bool RequiresADL, bool 
Overloaded,
- UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+ UnresolvedSetIterator Begin, UnresolvedSetIterator End,
+ bool KnownDependent);
 
   // After canonicalization, there may be dependent template arguments in
   // CanonicalConverted But none of Args is dependent. When any of
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6035445e90192..c6e0332c3176b3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5452,7 +5452,8 @@ class Sema final : public SemaBase {
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R,
   bool NeedsADL,
-  bool AcceptInvalidDecl = false);
+  bool AcceptInvalidDecl = false,
+  bool NeedUnresolved = false);
   ExprResult BuildDeclarationNameExpr(
   const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl 
*D,
   NamedDecl *FoundD = nullptr,
@@ -6595,7 +6596,10 @@ class Sema final : public SemaBase {
 SourceLocation RParenLoc);
 
    ActOnCXXThis -  Parse 'this' pointer.
-  ExprResult ActOnCXXThis(SourceLocation loc);
+  ExprResult ActOnCXXThis(SourceLocation Loc);
+
+  /// Check whether the type of 'this' is valid in the current context.
+  bool CheckCXXThisType(SourceLocation Loc, QualType Type);
 
   /// Build a CXXThisExpr and mark it referenced in the current context.
   Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);
@@ -7018,10 +7022,14 @@ class Sema final : public SemaBase {
   ///@{
 
 public:
+  /// Check whether an expression might be an implicit class member access.
+  bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R,
+   bool IsAddressOfOperand);
+
   ExprResult BuildPossibleImplicitMemberExpr(
   const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R,
-  const TemplateArgumentListInfo *TemplateArgs, const Scope *S,
-  UnresolvedLookupExpr *AsULE = nullptr);
+  const TemplateArgumentListInfo *TemplateArgs, const Scope *S);
+
   ExprResult
   BuildIm

[clang] Reapply "[Clang][Sema] Fix crash when 'this' is used in a dependent class scope function template specialization that instantiates to a static member function (#87541, #88311)" (PR #88731)

2024-04-15 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/88731

>From 02d98a20ad2214c928d6ffcc7f54abe1172a2407 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 15 Apr 2024 09:17:39 -0400
Subject: [PATCH] Reapply "[Clang][Sema] Fix crash when 'this' is used in a
 dependent class scope function template specialization that instantiates to a
 static member function (#87541, #88311)"

Reapplies #87541 and #88311 addressing the bug which caused expressions naming
overload sets to be incorrectly rebuilt, as well as the bug which caused
base class members to always be treated as overload sets.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/AST/ExprCXX.h |   3 +-
 clang/include/clang/Sema/Sema.h   |  16 +-
 clang/lib/AST/ASTImporter.cpp |   2 +-
 clang/lib/AST/ExprCXX.cpp |   9 +-
 clang/lib/Sema/SemaCoroutine.cpp  |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaExpr.cpp   |  38 +---
 clang/lib/Sema/SemaExprCXX.cpp|  61 +++---
 clang/lib/Sema/SemaExprMember.cpp |  63 --
 clang/lib/Sema/SemaOpenMP.cpp |   6 +-
 clang/lib/Sema/SemaOverload.cpp   |   3 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |   8 +
 clang/lib/Sema/TreeTransform.h|  82 ---
 .../SemaTemplate/instantiate-using-decl.cpp   |   2 +-
 ...ms-function-specialization-class-scope.cpp | 201 +-
 16 files changed, 376 insertions(+), 124 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index de5fa99bff5dbe..ade8f4e93d5a0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -529,6 +529,8 @@ Bug Fixes to C++ Support
 - Fix an issue caused by not handling invalid cases when substituting into the 
parameter mapping of a constraint. Fixes (#GH86757).
 - Fixed a bug that prevented member function templates of class templates 
declared with a deduced return type
   from being explicitly specialized for a given implicit instantiation of the 
class template.
+- Fixed a crash when ``this`` is used in a dependent class scope function 
template specialization
+  that instantiates to a static member function.
 
 - Fix crash when inheriting from a cv-qualified type. Fixes:
   (`#35603 `_)
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index d28e5c3a78ee4b..4d5293566580ae 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3219,7 +3219,8 @@ class UnresolvedLookupExpr final
   Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
  NestedNameSpecifierLoc QualifierLoc,
  const DeclarationNameInfo &NameInfo, bool RequiresADL, bool 
Overloaded,
- UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+ UnresolvedSetIterator Begin, UnresolvedSetIterator End,
+ bool KnownDependent);
 
   // After canonicalization, there may be dependent template arguments in
   // CanonicalConverted But none of Args is dependent. When any of
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6035445e90192..c6e0332c3176b3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5452,7 +5452,8 @@ class Sema final : public SemaBase {
 
   ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R,
   bool NeedsADL,
-  bool AcceptInvalidDecl = false);
+  bool AcceptInvalidDecl = false,
+  bool NeedUnresolved = false);
   ExprResult BuildDeclarationNameExpr(
   const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl 
*D,
   NamedDecl *FoundD = nullptr,
@@ -6595,7 +6596,10 @@ class Sema final : public SemaBase {
 SourceLocation RParenLoc);
 
    ActOnCXXThis -  Parse 'this' pointer.
-  ExprResult ActOnCXXThis(SourceLocation loc);
+  ExprResult ActOnCXXThis(SourceLocation Loc);
+
+  /// Check whether the type of 'this' is valid in the current context.
+  bool CheckCXXThisType(SourceLocation Loc, QualType Type);
 
   /// Build a CXXThisExpr and mark it referenced in the current context.
   Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit);
@@ -7018,10 +7022,14 @@ class Sema final : public SemaBase {
   ///@{
 
 public:
+  /// Check whether an expression might be an implicit class member access.
+  bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R,
+   bool IsAddressOfOperand);
+
   ExprResult BuildPossibleImplicitMemberExpr(
   const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R,
-  const T

[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

2024-04-15 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/88666

>From 8d48a0bd1cf15b9cf00bc294912b674b5f94a11c Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Mon, 15 Apr 2024 00:36:06 +0800
Subject: [PATCH 1/3] [Clang] Allow the value of unroll count to be zero  in
 '#pragma GCC unroll' and '#pragma unroll'

Signed-off-by: yronglin 
---
 clang/docs/ReleaseNotes.rst |  4 
 clang/include/clang/Sema/Sema.h |  3 ++-
 clang/lib/CodeGen/CGLoopInfo.cpp|  2 ++
 clang/lib/Parse/ParsePragma.cpp |  7 ---
 clang/lib/Sema/SemaExpr.cpp | 12 +--
 clang/lib/Sema/SemaStmtAttr.cpp | 19 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp  |  3 ++-
 clang/test/CodeGenCXX/pragma-gcc-unroll.cpp | 22 +
 clang/test/Parser/pragma-unroll.cpp |  8 ++--
 9 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ade8f4e93d5a0c..5183edcf01b1cc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -423,6 +423,10 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now allowed the value of unroll count to be zero in ``#pragma GCC 
unroll`` and ``#pragma unroll``. 
+  The values of 0 and 1 block any unrolling of the loop. This keeps the same 
behavior with GCC.
+  Fixes (`#88624 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6e0332c3176b3..3b2f3a6d82675c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5469,7 +5469,8 @@ class Sema final : public SemaBase {
   ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
   ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
 
-  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
+  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo);
 
   ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
   ExprResult ActOnCharacterConstant(const Token &Tok,
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index 0d4800b90a2f26..72d1471021ac02 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/CodeGen/CGLoopInfo.cpp
@@ -673,6 +673,8 @@ void LoopInfoStack::push(BasicBlock *Header, 
clang::ASTContext &Ctx,
 setPipelineDisabled(true);
 break;
   case LoopHintAttr::UnrollCount:
+setUnrollState(LoopAttributes::Disable);
+break;
   case LoopHintAttr::UnrollAndJamCount:
   case LoopHintAttr::VectorizeWidth:
   case LoopHintAttr::InterleaveCount:
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 3979f75b6020db..8fed9e70f7a56e 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1569,7 +1569,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
   ConsumeToken(); // Consume the constant expression eof terminator.
 
   if (Arg2Error || R.isInvalid() ||
-  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation(),
+PragmaNameInfo))
 return false;
 
   // Argument is a constant expression with an integer type.
@@ -1593,8 +1594,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
 
 ConsumeToken(); // Consume the constant expression eof terminator.
 
-if (R.isInvalid() ||
-Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+if (R.isInvalid() || Actions.CheckLoopHintExpr(
+ R.get(), Toks[0].getLocation(), PragmaNameInfo))
   return false;
 
 // Argument is a constant expression with an integer type.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 505d068ac42ebe..437b31716ed30c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3885,7 +3885,8 @@ static Expr *BuildFloatingLiteral(Sema &S, 
NumericLiteralParser &Literal,
   return FloatingLiteral::Create(S.Context, Val, isExact, Ty, Loc);
 }
 
-bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc) {
+bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo) {
   assert(E && "Invalid expression");
 
   if (E->isValueDependent())
@@ -3903,7 +3904,14 @@ bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation 
Loc) {
   if (R.isInvalid())
 return true;
 
-  bool ValueIsPositive = ValueAPS.isStrictlyPositive();
+  // GCC allows the value of unroll count to be 0.
+  // https://gcc.gnu.org/onlinedocs/gcc/

[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

2024-04-15 Thread via cfe-commits


@@ -423,6 +423,10 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now allowed the value of unroll count to be zero in ``#pragma GCC 
unroll`` and ``#pragma unroll``.

yronglin wrote:

Done!

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


[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

2024-04-15 Thread via cfe-commits

yronglin wrote:

Thanks for your review! @Endilll @tbaederr 

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


[clang] [PATCH] [clang-repl] Builtin Type printing in ValuePrinter.cpp (PR #88729)

2024-04-15 Thread via cfe-commits

https://github.com/wlonestar updated 
https://github.com/llvm/llvm-project/pull/88729

>From c953691de3eda4b72e16d215a6a0e5d230742c59 Mon Sep 17 00:00:00 2001
From: wlonestar <68649094+wlones...@users.noreply.github.com>
Date: Mon, 15 Apr 2024 13:12:55 +
Subject: [PATCH] [PATCH] [clang-repl] Builtin Type printing in
 ValuePrinter.cpp

---
 clang/include/clang/Interpreter/Interpreter.h |   2 +
 clang/include/clang/Interpreter/Value.h   |   8 +-
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/IncrementalParser.h |   1 +
 clang/lib/Interpreter/Interpreter.cpp |   8 +-
 clang/lib/Interpreter/InterpreterUtils.cpp|   2 +-
 clang/lib/Interpreter/InterpreterUtils.h  |   2 +-
 clang/lib/Interpreter/Value.cpp   |  13 +-
 clang/lib/Interpreter/ValuePrinter.cpp| 751 ++
 9 files changed, 779 insertions(+), 9 deletions(-)
 create mode 100644 clang/lib/Interpreter/ValuePrinter.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 970e0245417b51..3be29bd75cfca7 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -149,6 +149,8 @@ class Interpreter {
   CompilerInstance *getCompilerInstance();
   llvm::Expected getExecutionEngine();
 
+  Sema &getSema() const;
+
   llvm::Expected Parse(llvm::StringRef Code);
   llvm::Error Execute(PartialTranslationUnit &T);
   llvm::Error ParseAndExecute(llvm::StringRef Code, Value *V = nullptr);
diff --git a/clang/include/clang/Interpreter/Value.h 
b/clang/include/clang/Interpreter/Value.h
index d70e8f8719026b..186299a84db444 100644
--- a/clang/include/clang/Interpreter/Value.h
+++ b/clang/include/clang/Interpreter/Value.h
@@ -35,6 +35,7 @@
 
 #include "llvm/Support/Compiler.h"
 #include 
+#include 
 
 // NOTE: Since the REPL itself could also include this runtime, extreme caution
 // should be taken when MAKING CHANGES to this file, especially when INCLUDE 
NEW
@@ -117,6 +118,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Value &operator=(Value &&RHS) noexcept;
   ~Value();
 
+  std::string printValueInternal() const;
+
   void printType(llvm::raw_ostream &Out) const;
   void printData(llvm::raw_ostream &Out) const;
   void print(llvm::raw_ostream &Out) const;
@@ -126,7 +129,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
   ASTContext &getASTContext();
   const ASTContext &getASTContext() const;
   Interpreter &getInterpreter();
-  const Interpreter &getInterpreter() const;
+  Interpreter &getInterpreter() const;
   QualType getType() const;
 
   bool isValid() const { return ValueKind != K_Unspecified; }
@@ -136,6 +139,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Kind getKind() const { return ValueKind; }
   void setKind(Kind K) { ValueKind = K; }
   void setOpaqueType(void *Ty) { OpaqueType = Ty; }
+  void setName(std::string name) { Name = name; }
+  std::string getName() const { return Name; }
 
   void *getPtr() const;
   void setPtr(void *Ptr) { Data.m_Ptr = Ptr; }
@@ -197,6 +202,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Storage Data;
   Kind ValueKind = K_Unspecified;
   bool IsManuallyAlloc = false;
+  std::string Name;
 };
 
 template <> inline void *Value::as() const {
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 9065f998f73c47..ea00bdc80f595d 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterUtils.cpp
   Value.cpp
+  ValuePrinter.cpp
 
   DEPENDS
   intrinsics_gen
diff --git a/clang/lib/Interpreter/IncrementalParser.h 
b/clang/lib/Interpreter/IncrementalParser.h
index e13b74c7f65948..c9acc59b1ed602 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -67,6 +67,7 @@ class IncrementalParser {
 
   CompilerInstance *getCI() { return CI.get(); }
   CodeGenerator *getCodeGen() const;
+  Parser &getParser() const { return *P; }
 
   /// Parses incremental input by creating an in-memory file.
   ///\returns a \c PartialTranslationUnit which holds information about the
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index cf31456b6950ac..aa6f6657670bca 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -336,6 +336,8 @@ llvm::Expected 
Interpreter::getExecutionEngine() {
   return IncrExecutor->GetExecutionEngine();
 }
 
+Sema &Interpreter::getSema() const { return getCompilerInstance()->getSema(); }
+
 ASTContext &Interpreter::getASTContext() {
   return getCompilerInstance()->getASTContext();
 }
@@ -427,7 +429,7 @@ llvm::Error Interpreter::Execute(PartialTranslationUnit &T) 
{
 }
 
 llvm::Error Interpreter::ParseAndExecute(llvm::StringRef Code, Value *V) {
-
+  std::string name = Code.str();
   auto PTU = Parse(Code);
   if (!PTU)
 return P

[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-04-15 Thread Vassil Vassilev via cfe-commits
Stefan =?utf-8?q?Gr=C3=A4nitz?= 
Message-ID:
In-Reply-To: 



@@ -14,7 +14,7 @@ struct A { int a; A(int a) : a(a) {} virtual ~A(); };
 // PartialTranslationUnit.
 inline A::~A() { printf("~A(%d)\n", a); }
 
-// Create one instance with new and delete it.
+// Create one instance with new and delete it. We crash here now:
 A *a1 = new A(1);

vgvassilev wrote:

Correct, that's also the case with releases/16.x...

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


[clang-tools-extra] [clangd] Remove potential prefix from enum value names (PR #83412)

2024-04-15 Thread Julian Schmidt via cfe-commits


@@ -125,25 +123,42 @@ llvm::Error ScopifyEnum::addClassKeywordToDeclarations() {
 }
 
 llvm::Error ScopifyEnum::scopifyEnumValues() {
-  std::string PrefixToInsert(D->getName());
-  PrefixToInsert += "::";
+  StringRef EnumName(D->getName());
+  bool StripPrefix = true;
+  for (auto E : D->enumerators()) {
+if (!E->getName().starts_with(EnumName)) {
+  StripPrefix = false;
+  break;
+}
+  }
   for (auto E : D->enumerators()) {

5chmidti wrote:

This is not in your changed lines, but please change this `auto` to `const 
EnumConstantDecl *` as well.

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


[clang-tools-extra] [clangd] Remove potential prefix from enum value names (PR #83412)

2024-04-15 Thread Julian Schmidt via cfe-commits


@@ -125,25 +123,42 @@ llvm::Error ScopifyEnum::addClassKeywordToDeclarations() {
 }
 
 llvm::Error ScopifyEnum::scopifyEnumValues() {
-  std::string PrefixToInsert(D->getName());
-  PrefixToInsert += "::";
+  StringRef EnumName(D->getName());
+  bool StripPrefix = true;
+  for (auto E : D->enumerators()) {

5chmidti wrote:

Please use `const EnumConstantDecl *` instead of `auto`.

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


[clang-tools-extra] [clangd] Remove potential prefix from enum value names (PR #83412)

2024-04-15 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti commented:

I think this change could use a release note in the docs, could you please add 
one?

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


[clang-tools-extra] [clangd] Remove potential prefix from enum value names (PR #83412)

2024-04-15 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)

2024-04-15 Thread Edwin Vane via cfe-commits

https://github.com/revane created 
https://github.com/llvm/llvm-project/pull/88735

The handling of renaming failures and multiple usages related to those failures 
is currently spread over several functions. Identifying the failure NamedDecl 
for a given usage is also duplicated, once when creating failures and again 
when identify usages. There are currently two ways to a failed NamedDecl from a 
usage: use the canonical decl or use the overridden method. With new methods 
about to be added, a cleanup was in order.

The data flow is simplified as follows:
* The visitor always forwards NamedDecls to addUsage(NamedDecl).
* addUsage(NamedDecl) determines the failed NamedDecl and determines potential 
new names based on that failure. Usages are registered using 
addUsage(NamingCheckId).
* addUsage(NamingCheckId) is now protected and its single responsibility is 
maintaining the integrity of the failure/usage map.

>From 16271c2988994257d33a3f6b2b98254be2587b58 Mon Sep 17 00:00:00 2001
From: Edwin Vane 
Date: Thu, 28 Mar 2024 09:30:32 -0400
Subject: [PATCH] [clang-tidy] Refactor how NamedDecl are renamed

The handling of renaming failures and multiple usages related to those
failures is currently spread over several functions. Identifying the
failure NamedDecl for a given usage is also duplicated, once when
creating failures and again when identify usages. There are currently
two ways to a failed NamedDecl from a usage: use the canonical decl or
use the overridden method. With new methods about to be added, a cleanup
was in order.

The data flow is simplified as follows:
* The visitor always forwards NamedDecls to addUsage(NamedDecl).
* addUsage(NamedDecl) determines the failed NamedDecl and determines
  potential new names based on that failure. Usages are registered using
  addUsage(NamingCheckId).
* addUsage(NamingCheckId) is now protected and its single responsibility
  is maintaining the integrity of the failure/usage map.
---
 .../utils/RenamerClangTidyCheck.cpp   | 194 ++
 .../clang-tidy/utils/RenamerClangTidyCheck.h  |  14 +-
 2 files changed, 111 insertions(+), 97 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 962a243ce94d48..453d5a754f12fc 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -61,6 +61,44 @@ struct 
DenseMapInfo {
 namespace clang::tidy {
 
 namespace {
+/// Returns the function that \p Method is overridding. If There are none or
+/// multiple overrides it returns nullptr. If the overridden function itself is
+/// overridding then it will recurse up to find the first decl of the function.
+const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) {
+  if (Method->size_overridden_methods() != 1)
+return nullptr;
+
+  while (true) {
+Method = *Method->begin_overridden_methods();
+assert(Method && "Overridden method shouldn't be null");
+unsigned NumOverrides = Method->size_overridden_methods();
+if (NumOverrides == 0)
+  return Method;
+if (NumOverrides > 1)
+  return nullptr;
+  }
+}
+
+bool hasNoName(const NamedDecl *Decl) {
+  return !Decl->getIdentifier() || Decl->getName().empty();
+}
+
+const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) {
+  const auto *Canonical = cast(ND->getCanonicalDecl());
+  if (Canonical != ND)
+return Canonical;
+
+  if (const auto *Method = dyn_cast(ND)) {
+if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
+  Canonical = cast(Overridden->getCanonicalDecl());
+
+if (Canonical != ND)
+  return Canonical;
+  }
+
+  return ND;
+}
+
 class NameLookup {
   llvm::PointerIntPair Data;
 
@@ -132,24 +170,6 @@ static NameLookup findDeclInBases(const CXXRecordDecl 
&Parent,
   return NameLookup(Found); // If nullptr, decl wasn't found.
 }
 
-/// Returns the function that \p Method is overridding. If There are none or
-/// multiple overrides it returns nullptr. If the overridden function itself is
-/// overridding then it will recurse up to find the first decl of the function.
-static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) {
-  if (Method->size_overridden_methods() != 1)
-return nullptr;
-
-  while (true) {
-Method = *Method->begin_overridden_methods();
-assert(Method && "Overridden method shouldn't be null");
-unsigned NumOverrides = Method->size_overridden_methods();
-if (NumOverrides == 0)
-  return Method;
-if (NumOverrides > 1)
-  return nullptr;
-  }
-}
-
 namespace {
 
 /// Callback supplies macros to RenamerClangTidyCheck::checkMacro
@@ -192,10 +212,6 @@ class RenamerClangTidyVisitor
   : Check(Check), SM(SM),
 AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {}
 
-  static bool hasNoName(const NamedDecl *Decl) {
-return !Decl->getIdentifier() || Decl->getName

[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)

2024-04-15 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang-tidy

Author: Edwin Vane (revane)


Changes

The handling of renaming failures and multiple usages related to those failures 
is currently spread over several functions. Identifying the failure NamedDecl 
for a given usage is also duplicated, once when creating failures and again 
when identify usages. There are currently two ways to a failed NamedDecl from a 
usage: use the canonical decl or use the overridden method. With new methods 
about to be added, a cleanup was in order.

The data flow is simplified as follows:
* The visitor always forwards NamedDecls to addUsage(NamedDecl).
* addUsage(NamedDecl) determines the failed NamedDecl and determines potential 
new names based on that failure. Usages are registered using 
addUsage(NamingCheckId).
* addUsage(NamingCheckId) is now protected and its single responsibility is 
maintaining the integrity of the failure/usage map.

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


2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
(+103-91) 
- (modified) clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h (+8-6) 


``diff
diff --git a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
index 962a243ce94d48..453d5a754f12fc 100644
--- a/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
@@ -61,6 +61,44 @@ struct 
DenseMapInfo {
 namespace clang::tidy {
 
 namespace {
+/// Returns the function that \p Method is overridding. If There are none or
+/// multiple overrides it returns nullptr. If the overridden function itself is
+/// overridding then it will recurse up to find the first decl of the function.
+const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) {
+  if (Method->size_overridden_methods() != 1)
+return nullptr;
+
+  while (true) {
+Method = *Method->begin_overridden_methods();
+assert(Method && "Overridden method shouldn't be null");
+unsigned NumOverrides = Method->size_overridden_methods();
+if (NumOverrides == 0)
+  return Method;
+if (NumOverrides > 1)
+  return nullptr;
+  }
+}
+
+bool hasNoName(const NamedDecl *Decl) {
+  return !Decl->getIdentifier() || Decl->getName().empty();
+}
+
+const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) {
+  const auto *Canonical = cast(ND->getCanonicalDecl());
+  if (Canonical != ND)
+return Canonical;
+
+  if (const auto *Method = dyn_cast(ND)) {
+if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
+  Canonical = cast(Overridden->getCanonicalDecl());
+
+if (Canonical != ND)
+  return Canonical;
+  }
+
+  return ND;
+}
+
 class NameLookup {
   llvm::PointerIntPair Data;
 
@@ -132,24 +170,6 @@ static NameLookup findDeclInBases(const CXXRecordDecl 
&Parent,
   return NameLookup(Found); // If nullptr, decl wasn't found.
 }
 
-/// Returns the function that \p Method is overridding. If There are none or
-/// multiple overrides it returns nullptr. If the overridden function itself is
-/// overridding then it will recurse up to find the first decl of the function.
-static const CXXMethodDecl *getOverrideMethod(const CXXMethodDecl *Method) {
-  if (Method->size_overridden_methods() != 1)
-return nullptr;
-
-  while (true) {
-Method = *Method->begin_overridden_methods();
-assert(Method && "Overridden method shouldn't be null");
-unsigned NumOverrides = Method->size_overridden_methods();
-if (NumOverrides == 0)
-  return Method;
-if (NumOverrides > 1)
-  return nullptr;
-  }
-}
-
 namespace {
 
 /// Callback supplies macros to RenamerClangTidyCheck::checkMacro
@@ -192,10 +212,6 @@ class RenamerClangTidyVisitor
   : Check(Check), SM(SM),
 AggressiveDependentMemberLookup(AggressiveDependentMemberLookup) {}
 
-  static bool hasNoName(const NamedDecl *Decl) {
-return !Decl->getIdentifier() || Decl->getName().empty();
-  }
-
   bool shouldVisitTemplateInstantiations() const { return true; }
 
   bool shouldVisitImplicitCode() const { return false; }
@@ -246,29 +262,10 @@ class RenamerClangTidyVisitor
   }
 
   bool VisitNamedDecl(NamedDecl *Decl) {
-if (hasNoName(Decl))
-  return true;
-
-const auto *Canonical = cast(Decl->getCanonicalDecl());
-if (Canonical != Decl) {
-  Check->addUsage(Canonical, Decl->getLocation(), SM);
-  return true;
-}
-
-// Fix overridden methods
-if (const auto *Method = dyn_cast(Decl)) {
-  if (const CXXMethodDecl *Overridden = getOverrideMethod(Method)) {
-Check->addUsage(Overridden, Method->getLocation(), SM);
-return true; // Don't try to add the actual decl as a Failure.
-  }
-}
-
-// Ignore ClassTemplateSpecializationDecl which are creating duplicate
-// replacements with CXXRecordDecl.
-

[clang] [PATCH] [clang-repl] Builtin Type printing in ValuePrinter.cpp (PR #88729)

2024-04-15 Thread via cfe-commits

https://github.com/wlonestar updated 
https://github.com/llvm/llvm-project/pull/88729

>From c953691de3eda4b72e16d215a6a0e5d230742c59 Mon Sep 17 00:00:00 2001
From: wlonestar <68649094+wlones...@users.noreply.github.com>
Date: Mon, 15 Apr 2024 13:12:55 +
Subject: [PATCH 1/2] [PATCH] [clang-repl] Builtin Type printing in
 ValuePrinter.cpp

---
 clang/include/clang/Interpreter/Interpreter.h |   2 +
 clang/include/clang/Interpreter/Value.h   |   8 +-
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/IncrementalParser.h |   1 +
 clang/lib/Interpreter/Interpreter.cpp |   8 +-
 clang/lib/Interpreter/InterpreterUtils.cpp|   2 +-
 clang/lib/Interpreter/InterpreterUtils.h  |   2 +-
 clang/lib/Interpreter/Value.cpp   |  13 +-
 clang/lib/Interpreter/ValuePrinter.cpp| 751 ++
 9 files changed, 779 insertions(+), 9 deletions(-)
 create mode 100644 clang/lib/Interpreter/ValuePrinter.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 970e0245417b51..3be29bd75cfca7 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -149,6 +149,8 @@ class Interpreter {
   CompilerInstance *getCompilerInstance();
   llvm::Expected getExecutionEngine();
 
+  Sema &getSema() const;
+
   llvm::Expected Parse(llvm::StringRef Code);
   llvm::Error Execute(PartialTranslationUnit &T);
   llvm::Error ParseAndExecute(llvm::StringRef Code, Value *V = nullptr);
diff --git a/clang/include/clang/Interpreter/Value.h 
b/clang/include/clang/Interpreter/Value.h
index d70e8f8719026b..186299a84db444 100644
--- a/clang/include/clang/Interpreter/Value.h
+++ b/clang/include/clang/Interpreter/Value.h
@@ -35,6 +35,7 @@
 
 #include "llvm/Support/Compiler.h"
 #include 
+#include 
 
 // NOTE: Since the REPL itself could also include this runtime, extreme caution
 // should be taken when MAKING CHANGES to this file, especially when INCLUDE 
NEW
@@ -117,6 +118,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Value &operator=(Value &&RHS) noexcept;
   ~Value();
 
+  std::string printValueInternal() const;
+
   void printType(llvm::raw_ostream &Out) const;
   void printData(llvm::raw_ostream &Out) const;
   void print(llvm::raw_ostream &Out) const;
@@ -126,7 +129,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
   ASTContext &getASTContext();
   const ASTContext &getASTContext() const;
   Interpreter &getInterpreter();
-  const Interpreter &getInterpreter() const;
+  Interpreter &getInterpreter() const;
   QualType getType() const;
 
   bool isValid() const { return ValueKind != K_Unspecified; }
@@ -136,6 +139,8 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Kind getKind() const { return ValueKind; }
   void setKind(Kind K) { ValueKind = K; }
   void setOpaqueType(void *Ty) { OpaqueType = Ty; }
+  void setName(std::string name) { Name = name; }
+  std::string getName() const { return Name; }
 
   void *getPtr() const;
   void setPtr(void *Ptr) { Data.m_Ptr = Ptr; }
@@ -197,6 +202,7 @@ class REPL_EXTERNAL_VISIBILITY Value {
   Storage Data;
   Kind ValueKind = K_Unspecified;
   bool IsManuallyAlloc = false;
+  std::string Name;
 };
 
 template <> inline void *Value::as() const {
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 9065f998f73c47..ea00bdc80f595d 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterUtils.cpp
   Value.cpp
+  ValuePrinter.cpp
 
   DEPENDS
   intrinsics_gen
diff --git a/clang/lib/Interpreter/IncrementalParser.h 
b/clang/lib/Interpreter/IncrementalParser.h
index e13b74c7f65948..c9acc59b1ed602 100644
--- a/clang/lib/Interpreter/IncrementalParser.h
+++ b/clang/lib/Interpreter/IncrementalParser.h
@@ -67,6 +67,7 @@ class IncrementalParser {
 
   CompilerInstance *getCI() { return CI.get(); }
   CodeGenerator *getCodeGen() const;
+  Parser &getParser() const { return *P; }
 
   /// Parses incremental input by creating an in-memory file.
   ///\returns a \c PartialTranslationUnit which holds information about the
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index cf31456b6950ac..aa6f6657670bca 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -336,6 +336,8 @@ llvm::Expected 
Interpreter::getExecutionEngine() {
   return IncrExecutor->GetExecutionEngine();
 }
 
+Sema &Interpreter::getSema() const { return getCompilerInstance()->getSema(); }
+
 ASTContext &Interpreter::getASTContext() {
   return getCompilerInstance()->getASTContext();
 }
@@ -427,7 +429,7 @@ llvm::Error Interpreter::Execute(PartialTranslationUnit &T) 
{
 }
 
 llvm::Error Interpreter::ParseAndExecute(llvm::StringRef Code, Value *V) {
-
+  std::string name = Code.str();
   auto PTU = Parse(Code);
   if (!PTU)
 retu

[clang] [X86][test] Added extra cet tests (PR #88736)

2024-04-15 Thread Isha Agarwal via cfe-commits

https://github.com/iagarwa created 
https://github.com/llvm/llvm-project/pull/88736

Updated cet test to:
-Check different modules based on different cet options
-Added negative tests also

>From 2ee7dd40b0f2c4eed6d8631d60a31372785a2d6e Mon Sep 17 00:00:00 2001
From: Isha Agarwal 
Date: Mon, 15 Apr 2024 06:22:34 -0700
Subject: [PATCH] [X86][test] Added extra cet tests

Updated cet test to:
-Check different modules based on different cet options
-Added negative tests also

Signed-off-by: Isha Agarwal 
---
 clang/test/CodeGen/X86/x86-cf-protection.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang/test/CodeGen/X86/x86-cf-protection.c 
b/clang/test/CodeGen/X86/x86-cf-protection.c
index ba63b9e17c6f63..abc6ed63d61289 100644
--- a/clang/test/CodeGen/X86/x86-cf-protection.c
+++ b/clang/test/CodeGen/X86/x86-cf-protection.c
@@ -2,6 +2,10 @@
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=branch %s | 
FileCheck %s --check-prefix=BRANCH
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=full %s   | 
FileCheck %s --check-prefix=FULL
 // RUN: not %clang_cc1 -emit-llvm-only -triple i386 -target-cpu pentium-mmx 
-fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=NOCFPROT
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=branch %s -emit-llvm | 
FileCheck %s --check-prefix=CFPROT
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=full %s -emit-llvm | 
FileCheck %s --check-prefix=CFPROTF
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=none %s -emit-llvm | 
FileCheck %s --check-prefix=CFPROTNONE
+// RUN: %clang_cc1 -E -triple=x86_64 -dM -o - -fcf-protection=none %s | 
FileCheck %s --check-prefix=NOTCET
 
 // RETURN: #define __CET__ 2
 // BRANCH: #define __CET__ 1
@@ -9,5 +13,9 @@
 // CFPROT: !{i32 8, !"cf-protection-branch", i32 1}
 
 // NOCFPROT: error: option 'cf-protection=branch' cannot be specified on this 
target
+// CFPROTF: !{i32 8, !"cf-protection-return", i32 1}
+// CFPROTF-NEXT: !{i32 8, !"cf-protection-branch", i32 1}
+// CFPROTNONE-NOT: cf-protection-branch
+// NOTCET-NOT: #define __CET__
 
 void foo() {}

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


[clang-tools-extra] [clang-tidy] Refactor how NamedDecl are renamed (PR #88735)

2024-04-15 Thread Edwin Vane via cfe-commits

revane wrote:

@PiotrZSL Second-last in the sequence of PRs which fix another renaming issue.

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


[clang] [X86][test] Added extra cet tests (PR #88736)

2024-04-15 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [X86][test] Added extra cet tests (PR #88736)

2024-04-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Isha Agarwal (iagarwa)


Changes

Updated cet test to:
-Check different modules based on different cet options
-Added negative tests also

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


1 Files Affected:

- (modified) clang/test/CodeGen/X86/x86-cf-protection.c (+8) 


``diff
diff --git a/clang/test/CodeGen/X86/x86-cf-protection.c 
b/clang/test/CodeGen/X86/x86-cf-protection.c
index ba63b9e17c6f63..abc6ed63d61289 100644
--- a/clang/test/CodeGen/X86/x86-cf-protection.c
+++ b/clang/test/CodeGen/X86/x86-cf-protection.c
@@ -2,6 +2,10 @@
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=branch %s | 
FileCheck %s --check-prefix=BRANCH
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=full %s   | 
FileCheck %s --check-prefix=FULL
 // RUN: not %clang_cc1 -emit-llvm-only -triple i386 -target-cpu pentium-mmx 
-fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=NOCFPROT
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=branch %s -emit-llvm | 
FileCheck %s --check-prefix=CFPROT
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=full %s -emit-llvm | 
FileCheck %s --check-prefix=CFPROTF
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=none %s -emit-llvm | 
FileCheck %s --check-prefix=CFPROTNONE
+// RUN: %clang_cc1 -E -triple=x86_64 -dM -o - -fcf-protection=none %s | 
FileCheck %s --check-prefix=NOTCET
 
 // RETURN: #define __CET__ 2
 // BRANCH: #define __CET__ 1
@@ -9,5 +13,9 @@
 // CFPROT: !{i32 8, !"cf-protection-branch", i32 1}
 
 // NOCFPROT: error: option 'cf-protection=branch' cannot be specified on this 
target
+// CFPROTF: !{i32 8, !"cf-protection-return", i32 1}
+// CFPROTF-NEXT: !{i32 8, !"cf-protection-branch", i32 1}
+// CFPROTNONE-NOT: cf-protection-branch
+// NOTCET-NOT: #define __CET__
 
 void foo() {}

``




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


[clang] [clang][dataflow] Fix result object location for builtin `<=>`. (PR #88726)

2024-04-15 Thread Yitzhak Mandelbaum via cfe-commits

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


[clang] [clang][dataflow] Fix result object location for builtin `<=>`. (PR #88726)

2024-04-15 Thread Yitzhak Mandelbaum via cfe-commits


@@ -508,6 +508,11 @@ class ResultObjectVisitor : public 
RecursiveASTVisitor {
 isa(E)) {
   return;
 }
+if (auto *Op = dyn_cast(E);

ymand wrote:

aside: Might lines 506 through 553 be better expressed as a switch on 
`E->getStmtClass()`?

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


[clang] [clang][dataflow] Fix result object location for builtin `<=>`. (PR #88726)

2024-04-15 Thread Yitzhak Mandelbaum via cfe-commits

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


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


[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

2024-04-15 Thread Erich Keane via cfe-commits


@@ -3903,7 +3904,14 @@ bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation 
Loc) {
   if (R.isInvalid())
 return true;
 
-  bool ValueIsPositive = ValueAPS.isStrictlyPositive();
+  // GCC allows the value of unroll count to be 0.
+  // https://gcc.gnu.org/onlinedocs/gcc/Loop-Specific-Pragmas.html says
+  // "The values of 0 and 1 block any unrolling of the loop."
+  // The values doesn't have to be strictly positive in '#pragma GCC unroll' 
and
+  // '#pragma unroll' cases.
+  bool ValueIsPositive = PragmaNameInfo->isStr("unroll")

erichkeane wrote:

I'd very much like to keep this checking of the name OUT of Sema here, and have 
the function just take a bool for `IsPragmaUnroll` or something.

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


  1   2   3   4   5   >