@@ -47,7 +47,8 @@ static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro,
47
47
// Per GCC -D semantics, the macro ends at \n if it exists.
48
48
StringRef::size_type End = MacroBody.find_first_of (" \n\r " );
49
49
if (End != StringRef::npos)
50
- Diags.Report (diag::warn_fe_macro_contains_embedded_newline) << MacroName;
50
+ Diags.Report (diag::warn_fe_macro_contains_embedded_newline)
51
+ << MacroName;
51
52
MacroBody = MacroBody.substr (0 , End);
52
53
// We handle macro bodies which end in a backslash by appending an extra
53
54
// backslash+newline. This makes sure we don't accidentally treat the
@@ -96,17 +97,17 @@ template <typename T>
96
97
static T PickFP (const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal,
97
98
T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
98
99
T IEEEQuadVal) {
99
- if (Sem == (const llvm::fltSemantics *)&llvm::APFloat::IEEEhalf ())
100
+ if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf ())
100
101
return IEEEHalfVal;
101
- if (Sem == (const llvm::fltSemantics *)&llvm::APFloat::IEEEsingle ())
102
+ if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle ())
102
103
return IEEESingleVal;
103
- if (Sem == (const llvm::fltSemantics *)&llvm::APFloat::IEEEdouble ())
104
+ if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble ())
104
105
return IEEEDoubleVal;
105
- if (Sem == (const llvm::fltSemantics *)&llvm::APFloat::x87DoubleExtended ())
106
+ if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended ())
106
107
return X87DoubleExtendedVal;
107
- if (Sem == (const llvm::fltSemantics *)&llvm::APFloat::PPCDoubleDouble ())
108
+ if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble ())
108
109
return PPCDoubleDoubleVal;
109
- assert (Sem == (const llvm::fltSemantics *)&llvm::APFloat::IEEEquad ());
110
+ assert (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad ());
110
111
return IEEEQuadVal;
111
112
}
112
113
@@ -132,8 +133,8 @@ static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
132
133
int Max10Exp = PickFP (Sem, 4 , 38 , 308 , 4932 , 308 , 4932 );
133
134
int MinExp = PickFP (Sem, -13 , -125 , -1021 , -16381 , -968 , -16381 );
134
135
int MaxExp = PickFP (Sem, 16 , 128 , 1024 , 16384 , 1024 , 16384 );
135
- Min = PickFP (Sem, " 6.103515625e-5" , " 1.17549435e-38" ,
136
- " 2.2250738585072014e-308 " , " 3.36210314311209350626e-4932" ,
136
+ Min = PickFP (Sem, " 6.103515625e-5" , " 1.17549435e-38" , " 2.2250738585072014e-308 " ,
137
+ " 3.36210314311209350626e-4932" ,
137
138
" 2.00416836000897277799610805135016e-292" ,
138
139
" 3.36210314311209350626267781732175260e-4932" );
139
140
Max = PickFP (Sem, " 6.5504e+4" , " 3.40282347e+38" , " 1.7976931348623157e+308" ,
@@ -146,25 +147,26 @@ static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
146
147
DefPrefix += Prefix;
147
148
DefPrefix += " _" ;
148
149
149
- Builder.defineMacro (DefPrefix + " DENORM_MIN__" , Twine (DenormMin) + Ext);
150
- Builder.defineMacro (DefPrefix + " NORM_MAX__" , Twine (NormMax) + Ext);
150
+ Builder.defineMacro (DefPrefix + " DENORM_MIN__" , Twine (DenormMin)+ Ext);
151
+ Builder.defineMacro (DefPrefix + " NORM_MAX__" , Twine (NormMax)+ Ext);
151
152
Builder.defineMacro (DefPrefix + " HAS_DENORM__" );
152
153
Builder.defineMacro (DefPrefix + " DIG__" , Twine (Digits));
153
154
Builder.defineMacro (DefPrefix + " DECIMAL_DIG__" , Twine (DecimalDigits));
154
- Builder.defineMacro (DefPrefix + " EPSILON__" , Twine (Epsilon) + Ext);
155
+ Builder.defineMacro (DefPrefix + " EPSILON__" , Twine (Epsilon)+ Ext);
155
156
Builder.defineMacro (DefPrefix + " HAS_INFINITY__" );
156
157
Builder.defineMacro (DefPrefix + " HAS_QUIET_NAN__" );
157
158
Builder.defineMacro (DefPrefix + " MANT_DIG__" , Twine (MantissaDigits));
158
159
159
160
Builder.defineMacro (DefPrefix + " MAX_10_EXP__" , Twine (Max10Exp));
160
161
Builder.defineMacro (DefPrefix + " MAX_EXP__" , Twine (MaxExp));
161
- Builder.defineMacro (DefPrefix + " MAX__" , Twine (Max) + Ext);
162
+ Builder.defineMacro (DefPrefix + " MAX__" , Twine (Max)+ Ext);
162
163
163
- Builder.defineMacro (DefPrefix + " MIN_10_EXP__" , " (" + Twine (Min10Exp) + " )" );
164
- Builder.defineMacro (DefPrefix + " MIN_EXP__" , " (" + Twine (MinExp) + " )" );
165
- Builder.defineMacro (DefPrefix + " MIN__" , Twine (Min) + Ext);
164
+ Builder.defineMacro (DefPrefix + " MIN_10_EXP__" ," (" + Twine (Min10Exp)+ " )" );
165
+ Builder.defineMacro (DefPrefix + " MIN_EXP__" , " (" + Twine (MinExp)+ " )" );
166
+ Builder.defineMacro (DefPrefix + " MIN__" , Twine (Min)+ Ext);
166
167
}
167
168
169
+
168
170
// / DefineTypeSize - Emit a macro to the predefines buffer that declares a macro
169
171
// / named MacroName with the max value for a type with width 'TypeWidth' a
170
172
// / signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL).
@@ -213,7 +215,8 @@ static void DefineTypeWidth(const Twine &MacroName, TargetInfo::IntType Ty,
213
215
214
216
static void DefineTypeSizeof (StringRef MacroName, unsigned BitWidth,
215
217
const TargetInfo &TI, MacroBuilder &Builder) {
216
- Builder.defineMacro (MacroName, Twine (BitWidth / TI.getCharWidth ()));
218
+ Builder.defineMacro (MacroName,
219
+ Twine (BitWidth / TI.getCharWidth ()));
217
220
}
218
221
219
222
// This will generate a macro based on the prefix with `_MAX__` as the suffix
@@ -310,6 +313,7 @@ static void DefineFastIntType(const LangOptions &LangOpts, unsigned TypeWidth,
310
313
DefineFmt (LangOpts, Prefix + Twine (TypeWidth), Ty, TI, Builder);
311
314
}
312
315
316
+
313
317
// / Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with
314
318
// / the specified properties.
315
319
static const char *getLockFreeValue (unsigned TypeWidth, const TargetInfo &TI) {
@@ -350,8 +354,7 @@ static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts,
350
354
351
355
if (LangOpts.ObjCAutoRefCount ) {
352
356
Out << " template<typename _Tp>\n "
353
- << " struct __is_scalar<__attribute__((objc_ownership(strong))) _Tp> "
354
- " {\n "
357
+ << " struct __is_scalar<__attribute__((objc_ownership(strong))) _Tp> {\n "
355
358
<< " enum { __value = 0 };\n "
356
359
<< " typedef __false_type __type;\n "
357
360
<< " };\n "
@@ -546,12 +549,12 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
546
549
Builder.defineMacro (" __CL_CPP_VERSION_2021__" , " 202100" );
547
550
} else {
548
551
// OpenCL v1.0 and v1.1 do not have a predefined macro to indicate the
549
- // language standard with which the program is compiled.
550
- // __OPENCL_VERSION__ is for the OpenCL version supported by the OpenCL
551
- // device, which is not necessarily the language standard with which the
552
- // program is compiled. A shared OpenCL header file requires a macro to
553
- // indicate the language standard. As a workaround, __OPENCL_C_VERSION__
554
- // is defined for OpenCL v1.0 and v1.1.
552
+ // language standard with which the program is compiled. __OPENCL_VERSION__
553
+ // is for the OpenCL version supported by the OpenCL device, which is not
554
+ // necessarily the language standard with which the program is compiled.
555
+ // A shared OpenCL header file requires a macro to indicate the language
556
+ // standard. As a workaround, __OPENCL_C_VERSION__ is defined for
557
+ // OpenCL v1.0 and v1.1.
555
558
switch (LangOpts.OpenCLVersion ) {
556
559
case 100 :
557
560
Builder.defineMacro (" __OPENCL_C_VERSION__" , " 100" );
@@ -717,7 +720,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
717
720
Builder.defineMacro (" __cpp_capture_star_this" , " 201603L" );
718
721
Builder.defineMacro (" __cpp_if_constexpr" , " 201606L" );
719
722
Builder.defineMacro (" __cpp_deduction_guides" , " 201703L" ); // (not latest)
720
- Builder.defineMacro (" __cpp_template_auto" , " 201606L" ); // (old name)
723
+ Builder.defineMacro (" __cpp_template_auto" , " 201606L" ); // (old name)
721
724
Builder.defineMacro (" __cpp_namespace_attributes" , " 201411L" );
722
725
Builder.defineMacro (" __cpp_enumerator_attributes" , " 201411L" );
723
726
Builder.defineMacro (" __cpp_nested_namespace_definitions" , " 201411L" );
@@ -747,7 +750,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
747
750
Builder.defineMacro (" __cpp_impl_coroutine" , " 201902L" );
748
751
Builder.defineMacro (" __cpp_designated_initializers" , " 201707L" );
749
752
Builder.defineMacro (" __cpp_impl_three_way_comparison" , " 201907L" );
750
- // Builder.defineMacro("__cpp_modules", "201907L");
753
+ // Builder.defineMacro("__cpp_modules", "201907L");
751
754
Builder.defineMacro (" __cpp_using_enum" , " 201907L" );
752
755
}
753
756
// C++23 features.
@@ -862,7 +865,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
862
865
const LangOptions &LangOpts,
863
866
const FrontendOptions &FEOpts,
864
867
const PreprocessorOptions &PPOpts,
865
- const CodeGenOptions &CGOpts,
866
868
MacroBuilder &Builder) {
867
869
// Compiler version introspection macros.
868
870
Builder.defineMacro (" __llvm__" ); // LLVM Backend
@@ -874,9 +876,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
874
876
Builder.defineMacro (" __clang_patchlevel__" , TOSTR (CLANG_VERSION_PATCHLEVEL));
875
877
#undef TOSTR
876
878
#undef TOSTR2
877
- Builder.defineMacro (" __clang_version__" , " \" " CLANG_VERSION_STRING " " +
878
- getClangFullRepositoryVersion () +
879
- " \" " );
879
+ Builder.defineMacro (" __clang_version__" ,
880
+ " \" " CLANG_VERSION_STRING " "
881
+ + getClangFullRepositoryVersion () + " \" " );
880
882
881
883
if (LangOpts.GNUCVersion != 0 ) {
882
884
// Major, minor, patch, are given two decimal places each, so 4.2.1 becomes
@@ -941,8 +943,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
941
943
942
944
// Previously this macro was set to a string aiming to achieve compatibility
943
945
// with GCC 4.2.1. Now, just return the full Clang version
944
- Builder.defineMacro (" __VERSION__" ,
945
- " \" " + Twine (getClangFullCPPVersion ()) + " \" " );
946
+ Builder.defineMacro (" __VERSION__" , " \" " +
947
+ Twine (getClangFullCPPVersion ()) + " \" " );
946
948
947
949
// Initialize language-specific preprocessor defines.
948
950
@@ -990,9 +992,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
990
992
VersionTuple tuple = LangOpts.ObjCRuntime .getVersion ();
991
993
unsigned minor = tuple.getMinor ().value_or (0 );
992
994
unsigned subminor = tuple.getSubminor ().value_or (0 );
993
- Builder.defineMacro (
994
- " __OBJFW_RUNTIME_ABI__ " ,
995
- Twine (tuple. getMajor () * 10000 + minor * 100 + subminor));
995
+ Builder.defineMacro (" __OBJFW_RUNTIME_ABI__ " ,
996
+ Twine (tuple. getMajor () * 10000 + minor * 100 +
997
+ subminor));
996
998
}
997
999
998
1000
Builder.defineMacro (" IBOutlet" , " __attribute__((iboutlet))" );
@@ -1014,7 +1016,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1014
1016
// darwin_constant_cfstrings controls this. This is also dependent
1015
1017
// on other things like the runtime I believe. This is set even for C code.
1016
1018
if (!LangOpts.NoConstantCFStrings )
1017
- Builder.defineMacro (" __CONSTANT_CFSTRINGS__" );
1019
+ Builder.defineMacro (" __CONSTANT_CFSTRINGS__" );
1018
1020
1019
1021
if (LangOpts.ObjC )
1020
1022
Builder.defineMacro (" OBJC_NEW_PROPERTIES" );
@@ -1071,9 +1073,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1071
1073
Builder.defineMacro (" __clang_wide_literal_encoding__" , " \" UTF-16\" " );
1072
1074
}
1073
1075
1074
- if (CGOpts. OptimizationLevel != 0 )
1076
+ if (LangOpts. Optimize )
1075
1077
Builder.defineMacro (" __OPTIMIZE__" );
1076
- if (CGOpts .OptimizeSize != 0 )
1078
+ if (LangOpts .OptimizeSize )
1077
1079
Builder.defineMacro (" __OPTIMIZE_SIZE__" );
1078
1080
1079
1081
if (LangOpts.FastMath )
@@ -1087,8 +1089,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1087
1089
// We don't support the PDP-11 as a target, but include
1088
1090
// the define so it can still be compared against.
1089
1091
Builder.defineMacro (" __ORDER_LITTLE_ENDIAN__" , " 1234" );
1090
- Builder.defineMacro (" __ORDER_BIG_ENDIAN__" , " 4321" );
1091
- Builder.defineMacro (" __ORDER_PDP_ENDIAN__" , " 3412" );
1092
+ Builder.defineMacro (" __ORDER_BIG_ENDIAN__" , " 4321" );
1093
+ Builder.defineMacro (" __ORDER_PDP_ENDIAN__" , " 3412" );
1092
1094
if (TI.isBigEndian ()) {
1093
1095
Builder.defineMacro (" __BYTE_ORDER__" , " __ORDER_BIG_ENDIAN__" );
1094
1096
Builder.defineMacro (" __BIG_ENDIAN__" );
@@ -1154,21 +1156,20 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1154
1156
DefineTypeSizeof (" __SIZEOF_FLOAT__" , TI.getFloatWidth (), TI, Builder);
1155
1157
DefineTypeSizeof (" __SIZEOF_INT__" , TI.getIntWidth (), TI, Builder);
1156
1158
DefineTypeSizeof (" __SIZEOF_LONG__" , TI.getLongWidth (), TI, Builder);
1157
- DefineTypeSizeof (" __SIZEOF_LONG_DOUBLE__" , TI.getLongDoubleWidth (), TI,
1158
- Builder);
1159
+ DefineTypeSizeof (" __SIZEOF_LONG_DOUBLE__" ,TI.getLongDoubleWidth (),TI,Builder);
1159
1160
DefineTypeSizeof (" __SIZEOF_LONG_LONG__" , TI.getLongLongWidth (), TI, Builder);
1160
1161
DefineTypeSizeof (" __SIZEOF_POINTER__" , TI.getPointerWidth (LangAS::Default),
1161
1162
TI, Builder);
1162
1163
DefineTypeSizeof (" __SIZEOF_SHORT__" , TI.getShortWidth (), TI, Builder);
1163
1164
DefineTypeSizeof (" __SIZEOF_PTRDIFF_T__" ,
1164
1165
TI.getTypeWidth (TI.getPtrDiffType (LangAS::Default)), TI,
1165
1166
Builder);
1166
- DefineTypeSizeof (" __SIZEOF_SIZE_T__" , TI. getTypeWidth (TI. getSizeType ()), TI,
1167
- Builder);
1168
- DefineTypeSizeof (" __SIZEOF_WCHAR_T__" , TI. getTypeWidth (TI. getWCharType ()), TI,
1169
- Builder);
1170
- DefineTypeSizeof (" __SIZEOF_WINT_T__" , TI. getTypeWidth (TI. getWIntType ()), TI,
1171
- Builder);
1167
+ DefineTypeSizeof (" __SIZEOF_SIZE_T__" ,
1168
+ TI. getTypeWidth (TI. getSizeType ()), TI, Builder);
1169
+ DefineTypeSizeof (" __SIZEOF_WCHAR_T__" ,
1170
+ TI. getTypeWidth (TI. getWCharType ()), TI, Builder);
1171
+ DefineTypeSizeof (" __SIZEOF_WINT_T__" ,
1172
+ TI. getTypeWidth (TI. getWIntType ()), TI, Builder);
1172
1173
if (TI.hasInt128Type ())
1173
1174
DefineTypeSizeof (" __SIZEOF_INT128__" , 128 , TI, Builder);
1174
1175
@@ -1264,7 +1265,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1264
1265
1265
1266
// Define __BIGGEST_ALIGNMENT__ to be compatible with gcc.
1266
1267
Builder.defineMacro (" __BIGGEST_ALIGNMENT__" ,
1267
- Twine (TI.getSuitableAlign () / TI.getCharWidth ()));
1268
+ Twine (TI.getSuitableAlign () / TI.getCharWidth ()) );
1268
1269
1269
1270
if (!LangOpts.CharIsSigned )
1270
1271
Builder.defineMacro (" __CHAR_UNSIGNED__" );
@@ -1369,7 +1370,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1369
1370
Builder.append (" #pragma push_macro(\" __GCC_CONSTRUCTIVE_SIZE\" )" );
1370
1371
1371
1372
auto addLockFreeMacros = [&](const llvm::Twine &Prefix) {
1372
- // Used by libc++ and libstdc++ to implement ATOMIC_<foo>_LOCK_FREE.
1373
+ // Used by libc++ and libstdc++ to implement ATOMIC_<foo>_LOCK_FREE.
1373
1374
#define DEFINE_LOCK_FREE_MACRO (TYPE, Type ) \
1374
1375
Builder.defineMacro (Prefix + #TYPE " _LOCK_FREE" , \
1375
1376
getLockFreeValue (TI.get ##Type##Width (), TI));
@@ -1395,7 +1396,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1395
1396
if (LangOpts.GNUCVersion )
1396
1397
addLockFreeMacros (" __GCC_ATOMIC_" );
1397
1398
1398
- if (CGOpts. getInlining () == CodeGenOptions::OnlyAlwaysInlining )
1399
+ if (LangOpts. NoInlineDefine )
1399
1400
Builder.defineMacro (" __NO_INLINE__" );
1400
1401
1401
1402
if (unsigned PICLevel = LangOpts.PICLevel ) {
@@ -1534,7 +1535,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
1534
1535
#define TARGET_OS (Name, Predicate ) \
1535
1536
Builder.defineMacro (#Name, (Predicate) ? " 1" : " 0" );
1536
1537
#include " clang/Basic/TargetOSMacros.def"
1537
-
1538
1538
#undef TARGET_OS
1539
1539
}
1540
1540
@@ -1556,7 +1556,8 @@ static void InitializePGOProfileMacros(const CodeGenOptions &CodeGenOpts,
1556
1556
void clang::InitializePreprocessor (Preprocessor &PP,
1557
1557
const PreprocessorOptions &InitOpts,
1558
1558
const PCHContainerReader &PCHContainerRdr,
1559
- const FrontendOptions &FEOpts) {
1559
+ const FrontendOptions &FEOpts,
1560
+ const CodeGenOptions &CodeGenOpts) {
1560
1561
const LangOptions &LangOpts = PP.getLangOpts ();
1561
1562
std::string PredefineBuffer;
1562
1563
PredefineBuffer.reserve (4080 );
@@ -1574,12 +1575,10 @@ void clang::InitializePreprocessor(Preprocessor &PP,
1574
1575
// macros. This is not the right way to handle this.
1575
1576
if ((LangOpts.CUDA || LangOpts.isTargetDevice ()) && PP.getAuxTargetInfo ())
1576
1577
InitializePredefinedMacros (*PP.getAuxTargetInfo (), LangOpts, FEOpts,
1577
- PP.getPreprocessorOpts (), PP.getCodeGenOpts (),
1578
- Builder);
1578
+ PP.getPreprocessorOpts (), Builder);
1579
1579
1580
1580
InitializePredefinedMacros (PP.getTargetInfo (), LangOpts, FEOpts,
1581
- PP.getPreprocessorOpts (), PP.getCodeGenOpts (),
1582
- Builder);
1581
+ PP.getPreprocessorOpts (), Builder);
1583
1582
1584
1583
// Install definitions to make Objective-C++ ARC work well with various
1585
1584
// C++ Standard Library implementations.
@@ -1606,15 +1605,15 @@ void clang::InitializePreprocessor(Preprocessor &PP,
1606
1605
// The PGO instrumentation profile macros are driven by options
1607
1606
// -fprofile[-instr]-generate/-fcs-profile-generate/-fprofile[-instr]-use,
1608
1607
// hence they are not guarded by InitOpts.UsePredefines.
1609
- InitializePGOProfileMacros (PP. getCodeGenOpts () , Builder);
1608
+ InitializePGOProfileMacros (CodeGenOpts , Builder);
1610
1609
1611
1610
// Add on the predefines from the driver. Wrap in a #line directive to report
1612
1611
// that they come from the command line.
1613
1612
Builder.append (" # 1 \" <command line>\" 1" );
1614
1613
1615
1614
// Process #define's and #undef's in the order they are given.
1616
1615
for (unsigned i = 0 , e = InitOpts.Macros .size (); i != e; ++i) {
1617
- if (InitOpts.Macros [i].second ) // isUndef
1616
+ if (InitOpts.Macros [i].second ) // isUndef
1618
1617
Builder.undefineMacro (InitOpts.Macros [i].first );
1619
1618
else
1620
1619
DefineBuiltinMacro (Builder, InitOpts.Macros [i].first ,
0 commit comments