[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-09 Thread via cfe-commits

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread via cfe-commits

Sirraide wrote:

Yeah, I agree; I’ll wait a bit to see if Aaron has anything to say about it and 
merge this otherwise; once that’s done, I’ll add `[[omp::assume]]` in a 
separate pr and open an issue to discuss what to do w/ the other spellings.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread Erich Keane via cfe-commits

erichkeane wrote:

> If we can come to a consensus as to what to do w/ `clang::assume` and 
> `__attribute__((assume))` reasonably soon, then I’ll handle `[[omp::assume]]` 
> in this pr as well; otherwise, I’ll open a pr for `[[omp::assume]]` tomorrow 
> or so.

This patch is big enough as it is, as far as LOC and what effect, I would 
prefer we split the OMP decisions off to a separate patch and discuss that 
/implemetn that there.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread via cfe-commits

Sirraide wrote:

If we can come to a consensus as to what to do w/ `clang::assume` and 
`__attribute__((assume))` reasonably soon, then I’ll handle `[[omp::assume]]` 
in this pr as well; otherwise, I’ll open a pr for `[[omp::assume]]` tomorrow or 
so.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

> > > > > `[[clang::assume]]` or `__attribute__((assume))` are the OpenMP one
> > > > 
> > > > 
> > > > OpenMP requires only [[omp::assume]], neither [[clang::assume]] nor 
> > > > **attribute**((assume)) are OpenMP requirement.
> > > 
> > > 
> > > Yeah, the weird thing is I’m not sure we support `[[omp::assume]]` at the 
> > > moment. We should definitely fix this entire situation, but I’m not sure 
> > > it needs to be part of this pr.
> > 
> > 
> > Can you somehow fix omp::assume at first? Say, in a separate patch?
> 
> That’s independent of the changes introduced by this pr, from what I can tell 
> at least. So it should be possible to do that irrespective of when this gets 
> merged, yeah.

That would be great!

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread via cfe-commits

Sirraide wrote:

> > > > `[[clang::assume]]` or `__attribute__((assume))` are the OpenMP one
> > > 
> > > 
> > > OpenMP requires only [[omp::assume]], neither [[clang::assume]] nor 
> > > **attribute**((assume)) are OpenMP requirement.
> > 
> > 
> > Yeah, the weird thing is I’m not sure we support `[[omp::assume]]` at the 
> > moment. We should definitely fix this entire situation, but I’m not sure it 
> > needs to be part of this pr.
> 
> Can you somehow fix omp::assume at first? Say, in a separate patch?

That’s independent of the changes introduced by this pr, from what I can tell 
at least. So it should be possible to do that irrespective of when this gets 
merged, yeah.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

> > > `[[clang::assume]]` or `__attribute__((assume))` are the OpenMP one
> > 
> > 
> > OpenMP requires only [[omp::assume]], neither [[clang::assume]] nor 
> > **attribute**((assume)) are OpenMP requirement.
> 
> Yeah, the weird thing is I’m not sure we support `[[omp::assume]]` at the 
> moment. We should definitely fix this entire situation, but I’m not sure it 
> needs to be part of this pr.

Can you somehow fix omp::assume at first? Say, in a separate patch?

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread via cfe-commits

Sirraide wrote:

> > `[[clang::assume]]` or `__attribute__((assume))` are the OpenMP one
> 
> OpenMP requires only [[omp::assume]], neither [[clang::assume]] nor 
> **attribute**((assume)) are OpenMP requirement.

Yeah, the weird thing is I’m not sure we support `[[omp::assume]]` at the 
moment. We should definitely fix this entire situation, but I’m not sure it 
needs to be part of this pr.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

> `[[clang::assume]]` or `__attribute__((assume))` are the OpenMP one

OpenMP requires only [[omp::assume]], neither [[clang::assume]] nor 
__attribute__((assume)) are OpenMP requirement.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread via cfe-commits

Sirraide wrote:

@erichkeane @AaronBallman Do we want to figure out what to do wrt OpenMP’s 
`assume` attribute before we merge this, or do we want to decide on that after 
this is merged? Currently, only `[[assume]]` is treated as the standard 
attribute, and `[[clang::assume]]` or `__attribute__((assume))` are the OpenMP 
one.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread via cfe-commits

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


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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-08 Thread via cfe-commits

cor3ntin wrote:

LGTM, thanks!

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/28] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is

Sirraide wrote:

Iirc we were discussed adding a note about that, yeah.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/27] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/26] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread via cfe-commits


@@ -641,3 +652,53 @@ bool Sema::CheckRebuiltStmtAttributes(ArrayRef Attrs) {
   CheckForDuplicateLoopAttrs(*this, Attrs);
   return false;
 }
+
+ExprResult Sema::ActOnCXXAssumeAttr(Stmt *St, const ParsedAttr &A,
+SourceRange Range) {
+  if (A.getNumArgs() != 1 || !A.getArgAsExpr(0)) {
+Diag(A.getLoc(), diag::err_assume_attr_args) << A.getAttrName() << Range;
+return ExprError();
+  }
+
+  if (!isa(St)) {
+Diag(A.getLoc(), diag::err_assume_attr_wrong_target)
+<< A.getAttrName() << Range;
+return ExprError();
+  }
+
+  auto *Assumption = A.getArgAsExpr(0);
+  if (Assumption->getDependence() == ExprDependence::None) {
+ExprResult Res = BuildCXXAssumeExpr(Assumption, A.getAttrName(), Range);
+if (Res.isInvalid())
+  return ExprError();
+Assumption = Res.get();
+  }
+
+  if (!getLangOpts().CPlusPlus23)
+Diag(A.getLoc(), diag::ext_cxx23_attr) << A << Range;
+
+  return Assumption;
+}
+
+ExprResult Sema::BuildCXXAssumeExpr(Expr *Assumption,
+const IdentifierInfo *AttrName,
+SourceRange Range) {
+  ExprResult Res = CorrectDelayedTyposInExpr(Assumption);
+  if (Res.isInvalid())
+return ExprError();
+
+  Res = CheckPlaceholderExpr(Res.get());
+  if (Res.isInvalid())
+return ExprError();
+
+  Res = PerformContextuallyConvertToBool(Res.get());
+  if (Res.isInvalid())
+return ExprError();
+
+  Assumption = Res.get();
+  if (Assumption->HasSideEffects(Context))
+Diag(Assumption->getBeginLoc(), diag::warn_assume_side_effects)
+<< AttrName << Range;
+
+  return Assumption;
+}

Sirraide wrote:

Ah yes, as always.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread Vlad Serebrennikov via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is

Endilll wrote:

I think we do.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is

cor3ntin wrote:

Do we want to add some caveat to the docs?

"Note that due to the way the optimizer works, [[assume]] can affect 
performance negatively. It should be used with parsimony and care"

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread via cfe-commits

https://github.com/cor3ntin commented:

Generally looks good to me.
You should modify cxx_status

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread via cfe-commits


@@ -641,3 +652,53 @@ bool Sema::CheckRebuiltStmtAttributes(ArrayRef Attrs) {
   CheckForDuplicateLoopAttrs(*this, Attrs);
   return false;
 }
+
+ExprResult Sema::ActOnCXXAssumeAttr(Stmt *St, const ParsedAttr &A,
+SourceRange Range) {
+  if (A.getNumArgs() != 1 || !A.getArgAsExpr(0)) {
+Diag(A.getLoc(), diag::err_assume_attr_args) << A.getAttrName() << Range;
+return ExprError();
+  }
+
+  if (!isa(St)) {
+Diag(A.getLoc(), diag::err_assume_attr_wrong_target)
+<< A.getAttrName() << Range;
+return ExprError();
+  }
+
+  auto *Assumption = A.getArgAsExpr(0);
+  if (Assumption->getDependence() == ExprDependence::None) {
+ExprResult Res = BuildCXXAssumeExpr(Assumption, A.getAttrName(), Range);
+if (Res.isInvalid())
+  return ExprError();
+Assumption = Res.get();
+  }
+
+  if (!getLangOpts().CPlusPlus23)
+Diag(A.getLoc(), diag::ext_cxx23_attr) << A << Range;
+
+  return Assumption;
+}
+
+ExprResult Sema::BuildCXXAssumeExpr(Expr *Assumption,
+const IdentifierInfo *AttrName,
+SourceRange Range) {
+  ExprResult Res = CorrectDelayedTyposInExpr(Assumption);
+  if (Res.isInvalid())
+return ExprError();
+
+  Res = CheckPlaceholderExpr(Res.get());
+  if (Res.isInvalid())
+return ExprError();
+
+  Res = PerformContextuallyConvertToBool(Res.get());
+  if (Res.isInvalid())
+return ExprError();
+
+  Assumption = Res.get();
+  if (Assumption->HasSideEffects(Context))
+Diag(Assumption->getBeginLoc(), diag::warn_assume_side_effects)
+<< AttrName << Range;
+
+  return Assumption;
+}

cor3ntin wrote:

Missing EOL

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-07 Thread via cfe-commits

Sirraide wrote:

I seem to have missed a test that needs to be updated—I suppose that’s what I 
get for only running the Sema and Codegen tests locally instead of the entire 
test suite.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-06 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

`Sema.h` changes look good.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-06 Thread via cfe-commits

Sirraide wrote:

> Change __attribute__((assume)) (and [[clang::assume]] if we care enough about 
> that one) to be synonyms for [[assume]].

Actually, I think we could do that immediately because OpenMP’s `assume` isn’t 
valid as a statement attribute anyway iirc. I’d still deprecate all spellings 
other than `[[omp::assume]]` on functions, though—unless there is some problem 
with that that I’m missing.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-06 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/22] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-06 Thread via cfe-commits

Sirraide wrote:

I’ve implemented what we’ve decided on as a result of the RFC and also renamed 
the attribute to `CXXAssumeAttr` and the OpenMP one to `OMPAssumeAttr` so we 
don’t confuse the two.

> > But it sounds like my idea doesn't have legs because of OpenMP 
> > specification requirements. I'm fine with (3) as an approach then.
> 
> I think a hybrid approach between (3) and what you’re suggesting might make 
> sense:
> 
> 1. Introduce `[[omp::assume]]` for OpenMP (if that isn’t already a thing)
> 2. Deprecate `[[clang::assume]]` and `__attribute__((assume))`, telling 
> people to use `[[omp::assume]]` or `[[assume]]` instead, depending on where 
> we encounter the attribute, and maybe, eventually
> 3. Change `__attribute__((assume))` (and `[[clang::assume]]` if we care 
> enough about that one) to be synonyms for `[[assume]]`.

@AaronBallman, @erichkeane Thoughts on this?

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-06 Thread via cfe-commits

Sirraide wrote:

It requests a review automatically if one of the files has a code owner, 
interesting.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-06 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/21] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-03-04 Thread via cfe-commits

Sirraide wrote:

> But it sounds like my idea doesn't have legs because of OpenMP specification 
> requirements. I'm fine with (3) as an approach then.

I think a hybrid approach between (3) and what you’re suggesting might make 
sense:
1. Introduce `[[omp::assume]]` for OpenMP
2. Deprecate `[[clang::assume]]` and `__attribute__((assume))`, telling people 
to use `[[omp::assume]]` or `[[assume]]` instead, depending on where we 
encounter the attribute, and maybe, eventually
3. Change `__attribute__((assume))` (and `[[clang::assume]]` if we care enough 
about that one) to be synonyms for `[[assume]]`.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > > Thanks for the heads up. I don't think renaming to openmp_assume works 
> > > for OpenMP. We need to support `#pragma omp assume`, `[[omp::assume]]` 
> > > and `[[using omp : assume]]` as defined by the standard.
> > 
> > 
> > Hmm, `[[omp::assume]]` shouldn’t be an issue, because that’s pretty clearly 
> > something else. It’s mainly `[[clang::assume]]` and 
> > `__attribute__((assume))` that are the problem here.
> 
> Both `[[clang::assume]]` and `__attribute__((assume))` are not supported by 
> the standard, so it is up to you what to do with it.

Yeah, that's what we're trying to figure out. :-) GCC supports 
`__attribute__((assume))` as a synonym for `[[assume]]` and clang supports it 
as a synonym for OpenMP's assumptions.

But it sounds like my idea doesn't have legs because of OpenMP specification 
requirements. I'm fine with (3) as an approach then.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

> > Thanks for the heads up. I don't think renaming to openmp_assume works for 
> > OpenMP. We need to support `#pragma omp assume`, `[[omp::assume]]` and 
> > `[[using omp : assume]]` as defined by the standard.
> 
> Hmm, `[[omp::assume]]` shouldn’t be an issue, because that’s pretty clearly 
> something else. It’s mainly `[[clang::assume]]` and `__attribute__((assume))` 
> that are the problem here.

Both `[[clang::assume]]` and `__attribute__((assume))` are not supported by the 
standard, so it is up to you what to do with it.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

Wrt `[[clang::assume]]`/`__attribute__((assume))` applied to statements, those 
aren’t valid today anyway, so not supporting the former wouldn’t be a breaking 
change. We could consider supporting the latter though for GCC compatibility 
(afaik GCC’s `__attribute__((assume))` is pretty much `[[assume]]`).

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

In that case, we could maybe combine some of the approaches—i.e. differentiate 
the attributes based on appertainment, but also deprecate 
`[[clang::assume]]`/`__attribute__((assume))` and tell people to use 
`[[omp::assume]]` instead, if that is possible?

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

> Thanks for the heads up. I don't think renaming to openmp_assume works for 
> OpenMP. We need to support `#pragma omp assume`, `[[omp::assume]]` and 
> `[[using omp : assume]]` as defined by the standard.

Hmm, `[[omp::assume]]` shouldn’t be an issue, because that’s pretty clearly 
something else. It’s mainly `[[clang::assume]]` and `__attribute__((assume))` 
that are the problem here.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

> We'd need to see what @alexey-bataev has to say about renaming the OMP assume 
> attribute. I imagine that'll end up causing a headache for his users.

Thanks for the heads up. I don't think renaming to openmp_assume works for 
OpenMP. We need to support `#pragma omp assume`, `[[omp::assume]]` and `[[using 
omp : assume]]` as defined by the standard.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

I agree that renaming it to `openmp_assume` would probably avoid most 
complications, so if that’s not too big of a deal for the people that use this 
attribute then I’d probably go with that, otherwise option 3; with how 
`[[assume]]` works, I don’t particularly see it appertaining to declarations in 
a sane manner, but you never know—and not giving two unrelated attributes the 
same name would definitely be a more permanent fix.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread Erich Keane via cfe-commits

erichkeane wrote:

We'd need to see what @alexey-bataev has to say about renaming the OMP assume 
attribute.  I imagine that'll end up causing a headache for his users.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > I suppose the only question now is whether [[clang::assume]] should be 
> > treated like [[assume]] if it’s not applied to a function declaration?
> 
> THAT is an interesting question that @AaronBallman might have some comments 
> on...
> 
> Effectively, we have TWO 'assume' attributes-
> 1- An openmp FunctionDecl attribute that takes a string 
> 2- The standard 'statement' attribute that takes an expression.
> 
> So the question is, how do we differentiate between the two? We have a few 
> options: 
> 1- spelling: `[[clang::assume]]`/`__attribute__((assume))` currently work for 
> the 'string' version, so make ONLY `[[assume]]` the C++ one. 
> 2- Argument: The OMP one takes a string argument, we take an expression. 
> Bifurcate based on that? 
> 3- Appertainment: OMP is a function decl, standard is a statement.
> 
> Of the three, I lean towards 3 actually, I think that is perhaps the BEST 
> idea, and is perhaps supported by our existing infrastructure already (if you 
> have Attr.td set its targets right?). I'd like to see what Aaron has to say, 
> but I THINK that is my preference baring any concerns.

For (1), I think we would run into portability issues with 
`__attribute__((assume))` because of GCC: 
https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#index-assume-statement-attribute.
 We could alter this somewhat and make `[[assume]]` and 
`__attribute__((assume))` the same, and `[[clang::assume]]` can be the oddity. 
We'd probably need a deprecation period to avoid breaking users though.

I think (2) is workable so long as we're not going to support constexpr 
evaluation of the argument for the OpenMP assumption attribute. e.g., that 
means we can never support:
```
constexpr const char *get_omp_assumption(SomeEnum E);

__attribute__((assume(get_omp_assumption(OMP::DoTheFancyThing ...
```
because that is an expression rather than a string literal. I don't imagine 
WG21 would change assumption attributes to accept a single argument (esp of 
string type), so this option doesn't worry me too much about future-proofing.

I think (3) is also workable but perhaps slightly more risky because I can 
imagine WG21 changing the attribute to apply to declarations, though I think 
that's still a somewhat remote possibility. But if we went with (3) and WG21 
did allow the attribute on function declarations, we'd be in a pretty tight 
spot. We could perhaps then fall back to (2) to work around it.

Would it perhaps be worth considering a variation of (1) where we:
* Add `[[clang::openmp_assume]]` and `__attribute__((openmp_assume))` as new 
attributes to do OpenMP assumptions,
* At the same time, deprecate use of `[[clang::assume]]` and 
`__attribute__((assume))` for a period of time with a fix-it suggesting the new 
attributes,
* Support only `[[assume]]` for C++ assumptions until that deprecation period 
has ended (perhaps not introduce it until that deprecation period ends, 
maybe??),
* Repurpose `[[clang::assume]]` and `__attribute__((assume))` to mean C++ 
assumptions, but give a really good diagnostic w/fix-it if we see a single 
string literal argument to suggest using `openmp_assume` instead.

This gets us to an end state where there's far less long-term confusion about 
OpenMP and C++ assumptions because they'll be totally divorced from one another 
in terms of the spelling?

If that's a bad idea, then my preference is to go with (3) followed by (2) 
followed by the originally suggested (1).

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > I might lean toward CXXAssumeAttr and OMPAssumeAttr ?
> 
> That’s a good idea actually.

I have those occasionally :) 

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

> I might lean toward CXXAssumeAttr and OMPAssumeAttr ?

That’s a good idea actually.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > Of the three, I lean towards 3 actually, I think that is perhaps the BEST 
> > idea, and is perhaps supported by our existing infrastructure already (if 
> > you have Attr.td set its targets right?). I'd like to see what Aaron has to 
> > say, but I THINK that is my preference baring any concerns.
> 
> Yeah, I agree that that is probably the best option (though we should 
> probably still update the diagnostic I mentioned, because it’s not obvious 
> imo that `[[assume]]` != `[[clang::assume]]`).

Agreed, I think an improved diag there is a good idea.

> Also, `[[assume]]` is currently called `AssumeAttr`, whereas 
> `[[clang::assume]]` is called `AssumptionAttr`, so we might want to rename 
> one of those (e.g. the former to `CXXAssumeAttr` or the latter to 
> `ClangAssumptionAttr` or sth like that) because that sounds like a possible 
> source of confusion in the future...
> 
> That and the `[[clang::assume]]` docs should probably point out that this is 
> _not_ C++23’s `[[assume]]` if they don’t do that already.

I might lean toward CXXAssumeAttr and OMPAssumeAttr ? 

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

Also, `[[assume]]` is currently called `AssumeAttr`, whereas 
`[[clang::assume]]` is called `AssumptionAttr`, so we might want to rename one 
of those (e.g. the former to `CXXAssumeAttr` or the latter to 
`ClangAssumptionAttr` or sth like that) because that sounds like a possible 
source of confusion in the future...

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

And yes, it looks like the current implementation already differentiates the 
two attributes properly based on appertainment; the only thing left to do would 
be to investigate if there are any (other) diagnostics that need some 
improvement.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

> Of the three, I lean towards 3 actually, I think that is perhaps the BEST 
> idea, and is perhaps supported by our existing infrastructure already (if you 
> have Attr.td set its targets right?). I'd like to see what Aaron has to say, 
> but I THINK that is my preference baring any concerns.

Yeah, I agree that that is probably the best option (though we should probably 
still update the diagnostic I mentioned, because it’s not obvious imo that 
`[[assume]]` != `[[clang::assume]]`).



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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread Erich Keane via cfe-commits

erichkeane wrote:

>I suppose the only question now is whether [[clang::assume]] should be treated 
>like [[assume]] if it’s not applied to a function declaration?

THAT is an interesting question that @AaronBallman might have some comments 
on...

Effectively, we have TWO 'assume' attributes-
1- An openmp FunctionDecl attribute that takes a string
2- The standard 'statement' attribute that takes an expression.

So the question is, how do we differentiate between the two?  We have a few 
options:
1- spelling: `[[clang::assume]]`/`__attribute__((assume))` currently work for 
the 'string' version, so make ONLY `[[assume]]` the C++ one.
2- Argument: The OMP one takes a string argument, we take an expression.  
Bifurcate based on that?
3- Appertainment: OMP is a function decl, standard is a statement.

Of the three, I lean towards 3 actually, I think that is perhaps the BEST idea, 
and is perhaps supported by our existing infrastructure already (if you have 
Attr.td set its targets right?).  I'd like to see what Aaron has to say, but I 
THINK that is my preference baring any concerns.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread via cfe-commits

Sirraide wrote:

> I think your suggestion is sensible, though I'm equally as OK with just 
> making the standard attribute ONLY spellable as `[[assume]]` (and leaving the 
> other attribute alone).

That would also be an option yeah. Only somewhat related, this diagnostic 
probably needs to be updated:
```c++
test.cc:2:4: error: 'assume' attribute cannot be applied to a statement
2 | [[clang::assume(3)]];
  |   ^ ~
```
Because ‘'assume' attribute cannot be applied to a statement’ is just outright 
confusing now that `[[assume]]` exists and *has* to be applied to a statement. 
So if we keep `[[clang::assume]]` as-is, we should probably add something along 
the lines of ‘did you mean `[[assume]]` instead of `[[clang::assume]]`’.

Also, I just noticed that `[[clang::assume]]` apparently only appertains to 
function declarations, where `[[assume]]` isn’t allowed anyway, so I think 
distinguishing between the two is even less of a problem than I at least 
thought. I suppose the only question now is whether `[[clang::assume]]` should 
be treated like `[[assume]]` if it’s not applied to a function declaration?

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-27 Thread Erich Keane via cfe-commits

erichkeane wrote:

> Since we didn’t bring this up in the RFC, do we have any idea as to what we 
> should do with `[[clang::assume]]`?
> 
> My suggestion would be to keep the current semantics for `[[clang::assume]]` 
> (and `__attribute__((assume))`, but probably _not_ `[[assume]]`) iff the 
> argument is a string literal—mostly because a string literal would always 
> evaluate to `true` anyway, so there is literally nothing to be gained from 
> writing `[[clang::assume(string-literal)]]` anyway if we interpret it as 
> C++23’s `[[assume]]`.

I think your suggestion is sensible, though I'm equally as OK with just making 
the standard attribute ONLY spellable as `[[assume]]` (and leaving the other 
attribute alone).

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-26 Thread via cfe-commits

Sirraide wrote:

Since we didn’t bring this up in the RFC, do we have any idea as to what we 
should do with `[[clang::assume]]`? 

My suggestion would be to keep the current semantics for `[[clang::assume]]` 
(and `__attribute__((assume))`, but probably *not* `[[assume]]`) iff the 
argument is a string literal—mostly because a string literal would always 
evaluate to `true` anyway, so there is literally nothing to be gained from 
writing `[[clang::assume(string-literal)]]` anyway if we interpret it as 
C++23’s `[[assume]]`.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-12 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > > @Sirraide, would you be comfortable if you, @erichkeane, and I 
> > > co-authored an RFC to the community?
> > 
> > 
> > Sure, I’d be happy to help with that as best I can. An RFC makes sense imo 
> > seeing as this really impacts more parts of LLVM than just Clang.
> 
> Excellent, thanks! I will try to get a draft of the RFC over to you both 
> sometime tomorrow and we can go from there. I'll put it in a Google Doc so we 
> can hopefully collaborate more easily on it.

The RFC is now posted: 
https://discourse.llvm.org/t/rfc-builtin-assume-assume-optimization-behavior/76943

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-09 Thread via cfe-commits

Sirraide wrote:

Alright, done. I’ve also set my email address to public now since I only just 
realised that it was still set to private

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-08 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > @Sirraide, would you be comfortable if you, @erichkeane, and I co-authored 
> > an RFC to the community?
> 
> Sure, I’d be happy to help with that as best I can. An RFC makes sense imo 
> seeing as this really impacts more parts of LLVM than just Clang.

Excellent, thanks! I will try to get a draft of the RFC over to you both 
sometime tomorrow and we can go from there. I'll put it in a Google Doc so we 
can hopefully collaborate more easily on it.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-08 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > > We also need to figure out what to do w/ `clang::assume`, because the 
> > > entire situation with the two being separate attributes is a bit of a 
> > > mess, as @erichkeane also pointed out. That can probably be resolved 
> > > separately from the RFC, however—though I’m not that familiar w/ 
> > > `clang::assume`, so I may be wrong about this.
> > 
> > 
> > Yeah, I'd really like to figure that one out a bit, but I'm still thinking 
> > about it. This RFC is going to be our 'first order' issue though, so if we 
> > can get that solved first, we can figure out whether this is something we 
> > need to do, or can defer.
> 
> I’d imagine the RFC and the ensuing discussion are gonna take a bit anyway, 
> so we ought to have some time to think about this in the meantinme

Exactly my thoughts. 

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-08 Thread via cfe-commits

Sirraide wrote:

> > We also need to figure out what to do w/ `clang::assume`, because the 
> > entire situation with the two being separate attributes is a bit of a mess, 
> > as @erichkeane also pointed out. That can probably be resolved separately 
> > from the RFC, however—though I’m not that familiar w/ `clang::assume`, so I 
> > may be wrong about this.
> 
> Yeah, I'd really like to figure that one out a bit, but I'm still thinking 
> about it. This RFC is going to be our 'first order' issue though, so if we 
> can get that solved first, we can figure out whether this is something we 
> need to do, or can defer.

I’d imagine the RFC and the ensuing discussion are gonna take a bit anyway, so 
we ought to have some time to think about this in the meantinme

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-08 Thread Erich Keane via cfe-commits

erichkeane wrote:

> We also need to figure out what to do w/ `clang::assume`, because the entire 
> situation with the two being separate attributes is a bit of a mess, as 
> @erichkeane also pointed out. That can probably be resolved separately from 
> the RFC, however—though I’m not that familiar w/ `clang::assume`, so I may be 
> wrong about this.

Yeah, I'd really like to figure that one out a bit, but I'm still thinking 
about it.  This RFC is going to be our 'first order' issue though, so if we can 
get that solved first, we can figure out whether this is something we need to 
do, or can defer.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-08 Thread via cfe-commits

Sirraide wrote:

We also need to figure out what to do w/ `clang::assume`, because the entire 
situation with the two being separate attributes is a bit of a mess, as 
@erichkeane also pointed out. That can probably be resolved separately from the 
RFC, however—though I’m not that familiar w/ `clang::assume`, so I may be wrong 
about this.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-08 Thread via cfe-commits

Sirraide wrote:

> This feature is a bit more complicated than it appears at first. LLVM will 
> often pessimize code in the presence of assumptions and that's the exact 
> opposite of what users will expect from this feature.

Yeah, I’ve since looked into the discussions on that topic.

> that seemed to have pretty strong support for dropping llvm.assume 
> annotations due to how problematic they are in practice.

Yeah, imo that seems like the right approach to me at least since 
`@llvm.assume` being a pessimisation in some cases seems like something the 
backend should be handling, not the frontend, but that’s just my opinion.

>  @Sirraide, would you be comfortable if you, @erichkeane, and I co-authored 
> an RFC to the community?

Sure, I’d be happy to help with that as best I can. An RFC makes sense imo 
seeing as this really impacts more parts of LLVM than just Clang.

> (I'm sorry to add the extra layer of work on what would otherwise seem like a 
> straightforward PR, this is a bit of an unusual situation.)

No problem. Getting this figured out properly does seem like the right approach 
here.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-08 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Thank you for working on this! Improved standards support is always greatly 
appreciated.

This feature is a bit more complicated than it appears at first. LLVM will 
often pessimize code in the presence of assumptions and that's the exact 
opposite of what users will expect from this feature. For example, libc++ 
removed use of `__builtin_assume` (https://reviews.llvm.org/D153968) because of 
performance regressions that many folks didn't realize would happen. We ended 
up having a community discussion about `llvm.assume` and `__builtin_assume` 
(https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609/) that 
seemed to have pretty strong support for dropping `llvm.assume` annotations due 
to how problematic they are in practice. That makes this feature more 
complicated because it would be strange for us to drop annotations from 
`__builtin_assume` but then expose them via a standards-based feature.

Rather than re-hash those discussions here on this PR, I think we probably 
should get some measure of wider community buy-in on what approach to take. 
@Sirraide, would you be comfortable if you, @erichkeane, and I co-authored an 
RFC to the community? I'm happy to take the lead on writing the initial draft 
for it and we can all iterate on it until everyone is comfortable before 
posting it. (I'm sorry to add the extra layer of work on what would otherwise 
seem like a straightforward PR, this is a bit of an unusual situation.)

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/17] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/17] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/16] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/15] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1..2804ff1aea005 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002..192b081404a82 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3..9ecfdab3617e0 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63..847168af28862 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc9..0f982dbb67b41 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression(bool IsTr

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

Ok, I’ve added some more tests involving template instantiation (and also 
implemented actually handling `assume` in TreeTransform because I seem to have 
forgotten about that earlier...); just let me know if there are any other 
specific situations that we should test.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/14] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1..2804ff1aea005 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002..192b081404a82 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3..9ecfdab3617e0 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63..847168af28862 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc9..0f982dbb67b41 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression(bool IsTr

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/13] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

> I don't see any tests validating that these are being properly instantiated 
> (either by AST dump or by codegen), the only template cases i see are ones 
> where the instantiation not happening doesn't 'matter'. Also, I don't see how 
> these are affecting calls through concepts, so I'd like to see testing for 
> that as well (that is, how the attribute with a failure during instantiation 
> does).

I’ll add some more tests then. 


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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > I think the confusion/conflict between this and clang::assume needs to be 
> > figured out. These two should just be, as close as possible, spellings of 
> > the same thing.
> 
> Well, apparently, `clang::assume` always takes a string and is meant for OMP 
> assumptions, so one solution would be to just apply `clang::assume` semantics 
> iff the argument is a string literal since string literals would always be 
> converted to `true` anyway.

Hmm... I'll have to think about this.

Side note: I don't see any tests validating that these are being properly 
instantiated (either by AST dump or by codegen), the only template cases i see 
are ones where the instantiation not happening doesn't 'matter'.  Also, I don't 
see how these are affecting calls through concepts, so I'd like to see testing 
for that as well (that is, how the attribute with a failure during 
instantiation does).

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

> I think the confusion/conflict between this and clang::assume needs to be 
> figured out. These two should just be, as close as possible, spellings of the 
> same thing.

Well, apparently, `clang::assume` always takes a string and is meant for OMP 
assumptions, so one solution would be to just apply `clang::assume` semantics 
iff the argument is a string literal since string literals would always be 
converted to `true` anyway.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/12] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

> > GCC does checks assumption in constant evaluation. I think we should too.
> 
> I’ll look into it in that case.

Alright, this should be done now.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/11] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > We have 2 options:
> > 
> > * Wait for llvm to get improve their handling of assumption based 
> > optimizations.
> > * Proceed with this work hoping this encourages work on the optimizer.
> 
> The standard also mentions that `__has_cpp_attribute` should return `0` ‘if 
> an implementation does not attempt to deduce any such information from 
> assumptions’ [dcl.attr.assume], so another option would be to just have it 
> set to `0` for the time being and just not emit anything until that’s not an 
> issue anymore.

in this patch you ARE emitting the llvm assume, so I believe we ARE trying 
enough with this patch to mark it.  So `__has_cpp_attribute` needs to be 
properly populated.

I think the confusion/conflict between this and clang::assume needs to be 
figured out.  These two should just be, as close as possible, spellings of the 
same thing.  

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

> GCC does checks assumption in constant evaluation. I think we should too.

I’ll look into it in that case.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

> We have 2 options:
> 
> * Wait for llvm to get improve their handling of assumption based 
> optimizations.
> * Proceed with this work hoping this encourages work on the optimizer.

The standard also mentions that `__has_cpp_attribute` should return `0` ‘if an 
implementation does not attempt to deduce any such information from 
assumptions’ [dcl.attr.assume], so another option would be to just have it set 
to `0` for the time being and just not emit anything until that’s not an issue 
anymore.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is

Sirraide wrote:

That did strike me as odd as well. The proposal also explicitly mentions that 
entities appearing in `assume` are ODR-used, which would indicate that it’s 
supposed to be potentially evaluated, which is what I have it set to currently, 
and there’s also a test for that too.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

cor3ntin wrote:

Thanks for working on that.

GCC does checks assumption in constant evaluation. I think we should too.

My main question is whether we think supporting `assume` in the front-end is 
going to be a net positive knowing that the backend is going to pessimize some 
use of the attribute 

https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609

We have 2 options:
 - Wait for llvm to get improve their handling of assumption based 
optimizations.
 - Proceed with this work hoping this encourages work on the optimizer.

I don't have a strong opinion, but we should collectively be aware of pitfalls 
and
https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609  









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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

> Also note, we need to update the feature-test-macro/has_attribute-expr here.

I’ve already added a check for `__has_cpp_attribute` to one of the tests. 
`__has_attribute(assume)` already evaluates to `1` even without this pr, likely 
because of `clang::assume`, but I can add a test for that as well. I’m also not 
aware of a feature test macro for `assume`? AFAIK it’s just 
`__has_cpp_attribute`.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits

erichkeane wrote:

Also note, we need to update the feature-test-macro/has_attribute-expr here.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is

erichkeane wrote:

It came from memory of the discussion in EWG, though I note that the paper is 
actually pretty confusing about this, it calls it both 'not evaluated' 
(https://eel.is/c++draft/dcl.attr.assume#sentence-3) AND 'potentially 
evaluated' : https://eel.is/c++draft/dcl.attr.assume#sentence-6.

So I'm not sure actually...


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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 01/10] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1..2804ff1aea005 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002..192b081404a82 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3..9ecfdab3617e0 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63..847168af28862 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc9..0f982dbb67b41 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression(bool IsTr

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is

Sirraide wrote:

Actually, where does it state that side-effects are also UB, because I can’t 
seem to find that in `[dcl.attr.assume]` at least

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is

erichkeane wrote:

Just documented, there isn't really anything we can do about it.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits


@@ -4528,6 +4528,54 @@ static bool 
IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName,
   }
 }
 
+/// Parse the argument to C++23's [[assume()]] attribute.
+bool Parser::ParseAssumeAttributeArg(ParsedAttributes &Attrs,
+ IdentifierInfo *AttrName,
+ SourceLocation AttrNameLoc,
+ SourceLocation *EndLoc) {
+  assert(Tok.is(tok::l_paren) && "Not a C++11 attribute argument list");
+  BalancedDelimiterTracker T(*this, tok::l_paren);
+  T.consumeOpen();
+
+  // [dcl.attr.assume]: The expression is potentially evaluated.
+  EnterExpressionEvaluationContext Unevaluated(
+  Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
+
+  TentativeParsingAction TPA(*this);
+  ExprResult Res(

Sirraide wrote:

That’s currently handled in Sema

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is
+undefined. ``assume`` can only be applied to a null statement.
+
+Note that `clang::assume` is a different attribute. Always write ``assume``

Sirraide wrote:

Yeah, I agree, but I’m not that familiar w/ `clang::assume`, so I’m not too 
sure how to handle that.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is

Sirraide wrote:

Ah, I missed that. Should I do anything else about that other than add that to 
the documentation?

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is

erichkeane wrote:

Note also that side-effects are ALSO UB, and we don't have a way of checking 
that, so that should be added to this too.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -4528,6 +4528,54 @@ static bool 
IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName,
   }
 }
 
+/// Parse the argument to C++23's [[assume()]] attribute.
+bool Parser::ParseAssumeAttributeArg(ParsedAttributes &Attrs,
+ IdentifierInfo *AttrName,
+ SourceLocation AttrNameLoc,
+ SourceLocation *EndLoc) {
+  assert(Tok.is(tok::l_paren) && "Not a C++11 attribute argument list");
+  BalancedDelimiterTracker T(*this, tok::l_paren);
+  T.consumeOpen();
+
+  // [dcl.attr.assume]: The expression is potentially evaluated.
+  EnterExpressionEvaluationContext Unevaluated(
+  Actions, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
+
+  TentativeParsingAction TPA(*this);
+  ExprResult Res(

erichkeane wrote:

Does this check contextually convertible to bool?

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;

erichkeane wrote:

Please pass the name, it will allow us to better handle other spellings (since 
we allow standards spellings to work with other spellings, which I think 
`__attribute__((assume))` would work).

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -4528,6 +4528,54 @@ static bool 
IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName,
   }
 }
 
+/// Parse the argument to C++23's [[assume()]] attribute.
+bool Parser::ParseAssumeAttributeArg(ParsedAttributes &Attrs,

erichkeane wrote:

Hopefully someone more familiar with the parsing will come by, my familiarity 
here is limited.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Erich Keane via cfe-commits


@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is
+undefined. ``assume`` can only be applied to a null statement.
+
+Note that `clang::assume` is a different attribute. Always write ``assume``

erichkeane wrote:

This should be resolved IMO, we should merge these definitions/implementations 
if at all possible.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> CI on Windows seems to have had a stroke?

Yes it does have troubles ATM. We rely on Linux CI for now until Windows is 
fixed. Some context on the future may be found in 
https://discourse.llvm.org/t/rfc-future-of-windows-pre-commit-ci/76840/1 .

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

Actually, it would seem that there were some CMake errors earlier on too

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

CI on Windows seems to have had a stroke?
```
FAILED: cmTC_77a79.exe
cmd.exe /C "cd . && 
C:\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe 
-E vs_link_exe --intdir=CMakeFiles\cmTC_77a79.dir --rc="C:\Program Files 
(x86)\Windows Kits\10\bin\10.0.19041.0\x64\rc.exe" --mt="C:\Program Files 
(x86)\Windows Kits\10\bin\10.0.19041.0\x64\mt.exe" --manifests  -- 
C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\link.exe /nologo 
CMakeFiles\cmTC_77a79.dir\getErrc.cpp.obj  /out:cmTC_77a79.exe 
/implib:cmTC_77a79.lib /pdb:cmTC_77a79.pdb /version:0.0 /machine:x64  
/INCREMENTAL:NO /subsystem:console  kernel32.lib user32.lib gdi32.lib 
winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib 
advapi32.lib && cd ."
MT: command "C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\mt.exe 
/nologo /manifest cmTC_77a79.exe.manifest /outputresource:cmTC_77a79.exe;#1" 
failed (exit code 0x1f) with the following output:
mt.exe : general error c101008d: Failed to write the updated manifest to the 
resource of file "cmTC_77a79.exe". Operation did not complete successfully 
because the file contains a virus or potentially unwanted software.
```

Because I candidly don’t quite see how my `assume` code would being recognised 
as a virus...

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits


@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;

Sirraide wrote:

Speaking of `clang::assume`: We could add a warning in Sema that suggests using 
that instead if someone writes e.g. `[[assume("foo")]]` seeing as that 
tautological, albeit valid.

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 1/9] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1..2804ff1aea005 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002..192b081404a82 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3..9ecfdab3617e0 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63..847168af28862 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc9..0f982dbb67b41 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression(bool IsTrai

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits


@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;

Sirraide wrote:

Since `assume` (currently) only has one spelling (because `clang::assume` is 
something else as I understand it), I’ve inlined it here. Should I change this 
to `%0` and pass the attribute name to the diagnostic instead? The same also 
applies to some of the other assume-related diagnostics

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/81014

>From 5ba669011752b6ea6e6fe5f6141c4af66ca7ccbf Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 7 Feb 2024 17:25:10 +0100
Subject: [PATCH 1/8] [Clang] Parsing and Sema for C++23's `assume` attribute

---
 clang/include/clang/Basic/Attr.td |  9 
 clang/include/clang/Basic/DiagnosticGroups.td |  4 +-
 .../clang/Basic/DiagnosticParseKinds.td   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +++
 clang/include/clang/Parse/Parser.h|  7 +++
 clang/lib/Parse/ParseDeclCXX.cpp  | 54 ++-
 clang/lib/Parse/ParseExpr.cpp | 13 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 34 
 clang/test/Parser/cxx23-assume.cpp| 27 ++
 9 files changed, 156 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Parser/cxx23-assume.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..2804ff1aea005f 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumptionDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -783,6 +783,9 @@ def err_ms_property_expected_comma_or_rparen : Error<
 def err_ms_property_initializer : Error<
   "property declaration cannot have a default member initializer">;
 
+def err_assume_attr_expects_cond_expr : Error<
+  "use of this expression in an 'assume' attribute requires parentheses">;
+
 def warn_cxx20_compat_explicit_bool : Warning<
   "this expression will be parsed as explicit(bool) in C++20">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b4dc4feee8e63a..847168af288622 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9083,6 +9083,8 @@ def ext_cxx17_attr : Extension<
   "use of the %0 attribute is a C++17 extension">, InGroup;
 def ext_cxx20_attr : Extension<
   "use of the %0 attribute is a C++20 extension">, InGroup;
+def ext_cxx23_attr : Extension<
+  "use of the %0 attribute is a C++23 extension">, InGroup;
 
 def warn_unused_comparison : Warning<
   "%select{equality|inequality|relational|three-way}0 comparison result 
unused">,
@@ -10149,6 +10151,11 @@ def err_fallthrough_attr_outside_switch : Error<
 def err_fallthrough_attr_invalid_placement : Error<
   "fallthrough annotation does not directly precede switch label">;
 
+def err_assume_attr_args : Error<
+  "attribute 'assume' requires a single expression argument">;
+def err_assume_attr_wrong_target : Error<
+  "'assume' attribute is only allowed on empty statements">;
+
 def warn_unreachable_default : Warning<
   "default label in switch which covers all enumeration values">,
   InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index da18cf88edcc92..0f982dbb67b41c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1801,6 +1801,7 @@ class Parser : public CodeCompletionHandler {
   ExprResult ParseConstraintLogicalOrExpression(b

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 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 af6656c375b8aa9c9156575f7c0ac678a57070d5 
36fc751a4b3d55798f0e215bdb92f10e0d82afca -- 
clang/test/CodeGenCXX/cxx23-assume.cpp clang/test/Parser/cxx23-assume.cpp 
clang/test/SemaCXX/cxx23-assume.cpp clang/include/clang/Parse/Parser.h 
clang/lib/CodeGen/CGStmt.cpp clang/lib/Parse/ParseDeclCXX.cpp 
clang/lib/Parse/ParseExpr.cpp clang/lib/Sema/SemaStmtAttr.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index e712745a23..0812bc8761 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -329,7 +329,8 @@ static Attr *handleAssumeAttr(Sema &S, Stmt *St, const 
ParsedAttr &A,
 Assumption = Res.get();
 
 if (Assumption->HasSideEffects(S.Context, /*IncludePossibleEffects=*/true))
-  S.Diag(A.getLoc(), diag::warn_assume_side_effects) << A.getAttrName() << 
Range;
+  S.Diag(A.getLoc(), diag::warn_assume_side_effects)
+  << A.getAttrName() << Range;
   }
 
   if (!S.getLangOpts().CPlusPlus23)

``




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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

Sirraide wrote:

CC @AaronBallman @cor3ntin @erichkeane

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


[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Sirraide)


Changes

This implements the C++23 `assume` attribute.

This pr currently does not include any changes to constant evaluation. Even 
though the standard specifies that the behaviour is undefined should an 
assumption evaluate to `false` at runtime [dcl.attr.assume], it also mentions 
that we’re not required to diagnose that [expr.const], as I understand it.

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


14 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Basic/Attr.td (+9) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+24) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+3-1) 
- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+3) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+7) 
- (modified) clang/include/clang/Parse/Parser.h (+7) 
- (modified) clang/lib/CodeGen/CGStmt.cpp (+9-2) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+54-1) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+13) 
- (modified) clang/lib/Sema/SemaStmtAttr.cpp (+37) 
- (added) clang/test/CodeGenCXX/cxx23-assume.cpp (+28) 
- (added) clang/test/Parser/cxx23-assume.cpp (+14) 
- (added) clang/test/SemaCXX/cxx23-assume.cpp (+50) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 802c44b6c86080..6312e100913613 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -95,6 +95,7 @@ C++23 Feature Support
 
 - Implemented `P2718R0: Lifetime extension in range-based for loops 
`_. Also
   materialize temporary object which is a prvalue in discarded-value 
expression.
+- Implemented `P1774R8: Portable assumptions `_.
 
 C++2c Feature Support
 ^
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..6cd2a541da17d9 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumeDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 041786f37fb8a7..1b27a46ef1d901 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is
+undefined. ``assume`` can only be applied to a null statement.
+
+Note that `clang::assume` is a different attribute. Always write ``assume``
+without a namespace if you intend to use the standard C++ attribute.
+
+Example:
+
+.. code-block:: c++
+
+  int f(int x, int y) {
+[[assume(x == 27)]];
+[[assume(x == y)]];
+return y + 1; // Will be optimised to `return 28`.
+  }
+  }];
+}
+
 def LikelihoodDocs : Documentation {
   let Category = DocCatStmt;
   let Heading = "likely and unlikely";
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticPars

[clang] [Clang][C++23] Implement P1774R8: Portable assumptions (PR #81014)

2024-02-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (Sirraide)


Changes

This implements the C++23 `assume` attribute.

This pr currently does not include any changes to constant evaluation. Even 
though the standard specifies that the behaviour is undefined should an 
assumption evaluate to `false` at runtime [dcl.attr.assume], it also mentions 
that we’re not required to diagnose that [expr.const], as I understand it.

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


14 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Basic/Attr.td (+9) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+24) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+3-1) 
- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+3) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+7) 
- (modified) clang/include/clang/Parse/Parser.h (+7) 
- (modified) clang/lib/CodeGen/CGStmt.cpp (+9-2) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+54-1) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+13) 
- (modified) clang/lib/Sema/SemaStmtAttr.cpp (+37) 
- (added) clang/test/CodeGenCXX/cxx23-assume.cpp (+28) 
- (added) clang/test/Parser/cxx23-assume.cpp (+14) 
- (added) clang/test/SemaCXX/cxx23-assume.cpp (+50) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 802c44b6c86080..6312e100913613 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -95,6 +95,7 @@ C++23 Feature Support
 
 - Implemented `P2718R0: Lifetime extension in range-based for loops 
`_. Also
   materialize temporary object which is a prvalue in discarded-value 
expression.
+- Implemented `P1774R8: Portable assumptions `_.
 
 C++2c Feature Support
 ^
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b2d5309e142c1a..6cd2a541da17d9 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1564,6 +1564,15 @@ def Unlikely : StmtAttr {
 }
 def : MutualExclusions<[Likely, Unlikely]>;
 
+def Assume : StmtAttr {
+  let Spellings = [CXX11<"", "assume", 202302>];
+  let Subjects = SubjectList<[NullStmt], ErrorDiag, "empty statements">;
+  // The standard only allows a conditional-expression here, but we ought
+  // to get better results by handling that in Sema.
+  let Args = [ExprArgument<"Assumption">];
+  let Documentation = [AssumeDocs];
+}
+
 def NoMerge : DeclOrStmtAttr {
   let Spellings = [Clang<"nomerge">];
   let Documentation = [NoMergeDocs];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 041786f37fb8a7..1b27a46ef1d901 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1996,6 +1996,30 @@ Here is an example:
   }];
 }
 
+def AssumeDocs : Documentation {
+  let Category = DocCatStmt;
+  let Heading = "assume";
+  let Content = [{
+The ``assume`` attribute is used to indicate to the optimizer that a
+certain condition can be assumed to be true at a certain point in the
+program. If this condition is violated at runtime, the behavior is
+undefined. ``assume`` can only be applied to a null statement.
+
+Note that `clang::assume` is a different attribute. Always write ``assume``
+without a namespace if you intend to use the standard C++ attribute.
+
+Example:
+
+.. code-block:: c++
+
+  int f(int x, int y) {
+[[assume(x == 27)]];
+[[assume(x == y)]];
+return y + 1; // Will be optimised to `return 28`.
+  }
+  }];
+}
+
 def LikelihoodDocs : Documentation {
   let Category = DocCatStmt;
   let Heading = "likely and unlikely";
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..192b081404a827 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1124,9 +1124,11 @@ def NonGCC : DiagGroup<"non-gcc",
 def CXX14Attrs : DiagGroup<"c++14-attribute-extensions">;
 def CXX17Attrs : DiagGroup<"c++17-attribute-extensions">;
 def CXX20Attrs : DiagGroup<"c++20-attribute-extensions">;
+def CXX23Attrs : DiagGroup<"c++23-attribute-extensions">;
 def FutureAttrs : DiagGroup<"future-attribute-extensions", [CXX14Attrs,
 CXX17Attrs,
-CXX20Attrs]>;
+CXX20Attrs,
+CXX23Attrs]>;
 
 def CXX23AttrsOnLambda : DiagGroup<"c++23-lambda-attributes">;
 
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index a30ab27566ec3e..9ecfdab3617e05 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/Diagno

  1   2   >