authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-10 18:16:28+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-11 21:29:00+02:00
log655794f44fc8563f9fa4d45c208e859382a6a599
tree5c886da82f321086ec99759b0a7a26cd4cccd928
parentc766f3f9ca84b81a9f5669dd5132e46355ef284b

amend type_is_valid_extern_enum_tag


1 files changed, 9 insertions(+), 21 deletions(-)

src/analyze.cpp+9-21
...@@ -1908,28 +1908,16 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {...@@ -1908,28 +1908,16 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) {
1908 return ErrorNone;1908 return ErrorNone;
1909}1909}
19101910
1911static bool type_is_int_compatible(ZigType *t1, ZigType *t2) {
1912 assert(t1->id == ZigTypeIdInt);
1913 assert(t2->id == ZigTypeIdInt);
1914
1915 if (t1 == t2)
1916 return true;
1917
1918 return (t1->data.integral.bit_count == t2->data.integral.bit_count &&
1919 t1->data.integral.is_signed == t2->data.integral.is_signed);
1920}
1921
1922static bool type_is_valid_extern_enum_tag(CodeGen *g, ZigType *ty) {1911static bool type_is_valid_extern_enum_tag(CodeGen *g, ZigType *ty) {
1923 // According to the ANSI C standard:1912 // Only integer types are allowed by the C ABI
1924 // Each enumerated type shall be compatible with char, a signed integer1913 if(ty->id != ZigTypeIdInt)
1925 // type, or an unsigned integer type.1914 return false;
1926 ZigType *c_uint_type = get_c_int_type(g, CIntTypeInt);1915
1927 ZigType *c_int_type = get_c_int_type(g, CIntTypeInt);1916 // According to the ANSI C standard the enumeration type should be either a
1928 ZigType *c_schar_type = g->builtin_types.entry_i8;1917 // signed char, a signed integer or an unsigned one. But GCC/Clang allow
19291918 // other integral types as a compiler extension so let's accomodate them
1930 return (type_is_int_compatible(ty, c_schar_type) ||1919 // aswell.
1931 type_is_int_compatible(ty, c_int_type) ||1920 return type_allowed_in_extern(g, ty);
1932 type_is_int_compatible(ty, c_uint_type));
1933}1921}
19341922
1935static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {1923static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {