Permalink
Browse files

Make cgen_get_var return a pointer rather than an array pointer

  • Loading branch information...
1 parent cd9a5dc commit fffafad498c29b0b2bc92b043cb020ed1caf96e5 @nickg committed Aug 12, 2012
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/cgen.c
View
@@ -538,7 +538,14 @@ static LLVMValueRef cgen_get_var(tree_t decl, cgen_ctx_t *ctx)
int offset = tree_attr_int(decl, var_offset_i, -1);
assert(offset != -1);
- return LLVMBuildStructGEP(builder, ctx->state, offset, "");
+ LLVMValueRef var = LLVMBuildStructGEP(builder, ctx->state, offset, "");
+ if (type_is_array(tree_type(decl))) {
+ // Get a pointer to the first element
+ LLVMValueRef indexes[] = { llvm_int32(0), llvm_int32(0) };
+ return LLVMBuildGEP(builder, var, indexes, ARRAY_LEN(indexes), "");
+ }
+ else
+ return var;
}
static void cgen_array_copy(type_t src_type, type_t dest_type,

0 comments on commit fffafad

Please sign in to comment.