[PATCH] D23859: [Preprocessor] Add a macro for -fno-gnu-inline-asm

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 24 17:13:06 PDT 2016


bruno created this revision.
bruno added reviewers: rsmith, echristo.
bruno added subscribers: cfe-commits, friss.
Herald added a subscriber: mehdi_amini.

When building with -fno-gnu-inline-asm and -fmodules on Darwin, the compilation might fail if some of the implicit modules try to use gnu asm inline. For example, the issue happens when building _Builtin_intrinsics because of inline asm in cpuid.h

Add __CLANG_NO_GNU_INLINE_ASM macro when -fno-gnu-inline-asm is used and allow the user to ifdef asm inline's if desired.

https://reviews.llvm.org/D23859

Files:
  lib/Frontend/InitPreprocessor.cpp
  lib/Headers/cpuid.h
  test/Driver/inline-asm.c

Index: test/Driver/inline-asm.c
===================================================================
--- test/Driver/inline-asm.c
+++ test/Driver/inline-asm.c
@@ -22,3 +22,9 @@
 // RUN: FileCheck --check-prefix=CHECK-NO-GNU-INLINE-ASM %s
 
 // CHECK-NO-GNU-INLINE-ASM: "-fno-gnu-inline-asm"
+
+// RUN: %clang -target x86_64-apple-darwin10 \
+// RUN:   -fno-gnu-inline-asm -dM -E %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-NO-GNU-INLINE-ASM-DEFINE %s
+
+// CHECK-NO-GNU-INLINE-ASM-DEFINE: #define __CLANG_NO_GNU_INLINE_ASM 1
Index: lib/Headers/cpuid.h
===================================================================
--- lib/Headers/cpuid.h
+++ lib/Headers/cpuid.h
@@ -152,6 +152,8 @@
 #define bit_SMEP        0x00000080
 #define bit_ENH_MOVSB   0x00000200
 
+#ifndef __CLANG_NO_GNU_INLINE_ASM
+
 #if __i386__
 #define __cpuid(__level, __eax, __ebx, __ecx, __edx) \
     __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \
@@ -213,3 +215,5 @@
         *__sig = __ebx;
     return __eax;
 }
+
+#endif /* __CLANG_NO_GNU_INLINE_ASM */
Index: lib/Frontend/InitPreprocessor.cpp
===================================================================
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -952,6 +952,9 @@
     Builder.defineMacro("__CLANG_CUDA_APPROX_TRANSCENDENTALS__");
   }
 
+  if (!LangOpts.GNUAsm)
+    Builder.defineMacro("__CLANG_NO_GNU_INLINE_ASM");
+
   // OpenCL definitions.
   if (LangOpts.OpenCL) {
 #define OPENCLEXT(Ext) \


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23859.69185.patch
Type: text/x-patch
Size: 1499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160825/e5c312d5/attachment.bin>


More information about the cfe-commits mailing list