about summary refs log tree commit diff homepage
path: root/runtime/Intrinsic/klee_overshift_check.c
blob: c0cb6102f8531d65f8c0680b660d8eb127444716 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//===-- klee_overshift_check.c ---------------------------------------------===//
//
//                     The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include <klee/klee.h>

/* This instrumentation call is used to check for overshifting.
 * If we do try to do x << y or x >> y
 * where
 *   bitWidth = sizeof(x)*8
 *   shift = y
 *
 * then we can detect overshifting (which has undefined behaviour).
 */
void klee_overshift_check(unsigned long long bitWidth, unsigned long long shift) {
  if (shift >= bitWidth) {
    /* Maybe we shouldn't throw an error because
     * overshifting can be non-fatal? Perhaps
     * we should generate a test case but carry
     * on executing the state with a warning?
     */
    klee_report_error("IGNORED", 0 /*Ignored */, "overshift error", "overshift.err");
  }
}