aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-05-10 18:16:28 +0200
committerLemonBoy <thatlemon@gmail.com>2019-05-11 21:29:00 +0200
commit655794f44fc8563f9fa4d45c208e859382a6a599 (patch)
tree5c886da82f321086ec99759b0a7a26cd4cccd928 /src
parentc766f3f9ca84b81a9f5669dd5132e46355ef284b (diff)
downloadzig-655794f44fc8563f9fa4d45c208e859382a6a599.tar.gz
zig-655794f44fc8563f9fa4d45c208e859382a6a599.zip
amend type_is_valid_extern_enum_tag
Diffstat (limited to 'src')
-rw-r--r--src/analyze.cpp30
1 files changed, 9 insertions, 21 deletions
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) {