-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C front-end: constant folding for floating-point
- Loading branch information
Daniel Kroening
committed
Jul 17, 2018
1 parent
8542137
commit 171bf92
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// These need to be constant-folded at compile time | ||
|
||
#define C1 (int) ( 0. / 1. + 0.5) | ||
#define C2 (int) ( 1. / 1. + 0.5) | ||
|
||
int nondet_int(); | ||
|
||
int main(void) | ||
{ | ||
int i=nondet_int(); | ||
|
||
switch(i) | ||
{ | ||
case C1: | ||
break; | ||
|
||
case C2: | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
main.c | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ Author: Daniel Kroening, [email protected] | |
#include <util/simplify_expr.h> | ||
#include <util/string_constant.h> | ||
|
||
#include <goto-programs/adjust_float_expressions.h> | ||
|
||
#include "builtin_factory.h" | ||
#include "c_typecast.h" | ||
#include "c_qualifiers.h" | ||
|
@@ -3372,6 +3374,13 @@ void c_typecheck_baset::typecheck_side_effect_assignment( | |
|
||
void c_typecheck_baset::make_constant(exprt &expr) | ||
{ | ||
// Floating-point expressions may require a rounding mode. | ||
// The compile-time rounding mode may differ from the | ||
// run-time rounding mode. | ||
const auto rounding_mode = | ||
from_integer(config.ansi_c.rounding_mode, signed_int_type()); | ||
adjust_float_expressions(expr, rounding_mode); | ||
|
||
simplify(expr, *this); | ||
|
||
if(!expr.is_constant() && | ||
|