[cfe-commits] r173386 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h lib/StaticAnalyzer/Core/AnalyzerOptions.cpp test/Analysis/analyzer-config.c test/Analysis/analyzer-config.cpp test/Analysis/shallow-mode.m
Anna Zaks
ganna at apple.com
Thu Jan 24 15:15:34 PST 2013
Author: zaks
Date: Thu Jan 24 17:15:34 2013
New Revision: 173386
URL: http://llvm.org/viewvc/llvm-project?rev=173386&view=rev
Log:
[analyzer] Add "-analyzer-config mode=[deep|shallow] ".
The idea is to introduce a higher level "user mode" option for
different use scenarios. For example, if one wants to run the analyzer
for a small project each time the code is built, they would use
the "shallow" mode.
The user mode option will influence the default settings for the
lower-level analyzer options. For now, this just influences the ipa
modes, but we plan to find more optimal settings for them.
Added:
cfe/trunk/test/Analysis/shallow-mode.m
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/test/Analysis/analyzer-config.c
cfe/trunk/test/Analysis/analyzer-config.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=173386&r1=173385&r2=173386&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Thu Jan 24 17:15:34 2013
@@ -105,8 +105,7 @@
/// Inline C functions and blocks when their definitions are available.
IPAK_BasicInlining = 2,
- /// Inline callees when their definitions are available.
- // TODO: How is this different from BasicInlining?
+ /// Inline callees(C, C++, ObjC) when their definitions are available.
IPAK_Inlining = 3,
/// Enable inlining of dynamically dispatched methods.
@@ -176,6 +175,20 @@
AnalysisInliningMode InliningMode;
private:
+ /// \brief Describes the kinds for high-level analyzer mode.
+ enum UserModeKind {
+ UMK_NotSet = 0,
+ /// Perform shallow but fast analyzes.
+ UMK_Shallow = 1,
+ /// Perform deep analyzes.
+ UMK_Deep = 2
+ };
+
+ /// Controls the high-level analyzer mode, which influences the default
+ /// settings for some of the lower-level config options (such as IPAMode).
+ /// \sa getUserMode
+ UserModeKind UserMode;
+
/// Controls the mode of inter-procedural analysis.
IPAKind IPAMode;
@@ -224,6 +237,11 @@
int getOptionAsInteger(StringRef Name, int DefaultVal);
public:
+ /// \brief Retrieves and sets the UserMode. This is a high-level option,
+ /// which is used to set other low-level options. It is not accessible
+ /// outside of AnalyzerOptions.
+ UserModeKind getUserMode();
+
/// \brief Returns the inter-procedural analysis mode.
IPAKind getIPAMode();
Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=173386&r1=173385&r2=173386&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Thu Jan 24 17:15:34 2013
@@ -20,12 +20,34 @@
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 not set or 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 = "basic-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",
- "dynamic-bifurcate").getValue());
+ StringRef ModeStr(Config.GetOrCreateValue("ipa", DefaultIPA).getValue());
IPAKind IPAConfig = llvm::StringSwitch<IPAKind>(ModeStr)
.Case("none", IPAK_None)
.Case("basic-inlining", IPAK_BasicInlining)
Modified: cfe/trunk/test/Analysis/analyzer-config.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.c?rev=173386&r1=173385&r2=173386&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/analyzer-config.c (original)
+++ cfe/trunk/test/Analysis/analyzer-config.c Thu Jan 24 17:15:34 2013
@@ -11,5 +11,6 @@
// CHECK-NEXT: ipa = dynamic-bifurcate
// CHECK-NEXT: ipa-always-inline-size = 3
// CHECK-NEXT: max-times-inline-large = 32
+// CHECK-NEXT: mode = deep
// CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 6
+// CHECK-NEXT: num-entries = 7
Modified: cfe/trunk/test/Analysis/analyzer-config.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/analyzer-config.cpp?rev=173386&r1=173385&r2=173386&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/analyzer-config.cpp (original)
+++ cfe/trunk/test/Analysis/analyzer-config.cpp Thu Jan 24 17:15:34 2013
@@ -20,5 +20,6 @@
// CHECK-NEXT: ipa = dynamic-bifurcate
// CHECK-NEXT: ipa-always-inline-size = 3
// CHECK-NEXT: max-times-inline-large = 32
+// CHECK-NEXT: mode = deep
// CHECK-NEXT: [stats]
-// CHECK-NEXT: num-entries = 9
+// CHECK-NEXT: num-entries = 10
Added: cfe/trunk/test/Analysis/shallow-mode.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/shallow-mode.m?rev=173386&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/shallow-mode.m (added)
+++ cfe/trunk/test/Analysis/shallow-mode.m Thu Jan 24 17:15:34 2013
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config mode=shallow -verify %s
+// expected-no-diagnostics
+
+void clang_analyzer_checkInlined(unsigned);
+
+typedef signed char BOOL;
+typedef struct objc_class *Class;
+typedef struct objc_object {
+ Class isa;
+} *id;
+ at protocol NSObject - (BOOL)isEqual:(id)object; @end
+ at interface NSObject <NSObject> {}
++(id)alloc;
+-(id)init;
+ at end
+
+ at interface MyClass : NSObject
++ (void)callee;
++ (void)caller;
+ at end
+
+ at implementation MyClass
++ (void)caller {
+ [MyClass callee];
+}
++ (void)callee {
+ clang_analyzer_checkInlined(0); // The call is not inlined.
+}
+ at end
\ No newline at end of file
More information about the cfe-commits
mailing list