r366028 - Support __seg_fs and __seg_gs on x86

JF Bastien via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 14 11:33:51 PDT 2019


Author: jfb
Date: Sun Jul 14 11:33:51 2019
New Revision: 366028

URL: http://llvm.org/viewvc/llvm-project?rev=366028&view=rev
Log:
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

Added:
    cfe/trunk/test/Preprocessor/x86_seg_fs_gs.c
Modified:
    cfe/trunk/docs/LanguageExtensions.rst
    cfe/trunk/lib/Basic/Targets/X86.cpp

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=366028&r1=366027&r2=366028&view=diff
==============================================================================
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Sun Jul 14 11:33:51 2019
@@ -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
 ------------------------------
 

Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=366028&r1=366027&r2=366028&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/X86.cpp Sun Jul 14 11:33:51 2019
@@ -917,6 +917,11 @@ void X86TargetInfo::getTargetDefines(con
     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.

Added: cfe/trunk/test/Preprocessor/x86_seg_fs_gs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/x86_seg_fs_gs.c?rev=366028&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/x86_seg_fs_gs.c (added)
+++ cfe/trunk/test/Preprocessor/x86_seg_fs_gs.c Sun Jul 14 11:33:51 2019
@@ -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)))




More information about the cfe-commits mailing list