This revision was automatically updated to reflect the committed changes.
martong marked an inline comment as done.
Closed by commit rG015c39882ebc: [Analyzer] Infer 0 value when the divisible is 
0 (bug fix) (authored by martong).

Changed prior to commit:
  https://reviews.llvm.org/D99343?vs=333308&id=333341#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99343/new/

https://reviews.llvm.org/D99343

Files:
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/zero-operands.c


Index: clang/test/Analysis/zero-operands.c
===================================================================
--- /dev/null
+++ clang/test/Analysis/zero-operands.c
@@ -0,0 +1,53 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify %s
+
+void clang_analyzer_dump(int);
+
+void test_0_multiplier1(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a * y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+}}<int y>}}
+}
+
+void test_0_multiplier2(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = y * a;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+}}<int y>}}
+}
+
+void test_0_modulo(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a % y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 % (reg_${{[[:digit:]]+}}<int y>)}}
+}
+
+void test_0_divisible(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a / y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 / (reg_${{[[:digit:]]+}}<int y>)}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -652,6 +652,8 @@
         if (LHSValue == 0)
           return evalCastFromNonLoc(lhs, resultTy);
         return makeSymExprValNN(op, InputLHS, InputRHS, resultTy);
+      case BO_Div:
+        // 0 / x == 0
       case BO_Rem:
         // 0 % x == 0
         if (LHSValue == 0)


Index: clang/test/Analysis/zero-operands.c
===================================================================
--- /dev/null
+++ clang/test/Analysis/zero-operands.c
@@ -0,0 +1,53 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify %s
+
+void clang_analyzer_dump(int);
+
+void test_0_multiplier1(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a * y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+}}<int y>}}
+}
+
+void test_0_multiplier2(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = y * a;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{reg_${{[[:digit:]]+}}<int y>}}
+}
+
+void test_0_modulo(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a % y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 % (reg_${{[[:digit:]]+}}<int y>)}}
+}
+
+void test_0_divisible(int x, int y) {
+  int a = x < 0; // Eagerly bifurcate.
+  clang_analyzer_dump(a);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning@-2{{1 S32b}}
+
+  int b = a / y;
+  clang_analyzer_dump(b);
+  // expected-warning@-1{{0 S32b}}
+  // expected-warning-re@-2{{1 / (reg_${{[[:digit:]]+}}<int y>)}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -652,6 +652,8 @@
         if (LHSValue == 0)
           return evalCastFromNonLoc(lhs, resultTy);
         return makeSymExprValNN(op, InputLHS, InputRHS, resultTy);
+      case BO_Div:
+        // 0 / x == 0
       case BO_Rem:
         // 0 % x == 0
         if (LHSValue == 0)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to