[PATCH] D44044: [analyzer] Don't throw NSNumberObjectConversion warning on object initialization in if-expression
George Karpenkov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 2 13:39:26 PST 2018
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),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44044.136842.patch
Type: text/x-patch
Size: 1457 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180302/36bd8713/attachment.bin>
More information about the cfe-commits
mailing list