Skip to content

Commit 032d4fe

Browse files
committed
Work around GCC assuming that enum values are in the correct range.
The whole purpose of the is_valid function is to check it at runtime, so it obviously cannot assume this.
1 parent fdb85c0 commit 032d4fe

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Enum.pm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ sub render_enum_core($$) {
5252
sub render_enum_tables($$$$) {
5353
my ($name,$tag,$base,$count) = @_;
5454

55+
my $base_type = get_primitive_base($tag, 'int32_t');
56+
5557
# Enumerate enum attributes
5658

5759
my %aidx = ('key' => 0);
@@ -110,7 +112,9 @@ sub render_enum_tables($$$$) {
110112
emit "const $name _last_item_of_$name = ($name)", ($base+$count-1), ";";
111113

112114
emit_block {
113-
emit "return (value >= _first_item_of_$name && value <= _last_item_of_$name);";
115+
# Cast the enum to integer in order to avoid GCC assuming the value range is correct.
116+
emit "$base_type ivalue = ($base_type)value;";
117+
emit "return (ivalue >= $base && ivalue <= ",($base+$count-1),");";
114118
} "inline bool is_valid($name value) ";
115119

116120
for (my $i = 0; $i < @anames; $i++) {

0 commit comments

Comments
 (0)