diff options
author | Jordan Rose <jordan_rose@apple.com> | 2014-01-16 18:02:23 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2014-01-16 18:02:23 +0000 |
commit | 2be02a784828c66d0025fe63a8e84751d6531a37 (patch) | |
tree | 8f11b2bf927593ab6e4450f5c1a77588d8c00855 /clang/test/Analysis/bitwise-ops.c | |
parent | ef6fed7c84e7e7a03aa26db4b6d96d91e521419c (diff) | |
download | bcm5719-llvm-2be02a784828c66d0025fe63a8e84751d6531a37.tar.gz bcm5719-llvm-2be02a784828c66d0025fe63a8e84751d6531a37.zip |
[analyzer] Shitfing a constant value by its bit width is undefined.
Citation: C++11 [expr.shift]p1 (and the equivalent text in C11).
This fixes PR18073, but the right thing to do (as noted in the FIXME) is to
have a real checker for too-large shifts.
llvm-svn: 199405
Diffstat (limited to 'clang/test/Analysis/bitwise-ops.c')
-rw-r--r-- | clang/test/Analysis/bitwise-ops.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/clang/test/Analysis/bitwise-ops.c b/clang/test/Analysis/bitwise-ops.c index bf282eca27d..01daf422962 100644 --- a/clang/test/Analysis/bitwise-ops.c +++ b/clang/test/Analysis/bitwise-ops.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -triple x86_64-apple-darwin13 -Wno-shift-count-overflow -verify %s void clang_analyzer_eval(int); #define CHECK(expr) if (!(expr)) return; clang_analyzer_eval(expr) @@ -11,4 +11,22 @@ void testPersistentConstraints(int x, int y) { // False positives due to SValBuilder giving up on certain kinds of exprs. CHECK(1 - x); // expected-warning{{UNKNOWN}} CHECK(x & y); // expected-warning{{UNKNOWN}} +} + +int testConstantShifts_PR18073(int which) { + // FIXME: We should have a checker that actually specifically checks bitwise + // shifts against the width of the LHS's /static/ type, rather than just + // having BasicValueFactory return "undefined" when dealing with two constant + // operands. + switch (which) { + case 1: + return 0ULL << 63; // no-warning + case 2: + return 0ULL << 64; // expected-warning{{The result of the '<<' expression is undefined}} + case 3: + return 0ULL << 65; // expected-warning{{The result of the '<<' expression is undefined}} + + default: + return 0; + } }
\ No newline at end of file |