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);