xref: /minix3/external/bsd/llvm/dist/clang/test/Analysis/bitwise-ops.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc void clang_analyzer_eval(int);
4f4a2713aSLionel Sambuc #define CHECK(expr) if (!(expr)) return; clang_analyzer_eval(expr)
5f4a2713aSLionel Sambuc 
testPersistentConstraints(int x,int y)6f4a2713aSLionel Sambuc void testPersistentConstraints(int x, int y) {
7f4a2713aSLionel Sambuc   // Sanity check
8f4a2713aSLionel Sambuc   CHECK(x); // expected-warning{{TRUE}}
9f4a2713aSLionel Sambuc   CHECK(x & 1); // expected-warning{{TRUE}}
10f4a2713aSLionel Sambuc 
11f4a2713aSLionel Sambuc   // False positives due to SValBuilder giving up on certain kinds of exprs.
12f4a2713aSLionel Sambuc   CHECK(1 - x); // expected-warning{{UNKNOWN}}
13f4a2713aSLionel Sambuc   CHECK(x & y); // expected-warning{{UNKNOWN}}
14f4a2713aSLionel Sambuc }
15*0a6a1f1dSLionel Sambuc 
testConstantShifts_PR18073(int which)16*0a6a1f1dSLionel Sambuc int testConstantShifts_PR18073(int which) {
17*0a6a1f1dSLionel Sambuc   // FIXME: We should have a checker that actually specifically checks bitwise
18*0a6a1f1dSLionel Sambuc   // shifts against the width of the LHS's /static/ type, rather than just
19*0a6a1f1dSLionel Sambuc   // having BasicValueFactory return "undefined" when dealing with two constant
20*0a6a1f1dSLionel Sambuc   // operands.
21*0a6a1f1dSLionel Sambuc   switch (which) {
22*0a6a1f1dSLionel Sambuc   case 1:
23*0a6a1f1dSLionel Sambuc     return 0ULL << 63; // no-warning
24*0a6a1f1dSLionel Sambuc   case 2:
25*0a6a1f1dSLionel Sambuc     return 0ULL << 64; // expected-warning{{The result of the '<<' expression is undefined}}
26*0a6a1f1dSLionel Sambuc   case 3:
27*0a6a1f1dSLionel Sambuc     return 0ULL << 65; // expected-warning{{The result of the '<<' expression is undefined}}
28*0a6a1f1dSLionel Sambuc 
29*0a6a1f1dSLionel Sambuc   default:
30*0a6a1f1dSLionel Sambuc     return 0;
31*0a6a1f1dSLionel Sambuc   }
32*0a6a1f1dSLionel Sambuc }