This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix nullptr access in true_regnum
- From: Oleg Endo <oleg dot endo at t-online dot de>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 16 Oct 2014 23:33:20 +0200
- Subject: Fix nullptr access in true_regnum
- Authentication-results: sourceware.org; auth=none
Hi,
While working on some SH builtins I ran into the issue that the function
true_regnum in jump.c tries to access the reg_renumber array without
checking for nullptr. The particular use case here is using true_regnum
in a predicate that is invoked during builtin function expansion in the
TARGET_EXPAND_BUILTIN function. It seems that at that time reg_renumber
hasn't been initialized yet. Adding the nullptr check fixes the issue.
OK for trunk?
Cheers,
Oleg
gcc/ChangeLog:
* jump.c (true_regnum): Check that reg_renumber is not null
before accessing it.
Index: gcc/jump.c
===================================================================
--- gcc/jump.c (revision 216350)
+++ gcc/jump.c (working copy)
@@ -1908,7 +1908,8 @@
if (REG_P (x))
{
if (REGNO (x) >= FIRST_PSEUDO_REGISTER
- && (lra_in_progress || reg_renumber[REGNO (x)] >= 0))
+ && (lra_in_progress ||
+ (reg_renumber != NULL && reg_renumber[REGNO (x)] >= 0)))
return reg_renumber[REGNO (x)];
return REGNO (x);
}