[Lldb-commits] [llvm] [clang-tools-extra] [libcxx] [compiler-rt] [lld] [clang] [libc] [libunwind] [flang] [lldb] Warn inf nan fast fp (PR #76854)

Zahira Ammarguellat via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 3 11:39:44 PST 2024


https://github.com/zahiraam created https://github.com/llvm/llvm-project/pull/76854

None

>From 340e3777509f70b5b300adcb181261e84247cf1a Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Mon, 23 Oct 2023 12:51:21 -0700
Subject: [PATCH 1/4] Revert "[clang] Support fixed point types in C++
 (#67750)"

This reverts commit a3a7d6318027bb86e6614c022e77e0bd81aef6dc.

When compiling with MSVC2022 in  C++32 mode this is giving an
error.
Compiling this simple test case:
t1.cpp:
with -std=c++23 will give the following error:

In file included from C:\Users\zahiraam\t1.cpp:1:
c:\Program files\Microsoft Visual
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3329:16:
error:
      compile with '-ffixed-point' to enable fixed point types
       3329 |         _Vbase _Accum = 0;
             |                ^
c:\Program files\Microsoft Visual
Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3329:23:
error:
      expected unqualified-id
       3329 |         _Vbase _Accum = 0;
             |                       ^
Please full error in
https://github.com/llvm/llvm-project/pull/67750#issuecomment-1775264907
---
 clang/include/clang/Basic/TokenKinds.def     |  6 +-
 clang/include/clang/Driver/Options.td        |  2 +-
 clang/lib/AST/ItaniumMangle.cpp              | 59 +-------------------
 clang/lib/Parse/ParseExpr.cpp                |  3 -
 clang/lib/Parse/ParseExprCXX.cpp             |  9 ---
 clang/lib/Parse/ParseTentative.cpp           |  6 --
 clang/test/CodeGenCXX/fixed-point-mangle.cpp | 45 ---------------
 clang/test/Frontend/fixed_point_errors.cpp   | 24 ++++----
 8 files changed, 15 insertions(+), 139 deletions(-)
 delete mode 100644 clang/test/CodeGenCXX/fixed-point-mangle.cpp

diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def
index bbae1200d376c0..3ce317d318f9bb 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -423,9 +423,9 @@ C23_KEYWORD(typeof                  , KEYGNU)
 C23_KEYWORD(typeof_unqual           , 0)
 
 // ISO/IEC JTC1 SC22 WG14 N1169 Extension
-KEYWORD(_Accum                      , KEYALL)
-KEYWORD(_Fract                      , KEYALL)
-KEYWORD(_Sat                        , KEYALL)
+KEYWORD(_Accum                      , KEYNOCXX)
+KEYWORD(_Fract                      , KEYNOCXX)
+KEYWORD(_Sat                        , KEYNOCXX)
 
 // GNU Extensions (in impl-reserved namespace)
 KEYWORD(_Decimal32                  , KEYALL)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index e63158fb0e5333..ca883689b05c28 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2097,7 +2097,7 @@ defm fixed_point : BoolFOption<"fixed-point",
   LangOpts<"FixedPoint">, DefaultFalse,
   PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
   NegFlag<SetFalse, [], [ClangOption], "Disable">,
-  BothFlags<[], [ClangOption], " fixed point types">>;
+  BothFlags<[], [ClangOption], " fixed point types">>, ShouldParseIf<!strconcat("!", cplusplus.KeyPath)>;
 defm cxx_static_destructors : BoolFOption<"c++-static-destructors",
   LangOpts<"RegisterStaticDestructors">, DefaultTrue,
   NegFlag<SetFalse, [], [ClangOption, CC1Option],
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 27e8cbf6dc3f41..eafb121a8a4aa0 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3050,17 +3050,7 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
   //                 ::= Di # char32_t
   //                 ::= Ds # char16_t
   //                 ::= Dn # std::nullptr_t (i.e., decltype(nullptr))
-  //                 ::= [DS] DA  # N1169 fixed-point [_Sat] T _Accum
-  //                 ::= [DS] DR  # N1169 fixed-point [_Sat] T _Fract
   //                 ::= u <source-name>    # vendor extended type
-  //
-  //  <fixed-point-size>
-  //                 ::= s # short
-  //                 ::= t # unsigned short
-  //                 ::= i # plain
-  //                 ::= j # unsigned
-  //                 ::= l # long
-  //                 ::= m # unsigned long
   std::string type_name;
   // Normalize integer types as vendor extended types:
   // u<length>i<type size>
@@ -3205,77 +3195,30 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
     Out << "DF16_";
     break;
   case BuiltinType::ShortAccum:
-    Out << "DAs";
-    break;
   case BuiltinType::Accum:
-    Out << "DAi";
-    break;
   case BuiltinType::LongAccum:
-    Out << "DAl";
-    break;
   case BuiltinType::UShortAccum:
-    Out << "DAt";
-    break;
   case BuiltinType::UAccum:
-    Out << "DAj";
-    break;
   case BuiltinType::ULongAccum:
-    Out << "DAm";
-    break;
   case BuiltinType::ShortFract:
-    Out << "DRs";
-    break;
   case BuiltinType::Fract:
-    Out << "DRi";
-    break;
   case BuiltinType::LongFract:
-    Out << "DRl";
-    break;
   case BuiltinType::UShortFract:
-    Out << "DRt";
-    break;
   case BuiltinType::UFract:
-    Out << "DRj";
-    break;
   case BuiltinType::ULongFract:
-    Out << "DRm";
-    break;
   case BuiltinType::SatShortAccum:
-    Out << "DSDAs";
-    break;
   case BuiltinType::SatAccum:
-    Out << "DSDAi";
-    break;
   case BuiltinType::SatLongAccum:
-    Out << "DSDAl";
-    break;
   case BuiltinType::SatUShortAccum:
-    Out << "DSDAt";
-    break;
   case BuiltinType::SatUAccum:
-    Out << "DSDAj";
-    break;
   case BuiltinType::SatULongAccum:
-    Out << "DSDAm";
-    break;
   case BuiltinType::SatShortFract:
-    Out << "DSDRs";
-    break;
   case BuiltinType::SatFract:
-    Out << "DSDRi";
-    break;
   case BuiltinType::SatLongFract:
-    Out << "DSDRl";
-    break;
   case BuiltinType::SatUShortFract:
-    Out << "DSDRt";
-    break;
   case BuiltinType::SatUFract:
-    Out << "DSDRj";
-    break;
   case BuiltinType::SatULongFract:
-    Out << "DSDRm";
-    break;
+    llvm_unreachable("Fixed point types are disabled for c++");
   case BuiltinType::Half:
     Out << "Dh";
     break;
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 4d267c915ff247..dd2d9400b7747e 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1574,9 +1574,6 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
   case tok::kw_typename:
   case tok::kw_typeof:
   case tok::kw___vector:
-  case tok::kw__Accum:
-  case tok::kw__Fract:
-  case tok::kw__Sat:
 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
 #include "clang/Basic/OpenCLImageTypes.def"
   {
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 79db094e098f8e..99b4931004546c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2354,15 +2354,6 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
   case tok::kw_bool:
     DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID, Policy);
     break;
-  case tok::kw__Accum:
-    DS.SetTypeSpecType(DeclSpec::TST_accum, Loc, PrevSpec, DiagID, Policy);
-    break;
-  case tok::kw__Fract:
-    DS.SetTypeSpecType(DeclSpec::TST_fract, Loc, PrevSpec, DiagID, Policy);
-    break;
-  case tok::kw__Sat:
-    DS.SetTypeSpecSat(Loc, PrevSpec, DiagID);
-    break;
 #define GENERIC_IMAGE_TYPE(ImgType, Id)                                        \
   case tok::kw_##ImgType##_t:                                                  \
     DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID,     \
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index 8b653b1c4f8eaf..28decc4fc43f9b 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1775,9 +1775,6 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
   case tok::kw___ibm128:
   case tok::kw_void:
   case tok::annot_decltype:
-  case tok::kw__Accum:
-  case tok::kw__Fract:
-  case tok::kw__Sat:
 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
 #include "clang/Basic/OpenCLImageTypes.def"
     if (NextToken().is(tok::l_paren))
@@ -1897,9 +1894,6 @@ bool Parser::isCXXDeclarationSpecifierAType() {
   case tok::kw_void:
   case tok::kw___unknown_anytype:
   case tok::kw___auto_type:
-  case tok::kw__Accum:
-  case tok::kw__Fract:
-  case tok::kw__Sat:
 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
 #include "clang/Basic/OpenCLImageTypes.def"
     return true;
diff --git a/clang/test/CodeGenCXX/fixed-point-mangle.cpp b/clang/test/CodeGenCXX/fixed-point-mangle.cpp
deleted file mode 100644
index 103990a61316a9..00000000000000
--- a/clang/test/CodeGenCXX/fixed-point-mangle.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - -triple=x86_64-unknown-linux-gnu | FileCheck %s
-
-// Primary fixed point types
-void func(signed short _Accum){}    // CHECK: @_Z4funcDAs
-void func(signed _Accum){}          // CHECK: @_Z4funcDAi
-void func(signed long _Accum){}     // CHECK: @_Z4funcDAl
-void func(unsigned short _Accum){}  // CHECK: @_Z4funcDAt
-void func(unsigned _Accum){}        // CHECK: @_Z4funcDAj
-void func(unsigned long _Accum){}   // CHECK: @_Z4funcDAm
-void func(signed short _Fract){}    // CHECK: @_Z4funcDRs
-void func(signed _Fract){}          // CHECK: @_Z4funcDRi
-void func(signed long _Fract){}     // CHECK: @_Z4funcDRl
-void func(unsigned short _Fract){}  // CHECK: @_Z4funcDRt
-void func(unsigned _Fract){}        // CHECK: @_Z4funcDRj
-void func(unsigned long _Fract){}   // CHECK: @_Z4funcDRm
-
-// Aliased
-void func2(short _Accum){}          // CHECK: @_Z5func2DAs
-void func2(_Accum){}                // CHECK: @_Z5func2DAi
-void func2(long _Accum){}           // CHECK: @_Z5func2DAl
-void func2(short _Fract){}          // CHECK: @_Z5func2DRs
-void func2(_Fract){}                // CHECK: @_Z5func2DRi
-void func2(long _Fract){}           // CHECK: @_Z5func2DRl
-
-// Primary saturated
-void func(_Sat signed short _Accum){}    // CHECK: @_Z4funcDSDAs
-void func(_Sat signed _Accum){}          // CHECK: @_Z4funcDSDAi
-void func(_Sat signed long _Accum){}     // CHECK: @_Z4funcDSDAl
-void func(_Sat unsigned short _Accum){}  // CHECK: @_Z4funcDSDAt
-void func(_Sat unsigned _Accum){}        // CHECK: @_Z4funcDSDAj
-void func(_Sat unsigned long _Accum){}   // CHECK: @_Z4funcDSDAm
-void func(_Sat signed short _Fract){}    // CHECK: @_Z4funcDSDRs
-void func(_Sat signed _Fract){}          // CHECK: @_Z4funcDSDRi
-void func(_Sat signed long _Fract){}     // CHECK: @_Z4funcDSDRl
-void func(_Sat unsigned short _Fract){}  // CHECK: @_Z4funcDSDRt
-void func(_Sat unsigned _Fract){}        // CHECK: @_Z4funcDSDRj
-void func(_Sat unsigned long _Fract){}   // CHECK: @_Z4funcDSDRm
-
-// Aliased saturated
-void func2(_Sat short _Accum){}          // CHECK: @_Z5func2DSDAs
-void func2(_Sat _Accum){}                // CHECK: @_Z5func2DSDAi
-void func2(_Sat long _Accum){}           // CHECK: @_Z5func2DSDAl
-void func2(_Sat short _Fract){}          // CHECK: @_Z5func2DSDRs
-void func2(_Sat _Fract){}                // CHECK: @_Z5func2DSDRi
-void func2(_Sat long _Fract){}           // CHECK: @_Z5func2DSDRl
diff --git a/clang/test/Frontend/fixed_point_errors.cpp b/clang/test/Frontend/fixed_point_errors.cpp
index 2264622a2e8c87..cdd90ceb7548f9 100644
--- a/clang/test/Frontend/fixed_point_errors.cpp
+++ b/clang/test/Frontend/fixed_point_errors.cpp
@@ -1,18 +1,14 @@
-// RUN: %clang_cc1 -x c++ %s -verify -DWITHOUT_FIXED_POINT
-// RUN: %clang_cc1 -x c++ %s -verify -ffixed-point
+// RUN: %clang_cc1 -x c++ %s -verify
+// RUN: %clang_cc1 -x c++ -ffixed-point %s -verify
 
-#ifdef WITHOUT_FIXED_POINT
-_Accum accum;                           // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
-                                        // expected-error at -1{{a type specifier is required for all declarations}}
-_Fract fract;                           // expected-error{{compile with '-ffixed-point' to enable fixed point types}}
-                                        // expected-error at -1{{a type specifier is required for all declarations}}
-_Sat _Accum sat_accum;                  // expected-error 2{{compile with '-ffixed-point' to enable fixed point types}}
-                                        // expected-error at -1{{a type specifier is required for all declarations}}
-#endif
+// Name namgling is not provided for fixed point types in c++
+
+_Accum accum;                           // expected-error{{unknown type name '_Accum'}}
+_Fract fract;                           // expected-error{{unknown type name '_Fract'}}
+_Sat _Accum sat_accum;                  // expected-error{{unknown type name '_Sat'}}
+                                        // expected-error at -1{{expected ';' after top level declarator}}
 
 int accum_int = 10k;     // expected-error{{invalid suffix 'k' on integer constant}}
 int fract_int = 10r;     // expected-error{{invalid suffix 'r' on integer constant}}
-#ifdef WITHOUT_FIXED_POINT
-float accum_flt = 0.0k;  // expected-error{{invalid suffix 'k' on floating constant}}
-float fract_flt = 0.0r;  // expected-error{{invalid suffix 'r' on floating constant}}
-#endif
+float accum_flt = 10.0k; // expected-error{{invalid suffix 'k' on floating constant}}
+float fract_flt = 10.0r; // expected-error{{invalid suffix 'r' on floating constant}}

>From a9268af3c21a6dbb6bc70d607642cc698dbfc678 Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Mon, 23 Oct 2023 14:14:42 -0700
Subject: [PATCH 2/4] Fix format.

---
 clang/lib/AST/ItaniumMangle.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index eafb121a8a4aa0..c3be3366e66731 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3046,7 +3046,8 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
   // UNSUPPORTED:    ::= De # IEEE 754r decimal floating point (128 bits)
   // UNSUPPORTED:    ::= Df # IEEE 754r decimal floating point (32 bits)
   //                 ::= Dh # IEEE 754r half-precision floating point (16 bits)
-  //                 ::= DF <number> _ # ISO/IEC TS 18661 binary floating point type _FloatN (N bits);
+  //                 ::= DF <number> _ # ISO/IEC TS 18661 binary floating point
+  //                 type _FloatN (N bits);
   //                 ::= Di # char32_t
   //                 ::= Ds # char16_t
   //                 ::= Dn # std::nullptr_t (i.e., decltype(nullptr))

>From 14a8ea1566c6a2d172aafdf71fbb258609fa5014 Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Tue, 24 Oct 2023 05:21:58 -0700
Subject: [PATCH 3/4] Fix format.

---
 clang/lib/AST/ItaniumMangle.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index eafb121a8a4aa0..c3be3366e66731 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3046,7 +3046,8 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
   // UNSUPPORTED:    ::= De # IEEE 754r decimal floating point (128 bits)
   // UNSUPPORTED:    ::= Df # IEEE 754r decimal floating point (32 bits)
   //                 ::= Dh # IEEE 754r half-precision floating point (16 bits)
-  //                 ::= DF <number> _ # ISO/IEC TS 18661 binary floating point type _FloatN (N bits);
+  //                 ::= DF <number> _ # ISO/IEC TS 18661 binary floating point
+  //                 type _FloatN (N bits);
   //                 ::= Di # char32_t
   //                 ::= Ds # char16_t
   //                 ::= Dn # std::nullptr_t (i.e., decltype(nullptr))

>From b0943dc140624b394a8d89c97e8b1f1b5c60f7ba Mon Sep 17 00:00:00 2001
From: Ammarguellat <zahira.ammarguellat at intel.com>
Date: Wed, 3 Jan 2024 11:35:55 -0800
Subject: [PATCH 4/4] Check for comparisons to INF and NaN when in ffast-math
 mode and generate a warning.

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e54f969c19039d..1b75ae8f678b68 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6771,6 +6771,9 @@ def warn_pointer_sub_null_ptr : Warning<
 def warn_floatingpoint_eq : Warning<
   "comparing floating point with == or != is unsafe">,
   InGroup<DiagGroup<"float-equal">>, DefaultIgnore;
+def warn_fast_floatingpoint_eq : Warning<
+  "explicit comparison with %0 in fast floating point mode">,
+  InGroup<TautologicalConstantCompare>;
 
 def err_setting_eval_method_used_in_unsafe_context : Error <
   "%select{'#pragma clang fp eval_method'|option 'ffp-eval-method'}0 cannot be used with "



More information about the lldb-commits mailing list