[clang] [Clang] Add __datasizeof (PR #67805)

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

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


[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70217)

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

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

>From 26b9570fadf428e2f55efe0f2d9433cf18305239 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 25 Oct 2023 16:55:15 +0200
Subject: [PATCH 1/2] friend operator!=

---
 clang/lib/Sema/SemaOverload.cpp   | 11 +
 .../over.match.oper/p3-2a.cpp | 23 +++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index db386fef0661c05..ce7503162ef3ba3 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -960,15 +960,18 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
   if (FunctionsCorrespond(S.Context, EqFD, Op->getAsFunction()))
 return false;
 return true;
-  }
+  } 
   // Otherwise the search scope is the namespace scope of which F is a member.
-  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
+  DeclContext *EqDC = EqFD->getEnclosingNamespaceContext();
+  for (NamedDecl *Op : EqDC->lookup(NotEqOp)) {
 auto *NotEqFD = Op->getAsFunction();
+DeclContext *NotEqDC = Op->getFriendObjectKind()
+   ? NotEqFD->getEnclosingNamespaceContext()
+   : Op->getLexicalDeclContext();
 if (auto *UD = dyn_cast(Op))
   NotEqFD = UD->getUnderlyingDecl()->getAsFunction();
 if (FunctionsCorrespond(S.Context, EqFD, NotEqFD) && S.isVisible(NotEqFD) 
&&
-declaresSameEntity(cast(EqFD->getEnclosingNamespaceContext()),
-   cast(Op->getLexicalDeclContext(
+declaresSameEntity(cast(EqDC), cast(NotEqDC)))
   return false;
   }
   return true;
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index d83a176ec07eec9..603c91bd535f434 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -324,6 +324,29 @@ bool x = X() == X(); // expected-warning {{ambiguous}}
 }
 } // namespace P2468R2
 
+namespace friend_opNE_GH{
+namespace test1 {
+struct S {
+operator int();
+friend bool operator==(const S &, int); // expected-note {{reversed}}
+};
+struct A : S {};
+struct B : S {};
+bool x = A{} == B{}; // expected-warning {{ambiguous}}
+} // namespace test1
+
+namespace test2 {
+struct S {
+operator int();
+friend bool operator==(const S &, int);
+friend bool operator!=(const S &, int);
+};
+struct A : public P {};
+struct B : public P {};
+bool check(A a, B b) { return a == b; } // expected-warning {{use of 
overloaded operator '==' (with operand types 'A' and 'B') to be ambiguous}}
+} // namespace test2
+} // namespace friend_opNE_GH
+
 namespace ADL_GH68901{
 namespace test1 {
 namespace A {

>From 538c4e2d0244b2da4f0023bc17768448d728b6ce Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 25 Oct 2023 16:57:01 +0200
Subject: [PATCH 2/2] remove space

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

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ce7503162ef3ba3..3b6b474886340eb 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -960,7 +960,7 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
   if (FunctionsCorrespond(S.Context, EqFD, Op->getAsFunction()))
 return false;
 return true;
-  } 
+  }
   // Otherwise the search scope is the namespace scope of which F is a member.
   DeclContext *EqDC = EqFD->getEnclosingNamespaceContext();
   for (NamedDecl *Op : EqDC->lookup(NotEqOp)) {

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


[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70217)

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

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/70217

The namespace lookup should give a matching friend operator!= as friend 
functions belong to the namespace scope (as opposed to the lexical class scope).

Thus to resolve ambiguity of operator== with itself, defining a corresponding 
friend operator!= should suffice.

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

>From 26b9570fadf428e2f55efe0f2d9433cf18305239 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 25 Oct 2023 16:55:15 +0200
Subject: [PATCH] friend operator!=

---
 clang/lib/Sema/SemaOverload.cpp   | 11 +
 .../over.match.oper/p3-2a.cpp | 23 +++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index db386fef0661c05..ce7503162ef3ba3 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -960,15 +960,18 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
   if (FunctionsCorrespond(S.Context, EqFD, Op->getAsFunction()))
 return false;
 return true;
-  }
+  } 
   // Otherwise the search scope is the namespace scope of which F is a member.
-  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
+  DeclContext *EqDC = EqFD->getEnclosingNamespaceContext();
+  for (NamedDecl *Op : EqDC->lookup(NotEqOp)) {
 auto *NotEqFD = Op->getAsFunction();
+DeclContext *NotEqDC = Op->getFriendObjectKind()
+   ? NotEqFD->getEnclosingNamespaceContext()
+   : Op->getLexicalDeclContext();
 if (auto *UD = dyn_cast(Op))
   NotEqFD = UD->getUnderlyingDecl()->getAsFunction();
 if (FunctionsCorrespond(S.Context, EqFD, NotEqFD) && S.isVisible(NotEqFD) 
&&
-declaresSameEntity(cast(EqFD->getEnclosingNamespaceContext()),
-   cast(Op->getLexicalDeclContext(
+declaresSameEntity(cast(EqDC), cast(NotEqDC)))
   return false;
   }
   return true;
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index d83a176ec07eec9..603c91bd535f434 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -324,6 +324,29 @@ bool x = X() == X(); // expected-warning {{ambiguous}}
 }
 } // namespace P2468R2
 
+namespace friend_opNE_GH{
+namespace test1 {
+struct S {
+operator int();
+friend bool operator==(const S &, int); // expected-note {{reversed}}
+};
+struct A : S {};
+struct B : S {};
+bool x = A{} == B{}; // expected-warning {{ambiguous}}
+} // namespace test1
+
+namespace test2 {
+struct S {
+operator int();
+friend bool operator==(const S &, int);
+friend bool operator!=(const S &, int);
+};
+struct A : public P {};
+struct B : public P {};
+bool check(A a, B b) { return a == b; } // expected-warning {{use of 
overloaded operator '==' (with operand types 'A' and 'B') to be ambiguous}}
+} // namespace test2
+} // namespace friend_opNE_GH
+
 namespace ADL_GH68901{
 namespace test1 {
 namespace A {

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


[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70216)

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

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


[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70213)

2023-10-25 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 84d8ace51a5afb07b528f65cde091cf3dbd7c326 
183209f71b08a1fdba335d89c906cd26483115c1 -- clang/lib/Sema/SemaOverload.cpp 
clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 30bde49636b2..807a07a35d69 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -12119,8 +12119,7 @@ struct CompareOverloadCandidatesForDisplay {
 int leftBetter = 0;
 unsigned I = (L->IgnoreObjectArgument || R->IgnoreObjectArgument);
 for (unsigned E = L->Conversions.size(); I != E; ++I) {
-  switch (CompareImplicitConversionSequences(S, Loc,
- L->Conversions[I],
+  switch (CompareImplicitConversionSequences(S, Loc, L->Conversions[I],
  R->Conversions[I])) {
   case ImplicitConversionSequence::Better:
 leftBetter++;
@@ -12134,8 +12133,10 @@ struct CompareOverloadCandidatesForDisplay {
 break;
   }
 }
-if (leftBetter > 0) return true;
-if (leftBetter < 0) return false;
+if (leftBetter > 0)
+  return true;
+if (leftBetter < 0)
+  return false;
 
   } else if (RFailureKind == ovl_fail_bad_conversion)
 return false;
@@ -12158,13 +12159,15 @@ struct CompareOverloadCandidatesForDisplay {
 SourceLocation RLoc = GetLocationForCandidate(R);
 
 // Put candidates without locations (e.g. builtins) at the end.
-if (LLoc.isInvalid()) return false;
-if (RLoc.isInvalid()) return true;
+if (LLoc.isInvalid())
+  return false;
+if (RLoc.isInvalid())
+  return true;
 
 return S.SourceMgr.isBeforeInTranslationUnit(LLoc, RLoc);
   }
 };
-}
+} // namespace
 
 /// CompleteNonViableCandidate - Normally, overload resolution only
 /// computes up to the first bad conversion. Produces the FixIt set if

``




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


[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70213)

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

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


[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70216)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Utkarsh Saxena (usx95)


Changes

The namespace lookup should give a matching friend operator!= as friend 
functions belong to the namespace scope (as opposed to the lexical class scope).

Thus to resolve ambiguity of operator== with itself, defining a corresponding 
friend operator!= should suffice.

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

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaOverload.cpp (+7-4) 
- (modified) 
clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
(+163) 


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index db386fef0661c05..92a58b3c3cf5ed7 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -14,6 +14,7 @@
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclFriend.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DependenceFlags.h"
 #include "clang/AST/Expr.h"
@@ -962,13 +963,16 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
 return true;
   }
   // Otherwise the search scope is the namespace scope of which F is a member.
-  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
+  DeclContext *EqDC = EqFD->getEnclosingNamespaceContext();
+  for (NamedDecl *Op : EqDC->lookup(NotEqOp)) {
 auto *NotEqFD = Op->getAsFunction();
+DeclContext *NotEqDC = Op->getFriendObjectKind()
+   ? NotEqFD->getEnclosingNamespaceContext()
+   : Op->getLexicalDeclContext();
 if (auto *UD = dyn_cast(Op))
   NotEqFD = UD->getUnderlyingDecl()->getAsFunction();
 if (FunctionsCorrespond(S.Context, EqFD, NotEqFD) && S.isVisible(NotEqFD) 
&&
-declaresSameEntity(cast(EqFD->getEnclosingNamespaceContext()),
-   cast(Op->getLexicalDeclContext(
+declaresSameEntity(cast(EqDC), cast(NotEqDC)))
   return false;
   }
   return true;
@@ -10086,7 +10090,6 @@ static bool haveSameParameterTypes(ASTContext , 
const FunctionDecl *F1,
const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
-
   auto NextParam = [&](const FunctionDecl *F, unsigned , bool First) {
 if (First) {
   if (std::optional T = getImplicitObjectParamType(Context, F))
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index d83a176ec07eec9..ec3cf18b377dfce 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -403,6 +403,169 @@ bool h(X x) {
   return x == x; // expected-warning {{ambiguous}}
 }
 
+namespace friend_opNE_GH{
+namespace test1 {
+struct S {
+operator int();
+friend bool operator==(const S &, int); // expected-note {{reversed}}
+};
+struct A : S {};
+struct B : S {};
+bool x = A{} == B{}; // expected-warning {{ambiguous}}
+}
+
+namespace test2 {
+struct S {
+operator int();
+friend bool operator==(const S &, int);
+friend bool operator!=(const S &, int);
+};
+struct A : public P {};
+struct B : public P {};
+bool check(A a, B b) { return a == b; } // expected-warning {{use of 
overloaded operator '==' (with operand types 'A' and 'B') to be ambiguous}}
+}
+
+namespace non_member_template_1 {
+struct P {};
+template
+bool operator==(const P&, const S &); // expected-note {{candidate}} \
+  // expected-note {{ambiguous candidate 
function with reversed arguments}}
+
+struct A : public P {};
+struct B : public P {};
+bool check(A a, B b) { return a == b; } // expected-warning {{use of 
overloaded operator '==' (with operand types 'A' and 'B') to be ambiguous}}
+
+template
+bool operator!=(const P&, const S &);
+bool fine(A a, B b) { return a == b; } // Ok. Found a matching operator!=.
+}
+}
+
+namespace friend_opNE_GH{
+namespace test1 {
+struct S {
+operator int();
+friend bool operator==(const S &, int); // expected-note {{reversed}}
+};
+struct A : S {};
+struct B : S {};
+bool x = A{} == B{}; // expected-warning {{ambiguous}}
+}
+
+namespace test2 {
+struct S {
+operator int();
+friend bool operator==(const S &, int);
+friend bool operator!=(const S &, int);
+};
+struct A : S {};
+struct B : S {};
+bool x = A{} == B{};
+}
+}
+
+namespace ADL_GH68901{
+namespace test1 {
+namespace A {
+struct S {};
+bool operator==(S, int); // expected-note {{no known conversion from 'int' to 
'S' for 1st argument}}
+bool a = 0 == A::S(); // Ok. Operator!= not visible.
+bool operator!=(S, int);
+} // namespace A
+bool a = 0 == A::S(); // expected-error {{invalid operands to binary 
expression 

[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70216)

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

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/70216

The namespace lookup should give a matching friend operator!= as friend 
functions belong to the namespace scope (as opposed to the lexical class scope).

Thus to resolve ambiguity of operator== with itself, defining a corresponding 
friend operator!= should suffice.

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

>From 8aa439a97a56ef80bfc9ccc90a9f093680e455f5 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Sun, 22 Oct 2023 11:11:53 +0200
Subject: [PATCH 1/4] rebase...

---
 clang/docs/ReleaseNotes.rst   |  4 +
 clang/lib/Sema/SemaOverload.cpp   | 19 ++---
 .../over.match.oper/p3-2a.cpp | 78 +++
 3 files changed, 89 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a9a67f7451c092..cef857244387e8b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -85,6 +85,10 @@ C/C++ Language Potentially Breaking Changes
 ``__has_c_attribute(warn_unused_result)``,  202003, 0
 ``__has_c_attribute(gnu::warn_unused_result)``, 202003, 1
 
+- Fixed a bug in finding matching `operator!=` while adding reversed 
`operator==` as
+  outlined in "The Equality Operator You Are Looking For" (`P2468 
`_).
+  Fixes (`#68901: `_).
+
 C++ Specific Potentially Breaking Changes
 -
 - The name mangling rules for function templates has been changed to take into
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index d57a7ad8f46859a..75e4184c8aa6cb8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -960,18 +960,13 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
 return true;
   }
   // Otherwise the search scope is the namespace scope of which F is a member.
-  LookupResult NonMembers(S, NotEqOp, OpLoc,
-  Sema::LookupNameKind::LookupOperatorName);
-  S.LookupName(NonMembers,
-   S.getScopeForContext(EqFD->getEnclosingNamespaceContext()));
-  NonMembers.suppressAccessDiagnostics();
-  for (NamedDecl *Op : NonMembers) {
-auto *FD = Op->getAsFunction();
-if(auto* UD = dyn_cast(Op))
-  FD = UD->getUnderlyingDecl()->getAsFunction();
-if (FunctionsCorrespond(S.Context, EqFD, FD) &&
-declaresSameEntity(cast(EqFD->getDeclContext()),
-   cast(Op->getDeclContext(
+  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
+auto *NotEqFD = Op->getAsFunction();
+if (auto *UD = dyn_cast(Op))
+  NotEqFD = UD->getUnderlyingDecl()->getAsFunction();
+if (FunctionsCorrespond(S.Context, EqFD, NotEqFD) &&
+declaresSameEntity(cast(EqFD->getEnclosingNamespaceContext()),
+   cast(Op->getLexicalDeclContext(
   return false;
   }
   return true;
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index 5727d506fe5e61d..9dc5ee8db565341 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -374,6 +374,84 @@ bool fine(A a, B b) { return a == b; } // Ok. Found a 
matching operator!=.
 }
 }
 
+
+namespace ADL_GH68901{
+namespace A {
+struct S {};
+bool operator==(S, int); // expected-note {{no known conversion from 'int' to 
'S' for 1st argument}}
+bool operator!=(S, int);
+} // namespace A
+bool a = 0 == A::S(); // expected-error {{invalid operands to binary 
expression ('int' and 'A::S')}}
+
+namespace B {
+struct Derived {};
+struct Base : Derived {};
+
+bool operator==(Derived& a, Base& b);
+bool operator!=(Derived& a, Base& b);
+}  // namespace B
+
+void foo() {
+  // B::Base{} == B::Base{};
+  B::Base a,b;
+  bool v = a == b;
+}
+
+namespace ns {
+template 
+struct A {
+};
+
+template 
+struct B : A {
+};
+
+template  bool operator == (B, A); // expected-note {{candidate 
template ignored: could not match 'B' against 'A'}}
+template  bool operator != (B, A);
+}
+
+void test() {
+ns::A a;
+ns::B b;
+a == b; // expected-error {{invalid operands to binary expression}}
+}
+
+
+} //namespace ADL_GH68901
+
+namespace function_scope_operator_eqeq {
+// For non-members, we always lookup for matching operator!= in the namespace 
scope of
+// operator== (and not in the scope of operator==).
+struct X { operator int(); };
+namespace test1{
+bool h(X x) {
+  bool operator==(X, int); // expected-note {{reversed}}
+  return x == x; // expected-warning {{ambiguous}}
+}
+
+bool g(X x) {
+  bool operator==(X, int); // expected-note {{reversed}}
+  bool operator!=(X, int);
+  return x == x;  // expected-warning 

[clang-tools-extra] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

2023-10-25 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+
+#define CORO_TYPE [[clang::annotate("coro_type")]]
+#define CORO_UNSAFE [[clang::annotate("coro_unsafe")]]
+
+template  struct CORO_TYPE Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T );
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+template  using Co = Gen;
+
+Gen foo_coro(const int& b);
+
+Gen plain_return_foo_decl(int b) {
+  return foo_coro(b); // expected-warning {{address of stack memory associated 
with parameter}}
+}
+
+Gen foo_coro(const int& b) {
+  if (b > 0)
+co_return 1;
+  co_return 2;
+}
+
+int getInt() { return 0; }
+
+Co bar_coro(const int , int c) {
+  int x = co_await foo_coro(b);
+  int y = co_await foo_coro(1);

ChuanqiXu9 wrote:

How is this implemented? I mean how can we don't emit warnings to `co_await 
foo_coro(1)` but emit warnings to `auto unsafe1 = foo_coro(1);`? This is not 
showed in this patch itself.

I envision the reason may be that we will copy the parameters at the beginning 
of the coroutines. If it is indeed the reason, then it smells bad. Since the 
behavior depends that behavior implicitly.

For example, the behavior of `co_await foo_coro();` depends on the 
implementation of the corresponding awaiter. It is completely possible that 
`co_await foo_coro();` doing exactly the same thing with a standalone 
`foo_coro();`. But we may emit warnings for one place but not the other one.

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


[clang] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

2023-10-25 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

Thanks for bringing this! I didn't notice the post in discourse and I'll put 
higher level comments there.

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


[clang] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

2023-10-25 Thread Chuanqi Xu via cfe-commits

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


[clang] Recognize friend operator != to fix ambiguity with operator== (PR #70213)

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

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/70213

The namespace lookup should give a matching friend operator!= as friend 
functions belong to the namespace scope (as opposed to the lexical class scope).

Thus to resolve ambiguity of operator== with itself, defining a corresponding 
friend operator!= should suffice.

>From 8aa439a97a56ef80bfc9ccc90a9f093680e455f5 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Sun, 22 Oct 2023 11:11:53 +0200
Subject: [PATCH 1/4] rebase...

---
 clang/docs/ReleaseNotes.rst   |  4 +
 clang/lib/Sema/SemaOverload.cpp   | 19 ++---
 .../over.match.oper/p3-2a.cpp | 78 +++
 3 files changed, 89 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a9a67f7451c092..cef857244387e8b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -85,6 +85,10 @@ C/C++ Language Potentially Breaking Changes
 ``__has_c_attribute(warn_unused_result)``,  202003, 0
 ``__has_c_attribute(gnu::warn_unused_result)``, 202003, 1
 
+- Fixed a bug in finding matching `operator!=` while adding reversed 
`operator==` as
+  outlined in "The Equality Operator You Are Looking For" (`P2468 
`_).
+  Fixes (`#68901: `_).
+
 C++ Specific Potentially Breaking Changes
 -
 - The name mangling rules for function templates has been changed to take into
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index d57a7ad8f46859a..75e4184c8aa6cb8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -960,18 +960,13 @@ static bool shouldAddReversedEqEq(Sema , SourceLocation 
OpLoc,
 return true;
   }
   // Otherwise the search scope is the namespace scope of which F is a member.
-  LookupResult NonMembers(S, NotEqOp, OpLoc,
-  Sema::LookupNameKind::LookupOperatorName);
-  S.LookupName(NonMembers,
-   S.getScopeForContext(EqFD->getEnclosingNamespaceContext()));
-  NonMembers.suppressAccessDiagnostics();
-  for (NamedDecl *Op : NonMembers) {
-auto *FD = Op->getAsFunction();
-if(auto* UD = dyn_cast(Op))
-  FD = UD->getUnderlyingDecl()->getAsFunction();
-if (FunctionsCorrespond(S.Context, EqFD, FD) &&
-declaresSameEntity(cast(EqFD->getDeclContext()),
-   cast(Op->getDeclContext(
+  for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
+auto *NotEqFD = Op->getAsFunction();
+if (auto *UD = dyn_cast(Op))
+  NotEqFD = UD->getUnderlyingDecl()->getAsFunction();
+if (FunctionsCorrespond(S.Context, EqFD, NotEqFD) &&
+declaresSameEntity(cast(EqFD->getEnclosingNamespaceContext()),
+   cast(Op->getLexicalDeclContext(
   return false;
   }
   return true;
diff --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
index 5727d506fe5e61d..9dc5ee8db565341 100644
--- a/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
+++ b/clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp
@@ -374,6 +374,84 @@ bool fine(A a, B b) { return a == b; } // Ok. Found a 
matching operator!=.
 }
 }
 
+
+namespace ADL_GH68901{
+namespace A {
+struct S {};
+bool operator==(S, int); // expected-note {{no known conversion from 'int' to 
'S' for 1st argument}}
+bool operator!=(S, int);
+} // namespace A
+bool a = 0 == A::S(); // expected-error {{invalid operands to binary 
expression ('int' and 'A::S')}}
+
+namespace B {
+struct Derived {};
+struct Base : Derived {};
+
+bool operator==(Derived& a, Base& b);
+bool operator!=(Derived& a, Base& b);
+}  // namespace B
+
+void foo() {
+  // B::Base{} == B::Base{};
+  B::Base a,b;
+  bool v = a == b;
+}
+
+namespace ns {
+template 
+struct A {
+};
+
+template 
+struct B : A {
+};
+
+template  bool operator == (B, A); // expected-note {{candidate 
template ignored: could not match 'B' against 'A'}}
+template  bool operator != (B, A);
+}
+
+void test() {
+ns::A a;
+ns::B b;
+a == b; // expected-error {{invalid operands to binary expression}}
+}
+
+
+} //namespace ADL_GH68901
+
+namespace function_scope_operator_eqeq {
+// For non-members, we always lookup for matching operator!= in the namespace 
scope of
+// operator== (and not in the scope of operator==).
+struct X { operator int(); };
+namespace test1{
+bool h(X x) {
+  bool operator==(X, int); // expected-note {{reversed}}
+  return x == x; // expected-warning {{ambiguous}}
+}
+
+bool g(X x) {
+  bool operator==(X, int); // expected-note {{reversed}}
+  bool operator!=(X, int);
+  return x == x;  // expected-warning {{ambiguous}}
+}
+} // namespace test1
+
+namespace test2 {
+bool 

[clang] [AMDGPU] Rematerialize scalar loads (PR #68778)

2023-10-25 Thread Piotr Sobczak via cfe-commits

piotrAMD wrote:

Thanks. If there are no more comments, I will merge the change tomorrow.

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


[clang-tools-extra] [AMDGPU] Rematerialize scalar loads (PR #68778)

2023-10-25 Thread Piotr Sobczak via cfe-commits

piotrAMD wrote:

Thanks. If there are no more comments, I will merge the change tomorrow.

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


[PATCH] D61663: [clang-format] Fix a JavaScript import order bug.

2023-10-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 557879.
owenpan added a comment.

Make the test case pass.


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

https://reviews.llvm.org/D61663

Files:
  clang/lib/Format/SortJavaScriptImports.cpp
  clang/unittests/Format/SortImportsTestJS.cpp


Index: clang/unittests/Format/SortImportsTestJS.cpp
===
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -514,6 +514,14 @@
  "export {Y};\n");
 }
 
+TEST_F(SortImportsTestJS, TemplateKeyword) {
+  // Reproduces issue where importing "template" disables imports sorting.
+  verifySort("import {template} from './a';\n"
+ "import {b} from './b';\n",
+ "import {b} from './b';\n"
+ "import {template} from './a';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/SortJavaScriptImports.cpp
===
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -548,10 +548,12 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  bool isTypeOnly =
-  Current->is(Keywords.kw_type) && Current->Next &&
-  Current->Next->isOneOf(tok::identifier, tok::kw_default);
-  if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+  auto IsIdentifier = [](const auto *Tok) {
+return Tok->isOneOf(tok::identifier, tok::kw_default, 
tok::kw_template);
+  };
+  bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+IsIdentifier(Current->Next);
+  if (!isTypeOnly && !IsIdentifier(Current))
 return false;
 
   JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (!Current->isOneOf(tok::identifier, tok::kw_default))
+if (!IsIdentifier(Current))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();


Index: clang/unittests/Format/SortImportsTestJS.cpp
===
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -514,6 +514,14 @@
  "export {Y};\n");
 }
 
+TEST_F(SortImportsTestJS, TemplateKeyword) {
+  // Reproduces issue where importing "template" disables imports sorting.
+  verifySort("import {template} from './a';\n"
+ "import {b} from './b';\n",
+ "import {b} from './b';\n"
+ "import {template} from './a';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/SortJavaScriptImports.cpp
===
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -548,10 +548,12 @@
   nextToken();
   if (Current->is(tok::r_brace))
 break;
-  bool isTypeOnly =
-  Current->is(Keywords.kw_type) && Current->Next &&
-  Current->Next->isOneOf(tok::identifier, tok::kw_default);
-  if (!isTypeOnly && !Current->isOneOf(tok::identifier, tok::kw_default))
+  auto IsIdentifier = [](const auto *Tok) {
+return Tok->isOneOf(tok::identifier, tok::kw_default, tok::kw_template);
+  };
+  bool isTypeOnly = Current->is(Keywords.kw_type) && Current->Next &&
+IsIdentifier(Current->Next);
+  if (!isTypeOnly && !IsIdentifier(Current))
 return false;
 
   JsImportedSymbol Symbol;
@@ -565,7 +567,7 @@
 
   if (Current->is(Keywords.kw_as)) {
 nextToken();
-if (!Current->isOneOf(tok::identifier, tok::kw_default))
+if (!IsIdentifier(Current))
   return false;
 Symbol.Alias = Current->TokenText;
 nextToken();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61663: [clang-format] Fix a JavaScript import order bug.

2023-10-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan commandeered this revision.
owenpan edited reviewers, added: bowenni; removed: owenpan.
owenpan added a comment.

The test case doesn't pass.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61663

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

While the change itself looks neat, I am curious about the reason how this 
interact with modules.

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


[clang] [clang]improve diagnosing redefined defaulted constructor with different exception specs (PR #69688)

2023-10-25 Thread Congcong Cai via cfe-commits

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


[clang] 53705dd - [clang]improve diagnosing redefined defaulted constructor with different exception specs (#69688)

2023-10-25 Thread via cfe-commits

Author: Congcong Cai
Date: 2023-10-25T22:22:13+08:00
New Revision: 53705ddcb73b15393a48c868864522d23aef7884

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

LOG: [clang]improve diagnosing redefined defaulted constructor with different 
exception specs (#69688)

Added: 
clang/test/SemaCXX/diagnose-prioritiy-exception-redefining.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 903ad19d0b845f2..1bb842f9ba1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,9 @@ Improvements to Clang's diagnostics
   |   ~^~~~
 - Clang now always diagnoses when using non-standard layout types in 
``offsetof`` .
   (`#64619: `_)
+- Clang now diagnoses redefined defaulted constructor when redefined
+  defaulted constructor with 
diff erent exception specs.
+  (`#69094: `_)
 - Clang now diagnoses use of variable-length arrays in C++ by default (and
   under ``-Wall`` in GNU++ mode). This is an extension supported by Clang and
   GCC, but is very easy to accidentally use without realizing it's a

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index b363b0db79f164d..c4979b51e68f5e2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3922,18 +3922,6 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *, Scope *S,
   }
 
   if (getLangOpts().CPlusPlus) {
-// C++1z [over.load]p2
-//   Certain function declarations cannot be overloaded:
-// -- Function declarations that 
diff er only in the return type,
-//the exception specification, or both cannot be overloaded.
-
-// Check the exception specifications match. This may recompute the type of
-// both Old and New if it resolved exception specifications, so grab the
-// types again after this. Because this updates the type, we do this before
-// any of the other checks below, which may update the "de facto" NewQType
-// but do not necessarily update the type of New.
-if (CheckEquivalentExceptionSpec(Old, New))
-  return true;
 OldQType = Context.getCanonicalType(Old->getType());
 NewQType = Context.getCanonicalType(New->getType());
 
@@ -4055,6 +4043,19 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, 
NamedDecl *, Scope *S,
   }
 }
 
+// C++1z [over.load]p2
+//   Certain function declarations cannot be overloaded:
+// -- Function declarations that 
diff er only in the return type,
+//the exception specification, or both cannot be overloaded.
+
+// Check the exception specifications match. This may recompute the type of
+// both Old and New if it resolved exception specifications, so grab the
+// types again after this. Because this updates the type, we do this before
+// any of the other checks below, which may update the "de facto" NewQType
+// but do not necessarily update the type of New.
+if (CheckEquivalentExceptionSpec(Old, New))
+  return true;
+
 // C++11 [dcl.attr.noreturn]p1:
 //   The first declaration of a function shall specify the noreturn
 //   attribute if any declaration of that function specifies the noreturn

diff  --git a/clang/test/SemaCXX/diagnose-prioritiy-exception-redefining.cpp 
b/clang/test/SemaCXX/diagnose-prioritiy-exception-redefining.cpp
new file mode 100644
index 000..ad025bf041ce519
--- /dev/null
+++ b/clang/test/SemaCXX/diagnose-prioritiy-exception-redefining.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fcxx-exceptions -std=c++11 %s
+
+struct ExplicitlySpecialMethod {
+  ExplicitlySpecialMethod() = default;
+};
+ExplicitlySpecialMethod::ExplicitlySpecialMethod() {} // 
expected-error{{definition of explicitly defaulted default constructor}}
+
+struct ImplicitlySpecialMethod {};
+ImplicitlySpecialMethod::ImplicitlySpecialMethod() {} // 
expected-error{{definition of implicitly declared default constructor}}



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


[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

2023-10-25 Thread via cfe-commits


@@ -930,7 +930,11 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // and FP constants (specifically, the 'pp-number' regex), and assumes that
   // the byte at "*end" is both valid and not part of the regex.  Because of
   // this, it doesn't have to check for 'overscan' in various places.
-  if (isPreprocessingNumberBody(*ThisTokEnd)) {
+  // Note: For HLSL, the end token is allowed to be '.' which would be in the
+  // 'pp-number' regex. This is required to support vector swizzles on numeric
+  // constants (i.e. 1.xx or 1.5f.rrr).
+  if (isPreprocessingNumberBody(*ThisTokEnd) &&
+  !(LangOpts.HLSL && *ThisTokEnd == '.')) {

cor3ntin wrote:

I am happy to leave that as is then - even if i am a bit surprised by that 
commit.

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


[clang] [clang][dataflow] Add `Environment::allows()`. (PR #70046)

2023-10-25 Thread via cfe-commits

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


[clang] d1f5954 - [clang][dataflow] Add `Environment::allows()`. (#70046)

2023-10-25 Thread via cfe-commits

Author: martinboehme
Date: 2023-10-25T16:02:22+02:00
New Revision: d1f59544cf31488d84a2daff0020af2f8e366ed8

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

LOG: [clang][dataflow] Add `Environment::allows()`. (#70046)

This allows querying whether, given the flow condition, a certain
formula still
has a solution (though it is not necessarily implied by the flow
condition, as
`flowConditionImplies()` would check).

This can be checked today, but only with a double negation, i.e. to
check
whether, given the flow condition, a formula F has a solution, you can
check
`!Env.flowConditionImplies(Arena.makeNot(F))`. The double negation makes
this
hard to reason about, and it would be nicer to have a way of directly
checking
this.

For consistency, this patch also renames `flowConditionImplies()` to
`proves()`;
the old name is kept around for compatibility but deprecated.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index a792c3f911b1dd0..c1aa8484817a9d9 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -129,9 +129,17 @@ class DataflowAnalysisContext {
   /// token.
   Atom joinFlowConditions(Atom FirstToken, Atom SecondToken);
 
-  /// Returns true if and only if the constraints of the flow condition
-  /// identified by `Token` imply that `Val` is true.
-  bool flowConditionImplies(Atom Token, const Formula &);
+  /// Returns true if the constraints of the flow condition identified by
+  /// `Token` imply that `F` is true.
+  /// Returns false if the flow condition does not imply `F` or if the solver
+  /// times out.
+  bool flowConditionImplies(Atom Token, const Formula );
+
+  /// Returns true if the constraints of the flow condition identified by
+  /// `Token` still allow `F` to be true.
+  /// Returns false if the flow condition implies that `F` is false or if the
+  /// solver times out.
+  bool flowConditionAllows(Atom Token, const Formula );
 
   /// Returns true if `Val1` is equivalent to `Val2`.
   /// Note: This function doesn't take into account constraints on `Val1` and
@@ -184,6 +192,12 @@ class DataflowAnalysisContext {
   addTransitiveFlowConditionConstraints(Atom Token,
 llvm::SetVector );
 
+  /// Returns true if the solver is able to prove that there is a satisfying
+  /// assignment for `Constraints`.
+  bool isSatisfiable(llvm::SetVector Constraints) {
+return querySolver(std::move(Constraints)).getStatus() ==
+   Solver::Result::Status::Satisfiable;
+  }
 
   /// Returns true if the solver is able to prove that there is no satisfying
   /// assignment for `Constraints`

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 33e9f0fba02bc77..963197b728f4273 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -542,12 +542,29 @@ class Environment {
   Atom getFlowConditionToken() const { return FlowConditionToken; }
 
   /// Record a fact that must be true if this point in the program is reached.
-  void addToFlowCondition(const Formula &);
+  void assume(const Formula &);
+
+  /// Deprecated synonym for `assume()`.
+  void addToFlowCondition(const Formula ) { assume(F); }
 
   /// Returns true if the formula is always true when this point is reached.
-  /// Returns false if the formula may be false, or if the flow condition isn't
-  /// sufficiently precise to prove that it is true.
-  bool flowConditionImplies(const Formula &) const;
+  /// Returns false if the formula may be false (or the flow condition isn't
+  /// sufficiently precise to prove that it is true) or if the solver times 
out.
+  ///
+  /// Note that there is an asymmetry between this function and `allows()` in
+  /// that they both return false if the solver times out. The assumption is
+  /// that if `proves()` or `allows()` returns true, this will result in a
+  /// diagnostic, and we want to bias towards false negatives in the case where
+  /// the solver times out.
+  bool proves(const Formula &) const;
+
+  /// Returns true if the formula may be true when this 

[clang] [RecursiveASTVisitor] Fix RecursiveASTVisitor (RAV) fails to visit the initializer of a bitfield (PR #69557)

2023-10-25 Thread via cfe-commits

cor3ntin wrote:

Can you add a release note for this change? It looks good otherwise

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


[clang] [analyzer][NFC] Combine similar methods of StreamChecker (PR #70170)

2023-10-25 Thread Ben Shi via cfe-commits

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


[clang] 00b7979 - [clang][analyzer][NFC] Combine similar methods of StreamChecker (#70170)

2023-10-25 Thread via cfe-commits

Author: Ben Shi
Date: 2023-10-25T22:00:02+08:00
New Revision: 00b7979946e55ae291dc3e57112d3e5e7892b547

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

LOG: [clang][analyzer][NFC] Combine similar methods of StreamChecker (#70170)

Methods StreamChecker::preFread and StreamChecker::preFwrite are quite
similar, so they can be combined to StreamChecker::preFreadFwrite.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index ef209f64f0c372c..4b7103c20557cc4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -245,10 +245,10 @@ class StreamChecker : public CheckerStreamArgNo), C,
@@ -652,6 +650,11 @@ void StreamChecker::preFread(const FnDescription *Desc, 
const CallEvent ,
   if (!State)
 return;
 
+  if (!IsFread) {
+C.addTransition(State);
+return;
+  }
+
   SymbolRef Sym = StreamVal.getAsSymbol();
   if (Sym && State->get(Sym)) {
 const StreamState *SS = State->get(Sym);
@@ -662,24 +665,6 @@ void StreamChecker::preFread(const FnDescription *Desc, 
const CallEvent ,
   }
 }
 
-void StreamChecker::preFwrite(const FnDescription *Desc, const CallEvent ,
-  CheckerContext ) const {
-  ProgramStateRef State = C.getState();
-  SVal StreamVal = getStreamArg(Desc, Call);
-  State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
-  State);
-  if (!State)
-return;
-  State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
-return;
-  State = ensureNoFilePositionIndeterminate(StreamVal, C, State);
-  if (!State)
-return;
-
-  C.addTransition(State);
-}
-
 void StreamChecker::evalFreadFwrite(const FnDescription *Desc,
 const CallEvent , CheckerContext ,
 bool IsFread) const {
@@ -1222,7 +1207,7 @@ StreamChecker::reportLeaks(const SmallVector ,
 
 PathDiagnosticLocation LocUsedForUniqueing;
 if (const Stmt *StreamStmt = StreamOpenNode->getStmtForDiagnostics())
-   LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
+  LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
   StreamStmt, C.getSourceManager(),
   StreamOpenNode->getLocationContext());
 



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


[clang] [PowerPC] Fix use of FPSCR builtins in smmintrin.h (PR #67299)

2023-10-25 Thread Stefan Pintilie via cfe-commits


@@ -68,10 +68,10 @@ extern __inline __m128d
 __asm__("mffsce %0" : "=f"(__fpscr_save.__fr));
 __enables_save.__fpscr = __fpscr_save.__fpscr & 0xf8;
 #else
-__fpscr_save.__fr = __builtin_mffs();
+__fpscr_save.__fr = __builtin_ppc_mffs();

stefanp-ibm wrote:

I'm not sure that there are any assumptions broken here. For example, 
`__builtin_ppc_set_fpscr_rn` only uses the last two bits for the rounding 
control and masks off the rest anyway. Also, `__builtin_ppc_mtfsf(0b0011, 
__fpscr_save.__fr);` is using the mask `0b0011` so it only uses the last 8 
bits. 

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


[clang-tools-extra] [PowerPC] Fix use of FPSCR builtins in smmintrin.h (PR #67299)

2023-10-25 Thread Stefan Pintilie via cfe-commits

https://github.com/stefanp-ibm approved this pull request.

I'm going to approve this patch.
I don't think that removing the mask `__fpscr_save.__fpscr &= 0x70007f0ffL;`  
in `smmintrin.h` with have issues but I don't feel strongly enough about it to 
block this patch. If you are not convinced that it is safe you can leave the 
masks in. 

LGTM.

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


[clang] [PowerPC] Fix use of FPSCR builtins in smmintrin.h (PR #67299)

2023-10-25 Thread Stefan Pintilie via cfe-commits

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


[clang-tools-extra] [PowerPC] Fix use of FPSCR builtins in smmintrin.h (PR #67299)

2023-10-25 Thread Stefan Pintilie via cfe-commits


@@ -68,10 +68,10 @@ extern __inline __m128d
 __asm__("mffsce %0" : "=f"(__fpscr_save.__fr));
 __enables_save.__fpscr = __fpscr_save.__fpscr & 0xf8;
 #else
-__fpscr_save.__fr = __builtin_mffs();
+__fpscr_save.__fr = __builtin_ppc_mffs();

stefanp-ibm wrote:

I'm not sure that there are any assumptions broken here. For example, 
`__builtin_ppc_set_fpscr_rn` only uses the last two bits for the rounding 
control and masks off the rest anyway. Also, `__builtin_ppc_mtfsf(0b0011, 
__fpscr_save.__fr);` is using the mask `0b0011` so it only uses the last 8 
bits. 

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


[clang] [PowerPC] Fix use of FPSCR builtins in smmintrin.h (PR #67299)

2023-10-25 Thread Stefan Pintilie via cfe-commits

https://github.com/stefanp-ibm approved this pull request.

I'm going to approve this patch.
I don't think that removing the mask `__fpscr_save.__fpscr &= 0x70007f0ffL;`  
in `smmintrin.h` with have issues but I don't feel strongly enough about it to 
block this patch. If you are not convinced that it is safe you can leave the 
masks in. 

LGTM.

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


[clang] [Clang][Sema] Skip RecordDecl when checking scope of declarations (PR #69432)

2023-10-25 Thread via cfe-commits

cor3ntin wrote:

The change looks good to me, but it is missing a release note in 
clang/docs/ReleaseNotes.rst

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


[clang] 6687c57 - [NFC][Clang] Make GetSDLFromOffloadArchive return void

2023-10-25 Thread Juan Manuel MARTINEZ CAAMAÑO via cfe-commits

Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2023-10-25T15:57:22+02:00
New Revision: 6687c5725cd51ff5c69a8ed90dceaf86c361ae6d

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

LOG: [NFC][Clang] Make GetSDLFromOffloadArchive return void

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 3b3d77fd930a938..ad012d3d0d4b46f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2129,7 +2129,7 @@ static bool SDLSearch(const Driver , const 
llvm::opt::ArgList ,
 /// the library paths. If so, add a new command to clang-offload-bundler to
 /// unbundle this archive and create a temporary device specific archive. Name
 /// of this SDL is passed to the llvm-link tool.
-static bool GetSDLFromOffloadArchive(
+static void GetSDLFromOffloadArchive(
 Compilation , const Driver , const Tool , const JobAction ,
 const InputInfoList , const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ,
@@ -2138,7 +2138,7 @@ static bool GetSDLFromOffloadArchive(
 
   // We don't support bitcode archive bundles for nvptx
   if (isBitCodeSDL && Arch.contains("nvptx"))
-return false;
+return;
 
   bool FoundAOB = false;
   std::string ArchiveOfBundles;
@@ -2174,12 +2174,12 @@ static bool GetSDLFromOffloadArchive(
   }
 
   if (!FoundAOB)
-return false;
+return;
 
   llvm::file_magic Magic;
   auto EC = llvm::identify_magic(ArchiveOfBundles, Magic);
   if (EC || Magic != llvm::file_magic::archive)
-return false;
+return;
 
   StringRef Prefix = isBitCodeSDL ? "libbc-" : "lib";
   std::string OutputLib =
@@ -2234,7 +2234,7 @@ static bool GetSDLFromOffloadArchive(
 
   CC1Args.push_back(DriverArgs.MakeArgString(OutputLib));
 
-  return true;
+  return;
 }
 
 // Wrapper function used by driver for adding SDLs during link phase.



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


[clang] 7c94603 - [NFC][Clang] Make read-only arguments of GetSDLFromOffloadArchive and SDLSearch read-only references instead of copying them

2023-10-25 Thread Juan Manuel MARTINEZ CAAMAÑO via cfe-commits

Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2023-10-25T15:57:22+02:00
New Revision: 7c946031b2f4e8b2e0cf23af503a25a2c92be1a0

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

LOG: [NFC][Clang] Make read-only arguments of GetSDLFromOffloadArchive and 
SDLSearch read-only references instead of copying them

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 5a66a244bb1139e..3b3d77fd930a938 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2053,8 +2053,9 @@ void tools::addX86AlignBranchArgs(const Driver , const 
ArgList ,
 ///
 static bool SDLSearch(const Driver , const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ,
-  SmallVector LibraryPaths, std::string 
Lib,
-  StringRef Arch, StringRef Target, bool isBitCodeSDL) {
+  const SmallVectorImpl ,
+  StringRef Lib, StringRef Arch, StringRef Target,
+  bool isBitCodeSDL) {
   SmallVector SDLs;
 
   std::string LibDeviceLoc = "/libdevice";
@@ -2131,8 +2132,9 @@ static bool SDLSearch(const Driver , const 
llvm::opt::ArgList ,
 static bool GetSDLFromOffloadArchive(
 Compilation , const Driver , const Tool , const JobAction ,
 const InputInfoList , const llvm::opt::ArgList ,
-llvm::opt::ArgStringList , SmallVector 
LibraryPaths,
-StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL) {
+llvm::opt::ArgStringList ,
+const SmallVectorImpl , StringRef Lib,
+StringRef Arch, StringRef Target, bool isBitCodeSDL) {
 
   // We don't support bitcode archive bundles for nvptx
   if (isBitCodeSDL && Arch.contains("nvptx"))



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


[clang] [clang]improve diagnosing redefined defaulted constructor with different exception specs (PR #69688)

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

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


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


[clang] [clang] Non-object types are non-trivially relocatable (PR #69734)

2023-10-25 Thread via cfe-commits

cor3ntin wrote:

an you add tests  / release notes? (the change itself looks fine to me)

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


[clang] [analyzer][NFC] Combine similar methods of StreamChecker (PR #70170)

2023-10-25 Thread Balázs Kéri via cfe-commits

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


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


[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

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


@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library  -x hlsl \
+// RUN:   -finclude-default-header -ast-dump %s | FileCheck %s
+
+
+// CHECK: ExtVectorElementExpr {{.*}} 'int 
__attribute__((ext_vector_type(2)))' xx
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int 
__attribute__((ext_vector_type(1)))' lvalue 
+// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'V' 'int'
+
+int2 ToTwoInts(int V){
+  return V.xx;
+}
+
+// CHECK: ExtVectorElementExpr {{.*}} 'float 
__attribute__((ext_vector_type(4)))' 
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float 
__attribute__((ext_vector_type(1)))' lvalue 
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float' lvalue ParmVar {{.*}} 'V' 'float'
+
+
+float4 ToThreeFloats(float V){

AaronBallman wrote:

Isn't this to four floats?

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


[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

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


@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library  -x hlsl 
-finclude-default-header -verify %s
+
+
+int2 ToTwoInts(int V) {
+  return V.xy; // expected-error{{vector component access exceeds type 'int 
__attribute__((ext_vector_type(1)))' (vector of 1 'int' value)}}
+}
+
+float2 ToTwoFloats(float V) {
+  return V.rg; // expected-error{{vector component access exceeds type 'float 
__attribute__((ext_vector_type(1)))' (vector of 1 'float' value)}}
+}
+
+int4 SomeNonsense(int V) {
+  return V.poop; // expected-error{{illegal vector component name 'p'}}

AaronBallman wrote:

Please also add CodeGen tests that show we do... whatever *that* is.

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


[clang] [HLSL] Support vector swizzles on scalars (PR #67700)

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


@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library  -x hlsl \
+// RUN:   -finclude-default-header -ast-dump %s | FileCheck %s
+
+
+// CHECK: ExtVectorElementExpr {{.*}} 'int 
__attribute__((ext_vector_type(2)))' xx
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int 
__attribute__((ext_vector_type(1)))' lvalue 
+// CHECK-NEXT: DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'V' 'int'
+
+int2 ToTwoInts(int V){
+  return V.xx;
+}
+
+// CHECK: ExtVectorElementExpr {{.*}} 'float 
__attribute__((ext_vector_type(4)))' 
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'float 
__attribute__((ext_vector_type(1)))' lvalue 
+// CHECK-NEXT: DeclRefExpr {{.*}} 'float' lvalue ParmVar {{.*}} 'V' 'float'
+
+
+float4 ToThreeFloats(float V){
+  return V.;
+}
+
+// CHECK: ExtVectorElementExpr {{.*}} 'int 
__attribute__((ext_vector_type(2)))' xx
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'int 
__attribute__((ext_vector_type(1)))' 
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 1
+
+int2 FillOne(){
+  return 1.xx;
+}
+
+
+// CHECK: ExtVectorElementExpr {{.*}} 'unsigned int 
__attribute__((ext_vector_type(3)))' xxx
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int 
__attribute__((ext_vector_type(1)))' 
+// CHECK-NEXT: IntegerLiteral {{.*}} 'unsigned int' 1
+
+uint3 FillOneUnsigned(){
+  return 1u.xxx;
+}

AaronBallman wrote:

Please add a codegen test for `err()`

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


[clang] [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (PR #69916)

2023-10-25 Thread Vlad Serebrennikov via cfe-commits

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


[clang] 2005f48 - [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (#69916)

2023-10-25 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-10-25T17:37:56+04:00
New Revision: 2005f484f6c021318848cffda2c3d97c58615bb5

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

LOG: [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (#69916)

Refactor `uintptr_t` inside of `clang::Selector` that holds a pointer to 
`IdentifierInfo` or `MultiKeywordSelector` and `IdentifierInfoFlag` enum into 
`PointerIntPair`. This is a part of `PointerIntPair` migration outlined in 
https://github.com/llvm/llvm-project/issues/69835.

Unlike `uintpt_t`, `PointerIntPair` required pointee types to be complete, so I 
had to shuffle definitions of `MultiKeywordSelector` and 
`detail::DeclarationNameExtra` around to make them complete at `Selector`. 
Also, there were outdated specializations of `PointerLikeTypeTraits` for 
`IdentifierInfo *`, which are no longer needed, because `alignof` that primary 
template use works just fine. Not just that, but they declared that 
`IdentifierInfo *` has only 1 spare lower bit, but today they are 8-byte 
aligned.

Added: 


Modified: 
clang/include/clang/AST/DeclarationName.h
clang/include/clang/Basic/IdentifierTable.h
clang/lib/Basic/IdentifierTable.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclarationName.h 
b/clang/include/clang/AST/DeclarationName.h
index b06931ea3e418f8..c9b01dc53964bd0 100644
--- a/clang/include/clang/AST/DeclarationName.h
+++ b/clang/include/clang/AST/DeclarationName.h
@@ -362,7 +362,8 @@ class DeclarationName {
   }
 
   /// Construct a declaration name from an Objective-C selector.
-  DeclarationName(Selector Sel) : Ptr(Sel.InfoPtr) {}
+  DeclarationName(Selector Sel)
+  : Ptr(reinterpret_cast(Sel.InfoPtr.getOpaqueValue())) {}
 
   /// Returns the name for all C++ using-directives.
   static DeclarationName getUsingDirectiveName() {

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 1a1ffddf2b1c601..2eafe5938406749 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -19,6 +19,9 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
@@ -794,6 +797,121 @@ enum ObjCStringFormatFamily {
   SFF_CFString
 };
 
+namespace detail {
+
+/// DeclarationNameExtra is used as a base of various uncommon special names.
+/// This class is needed since DeclarationName has not enough space to store
+/// the kind of every possible names. Therefore the kind of common names is
+/// stored directly in DeclarationName, and the kind of uncommon names is
+/// stored in DeclarationNameExtra. It is aligned to 8 bytes because
+/// DeclarationName needs the lower 3 bits to store the kind of common names.
+/// DeclarationNameExtra is tightly coupled to DeclarationName and any change
+/// here is very likely to require changes in DeclarationName(Table).
+class alignas(IdentifierInfoAlignment) DeclarationNameExtra {
+  friend class clang::DeclarationName;
+  friend class clang::DeclarationNameTable;
+
+protected:
+  /// The kind of "extra" information stored in the DeclarationName. See
+  /// @c ExtraKindOrNumArgs for an explanation of how these enumerator values
+  /// are used. Note that DeclarationName depends on the numerical values
+  /// of the enumerators in this enum. See DeclarationName::StoredNameKind
+  /// for more info.
+  enum ExtraKind {
+CXXDeductionGuideName,
+CXXLiteralOperatorName,
+CXXUsingDirective,
+ObjCMultiArgSelector
+  };
+
+  /// ExtraKindOrNumArgs has one of the following meaning:
+  ///  * The kind of an uncommon C++ special name. This DeclarationNameExtra
+  ///is in this case in fact either a CXXDeductionGuideNameExtra or
+  ///a CXXLiteralOperatorIdName.
+  ///
+  ///  * It may be also name common to C++ using-directives 
(CXXUsingDirective),
+  ///
+  ///  * Otherwise it is ObjCMultiArgSelector+NumArgs, where NumArgs is
+  ///the number of arguments in the Objective-C selector, in which
+  ///case the DeclarationNameExtra is also a MultiKeywordSelector.
+  unsigned ExtraKindOrNumArgs;
+
+  DeclarationNameExtra(ExtraKind Kind) : ExtraKindOrNumArgs(Kind) {}
+  DeclarationNameExtra(unsigned NumArgs)
+  : ExtraKindOrNumArgs(ObjCMultiArgSelector + NumArgs) {}
+
+  /// Return the corresponding ExtraKind.
+  ExtraKind getKind() const {
+return static_cast(ExtraKindOrNumArgs >
+  (unsigned)ObjCMultiArgSelector
+  ? 

[clang] [tooling/include-mapping] Add missing localtime_r symbols (PR #66091)

2023-10-25 Thread Haojian Wu via cfe-commits

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


[clang] 80db833 - [tooling/include-mapping] Add missing localtime_r symbols (#66091)

2023-10-25 Thread via cfe-commits

Author: Haojian Wu
Date: 2023-10-25T15:37:04+02:00
New Revision: 80db833c75f5ea514f331b50372a1baf520b887e

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

LOG: [tooling/include-mapping] Add missing localtime_r symbols (#66091)

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

Added: 


Modified: 
clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc

Removed: 




diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index 165c1fc2eebc2c3..0d351d688a3296c 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -367,6 +367,16 @@ SYMBOL(any_cast, std::, )
 SYMBOL(div, std::, )
 SYMBOL(abort, std::, )
 
+// These are C symbols that are not under std namespace.
+SYMBOL(localtime_r, None, )
+SYMBOL(localtime_r, None, )
+SYMBOL(localtime_s, None, )
+SYMBOL(localtime_s, None, )
+SYMBOL(gmtime_r, None, )
+SYMBOL(gmtime_r, None, )
+SYMBOL(gmtime_s, None, )
+SYMBOL(gmtime_s, None, )
+
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, 
..., _N"
 // text, which are not handled by the script.



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


[clang] [NFC][Clang] Make GetSDLFromOffloadArchive and SDLSearch static (PR #70201)

2023-10-25 Thread Juan Manuel Martinez Caamaño via cfe-commits

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


[clang] 6c0ceae - [NFC][Clang] Make GetSDLFromOffloadArchive and SDLSearch static (#70201)

2023-10-25 Thread via cfe-commits

Author: Juan Manuel Martinez Caamaño
Date: 2023-10-25T15:31:04+02:00
New Revision: 6c0ceaeccc1358cc3478e832c86615f92801a657

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

LOG: [NFC][Clang] Make GetSDLFromOffloadArchive and SDLSearch static (#70201)

Make GetSDLFromOffloadArchive and SDLSearch functions static since they
are used only in the file where they are defined. The aim is to ease
refactoring/modifying the declarations of these functions in the future.

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 484a6484a085cce..5a66a244bb1139e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2051,7 +2051,7 @@ void tools::addX86AlignBranchArgs(const Driver , const 
ArgList ,
 /// convention has been to use the prefix “lib”. To avoid confusion with host
 /// archive libraries, we use prefix "libbc-" for the bitcode SDL archives.
 ///
-bool tools::SDLSearch(const Driver , const llvm::opt::ArgList ,
+static bool SDLSearch(const Driver , const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ,
   SmallVector LibraryPaths, std::string 
Lib,
   StringRef Arch, StringRef Target, bool isBitCodeSDL) {
@@ -2128,7 +2128,7 @@ bool tools::SDLSearch(const Driver , const 
llvm::opt::ArgList ,
 /// the library paths. If so, add a new command to clang-offload-bundler to
 /// unbundle this archive and create a temporary device specific archive. Name
 /// of this SDL is passed to the llvm-link tool.
-bool tools::GetSDLFromOffloadArchive(
+static bool GetSDLFromOffloadArchive(
 Compilation , const Driver , const Tool , const JobAction ,
 const InputInfoList , const llvm::opt::ArgList ,
 llvm::opt::ArgStringList , SmallVector 
LibraryPaths,

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index 096152bfbdcf68a..f364c9793c9be62 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -66,19 +66,6 @@ void AddStaticDeviceLibs(Compilation *C, const Tool *T, 
const JobAction *JA,
  llvm::opt::ArgStringList , StringRef Arch,
  StringRef Target, bool isBitCodeSDL);
 
-bool SDLSearch(const Driver , const llvm::opt::ArgList ,
-   llvm::opt::ArgStringList ,
-   SmallVector LibraryPaths, std::string Lib,
-   StringRef Arch, StringRef Target, bool isBitCodeSDL);
-
-bool GetSDLFromOffloadArchive(Compilation , const Driver , const Tool ,
-  const JobAction , const InputInfoList ,
-  const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ,
-  SmallVector LibraryPaths,
-  StringRef Lib, StringRef Arch, StringRef Target,
-  bool isBitCodeSDL);
-
 const char *SplitDebugName(const JobAction , const llvm::opt::ArgList ,
const InputInfo , const InputInfo );
 



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


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Joseph Huber via cfe-commits

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


[clang] 078ae8c - [Offloading][NFC] Move creation of offloading entries from OpenMP (#70116)

2023-10-25 Thread via cfe-commits

Author: Joseph Huber
Date: 2023-10-25T09:25:43-04:00
New Revision: 078ae8cd64b44f2ead538c45cf7fb4c4b63fdcaa

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

LOG: [Offloading][NFC] Move creation of offloading entries from OpenMP (#70116)

Summary:
This patch is a first step to remove dependencies on the OpenMPIRBuilder
for creating generic offloading entries. This patch changes no
functionality and merely moves the code around. In the future the
interface will be changed to allow for more code re-use in the
registration and creation of offloading entries as well as a more
generic interface for CUDA, HIP, OpenMP, and SYCL(?). Doing this as a
first step to reduce the noise involved in the functional changes.

Added: 
llvm/include/llvm/Frontend/Offloading/Utility.h
llvm/lib/Frontend/Offloading/CMakeLists.txt
llvm/lib/Frontend/Offloading/Utility.cpp

Modified: 
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CMakeLists.txt
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
llvm/lib/Frontend/CMakeLists.txt
llvm/lib/Frontend/OpenMP/CMakeLists.txt
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 8a1212f2272e87a..2ef4dc236d091b0 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/Cuda.h"
 #include "clang/CodeGen/CodeGenABITypes.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -1129,33 +1130,32 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  llvm::OpenMPIRBuilder OMPBuilder(CGM.getModule());
-  OMPBuilder.initialize();
-
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
+  llvm::Module  = CGM.getModule();
   for (KernelInfo  : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
-   getDeviceSideName(cast(I.D)), 0,
-   DeviceVarFlags::OffloadGlobalEntry, 
Section);
+llvm::offloading::emitOffloadingEntry(
+M, KernelHandles[I.Kernel->getName()],
+getDeviceSideName(cast(I.D)), 0,
+DeviceVarFlags::OffloadGlobalEntry, Section);
 
   for (VarInfo  : DeviceVars) {
 uint64_t VarSize =
 CGM.getDataLayout().getTypeAllocSize(I.Var->getValueType());
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  OMPBuilder.emitOffloadingEntry(
-  I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
   I.Flags.isManaged() ? DeviceVarFlags::OffloadGlobalManagedEntry
   : DeviceVarFlags::OffloadGlobalEntry,
   Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Surface) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalSurfaceEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalSurfaceEntry, Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Texture) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalTextureEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalTextureEntry, Section);
 }
   }
 }

diff  --git a/clang/lib/CodeGen/CMakeLists.txt 
b/clang/lib/CodeGen/CMakeLists.txt
index d67ce982d78acf3..da98848e3b44387 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
   Extensions
   FrontendHLSL
   FrontendOpenMP
+  FrontendOffloading
   HIPStdPar
   IPO
   IRPrinter

diff  --git a/llvm/include/llvm/Frontend/Offloading/Utility.h 
b/llvm/include/llvm/Frontend/Offloading/Utility.h
new file mode 100644
index 000..f74f9e3ff119fd8
--- /dev/null
+++ b/llvm/include/llvm/Frontend/Offloading/Utility.h
@@ -0,0 +1,37 @@
+//===- Utility.h - Collection of geneirc offloading utilities 

[clang] [clang] Catch missing format attributes (PR #70024)

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


@@ -10615,6 +10615,8 @@ class Sema final {
 ChangedStateAtExit
   };
 
+  void DiagnoseMissingFormatAttributes(NamedDecl *FDecl, SourceLocation Loc);

AaronBallman wrote:

```suggestion
  void DiagnoseMissingFormatAttributes(const NamedDecl *FDecl, SourceLocation 
Loc);
```
(If we can't add the `const` here because it's viral for some reason, then I 
don't insist on this change.)

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


[clang] [clang] Catch missing format attributes (PR #70024)

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


@@ -936,6 +936,9 @@ def err_opencl_invalid_param : Error<
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
 def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
+def warn_missing_format_attribute : Warning<
+  "Function %0 might be candidate for %1 format attribute.">,
+  InGroup, DefaultIgnore;

AaronBallman wrote:

```suggestion
  "diagnostic behavior may be improved by adding the %0 format attribute to the 
declaration of %1">,
  InGroup, DefaultIgnore;
```
(likely need to be reformatted for our usual 80-col limits.)

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


[clang] [clang] Catch missing format attributes (PR #70024)

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

https://github.com/AaronBallman commented:

Some additional comments and suggestions - you should also add a release note 
to clang/docs/ReleaseNotes.rst so users know about the new functionality.

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


[clang] [clang] Catch missing format attributes (PR #70024)

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

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


[clang] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

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

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

>From be3f5faa6cd17d76f26fb1bc6d6b59a8a78ffe82 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 17 Oct 2023 19:37:28 +0200
Subject: [PATCH 1/2] Lifetime bound check for coroutine

---
 clang/lib/Sema/SemaInit.cpp   |  16 +-
 .../SemaCXX/coroutine-lifetimebound-args.cpp  | 184 ++
 2 files changed, 198 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/coroutine-lifetimebound-args.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index fd95b16b84b6e3a..54e72b220bc47a4 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7607,11 +7607,23 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath , Expr *Call,
 
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
-
+  bool checkCoroCall = false;
+  if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
+for (const auto  :
+ RD->getUnderlyingDecl()->specific_attrs()) {
+  // Only for demonstration: Get feedback and add a clang annotation as an
+  // extension.
+  if (attr->getAnnotation() == "coro_type") {
+
+checkCoroCall = true;
+break;
+  }
+}
+  }
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
-if (Callee->getParamDecl(I)->hasAttr())
+if (checkCoroCall || Callee->getParamDecl(I)->hasAttr())
   VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
   }
 }
diff --git a/clang/test/SemaCXX/coroutine-lifetimebound-args.cpp 
b/clang/test/SemaCXX/coroutine-lifetimebound-args.cpp
new file mode 100644
index 000..4cc5730ef896581
--- /dev/null
+++ b/clang/test/SemaCXX/coroutine-lifetimebound-args.cpp
@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+
+#define CORO_TYPE [[clang::annotate("coro_type")]]
+#define CORO_UNSAFE [[clang::annotate("coro_unsafe")]]
+
+template  struct CORO_TYPE Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T );
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+template  using Co = Gen;
+
+Gen foo_coro(const int& b);
+
+Gen plain_return_foo_decl(int b) {
+  return foo_coro(b); // expected-warning {{address of stack memory associated 
with parameter}}
+}
+
+Gen foo_coro(const int& b) {
+  if (b > 0)
+co_return 1;
+  co_return 2;
+}
+
+int getInt() { return 0; }
+
+Co bar_coro(const int , int c) {
+  int x = co_await foo_coro(b);
+  int y = co_await foo_coro(1);
+  int z = co_await foo_coro(getInt());
+  auto unsafe1 = foo_coro(1); // expected-warning {{temporary whose address is 
used as value of local variable}}
+  auto unsafe2 = foo_coro(getInt()); // expected-warning {{temporary whose 
address is used as value of local variable}}
+  auto  safe1 = foo_coro(b);
+  auto  safe2 = foo_coro(c);
+  co_return co_await foo_coro(co_await foo_coro(1));
+}
+
+Gen plain_return_co(int b) {
+  return foo_coro(b); // expected-warning {{address of stack memory associated 
with parameter}}
+}
+
+Gen safe_forwarding(const int& b) {
+  return foo_coro(b);
+}
+
+Gen unsafe_wrapper(int b) {
+  return safe_forwarding(b); // expected-warning {{address of stack memory 
associated with parameter}}
+}
+
+Co complex_plain_return(int b) {
+  return b > 0 
+  ? foo_coro(1)   // expected-warning {{returning address of local 
temporary object}}
+  : bar_coro(0, 1); // expected-warning {{returning address of local 
temporary object}}
+}
+
+void lambdas() {
+  auto unsafe_lambda = [](int b) {
+return foo_coro(b); // expected-warning {{address of stack memory 
associated with parameter}}
+  };
+  auto safe_lambda = [](int b) -> Co {
+int x = co_await foo_coro(1);
+co_return x + co_await foo_coro(b);
+  };
+}
+// 
=
+// Safe usage when parameters are value
+// 
=
+namespace by_value {
+Gen value_coro(int b) { co_return co_await foo_coro(b); }
+
+Gen wrapper1(int b) { return value_coro(b); }
+Gen wrapper2(const int& b) { return value_coro(b); }
+}
+
+// 
=
+// std::function like 

[clang-tools-extra] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

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

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

>From be3f5faa6cd17d76f26fb1bc6d6b59a8a78ffe82 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 17 Oct 2023 19:37:28 +0200
Subject: [PATCH 1/2] Lifetime bound check for coroutine

---
 clang/lib/Sema/SemaInit.cpp   |  16 +-
 .../SemaCXX/coroutine-lifetimebound-args.cpp  | 184 ++
 2 files changed, 198 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/coroutine-lifetimebound-args.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index fd95b16b84b6e3a..54e72b220bc47a4 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7607,11 +7607,23 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath , Expr *Call,
 
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
-
+  bool checkCoroCall = false;
+  if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
+for (const auto  :
+ RD->getUnderlyingDecl()->specific_attrs()) {
+  // Only for demonstration: Get feedback and add a clang annotation as an
+  // extension.
+  if (attr->getAnnotation() == "coro_type") {
+
+checkCoroCall = true;
+break;
+  }
+}
+  }
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
-if (Callee->getParamDecl(I)->hasAttr())
+if (checkCoroCall || Callee->getParamDecl(I)->hasAttr())
   VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
   }
 }
diff --git a/clang/test/SemaCXX/coroutine-lifetimebound-args.cpp 
b/clang/test/SemaCXX/coroutine-lifetimebound-args.cpp
new file mode 100644
index 000..4cc5730ef896581
--- /dev/null
+++ b/clang/test/SemaCXX/coroutine-lifetimebound-args.cpp
@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+
+#define CORO_TYPE [[clang::annotate("coro_type")]]
+#define CORO_UNSAFE [[clang::annotate("coro_unsafe")]]
+
+template  struct CORO_TYPE Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T );
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return false; }
+void await_suspend(std::coroutine_handle<>) noexcept {}
+U await_resume() noexcept { return {}; }
+  };
+  return awaitable{};
+}
+  };
+};
+
+template  using Co = Gen;
+
+Gen foo_coro(const int& b);
+
+Gen plain_return_foo_decl(int b) {
+  return foo_coro(b); // expected-warning {{address of stack memory associated 
with parameter}}
+}
+
+Gen foo_coro(const int& b) {
+  if (b > 0)
+co_return 1;
+  co_return 2;
+}
+
+int getInt() { return 0; }
+
+Co bar_coro(const int , int c) {
+  int x = co_await foo_coro(b);
+  int y = co_await foo_coro(1);
+  int z = co_await foo_coro(getInt());
+  auto unsafe1 = foo_coro(1); // expected-warning {{temporary whose address is 
used as value of local variable}}
+  auto unsafe2 = foo_coro(getInt()); // expected-warning {{temporary whose 
address is used as value of local variable}}
+  auto  safe1 = foo_coro(b);
+  auto  safe2 = foo_coro(c);
+  co_return co_await foo_coro(co_await foo_coro(1));
+}
+
+Gen plain_return_co(int b) {
+  return foo_coro(b); // expected-warning {{address of stack memory associated 
with parameter}}
+}
+
+Gen safe_forwarding(const int& b) {
+  return foo_coro(b);
+}
+
+Gen unsafe_wrapper(int b) {
+  return safe_forwarding(b); // expected-warning {{address of stack memory 
associated with parameter}}
+}
+
+Co complex_plain_return(int b) {
+  return b > 0 
+  ? foo_coro(1)   // expected-warning {{returning address of local 
temporary object}}
+  : bar_coro(0, 1); // expected-warning {{returning address of local 
temporary object}}
+}
+
+void lambdas() {
+  auto unsafe_lambda = [](int b) {
+return foo_coro(b); // expected-warning {{address of stack memory 
associated with parameter}}
+  };
+  auto safe_lambda = [](int b) -> Co {
+int x = co_await foo_coro(1);
+co_return x + co_await foo_coro(b);
+  };
+}
+// 
=
+// Safe usage when parameters are value
+// 
=
+namespace by_value {
+Gen value_coro(int b) { co_return co_await foo_coro(b); }
+
+Gen wrapper1(int b) { return value_coro(b); }
+Gen wrapper2(const int& b) { return value_coro(b); }
+}
+
+// 
=
+// std::function like 

[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Yaxun Liu via cfe-commits

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

LGTM. Thanks.

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


[clang-tools-extra] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

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

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


[clang] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

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

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


[clang] [tooling/include-mapping] Add missing localtime_r symbols (PR #66091)

2023-10-25 Thread kadir çetinkaya via cfe-commits

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

thanks!

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


[clang] [analyzer][NFC] Combine similar methods of StreamChecker (PR #70170)

2023-10-25 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/70170

>From 44a9b1cc4a526b69c78aaed739df99af6c94bd79 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 25 Oct 2023 14:58:55 +0800
Subject: [PATCH] [clang][analyzer][NFC] Combine similar methods of
 StreamChecker

Methods StreamChecker::preFread and StreamChecker::preFwrite are quite
similar, so they can be combined to StreamChecker::preFreadFwrite.
---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 41 ++-
 1 file changed, 13 insertions(+), 28 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index ef209f64f0c372c..4b7103c20557cc4 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -245,10 +245,10 @@ class StreamChecker : public CheckerStreamArgNo), C,
@@ -652,6 +650,11 @@ void StreamChecker::preFread(const FnDescription *Desc, 
const CallEvent ,
   if (!State)
 return;
 
+  if (!IsFread) {
+C.addTransition(State);
+return;
+  }
+
   SymbolRef Sym = StreamVal.getAsSymbol();
   if (Sym && State->get(Sym)) {
 const StreamState *SS = State->get(Sym);
@@ -662,24 +665,6 @@ void StreamChecker::preFread(const FnDescription *Desc, 
const CallEvent ,
   }
 }
 
-void StreamChecker::preFwrite(const FnDescription *Desc, const CallEvent ,
-  CheckerContext ) const {
-  ProgramStateRef State = C.getState();
-  SVal StreamVal = getStreamArg(Desc, Call);
-  State = ensureStreamNonNull(StreamVal, Call.getArgExpr(Desc->StreamArgNo), C,
-  State);
-  if (!State)
-return;
-  State = ensureStreamOpened(StreamVal, C, State);
-  if (!State)
-return;
-  State = ensureNoFilePositionIndeterminate(StreamVal, C, State);
-  if (!State)
-return;
-
-  C.addTransition(State);
-}
-
 void StreamChecker::evalFreadFwrite(const FnDescription *Desc,
 const CallEvent , CheckerContext ,
 bool IsFread) const {
@@ -1222,7 +1207,7 @@ StreamChecker::reportLeaks(const SmallVector ,
 
 PathDiagnosticLocation LocUsedForUniqueing;
 if (const Stmt *StreamStmt = StreamOpenNode->getStmtForDiagnostics())
-   LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
+  LocUsedForUniqueing = PathDiagnosticLocation::createBegin(
   StreamStmt, C.getSourceManager(),
   StreamOpenNode->getLocationContext());
 

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


[clang] [clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (PR #69916)

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

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

LGTM!

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


[clang] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

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

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


[clang-tools-extra] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

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

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


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> Maybe a clang documentation can be added for this generic offloading 
> toolchain for OpenMP/CUDA/HIP. Could be a brief description about the 
> offloading entries and registration mechanism in the beginning then buffy it 
> up later.

We have https://clang.llvm.org/docs/OffloadingDesign.html which describes the 
entries, but from an OpenMP perspective. But I have thought about reworking it 
once I finish up the new driver support (which this is a part of).

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


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

Maybe a clang documentation can be added for this generic offloading toolchain 
for OpenMP/CUDA/HIP. Could be a brief description about the offloading entries 
and registration mechanism in the beginning then buffy it up later.

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


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

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

AaronBallman wrote:

> @AaronBallman, hope the WG14 meeting went well? I've essentially done what I 
> planned to do here, so I was wondering if you're ready to take it from here? 
> I can try to incorporate the review feedback myself, but it's quite likely 
> I'd make a mess of it (not familiar with the clang code base at all). 

Thank you! I hope to pick this up soon-ish (I'm still trying to dig out from 
under my review backlog at the moment). I'm hoping to have time to dedicate to 
it so this gets in before the holiday season. As a backup plan, @Fznamznon is 
also willing to help out if I'm not able to get to it soon enough, but she's 
currently working on constexpr issues. So this is staying hot on my radar, but 
it may be a month+ before it gets picked up due to other pressures.

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] [OpenMP 5.2] Deprecate old syntax of linear clause (PR #70152)

2023-10-25 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.

LG

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


[PATCH] D158266: [OpenMP] Patch for Support to loop bind clause : Checking Parent Region

2023-10-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


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

https://reviews.llvm.org/D158266

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


[clang] 23d6a6d - [clang-format] Fix the version for a newly added option

2023-10-25 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-10-25T05:45:32-07:00
New Revision: 23d6a6dfc1bc6e79bdcc48a59a0698a5b79262e9

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

LOG: [clang-format] Fix the version for a newly added option

Also update the release notes.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index a552c9795acb952..21342e1b89ea866 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1217,7 +1217,7 @@ the configuration (without a prefix: ``Auto``).
 
 .. _AllowShortCompoundRequirementOnASingleLine:
 
-**AllowShortCompoundRequirementOnASingleLine** (``Boolean``) 
:versionbadge:`clang-format 16` :ref:`¶ 
`
+**AllowShortCompoundRequirementOnASingleLine** (``Boolean``) 
:versionbadge:`clang-format 18` :ref:`¶ 
`
   Allow short compound requirement on a single line.
 
   .. code-block:: c++

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c0514e5b70783b6..903ad19d0b845f2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -775,6 +775,7 @@ AST Matchers
 clang-format
 
 - Add ``AllowBreakBeforeNoexceptSpecifier`` option.
+- Add ``AllowShortCompoundRequirementOnASingleLine`` option.
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index f2ee25bc96d6f0d..3e9d1915badd87f 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -701,7 +701,7 @@ struct FormatStyle {
   /// } -> std::same_as;
   ///   };
   /// \endcode
-  /// \version 16
+  /// \version 18
   bool AllowShortCompoundRequirementOnASingleLine;
 
   /// Allow short enums on a single line.



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


[clang] Disable memtag sanitization for global fnptrs going into .ctors (PR #70186)

2023-10-25 Thread Victor Signaevskyi via cfe-commits

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

LGTM

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


[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-25 Thread Matt Arsenault via cfe-commits

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


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


[PATCH] D123676: [clang-format] Fix WhitespaceSensitiveMacros not being honoured when macro closing parenthesis is followed by a newline.

2023-10-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan closed this revision.
owenpan added a comment.
Herald added a subscriber: wangpc.
Herald added a project: clang-format.
Herald added a reviewer: rymiel.

Fixed in D132001 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123676

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


[clang] Disable memtag sanitization for global fnptrs going into .ctors (PR #70186)

2023-10-25 Thread Victor Signaevskyi via cfe-commits

P1119r1m wrote:

Dear Mitch,

thank you for your PR!
Let me check it on our end before submitting.

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


[PATCH] D139834: [clang-format] AllowShortCompoundRequirementOnASingleLine

2023-10-25 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG69209e30a716: [clang-format] 
AllowShortCompoundRequirementOnASingleLine (authored by Backl1ght, committed by 
owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D139834?vs=482075=557878#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139834

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2767,6 +2767,40 @@
Style);
 }
 
+TEST_F(FormatTest, ShortCompoundRequirement) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_TRUE(Style.AllowShortCompoundRequirementOnASingleLine);
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  { x + 1 } -> std::same_as;\n"
+   "};",
+   Style);
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  { x + 1 } -> std::same_as;\n"
+   "  { x + 2 } -> std::same_as;\n"
+   "};",
+   Style);
+  Style.AllowShortCompoundRequirementOnASingleLine = false;
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  {\n"
+   "x + 1\n"
+   "  } -> std::same_as;\n"
+   "};",
+   Style);
+  verifyFormat("template \n"
+   "concept c = requires(T x) {\n"
+   "  {\n"
+   "x + 1\n"
+   "  } -> std::same_as;\n"
+   "  {\n"
+   "x + 2\n"
+   "  } -> std::same_as;\n"
+   "};",
+   Style);
+}
+
 TEST_F(FormatTest, ShortCaseLabels) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortCaseLabelsOnASingleLine = true;
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -154,6 +154,7 @@
   CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
   CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
+  CHECK_PARSE_BOOL(AllowShortCompoundRequirementOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
   CHECK_PARSE_BOOL(BinPackArguments);
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -520,6 +520,8 @@
   // Try to merge records.
   if (TheLine->Last->is(TT_EnumLBrace)) {
 ShouldMerge = Style.AllowShortEnumsOnASingleLine;
+  } else if (TheLine->Last->is(TT_RequiresExpressionLBrace)) {
+ShouldMerge = Style.AllowShortCompoundRequirementOnASingleLine;
   } else if (TheLine->Last->isOneOf(TT_ClassLBrace, TT_StructLBrace)) {
 // NOTE: We use AfterClass (whereas AfterStruct exists) for both classes
 // and structs, but it seems that wrapping is still handled correctly
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -938,6 +938,8 @@
Style.AllowShortBlocksOnASingleLine);
 IO.mapOptional("AllowShortCaseLabelsOnASingleLine",
Style.AllowShortCaseLabelsOnASingleLine);
+IO.mapOptional("AllowShortCompoundRequirementOnASingleLine",
+   Style.AllowShortCompoundRequirementOnASingleLine);
 IO.mapOptional("AllowShortEnumsOnASingleLine",
Style.AllowShortEnumsOnASingleLine);
 IO.mapOptional("AllowShortFunctionsOnASingleLine",
@@ -1441,6 +1443,7 @@
   LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
   LLVMStyle.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
   LLVMStyle.AllowShortCaseLabelsOnASingleLine = false;
+  LLVMStyle.AllowShortCompoundRequirementOnASingleLine = true;
   LLVMStyle.AllowShortEnumsOnASingleLine = true;
   LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
   LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -685,6 +685,25 @@
   /// \version 3.6
   

[clang] 69209e3 - [clang-format] AllowShortCompoundRequirementOnASingleLine

2023-10-25 Thread Owen Pan via cfe-commits

Author: Backl1ght
Date: 2023-10-25T05:13:50-07:00
New Revision: 69209e30a7168b0493d8fb34989ddccd8c574670

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

LOG: [clang-format] AllowShortCompoundRequirementOnASingleLine

clang-format brace wrapping did not take requires into consideration,
compound requirements will be affected by BraceWrapping.AfterFunction.

Closes #59412.

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 5f369ea9759edad..a552c9795acb952 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1215,6 +1215,27 @@ the configuration (without a prefix: ``Auto``).
   return;
 }
 
+.. _AllowShortCompoundRequirementOnASingleLine:
+
+**AllowShortCompoundRequirementOnASingleLine** (``Boolean``) 
:versionbadge:`clang-format 16` :ref:`¶ 
`
+  Allow short compound requirement on a single line.
+
+  .. code-block:: c++
+
+true:
+template 
+concept c = requires(T x) {
+  { x + 1 } -> std::same_as;
+};
+
+false:
+template 
+concept c = requires(T x) {
+  {
+x + 1
+  } -> std::same_as;
+};
+
 .. _AllowShortEnumsOnASingleLine:
 
 **AllowShortEnumsOnASingleLine** (``Boolean``) :versionbadge:`clang-format 11` 
:ref:`¶ `

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index d0145fa9272cdd6..f2ee25bc96d6f0d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -685,6 +685,25 @@ struct FormatStyle {
   /// \version 3.6
   bool AllowShortCaseLabelsOnASingleLine;
 
+  /// Allow short compound requirement on a single line.
+  /// \code
+  ///   true:
+  ///   template 
+  ///   concept c = requires(T x) {
+  /// { x + 1 } -> std::same_as;
+  ///   };
+  ///
+  ///   false:
+  ///   template 
+  ///   concept c = requires(T x) {
+  /// {
+  ///   x + 1
+  /// } -> std::same_as;
+  ///   };
+  /// \endcode
+  /// \version 16
+  bool AllowShortCompoundRequirementOnASingleLine;
+
   /// Allow short enums on a single line.
   /// \code
   ///   true:
@@ -4650,6 +4669,8 @@ struct FormatStyle {
AllowShortBlocksOnASingleLine == R.AllowShortBlocksOnASingleLine &&
AllowShortCaseLabelsOnASingleLine ==
R.AllowShortCaseLabelsOnASingleLine &&
+   AllowShortCompoundRequirementOnASingleLine ==
+   R.AllowShortCompoundRequirementOnASingleLine &&
AllowShortEnumsOnASingleLine == R.AllowShortEnumsOnASingleLine &&
AllowShortFunctionsOnASingleLine ==
R.AllowShortFunctionsOnASingleLine &&

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff7cb097a59d6a0..edb33f4af4defef 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -938,6 +938,8 @@ template <> struct MappingTraits {
Style.AllowShortBlocksOnASingleLine);
 IO.mapOptional("AllowShortCaseLabelsOnASingleLine",
Style.AllowShortCaseLabelsOnASingleLine);
+IO.mapOptional("AllowShortCompoundRequirementOnASingleLine",
+   Style.AllowShortCompoundRequirementOnASingleLine);
 IO.mapOptional("AllowShortEnumsOnASingleLine",
Style.AllowShortEnumsOnASingleLine);
 IO.mapOptional("AllowShortFunctionsOnASingleLine",
@@ -1441,6 +1443,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.AllowAllParametersOfDeclarationOnNextLine = true;
   LLVMStyle.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never;
   LLVMStyle.AllowShortCaseLabelsOnASingleLine = false;
+  LLVMStyle.AllowShortCompoundRequirementOnASingleLine = true;
   LLVMStyle.AllowShortEnumsOnASingleLine = true;
   LLVMStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
   LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;

diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 0dcf3b7c8dd06bc..280485d9a90d1bf 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -520,6 +520,8 @@ class LineJoiner {
   // Try to merge records.
   if (TheLine->Last->is(TT_EnumLBrace)) {
 ShouldMerge = Style.AllowShortEnumsOnASingleLine;
+  } 

[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-25 Thread Rana Pratap Reddy via cfe-commits


@@ -7995,15 +7995,24 @@ enum SpecialRegisterAccessKind {
   Write,
 };
 
+// Generates the IR for __builtin_read_exec_*.
+// Lowers the builtin to amdgcn_ballot intrinsic.
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction , const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy  = CGF.Builder;
   CodeGen::CodeGenModule  = CGF.CGM;
 
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
   llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+
+  if (isExecHi) {
+Value *C1 = llvm::ConstantInt::get(ValueType, 32);
+Value *Rt2 = Builder.CreateLShr(Call, C1);

ranapratap55 wrote:

Removed ConstantInt::get.

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


[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-25 Thread Rana Pratap Reddy via cfe-commits


@@ -21,6 +23,28 @@ void test_ballot_wave32_target_attr(global uint* out, int a, 
int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+void test_read_exec(global uint* out) {
+  *out = __builtin_amdgcn_read_exec();
+}
+
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
+// CHECK-LABEL: @test_read_exec_lo(
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+void test_read_exec_lo(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_lo();
+}
+
+// CHECK-LABEL: @test_read_exec_hi(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)

ranapratap55 wrote:

Yes, this is generated codegen on wave32.

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


[clang] [AMDGPU] Lower __builtin_amdgcn_read_exec_hi to use amdgcn_ballot (PR #69567)

2023-10-25 Thread Rana Pratap Reddy via cfe-commits

https://github.com/ranapratap55 updated 
https://github.com/llvm/llvm-project/pull/69567

>From 8a5dfe62b7ce84d49f6684563f04122b75fc35ef Mon Sep 17 00:00:00 2001
From: ranapratap55 
Date: Thu, 19 Oct 2023 12:52:13 +0530
Subject: [PATCH] [AMDGPU] Lower __builtin_read_exec_hi to use amdgcn_ballot

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 21 +++-
 .../CodeGenOpenCL/builtins-amdgcn-wave32.cl   | 24 +++
 .../CodeGenOpenCL/builtins-amdgcn-wave64.cl   | 23 ++
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  4 +++-
 4 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..85be8bdd00516cb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7995,15 +7995,23 @@ enum SpecialRegisterAccessKind {
   Write,
 };
 
+// Generates the IR for __builtin_read_exec_*.
+// Lowers the builtin to amdgcn_ballot intrinsic.
 static Value *EmitAMDGCNBallotForExec(CodeGenFunction , const CallExpr *E,
   llvm::Type *RegisterType,
-  llvm::Type *ValueType) {
+  llvm::Type *ValueType, bool isExecHi) {
   CodeGen::CGBuilderTy  = CGF.Builder;
   CodeGen::CodeGenModule  = CGF.CGM;
 
-  llvm::Type *ResultType = CGF.ConvertType(E->getType());
-  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
+  Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
   llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)});
+
+  if (isExecHi) {
+Value *Rt2 = Builder.CreateLShr(Call, 32);
+Rt2 = Builder.CreateTrunc(Rt2, CGF.Int32Ty);
+return Rt2;
+  }
+
   return Call;
 }
 
@@ -17857,10 +17865,11 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
   case AMDGPU::BI__builtin_amdgcn_read_exec:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, false);
   case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
-  case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
-return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty);
-  }
+return EmitAMDGCNBallotForExec(*this, E, Int32Ty, Int32Ty, false);
+  case AMDGPU::BI__builtin_amdgcn_read_exec_hi:
+return EmitAMDGCNBallotForExec(*this, E, Int64Ty, Int64Ty, true);
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
   case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
index a4d14cf1f6cf0bd..43553131f63c549 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
@@ -13,6 +13,8 @@ void test_ballot_wave32(global uint* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK: declare i32 @llvm.amdgcn.ballot.i32(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave32_target_attr(
 // CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 %{{.+}})
 __attribute__((target("wavefrontsize32")))
@@ -21,6 +23,28 @@ void test_ballot_wave32_target_attr(global uint* out, int a, 
int b)
   *out = __builtin_amdgcn_ballot_w32(a == b);
 }
 
+// CHECK-LABEL: @test_read_exec(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+void test_read_exec(global uint* out) {
+  *out = __builtin_amdgcn_read_exec();
+}
+
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
+// CHECK-LABEL: @test_read_exec_lo(
+// CHECK: call i32 @llvm.amdgcn.ballot.i32(i1 true)
+void test_read_exec_lo(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_lo();
+}
+
+// CHECK-LABEL: @test_read_exec_hi(
+// CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 true)
+// CHECK: lshr i64 [[A:%.*]], 32
+// CHECK: trunc i64 [[B:%.*]] to i32
+void test_read_exec_hi(global uint* out) {
+  *out = __builtin_amdgcn_read_exec_hi();
+}
+
 #if __AMDGCN_WAVEFRONT_SIZE != 32
 #error Wrong wavesize detected
 #endif
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
index 563c9a2a240c1dc..53f34c6a44ae7dc 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
@@ -13,6 +13,8 @@ void test_ballot_wave64(global ulong* out, int a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK: declare i64 @llvm.amdgcn.ballot.i64(i1) 
#[[$NOUNWIND_READONLY:[0-9]+]]
+
 // CHECK-LABEL: @test_ballot_wave64_target_attr(
 // CHECK: call i64 @llvm.amdgcn.ballot.i64(i1 %{{.+}})
 __attribute__((target("wavefrontsize64")))
@@ -21,6 +23,27 @@ void test_ballot_wave64_target_attr(global ulong* out, int 
a, int b)
   *out = __builtin_amdgcn_ballot_w64(a == b);
 }
 
+// CHECK-LABEL: 

[clang] [NFC][Clang] Make GetSDLFromOffloadArchive and SDLSearch static (PR #70201)

2023-10-25 Thread Joseph Huber via cfe-commits

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

All of this code can be deleted once we move HIP to the new driver.

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


[clang] [NFC][Clang] Make GetSDLFromOffloadArchive and SDLSearch static (PR #70201)

2023-10-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Juan Manuel Martinez Caamaño (jmmartinez)


Changes

Make GetSDLFromOffloadArchive and SDLSearch functions static since they are 
used only in the file where they are defined. The aim is to ease 
refactoring/modifying the declarations of these functions in the future.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+2-2) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.h (-13) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 484a6484a085cce..5a66a244bb1139e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2051,7 +2051,7 @@ void tools::addX86AlignBranchArgs(const Driver , const 
ArgList ,
 /// convention has been to use the prefix “lib”. To avoid confusion with host
 /// archive libraries, we use prefix "libbc-" for the bitcode SDL archives.
 ///
-bool tools::SDLSearch(const Driver , const llvm::opt::ArgList ,
+static bool SDLSearch(const Driver , const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ,
   SmallVector LibraryPaths, std::string 
Lib,
   StringRef Arch, StringRef Target, bool isBitCodeSDL) {
@@ -2128,7 +2128,7 @@ bool tools::SDLSearch(const Driver , const 
llvm::opt::ArgList ,
 /// the library paths. If so, add a new command to clang-offload-bundler to
 /// unbundle this archive and create a temporary device specific archive. Name
 /// of this SDL is passed to the llvm-link tool.
-bool tools::GetSDLFromOffloadArchive(
+static bool GetSDLFromOffloadArchive(
 Compilation , const Driver , const Tool , const JobAction ,
 const InputInfoList , const llvm::opt::ArgList ,
 llvm::opt::ArgStringList , SmallVector 
LibraryPaths,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index 096152bfbdcf68a..f364c9793c9be62 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -66,19 +66,6 @@ void AddStaticDeviceLibs(Compilation *C, const Tool *T, 
const JobAction *JA,
  llvm::opt::ArgStringList , StringRef Arch,
  StringRef Target, bool isBitCodeSDL);
 
-bool SDLSearch(const Driver , const llvm::opt::ArgList ,
-   llvm::opt::ArgStringList ,
-   SmallVector LibraryPaths, std::string Lib,
-   StringRef Arch, StringRef Target, bool isBitCodeSDL);
-
-bool GetSDLFromOffloadArchive(Compilation , const Driver , const Tool ,
-  const JobAction , const InputInfoList ,
-  const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ,
-  SmallVector LibraryPaths,
-  StringRef Lib, StringRef Arch, StringRef Target,
-  bool isBitCodeSDL);
-
 const char *SplitDebugName(const JobAction , const llvm::opt::ArgList ,
const InputInfo , const InputInfo );
 

``




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


[clang] [NFC][Clang] Make GetSDLFromOffloadArchive and SDLSearch static (PR #70201)

2023-10-25 Thread Juan Manuel Martinez Caamaño via cfe-commits

https://github.com/jmmartinez created 
https://github.com/llvm/llvm-project/pull/70201

Make GetSDLFromOffloadArchive and SDLSearch functions static since they are 
used only in the file where they are defined. The aim is to ease 
refactoring/modifying the declarations of these functions in the future.

From 24d16a7602c8699b785bd929648c9d466b7078ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20MARTINEZ=20CAAMA=C3=91O?= 
Date: Thu, 19 Oct 2023 12:17:29 +0200
Subject: [PATCH] [NFC][Clang] Make GetSDLFromOffloadArchive and SDLSearch
 static

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp |  4 ++--
 clang/lib/Driver/ToolChains/CommonArgs.h   | 13 -
 2 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 484a6484a085cce..5a66a244bb1139e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2051,7 +2051,7 @@ void tools::addX86AlignBranchArgs(const Driver , const 
ArgList ,
 /// convention has been to use the prefix “lib”. To avoid confusion with host
 /// archive libraries, we use prefix "libbc-" for the bitcode SDL archives.
 ///
-bool tools::SDLSearch(const Driver , const llvm::opt::ArgList ,
+static bool SDLSearch(const Driver , const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ,
   SmallVector LibraryPaths, std::string 
Lib,
   StringRef Arch, StringRef Target, bool isBitCodeSDL) {
@@ -2128,7 +2128,7 @@ bool tools::SDLSearch(const Driver , const 
llvm::opt::ArgList ,
 /// the library paths. If so, add a new command to clang-offload-bundler to
 /// unbundle this archive and create a temporary device specific archive. Name
 /// of this SDL is passed to the llvm-link tool.
-bool tools::GetSDLFromOffloadArchive(
+static bool GetSDLFromOffloadArchive(
 Compilation , const Driver , const Tool , const JobAction ,
 const InputInfoList , const llvm::opt::ArgList ,
 llvm::opt::ArgStringList , SmallVector 
LibraryPaths,
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index 096152bfbdcf68a..f364c9793c9be62 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -66,19 +66,6 @@ void AddStaticDeviceLibs(Compilation *C, const Tool *T, 
const JobAction *JA,
  llvm::opt::ArgStringList , StringRef Arch,
  StringRef Target, bool isBitCodeSDL);
 
-bool SDLSearch(const Driver , const llvm::opt::ArgList ,
-   llvm::opt::ArgStringList ,
-   SmallVector LibraryPaths, std::string Lib,
-   StringRef Arch, StringRef Target, bool isBitCodeSDL);
-
-bool GetSDLFromOffloadArchive(Compilation , const Driver , const Tool ,
-  const JobAction , const InputInfoList ,
-  const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ,
-  SmallVector LibraryPaths,
-  StringRef Lib, StringRef Arch, StringRef Target,
-  bool isBitCodeSDL);
-
 const char *SplitDebugName(const JobAction , const llvm::opt::ArgList ,
const InputInfo , const InputInfo );
 

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


[clang] [NFC][Clang] Make GetSDLFromOffloadArchive and SDLSearch static and avoid useless copies in their arguments (PR #69463)

2023-10-25 Thread Juan Manuel Martinez Caamaño via cfe-commits

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


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Joseph Huber via cfe-commits

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


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/70116

>From 5f8318bcb3419a675680d8e58b4707d42397ae1e Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Tue, 24 Oct 2023 15:27:21 -0500
Subject: [PATCH] [Offloading][NFC] Move creation of offloading entries from
 OpenMP

Summary:
This patch is a first step to remove dependencies on the OpenMPIRBuilder
for creating generic offloading entires. This patch changes no
functionality and merely moves the code around. In the future the
interface will be changed to allow for more code re-use in the
registeration and creation of offloading entries as well as a more
generic interface for CUDA, HIP, OpenMP, and SYCL(?). Doing this as a
first step to reduce the noise involved in the functional changes.
---
 clang/lib/CodeGen/CGCUDANV.cpp| 28 
 clang/lib/CodeGen/CMakeLists.txt  |  1 +
 .../llvm/Frontend/Offloading/Utility.h| 37 ++
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   | 21 --
 .../include/llvm/Frontend/OpenMP/OMPKinds.def |  2 -
 llvm/lib/Frontend/CMakeLists.txt  |  1 +
 llvm/lib/Frontend/Offloading/CMakeLists.txt   | 14 
 llvm/lib/Frontend/Offloading/Utility.cpp  | 67 +++
 llvm/lib/Frontend/OpenMP/CMakeLists.txt   |  1 +
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 43 ++--
 10 files changed, 139 insertions(+), 76 deletions(-)
 create mode 100644 llvm/include/llvm/Frontend/Offloading/Utility.h
 create mode 100644 llvm/lib/Frontend/Offloading/CMakeLists.txt
 create mode 100644 llvm/lib/Frontend/Offloading/Utility.cpp

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 8a1212f2272e87a..2ef4dc236d091b0 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/Cuda.h"
 #include "clang/CodeGen/CodeGenABITypes.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
+#include "llvm/Frontend/Offloading/Utility.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
@@ -1129,33 +1130,32 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  llvm::OpenMPIRBuilder OMPBuilder(CGM.getModule());
-  OMPBuilder.initialize();
-
   StringRef Section = CGM.getLangOpts().HIP ? "hip_offloading_entries"
 : "cuda_offloading_entries";
+  llvm::Module  = CGM.getModule();
   for (KernelInfo  : EmittedKernels)
-OMPBuilder.emitOffloadingEntry(KernelHandles[I.Kernel->getName()],
-   getDeviceSideName(cast(I.D)), 0,
-   DeviceVarFlags::OffloadGlobalEntry, 
Section);
+llvm::offloading::emitOffloadingEntry(
+M, KernelHandles[I.Kernel->getName()],
+getDeviceSideName(cast(I.D)), 0,
+DeviceVarFlags::OffloadGlobalEntry, Section);
 
   for (VarInfo  : DeviceVars) {
 uint64_t VarSize =
 CGM.getDataLayout().getTypeAllocSize(I.Var->getValueType());
 if (I.Flags.getKind() == DeviceVarFlags::Variable) {
-  OMPBuilder.emitOffloadingEntry(
-  I.Var, getDeviceSideName(I.D), VarSize,
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
   I.Flags.isManaged() ? DeviceVarFlags::OffloadGlobalManagedEntry
   : DeviceVarFlags::OffloadGlobalEntry,
   Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Surface) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalSurfaceEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalSurfaceEntry, Section);
 } else if (I.Flags.getKind() == DeviceVarFlags::Texture) {
-  OMPBuilder.emitOffloadingEntry(I.Var, getDeviceSideName(I.D), VarSize,
- DeviceVarFlags::OffloadGlobalTextureEntry,
- Section);
+  llvm::offloading::emitOffloadingEntry(
+  M, I.Var, getDeviceSideName(I.D), VarSize,
+  DeviceVarFlags::OffloadGlobalTextureEntry, Section);
 }
   }
 }
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index d67ce982d78acf3..da98848e3b44387 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
   Extensions
   FrontendHLSL
   FrontendOpenMP
+  FrontendOffloading
   HIPStdPar
   IPO
   IRPrinter
diff --git a/llvm/include/llvm/Frontend/Offloading/Utility.h 
b/llvm/include/llvm/Frontend/Offloading/Utility.h
new file mode 100644
index 

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

2023-10-25 Thread via cfe-commits

h-vetinari wrote:

@AaronBallman, hope the WG14 meeting went well? I've essentially done what I 
planned to do here, so I was wondering if you're ready to take it from here? I 
can try to incorporate the review feedback myself, but it's quite likely I'd 
make a mess of it (not familiar with the clang code base at all).  

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] 66f4a13 - [C23] Use thread_local semantics (#70107)

2023-10-25 Thread via cfe-commits

Author: Aaron Ballman
Date: 2023-10-25T07:51:28-04:00
New Revision: 66f4a1399d7de3d38312a5b251d4f8acd75237ca

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

LOG: [C23] Use thread_local semantics (#70107)

When implementing thread_local as a keyword in C23, we accidentally
started using C++11 thread_local semantics when using that keyword
instead of using C11 _Thread_local semantics.

This oversight is fixed by pretending the user wrote _Thread_local
instead. This doesn't have the best behavior in terms of diagnostics,
but it does correct the semantic behavior.

Fixes https://github.com/llvm/llvm-project/issues/70068
Fixes https://github.com/llvm/llvm-project/issues/69167

Added: 
clang/test/CodeGen/thread_local.c
clang/test/Sema/thread_local.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseDecl.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4cc148905d4e130..c0514e5b70783b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -496,6 +496,10 @@ Bug Fixes in This Version
   Fixes (`#65143 `_)
 - Fix crash in formatting the real/imaginary part of a complex lvalue.
   Fixes (`#69218 `_)
+- No longer use C++ ``thread_local`` semantics in C23 when using
+  ``thread_local`` instead of ``_Thread_local``.
+  Fixes (`#70068 `_) and
+  (`#69167 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 14a28e5a31c57db..78c3ab72979a007 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4076,8 +4076,15 @@ void Parser::ParseDeclarationSpecifiers(
 case tok::kw_thread_local:
   if (getLangOpts().C23)
 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
-  isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS_thread_local, 
Loc,
-   PrevSpec, DiagID);
+  // We map thread_local to _Thread_local in C23 mode so it retains the C
+  // semantics rather than getting the C++ semantics.
+  // FIXME: diagnostics will show _Thread_local when the user wrote
+  // thread_local in source in C23 mode; we need some general way to
+  // identify which way the user spelled the keyword in source.
+  isInvalid = DS.SetStorageClassSpecThread(
+  getLangOpts().C23 ? DeclSpec::TSCS__Thread_local
+: DeclSpec::TSCS_thread_local,
+  Loc, PrevSpec, DiagID);
   isStorageClass = true;
   break;
 case tok::kw__Thread_local:

diff  --git a/clang/test/CodeGen/thread_local.c 
b/clang/test/CodeGen/thread_local.c
new file mode 100644
index 000..b97f31c2fff2f6c
--- /dev/null
+++ b/clang/test/CodeGen/thread_local.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -std=c23 -emit-llvm -o - %s | 
FileCheck %s
+
+// Ensure that thread_local and _Thread_local emit the same codegen. See
+// https://github.com/llvm/llvm-project/issues/70068 for details.
+
+void func(void) {
+  static thread_local int i = 12;
+  static _Thread_local int j = 13;
+
+  extern thread_local int k;
+  extern thread_local int l;
+
+  (void)k;
+  (void)l;
+}
+
+// CHECK:  @func.i = internal thread_local global i32 12, align 4
+// CHECK-NEXT: @func.j = internal thread_local global i32 13, align 4
+// CHECK-NEXT: @k = external thread_local global i32, align 4
+// CHECK-NEXT: @l = external thread_local global i32, align 4
+
+// CHECK:  define dso_local void @func()
+// CHECK-NEXT: entry:
+// CHECK-NEXT: %[[K:.+]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr 
align 4 @k)
+// CHECK-NEXT: load i32, ptr %[[K]], align 4
+// CHECK-NEXT: %[[L:.+]] = call align 4 ptr @llvm.threadlocal.address.p0(ptr 
align 4 @l)
+// CHECK-NEXT: load i32, ptr %[[L]], align 4

diff  --git a/clang/test/Sema/thread_local.c b/clang/test/Sema/thread_local.c
new file mode 100644
index 000..a0de0aa4e39a6e1
--- /dev/null
+++ b/clang/test/Sema/thread_local.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 %s -verify
+
+// Ensure that thread_local and _Thread_local are synonyms in C23 and both
+// restrict local variables to be explicitly static or extern.
+void func(void) {
+  // FIXME: it would be nice if the diagnostic said 'thread_local' in this 
case.
+  thread_local int i = 12;  // expected-error {{'_Thread_local' variables must 
have global storage}}
+  _Thread_local int j = 13; // expected-error {{'_Thread_local' variables must 
have global storage}}
+
+  

[clang] [C23] Use thread_local semantics (PR #70107)

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

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-25 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

ping @cor3ntin @shafik, could you have a look here?

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


[PATCH] D33944: git-clang-format: Add --cached option to format index

2023-10-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan commandeered this revision.
owenpan edited reviewers, added: kevinoid; removed: owenpan.
owenpan added a comment.
Herald added a project: All.

We have `--cached` now.


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Repository:
  rC Clang

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

https://reviews.llvm.org/D33944

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


[clang] [C23] Use thread_local semantics (PR #70107)

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

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/70107

>From 9db10fc83ec3683b1d5b6f8606fc37a83fe224fa Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Tue, 24 Oct 2023 15:15:15 -0400
Subject: [PATCH 1/4] [C23] Use thread_local semantics

When implementing thread_local as a keyword in C23, we accidentally
started using C++11 thread_local semantics when using that keyword
instead of using C11 _Thread_local semantics.

This oversight is fixed by pretending the user wrote _Thread_local
instead. This doesn't have the best behavior in terms of diagnostics,
but it does correct the semantic behavior.

Fixes https://github.com/llvm/llvm-project/issues/70068
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/Parse/ParseDecl.cpp | 11 +--
 clang/test/CodeGen/thread_local.c | 27 +++
 clang/test/Sema/thread_local.c| 16 
 4 files changed, 55 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/thread_local.c
 create mode 100644 clang/test/Sema/thread_local.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cf3f0c343b4d014..b104c5da97ab124 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -493,6 +493,9 @@ Bug Fixes in This Version
   Fixes (`#65143 `_)
 - Fix crash in formatting the real/imaginary part of a complex lvalue.
   Fixes (`#69218 `_)
+- No longer use C++ ``thread_local`` semantics in C23 when using
+  ``thread_local`` instead of ``_Thread_local``.
+  Fixes (`#70068 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 14a28e5a31c57db..43c18090d6ef79c 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4076,8 +4076,15 @@ void Parser::ParseDeclarationSpecifiers(
 case tok::kw_thread_local:
   if (getLangOpts().C23)
 Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
-  isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS_thread_local, 
Loc,
-   PrevSpec, DiagID);
+  // We map thread_local to _Thread_local in C23 mode so it retains the C
+  // semantics rather than getting the C++ semantics.
+  // FIXME: diagnostics will now show _Thread_local when the user wrote
+  // thread_local in source in C23 mode; we need some general way to
+  // identify which way the user spelled the keyword in source.
+  isInvalid = DS.SetStorageClassSpecThread(
+  getLangOpts().C23 ? DeclSpec::TSCS__Thread_local
+: DeclSpec::TSCS_thread_local,
+  Loc, PrevSpec, DiagID);
   isStorageClass = true;
   break;
 case tok::kw__Thread_local:
diff --git a/clang/test/CodeGen/thread_local.c 
b/clang/test/CodeGen/thread_local.c
new file mode 100644
index 000..2daa43492cbf271
--- /dev/null
+++ b/clang/test/CodeGen/thread_local.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -std=c23 -emit-llvm -o - %s | 
FileCheck %s
+
+// Ensure that thread_local and _Thread_local emit the same codegen. See
+// https://github.com/llvm/llvm-project/issues/70068 for details.
+
+void func(void) {
+  static thread_local int i = 12;
+  static _Thread_local int j = 13;
+
+  extern thread_local int k;
+  extern thread_local int l;
+
+  (void)k;
+  (void)l;
+}
+
+// CHECK:  @func.i = internal thread_local global i32 12, align 4
+// CHECK-NEXT: @func.j = internal thread_local global i32 13, align 4
+// CHECK-NEXT: @k = external thread_local global i32, align 4
+// CHECK-NEXT: @l = external thread_local global i32, align 4
+
+// CHECK:  define dso_local void @func()
+// CHECK-NEXT: entry:
+// CHECK-NEXT: %0 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 
@k)
+// CHECK-NEXT: %1 = load i32, ptr %0, align 4
+// CHECK-NEXT: %2 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 
@l)
+// CHECK-NEXT: %3 = load i32, ptr %2, align 4
diff --git a/clang/test/Sema/thread_local.c b/clang/test/Sema/thread_local.c
new file mode 100644
index 000..c4a4dd4ceb1cd0d
--- /dev/null
+++ b/clang/test/Sema/thread_local.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c23 %s -verify
+
+// Ensure that thread_local and _Thread_local are synonyms in C23 and both
+// restrict local variables to be explicitly static or extern.
+void func(void) {
+  // FIXME: it would be nice if the diagnostic said 'thread_local' in this 
case.
+  thread_local int i = 12;  // expected-error {{'_Thread_local' variables must 
have global storage}}
+  _Thread_local int j = 13; // expected-error {{'_Thread_local' variables must 
have global storage}}
+
+  static thread_local int k = 14;
+  static _Thread_local int l = 15;
+
+  extern thread_local 

[clang] [clang] [Gnu] Improve GCCVersion parsing to match versions such as "10-win32" (PR #69079)

2023-10-25 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

Ping

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


[PATCH] D110252: Added note about Whatstyle and Unformat

2023-10-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan commandeered this revision.
owenpan edited reviewers, added: Volker-Weissmann; removed: owenpan.
Herald added a project: All.
Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to ClangFormatStyleOptions.rst but not a change 
to clang/include/clang/Format/Format.h

ClangFormatStyleOptions.rst is auto generated from Format.h via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110252

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


[clang] [C23] Use thread_local semantics (PR #70107)

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


@@ -493,6 +493,9 @@ Bug Fixes in This Version
   Fixes (`#65143 `_)
 - Fix crash in formatting the real/imaginary part of a complex lvalue.
   Fixes (`#69218 `_)
+- No longer use C++ ``thread_local`` semantics in C23 when using

AaronBallman wrote:

It does, thank you for spotting that! I'm going to add another test case from 
that issue when landing this.

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


[PATCH] D158266: [OpenMP] Patch for Support to loop bind clause : Checking Parent Region

2023-10-25 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 557877.

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

https://reviews.llvm.org/D158266

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/loop_bind_messages.cpp
  clang/test/PCH/pragma-loop.cpp

Index: clang/test/PCH/pragma-loop.cpp
===
--- clang/test/PCH/pragma-loop.cpp
+++ clang/test/PCH/pragma-loop.cpp
@@ -116,9 +116,13 @@
 
   inline void run10(int *List, int Length) {
 int i = 0;
-#pragma omp loop bind(teams)
+int j = 0;
+#pragma omp teams
 for (int i = 0; i < Length; i++) {
-  List[i] = i;
+  #pragma omp loop bind(teams)
+  for (int j = 0; j < Length; j++) {
+List[i] = i+j;
+  }
 }
   }
 
Index: clang/test/OpenMP/loop_bind_messages.cpp
===
--- clang/test/OpenMP/loop_bind_messages.cpp
+++ clang/test/OpenMP/loop_bind_messages.cpp
@@ -4,6 +4,7 @@
 
 #define NNN 50
 int aaa[NNN];
+int aaa2[NNN][NNN];
 
 void parallel_loop() {
   #pragma omp parallel
@@ -15,6 +16,91 @@
}
 }
 
+void parallel_for_AND_loop_bind() {
+  #pragma omp parallel for
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void parallel_nowait() {
+  #pragma omp parallel
+  #pragma omp for nowait
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void parallel_for_with_nothing() {
+  #pragma omp parallel for
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp nothing
+#pragma omp loop // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void parallel_targetfor_with_loop_bind() {
+  #pragma omp target teams distribute parallel for 
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'target teams distribute parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void parallel_targetparallel_with_loop() {
+  #pragma omp target parallel
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(parallel)
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void loop_bind_AND_loop_bind() {
+  #pragma omp parallel for
+  for (int i = 0; i < 100; ++i) {
+#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}} 
+for (int i = 0 ; i < NNN ; i++) {
+  #pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'loop' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}} 
+  for (int j = 0 ; j < NNN ; j++) {
+aaa[j] = j*NNN;
+  }
+}
+  }
+}
+
+void parallel_with_sections_loop() {
+  #pragma omp parallel
+  {
+ #pragma omp sections
+ {
+for (int i = 0 ; i < NNN ; i++) {
+  #pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+  for (int j = 0 ; j < NNN ; j++) {
+aaa2[i][j] = i+j;
+  }
+}
+
+#pragma omp section
+	{
+  aaa[NNN-1] = NNN;
+}
+ }
+  }
+}
+
 void teams_loop() {
   int var1, var2;
 
@@ -34,17 +120,23 @@
}
 }
 
-void orphan_loop_with_bind() {
-  #pragma omp loop bind(parallel) 
-  for (int j = 0 ; j < NNN ; j++) {
-aaa[j] = j*NNN;
+void teams_targetteams_with_loop() {
+  #pragma omp target teams
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(teams)
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
   }
 }
 
-void orphan_loop_no_bind() {
-  #pragma omp loop  // expected-error{{expected 'bind' clause for 'loop' construct without an enclosing OpenMP construct}}
-  for (int j = 0 ; j < NNN ; j++) {
-aaa[j] = j*NNN;
+void teams_targetfor_with_loop_bind() {
+  #pragma omp target teams distribute parallel for 
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(teams) // expected-error{{region 

[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,78 @@
+//===- Utility.cpp -- Collection of geneirc offloading utilities 
--===//
+//
+// 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 "llvm/Frontend/Offloading/Utility.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/Value.h"
+
+using namespace llvm;
+using namespace llvm::offloading;
+
+static IntegerType *getSizeTTy(Module ) {

arsenm wrote:

Why not just use getIntPtrType

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


[clang] [Offloading][NFC] Move creation of offloading entries from OpenMP (PR #70116)

2023-10-25 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> to allow for more code re-use in the registeration

Typo 'registeration'


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


[clang-tools-extra] [RFC] Perform lifetime bound checks for arguments to coroutine (PR #69360)

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

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


[clang-tools-extra] [AMDGPU] Rematerialize scalar loads (PR #68778)

2023-10-25 Thread Piotr Sobczak via cfe-commits

https://github.com/piotrAMD updated 
https://github.com/llvm/llvm-project/pull/68778

>From 6b5ada294d999ba1412020806ce8fab8e34a408e Mon Sep 17 00:00:00 2001
From: Piotr Sobczak 
Date: Wed, 11 Oct 2023 10:32:57 +0200
Subject: [PATCH 1/5] [AMDGPU] Rematerialize scalar loads

Extend the list of instructions that can be rematerialized in
SIInstrInfo::isReallyTriviallyReMaterializable() to support scalar loads.

Try shrinking instructions to remat only the part needed for current
context. Add SIInstrInfo::reMaterialize target hook, and handle shrinking
of S_LOAD_DWORDX16_IMM to S_LOAD_DWORDX8_IMM as a proof of concept.
---
 llvm/lib/Target/AMDGPU/SIInstrInfo.cpp| 110 +
 llvm/lib/Target/AMDGPU/SIInstrInfo.h  |   5 +
 .../hsa-metadata-kernel-code-props-v3.ll  |   4 +-
 llvm/test/CodeGen/AMDGPU/remat-smrd.mir   | 116 +-
 .../AMDGPU/snippet-copy-bundle-regression.mir |  42 +--
 5 files changed, 151 insertions(+), 126 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp 
b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 51397cbb791469d..31a086cd2a61820 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -108,7 +108,18 @@ static bool nodesHaveSameOperandValue(SDNode *N0, SDNode* 
N1, unsigned OpName) {
 
 bool SIInstrInfo::isReallyTriviallyReMaterializable(
 const MachineInstr ) const {
+
+  bool CanRemat = false;
   if (isVOP1(MI) || isVOP2(MI) || isVOP3(MI) || isSDWA(MI) || isSALU(MI)) {
+CanRemat = true;
+  } else if (isSMRD(MI)) {
+CanRemat = !MI.memoperands_empty() &&
+   llvm::all_of(MI.memoperands(), [](const MachineMemOperand *MMO) 
{
+ return MMO->isLoad() && MMO->isInvariant();
+   });
+  }
+
+  if (CanRemat) {
 // Normally VALU use of exec would block the rematerialization, but that
 // is OK in this case to have an implicit exec read as all VALU do.
 // We really want all of the generic logic for this except for this.
@@ -2434,6 +2445,105 @@ bool SIInstrInfo::expandPostRAPseudo(MachineInstr ) 
const {
   return true;
 }
 
+void SIInstrInfo::reMaterialize(MachineBasicBlock ,
+MachineBasicBlock::iterator I, Register 
DestReg,
+unsigned SubIdx, const MachineInstr ,
+const TargetRegisterInfo ) const {
+
+  // Try shrinking the instruction to remat only the part needed for current
+  // context.
+  // TODO: Handle more cases.
+  unsigned Opcode = Orig.getOpcode();
+  switch (Opcode) {
+  case AMDGPU::S_LOAD_DWORDX16_IMM:
+  case AMDGPU::S_LOAD_DWORDX8_IMM: {
+if (SubIdx != 0)
+  break;
+
+if (I == MBB.end())
+  break;
+
+if (I->isBundled())
+  break;
+
+// Look for a single use of the register that is also a subreg.
+Register RegToFind = Orig.getOperand(0).getReg();
+int SingleUseIdx = -1;
+for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
+  const MachineOperand  = I->getOperand(i);
+  if (!CandMO.isReg())
+continue;
+  Register CandReg = CandMO.getReg();
+  if (!CandReg)
+continue;
+
+  if (CandReg == RegToFind || RI.regsOverlap(CandReg, RegToFind)) {
+if (SingleUseIdx == -1 && CandMO.isUse()) {
+  SingleUseIdx = i;
+} else {
+  SingleUseIdx = -1;
+  break;
+}
+  }
+}
+if (SingleUseIdx == -1)
+  break;
+MachineOperand *UseMO = >getOperand(SingleUseIdx);
+if (UseMO->getSubReg() == AMDGPU::NoSubRegister)
+  break;
+
+unsigned Offset = RI.getSubRegIdxOffset(UseMO->getSubReg());
+unsigned SubregSize = RI.getSubRegIdxSize(UseMO->getSubReg());
+
+MachineFunction *MF = MBB.getParent();
+MachineRegisterInfo  = MF->getRegInfo();
+assert(MRI.hasAtMostUserInstrs(DestReg, 0) &&
+   "DestReg should have no users yet.");
+
+unsigned NewOpcode = -1;
+if (SubregSize == 256)
+  NewOpcode = AMDGPU::S_LOAD_DWORDX8_IMM;
+else if (SubregSize == 128)
+  NewOpcode = AMDGPU::S_LOAD_DWORDX4_IMM;
+else
+  break;
+
+const MCInstrDesc  = get(NewOpcode);
+const TargetRegisterClass *NewRC =
+RI.getAllocatableClass(getRegClass(TID, 0, , *MF));
+MRI.setRegClass(DestReg, NewRC);
+
+UseMO->setReg(DestReg);
+UseMO->setSubReg(AMDGPU::NoSubRegister);
+
+// Use a smaller load with the desired size, possibly with updated offset.
+MachineInstr *MI = MF->CloneMachineInstr();
+MI->setDesc(TID);
+MI->getOperand(0).setReg(DestReg);
+MI->getOperand(0).setSubReg(AMDGPU::NoSubRegister);
+if (Offset) {
+  MachineOperand *OffsetMO = getNamedOperand(*MI, AMDGPU::OpName::offset);
+  int64_t FinalOffset = OffsetMO->getImm() + Offset / 8;
+  OffsetMO->setImm(FinalOffset);
+}
+SmallVector NewMMOs;
+for (const MachineMemOperand *MemOp : Orig.memoperands())
+  

[clang] [NFC][Clang] Fix potential deref of end iterator (PR #70193)

2023-10-25 Thread Nathan Gauër via cfe-commits

https://github.com/Keenuts created 
https://github.com/llvm/llvm-project/pull/70193

This was found by doing bound-checking on SmallVector iterator usage. When the 
count is 0, the end iterator is dereferenced to get its address. This doesn't 
seem to be an issue in practice as most of the time, and we are allowed to 
deref this address, but I don't think this is correct.

From cde1bc9613fa384e4355d39ea29b705b1140dc83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nathan=20Gau=C3=ABr?= 
Date: Wed, 25 Oct 2023 12:40:22 +0200
Subject: [PATCH] [NFC][Clang] Fix potential deref of end iterator
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This was found by doing bound-checking on SmallVector iterator usage.
When the count is 0, the end iterator is dereferenced to get its
address. This doesn't seem to be an issue in practice as most of the
time, and we are allowed to deref this address, but I don't think
this is correct.

Signed-off-by: Nathan Gauër 
---
 clang/include/clang/Sema/CXXFieldCollector.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Sema/CXXFieldCollector.h 
b/clang/include/clang/Sema/CXXFieldCollector.h
index f6ecd9f46e5ebdb..ce066581c93fda7 100644
--- a/clang/include/clang/Sema/CXXFieldCollector.h
+++ b/clang/include/clang/Sema/CXXFieldCollector.h
@@ -65,7 +65,7 @@ class CXXFieldCollector {
 
   /// getCurFields - Pointer to array of fields added to the currently parsed
   /// class.
-  FieldDecl **getCurFields() { return &*(Fields.end() - getCurNumFields()); }
+  FieldDecl **getCurFields() { return Fields.end() - getCurNumFields(); }
 
   /// FinishClass - Called by Sema::ActOnFinishCXXClassDef.
   void FinishClass() {

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-10-25 Thread Simon Tatham via cfe-commits


@@ -152,6 +180,7 @@ template <> struct 
llvm::yaml::MappingTraits {
   static void mapping(llvm::yaml::IO , MultilibSerialization ) {
 io.mapRequired("Dir", V.Dir);
 io.mapRequired("Flags", V.Flags);
+io.mapOptional("ExclusiveGroup", V.ExclusiveGroup);

statham-arm wrote:

I'll rename it if you like, but I worry that that might be ambiguous, or at 
least unclear. Within the general context of linking and libraries, "group" 
need not mean a _mutually exclusive_ group; it could mean a grouping of 
libraries for other purposes too, like a mutually _dependent_ group (you must 
select all of these or none).

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


[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-25 Thread Björn Schäpers via cfe-commits

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


[clang] 5efa84c - [clang-format] Don't align comments over scopes

2023-10-25 Thread via cfe-commits

Author: Björn Schäpers
Date: 2023-10-25T12:50:15+02:00
New Revision: 5efa84cf6feaaa03e6325836f89503b0ab2be0d8

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

LOG: [clang-format] Don't align comments over scopes

We now stop aligning trailing comments on all closing braces, for
classes etc. we even check for the semicolon between the comment and the
brace.

Fixes #67906.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index cfd57f5fa8153f4..5f369ea9759edad 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -980,6 +980,10 @@ the configuration (without a prefix: ``Auto``).
 **AlignTrailingComments** (``TrailingCommentsAlignmentStyle``) 
:versionbadge:`clang-format 3.7` :ref:`¶ `
   Control of trailing comments.
 
+  The alignment stops at closing braces after a line break, and only
+  followed by other closing braces, a (``do-``) ``while``, a lambda call, or
+  a semicolon.
+
 
   .. note::
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4c344135d25163c..d0145fa9272cdd6 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -539,6 +539,10 @@ struct FormatStyle {
 
   /// Control of trailing comments.
   ///
+  /// The alignment stops at closing braces after a line break, and only
+  /// followed by other closing braces, a (``do-``) ``while``, a lambda call, 
or
+  /// a semicolon.
+  ///
   /// \note
   ///  As of clang-format 16 this option is not a bool but can be set
   ///  to the options. Conventional bool options still can be parsed as before.

diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dbe6175fb9653ed..ff8b1e6e13a3f77 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1048,6 +1048,9 @@ void WhitespaceManager::alignChainedConditionals() {
 }
 
 void WhitespaceManager::alignTrailingComments() {
+  if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never)
+return;
+
   const int Size = Changes.size();
   int MinColumn = 0;
   int StartOfSequence = 0;
@@ -1118,16 +1121,48 @@ void WhitespaceManager::alignTrailingComments() {
   }
 }
 
-// We don't want to align namespace end comments.
-const bool DontAlignThisComment =
-I > 0 && C.NewlinesBefore == 0 &&
-Changes[I - 1].Tok->is(TT_NamespaceRBrace);
-if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Never ||
-DontAlignThisComment) {
+// We don't want to align comments which end a scope, which are here
+// identified by most closing braces.
+auto DontAlignThisComment = [](const auto *Tok) {
+  if (Tok->is(tok::semi)) {
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+  }
+  if (Tok->is(tok::r_paren)) {
+// Back up past the parentheses and a `TT_DoWhile` that may precede.
+Tok = Tok->MatchingParen;
+if (!Tok)
+  return false;
+Tok = Tok->getPreviousNonComment();
+if (!Tok)
+  return false;
+if (Tok->is(TT_DoWhile)) {
+  const auto *Prev = Tok->getPreviousNonComment();
+  if (!Prev) {
+// A do-while-loop without braces.
+return true;
+  }
+  Tok = Prev;
+}
+  }
+
+  if (Tok->isNot(tok::r_brace))
+return false;
+
+  while (Tok->Previous && Tok->Previous->is(tok::r_brace))
+Tok = Tok->Previous;
+  return Tok->NewlinesBefore > 0;
+};
+
+if (I > 0 && C.NewlinesBefore == 0 &&
+DontAlignThisComment(Changes[I - 1].Tok)) {
   alignTrailingComments(StartOfSequence, I, MinColumn);
-  MinColumn = ChangeMinColumn;
-  MaxColumn = ChangeMinColumn;
-  StartOfSequence = I;
+  // Reset to initial values, but skip this change for the next alignment
+  // pass.
+  MinColumn = 0;
+  MaxColumn = INT_MAX;
+  StartOfSequence = I + 1;
 } else if (BreakBeforeNext || Newlines > NewLineThreshold ||
(ChangeMinColumn > MaxColumn || ChangeMaxColumn < MinColumn) ||
// Break the comment sequence if the previous line did not end

diff  --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 1198329b7b5a8f0..5e5324f01d8670a 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -182,7 

<    1   2   3   4   5   6   >