From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13569 invoked by alias); 29 Feb 2008 22:15:11 -0000 Received: (qmail 13555 invoked by uid 22791); 29 Feb 2008 22:15:11 -0000 X-Spam-Check-By: sourceware.org Received: from ug-out-1314.google.com (HELO ug-out-1314.google.com) (66.249.92.170) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 29 Feb 2008 22:14:42 +0000 Received: by ug-out-1314.google.com with SMTP id o38so667211ugd.17 for ; Fri, 29 Feb 2008 14:14:39 -0800 (PST) Received: by 10.67.196.2 with SMTP id y2mr2316393ugp.60.1204323279297; Fri, 29 Feb 2008 14:14:39 -0800 (PST) Received: from ?192.168.0.5? ( [90.193.94.40]) by mx.google.com with ESMTPS id b39sm2250997ugf.27.2008.02.29.14.14.37 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 29 Feb 2008 14:14:37 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v753) To: Fortran List , gcc patches Message-Id: <447949DD-912F-4EBA-8BAE-2BAB089B2758@gmail.com> Content-Type: multipart/mixed; boundary=Apple-Mail-61-530285316 From: FX Coudert Subject: [fortran,patch] Fix PR 34956 by not checking bounds of absent optional arguments Date: Fri, 29 Feb 2008 22:53:00 -0000 X-Mailer: Apple Mail (2.753) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2008-02/txt/msg01508.txt.bz2 --Apple-Mail-61-530285316 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed Content-length: 807 valgrind revealed the use of an uninitialized value in gfortran.dg/=20 bounds_check_9.f90 compiled with -fbounds-check, due to bounds-=20 checking being performend on an absent optional argument. There=20=20 already was some code to check for optional args, but it only covered=20=20 half of the bound-checking; IIRC, I was the one who wrote it in the=20=20 first place, so I can only apologize for the bad initial fix. Bootstrapped and regtested on x86_64-linux, checked the tree dump and=20=20 with valgrind that the issue was take care of. No testcase, because I=20=20 can't seem to think of a way to get it to appear without valgrind=20=20 (and the original testcase, of course, is already in the testsuite). OK to commit? FX --=20 Fran=E7ois-Xavier Coudert http://www.homepages.ucl.ac.uk/~uccafco/ --Apple-Mail-61-530285316 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name=pr34956.ChangeLog Content-Disposition: attachment; filename=pr34956.ChangeLog Content-length: 195 2008-02-29 Francois-Xavier Coudert PR fortran/34956 * trans-array.c (gfc_conv_ss_startstride): Fix the logic to avoid checking bounds of absent optional arguments. --Apple-Mail-61-530285316 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name=pr34956.diff Content-Disposition: attachment; filename=pr34956.diff Content-length: 4446 Index: gcc/fortran/trans-array.c =================================================================== --- gcc/fortran/trans-array.c (revision 132773) +++ gcc/fortran/trans-array.c (working copy) @@ -2924,9 +2924,13 @@ gfc_conv_ss_startstride (gfc_loopinfo * for (ss = loop->ss; ss != gfc_ss_terminator; ss = ss->loop_chain) { + stmtblock_t inner; + if (ss->type != GFC_SS_SECTION) continue; + gfc_start_block (&inner); + /* TODO: range checking for mapped dimensions. */ info = &ss->data.info; @@ -2953,7 +2957,7 @@ gfc_conv_ss_startstride (gfc_loopinfo * asprintf (&msg, "Zero stride is not allowed, for dimension %d " "of array '%s'", info->dim[n]+1, ss->expr->symtree->name); - gfc_trans_runtime_check (tmp, &block, &ss->expr->where, msg); + gfc_trans_runtime_check (tmp, &inner, &ss->expr->where, msg); gfc_free (msg); desc = ss->data.info.descriptor; @@ -2995,7 +2999,7 @@ gfc_conv_ss_startstride (gfc_loopinfo * asprintf (&msg, "%s, lower bound of dimension %d of array '%s'" " exceeded (%%ld < %%ld)", gfc_msg_fault, info->dim[n]+1, ss->expr->symtree->name); - gfc_trans_runtime_check (tmp, &block, &ss->expr->where, msg, + gfc_trans_runtime_check (tmp, &inner, &ss->expr->where, msg, fold_convert (long_integer_type_node, info->start[n]), fold_convert (long_integer_type_node, @@ -3011,7 +3015,7 @@ gfc_conv_ss_startstride (gfc_loopinfo * asprintf (&msg, "%s, upper bound of dimension %d of array " "'%s' exceeded (%%ld > %%ld)", gfc_msg_fault, info->dim[n]+1, ss->expr->symtree->name); - gfc_trans_runtime_check (tmp, &block, &ss->expr->where, msg, + gfc_trans_runtime_check (tmp, &inner, &ss->expr->where, msg, fold_convert (long_integer_type_node, info->start[n]), fold_convert (long_integer_type_node, ubound)); gfc_free (msg); @@ -3033,7 +3037,7 @@ gfc_conv_ss_startstride (gfc_loopinfo * asprintf (&msg, "%s, lower bound of dimension %d of array '%s'" " exceeded (%%ld < %%ld)", gfc_msg_fault, info->dim[n]+1, ss->expr->symtree->name); - gfc_trans_runtime_check (tmp, &block, &ss->expr->where, msg, + gfc_trans_runtime_check (tmp, &inner, &ss->expr->where, msg, fold_convert (long_integer_type_node, tmp2), fold_convert (long_integer_type_node, @@ -3048,7 +3052,7 @@ gfc_conv_ss_startstride (gfc_loopinfo * asprintf (&msg, "%s, upper bound of dimension %d of array " "'%s' exceeded (%%ld > %%ld)", gfc_msg_fault, info->dim[n]+1, ss->expr->symtree->name); - gfc_trans_runtime_check (tmp, &block, &ss->expr->where, msg, + gfc_trans_runtime_check (tmp, &inner, &ss->expr->where, msg, fold_convert (long_integer_type_node, tmp2), fold_convert (long_integer_type_node, ubound)); gfc_free (msg); @@ -3066,30 +3070,30 @@ gfc_conv_ss_startstride (gfc_loopinfo * tree tmp3; tmp3 = fold_build2 (NE_EXPR, boolean_type_node, tmp, size[n]); - - /* For optional arguments, only check bounds if the - argument is present. */ - if (ss->expr->symtree->n.sym->attr.optional - || ss->expr->symtree->n.sym->attr.not_always_present) - { - tree cond; - - cond = gfc_conv_expr_present (ss->expr->symtree->n.sym); - tmp3 = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, - cond, tmp3); - } - asprintf (&msg, "%s, size mismatch for dimension %d " "of array '%s' (%%ld/%%ld)", gfc_msg_bounds, info->dim[n]+1, ss->expr->symtree->name); - gfc_trans_runtime_check (tmp3, &block, &ss->expr->where, msg, + gfc_trans_runtime_check (tmp3, &inner, &ss->expr->where, msg, fold_convert (long_integer_type_node, tmp), fold_convert (long_integer_type_node, size[n])); gfc_free (msg); } else - size[n] = gfc_evaluate_now (tmp, &block); + size[n] = gfc_evaluate_now (tmp, &inner); } + + tmp = gfc_finish_block (&inner); + + /* For optional arguments, only check bounds if the argument is + present. */ + if (ss->expr->symtree->n.sym->attr.optional + || ss->expr->symtree->n.sym->attr.not_always_present) + tmp = build3_v (COND_EXPR, + gfc_conv_expr_present (ss->expr->symtree->n.sym), + tmp, build_empty_stmt ()); + + gfc_add_expr_to_block (&block, tmp); + } tmp = gfc_finish_block (&block); --Apple-Mail-61-530285316--