Skip to content

Commit c980e48

Browse files
jakebaileydeadprogram
authored andcommitted
interp: add regression test for partial store aliasing
Adds a third init function to the store testdata: an initial partial store puts the buffer into the current memory view, then a partial load is followed by another partial store at the same offset, and finally the loaded value is written to a separate global. The expected output captures the current (incorrect) behavior of the in-place partial store optimization: the loaded value gets corrupted by the subsequent in-place store. The next commit fixes this.
1 parent f5bd750 commit c980e48

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

interp/testdata/store.ll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ target triple = "x86_64--linux"
44
@overlap.buf = global [4 x i8] c"\01\02\03\04"
55
@alias.src = global [4 x i8] c"\05\06\07\08"
66
@alias.dst = global [2 x i8] zeroinitializer
7+
@reload.buf = global [4 x i8] c"\01\02\03\04"
8+
@reload.out = global [2 x i8] zeroinitializer
79

810
define void @runtime.initAll() unnamed_addr {
911
entry:
1012
call void @overlap.init(ptr undef)
1113
call void @alias.init(ptr undef)
14+
call void @reload.init(ptr undef)
1215
ret void
1316
}
1417

@@ -30,3 +33,17 @@ entry:
3033
store i8 9, ptr @alias.dst
3134
ret void
3235
}
36+
37+
define internal void @reload.init(ptr %context) unnamed_addr {
38+
entry:
39+
; First store makes reload.buf writable in the current memory view.
40+
%tail = getelementptr [4 x i8], ptr @reload.buf, i32 0, i32 3
41+
store i8 9, ptr %tail
42+
; Partial load whose result may share the underlying buffer.
43+
%val = load i16, ptr @reload.buf
44+
; Subsequent in-place partial store; this must not corrupt %val.
45+
store i8 99, ptr @reload.buf
46+
; Write the originally-loaded value to a separate global.
47+
store i16 %val, ptr @reload.out
48+
ret void
49+
}

interp/testdata/store.out.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ target triple = "x86_64--linux"
44
@overlap.buf = local_unnamed_addr global [4 x i8] c"\01\01\02\09"
55
@alias.src = local_unnamed_addr global [4 x i8] c"\05\06\07\08"
66
@alias.dst = local_unnamed_addr global [2 x i8] c"\09\07"
7+
@reload.buf = local_unnamed_addr global [4 x i8] c"c\02\03\09"
8+
@reload.out = local_unnamed_addr global [2 x i8] c"c\02"
79

810
define void @runtime.initAll() unnamed_addr {
911
entry:

0 commit comments

Comments
 (0)