From 655794f44fc8563f9fa4d45c208e859382a6a599 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 10 May 2019 18:16:28 +0200 Subject: amend type_is_valid_extern_enum_tag --- src/analyze.cpp | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index d4e69a1fe6..9462ce0121 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1908,28 +1908,16 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { return ErrorNone; } -static bool type_is_int_compatible(ZigType *t1, ZigType *t2) { - assert(t1->id == ZigTypeIdInt); - assert(t2->id == ZigTypeIdInt); - - if (t1 == t2) - return true; - - return (t1->data.integral.bit_count == t2->data.integral.bit_count && - t1->data.integral.is_signed == t2->data.integral.is_signed); -} - static bool type_is_valid_extern_enum_tag(CodeGen *g, ZigType *ty) { - // According to the ANSI C standard: - // Each enumerated type shall be compatible with char, a signed integer - // type, or an unsigned integer type. - ZigType *c_uint_type = get_c_int_type(g, CIntTypeInt); - ZigType *c_int_type = get_c_int_type(g, CIntTypeInt); - ZigType *c_schar_type = g->builtin_types.entry_i8; - - return (type_is_int_compatible(ty, c_schar_type) || - type_is_int_compatible(ty, c_int_type) || - type_is_int_compatible(ty, c_uint_type)); + // Only integer types are allowed by the C ABI + if(ty->id != ZigTypeIdInt) + return false; + + // According to the ANSI C standard the enumeration type should be either a + // signed char, a signed integer or an unsigned one. But GCC/Clang allow + // other integral types as a compiler extension so let's accomodate them + // aswell. + return type_allowed_in_extern(g, ty); } static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { -- cgit v1.2.3