@@ -181,14 +181,21 @@ static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty,
181
181
TI.isTypeSigned (Ty), Builder);
182
182
}
183
183
184
- static void DefineFmt (const Twine &Prefix, TargetInfo::IntType Ty ,
185
- const TargetInfo &TI, MacroBuilder &Builder) {
186
- bool IsSigned = TI. isTypeSigned (Ty);
184
+ static void DefineFmt (const LangOptions &LangOpts, const Twine &Prefix ,
185
+ TargetInfo::IntType Ty, const TargetInfo &TI,
186
+ MacroBuilder &Builder) {
187
187
StringRef FmtModifier = TI.getTypeFormatModifier (Ty);
188
- for (const char *Fmt = IsSigned ? " di" : " ouxX" ; *Fmt; ++Fmt) {
189
- Builder.defineMacro (Prefix + " _FMT" + Twine (*Fmt) + " __" ,
190
- Twine (" \" " ) + FmtModifier + Twine (*Fmt) + " \" " );
191
- }
188
+ auto Emitter = [&](char Fmt) {
189
+ Builder.defineMacro (Prefix + " _FMT" + Twine (Fmt) + " __" ,
190
+ Twine (" \" " ) + FmtModifier + Twine (Fmt) + " \" " );
191
+ };
192
+ bool IsSigned = TI.isTypeSigned (Ty);
193
+ llvm::for_each (StringRef (IsSigned ? " di" : " ouxX" ), Emitter);
194
+
195
+ // C23 added the b and B modifiers for printing binary output of unsigned
196
+ // integers. Conditionally define those if compiling in C23 mode.
197
+ if (LangOpts.C23 && !IsSigned)
198
+ llvm::for_each (StringRef (" bB" ), Emitter);
192
199
}
193
200
194
201
static void DefineType (const Twine &MacroName, TargetInfo::IntType Ty,
@@ -217,7 +224,8 @@ static void DefineTypeSizeAndWidth(const Twine &Prefix, TargetInfo::IntType Ty,
217
224
DefineTypeWidth (Prefix + " _WIDTH__" , Ty, TI, Builder);
218
225
}
219
226
220
- static void DefineExactWidthIntType (TargetInfo::IntType Ty,
227
+ static void DefineExactWidthIntType (const LangOptions &LangOpts,
228
+ TargetInfo::IntType Ty,
221
229
const TargetInfo &TI,
222
230
MacroBuilder &Builder) {
223
231
int TypeWidth = TI.getTypeWidth (Ty);
@@ -236,7 +244,7 @@ static void DefineExactWidthIntType(TargetInfo::IntType Ty,
236
244
const char *Prefix = IsSigned ? " __INT" : " __UINT" ;
237
245
238
246
DefineType (Prefix + Twine (TypeWidth) + " _TYPE__" , Ty, Builder);
239
- DefineFmt (Prefix + Twine (TypeWidth), Ty, TI, Builder);
247
+ DefineFmt (LangOpts, Prefix + Twine (TypeWidth), Ty, TI, Builder);
240
248
241
249
StringRef ConstSuffix (TI.getTypeConstantSuffix (Ty));
242
250
Builder.defineMacro (Prefix + Twine (TypeWidth) + " _C_SUFFIX__" , ConstSuffix);
@@ -259,7 +267,8 @@ static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty,
259
267
DefineTypeSize (Prefix + Twine (TypeWidth) + " _MAX__" , Ty, TI, Builder);
260
268
}
261
269
262
- static void DefineLeastWidthIntType (unsigned TypeWidth, bool IsSigned,
270
+ static void DefineLeastWidthIntType (const LangOptions &LangOpts,
271
+ unsigned TypeWidth, bool IsSigned,
263
272
const TargetInfo &TI,
264
273
MacroBuilder &Builder) {
265
274
TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth (TypeWidth, IsSigned);
@@ -274,11 +283,12 @@ static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned,
274
283
DefineTypeSizeAndWidth (Prefix + Twine (TypeWidth), Ty, TI, Builder);
275
284
else
276
285
DefineTypeSize (Prefix + Twine (TypeWidth) + " _MAX__" , Ty, TI, Builder);
277
- DefineFmt (Prefix + Twine (TypeWidth), Ty, TI, Builder);
286
+ DefineFmt (LangOpts, Prefix + Twine (TypeWidth), Ty, TI, Builder);
278
287
}
279
288
280
- static void DefineFastIntType (unsigned TypeWidth, bool IsSigned,
281
- const TargetInfo &TI, MacroBuilder &Builder) {
289
+ static void DefineFastIntType (const LangOptions &LangOpts, unsigned TypeWidth,
290
+ bool IsSigned, const TargetInfo &TI,
291
+ MacroBuilder &Builder) {
282
292
// stdint.h currently defines the fast int types as equivalent to the least
283
293
// types.
284
294
TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth (TypeWidth, IsSigned);
@@ -293,7 +303,7 @@ static void DefineFastIntType(unsigned TypeWidth, bool IsSigned,
293
303
DefineTypeSizeAndWidth (Prefix + Twine (TypeWidth), Ty, TI, Builder);
294
304
else
295
305
DefineTypeSize (Prefix + Twine (TypeWidth) + " _MAX__" , Ty, TI, Builder);
296
- DefineFmt (Prefix + Twine (TypeWidth), Ty, TI, Builder);
306
+ DefineFmt (LangOpts, Prefix + Twine (TypeWidth), Ty, TI, Builder);
297
307
}
298
308
299
309
@@ -1120,27 +1130,28 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1120
1130
DefineTypeSizeof (" __SIZEOF_INT128__" , 128 , TI, Builder);
1121
1131
1122
1132
DefineType (" __INTMAX_TYPE__" , TI.getIntMaxType (), Builder);
1123
- DefineFmt (" __INTMAX" , TI.getIntMaxType (), TI, Builder);
1133
+ DefineFmt (LangOpts, " __INTMAX" , TI.getIntMaxType (), TI, Builder);
1124
1134
Builder.defineMacro (" __INTMAX_C_SUFFIX__" ,
1125
1135
TI.getTypeConstantSuffix (TI.getIntMaxType ()));
1126
1136
DefineType (" __UINTMAX_TYPE__" , TI.getUIntMaxType (), Builder);
1127
- DefineFmt (" __UINTMAX" , TI.getUIntMaxType (), TI, Builder);
1137
+ DefineFmt (LangOpts, " __UINTMAX" , TI.getUIntMaxType (), TI, Builder);
1128
1138
Builder.defineMacro (" __UINTMAX_C_SUFFIX__" ,
1129
1139
TI.getTypeConstantSuffix (TI.getUIntMaxType ()));
1130
1140
DefineType (" __PTRDIFF_TYPE__" , TI.getPtrDiffType (LangAS::Default), Builder);
1131
- DefineFmt (" __PTRDIFF" , TI.getPtrDiffType (LangAS::Default), TI, Builder);
1141
+ DefineFmt (LangOpts, " __PTRDIFF" , TI.getPtrDiffType (LangAS::Default), TI,
1142
+ Builder);
1132
1143
DefineType (" __INTPTR_TYPE__" , TI.getIntPtrType (), Builder);
1133
- DefineFmt (" __INTPTR" , TI.getIntPtrType (), TI, Builder);
1144
+ DefineFmt (LangOpts, " __INTPTR" , TI.getIntPtrType (), TI, Builder);
1134
1145
DefineType (" __SIZE_TYPE__" , TI.getSizeType (), Builder);
1135
- DefineFmt (" __SIZE" , TI.getSizeType (), TI, Builder);
1146
+ DefineFmt (LangOpts, " __SIZE" , TI.getSizeType (), TI, Builder);
1136
1147
DefineType (" __WCHAR_TYPE__" , TI.getWCharType (), Builder);
1137
1148
DefineType (" __WINT_TYPE__" , TI.getWIntType (), Builder);
1138
1149
DefineTypeSizeAndWidth (" __SIG_ATOMIC" , TI.getSigAtomicType (), TI, Builder);
1139
1150
DefineType (" __CHAR16_TYPE__" , TI.getChar16Type (), Builder);
1140
1151
DefineType (" __CHAR32_TYPE__" , TI.getChar32Type (), Builder);
1141
1152
1142
1153
DefineType (" __UINTPTR_TYPE__" , TI.getUIntPtrType (), Builder);
1143
- DefineFmt (" __UINTPTR" , TI.getUIntPtrType (), TI, Builder);
1154
+ DefineFmt (LangOpts, " __UINTPTR" , TI.getUIntPtrType (), TI, Builder);
1144
1155
1145
1156
// The C standard requires the width of uintptr_t and intptr_t to be the same,
1146
1157
// per 7.20.2.4p1. Same for intmax_t and uintmax_t, per 7.20.2.5p1.
@@ -1216,65 +1227,66 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1216
1227
Builder.defineMacro (" __WINT_UNSIGNED__" );
1217
1228
1218
1229
// Define exact-width integer types for stdint.h
1219
- DefineExactWidthIntType (TargetInfo::SignedChar, TI, Builder);
1230
+ DefineExactWidthIntType (LangOpts, TargetInfo::SignedChar, TI, Builder);
1220
1231
1221
1232
if (TI.getShortWidth () > TI.getCharWidth ())
1222
- DefineExactWidthIntType (TargetInfo::SignedShort, TI, Builder);
1233
+ DefineExactWidthIntType (LangOpts, TargetInfo::SignedShort, TI, Builder);
1223
1234
1224
1235
if (TI.getIntWidth () > TI.getShortWidth ())
1225
- DefineExactWidthIntType (TargetInfo::SignedInt, TI, Builder);
1236
+ DefineExactWidthIntType (LangOpts, TargetInfo::SignedInt, TI, Builder);
1226
1237
1227
1238
if (TI.getLongWidth () > TI.getIntWidth ())
1228
- DefineExactWidthIntType (TargetInfo::SignedLong, TI, Builder);
1239
+ DefineExactWidthIntType (LangOpts, TargetInfo::SignedLong, TI, Builder);
1229
1240
1230
1241
if (TI.getLongLongWidth () > TI.getLongWidth ())
1231
- DefineExactWidthIntType (TargetInfo::SignedLongLong, TI, Builder);
1242
+ DefineExactWidthIntType (LangOpts, TargetInfo::SignedLongLong, TI, Builder);
1232
1243
1233
- DefineExactWidthIntType (TargetInfo::UnsignedChar, TI, Builder);
1244
+ DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedChar, TI, Builder);
1234
1245
DefineExactWidthIntTypeSize (TargetInfo::UnsignedChar, TI, Builder);
1235
1246
DefineExactWidthIntTypeSize (TargetInfo::SignedChar, TI, Builder);
1236
1247
1237
1248
if (TI.getShortWidth () > TI.getCharWidth ()) {
1238
- DefineExactWidthIntType (TargetInfo::UnsignedShort, TI, Builder);
1249
+ DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedShort, TI, Builder);
1239
1250
DefineExactWidthIntTypeSize (TargetInfo::UnsignedShort, TI, Builder);
1240
1251
DefineExactWidthIntTypeSize (TargetInfo::SignedShort, TI, Builder);
1241
1252
}
1242
1253
1243
1254
if (TI.getIntWidth () > TI.getShortWidth ()) {
1244
- DefineExactWidthIntType (TargetInfo::UnsignedInt, TI, Builder);
1255
+ DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedInt, TI, Builder);
1245
1256
DefineExactWidthIntTypeSize (TargetInfo::UnsignedInt, TI, Builder);
1246
1257
DefineExactWidthIntTypeSize (TargetInfo::SignedInt, TI, Builder);
1247
1258
}
1248
1259
1249
1260
if (TI.getLongWidth () > TI.getIntWidth ()) {
1250
- DefineExactWidthIntType (TargetInfo::UnsignedLong, TI, Builder);
1261
+ DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedLong, TI, Builder);
1251
1262
DefineExactWidthIntTypeSize (TargetInfo::UnsignedLong, TI, Builder);
1252
1263
DefineExactWidthIntTypeSize (TargetInfo::SignedLong, TI, Builder);
1253
1264
}
1254
1265
1255
1266
if (TI.getLongLongWidth () > TI.getLongWidth ()) {
1256
- DefineExactWidthIntType (TargetInfo::UnsignedLongLong, TI, Builder);
1267
+ DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedLongLong, TI,
1268
+ Builder);
1257
1269
DefineExactWidthIntTypeSize (TargetInfo::UnsignedLongLong, TI, Builder);
1258
1270
DefineExactWidthIntTypeSize (TargetInfo::SignedLongLong, TI, Builder);
1259
1271
}
1260
1272
1261
- DefineLeastWidthIntType (8 , true , TI, Builder);
1262
- DefineLeastWidthIntType (8 , false , TI, Builder);
1263
- DefineLeastWidthIntType (16 , true , TI, Builder);
1264
- DefineLeastWidthIntType (16 , false , TI, Builder);
1265
- DefineLeastWidthIntType (32 , true , TI, Builder);
1266
- DefineLeastWidthIntType (32 , false , TI, Builder);
1267
- DefineLeastWidthIntType (64 , true , TI, Builder);
1268
- DefineLeastWidthIntType (64 , false , TI, Builder);
1269
-
1270
- DefineFastIntType (8 , true , TI, Builder);
1271
- DefineFastIntType (8 , false , TI, Builder);
1272
- DefineFastIntType (16 , true , TI, Builder);
1273
- DefineFastIntType (16 , false , TI, Builder);
1274
- DefineFastIntType (32 , true , TI, Builder);
1275
- DefineFastIntType (32 , false , TI, Builder);
1276
- DefineFastIntType (64 , true , TI, Builder);
1277
- DefineFastIntType (64 , false , TI, Builder);
1273
+ DefineLeastWidthIntType (LangOpts, 8 , true , TI, Builder);
1274
+ DefineLeastWidthIntType (LangOpts, 8 , false , TI, Builder);
1275
+ DefineLeastWidthIntType (LangOpts, 16 , true , TI, Builder);
1276
+ DefineLeastWidthIntType (LangOpts, 16 , false , TI, Builder);
1277
+ DefineLeastWidthIntType (LangOpts, 32 , true , TI, Builder);
1278
+ DefineLeastWidthIntType (LangOpts, 32 , false , TI, Builder);
1279
+ DefineLeastWidthIntType (LangOpts, 64 , true , TI, Builder);
1280
+ DefineLeastWidthIntType (LangOpts, 64 , false , TI, Builder);
1281
+
1282
+ DefineFastIntType (LangOpts, 8 , true , TI, Builder);
1283
+ DefineFastIntType (LangOpts, 8 , false , TI, Builder);
1284
+ DefineFastIntType (LangOpts, 16 , true , TI, Builder);
1285
+ DefineFastIntType (LangOpts, 16 , false , TI, Builder);
1286
+ DefineFastIntType (LangOpts, 32 , true , TI, Builder);
1287
+ DefineFastIntType (LangOpts, 32 , false , TI, Builder);
1288
+ DefineFastIntType (LangOpts, 64 , true , TI, Builder);
1289
+ DefineFastIntType (LangOpts, 64 , false , TI, Builder);
1278
1290
1279
1291
Builder.defineMacro (" __USER_LABEL_PREFIX__" , TI.getUserLabelPrefix ());
1280
1292
0 commit comments