Skip to content

Commit d2fd110

Browse files
committed
Reapply "[clang] Support fixed point types in C++ (#67750)" (#69963)
This reverts commit d593f6c.
1 parent 2ccd79d commit d2fd110

File tree

7 files changed

+131
-10
lines changed

7 files changed

+131
-10
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,7 @@ defm fixed_point : BoolFOption<"fixed-point",
21172117
LangOpts<"FixedPoint">, DefaultFalse,
21182118
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Enable">,
21192119
NegFlag<SetFalse, [], [ClangOption], "Disable">,
2120-
BothFlags<[], [ClangOption], " fixed point types">>, ShouldParseIf<!strconcat("!", cplusplus.KeyPath)>;
2120+
BothFlags<[], [ClangOption], " fixed point types">>;
21212121
defm cxx_static_destructors : BoolFOption<"c++-static-destructors",
21222122
LangOpts<"RegisterStaticDestructors">, DefaultTrue,
21232123
NegFlag<SetFalse, [], [ClangOption, CC1Option],

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,12 +3051,21 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
30513051
// UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits)
30523052
// UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits)
30533053
// ::= Dh # IEEE 754r half-precision floating point (16 bits)
3054-
// ::= DF <number> _ # ISO/IEC TS 18661 binary floating point
3055-
// type _FloatN (N bits);
3054+
// ::= DF <number> _ # ISO/IEC TS 18661 binary floating point type _FloatN (N bits);
30563055
// ::= Di # char32_t
30573056
// ::= Ds # char16_t
30583057
// ::= Dn # std::nullptr_t (i.e., decltype(nullptr))
3058+
// ::= [DS] DA # N1169 fixed-point [_Sat] T _Accum
3059+
// ::= [DS] DR # N1169 fixed-point [_Sat] T _Fract
30593060
// ::= u <source-name> # vendor extended type
3061+
//
3062+
// <fixed-point-size>
3063+
// ::= s # short
3064+
// ::= t # unsigned short
3065+
// ::= i # plain
3066+
// ::= j # unsigned
3067+
// ::= l # long
3068+
// ::= m # unsigned long
30603069
std::string type_name;
30613070
// Normalize integer types as vendor extended types:
30623071
// u<length>i<type size>
@@ -3201,30 +3210,77 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
32013210
Out << "DF16_";
32023211
break;
32033212
case BuiltinType::ShortAccum:
3213+
Out << "DAs";
3214+
break;
32043215
case BuiltinType::Accum:
3216+
Out << "DAi";
3217+
break;
32053218
case BuiltinType::LongAccum:
3219+
Out << "DAl";
3220+
break;
32063221
case BuiltinType::UShortAccum:
3222+
Out << "DAt";
3223+
break;
32073224
case BuiltinType::UAccum:
3225+
Out << "DAj";
3226+
break;
32083227
case BuiltinType::ULongAccum:
3228+
Out << "DAm";
3229+
break;
32093230
case BuiltinType::ShortFract:
3231+
Out << "DRs";
3232+
break;
32103233
case BuiltinType::Fract:
3234+
Out << "DRi";
3235+
break;
32113236
case BuiltinType::LongFract:
3237+
Out << "DRl";
3238+
break;
32123239
case BuiltinType::UShortFract:
3240+
Out << "DRt";
3241+
break;
32133242
case BuiltinType::UFract:
3243+
Out << "DRj";
3244+
break;
32143245
case BuiltinType::ULongFract:
3246+
Out << "DRm";
3247+
break;
32153248
case BuiltinType::SatShortAccum:
3249+
Out << "DSDAs";
3250+
break;
32163251
case BuiltinType::SatAccum:
3252+
Out << "DSDAi";
3253+
break;
32173254
case BuiltinType::SatLongAccum:
3255+
Out << "DSDAl";
3256+
break;
32183257
case BuiltinType::SatUShortAccum:
3258+
Out << "DSDAt";
3259+
break;
32193260
case BuiltinType::SatUAccum:
3261+
Out << "DSDAj";
3262+
break;
32203263
case BuiltinType::SatULongAccum:
3264+
Out << "DSDAm";
3265+
break;
32213266
case BuiltinType::SatShortFract:
3267+
Out << "DSDRs";
3268+
break;
32223269
case BuiltinType::SatFract:
3270+
Out << "DSDRi";
3271+
break;
32233272
case BuiltinType::SatLongFract:
3273+
Out << "DSDRl";
3274+
break;
32243275
case BuiltinType::SatUShortFract:
3276+
Out << "DSDRt";
3277+
break;
32253278
case BuiltinType::SatUFract:
3279+
Out << "DSDRj";
3280+
break;
32263281
case BuiltinType::SatULongFract:
3227-
llvm_unreachable("Fixed point types are disabled for c++");
3282+
Out << "DSDRm";
3283+
break;
32283284
case BuiltinType::Half:
32293285
Out << "Dh";
32303286
break;

clang/lib/Parse/ParseExpr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,9 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
15771577
case tok::kw_typename:
15781578
case tok::kw_typeof:
15791579
case tok::kw___vector:
1580+
case tok::kw__Accum:
1581+
case tok::kw__Fract:
1582+
case tok::kw__Sat:
15801583
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
15811584
#include "clang/Basic/OpenCLImageTypes.def"
15821585
{

clang/lib/Parse/ParseExprCXX.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,15 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
23542354
case tok::kw_bool:
23552355
DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID, Policy);
23562356
break;
2357+
case tok::kw__Accum:
2358+
DS.SetTypeSpecType(DeclSpec::TST_accum, Loc, PrevSpec, DiagID, Policy);
2359+
break;
2360+
case tok::kw__Fract:
2361+
DS.SetTypeSpecType(DeclSpec::TST_fract, Loc, PrevSpec, DiagID, Policy);
2362+
break;
2363+
case tok::kw__Sat:
2364+
DS.SetTypeSpecSat(Loc, PrevSpec, DiagID);
2365+
break;
23572366
#define GENERIC_IMAGE_TYPE(ImgType, Id) \
23582367
case tok::kw_##ImgType##_t: \
23592368
DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \

clang/lib/Parse/ParseTentative.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,9 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
17751775
case tok::kw___ibm128:
17761776
case tok::kw_void:
17771777
case tok::annot_decltype:
1778+
case tok::kw__Accum:
1779+
case tok::kw__Fract:
1780+
case tok::kw__Sat:
17781781
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
17791782
#include "clang/Basic/OpenCLImageTypes.def"
17801783
if (NextToken().is(tok::l_paren))
@@ -1894,6 +1897,9 @@ bool Parser::isCXXDeclarationSpecifierAType() {
18941897
case tok::kw_void:
18951898
case tok::kw___unknown_anytype:
18961899
case tok::kw___auto_type:
1900+
case tok::kw__Accum:
1901+
case tok::kw__Fract:
1902+
case tok::kw__Sat:
18971903
#define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t:
18981904
#include "clang/Basic/OpenCLImageTypes.def"
18991905
return true;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - -triple=x86_64-unknown-linux-gnu | FileCheck %s
2+
3+
// Primary fixed point types
4+
void func(signed short _Accum){} // CHECK: @_Z4funcDAs
5+
void func(signed _Accum){} // CHECK: @_Z4funcDAi
6+
void func(signed long _Accum){} // CHECK: @_Z4funcDAl
7+
void func(unsigned short _Accum){} // CHECK: @_Z4funcDAt
8+
void func(unsigned _Accum){} // CHECK: @_Z4funcDAj
9+
void func(unsigned long _Accum){} // CHECK: @_Z4funcDAm
10+
void func(signed short _Fract){} // CHECK: @_Z4funcDRs
11+
void func(signed _Fract){} // CHECK: @_Z4funcDRi
12+
void func(signed long _Fract){} // CHECK: @_Z4funcDRl
13+
void func(unsigned short _Fract){} // CHECK: @_Z4funcDRt
14+
void func(unsigned _Fract){} // CHECK: @_Z4funcDRj
15+
void func(unsigned long _Fract){} // CHECK: @_Z4funcDRm
16+
17+
// Aliased
18+
void func2(short _Accum){} // CHECK: @_Z5func2DAs
19+
void func2(_Accum){} // CHECK: @_Z5func2DAi
20+
void func2(long _Accum){} // CHECK: @_Z5func2DAl
21+
void func2(short _Fract){} // CHECK: @_Z5func2DRs
22+
void func2(_Fract){} // CHECK: @_Z5func2DRi
23+
void func2(long _Fract){} // CHECK: @_Z5func2DRl
24+
25+
// Primary saturated
26+
void func(_Sat signed short _Accum){} // CHECK: @_Z4funcDSDAs
27+
void func(_Sat signed _Accum){} // CHECK: @_Z4funcDSDAi
28+
void func(_Sat signed long _Accum){} // CHECK: @_Z4funcDSDAl
29+
void func(_Sat unsigned short _Accum){} // CHECK: @_Z4funcDSDAt
30+
void func(_Sat unsigned _Accum){} // CHECK: @_Z4funcDSDAj
31+
void func(_Sat unsigned long _Accum){} // CHECK: @_Z4funcDSDAm
32+
void func(_Sat signed short _Fract){} // CHECK: @_Z4funcDSDRs
33+
void func(_Sat signed _Fract){} // CHECK: @_Z4funcDSDRi
34+
void func(_Sat signed long _Fract){} // CHECK: @_Z4funcDSDRl
35+
void func(_Sat unsigned short _Fract){} // CHECK: @_Z4funcDSDRt
36+
void func(_Sat unsigned _Fract){} // CHECK: @_Z4funcDSDRj
37+
void func(_Sat unsigned long _Fract){} // CHECK: @_Z4funcDSDRm
38+
39+
// Aliased saturated
40+
void func2(_Sat short _Accum){} // CHECK: @_Z5func2DSDAs
41+
void func2(_Sat _Accum){} // CHECK: @_Z5func2DSDAi
42+
void func2(_Sat long _Accum){} // CHECK: @_Z5func2DSDAl
43+
void func2(_Sat short _Fract){} // CHECK: @_Z5func2DSDRs
44+
void func2(_Sat _Fract){} // CHECK: @_Z5func2DSDRi
45+
void func2(_Sat long _Fract){} // CHECK: @_Z5func2DSDRl
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
// RUN: %clang_cc1 -x c++ %s -verify
2-
// RUN: %clang_cc1 -x c++ -ffixed-point %s -verify
3-
4-
// Name namgling is not provided for fixed point types in c++
1+
// RUN: %clang_cc1 -x c++ %s -verify -DWITHOUT_FIXED_POINT
2+
// RUN: %clang_cc1 -x c++ %s -verify -ffixed-point
53

4+
#ifdef WITHOUT_FIXED_POINT
65
_Accum accum; // expected-error{{unknown type name '_Accum'}}
76
_Fract fract; // expected-error{{unknown type name '_Fract'}}
87
_Sat _Accum sat_accum; // expected-error{{unknown type name '_Sat'}}
98
// expected-error@-1{{expected ';' after top level declarator}}
9+
#endif
1010

1111
int accum_int = 10k; // expected-error{{invalid suffix 'k' on integer constant}}
1212
int fract_int = 10r; // expected-error{{invalid suffix 'r' on integer constant}}
13-
float accum_flt = 10.0k; // expected-error{{invalid suffix 'k' on floating constant}}
14-
float fract_flt = 10.0r; // expected-error{{invalid suffix 'r' on floating constant}}
13+
#ifdef WITHOUT_FIXED_POINT
14+
float accum_flt = 0.0k; // expected-error{{invalid suffix 'k' on floating constant}}
15+
float fract_flt = 0.0r; // expected-error{{invalid suffix 'r' on floating constant}}
16+
#endif

0 commit comments

Comments
 (0)