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
+18
View File
@@ -2,6 +2,8 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64--linux"
@main.v1 = internal global i64 0
@main.nonConst1 = global [4 x i64] zeroinitializer
@main.nonConst2 = global i64 0
declare void @runtime.printint64(i64) unnamed_addr
@@ -31,6 +33,20 @@ define internal void @main.init() unnamed_addr {
entry:
store i64 3, i64* @main.v1
call void @"main.init#1"()
; test the following pattern:
; func someValue() int // extern function
; var nonConst1 = [4]int{someValue(), 0, 0, 0}
%value1 = call i64 @someValue()
%gep1 = getelementptr [4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0
store i64 %value1, i64* %gep1
; Test that the global really is marked dirty:
; var nonConst2 = nonConst1[0]
%gep2 = getelementptr [4 x i64], [4 x i64]* @main.nonConst1, i32 0, i32 0
%value2 = load i64, i64* %gep2
store i64 %value2, i64* @main.nonConst2
ret void
}
@@ -40,3 +56,5 @@ entry:
call void @runtime.printnl()
ret void
}
declare i64 @someValue()