From 1ce09948975a148e09bf405f6a899e4fb0730ce6 Mon Sep 17 00:00:00 2001 From: frmdstryr Date: Mon, 26 Oct 2020 13:42:23 -0400 Subject: Fix @import of empty file --- src/stage1/analyze.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/stage1/analyze.cpp') diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index 04c064efe3..24530307a2 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -1988,7 +1988,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc // behaviour when checking expected alignment with `@ptrToInt(fn_ptr)` // or similar. This commit proposes to make `align` expressions a // compile error when compiled to Wasm architecture. - // + // // Some references: // [1] [Mozilla: WebAssembly Tables](https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format#WebAssembly_tables) // [2] [Sunfishcode's Wasm Ref Manual](https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#indirect-call) @@ -8052,10 +8052,13 @@ not_integer: } Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents_buf) { - size_t len; + size_t len = 0xAA; const char *contents = stage2_fetch_file(&g->stage1, buf_ptr(resolved_path), buf_len(resolved_path), &len); - if (contents == nullptr) + if (len == 0) { + // File exists but is empty (otherwise it would be 0xAA) + } else if (contents == nullptr) { return ErrorFileNotFound; + } buf_init_from_mem(contents_buf, contents, len); return ErrorNone; } @@ -9044,7 +9047,7 @@ static void resolve_llvm_types_optional(CodeGen *g, ZigType *type, ResolveStatus 8 * child_type->abi_align, val_offset_in_bits, ZigLLVM_DIFlags_Zero, child_llvm_di_type); - di_element_types[maybe_null_index] = + di_element_types[maybe_null_index] = ZigLLVMCreateDebugMemberType(g->dbuilder, ZigLLVMTypeToScope(type->llvm_di_type), "maybe", di_file, line, 8*g->builtin_types.entry_bool->abi_size, -- cgit v1.2.3