[clang] d2fd110 - Reapply "[clang] Support fixed point types in C++ (#67750)" (#69963)

Leonard Chan via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 14 12:22:05 PST 2023


Author: Leonard Chan
Date: 2023-11-14T20:18:06Z
New Revision: d2fd1106f6879c410b6a807133090866e6c3a243

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

LOG: Reapply "[clang] Support fixed point types in C++ (#67750)" (#69963)

This reverts commit d593f6cb387fe86aad47d3b763abcf0048e5b568.

Added: 
    clang/test/CodeGenCXX/fixed-point-mangle.cpp

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/AST/ItaniumMangle.cpp
    clang/lib/Parse/ParseExpr.cpp
    clang/lib/Parse/ParseExprCXX.cpp
    clang/lib/Parse/ParseTentative.cpp
    clang/test/Frontend/fixed_point_errors.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index d1b67a448b2a59b..e63ee583f6b30c5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2117,7 +2117,7 @@ defm fixed_point : BoolFOption<"fixed-point",
   LangOpts<"FixedPoint">, DefaultFalse,
   PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
   NegFlag<SetFalse, [], [ClangOption], "Disable">,
-  BothFlags<[], [ClangOption], " fixed point types">>, ShouldParseIf<!strconcat("!", cplusplus.KeyPath)>;
+  BothFlags<[], [ClangOption], " fixed point types">>;
 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 6c5217f0da11e6c..2a62ac0175afb72 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3051,12 +3051,21 @@ 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))
+  //                 ::= [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>
@@ -3201,30 +3210,77 @@ 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:
-    llvm_unreachable("Fixed point types are disabled for c++");
+    Out << "DSDRm";
+    break;
   case BuiltinType::Half:
     Out << "Dh";
     break;

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 9e05394e8d07dd6..897810557976151 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1577,6 +1577,9 @@ 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 99b4931004546c1..79db094e098f8e6 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2354,6 +2354,15 @@ 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 28decc4fc43f9b8..8b653b1c4f8eaf4 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -1775,6 +1775,9 @@ 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))
@@ -1894,6 +1897,9 @@ 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
new file mode 100644
index 000000000000000..103990a61316a9c
--- /dev/null
+++ b/clang/test/CodeGenCXX/fixed-point-mangle.cpp
@@ -0,0 +1,45 @@
+// 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 cdd90ceb7548f94..4097cd73c845050 100644
--- a/clang/test/Frontend/fixed_point_errors.cpp
+++ b/clang/test/Frontend/fixed_point_errors.cpp
@@ -1,14 +1,16 @@
-// RUN: %clang_cc1 -x c++ %s -verify
-// RUN: %clang_cc1 -x c++ -ffixed-point %s -verify
-
-// Name namgling is not provided for fixed point types in c++
+// RUN: %clang_cc1 -x c++ %s -verify -DWITHOUT_FIXED_POINT
+// RUN: %clang_cc1 -x c++ %s -verify -ffixed-point
 
+#ifdef WITHOUT_FIXED_POINT
 _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}}
+#endif
 
 int accum_int = 10k;     // expected-error{{invalid suffix 'k' on integer constant}}
 int fract_int = 10r;     // expected-error{{invalid suffix 'r' on integer constant}}
-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}}
+#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


        


More information about the cfe-commits mailing list