clang  7.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  break;
489  }
490  }
491 };
492 
493 // RTEMS Target
494 template <typename Target>
495 class LLVM_LIBRARY_VISIBILITY RTEMSTargetInfo : public OSTargetInfo<Target> {
496 protected:
497  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
498  MacroBuilder &Builder) const override {
499  // RTEMS defines; list based off of gcc output
500 
501  Builder.defineMacro("__rtems__");
502  Builder.defineMacro("__ELF__");
503  if (Opts.CPlusPlus)
504  Builder.defineMacro("_GNU_SOURCE");
505  }
506 
507 public:
508  RTEMSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
509  : OSTargetInfo<Target>(Triple, Opts) {
510  switch (Triple.getArch()) {
511  default:
512  case llvm::Triple::x86:
513  // this->MCountName = ".mcount";
514  break;
515  case llvm::Triple::mips:
516  case llvm::Triple::mipsel:
517  case llvm::Triple::ppc:
518  case llvm::Triple::ppc64:
519  case llvm::Triple::ppc64le:
520  // this->MCountName = "_mcount";
521  break;
522  case llvm::Triple::arm:
523  // this->MCountName = "__mcount";
524  break;
525  }
526  }
527 };
528 
529 // Solaris target
530 template <typename Target>
531 class LLVM_LIBRARY_VISIBILITY SolarisTargetInfo : public OSTargetInfo<Target> {
532 protected:
533  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
534  MacroBuilder &Builder) const override {
535  DefineStd(Builder, "sun", Opts);
536  DefineStd(Builder, "unix", Opts);
537  Builder.defineMacro("__ELF__");
538  Builder.defineMacro("__svr4__");
539  Builder.defineMacro("__SVR4");
540  // Solaris headers require _XOPEN_SOURCE to be set to 600 for C99 and
541  // newer, but to 500 for everything else. feature_test.h has a check to
542  // ensure that you are not using C99 with an old version of X/Open or C89
543  // with a new version.
544  if (Opts.C99)
545  Builder.defineMacro("_XOPEN_SOURCE", "600");
546  else
547  Builder.defineMacro("_XOPEN_SOURCE", "500");
548  if (Opts.CPlusPlus)
549  Builder.defineMacro("__C99FEATURES__");
550  Builder.defineMacro("_LARGEFILE_SOURCE");
551  Builder.defineMacro("_LARGEFILE64_SOURCE");
552  Builder.defineMacro("__EXTENSIONS__");
553  Builder.defineMacro("_REENTRANT");
554  }
555 
556 public:
557  SolarisTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
558  : OSTargetInfo<Target>(Triple, Opts) {
559  // FIXME: WIntType should be SignedLong
560  }
561 };
562 
563 // Windows target
564 template <typename Target>
565 class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
566 protected:
567  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
568  MacroBuilder &Builder) const override {
569  Builder.defineMacro("_WIN32");
570  if (Triple.isArch64Bit())
571  Builder.defineMacro("_WIN64");
572  if (Triple.isWindowsGNUEnvironment())
573  addMinGWDefines(Triple, Opts, Builder);
574 
575  }
577  MacroBuilder &Builder) const {
578  if (Opts.CPlusPlus) {
579  if (Opts.RTTIData)
580  Builder.defineMacro("_CPPRTTI");
581 
582  if (Opts.CXXExceptions)
583  Builder.defineMacro("_CPPUNWIND");
584  }
585 
586  if (Opts.Bool)
587  Builder.defineMacro("__BOOL_DEFINED");
588 
589  if (!Opts.CharIsSigned)
590  Builder.defineMacro("_CHAR_UNSIGNED");
591 
592  // FIXME: POSIXThreads isn't exactly the option this should be defined for,
593  // but it works for now.
594  if (Opts.POSIXThreads)
595  Builder.defineMacro("_MT");
596 
597  if (Opts.MSCompatibilityVersion) {
598  Builder.defineMacro("_MSC_VER",
599  Twine(Opts.MSCompatibilityVersion / 100000));
600  Builder.defineMacro("_MSC_FULL_VER", Twine(Opts.MSCompatibilityVersion));
601  // FIXME We cannot encode the revision information into 32-bits
602  Builder.defineMacro("_MSC_BUILD", Twine(1));
603 
604  if (Opts.CPlusPlus11 && Opts.isCompatibleWithMSVC(LangOptions::MSVC2015))
605  Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", Twine(1));
606 
608  if (Opts.CPlusPlus17)
609  Builder.defineMacro("_MSVC_LANG", "201403L");
610  else if (Opts.CPlusPlus14)
611  Builder.defineMacro("_MSVC_LANG", "201402L");
612  }
613  }
614 
615  if (Opts.MicrosoftExt) {
616  Builder.defineMacro("_MSC_EXTENSIONS");
617 
618  if (Opts.CPlusPlus11) {
619  Builder.defineMacro("_RVALUE_REFERENCES_V2_SUPPORTED");
620  Builder.defineMacro("_RVALUE_REFERENCES_SUPPORTED");
621  Builder.defineMacro("_NATIVE_NULLPTR_SUPPORTED");
622  }
623  }
624 
625  Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
626  }
627 
628 public:
629  WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
630  : OSTargetInfo<Target>(Triple, Opts) {
631  this->WCharType = TargetInfo::UnsignedShort;
632  }
633 };
634 
635 template <typename Target>
636 class LLVM_LIBRARY_VISIBILITY NaClTargetInfo : public OSTargetInfo<Target> {
637 protected:
638  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
639  MacroBuilder &Builder) const override {
640  if (Opts.POSIXThreads)
641  Builder.defineMacro("_REENTRANT");
642  if (Opts.CPlusPlus)
643  Builder.defineMacro("_GNU_SOURCE");
644 
645  DefineStd(Builder, "unix", Opts);
646  Builder.defineMacro("__ELF__");
647  Builder.defineMacro("__native_client__");
648  }
649 
650 public:
651  NaClTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
652  : OSTargetInfo<Target>(Triple, Opts) {
653  this->LongAlign = 32;
654  this->LongWidth = 32;
655  this->PointerAlign = 32;
656  this->PointerWidth = 32;
657  this->IntMaxType = TargetInfo::SignedLongLong;
658  this->Int64Type = TargetInfo::SignedLongLong;
659  this->DoubleAlign = 64;
660  this->LongDoubleWidth = 64;
661  this->LongDoubleAlign = 64;
662  this->LongLongWidth = 64;
663  this->LongLongAlign = 64;
664  this->SizeType = TargetInfo::UnsignedInt;
665  this->PtrDiffType = TargetInfo::SignedInt;
666  this->IntPtrType = TargetInfo::SignedInt;
667  // RegParmMax is inherited from the underlying architecture.
668  this->LongDoubleFormat = &llvm::APFloat::IEEEdouble();
669  if (Triple.getArch() == llvm::Triple::arm) {
670  // Handled in ARM's setABI().
671  } else if (Triple.getArch() == llvm::Triple::x86) {
672  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32-S128");
673  } else if (Triple.getArch() == llvm::Triple::x86_64) {
674  this->resetDataLayout("e-m:e-p:32:32-i64:64-n8:16:32:64-S128");
675  } else if (Triple.getArch() == llvm::Triple::mipsel) {
676  // Handled on mips' setDataLayout.
677  } else {
678  assert(Triple.getArch() == llvm::Triple::le32);
679  this->resetDataLayout("e-p:32:32-i64:64");
680  }
681  }
682 };
683 
684 // Fuchsia Target
685 template <typename Target>
686 class LLVM_LIBRARY_VISIBILITY FuchsiaTargetInfo : public OSTargetInfo<Target> {
687 protected:
688  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
689  MacroBuilder &Builder) const override {
690  Builder.defineMacro("__Fuchsia__");
691  Builder.defineMacro("__ELF__");
692  if (Opts.POSIXThreads)
693  Builder.defineMacro("_REENTRANT");
694  // Required by the libc++ locale support.
695  if (Opts.CPlusPlus)
696  Builder.defineMacro("_GNU_SOURCE");
697  }
698 
699 public:
700  FuchsiaTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
701  : OSTargetInfo<Target>(Triple, Opts) {
702  this->MCountName = "__mcount";
703  }
704 };
705 
706 // WebAssembly target
707 template <typename Target>
708 class LLVM_LIBRARY_VISIBILITY WebAssemblyOSTargetInfo
709  : public OSTargetInfo<Target> {
710  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
711  MacroBuilder &Builder) const final {
712  // A common platform macro.
713  if (Opts.POSIXThreads)
714  Builder.defineMacro("_REENTRANT");
715  // Follow g++ convention and predefine _GNU_SOURCE for C++.
716  if (Opts.CPlusPlus)
717  Builder.defineMacro("_GNU_SOURCE");
718  }
719 
720 public:
721  explicit WebAssemblyOSTargetInfo(const llvm::Triple &Triple,
722  const TargetOptions &Opts)
723  : OSTargetInfo<Target>(Triple, Opts) {
724  this->MCountName = "__mcount";
725  this->TheCXXABI.set(TargetCXXABI::WebAssembly);
726  }
727 };
728 
729 } // namespace targets
730 } // namespace clang
731 #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
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
Definition: LangOptions.h:202
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const override
Definition: OSTargets.h:688
WindowsTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:629
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:567
WebAssemblyOSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: OSTargets.h:721
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:508
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:651
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:557
void getVisualStudioDefines(const LangOptions &Opts, MacroBuilder &Builder) const
Definition: OSTargets.h:576
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:700
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:497
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:638
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:533
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