Skip to content

Commit 707f162

Browse files
committed
[clang][DFP] Add basic builtin type representation for decimal floating point types.
This change adds basic type representation support for the decimal floating point types defined by ISO/IEC TS 18661-2 and adopted for C23. These types will also serve as the underlying native types for the library types defined by ISO/IEC TR 24733 and as implemented in libstdcxx. This change does not include representation support in LLVM IR, in debugging information, or in C++ mangling for the MS ABI; such support will be added in later patches.
1 parent 32db121 commit 707f162

File tree

23 files changed

+168
-3
lines changed

23 files changed

+168
-3
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
10981098
CanQualType SatShortFractTy, SatFractTy, SatLongFractTy;
10991099
CanQualType SatUnsignedShortFractTy, SatUnsignedFractTy,
11001100
SatUnsignedLongFractTy;
1101+
// ISO/IEC TS 18661-2, ISO/IEC TR 24733, and C23 decimal floating-point.
1102+
CanQualType DecimalFloat32Ty, DecimalFloat64Ty, DecimalFloat128Ty;
11011103
CanQualType HalfTy; // [OpenCL 6.1.1.1], ARM NEON
11021104
CanQualType BFloat16Ty;
11031105
CanQualType Float16Ty; // C11 extension ISO/IEC TS 18661-3

clang/include/clang/AST/BuiltinTypes.def

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
#define FLOATING_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId)
4545
#endif
4646

47+
#ifndef DECIMAL_FLOATING_TYPE
48+
#define DECIMAL_FLOATING_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId)
49+
#endif
50+
4751
#ifndef PLACEHOLDER_TYPE
4852
#define PLACEHOLDER_TYPE(Id, SingletonId) BUILTIN_TYPE(Id, SingletonId)
4953
#endif
@@ -221,6 +225,18 @@ FLOATING_TYPE(Float128, Float128Ty)
221225
// '__ibm128'
222226
FLOATING_TYPE(Ibm128, Ibm128Ty)
223227

228+
//===- Decimal floating point types ---------------------------------------===//
229+
// ISO/IEC TS 18661-2, ISO/IEC TR 24733, and C23 decimal floating-point.
230+
231+
// '_Decimal32'
232+
DECIMAL_FLOATING_TYPE(DecimalFloat32, DecimalFloat32Ty)
233+
234+
// '_Decimal64'
235+
DECIMAL_FLOATING_TYPE(DecimalFloat64, DecimalFloat64Ty)
236+
237+
// '_Decimal128'
238+
DECIMAL_FLOATING_TYPE(DecimalFloat128, DecimalFloat128Ty)
239+
224240
//===- Language-specific types --------------------------------------------===//
225241

226242
// This is the type of C++0x 'nullptr'.
@@ -336,6 +352,7 @@ LAST_BUILTIN_TYPE(OMPIterator)
336352
#undef SHARED_SINGLETON_TYPE
337353
#undef PLACEHOLDER_TYPE
338354
#undef FLOATING_TYPE
355+
#undef DECIMAL_FLOATING_TYPE
339356
#undef SIGNED_TYPE
340357
#undef UNSIGNED_TYPE
341358
#undef BUILTIN_TYPE

clang/include/clang/Basic/TargetInfo.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ struct TransferrableTargetInfo {
9595
unsigned char LongLongWidth, LongLongAlign;
9696
unsigned char Int128Align;
9797

98+
// Decimal floating-point bit widths and alignment.
99+
unsigned char DecimalFloat32Width, DecimalFloat32Align;
100+
unsigned char DecimalFloat64Width, DecimalFloat64Align;
101+
unsigned char DecimalFloat128Width, DecimalFloat128Align;
102+
98103
// Fixed point bit widths
99104
unsigned char ShortAccumWidth, ShortAccumAlign;
100105
unsigned char AccumWidth, AccumAlign;
@@ -500,6 +505,18 @@ class TargetInfo : public TransferrableTargetInfo,
500505
/// getInt128Align() - Returns the alignment of Int128.
501506
unsigned getInt128Align() const { return Int128Align; }
502507

508+
/// DecimalFloat32Width/Align - Return the size/align of '_Decimal32'.
509+
unsigned getDecimalFloat32Width() const { return DecimalFloat32Width; }
510+
unsigned getDecimalFloat32Align() const { return DecimalFloat32Align; }
511+
512+
/// DecimalFloat64Width/Align - Return the size/align of '_Decimal64'.
513+
unsigned getDecimalFloat64Width() const { return DecimalFloat64Width; }
514+
unsigned getDecimalFloat64Align() const { return DecimalFloat64Align; }
515+
516+
/// DecimalFloat128Width/Align - Return the size/align of '_Decimal128'.
517+
unsigned getDecimalFloat128Width() const { return DecimalFloat128Width; }
518+
unsigned getDecimalFloat128Align() const { return DecimalFloat128Align; }
519+
503520
/// getShortAccumWidth/Align - Return the size of 'signed short _Accum' and
504521
/// 'unsigned short _Accum' for this target, in bits.
505522
unsigned getShortAccumWidth() const { return ShortAccumWidth; }

clang/include/clang/Basic/TokenKinds.def

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,12 @@ KEYWORD(_Accum , KEYNOCXX)
427427
KEYWORD(_Fract , KEYNOCXX)
428428
KEYWORD(_Sat , KEYNOCXX)
429429

430-
// GNU Extensions (in impl-reserved namespace)
430+
// ISO/IEC TS 18661-2, ISO/IEC TR 24733, and C23 decimal floating-point.
431431
KEYWORD(_Decimal32 , KEYALL)
432432
KEYWORD(_Decimal64 , KEYALL)
433433
KEYWORD(_Decimal128 , KEYALL)
434+
435+
// GNU Extensions (in impl-reserved namespace)
434436
KEYWORD(__null , KEYCXX)
435437
// __alignof returns the preferred alignment of a type, the alignment
436438
// clang will attempt to give an object of the type if allowed by ABI.

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,15 @@ enum PredefinedTypeIDs {
10791079
/// \brief The '__ibm128' type
10801080
PREDEF_TYPE_IBM128_ID = 74,
10811081

1082+
/// \brief The '_Decimal32' type
1083+
PREDEF_TYPE_DECIMAL32_ID = 75,
1084+
1085+
/// \brief The '_Decimal64' type
1086+
PREDEF_TYPE_DECIMAL64_ID = 76,
1087+
1088+
/// \brief The '_Decimal128' type
1089+
PREDEF_TYPE_DECIMAL128_ID = 77,
1090+
10821091
/// OpenCL image types with auto numeration
10831092
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
10841093
PREDEF_TYPE_##Id##_ID,

clang/lib/AST/ASTContext.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,11 @@ void ASTContext::InitBuiltinTypes(const TargetInfo &Target,
13111311
InitBuiltinType(SatUnsignedFractTy, BuiltinType::SatUFract);
13121312
InitBuiltinType(SatUnsignedLongFractTy, BuiltinType::SatULongFract);
13131313

1314+
// ISO/IEC TS 18661-2, ISO/IEC TR 24733, and C23 decimal floating-point.
1315+
InitBuiltinType(DecimalFloat32Ty, BuiltinType::DecimalFloat32);
1316+
InitBuiltinType(DecimalFloat64Ty, BuiltinType::DecimalFloat64);
1317+
InitBuiltinType(DecimalFloat128Ty, BuiltinType::DecimalFloat128);
1318+
13141319
// GNU extension, 128-bit integers.
13151320
InitBuiltinType(Int128Ty, BuiltinType::Int128);
13161321
InitBuiltinType(UnsignedInt128Ty, BuiltinType::UInt128);
@@ -2114,6 +2119,18 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
21142119
Width = Target->getLongFractWidth();
21152120
Align = Target->getLongFractAlign();
21162121
break;
2122+
case BuiltinType::DecimalFloat32:
2123+
Width = Target->getDecimalFloat32Width();
2124+
Align = Target->getDecimalFloat32Align();
2125+
break;
2126+
case BuiltinType::DecimalFloat64:
2127+
Width = Target->getDecimalFloat64Width();
2128+
Align = Target->getDecimalFloat64Align();
2129+
break;
2130+
case BuiltinType::DecimalFloat128:
2131+
Width = Target->getDecimalFloat128Width();
2132+
Align = Target->getDecimalFloat128Align();
2133+
break;
21172134
case BuiltinType::BFloat16:
21182135
if (Target->hasBFloat16Type()) {
21192136
Width = Target->getBFloat16Width();
@@ -8066,6 +8083,9 @@ static char getObjCEncodingForPrimitiveType(const ASTContext *C,
80668083
case BuiltinType::SatUShortFract:
80678084
case BuiltinType::SatUFract:
80688085
case BuiltinType::SatULongFract:
8086+
case BuiltinType::DecimalFloat32:
8087+
case BuiltinType::DecimalFloat64:
8088+
case BuiltinType::DecimalFloat128:
80698089
// FIXME: potentially need @encodes for these!
80708090
return ' ';
80718091

clang/lib/AST/ExprConstant.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11416,6 +11416,8 @@ EvaluateBuiltinClassifyType(QualType T, const LangOptions &LangOpts) {
1141611416
case BuiltinType::ID: return GCCTypeClass::Integer;
1141711417
#define FLOATING_TYPE(ID, SINGLETON_ID) \
1141811418
case BuiltinType::ID: return GCCTypeClass::RealFloat;
11419+
#define DECIMAL_FLOATING_TYPE(ID, SINGLETON_ID) \
11420+
case BuiltinType::ID: return GCCTypeClass::RealFloat;
1141911421
#define PLACEHOLDER_TYPE(ID, SINGLETON_ID) \
1142011422
case BuiltinType::ID: break;
1142111423
#include "clang/AST/BuiltinTypes.def"

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,15 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
31653165
case BuiltinType::NullPtr:
31663166
Out << "Dn";
31673167
break;
3168+
case BuiltinType::DecimalFloat32:
3169+
Out << "Df";
3170+
break;
3171+
case BuiltinType::DecimalFloat64:
3172+
Out << "Dd";
3173+
break;
3174+
case BuiltinType::DecimalFloat128:
3175+
Out << "De";
3176+
break;
31683177

31693178
#define BUILTIN_TYPE(Id, SingletonId)
31703179
#define PLACEHOLDER_TYPE(Id, SingletonId) \

clang/lib/AST/MicrosoftMangle.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,9 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
24082408
// ::= _U # char32_t
24092409
// ::= _W # wchar_t
24102410
// ::= _Z # __float80 (Digital Mars)
2411+
// ::= FIXME # _Decimal32
2412+
// ::= FIXME # _Decimal64
2413+
// ::= FIXME # _Decimal128
24112414
switch (T->getKind()) {
24122415
case BuiltinType::Void:
24132416
Out << 'X';
@@ -2588,6 +2591,9 @@ void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
25882591
case BuiltinType::SatUFract:
25892592
case BuiltinType::SatULongFract:
25902593
case BuiltinType::Ibm128:
2594+
case BuiltinType::DecimalFloat32:
2595+
case BuiltinType::DecimalFloat64:
2596+
case BuiltinType::DecimalFloat128:
25912597
case BuiltinType::Float128: {
25922598
DiagnosticsEngine &Diags = Context.getDiags();
25932599
unsigned DiagID = Diags.getCustomDiagID(

clang/lib/AST/NSAPI.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ NSAPI::getNSNumberFactoryMethodKind(QualType T) const {
458458
case BuiltinType::Float16:
459459
case BuiltinType::Float128:
460460
case BuiltinType::Ibm128:
461+
case BuiltinType::DecimalFloat32:
462+
case BuiltinType::DecimalFloat64:
463+
case BuiltinType::DecimalFloat128:
461464
case BuiltinType::NullPtr:
462465
case BuiltinType::ObjCClass:
463466
case BuiltinType::ObjCId:

0 commit comments

Comments
 (0)