File tree 3 files changed +40
-0
lines changed
3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ // These need to be constant-folded at compile time
2
+
3
+ #define C1 (int)(0. / 1. + 0.5)
4
+ #define C2 (int)(1. / 1. + 0.5)
5
+
6
+ int nondet_int ();
7
+
8
+ int main (void )
9
+ {
10
+ int i = nondet_int ();
11
+
12
+ switch (i )
13
+ {
14
+ case C1 :
15
+ break ;
16
+
17
+ case C2 :
18
+ break ;
19
+
20
+ default :
21
+ break ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
7
+ --
8
+ ^warning: ignoring
Original file line number Diff line number Diff line change 26
26
#include < util/simplify_expr.h>
27
27
#include < util/string_constant.h>
28
28
29
+ #include < goto-programs/adjust_float_expressions.h>
30
+
29
31
#include " builtin_factory.h"
30
32
#include " c_typecast.h"
31
33
#include " c_qualifiers.h"
@@ -3451,6 +3453,13 @@ void c_typecheck_baset::typecheck_side_effect_assignment(
3451
3453
3452
3454
void c_typecheck_baset::make_constant (exprt &expr)
3453
3455
{
3456
+ // Floating-point expressions may require a rounding mode.
3457
+ // ISO 9899:1999 F.7.2 says that the default is "round to nearest".
3458
+ // Some compilers have command-line options to override.
3459
+ const auto rounding_mode =
3460
+ from_integer (ieee_floatt::ROUND_TO_EVEN, signed_int_type ());
3461
+ adjust_float_expressions (expr, rounding_mode);
3462
+
3454
3463
simplify (expr, *this );
3455
3464
3456
3465
if (!expr.is_constant () &&
You can’t perform that action at this time.
0 commit comments