Closed Akuli closed 1 year ago
Here is a minimal reproducer that does not use the Jou compiler. Commands to run it are included as comments. Comments assume this file is saved to log.ll
; /usr/lib/llvm-11/bin/opt -O1 < log.ll > log2.ll && clang-11 log.ll && valgrind -q ./a.out && clang-11 log2.ll && valgrind -q ./a.out
; /usr/lib/llvm-11/bin/llvm-dis < log2.ll
target triple = "x86_64-pc-linux-gnu"
@printf_string = private global [22 x i8] c"Allocated %lld bytes\0A\00"
declare i32 @printf(i8*, ...)
declare { i32, i64, i8 }* @malloc(i64)
define i32 @main() {
; Calculate sizeof({ i32, i64, i8 }) and allocate that much heap memory.
%size = ptrtoint { i32, i64, i8 }* getelementptr ({ i32, i64, i8 }, { i32, i64, i8 }* null, i32 1) to i64
%heap_ptr = call { i32, i64, i8 }* @malloc(i64 %size)
; Print the size we calculated.
;%printf_format = getelementptr inbounds [22 x i8], [22 x i8]* @printf_string, i32 0, i32 0
;%r = call i32 (i8*, ...) @printf(i8* %printf_format, i64 %size)
; Store data into the pointer.
; If I change the data from 1,2,3 to 0,0,0 then it works...
store { i32, i64, i8 } { i32 1, i64 2, i8 3 }, { i32, i64, i8 }* %heap_ptr, align 4
ret i32 0
}
content of
bug.jou
:Running it under valgrind on Linux:
Expected result: no valgrind errors except the leak. Actual result:
Invalid write
error