From c980e48ad49b6440cfa4549cd4ce68feeaae537c Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 11 May 2026 13:40:58 -0700 Subject: [PATCH] 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. --- interp/testdata/store.ll | 17 +++++++++++++++++ interp/testdata/store.out.ll | 2 ++ 2 files changed, 19 insertions(+) diff --git a/interp/testdata/store.ll b/interp/testdata/store.ll index 6d532f77f..d42010179 100644 --- a/interp/testdata/store.ll +++ b/interp/testdata/store.ll @@ -4,11 +4,14 @@ target triple = "x86_64--linux" @overlap.buf = global [4 x i8] c"\01\02\03\04" @alias.src = global [4 x i8] c"\05\06\07\08" @alias.dst = global [2 x i8] zeroinitializer +@reload.buf = global [4 x i8] c"\01\02\03\04" +@reload.out = global [2 x i8] zeroinitializer define void @runtime.initAll() unnamed_addr { entry: call void @overlap.init(ptr undef) call void @alias.init(ptr undef) + call void @reload.init(ptr undef) ret void } @@ -30,3 +33,17 @@ entry: store i8 9, ptr @alias.dst ret void } + +define internal void @reload.init(ptr %context) unnamed_addr { +entry: + ; First store makes reload.buf writable in the current memory view. + %tail = getelementptr [4 x i8], ptr @reload.buf, i32 0, i32 3 + store i8 9, ptr %tail + ; Partial load whose result may share the underlying buffer. + %val = load i16, ptr @reload.buf + ; Subsequent in-place partial store; this must not corrupt %val. + store i8 99, ptr @reload.buf + ; Write the originally-loaded value to a separate global. + store i16 %val, ptr @reload.out + ret void +} diff --git a/interp/testdata/store.out.ll b/interp/testdata/store.out.ll index 1de806aa1..6c0f95052 100644 --- a/interp/testdata/store.out.ll +++ b/interp/testdata/store.out.ll @@ -4,6 +4,8 @@ target triple = "x86_64--linux" @overlap.buf = local_unnamed_addr global [4 x i8] c"\01\01\02\09" @alias.src = local_unnamed_addr global [4 x i8] c"\05\06\07\08" @alias.dst = local_unnamed_addr global [2 x i8] c"\09\07" +@reload.buf = local_unnamed_addr global [4 x i8] c"c\02\03\09" +@reload.out = local_unnamed_addr global [2 x i8] c"c\02" define void @runtime.initAll() unnamed_addr { entry: