Commit 0c1800a9c9
Changed files (5)
src/analyze.cpp
@@ -1082,7 +1082,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
return get_fn_type(g, &fn_type_id);
}
-static bool type_is_invalid(TypeTableEntry *type_entry) {
+bool type_is_invalid(TypeTableEntry *type_entry) {
switch (type_entry->id) {
case TypeTableEntryIdInvalid:
return true;
@@ -1118,6 +1118,9 @@ static void resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) {
// if you change this logic you likely must also change similar logic in parseh.cpp
assert(enum_type->id == TypeTableEntryIdEnum);
+ if (enum_type->data.enumeration.complete)
+ return;
+
resolve_enum_zero_bits(g, enum_type);
if (enum_type->data.enumeration.is_invalid)
return;
@@ -1298,6 +1301,9 @@ static void resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) {
// parseh.cpp
assert(struct_type->id == TypeTableEntryIdStruct);
+ if (struct_type->data.structure.complete)
+ return;
+
resolve_struct_zero_bits(g, struct_type);
if (struct_type->data.structure.is_invalid)
return;
@@ -2045,45 +2051,6 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only) {
tld->dep_loop_flag = false;
}
-static bool type_has_codegen_value(TypeTableEntry *type_entry) {
- switch (type_entry->id) {
- case TypeTableEntryIdInvalid:
- case TypeTableEntryIdMetaType:
- case TypeTableEntryIdVoid:
- case TypeTableEntryIdUnreachable:
- case TypeTableEntryIdNumLitFloat:
- case TypeTableEntryIdNumLitInt:
- case TypeTableEntryIdUndefLit:
- case TypeTableEntryIdNullLit:
- case TypeTableEntryIdNamespace:
- case TypeTableEntryIdBlock:
- case TypeTableEntryIdBoundFn:
- return false;
-
- case TypeTableEntryIdBool:
- case TypeTableEntryIdInt:
- case TypeTableEntryIdFloat:
- case TypeTableEntryIdPointer:
- case TypeTableEntryIdArray:
- case TypeTableEntryIdStruct:
- case TypeTableEntryIdMaybe:
- case TypeTableEntryIdErrorUnion:
- case TypeTableEntryIdPureError:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
- case TypeTableEntryIdFn:
- case TypeTableEntryIdEnumTag:
- return true;
-
- case TypeTableEntryIdTypeDecl:
- return type_has_codegen_value(type_entry->data.type_decl.canonical_type);
-
- case TypeTableEntryIdVar:
- zig_unreachable();
- }
- zig_unreachable();
-}
-
bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type) {
if (expected_type == actual_type)
return true;
src/analyze.hpp
@@ -54,6 +54,7 @@ bool type_is_codegen_pointer(TypeTableEntry *type);
TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry);
TypeTableEntry *container_ref_type(TypeTableEntry *type_entry);
bool type_is_complete(TypeTableEntry *type_entry);
+bool type_is_invalid(TypeTableEntry *type_entry);
bool type_has_zero_bits_known(TypeTableEntry *type_entry);
void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);
TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name);
src/parseh.cpp
@@ -934,7 +934,7 @@ static TypeTableEntry *resolve_record_decl(Context *c, const RecordDecl *record_
TypeTableEntry *field_type = resolve_qual_type(c, field_decl->getType(), field_decl);
type_struct_field->type_entry = field_type;
- if (field_type->id == TypeTableEntryIdInvalid) {
+ if (type_is_invalid(field_type) || !type_is_complete(field_type)) {
emit_warning(c, field_decl, "struct %s demoted to typedef - unresolved type\n", buf_ptr(bare_name));
replace_with_fwd_decl(c, struct_type, full_type_name);
return struct_type;
src/parser.cpp
@@ -598,6 +598,7 @@ static AstNode *ast_parse_goto_expr(ParseContext *pc, size_t *token_index, bool
*token_index += 2;
} else if (mandatory) {
ast_expect_token(pc, first_token, TokenIdKeywordGoto);
+ zig_unreachable();
} else {
return nullptr;
}
@@ -607,6 +608,7 @@ static AstNode *ast_parse_goto_expr(ParseContext *pc, size_t *token_index, bool
*token_index += 1;
} else if (mandatory) {
ast_expect_token(pc, first_token, TokenIdKeywordGoto);
+ zig_unreachable();
} else {
return nullptr;
}
@@ -1605,6 +1607,7 @@ static AstNode *ast_parse_while_expr(ParseContext *pc, size_t *token_index, bool
*token_index += 2;
} else if (mandatory) {
ast_expect_token(pc, while_token, TokenIdKeywordWhile);
+ zig_unreachable();
} else {
return nullptr;
}
@@ -1614,6 +1617,7 @@ static AstNode *ast_parse_while_expr(ParseContext *pc, size_t *token_index, bool
*token_index += 1;
} else if (mandatory) {
ast_expect_token(pc, first_token, TokenIdKeywordWhile);
+ zig_unreachable();
} else {
return nullptr;
}
@@ -1663,6 +1667,7 @@ static AstNode *ast_parse_for_expr(ParseContext *pc, size_t *token_index, bool m
*token_index += 2;
} else if (mandatory) {
ast_expect_token(pc, first_token, TokenIdKeywordFor);
+ zig_unreachable();
} else {
return nullptr;
}
@@ -1672,6 +1677,7 @@ static AstNode *ast_parse_for_expr(ParseContext *pc, size_t *token_index, bool m
*token_index += 1;
} else if (mandatory) {
ast_expect_token(pc, first_token, TokenIdKeywordFor);
+ zig_unreachable();
} else {
return nullptr;
}
@@ -1726,6 +1732,7 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, boo
*token_index += 2;
} else if (mandatory) {
ast_expect_token(pc, first_token, TokenIdKeywordSwitch);
+ zig_unreachable();
} else {
return nullptr;
}
@@ -1735,6 +1742,7 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, boo
*token_index += 1;
} else if (mandatory) {
ast_expect_token(pc, first_token, TokenIdKeywordSwitch);
+ zig_unreachable();
} else {
return nullptr;
}
@@ -2112,6 +2120,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m
*token_index += 1;
} else if (mandatory) {
ast_expect_token(pc, first_token, TokenIdKeywordFn);
+ zig_unreachable();
} else {
return nullptr;
}
CMakeLists.txt
@@ -178,7 +178,7 @@ if(MINGW)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-error=format= -Wno-error=format -Wno-error=format-extra-args")
endif()
-set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__USE_MINGW_ANSI_STDIO -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits")
+set(EXE_CFLAGS "-std=c++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__USE_MINGW_ANSI_STDIO -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces")
set(EXE_LDFLAGS " ")
if(ZIG_TEST_COVERAGE)
set(EXE_CFLAGS "${EXE_CFLAGS} -fprofile-arcs -ftest-coverage")