xref: /llvm-project/clang/test/Analysis/symbolcast-floatingpoint.cpp (revision 5d7fa481cf4d36e14345b1c3ebc951edda0b40b1)
1 // RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
2 // RUN:    -analyzer-config support-symbolic-integer-casts=false \
3 // RUN:    -verify %s
4 
5 // RUN: %clang_analyze_cc1 -x c++ -analyzer-checker=debug.ExprInspection \
6 // RUN:    -analyzer-config support-symbolic-integer-casts=true \
7 // RUN:    -verify %s
8 
9 template <typename T>
10 void clang_analyzer_dump(T);
11 
test_no_redundant_floating_point_cast(int n)12 void test_no_redundant_floating_point_cast(int n) {
13 
14   double D = n / 30;
15   clang_analyzer_dump(D); // expected-warning{{(double) ((reg_$0<int n>) / 30)}}
16 
17   // There are two cast operations evaluated above:
18   // 1. (n / 30) is cast to a double during the store of `D`.
19   // 2. Then in the next line, in RegionStore::getBinding during the load of `D`.
20   //
21   // We should not see in the dump of the SVal any redundant casts like
22   // (double) ((double) $n / 30)
23 
24 }
25