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

Commit c89f02a

Browse files
committed
Disable non-standard library builtins in non-gnu language modes.
Fixes PR16138. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183015 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b8b4295 commit c89f02a

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

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

+27-28
Original file line numberDiff line numberDiff line change
@@ -718,48 +718,47 @@ LIBBUILTIN(vscanf, "icC*Ra", "fS:0:", "stdio.h", ALL_LANGUAGES)
718718
LIBBUILTIN(vfscanf, "iP*RcC*Ra", "fS:1:", "stdio.h", ALL_LANGUAGES)
719719
LIBBUILTIN(vsscanf, "icC*RcC*Ra", "fS:1:", "stdio.h", ALL_LANGUAGES)
720720
// C99
721+
#undef setjmp
722+
LIBBUILTIN(setjmp, "iJ", "fj", "setjmp.h", ALL_LANGUAGES)
721723
LIBBUILTIN(longjmp, "vJi", "fr", "setjmp.h", ALL_LANGUAGES)
722724

723-
// Non-C library functions
724-
// FIXME: Non-C-standard stuff shouldn't be builtins in non-GNU mode!
725-
LIBBUILTIN(alloca, "v*z", "f", "stdlib.h", ALL_LANGUAGES)
725+
// Non-C library functions, active in GNU mode only.
726+
LIBBUILTIN(alloca, "v*z", "f", "stdlib.h", ALL_GNU_LANGUAGES)
726727
// POSIX string.h
727-
LIBBUILTIN(stpcpy, "c*c*cC*", "f", "string.h", ALL_LANGUAGES)
728-
LIBBUILTIN(stpncpy, "c*c*cC*z", "f", "string.h", ALL_LANGUAGES)
729-
LIBBUILTIN(strdup, "c*cC*", "f", "string.h", ALL_LANGUAGES)
730-
LIBBUILTIN(strndup, "c*cC*z", "f", "string.h", ALL_LANGUAGES)
728+
LIBBUILTIN(stpcpy, "c*c*cC*", "f", "string.h", ALL_GNU_LANGUAGES)
729+
LIBBUILTIN(stpncpy, "c*c*cC*z", "f", "string.h", ALL_GNU_LANGUAGES)
730+
LIBBUILTIN(strdup, "c*cC*", "f", "string.h", ALL_GNU_LANGUAGES)
731+
LIBBUILTIN(strndup, "c*cC*z", "f", "string.h", ALL_GNU_LANGUAGES)
731732
// POSIX strings.h
732-
LIBBUILTIN(index, "c*cC*i", "f", "strings.h", ALL_LANGUAGES)
733-
LIBBUILTIN(rindex, "c*cC*i", "f", "strings.h", ALL_LANGUAGES)
734-
LIBBUILTIN(bzero, "vv*z", "f", "strings.h", ALL_LANGUAGES)
733+
LIBBUILTIN(index, "c*cC*i", "f", "strings.h", ALL_GNU_LANGUAGES)
734+
LIBBUILTIN(rindex, "c*cC*i", "f", "strings.h", ALL_GNU_LANGUAGES)
735+
LIBBUILTIN(bzero, "vv*z", "f", "strings.h", ALL_GNU_LANGUAGES)
735736
// In some systems str[n]casejmp is a macro that expands to _str[n]icmp.
736737
// We undefine then here to avoid wrong name.
737738
#undef strcasecmp
738739
#undef strncasecmp
739-
LIBBUILTIN(strcasecmp, "icC*cC*", "f", "strings.h", ALL_LANGUAGES)
740-
LIBBUILTIN(strncasecmp, "icC*cC*z", "f", "strings.h", ALL_LANGUAGES)
740+
LIBBUILTIN(strcasecmp, "icC*cC*", "f", "strings.h", ALL_GNU_LANGUAGES)
741+
LIBBUILTIN(strncasecmp, "icC*cC*z", "f", "strings.h", ALL_GNU_LANGUAGES)
741742
// POSIX unistd.h
742-
LIBBUILTIN(_exit, "vi", "fr", "unistd.h", ALL_LANGUAGES)
743-
LIBBUILTIN(vfork, "p", "fj", "unistd.h", ALL_LANGUAGES)
743+
LIBBUILTIN(_exit, "vi", "fr", "unistd.h", ALL_GNU_LANGUAGES)
744+
LIBBUILTIN(vfork, "p", "fj", "unistd.h", ALL_GNU_LANGUAGES)
744745
// POSIX setjmp.h
745746

746747
// In some systems setjmp is a macro that expands to _setjmp. We undefine
747748
// it here to avoid having two identical LIBBUILTIN entries.
748-
#undef setjmp
749-
LIBBUILTIN(_setjmp, "iJ", "fj", "setjmp.h", ALL_LANGUAGES)
750-
LIBBUILTIN(__sigsetjmp, "iSJi", "fj", "setjmp.h", ALL_LANGUAGES)
751-
LIBBUILTIN(setjmp, "iJ", "fj", "setjmp.h", ALL_LANGUAGES)
752-
LIBBUILTIN(sigsetjmp, "iSJi", "fj", "setjmp.h", ALL_LANGUAGES)
753-
LIBBUILTIN(setjmp_syscall, "iJ", "fj", "setjmp.h", ALL_LANGUAGES)
754-
LIBBUILTIN(savectx, "iJ", "fj", "setjmp.h", ALL_LANGUAGES)
755-
LIBBUILTIN(qsetjmp, "iJ", "fj", "setjmp.h", ALL_LANGUAGES)
756-
LIBBUILTIN(getcontext, "iK*", "fj", "setjmp.h", ALL_LANGUAGES)
757-
758-
LIBBUILTIN(_longjmp, "vJi", "fr", "setjmp.h", ALL_LANGUAGES)
759-
LIBBUILTIN(siglongjmp, "vSJi", "fr", "setjmp.h", ALL_LANGUAGES)
749+
LIBBUILTIN(_setjmp, "iJ", "fj", "setjmp.h", ALL_GNU_LANGUAGES)
750+
LIBBUILTIN(__sigsetjmp, "iSJi", "fj", "setjmp.h", ALL_GNU_LANGUAGES)
751+
LIBBUILTIN(sigsetjmp, "iSJi", "fj", "setjmp.h", ALL_GNU_LANGUAGES)
752+
LIBBUILTIN(setjmp_syscall, "iJ", "fj", "setjmp.h", ALL_GNU_LANGUAGES)
753+
LIBBUILTIN(savectx, "iJ", "fj", "setjmp.h", ALL_GNU_LANGUAGES)
754+
LIBBUILTIN(qsetjmp, "iJ", "fj", "setjmp.h", ALL_GNU_LANGUAGES)
755+
LIBBUILTIN(getcontext, "iK*", "fj", "setjmp.h", ALL_GNU_LANGUAGES)
756+
757+
LIBBUILTIN(_longjmp, "vJi", "fr", "setjmp.h", ALL_GNU_LANGUAGES)
758+
LIBBUILTIN(siglongjmp, "vSJi", "fr", "setjmp.h", ALL_GNU_LANGUAGES)
760759
// non-standard but very common
761-
LIBBUILTIN(strlcpy, "zc*cC*z", "f", "string.h", ALL_LANGUAGES)
762-
LIBBUILTIN(strlcat, "zc*cC*z", "f", "string.h", ALL_LANGUAGES)
760+
LIBBUILTIN(strlcpy, "zc*cC*z", "f", "string.h", ALL_GNU_LANGUAGES)
761+
LIBBUILTIN(strlcat, "zc*cC*z", "f", "string.h", ALL_GNU_LANGUAGES)
763762
// id objc_msgSend(id, SEL, ...)
764763
LIBBUILTIN(objc_msgSend, "GGH.", "f", "objc/message.h", OBJC_LANG)
765764
// long double objc_msgSend_fpret(id self, SEL op, ...)

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ namespace clang {
3131
class LangOptions;
3232

3333
enum LanguageID {
34-
C_LANG = 0x1, // builtin for c only.
35-
CXX_LANG = 0x2, // builtin for cplusplus only.
36-
OBJC_LANG = 0x4, // builtin for objective-c and objective-c++
37-
ALL_LANGUAGES = (C_LANG|CXX_LANG|OBJC_LANG) //builtin is for all languages.
34+
GNU_LANG = 0x1, // builtin requires GNU mode.
35+
C_LANG = 0x2, // builtin for c only.
36+
CXX_LANG = 0x4, // builtin for cplusplus only.
37+
OBJC_LANG = 0x8, // builtin for objective-c and objective-c++
38+
ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
39+
ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG // builtin requires GNU mode.
3840
};
3941

4042
namespace Builtin {

Diff for: lib/Basic/Builtins.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ void Builtin::Context::InitializeBuiltins(IdentifierTable &Table,
5151
const LangOptions& LangOpts) {
5252
// Step #1: mark all target-independent builtins with their ID's.
5353
for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i)
54-
if (!LangOpts.NoBuiltin || !strchr(BuiltinInfo[i].Attributes, 'f')) {
55-
if (LangOpts.ObjC1 ||
56-
BuiltinInfo[i].builtin_lang != clang::OBJC_LANG)
57-
Table.get(BuiltinInfo[i].Name).setBuiltinID(i);
58-
}
54+
if ((!LangOpts.NoBuiltin || !strchr(BuiltinInfo[i].Attributes, 'f')) &&
55+
(LangOpts.GNUMode || !(BuiltinInfo[i].builtin_lang & GNU_LANG)) &&
56+
(LangOpts.ObjC1 || BuiltinInfo[i].builtin_lang != OBJC_LANG))
57+
Table.get(BuiltinInfo[i].Name).setBuiltinID(i);
5958

6059
// Step #2: Register target-specific builtins.
6160
for (unsigned i = 0, e = NumTSRecords; i != e; ++i)

0 commit comments

Comments
 (0)