ipa-prop: Skip analysis od static constructor entries with no index (PR124260)

PR 124260 is about dereferencing a NULL "index" tree when traversing
static constructors of global variables.  As discussed in the bug, it
is unclear whether that is allowed but ObjC compiler creates these at
least on 32bit hosts.  Ian plans to fix this in the FE in the next
stage1 but for this stage4, such entries can be easily skipped in
ipa-prop (too).  The collected information is used for speculative
"devirtualization" ony and so if we miss a relevant entry, it may only
result in a "bad" decision whether to do that or not.

gcc/ChangeLog:

2026-03-11  Martin Jambor  <mjambor@suse.cz>

	PR objc/124260
	* ipa-prop.cc (ipa_analyze_var_static_initializer): Skip a constructor
	entry if its index is NULL.
This commit is contained in:
Martin Jambor
2026-03-12 16:59:34 +01:00
committed by Martin Jambor
parent 0661c5480c
commit 70e1e055e5

View File

@@ -3637,7 +3637,9 @@ ipa_analyze_var_static_initializer (varpool_node *node)
val)
{
if (TREE_CODE (val) != ADDR_EXPR
|| TREE_CODE (TREE_OPERAND (val, 0)) != FUNCTION_DECL)
|| TREE_CODE (TREE_OPERAND (val, 0)) != FUNCTION_DECL
/* ObjC can produce constructor elements with NULL indices. */
|| !index)
continue;
HOST_WIDE_INT elt_offset = int_bit_position (index);
if ((elt_offset % BITS_PER_UNIT) != 0)