[clang] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-04-25 Thread M. Zeeshan Siddiqui via cfe-commits

codemzs wrote:

> @codemzs Any news? Thanks a lot for your work!

@cor3ntin Sorry for the delay, I plan to get back to this PR in the next few 
weeks. Do you need this change for something?

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


[clang] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-02-28 Thread M. Zeeshan Siddiqui via cfe-commits

codemzs wrote:

> What's the status of this PR?  Seems like it would be helpful for some of the 
> C23 additions (`_Float128` being of most interest to me)

Thank you for checking in on this PR! It has gone through several iterations 
based on valuable feedback from the community (carried over from Phabricator). 
I’m currently addressing the latest round of feedback and plan to update the PR 
within this week.

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


[clang] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-01-17 Thread M. Zeeshan Siddiqui via cfe-commits

codemzs wrote:

@tahonermann @zahiraam I have migrated the review from 
https://reviews.llvm.org/D149573 here and have addressed your most recent 
comment. 

I'm not sure how to add you as reviewers as I don't see that option on my end.

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


[clang] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-01-17 Thread M. Zeeshan Siddiqui via cfe-commits

https://github.com/codemzs updated 
https://github.com/llvm/llvm-project/pull/78503

>From c9a95ed6db27861de2e7363eff17839b3bcb32d1 Mon Sep 17 00:00:00 2001
From: "M. Zeeshan Siddiqui" 
Date: Mon, 13 Nov 2023 17:37:36 +
Subject: [PATCH] [Clang][C++23] Implement core language changes from P1467R9
 extended floating-point types and standard names.

This commit implements Core language changes based on P1467R9 Extended
floating-point types and standard names.

As per the proposal's definition the following two types are marked as
extended floating point: Float16 (aka _Float16) and
Bfloat16 (aka decltype (0.0bf16) or __bf16). Future work can extend this
to support other floating-point types such as Float32, Float64, and
Float128.

RFC: 
https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033

Differential Revision: https://reviews.llvm.org/D149573
---
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/AST/ASTContext.h  |  54 +-
 clang/include/clang/AST/BuiltinTypes.def  |   4 +-
 clang/include/clang/AST/Type.h|   7 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/include/clang/Lex/LiteralSupport.h  |   1 +
 .../Core/PathSensitive/SMTConv.h  |  19 +-
 clang/lib/AST/ASTContext.cpp  | 148 -
 clang/lib/AST/StmtPrinter.cpp |   1 +
 clang/lib/AST/Type.cpp|  27 +
 clang/lib/Frontend/InitPreprocessor.cpp   |   6 +-
 clang/lib/Lex/LiteralSupport.cpp  |  17 +
 clang/lib/Sema/Sema.cpp   |  16 +
 clang/lib/Sema/SemaCast.cpp   |  13 +
 clang/lib/Sema/SemaChecking.cpp   |  23 +-
 clang/lib/Sema/SemaExpr.cpp   |  60 ++-
 clang/lib/Sema/SemaOverload.cpp   |  81 ++-
 .../cxx23-fp-ext-std-names-p1467r9.cpp| 499 +
 .../test/CodeGenCXX/cxx23-vector-bfloat16.cpp |  67 +++
 .../Sema/cxx23-fp-ext-std-names-p1467r9.cpp   | 505 ++
 20 files changed, 1509 insertions(+), 46 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/cxx23-fp-ext-std-names-p1467r9.cpp
 create mode 100644 clang/test/CodeGenCXX/cxx23-vector-bfloat16.cpp
 create mode 100644 clang/test/Sema/cxx23-fp-ext-std-names-p1467r9.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cf52c1e66b91b4..64cbb55ca80edb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -192,6 +192,11 @@ C++23 Feature Support
 - Added a separate warning to warn the use of attributes on lambdas as a C++23 
extension
   in previous language versions: ``-Wc++23-lambda-attributes``.
 
+- Implemented `P1467R9: Extended floating-point types and standard names 
`_. Enables
+  extended floating-point types beyond the three standard ones, establishing 
rules for their interactions and
+  conversions with each other and other types, while ensuring no alteration in 
the behavior of existing
+  standard types. The current implementation enables support for 
`std::float16_t` and `std::bfloat16_t` types.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3e46a5da3fc043..7f823d9e57d3da 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -52,6 +52,16 @@ template  class SmallPtrSet;
 
 namespace clang {
 
+// Conversion ranks introduced in C++23 6.8.6p2 [conv.rank]
+enum FloatConvRankCompareResult {
+  FRCR_Unordered,
+  FRCR_Lesser,
+  FRCR_Greater,
+  FRCR_Equal,
+  FRCR_Equal_Lesser_Subrank,
+  FRCR_Equal_Greater_Subrank,
+};
+
 class APValue;
 class ASTMutationListener;
 class ASTRecordLayout;
@@ -1105,8 +1115,8 @@ class ASTContext : public RefCountedBase {
   CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
   SatUnsignedLongFractTy;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
-  CanQualType BFloat16Ty;
-  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
+  CanQualType BFloat16Ty; // [C++23 6.8.3p5][basic.extended.fp]
+  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 and [C++23 
6.8.3p1][basic.extended.fp]
   CanQualType VoidPtrTy, NullPtrTy;
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
   CanQualType BuiltinFnTy;
@@ -2388,6 +2398,9 @@ class ASTContext : public RefCountedBase {
   /// More type predicates useful for type checking/promotion
   bool isPromotableIntegerType(QualType T) const; // C99 6.3.1.1p2
 
+  /// Determine if a floating type can be promoted to another floating type.
+  bool isPromotableFloatingType(QualType T) const;
+
   /// Return the "preferred" alignment of the specified type \p T for
   /// the current target, in bits.
   ///
@@ -2783,6 +2796,9 @@ class ASTContext : public RefCountedBase {
   /// 6.3.1.1p2, assuming that \p PromotableType is a promotable integer type.
   QualType g

[clang] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-01-17 Thread M. Zeeshan Siddiqui via cfe-commits

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


[clang] [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2024-01-17 Thread M. Zeeshan Siddiqui via cfe-commits

https://github.com/codemzs created 
https://github.com/llvm/llvm-project/pull/78503

Implements Core language changes based on 
[P1467R9](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1467r9.html)
 Extended floating-point types and standard names.

As per the proposal's definition the following two types are marked as extended 
floating point: `Float16` (aka `_Float16`) and `Bfloat16` (aka `decltype 
(0.0bf16)` or `__bf16`). Future work can extend this to support other 
floating-point types such as `Float32`, `Float64`, and `Float128`.

RFC: 
https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033

This pull request is a carryover from the now offline phabricator differential 
revision: https://reviews.llvm.org/D149573

>From d47d92d074e6a4870849db79dec5adb197bed010 Mon Sep 17 00:00:00 2001
From: "M. Zeeshan Siddiqui" 
Date: Mon, 13 Nov 2023 17:37:36 +
Subject: [PATCH] [Clang][C++23] Implement core language changes from P1467R9
 extended floating-point types and standard names.

This commit implements Core language changes based on P1467R9 Extended
floating-point types and standard names.

As per the proposal's definition the following two types are marked as
extended floating point: Float16 (aka _Float16) and
Bfloat16 (aka decltype (0.0bf16) or __bf16). Future work can extend this
to support other floating-point types such as Float32, Float64, and
Float128.

RFC: 
https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033

Differential Revision: https://reviews.llvm.org/D149573
---
 clang/include/clang/AST/ASTContext.h  |  48 +-
 clang/include/clang/AST/Type.h|   7 +
 .../clang/Basic/DiagnosticSemaKinds.td|   1 +
 clang/include/clang/Lex/LiteralSupport.h  |   1 +
 .../Core/PathSensitive/SMTConv.h  |   7 +-
 clang/lib/AST/ASTContext.cpp  | 137 -
 clang/lib/AST/StmtPrinter.cpp |   1 +
 clang/lib/AST/Type.cpp|  27 +
 clang/lib/Frontend/InitPreprocessor.cpp   |   6 +-
 clang/lib/Lex/LiteralSupport.cpp  |  17 +
 clang/lib/Sema/Sema.cpp   |  17 +
 clang/lib/Sema/SemaCast.cpp   |  13 +
 clang/lib/Sema/SemaChecking.cpp   |  17 +-
 clang/lib/Sema/SemaExpr.cpp   |  60 ++-
 clang/lib/Sema/SemaOverload.cpp   |  81 ++-
 .../cxx23-fp-ext-std-names-p1467r9.cpp| 499 +
 .../test/CodeGenCXX/cxx23-vector-bfloat16.cpp |  67 +++
 .../Sema/cxx23-fp-ext-std-names-p1467r9.cpp   | 505 ++
 18 files changed, 1471 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/cxx23-fp-ext-std-names-p1467r9.cpp
 create mode 100644 clang/test/CodeGenCXX/cxx23-vector-bfloat16.cpp
 create mode 100644 clang/test/Sema/cxx23-fp-ext-std-names-p1467r9.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3e46a5da3fc043..beec40b4a8197b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -52,6 +52,16 @@ template  class SmallPtrSet;
 
 namespace clang {
 
+// Conversion ranks introduced in C++23 6.8.6p2 [conv.rank]
+enum FloatingRankCompareResult {
+  FRCR_Unordered,
+  FRCR_Lesser,
+  FRCR_Greater,
+  FRCR_Equal,
+  FRCR_Equal_Lesser_Subrank,
+  FRCR_Equal_Greater_Subrank,
+};
+
 class APValue;
 class ASTMutationListener;
 class ASTRecordLayout;
@@ -1105,8 +1115,8 @@ class ASTContext : public RefCountedBase {
   CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
   SatUnsignedLongFractTy;
   CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
-  CanQualType BFloat16Ty;
-  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3
+  CanQualType BFloat16Ty; // [C++23 6.8.3p5][basic.extended.fp]
+  CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3 and [C++23 
6.8.3p5][basic.extended.fp]
   CanQualType VoidPtrTy, NullPtrTy;
   CanQualType DependentTy, OverloadTy, BoundMemberTy, UnknownAnyTy;
   CanQualType BuiltinFnTy;
@@ -2803,14 +2813,38 @@ class ASTContext : public RefCountedBase {
   /// Compare the rank of the two specified floating point types,
   /// ignoring the domain of the type (i.e. 'double' == '_Complex double').
   ///
-  /// If \p LHS > \p RHS, returns 1.  If \p LHS == \p RHS, returns 0.  If
-  /// \p LHS < \p RHS, return -1.
-  int getFloatingTypeOrder(QualType LHS, QualType RHS) const;
+  /// If \p LHS > \p RHS, returns FRCR_Greater. If \p LHS == \p RHS, returns
+  /// FRCR_Equal.  If \p LHS < \p RHS, return FRCR_Lesser. If \p LHS and \p RHS
+  /// are unordered, return FRCR_Unordered. If \p LHS and \p RHS are equal but
+  /// the subrank of \p LHS is greater than \p RHS, return
+  /// FRCR_Equal_Greater_Subrank. If \p LHS and \p RHS are equal but the 
subrank
+  /// of \p LHS is less than \p RHS, return FRCR_Equal_Lesser_Subrank. Subrank
+  /// and Unordered comparison were i