diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-11-30 17:35:24 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-11-30 17:35:24 +0000 |
commit | 67aba816901503d9cf7ba699525fa62cc7f8e5e4 (patch) | |
tree | cdf41986024677632d6c4ca9e373b01d1d481b29 | |
parent | 7e4857931bfe27bb355275bc7ec1eaa44612dfff (diff) |
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
-rw-r--r-- | clang.xcodeproj/project.pbxproj | 1 | ||||
-rw-r--r-- | include/clang/Basic/Builtins.def | 122 | ||||
-rw-r--r-- | include/clang/Basic/Builtins.h | 13 | ||||
-rw-r--r-- | lib/Basic/Builtins.cpp | 19 | ||||
-rw-r--r-- | lib/Basic/Targets.cpp | 15 | ||||
-rw-r--r-- | lib/Frontend/FrontendAction.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 7 |
8 files changed, 97 insertions, 91 deletions
diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index 877d81e61e..36660f04aa 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -2063,7 +2063,6 @@ isa = PBXProject; buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */; compatibilityVersion = "Xcode 2.4"; - developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( English, diff --git a/include/clang/Basic/Builtins.def b/include/clang/Basic/Builtins.def index df5b11e2cd..527244719c 100644 --- a/include/clang/Basic/Builtins.def +++ b/include/clang/Basic/Builtins.def @@ -78,7 +78,7 @@ // FIXME: gcc has nonnull #if defined(BUILTIN) && !defined(LIBBUILTIN) -# define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) BUILTIN(ID, TYPE, ATTRS) +# define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) BUILTIN(ID, TYPE, ATTRS) #endif // Standard libc/libm functions: @@ -512,85 +512,85 @@ BUILTIN(__noop, "v.", "n") // C99 library functions // C99 stdlib.h -LIBBUILTIN(abort, "v", "fr", "stdlib.h") -LIBBUILTIN(calloc, "v*zz", "f", "stdlib.h") -LIBBUILTIN(exit, "vi", "fr", "stdlib.h") -LIBBUILTIN(_Exit, "vi", "fr", "stdlib.h") -LIBBUILTIN(malloc, "v*z", "f", "stdlib.h") -LIBBUILTIN(realloc, "v*v*z", "f", "stdlib.h") +LIBBUILTIN(abort, "v", "fr", "stdlib.h", ALL_LANGUAGES) +LIBBUILTIN(calloc, "v*zz", "f", "stdlib.h", ALL_LANGUAGES) +LIBBUILTIN(exit, "vi", "fr", "stdlib.h", ALL_LANGUAGES) +LIBBUILTIN(_Exit, "vi", "fr", "stdlib.h", ALL_LANGUAGES) +LIBBUILTIN(malloc, "v*z", "f", "stdlib.h", ALL_LANGUAGES) +LIBBUILTIN(realloc, "v*v*z", "f", "stdlib.h", ALL_LANGUAGES) // C99 string.h -LIBBUILTIN(memcpy, "v*v*vC*z", "f", "string.h") -LIBBUILTIN(memmove, "v*v*vC*z", "f", "string.h") -LIBBUILTIN(strcpy, "c*c*cC*", "f", "string.h") -LIBBUILTIN(strncpy, "c*c*cC*z", "f", "string.h") -LIBBUILTIN(strcat, "c*c*cC*", "f", "string.h") -LIBBUILTIN(strncat, "c*c*cC*z", "f", "string.h") -LIBBUILTIN(strxfrm, "zc*cC*z", "f", "string.h") -LIBBUILTIN(memchr, "v*vC*iz", "f", "string.h") -LIBBUILTIN(strchr, "c*cC*i", "f", "string.h") -LIBBUILTIN(strcspn, "zcC*cC*", "f", "string.h") -LIBBUILTIN(strpbrk, "c*cC*cC*", "f", "string.h") -LIBBUILTIN(strrchr, "c*cC*i", "f", "string.h") -LIBBUILTIN(strspn, "zcC*cC*", "f", "string.h") -LIBBUILTIN(strstr, "c*cC*cC*", "f", "string.h") -LIBBUILTIN(strtok, "c*c*cC*", "f", "string.h") -LIBBUILTIN(memset, "v*v*iz", "f", "string.h") -LIBBUILTIN(strerror, "c*i", "f", "string.h") -LIBBUILTIN(strlen, "zcC*", "f", "string.h") +LIBBUILTIN(memcpy, "v*v*vC*z", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(memmove, "v*v*vC*z", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strcpy, "c*c*cC*", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strncpy, "c*c*cC*z", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strcat, "c*c*cC*", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strncat, "c*c*cC*z", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strxfrm, "zc*cC*z", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(memchr, "v*vC*iz", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strchr, "c*cC*i", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strcspn, "zcC*cC*", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strpbrk, "c*cC*cC*", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strrchr, "c*cC*i", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strspn, "zcC*cC*", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strstr, "c*cC*cC*", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strtok, "c*c*cC*", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(memset, "v*v*iz", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strerror, "c*i", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strlen, "zcC*", "f", "string.h", ALL_LANGUAGES) // C99 stdio.h -LIBBUILTIN(printf, "icC*.", "fp:0:", "stdio.h") -LIBBUILTIN(fprintf, "iP*cC*.", "fp:1:", "stdio.h") -LIBBUILTIN(snprintf, "ic*zcC*.", "fp:2:", "stdio.h") -LIBBUILTIN(sprintf, "ic*cC*.", "fp:1:", "stdio.h") -LIBBUILTIN(vprintf, "icC*a", "fP:0:", "stdio.h") -LIBBUILTIN(vfprintf, "i.", "fP:1:", "stdio.h") -LIBBUILTIN(vsnprintf, "ic*zcC*a", "fP:2:", "stdio.h") -LIBBUILTIN(vsprintf, "ic*cC*a", "fP:1:", "stdio.h") -LIBBUILTIN(scanf, "icC*.", "fs:0:", "stdio.h") +LIBBUILTIN(printf, "icC*.", "fp:0:", "stdio.h", ALL_LANGUAGES) +LIBBUILTIN(fprintf, "iP*cC*.", "fp:1:", "stdio.h", ALL_LANGUAGES) +LIBBUILTIN(snprintf, "ic*zcC*.", "fp:2:", "stdio.h", ALL_LANGUAGES) +LIBBUILTIN(sprintf, "ic*cC*.", "fp:1:", "stdio.h", ALL_LANGUAGES) +LIBBUILTIN(vprintf, "icC*a", "fP:0:", "stdio.h", ALL_LANGUAGES) +LIBBUILTIN(vfprintf, "i.", "fP:1:", "stdio.h", ALL_LANGUAGES) +LIBBUILTIN(vsnprintf, "ic*zcC*a", "fP:2:", "stdio.h", ALL_LANGUAGES) +LIBBUILTIN(vsprintf, "ic*cC*a", "fP:1:", "stdio.h", ALL_LANGUAGES) +LIBBUILTIN(scanf, "icC*.", "fs:0:", "stdio.h", ALL_LANGUAGES) // C99 -LIBBUILTIN(longjmp, "vJi", "fr", "setjmp.h") +LIBBUILTIN(longjmp, "vJi", "fr", "setjmp.h", ALL_LANGUAGES) // Non-C library functions // FIXME: Non-C-standard stuff shouldn't be builtins in non-GNU mode! -LIBBUILTIN(alloca, "v*z", "f", "stdlib.h") +LIBBUILTIN(alloca, "v*z", "f", "stdlib.h", ALL_LANGUAGES) // POSIX string.h -LIBBUILTIN(stpcpy, "c*c*cC*", "f", "string.h") -LIBBUILTIN(stpncpy, "c*c*cC*z", "f", "string.h") -LIBBUILTIN(strdup, "c*cC*", "f", "string.h") -LIBBUILTIN(strndup, "c*cC*z", "f", "string.h") +LIBBUILTIN(stpcpy, "c*c*cC*", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(stpncpy, "c*c*cC*z", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strdup, "c*cC*", "f", "string.h", ALL_LANGUAGES) +LIBBUILTIN(strndup, "c*cC*z", "f", "string.h", ALL_LANGUAGES) // POSIX strings.h -LIBBUILTIN(index, "c*cC*i", "f", "strings.h") -LIBBUILTIN(rindex, "c*cC*i", "f", "strings.h") -LIBBUILTIN(bzero, "vv*z", "f", "strings.h") +LIBBUILTIN(index, "c*cC*i", "f", "strings.h", ALL_LANGUAGES) +LIBBUILTIN(rindex, "c*cC*i", "f", "strings.h", ALL_LANGUAGES) +LIBBUILTIN(bzero, "vv*z", "f", "strings.h", ALL_LANGUAGES) // POSIX unistd.h -LIBBUILTIN(_exit, "vi", "fr", "unistd.h") +LIBBUILTIN(_exit, "vi", "fr", "unistd.h", ALL_LANGUAGES) // POSIX setjmp.h -LIBBUILTIN(_longjmp, "vJi", "fr", "setjmp.h") -LIBBUILTIN(siglongjmp, "vSJi", "fr", "setjmp.h") +LIBBUILTIN(_longjmp, "vJi", "fr", "setjmp.h", ALL_LANGUAGES) +LIBBUILTIN(siglongjmp, "vSJi", "fr", "setjmp.h", ALL_LANGUAGES) // id objc_msgSend(id, SEL, ...) -LIBBUILTIN(objc_msgSend, "GGH.", "f", "objc/message.h") +LIBBUILTIN(objc_msgSend, "GGH.", "f", "objc/message.h", OBJC_LANG) BUILTIN(__builtin_objc_memmove_collectable, "v*v*vC*z", "nF") // Builtin math library functions -LIBBUILTIN(pow, "ddd", "fe", "math.h") -LIBBUILTIN(powl, "LdLdLd", "fe", "math.h") -LIBBUILTIN(powf, "fff", "fe", "math.h") +LIBBUILTIN(pow, "ddd", "fe", "math.h", ALL_LANGUAGES) +LIBBUILTIN(powl, "LdLdLd", "fe", "math.h", ALL_LANGUAGES) +LIBBUILTIN(powf, "fff", "fe", "math.h", ALL_LANGUAGES) -LIBBUILTIN(sqrt, "dd", "fe", "math.h") -LIBBUILTIN(sqrtl, "LdLd", "fe", "math.h") -LIBBUILTIN(sqrtf, "ff", "fe", "math.h") +LIBBUILTIN(sqrt, "dd", "fe", "math.h", ALL_LANGUAGES) +LIBBUILTIN(sqrtl, "LdLd", "fe", "math.h", ALL_LANGUAGES) +LIBBUILTIN(sqrtf, "ff", "fe", "math.h", ALL_LANGUAGES) -LIBBUILTIN(sin, "dd", "fe", "math.h") -LIBBUILTIN(sinl, "LdLd", "fe", "math.h") -LIBBUILTIN(sinf, "ff", "fe", "math.h") +LIBBUILTIN(sin, "dd", "fe", "math.h", ALL_LANGUAGES) +LIBBUILTIN(sinl, "LdLd", "fe", "math.h", ALL_LANGUAGES) +LIBBUILTIN(sinf, "ff", "fe", "math.h", ALL_LANGUAGES) -LIBBUILTIN(cos, "dd", "fe", "math.h") -LIBBUILTIN(cosl, "LdLd", "fe", "math.h") -LIBBUILTIN(cosf, "ff", "fe", "math.h") +LIBBUILTIN(cos, "dd", "fe", "math.h", ALL_LANGUAGES) +LIBBUILTIN(cosl, "LdLd", "fe", "math.h", ALL_LANGUAGES) +LIBBUILTIN(cosf, "ff", "fe", "math.h", ALL_LANGUAGES) // Blocks runtime Builtin math library functions -LIBBUILTIN(_Block_object_assign, "vv*vC*iC", "f", "Blocks.h") -LIBBUILTIN(_Block_object_dispose, "vvC*iC", "f", "Blocks.h") +LIBBUILTIN(_Block_object_assign, "vv*vC*iC", "f", "Blocks.h", ALL_LANGUAGES) +LIBBUILTIN(_Block_object_dispose, "vvC*iC", "f", "Blocks.h", ALL_LANGUAGES) // FIXME: Also declare NSConcreteGlobalBlock and NSConcreteStackBlock. #undef BUILTIN diff --git a/include/clang/Basic/Builtins.h b/include/clang/Basic/Builtins.h index fa437ffd67..eb26042052 100644 --- a/include/clang/Basic/Builtins.h +++ b/include/clang/Basic/Builtins.h @@ -30,7 +30,15 @@ namespace clang { class IdentifierTable; class ASTContext; class QualType; - + class LangOptions; + + enum LANGUAGEID { + C_LANG = 0x1, // builtin for c only. + CXX_LANG = 0x2, // builtin for cplusplus only. + OBJC_LANG = 0x4, // builtin for objective-c and objective-c++ + ALL_LANGUAGES = (C_LANG|CXX_LANG|OBJC_LANG) //builtin is for all languages. + }; + namespace Builtin { enum ID { NotBuiltin = 0, // This is not a builtin function. @@ -41,6 +49,7 @@ enum ID { struct Info { const char *Name, *Type, *Attributes, *HeaderName; + LANGUAGEID builtin_lang; bool Suppressed; bool operator==(const Info &RHS) const { @@ -62,7 +71,7 @@ public: /// InitializeBuiltins - Mark the identifiers for all the builtins with their /// appropriate builtin ID # and mark any non-portable builtin identifiers as /// such. - void InitializeBuiltins(IdentifierTable &Table, bool NoBuiltins = false); + void InitializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts); /// \brief Popular the vector with the names of all of the builtins. void GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names, diff --git a/lib/Basic/Builtins.cpp b/lib/Basic/Builtins.cpp index 040cdb5d55..3eacb3aa61 100644 --- a/lib/Basic/Builtins.cpp +++ b/lib/Basic/Builtins.cpp @@ -14,12 +14,14 @@ #include "clang/Basic/Builtins.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/TargetInfo.h" +#include "clang/Basic/LangOptions.h" using namespace clang; static const Builtin::Info BuiltinInfo[] = { - { "not a builtin function", 0, 0, 0, false }, -#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, -#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, + { "not a builtin function", 0, 0, 0, ALL_LANGUAGES, false }, +#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false }, +#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) { #ID, TYPE, ATTRS, HEADER,\ + BUILTIN_LANG, false }, #include "clang/Basic/Builtins.def" }; @@ -41,17 +43,20 @@ Builtin::Context::Context(const TargetInfo &Target) { /// appropriate builtin ID # and mark any non-portable builtin identifiers as /// such. void Builtin::Context::InitializeBuiltins(IdentifierTable &Table, - bool NoBuiltins) { + const LangOptions& LangOpts) { // Step #1: mark all target-independent builtins with their ID's. for (unsigned i = Builtin::NotBuiltin+1; i != Builtin::FirstTSBuiltin; ++i) if (!BuiltinInfo[i].Suppressed && - (!NoBuiltins || !strchr(BuiltinInfo[i].Attributes, 'f'))) - Table.get(BuiltinInfo[i].Name).setBuiltinID(i); + (!LangOpts.NoBuiltin || !strchr(BuiltinInfo[i].Attributes, 'f'))) { + if (LangOpts.ObjC1 || + BuiltinInfo[i].builtin_lang != clang::OBJC_LANG) + Table.get(BuiltinInfo[i].Name).setBuiltinID(i); + } // Step #2: Register target-specific builtins. for (unsigned i = 0, e = NumTSRecords; i != e; ++i) if (!TSRecords[i].Suppressed && - (!NoBuiltins || + (!LangOpts.NoBuiltin || (TSRecords[i].Attributes && !strchr(TSRecords[i].Attributes, 'f')))) Table.get(TSRecords[i].Name).setBuiltinID(i+Builtin::FirstTSBuiltin); diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index aa5147f76f..1227029236 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -598,8 +598,9 @@ public: }; const Builtin::Info PPCTargetInfo::BuiltinInfo[] = { -#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, -#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, +#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false }, +#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ + ALL_LANGUAGES, false }, #include "clang/Basic/BuiltinsPPC.def" }; @@ -924,8 +925,9 @@ void MBlazeTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, namespace { // Namespace for x86 abstract base class const Builtin::Info BuiltinInfo[] = { -#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, -#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, +#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false }, +#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ + ALL_LANGUAGES, false }, #include "clang/Basic/BuiltinsX86.def" }; @@ -1948,8 +1950,9 @@ void ARMTargetInfo::getGCCRegAliases(const GCCRegAlias *&Aliases, } const Builtin::Info ARMTargetInfo::BuiltinInfo[] = { -#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, false }, -#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER, false }, +#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES, false }, +#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) { #ID, TYPE, ATTRS, HEADER,\ + ALL_LANGUAGES, false }, #include "clang/Basic/BuiltinsARM.def" }; } // end anonymous namespace. diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index f70bc72269..6f9a1fbd59 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -202,7 +202,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, if (!CI.hasASTContext() || !CI.getASTContext().getExternalSource()) { Preprocessor &PP = CI.getPreprocessor(); PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(), - PP.getLangOptions().NoBuiltin); + PP.getLangOptions()); } return true; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 39a51c1acd..c115061164 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4305,13 +4305,8 @@ Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, if (CheckFunctionCall(FDecl, TheCall)) return ExprError(); - if (unsigned BuiltinID = FDecl->getBuiltinID()) { - // When not in Objective-C mode, there is no builtin 'id' type. - // We won't have pre-defined library functions which use this type. - if (getLangOptions().ObjC1 || - Context.BuiltinInfo.GetTypeString(BuiltinID)[0] != 'G') - return CheckBuiltinFunctionCall(BuiltinID, TheCall); - } + if (unsigned BuiltinID = FDecl->getBuiltinID()) + return CheckBuiltinFunctionCall(BuiltinID, TheCall); } else if (NDecl) { if (CheckBlockCall(NDecl, TheCall)) return ExprError(); diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 29b45df63b..b73177e791 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -484,12 +484,7 @@ static bool LookupBuiltin(Sema &S, LookupResult &R) { if (S.getLangOptions().CPlusPlus && S.Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) return false; - // When not in Objective-C mode, there is no builtin 'id' type. - // We won't have pre-defined library functions which use this type. - if (!S.getLangOptions().ObjC1 && - S.Context.BuiltinInfo.GetTypeString(BuiltinID)[0] == 'G') - return false; - + NamedDecl *D = S.LazilyCreateBuiltin((IdentifierInfo *)II, BuiltinID, S.TUScope, R.isForRedeclaration(), R.getNameLoc()); |