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

Commit 67aba81

Browse files
author
Fariborz Jahanian
committed
Such function decls,as objc's objc_msgSend, builtins in
a specific language. We are adding such language info. by extensing Builtins.def and via a language flag added to LIBBUILTIN/BUILTIN and check for that when deciding a name is builtin or not. Implements //rdar://8689273. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120429 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7e48579 commit 67aba81

File tree

8 files changed

+97
-91
lines changed

8 files changed

+97
-91
lines changed

Diff for: clang.xcodeproj/project.pbxproj

-1
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,6 @@
20632063
isa = PBXProject;
20642064
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
20652065
compatibilityVersion = "Xcode 2.4";
2066-
developmentRegion = English;
20672066
hasScannedForEncodings = 1;
20682067
knownRegions = (
20692068
English,

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

+61-61
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
// FIXME: gcc has nonnull
7979

8080
#if defined(BUILTIN) && !defined(LIBBUILTIN)
81-
# define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) BUILTIN(ID, TYPE, ATTRS)
81+
# define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS)
8282
#endif
8383

8484
// Standard libc/libm functions:
@@ -512,85 +512,85 @@ BUILTIN(__noop, "v.", "n")
512512

513513
// C99 library functions
514514
// C99 stdlib.h
515-
LIBBUILTIN(abort, "v", "fr", "stdlib.h")
516-
LIBBUILTIN(calloc, "v*zz", "f", "stdlib.h")
517-
LIBBUILTIN(exit, "vi", "fr", "stdlib.h")
518-
LIBBUILTIN(_Exit, "vi", "fr", "stdlib.h")
519-
LIBBUILTIN(malloc, "v*z", "f", "stdlib.h")
520-
LIBBUILTIN(realloc, "v*v*z", "f", "stdlib.h")
515+
LIBBUILTIN(abort, "v", "fr", "stdlib.h", ALL_LANGUAGES)
516+
LIBBUILTIN(calloc, "v*zz", "f", "stdlib.h", ALL_LANGUAGES)
517+
LIBBUILTIN(exit, "vi", "fr", "stdlib.h", ALL_LANGUAGES)
518+
LIBBUILTIN(_Exit, "vi", "fr", "stdlib.h", ALL_LANGUAGES)
519+
LIBBUILTIN(malloc, "v*z", "f", "stdlib.h", ALL_LANGUAGES)
520+
LIBBUILTIN(realloc, "v*v*z", "f", "stdlib.h", ALL_LANGUAGES)
521521
// C99 string.h
522-
LIBBUILTIN(memcpy, "v*v*vC*z", "f", "string.h")
523-
LIBBUILTIN(memmove, "v*v*vC*z", "f", "string.h")
524-
LIBBUILTIN(strcpy, "c*c*cC*", "f", "string.h")
525-
LIBBUILTIN(strncpy, "c*c*cC*z", "f", "string.h")
526-
LIBBUILTIN(strcat, "c*c*cC*", "f", "string.h")
527-
LIBBUILTIN(strncat, "c*c*cC*z", "f", "string.h")
528-
LIBBUILTIN(strxfrm, "zc*cC*z", "f", "string.h")
529-
LIBBUILTIN(memchr, "v*vC*iz", "f", "string.h")
530-
LIBBUILTIN(strchr, "c*cC*i", "f", "string.h")
531-
LIBBUILTIN(strcspn, "zcC*cC*", "f", "string.h")
532-
LIBBUILTIN(strpbrk, "c*cC*cC*", "f", "string.h")
533-
LIBBUILTIN(strrchr, "c*cC*i", "f", "string.h")
534-
LIBBUILTIN(strspn, "zcC*cC*", "f", "string.h")
535-
LIBBUILTIN(strstr, "c*cC*cC*", "f", "string.h")
536-
LIBBUILTIN(strtok, "c*c*cC*", "f", "string.h")
537-
LIBBUILTIN(memset, "v*v*iz", "f", "string.h")
538-
LIBBUILTIN(strerror, "c*i", "f", "string.h")
539-
LIBBUILTIN(strlen, "zcC*", "f", "string.h")
522+
LIBBUILTIN(memcpy, "v*v*vC*z", "f", "string.h", ALL_LANGUAGES)
523+
LIBBUILTIN(memmove, "v*v*vC*z", "f", "string.h", ALL_LANGUAGES)
524+
LIBBUILTIN(strcpy, "c*c*cC*", "f", "string.h", ALL_LANGUAGES)
525+
LIBBUILTIN(strncpy, "c*c*cC*z", "f", "string.h", ALL_LANGUAGES)
526+
LIBBUILTIN(strcat, "c*c*cC*", "f", "string.h", ALL_LANGUAGES)
527+
LIBBUILTIN(strncat, "c*c*cC*z", "f", "string.h", ALL_LANGUAGES)
528+
LIBBUILTIN(strxfrm, "zc*cC*z", "f", "string.h", ALL_LANGUAGES)
529+
LIBBUILTIN(memchr, "v*vC*iz", "f", "string.h", ALL_LANGUAGES)
530+
LIBBUILTIN(strchr, "c*cC*i", "f", "string.h", ALL_LANGUAGES)
531+
LIBBUILTIN(strcspn, "zcC*cC*", "f", "string.h", ALL_LANGUAGES)
532+
LIBBUILTIN(strpbrk, "c*cC*cC*", "f", "string.h", ALL_LANGUAGES)
533+
LIBBUILTIN(strrchr, "c*cC*i", "f", "string.h", ALL_LANGUAGES)
534+
LIBBUILTIN(strspn, "zcC*cC*", "f", "string.h", ALL_LANGUAGES)
535+
LIBBUILTIN(strstr, "c*cC*cC*", "f", "string.h", ALL_LANGUAGES)
536+
LIBBUILTIN(strtok, "c*c*cC*", "f", "string.h", ALL_LANGUAGES)
537+
LIBBUILTIN(memset, "v*v*iz", "f", "string.h", ALL_LANGUAGES)
538+
LIBBUILTIN(strerror, "c*i", "f", "string.h", ALL_LANGUAGES)
539+
LIBBUILTIN(strlen, "zcC*", "f", "string.h", ALL_LANGUAGES)
540540
// C99 stdio.h
541-
LIBBUILTIN(printf, "icC*.", "fp:0:", "stdio.h")
542-
LIBBUILTIN(fprintf, "iP*cC*.", "fp:1:", "stdio.h")
543-
LIBBUILTIN(snprintf, "ic*zcC*.", "fp:2:", "stdio.h")
544-
LIBBUILTIN(sprintf, "ic*cC*.", "fp:1:", "stdio.h")
545-
LIBBUILTIN(vprintf, "icC*a", "fP:0:", "stdio.h")
546-
LIBBUILTIN(vfprintf, "i.", "fP:1:", "stdio.h")
547-
LIBBUILTIN(vsnprintf, "ic*zcC*a", "fP:2:", "stdio.h")
548-
LIBBUILTIN(vsprintf, "ic*cC*a", "fP:1:", "stdio.h")
549-
LIBBUILTIN(scanf, "icC*.", "fs:0:", "stdio.h")
541+
LIBBUILTIN(printf, "icC*.", "fp:0:", "stdio.h", ALL_LANGUAGES)
542+
LIBBUILTIN(fprintf, "iP*cC*.", "fp:1:", "stdio.h", ALL_LANGUAGES)
543+
LIBBUILTIN(snprintf, "ic*zcC*.", "fp:2:", "stdio.h", ALL_LANGUAGES)
544+
LIBBUILTIN(sprintf, "ic*cC*.", "fp:1:", "stdio.h", ALL_LANGUAGES)
545+
LIBBUILTIN(vprintf, "icC*a", "fP:0:", "stdio.h", ALL_LANGUAGES)
546+
LIBBUILTIN(vfprintf, "i.", "fP:1:", "stdio.h", ALL_LANGUAGES)
547+
LIBBUILTIN(vsnprintf, "ic*zcC*a", "fP:2:", "stdio.h", ALL_LANGUAGES)
548+
LIBBUILTIN(vsprintf, "ic*cC*a", "fP:1:", "stdio.h", ALL_LANGUAGES)
549+
LIBBUILTIN(scanf, "icC*.", "fs:0:", "stdio.h", ALL_LANGUAGES)
550550
// C99
551-
LIBBUILTIN(longjmp, "vJi", "fr", "setjmp.h")
551+
LIBBUILTIN(longjmp, "vJi", "fr", "setjmp.h", ALL_LANGUAGES)
552552

553553
// Non-C library functions
554554
// FIXME: Non-C-standard stuff shouldn't be builtins in non-GNU mode!
555-
LIBBUILTIN(alloca, "v*z", "f", "stdlib.h")
555+
LIBBUILTIN(alloca, "v*z", "f", "stdlib.h", ALL_LANGUAGES)
556556
// POSIX string.h
557-
LIBBUILTIN(stpcpy, "c*c*cC*", "f", "string.h")
558-
LIBBUILTIN(stpncpy, "c*c*cC*z", "f", "string.h")
559-
LIBBUILTIN(strdup, "c*cC*", "f", "string.h")
560-
LIBBUILTIN(strndup, "c*cC*z", "f", "string.h")
557+
LIBBUILTIN(stpcpy, "c*c*cC*", "f", "string.h", ALL_LANGUAGES)
558+
LIBBUILTIN(stpncpy, "c*c*cC*z", "f", "string.h", ALL_LANGUAGES)
559+
LIBBUILTIN(strdup, "c*cC*", "f", "string.h", ALL_LANGUAGES)
560+
LIBBUILTIN(strndup, "c*cC*z", "f", "string.h", ALL_LANGUAGES)
561561
// POSIX strings.h
562-
LIBBUILTIN(index, "c*cC*i", "f", "strings.h")
563-
LIBBUILTIN(rindex, "c*cC*i", "f", "strings.h")
564-
LIBBUILTIN(bzero, "vv*z", "f", "strings.h")
562+
LIBBUILTIN(index, "c*cC*i", "f", "strings.h", ALL_LANGUAGES)
563+
LIBBUILTIN(rindex, "c*cC*i", "f", "strings.h", ALL_LANGUAGES)
564+
LIBBUILTIN(bzero, "vv*z", "f", "strings.h", ALL_LANGUAGES)
565565
// POSIX unistd.h
566-
LIBBUILTIN(_exit, "vi", "fr", "unistd.h")
566+
LIBBUILTIN(_exit, "vi", "fr", "unistd.h", ALL_LANGUAGES)
567567
// POSIX setjmp.h
568-
LIBBUILTIN(_longjmp, "vJi", "fr", "setjmp.h")
569-
LIBBUILTIN(siglongjmp, "vSJi", "fr", "setjmp.h")
568+
LIBBUILTIN(_longjmp, "vJi", "fr", "setjmp.h", ALL_LANGUAGES)
569+
LIBBUILTIN(siglongjmp, "vSJi", "fr", "setjmp.h", ALL_LANGUAGES)
570570
// id objc_msgSend(id, SEL, ...)
571-
LIBBUILTIN(objc_msgSend, "GGH.", "f", "objc/message.h")
571+
LIBBUILTIN(objc_msgSend, "GGH.", "f", "objc/message.h", OBJC_LANG)
572572
BUILTIN(__builtin_objc_memmove_collectable, "v*v*vC*z", "nF")
573573

574574
// Builtin math library functions
575-
LIBBUILTIN(pow, "ddd", "fe", "math.h")
576-
LIBBUILTIN(powl, "LdLdLd", "fe", "math.h")
577-
LIBBUILTIN(powf, "fff", "fe", "math.h")
575+
LIBBUILTIN(pow, "ddd", "fe", "math.h", ALL_LANGUAGES)
576+
LIBBUILTIN(powl, "LdLdLd", "fe", "math.h", ALL_LANGUAGES)
577+
LIBBUILTIN(powf, "fff", "fe", "math.h", ALL_LANGUAGES)
578578

579-
LIBBUILTIN(sqrt, "dd", "fe", "math.h")
580-
LIBBUILTIN(sqrtl, "LdLd", "fe", "math.h")
581-
LIBBUILTIN(sqrtf, "ff", "fe", "math.h")
579+
LIBBUILTIN(sqrt, "dd", "fe", "math.h", ALL_LANGUAGES)
580+
LIBBUILTIN(sqrtl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
581+
LIBBUILTIN(sqrtf, "ff", "fe", "math.h", ALL_LANGUAGES)
582582

583-
LIBBUILTIN(sin, "dd", "fe", "math.h")
584-
LIBBUILTIN(sinl, "LdLd", "fe", "math.h")
585-
LIBBUILTIN(sinf, "ff", "fe", "math.h")
583+
LIBBUILTIN(sin, "dd", "fe", "math.h", ALL_LANGUAGES)
584+
LIBBUILTIN(sinl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
585+
LIBBUILTIN(sinf, "ff", "fe", "math.h", ALL_LANGUAGES)
586586

587-
LIBBUILTIN(cos, "dd", "fe", "math.h")
588-
LIBBUILTIN(cosl, "LdLd", "fe", "math.h")
589-
LIBBUILTIN(cosf, "ff", "fe", "math.h")
587+
LIBBUILTIN(cos, "dd", "fe", "math.h", ALL_LANGUAGES)
588+
LIBBUILTIN(cosl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
589+
LIBBUILTIN(cosf, "ff", "fe", "math.h", ALL_LANGUAGES)
590590

591591
// Blocks runtime Builtin math library functions
592-
LIBBUILTIN(_Block_object_assign, "vv*vC*iC", "f", "Blocks.h")
593-
LIBBUILTIN(_Block_object_dispose, "vvC*iC", "f", "Blocks.h")
592+
LIBBUILTIN(_Block_object_assign, "vv*vC*iC", "f", "Blocks.h", ALL_LANGUAGES)
593+
LIBBUILTIN(_Block_object_dispose, "vvC*iC", "f", "Blocks.h", ALL_LANGUAGES)
594594
// FIXME: Also declare NSConcreteGlobalBlock and NSConcreteStackBlock.
595595

596596
#undef BUILTIN

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ namespace clang {
3030
class IdentifierTable;
3131
class ASTContext;
3232
class QualType;
33-
33+
class LangOptions;
34+
35+
enum LANGUAGEID {
36+
C_LANG = 0x1, // builtin for c only.
37+
CXX_LANG = 0x2, // builtin for cplusplus only.
38+
OBJC_LANG = 0x4, // builtin for objective-c and objective-c++
39+
ALL_LANGUAGES = (C_LANG|CXX_LANG|OBJC_LANG) //builtin is for all languages.
40+
};
41+
3442
namespace Builtin {
3543
enum ID {
3644
NotBuiltin = 0, // This is not a builtin function.
@@ -41,6 +49,7 @@ enum ID {
4149

4250
struct Info {
4351
const char *Name, *Type, *Attributes, *HeaderName;
52+
LANGUAGEID builtin_lang;
4453
bool Suppressed;
4554

4655
bool operator==(const Info &RHS) const {
@@ -62,7 +71,7 @@ class Context {
6271
/// InitializeBuiltins - Mark the identifiers for all the builtins with their
6372
/// appropriate builtin ID # and mark any non-portable builtin identifiers as
6473
/// such.
65-
void InitializeBuiltins(IdentifierTable &Table, bool NoBuiltins = false);
74+
void InitializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts);
6675

6776
/// \brief Popular the vector with the names of all of the builtins.
6877
void GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names,

Diff for: lib/Basic/Builtins.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
#include "clang/Basic/Builtins.h"
1515
#include "clang/Basic/IdentifierTable.h"
1616
#include "clang/Basic/TargetInfo.h"
17+
#include "clang/Basic/LangOptions.h"
1718
using namespace clang;
1819

1920
static const Builtin::Info BuiltinInfo[] = {
20-
{ "not a builtin function", 0, 0, 0, false },
21-
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
22-
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
21+
{ "not a builtin function", 0, 0, 0, ALL_LANGUAGES, false },
22+
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
23+
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) { #ID, TYPE, ATTRS, HEADER,\
24+
BUILTIN_LANG, false },
2325
#include "clang/Basic/Builtins.def"
2426
};
2527

@@ -41,17 +43,20 @@ Builtin::Context::Context(const TargetInfo &Target) {
4143
/// appropriate builtin ID # and mark any non-portable builtin identifiers as
4244
/// such.
4345
void Builtin::Context::InitializeBuiltins(IdentifierTable &Table,
44-
bool NoBuiltins) {
46+
const LangOptions& LangOpts) {
4547
// Step #1: mark all target-independent builtins with their ID's.
4648
for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i)
4749
if (!BuiltinInfo[i].Suppressed &&
48-
(!NoBuiltins || !strchr(BuiltinInfo[i].Attributes, 'f')))
49-
Table.get(BuiltinInfo[i].Name).setBuiltinID(i);
50+
(!LangOpts.NoBuiltin || !strchr(BuiltinInfo[i].Attributes, 'f'))) {
51+
if (LangOpts.ObjC1 ||
52+
BuiltinInfo[i].builtin_lang != clang::OBJC_LANG)
53+
Table.get(BuiltinInfo[i].Name).setBuiltinID(i);
54+
}
5055

5156
// Step #2: Register target-specific builtins.
5257
for (unsigned i = 0, e = NumTSRecords; i != e; ++i)
5358
if (!TSRecords[i].Suppressed &&
54-
(!NoBuiltins ||
59+
(!LangOpts.NoBuiltin ||
5560
(TSRecords[i].Attributes &&
5661
!strchr(TSRecords[i].Attributes, 'f'))))
5762
Table.get(TSRecords[i].Name).setBuiltinID(i+Builtin::FirstTSBuiltin);

Diff for: lib/Basic/Targets.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,9 @@ class PPCTargetInfo : public TargetInfo {
598598
};
599599

600600
const Builtin::Info PPCTargetInfo::BuiltinInfo[] = {
601-
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
602-
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
601+
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
602+
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
603+
ALL_LANGUAGES, false },
603604
#include "clang/Basic/BuiltinsPPC.def"
604605
};
605606

@@ -924,8 +925,9 @@ void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
924925
namespace {
925926
// Namespace for x86 abstract base class
926927
const Builtin::Info BuiltinInfo[] = {
927-
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
928-
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
928+
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
929+
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
930+
ALL_LANGUAGES, false },
929931
#include "clang/Basic/BuiltinsX86.def"
930932
};
931933

@@ -1948,8 +1950,9 @@ void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases,
19481950
}
19491951

19501952
const Builtin::Info ARMTargetInfo::BuiltinInfo[] = {
1951-
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false },
1952-
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false },
1953+
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false },
1954+
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\
1955+
ALL_LANGUAGES, false },
19531956
#include "clang/Basic/BuiltinsARM.def"
19541957
};
19551958
} // end anonymous namespace.

Diff for: lib/Frontend/FrontendAction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
202202
if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) {
203203
Preprocessor &PP = CI.getPreprocessor();
204204
PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
205-
PP.getLangOptions().NoBuiltin);
205+
PP.getLangOptions());
206206
}
207207

208208
return true;

Diff for: lib/Sema/SemaExpr.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -4305,13 +4305,8 @@ Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
43054305
if (CheckFunctionCall(FDecl, TheCall))
43064306
return ExprError();
43074307

4308-
if (unsigned BuiltinID = FDecl->getBuiltinID()) {
4309-
// When not in Objective-C mode, there is no builtin 'id' type.
4310-
// We won't have pre-defined library functions which use this type.
4311-
if (getLangOptions().ObjC1 ||
4312-
Context.BuiltinInfo.GetTypeString(BuiltinID)[0] != 'G')
4313-
return CheckBuiltinFunctionCall(BuiltinID, TheCall);
4314-
}
4308+
if (unsigned BuiltinID = FDecl->getBuiltinID())
4309+
return CheckBuiltinFunctionCall(BuiltinID, TheCall);
43154310
} else if (NDecl) {
43164311
if (CheckBlockCall(NDecl, TheCall))
43174312
return ExprError();

Diff for: lib/Sema/SemaLookup.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,7 @@ static bool LookupBuiltin(Sema &S, LookupResult &R) {
484484
if (S.getLangOptions().CPlusPlus &&
485485
S.Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
486486
return false;
487-
// When not in Objective-C mode, there is no builtin 'id' type.
488-
// We won't have pre-defined library functions which use this type.
489-
if (!S.getLangOptions().ObjC1 &&
490-
S.Context.BuiltinInfo.GetTypeString(BuiltinID)[0] == 'G')
491-
return false;
492-
487+
493488
NamedDecl *D = S.LazilyCreateBuiltin((IdentifierInfo *)II, BuiltinID,
494489
S.TUScope, R.isForRedeclaration(),
495490
R.getNameLoc());

0 commit comments

Comments
 (0)