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