aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-08-30 02:56:42 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-08-30 02:56:42 -0400
commite9280c86a1fc79aec5936bb21c9469657555a7ed (patch)
treed46be8ed77adda6487f49f25d2d43a36ec98b18c /src/ir.cpp
parent010b725bdef57eee969668087c8737e053b10e9f (diff)
downloadzig-e9280c86a1fc79aec5936bb21c9469657555a7ed.tar.gz
zig-e9280c86a1fc79aec5936bb21c9469657555a7ed.zip
compile error for not-aligned-enough pointer to cmpxchg
See #37
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 40d1a3d10c..fb485ede98 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -13488,6 +13488,15 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;
+ uint32_t align_bytes = ptr->value.type->data.pointer.alignment;
+ uint64_t size_bytes = type_size(ira->codegen, child_type);
+ if (align_bytes < size_bytes) {
+ ir_add_error(ira, instruction->ptr,
+ buf_sprintf("expected pointer alignment of at least %" ZIG_PRI_u64 ", found %" PRIu32,
+ size_bytes, align_bytes));
+ return ira->codegen->builtin_types.entry_invalid;
+ }
+
IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, child_type);
if (type_is_invalid(casted_cmp_value->value.type))
return ira->codegen->builtin_types.entry_invalid;