Closed SaswatPadhi closed 3 years ago
cc: @feliperodri @tautschnig
cc. @chrisr-diffblue
That's horrible :-\
Conjecture : your problem is here:
cfgt
is called by cfg_dominatorst
which is called by natural_loops
. It fails to detect an edge and thus it is not a loop.
Fixing it at the source is ... going to be unpleasant, ironically for the same reason that this bug happened in the first place.
My suggested work-around is to insert calls to goto_instrument_parse_optionst::do_indirect_call_and_rtti_removal
before the natural loop and contract code.
Joining this conversation with some delay. @martin-cs Many thanks for root causing this! While I agree that "normal" form(s) aren't properly defined for now, we should review why cfg_dominatorst
even is using an inter-procedural CFG. I would like to think that procedure-local CFGs should be good enough for both dominators and natural loops? I'll take a proper look at the code.
My guess (not recalling that I had worked on this!) is that the edge computation is general purpose and interprocedural and used for many things and natural loop computation just uses that without really thinking about the consequences.
It looks like the issue should be worked around using @martin-cs' suggestion after the merge of #6340 .
Let us know if this has been fixed adequately for your use case, or if we need to be doing something more.
@SaswatPadhi, can you confirm this works now. And, if so, close the ticket.
The fix seems to work for the loop contracts I added to s2n_set_binary_search
, so I am closing this issue now.
Thanks @NlightNFotis and @martin-cs!
CBMC version: 556b4325 Operating system: Mac OS 10.15.7
Test case:
Exact command line resulting in the issue:
What behaviour did you expect:
The loop invariant would be used and unwinding wouldn't be necessary.
What happened instead:
The loop invariant is not used because the loop in
main
is not recognized.Note that if we use
adder
in place oflocal_adder
within the loop, then the loop is detected and the loop invariant is processed as expected.Additional context:
If we use
adder
in place oflocal_adder
above, i.e. call the function directly as opposed to using a function pointer, then loop is detected and invariant is processed as expected.The following instrumentation code:
produces the following output when using
local_adder
function pointerand produces the following output when using
adder
directly