No, memory created with alloca
is not 0-initialized - it's up to you to initialize it.
As for the next question, I strongly recommend using Clang to compile C code snippets to LLVM IR instead of hand-crafting the latter. Here's an example:
#include <memory.h>
struct Foo {
int a, b;
};
void test() {
Foo f;
memset(&f, 0, sizeof(f));
}
Compiled (without optimizations) this produces:
%struct.Foo = type { i32, i32 }
; Function Attrs: nounwind uwtable
define void @_Z4testv() #0 {
entry:
%f = alloca %struct.Foo, align 4
%0 = bitcast %struct.Foo* %f to i8*
call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 8, i32 4, i1 false)
ret void
}
; Function Attrs: nounwind
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) #1
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind }