summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJF Bastien <jfbastien@apple.com>2019-07-14 18:33:51 +0000
committerJF Bastien <jfbastien@apple.com>2019-07-14 18:33:51 +0000
commitfff5dc0b173fc35ce9a75a737a980875be125566 (patch)
tree1281f77fbe8f2ebb67c69259a2e9374fb001ff21
parent24cacf9c56f0b55534e98941cc8675a9a7489c37 (diff)
downloadbcm5719-llvm-fff5dc0b173fc35ce9a75a737a980875be125566.tar.gz
bcm5719-llvm-fff5dc0b173fc35ce9a75a737a980875be125566.zip
Support __seg_fs and __seg_gs on x86
Summary: GCC supports named address spaces macros: https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html clang does as well with address spaces: https://clang.llvm.org/docs/LanguageExtensions.html#memory-references-to-specified-segments Add the __seg_fs and __seg_gs macros for compatibility with GCC. <rdar://problem/52944935> Subscribers: jkorous, dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64676 llvm-svn: 366028
-rw-r--r--clang/docs/LanguageExtensions.rst4
-rw-r--r--clang/lib/Basic/Targets/X86.cpp5
-rw-r--r--clang/test/Preprocessor/x86_seg_fs_gs.c7
3 files changed, 16 insertions, 0 deletions
diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index ecbf04c3c82..266309c6ce2 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2465,6 +2465,10 @@ Which compiles to (on X86-32):
movl %gs:(%eax), %eax
ret
+You can also use the GCC compatibility macros ``__seg_fs`` and ``__seg_gs`` for
+the same purpose. The preprocessor symbols ``__SEG_FS`` and ``__SEG_GS``
+indicate their support.
+
PowerPC Language Extensions
------------------------------
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 76d8ab8146f..d618c90b05c 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -917,6 +917,11 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
DefineStd(Builder, "i386", Opts);
}
+ Builder.defineMacro("__SEG_GS");
+ Builder.defineMacro("__SEG_FS");
+ Builder.defineMacro("__seg_gs", "__attribute__((address_space(256)))");
+ Builder.defineMacro("__seg_fs", "__attribute__((address_space(257)))");
+
// Subtarget options.
// FIXME: We are hard-coding the tune parameters based on the CPU, but they
// truly should be based on -mtune options.
diff --git a/clang/test/Preprocessor/x86_seg_fs_gs.c b/clang/test/Preprocessor/x86_seg_fs_gs.c
new file mode 100644
index 00000000000..b7a586c8202
--- /dev/null
+++ b/clang/test/Preprocessor/x86_seg_fs_gs.c
@@ -0,0 +1,7 @@
+// RUN: %clang -target i386-unknown-unknown -x c -E -dM -o - %s | FileCheck -match-full-lines %s
+// RUN: %clang -target x86_64-unknown-unknown -x c -E -dM -o - %s | FileCheck -match-full-lines %s
+
+// CHECK: #define __SEG_FS 1
+// CHECK: #define __SEG_GS 1
+// CHECK: #define __seg_fs __attribute__((address_space(257)))
+// CHECK: #define __seg_gs __attribute__((address_space(256)))
OpenPOWER on IntegriCloud