From c72c57c9e9b69944e3e009cd5e209634839581d3 Mon Sep 17 00:00:00 2001
From: dim <dim@FreeBSD.org>
Date: Mon, 8 Apr 2013 18:45:10 +0000
Subject: Vendor import of clang trunk r178860:
 http://llvm.org/svn/llvm-project/cfe/trunk@178860

---
 lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 134 ++++++++++++++++++++++++++--
 1 file changed, 126 insertions(+), 8 deletions(-)

(limited to 'lib/StaticAnalyzer/Core/AnalyzerOptions.cpp')

diff --git a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
index da88589..ae70739 100644
--- a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -13,23 +13,68 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
-#include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 using namespace llvm;
 
+AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() {
+  if (UserMode == UMK_NotSet) {
+    StringRef ModeStr(Config.GetOrCreateValue("mode", "deep").getValue());
+    UserMode = llvm::StringSwitch<UserModeKind>(ModeStr)
+      .Case("shallow", UMK_Shallow)
+      .Case("deep", UMK_Deep)
+      .Default(UMK_NotSet);
+    assert(UserMode != UMK_NotSet && "User mode is invalid.");
+  }
+  return UserMode;
+}
+
+IPAKind AnalyzerOptions::getIPAMode() {
+  if (IPAMode == IPAK_NotSet) {
+
+    // Use the User Mode to set the default IPA value.
+    // Note, we have to add the string to the Config map for the ConfigDumper
+    // checker to function properly.
+    const char *DefaultIPA = 0;
+    UserModeKind HighLevelMode = getUserMode();
+    if (HighLevelMode == UMK_Shallow)
+      DefaultIPA = "inlining";
+    else if (HighLevelMode == UMK_Deep)
+      DefaultIPA = "dynamic-bifurcate";
+    assert(DefaultIPA);
+
+    // Lookup the ipa configuration option, use the default from User Mode.
+    StringRef ModeStr(Config.GetOrCreateValue("ipa", DefaultIPA).getValue());
+    IPAKind IPAConfig = llvm::StringSwitch<IPAKind>(ModeStr)
+            .Case("none", IPAK_None)
+            .Case("basic-inlining", IPAK_BasicInlining)
+            .Case("inlining", IPAK_Inlining)
+            .Case("dynamic", IPAK_DynamicDispatch)
+            .Case("dynamic-bifurcate", IPAK_DynamicDispatchBifurcate)
+            .Default(IPAK_NotSet);
+    assert(IPAConfig != IPAK_NotSet && "IPA Mode is invalid.");
+
+    // Set the member variable.
+    IPAMode = IPAConfig;
+  }
+  
+  return IPAMode;
+}
+
 bool
 AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind K) {
-  if (IPAMode < Inlining)
+  if (getIPAMode() < IPAK_Inlining)
     return false;
 
   if (!CXXMemberInliningMode) {
     static const char *ModeKey = "c++-inlining";
     
     StringRef ModeStr(Config.GetOrCreateValue(ModeKey,
-                                              "methods").getValue());
+                                              "destructors").getValue());
 
     CXXInlineableMemberKind &MutableMode =
       const_cast<CXXInlineableMemberKind &>(CXXMemberInliningMode);
@@ -64,8 +109,7 @@ bool AnalyzerOptions::getBooleanOption(StringRef Name, bool DefaultVal) {
       .Default(DefaultVal);
 }
 
-bool AnalyzerOptions::getBooleanOption(llvm::Optional<bool> &V,
-                                       StringRef Name,
+bool AnalyzerOptions::getBooleanOption(Optional<bool> &V, StringRef Name,
                                        bool DefaultVal) {
   if (!V.hasValue())
     V = getBooleanOption(Name, DefaultVal);
@@ -90,14 +134,21 @@ bool AnalyzerOptions::mayInlineTemplateFunctions() {
                           /*Default=*/true);
 }
 
+bool AnalyzerOptions::mayInlineCXXContainerCtorsAndDtors() {
+  return getBooleanOption(InlineCXXContainerCtorsAndDtors,
+                          "c++-container-inlining",
+                          /*Default=*/false);
+}
+
+
 bool AnalyzerOptions::mayInlineObjCMethod() {
   return getBooleanOption(ObjCInliningMode,
                           "objc-inlining",
                           /* Default = */ true);
 }
 
-bool AnalyzerOptions::shouldPruneNullReturnPaths() {
-  return getBooleanOption(PruneNullReturnPaths,
+bool AnalyzerOptions::shouldSuppressNullReturnPaths() {
+  return getBooleanOption(SuppressNullReturnPaths,
                           "suppress-null-return-paths",
                           /* Default = */ true);
 }
@@ -108,8 +159,20 @@ bool AnalyzerOptions::shouldAvoidSuppressingNullArgumentPaths() {
                           /* Default = */ false);
 }
 
+bool AnalyzerOptions::shouldSuppressInlinedDefensiveChecks() {
+  return getBooleanOption(SuppressInlinedDefensiveChecks,
+                          "suppress-inlined-defensive-checks",
+                          /* Default = */ true);
+}
+
+bool AnalyzerOptions::shouldSuppressFromCXXStandardLibrary() {
+  return getBooleanOption(SuppressFromCXXStandardLibrary,
+                          "suppress-c++-stdlib",
+                          /* Default = */ false);
+}
+
 int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) {
-  llvm::SmallString<10> StrBuf;
+  SmallString<10> StrBuf;
   llvm::raw_svector_ostream OS(StrBuf);
   OS << DefaultVal;
   
@@ -127,12 +190,67 @@ unsigned AnalyzerOptions::getAlwaysInlineSize() {
   return AlwaysInlineSize.getValue();
 }
 
+unsigned AnalyzerOptions::getMaxInlinableSize() {
+  if (!MaxInlinableSize.hasValue()) {
+
+    int DefaultValue = 0;
+    UserModeKind HighLevelMode = getUserMode();
+    switch (HighLevelMode) {
+      default:
+        llvm_unreachable("Invalid mode.");
+      case UMK_Shallow:
+        DefaultValue = 4;
+        break;
+      case UMK_Deep:
+        DefaultValue = 50;
+        break;
+    }
+
+    MaxInlinableSize = getOptionAsInteger("max-inlinable-size", DefaultValue);
+  }
+  return MaxInlinableSize.getValue();
+}
+
 unsigned AnalyzerOptions::getGraphTrimInterval() {
   if (!GraphTrimInterval.hasValue())
     GraphTrimInterval = getOptionAsInteger("graph-trim-interval", 1000);
   return GraphTrimInterval.getValue();
 }
 
+unsigned AnalyzerOptions::getMaxTimesInlineLarge() {
+  if (!MaxTimesInlineLarge.hasValue())
+    MaxTimesInlineLarge = getOptionAsInteger("max-times-inline-large", 32);
+  return MaxTimesInlineLarge.getValue();
+}
+
+unsigned AnalyzerOptions::getMaxNodesPerTopLevelFunction() {
+  if (!MaxNodesPerTopLevelFunction.hasValue()) {
+    int DefaultValue = 0;
+    UserModeKind HighLevelMode = getUserMode();
+    switch (HighLevelMode) {
+      default:
+        llvm_unreachable("Invalid mode.");
+      case UMK_Shallow:
+        DefaultValue = 75000;
+        break;
+      case UMK_Deep:
+        DefaultValue = 150000;
+        break;
+    }
+    MaxNodesPerTopLevelFunction = getOptionAsInteger("max-nodes", DefaultValue);
+  }
+  return MaxNodesPerTopLevelFunction.getValue();
+}
+
 bool AnalyzerOptions::shouldSynthesizeBodies() {
   return getBooleanOption("faux-bodies", true);
 }
+
+bool AnalyzerOptions::shouldPrunePaths() {
+  return getBooleanOption("prune-paths", true);
+}
+
+bool AnalyzerOptions::shouldConditionalizeStaticInitializers() {
+  return getBooleanOption("cfg-conditional-static-initializers", true);
+}
+
-- 
cgit v1.1