Feature #9985
closedFold temporary variables back
0%
Description
To simplify complex expressions that contain function calls CIL introduces temporary variables. This is good for internals but not so good for users of outputted code.
Files
Updated by Evgeny Novikov about 5 years ago
- Blocks Feature #9825: Get rid of temporary variables and their removing added
Updated by Evgeny Novikov almost 5 years ago
- Blocks Feature #9906: Update CIL added
Updated by Mikhail Mandrykin almost 5 years ago
- Status changed from New to Open
- Ternary operator
_?_:_
is not supported and is rewritten into an if — then — else with a temporary variable as before - Constant initializers still use temporary variables with the names of the form __const_expr#
- Expression statements of the form
{ ...; result }
still introduce a temporary variable
Many other constructions, notably, nested function calls, side-effecting expressions, and some type casts are successfully inlined. The inlining is activated with an option -fold-temp-vars
. I'd also recommend to use it in conjunction with -no-single-return
, -keep-logical-operators
and -no-print-cil-as-is
(the default) to make the resulting output as close as possible to the original source.
Updated by Evgeny Novikov almost 5 years ago
- File hwa-rc.zip hwa-rc.zip added
After running something like:
toplevel.opt "-no-autoload-plugins" "-no-findlib" "-kernel-log" "e:problem desc.txt" "-machdep" "gcc_x86_64" "-c11" "-kernel-warn-key" "CERT:MSC:38=active" "-remove-unused-inline-functions" "-remove-unused-static-functions" "-no-annot" "-no-single-return" "-fold-temp-vars" "-shrink-initializers" "-print-cil-as-is" "-keep-logical-operators" "-aggressive-merging" "-print" "-print-lines" "-no-print-annot" "-ocode" "cil.i" ...
on the code attached, I got invalid statements as a result:
usb_fill_int_urb(hwarc->neep_urb,usb_dev,08 tmp_1 = __create_pipe(usb_dev,(unsigned int)epd->bEndpointAddress) | 1073741952U,hwarc->rd_buffer,4096,& hwarc_neep_cb,(void *)hwarc,(int)epd->bInterval);
Updated by Evgeny Novikov almost 5 years ago
- File pata_arasan_cf.zip pata_arasan_cf.zip added
Another failure (perhaps due to the same reasons) is for the attached code:
#line 614 return 614 tmp = devm_kmalloc(dev,size,gfp | 32768U);
Updated by Mikhail Mandrykin almost 5 years ago
Fixed in framac|7d70550d. This was due to -print-lines
interfering with intermediate printing of nested expressions, the new option was not tested in this combination yet.
Updated by Evgeny Novikov almost 5 years ago
There are still temporary variables in such statements as "if (!func(...)) ...".
Updated by Evgeny Novikov almost 5 years ago
- File i7300_idle.i.zip i7300_idle.i.zip added
I attached an example where this issue exists.
Updated by Mikhail Mandrykin almost 5 years ago
Added a special case for int casts in conditional expressions in framac|918782e6. (int)cond
was treated differently because CIL only supports logical expressions with side effects as conditions in if statements (note that there is no way to use A && B
if B
has a side-effect and we do not unfold temporary variables, but at the Cabs2cil
stage this is not yet known and moreover can fail in general), in other contexts they are rewritten to temporaries as if cond then 1 else 0
. With an additional cast the logical expression becomes nested into another expression and is rewritten with a temporary.
Updated by Evgeny Novikov almost 5 years ago
- Status changed from Open to Closed
Despite some explicitly mentioned and expected cases the new option works perfectly. At last we see no temporary variables in Klever while there is no more an in-house dreadful code that folded them for violation witnesses.