aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-12-26 21:44:08 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-12-26 21:44:08 -0500
commit6bfaf262d5a1d18482a813c7022ffb03a18f52a8 (patch)
tree7f432e8f386aed17df3f1bccdff34ec58b3ff2af /src/codegen.cpp
parent8b716f941dbd43936a994a008aec9cd21d0b08f2 (diff)
parent08dd1b553b37de24eaf24a37558b0f9993d4ca42 (diff)
downloadzig-6bfaf262d5a1d18482a813c7022ffb03a18f52a8.tar.gz
zig-6bfaf262d5a1d18482a813c7022ffb03a18f52a8.zip
Merge branch 'master' into llvm6
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 339c643425..108b5e0e2e 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -17,7 +17,7 @@
#include "os.hpp"
#include "translate_c.hpp"
#include "target.hpp"
-#include "zig_llvm.hpp"
+#include "zig_llvm.h"
#include <stdio.h>
#include <errno.h>
@@ -3705,12 +3705,24 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar
ConstParent *parent = &array_const_val->data.x_array.s_none.parent;
LLVMValueRef base_ptr = gen_parent_ptr(g, array_const_val, parent);
- TypeTableEntry *usize = g->builtin_types.entry_usize;
- LLVMValueRef indices[] = {
- LLVMConstNull(usize->type_ref),
- LLVMConstInt(usize->type_ref, index, false),
- };
- return LLVMConstInBoundsGEP(base_ptr, indices, 2);
+ LLVMTypeKind el_type = LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(base_ptr)));
+ if (el_type == LLVMArrayTypeKind) {
+ TypeTableEntry *usize = g->builtin_types.entry_usize;
+ LLVMValueRef indices[] = {
+ LLVMConstNull(usize->type_ref),
+ LLVMConstInt(usize->type_ref, index, false),
+ };
+ return LLVMConstInBoundsGEP(base_ptr, indices, 2);
+ } else if (el_type == LLVMStructTypeKind) {
+ TypeTableEntry *u32 = g->builtin_types.entry_u32;
+ LLVMValueRef indices[] = {
+ LLVMConstNull(u32->type_ref),
+ LLVMConstInt(u32->type_ref, index, false),
+ };
+ return LLVMConstInBoundsGEP(base_ptr, indices, 2);
+ } else {
+ zig_unreachable();
+ }
}
static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *struct_const_val, size_t field_index) {
@@ -3732,7 +3744,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un
TypeTableEntry *u32 = g->builtin_types.entry_u32;
LLVMValueRef indices[] = {
LLVMConstNull(u32->type_ref),
- LLVMConstInt(u32->type_ref, 0, false),
+ LLVMConstInt(u32->type_ref, 0, false), // TODO test const union with more aligned tag type than payload
};
return LLVMConstInBoundsGEP(base_ptr, indices, 2);
}