[cfe-commits] r163562 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h lib/StaticAnalyzer/Core/AnalyzerOptions.cpp lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp test/Analysis/inlining/test_objc_inlining_option.m
Anna Zaks
ganna at apple.com
Mon Sep 10 15:56:42 PDT 2012
Author: zaks
Date: Mon Sep 10 17:56:41 2012
New Revision: 163562
URL: http://llvm.org/viewvc/llvm-project?rev=163562&view=rev
Log:
[analyzer] Add an option to enable/disable objc inlining.
Added:
cfe/trunk/test/Analysis/inlining/test_objc_inlining_option.m
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.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=163562&r1=163561&r2=163562&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Mon Sep 10 17:56:41 2012
@@ -178,6 +178,9 @@
/// \sa mayInlineTemplateFunctions
llvm::Optional<bool> InlineTemplateFunctions;
+ /// \sa mayInlineObjCMethod
+ llvm::Optional<bool> ObjCInliningMode;
+
// Cache of the "ipa-always-inline-size" setting.
// \sa getAlwaysInlineSize
llvm::Optional<unsigned> AlwaysInlineSize;
@@ -200,6 +203,9 @@
/// \sa CXXMemberInliningMode
bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const;
+ /// Returns true if ObjectiveC inlining is enabled, false otherwise.
+ bool mayInlineObjCMethod() const;
+
/// Returns whether or not the destructors for C++ temporary objects should
/// be included in the CFG.
///
Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=163562&r1=163561&r2=163562&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Mon Sep 10 17:56:41 2012
@@ -82,6 +82,14 @@
return *InlineTemplateFunctions;
}
+bool AnalyzerOptions::mayInlineObjCMethod() const {
+ if (!ObjCInliningMode.hasValue())
+ const_cast<llvm::Optional<bool> &>(ObjCInliningMode) =
+ getBooleanOption("objc-inlining", /*Default=*/true);
+
+ return *ObjCInliningMode;
+}
+
int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) const {
std::string OptStr = Config.lookup(Name);
if (OptStr.empty())
@@ -97,9 +105,8 @@
unsigned AnalyzerOptions::getAlwaysInlineSize() const {
if (!AlwaysInlineSize.hasValue()) {
unsigned DefaultSize = 3;
- Optional<unsigned> &MutableOption =
- const_cast<Optional<unsigned> &>(AlwaysInlineSize);
- MutableOption = getOptionAsInteger("ipa-always-inline-size", DefaultSize);
+ const_cast<Optional<unsigned> &>(AlwaysInlineSize) =
+ getOptionAsInteger("ipa-always-inline-size", DefaultSize);
}
return AlwaysInlineSize.getValue();
Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=163562&r1=163561&r2=163562&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Mon Sep 10 17:56:41 2012
@@ -448,6 +448,8 @@
break;
}
case CE_ObjCMessage:
+ if (!Opts.mayInlineObjCMethod())
+ return false;
if (!(getAnalysisManager().options.IPAMode == DynamicDispatch ||
getAnalysisManager().options.IPAMode == DynamicDispatchBifurcate))
return false;
Added: cfe/trunk/test/Analysis/inlining/test_objc_inlining_option.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/test_objc_inlining_option.m?rev=163562&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/inlining/test_objc_inlining_option.m (added)
+++ cfe/trunk/test/Analysis/inlining/test_objc_inlining_option.m Mon Sep 10 17:56:41 2012
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-ipa=dynamic-bifurcate -analyzer-config objc-inlining=false -verify %s
+
+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;
+-(id)autorelease;
+-(id)copy;
+- (Class)class;
+-(id)retain;
+ at end
+
+// Vanila: ObjC class method is called by name.
+ at interface MyParent : NSObject
++ (int)getInt;
+ at end
+ at interface MyClass : MyParent
++ (int)getInt;
+ at end
+ at implementation MyClass
++ (int)testClassMethodByName {
+ int y = [MyClass getInt];
+ return 5/y; // no-warning
+}
++ (int)getInt {
+ return 0;
+}
+ at end
\ No newline at end of file
More information about the cfe-commits
mailing list