1/*
2 * Copyright 2014, NICTA
3 *
4 * This software may be distributed and modified according to the terms of
5 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
6 * See "LICENSE_BSD2.txt" for details.
7 *
8 * @TAG(NICTA_BSD)
9 */
10
11/* Basic undefinedness requirements
12
13   A.  arg2 not too large
14         if result is unsigned [A+]: arg2 < 32
15         if result is signed   [A-]: arg1 * 2^arg2 < 2^31
16   B.  arg2 nonnegative
17         if arg2 is unsigned:  - (nothing required)
18         if arg2 is signed [B-]: 0 <= arg2
19   C.  arg1 nonnegative
20         if arg1 is unsigned:  - (nothing required)
21         if arg1 is signed [C-]: 0 <= arg1
22*/
23
24unsigned f(void)
25{
26  int i = -1;
27  unsigned larg = 4;
28  int test1 = (i << 3);       /* [A- = 7, B- = 4, C- = 1] */
29  int test2 = (larg << 32);   /* [A+ = 3, B- = 6, C+ = -] */
30  int test3 = (i << larg);    /* [A- = 5, B+ = -, C- = 1] */
31  int test4 = (larg << larg); /* [A+ = 8, B+ = -, C+ = -] */
32
33  //  1. 0 <= i      (left argument must be non-negative)
34  //  2.
35  //  3. 32 < 32     (right argument must be less than width of promoted left
36  //                  argument's type, when promoted type is unsigned)
37  //  4. 0 <= 3      (shift amount must be non-negative)
38  //  5. i * 2^larg < 2^31
39  //                 (when result is signed, result can't be too large)
40  //  6. 0 <= 32     (signed right argument must be non-negative)
41  //  7. i * 2^3 < 2^31
42  //                 (when result is signed, result can't be too large)
43  //  8. larg < 32   (when argument is unsigned, must be < result's width)
44
45  return 3;
46
47}
48