@@ -181,21 +181,14 @@ static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty,
181181 TI.isTypeSigned (Ty), Builder);
182182}
183183
184- static void DefineFmt (const LangOptions &LangOpts, const Twine &Prefix,
185- TargetInfo::IntType Ty, const TargetInfo &TI,
186- MacroBuilder &Builder) {
187- StringRef FmtModifier = TI.getTypeFormatModifier (Ty);
188- auto Emitter = [&](char Fmt) {
189- Builder.defineMacro (Prefix + " _FMT" + Twine (Fmt) + " __" ,
190- Twine (" \" " ) + FmtModifier + Twine (Fmt) + " \" " );
191- };
184+ static void DefineFmt (const Twine &Prefix, TargetInfo::IntType Ty,
185+ const TargetInfo &TI, MacroBuilder &Builder) {
192186 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);
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+ }
199192}
200193
201194static void DefineType (const Twine &MacroName, TargetInfo::IntType Ty,
@@ -224,8 +217,7 @@ static void DefineTypeSizeAndWidth(const Twine &Prefix, TargetInfo::IntType Ty,
224217 DefineTypeWidth (Prefix + " _WIDTH__" , Ty, TI, Builder);
225218}
226219
227- static void DefineExactWidthIntType (const LangOptions &LangOpts,
228- TargetInfo::IntType Ty,
220+ static void DefineExactWidthIntType (TargetInfo::IntType Ty,
229221 const TargetInfo &TI,
230222 MacroBuilder &Builder) {
231223 int TypeWidth = TI.getTypeWidth (Ty);
@@ -244,7 +236,7 @@ static void DefineExactWidthIntType(const LangOptions &LangOpts,
244236 const char *Prefix = IsSigned ? " __INT" : " __UINT" ;
245237
246238 DefineType (Prefix + Twine (TypeWidth) + " _TYPE__" , Ty, Builder);
247- DefineFmt (LangOpts, Prefix + Twine (TypeWidth), Ty, TI, Builder);
239+ DefineFmt (Prefix + Twine (TypeWidth), Ty, TI, Builder);
248240
249241 StringRef ConstSuffix (TI.getTypeConstantSuffix (Ty));
250242 Builder.defineMacro (Prefix + Twine (TypeWidth) + " _C_SUFFIX__" , ConstSuffix);
@@ -267,8 +259,7 @@ static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty,
267259 DefineTypeSize (Prefix + Twine (TypeWidth) + " _MAX__" , Ty, TI, Builder);
268260}
269261
270- static void DefineLeastWidthIntType (const LangOptions &LangOpts,
271- unsigned TypeWidth, bool IsSigned,
262+ static void DefineLeastWidthIntType (unsigned TypeWidth, bool IsSigned,
272263 const TargetInfo &TI,
273264 MacroBuilder &Builder) {
274265 TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth (TypeWidth, IsSigned);
@@ -283,12 +274,11 @@ static void DefineLeastWidthIntType(const LangOptions &LangOpts,
283274 DefineTypeSizeAndWidth (Prefix + Twine (TypeWidth), Ty, TI, Builder);
284275 else
285276 DefineTypeSize (Prefix + Twine (TypeWidth) + " _MAX__" , Ty, TI, Builder);
286- DefineFmt (LangOpts, Prefix + Twine (TypeWidth), Ty, TI, Builder);
277+ DefineFmt (Prefix + Twine (TypeWidth), Ty, TI, Builder);
287278}
288279
289- static void DefineFastIntType (const LangOptions &LangOpts, unsigned TypeWidth,
290- bool IsSigned, const TargetInfo &TI,
291- MacroBuilder &Builder) {
280+ static void DefineFastIntType (unsigned TypeWidth, bool IsSigned,
281+ const TargetInfo &TI, MacroBuilder &Builder) {
292282 // stdint.h currently defines the fast int types as equivalent to the least
293283 // types.
294284 TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth (TypeWidth, IsSigned);
@@ -303,7 +293,7 @@ static void DefineFastIntType(const LangOptions &LangOpts, unsigned TypeWidth,
303293 DefineTypeSizeAndWidth (Prefix + Twine (TypeWidth), Ty, TI, Builder);
304294 else
305295 DefineTypeSize (Prefix + Twine (TypeWidth) + " _MAX__" , Ty, TI, Builder);
306- DefineFmt (LangOpts, Prefix + Twine (TypeWidth), Ty, TI, Builder);
296+ DefineFmt (Prefix + Twine (TypeWidth), Ty, TI, Builder);
307297}
308298
309299
@@ -1130,28 +1120,27 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
11301120 DefineTypeSizeof (" __SIZEOF_INT128__" , 128 , TI, Builder);
11311121
11321122 DefineType (" __INTMAX_TYPE__" , TI.getIntMaxType (), Builder);
1133- DefineFmt (LangOpts, " __INTMAX" , TI.getIntMaxType (), TI, Builder);
1123+ DefineFmt (" __INTMAX" , TI.getIntMaxType (), TI, Builder);
11341124 Builder.defineMacro (" __INTMAX_C_SUFFIX__" ,
11351125 TI.getTypeConstantSuffix (TI.getIntMaxType ()));
11361126 DefineType (" __UINTMAX_TYPE__" , TI.getUIntMaxType (), Builder);
1137- DefineFmt (LangOpts, " __UINTMAX" , TI.getUIntMaxType (), TI, Builder);
1127+ DefineFmt (" __UINTMAX" , TI.getUIntMaxType (), TI, Builder);
11381128 Builder.defineMacro (" __UINTMAX_C_SUFFIX__" ,
11391129 TI.getTypeConstantSuffix (TI.getUIntMaxType ()));
11401130 DefineType (" __PTRDIFF_TYPE__" , TI.getPtrDiffType (LangAS::Default), Builder);
1141- DefineFmt (LangOpts, " __PTRDIFF" , TI.getPtrDiffType (LangAS::Default), TI,
1142- Builder);
1131+ DefineFmt (" __PTRDIFF" , TI.getPtrDiffType (LangAS::Default), TI, Builder);
11431132 DefineType (" __INTPTR_TYPE__" , TI.getIntPtrType (), Builder);
1144- DefineFmt (LangOpts, " __INTPTR" , TI.getIntPtrType (), TI, Builder);
1133+ DefineFmt (" __INTPTR" , TI.getIntPtrType (), TI, Builder);
11451134 DefineType (" __SIZE_TYPE__" , TI.getSizeType (), Builder);
1146- DefineFmt (LangOpts, " __SIZE" , TI.getSizeType (), TI, Builder);
1135+ DefineFmt (" __SIZE" , TI.getSizeType (), TI, Builder);
11471136 DefineType (" __WCHAR_TYPE__" , TI.getWCharType (), Builder);
11481137 DefineType (" __WINT_TYPE__" , TI.getWIntType (), Builder);
11491138 DefineTypeSizeAndWidth (" __SIG_ATOMIC" , TI.getSigAtomicType (), TI, Builder);
11501139 DefineType (" __CHAR16_TYPE__" , TI.getChar16Type (), Builder);
11511140 DefineType (" __CHAR32_TYPE__" , TI.getChar32Type (), Builder);
11521141
11531142 DefineType (" __UINTPTR_TYPE__" , TI.getUIntPtrType (), Builder);
1154- DefineFmt (LangOpts, " __UINTPTR" , TI.getUIntPtrType (), TI, Builder);
1143+ DefineFmt (" __UINTPTR" , TI.getUIntPtrType (), TI, Builder);
11551144
11561145 // The C standard requires the width of uintptr_t and intptr_t to be the same,
11571146 // per 7.20.2.4p1. Same for intmax_t and uintmax_t, per 7.20.2.5p1.
@@ -1227,66 +1216,65 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
12271216 Builder.defineMacro (" __WINT_UNSIGNED__" );
12281217
12291218 // Define exact-width integer types for stdint.h
1230- DefineExactWidthIntType (LangOpts, TargetInfo::SignedChar, TI, Builder);
1219+ DefineExactWidthIntType (TargetInfo::SignedChar, TI, Builder);
12311220
12321221 if (TI.getShortWidth () > TI.getCharWidth ())
1233- DefineExactWidthIntType (LangOpts, TargetInfo::SignedShort, TI, Builder);
1222+ DefineExactWidthIntType (TargetInfo::SignedShort, TI, Builder);
12341223
12351224 if (TI.getIntWidth () > TI.getShortWidth ())
1236- DefineExactWidthIntType (LangOpts, TargetInfo::SignedInt, TI, Builder);
1225+ DefineExactWidthIntType (TargetInfo::SignedInt, TI, Builder);
12371226
12381227 if (TI.getLongWidth () > TI.getIntWidth ())
1239- DefineExactWidthIntType (LangOpts, TargetInfo::SignedLong, TI, Builder);
1228+ DefineExactWidthIntType (TargetInfo::SignedLong, TI, Builder);
12401229
12411230 if (TI.getLongLongWidth () > TI.getLongWidth ())
1242- DefineExactWidthIntType (LangOpts, TargetInfo::SignedLongLong, TI, Builder);
1231+ DefineExactWidthIntType (TargetInfo::SignedLongLong, TI, Builder);
12431232
1244- DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedChar, TI, Builder);
1233+ DefineExactWidthIntType (TargetInfo::UnsignedChar, TI, Builder);
12451234 DefineExactWidthIntTypeSize (TargetInfo::UnsignedChar, TI, Builder);
12461235 DefineExactWidthIntTypeSize (TargetInfo::SignedChar, TI, Builder);
12471236
12481237 if (TI.getShortWidth () > TI.getCharWidth ()) {
1249- DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedShort, TI, Builder);
1238+ DefineExactWidthIntType (TargetInfo::UnsignedShort, TI, Builder);
12501239 DefineExactWidthIntTypeSize (TargetInfo::UnsignedShort, TI, Builder);
12511240 DefineExactWidthIntTypeSize (TargetInfo::SignedShort, TI, Builder);
12521241 }
12531242
12541243 if (TI.getIntWidth () > TI.getShortWidth ()) {
1255- DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedInt, TI, Builder);
1244+ DefineExactWidthIntType (TargetInfo::UnsignedInt, TI, Builder);
12561245 DefineExactWidthIntTypeSize (TargetInfo::UnsignedInt, TI, Builder);
12571246 DefineExactWidthIntTypeSize (TargetInfo::SignedInt, TI, Builder);
12581247 }
12591248
12601249 if (TI.getLongWidth () > TI.getIntWidth ()) {
1261- DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedLong, TI, Builder);
1250+ DefineExactWidthIntType (TargetInfo::UnsignedLong, TI, Builder);
12621251 DefineExactWidthIntTypeSize (TargetInfo::UnsignedLong, TI, Builder);
12631252 DefineExactWidthIntTypeSize (TargetInfo::SignedLong, TI, Builder);
12641253 }
12651254
12661255 if (TI.getLongLongWidth () > TI.getLongWidth ()) {
1267- DefineExactWidthIntType (LangOpts, TargetInfo::UnsignedLongLong, TI,
1268- Builder);
1256+ DefineExactWidthIntType (TargetInfo::UnsignedLongLong, TI, Builder);
12691257 DefineExactWidthIntTypeSize (TargetInfo::UnsignedLongLong, TI, Builder);
12701258 DefineExactWidthIntTypeSize (TargetInfo::SignedLongLong, TI, Builder);
12711259 }
12721260
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);
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);
12901278
12911279 Builder.defineMacro (" __USER_LABEL_PREFIX__" , TI.getUserLabelPrefix ());
12921280
0 commit comments