This revision was automatically updated to reflect the committed changes. Closed by commit rC326619: [analyzer] Don't throw NSNumberObjectConversion warning on object… (authored by george.karpenkov, committed by ). Herald added a subscriber: cfe-commits.
Repository: rC Clang https://reviews.llvm.org/D44044 Files: lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp test/Analysis/number-object-conversion.mm Index: test/Analysis/number-object-conversion.mm =================================================================== --- test/Analysis/number-object-conversion.mm +++ test/Analysis/number-object-conversion.mm @@ -0,0 +1,13 @@ +// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -fblocks -fobjc-arc -w -analyzer-checker=osx.NumberObjectConversion -analyzer-config osx.NumberObjectConversion:Pedantic=true %s -verify + +#include "Inputs/system-header-simulator-objc.h" + +NSNumber* generateNumber(); + +// expected-no-diagnostics +int test_initialization_in_ifstmt() { // Don't warn on initialization in guard. + if (NSNumber* number = generateNumber()) { // no-warning + return 0; + } + return 1; +} Index: lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp +++ lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp @@ -270,8 +270,10 @@ hasRHS(SuspiciousNumberObjectExprM))); auto ConversionThroughBranchingM = - ifStmt(hasCondition(SuspiciousNumberObjectExprM)) - .bind("pedantic"); + ifStmt(allOf( + hasCondition(SuspiciousNumberObjectExprM), + unless(hasConditionVariableStatement(declStmt()) + ))).bind("pedantic"); auto ConversionThroughCallM = callExpr(hasAnyArgument(allOf(hasType(SuspiciousScalarTypeM),
Index: test/Analysis/number-object-conversion.mm =================================================================== --- test/Analysis/number-object-conversion.mm +++ test/Analysis/number-object-conversion.mm @@ -0,0 +1,13 @@ +// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -fblocks -fobjc-arc -w -analyzer-checker=osx.NumberObjectConversion -analyzer-config osx.NumberObjectConversion:Pedantic=true %s -verify + +#include "Inputs/system-header-simulator-objc.h" + +NSNumber* generateNumber(); + +// expected-no-diagnostics +int test_initialization_in_ifstmt() { // Don't warn on initialization in guard. + if (NSNumber* number = generateNumber()) { // no-warning + return 0; + } + return 1; +} Index: lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp +++ lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp @@ -270,8 +270,10 @@ hasRHS(SuspiciousNumberObjectExprM))); auto ConversionThroughBranchingM = - ifStmt(hasCondition(SuspiciousNumberObjectExprM)) - .bind("pedantic"); + ifStmt(allOf( + hasCondition(SuspiciousNumberObjectExprM), + unless(hasConditionVariableStatement(declStmt()) + ))).bind("pedantic"); auto ConversionThroughCallM = callExpr(hasAnyArgument(allOf(hasType(SuspiciousScalarTypeM),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits