Dereferencing an array using a ternary operation (?:) and a function return value as indices can give faulty (and variable) results. In the example code one or more of the asserts can fail (depending on the optimization level), but only when compiling as C++. Release: 3.1 Environment: DOS (DJGPP) and Linux, both x86.
Fix: Doing the ternary operation and/or function call before the array indexing solves (avoids) the problem.
State-Changed-From-To: open->analyzed State-Changed-Why: confirmed, regression
Responsible-Changed-From-To: unassigned->nathan Responsible-Changed-Why: fixing
State-Changed-From-To: analyzed->closed State-Changed-Why: this will appear in 3.2.1 & 3.3 2002-10-22 Nathan Sidwell <nathan@codesourcery.com> PR c++/7209 * fold_const.c (fold_binary_op_with_conditional_arg): Always build compound_expr if we used save_expr.
From: nathan@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/7209 Date: 22 Oct 2002 08:56:50 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: nathan@gcc.gnu.org 2002-10-22 01:56:49 Modified files: gcc : ChangeLog fold-const.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/expr: cond1.C Log message: PR c++/7209 * fold_const.c (fold_binary_op_with_conditional_arg): Always build compound_expr if we used save_expr. testsuite: * g++.dg/expr/cond1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=1.15750&r2=1.15751 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&r1=1.223&r2=1.224 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2171&r2=1.2172 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/cond1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
From: nathan@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: c++/7209 Date: 22 Oct 2002 09:06:20 -0000 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_2-branch Changes by: nathan@gcc.gnu.org 2002-10-22 02:06:20 Modified files: gcc : fold-const.c gcc/testsuite : ChangeLog Log message: PR c++/7209 * fold_const.c (fold_binary_op_with_conditional_arg): Always build compound_expr if we used save_expr. testsuite: * g++.dg/expr: New directory. * g++.dg/expr/cond1.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/fold-const.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.185.2.4.2.1&r2=1.185.2.4.2.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.34&r2=1.1672.2.166.2.35