authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-05 16:00:12-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-05 16:00:12-05:00
log025051885be8c99bfccc7d3746ac138f7d5546e1
tree20cbf34b93811f6b1a3d8c409d2a6bddc2eb3ea4
parentd151c58788098778c07f764d2256955cb36a832f

fix volatile not respected for loads


2 files changed, 26 insertions(+), 20 deletions(-)

src/codegen.cpp+25-19
......@@ -415,12 +415,14 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry,
415415 return *fn;
416416}
417417
418static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *type) {
418static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *type, bool is_volatile) {
419419 if (type_has_bits(type)) {
420420 if (handle_is_ptr(type)) {
421421 return ptr;
422422 } else {
423 return LLVMBuildLoad(g->builder, ptr, "");
423 LLVMValueRef result = LLVMBuildLoad(g->builder, ptr, "");
424 LLVMSetVolatile(result, is_volatile);
425 return result;
424426 }
425427 } else {
426428 return nullptr;
......@@ -1191,6 +1193,7 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
11911193 case IrUnOpInvalid:
11921194 case IrUnOpError:
11931195 case IrUnOpMaybe:
1196 case IrUnOpDereference:
11941197 zig_unreachable();
11951198 case IrUnOpNegation:
11961199 case IrUnOpNegationWrap:
......@@ -1214,16 +1217,6 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
12141217 }
12151218 case IrUnOpBinNot:
12161219 return LLVMBuildNot(g->builder, expr, "");
1217 case IrUnOpDereference:
1218 {
1219 assert(expr_type->id == TypeTableEntryIdPointer);
1220 if (!type_has_bits(expr_type)) {
1221 return nullptr;
1222 } else {
1223 TypeTableEntry *child_type = expr_type->data.pointer.child_type;
1224 return get_handle_value(g, expr, child_type);
1225 }
1226 }
12271220 }
12281221
12291222 zig_unreachable();
......@@ -1289,8 +1282,15 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
12891282}
12901283
12911284static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrInstructionLoadPtr *instruction) {
1285 TypeTableEntry *child_type = instruction->base.value.type;
1286 if (!type_has_bits(child_type)) {
1287 return nullptr;
1288 }
12921289 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
1293 return get_handle_value(g, ptr, instruction->base.value.type);
1290 TypeTableEntry *ptr_type = instruction->ptr->value.type;
1291 assert(ptr_type->id == TypeTableEntryIdPointer);
1292 bool is_volatile = ptr_type->data.pointer.is_volatile;
1293 return get_handle_value(g, ptr, child_type, is_volatile);
12941294}
12951295
12961296static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) {
......@@ -1329,8 +1329,9 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
13291329 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
13301330 TypeTableEntry *array_ptr_type = instruction->array_ptr->value.type;
13311331 assert(array_ptr_type->id == TypeTableEntryIdPointer);
1332 bool is_volatile = array_ptr_type->data.pointer.is_volatile;
13321333 TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type;
1333 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type);
1334 LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, is_volatile);
13341335 LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index);
13351336 assert(subscript_value);
13361337
......@@ -1607,12 +1608,13 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
16071608{
16081609 TypeTableEntry *ptr_type = instruction->value->value.type;
16091610 assert(ptr_type->id == TypeTableEntryIdPointer);
1611 bool is_volatile = ptr_type->data.pointer.is_volatile;
16101612 TypeTableEntry *maybe_type = ptr_type->data.pointer.child_type;
16111613 assert(maybe_type->id == TypeTableEntryIdMaybe);
16121614 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
16131615 bool maybe_is_ptr = (child_type->id == TypeTableEntryIdPointer || child_type->id == TypeTableEntryIdFn);
16141616 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);
1615 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type);
1617 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, is_volatile);
16161618 if (ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on) {
16171619 LLVMValueRef non_null_bit = gen_non_null_bit(g, maybe_type, maybe_handle);
16181620 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeOk");
......@@ -1627,7 +1629,7 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
16271629 if (maybe_is_ptr) {
16281630 return maybe_ptr;
16291631 } else {
1630 LLVMValueRef maybe_struct_ref = get_handle_value(g, maybe_ptr, maybe_type);
1632 LLVMValueRef maybe_struct_ref = get_handle_value(g, maybe_ptr, maybe_type, is_volatile);
16311633 return LLVMBuildStructGEP(g->builder, maybe_struct_ref, maybe_child_index, "");
16321634 }
16331635}
......@@ -2066,10 +2068,12 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
20662068
20672069static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) {
20682070 TypeTableEntry *ptr_type = get_underlying_type(instruction->value->value.type);
2071 assert(ptr_type->id == TypeTableEntryIdPointer);
2072 bool is_volatile = ptr_type->data.pointer.is_volatile;
20692073 TypeTableEntry *err_union_type = get_underlying_type(ptr_type->data.pointer.child_type);
20702074 TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type);
20712075 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
2072 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type);
2076 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, is_volatile);
20732077
20742078 if (type_has_bits(child_type)) {
20752079 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");
......@@ -2081,10 +2085,12 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
20812085
20822086static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) {
20832087 TypeTableEntry *ptr_type = get_underlying_type(instruction->value->value.type);
2088 assert(ptr_type->id == TypeTableEntryIdPointer);
2089 bool is_volatile = ptr_type->data.pointer.is_volatile;
20842090 TypeTableEntry *err_union_type = get_underlying_type(ptr_type->data.pointer.child_type);
20852091 TypeTableEntry *child_type = get_underlying_type(err_union_type->data.error.child_type);
20862092 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
2087 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type);
2093 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, is_volatile);
20882094
20892095 if (ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on) {
20902096 LLVMValueRef err_val;
......@@ -2193,7 +2199,7 @@ static LLVMValueRef ir_render_enum_tag(CodeGen *g, IrExecutable *executable, IrI
21932199 return enum_val;
21942200
21952201 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, enum_val, enum_gen_tag_index, "");
2196 return get_handle_value(g, tag_field_ptr, tag_type);
2202 return get_handle_value(g, tag_field_ptr, tag_type, false);
21972203}
21982204
21992205static LLVMValueRef ir_render_init_enum(CodeGen *g, IrExecutable *executable, IrInstructionInitEnum *instruction) {
src/ir.cpp+1-1
......@@ -8367,7 +8367,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
83678367 return child_type;
83688368 }
83698369
8370 ir_build_un_op_from(&ira->new_irb, &un_op_instruction->base, IrUnOpDereference, value);
8370 ir_build_load_ptr_from(&ira->new_irb, &un_op_instruction->base, value);
83718371 return child_type;
83728372}
83738373