wire up a new -fno-builtin option, make it control things like simplifylibcalls,
etc and make freestanding imply it.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66972 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index b33f344..6d9aaa7 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -231,6 +231,11 @@
                             "freestanding environment"));
 
 static llvm::cl::opt<bool>
+NoBuiltin("fno-builtin",
+          llvm::cl::desc("Disable implicit builtin knowledge of functions"));
+
+
+static llvm::cl::opt<bool>
 MathErrno("fmath-errno", 
           llvm::cl::desc("Require math functions to respect errno"),
           llvm::cl::init(true), llvm::cl::AllowInverse);
@@ -650,8 +655,11 @@
   if (EnableBlocks.getPosition())
     Options.Blocks = EnableBlocks;
 
+  if (NoBuiltin)
+    Options.NoBuiltin = 1;
   if (Freestanding)
-    Options.Freestanding = 1;
+    Options.Freestanding = Options.NoBuiltin = 1;
+  
   if (EnableHeinousExtensions)
     Options.HeinousExtensions = 1;
 
@@ -1195,7 +1203,7 @@
   // FIXME: There are llvm-gcc options to control these selectively.
   Opts.InlineFunctions = (Opts.OptimizationLevel > 1);
   Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
-  Opts.SimplifyLibCalls = !Freestanding;
+  Opts.SimplifyLibCalls = !NoBuiltin;
 
 #ifdef NDEBUG
   Opts.VerifyModule = 0;
diff --git a/include/clang/AST/Builtins.h b/include/clang/AST/Builtins.h
index ad71375..2eabd88 100644
--- a/include/clang/AST/Builtins.h
+++ b/include/clang/AST/Builtins.h
@@ -56,7 +56,7 @@
   /// appropriate builtin ID # and mark any non-portable builtin identifiers as
   /// such.
   void InitializeBuiltins(IdentifierTable &Table, const TargetInfo &Target,
-                          bool Freestanding = false);
+                          bool NoBuiltins = false);
   
   /// Builtin::GetName - Return the identifier name for the specified builtin,
   /// e.g. "__builtin_abs".
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index f0a583c..ee04439 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -48,6 +48,7 @@
 
   unsigned NeXTRuntime       : 1; // Use NeXT runtime.
   unsigned Freestanding      : 1; // Freestanding implementation
+  unsigned NoBuiltin         : 1; // Do not use builtin functions (-fno-builtin)
 
   unsigned ThreadsafeStatics : 1; // Whether static initializers are protected
                                   // by locks.
@@ -75,7 +76,7 @@
     GC = ObjC1 = ObjC2 = ObjCNonFragileABI = 0;
     C99 = Microsoft = CPlusPlus = CPlusPlus0x = NoExtensions = 0;
     CXXOperatorNames = PascalStrings = Boolean = WritableStrings = 0;
-    Exceptions = NeXTRuntime = Freestanding = 0;
+    Exceptions = NeXTRuntime = Freestanding = NoBuiltin = 0;
     LaxVectorConversions = 1;
     HeinousExtensions = 0;
     
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index a51f432..80e1774 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -39,7 +39,7 @@
 {  
   if (size_reserve > 0) Types.reserve(size_reserve);    
   InitBuiltinTypes();
-  BuiltinInfo.InitializeBuiltins(idents, Target, LangOpts.Freestanding);
+  BuiltinInfo.InitializeBuiltins(idents, Target, LangOpts.NoBuiltin);
   TUDecl = TranslationUnitDecl::Create(*this);
 }
 
diff --git a/lib/AST/Builtins.cpp b/lib/AST/Builtins.cpp
index 46b0346..4655cf3 100644
--- a/lib/AST/Builtins.cpp
+++ b/lib/AST/Builtins.cpp
@@ -38,12 +38,11 @@
 /// such.
 void Builtin::Context::InitializeBuiltins(IdentifierTable &Table,
                                           const TargetInfo &Target,
-                                          bool Freestanding) {
+                                          bool NoBuiltins) {
   // 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 &&
-        (!Freestanding || 
-         !strchr(BuiltinInfo[i].Attributes, 'f')))
+        (!NoBuiltins || !strchr(BuiltinInfo[i].Attributes, 'f')))
       Table.get(BuiltinInfo[i].Name).setBuiltinID(i);
   
   // Step #2: Get target builtins.
@@ -52,7 +51,7 @@
   // Step #3: Register target-specific builtins.
   for (unsigned i = 0, e = NumTSRecords; i != e; ++i)
     if (!TSRecords[i].Suppressed &&
-        (!Freestanding || 
+        (!NoBuiltins || 
          (TSRecords[i].Attributes && 
           !strchr(TSRecords[i].Attributes, 'f'))))
       Table.get(TSRecords[i].Name).setBuiltinID(i+Builtin::FirstTSBuiltin);