interp: fix inserting non-const values in a const aggregate

This bug was triggered by the following code:

    package main

    func foo() byte

    var array = [1]byte{foo()}

    func main() {
    }
This commit is contained in:
Ayke van Laethem
2019-11-17 15:03:16 +01:00
committed by Ron Evans
parent 98eee7c22a
commit 4605cbbc6e
4 changed files with 55 additions and 3 deletions
+19
View File
@@ -76,3 +76,22 @@ func isPointerNil(v llvm.Value) (result bool, ok bool) {
}
return false, false // not valid
}
// unwrap returns the underlying value, with GEPs removed. This can be useful to
// get the underlying global of a GEP pointer.
func unwrap(value llvm.Value) llvm.Value {
for {
if !value.IsAConstantExpr().IsNil() {
switch value.Opcode() {
case llvm.GetElementPtr:
value = value.Operand(0)
continue
}
} else if !value.IsAGetElementPtrInst().IsNil() {
value = value.Operand(0)
continue
}
break
}
return value
}