[PATCH] Only provide MS builtins when -fms-extensions is on
Reid Kleckner
rnk at google.com
Wed Nov 13 13:11:40 PST 2013
- Use LANGBUILTIN over LIBBUILTIN
Hi rsmith,
http://llvm-reviews.chandlerc.com/D2128
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D2128?vs=5419&id=5517#toc
Files:
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: include/clang/Basic/Builtins.def
===================================================================
--- include/clang/Basic/Builtins.def
+++ include/clang/Basic/Builtins.def
@@ -92,6 +92,10 @@
# 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_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
Index: include/clang/Basic/Builtins.h
===================================================================
--- include/clang/Basic/Builtins.h
+++ include/clang/Basic/Builtins.h
@@ -35,8 +35,10 @@
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: lib/Basic/Builtins.cpp
===================================================================
--- lib/Basic/Builtins.cpp
+++ lib/Basic/Builtins.cpp
@@ -22,6 +22,7 @@
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 @@
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: test/CodeGen/builtin-ms-noop.cpp
===================================================================
--- test/CodeGen/builtin-ms-noop.cpp
+++ test/CodeGen/builtin-ms-noop.cpp
@@ -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: test/Sema/builtins.c
===================================================================
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -191,3 +191,9 @@
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: test/SemaCXX/builtins.cpp
===================================================================
--- test/SemaCXX/builtins.cpp
+++ test/SemaCXX/builtins.cpp
@@ -38,3 +38,9 @@
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}}
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2128.2.patch
Type: text/x-patch
Size: 4698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131113/27581cb7/attachment.bin>
More information about the cfe-commits
mailing list