stage3/array_range_check.cc
changeset 599 60f3edcf6a8f
parent 598 0b1ee7e7123b
child 612 c062ff18d04f
equal deleted inserted replaced
598:0b1ee7e7123b 599:60f3edcf6a8f
   117   for (int i =  0; i < l->n; i++) {
   117   for (int i =  0; i < l->n; i++) {
   118     subrange_c *dimension = array_dimension_iterator.next();
   118     subrange_c *dimension = array_dimension_iterator.next();
   119     /* mismatch between number of indexes/subscripts. This error will be caught in check_dimension_count() so we ignore it. */
   119     /* mismatch between number of indexes/subscripts. This error will be caught in check_dimension_count() so we ignore it. */
   120     if (NULL == dimension) 
   120     if (NULL == dimension) 
   121       return;
   121       return;
   122     
   122 
       
   123     /* Check lower limit */
   123     if ( VALID_CVALUE( int64, l->elements[i]) && VALID_CVALUE( int64, dimension->lower_limit))
   124     if ( VALID_CVALUE( int64, l->elements[i]) && VALID_CVALUE( int64, dimension->lower_limit))
   124       if ( GET_CVALUE( int64, l->elements[i])   <  GET_CVALUE( int64, dimension->lower_limit))
   125       if ( GET_CVALUE( int64, l->elements[i])   <  GET_CVALUE( int64, dimension->lower_limit))
   125       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
   126       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
   126 
   127 
       
   128     if ( VALID_CVALUE( int64, l->elements[i]) && VALID_CVALUE(uint64, dimension->lower_limit))
       
   129       if ( GET_CVALUE( int64, l->elements[i])   <  GET_CVALUE(uint64, dimension->lower_limit))
       
   130       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
       
   131 
       
   132     if ( VALID_CVALUE(uint64, l->elements[i]) && VALID_CVALUE(uint64, dimension->lower_limit))
       
   133       if ( GET_CVALUE(uint64, l->elements[i])   <  GET_CVALUE(uint64, dimension->lower_limit))
       
   134       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
       
   135 
       
   136     if ( VALID_CVALUE(uint64, l->elements[i]) && VALID_CVALUE( int64, dimension->lower_limit))
       
   137       if ( GET_CVALUE(uint64, l->elements[i])   <  GET_CVALUE( int64, dimension->lower_limit))
       
   138       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
       
   139 
       
   140     /* Repeat the same check, now for upper limit */
   127     if ( VALID_CVALUE( int64, l->elements[i]) && VALID_CVALUE( int64, dimension->upper_limit))
   141     if ( VALID_CVALUE( int64, l->elements[i]) && VALID_CVALUE( int64, dimension->upper_limit))
   128       if ( GET_CVALUE( int64, l->elements[i])   >  GET_CVALUE( int64, dimension->upper_limit))
   142       if ( GET_CVALUE( int64, l->elements[i])   >  GET_CVALUE( int64, dimension->upper_limit))
   129       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
   143       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
   130 
   144 
   131     if ( VALID_CVALUE(uint64, l->elements[i]) && VALID_CVALUE(uint64, dimension->lower_limit))
   145     if ( VALID_CVALUE( int64, l->elements[i]) && VALID_CVALUE(uint64, dimension->upper_limit))
   132       if ( GET_CVALUE(uint64, l->elements[i])   <  GET_CVALUE(uint64, dimension->lower_limit))
   146       if ( GET_CVALUE( int64, l->elements[i])   >  GET_CVALUE(uint64, dimension->upper_limit))
   133       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
   147       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
   134 
   148 
   135     if ( VALID_CVALUE(uint64, l->elements[i]) && VALID_CVALUE(uint64, dimension->upper_limit))
   149     if ( VALID_CVALUE(uint64, l->elements[i]) && VALID_CVALUE(uint64, dimension->upper_limit))
   136       if ( GET_CVALUE(uint64, l->elements[i])   >  GET_CVALUE(uint64, dimension->upper_limit))
   150       if ( GET_CVALUE(uint64, l->elements[i])   >  GET_CVALUE(uint64, dimension->upper_limit))
   137       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
   151       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
   138       
   152       
   139     /* TODO: what happens when one has a int64 cvalue, and another has a uint64 cvalue? */
   153     if ( VALID_CVALUE(uint64, l->elements[i]) && VALID_CVALUE( int64, dimension->upper_limit))
       
   154       if ( GET_CVALUE(uint64, l->elements[i])   >  GET_CVALUE( int64, dimension->upper_limit))
       
   155       {STAGE3_ERROR(0, symbol, symbol, "Array access out of bounds."); continue;}
       
   156       
       
   157    /* TODO: How do we make these comparisons between int and unsigned int, without the compiler complaining? */
   140   }
   158   }
   141 }
   159 }
   142 
   160 
   143 
   161 
   144 
   162