Skip to content

Commit

Permalink
Infer type of wrapper-function args from call-site
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertMensing committed Jan 22, 2025
1 parent ccb94cc commit 580e370
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/rewrite/vct/rewrite/lang/LangLLVMToCol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,27 @@ case class LangLLVMToCol[Pre <: Generation](rw: LangSpecificToCol[Pre])
)
)
case inv: LLVMFunctionInvocation[Pre] =>
inv.ref.decl.importedArguments.getOrElse(inv.ref.decl.args).zipWithIndex
.foreach { case (a, i) =>
getVariable(inv.args(i))
.foreach(v => addTypeGuess(v, Set.empty, _ => a.t))
val calledFunc = inv.ref.decl
val isWrapperFunc = calledFunc.pallasExprWrapperFor.isDefined
calledFunc.importedArguments.getOrElse(calledFunc.args).zipWithIndex
.foreach { case (arg, idx) =>
// Infer type of variable that is used as arg in function call
// from function definition
getVariable(inv.args(idx))
.foreach(v => addTypeGuess(v, Set.empty, _ => arg.t))

// If the invoked function is a wrapper function, we infer the
// type of the pointer-typed argument from the call-site.
if (isWrapperFunc && arg.t.asPointer.isDefined) {
val dependencies = findDependencies(inv.args(idx))
// TODO: Check if this can be simplified I.e. the expression
// should almost always be resolvable with getVariable
addTypeGuess(
arg,
dependencies,
_ => replaceWithGuesses(inv.args(idx), dependencies).t,
)
}
}
}

Expand Down

0 comments on commit 580e370

Please sign in to comment.