1/* { dg-do compile } */
2/* { dg-options "-fsanitize=undefined -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow" } */
3
4/* Test that we don't instrument functions marked with
5   no_sanitize_undefined attribute.  */
6
7#ifndef __cplusplus
8#define bool _Bool
9#endif
10enum A { B = -3, C = 2 } a;
11bool b;
12
13__attribute__((no_sanitize_undefined))
14static void
15vla_bound (void)
16{
17  int i = -1;
18  volatile int a[i];
19}
20
21__attribute__((no_sanitize_undefined))
22static void
23si_overflow (void)
24{
25  int x = 123, y = 267;
26  volatile int z1 = x + y;
27  volatile int z2 = x - y;
28  volatile int z3 = x * y;
29  volatile int z4 = x / y;
30}
31
32__attribute__((no_sanitize_undefined))
33static void
34null (int *p)
35{
36  *p = 42;
37}
38
39__attribute__((no_sanitize_undefined))
40static void
41retrn (int *p)
42{
43  *p = 42;
44}
45
46__attribute__((no_sanitize_undefined))
47static enum A
48bool_enum (bool *p)
49{
50  *p = b;
51  return a;
52}
53
54__attribute__((no_sanitize_undefined))
55static void
56float_zero (void)
57{
58  volatile float a = 4.2f, b = 0.0f, c;
59  c = a / b;
60}
61
62__attribute__((no_sanitize_undefined))
63static void
64float_cast (void)
65{
66  volatile double d = 300;
67  volatile signed char c;
68  c = d;
69}
70
71/* { dg-final { scan-assembler-not "__ubsan_handle" } } */
72