aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/ubsan/signed1bitfield-1.c
blob: 2ba8cf4dab0d083318974ec5e02bf6642f322cbd (plain)
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
/* { dg-do run } */
/* { dg-options "-O2 -fsanitize=undefined" } */

/* PR tree-optimization/115154 */
/* This was being miscompiled with -fsanitize=undefined due to
   `(signed:1)(t*5)` being transformed into `-((signed:1)t)` which
   is undefined. */

struct s {
  signed b : 1;
} f;
int i = 55;
__attribute__((noinline))
void check(int a)
{
        if (!a)
        __builtin_abort();
}
int main() {
    int t = i != 5;
    t = t*5;
    f.b = t;
    int tt = f.b;
    check(f.b);
}