Skip to content

alive-exec returns poison for load from freshly calloc-ed memory #1345

Description

@Roticv912

Running alive-exec on the module below, the load from calloc(1, 8) yields poison (%v = poison) and terminates with ERROR: program returned poison.
calloc memory is zero-initialized (C23), so the load is defined and yields 0, and alive-exec's own echo even annotates this call allockind(alloc, zeroed).
Experiment 1 shows calloc is handled exactly like an uninitialized malloc, and Experiment 2 shows the returned block is ordinary accessible memory — the zeroed semantics are simply never applied.

Input Program

declare ptr @calloc(i64, i64)

define i32 @main() {
  %p = call ptr @calloc(i64 1, i64 8)
  %v = load i32, ptr %p
  ret i32 %v
}

Output

$ alive-exec e3.ll
----------------------------------------
declare ptr @calloc(i64, i64)

define i32 @main() {
#0:
  %p = call ptr @calloc(noundef i64 1, noundef i64 8) nofree noundef nothrow noalias willreturn dereferenceable_or_null(8) alloc-family(malloc) allockind(alloc, zeroed) allocsize(0, 1) memory(inaccessiblemem: readwrite)
  %v = load i32, ptr %p, align 4
  ret i32 %v
}
Executing %#0
%p = #b0000...
%v = poison
Returned #x00000000 / non-poison=false
ERROR: program returned poison

Additional Experiments

Experiment 1 — malloc behaves identically:

declare ptr @malloc(i64)

define i32 @main() {
  %p = call ptr @malloc(i64 8)
  %v = load i32, ptr %p
  ret i32 %v
}

%v = poison
Returned #x00000000 / non-poison=false
ERROR: program returned poison

Experiment 2 — the calloc block is accessible once stored to:

declare ptr @calloc(i64, i64)

define i32 @main() {
  %p = call ptr @calloc(i64 1, i64 8)
  store i32 5, ptr %p
  %v = load i32, ptr %p
  ret i32 %v
}

store
%v = #x00000005
Returned #x00000005 / non-poison=true

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions