Skip to content

Commit

Permalink
Ensure the array index is of integer type.
Browse files Browse the repository at this point in the history
The index expression must be validated to ensure it is an integer.

Addresses: gcc-mirror#27 gcc-mirror#55
  • Loading branch information
philberty committed Dec 1, 2020
1 parent efbe8cc commit 8567160
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gcc/rust/analysis/rust-type-resolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,15 @@ TypeResolution::visit (AST::ArrayIndexExpr &expr)

// check the index_type should be an i32 which should really be
// more permissive
// TODO
AST::Type *i32 = nullptr;
scope.LookupType ("i32", &i32);
rust_assert (i32 != nullptr);

if (!typesAreCompatible (array_index_type, i32,
expr.get_index_expr ()->get_locus_slow ()))
{
return;
}

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

0 comments on commit 8567160

Please sign in to comment.