/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Frontend/InitPreprocessor.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- InitPreprocessor.cpp - PP initialization code. ---------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file implements the clang::InitializePreprocessor function. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "clang/Basic/FileManager.h" |
14 | | #include "clang/Basic/MacroBuilder.h" |
15 | | #include "clang/Basic/SourceManager.h" |
16 | | #include "clang/Basic/SyncScope.h" |
17 | | #include "clang/Basic/TargetInfo.h" |
18 | | #include "clang/Basic/Version.h" |
19 | | #include "clang/Frontend/FrontendDiagnostic.h" |
20 | | #include "clang/Frontend/FrontendOptions.h" |
21 | | #include "clang/Frontend/Utils.h" |
22 | | #include "clang/Lex/HeaderSearch.h" |
23 | | #include "clang/Lex/Preprocessor.h" |
24 | | #include "clang/Lex/PreprocessorOptions.h" |
25 | | #include "clang/Serialization/ASTReader.h" |
26 | | #include "llvm/ADT/APFloat.h" |
27 | | #include "llvm/IR/DataLayout.h" |
28 | | using namespace clang; |
29 | | |
30 | 1.19k | static bool MacroBodyEndsInBackslash(StringRef MacroBody) { |
31 | 1.19k | while (!MacroBody.empty() && isWhitespace(MacroBody.back())898 ) |
32 | 0 | MacroBody = MacroBody.drop_back(); |
33 | 1.19k | return !MacroBody.empty() && MacroBody.back() == '\\'898 ; |
34 | 1.19k | } |
35 | | |
36 | | // Append a #define line to Buf for Macro. Macro should be of the form XXX, |
37 | | // in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit |
38 | | // "#define XXX Y z W". To get a #define with no value, use "XXX=". |
39 | | static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro, |
40 | 312k | DiagnosticsEngine &Diags) { |
41 | 312k | std::pair<StringRef, StringRef> MacroPair = Macro.split('='); |
42 | 312k | StringRef MacroName = MacroPair.first; |
43 | 312k | StringRef MacroBody = MacroPair.second; |
44 | 312k | if (MacroName.size() != Macro.size()) { |
45 | | // Per GCC -D semantics, the macro ends at \n if it exists. |
46 | 1.19k | StringRef::size_type End = MacroBody.find_first_of("\n\r"); |
47 | 1.19k | if (End != StringRef::npos) |
48 | 3 | Diags.Report(diag::warn_fe_macro_contains_embedded_newline) |
49 | 3 | << MacroName; |
50 | 1.19k | MacroBody = MacroBody.substr(0, End); |
51 | | // We handle macro bodies which end in a backslash by appending an extra |
52 | | // backslash+newline. This makes sure we don't accidentally treat the |
53 | | // backslash as a line continuation marker. |
54 | 1.19k | if (MacroBodyEndsInBackslash(MacroBody)) |
55 | 1 | Builder.defineMacro(MacroName, Twine(MacroBody) + "\\\n"); |
56 | 1.18k | else |
57 | 1.18k | Builder.defineMacro(MacroName, MacroBody); |
58 | 310k | } else { |
59 | | // Push "macroname 1". |
60 | 310k | Builder.defineMacro(Macro); |
61 | 310k | } |
62 | 312k | } |
63 | | |
64 | | /// AddImplicitInclude - Add an implicit \#include of the specified file to the |
65 | | /// predefines buffer. |
66 | | /// As these includes are generated by -include arguments the header search |
67 | | /// logic is going to search relatively to the current working directory. |
68 | 6.88k | static void AddImplicitInclude(MacroBuilder &Builder, StringRef File) { |
69 | 6.88k | Builder.append(Twine("#include \"") + File + "\""); |
70 | 6.88k | } |
71 | | |
72 | 2 | static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File) { |
73 | 2 | Builder.append(Twine("#__include_macros \"") + File + "\""); |
74 | | // Marker token to stop the __include_macros fetch loop. |
75 | 2 | Builder.append("##"); // ##? |
76 | 2 | } |
77 | | |
78 | | /// Add an implicit \#include using the original file used to generate |
79 | | /// a PCH file. |
80 | | static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP, |
81 | | const PCHContainerReader &PCHContainerRdr, |
82 | 3.53k | StringRef ImplicitIncludePCH) { |
83 | 3.53k | std::string OriginalFile = ASTReader::getOriginalSourceFile( |
84 | 3.53k | std::string(ImplicitIncludePCH), PP.getFileManager(), PCHContainerRdr, |
85 | 3.53k | PP.getDiagnostics()); |
86 | 3.53k | if (OriginalFile.empty()) |
87 | 1 | return; |
88 | | |
89 | 3.53k | AddImplicitInclude(Builder, OriginalFile); |
90 | 3.53k | } |
91 | | |
92 | | /// PickFP - This is used to pick a value based on the FP semantics of the |
93 | | /// specified FP model. |
94 | | template <typename T> |
95 | | static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal, |
96 | | T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal, |
97 | 2.72M | T IEEEQuadVal) { |
98 | 2.72M | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf()) |
99 | 46.3k | return IEEEHalfVal; |
100 | 2.68M | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle()) |
101 | 894k | return IEEESingleVal; |
102 | 1.78M | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble()) |
103 | 1.00M | return IEEEDoubleVal; |
104 | 777k | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended()) |
105 | 698k | return X87DoubleExtendedVal; |
106 | 79.0k | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble()) |
107 | 41.4k | return PPCDoubleDoubleVal; |
108 | 37.5k | assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad()); |
109 | 37.5k | return IEEEQuadVal; |
110 | 37.5k | } InitPreprocessor.cpp:char const* PickFP<char const*>(llvm::fltSemantics const*, char const*, char const*, char const*, char const*, char const*, char const*) Line | Count | Source | 97 | 991k | T IEEEQuadVal) { | 98 | 991k | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf()) | 99 | 16.8k | return IEEEHalfVal; | 100 | 975k | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle()) | 101 | 325k | return IEEESingleVal; | 102 | 649k | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble()) | 103 | 367k | return IEEEDoubleVal; | 104 | 282k | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended()) | 105 | 253k | return X87DoubleExtendedVal; | 106 | 28.7k | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble()) | 107 | 15.0k | return PPCDoubleDoubleVal; | 108 | 13.6k | assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad()); | 109 | 13.6k | return IEEEQuadVal; | 110 | 13.6k | } |
InitPreprocessor.cpp:int PickFP<int>(llvm::fltSemantics const*, int, int, int, int, int, int) Line | Count | Source | 97 | 1.73M | T IEEEQuadVal) { | 98 | 1.73M | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf()) | 99 | 29.4k | return IEEEHalfVal; | 100 | 1.70M | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle()) | 101 | 569k | return IEEESingleVal; | 102 | 1.13M | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble()) | 103 | 642k | return IEEEDoubleVal; | 104 | 494k | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended()) | 105 | 444k | return X87DoubleExtendedVal; | 106 | 50.2k | if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble()) | 107 | 26.3k | return PPCDoubleDoubleVal; | 108 | 23.8k | assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad()); | 109 | 23.8k | return IEEEQuadVal; | 110 | 23.8k | } |
|
111 | | |
112 | | static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix, |
113 | 247k | const llvm::fltSemantics *Sem, StringRef Ext) { |
114 | 247k | const char *DenormMin, *Epsilon, *Max, *Min; |
115 | 247k | DenormMin = PickFP(Sem, "5.9604644775390625e-8", "1.40129846e-45", |
116 | 247k | "4.9406564584124654e-324", "3.64519953188247460253e-4951", |
117 | 247k | "4.94065645841246544176568792868221e-324", |
118 | 247k | "6.47517511943802511092443895822764655e-4966"); |
119 | 247k | int Digits = PickFP(Sem, 3, 6, 15, 18, 31, 33); |
120 | 247k | int DecimalDigits = PickFP(Sem, 5, 9, 17, 21, 33, 36); |
121 | 247k | Epsilon = PickFP(Sem, "9.765625e-4", "1.19209290e-7", |
122 | 247k | "2.2204460492503131e-16", "1.08420217248550443401e-19", |
123 | 247k | "4.94065645841246544176568792868221e-324", |
124 | 247k | "1.92592994438723585305597794258492732e-34"); |
125 | 247k | int MantissaDigits = PickFP(Sem, 11, 24, 53, 64, 106, 113); |
126 | 247k | int Min10Exp = PickFP(Sem, -4, -37, -307, -4931, -291, -4931); |
127 | 247k | int Max10Exp = PickFP(Sem, 4, 38, 308, 4932, 308, 4932); |
128 | 247k | int MinExp = PickFP(Sem, -13, -125, -1021, -16381, -968, -16381); |
129 | 247k | int MaxExp = PickFP(Sem, 16, 128, 1024, 16384, 1024, 16384); |
130 | 247k | Min = PickFP(Sem, "6.103515625e-5", "1.17549435e-38", "2.2250738585072014e-308", |
131 | 247k | "3.36210314311209350626e-4932", |
132 | 247k | "2.00416836000897277799610805135016e-292", |
133 | 247k | "3.36210314311209350626267781732175260e-4932"); |
134 | 247k | Max = PickFP(Sem, "6.5504e+4", "3.40282347e+38", "1.7976931348623157e+308", |
135 | 247k | "1.18973149535723176502e+4932", |
136 | 247k | "1.79769313486231580793728971405301e+308", |
137 | 247k | "1.18973149535723176508575932662800702e+4932"); |
138 | | |
139 | 247k | SmallString<32> DefPrefix; |
140 | 247k | DefPrefix = "__"; |
141 | 247k | DefPrefix += Prefix; |
142 | 247k | DefPrefix += "_"; |
143 | | |
144 | 247k | Builder.defineMacro(DefPrefix + "DENORM_MIN__", Twine(DenormMin)+Ext); |
145 | 247k | Builder.defineMacro(DefPrefix + "HAS_DENORM__"); |
146 | 247k | Builder.defineMacro(DefPrefix + "DIG__", Twine(Digits)); |
147 | 247k | Builder.defineMacro(DefPrefix + "DECIMAL_DIG__", Twine(DecimalDigits)); |
148 | 247k | Builder.defineMacro(DefPrefix + "EPSILON__", Twine(Epsilon)+Ext); |
149 | 247k | Builder.defineMacro(DefPrefix + "HAS_INFINITY__"); |
150 | 247k | Builder.defineMacro(DefPrefix + "HAS_QUIET_NAN__"); |
151 | 247k | Builder.defineMacro(DefPrefix + "MANT_DIG__", Twine(MantissaDigits)); |
152 | | |
153 | 247k | Builder.defineMacro(DefPrefix + "MAX_10_EXP__", Twine(Max10Exp)); |
154 | 247k | Builder.defineMacro(DefPrefix + "MAX_EXP__", Twine(MaxExp)); |
155 | 247k | Builder.defineMacro(DefPrefix + "MAX__", Twine(Max)+Ext); |
156 | | |
157 | 247k | Builder.defineMacro(DefPrefix + "MIN_10_EXP__","("+Twine(Min10Exp)+")"); |
158 | 247k | Builder.defineMacro(DefPrefix + "MIN_EXP__", "("+Twine(MinExp)+")"); |
159 | 247k | Builder.defineMacro(DefPrefix + "MIN__", Twine(Min)+Ext); |
160 | 247k | } |
161 | | |
162 | | |
163 | | /// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro |
164 | | /// named MacroName with the max value for a type with width 'TypeWidth' a |
165 | | /// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL). |
166 | | static void DefineTypeSize(const Twine &MacroName, unsigned TypeWidth, |
167 | | StringRef ValSuffix, bool isSigned, |
168 | 3.08M | MacroBuilder &Builder) { |
169 | 1.84M | llvm::APInt MaxVal = isSigned ? llvm::APInt::getSignedMaxValue(TypeWidth) |
170 | 1.24M | : llvm::APInt::getMaxValue(TypeWidth); |
171 | 3.08M | Builder.defineMacro(MacroName, MaxVal.toString(10, isSigned) + ValSuffix); |
172 | 3.08M | } |
173 | | |
174 | | /// DefineTypeSize - An overloaded helper that uses TargetInfo to determine |
175 | | /// the width, suffix, and signedness of the given type |
176 | | static void DefineTypeSize(const Twine &MacroName, TargetInfo::IntType Ty, |
177 | 3.08M | const TargetInfo &TI, MacroBuilder &Builder) { |
178 | 3.08M | DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty), |
179 | 3.08M | TI.isTypeSigned(Ty), Builder); |
180 | 3.08M | } |
181 | | |
182 | | static void DefineFmt(const Twine &Prefix, TargetInfo::IntType Ty, |
183 | 2.43M | const TargetInfo &TI, MacroBuilder &Builder) { |
184 | 2.43M | bool IsSigned = TI.isTypeSigned(Ty); |
185 | 2.43M | StringRef FmtModifier = TI.getTypeFormatModifier(Ty); |
186 | 9.75M | for (const char *Fmt = IsSigned ? "di"1.21M : "ouxX"1.21M ; *Fmt; ++Fmt7.31M ) { |
187 | 7.31M | Builder.defineMacro(Prefix + "_FMT" + Twine(*Fmt) + "__", |
188 | 7.31M | Twine("\"") + FmtModifier + Twine(*Fmt) + "\""); |
189 | 7.31M | } |
190 | 2.43M | } |
191 | | |
192 | | static void DefineType(const Twine &MacroName, TargetInfo::IntType Ty, |
193 | 2.76M | MacroBuilder &Builder) { |
194 | 2.76M | Builder.defineMacro(MacroName, TargetInfo::getTypeName(Ty)); |
195 | 2.76M | } |
196 | | |
197 | | static void DefineTypeWidth(StringRef MacroName, TargetInfo::IntType Ty, |
198 | 731k | const TargetInfo &TI, MacroBuilder &Builder) { |
199 | 731k | Builder.defineMacro(MacroName, Twine(TI.getTypeWidth(Ty))); |
200 | 731k | } |
201 | | |
202 | | static void DefineTypeSizeof(StringRef MacroName, unsigned BitWidth, |
203 | 1.04M | const TargetInfo &TI, MacroBuilder &Builder) { |
204 | 1.04M | Builder.defineMacro(MacroName, |
205 | 1.04M | Twine(BitWidth / TI.getCharWidth())); |
206 | 1.04M | } |
207 | | |
208 | | static void DefineExactWidthIntType(TargetInfo::IntType Ty, |
209 | | const TargetInfo &TI, |
210 | 651k | MacroBuilder &Builder) { |
211 | 651k | int TypeWidth = TI.getTypeWidth(Ty); |
212 | 651k | bool IsSigned = TI.isTypeSigned(Ty); |
213 | | |
214 | | // Use the target specified int64 type, when appropriate, so that [u]int64_t |
215 | | // ends up being defined in terms of the correct type. |
216 | 651k | if (TypeWidth == 64) |
217 | 162k | Ty = IsSigned ? TI.getInt64Type()81.2k : TI.getUInt64Type()81.2k ; |
218 | | |
219 | 325k | const char *Prefix = IsSigned ? "__INT" : "__UINT"325k ; |
220 | | |
221 | 651k | DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder); |
222 | 651k | DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder); |
223 | | |
224 | 651k | StringRef ConstSuffix(TI.getTypeConstantSuffix(Ty)); |
225 | 651k | Builder.defineMacro(Prefix + Twine(TypeWidth) + "_C_SUFFIX__", ConstSuffix); |
226 | 651k | } |
227 | | |
228 | | static void DefineExactWidthIntTypeSize(TargetInfo::IntType Ty, |
229 | | const TargetInfo &TI, |
230 | 651k | MacroBuilder &Builder) { |
231 | 651k | int TypeWidth = TI.getTypeWidth(Ty); |
232 | 651k | bool IsSigned = TI.isTypeSigned(Ty); |
233 | | |
234 | | // Use the target specified int64 type, when appropriate, so that [u]int64_t |
235 | | // ends up being defined in terms of the correct type. |
236 | 651k | if (TypeWidth == 64) |
237 | 162k | Ty = IsSigned ? TI.getInt64Type()81.2k : TI.getUInt64Type()81.2k ; |
238 | | |
239 | 325k | const char *Prefix = IsSigned ? "__INT" : "__UINT"325k ; |
240 | 651k | DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder); |
241 | 651k | } |
242 | | |
243 | | static void DefineLeastWidthIntType(unsigned TypeWidth, bool IsSigned, |
244 | | const TargetInfo &TI, |
245 | 650k | MacroBuilder &Builder) { |
246 | 650k | TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned); |
247 | 650k | if (Ty == TargetInfo::NoInt) |
248 | 12 | return; |
249 | | |
250 | 650k | const char *Prefix = IsSigned ? "__INT_LEAST"325k : "__UINT_LEAST"325k ; |
251 | 650k | DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder); |
252 | 650k | DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder); |
253 | 650k | DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder); |
254 | 650k | } |
255 | | |
256 | | static void DefineFastIntType(unsigned TypeWidth, bool IsSigned, |
257 | 650k | const TargetInfo &TI, MacroBuilder &Builder) { |
258 | | // stdint.h currently defines the fast int types as equivalent to the least |
259 | | // types. |
260 | 650k | TargetInfo::IntType Ty = TI.getLeastIntTypeByWidth(TypeWidth, IsSigned); |
261 | 650k | if (Ty == TargetInfo::NoInt) |
262 | 12 | return; |
263 | | |
264 | 650k | const char *Prefix = IsSigned ? "__INT_FAST"325k : "__UINT_FAST"325k ; |
265 | 650k | DefineType(Prefix + Twine(TypeWidth) + "_TYPE__", Ty, Builder); |
266 | 650k | DefineTypeSize(Prefix + Twine(TypeWidth) + "_MAX__", Ty, TI, Builder); |
267 | | |
268 | 650k | DefineFmt(Prefix + Twine(TypeWidth), Ty, TI, Builder); |
269 | 650k | } |
270 | | |
271 | | |
272 | | /// Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with |
273 | | /// the specified properties. |
274 | | static const char *getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign, |
275 | 1.07M | unsigned InlineWidth) { |
276 | | // Fully-aligned, power-of-2 sizes no larger than the inline |
277 | | // width will be inlined as lock-free operations. |
278 | 1.07M | if (TypeWidth == TypeAlign && (TypeWidth & (TypeWidth - 1)) == 01.05M && |
279 | 1.05M | TypeWidth <= InlineWidth) |
280 | 1.04M | return "2"; // "always lock free" |
281 | | // We cannot be certain what operations the lib calls might be |
282 | | // able to implement as lock-free on future processors. |
283 | 34.1k | return "1"; // "sometimes lock free" |
284 | 34.1k | } |
285 | | |
286 | | /// Add definitions required for a smooth interaction between |
287 | | /// Objective-C++ automated reference counting and libstdc++ (4.2). |
288 | | static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts, |
289 | 8 | MacroBuilder &Builder) { |
290 | 8 | Builder.defineMacro("_GLIBCXX_PREDEFINED_OBJC_ARC_IS_SCALAR"); |
291 | | |
292 | 8 | std::string Result; |
293 | 8 | { |
294 | | // Provide specializations for the __is_scalar type trait so that |
295 | | // lifetime-qualified objects are not considered "scalar" types, which |
296 | | // libstdc++ uses as an indicator of the presence of trivial copy, assign, |
297 | | // default-construct, and destruct semantics (none of which hold for |
298 | | // lifetime-qualified objects in ARC). |
299 | 8 | llvm::raw_string_ostream Out(Result); |
300 | | |
301 | 8 | Out << "namespace std {\n" |
302 | 8 | << "\n" |
303 | 8 | << "struct __true_type;\n" |
304 | 8 | << "struct __false_type;\n" |
305 | 8 | << "\n"; |
306 | | |
307 | 8 | Out << "template<typename _Tp> struct __is_scalar;\n" |
308 | 8 | << "\n"; |
309 | | |
310 | 8 | if (LangOpts.ObjCAutoRefCount) { |
311 | 8 | Out << "template<typename _Tp>\n" |
312 | 8 | << "struct __is_scalar<__attribute__((objc_ownership(strong))) _Tp> {\n" |
313 | 8 | << " enum { __value = 0 };\n" |
314 | 8 | << " typedef __false_type __type;\n" |
315 | 8 | << "};\n" |
316 | 8 | << "\n"; |
317 | 8 | } |
318 | | |
319 | 8 | if (LangOpts.ObjCWeak) { |
320 | 1 | Out << "template<typename _Tp>\n" |
321 | 1 | << "struct __is_scalar<__attribute__((objc_ownership(weak))) _Tp> {\n" |
322 | 1 | << " enum { __value = 0 };\n" |
323 | 1 | << " typedef __false_type __type;\n" |
324 | 1 | << "};\n" |
325 | 1 | << "\n"; |
326 | 1 | } |
327 | | |
328 | 8 | if (LangOpts.ObjCAutoRefCount) { |
329 | 8 | Out << "template<typename _Tp>\n" |
330 | 8 | << "struct __is_scalar<__attribute__((objc_ownership(autoreleasing)))" |
331 | 8 | << " _Tp> {\n" |
332 | 8 | << " enum { __value = 0 };\n" |
333 | 8 | << " typedef __false_type __type;\n" |
334 | 8 | << "};\n" |
335 | 8 | << "\n"; |
336 | 8 | } |
337 | | |
338 | 8 | Out << "}\n"; |
339 | 8 | } |
340 | 8 | Builder.append(Result); |
341 | 8 | } |
342 | | |
343 | | static void InitializeStandardPredefinedMacros(const TargetInfo &TI, |
344 | | const LangOptions &LangOpts, |
345 | | const FrontendOptions &FEOpts, |
346 | 81.1k | MacroBuilder &Builder) { |
347 | | // C++ [cpp.predefined]p1: |
348 | | // The following macro names shall be defined by the implementation: |
349 | | |
350 | | // -- __STDC__ |
351 | | // [C++] Whether __STDC__ is predefined and if so, what its value is, |
352 | | // are implementation-defined. |
353 | | // (Removed in C++20.) |
354 | 81.1k | if (!LangOpts.MSVCCompat && !LangOpts.TraditionalCPP71.3k ) |
355 | 71.3k | Builder.defineMacro("__STDC__"); |
356 | | // -- __STDC_HOSTED__ |
357 | | // The integer literal 1 if the implementation is a hosted |
358 | | // implementation or the integer literal 0 if it is not. |
359 | 81.1k | if (LangOpts.Freestanding) |
360 | 778 | Builder.defineMacro("__STDC_HOSTED__", "0"); |
361 | 80.3k | else |
362 | 80.3k | Builder.defineMacro("__STDC_HOSTED__"); |
363 | | |
364 | | // -- __STDC_VERSION__ |
365 | | // [C++] Whether __STDC_VERSION__ is predefined and if so, what its |
366 | | // value is, are implementation-defined. |
367 | | // (Removed in C++20.) |
368 | 81.1k | if (!LangOpts.CPlusPlus) { |
369 | 19.6k | if (LangOpts.C17) |
370 | 11.2k | Builder.defineMacro("__STDC_VERSION__", "201710L"); |
371 | 8.40k | else if (LangOpts.C11) |
372 | 5.47k | Builder.defineMacro("__STDC_VERSION__", "201112L"); |
373 | 2.93k | else if (LangOpts.C99) |
374 | 2.01k | Builder.defineMacro("__STDC_VERSION__", "199901L"); |
375 | 916 | else if (!LangOpts.GNUMode && LangOpts.Digraphs863 ) |
376 | 5 | Builder.defineMacro("__STDC_VERSION__", "199409L"); |
377 | 61.4k | } else { |
378 | | // -- __cplusplus |
379 | | // FIXME: Use correct value for C++23. |
380 | 61.4k | if (LangOpts.CPlusPlus2b) |
381 | 6 | Builder.defineMacro("__cplusplus", "202101L"); |
382 | | // [C++20] The integer literal 202002L. |
383 | 61.4k | else if (LangOpts.CPlusPlus20) |
384 | 3.23k | Builder.defineMacro("__cplusplus", "202002L"); |
385 | | // [C++17] The integer literal 201703L. |
386 | 58.2k | else if (LangOpts.CPlusPlus17) |
387 | 3.54k | Builder.defineMacro("__cplusplus", "201703L"); |
388 | | // [C++14] The name __cplusplus is defined to the value 201402L when |
389 | | // compiling a C++ translation unit. |
390 | 54.7k | else if (LangOpts.CPlusPlus14) |
391 | 18.4k | Builder.defineMacro("__cplusplus", "201402L"); |
392 | | // [C++11] The name __cplusplus is defined to the value 201103L when |
393 | | // compiling a C++ translation unit. |
394 | 36.2k | else if (LangOpts.CPlusPlus11) |
395 | 27.7k | Builder.defineMacro("__cplusplus", "201103L"); |
396 | | // [C++03] The name __cplusplus is defined to the value 199711L when |
397 | | // compiling a C++ translation unit. |
398 | 8.41k | else |
399 | 8.41k | Builder.defineMacro("__cplusplus", "199711L"); |
400 | | |
401 | | // -- __STDCPP_DEFAULT_NEW_ALIGNMENT__ |
402 | | // [C++17] An integer literal of type std::size_t whose value is the |
403 | | // alignment guaranteed by a call to operator new(std::size_t) |
404 | | // |
405 | | // We provide this in all language modes, since it seems generally useful. |
406 | 61.4k | Builder.defineMacro("__STDCPP_DEFAULT_NEW_ALIGNMENT__", |
407 | 61.4k | Twine(TI.getNewAlign() / TI.getCharWidth()) + |
408 | 61.4k | TI.getTypeConstantSuffix(TI.getSizeType())); |
409 | | |
410 | | // -- __STDCPP_ÂTHREADS__ |
411 | | // Defined, and has the value integer literal 1, if and only if a |
412 | | // program can have more than one thread of execution. |
413 | 61.4k | if (LangOpts.getThreadModel() == LangOptions::ThreadModelKind::POSIX) |
414 | 61.4k | Builder.defineMacro("__STDCPP_THREADS__", "1"); |
415 | 61.4k | } |
416 | | |
417 | | // In C11 these are environment macros. In C++11 they are only defined |
418 | | // as part of <cuchar>. To prevent breakage when mixing C and C++ |
419 | | // code, define these macros unconditionally. We can define them |
420 | | // unconditionally, as Clang always uses UTF-16 and UTF-32 for 16-bit |
421 | | // and 32-bit character literals. |
422 | 81.1k | Builder.defineMacro("__STDC_UTF_16__", "1"); |
423 | 81.1k | Builder.defineMacro("__STDC_UTF_32__", "1"); |
424 | | |
425 | 81.1k | if (LangOpts.ObjC) |
426 | 19.8k | Builder.defineMacro("__OBJC__"); |
427 | | |
428 | | // OpenCL v1.0/1.1 s6.9, v1.2/2.0 s6.10: Preprocessor Directives and Macros. |
429 | 81.1k | if (LangOpts.OpenCL) { |
430 | 691 | if (LangOpts.CPlusPlus) { |
431 | 77 | if (LangOpts.OpenCLCPlusPlusVersion == 100) |
432 | 77 | Builder.defineMacro("__OPENCL_CPP_VERSION__", "100"); |
433 | 77 | else |
434 | 0 | llvm_unreachable("Unsupported C++ version for OpenCL"); |
435 | 77 | Builder.defineMacro("__CL_CPP_VERSION_1_0__", "100"); |
436 | 614 | } else { |
437 | | // OpenCL v1.0 and v1.1 do not have a predefined macro to indicate the |
438 | | // language standard with which the program is compiled. __OPENCL_VERSION__ |
439 | | // is for the OpenCL version supported by the OpenCL device, which is not |
440 | | // necessarily the language standard with which the program is compiled. |
441 | | // A shared OpenCL header file requires a macro to indicate the language |
442 | | // standard. As a workaround, __OPENCL_C_VERSION__ is defined for |
443 | | // OpenCL v1.0 and v1.1. |
444 | 614 | switch (LangOpts.OpenCLVersion) { |
445 | 355 | case 100: |
446 | 355 | Builder.defineMacro("__OPENCL_C_VERSION__", "100"); |
447 | 355 | break; |
448 | 25 | case 110: |
449 | 25 | Builder.defineMacro("__OPENCL_C_VERSION__", "110"); |
450 | 25 | break; |
451 | 66 | case 120: |
452 | 66 | Builder.defineMacro("__OPENCL_C_VERSION__", "120"); |
453 | 66 | break; |
454 | 165 | case 200: |
455 | 165 | Builder.defineMacro("__OPENCL_C_VERSION__", "200"); |
456 | 165 | break; |
457 | 3 | case 300: |
458 | 3 | Builder.defineMacro("__OPENCL_C_VERSION__", "300"); |
459 | 3 | break; |
460 | 0 | default: |
461 | 0 | llvm_unreachable("Unsupported OpenCL version"); |
462 | 691 | } |
463 | 691 | } |
464 | 691 | Builder.defineMacro("CL_VERSION_1_0", "100"); |
465 | 691 | Builder.defineMacro("CL_VERSION_1_1", "110"); |
466 | 691 | Builder.defineMacro("CL_VERSION_1_2", "120"); |
467 | 691 | Builder.defineMacro("CL_VERSION_2_0", "200"); |
468 | 691 | Builder.defineMacro("CL_VERSION_3_0", "300"); |
469 | | |
470 | 691 | if (TI.isLittleEndian()) |
471 | 691 | Builder.defineMacro("__ENDIAN_LITTLE__"); |
472 | | |
473 | 691 | if (LangOpts.FastRelaxedMath) |
474 | 3 | Builder.defineMacro("__FAST_RELAXED_MATH__"); |
475 | 691 | } |
476 | | |
477 | 81.1k | if (LangOpts.SYCL) { |
478 | | // SYCL Version is set to a value when building SYCL applications |
479 | 10 | if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017) |
480 | 2 | Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121"); |
481 | 10 | } |
482 | | |
483 | | // Not "standard" per se, but available even with the -undef flag. |
484 | 81.1k | if (LangOpts.AsmPreprocessor) |
485 | 40 | Builder.defineMacro("__ASSEMBLER__"); |
486 | 81.1k | if (LangOpts.CUDA && !LangOpts.HIP379 ) |
487 | 291 | Builder.defineMacro("__CUDA__"); |
488 | 81.1k | if (LangOpts.HIP) { |
489 | 88 | Builder.defineMacro("__HIP__"); |
490 | 88 | Builder.defineMacro("__HIPCC__"); |
491 | 88 | if (LangOpts.CUDAIsDevice) |
492 | 58 | Builder.defineMacro("__HIP_DEVICE_COMPILE__"); |
493 | 88 | } |
494 | 81.1k | } |
495 | | |
496 | | /// Initialize the predefined C++ language feature test macros defined in |
497 | | /// ISO/IEC JTC1/SC22/WG21 (C++) SD-6: "SG10 Feature Test Recommendations". |
498 | | static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts, |
499 | 61.6k | MacroBuilder &Builder) { |
500 | | // C++98 features. |
501 | 61.6k | if (LangOpts.RTTI) |
502 | 61.4k | Builder.defineMacro("__cpp_rtti", "199711L"); |
503 | 61.6k | if (LangOpts.CXXExceptions) |
504 | 28.2k | Builder.defineMacro("__cpp_exceptions", "199711L"); |
505 | | |
506 | | // C++11 features. |
507 | 61.6k | if (LangOpts.CPlusPlus11) { |
508 | 53.1k | Builder.defineMacro("__cpp_unicode_characters", "200704L"); |
509 | 53.1k | Builder.defineMacro("__cpp_raw_strings", "200710L"); |
510 | 53.1k | Builder.defineMacro("__cpp_unicode_literals", "200710L"); |
511 | 53.1k | Builder.defineMacro("__cpp_user_defined_literals", "200809L"); |
512 | 53.1k | Builder.defineMacro("__cpp_lambdas", "200907L"); |
513 | 53.1k | Builder.defineMacro("__cpp_constexpr", |
514 | 3.23k | LangOpts.CPlusPlus20 ? "201907L" : |
515 | 49.9k | LangOpts.CPlusPlus17 ? "201603L"3.54k : |
516 | 46.3k | LangOpts.CPlusPlus14 ? "201304L"18.5k : "200704"27.8k ); |
517 | 53.1k | Builder.defineMacro("__cpp_constexpr_in_decltype", "201711L"); |
518 | 53.1k | Builder.defineMacro("__cpp_range_based_for", |
519 | 46.3k | LangOpts.CPlusPlus17 ? "201603L"6.77k : "200907"); |
520 | 53.1k | Builder.defineMacro("__cpp_static_assert", |
521 | 46.3k | LangOpts.CPlusPlus17 ? "201411L"6.77k : "200410"); |
522 | 53.1k | Builder.defineMacro("__cpp_decltype", "200707L"); |
523 | 53.1k | Builder.defineMacro("__cpp_attributes", "200809L"); |
524 | 53.1k | Builder.defineMacro("__cpp_rvalue_references", "200610L"); |
525 | 53.1k | Builder.defineMacro("__cpp_variadic_templates", "200704L"); |
526 | 53.1k | Builder.defineMacro("__cpp_initializer_lists", "200806L"); |
527 | 53.1k | Builder.defineMacro("__cpp_delegating_constructors", "200604L"); |
528 | 53.1k | Builder.defineMacro("__cpp_nsdmi", "200809L"); |
529 | 53.1k | Builder.defineMacro("__cpp_inheriting_constructors", "201511L"); |
530 | 53.1k | Builder.defineMacro("__cpp_ref_qualifiers", "200710L"); |
531 | 53.1k | Builder.defineMacro("__cpp_alias_templates", "200704L"); |
532 | 53.1k | } |
533 | 61.6k | if (LangOpts.ThreadsafeStatics) |
534 | 48.1k | Builder.defineMacro("__cpp_threadsafe_static_init", "200806L"); |
535 | | |
536 | | // C++14 features. |
537 | 61.6k | if (LangOpts.CPlusPlus14) { |
538 | 25.3k | Builder.defineMacro("__cpp_binary_literals", "201304L"); |
539 | 25.3k | Builder.defineMacro("__cpp_digit_separators", "201309L"); |
540 | 25.3k | Builder.defineMacro("__cpp_init_captures", |
541 | 22.0k | LangOpts.CPlusPlus20 ? "201803L"3.23k : "201304L"); |
542 | 25.3k | Builder.defineMacro("__cpp_generic_lambdas", |
543 | 22.0k | LangOpts.CPlusPlus20 ? "201707L"3.23k : "201304L"); |
544 | 25.3k | Builder.defineMacro("__cpp_decltype_auto", "201304L"); |
545 | 25.3k | Builder.defineMacro("__cpp_return_type_deduction", "201304L"); |
546 | 25.3k | Builder.defineMacro("__cpp_aggregate_nsdmi", "201304L"); |
547 | 25.3k | Builder.defineMacro("__cpp_variable_templates", "201304L"); |
548 | 25.3k | } |
549 | 61.6k | if (LangOpts.SizedDeallocation) |
550 | 39 | Builder.defineMacro("__cpp_sized_deallocation", "201309L"); |
551 | | |
552 | | // C++17 features. |
553 | 61.6k | if (LangOpts.CPlusPlus17) { |
554 | 6.77k | Builder.defineMacro("__cpp_hex_float", "201603L"); |
555 | 6.77k | Builder.defineMacro("__cpp_inline_variables", "201606L"); |
556 | 6.77k | Builder.defineMacro("__cpp_noexcept_function_type", "201510L"); |
557 | 6.77k | Builder.defineMacro("__cpp_capture_star_this", "201603L"); |
558 | 6.77k | Builder.defineMacro("__cpp_if_constexpr", "201606L"); |
559 | 6.77k | Builder.defineMacro("__cpp_deduction_guides", "201703L"); // (not latest) |
560 | 6.77k | Builder.defineMacro("__cpp_template_auto", "201606L"); // (old name) |
561 | 6.77k | Builder.defineMacro("__cpp_namespace_attributes", "201411L"); |
562 | 6.77k | Builder.defineMacro("__cpp_enumerator_attributes", "201411L"); |
563 | 6.77k | Builder.defineMacro("__cpp_nested_namespace_definitions", "201411L"); |
564 | 6.77k | Builder.defineMacro("__cpp_variadic_using", "201611L"); |
565 | 6.77k | Builder.defineMacro("__cpp_aggregate_bases", "201603L"); |
566 | 6.77k | Builder.defineMacro("__cpp_structured_bindings", "201606L"); |
567 | 6.77k | Builder.defineMacro("__cpp_nontype_template_args", |
568 | 3.54k | LangOpts.CPlusPlus20 ? "201911L"3.23k : "201411L"); |
569 | 6.77k | Builder.defineMacro("__cpp_fold_expressions", "201603L"); |
570 | 6.77k | Builder.defineMacro("__cpp_guaranteed_copy_elision", "201606L"); |
571 | 6.77k | Builder.defineMacro("__cpp_nontype_template_parameter_auto", "201606L"); |
572 | 6.77k | } |
573 | 61.6k | if (LangOpts.AlignedAllocation && !LangOpts.AlignedAllocationUnavailable6.78k ) |
574 | 6.77k | Builder.defineMacro("__cpp_aligned_new", "201606L"); |
575 | 61.6k | if (LangOpts.RelaxedTemplateTemplateArgs) |
576 | 3 | Builder.defineMacro("__cpp_template_template_args", "201611L"); |
577 | | |
578 | | // C++20 features. |
579 | 61.6k | if (LangOpts.CPlusPlus20) { |
580 | | //Builder.defineMacro("__cpp_aggregate_paren_init", "201902L"); |
581 | 3.23k | Builder.defineMacro("__cpp_concepts", "201907L"); |
582 | 3.23k | Builder.defineMacro("__cpp_conditional_explicit", "201806L"); |
583 | | //Builder.defineMacro("__cpp_consteval", "201811L"); |
584 | 3.23k | Builder.defineMacro("__cpp_constexpr_dynamic_alloc", "201907L"); |
585 | 3.23k | Builder.defineMacro("__cpp_constinit", "201907L"); |
586 | | //Builder.defineMacro("__cpp_coroutines", "201902L"); |
587 | 3.23k | Builder.defineMacro("__cpp_designated_initializers", "201707L"); |
588 | 3.23k | Builder.defineMacro("__cpp_impl_three_way_comparison", "201907L"); |
589 | | //Builder.defineMacro("__cpp_modules", "201907L"); |
590 | | //Builder.defineMacro("__cpp_using_enum", "201907L"); |
591 | 3.23k | } |
592 | 61.6k | if (LangOpts.Char8) |
593 | 3.23k | Builder.defineMacro("__cpp_char8_t", "201811L"); |
594 | 61.6k | Builder.defineMacro("__cpp_impl_destroying_delete", "201806L"); |
595 | | |
596 | | // TS features. |
597 | 61.6k | if (LangOpts.Coroutines) |
598 | 3.29k | Builder.defineMacro("__cpp_coroutines", "201703L"); |
599 | 61.6k | } |
600 | | |
601 | | static void InitializePredefinedMacros(const TargetInfo &TI, |
602 | | const LangOptions &LangOpts, |
603 | | const FrontendOptions &FEOpts, |
604 | | const PreprocessorOptions &PPOpts, |
605 | 81.2k | MacroBuilder &Builder) { |
606 | | // Compiler version introspection macros. |
607 | 81.2k | Builder.defineMacro("__llvm__"); // LLVM Backend |
608 | 81.2k | Builder.defineMacro("__clang__"); // Clang Frontend |
609 | 243k | #define TOSTR2(X) #X |
610 | 243k | #define TOSTR(X) TOSTR2(X) |
611 | 81.2k | Builder.defineMacro("__clang_major__", TOSTR(CLANG_VERSION_MAJOR)); |
612 | 81.2k | Builder.defineMacro("__clang_minor__", TOSTR(CLANG_VERSION_MINOR)); |
613 | 81.2k | Builder.defineMacro("__clang_patchlevel__", TOSTR(CLANG_VERSION_PATCHLEVEL)); |
614 | 81.2k | #undef TOSTR |
615 | 81.2k | #undef TOSTR2 |
616 | 81.2k | Builder.defineMacro("__clang_version__", |
617 | 81.2k | "\"" CLANG_VERSION_STRING " " |
618 | 81.2k | + getClangFullRepositoryVersion() + "\""); |
619 | | |
620 | 81.2k | if (LangOpts.GNUCVersion != 0) { |
621 | | // Major, minor, patch, are given two decimal places each, so 4.2.1 becomes |
622 | | // 40201. |
623 | 25.9k | unsigned GNUCMajor = LangOpts.GNUCVersion / 100 / 100; |
624 | 25.9k | unsigned GNUCMinor = LangOpts.GNUCVersion / 100 % 100; |
625 | 25.9k | unsigned GNUCPatch = LangOpts.GNUCVersion % 100; |
626 | 25.9k | Builder.defineMacro("__GNUC__", Twine(GNUCMajor)); |
627 | 25.9k | Builder.defineMacro("__GNUC_MINOR__", Twine(GNUCMinor)); |
628 | 25.9k | Builder.defineMacro("__GNUC_PATCHLEVEL__", Twine(GNUCPatch)); |
629 | 25.9k | Builder.defineMacro("__GXX_ABI_VERSION", "1002"); |
630 | | |
631 | 25.9k | if (LangOpts.CPlusPlus) { |
632 | 19.0k | Builder.defineMacro("__GNUG__", Twine(GNUCMajor)); |
633 | 19.0k | Builder.defineMacro("__GXX_WEAK__"); |
634 | 19.0k | } |
635 | 25.9k | } |
636 | | |
637 | | // Define macros for the C11 / C++11 memory orderings |
638 | 81.2k | Builder.defineMacro("__ATOMIC_RELAXED", "0"); |
639 | 81.2k | Builder.defineMacro("__ATOMIC_CONSUME", "1"); |
640 | 81.2k | Builder.defineMacro("__ATOMIC_ACQUIRE", "2"); |
641 | 81.2k | Builder.defineMacro("__ATOMIC_RELEASE", "3"); |
642 | 81.2k | Builder.defineMacro("__ATOMIC_ACQ_REL", "4"); |
643 | 81.2k | Builder.defineMacro("__ATOMIC_SEQ_CST", "5"); |
644 | | |
645 | | // Define macros for the OpenCL memory scope. |
646 | | // The values should match AtomicScopeOpenCLModel::ID enum. |
647 | 81.2k | static_assert( |
648 | 81.2k | static_cast<unsigned>(AtomicScopeOpenCLModel::WorkGroup) == 1 && |
649 | 81.2k | static_cast<unsigned>(AtomicScopeOpenCLModel::Device) == 2 && |
650 | 81.2k | static_cast<unsigned>(AtomicScopeOpenCLModel::AllSVMDevices) == 3 && |
651 | 81.2k | static_cast<unsigned>(AtomicScopeOpenCLModel::SubGroup) == 4, |
652 | 81.2k | "Invalid OpenCL memory scope enum definition"); |
653 | 81.2k | Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_ITEM", "0"); |
654 | 81.2k | Builder.defineMacro("__OPENCL_MEMORY_SCOPE_WORK_GROUP", "1"); |
655 | 81.2k | Builder.defineMacro("__OPENCL_MEMORY_SCOPE_DEVICE", "2"); |
656 | 81.2k | Builder.defineMacro("__OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES", "3"); |
657 | 81.2k | Builder.defineMacro("__OPENCL_MEMORY_SCOPE_SUB_GROUP", "4"); |
658 | | |
659 | | // Support for #pragma redefine_extname (Sun compatibility) |
660 | 81.2k | Builder.defineMacro("__PRAGMA_REDEFINE_EXTNAME", "1"); |
661 | | |
662 | | // Previously this macro was set to a string aiming to achieve compatibility |
663 | | // with GCC 4.2.1. Now, just return the full Clang version |
664 | 81.2k | Builder.defineMacro("__VERSION__", "\"" + |
665 | 81.2k | Twine(getClangFullCPPVersion()) + "\""); |
666 | | |
667 | | // Initialize language-specific preprocessor defines. |
668 | | |
669 | | // Standard conforming mode? |
670 | 81.2k | if (!LangOpts.GNUMode && !LangOpts.MSVCCompat36.4k ) |
671 | 26.8k | Builder.defineMacro("__STRICT_ANSI__"); |
672 | | |
673 | 81.2k | if (LangOpts.GNUCVersion && LangOpts.CPlusPlus1125.9k ) |
674 | 15.1k | Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__"); |
675 | | |
676 | 81.2k | if (LangOpts.ObjC) { |
677 | 19.8k | if (LangOpts.ObjCRuntime.isNonFragile()) { |
678 | 19.4k | Builder.defineMacro("__OBJC2__"); |
679 | | |
680 | 19.4k | if (LangOpts.ObjCExceptions) |
681 | 4.23k | Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS"); |
682 | 19.4k | } |
683 | | |
684 | 19.8k | if (LangOpts.getGC() != LangOptions::NonGC) |
685 | 92 | Builder.defineMacro("__OBJC_GC__"); |
686 | | |
687 | 19.8k | if (LangOpts.ObjCRuntime.isNeXTFamily()) |
688 | 18.9k | Builder.defineMacro("__NEXT_RUNTIME__"); |
689 | | |
690 | 19.8k | if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::GNUstep) { |
691 | 797 | auto version = LangOpts.ObjCRuntime.getVersion(); |
692 | 797 | std::string versionString = "1"; |
693 | | // Don't rely on the tuple argument, because we can be asked to target |
694 | | // later ABIs than we actually support, so clamp these values to those |
695 | | // currently supported |
696 | 797 | if (version >= VersionTuple(2, 0)) |
697 | 13 | Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__", "20"); |
698 | 784 | else |
699 | 784 | Builder.defineMacro("__OBJC_GNUSTEP_RUNTIME_ABI__", |
700 | 784 | "1" + Twine(std::min(8U, version.getMinor().getValueOr(0)))); |
701 | 797 | } |
702 | | |
703 | 19.8k | if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::ObjFW) { |
704 | 21 | VersionTuple tuple = LangOpts.ObjCRuntime.getVersion(); |
705 | | |
706 | 21 | unsigned minor = 0; |
707 | 21 | if (tuple.getMinor().hasValue()) |
708 | 21 | minor = tuple.getMinor().getValue(); |
709 | | |
710 | 21 | unsigned subminor = 0; |
711 | 21 | if (tuple.getSubminor().hasValue()) |
712 | 0 | subminor = tuple.getSubminor().getValue(); |
713 | | |
714 | 21 | Builder.defineMacro("__OBJFW_RUNTIME_ABI__", |
715 | 21 | Twine(tuple.getMajor() * 10000 + minor * 100 + |
716 | 21 | subminor)); |
717 | 21 | } |
718 | | |
719 | 19.8k | Builder.defineMacro("IBOutlet", "__attribute__((iboutlet))"); |
720 | 19.8k | Builder.defineMacro("IBOutletCollection(ClassName)", |
721 | 19.8k | "__attribute__((iboutletcollection(ClassName)))"); |
722 | 19.8k | Builder.defineMacro("IBAction", "void)__attribute__((ibaction)"); |
723 | 19.8k | Builder.defineMacro("IBInspectable", ""); |
724 | 19.8k | Builder.defineMacro("IB_DESIGNABLE", ""); |
725 | 19.8k | } |
726 | | |
727 | | // Define a macro that describes the Objective-C boolean type even for C |
728 | | // and C++ since BOOL can be used from non Objective-C code. |
729 | 81.2k | Builder.defineMacro("__OBJC_BOOL_IS_BOOL", |
730 | 80.8k | Twine(TI.useSignedCharForObjCBool() ? "0" : "1"418 )); |
731 | | |
732 | 81.2k | if (LangOpts.CPlusPlus) |
733 | 61.6k | InitializeCPlusPlusFeatureTestMacros(LangOpts, Builder); |
734 | | |
735 | | // darwin_constant_cfstrings controls this. This is also dependent |
736 | | // on other things like the runtime I believe. This is set even for C code. |
737 | 81.2k | if (!LangOpts.NoConstantCFStrings) |
738 | 81.2k | Builder.defineMacro("__CONSTANT_CFSTRINGS__"); |
739 | | |
740 | 81.2k | if (LangOpts.ObjC) |
741 | 19.8k | Builder.defineMacro("OBJC_NEW_PROPERTIES"); |
742 | | |
743 | 81.2k | if (LangOpts.PascalStrings) |
744 | 8 | Builder.defineMacro("__PASCAL_STRINGS__"); |
745 | | |
746 | 81.2k | if (LangOpts.Blocks) { |
747 | 31.2k | Builder.defineMacro("__block", "__attribute__((__blocks__(byref)))"); |
748 | 31.2k | Builder.defineMacro("__BLOCKS__"); |
749 | 31.2k | } |
750 | | |
751 | 81.2k | if (!LangOpts.MSVCCompat && LangOpts.Exceptions71.4k ) |
752 | 22.8k | Builder.defineMacro("__EXCEPTIONS"); |
753 | 81.2k | if (LangOpts.GNUCVersion && LangOpts.RTTI25.9k ) |
754 | 19.0k | Builder.defineMacro("__GXX_RTTI"); |
755 | | |
756 | 81.2k | if (LangOpts.hasSjLjExceptions()) |
757 | 34 | Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__"); |
758 | 81.2k | else if (LangOpts.hasSEHExceptions()) |
759 | 24 | Builder.defineMacro("__SEH__"); |
760 | 81.1k | else if (LangOpts.hasDWARFExceptions() && |
761 | 32 | (TI.getTriple().isThumb() || TI.getTriple().isARM()25 )) |
762 | 12 | Builder.defineMacro("__ARM_DWARF_EH__"); |
763 | | |
764 | 81.2k | if (LangOpts.Deprecated) |
765 | 26.8k | Builder.defineMacro("__DEPRECATED"); |
766 | | |
767 | 81.2k | if (!LangOpts.MSVCCompat && LangOpts.CPlusPlus71.4k ) |
768 | 52.8k | Builder.defineMacro("__private_extern__", "extern"); |
769 | | |
770 | 81.2k | if (LangOpts.MicrosoftExt) { |
771 | 10.4k | if (LangOpts.WChar) { |
772 | | // wchar_t supported as a keyword. |
773 | 9.18k | Builder.defineMacro("_WCHAR_T_DEFINED"); |
774 | 9.18k | Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED"); |
775 | 9.18k | } |
776 | 10.4k | } |
777 | | |
778 | 81.2k | if (LangOpts.Optimize) |
779 | 2.72k | Builder.defineMacro("__OPTIMIZE__"); |
780 | 81.2k | if (LangOpts.OptimizeSize) |
781 | 84 | Builder.defineMacro("__OPTIMIZE_SIZE__"); |
782 | | |
783 | 81.2k | if (LangOpts.FastMath) |
784 | 39 | Builder.defineMacro("__FAST_MATH__"); |
785 | | |
786 | | // Initialize target-specific preprocessor defines. |
787 | | |
788 | | // __BYTE_ORDER__ was added in GCC 4.6. It's analogous |
789 | | // to the macro __BYTE_ORDER (no trailing underscores) |
790 | | // from glibc's <endian.h> header. |
791 | | // We don't support the PDP-11 as a target, but include |
792 | | // the define so it can still be compared against. |
793 | 81.2k | Builder.defineMacro("__ORDER_LITTLE_ENDIAN__", "1234"); |
794 | 81.2k | Builder.defineMacro("__ORDER_BIG_ENDIAN__", "4321"); |
795 | 81.2k | Builder.defineMacro("__ORDER_PDP_ENDIAN__", "3412"); |
796 | 81.2k | if (TI.isBigEndian()) { |
797 | 802 | Builder.defineMacro("__BYTE_ORDER__", "__ORDER_BIG_ENDIAN__"); |
798 | 802 | Builder.defineMacro("__BIG_ENDIAN__"); |
799 | 80.4k | } else { |
800 | 80.4k | Builder.defineMacro("__BYTE_ORDER__", "__ORDER_LITTLE_ENDIAN__"); |
801 | 80.4k | Builder.defineMacro("__LITTLE_ENDIAN__"); |
802 | 80.4k | } |
803 | | |
804 | 81.2k | if (TI.getPointerWidth(0) == 64 && TI.getLongWidth() == 6465.0k |
805 | 57.3k | && TI.getIntWidth() == 32) { |
806 | 57.3k | Builder.defineMacro("_LP64"); |
807 | 57.3k | Builder.defineMacro("__LP64__"); |
808 | 57.3k | } |
809 | | |
810 | 81.2k | if (TI.getPointerWidth(0) == 32 && TI.getLongWidth() == 3216.1k |
811 | 15.9k | && TI.getIntWidth() == 32) { |
812 | 15.9k | Builder.defineMacro("_ILP32"); |
813 | 15.9k | Builder.defineMacro("__ILP32__"); |
814 | 15.9k | } |
815 | | |
816 | | // Define type sizing macros based on the target properties. |
817 | 81.2k | assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far"); |
818 | 81.2k | Builder.defineMacro("__CHAR_BIT__", Twine(TI.getCharWidth())); |
819 | | |
820 | 81.2k | DefineTypeSize("__SCHAR_MAX__", TargetInfo::SignedChar, TI, Builder); |
821 | 81.2k | DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder); |
822 | 81.2k | DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder); |
823 | 81.2k | DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder); |
824 | 81.2k | DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder); |
825 | 81.2k | DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder); |
826 | 81.2k | DefineTypeSize("__WINT_MAX__", TI.getWIntType(), TI, Builder); |
827 | 81.2k | DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder); |
828 | 81.2k | DefineTypeSize("__SIZE_MAX__", TI.getSizeType(), TI, Builder); |
829 | | |
830 | 81.2k | DefineTypeSize("__UINTMAX_MAX__", TI.getUIntMaxType(), TI, Builder); |
831 | 81.2k | DefineTypeSize("__PTRDIFF_MAX__", TI.getPtrDiffType(0), TI, Builder); |
832 | 81.2k | DefineTypeSize("__INTPTR_MAX__", TI.getIntPtrType(), TI, Builder); |
833 | 81.2k | DefineTypeSize("__UINTPTR_MAX__", TI.getUIntPtrType(), TI, Builder); |
834 | | |
835 | 81.2k | DefineTypeSizeof("__SIZEOF_DOUBLE__", TI.getDoubleWidth(), TI, Builder); |
836 | 81.2k | DefineTypeSizeof("__SIZEOF_FLOAT__", TI.getFloatWidth(), TI, Builder); |
837 | 81.2k | DefineTypeSizeof("__SIZEOF_INT__", TI.getIntWidth(), TI, Builder); |
838 | 81.2k | DefineTypeSizeof("__SIZEOF_LONG__", TI.getLongWidth(), TI, Builder); |
839 | 81.2k | DefineTypeSizeof("__SIZEOF_LONG_DOUBLE__",TI.getLongDoubleWidth(),TI,Builder); |
840 | 81.2k | DefineTypeSizeof("__SIZEOF_LONG_LONG__", TI.getLongLongWidth(), TI, Builder); |
841 | 81.2k | DefineTypeSizeof("__SIZEOF_POINTER__", TI.getPointerWidth(0), TI, Builder); |
842 | 81.2k | DefineTypeSizeof("__SIZEOF_SHORT__", TI.getShortWidth(), TI, Builder); |
843 | 81.2k | DefineTypeSizeof("__SIZEOF_PTRDIFF_T__", |
844 | 81.2k | TI.getTypeWidth(TI.getPtrDiffType(0)), TI, Builder); |
845 | 81.2k | DefineTypeSizeof("__SIZEOF_SIZE_T__", |
846 | 81.2k | TI.getTypeWidth(TI.getSizeType()), TI, Builder); |
847 | 81.2k | DefineTypeSizeof("__SIZEOF_WCHAR_T__", |
848 | 81.2k | TI.getTypeWidth(TI.getWCharType()), TI, Builder); |
849 | 81.2k | DefineTypeSizeof("__SIZEOF_WINT_T__", |
850 | 81.2k | TI.getTypeWidth(TI.getWIntType()), TI, Builder); |
851 | 81.2k | if (TI.hasInt128Type()) |
852 | 65.0k | DefineTypeSizeof("__SIZEOF_INT128__", 128, TI, Builder); |
853 | | |
854 | 81.2k | DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder); |
855 | 81.2k | DefineFmt("__INTMAX", TI.getIntMaxType(), TI, Builder); |
856 | 81.2k | Builder.defineMacro("__INTMAX_C_SUFFIX__", |
857 | 81.2k | TI.getTypeConstantSuffix(TI.getIntMaxType())); |
858 | 81.2k | DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder); |
859 | 81.2k | DefineFmt("__UINTMAX", TI.getUIntMaxType(), TI, Builder); |
860 | 81.2k | Builder.defineMacro("__UINTMAX_C_SUFFIX__", |
861 | 81.2k | TI.getTypeConstantSuffix(TI.getUIntMaxType())); |
862 | 81.2k | DefineTypeWidth("__INTMAX_WIDTH__", TI.getIntMaxType(), TI, Builder); |
863 | 81.2k | DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder); |
864 | 81.2k | DefineFmt("__PTRDIFF", TI.getPtrDiffType(0), TI, Builder); |
865 | 81.2k | DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder); |
866 | 81.2k | DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder); |
867 | 81.2k | DefineFmt("__INTPTR", TI.getIntPtrType(), TI, Builder); |
868 | 81.2k | DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder); |
869 | 81.2k | DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder); |
870 | 81.2k | DefineFmt("__SIZE", TI.getSizeType(), TI, Builder); |
871 | 81.2k | DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder); |
872 | 81.2k | DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder); |
873 | 81.2k | DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder); |
874 | 81.2k | DefineType("__WINT_TYPE__", TI.getWIntType(), Builder); |
875 | 81.2k | DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder); |
876 | 81.2k | DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder); |
877 | 81.2k | DefineTypeSize("__SIG_ATOMIC_MAX__", TI.getSigAtomicType(), TI, Builder); |
878 | 81.2k | DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder); |
879 | 81.2k | DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder); |
880 | | |
881 | 81.2k | DefineTypeWidth("__UINTMAX_WIDTH__", TI.getUIntMaxType(), TI, Builder); |
882 | 81.2k | DefineType("__UINTPTR_TYPE__", TI.getUIntPtrType(), Builder); |
883 | 81.2k | DefineFmt("__UINTPTR", TI.getUIntPtrType(), TI, Builder); |
884 | 81.2k | DefineTypeWidth("__UINTPTR_WIDTH__", TI.getUIntPtrType(), TI, Builder); |
885 | | |
886 | 81.2k | if (TI.hasFloat16Type()) |
887 | 4.21k | DefineFloatMacros(Builder, "FLT16", &TI.getHalfFormat(), "F16"); |
888 | 81.2k | DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F"); |
889 | 81.2k | DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), ""); |
890 | 81.2k | DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L"); |
891 | | |
892 | | // Define a __POINTER_WIDTH__ macro for stdint.h. |
893 | 81.2k | Builder.defineMacro("__POINTER_WIDTH__", |
894 | 81.2k | Twine((int)TI.getPointerWidth(0))); |
895 | | |
896 | | // Define __BIGGEST_ALIGNMENT__ to be compatible with gcc. |
897 | 81.2k | Builder.defineMacro("__BIGGEST_ALIGNMENT__", |
898 | 81.2k | Twine(TI.getSuitableAlign() / TI.getCharWidth()) ); |
899 | | |
900 | 81.2k | if (!LangOpts.CharIsSigned) |
901 | 870 | Builder.defineMacro("__CHAR_UNSIGNED__"); |
902 | | |
903 | 81.2k | if (!TargetInfo::isTypeSigned(TI.getWCharType())) |
904 | 11.7k | Builder.defineMacro("__WCHAR_UNSIGNED__"); |
905 | | |
906 | 81.2k | if (!TargetInfo::isTypeSigned(TI.getWIntType())) |
907 | 14.6k | Builder.defineMacro("__WINT_UNSIGNED__"); |
908 | | |
909 | | // Define exact-width integer types for stdint.h |
910 | 81.2k | DefineExactWidthIntType(TargetInfo::SignedChar, TI, Builder); |
911 | | |
912 | 81.2k | if (TI.getShortWidth() > TI.getCharWidth()) |
913 | 81.2k | DefineExactWidthIntType(TargetInfo::SignedShort, TI, Builder); |
914 | | |
915 | 81.2k | if (TI.getIntWidth() > TI.getShortWidth()) |
916 | 81.2k | DefineExactWidthIntType(TargetInfo::SignedInt, TI, Builder); |
917 | | |
918 | 81.2k | if (TI.getLongWidth() > TI.getIntWidth()) |
919 | 57.6k | DefineExactWidthIntType(TargetInfo::SignedLong, TI, Builder); |
920 | | |
921 | 81.2k | if (TI.getLongLongWidth() > TI.getLongWidth()) |
922 | 24.3k | DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder); |
923 | | |
924 | 81.2k | DefineExactWidthIntType(TargetInfo::UnsignedChar, TI, Builder); |
925 | 81.2k | DefineExactWidthIntTypeSize(TargetInfo::UnsignedChar, TI, Builder); |
926 | 81.2k | DefineExactWidthIntTypeSize(TargetInfo::SignedChar, TI, Builder); |
927 | | |
928 | 81.2k | if (TI.getShortWidth() > TI.getCharWidth()81.2k ) { |
929 | 81.2k | DefineExactWidthIntType(TargetInfo::UnsignedShort, TI, Builder); |
930 | 81.2k | DefineExactWidthIntTypeSize(TargetInfo::UnsignedShort, TI, Builder); |
931 | 81.2k | DefineExactWidthIntTypeSize(TargetInfo::SignedShort, TI, Builder); |
932 | 81.2k | } |
933 | | |
934 | 81.2k | if (TI.getIntWidth() > TI.getShortWidth()) { |
935 | 81.2k | DefineExactWidthIntType(TargetInfo::UnsignedInt, TI, Builder); |
936 | 81.2k | DefineExactWidthIntTypeSize(TargetInfo::UnsignedInt, TI, Builder); |
937 | 81.2k | DefineExactWidthIntTypeSize(TargetInfo::SignedInt, TI, Builder); |
938 | 81.2k | } |
939 | | |
940 | 81.2k | if (TI.getLongWidth() > TI.getIntWidth()) { |
941 | 57.6k | DefineExactWidthIntType(TargetInfo::UnsignedLong, TI, Builder); |
942 | 57.6k | DefineExactWidthIntTypeSize(TargetInfo::UnsignedLong, TI, Builder); |
943 | 57.6k | DefineExactWidthIntTypeSize(TargetInfo::SignedLong, TI, Builder); |
944 | 57.6k | } |
945 | | |
946 | 81.2k | if (TI.getLongLongWidth() > TI.getLongWidth()) { |
947 | 24.3k | DefineExactWidthIntType(TargetInfo::UnsignedLongLong, TI, Builder); |
948 | 24.3k | DefineExactWidthIntTypeSize(TargetInfo::UnsignedLongLong, TI, Builder); |
949 | 24.3k | DefineExactWidthIntTypeSize(TargetInfo::SignedLongLong, TI, Builder); |
950 | 24.3k | } |
951 | | |
952 | 81.2k | DefineLeastWidthIntType(8, true, TI, Builder); |
953 | 81.2k | DefineLeastWidthIntType(8, false, TI, Builder); |
954 | 81.2k | DefineLeastWidthIntType(16, true, TI, Builder); |
955 | 81.2k | DefineLeastWidthIntType(16, false, TI, Builder); |
956 | 81.2k | DefineLeastWidthIntType(32, true, TI, Builder); |
957 | 81.2k | DefineLeastWidthIntType(32, false, TI, Builder); |
958 | 81.2k | DefineLeastWidthIntType(64, true, TI, Builder); |
959 | 81.2k | DefineLeastWidthIntType(64, false, TI, Builder); |
960 | | |
961 | 81.2k | DefineFastIntType(8, true, TI, Builder); |
962 | 81.2k | DefineFastIntType(8, false, TI, Builder); |
963 | 81.2k | DefineFastIntType(16, true, TI, Builder); |
964 | 81.2k | DefineFastIntType(16, false, TI, Builder); |
965 | 81.2k | DefineFastIntType(32, true, TI, Builder); |
966 | 81.2k | DefineFastIntType(32, false, TI, Builder); |
967 | 81.2k | DefineFastIntType(64, true, TI, Builder); |
968 | 81.2k | DefineFastIntType(64, false, TI, Builder); |
969 | | |
970 | 81.2k | char UserLabelPrefix[2] = {TI.getDataLayout().getGlobalPrefix(), 0}; |
971 | 81.2k | Builder.defineMacro("__USER_LABEL_PREFIX__", UserLabelPrefix); |
972 | | |
973 | 81.2k | if (LangOpts.FastMath || LangOpts.FiniteMathOnly81.2k ) |
974 | 44 | Builder.defineMacro("__FINITE_MATH_ONLY__", "1"); |
975 | 81.2k | else |
976 | 81.2k | Builder.defineMacro("__FINITE_MATH_ONLY__", "0"); |
977 | | |
978 | 81.2k | if (LangOpts.GNUCVersion) { |
979 | 25.9k | if (LangOpts.GNUInline || LangOpts.CPlusPlus25.5k ) |
980 | 19.4k | Builder.defineMacro("__GNUC_GNU_INLINE__"); |
981 | 6.45k | else |
982 | 6.45k | Builder.defineMacro("__GNUC_STDC_INLINE__"); |
983 | | |
984 | | // The value written by __atomic_test_and_set. |
985 | | // FIXME: This is target-dependent. |
986 | 25.9k | Builder.defineMacro("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL", "1"); |
987 | 25.9k | } |
988 | | |
989 | 107k | auto addLockFreeMacros = [&](const llvm::Twine &Prefix) { |
990 | | // Used by libc++ and libstdc++ to implement ATOMIC_<foo>_LOCK_FREE. |
991 | 107k | unsigned InlineWidthBits = TI.getMaxAtomicInlineWidth(); |
992 | 107k | #define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \ |
993 | 4.75k | Builder.defineMacro(Prefix + #TYPE "_LOCK_FREE", \ |
994 | 4.75k | getLockFreeValue(TI.get##Type##Width(), \ |
995 | 4.75k | TI.get##Type##Align(), \ |
996 | 4.75k | InlineWidthBits)); |
997 | 107k | DEFINE_LOCK_FREE_MACRO(BOOL, Bool); |
998 | 107k | DEFINE_LOCK_FREE_MACRO(CHAR, Char); |
999 | 107k | if (LangOpts.Char8) |
1000 | 4.75k | DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char); // Treat char8_t like char. |
1001 | 107k | DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16); |
1002 | 107k | DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32); |
1003 | 107k | DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar); |
1004 | 107k | DEFINE_LOCK_FREE_MACRO(SHORT, Short); |
1005 | 107k | DEFINE_LOCK_FREE_MACRO(INT, Int); |
1006 | 107k | DEFINE_LOCK_FREE_MACRO(LONG, Long); |
1007 | 107k | DEFINE_LOCK_FREE_MACRO(LLONG, LongLong); |
1008 | 107k | Builder.defineMacro(Prefix + "POINTER_LOCK_FREE", |
1009 | 107k | getLockFreeValue(TI.getPointerWidth(0), |
1010 | 107k | TI.getPointerAlign(0), |
1011 | 107k | InlineWidthBits)); |
1012 | 107k | #undef DEFINE_LOCK_FREE_MACRO |
1013 | 107k | }; |
1014 | 81.2k | addLockFreeMacros("__CLANG_ATOMIC_"); |
1015 | 81.2k | if (LangOpts.GNUCVersion) |
1016 | 25.9k | addLockFreeMacros("__GCC_ATOMIC_"); |
1017 | | |
1018 | 81.2k | if (LangOpts.NoInlineDefine) |
1019 | 65.2k | Builder.defineMacro("__NO_INLINE__"); |
1020 | | |
1021 | 81.2k | if (unsigned PICLevel = LangOpts.PICLevel) { |
1022 | 23.0k | Builder.defineMacro("__PIC__", Twine(PICLevel)); |
1023 | 23.0k | Builder.defineMacro("__pic__", Twine(PICLevel)); |
1024 | 23.0k | if (LangOpts.PIE) { |
1025 | 26 | Builder.defineMacro("__PIE__", Twine(PICLevel)); |
1026 | 26 | Builder.defineMacro("__pie__", Twine(PICLevel)); |
1027 | 26 | } |
1028 | 23.0k | } |
1029 | | |
1030 | | // Macros to control C99 numerics and <float.h> |
1031 | 81.2k | Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod())); |
1032 | 81.2k | Builder.defineMacro("__FLT_RADIX__", "2"); |
1033 | 81.2k | Builder.defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__"); |
1034 | | |
1035 | 81.2k | if (LangOpts.getStackProtector() == LangOptions::SSPOn) |
1036 | 15.7k | Builder.defineMacro("__SSP__"); |
1037 | 65.4k | else if (LangOpts.getStackProtector() == LangOptions::SSPStrong) |
1038 | 52 | Builder.defineMacro("__SSP_STRONG__", "2"); |
1039 | 65.4k | else if (LangOpts.getStackProtector() == LangOptions::SSPReq) |
1040 | 2 | Builder.defineMacro("__SSP_ALL__", "3"); |
1041 | | |
1042 | 81.2k | if (PPOpts.SetUpStaticAnalyzer) |
1043 | 1.28k | Builder.defineMacro("__clang_analyzer__"); |
1044 | | |
1045 | 81.2k | if (LangOpts.FastRelaxedMath) |
1046 | 3 | Builder.defineMacro("__FAST_RELAXED_MATH__"); |
1047 | | |
1048 | 81.2k | if (FEOpts.ProgramAction == frontend::RewriteObjC || |
1049 | 81.0k | LangOpts.getGC() != LangOptions::NonGC) { |
1050 | 255 | Builder.defineMacro("__weak", "__attribute__((objc_gc(weak)))"); |
1051 | 255 | Builder.defineMacro("__strong", "__attribute__((objc_gc(strong)))"); |
1052 | 255 | Builder.defineMacro("__autoreleasing", ""); |
1053 | 255 | Builder.defineMacro("__unsafe_unretained", ""); |
1054 | 80.9k | } else if (LangOpts.ObjC) { |
1055 | 19.5k | Builder.defineMacro("__weak", "__attribute__((objc_ownership(weak)))"); |
1056 | 19.5k | Builder.defineMacro("__strong", "__attribute__((objc_ownership(strong)))"); |
1057 | 19.5k | Builder.defineMacro("__autoreleasing", |
1058 | 19.5k | "__attribute__((objc_ownership(autoreleasing)))"); |
1059 | 19.5k | Builder.defineMacro("__unsafe_unretained", |
1060 | 19.5k | "__attribute__((objc_ownership(none)))"); |
1061 | 19.5k | } |
1062 | | |
1063 | | // On Darwin, there are __double_underscored variants of the type |
1064 | | // nullability qualifiers. |
1065 | 81.2k | if (TI.getTriple().isOSDarwin()) { |
1066 | 46.8k | Builder.defineMacro("__nonnull", "_Nonnull"); |
1067 | 46.8k | Builder.defineMacro("__null_unspecified", "_Null_unspecified"); |
1068 | 46.8k | Builder.defineMacro("__nullable", "_Nullable"); |
1069 | 46.8k | } |
1070 | | |
1071 | | // Add a macro to differentiate between regular iOS/tvOS/watchOS targets and |
1072 | | // the corresponding simulator targets. |
1073 | 81.2k | if (TI.getTriple().isOSDarwin() && TI.getTriple().isSimulatorEnvironment()46.8k ) |
1074 | 39 | Builder.defineMacro("__APPLE_EMBEDDED_SIMULATOR__", "1"); |
1075 | | |
1076 | | // OpenMP definition |
1077 | | // OpenMP 2.2: |
1078 | | // In implementations that support a preprocessor, the _OPENMP |
1079 | | // macro name is defined to have the decimal value yyyymm where |
1080 | | // yyyy and mm are the year and the month designations of the |
1081 | | // version of the OpenMP API that the implementation support. |
1082 | 81.2k | if (!LangOpts.OpenMPSimd) { |
1083 | 76.4k | switch (LangOpts.OpenMP) { |
1084 | 69.7k | case 0: |
1085 | 69.7k | break; |
1086 | 2 | case 31: |
1087 | 2 | Builder.defineMacro("_OPENMP", "201107"); |
1088 | 2 | break; |
1089 | 11 | case 40: |
1090 | 11 | Builder.defineMacro("_OPENMP", "201307"); |
1091 | 11 | break; |
1092 | 1.26k | case 45: |
1093 | 1.26k | Builder.defineMacro("_OPENMP", "201511"); |
1094 | 1.26k | break; |
1095 | 5.37k | default: |
1096 | | // Default version is OpenMP 5.0 |
1097 | 5.37k | Builder.defineMacro("_OPENMP", "201811"); |
1098 | 5.37k | break; |
1099 | 81.2k | } |
1100 | 81.2k | } |
1101 | | |
1102 | | // CUDA device path compilaton |
1103 | 81.2k | if (LangOpts.CUDAIsDevice && !LangOpts.HIP254 ) { |
1104 | | // The CUDA_ARCH value is set for the GPU target specified in the NVPTX |
1105 | | // backend's target defines. |
1106 | 188 | Builder.defineMacro("__CUDA_ARCH__"); |
1107 | 188 | } |
1108 | | |
1109 | | // We need to communicate this to our CUDA header wrapper, which in turn |
1110 | | // informs the proper CUDA headers of this choice. |
1111 | 81.2k | if (LangOpts.CUDADeviceApproxTranscendentals81.2k || LangOpts.FastMath) { |
1112 | 41 | Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__"); |
1113 | 41 | } |
1114 | | |
1115 | | // Define a macro indicating that the source file is being compiled with a |
1116 | | // SYCL device compiler which doesn't produce host binary. |
1117 | 81.2k | if (LangOpts.SYCLIsDevice) { |
1118 | 11 | Builder.defineMacro("__SYCL_DEVICE_ONLY__", "1"); |
1119 | 11 | } |
1120 | | |
1121 | | // OpenCL definitions. |
1122 | 81.2k | if (LangOpts.OpenCL) { |
1123 | 691 | #define OPENCLEXT(Ext) \ |
1124 | 20.0k | if (TI.getSupportedOpenCLOpts().isSupported(#Ext, LangOpts)) \ |
1125 | 12.9k | Builder.defineMacro(#Ext); |
1126 | 691 | #include "clang/Basic/OpenCLExtensions.def" |
1127 | | |
1128 | 691 | if (TI.getTriple().isSPIR()) |
1129 | 182 | Builder.defineMacro("__IMAGE_SUPPORT__"); |
1130 | 691 | } |
1131 | | |
1132 | 81.2k | if (TI.hasInt128Type() && LangOpts.CPlusPlus65.0k && LangOpts.GNUMode49.7k ) { |
1133 | | // For each extended integer type, g++ defines a macro mapping the |
1134 | | // index of the type (0 in this case) in some list of extended types |
1135 | | // to the type. |
1136 | 25.2k | Builder.defineMacro("__GLIBCXX_TYPE_INT_N_0", "__int128"); |
1137 | 25.2k | Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128"); |
1138 | 25.2k | } |
1139 | | |
1140 | | // Get other target #defines. |
1141 | 81.2k | TI.getTargetDefines(LangOpts, Builder); |
1142 | 81.2k | } |
1143 | | |
1144 | | /// InitializePreprocessor - Initialize the preprocessor getting it and the |
1145 | | /// environment ready to process a single file. This returns true on error. |
1146 | | /// |
1147 | | void clang::InitializePreprocessor( |
1148 | | Preprocessor &PP, const PreprocessorOptions &InitOpts, |
1149 | | const PCHContainerReader &PCHContainerRdr, |
1150 | 81.1k | const FrontendOptions &FEOpts) { |
1151 | 81.1k | const LangOptions &LangOpts = PP.getLangOpts(); |
1152 | 81.1k | std::string PredefineBuffer; |
1153 | 81.1k | PredefineBuffer.reserve(4080); |
1154 | 81.1k | llvm::raw_string_ostream Predefines(PredefineBuffer); |
1155 | 81.1k | MacroBuilder Builder(Predefines); |
1156 | | |
1157 | | // Emit line markers for various builtin sections of the file. We don't do |
1158 | | // this in asm preprocessor mode, because "# 4" is not a line marker directive |
1159 | | // in this mode. |
1160 | 81.1k | if (!PP.getLangOpts().AsmPreprocessor) |
1161 | 81.0k | Builder.append("# 1 \"<built-in>\" 3"); |
1162 | | |
1163 | | // Install things like __POWERPC__, __GNUC__, etc into the macro table. |
1164 | 81.1k | if (InitOpts.UsePredefines) { |
1165 | | // FIXME: This will create multiple definitions for most of the predefined |
1166 | | // macros. This is not the right way to handle this. |
1167 | 81.1k | if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice80.7k || LangOpts.SYCLIsDevice79.9k ) && |
1168 | 1.14k | PP.getAuxTargetInfo()) |
1169 | 138 | InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts, |
1170 | 138 | PP.getPreprocessorOpts(), Builder); |
1171 | | |
1172 | 81.1k | InitializePredefinedMacros(PP.getTargetInfo(), LangOpts, FEOpts, |
1173 | 81.1k | PP.getPreprocessorOpts(), Builder); |
1174 | | |
1175 | | // Install definitions to make Objective-C++ ARC work well with various |
1176 | | // C++ Standard Library implementations. |
1177 | 81.1k | if (LangOpts.ObjC && LangOpts.CPlusPlus19.8k && |
1178 | 14.4k | (LangOpts.ObjCAutoRefCount || LangOpts.ObjCWeak13.0k )) { |
1179 | 1.46k | switch (InitOpts.ObjCXXARCStandardLibrary) { |
1180 | 134 | case ARCXX_nolib: |
1181 | 1.45k | case ARCXX_libcxx: |
1182 | 1.45k | break; |
1183 | | |
1184 | 8 | case ARCXX_libstdcxx: |
1185 | 8 | AddObjCXXARCLibstdcxxDefines(LangOpts, Builder); |
1186 | 8 | break; |
1187 | 81.1k | } |
1188 | 81.1k | } |
1189 | 81.1k | } |
1190 | | |
1191 | | // Even with predefines off, some macros are still predefined. |
1192 | | // These should all be defined in the preprocessor according to the |
1193 | | // current language configuration. |
1194 | 81.1k | InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(), |
1195 | 81.1k | FEOpts, Builder); |
1196 | | |
1197 | | // Add on the predefines from the driver. Wrap in a #line directive to report |
1198 | | // that they come from the command line. |
1199 | 81.1k | if (!PP.getLangOpts().AsmPreprocessor) |
1200 | 81.0k | Builder.append("# 1 \"<command line>\" 1"); |
1201 | | |
1202 | | // Process #define's and #undef's in the order they are given. |
1203 | 393k | for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i312k ) { |
1204 | 312k | if (InitOpts.Macros[i].second) // isUndef |
1205 | 49 | Builder.undefineMacro(InitOpts.Macros[i].first); |
1206 | 312k | else |
1207 | 312k | DefineBuiltinMacro(Builder, InitOpts.Macros[i].first, |
1208 | 312k | PP.getDiagnostics()); |
1209 | 312k | } |
1210 | | |
1211 | | // Exit the command line and go back to <built-in> (2 is LC_LEAVE). |
1212 | 81.1k | if (!PP.getLangOpts().AsmPreprocessor) |
1213 | 81.0k | Builder.append("# 1 \"<built-in>\" 2"); |
1214 | | |
1215 | | // If -imacros are specified, include them now. These are processed before |
1216 | | // any -include directives. |
1217 | 81.1k | for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i2 ) |
1218 | 2 | AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]); |
1219 | | |
1220 | | // Process -include-pch/-include-pth directives. |
1221 | 81.1k | if (!InitOpts.ImplicitPCHInclude.empty()) |
1222 | 3.53k | AddImplicitIncludePCH(Builder, PP, PCHContainerRdr, |
1223 | 3.53k | InitOpts.ImplicitPCHInclude); |
1224 | | |
1225 | | // Process -include directives. |
1226 | 84.4k | for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i3.35k ) { |
1227 | 3.35k | const std::string &Path = InitOpts.Includes[i]; |
1228 | 3.35k | AddImplicitInclude(Builder, Path); |
1229 | 3.35k | } |
1230 | | |
1231 | | // Instruct the preprocessor to skip the preamble. |
1232 | 81.1k | PP.setSkipMainFilePreamble(InitOpts.PrecompiledPreambleBytes.first, |
1233 | 81.1k | InitOpts.PrecompiledPreambleBytes.second); |
1234 | | |
1235 | | // Copy PredefinedBuffer into the Preprocessor. |
1236 | 81.1k | PP.setPredefines(Predefines.str()); |
1237 | 81.1k | } |