CBMC
Loading...
Searching...
No Matches
gcc_conditional_expression.h File Reference

Lowering of GCC's conditional expression with omitted middle operand. More...

#include <util/invariant.h>
#include <util/std_code.h>
#include <util/std_expr.h>
#include <util/std_types.h>
Include dependency graph for gcc_conditional_expression.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

if_exprt lower_gcc_conditional_expression (const side_effect_exprt &expr)
 Lower a single GCC conditional expression with omitted middle operand.
void lower_gcc_conditional_expressions (exprt &expr)
 Recursively lower all GCC conditional expressions with omitted middle operand in expr.

Detailed Description

Lowering of GCC's conditional expression with omitted middle operand.

GCC's a ? : b is rewritten into an equivalent if-expression.

Definition in file gcc_conditional_expression.h.

Function Documentation

◆ lower_gcc_conditional_expression()

if_exprt lower_gcc_conditional_expression ( const side_effect_exprt & expr)
inline

Lower a single GCC conditional expression with omitted middle operand.

Rewrites the side effect a ? : b into the equivalent if-expression (a != 0) ? a : b. This drops the guarantee that a is evaluated only once, so it is only valid where a has no side effects – i.e. in constant contexts, or after side effects have already been removed (as in goto conversion).

Parameters
expra side_effect_exprt whose statement is ID_gcc_conditional_expression and which has exactly two operands
Returns
the equivalent if-expression, carrying expr's type and location

Definition at line 32 of file gcc_conditional_expression.h.

◆ lower_gcc_conditional_expressions()

void lower_gcc_conditional_expressions ( exprt & expr)
inline

Recursively lower all GCC conditional expressions with omitted middle operand in expr.

Rewrites every side effect a ? : b into the if-expression (a != 0) ? a : b. Only valid in constant contexts, where the once-only evaluation of a is immaterial (there are no side effects), so that the simplifier can fold the result.

Definition at line 52 of file gcc_conditional_expression.h.