sigprocmask: Fix configuration failure on Solaris 10 (regr. 2020-07-25).
[gnulib.git] / tests / test-verify.c
blob7201ca1fffaa3bf096dea86add0fa4e2d89947be
1 /* Test the "verify" module.
3 Copyright (C) 2005, 2009-2020 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Written by Bruno Haible. */
20 #include <config.h>
22 #include "verify.h"
24 #ifndef EXP_FAIL
25 # define EXP_FAIL 0
26 #endif
28 /* ======================= Test verify, verify_expr ======================= */
30 int x;
31 enum { a, b, c };
33 #if EXP_FAIL == 1
34 verify (x >= 0); /* should give ERROR: non-constant expression */
35 #endif
36 verify (c == 2); /* should be ok */
37 #if EXP_FAIL == 2
38 verify (1 + 1 == 3); /* should give ERROR */
39 #endif
40 verify (1 == 1); verify (1 == 1); /* should be ok */
42 enum
44 item = verify_expr (1 == 1, 10 * 0 + 17) /* should be ok */
47 static int
48 function (int n)
50 #if EXP_FAIL == 3
51 verify (n >= 0); /* should give ERROR: non-constant expression */
52 #endif
53 verify (c == 2); /* should be ok */
54 #if EXP_FAIL == 4
55 verify (1 + 1 == 3); /* should give ERROR */
56 #endif
57 verify (1 == 1); verify (1 == 1); /* should be ok */
59 if (n)
60 return ((void) verify_expr (1 == 1, 1), verify_expr (1 == 1, 8)); /* should be ok */
61 #if EXP_FAIL == 5
62 return verify_expr (1 == 2, 5); /* should give ERROR */
63 #endif
64 return 0;
67 int
68 main (void)
70 return !(function (0) == 0 && function (1) == 8);
73 /* ============================== Test assume ============================== */
75 static int
76 f (int a)
78 return a;
81 typedef struct { unsigned int context : 4; unsigned int halt : 1; } state;
83 void
84 test_assume_expressions (state *s)
86 /* Check that 'assume' accepts a function call, even of a non-const
87 function. */
88 assume (f (1));
89 /* Check that 'assume' accepts a bit-field expression. */
90 assume (s->halt);
93 int
94 test_assume_optimization (int x)
96 /* Check that the compiler uses 'assume' for optimization.
97 This function, when compiled with optimization, should have code
98 equivalent to
99 return x + 3;
100 Use 'objdump --disassemble test-verify.o' to verify this. */
101 assume (x >= 4);
102 return (x > 1 ? x + 3 : 2 * x + 10);
105 _Noreturn void
106 test_assume_noreturn (void)
108 /* Check that the compiler's data-flow analysis recognizes 'assume (0)'.
109 This function should not elicit a warning. */
110 assume (0);