Skip to content

Commit 8567160

Browse files
committed
Ensure the array index is of integer type.
The index expression must be validated to ensure it is an integer. Addresses: gcc-mirror#27 gcc-mirror#55
1 parent efbe8cc commit 8567160

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

gcc/rust/analysis/rust-type-resolution.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,15 @@ TypeResolution::visit (AST::ArrayIndexExpr &expr)
496496

497497
// check the index_type should be an i32 which should really be
498498
// more permissive
499-
// TODO
499+
AST::Type *i32 = nullptr;
500+
scope.LookupType ("i32", &i32);
501+
rust_assert (i32 != nullptr);
502+
503+
if (!typesAreCompatible (array_index_type, i32,
504+
expr.get_index_expr ()->get_locus_slow ()))
505+
{
506+
return;
507+
}
500508

501509
// the the element type from the array_expr_type and it _must_ be an array
502510
AST::ArrayType *resolved = ArrayTypeVisitor::Resolve (array_expr_type);

0 commit comments

Comments
 (0)