aboutsummaryrefslogtreecommitdiffhomepage
path: root/interp/testdata
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-11-11 02:41:29 +0100
committerRon Evans <[email protected]>2021-11-11 08:59:32 +0100
commit1681ed02d3035f3216885d560433bc1ad953ed24 (patch)
treecc6d9d57f827121882e42673c7d15cbe50f6d748 /interp/testdata
parent7e68980c395339b1e9b78c08477d47b7ba15354d (diff)
downloadtinygo-1681ed02d3035f3216885d560433bc1ad953ed24.tar.gz
tinygo-1681ed02d3035f3216885d560433bc1ad953ed24.zip
interp: take care of constant globals
Constant globals can't have been modified, even if a pointer is passed externally. Therefore, don't treat it as such in hasExternalStore. In addition, it doesn't make sense to update values of constant globals after the interp pass is finished. So don't do this. TODO: track whether objects are actually modified and only update the globals if this is the case.
Diffstat (limited to 'interp/testdata')
-rw-r--r--interp/testdata/basic.ll8
-rw-r--r--interp/testdata/basic.out.ll5
2 files changed, 13 insertions, 0 deletions
diff --git a/interp/testdata/basic.ll b/interp/testdata/basic.ll
index d0af3af37..30c0bf088 100644
--- a/interp/testdata/basic.ll
+++ b/interp/testdata/basic.ll
@@ -6,6 +6,7 @@ target triple = "x86_64--linux"
@main.nonConst2 = global i64 0
@main.someArray = global [8 x {i16, i32}] zeroinitializer
@main.exportedValue = global [1 x i16*] [i16* @main.exposedValue1]
[email protected] = constant i64 42
@main.exposedValue1 = global i16 0
@main.exposedValue2 = global i16 0
@main.insertedValue = global {i8, i32, {float, {i64, i16}}} zeroinitializer
@@ -62,6 +63,11 @@ entry:
call void @modifyExternal(i32* bitcast ([1 x i16*]* @main.exportedValue to i32*))
store i16 5, i16* @main.exposedValue1
+ ; Test that marking a constant as external still allows loading from it.
+ call void @readExternal(i32* bitcast (i64* @main.exportedConst to i32*))
+ %constLoad = load i64, i64 * @main.exportedConst
+ call void @runtime.printint64(i64 %constLoad)
+
; Test that this even propagates through functions.
call void @modifyExternal(i32* bitcast (void ()* @willModifyGlobal to i32*))
store i16 7, i16* @main.exposedValue2
@@ -96,6 +102,8 @@ declare i64 @someValue()
declare void @modifyExternal(i32*)
+declare void @readExternal(i32*)
+
; This function will modify an external value. By passing this function as a
; function pointer to an external function, @main.exposedValue2 should be
; marked as external.
diff --git a/interp/testdata/basic.out.ll b/interp/testdata/basic.out.ll
index 9279606e5..5c68ec5e9 100644
--- a/interp/testdata/basic.out.ll
+++ b/interp/testdata/basic.out.ll
@@ -5,6 +5,7 @@ target triple = "x86_64--linux"
@main.nonConst2 = local_unnamed_addr global i64 0
@main.someArray = global [8 x { i16, i32 }] zeroinitializer
@main.exportedValue = global [1 x i16*] [i16* @main.exposedValue1]
[email protected] = constant i64 42
@main.exposedValue1 = global i16 0
@main.exposedValue2 = local_unnamed_addr global i16 0
@main.insertedValue = local_unnamed_addr global { i8, i32, { float, { i64, i16 } } } zeroinitializer
@@ -24,6 +25,8 @@ entry:
call void @modifyExternal(i32* bitcast (i8* getelementptr inbounds (i8, i8* bitcast ([8 x { i16, i32 }]* @main.someArray to i8*), i32 28) to i32*))
call void @modifyExternal(i32* bitcast ([1 x i16*]* @main.exportedValue to i32*))
store i16 5, i16* @main.exposedValue1, align 2
+ call void @readExternal(i32* bitcast (i64* @main.exportedConst to i32*))
+ call void @runtime.printint64(i64 42)
call void @modifyExternal(i32* bitcast (void ()* @willModifyGlobal to i32*))
store i16 7, i16* @main.exposedValue2, align 2
call void @modifyExternal(i32* bitcast (void ()* @hasInlineAsm to i32*))
@@ -54,6 +57,8 @@ declare i64 @someValue() local_unnamed_addr
declare void @modifyExternal(i32*) local_unnamed_addr
+declare void @readExternal(i32*) local_unnamed_addr
+
define void @willModifyGlobal() {
entry:
store i16 8, i16* @main.exposedValue2, align 2