cil-project / cil

C Intermediate Language
Other
348 stars 86 forks source link

Does copyFunction handle CFG-computed successors and predecessors lists? #27

Open IagoAbal opened 8 years ago

IagoAbal commented 8 years ago

The docs for copyFunction do not specify what is the behavior of this function when computeCFGInfo has been called on the given fundec. I have preemptively looked into copyFunction's definition and it seems that this case is not handled, vstmt does not touch succs nor preds. This could break the stated invariant that

There should be no sharing between the copy and the original function

The fix should be relatively easy, we need to patch the succs and preds fields of each statement in a similar way as it is done for goto and switch. Something like

stmtmap |> IH.iter (fun _ s ->
    s.succs <- List.map (fun s1 -> findStmt !s1.sid) s.succs;
    s.preds <- List.map (fun s1 -> findStmt !s1.sid) s.preds
    )

Should I?

Warning: I have not yet tried to copy a fundec after computing CFG info. I report this issue based on my sole understanding of the code.

Thanks!