aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-09-23 15:02:38 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-09-23 15:02:38 -0400
commit53ae03ebe9e0aa56bca1c9219a47d124b0435258 (patch)
tree2f69fc4aeb6bdbc9567338b033337c4556f5c0c0 /src/ir.cpp
parent29b82d20a4534fc7e3393c21ad637d44d20449a2 (diff)
downloadzig-53ae03ebe9e0aa56bca1c9219a47d124b0435258.tar.gz
zig-53ae03ebe9e0aa56bca1c9219a47d124b0435258.zip
make type_allowed_in_extern more robust
Previously if the type parameter was a pointer, it would assert that the size of the type was resolved. It used to be that the size of pointers was always resolved, however with lazy values, pointers gained the possibility of not having their size resolved. Now, type_allowed_in_extern triggers the resolution of whether a pointer is zero bits, and returns a possible error if the resolution fails. This fixes a compiler assertion when building the [zootdeck project](https://github.com/donpdonp/zootdeck). I do not have a test case reduction for the issue.
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 4147fcd599..16e37d61ac 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -14837,6 +14837,8 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
}
static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {
+ Error err;
+
IrInstruction *name = instruction->name->child;
Buf *symbol_name = ir_resolve_str(ira, name);
if (symbol_name == nullptr) {
@@ -14933,8 +14935,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
want_var_export = true;
}
break;
- case ZigTypeIdArray:
- if (!type_allowed_in_extern(ira->codegen, target->value.type->data.array.child_type)) {
+ case ZigTypeIdArray: {
+ bool ok_type;
+ if ((err = type_allowed_in_extern(ira->codegen, target->value.type->data.array.child_type, &ok_type)))
+ return ira->codegen->invalid_instruction;
+
+ if (!ok_type) {
ir_add_error(ira, target,
buf_sprintf("array element type '%s' not extern-compatible",
buf_ptr(&target->value.type->data.array.child_type->name)));
@@ -14942,6 +14948,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
want_var_export = true;
}
break;
+ }
case ZigTypeIdMetaType: {
ZigType *type_value = target->value.data.x_type;
switch (type_value->id) {
@@ -26720,7 +26727,10 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) {
buf_create_from_str("unknown-length pointer to opaque"));
return ErrorSemanticAnalyzeFail;
} else if (lazy_ptr_type->ptr_len == PtrLenC) {
- if (!type_allowed_in_extern(ira->codegen, elem_type)) {
+ bool ok_type;
+ if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type)))
+ return err;
+ if (!ok_type) {
ir_add_error(ira, lazy_ptr_type->elem_type,
buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",
buf_ptr(&elem_type->name)));