clang  8.0.0svn
OSTargets.h
Go to the documentation of this file.
1 //===--- OSTargets.h - Declare OS target feature support --------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares OS specific TargetInfo types.
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
15 
16 #include "Targets.h"
17 #include "llvm/MC/MCSectionMachO.h"
18 
19 namespace clang {
20 namespace targets {
21 
22 template <typename TgtInfo>
23 class LLVM_LIBRARY_VISIBILITY OSTargetInfo : public TgtInfo {
24 protected:
25  virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
26  MacroBuilder &Builder) const = 0;
27 
28 public:
29  OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
30  : TgtInfo(Triple, Opts) {}
31 
32  void getTargetDefines(const LangOptions &Opts,
33  MacroBuilder &Builder) const override {
34  TgtInfo::getTargetDefines(Opts, Builder);
35  getOSDefines(Opts, TgtInfo::getTriple(), Builder);
36  }
37 };
38 
39 // CloudABI Target
40 template <typename Target>
41 class LLVM_LIBRARY_VISIBILITY CloudABITargetInfo : public OSTargetInfo<Target> {
42 protected:
43  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
44  MacroBuilder &Builder) const override {
45  Builder.defineMacro("__CloudABI__");
46  Builder.defineMacro("__ELF__");
47 
48  // CloudABI uses ISO/IEC 10646:2012 for wchar_t, char16_t and char32_t.
49  Builder.defineMacro("__STDC_ISO_10646__", "201206L");
50  Builder.defineMacro("__STDC_UTF_16__");
51  Builder.defineMacro("__STDC_UTF_32__");
52  }
53 
54 public:
55  CloudABITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
56  : OSTargetInfo<Target>(Triple, Opts) {}
57 };
58 
59 // Ananas target
60 template <typename Target>
61 class LLVM_LIBRARY_VISIBILITY AnanasTargetInfo : public OSTargetInfo<Target> {
62 protected:
63  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
64  MacroBuilder &Builder) const override {
65  // Ananas defines
66  Builder.defineMacro("__Ananas__");
67  Builder.defineMacro("__ELF__");
68  }
69 
70 public:
71  AnanasTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
72  : OSTargetInfo<Target>(Triple, Opts) {}
73 };
74 
75 void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
76  const llvm::Triple &Triple, StringRef &PlatformName,
77  VersionTuple &PlatformMinVersion);
78 
79 template <typename Target>
80 class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public OSTargetInfo<Target> {
81 protected:
82  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
83  MacroBuilder &Builder) const override {
84  getDarwinDefines(Builder, Opts, Triple, this->PlatformName,
85  this->PlatformMinVersion);
86  }
87 
88 public:
89  DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
90  : OSTargetInfo<Target>(Triple, Opts) {
91  // By default, no TLS, and we whitelist permitted architecture/OS
92  // combinations.
93  this->TLSSupported = false;
94 
95  if (Triple.isMacOSX())
96  this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7);
97  else if (Triple.isiOS()) {
98  // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
99  // 32-bit simulator from 10 onwards.
100  if (Triple.isArch64Bit())
101  this->TLSSupported = !Triple.isOSVersionLT(8);
102  else if (Triple.isArch32Bit()) {
103  if (!Triple.isSimulatorEnvironment())
104  this->TLSSupported = !Triple.isOSVersionLT(9);
105  else
106  this->TLSSupported = !Triple.isOSVersionLT(10);
107  }
108  } else if (Triple.isWatchOS()) {
109  if (!Triple.isSimulatorEnvironment())
110  this->TLSSupported = !Triple.isOSVersionLT(2);
111  else
112  this->TLSSupported = !Triple.isOSVersionLT(3);
113  }
114 
115  this->MCountName = "\01mcount";
116  }
117 
118  std::string isValidSectionSpecifier(StringRef SR) const override {
119  // Let MCSectionMachO validate this.
120  StringRef Segment, Section;
121  unsigned TAA, StubSize;
122  bool HasTAA;
123  return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
124  TAA, HasTAA, StubSize);
125  }
126 
127  const char *getStaticInitSectionSpecifier() const override {
128  // FIXME: We should return 0 when building kexts.
129  return "__TEXT,__StaticInit,regular,pure_instructions";
130  }
131 
132  /// Darwin does not support protected visibility. Darwin's "default"
133  /// is very similar to ELF's "protected"; Darwin requires a "weak"
134  /// attribute on declarations that can be dynamically replaced.
135  bool hasProtectedVisibility() const override { return false; }
136 };
137 
138 // DragonFlyBSD Target
139 template <typename Target>
140 class LLVM_LIBRARY_VISIBILITY DragonFlyBSDTargetInfo
141  : public OSTargetInfo<Target> {
142 protected:
143  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
144  MacroBuilder &Builder) const override {
145  // DragonFly defines; list based off of gcc output
146  Builder.defineMacro("__DragonFly__");
147  Builder.defineMacro("__DragonFly_cc_version", "100001");
148  Builder.defineMacro("__ELF__");
149  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
150  Builder.defineMacro("__tune_i386__");
151  DefineStd(Builder, "unix", Opts);
152  }
153 
154 public:
155  DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
156  : OSTargetInfo<Target>(Triple, Opts) {
157  switch (Triple.getArch()) {
158  default:
159  case llvm::Triple::x86:
160  case llvm::Triple::x86_64:
161  this->MCountName = ".mcount";
162  break;
163  }
164  }
165 };
166 
167 #ifndef FREEBSD_CC_VERSION
168 #define FREEBSD_CC_VERSION 0U
169 #endif
170 
171 // FreeBSD Target
172 template <typename Target>
173 class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo<Target> {
174 protected:
175  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
176  MacroBuilder &Builder) const override {
177  // FreeBSD defines; list based off of gcc output
178 
179  unsigned Release = Triple.getOSMajorVersion();
180  if (Release == 0U)
181  Release = 8U;
182  unsigned CCVersion = FREEBSD_CC_VERSION;
183  if (CCVersion == 0U)
184  CCVersion = Release * 100000U + 1U;
185 
186  Builder.defineMacro("__FreeBSD__", Twine(Release));
187  Builder.defineMacro("__FreeBSD_cc_version", Twine(CCVersion));
188  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
189  DefineStd(Builder, "unix", Opts);
190  Builder.defineMacro("__ELF__");
191 
192  // On FreeBSD, wchar_t contains the number of the code point as
193  // used by the character set of the locale. These character sets are
194  // not necessarily a superset of ASCII.
195  //
196  // FIXME: This is wrong; the macro refers to the numerical values
197  // of wchar_t *literals*, which are not locale-dependent. However,
198  // FreeBSD systems apparently depend on us getting this wrong, and
199  // setting this to 1 is conforming even if all the basic source
200  // character literals have the same encoding as char and wchar_t.
201  Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
202  }
203 
204 public:
205  FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
206  : OSTargetInfo<Target>(Triple, Opts) {
207  switch (Triple.getArch()) {
208  default:
209  case llvm::Triple::x86:
210  case llvm::Triple::x86_64:
211  this->MCountName = ".mcount";
212  break;
213  case llvm::Triple::mips:
214  case llvm::Triple::mipsel:
215  case llvm::Triple::ppc:
216  case llvm::Triple::ppc64:
217  case llvm::Triple::ppc64le:
218  this->MCountName = "_mcount";
219  break;
220  case llvm::Triple::arm:
221  this->MCountName = "__mcount";
222  break;
223  }
224  }
225 };
226 
227 // GNU/kFreeBSD Target
228 template <typename Target>
229 class LLVM_LIBRARY_VISIBILITY KFreeBSDTargetInfo : public OSTargetInfo<Target> {
230 protected:
231  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
232  MacroBuilder &Builder) const override {
233  // GNU/kFreeBSD defines; list based off of gcc output
234 
235  DefineStd(Builder, "unix", Opts);
236  Builder.defineMacro("__FreeBSD_kernel__");
237  Builder.defineMacro("__GLIBC__");
238  Builder.defineMacro("__ELF__");
239  if (Opts.POSIXThreads)
240  Builder.defineMacro("_REENTRANT");
241  if (Opts.CPlusPlus)
242  Builder.defineMacro("_GNU_SOURCE");
243  }
244 
245 public:
246  KFreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
247  : OSTargetInfo<Target>(Triple, Opts) {}
248 };
249 
250 // Haiku Target
251 template <typename Target>
252 class LLVM_LIBRARY_VISIBILITY HaikuTargetInfo : public OSTargetInfo<Target> {
253 protected:
254  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
255  MacroBuilder &Builder) const override {
256  // Haiku defines; list based off of gcc output
257  Builder.defineMacro("__HAIKU__");
258  Builder.defineMacro("__ELF__");
259  DefineStd(Builder, "unix", Opts);
260  }
261 
262 public:
263  HaikuTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
264  : OSTargetInfo<Target>(Triple, Opts) {
265  this->SizeType = TargetInfo::UnsignedLong;
266  this->IntPtrType = TargetInfo::SignedLong;
267  this->PtrDiffType = TargetInfo::SignedLong;
268  this->ProcessIDType = TargetInfo::SignedLong;
269  this->TLSSupported = false;
270  }
271 };
272 
273 // Minix Target
274 template <typename Target>
275 class LLVM_LIBRARY_VISIBILITY MinixTargetInfo : public OSTargetInfo<Target> {
276 protected:
277  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
278  MacroBuilder &Builder) const override {
279  // Minix defines
280 
281  Builder.defineMacro("__minix", "3");
282  Builder.defineMacro("_EM_WSIZE", "4");
283  Builder.defineMacro("_EM_PSIZE", "4");
284  Builder.defineMacro("_EM_SSIZE", "2");
285  Builder.defineMacro("_EM_LSIZE", "4");
286  Builder.defineMacro("_EM_FSIZE", "4");
287  Builder.defineMacro("_EM_DSIZE", "8");
288  Builder.defineMacro("__ELF__");
289  DefineStd(Builder, "unix", Opts);
290  }
291 
292 public:
293  MinixTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
294  : OSTargetInfo<Target>(Triple, Opts) {}
295 };
296 
297 // Linux target
298 template <typename Target>
299 class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public OSTargetInfo<Target> {
300 protected:
301  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
302  MacroBuilder &Builder) const override {
303  // Linux defines; list based off of gcc output
304  DefineStd(Builder, "unix", Opts);
305  DefineStd(Builder, "linux", Opts);
306  Builder.defineMacro("__gnu_linux__");
307  Builder.defineMacro("__ELF__");
308  if (Triple.isAndroid()) {
309  Builder.defineMacro("__ANDROID__", "1");
310  unsigned Maj, Min, Rev;
311  Triple.getEnvironmentVersion(Maj, Min, Rev);
312  this->PlatformName = "android";
313  this->PlatformMinVersion = VersionTuple(Maj, Min, Rev);
314  if (Maj)
315  Builder.defineMacro("__ANDROID_API__", Twine(Maj));
316  }
317  if (Opts.POSIXThreads)
318  Builder.defineMacro("_REENTRANT");
319  if (Opts.CPlusPlus)
320  Builder.defineMacro("_GNU_SOURCE");
321  if (this->HasFloat128)
322  Builder.defineMacro("__FLOAT128__");
323  }
324 
325 public:
326  LinuxTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
327  : OSTargetInfo<Target>(Triple, Opts) {
328  this->WIntType = TargetInfo::UnsignedInt;
329 
330  switch (Triple.getArch()) {
331  default:
332  break;
333  case llvm::Triple::mips:
334  case llvm::Triple::mipsel:
335  case llvm::Triple::mips64:
336  case llvm::Triple::mips64el:
337  case llvm::Triple::ppc:
338  case llvm::Triple::ppc64:
339  case llvm::Triple::ppc64le:
340  this->MCountName = "_mcount";
341  break;
342  case llvm::Triple::x86:
343  case llvm::Triple::x86_64:
344  case llvm::Triple::systemz:
345  this->HasFloat128 = true;
346  break;
347  }
348  }
349 
350  const char *getStaticInitSectionSpecifier() const override {
351  return ".text.startup";
352  }
353 };
354 
355 // NetBSD Target
356 template <typename Target>
357 class LLVM_LIBRARY_VISIBILITY NetBSDTargetInfo : public OSTargetInfo<Target> {
358 protected:
359  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
360  MacroBuilder &Builder) const override {
361  // NetBSD defines; list based off of gcc output
362  Builder.defineMacro("__NetBSD__");
363  Builder.defineMacro("__unix__");
364  Builder.defineMacro("__ELF__");
365  if (Opts.POSIXThreads)
366  Builder.defineMacro("_REENTRANT");
367  }
368 
369 public:
370  NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
371  : OSTargetInfo<Target>(Triple, Opts) {
372  this->MCountName = "__mcount";
373  }
374 };
375 
376 // OpenBSD Target
377 template <typename Target>
378 class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
379 protected:
380  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
381  MacroBuilder &Builder) const override {
382  // OpenBSD defines; list based off of gcc output
383 
384  Builder.defineMacro("__OpenBSD__");
385  DefineStd(Builder, "unix", Opts);
386  Builder.defineMacro("__ELF__");
387  if (Opts.POSIXThreads)
388  Builder.defineMacro("_REENTRANT");
389  if (this->HasFloat128)
390  Builder.defineMacro("__FLOAT128__");
391  }
392 
393 public:
394  OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
395  : OSTargetInfo<Target>(Triple, Opts) {
396  switch (Triple.getArch()) {
397  case llvm::Triple::x86:
398  case llvm::Triple::x86_64:
399  this->HasFloat128 = true;
400  // FALLTHROUGH
401  default:
402  this->MCountName = "__mcount";
403  break;
404  case llvm::Triple::mips64:
405  case llvm::Triple::mips64el:
406  case llvm::Triple::ppc:
407  case llvm::Triple::sparcv9:
408  this->MCountName = "_mcount";
409  break;
410  }
411  }
412 };
413 
414 // PSP Target
415 template <typename Target>
416 class LLVM_LIBRARY_VISIBILITY PSPTargetInfo : public OSTargetInfo<Target> {
417 protected:
418  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
419  MacroBuilder &Builder) const override {
420  // PSP defines; list based on the output of the pspdev gcc toolchain.
421  Builder.defineMacro("PSP");
422  Builder.defineMacro("_PSP");
423  Builder.defineMacro("__psp__");
424  Builder.defineMacro("__ELF__");
425  }
426 
427 public:
428  PSPTargetInfo(const llvm::Triple &Triple) : OSTargetInfo<Target>(Triple) {}
429 };
430 
431 // PS3 PPU Target
432 template <typename Target>
433 class LLVM_LIBRARY_VISIBILITY PS3PPUTargetInfo : public OSTargetInfo<Target> {
434 protected:
435  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
436  MacroBuilder &Builder) const override {
437  // PS3 PPU defines.
438  Builder.defineMacro("__PPC__");
439  Builder.defineMacro("__PPU__");
440  Builder.defineMacro("__CELLOS_LV2__");
441  Builder.defineMacro("__ELF__");
442  Builder.defineMacro("__LP32__");
443  Builder.defineMacro("_ARCH_PPC64");
444  Builder.defineMacro("__powerpc64__");
445  }
446 
447 public:
448  PS3PPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
449  : OSTargetInfo<Target>(Triple, Opts) {
450  this->LongWidth = this->LongAlign = 32;
451  this->PointerWidth = this->PointerAlign = 32;
452  this->IntMaxType = TargetInfo::SignedLongLong;
453  this->Int64Type = TargetInfo::SignedLongLong;
454  this->SizeType = TargetInfo::UnsignedInt;
455  this->resetDataLayout("E-m:e-p:32:32-i64:64-n32:64");
456  }
457 };
458 
459 template <typename Target>
460 class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public OSTargetInfo<Target> {
461 protected:
462  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
463  MacroBuilder &Builder) const override {
464  Builder.defineMacro("__FreeBSD__", "9");
465  Builder.defineMacro("__FreeBSD_cc_version", "900001");
466  Builder.defineMacro("__KPRINTF_ATTRIBUTE__");
467  DefineStd(Builder, "unix", Opts);
468  Builder.defineMacro("__ELF__");
469  Builder.defineMacro("__ORBIS__");
470  }
471 
472 public:
473  PS4OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
474  : OSTargetInfo<Target>(Triple, Opts) {
475  this->WCharType = TargetInfo::UnsignedShort;
476 
477  // On PS4, TLS variable cannot be aligned to more than 32 bytes (256 bits).
478  this->MaxTLSAlign = 256;
479 
480  // On PS4, do not honor explicit bit field alignment,
481  // as in "__attribute__((aligned(2))) int b : 1;".
482  this->UseExplicitBitFieldAlignment = false;
483 
484  switch (Triple.getArch()) {
485  default:
486  case llvm::Triple::x86_64:
487  this->MCountName = ".mcount";
488  this->NewAlign = 256;
489  break;
490  }
491  }
492 };
493 
494 // RTEMS Target
495 template <typename Target>
496 class LLVM_LIBRARY_VISIBILITY RTEMSTargetInfo : public OSTargetInfo<Target> {
497 protected:
498  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
499  MacroBuilder &Builder) const override {
500  // RTEMS defines; list based off of gcc output
501 
502  Builder.defineMacro("__rtems__");
503  Builder.defineMacro("__ELF__");
504  if (Opts.CPlusPlus)
505  Builder.defineMacro("_GNU_SOURCE");
506  }
507 
508 public:
509  RTEMSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
510  : OSTargetInfo<Target>(Triple, Opts) {
511  switch (Triple.getArch()) {
512  default:
513  case llvm::Triple::x86:
514  // this->MCountName = ".mcount";
515  break;
516  case llvm::Triple::mips:
517  case llvm::Triple::mipsel:
518  case llvm::Triple::ppc:
519  case llvm::Triple::ppc64:
520  case llvm::Triple::ppc64le:
521  // this->MCountName = "_mcount";
522  break;
523  case llvm::Triple::arm:
524  // this->MCountName = "__mcount";
525  break;
526  }
527  }
528 };
529 
530 // Solaris target
531 template <typename Target>
532 class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo : public OSTargetInfo<Target> {
533 protected:
534  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
535  MacroBuilder &Builder) const override {
536  DefineStd(Builder, "sun", Opts);
537  DefineStd(Builder, "unix", Opts);
538  Builder.defineMacro("__ELF__");
539  Builder.defineMacro("__svr4__");
540  Builder.defineMacro("__SVR4");
541  // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
542  // newer, but to 500 for everything else. feature_test.h has a check to
543  // ensure that you are not using C99 with an old version of X/Open or C89
544  // with a new version.
545  if (Opts.C99)
546  Builder.defineMacro("_XOPEN_SOURCE", "600");
547  else
548  Builder.defineMacro("_XOPEN_SOURCE", "500");
549  if (Opts.CPlusPlus)
550  Builder.defineMacro("__C99FEATURES__");
551  Builder.defineMacro("_LARGEFILE_SOURCE");
552  Builder.defineMacro("_LARGEFILE64_SOURCE");
553  Builder.defineMacro("__EXTENSIONS__");
554  if (Opts.POSIXThreads)
555  Builder.defineMacro("_REENTRANT");
556  if (this->HasFloat128)
557  Builder.defineMacro("__FLOAT128__");
558  }
559 
560 public:
561  SolarisTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
562  : OSTargetInfo<Target>(Triple, Opts) {
563  // FIXME: WIntType should be SignedLong
564  switch (Triple.getArch()) {
565  default:
566  break;
567  case llvm::Triple::x86:
568  case llvm::Triple::x86_64:
569  this->HasFloat128 = true;
570  break;
571  }
572  }
573 };
574 
575 // Windows target
576 template <typename Target>
577 class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
578 protected:
579  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
580  MacroBuilder &Builder) const override {
581  Builder.defineMacro("_WIN32");
582  if (Triple.isArch64Bit())
583  Builder.defineMacro("_WIN64");
584  if (Triple.isWindowsGNUEnvironment())
585  addMinGWDefines(Triple, Opts, Builder);
586 
587  }
589  MacroBuilder &Builder) const {
590  if (Opts.CPlusPlus) {
591  if (Opts.RTTIData)
592  Builder.defineMacro("_CPPRTTI");
593 
594  if (Opts.CXXExceptions)
595  Builder.defineMacro("_CPPUNWIND");
596  }
597 
598  if (Opts.Bool)
599  Builder.defineMacro("__BOOL_DEFINED");
600 
601  if (!Opts.CharIsSigned)
602  Builder.defineMacro("_CHAR_UNSIGNED");
603 
604  // FIXME: POSIXThreads isn't exactly the option this should be defined for,
605  // but it works for now.
606  if (Opts.POSIXThreads)
607  Builder.defineMacro("_MT");
608 
609  if (Opts.MSCompatibilityVersion) {
610  Builder.defineMacro("_MSC_VER",
611  Twine(Opts.MSCompatibilityVersion / 100000));
612  Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
613  // FIXME We cannot encode the revision information into 32-bits
614  Builder.defineMacro("_MSC_BUILD", Twine(1));
615 
616  if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
617  Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
618 
620  if (Opts.CPlusPlus2a)
621  Builder.defineMacro("_MSVC_LANG", "201704L");
622  else if (Opts.CPlusPlus17)
623  Builder.defineMacro("_MSVC_LANG", "201703L");
624  else if (Opts.CPlusPlus14)
625  Builder.defineMacro("_MSVC_LANG", "201402L");
626  }
627  }
628 
629  if (Opts.MicrosoftExt) {
630  Builder.defineMacro("_MSC_EXTENSIONS");
631 
632  if (Opts.CPlusPlus11) {
633  Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
634  Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
635  Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
636  }
637  }
638 
639  Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
640  }
641 
642 public:
643  WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
644  : OSTargetInfo<Target>(Triple, Opts) {
645  this->WCharType = TargetInfo::UnsignedShort;
646  }
647 };
648 
649 template <typename Target>
650 class LLVM_LIBRARY_VISIBILITY NaClTargetInfo : public OSTargetInfo<Target> {
651 protected:
652  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
653  MacroBuilder &Builder) const override {
654  if (Opts.POSIXThreads)
655  Builder.defineMacro("_REENTRANT");
656  if (Opts.CPlusPlus)
657  Builder.defineMacro("_GNU_SOURCE");
658 
659  DefineStd(Builder, "unix", Opts);
660  Builder.defineMacro("__ELF__");
661  Builder.defineMacro("__native_client__");
662  }
663 
664 public:
665  NaClTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
666  : OSTargetInfo<Target>(Triple, Opts) {
667  this->LongAlign = 32;
668  this->LongWidth = 32;
669  this->PointerAlign = 32;
670  this->PointerWidth = 32;
671  this->IntMaxType = TargetInfo::SignedLongLong;
672  this->Int64Type = TargetInfo::SignedLongLong;
673  this->DoubleAlign = 64;
674  this->LongDoubleWidth = 64;
675  this->LongDoubleAlign = 64;
676  this->LongLongWidth = 64;
677  this->LongLongAlign = 64;
678  this->SizeType = TargetInfo::UnsignedInt;
679  this->PtrDiffType = TargetInfo::SignedInt;
680  this->IntPtrType = TargetInfo::SignedInt;
681  // RegParmMax is inherited from the underlying architecture.
682  this->LongDoubleFormat = &llvm::APFloat::IEEEdouble();
683  if (Triple.getArch() == llvm::Triple::arm) {
684  // Handled in ARM's setABI().
685  } else if (Triple.getArch() == llvm::Triple::x86) {
686  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32-S128");
687  } else if (Triple.getArch() == llvm::Triple::x86_64) {
688  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32:64-S128");
689  } else if (Triple.getArch() == llvm::Triple::mipsel) {
690  // Handled on mips' setDataLayout.
691  } else {
692  assert(Triple.getArch() == llvm::Triple::le32);
693  this->resetDataLayout("e-p:32:32-i64:64");
694  }
695  }
696 };
697 
698 // Fuchsia Target
699 template <typename Target>
700 class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo : public OSTargetInfo<Target> {
701 protected:
702  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
703  MacroBuilder &Builder) const override {
704  Builder.defineMacro("__Fuchsia__");
705  Builder.defineMacro("__ELF__");
706  if (Opts.POSIXThreads)
707  Builder.defineMacro("_REENTRANT");
708  // Required by the libc++ locale support.
709  if (Opts.CPlusPlus)
710  Builder.defineMacro("_GNU_SOURCE");
711  }
712 
713 public:
714  FuchsiaTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
715  : OSTargetInfo<Target>(Triple, Opts) {
716  this->MCountName = "__mcount";
717  }
718 };
719 
720 // WebAssembly target
721 template <typename Target>
722 class LLVM_LIBRARY_VISIBILITY WebAssemblyOSTargetInfo
723  : public OSTargetInfo<Target> {
724  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
725  MacroBuilder &Builder) const final {
726  // A common platform macro.
727  if (Opts.POSIXThreads)
728  Builder.defineMacro("_REENTRANT");
729  // Follow g++ convention and predefine _GNU_SOURCE for C++.
730  if (Opts.CPlusPlus)
731  Builder.defineMacro("_GNU_SOURCE");
732  }
733 
734 public:
735  explicit WebAssemblyOSTargetInfo(const llvm::Triple &Triple,
736  const TargetOptions &Opts)
737  : OSTargetInfo<Target>(Triple, Opts) {
738  this->MCountName = "__mcount";
739  this->TheCXXABI.set(TargetCXXABI::WebAssembly);
740  }
741 };
742 
743 } // namespace targets
744 } // namespace clang
745 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
PSPTargetInfo(const llvm::Triple &Triple)
Definition: OSTargets.h:428
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:43
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:55
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:254
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:245
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:702
WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:643
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:82
const char * getStaticInitSectionSpecifier() const override
Definition: OSTargets.h:127
Options for controlling the target.
Definition: TargetOptions.h:26
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:435
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:579
WebAssemblyOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:735
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:175
LinuxTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:326
bool hasProtectedVisibility() const override
Darwin does not support protected visibility.
Definition: OSTargets.h:135
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
RTEMSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:509
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:63
AnanasTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:71
NaClTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:665
const char * getStaticInitSectionSpecifier() const override
Definition: OSTargets.h:350
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:301
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:231
void addMinGWDefines(const llvm::Triple &Triple, const LangOptions &Opts, MacroBuilder &Builder)
Definition: Targets.cpp:102
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:143
std::string isValidSectionSpecifier(StringRef SR) const override
Definition: OSTargets.h:118
KFreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:246
SolarisTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:561
void getVisualStudioDefines(const LangOptions &Opts, MacroBuilder &Builder) const
Definition: OSTargets.h:588
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
Definition: OSTargets.h:32
DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:89
HaikuTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:263
DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:155
FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:205
void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, const llvm::Triple &Triple, StringRef &PlatformName, VersionTuple &PlatformMinVersion)
Definition: OSTargets.cpp:23
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:462
#define FREEBSD_CC_VERSION
Definition: OSTargets.h:168
FuchsiaTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:714
CloudABITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:55
The WebAssembly ABI is a modified version of the Itanium ABI.
Definition: TargetCXXABI.h:105
Dataflow Directional Tag Classes.
PS4OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:473
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:498
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:277
NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:370
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:359
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:652
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:418
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:534
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:380
MinixTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:293
OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:29
void defineMacro(const Twine &Name, const Twine &Value="1")
Append a #define line for macro of the form "\#define Name Value\n".
Definition: MacroBuilder.h:30
OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:394
PS3PPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:448