This is a patch containing some old stuff and some new stuff related to logical operators. Here are two old emails I've sent on this topic:
http://www.mail-archive.com/cil-users@lists.sourceforge.net/msg00143.html
http://www.mail-archive.com/cil-users@lists.sourceforge.net/msg00012.html

The first suggests removing the (incorrect) cast of the arguments to && and || to int. The second mentions two things: (1) removing '!= 0' comparisons when they are unnecessary because the underlying expression must already be boolean valued, and (2) retaining && and || operators (when useLogicalOperators is set to true) when the first operand (but not the second) has side effects.

The attached patch addresses those three items, and it also introduces a command-line option to set the useLogicalOperators flag.

Beyond these old ideas, there are two new items in this patch, about which I'm curious to hear people's feedback.

First, CIL already had a check to see if the first operand of && and || is constant, and it does a form of constant-folding in such cases. I added a similar check for the second operand, when it does not have side effects. One result of this, however, is that something like '*p && 0' will become simply '0', and if p was null, this means that the transformed program does not crash, whereas the original would have. I would argue that this an acceptable transformation, but I'm curious to hear if others disagree.

Second, this patch also (re-)introduces a Question variant for the Cil.exp type, representing a side-effect free use of the conditional operator '?:'. I addressed all of the compiler warnings about non- exhaustive pattern-matchings, but I'm not entirely sure I handled all of them properly. I'm also not sure the compiler warnings tell me everywhere that needs to change. (This patch only changes 8 files.) If someone who knows more than I about those pieces wants to double- check, that would be great. Even if the CIL owners don't want to reintroduce Question, I'd like to know if anyone notices anything obviously wrong about my modifications, because I think I want to use this myself.

In case anyone is curious, I want to retain these logical operators because my research group has a symbolic executor built on top of CIL. 'If' statements magnify the amount of work the executor has to do, but it can represent logical expressions, so retaining &&, ||, and ?: is beneficial.

Elnatan

Attachment: logicalOperatorsAndQuestion.patch
Description: Binary data

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
CIL-users mailing list
CIL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cil-users

Reply via email to