public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug fortran/50514] New: gfortran should check ISHFT & ISHFTC aruments (r178939) @ 2011-09-25 20:07 zeccav at gmail dot com 2011-09-25 22:13 ` [Bug fortran/50514] " kargl at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: zeccav at gmail dot com @ 2011-09-25 20:07 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50514 Bug #: 50514 Summary: gfortran should check ISHFT & ISHFTC aruments (r178939) Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: fortran AssignedTo: unassigned@gcc.gnu.org ReportedBy: zeccav@gmail.com ! gfortran should check ISHFT & ISHFTC aruments (r178939) ! gfortran should not accept SHIFT>BIT_SIZE(I) print *,ishft(I=m,SHIFT=640) print *,ishftc(I=m,SHIFT=640) ! abs(SHIFT) must be <= SIZE print *,ishftc(I=m,SHIFT=1,SIZE=0) end ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50514] gfortran should check ISHFT & ISHFTC aruments (r178939) 2011-09-25 20:07 [Bug fortran/50514] New: gfortran should check ISHFT & ISHFTC aruments (r178939) zeccav at gmail dot com @ 2011-09-25 22:13 ` kargl at gcc dot gnu.org 2011-09-28 10:43 ` zeccav at gmail dot com ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: kargl at gcc dot gnu.org @ 2011-09-25 22:13 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50514 kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kargl at gcc dot gnu.org --- Comment #1 from kargl at gcc dot gnu.org 2011-09-25 22:05:14 UTC --- Technically, it the programmer that should check the arguments. The prohibitions in the Fortran Standard are placed on the programmer not the Fortran processor (ie., the compiler). Adding the check into do i = 1,1000000 do j = 1, 1000000 do k = 1, 1000000 ! Some stuff here to compute k and n < bit_size(k) m = ishft(k,n) ! for some k, n ! More stuff here to use m end do end do end do seems like useless overhead. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50514] gfortran should check ISHFT & ISHFTC aruments (r178939) 2011-09-25 20:07 [Bug fortran/50514] New: gfortran should check ISHFT & ISHFTC aruments (r178939) zeccav at gmail dot com 2011-09-25 22:13 ` [Bug fortran/50514] " kargl at gcc dot gnu.org @ 2011-09-28 10:43 ` zeccav at gmail dot com 2011-09-28 20:03 ` sgk at troutmask dot apl.washington.edu ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: zeccav at gmail dot com @ 2011-09-28 10:43 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50514 --- Comment #2 from Vittorio Zecca <zeccav at gmail dot com> 2011-09-28 09:20:40 UTC --- I meant checking static expressions at compilation time, as in my example. This has no cost at run time. You proposed a run time check that still should be done if requested with a kind of -fcheck option. By the way, gfortran is already checking consistency of static arguments to intrinsic functions, it is that just these one are left unchecked. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50514] gfortran should check ISHFT & ISHFTC aruments (r178939) 2011-09-25 20:07 [Bug fortran/50514] New: gfortran should check ISHFT & ISHFTC aruments (r178939) zeccav at gmail dot com 2011-09-25 22:13 ` [Bug fortran/50514] " kargl at gcc dot gnu.org 2011-09-28 10:43 ` zeccav at gmail dot com @ 2011-09-28 20:03 ` sgk at troutmask dot apl.washington.edu 2011-09-29 7:56 ` zeccav at gmail dot com 2011-10-20 18:12 ` kargl at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: sgk at troutmask dot apl.washington.edu @ 2011-09-28 20:03 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50514 --- Comment #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> 2011-09-28 19:45:48 UTC --- On Wed, Sep 28, 2011 at 09:20:40AM +0000, zeccav at gmail dot com wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50514 > > --- Comment #2 from Vittorio Zecca <zeccav at gmail dot com> 2011-09-28 09:20:40 UTC --- > I meant checking static expressions at compilation time, as in my example. > This has no cost at run time. I know want you meant. > You proposed a run time check that still should be done if requested with a > kind of -fcheck option. I disagree. > By the way, gfortran is already checking consistency of static arguments to > intrinsic functions, it is that just these one are left unchecked. Yes, I know. I wrote some of the code. Index: testsuite/gfortran.dg/ishft_3.f90 =================================================================== --- testsuite/gfortran.dg/ishft_3.f90 (revision 179208) +++ testsuite/gfortran.dg/ishft_3.f90 (working copy) @@ -1,11 +1,38 @@ ! { dg-do compile } +! PR fortran/50514 program ishft_3 - integer i, j - write(*,*) ishftc( 3, 2, 3 ) - write(*,*) ishftc( 3, 2, i ) - write(*,*) ishftc( 3, i, j ) - write(*,*) ishftc( 3, 128 ) ! { dg-error "exceeds BIT_SIZE of first" } - write(*,*) ishftc( 3, 0, 128 ) ! { dg-error "exceeds BIT_SIZE of first" } - write(*,*) ishftc( 3, 0, 0 ) ! { dg-error "Invalid third argument" } - write(*,*) ishftc( 3, 3, 2 ) ! { dg-error "exceeds third argument" } + + implicit none + + integer j, m + + m = 42 + ! + ! These should compile. + ! + j = ishft(m, 16) + j = ishft(m, -16) + j = ishftc(m, 16) + j = ishftc(m, -16) + ! + ! These should issue an error. + ! + j = ishft(m, 640) ! { dg-error "absolute value of SHIFT" } + j = ishftc(m, 640) ! { dg-error "absolute value of SHIFT" } + j = ishft(m, -640) ! { dg-error "absolute value of SHIFT" } + j = ishftc(m, -640) ! { dg-error "absolute value of SHIFT" } + + ! abs(SHIFT) must be <= SIZE + + j = ishftc(m, 1, 2) + j = ishftc(m, 1, 2) + j = ishftc(m, -1, 2) + j = ishftc(m, -1, 2) + + j = ishftc(m, 10, 2)! { dg-error "absolute value of SHIFT" } + j = ishftc(m, 10, 2)! { dg-error "absolute value of SHIFT" } + j = ishftc(m, -10, 2)! { dg-error "absolute value of SHIFT" } + j = ishftc(m, -10, 2)! { dg-error "absolute value of SHIFT" } + + j = ishftc(m, 1, -2) ! { dg-error "must be positive" } end program Index: fortran/check.c =================================================================== --- fortran/check.c (revision 179208) +++ fortran/check.c (working copy) @@ -318,6 +318,22 @@ less_than_bitsize1 (const char *arg1, gf { gfc_extract_int (expr2, &i2); i3 = gfc_validate_kind (BT_INTEGER, expr1->ts.kind, false); + + /* For ISHFT[C], |shift| <= bit_size(i). */ + if (strncmp (arg2, "ISHFT", 5) == 0) + { + 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) @@ -1961,6 +1977,9 @@ gfc_check_ishft (gfc_expr *i, gfc_expr * || type_check (shift, 1, BT_INTEGER) == FAILURE) return FAILURE; + if (less_than_bitsize1 ("I", i, "ISHFT", shift, true) == FAILURE) + return FAILURE; + return SUCCESS; } @@ -1972,7 +1991,35 @@ gfc_check_ishftc (gfc_expr *i, gfc_expr || 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, "ISHFTC", shift, true) == FAILURE) return FAILURE; return SUCCESS; ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50514] gfortran should check ISHFT & ISHFTC aruments (r178939) 2011-09-25 20:07 [Bug fortran/50514] New: gfortran should check ISHFT & ISHFTC aruments (r178939) zeccav at gmail dot com ` (2 preceding siblings ...) 2011-09-28 20:03 ` sgk at troutmask dot apl.washington.edu @ 2011-09-29 7:56 ` zeccav at gmail dot com 2011-10-20 18:12 ` kargl at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: zeccav at gmail dot com @ 2011-09-29 7:56 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50514 --- Comment #4 from Vittorio Zecca <zeccav at gmail dot com> 2011-09-29 06:58:24 UTC --- About run time checking: I believe the bit size of k is known at compile time, and the overhead to check n against it is negligible as compared to computing ishft itself and maybe n. Of course when I am asking -fcheck I am prepared to slower execution, but it may well pay off, if I find a bug. I believe programmer (debugging) time is now costlier than hardware time. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug fortran/50514] gfortran should check ISHFT & ISHFTC aruments (r178939) 2011-09-25 20:07 [Bug fortran/50514] New: gfortran should check ISHFT & ISHFTC aruments (r178939) zeccav at gmail dot com ` (3 preceding siblings ...) 2011-09-29 7:56 ` zeccav at gmail dot com @ 2011-10-20 18:12 ` kargl at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: kargl at gcc dot gnu.org @ 2011-10-20 18:12 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50514 kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |FIXED --- Comment #5 from kargl at gcc dot gnu.org 2011-10-20 18:11:33 UTC --- Fixed on trunk for static checking. Runtime checking is not going to happen due to the overhead. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-10-20 18:12 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-09-25 20:07 [Bug fortran/50514] New: gfortran should check ISHFT & ISHFTC aruments (r178939) zeccav at gmail dot com 2011-09-25 22:13 ` [Bug fortran/50514] " kargl at gcc dot gnu.org 2011-09-28 10:43 ` zeccav at gmail dot com 2011-09-28 20:03 ` sgk at troutmask dot apl.washington.edu 2011-09-29 7:56 ` zeccav at gmail dot com 2011-10-20 18:12 ` kargl at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).