[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Jay Foad via cfe-commits

https://github.com/jayfoad updated 
https://github.com/llvm/llvm-project/pull/65729

>From 66129acffd34a4b0f2c8a956d88212ed2ee30946 Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Fri, 8 Sep 2023 10:09:21 +0100
Subject: [PATCH] Clean up strange uses of getAnalysisIfAvailable

After a pass calls addRequired() it is strange to call
getAnalysisIfAvailable() because analysis X should always be
available. Use getAnalysis() instead.
---
 llvm/lib/CodeGen/EarlyIfConversion.cpp | 4 ++--
 llvm/lib/CodeGen/TypePromotion.cpp | 7 ++-
 llvm/lib/CodeGen/VirtRegMap.cpp| 2 +-
 llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp | 2 +-
 llvm/lib/Transforms/Scalar/GVN.cpp | 4 ++--
 5 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/CodeGen/EarlyIfConversion.cpp 
b/llvm/lib/CodeGen/EarlyIfConversion.cpp
index 61867d74bfa293c..3086d953a23699f 100644
--- a/llvm/lib/CodeGen/EarlyIfConversion.cpp
+++ b/llvm/lib/CodeGen/EarlyIfConversion.cpp
@@ -1092,7 +1092,7 @@ bool 
EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
   SchedModel = STI.getSchedModel();
   MRI = &MF.getRegInfo();
   DomTree = &getAnalysis();
-  Loops = getAnalysisIfAvailable();
+  Loops = &getAnalysis();
   Traces = &getAnalysis();
   MinInstr = nullptr;
 
@@ -1226,7 +1226,7 @@ bool 
EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
   MRI = &MF.getRegInfo();
   SchedModel.init(&STI);
   DomTree = &getAnalysis();
-  Loops = getAnalysisIfAvailable();
+  Loops = &getAnalysis();
   MBPI = &getAnalysis();
 
   bool Changed = false;
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp 
b/llvm/lib/CodeGen/TypePromotion.cpp
index 426292345a1478a..9deeb0d090595b7 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -1014,11 +1014,8 @@ bool TypePromotionLegacy::runOnFunction(Function &F) {
   if (skipFunction(F))
 return false;
 
-  auto *TPC = getAnalysisIfAvailable();
-  if (!TPC)
-return false;
-
-  auto *TM = &TPC->getTM();
+  auto &TPC = getAnalysis();
+  auto *TM = &TPC.getTM();
   auto &TTI = getAnalysis().getTTI(F);
   auto &LI = getAnalysis().getLoopInfo();
 
diff --git a/llvm/lib/CodeGen/VirtRegMap.cpp b/llvm/lib/CodeGen/VirtRegMap.cpp
index c1c6ce227334a4b..6e29a41b617a87e 100644
--- a/llvm/lib/CodeGen/VirtRegMap.cpp
+++ b/llvm/lib/CodeGen/VirtRegMap.cpp
@@ -261,7 +261,7 @@ bool VirtRegRewriter::runOnMachineFunction(MachineFunction 
&fn) {
   Indexes = &getAnalysis();
   LIS = &getAnalysis();
   VRM = &getAnalysis();
-  DebugVars = getAnalysisIfAvailable();
+  DebugVars = &getAnalysis();
   LLVM_DEBUG(dbgs() << "** REWRITE VIRTUAL REGISTERS **\n"
 << "** Function: " << MF->getName() << '\n');
   LLVM_DEBUG(VRM->dump());
diff --git a/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp 
b/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
index 4c8c03a4c693fe1..ad0ff8335647419 100644
--- a/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
@@ -935,7 +935,7 @@ bool 
AArch64ConditionalCompares::runOnMachineFunction(MachineFunction &MF) {
   SchedModel = MF.getSubtarget().getSchedModel();
   MRI = &MF.getRegInfo();
   DomTree = &getAnalysis();
-  Loops = getAnalysisIfAvailable();
+  Loops = &getAnalysis();
   MBPI = &getAnalysis();
   Traces = &getAnalysis();
   MinInstr = nullptr;
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index 635e56ec6012297..aaf117a3a084afd 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -3280,7 +3280,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
 if (skipFunction(F))
   return false;
 
-auto *LIWP = getAnalysisIfAvailable();
+auto &LIWP = getAnalysis();
 
 auto *MSSAWP = getAnalysisIfAvailable();
 return Impl.runImpl(
@@ -3291,7 +3291,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
 Impl.isMemDepEnabled()
 ? &getAnalysis().getMemDep()
 : nullptr,
-LIWP ? &LIWP->getLoopInfo() : nullptr,
+&LIWP.getLoopInfo(),
 &getAnalysis().getORE(),
 MSSAWP ? &MSSAWP->getMSSA() : nullptr);
   }

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


[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Jay Foad (jayfoad)


Changes

After a pass calls addRequired() it is strange to call
getAnalysisIfAvailable() because analysis X should always be
available. Use getAnalysis() instead.


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


5 Files Affected:

- (modified) llvm/lib/CodeGen/EarlyIfConversion.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/TypePromotion.cpp (+2-5) 
- (modified) llvm/lib/CodeGen/VirtRegMap.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+2-2) 


``diff
diff --git a/llvm/lib/CodeGen/EarlyIfConversion.cpp 
b/llvm/lib/CodeGen/EarlyIfConversion.cpp
index 61867d74bfa293c..3086d953a23699f 100644
--- a/llvm/lib/CodeGen/EarlyIfConversion.cpp
+++ b/llvm/lib/CodeGen/EarlyIfConversion.cpp
@@ -1092,7 +1092,7 @@ bool 
EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
   SchedModel = STI.getSchedModel();
   MRI = &MF.getRegInfo();
   DomTree = &getAnalysis();
-  Loops = getAnalysisIfAvailable();
+  Loops = &getAnalysis();
   Traces = &getAnalysis();
   MinInstr = nullptr;
 
@@ -1226,7 +1226,7 @@ bool 
EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
   MRI = &MF.getRegInfo();
   SchedModel.init(&STI);
   DomTree = &getAnalysis();
-  Loops = getAnalysisIfAvailable();
+  Loops = &getAnalysis();
   MBPI = &getAnalysis();
 
   bool Changed = false;
diff --git a/llvm/lib/CodeGen/TypePromotion.cpp 
b/llvm/lib/CodeGen/TypePromotion.cpp
index 51f77e5fd8b08af..053caf518bd1f78 100644
--- a/llvm/lib/CodeGen/TypePromotion.cpp
+++ b/llvm/lib/CodeGen/TypePromotion.cpp
@@ -1016,11 +1016,8 @@ bool TypePromotionLegacy::runOnFunction(Function &F) {
   if (skipFunction(F))
 return false;
 
-  auto *TPC = getAnalysisIfAvailable();
-  if (!TPC)
-return false;
-
-  auto *TM = &TPC->getTM();
+  auto &TPC = getAnalysis();
+  auto *TM = &TPC.getTM();
   auto &TTI = getAnalysis().getTTI(F);
   auto &LI = getAnalysis().getLoopInfo();
 
diff --git a/llvm/lib/CodeGen/VirtRegMap.cpp b/llvm/lib/CodeGen/VirtRegMap.cpp
index c1c6ce227334a4b..6e29a41b617a87e 100644
--- a/llvm/lib/CodeGen/VirtRegMap.cpp
+++ b/llvm/lib/CodeGen/VirtRegMap.cpp
@@ -261,7 +261,7 @@ bool VirtRegRewriter::runOnMachineFunction(MachineFunction 
&fn) {
   Indexes = &getAnalysis();
   LIS = &getAnalysis();
   VRM = &getAnalysis();
-  DebugVars = getAnalysisIfAvailable();
+  DebugVars = &getAnalysis();
   LLVM_DEBUG(dbgs() << "** REWRITE VIRTUAL REGISTERS **\n"
 << "** Function: " << MF->getName() << '\n');
   LLVM_DEBUG(VRM->dump());
diff --git a/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp 
b/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
index 4c8c03a4c693fe1..ad0ff8335647419 100644
--- a/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ConditionalCompares.cpp
@@ -935,7 +935,7 @@ bool 
AArch64ConditionalCompares::runOnMachineFunction(MachineFunction &MF) {
   SchedModel = MF.getSubtarget().getSchedModel();
   MRI = &MF.getRegInfo();
   DomTree = &getAnalysis();
-  Loops = getAnalysisIfAvailable();
+  Loops = &getAnalysis();
   MBPI = &getAnalysis();
   Traces = &getAnalysis();
   MinInstr = nullptr;
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index 4c5b0ff3af16e53..f419d03c0ce3837 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -3286,7 +3286,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
 if (skipFunction(F))
   return false;
 
-auto *LIWP = getAnalysisIfAvailable();
+auto &LIWP = getAnalysis();
 
 auto *MSSAWP = getAnalysisIfAvailable();
 return Impl.runImpl(
@@ -3297,7 +3297,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
 Impl.isMemDepEnabled()
 ? &getAnalysis().getMemDep()
 : nullptr,
-LIWP ? &LIWP->getLoopInfo() : nullptr,
+&LIWP.getLoopInfo(),
 &getAnalysis().getORE(),
 MSSAWP ? &MSSAWP->getMSSA() : nullptr);
   }

``




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


[clang] [clang][C2x] Remove confusing diagnostic auto storage class specifier (PR #68710)

2023-10-11 Thread via cfe-commits

cor3ntin wrote:

You should just be able to click "squash and merge", no?

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


[clang] [clang][C2x] Remove confusing diagnostic auto storage class specifier (PR #68710)

2023-10-11 Thread Guillot Tony via cfe-commits

to268 wrote:

Nope, I can't
> This branch has no conflicts with the base branch
Only those with [write 
access](https://docs.github.com/articles/what-are-the-different-access-permissions)
 to this repository can merge pull requests.

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


[clang] c3f67b3 - [clang][Interp] Limit MaxBitInt to 128 bits

2023-10-11 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-11T09:48:28+02:00
New Revision: c3f67b3ba9c8cf1677c7ee2a42a6ebd35fdcc763

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

LOG: [clang][Interp] Limit MaxBitInt to 128 bits

Looks like larger bitints aren't supported everywhere.

Added: 


Modified: 
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 547e0a90d0da5de..ba9f28f2da4ab05 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -std=c++20 -fms-extensions -verify=ref %s
 
 
-using MaxBitInt = _BitInt(8388608);
+using MaxBitInt = _BitInt(128);
 
 constexpr _BitInt(2) A = 0;
 constexpr _BitInt(2) B = A + 1;



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


[clang] [clang][ASTImporter] Fix crash when template class static member impo… (PR #68774)

2023-10-11 Thread via cfe-commits

https://github.com/mzyKi created https://github.com/llvm/llvm-project/pull/68774

…rted to other translation unit.

Fixes: #68769 https://github.com/llvm/llvm-project/issues/68769

>From 1c3b9f6696842230b49962531c065956a1b3ab8c Mon Sep 17 00:00:00 2001
From: miaozhiyuan 
Date: Wed, 11 Oct 2023 15:45:36 +0800
Subject: [PATCH] [clang][ASTImporter] Fix crash when template class static
 member imported to other translation unit. Fixes: #68769
 https://github.com/llvm/llvm-project/issues/68769

---
 clang/docs/ReleaseNotes.rst   |  4 
 clang/lib/AST/ASTImporter.cpp |  3 ++-
 .../Inputs/externalDefMap.txt |  1 +
 .../Inputs/template-class-static-member.cpp   |  3 +++
 .../Inputs/template-class-static-member.h |  7 +++
 .../ctu/template-class-static-member/main.cpp | 19 +++
 6 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/Analysis/ctu/template-class-static-member/Inputs/externalDefMap.txt
 create mode 100644 
clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.cpp
 create mode 100644 
clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.h
 create mode 100644 
clang/test/Analysis/ctu/template-class-static-member/main.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..3be9e60c82a18d0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -497,6 +497,10 @@ Bug Fixes to C++ Support
   rather than prefer the non-templated constructor as specified in
   [standard.group]p3.
 
+- Fix crash when template class static member imported to other translation 
unit.
+  Fixes:
+  (`#68769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 72e70427161bb0e..5c9a3eda58d2252 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4358,7 +4358,8 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
   // Try to find a variable in our own ("to") context with the same name and
   // in the same context as the variable we're importing.
   VarDecl *FoundByLookup = nullptr;
-  if (D->isFileVarDecl()) {
+  MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo();
+  if (D->isFileVarDecl() && !MSI) {
 SmallVector ConflictingDecls;
 unsigned IDNS = Decl::IDNS_Ordinary;
 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
diff --git 
a/clang/test/Analysis/ctu/template-class-static-member/Inputs/externalDefMap.txt
 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/externalDefMap.txt
new file mode 100644
index 000..2cc394701d12e1d
--- /dev/null
+++ 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/externalDefMap.txt
@@ -0,0 +1 @@
+19:c:@S@Test>#I@length template-class-static-member.cpp.ast
diff --git 
a/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.cpp
 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.cpp
new file mode 100644
index 000..489aa41aec70452
--- /dev/null
+++ 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.cpp
@@ -0,0 +1,3 @@
+#include "template-class-static-member.h"
+
+template<> const unsigned int Test::length = 0;
diff --git 
a/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.h
 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.h
new file mode 100644
index 000..f31d05728594a9a
--- /dev/null
+++ 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.h
@@ -0,0 +1,7 @@
+template  class Test
+{
+public:
+   static const unsigned int length;
+};
+
+template<> const unsigned int Test::length;
diff --git a/clang/test/Analysis/ctu/template-class-static-member/main.cpp 
b/clang/test/Analysis/ctu/template-class-static-member/main.cpp
new file mode 100644
index 000..ef4216ae4e28517
--- /dev/null
+++ b/clang/test/Analysis/ctu/template-class-static-member/main.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu \
+// RUN: -emit-pch -o %t/ctudir/template-class-static-member.cpp.ast 
%p/Inputs/template-class-static-member.cpp
+// RUN: cp %p/Inputs/externalDefMap.txt %t/ctudir/externalDefMap.txt
+// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu \
+// RUN: -analyzer-checker=core.DivideZero \
+// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN: -analyzer-config ctu-dir=%t/ctudir \
+// RUN: -analyzer-config display-ctu-progress=true 2>&1 %s | FileCheck %s
+
+
+// CHECK: CTU loaded AST file: {{.*}}template-class-stat

[clang] [clang][ASTImporter] Fix crash when template class static member impo… (PR #68774)

2023-10-11 Thread via cfe-commits

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


[clang] [clang][ASTImporter] Fix crash when template class static member impo… (PR #68774)

2023-10-11 Thread via cfe-commits

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


[clang] [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-11 Thread via cfe-commits

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


[clang] [clang][Interp] IntegralAP zero-init (PR #68081)

2023-10-11 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Only emit function_param_value_unknown in C++11 (PR #67990)

2023-10-11 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[PATCH] D93829: [clangd] Support outgoing calls in call hierarchy

2023-10-11 Thread Nathan Ridge via Phabricator via cfe-commits
nridge commandeered this revision.
nridge added a reviewer: qchateau.
nridge added a comment.

In D93829#4422090 , @qchateau wrote:

> So if anyone wants to take it from there, feel free to reuse my commits (or 
> not).

I'm going to pick up this work and try to address Sam's review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93829

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


[clang] [clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Exile (mzyKi)


Changes

Fixes: #68769

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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/lib/AST/ASTImporter.cpp (+2-1) 
- (added) 
clang/test/Analysis/ctu/template-class-static-member/Inputs/externalDefMap.txt 
(+1) 
- (added) 
clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.cpp
 (+3) 
- (added) 
clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.h
 (+7) 
- (added) clang/test/Analysis/ctu/template-class-static-member/main.cpp (+19) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..3be9e60c82a18d0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -497,6 +497,10 @@ Bug Fixes to C++ Support
   rather than prefer the non-templated constructor as specified in
   [standard.group]p3.
 
+- Fix crash when template class static member imported to other translation 
unit.
+  Fixes:
+  (`#68769 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 72e70427161bb0e..5c9a3eda58d2252 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4358,7 +4358,8 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
   // Try to find a variable in our own ("to") context with the same name and
   // in the same context as the variable we're importing.
   VarDecl *FoundByLookup = nullptr;
-  if (D->isFileVarDecl()) {
+  MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo();
+  if (D->isFileVarDecl() && !MSI) {
 SmallVector ConflictingDecls;
 unsigned IDNS = Decl::IDNS_Ordinary;
 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
diff --git 
a/clang/test/Analysis/ctu/template-class-static-member/Inputs/externalDefMap.txt
 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/externalDefMap.txt
new file mode 100644
index 000..2cc394701d12e1d
--- /dev/null
+++ 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/externalDefMap.txt
@@ -0,0 +1 @@
+19:c:@S@Test>#I@length template-class-static-member.cpp.ast
diff --git 
a/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.cpp
 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.cpp
new file mode 100644
index 000..489aa41aec70452
--- /dev/null
+++ 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.cpp
@@ -0,0 +1,3 @@
+#include "template-class-static-member.h"
+
+template<> const unsigned int Test::length = 0;
diff --git 
a/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.h
 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.h
new file mode 100644
index 000..f31d05728594a9a
--- /dev/null
+++ 
b/clang/test/Analysis/ctu/template-class-static-member/Inputs/template-class-static-member.h
@@ -0,0 +1,7 @@
+template  class Test
+{
+public:
+   static const unsigned int length;
+};
+
+template<> const unsigned int Test::length;
diff --git a/clang/test/Analysis/ctu/template-class-static-member/main.cpp 
b/clang/test/Analysis/ctu/template-class-static-member/main.cpp
new file mode 100644
index 000..ef4216ae4e28517
--- /dev/null
+++ b/clang/test/Analysis/ctu/template-class-static-member/main.cpp
@@ -0,0 +1,19 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu \
+// RUN: -emit-pch -o %t/ctudir/template-class-static-member.cpp.ast 
%p/Inputs/template-class-static-member.cpp
+// RUN: cp %p/Inputs/externalDefMap.txt %t/ctudir/externalDefMap.txt
+// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu \
+// RUN: -analyzer-checker=core.DivideZero \
+// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN: -analyzer-config ctu-dir=%t/ctudir \
+// RUN: -analyzer-config display-ctu-progress=true 2>&1 %s | FileCheck %s
+
+
+// CHECK: CTU loaded AST file: {{.*}}template-class-static-member.cpp.ast
+
+#include "Inputs/template-class-static-member.h"
+
+void foo(){
+int i = 1 / Test::length;
+}

``




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


[clang] [clang][C2x] Remove confusing diagnostic auto storage class specifier (PR #68710)

2023-10-11 Thread via cfe-commits

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


[clang] d5444ab - [clang][C2x] Remove confusing diagnostic auto storage class specifier (#68710)

2023-10-11 Thread via cfe-commits

Author: Guillot Tony
Date: 2023-10-11T09:51:46+02:00
New Revision: d5444ab26743115e42e4abb3782bbefb0e8912d0

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

LOG: [clang][C2x] Remove confusing diagnostic auto storage class specifier 
(#68710)

When declaring `auto int` at local or file scope, we emit a warning
intended for C++11 and later, which is incorrect and confusing in C23.
See [Godbolt example](https://godbolt.org/z/j1acGhecd).
Now this diagnostic does not show up in C23.

Added: 


Modified: 
clang/lib/Parse/ParseDecl.cpp
clang/test/C/C2x/n3007.c
clang/test/Sema/c2x-auto.c

Removed: 




diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index bcc70c04dec91ba..14a28e5a31c57db 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4042,7 +4042,7 @@ void Parser::ParseDeclarationSpecifiers(
 if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
   isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc,
  PrevSpec, DiagID, Policy);
-  if (!isInvalid)
+  if (!isInvalid && !getLangOpts().C23)
 Diag(Tok, diag::ext_auto_storage_class)
   << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
 } else

diff  --git a/clang/test/C/C2x/n3007.c b/clang/test/C/C2x/n3007.c
index 1fd20332ceb4715..34ec419b71b271d 100644
--- a/clang/test/C/C2x/n3007.c
+++ b/clang/test/C/C2x/n3007.c
@@ -3,6 +3,10 @@
 /* WG14 N3007: Yes
  * Type Inference for object definitions
  */
+void test_auto_int(void) {
+  auto int auto_int = 12;
+}
+
 void test_qualifiers(int x, const int y, int * restrict z) {
   const auto a = x;
   auto b = y;

diff  --git a/clang/test/Sema/c2x-auto.c b/clang/test/Sema/c2x-auto.c
index 916c179adcf3182..7cbd1db31315aef 100644
--- a/clang/test/Sema/c2x-auto.c
+++ b/clang/test/Sema/c2x-auto.c
@@ -4,6 +4,7 @@ void test_basic_types(void) {
   auto undefined; // expected-error {{declaration of variable 'undefined' 
with deduced type 'auto' requires an initializer}}
   auto auto_int = 4;
   auto auto_long = 4UL;
+  auto int auto_int_ts = 12;
   signed auto a = 1L; // expected-error {{'auto' cannot be signed or unsigned}}
 
   _Static_assert(_Generic(auto_int, int : 1));



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


[PATCH] D93829: [clangd] Support outgoing calls in call hierarchy

2023-10-11 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

To be able to reason about the impact of various memory usage optimizations, I 
took some baseline measurements.

I used a workload consisting of the LLVM codebase, with the 
compile_commands.json entries filtered to those containing `clang/lib` or 
`clang-tools-extra/clangd`, a total of 1082 source files. (This is what I 
happen to use for local clangd development, but I also think it strikes a good 
balance between being large enough to be representative but not so large that 
taking local measurements is too much of a hassle.)

I measured the memory usage of the background index by performing the `clangd: 
show memory usage` command.

Without this patch (baseline): background_index 560MB (index 372MB, slabs 187MB)
With the patch in its current state: background_index 606MB (index 418MB, slabs 
187MB)

This is an increase of (606 - 560) / 560 = 8.2% over basline, which is 
consistent with previous reports of 5-10%.

My plan going forward is to implement some of the suggested memory usage 
optimizations, and measure their impact.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93829

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


[clang-tools-extra] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-10-11 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Gentle ping.

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


[clang] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-10-11 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Gentle ping.

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


[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Jay Foad via cfe-commits

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


[clang-tools-extra] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Jay Foad via cfe-commits

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


[clang] 4803ba9 - [clang][Interp] Remove expected-no-directives lines

2023-10-11 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-11T10:54:04+02:00
New Revision: 4803ba9ecbfcc9cd4be4d2ff4736ca510bd2ebd1

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

LOG: [clang][Interp] Remove expected-no-directives lines

We now always have expected output.

Added: 


Modified: 
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index ba9f28f2da4ab05..8fe65a69a4fee8d 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -90,10 +90,4 @@ namespace i128 {
// expected-error {{must be 
initialized by a constant expression}} \
// expected-note {{is outside the 
range of representable values of type}}
 }
-
-#else
-/// No int128 support, so no expected directives.
-
-// expected-no-diagnostics
-// ref-no-diagnostics
 #endif



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


[clang-tools-extra] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Björn Pettersson via cfe-commits

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


[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Björn Pettersson via cfe-commits


@@ -3280,7 +3280,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
 if (skipFunction(F))
   return false;
 
-auto *LIWP = getAnalysisIfAvailable();
+auto &LIWP = getAnalysis();

bjope wrote:

IIUC GVN doesn't depend on LoopInfo itself. It should just make sure to 
preserve it if it is available. So one might wonder if it is the addRequire 
that should be questioned and possibly removed instead.
But it's been like this for years (that it is required), and messing around 
with the legacy PM analysis dependencies for an IR pass (even if it is used by 
some backends) is perhaps not worth it.

Therefore I think you proposed change is ok. Or you could just leave this as 
is, since the IfAvailable part in some sense indicate that the pass itself 
doesn't depend on the analysis.

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


[clang-tools-extra] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Björn Pettersson via cfe-commits

https://github.com/bjope commented:

I guess I don't know how pull requests and reviewing works in github. I 
actually added 3 comments on this patch a several days (or weeks) ago. But 
turns out that they were "pending" because I had only "started review" and not 
found the place to "submit review".

So sorry for some late comments here. Since this has been pushed already, then 
I guess you may ignore them. 

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


[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Björn Pettersson via cfe-commits


@@ -261,7 +261,7 @@ bool VirtRegRewriter::runOnMachineFunction(MachineFunction 
&fn) {
   Indexes = &getAnalysis();
   LIS = &getAnalysis();
   VRM = &getAnalysis();
-  DebugVars = getAnalysisIfAvailable();
+  DebugVars = &getAnalysis();

bjope wrote:

Not sure how to add a comment on line 278 if I want to suggest an edit on that 
line (in Phabricator it would have been easy). But I guess the check if 
DebugVars is null or not on line 278 is redundant now.

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


[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Björn Pettersson via cfe-commits

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


[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Björn Pettersson via cfe-commits


@@ -935,7 +935,7 @@ bool 
AArch64ConditionalCompares::runOnMachineFunction(MachineFunction &MF) {
   SchedModel = MF.getSubtarget().getSchedModel();
   MRI = &MF.getRegInfo();
   DomTree = &getAnalysis();
-  Loops = getAnalysisIfAvailable();
+  Loops = &getAnalysis();

bjope wrote:

I think there are some "weird" things going on here. But maybe not worth 
digging into those unless being an AArch64 maintainer.

Afaict the goal here is to make sure MachineLoopInfo is preserved. So this pass 
shouldn't really need to require it explicitly. However, the 
MachineTraceMetrics pass is also using MachineLoopInfo transitively. So, the 
MachineLoopInfo analysis will be run. Although I think there is a "bug" in 
MachineTraceMetrics related to not using addRequiredTransitive. So things might 
break if removing the addRequired in this pass.

To sum up. The proposed change is probably harmless and OK. Just saying that 
the analysis pass dependencies used in here seem to be a bit ad-hoc(?).

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


[clang-tools-extra] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Björn Pettersson via cfe-commits


@@ -3280,7 +3280,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
 if (skipFunction(F))
   return false;
 
-auto *LIWP = getAnalysisIfAvailable();
+auto &LIWP = getAnalysis();

bjope wrote:

IIUC GVN doesn't depend on LoopInfo itself. It should just make sure to 
preserve it if it is available. So one might wonder if it is the addRequire 
that should be questioned and possibly removed instead.
But it's been like this for years (that it is required), and messing around 
with the legacy PM analysis dependencies for an IR pass (even if it is used by 
some backends) is perhaps not worth it.

Therefore I think you proposed change is ok. Or you could just leave this as 
is, since the IfAvailable part in some sense indicate that the pass itself 
doesn't depend on the analysis.

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


[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Jay Foad via cfe-commits

jayfoad wrote:

> I guess I don't know how pull requests and reviewing works in github. I 
> actually added 3 comments on this patch a several days (or weeks) ago. But 
> turns out that they were "pending" because I had only "started review" and 
> not found the place to "submit review".

For that reason I usually click "add single comment" instead of "start a 
review".

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


[clang] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Nikita Popov via cfe-commits

nikic wrote:

> GVN seems to have different behavior regarding LoopInfo in the LegacyPM and 
> NewPM, but that's an orthogonal issue. I'll check whether always requiring 
> LoopInfo in GVN has any compile-time impact, as I don't think this is 
> supposed to be an optional analysis there (otherwise loop load PRE is not 
> going to work reliably).

I've checked, and LoopInfo is always available in pipeline positions where GVN 
runs, so this effectively has no impact. I've made it a required analysis for 
the NewPM as well in 
https://github.com/llvm/llvm-project/commit/fa5884770ab240139f33a8b2be801673ca21b9c0.


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


[clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-10-11 Thread Dinar Temirbulatov via cfe-commits


@@ -292,7 +310,7 @@ define void @ldr_with_off_16mulvl(ptr %ptr) {
   %vscale = call i64 @llvm.vscale.i64()
   %mulvl = mul i64 %vscale, 256
   %base = getelementptr i8, ptr %ptr, i64 %mulvl
-  call void @llvm.aarch64.sme.ldr(i32 16, ptr %base)
+  call void @llvm.aarch64.sme.ldr(i32 16, i32 0, ptr %base)

dtemirbulatov wrote:

Maybe test non zero second parameter to see how it apllied in LDR instruction?

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


[PATCH] D159351: [Sema] Change order of displayed overloads in diagnostics

2023-10-11 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D159351#4653687 , @shafik wrote:

> You say "attempts to be a strict weak order" does that mean there are still 
> cases which will cause an assert or are we not sure?

No, it's an actual strict weak order.  It's a bad choice of wording on my part.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159351

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


[clang] [clang] static operators should evaluate object argument (PR #68485)

2023-10-11 Thread Tianlan Zhou via cfe-commits

https://github.com/SuperSodaSea updated 
https://github.com/llvm/llvm-project/pull/68485

>From 03276260c48d9cafb2a0d80825156e77cdf02eba Mon Sep 17 00:00:00 2001
From: SuperSodaSea 
Date: Sat, 7 Oct 2023 21:05:17 +0800
Subject: [PATCH 1/5] [clang] static operators should evaluate object argument

---
 clang/lib/AST/ExprConstant.cpp|  3 +-
 clang/lib/CodeGen/CGExpr.cpp  |  2 +-
 clang/lib/CodeGen/CGExprCXX.cpp   | 41 --
 clang/lib/CodeGen/CodeGenFunction.h   |  3 +
 clang/lib/Sema/SemaChecking.cpp   |  5 +-
 clang/lib/Sema/SemaOverload.cpp   | 33 ---
 clang/test/AST/ast-dump-static-operators.cpp  | 55 +++
 .../CodeGenCXX/cxx2b-static-call-operator.cpp | 26 ++---
 .../cxx2b-static-subscript-operator.cpp   | 11 +++-
 9 files changed, 137 insertions(+), 42 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-static-operators.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c0..a6c81f467fbe01c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {
 // FIXME: When selecting an implicit conversion for an overloaded
 // operator delete, we sometimes try to evaluate calls to conversion
 // operators without a 'this' parameter!
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac738..19406ff174dea14 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5070,7 +5070,7 @@ RValue CodeGenFunction::EmitCallExpr(const CallExpr *E,
   if (const auto *CE = dyn_cast(E))
 if (const auto *MD =
 dyn_cast_if_present(CE->getCalleeDecl());
-MD && MD->isImplicitObjectMemberFunction())
+MD && !MD->isExplicitObjectMemberFunction())
   return EmitCXXOperatorMemberCallExpr(CE, MD, ReturnValue);
 
   CGCallee callee = EmitCallee(E->getCallee());
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 2e7059cc8f5b639..a580c635998510f 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -489,11 +489,42 @@ RValue
 CodeGenFunction::EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue) {
-  assert(MD->isImplicitObjectMemberFunction() &&
- "Trying to emit a member call expr on a static method!");
-  return EmitCXXMemberOrOperatorMemberCallExpr(
-  E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
-  /*IsArrow=*/false, E->getArg(0));
+  assert(!MD->isExplicitObjectMemberFunction() &&
+ "Trying to emit a member call expr on an explicit object member "
+ "function!");
+
+  if (MD->isStatic())
+return EmitCXXStaticOperatorMemberCallExpr(E, MD, ReturnValue);
+  else
+return EmitCXXMemberOrOperatorMemberCallExpr(
+E, MD, ReturnValue, /*HasQualifier=*/false, /*Qualifier=*/nullptr,
+/*IsArrow=*/false, E->getArg(0));
+}
+
+RValue CodeGenFunction::EmitCXXStaticOperatorMemberCallExpr(
+const CXXOperatorCallExpr *E, const CXXMethodDecl *MD,
+ReturnValueSlot ReturnValue) {
+  assert(MD->isStatic());
+
+  CGCallee Callee = EmitCallee(E->getCallee());
+
+  // Emit and ignore `this` pointer.
+  EmitIgnoredExpr(E->getArg(0));
+
+  auto ProtoType = MD->getFunctionType()->castAs();
+
+  // Emit the rest of the call args.
+  CallArgList Args;
+  EmitCallArgs(Args, ProtoType, drop_begin(E->arguments(), 1),
+   E->getDirectCallee());
+
+  bool Chain = E == MustTailCall;
+  const CGFunctionInfo &FnInfo =
+  CGM.getTypes().arrangeFreeFunctionCall(Args, ProtoType, Chain);
+  llvm::CallBase *CallOrInvoke = nullptr;
+
+  return EmitCall(FnInfo, Callee, ReturnValue, Args, &CallOrInvoke, Chain,
+  E->getExprLoc());
 }
 
 RValue CodeGenFunction::EmitCUDAKernelCallExpr(const CUDAKernelCallExpr *E,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d5336382a2b9c95..42de125e7489911 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4163,6 +4163,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   RValue EmitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *E,
const CXXMethodDecl *MD,
ReturnValueSlot ReturnValue);
+  RValue EmitCXXStaticOperatorMemberCallExpr(const CXXOperatorCallEx

[clang-tools-extra] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Jay Foad via cfe-commits


@@ -3280,7 +3280,7 @@ class llvm::gvn::GVNLegacyPass : public FunctionPass {
 if (skipFunction(F))
   return false;
 
-auto *LIWP = getAnalysisIfAvailable();
+auto &LIWP = getAnalysis();

jayfoad wrote:

I prefer not to leave it as is - I think either we should get the analysis with 
`getAnalysis` or we should remove the `addRequired`, so that they are 
consistent with each other.

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


[clang-tools-extra] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Jay Foad via cfe-commits


@@ -261,7 +261,7 @@ bool VirtRegRewriter::runOnMachineFunction(MachineFunction 
&fn) {
   Indexes = &getAnalysis();
   LIS = &getAnalysis();
   VRM = &getAnalysis();
-  DebugVars = getAnalysisIfAvailable();
+  DebugVars = &getAnalysis();

jayfoad wrote:

Thanks! Fixed in 05c16f40c9de93c181d45ec718de5487380f0514

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


[PATCH] D86310: [X86] Align i128 to 16 bytes in x86 datalayouts

2023-10-11 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk added a comment.

The buildbot found one more test that needed updating, that was disabled on my 
system. Created https://github.com/llvm/llvm-project/pull/68781 for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86310

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


[clang] Draft:[clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-11 Thread via cfe-commits

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


[clang-tools-extra] Clean up strange uses of getAnalysisIfAvailable (PR #65729)

2023-10-11 Thread Jay Foad via cfe-commits


@@ -935,7 +935,7 @@ bool 
AArch64ConditionalCompares::runOnMachineFunction(MachineFunction &MF) {
   SchedModel = MF.getSubtarget().getSchedModel();
   MRI = &MF.getRegInfo();
   DomTree = &getAnalysis();
-  Loops = getAnalysisIfAvailable();
+  Loops = &getAnalysis();

jayfoad wrote:

Everything seems to work if I change `AArch64ConditionalCompares` to not 
require `MachineLoopInfo`. But I think I'll leave it to the AArch64 maintainers 
like you suggest.

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


[clang] Draft:[clang][ASTImporter] Fix crash when template class static member imported to other translation unit. (PR #68774)

2023-10-11 Thread via cfe-commits

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


[clang] [flang] Add flags controlling whether to run the fir alias tags pass (PR #68595)

2023-10-11 Thread Mats Petersson via cfe-commits

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

LGTM

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


[clang] [flang] Add flags controlling whether to run the fir alias tags pass (PR #68595)

2023-10-11 Thread Mats Petersson via cfe-commits

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

LGTM

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


[clang] [flang] Add flags controlling whether to run the fir alias tags pass (PR #68595)

2023-10-11 Thread David Truby via cfe-commits

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

LGTM

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


[clang] [clang] static operators should evaluate object argument (PR #68485)

2023-10-11 Thread Tianlan Zhou via cfe-commits


@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {

SuperSodaSea wrote:

It doesn't look like anything has gone wrong so far, but just to be on the safe 
side, maybe we could change the code below to this?

```diff
- This = &ThisVal;
+ if (MD->isInstance())
+   This = &ThisVal;
```

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


[clang] [flang] Add flags controlling whether to run the fir alias tags pass (PR #68595)

2023-10-11 Thread Tom Eccles via cfe-commits

tblah wrote:

> Does `falias-analysis` control the existing TBAA generation as well?

Not in this patch while -falias-analysis is kept separate and non-default. But 
that will be the intention in the future.

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


[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

2023-10-11 Thread via cfe-commits


@@ -7098,6 +7052,69 @@ class APValueToBufferConverter {
 return true;
   }
 
+  bool visitVector(const APValue &Val, QualType Ty, CharUnits Offset) {
+const VectorType *VTy = Ty->castAs();
+QualType EltTy = VTy->getElementType();
+unsigned NElts = VTy->getNumElements();
+unsigned EltSize =
+VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy);
+
+if ((NElts * EltSize) % Info.Ctx.getCharWidth() != 0) {
+  // The vector's size in bits is not a multiple of the target's byte size,
+  // so its layout is unspecified. For now, we'll simply treat these cases
+  // as unsupported (this should only be possible with OpenCL bool vectors
+  // whose element count isn't a multiple of the byte size).
+  Info.FFDiag(BCE->getBeginLoc(),
+  diag::note_constexpr_bit_cast_invalid_vector)
+  << Ty.getCanonicalType() << EltSize << NElts
+  << Info.Ctx.getCharWidth();
+  return false;
+}
+
+if (VTy->isExtVectorBoolType()) {
+  // Special handling for OpenCL bool vectors:
+  // Since these vectors are stored as packed bits, but we can't write
+  // individual bits to the BitCastBuffer, we'll buffer all of the elements
+  // together into an appropriately sized APInt and write them all out at
+  // once. Because we don't accept vectors where NElts * EltSize isn't a
+  // multiple of the char size, there will be no padding space, so we don't
+  // have to worry about writing data which should have been left
+  // uninitialized.
+  bool BigEndian = Info.Ctx.getTargetInfo().isBigEndian();
+
+  llvm::APInt Res = llvm::APInt::getZero(NElts);
+  for (unsigned I = 0; I < NElts; ++I) {
+const llvm::APSInt &EltAsInt = Val.getVectorElt(I).getInt();
+assert(EltAsInt.isUnsigned() && EltAsInt.getBitWidth() == 1 &&
+   "bool vector element must be 1-bit unsigned integer!");
+
+Res.insertBits(EltAsInt, BigEndian ? (NElts - I - 1) : I);
+  }
+
+  SmallVector Bytes(NElts / 8);
+  llvm::StoreIntToMemory(Res, &*Bytes.begin(), NElts / 8);
+  Buffer.writeObject(Offset, Bytes);
+} else {
+  // Iterate over each of the elements and write them out to the buffer at
+  // the appropriate offset.
+  CharUnits EltSizeChars = Info.Ctx.getTypeSizeInChars(EltTy);
+
+  // Special handling for vectors of x86_fp80: use a size of exactly 80 
bits
+  // because LLVM stores vector elements without padding
+  if (EltTy->isRealFloatingType() &&
+  &Info.Ctx.getFloatTypeSemantics(EltTy) ==
+  &APFloat::x87DoubleExtended())
+EltSizeChars = Info.Ctx.toCharUnitsFromBits(80);

DaMatrix wrote:

@nikic gave [an example](https://godbolt.org/z/rcev7Ps1a) in #68566 which shows 
that sometimes it doesn't, and pointed out that LLVM itself documents that 
vector types are represented without padding. Actually, [this example I just 
came up with](https://godbolt.org/z/hsdxhPrE8) shows how inconsistent it is, 
with LLVM storing vector elements at different offsets depending on how many 
elements are being written to and the current optimization level. Honestly, at 
this point I have no idea what's supposed to be correct, it seems like every 
time I think I've figured out which the "correct" format is something else pops 
up, and I don't really see much point in spending any more time trying to fix 
this code which only breaks on a vector format which nobody will ever actually 
use in practice. Can I just make it fail constant evaluation when the element 
type is `x86_fp80` and leave it at that?

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


[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From 32bcab427637432621590a64afaad1677fe832cb Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 6cd6d63fbc38e09f181ecbc93b2c5ecca89d4a71 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From 896fbb672c6361588af392343eb217477c066e18 Mon Sep 17 00:00:00 2001
From: Arthur O'Dwyer 
Date: Tue, 10 Oct 2023 10:03:17 -0400
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 ++--
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h

[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From fdbeba9c94ddb13ee53a761d9e1a95b044f2c20a Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 5820c4e478c035a65512994f354df081266467dc Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From 95f963747225adea8cf03de6a649a4fc49b80597 Mon Sep 17 00:00:00 2001
From: Arthur O'Dwyer 
Date: Tue, 10 Oct 2023 10:03:17 -0400
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 ++--
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From fdbeba9c94ddb13ee53a761d9e1a95b044f2c20a Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 5820c4e478c035a65512994f354df081266467dc Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From e7a5141ca78d0182cf3a372838bdc40b209e56b1 Mon Sep 17 00:00:00 2001
From: Arthur O'Dwyer 
Date: Tue, 10 Oct 2023 10:03:17 -0400
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 4 ++--
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From fdbeba9c94ddb13ee53a761d9e1a95b044f2c20a Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 5820c4e478c035a65512994f354df081266467dc Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From edd82edc6dd1ca1a143b4e667d5e4a30d8e7a1d4 Mon Sep 17 00:00:00 2001
From: Arthur O'Dwyer 
Date: Tue, 10 Oct 2023 10:03:17 -0400
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 ++---
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

https://github.com/AMP999 updated 
https://github.com/llvm/llvm-project/pull/68506

>From fdbeba9c94ddb13ee53a761d9e1a95b044f2c20a Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sat, 7 Oct 2023 19:02:34 +0330
Subject: [PATCH 1/3] [clang] Rename some misleading names (Non-functional)
 These names could be misleading; should we change them to
 `NonTriviallyComparable` instead?

---
 clang/test/SemaCXX/type-traits.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a35689d52978fcc..a1315f1966a6dd4 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3160,11 +3160,18 @@ 
static_assert(!__is_trivially_equality_comparable(float), "");
 static_assert(!__is_trivially_equality_comparable(double), "");
 static_assert(!__is_trivially_equality_comparable(long double), "");
 
-struct TriviallyEqualityComparableNoDefaultedComparator {
+struct NonTriviallyEqualityComparableNoComparator {
   int i;
   int j;
 };
-static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparableNoDefaultedComparator),
 "");
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator),
 "");
+
+struct NonTriviallyEqualityComparableNonDefaultedComparator {
+  int i;
+  int j;
+  bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&);
+};
+static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator),
 "");
 
 #if __cplusplus >= 202002L
 
@@ -3177,7 +3184,7 @@ struct TriviallyEqualityComparable {
 
   bool operator==(const TriviallyEqualityComparable&) const = default;
 };
-static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable), 
"");
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable));
 
 struct TriviallyEqualityComparableContainsArray {
   int a[4];

>From 5820c4e478c035a65512994f354df081266467dc Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Sun, 8 Oct 2023 18:00:51 +0330
Subject: [PATCH 2/3] [clang] __is_trivially_equality_comparable for types
 containing lambdas

Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if `(lam1 == lam2)` compiles, then `lam1` and `lam2` must have
the same type, and be always-equal, and be empty.
---
 clang/lib/AST/Type.cpp |  3 +++
 clang/test/SemaCXX/type-traits.cpp | 11 +++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 4c433f7fe9daca0..23f856c715a5e13 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2663,6 +2663,9 @@ static bool
 HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
   if (Decl->isUnion())
 return false;
+  if (Decl->isLambda())
+return Decl->captures().empty() &&
+   (Decl->getLambdaCaptureDefault() == LCD_None);
 
   auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
 return Function->getOverloadedOperator() ==
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index a1315f1966a6dd4..275ddcbae73930d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3200,6 +3200,17 @@ struct 
TriviallyEqualityComparableContainsMultiDimensionArray {
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
 
+auto GetNonCapturingLambda() { return [](){ return 42; }; }
+
+struct TriviallyEqualityComparableContainsLambda {
+  [[no_unique_address]] decltype(GetNonCapturingLambda()) l;
+  int i;
+
+  bool operator==(const TriviallyEqualityComparableContainsLambda&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda(;
 // padding
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();

>From 344455e5451b515b077b0f6358f99db7ee26faf9 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri 
Date: Wed, 11 Oct 2023 15:27:53 +0330
Subject: [PATCH 3/3] [clang] Factor out isCapturelessLambda

This changes the behavior of the call-site in "CodeGenFunction.cpp",
I think for the better. But I couldn't figure out how to test that
codepath.
---
 clang/include/clang/AST/DeclCXX.h | 6 ++
 clang/lib/AST/DeclCXX.cpp | 2 +-
 clang/lib/AST/Type.cpp| 3 +--
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 ++---
 clang/lib/Sema/SemaLambda.cpp | 3 +--
 5 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX

[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Utkarsh Saxena via cfe-commits

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

>From f9e29053a7a8fd8222cfbdf579776fafd6564b89 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 10 Oct 2023 21:53:37 +0200
Subject: [PATCH 1/2] [clang-tidy] Add check to flag objects hostile to
 suspension in a coroutine

---
 .../clang-tidy/misc/CMakeLists.txt|   1 +
 .../misc/CoroutineSuspensionHostileCheck.cpp  |  79 +++
 .../misc/CoroutineSuspensionHostileCheck.h|  45 ++
 .../clang-tidy/misc/MiscTidyModule.cpp|   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../misc/coroutine-suspension-hostile.rst |  36 +
 .../misc/coroutine-suspension-hostile.cpp | 131 ++
 8 files changed, 302 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-suspension-hostile.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-suspension-hostile.cpp

diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 2e88e68a5447825..c58a99d165dc34c 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -18,6 +18,7 @@ add_custom_target(genconfusable DEPENDS Confusables.inc)
 
 add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
+  CoroutineSuspensionHostileCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
   HeaderIncludeCycleCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp
new file mode 100644
index 000..d9fb34f5e92888a
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp
@@ -0,0 +1,79 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineSuspensionHostileCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineSuspensionHostileCheck::CoroutineSuspensionHostileCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  DenyTypeList(
+  utils::options::parseStringList(Options.get("DenyTypeList", ""))) {}
+
+void CoroutineSuspensionHostileCheck::registerMatchers(MatchFinder *Finder) {
+  // A suspension happens with co_await or co_yield.
+  Finder->addMatcher(coawaitExpr().bind("suspension"), this);
+  Finder->addMatcher(coyieldExpr().bind("suspension"), this);
+}
+
+void CoroutineSuspensionHostileCheck::checkVarDecl(VarDecl *VD) {
+  RecordDecl *RD = VD->getType().getCanonicalType()->getAsRecordDecl();
+  if (RD->hasAttr()) {
+diag(VD->getLocation(),
+ "%0 holds a lock across a suspension point of coroutine and could be "
+ "unlocked by a different thread")
+<< VD;
+  }
+  if (std::find(DenyTypeList.begin(), DenyTypeList.end(),
+RD->getQualifiedNameAsString()) != DenyTypeList.end()) {
+diag(VD->getLocation(),
+ "%0 persists across a suspension point of coroutine")
+<< VD;
+  }
+}
+
+void CoroutineSuspensionHostileCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *Suspension = Result.Nodes.getNodeAs("suspension");
+  DynTypedNode P;
+  for (const Stmt *Child = Suspension; Child; Child = P.get()) {
+auto Parents = Result.Context->getParents(*Child);
+if (Parents.empty())
+  break;
+P = *Parents.begin();
+auto *PCS = P.get();
+if (!PCS)
+  continue;
+for (auto Sibling = PCS->child_begin();
+ *Sibling != Child && Sibling != PCS->child_end(); ++Sibling) {
+  if (auto *DS = dyn_cast(*Sibling)) {
+for (Decl *D : DS->decls()) {
+  if (VarDecl *VD = dyn_cast(D)) {
+checkVarDecl(VD);
+  }
+}
+  }
+}
+  }
+}
+
+void CoroutineSuspensionHostileCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "DenyTypeList",
+utils::options::serializeStringList(DenyTypeList));
+}
+} // namespace clang::tidy::misc
diff --git 
a/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.h 

[clang] [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-10-11 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > > Because I don't know of any better way to commandeer a patch in GitHub
> > 
> > 
> > As a maintainer, you can push into this branch
> 
> I had reached out to @ThePhD with an offer to help on this before they opened 
> this PR, and I now have push access to their fork, which means I could change 
> the state of this PR.
> 
> To be clear, I cannot offer to defend the content (semantically) in the face 
> of review, but - if desired - I'd be happy to help with some more routine 
> operations like rebasing, formatting, or chopping off pieces into separate 
> PRs (all while keeping @ThePhD's authorship, of course).

Oh, that's excellent! @ThePhD also gave me push access to his repo. If we're 
going to tag-team efforts on this and we both have access, it probably makes 
sense to just leave it in his repo and work from there. If he finds the 
notifications too distracting, we can always move the work elsewhere at that 
point.

@h-vetinari -- would you mind doing some initial cleanup on the patch for 
things like rebasing, removing spurious formatting changes, naming, and the 
likes? I have WG14 meetings coming up next week (they should hopefully go 
quickly though), so it is likely going to be ~a week before I have the chance 
to work on this more heavily.

> So just to clarify, we should wait till you post a follow-up review before 
> commenting, to avoid fragmenting the discussion.

Given the above, I'd say we can keep the review going here.

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


[clang] a633a37 - Diagnose problematic uses of constructor/destructor attribute (#67673)

2023-10-11 Thread via cfe-commits

Author: Aaron Ballman
Date: 2023-10-11T08:14:45-04:00
New Revision: a633a3761fcbd0799426cbf5fbd7794961080e43

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

LOG: Diagnose problematic uses of constructor/destructor attribute (#67673)

Functions with these attributes will be automatically called before
main() or after main() exits gracefully. In glibc environments, the
constructor function is passed the same arguments as main(), so that
signature is allowed. In all other environments, we require the function
to accept no arguments and either return `void` or `int`. The functions
must use the C calling convention. In C++ language modes, the functions
cannot be a nonstatic member function, or a consteval function.

Additionally, these reuse the same priority logic as the init_priority
attribute which explicitly reserved priorty values <= 100 or > 65535. So
we now diagnose use of reserved priorities the same as we do for the
init_priority attribute, but we downgrade the error to be a warning
which defaults to an error to ease use for implementers like compiler-rt
or libc.

This relands b4435104ca3904529723b0673cc0f624cf8c54e6 with fixes.

Added: 
clang/test/Sema/constructor-attribute-diag-group.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/PowerPC/aix-destructor-attribute.c
clang/test/CodeGenCXX/aix-destructor-attribute.cpp
clang/test/Sema/constructor-attribute.c
compiler-rt/CMakeLists.txt
compiler-rt/cmake/config-ix.cmake
compiler-rt/test/profile/Posix/gcov-destructor.c
compiler-rt/test/ubsan/TestCases/Misc/Linux/sigaction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..530dbe55fcb1362 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,11 @@ Attribute Changes in Clang
   automatic diagnostic to use parameters of types that the format style
   supports but that are never the result of default argument promotion, such as
   ``float``. (`#59824: `_)
+- The ``constructor`` and ``destructor`` attributes now diagnose when:
+  - the priority is not between 101 and 65535, inclusive,
+  - the function it is applied to accepts arguments or has a non-void return
+type, or
+  - the function it is applied to is a non-static member function (C++).
 
 Improvements to Clang's diagnostics
 ---

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 8d928dcc146b254..eb4ccc6fb9389d4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7255,8 +7255,14 @@ after returning from ``main()`` or when the ``exit()`` 
function has been
 called. Note, ``quick_exit()``, ``_Exit()``, and ``abort()`` prevent a function
 marked ``destructor`` from being called.
 
-The constructor or destructor function should not accept any arguments and its
-return type should be ``void``.
+In general, the constructor or destructor function must use the C calling
+convention, cannot accept any arguments, and its return type should be
+``void``, ``int``, or ``unsigned int``. The latter two types are supported for
+historical reasons. On targets with a GNU environment (one which uses glibc),
+the signature of the function can also be the same as that of ``main()``.
+
+In C++ language modes, the function cannot be marked ``consteval``, nor can it
+be a non-static member function.
 
 The attributes accept an optional argument used to specify the priority order
 in which to execute constructor and destructor functions. The priority is

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0b09c002191848a..e017ca45aeeeb67 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -105,6 +105,10 @@ def EnumConversion : DiagGroup<"enum-conversion",
[EnumEnumConversion,
 EnumFloatConversion,
 EnumCompareConditional]>;
+def InvalidPriority : DiagGroup<"priority-ctor-dtor">;
+// For compatibility with GCC.
+def : DiagGroup<"prio-ctor-dtor", [InvalidPriority]>;
+
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def ImplicitIntConversion : DiagGroup<"implicit-int-conversion",

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/Diagnosti

[clang-tools-extra] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-11 Thread Aaron Ballman via cfe-commits

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


[clang] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-11 Thread Aaron Ballman via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 97b989b27496d5aeadb3b90cbb9305ddcd9e35d2 
78e3102b83809486fd6b4f255a2e77b59bc4ad0e -- 
clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h 
clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-suspension-hostile.cpp
 clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h
index cd61523b6561..ab3cedc84bf6 100644
--- a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h
@@ -1,4 +1,5 @@
-//===--- CoroutineHostileRAIICheck.h - clang-tidy -*- C++ 
-*-===//
+//===--- CoroutineHostileRAIICheck.h - clang-tidy -*- C++
+//-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -22,8 +23,7 @@ namespace clang::tidy::misc {
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/misc/coroutine-hostile-check.html
 class CoroutineHostileRAIICheck : public ClangTidyCheck {
 public:
-  CoroutineHostileRAIICheck(llvm::StringRef Name,
-  ClangTidyContext *Context);
+  CoroutineHostileRAIICheck(llvm::StringRef Name, ClangTidyContext *Context);
 
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 return LangOpts.CPlusPlus20;

``




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


[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread Amirreza Ashouri via cfe-commits

AMP999 wrote:

> I think there is an opportunity for a small refactor here, but feel free to 
> land this and we can handle the refactor later as an NFC change if you prefer

Is this (344455e) what you had in mind? I only found a few places that could 
use the factored-out function, and in the "CodeGenFunction.cpp" case, I'm not 
even sure it applies. It looks like that codepath is intended to be hit when we 
codegen the `operator()` of a lambda with captures under `-fsanitize=null`, but 
I couldn't see any null-check in the generated code even when the lambda did 
have captures, so I'm not sure I understand it. That codepath is 
@zygoloid's from 2017 (376c28e). Should I keep that diff, or revert it?

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


[clang] 0cb6c41 - Revert "Diagnose problematic uses of constructor/destructor attribute (#67673)"

2023-10-11 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-10-11T08:31:13-04:00
New Revision: 0cb6c413b1883a18341a428bb9179fa31cd6e4e3

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

LOG: Revert "Diagnose problematic uses of constructor/destructor attribute 
(#67673)"

This reverts commit a633a3761fcbd0799426cbf5fbd7794961080e43.

Still breaking compiler-rt bots:
https://lab.llvm.org/buildbot/#/builders/109/builds/75360

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/PowerPC/aix-destructor-attribute.c
clang/test/CodeGenCXX/aix-destructor-attribute.cpp
clang/test/Sema/constructor-attribute.c
compiler-rt/CMakeLists.txt
compiler-rt/cmake/config-ix.cmake
compiler-rt/test/profile/Posix/gcov-destructor.c
compiler-rt/test/ubsan/TestCases/Misc/Linux/sigaction.cpp

Removed: 
clang/test/Sema/constructor-attribute-diag-group.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 530dbe55fcb1362..2d918967e7f0b02 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,11 +217,6 @@ Attribute Changes in Clang
   automatic diagnostic to use parameters of types that the format style
   supports but that are never the result of default argument promotion, such as
   ``float``. (`#59824: `_)
-- The ``constructor`` and ``destructor`` attributes now diagnose when:
-  - the priority is not between 101 and 65535, inclusive,
-  - the function it is applied to accepts arguments or has a non-void return
-type, or
-  - the function it is applied to is a non-static member function (C++).
 
 Improvements to Clang's diagnostics
 ---

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index eb4ccc6fb9389d4..8d928dcc146b254 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7255,14 +7255,8 @@ after returning from ``main()`` or when the ``exit()`` 
function has been
 called. Note, ``quick_exit()``, ``_Exit()``, and ``abort()`` prevent a function
 marked ``destructor`` from being called.
 
-In general, the constructor or destructor function must use the C calling
-convention, cannot accept any arguments, and its return type should be
-``void``, ``int``, or ``unsigned int``. The latter two types are supported for
-historical reasons. On targets with a GNU environment (one which uses glibc),
-the signature of the function can also be the same as that of ``main()``.
-
-In C++ language modes, the function cannot be marked ``consteval``, nor can it
-be a non-static member function.
+The constructor or destructor function should not accept any arguments and its
+return type should be ``void``.
 
 The attributes accept an optional argument used to specify the priority order
 in which to execute constructor and destructor functions. The priority is

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index e017ca45aeeeb67..0b09c002191848a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -105,10 +105,6 @@ def EnumConversion : DiagGroup<"enum-conversion",
[EnumEnumConversion,
 EnumFloatConversion,
 EnumCompareConditional]>;
-def InvalidPriority : DiagGroup<"priority-ctor-dtor">;
-// For compatibility with GCC.
-def : DiagGroup<"prio-ctor-dtor", [InvalidPriority]>;
-
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def ImplicitIntConversion : DiagGroup<"implicit-int-conversion",

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cce4601770a7ecc..c1a6e3831127e56 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2870,8 +2870,6 @@ def warn_cxx11_compat_constexpr_body_multiple_return : 
Warning<
   InGroup, DefaultIgnore;
 def note_constexpr_body_previous_return : Note<
   "previous return statement is here">;
-def err_ctordtor_attr_consteval : Error<
-  "%0 attribute cannot be applied to a 'consteval' function">;
 
 // C++20 function try blocks in constexpr
 def ext_constexpr_function_try_block_cxx20 : ExtWarn<
@@ -3184,13 +3182,6 @@ def err_alignas_underaligned : Error<
   "requested alignment is less than minimum alignment of %1 for type %0">;
 def warn_aligned_attr_underaligned 

[PATCH] D156784: [AArch64][PAC] Declare FPAC subtarget feature

2023-10-11 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko added a comment.

As discussed in D156716 , it is not clear if 
I have to add FeatureFPAC to every relevant CPU. Maybe it is worth 
conservatively assuming that this feature should only be enabled manually by 
the user as a precaution against "I have CPU core X but it is not listed, so 
let's use cpu=Y because X supports all the instructions supported by Y //(but 
not FEAT_FPAC)//" - that would not cause any obvious run-time crashes under 
normal operation, but would make the code less secure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156784

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Utkarsh Saxena via cfe-commits

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

>From f9e29053a7a8fd8222cfbdf579776fafd6564b89 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 10 Oct 2023 21:53:37 +0200
Subject: [PATCH 1/4] [clang-tidy] Add check to flag objects hostile to
 suspension in a coroutine

---
 .../clang-tidy/misc/CMakeLists.txt|   1 +
 .../misc/CoroutineSuspensionHostileCheck.cpp  |  79 +++
 .../misc/CoroutineSuspensionHostileCheck.h|  45 ++
 .../clang-tidy/misc/MiscTidyModule.cpp|   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../misc/coroutine-suspension-hostile.rst |  36 +
 .../misc/coroutine-suspension-hostile.cpp | 131 ++
 8 files changed, 302 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-suspension-hostile.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-suspension-hostile.cpp

diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 2e88e68a5447825..c58a99d165dc34c 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -18,6 +18,7 @@ add_custom_target(genconfusable DEPENDS Confusables.inc)
 
 add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
+  CoroutineSuspensionHostileCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
   HeaderIncludeCycleCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp
new file mode 100644
index 000..d9fb34f5e92888a
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp
@@ -0,0 +1,79 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineSuspensionHostileCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineSuspensionHostileCheck::CoroutineSuspensionHostileCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  DenyTypeList(
+  utils::options::parseStringList(Options.get("DenyTypeList", ""))) {}
+
+void CoroutineSuspensionHostileCheck::registerMatchers(MatchFinder *Finder) {
+  // A suspension happens with co_await or co_yield.
+  Finder->addMatcher(coawaitExpr().bind("suspension"), this);
+  Finder->addMatcher(coyieldExpr().bind("suspension"), this);
+}
+
+void CoroutineSuspensionHostileCheck::checkVarDecl(VarDecl *VD) {
+  RecordDecl *RD = VD->getType().getCanonicalType()->getAsRecordDecl();
+  if (RD->hasAttr()) {
+diag(VD->getLocation(),
+ "%0 holds a lock across a suspension point of coroutine and could be "
+ "unlocked by a different thread")
+<< VD;
+  }
+  if (std::find(DenyTypeList.begin(), DenyTypeList.end(),
+RD->getQualifiedNameAsString()) != DenyTypeList.end()) {
+diag(VD->getLocation(),
+ "%0 persists across a suspension point of coroutine")
+<< VD;
+  }
+}
+
+void CoroutineSuspensionHostileCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *Suspension = Result.Nodes.getNodeAs("suspension");
+  DynTypedNode P;
+  for (const Stmt *Child = Suspension; Child; Child = P.get()) {
+auto Parents = Result.Context->getParents(*Child);
+if (Parents.empty())
+  break;
+P = *Parents.begin();
+auto *PCS = P.get();
+if (!PCS)
+  continue;
+for (auto Sibling = PCS->child_begin();
+ *Sibling != Child && Sibling != PCS->child_end(); ++Sibling) {
+  if (auto *DS = dyn_cast(*Sibling)) {
+for (Decl *D : DS->decls()) {
+  if (VarDecl *VD = dyn_cast(D)) {
+checkVarDecl(VD);
+  }
+}
+  }
+}
+  }
+}
+
+void CoroutineSuspensionHostileCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "DenyTypeList",
+utils::options::serializeStringList(DenyTypeList));
+}
+} // namespace clang::tidy::misc
diff --git 
a/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.h 

[clang] [clang] __is_trivially_equality_comparable for types containing lambdas (PR #68506)

2023-10-11 Thread via cfe-commits

cor3ntin wrote:

Yup, this is what i have in mind. Afaik, the CodeGenFunction.cpp change was a 
bug that you fixed - just going off the comment.

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


[clang] 27ecb63 - Diagnose problematic uses of constructor/destructor attribute (#67673)

2023-10-11 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-10-11T08:55:33-04:00
New Revision: 27ecb63c260400dd20b8c5dc16d0dfd2d0e7122e

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

LOG: Diagnose problematic uses of constructor/destructor attribute (#67673)

Functions with these attributes will be automatically called before
main() or after main() exits gracefully. In glibc environments, the
constructor function is passed the same arguments as main(), so that
signature is allowed. In all other environments, we require the function
to accept no arguments and either return `void` or `int`. The functions
must use the C calling convention. In C++ language modes, the functions
cannot be a nonstatic member function, or a consteval function.

Additionally, these reuse the same priority logic as the init_priority
attribute which explicitly reserved priorty values <= 100 or > 65535. So
we now diagnose use of reserved priorities the same as we do for the
init_priority attribute, but we downgrade the error to be a warning
which defaults to an error to ease use for implementers like compiler-rt
or libc.

This relands a633a3761fcbd0799426cbf5fbd7794961080e43 with fixes.

Added: 
clang/test/Sema/constructor-attribute-diag-group.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/PowerPC/aix-destructor-attribute.c
clang/test/CodeGenCXX/aix-destructor-attribute.cpp
clang/test/Sema/constructor-attribute.c
compiler-rt/CMakeLists.txt
compiler-rt/cmake/config-ix.cmake
compiler-rt/lib/builtins/CMakeLists.txt
compiler-rt/lib/profile/CMakeLists.txt
compiler-rt/test/profile/Posix/gcov-destructor.c
compiler-rt/test/ubsan/TestCases/Misc/Linux/sigaction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..530dbe55fcb1362 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,6 +217,11 @@ Attribute Changes in Clang
   automatic diagnostic to use parameters of types that the format style
   supports but that are never the result of default argument promotion, such as
   ``float``. (`#59824: `_)
+- The ``constructor`` and ``destructor`` attributes now diagnose when:
+  - the priority is not between 101 and 65535, inclusive,
+  - the function it is applied to accepts arguments or has a non-void return
+type, or
+  - the function it is applied to is a non-static member function (C++).
 
 Improvements to Clang's diagnostics
 ---

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 8d928dcc146b254..eb4ccc6fb9389d4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7255,8 +7255,14 @@ after returning from ``main()`` or when the ``exit()`` 
function has been
 called. Note, ``quick_exit()``, ``_Exit()``, and ``abort()`` prevent a function
 marked ``destructor`` from being called.
 
-The constructor or destructor function should not accept any arguments and its
-return type should be ``void``.
+In general, the constructor or destructor function must use the C calling
+convention, cannot accept any arguments, and its return type should be
+``void``, ``int``, or ``unsigned int``. The latter two types are supported for
+historical reasons. On targets with a GNU environment (one which uses glibc),
+the signature of the function can also be the same as that of ``main()``.
+
+In C++ language modes, the function cannot be marked ``consteval``, nor can it
+be a non-static member function.
 
 The attributes accept an optional argument used to specify the priority order
 in which to execute constructor and destructor functions. The priority is

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0b09c002191848a..e017ca45aeeeb67 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -105,6 +105,10 @@ def EnumConversion : DiagGroup<"enum-conversion",
[EnumEnumConversion,
 EnumFloatConversion,
 EnumCompareConditional]>;
+def InvalidPriority : DiagGroup<"priority-ctor-dtor">;
+// For compatibility with GCC.
+def : DiagGroup<"prio-ctor-dtor", [InvalidPriority]>;
+
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def ImplicitIntConversion : DiagGroup<"implicit-int-conversion",

diff  --git a/

[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Tom Eccles via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

tblah wrote:

So `SourceKind::Direct` isn't necessarily a global?

The use case for the tbaa alias analysis is we want to be able to add tags to 
global arrays. These can be boxed. The specific case I care about is
```
module mod
real, dimension(:), allocatable :: glbl

subroutine func(arg)
  real, intent(in), dimension(:) :: arg
  ! glbl can't alias with arg
end subroutine
end module
```

The generated code looks something like
```
fir.global @_QMmodEglbl : !fir.box>> { [...]}

func.func @_QMmodPfunc([...]) {
  [...]
  %glbl_addr = fir.address_of(@_QmodEa) : 
!fir.ref>>>
  %decl = fir.declare %glbl_addr [...]
  [...]
  %box = fir.load %decl
  %addr = fir.box_addr %box : (!fir.box>>) -> 
!fir.heap>
  [...]
  %element = fir.array_coor %addr(%shape) %index
  %val = fir.array_coor %element
```

What I want to happen here is to notice that `%val`  comes from a global 
variable and to tag that load as such. This is a lot clearer from the fortran 
source than the FIR so maybe we need to store more information somewhere.

As I understand it, you're saying that we can't know much about this variable 
because the global variable is boxed. Why is the box special?

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


[clang] ac27228 - Revert "Diagnose problematic uses of constructor/destructor attribute (#67673)"

2023-10-11 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-10-11T09:02:24-04:00
New Revision: ac2722873b26e2623a0be8cd6cacf529aa8f26ca

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

LOG: Revert "Diagnose problematic uses of constructor/destructor attribute 
(#67673)"

This reverts commit 27ecb63c260400dd20b8c5dc16d0dfd2d0e7122e.

Still fails compiler-rt:
https://lab.llvm.org/buildbot/#/builders/109/builds/75364

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/CodeGen/PowerPC/aix-destructor-attribute.c
clang/test/CodeGenCXX/aix-destructor-attribute.cpp
clang/test/Sema/constructor-attribute.c
compiler-rt/CMakeLists.txt
compiler-rt/cmake/config-ix.cmake
compiler-rt/lib/builtins/CMakeLists.txt
compiler-rt/lib/profile/CMakeLists.txt
compiler-rt/test/profile/Posix/gcov-destructor.c
compiler-rt/test/ubsan/TestCases/Misc/Linux/sigaction.cpp

Removed: 
clang/test/Sema/constructor-attribute-diag-group.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 530dbe55fcb1362..2d918967e7f0b02 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -217,11 +217,6 @@ Attribute Changes in Clang
   automatic diagnostic to use parameters of types that the format style
   supports but that are never the result of default argument promotion, such as
   ``float``. (`#59824: `_)
-- The ``constructor`` and ``destructor`` attributes now diagnose when:
-  - the priority is not between 101 and 65535, inclusive,
-  - the function it is applied to accepts arguments or has a non-void return
-type, or
-  - the function it is applied to is a non-static member function (C++).
 
 Improvements to Clang's diagnostics
 ---

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index eb4ccc6fb9389d4..8d928dcc146b254 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7255,14 +7255,8 @@ after returning from ``main()`` or when the ``exit()`` 
function has been
 called. Note, ``quick_exit()``, ``_Exit()``, and ``abort()`` prevent a function
 marked ``destructor`` from being called.
 
-In general, the constructor or destructor function must use the C calling
-convention, cannot accept any arguments, and its return type should be
-``void``, ``int``, or ``unsigned int``. The latter two types are supported for
-historical reasons. On targets with a GNU environment (one which uses glibc),
-the signature of the function can also be the same as that of ``main()``.
-
-In C++ language modes, the function cannot be marked ``consteval``, nor can it
-be a non-static member function.
+The constructor or destructor function should not accept any arguments and its
+return type should be ``void``.
 
 The attributes accept an optional argument used to specify the priority order
 in which to execute constructor and destructor functions. The priority is

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index e017ca45aeeeb67..0b09c002191848a 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -105,10 +105,6 @@ def EnumConversion : DiagGroup<"enum-conversion",
[EnumEnumConversion,
 EnumFloatConversion,
 EnumCompareConditional]>;
-def InvalidPriority : DiagGroup<"priority-ctor-dtor">;
-// For compatibility with GCC.
-def : DiagGroup<"prio-ctor-dtor", [InvalidPriority]>;
-
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def ImplicitIntConversion : DiagGroup<"implicit-int-conversion",

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index cce4601770a7ecc..c1a6e3831127e56 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2870,8 +2870,6 @@ def warn_cxx11_compat_constexpr_body_multiple_return : 
Warning<
   InGroup, DefaultIgnore;
 def note_constexpr_body_previous_return : Note<
   "previous return statement is here">;
-def err_ctordtor_attr_consteval : Error<
-  "%0 attribute cannot be applied to a 'consteval' function">;
 
 // C++20 function try blocks in constexpr
 def ext_constexpr_function_try_block_cxx20 : ExtWarn<
@@ -3184,13 +3182,6 @@ def err_alignas_underaligned : Error<
   "requested alignment is less t

[clang-tools-extra] Diagnose problematic uses of constructor/destructor attribute (PR #67673)

2023-10-11 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

I landed this and compiler-rt is still broken. I tried again to fix it up and 
wasn't able to find the right way to convince CMake to suppress the diagnostic. 
I have run out of time to put into trying to solve the build system issues 
(this was a drive-by set of fixes that have now eaten up more time than I can 
afford to spend on this), so abandoning this work. Anyone who wants to take it 
across the finish line is welcome to do so.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Utkarsh Saxena via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Utkarsh Saxena via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Utkarsh Saxena via cfe-commits

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

>From f9e29053a7a8fd8222cfbdf579776fafd6564b89 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 10 Oct 2023 21:53:37 +0200
Subject: [PATCH 1/5] [clang-tidy] Add check to flag objects hostile to
 suspension in a coroutine

---
 .../clang-tidy/misc/CMakeLists.txt|   1 +
 .../misc/CoroutineSuspensionHostileCheck.cpp  |  79 +++
 .../misc/CoroutineSuspensionHostileCheck.h|  45 ++
 .../clang-tidy/misc/MiscTidyModule.cpp|   3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../misc/coroutine-suspension-hostile.rst |  36 +
 .../misc/coroutine-suspension-hostile.cpp | 131 ++
 8 files changed, 302 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-suspension-hostile.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-suspension-hostile.cpp

diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 2e88e68a5447825..c58a99d165dc34c 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -18,6 +18,7 @@ add_custom_target(genconfusable DEPENDS Confusables.inc)
 
 add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
+  CoroutineSuspensionHostileCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
   HeaderIncludeCycleCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp
new file mode 100644
index 000..d9fb34f5e92888a
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.cpp
@@ -0,0 +1,79 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineSuspensionHostileCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineSuspensionHostileCheck::CoroutineSuspensionHostileCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  DenyTypeList(
+  utils::options::parseStringList(Options.get("DenyTypeList", ""))) {}
+
+void CoroutineSuspensionHostileCheck::registerMatchers(MatchFinder *Finder) {
+  // A suspension happens with co_await or co_yield.
+  Finder->addMatcher(coawaitExpr().bind("suspension"), this);
+  Finder->addMatcher(coyieldExpr().bind("suspension"), this);
+}
+
+void CoroutineSuspensionHostileCheck::checkVarDecl(VarDecl *VD) {
+  RecordDecl *RD = VD->getType().getCanonicalType()->getAsRecordDecl();
+  if (RD->hasAttr()) {
+diag(VD->getLocation(),
+ "%0 holds a lock across a suspension point of coroutine and could be "
+ "unlocked by a different thread")
+<< VD;
+  }
+  if (std::find(DenyTypeList.begin(), DenyTypeList.end(),
+RD->getQualifiedNameAsString()) != DenyTypeList.end()) {
+diag(VD->getLocation(),
+ "%0 persists across a suspension point of coroutine")
+<< VD;
+  }
+}
+
+void CoroutineSuspensionHostileCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *Suspension = Result.Nodes.getNodeAs("suspension");
+  DynTypedNode P;
+  for (const Stmt *Child = Suspension; Child; Child = P.get()) {
+auto Parents = Result.Context->getParents(*Child);
+if (Parents.empty())
+  break;
+P = *Parents.begin();
+auto *PCS = P.get();
+if (!PCS)
+  continue;
+for (auto Sibling = PCS->child_begin();
+ *Sibling != Child && Sibling != PCS->child_end(); ++Sibling) {
+  if (auto *DS = dyn_cast(*Sibling)) {
+for (Decl *D : DS->decls()) {
+  if (VarDecl *VD = dyn_cast(D)) {
+checkVarDecl(VD);
+  }
+}
+  }
+}
+  }
+}
+
+void CoroutineSuspensionHostileCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "DenyTypeList",
+utils::options::serializeStringList(DenyTypeList));
+}
+} // namespace clang::tidy::misc
diff --git 
a/clang-tools-extra/clang-tidy/misc/CoroutineSuspensionHostileCheck.h 

[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Utkarsh Saxena (usx95)


Changes

This check detects **hostile-RAII** objects which should not **persist across a 
suspension point in a coroutine**.

Some objects require that they be destroyed on the same thread that created 
them. Traditionally this requirement was often phrased as "must be a local 
variable", under the assumption that local variables always work this way. 
However this is incorrect with **C++20 coroutines**, since an intervening 
`co_await` may cause the coroutine to suspend and later be resumed on another 
thread.

The lifetime of an object that requires being destroyed on the same thread must 
 not encompass a `co_await` or `co_yield` point. If you create/destroy an 
object, you must do so without allowing the coroutine to suspend in the 
meantime.

The check considers the following type as hostile:

 - **Scoped-lockable types**: A scoped-lockable object persisting across a 
suspension point is problematic as the lock held by this object could be 
unlocked by a different thread. This would be undefined behaviour.

 - Types belonging to a configurable **denylist**.

```cpp
  // Call some async API while holding a lock.
const my::MutexLock l(&mu_);

// Oops! The async Bar function may finish on a different
// thread from the one that created the MutexLock object and therefore called
// Mutex::Lock -- now Mutex::Unlock will be called on the wrong thread.
co_await Bar();
```


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


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/CMakeLists.txt (+1) 
- (added) clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp (+82) 
- (added) clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.h (+44) 
- (modified) clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp (+3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/misc/coroutine-hostile-raii.rst (+48) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/misc/coroutine-hostile-raii.cpp 
(+131) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 2e88e68a5447825..d9ec268650c0532 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -18,6 +18,7 @@ add_custom_target(genconfusable DEPENDS Confusables.inc)
 
 add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
+  CoroutineHostileRAIICheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
   HeaderIncludeCycleCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp 
b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
new file mode 100644
index 000..7b084cd993c35ee
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/CoroutineHostileRAIICheck.cpp
@@ -0,0 +1,82 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineHostileRAIICheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+  for (StringRef Denied :
+   utils::options::parseStringList(Options.get("RAIIDenyList", ""))) {
+Denied.consume_front("::");
+RAIIDenyList.push_back(Denied);
+  }
+}
+
+void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
+  // A suspension happens with co_await or co_yield.
+  Finder->addMatcher(coawaitExpr().bind("suspension"), this);
+  Finder->addMatcher(coyieldExpr().bind("suspension"), this);
+}
+
+void CoroutineHostileRAIICheck::checkVarDecl(VarDecl *VD) {
+  RecordDecl *RD = VD->getType().getCanonicalType()->getAsRecordDecl();
+  if (RD->hasAttr()) {
+diag(VD->getLocation(),
+ "%0 holds a lock across a suspension point of coroutine and could be "
+ "unlocked by a different thread")
+<< VD;
+  }
+  if (std::find(RAIIDenyList.begin(), RAIIDenyList.end(),
+RD->getQualifiedNameAsString()) != RAIIDenyList.end()) {
+diag(VD->getLocation(),
+ "%0 persists across a suspension point of coroutine")
+<< VD;
+  }
+}
+
+void Corouti

[PATCH] D159351: [Sema] Change order of displayed overloads in diagnostics

2023-10-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

I think the changes should come with a release note so users know about the 
improved user experience (it would be great to show the code example from this 
patch summary in the release notes with the explanation you gave). Overall, I 
think this gives reasonable diagnostic behavior (I expect it to roughly be a 
wash in terms of showing the "best" order -- some will improve, some will 
degrade) but the ability to make the sets sortable without triggering checked 
STL diagnostics is definitely an improvement. Thanks!




Comment at: clang/lib/Sema/SemaOverload.cpp:11817-11819
+  if (int Ord = CompareConversions(*L, *R)) {
+return Ord < 0;
+  }

Coding style nit.



Comment at: clang/lib/Sema/SemaOverload.cpp:11872-11874
+if (int Ord = CompareConversions(*L, *R)) {
+  return Ord < 0;
 }





Comment at: clang/lib/Sema/SemaOverload.cpp:11927-11928
+  // We intend StaticObjectArgumentConversion to compare the same as
+  // StandardConversion with ICR_ExactMatch rank.
+  // Default give us that.
+  return {};





Comment at: clang/lib/Sema/SemaOverload.cpp:11955
+// FIXME: find a way to compare templates for being more or less
+// specialized that provides a weak ordering.
+return 0;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159351

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


[clang] [clang][dataflow] Add support for lambda captures (PR #68558)

2023-10-11 Thread Yitzhak Mandelbaum via cfe-commits

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

Thanks!

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,48 @@
+.. title:: clang-tidy - misc-coroutine-hostile-raii
+
+misc-coroutine-hostile-raii
+
+
+This check detects hostile-RAII objects which should not persist across a 

PiotrZSL wrote:

first paragraph in documentation should be same as on in release notes and as 
in .hpp file for a class description

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,82 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineHostileRAIICheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+  for (StringRef Denied :
+   utils::options::parseStringList(Options.get("RAIIDenyList", ""))) {
+Denied.consume_front("::");
+RAIIDenyList.push_back(Denied);
+  }
+}
+
+void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
+  // A suspension happens with co_await or co_yield.
+  Finder->addMatcher(coawaitExpr().bind("suspension"), this);
+  Finder->addMatcher(coyieldExpr().bind("suspension"), this);
+}
+
+void CoroutineHostileRAIICheck::checkVarDecl(VarDecl *VD) {
+  RecordDecl *RD = VD->getType().getCanonicalType()->getAsRecordDecl();
+  if (RD->hasAttr()) {
+diag(VD->getLocation(),
+ "%0 holds a lock across a suspension point of coroutine and could be "
+ "unlocked by a different thread")
+<< VD;
+  }
+  if (std::find(RAIIDenyList.begin(), RAIIDenyList.end(),
+RD->getQualifiedNameAsString()) != RAIIDenyList.end()) {
+diag(VD->getLocation(),
+ "%0 persists across a suspension point of coroutine")
+<< VD;
+  }
+}
+
+void CoroutineHostileRAIICheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Suspension = Result.Nodes.getNodeAs("suspension");
+  DynTypedNode P;
+  for (const Stmt *Child = Suspension; Child; Child = P.get()) {

PiotrZSL wrote:

Please rewrite this in Matcher by writing custom one (best option).
Or at least split into functions:
- one for iterating over child's declared before this.
- one for handling single child


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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,82 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineHostileRAIICheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+  for (StringRef Denied :
+   utils::options::parseStringList(Options.get("RAIIDenyList", ""))) {
+Denied.consume_front("::");
+RAIIDenyList.push_back(Denied);

PiotrZSL wrote:

put reserve for vector

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,82 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineHostileRAIICheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+  for (StringRef Denied :
+   utils::options::parseStringList(Options.get("RAIIDenyList", ""))) {
+Denied.consume_front("::");
+RAIIDenyList.push_back(Denied);
+  }
+}
+
+void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
+  // A suspension happens with co_await or co_yield.
+  Finder->addMatcher(coawaitExpr().bind("suspension"), this);
+  Finder->addMatcher(coyieldExpr().bind("suspension"), this);
+}
+
+void CoroutineHostileRAIICheck::checkVarDecl(VarDecl *VD) {
+  RecordDecl *RD = VD->getType().getCanonicalType()->getAsRecordDecl();
+  if (RD->hasAttr()) {
+diag(VD->getLocation(),
+ "%0 holds a lock across a suspension point of coroutine and could be "
+ "unlocked by a different thread")
+<< VD;
+  }
+  if (std::find(RAIIDenyList.begin(), RAIIDenyList.end(),
+RD->getQualifiedNameAsString()) != RAIIDenyList.end()) {

PiotrZSL wrote:

would be nice to somehow utilize MatchesAnyListedNameMatcher, this could be 
possible if this would be rewritten into AST matcher or just extracting 
NameMatcher from it (make it public) and use here.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,82 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineHostileRAIICheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+  for (StringRef Denied :
+   utils::options::parseStringList(Options.get("RAIIDenyList", ""))) {
+Denied.consume_front("::");
+RAIIDenyList.push_back(Denied);
+  }
+}
+
+void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
+  // A suspension happens with co_await or co_yield.
+  Finder->addMatcher(coawaitExpr().bind("suspension"), this);
+  Finder->addMatcher(coyieldExpr().bind("suspension"), this);
+}
+
+void CoroutineHostileRAIICheck::checkVarDecl(VarDecl *VD) {
+  RecordDecl *RD = VD->getType().getCanonicalType()->getAsRecordDecl();
+  if (RD->hasAttr()) {
+diag(VD->getLocation(),
+ "%0 holds a lock across a suspension point of coroutine and could be "
+ "unlocked by a different thread")
+<< VD;
+  }

PiotrZSL wrote:

maybe we should return here, to avoid providing 2 diags for same variable.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,82 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineHostileRAIICheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+  for (StringRef Denied :
+   utils::options::parseStringList(Options.get("RAIIDenyList", ""))) {
+Denied.consume_front("::");
+RAIIDenyList.push_back(Denied);
+  }
+}
+
+void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
+  // A suspension happens with co_await or co_yield.
+  Finder->addMatcher(coawaitExpr().bind("suspension"), this);
+  Finder->addMatcher(coyieldExpr().bind("suspension"), this);
+}
+
+void CoroutineHostileRAIICheck::checkVarDecl(VarDecl *VD) {
+  RecordDecl *RD = VD->getType().getCanonicalType()->getAsRecordDecl();
+  if (RD->hasAttr()) {
+diag(VD->getLocation(),
+ "%0 holds a lock across a suspension point of coroutine and could be "
+ "unlocked by a different thread")
+<< VD;
+  }
+  if (std::find(RAIIDenyList.begin(), RAIIDenyList.end(),
+RD->getQualifiedNameAsString()) != RAIIDenyList.end()) {
+diag(VD->getLocation(),
+ "%0 persists across a suspension point of coroutine")
+<< VD;
+  }

PiotrZSL wrote:

add not with info about where is suspension point, something like "suspension 
point is here"

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,82 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineHostileRAIICheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+  for (StringRef Denied :
+   utils::options::parseStringList(Options.get("RAIIDenyList", ""))) {

PiotrZSL wrote:

1. Maybe all it RAIITypesList
2. Consider puting things like std::mutex by default here.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,131 @@
+// RUN: %check_clang_tidy -std=c++20 %s misc-coroutine-hostile-raii %t \
+// RUN:   -config="{CheckOptions: \
+// RUN: {misc-coroutine-hostile-raii.RAIIDenyList: \
+// RUN:   'my::Mutex; ::my::other::Mutex'}}"
+
+namespace std {
+
+template  struct coroutine_traits {
+  using promise_type = typename R::promise_type;
+};
+
+template  struct coroutine_handle;
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *addr) noexcept {
+coroutine_handle me;
+me.ptr = addr;
+return me;
+  }
+  void operator()() { resume(); }
+  void *address() const noexcept { return ptr; }
+  void resume() const {  }
+  void destroy() const { }
+  bool done() const { return true; }
+  coroutine_handle &operator=(decltype(nullptr)) {
+ptr = nullptr;
+return *this;
+  }
+  coroutine_handle(decltype(nullptr)) : ptr(nullptr) {}
+  coroutine_handle() : ptr(nullptr) {}
+  //  void reset() { ptr = nullptr; } // add to P0057?
+  explicit operator bool() const { return ptr; }
+
+protected:
+  void *ptr;
+};
+
+template  struct coroutine_handle : coroutine_handle<> {
+  using coroutine_handle<>::operator=;
+
+  static coroutine_handle from_address(void *addr) noexcept {
+coroutine_handle me;
+me.ptr = addr;
+return me;
+  }
+
+  Promise &promise() const {
+return *reinterpret_cast(
+__builtin_coro_promise(ptr, alignof(Promise), false));
+  }
+  static coroutine_handle from_promise(Promise &promise) {
+coroutine_handle p;
+p.ptr = __builtin_coro_promise(&promise, alignof(Promise), true);
+return p;
+  }
+};
+
+struct suspend_always {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+} // namespace std
+
+struct ReturnObject {
+struct promise_type {
+ReturnObject get_return_object() { return {}; }
+std::suspend_always initial_suspend() { return {}; }
+std::suspend_always final_suspend() noexcept { return {}; }
+void unhandled_exception() {}
+std::suspend_always yield_value(int value) { return {}; }
+};
+};
+
+
+#define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
+
+namespace absl {
+class SCOPED_LOCKABLE Mutex {};
+using Mutex2 = Mutex;
+} // namespace absl
+
+
+ReturnObject scopedLockableTest() {
+absl::Mutex a;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'a' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+absl::Mutex2 b;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'b' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+{
+absl::Mutex no_warning_1;
+{ absl::Mutex no_warning_2; }
+}
+
+co_yield 1;
+absl::Mutex c;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'c' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+co_await std::suspend_always{};
+for(int i=1;i<=10;++i ) {
+  absl::Mutex d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'd' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+  co_await std::suspend_always{};
+  co_yield 1;
+  absl::Mutex no_warning_3;
+}
+if (true) {
+  absl::Mutex e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'e' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+  co_yield 1;
+  absl::Mutex no_warning_4;
+}
+absl::Mutex no_warning_5;
+}
+namespace my {
+class Mutex{};
+
+namespace other {
+class Mutex{};
+} // namespace other
+
+using Mutex2 = Mutex;
+} // namespace my
+
+ReturnObject denyListTest() {
+my::Mutex a;
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'a' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+my::other::Mutex b;
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'b' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+my::Mutex2 c;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'c' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+co_yield 1;
+}

PiotrZSL wrote:

add test with mutex being an template argument with an template instantiation.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,48 @@
+.. title:: clang-tidy - misc-coroutine-hostile-raii
+
+misc-coroutine-hostile-raii
+
+
+This check detects hostile-RAII objects which should not persist across a 
+suspension point in a coroutine.
+
+Some objects require that they be destroyed on the same thread that created 
them. 
+Traditionally this requirement was often phrased as "must be a local variable",
+under the assumption that local variables always work this way. However this is
+incorrect with C++20 coroutines, since an intervening `co_await` may cause the
+coroutine to suspend and later be resumed on another thread.
+
+The lifetime of an object that requires being destroyed on the same thread 
must 
+not encompass a `co_await` or `co_yield` point. If you create/destroy an 
object,
+you must do so without allowing the coroutine to suspend in the meantime.
+
+The check considers the following type as hostile:
+
+ - Scoped-lockable types: A scoped-lockable object persisting across a 
suspension

PiotrZSL wrote:

mention here about attribute.

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-11 Thread Aaron Ballman via cfe-commits

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -186,14 +186,14 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
-  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; }
-
+  bool isAlignas() const { return IsAlignas; }
+  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }

AaronBallman wrote:

This function was intended to tell you whether the attribute is a C++ 
attribute, and now it's changed to whether it's a C++ attribute spelled with 
`[[]]`. https://eel.is/c++draft/dcl.attr - note that `alignas` is an 
`attribute-specifier`. In C, `alignas` is *not* an attribute specifier (but it 
might become one someday) but is a kind of `declaration-specifier` instead.

I think it'd be better to keep this distinction, but I'll defer to @erichkeane 
if he has other opinions.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,48 @@
+.. title:: clang-tidy - misc-coroutine-hostile-raii
+
+misc-coroutine-hostile-raii
+
+
+This check detects hostile-RAII objects which should not persist across a 
+suspension point in a coroutine.
+
+Some objects require that they be destroyed on the same thread that created 
them. 
+Traditionally this requirement was often phrased as "must be a local variable",
+under the assumption that local variables always work this way. However this is
+incorrect with C++20 coroutines, since an intervening `co_await` may cause the
+coroutine to suspend and later be resumed on another thread.
+
+The lifetime of an object that requires being destroyed on the same thread 
must 
+not encompass a `co_await` or `co_yield` point. If you create/destroy an 
object,
+you must do so without allowing the coroutine to suspend in the meantime.
+
+The check considers the following type as hostile:
+
+ - Scoped-lockable types: A scoped-lockable object persisting across a 
suspension
+ point is problematic as the lock held by this object could be unlocked by a 
+ different thread. This would be undefined behaviour.
+
+ - Types belonging to a configurable denylist.
+
+.. code-block:: c++
+
+  // Call some async API while holding a lock.
+  {
+const my::MutexLock l(&mu_);
+
+// Oops! The async Bar function may finish on a different
+// thread from the one that created the MutexLock object and therefore 
called
+// Mutex::Lock -- now Mutex::Unlock will be called on the wrong thread.
+co_await Bar();
+  }
+
+
+Options
+---
+
+.. option:: RAIIDenyList
+
+   A semicolon-separated list of qualified types which should not be allowed 
to 
+   persist across suspension points.

PiotrZSL wrote:

do not wrap line on "Do"

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,48 @@
+.. title:: clang-tidy - misc-coroutine-hostile-raii
+
+misc-coroutine-hostile-raii
+
+
+This check detects hostile-RAII objects which should not persist across a 
+suspension point in a coroutine.
+
+Some objects require that they be destroyed on the same thread that created 
them. 
+Traditionally this requirement was often phrased as "must be a local variable",
+under the assumption that local variables always work this way. However this is
+incorrect with C++20 coroutines, since an intervening `co_await` may cause the
+coroutine to suspend and later be resumed on another thread.
+
+The lifetime of an object that requires being destroyed on the same thread 
must 
+not encompass a `co_await` or `co_yield` point. If you create/destroy an 
object,
+you must do so without allowing the coroutine to suspend in the meantime.
+
+The check considers the following type as hostile:
+
+ - Scoped-lockable types: A scoped-lockable object persisting across a 
suspension
+ point is problematic as the lock held by this object could be unlocked by a 
+ different thread. This would be undefined behaviour.
+
+ - Types belonging to a configurable denylist.
+
+.. code-block:: c++
+
+  // Call some async API while holding a lock.
+  {
+const my::MutexLock l(&mu_);
+
+// Oops! The async Bar function may finish on a different
+// thread from the one that created the MutexLock object and therefore 
called
+// Mutex::Lock -- now Mutex::Unlock will be called on the wrong thread.
+co_await Bar();
+  }
+
+
+Options
+---
+
+.. option:: RAIIDenyList
+
+   A semicolon-separated list of qualified types which should not be allowed 
to 
+   persist across suspension points.
+   Do not include `::` in the beginning of the qualified name.
+   Eg: `my::lockable; a::b; ::my::other::lockable;`

PiotrZSL wrote:

At info at the end about default value.

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-11 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for working on this! I think the changes should come with a release 
note so users know about the fix. I did have a question on the design, but 
overall the direction seems sensible to me.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,48 @@
+.. title:: clang-tidy - misc-coroutine-hostile-raii
+
+misc-coroutine-hostile-raii
+
+
+This check detects hostile-RAII objects which should not persist across a 
+suspension point in a coroutine.
+
+Some objects require that they be destroyed on the same thread that created 
them. 
+Traditionally this requirement was often phrased as "must be a local variable",
+under the assumption that local variables always work this way. However this is
+incorrect with C++20 coroutines, since an intervening `co_await` may cause the
+coroutine to suspend and later be resumed on another thread.
+
+The lifetime of an object that requires being destroyed on the same thread 
must 
+not encompass a `co_await` or `co_yield` point. If you create/destroy an 
object,
+you must do so without allowing the coroutine to suspend in the meantime.
+
+The check considers the following type as hostile:
+
+ - Scoped-lockable types: A scoped-lockable object persisting across a 
suspension
+ point is problematic as the lock held by this object could be unlocked by a 
+ different thread. This would be undefined behaviour.
+
+ - Types belonging to a configurable denylist.
+
+.. code-block:: c++
+
+  // Call some async API while holding a lock.
+  {
+const my::MutexLock l(&mu_);
+
+// Oops! The async Bar function may finish on a different
+// thread from the one that created the MutexLock object and therefore 
called
+// Mutex::Lock -- now Mutex::Unlock will be called on the wrong thread.
+co_await Bar();
+  }
+
+
+Options
+---
+
+.. option:: RAIIDenyList
+
+   A semicolon-separated list of qualified types which should not be allowed 
to 
+   persist across suspension points.
+   Do not include `::` in the beginning of the qualified name.
+   Eg: `my::lockable; a::b; ::my::other::lockable;`

PiotrZSL wrote:

spaces shouldn't be used in this list.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -241,6 +241,7 @@ Clang-Tidy Checks
:doc:`llvmlibc-restrict-system-libc-headers 
`, "Yes"
:doc:`misc-confusable-identifiers `,
:doc:`misc-const-correctness `, "Yes"
+   :doc:`misc-coroutine-hostile-raii `_, 
"Yes"

PiotrZSL wrote:

Check does not provided auto-fixes, remove "Yes"

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,82 @@
+//===--- CoroutineSuspensionHostileCheck.cpp - clang-tidy --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CoroutineHostileRAIICheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+CoroutineHostileRAIICheck::CoroutineHostileRAIICheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+  for (StringRef Denied :
+   utils::options::parseStringList(Options.get("RAIIDenyList", ""))) {
+Denied.consume_front("::");
+RAIIDenyList.push_back(Denied);
+  }
+}
+
+void CoroutineHostileRAIICheck::registerMatchers(MatchFinder *Finder) {
+  // A suspension happens with co_await or co_yield.
+  Finder->addMatcher(coawaitExpr().bind("suspension"), this);
+  Finder->addMatcher(coyieldExpr().bind("suspension"), this);
+}
+
+void CoroutineHostileRAIICheck::checkVarDecl(VarDecl *VD) {

PiotrZSL wrote:

What about static local variables ? Maybe they should be excluded as they wont 
be destroyed during leaving a function.

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-11 Thread Erich Keane via cfe-commits


@@ -186,14 +186,14 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
-  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; }
-
+  bool isAlignas() const { return IsAlignas; }
+  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }

erichkeane wrote:

I can see this both ways. It is typically used AFAIK as a 'is this a C++ 
spelling' despite not exactly meaning that.  On the other hand, as Aaron 
mentions, this is changing its meaning fairly significantly.  I'm still on the 
fence here.

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-11 Thread Erich Keane via cfe-commits


@@ -186,14 +186,14 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
-  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; }
-
+  bool isAlignas() const { return IsAlignas; }
+  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
   /// attributes spelled with a keyword, like alignas.
   bool isStandardAttributeSyntax() const {
-return isCXX11Attribute() || isC23Attribute();
+return isCXX11Attribute() || isC23Attribute() || IsAlignas;

erichkeane wrote:

So THIS one I definitely think shouldn't change.  BUT this shows another 
situation where `isCXX11Attribute` is being misused.

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,131 @@
+// RUN: %check_clang_tidy -std=c++20 %s misc-coroutine-hostile-raii %t \
+// RUN:   -config="{CheckOptions: \
+// RUN: {misc-coroutine-hostile-raii.RAIIDenyList: \
+// RUN:   'my::Mutex; ::my::other::Mutex'}}"
+
+namespace std {
+
+template  struct coroutine_traits {
+  using promise_type = typename R::promise_type;
+};
+
+template  struct coroutine_handle;
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *addr) noexcept {
+coroutine_handle me;
+me.ptr = addr;
+return me;
+  }
+  void operator()() { resume(); }
+  void *address() const noexcept { return ptr; }
+  void resume() const {  }
+  void destroy() const { }
+  bool done() const { return true; }
+  coroutine_handle &operator=(decltype(nullptr)) {
+ptr = nullptr;
+return *this;
+  }
+  coroutine_handle(decltype(nullptr)) : ptr(nullptr) {}
+  coroutine_handle() : ptr(nullptr) {}
+  //  void reset() { ptr = nullptr; } // add to P0057?
+  explicit operator bool() const { return ptr; }
+
+protected:
+  void *ptr;
+};
+
+template  struct coroutine_handle : coroutine_handle<> {
+  using coroutine_handle<>::operator=;
+
+  static coroutine_handle from_address(void *addr) noexcept {
+coroutine_handle me;
+me.ptr = addr;
+return me;
+  }
+
+  Promise &promise() const {
+return *reinterpret_cast(
+__builtin_coro_promise(ptr, alignof(Promise), false));
+  }
+  static coroutine_handle from_promise(Promise &promise) {
+coroutine_handle p;
+p.ptr = __builtin_coro_promise(&promise, alignof(Promise), true);
+return p;
+  }
+};
+
+struct suspend_always {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+} // namespace std
+
+struct ReturnObject {
+struct promise_type {
+ReturnObject get_return_object() { return {}; }
+std::suspend_always initial_suspend() { return {}; }
+std::suspend_always final_suspend() noexcept { return {}; }
+void unhandled_exception() {}
+std::suspend_always yield_value(int value) { return {}; }
+};
+};
+
+
+#define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
+
+namespace absl {
+class SCOPED_LOCKABLE Mutex {};
+using Mutex2 = Mutex;
+} // namespace absl
+
+
+ReturnObject scopedLockableTest() {
+absl::Mutex a;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'a' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+absl::Mutex2 b;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'b' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+{
+absl::Mutex no_warning_1;
+{ absl::Mutex no_warning_2; }
+}
+
+co_yield 1;
+absl::Mutex c;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'c' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+co_await std::suspend_always{};
+for(int i=1;i<=10;++i ) {
+  absl::Mutex d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'd' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+  co_await std::suspend_always{};
+  co_yield 1;
+  absl::Mutex no_warning_3;
+}
+if (true) {
+  absl::Mutex e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'e' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+  co_yield 1;
+  absl::Mutex no_warning_4;
+}
+absl::Mutex no_warning_5;
+}
+namespace my {
+class Mutex{};
+
+namespace other {
+class Mutex{};
+} // namespace other
+
+using Mutex2 = Mutex;
+} // namespace my
+
+ReturnObject denyListTest() {
+my::Mutex a;
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'a' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+my::other::Mutex b;
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'b' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+my::Mutex2 c;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'c' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+co_yield 1;
+}

PiotrZSL wrote:

add test with mutex being just an reference or pointer, like
```
ReturnObject denyListTest(my::Mutex& ref) {
my::Mutex& a = ref;
 
co_yield 1;
}
```

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


[PATCH] D154581: [clang][Interp] Track existing InitMaps in InterpState

2023-10-11 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/Descriptor.cpp:42
 const Descriptor *D) {
+  new (Ptr) InitMapPtr(std::nullopt);
+

tbaeder wrote:
> aaron.ballman wrote:
> > This worries me a little bit for a few reasons, but it might be okay:
> > 
> > * What validates that the bytes pointed to by `Ptr` are aligned properly 
> > for an `InitMapPtr` object? Perhaps we need an `alignas` in the function 
> > signature to ensure correct alignment of those bytes?
> > * `InitMapPtr` is `std::optional > std::shared_ptr>>` and I *think* using placement new will ensure 
> > we have correct objects in all the expected places, but I'm not 100% sure 
> > because we're calling the `nullopt` constructor here.
> > * I *think* it is correct that you are not assigning the result of the 
> > placement `new` expression into anything; and I think we need this 
> > placement `new` because of the `reinterpret_cast` happening in 
> > `dtorArrayTy()`. But it is a bit strange to see the placement `new` hanging 
> > off on its own like this. Might be worth some comments explaining. 
> > 
> > CC @hubert.reinterpretcast @rsmith in case my assessment is incorrect.
> I thought using placement new would just call the normal constructors anyway?
> 
> BTW, does using a `shared_ptr` here even make sense? Since this is allocated 
> in the `Block`, we need to call the constructor and destructors manually 
> anyway.
> I thought using placement new would just call the normal constructors anyway?

It should, so I think all the lifetime issues are accounted for, but this area 
of C++ is poorly understood at the best of times.

> BTW, does using a shared_ptr here even make sense? Since this is allocated in 
> the Block, we need to call the constructor and destructors manually anyway.

I think it makes sense as we're intentionally sharing the pointer, aren't we? 
So we'll call the ctors/dtors manually in this case, but other objects holding 
the shared pointer don't have to worry about the pointer being yanked out from 
under them.


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

https://reviews.llvm.org/D154581

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,131 @@
+// RUN: %check_clang_tidy -std=c++20 %s misc-coroutine-hostile-raii %t \
+// RUN:   -config="{CheckOptions: \
+// RUN: {misc-coroutine-hostile-raii.RAIIDenyList: \
+// RUN:   'my::Mutex; ::my::other::Mutex'}}"
+
+namespace std {
+
+template  struct coroutine_traits {
+  using promise_type = typename R::promise_type;
+};
+
+template  struct coroutine_handle;
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *addr) noexcept {
+coroutine_handle me;
+me.ptr = addr;
+return me;
+  }
+  void operator()() { resume(); }
+  void *address() const noexcept { return ptr; }
+  void resume() const {  }
+  void destroy() const { }
+  bool done() const { return true; }
+  coroutine_handle &operator=(decltype(nullptr)) {
+ptr = nullptr;
+return *this;
+  }
+  coroutine_handle(decltype(nullptr)) : ptr(nullptr) {}
+  coroutine_handle() : ptr(nullptr) {}
+  //  void reset() { ptr = nullptr; } // add to P0057?
+  explicit operator bool() const { return ptr; }
+
+protected:
+  void *ptr;
+};
+
+template  struct coroutine_handle : coroutine_handle<> {
+  using coroutine_handle<>::operator=;
+
+  static coroutine_handle from_address(void *addr) noexcept {
+coroutine_handle me;
+me.ptr = addr;
+return me;
+  }
+
+  Promise &promise() const {
+return *reinterpret_cast(
+__builtin_coro_promise(ptr, alignof(Promise), false));
+  }
+  static coroutine_handle from_promise(Promise &promise) {
+coroutine_handle p;
+p.ptr = __builtin_coro_promise(&promise, alignof(Promise), true);
+return p;
+  }
+};
+
+struct suspend_always {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+} // namespace std
+
+struct ReturnObject {
+struct promise_type {
+ReturnObject get_return_object() { return {}; }
+std::suspend_always initial_suspend() { return {}; }
+std::suspend_always final_suspend() noexcept { return {}; }
+void unhandled_exception() {}
+std::suspend_always yield_value(int value) { return {}; }
+};
+};
+
+
+#define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
+
+namespace absl {
+class SCOPED_LOCKABLE Mutex {};
+using Mutex2 = Mutex;
+} // namespace absl
+
+
+ReturnObject scopedLockableTest() {
+absl::Mutex a;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'a' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+absl::Mutex2 b;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'b' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+{
+absl::Mutex no_warning_1;
+{ absl::Mutex no_warning_2; }
+}
+
+co_yield 1;
+absl::Mutex c;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'c' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+co_await std::suspend_always{};
+for(int i=1;i<=10;++i ) {
+  absl::Mutex d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'd' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+  co_await std::suspend_always{};
+  co_yield 1;
+  absl::Mutex no_warning_3;
+}
+if (true) {
+  absl::Mutex e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'e' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+  co_yield 1;
+  absl::Mutex no_warning_4;
+}
+absl::Mutex no_warning_5;
+}
+namespace my {
+class Mutex{};
+
+namespace other {
+class Mutex{};
+} // namespace other
+
+using Mutex2 = Mutex;
+} // namespace my
+
+ReturnObject denyListTest() {
+my::Mutex a;
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'a' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+my::other::Mutex b;
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'b' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+my::Mutex2 c;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'c' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+co_yield 1;
+}

PiotrZSL wrote:

Add test with mutex used as an function argument:
```
ReturnObject denyListTest(my::Mutex ref) {
```

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,131 @@
+// RUN: %check_clang_tidy -std=c++20 %s misc-coroutine-hostile-raii %t \
+// RUN:   -config="{CheckOptions: \
+// RUN: {misc-coroutine-hostile-raii.RAIIDenyList: \
+// RUN:   'my::Mutex; ::my::other::Mutex'}}"
+
+namespace std {
+
+template  struct coroutine_traits {
+  using promise_type = typename R::promise_type;
+};
+
+template  struct coroutine_handle;
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *addr) noexcept {
+coroutine_handle me;
+me.ptr = addr;
+return me;
+  }
+  void operator()() { resume(); }
+  void *address() const noexcept { return ptr; }
+  void resume() const {  }
+  void destroy() const { }
+  bool done() const { return true; }
+  coroutine_handle &operator=(decltype(nullptr)) {
+ptr = nullptr;
+return *this;
+  }
+  coroutine_handle(decltype(nullptr)) : ptr(nullptr) {}
+  coroutine_handle() : ptr(nullptr) {}
+  //  void reset() { ptr = nullptr; } // add to P0057?
+  explicit operator bool() const { return ptr; }
+
+protected:
+  void *ptr;
+};
+
+template  struct coroutine_handle : coroutine_handle<> {
+  using coroutine_handle<>::operator=;
+
+  static coroutine_handle from_address(void *addr) noexcept {
+coroutine_handle me;
+me.ptr = addr;
+return me;
+  }
+
+  Promise &promise() const {
+return *reinterpret_cast(
+__builtin_coro_promise(ptr, alignof(Promise), false));
+  }
+  static coroutine_handle from_promise(Promise &promise) {
+coroutine_handle p;
+p.ptr = __builtin_coro_promise(&promise, alignof(Promise), true);
+return p;
+  }
+};
+
+struct suspend_always {
+  bool await_ready() noexcept { return false; }
+  void await_suspend(std::coroutine_handle<>) noexcept {}
+  void await_resume() noexcept {}
+};
+} // namespace std
+
+struct ReturnObject {
+struct promise_type {
+ReturnObject get_return_object() { return {}; }
+std::suspend_always initial_suspend() { return {}; }
+std::suspend_always final_suspend() noexcept { return {}; }
+void unhandled_exception() {}
+std::suspend_always yield_value(int value) { return {}; }
+};
+};
+
+
+#define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
+
+namespace absl {
+class SCOPED_LOCKABLE Mutex {};
+using Mutex2 = Mutex;
+} // namespace absl
+
+
+ReturnObject scopedLockableTest() {
+absl::Mutex a;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'a' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+absl::Mutex2 b;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'b' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+{
+absl::Mutex no_warning_1;
+{ absl::Mutex no_warning_2; }
+}
+
+co_yield 1;
+absl::Mutex c;
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: 'c' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+co_await std::suspend_always{};
+for(int i=1;i<=10;++i ) {
+  absl::Mutex d;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'd' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+  co_await std::suspend_always{};
+  co_yield 1;
+  absl::Mutex no_warning_3;
+}
+if (true) {
+  absl::Mutex e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 'e' holds a lock across a 
suspension point of coroutine and could be unlocked by a different thread 
[misc-coroutine-hostile-raii]
+  co_yield 1;
+  absl::Mutex no_warning_4;
+}
+absl::Mutex no_warning_5;
+}
+namespace my {
+class Mutex{};
+
+namespace other {
+class Mutex{};
+} // namespace other
+
+using Mutex2 = Mutex;
+} // namespace my
+
+ReturnObject denyListTest() {
+my::Mutex a;
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 'a' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+my::other::Mutex b;
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'b' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+my::Mutex2 c;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: 'c' persists across a 
suspension point of coroutine [misc-coroutine-hostile-raii]
+co_yield 1;
+}

PiotrZSL wrote:

add explicit test with mutex being on higher level:
```
{
   mutex mtx;

   {
   co_yield ;
   }
}
```

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


[clang-tools-extra] [clang-tidy] Add check to diagnose coroutine-hostile RAII objects (PR #68738)

2023-10-11 Thread Piotr Zegar via cfe-commits

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

>From functional point of view doesn't look do bad.
My main concerns is about that 3 nested for-loops and ifs, this need to be 
refactored to show more clear that it's trying to match varDecl defined before 
suspension point.

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-11 Thread Aaron Ballman via cfe-commits


@@ -186,14 +186,14 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
-  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; }
-
+  bool isAlignas() const { return IsAlignas; }
+  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
   /// attributes spelled with a keyword, like alignas.
   bool isStandardAttributeSyntax() const {
-return isCXX11Attribute() || isC23Attribute();
+return isCXX11Attribute() || isC23Attribute() || IsAlignas;

AaronBallman wrote:

I think `isCXX11Attribute()` was being used properly there, at least per the 
comment. But you're right, this one now changed behavior in C23 because it will 
treat `_Alignas` as a standard attribute.

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


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Kiran Chandramohan via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

kiranchandramohan wrote:

That could be because `glbl` can be passed as one of the arguments to the 
subroutine `func` and hence alias.

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


[PATCH] D153001: [clang][ThreadSafety] Add __builtin_instance_member (WIP)

2023-10-11 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder abandoned this revision.
tbaeder added a comment.

As discussed via other channels, this is going nowhere and we will take another 
approach, if any.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153001

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


  1   2   3   >