Skip to content

Commit e695e55

Browse files
committed
fix(bleach): add missing zero index on stack access
1 parent 4d1b5a1 commit e695e55

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

lib/lifter/lifter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,13 @@ static auto generate_load_store_from_stack(
772772
auto *idx = builder.CreateAdd(sp, offset);
773773
auto *state_arg = get_current_state(*bb.getParent());
774774
auto *stack_type = *std::next(state.element_begin(), reg_stats.size());
775+
auto *const_zero = ConstantInt::get(ctx, APInt(32, 0));
775776
auto *stack_addr = builder.CreateGEP(
776777
&state, state_arg,
777-
ArrayRef<Value *>{ConstantInt::get(ctx, APInt(64, reg_stats.size()))});
778-
auto *addr = builder.CreateInBoundsGEP(
779-
stack_type, stack_addr,
780-
ArrayRef<Value *>{ConstantInt::get(ctx, APInt(64, 0)), idx});
778+
ArrayRef<Value *>{const_zero,
779+
ConstantInt::get(ctx, APInt(32, reg_stats.size()))});
780+
auto *addr = builder.CreateInBoundsGEP(stack_type, stack_addr,
781+
ArrayRef<Value *>{const_zero, idx});
781782
auto *iinfo = target_machine.getMCInstrInfo();
782783
auto name = get_instruction_name(minst, *iinfo);
783784
auto *m = bb.getParent()->getParent();
@@ -1174,7 +1175,6 @@ Module &bleach_module(Module &m, MachineModuleInfo &mmi,
11741175
for (auto &&[oldf, func_info] : funcs)
11751176
generate_function(*oldf, func_info, instrs, mmi, state, reg_stats,
11761177
assume_functions_nop);
1177-
m.print(errs(), nullptr);
11781178
if (finfo) {
11791179
for (auto *func :
11801180
translated | views::filter([](auto *f) { return !f->empty(); }))

test/integration/fact-local-var.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Failes due to corruption of local variable in bleached-main-local-var.c
2-
// XFAIL: *
31
// RUN: %config-gen-path/config-gen.rb --march rv64im \
42
// RUN: --template-dir %config-gen-path/templates -o %t.yaml
53
// RUN: riscv64-unknown-linux-gnu-clang %s -O2 -o %t.out -march=rv64im -nostdlib

test/tools/llvm-bleach/loadsstores.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# CHECK: define void @SnippyFunction(ptr %0) {
66
# CHECK: %[[SP:[0-9]+]] = call i64 @ADDI(i64 %{{[0-9]+}}, i64 6)
77
# CHECK: %[[IDX:[0-9]+]] = add i64 %[[SP]], -5
8-
# CHECK: %[[STACK:[0-9]+]] = getelementptr %register_state, ptr %0, i64 1
9-
# CHECK: %[[ADDR:[0-9]+]] = getelementptr inbounds [1000 x i64], ptr %[[STACK]], i64 0, i64 %[[IDX]]
8+
# CHECK: %[[STACK:[0-9]+]] = getelementptr %register_state, ptr %0, i32 0, i32 1
9+
# CHECK: %[[ADDR:[0-9]+]] = getelementptr inbounds [1000 x i64], ptr %[[STACK]], i32 0, i64 %[[IDX]]
1010
# CHECK: %[[LOADED:[0-9]+]] = load i64, ptr %[[ADDR]]
1111

1212
# CHECK: %[[IDX2:[0-9]+]] = add i64 %[[SP]], -3
13-
# CHECK: %[[STACK2:[0-9]+]] = getelementptr %register_state, ptr %0, i64 1
14-
# CHECK: %[[ADDR2:[0-9]+]] = getelementptr inbounds [1000 x i64], ptr %[[STACK2]], i64 0, i64 %[[IDX2]]
13+
# CHECK: %[[STACK2:[0-9]+]] = getelementptr %register_state, ptr %0, i32 0, i32 1
14+
# CHECK: %[[ADDR2:[0-9]+]] = getelementptr inbounds [1000 x i64], ptr %[[STACK2]], i32 0, i64 %[[IDX2]]
1515
# CHECK: store i64 %[[LOADED]], ptr %[[ADDR2]]

0 commit comments

Comments
 (0)