From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19801 invoked by alias); 21 Nov 2014 19:04:29 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 19781 invoked by uid 48); 21 Nov 2014 19:04:23 -0000 From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/64003] valgrind complains about get_attr_length_nobnd in insn-attrtab.c from i386.md Date: Fri, 21 Nov 2014 19:04:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dmalcolm at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-11/txt/msg02472.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64003 --- Comment #6 from dmalcolm at gcc dot gnu.org --- If I'm reading things right, this loop in shorten_branches populates insn_lengths[uid] in order of the NEXT_INSN () iteration: int (*length_fun) (rtx_insn *) = increasing ? insn_min_length : insn_default_length; for (insn_current_address = 0, insn = first; insn != 0; insn_current_address += insn_lengths[uid], insn = NEXT_INSN (insn)) { uid = INSN_UID (insn); insn_lengths[uid] = 0; /* lots of logic, which can call length_fun, and hence insn_min_length. */ } and "length_fun" can call into insn_min_length, and hence this calls into the get_attr_length_nobnd, which AIUI for this case is accessing lengths of other insns before they've been populated: presumably for a jump forwards? FWIW this untested patch silences the valgrind warning: diff --git a/gcc/final.c b/gcc/final.c index c3805c9..0805418 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -1019,7 +1019,7 @@ shorten_branches (rtx_insn *first) return; /* Allocate the rest of the arrays. */ - insn_lengths = XNEWVEC (int, max_uid); + insn_lengths = XCNEWVEC (int, max_uid); insn_lengths_max_uid = max_uid; /* Syntax errors can lead to labels being outside of the main insn stream. Initialize insn_addresses, so that we get reproducible results. */ @@ -1127,8 +1127,6 @@ shorten_branches (rtx_insn *first) { uid = INSN_UID (insn); - insn_lengths[uid] = 0; - if (LABEL_P (insn)) { int log = LABEL_TO_ALIGNMENT (insn);