diff options
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -12267,4 +12267,32 @@ drop_tree_overflow (tree t) return t; } +/* Given a memory reference expression T, return its base address. + The base address of a memory reference expression is the main + object being referenced. For instance, the base address for + 'array[i].fld[j]' is 'array'. You can think of this as stripping + away the offset part from a memory address. + + This function calls handled_component_p to strip away all the inner + parts of the memory reference until it reaches the base object. */ + +tree +get_base_address (tree t) +{ + while (handled_component_p (t)) + t = TREE_OPERAND (t, 0); + + if ((TREE_CODE (t) == MEM_REF + || TREE_CODE (t) == TARGET_MEM_REF) + && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR) + t = TREE_OPERAND (TREE_OPERAND (t, 0), 0); + + /* ??? Either the alias oracle or all callers need to properly deal + with WITH_SIZE_EXPRs before we can look through those. */ + if (TREE_CODE (t) == WITH_SIZE_EXPR) + return NULL_TREE; + + return t; +} + #include "gt-tree.h" |