Include ResultZeroInitInstruction in EvalImplicitInitInstruction

This commit is contained in:
Owen Mansel-Chan
2026-06-29 11:15:47 +01:00
parent e444730da3
commit f730c889d9

View File

@@ -843,12 +843,17 @@ module IR {
*/
class EvalImplicitInitInstruction extends Instruction {
ValueEntity v;
int idx;
ValueSpec spec;
EvalImplicitInitInstruction() {
this.isAdditional(spec, "zero-init:" + idx.toString()) and
spec.getNameExpr(idx) = v.getDeclaration()
exists(ValueSpec spec, int idx |
this.isAdditional(spec, "zero-init:" + idx.toString()) and
spec.getNameExpr(idx) = v.getDeclaration()
)
or
exists(FuncDef fd, int idx |
this.isAdditional(fd.getBody(), "result-zero-init:" + idx.toString()) and
v = fd.getResultVar(idx)
)
}
override Type getResultType() { result = v.getType() }
@@ -1091,48 +1096,13 @@ module IR {
override Instruction getRhs() {
result
.(ResultZeroInitInstruction)
.(EvalImplicitInitInstruction)
.isAdditional(fd.getBody(), "result-zero-init:" + idx.toString())
}
override ControlFlow::Root getRoot() { result = res.getFunction() }
}
private class ResultZeroInitInstruction extends Instruction {
ResultVariable res;
int idx;
FuncDef fd;
ResultZeroInitInstruction() {
this.isAdditional(fd.getBody(), "result-zero-init:" + idx.toString()) and
res = fd.getResultVar(idx)
}
override Type getResultType() { result = res.getType() }
override ControlFlow::Root getRoot() { result.isRootOf(fd) }
override int getIntValue() {
res.getType().getUnderlyingType() instanceof IntegerType and result = 0
}
override float getFloatValue() {
res.getType().getUnderlyingType() instanceof FloatType and result = 0.0
}
override string getStringValue() {
res.getType().getUnderlyingType() instanceof StringType and result = ""
}
override boolean getBoolValue() {
res.getType().getUnderlyingType() instanceof BoolType and result = false
}
override predicate isConst() { any() }
override predicate isPlatformIndependentConstant() { any() }
}
/** An instruction that gets the next key-value pair in a range loop. */
class GetNextEntryInstruction extends Instruction {
RangeStmt rs;
@@ -1531,6 +1501,11 @@ module IR {
spec.getNameExpr(i) = v.getDeclaration() and
result.isAdditional(spec, "zero-init:" + i.toString())
)
or
exists(FuncDef fd, int i |
fd.getResultVar(i) = v and
result.isAdditional(fd.getBody(), "result-zero-init:" + i.toString())
)
}
/**