From 53ae03ebe9e0aa56bca1c9219a47d124b0435258 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 23 Sep 2019 15:02:38 -0400 Subject: 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. --- src/ir.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/ir.cpp') 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))); -- cgit v1.2.3