]> granicus.if.org Git - clang/commitdiff
Only provide MS builtins when -fms-extensions is on
authorReid Kleckner <reid@kleckner.net>
Wed, 13 Nov 2013 22:47:22 +0000 (22:47 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 13 Nov 2013 22:47:22 +0000 (22:47 +0000)
We already have builtins that are only available in GNU mode, so this
mirrors that.

Reviewers: rsmith

Differential Revision: http://llvm-reviews.chandlerc.com/D2128

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194615 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Builtins.def
include/clang/Basic/Builtins.h
lib/Basic/Builtins.cpp
test/CodeGen/builtin-ms-noop.cpp
test/Sema/builtins.c
test/SemaCXX/builtins.cpp

index 23a8513ca1bccde2b5cca260d284d8965af0d9cf..b1f92a15c6f020d5fbe2b919e9d6bb20acd3c0cc 100644 (file)
 #  define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
 #endif
 
+#if defined(BUILTIN) && !defined(LANGBUILTIN)
+#  define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
+#endif
+
 // Standard libc/libm functions:
 BUILTIN(__builtin_atan2 , "ddd"  , "Fnc")
 BUILTIN(__builtin_atan2f, "fff"  , "Fnc")
@@ -670,11 +674,10 @@ BUILTIN(__builtin_abort, "v", "Fnr")
 BUILTIN(__builtin_index, "c*cC*i", "Fn")
 BUILTIN(__builtin_rindex, "c*cC*i", "Fn")
 
-// Microsoft builtins.
-BUILTIN(__assume, "vb", "n")
-BUILTIN(__noop, "v.", "n")
-BUILTIN(__debugbreak, "v", "n")
-
+// Microsoft builtins.  These are only active with -fms-extensions.
+LANGBUILTIN(__assume,     "vb",  "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(__noop,       "v.",  "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(__debugbreak, "v",   "n", ALL_MS_LANGUAGES)
 
 // C99 library functions
 // C99 stdlib.h
@@ -1178,3 +1181,4 @@ BUILTIN(__builtin_addressof, "v*v&", "nct")
 
 #undef BUILTIN
 #undef LIBBUILTIN
+#undef LANGBUILTIN
index b66c0db464d41e9cfbce7dcd25fb45cd5d15c1e5..9756f21a1c4842c446dbd955ffd983484202c791 100644 (file)
@@ -35,8 +35,10 @@ namespace clang {
     C_LANG = 0x2,    // builtin for c only.
     CXX_LANG = 0x4,  // builtin for cplusplus only.
     OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
+    MS_LANG = 0x10,  // builtin requires MS mode.
     ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
-    ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG   // builtin requires GNU mode.
+    ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG,  // builtin requires GNU mode.
+    ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG     // builtin requires MS mode.
   };
   
 namespace Builtin {
index e5775b687ce7e8402e8f0ff983a5bbef78e7e9cb..c84dd6dc38ffbb48d31540e2adec80803fdce32f 100644 (file)
@@ -22,6 +22,7 @@ using namespace clang;
 static const Builtin::Info BuiltinInfo[] = {
   { "not a builtin function", 0, 0, 0, ALL_LANGUAGES },
 #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
+#define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) { #ID, TYPE, ATTRS, 0, BUILTIN_LANG },
 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) { #ID, TYPE, ATTRS, HEADER,\
                                                             BUILTIN_LANG },
 #include "clang/Basic/Builtins.def"
@@ -54,10 +55,12 @@ bool Builtin::Context::BuiltinIsSupported(const Builtin::Info &BuiltinInfo,
     llvm::StringRef(BuiltinInfo.HeaderName).equals("math.h");
   bool GnuModeUnsupported = !LangOpts.GNUMode &&
                             (BuiltinInfo.builtin_lang & GNU_LANG);
+  bool MSModeUnsupported = !LangOpts.MicrosoftExt &&
+                           (BuiltinInfo.builtin_lang & MS_LANG);
   bool ObjCUnsupported = !LangOpts.ObjC1 &&
                          BuiltinInfo.builtin_lang == OBJC_LANG;
   return !BuiltinsUnsupported && !MathBuiltinsUnsupported &&
-         !GnuModeUnsupported && !ObjCUnsupported;
+         !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
 }
 
 /// InitializeBuiltins - Mark the identifiers for all the builtins with their
index 42c25016b138ac8badc1b7939f907a8e58e91147..7c5068dd61b06fd1ce8857c7d5550b0a7be0f3aa 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i686-pc-win32 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -triple i686-pc-win32 -emit-llvm %s -o - | FileCheck %s
 
 class A {
  public:
index 33b09543819869b2696d83ddc9b6dc2bbaf5b59c..8ca33c8e752741127c97dc0ca5f827fed7209815 100644 (file)
@@ -191,3 +191,9 @@ void test18() {
   ptr = __builtin___strlcpy_chk(dst, src, sizeof(src), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}}
   ptr = __builtin___strlcat_chk(dst, src, sizeof(src), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}}
 }
+
+void no_ms_builtins() {
+  __assume(1); // expected-warning {{implicit declaration}}
+  __noop(1); // expected-warning {{implicit declaration}}
+  __debugbreak(); // expected-warning {{implicit declaration}}
+}
index 63aa711d62dbc1f4b2de7fd0433da9bda7b7de37..69bdfa6145170d5bfff3d00d0d568fb68b143f29 100644 (file)
@@ -38,3 +38,9 @@ namespace addressof {
 
   S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}}
 }
+
+void no_ms_builtins() {
+  __assume(1); // expected-error {{use of undeclared}}
+  __noop(1); // expected-error {{use of undeclared}}
+  __debugbreak(); // expected-error {{use of undeclared}}
+}