Hi Martin! Thanks for replying, turns out that while I was trying to reply to you I was able to get the answer. Turns out there is indeed one tree node which is shared across the two functions. And that is
TREE_OPERAND (MEM_REF, 1). When I was assigning to TREE_TYPE ( TREE_OPERAND (MEM_REF, 1) ) in one function, I was modifying the other. The solution was to create a new tree and assign it directly to TREE_OPERAND (MEM_REF, 1) in both functions. Thanks!