Semantic constant folding
- Overview
-
The Semantic constant folding plug-in produces an output program where C expressions which are established as constant by the Value analysis plug-in are replaced by their value. Because it relies on EVA, it is able to do more of these simplifications than a syntactic analysis would. The output program is guaranteed to be compilable C code, and to have the same semantics as the original program.
The plug-in performs propagation of constant integers and addresses, but at this time, it does not handle floating-point values.
- Usage
-
The command-line options related to constant folding are:
- -semantic-const-folding
activate semantic constant folding and pretty print the new source code. - -semantic-const-fold f1,...,fn
replace constant expressions in functions f1,...,fn. - -cast-from-constant
allow introduction of new casts from a folded constant.
- -semantic-const-folding
- Example
-
Consider the code fragment:
p = &x; x = 3; send(*p+4);
The Semantic constant folding plug-in produces:
p = &x; x = 3; send(7);
If you need to remove the (now useless) first two statements, you may make use of the Spare Code analysis plug-in.