diff options
author | Steven G. Kargl <kargl@gcc.gnu.org> | 2011-10-20 18:07:10 +0000 |
---|---|---|
committer | Steven G. Kargl <kargl@gcc.gnu.org> | 2011-10-20 18:07:10 +0000 |
commit | 0019028b0b585fddd080e626e33c3c4420fbd486 (patch) | |
tree | 97790bb4887f0402df98a32050b17ae9213d8e02 /gcc/fortran/check.c | |
parent | 86daf6d59d37755f3b73a10bb489e53f6c224a8c (diff) | |
download | gcc-0019028b0b585fddd080e626e33c3c4420fbd486.zip gcc-0019028b0b585fddd080e626e33c3c4420fbd486.tar.gz gcc-0019028b0b585fddd080e626e33c3c4420fbd486.tar.bz2 |
ishft_3.f90: Update test.
2011-10-20 Steven G. Kargl <kargl@gcc.gnu.org>
* gfortran.dg/ishft_3.f90: Update test.
2011-10-20 Steven G. Kargl <kargl@gcc.gnu.org>
* check.c (less_than_bitsize1): Check |shift| <= bit_size(i).
(gfc_check_ishftc): Check |shift| <= bit_size(i) and check
that size is positive.
From-SVN: r180264
Diffstat (limited to 'gcc/fortran/check.c')
-rw-r--r-- | gcc/fortran/check.c | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index bf45592..9aaad01 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -286,6 +286,22 @@ less_than_bitsize1 (const char *arg1, gfc_expr *expr1, const char *arg2, { gfc_extract_int (expr2, &i2); i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false); + + /* For ISHFT[C], check that |shift| <= bit_size(i). */ + if (arg2 == NULL) + { + if (i2 < 0) + i2 = -i2; + + if (i2 > gfc_integer_kinds[i3].bit_size) + { + gfc_error ("The absolute value of SHIFT at %L must be less " + "than or equal to BIT_SIZE('%s')", + &expr2->where, arg1); + return FAILURE; + } + } + if (or_equal) { if (i2 > gfc_integer_kinds[i3].bit_size) @@ -1927,6 +1943,9 @@ gfc_check_ishft (gfc_expr *i, gfc_expr *shift) || type_check (shift, 1, BT_INTEGER) == FAILURE) return FAILURE; + if (less_than_bitsize1 ("I", i, NULL, shift, true) == FAILURE) + return FAILURE; + return SUCCESS; } @@ -1938,7 +1957,35 @@ gfc_check_ishftc (gfc_expr *i, gfc_expr *shift, gfc_expr *size) || type_check (shift, 1, BT_INTEGER) == FAILURE) return FAILURE; - if (size != NULL && type_check (size, 2, BT_INTEGER) == FAILURE) + if (size != NULL) + { + int i2, i3; + + if (type_check (size, 2, BT_INTEGER) == FAILURE) + return FAILURE; + + if (less_than_bitsize1 ("I", i, "SIZE", size, true) == FAILURE) + return FAILURE; + + gfc_extract_int (size, &i3); + if (i3 <= 0) + { + gfc_error ("SIZE at %L must be positive", &size->where); + return FAILURE; + } + + gfc_extract_int (shift, &i2); + if (i2 < 0) + i2 = -i2; + + if (i2 > i3) + { + gfc_error ("The absolute value of SHIFT at %L must be less than " + "or equal to SIZE at %L", &shift->where, &size->where); + return FAILURE; + } + } + else if (less_than_bitsize1 ("I", i, NULL, shift, true) == FAILURE) return FAILURE; return SUCCESS; |