From f2941ec5bfcce36feffac514582d168b4e0ef811 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 13 Nov 2013 22:47:22 +0000 Subject: [PATCH] Only provide MS builtins when -fms-extensions is on 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 | 14 +++++++++----- include/clang/Basic/Builtins.h | 4 +++- lib/Basic/Builtins.cpp | 5 ++++- test/CodeGen/builtin-ms-noop.cpp | 2 +- test/Sema/builtins.c | 6 ++++++ test/SemaCXX/builtins.cpp | 6 ++++++ 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/clang/Basic/Builtins.def b/include/clang/Basic/Builtins.def index 23a8513ca1..b1f92a15c6 100644 --- a/include/clang/Basic/Builtins.def +++ b/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_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 diff --git a/include/clang/Basic/Builtins.h b/include/clang/Basic/Builtins.h index b66c0db464..9756f21a1c 100644 --- a/include/clang/Basic/Builtins.h +++ b/include/clang/Basic/Builtins.h @@ -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 { diff --git a/lib/Basic/Builtins.cpp b/lib/Basic/Builtins.cpp index e5775b687c..c84dd6dc38 100644 --- a/lib/Basic/Builtins.cpp +++ b/lib/Basic/Builtins.cpp @@ -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 diff --git a/test/CodeGen/builtin-ms-noop.cpp b/test/CodeGen/builtin-ms-noop.cpp index 42c25016b1..7c5068dd61 100644 --- a/test/CodeGen/builtin-ms-noop.cpp +++ b/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: diff --git a/test/Sema/builtins.c b/test/Sema/builtins.c index 33b0954381..8ca33c8e75 100644 --- a/test/Sema/builtins.c +++ b/test/Sema/builtins.c @@ -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}} +} diff --git a/test/SemaCXX/builtins.cpp b/test/SemaCXX/builtins.cpp index 63aa711d62..69bdfa6145 100644 --- a/test/SemaCXX/builtins.cpp +++ b/test/SemaCXX/builtins.cpp @@ -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}} +} -- 2.40.0