aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2020-12-01 12:11:06 +0000
committerPhilip Herron <herron.philip@googlemail.com>2020-12-01 17:50:50 +0000
commit8567160538a82110847b7a62a881ed222718881a (patch)
treea625839935cbe688508d8ec2c2394143de33eaba
parentefbe8cc4d958cf71e95cb681b11eaaba7652f3b2 (diff)
downloadgcc-8567160538a82110847b7a62a881ed222718881a.zip
gcc-8567160538a82110847b7a62a881ed222718881a.tar.gz
gcc-8567160538a82110847b7a62a881ed222718881a.tar.bz2
Ensure the array index is of integer type.
The index expression must be validated to ensure it is an integer. Addresses: #27 #55
-rw-r--r--gcc/rust/analysis/rust-type-resolution.cc10
1 files changed, 9 insertions, 1 deletions
diff --git a/gcc/rust/analysis/rust-type-resolution.cc b/gcc/rust/analysis/rust-type-resolution.cc
index 387f7fc..98ff918 100644
--- a/gcc/rust/analysis/rust-type-resolution.cc
+++ b/gcc/rust/analysis/rust-type-resolution.cc
@@ -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);