Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f2941ec

Browse files
committed
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
1 parent d4315fe commit f2941ec

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

Diff for: include/clang/Basic/Builtins.def

+9-5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
# define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
9393
#endif
9494

95+
#if defined(BUILTIN) && !defined(LANGBUILTIN)
96+
# define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
97+
#endif
98+
9599
// Standard libc/libm functions:
96100
BUILTIN(__builtin_atan2 , "ddd" , "Fnc")
97101
BUILTIN(__builtin_atan2f, "fff" , "Fnc")
@@ -670,11 +674,10 @@ BUILTIN(__builtin_abort, "v", "Fnr")
670674
BUILTIN(__builtin_index, "c*cC*i", "Fn")
671675
BUILTIN(__builtin_rindex, "c*cC*i", "Fn")
672676

673-
// Microsoft builtins.
674-
BUILTIN(__assume, "vb", "n")
675-
BUILTIN(__noop, "v.", "n")
676-
BUILTIN(__debugbreak, "v", "n")
677-
677+
// Microsoft builtins. These are only active with -fms-extensions.
678+
LANGBUILTIN(__assume, "vb", "n", ALL_MS_LANGUAGES)
679+
LANGBUILTIN(__noop, "v.", "n", ALL_MS_LANGUAGES)
680+
LANGBUILTIN(__debugbreak, "v", "n", ALL_MS_LANGUAGES)
678681

679682
// C99 library functions
680683
// C99 stdlib.h
@@ -1178,3 +1181,4 @@ BUILTIN(__builtin_addressof, "v*v&", "nct")
11781181

11791182
#undef BUILTIN
11801183
#undef LIBBUILTIN
1184+
#undef LANGBUILTIN

Diff for: include/clang/Basic/Builtins.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ namespace clang {
3535
C_LANG = 0x2, // builtin for c only.
3636
CXX_LANG = 0x4, // builtin for cplusplus only.
3737
OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
38+
MS_LANG = 0x10, // builtin requires MS mode.
3839
ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
39-
ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG // builtin requires GNU mode.
40+
ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
41+
ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
4042
};
4143

4244
namespace Builtin {

Diff for: lib/Basic/Builtins.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ using namespace clang;
2222
static const Builtin::Info BuiltinInfo[] = {
2323
{ "not a builtin function", 0, 0, 0, ALL_LANGUAGES },
2424
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
25+
#define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) { #ID, TYPE, ATTRS, 0, BUILTIN_LANG },
2526
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) { #ID, TYPE, ATTRS, HEADER,\
2627
BUILTIN_LANG },
2728
#include "clang/Basic/Builtins.def"
@@ -54,10 +55,12 @@ bool Builtin::Context::BuiltinIsSupported(const Builtin::Info &BuiltinInfo,
5455
llvm::StringRef(BuiltinInfo.HeaderName).equals("math.h");
5556
bool GnuModeUnsupported = !LangOpts.GNUMode &&
5657
(BuiltinInfo.builtin_lang & GNU_LANG);
58+
bool MSModeUnsupported = !LangOpts.MicrosoftExt &&
59+
(BuiltinInfo.builtin_lang & MS_LANG);
5760
bool ObjCUnsupported = !LangOpts.ObjC1 &&
5861
BuiltinInfo.builtin_lang == OBJC_LANG;
5962
return !BuiltinsUnsupported && !MathBuiltinsUnsupported &&
60-
!GnuModeUnsupported && !ObjCUnsupported;
63+
!GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
6164
}
6265

6366
/// InitializeBuiltins - Mark the identifiers for all the builtins with their

Diff for: test/CodeGen/builtin-ms-noop.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple i686-pc-win32 -emit-llvm %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -fms-extensions -triple i686-pc-win32 -emit-llvm %s -o - | FileCheck %s
22

33
class A {
44
public:

Diff for: test/Sema/builtins.c

+6
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,9 @@ void test18() {
191191
ptr = __builtin___strlcpy_chk(dst, src, sizeof(src), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}}
192192
ptr = __builtin___strlcat_chk(dst, src, sizeof(src), sizeof(dst)); // expected-warning {{incompatible integer to pointer conversion}}
193193
}
194+
195+
void no_ms_builtins() {
196+
__assume(1); // expected-warning {{implicit declaration}}
197+
__noop(1); // expected-warning {{implicit declaration}}
198+
__debugbreak(); // expected-warning {{implicit declaration}}
199+
}

Diff for: test/SemaCXX/builtins.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ namespace addressof {
3838

3939
S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}}
4040
}
41+
42+
void no_ms_builtins() {
43+
__assume(1); // expected-error {{use of undeclared}}
44+
__noop(1); // expected-error {{use of undeclared}}
45+
__debugbreak(); // expected-error {{use of undeclared}}
46+
}

0 commit comments

Comments
 (0)