public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "fxcoudert at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/35994] [4.3/4.4 regression] MAXLOC and MINLOC off by one with mask Date: Wed, 23 Apr 2008 08:12:00 -0000 [thread overview] Message-ID: <20080423081151.4506.qmail@sourceware.org> (raw) In-Reply-To: <bug-35994-15620@http.gcc.gnu.org/bugzilla/> ------- Comment #5 from fxcoudert at gcc dot gnu dot org 2008-04-23 08:11 ------- It's not about constantness, but about creating a temporary or not. The following testcase uses a constant mask and it still gives the right answer: REAL DDA(100) logical, parameter :: mask(1:100) = (/(J1,J1=1,100)/) > 50 dda = (/(J1,J1=1,100)/) IDS = MAXLOC(DDA,1, mask) print *, ids ! expect 100 END while the following also uses a compile-time constant mask and gives the wrong answer (51 when it should be 50): REAL DDA(100) logical, parameter :: mask(1:100) = (/(J1,J1=1,100)/) > 50 dda = (/(J1,J1=1,100)/) IDS = MAXLOC(DDA,1, .not. mask) print *, ids ! expect 50 END The code in question is in gfc_conv_intrinsic_minmaxloc (trans-intrinsic.c): /* Remember where we are. An offset must be added to the loop counter to obtain the required position. */ if (loop.temp_dim) tmp = build_int_cst (gfc_array_index_type, 1); else tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type, gfc_index_one_node, loop.from[0]); All the failing cases I've seen so far happen in the (loop.temp_dim == true) branch, and would be fixed by putting a zero there instead of the 1. But... that's not all! It can also be something else than an off-by-one, it can be off-by-more-than-that: REAL DDA(5:104) dda = (/(J1,J1=1,100)/) IDS = MAXLOC(DDA,1) print *, ids ! expect 100 IDS = MAXLOC(DDA,1, (/(J1,J1=1,100)/) > 50) print *, ids ! expect 100 END gives 105 instead of 100 for the second call to MAXLOC. I'm not too sure what is the correct approach, maybe something like (can't test right now): Index: trans-intrinsic.c =================================================================== --- trans-intrinsic.c (revision 134439) +++ trans-intrinsic.c (working copy) @@ -2171,11 +2171,11 @@ /* Remember where we are. An offset must be added to the loop counter to obtain the required position. */ - if (loop.temp_dim) + if (loop.from[0]) tmp = build_int_cst (gfc_array_index_type, 1); else - tmp =fold_build2 (MINUS_EXPR, gfc_array_index_type, - gfc_index_one_node, loop.from[0]); + tmp = fold_build2 (MINUS_EXPR, gfc_array_index_type, + gfc_index_one_node, loop.from[0]); gfc_add_modify_expr (&block, offset, tmp); tmp = fold_build2 (PLUS_EXPR, TREE_TYPE (pos), (the loop.temp_dim vs. loop.from[0] is important, the rest is whitespace change). -- fxcoudert at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |fxcoudert at gcc dot gnu dot | |org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35994
next prev parent reply other threads:[~2008-04-23 8:12 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-04-20 20:31 [Bug fortran/35994] New: " dick dot hendrickson at gmail dot com 2008-04-20 20:51 ` [Bug fortran/35994] " tkoenig at gcc dot gnu dot org 2008-04-22 18:43 ` [Bug fortran/35994] [4.3/4.4 regression] " tkoenig at gcc dot gnu dot org 2008-04-22 18:58 ` tkoenig at gcc dot gnu dot org 2008-04-22 19:35 ` jakub at gcc dot gnu dot org 2008-04-22 22:35 ` pault at gcc dot gnu dot org 2008-04-23 8:12 ` fxcoudert at gcc dot gnu dot org [this message] 2008-04-24 2:05 ` jvdelisle at gcc dot gnu dot org 2008-04-24 3:49 ` jvdelisle at gcc dot gnu dot org 2008-04-24 3:50 ` jvdelisle at gcc dot gnu dot org 2008-04-24 3:56 ` jvdelisle at gcc dot gnu dot org 2008-04-26 15:34 ` jvdelisle at gcc dot gnu dot org 2008-04-26 15:36 ` jvdelisle at gcc dot gnu dot org 2008-04-26 15:37 ` jvdelisle at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080423081151.4506.qmail@sourceware.org \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).