]> granicus.if.org Git - clang/commitdiff
Such function decls,as objc's objc_msgSend, builtins in
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 30 Nov 2010 17:35:24 +0000 (17:35 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 30 Nov 2010 17:35:24 +0000 (17:35 +0000)
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

clang.xcodeproj/project.pbxproj
include/clang/Basic/Builtins.def
include/clang/Basic/Builtins.h
lib/Basic/Builtins.cpp
lib/Basic/Targets.cpp
lib/Frontend/FrontendAction.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaLookup.cpp

index 877d81e61e19d4ae059b8183e3fbd784cdecf2fd..36660f04aa4beae4d633193d3c3f8d21b12ec26c 100644 (file)
                        isa = PBXProject;
                        buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
                        compatibilityVersion = "Xcode 2.4";
-                       developmentRegion = English;
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
index df5b11e2cde4940d2dafd634052efd357bac1afa..527244719c86a6a2551287c405b8ca4b576ad75e 100644 (file)
@@ -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
index fa437ffd6715b86d7b4612299db107f6386f5e1e..eb2604205280e1e1bbb301e9d32b5a211d656068 100644 (file)
@@ -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,
index 040cdb5d55f3746a7adbd01b240a990e7375ca4c..3eacb3aa6118cf796958a3a9811962251169adf6 100644 (file)
 #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);
index aa5147f76f01006f4ecfe5adc0a117d6b7ae02e3..122702923636aa00172550e972cb5994152cc9f9 100644 (file)
@@ -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.
index f70bc722697d913f5e11b584ca79268547d0fd18..6f9a1fbd593b7a52b2520503ddc5896028051e79 100644 (file)
@@ -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;
index 39a51c1acd6f3a1113d284a5a98876342f9326d7..c115061164dea8c3da633d7f0a18ef520c53ae1d 100644 (file)
@@ -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();
index 29b45df63b7f4cfa4a1fd38b85cf1cf37ffb2527..b73177e791bddb932ac912dd503bc22dc5596009 100644 (file)
@@ -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());