Skip to content
Snippets Groups Projects
Commit 5446f4df authored by Anna Zaks's avatar Anna Zaks
Browse files

[analyzer] Add an option to enable/disable objc inlining.

llvm-svn: 163562
parent 38e05a9e
No related branches found
No related tags found
No related merge requests found
...@@ -178,6 +178,9 @@ private: ...@@ -178,6 +178,9 @@ private:
/// \sa mayInlineTemplateFunctions /// \sa mayInlineTemplateFunctions
llvm::Optional<bool> InlineTemplateFunctions; llvm::Optional<bool> InlineTemplateFunctions;
/// \sa mayInlineObjCMethod
llvm::Optional<bool> ObjCInliningMode;
// Cache of the "ipa-always-inline-size" setting. // Cache of the "ipa-always-inline-size" setting.
// \sa getAlwaysInlineSize // \sa getAlwaysInlineSize
llvm::Optional<unsigned> AlwaysInlineSize; llvm::Optional<unsigned> AlwaysInlineSize;
...@@ -200,6 +203,9 @@ public: ...@@ -200,6 +203,9 @@ public:
/// \sa CXXMemberInliningMode /// \sa CXXMemberInliningMode
bool mayInlineCXXMemberFunction(CXXInlineableMemberKind K) const; 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 /// Returns whether or not the destructors for C++ temporary objects should
/// be included in the CFG. /// be included in the CFG.
/// ///
......
...@@ -82,6 +82,14 @@ bool AnalyzerOptions::mayInlineTemplateFunctions() const { ...@@ -82,6 +82,14 @@ bool AnalyzerOptions::mayInlineTemplateFunctions() const {
return *InlineTemplateFunctions; 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 { int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) const {
std::string OptStr = Config.lookup(Name); std::string OptStr = Config.lookup(Name);
if (OptStr.empty()) if (OptStr.empty())
...@@ -97,9 +105,8 @@ int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) const { ...@@ -97,9 +105,8 @@ int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) const {
unsigned AnalyzerOptions::getAlwaysInlineSize() const { unsigned AnalyzerOptions::getAlwaysInlineSize() const {
if (!AlwaysInlineSize.hasValue()) { if (!AlwaysInlineSize.hasValue()) {
unsigned DefaultSize = 3; unsigned DefaultSize = 3;
Optional<unsigned> &MutableOption = const_cast<Optional<unsigned> &>(AlwaysInlineSize) =
const_cast<Optional<unsigned> &>(AlwaysInlineSize); getOptionAsInteger("ipa-always-inline-size", DefaultSize);
MutableOption = getOptionAsInteger("ipa-always-inline-size", DefaultSize);
} }
return AlwaysInlineSize.getValue(); return AlwaysInlineSize.getValue();
......
...@@ -448,6 +448,8 @@ bool ExprEngine::inlineCall(const CallEvent &Call, const Decl *D, ...@@ -448,6 +448,8 @@ bool ExprEngine::inlineCall(const CallEvent &Call, const Decl *D,
break; break;
} }
case CE_ObjCMessage: case CE_ObjCMessage:
if (!Opts.mayInlineObjCMethod())
return false;
if (!(getAnalysisManager().options.IPAMode == DynamicDispatch || if (!(getAnalysisManager().options.IPAMode == DynamicDispatch ||
getAnalysisManager().options.IPAMode == DynamicDispatchBifurcate)) getAnalysisManager().options.IPAMode == DynamicDispatchBifurcate))
return false; return false;
......
// 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;
@protocol NSObject - (BOOL)isEqual:(id)object; @end
@interface NSObject <NSObject> {}
+(id)alloc;
-(id)init;
-(id)autorelease;
-(id)copy;
- (Class)class;
-(id)retain;
@end
// Vanila: ObjC class method is called by name.
@interface MyParent : NSObject
+ (int)getInt;
@end
@interface MyClass : MyParent
+ (int)getInt;
@end
@implementation MyClass
+ (int)testClassMethodByName {
int y = [MyClass getInt];
return 5/y; // no-warning
}
+ (int)getInt {
return 0;
}
@end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment