Repository navigation
Conversation
A parameter passed by value whose copy shares nothing with the argument, so the callee cannot change the argument. BY_VALUE does not say this: frontends set it on parameters that receive an object, slice or map the callee can change.
|
|
Thanks, Markus. The real problem is the existing labels: across the frontends they are wrong far more often than right. On Joern master, 9 of the 13 frontends that set
Only javasrc2cpg, jimple2cpg, abap2cpg and pysrc2cpg match their language. On top of that, x2cpg's method stubs set Even a That is why I asked for a new value: using
For more information, see joernio/joern#6529, including its comments. So this PR is no longer needed, and I'm closing it. |
This PR adds
BY_COPYto theEvaluationStrategiesconstants: a parameter passed by value whose copy shares nothing with the argument, so the callee cannot change the argument. A consumer such as Joern's reaching-definition pass can then tell, from the callee's parameter alone, that a call does not write a variable it is given.Problem
No existing value says that a call cannot change an argument:
BY_VALUEis defined as "passed by value which means a flat copy is used". A flat copy can still share: forvoid f(struct Node n)withstruct Node { struct Node *next; },fgets a copy of the pointer and can change the nodes it reaches.nis a correctBY_VALUEby that definition, andfcan change the argument.BY_REFERENCEandBY_SHARINGsay that the callee can.In practice
BY_VALUEis wider still. On Joern master, the frontends set these on method parameters:this/selfBY_VALUE, pointers, arrays and references included;...and macro parameters tooBY_SHARINGBY_VALUEfor primitives,BY_SHARINGotherwiseBY_SHARINGBY_VALUEfor primitive, void and null types,BY_SHARINGotherwiseBY_SHARINGBY_VALUE; the implicit lambda parameteritBY_REFERENCEBY_SHARINGBY_VALUEBY_VALUEBY_VALUE,inoutincludedBY_SHARINGBY_SHARINGfor a pointer type,BY_VALUEotherwise, slices, maps, channels and interfaces includedBY_REFERENCEfor&$x,BY_VALUEotherwiseBY_SHARINGBY_VALUEforVALUE(...),BY_REFERENCEotherwiseBY_SHARINGBY_SHARINGBY_REFERENCEBY_SHARINGBY_SHARINGBY_VALUEforself,BY_SHARINGfor&selfBY_SHARING(marked TODO),refandoutincludedBY_SHARINGBY_VALUEBY_VALUESo
BY_VALUEis set on parameters that share their argument with the caller: pointers in C and C++, objects in Kotlin, JavaScript, Swift and PHP, and slices, maps and interfaces in Go. Apart from the code that builds the graph, which sets the strategy and copies it to output parameters and closure bindings, no code readsEVALUATION_STRATEGY, so none of this has mattered: Joern's reaching-definition pass treats every argument of a call as defined by the call.So the existing labels cannot be trusted to say that a callee cannot change an argument. Making them trustworthy means reviewing every frontend against its language; that is each frontend's work, and this change does not take it on. A new value of the existing property lets a frontend mark what it has decided, without changing any other frontend's graphs: a frontend sets
BY_COPYonly where it knows the copy shares nothing, and every other parameter keeps the strategy it has now.Change
CallGraph.scalaadds the constant, andEVALUATION_STRATEGY's description lists it:ProtoIds.ByCopyis 4, the next free ID among the strategies. The domain classes are regenerated. Nothing else changes: no frontend setsBY_COPYyet. Each language decides whether it needs handling different from what Joern does now, with value(s) of its own.EvaluationStrategies.BY_COPYis a new public name.Testing
sbt test: 27 passed, 0 failed.testFullpasses (8,524 tests), with c2cpg settingBY_COPYand the reaching-definition pass reading it. That Joern change will update [c2cpg][dataflowengineoss] Optionally do not treat a call as defining a variable it receives by value joernio/joern#6529 once this is released.