gallivm: Fix segfaul when inserting allocas in an empty function.
authorJosé Fonseca <jfonseca@vmware.com>
Sat, 8 May 2010 12:02:46 +0000 (13:02 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 8 May 2010 12:02:46 +0000 (13:02 +0100)
src/gallium/auxiliary/gallivm/lp_bld_flow.c

index 8f15b1d287d40076d75de1bf37405a78cebd33ab..560ce1de73f558f1d568e2b2bc212b83a78d6389 100644 (file)
@@ -821,8 +821,11 @@ lp_build_alloca(LLVMBuilderRef builder,
    LLVMBuilderRef first_builder = LLVMCreateBuilder();
    LLVMValueRef res;
 
-   LLVMPositionBuilderAtEnd(first_builder, first_block);
-   LLVMPositionBuilderBefore(first_builder, first_instr);
+   if (first_instr) {
+      LLVMPositionBuilderBefore(first_builder, first_instr);
+   } else {
+      LLVMPositionBuilderAtEnd(first_builder, first_block);
+   }
 
    res = LLVMBuildAlloca(first_builder, type, name);
 
@@ -859,7 +862,11 @@ lp_build_array_alloca(LLVMBuilderRef builder,
    LLVMBuilderRef first_builder = LLVMCreateBuilder();
    LLVMValueRef res;
 
-   LLVMPositionBuilderBefore(first_builder, first_instr);
+   if (first_instr) {
+      LLVMPositionBuilderBefore(first_builder, first_instr);
+   } else {
+      LLVMPositionBuilderAtEnd(first_builder, first_block);
+   }
 
    res = LLVMBuildArrayAlloca(first_builder, type, count, name);