Skip to content

Commit 702167d

Browse files
committed
testdata:asmFull
1 parent a996f85 commit 702167d

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

compiler/compiler_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func TestCompiler(t *testing.T) {
5050
{"channel.go", "", ""},
5151
{"gc.go", "", ""},
5252
{"zeromap.go", "", ""},
53+
{"asmfull.go", "", ""},
5354
}
5455
if goMinor >= 20 {
5556
tests = append(tests, testCase{"go1.20.go", "", ""})

compiler/testdata/asmfull.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import "device"
4+
5+
// Test the specific bug case: AsmFull should use call-time input register value (42), not post-call value (44)
6+
func testAsmFullBug() uintptr {
7+
place := make(map[string]interface{})
8+
place["input"] = uint32(42)
9+
10+
// This should use input=42 at call time, return the moved value
11+
result := device.AsmFull("mov {}, {input}", place)
12+
13+
// This update should NOT affect the AsmFull result (was the bug)
14+
place["input"] = uint32(44)
15+
16+
return result
17+
}
18+
19+
func main() {
20+
_ = testAsmFullBug()
21+
}

compiler/testdata/asmfull.ll

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
; ModuleID = 'asmfull_bug.go'
2+
source_filename = "asmfull_bug.go"
3+
target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20"
4+
target triple = "wasm32-unknown-wasi"
5+
6+
%runtime._interface = type { ptr, ptr }
7+
8+
@"reflect/types.type:basic:uint32" = linkonce_odr constant { i8, ptr } { i8 -54, ptr @"reflect/types.type:pointer:basic:uint32" }, align 4
9+
@"reflect/types.type:pointer:basic:uint32" = linkonce_odr constant { i8, i16, ptr } { i8 -43, i16 0, ptr @"reflect/types.type:basic:uint32" }, align 4
10+
@"main$string" = internal unnamed_addr constant [5 x i8] c"input", align 1
11+
@"main$string.1" = internal unnamed_addr constant [5 x i8] c"input", align 1
12+
13+
; Function Attrs: allockind("alloc,zeroed") allocsize(0)
14+
declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0
15+
16+
declare void @runtime.trackPointer(ptr nocapture readonly, ptr, ptr) #1
17+
18+
; Function Attrs: nounwind
19+
define hidden void @main.init(ptr %context) unnamed_addr #2 {
20+
entry:
21+
ret void
22+
}
23+
24+
; Function Attrs: nounwind
25+
define hidden i32 @main.testAsmFullBug(ptr %context) unnamed_addr #2 {
26+
entry:
27+
%hashmap.value1 = alloca %runtime._interface, align 8
28+
%hashmap.value = alloca %runtime._interface, align 8
29+
%stackalloc = alloca i8, align 1
30+
%0 = call ptr @runtime.hashmapMake(i32 8, i32 8, i32 8, i8 1, ptr undef) #4
31+
call void @runtime.trackPointer(ptr %0, ptr nonnull %stackalloc, ptr undef) #4
32+
call void @runtime.trackPointer(ptr nonnull @"reflect/types.type:basic:uint32", ptr nonnull %stackalloc, ptr undef) #4
33+
call void @runtime.trackPointer(ptr nonnull inttoptr (i32 42 to ptr), ptr nonnull %stackalloc, ptr undef) #4
34+
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %hashmap.value)
35+
store ptr @"reflect/types.type:basic:uint32", ptr %hashmap.value, align 4
36+
%hashmap.value.repack2 = getelementptr inbounds i8, ptr %hashmap.value, i32 4
37+
store ptr inttoptr (i32 42 to ptr), ptr %hashmap.value.repack2, align 4
38+
call void @runtime.hashmapStringSet(ptr %0, ptr nonnull @"main$string", i32 5, ptr nonnull %hashmap.value, ptr undef) #4
39+
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %hashmap.value)
40+
%1 = call i32 asm sideeffect "mov $0, ${1}", "=&r,r"(i32 42) #4
41+
call void @runtime.trackPointer(ptr nonnull @"reflect/types.type:basic:uint32", ptr nonnull %stackalloc, ptr undef) #4
42+
call void @runtime.trackPointer(ptr nonnull inttoptr (i32 44 to ptr), ptr nonnull %stackalloc, ptr undef) #4
43+
call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %hashmap.value1)
44+
store ptr @"reflect/types.type:basic:uint32", ptr %hashmap.value1, align 4
45+
%hashmap.value1.repack3 = getelementptr inbounds i8, ptr %hashmap.value1, i32 4
46+
store ptr inttoptr (i32 44 to ptr), ptr %hashmap.value1.repack3, align 4
47+
call void @runtime.hashmapStringSet(ptr %0, ptr nonnull @"main$string.1", i32 5, ptr nonnull %hashmap.value1, ptr undef) #4
48+
call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %hashmap.value1)
49+
ret i32 %1
50+
}
51+
52+
declare ptr @runtime.hashmapMake(i32, i32, i32, i8, ptr) #1
53+
54+
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
55+
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3
56+
57+
declare void @runtime.hashmapStringSet(ptr dereferenceable_or_null(40), ptr, i32, ptr, ptr) #1
58+
59+
; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
60+
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3
61+
62+
; Function Attrs: nounwind
63+
define hidden void @main.main(ptr %context) unnamed_addr #2 {
64+
entry:
65+
%0 = call i32 @main.testAsmFullBug(ptr undef)
66+
ret void
67+
}
68+
69+
attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
70+
attributes #1 = { "target-features"="+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
71+
attributes #2 = { nounwind "target-features"="+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext,-multivalue,-reference-types" }
72+
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
73+
attributes #4 = { nounwind }

0 commit comments

Comments
 (0)