On 2026-01-28 18:48, Andrew Pinski wrote:
+/* In the late (waccess3) pass run, addresses to union members may have been
+   replaced to optimize accesses.  This may result in waccess seeing the wrong
+   union member and come to a wrong conclusion about its size.  For now, just
+   bail out when we see the possibility of such a situation.  This could in
+   future walk through the different types and see if there's a union member at
+   the same address that matches the size of the access.  */
+static inline bool
+aliasing_union_addr_p (tree ptr, bool early)
+{
+  if (early)
+    return false;
+
+  /* Thread through the chain of definitions to arrive at an address
+     expression.  */

Isn't at this point one look back enough to get the ADDR_EXPR? Or
there cases where more than one is needed?
Do you have a testcase for those included?

I was trying to be conservative but you're right, for this case there need only be one look back.

+  while (ptr && TREE_CODE (ptr) == SSA_NAME)
+    {
+      gimple *stmt = SSA_NAME_DEF_STMT (ptr);
+      if (gimple_code (stmt) == GIMPLE_ASSIGN)
if (is_a <gassign *> (stmt))

+       ptr = gimple_assign_rhs1 (stmt);

This brings up we looking past a in "a + b". I am not sure that is
correct; yes we are looking for the ADDR_EXPR here though.
Maybe gimple_assign_single_p is better than looking at all assigns.

Agreed.

+      else
+       ptr = NULL;

Why not just return false here?


Indeed, yes.

+    }
+
+  if (ptr && TREE_CODE (ptr) == ADDR_EXPR)
And then this becomes:
if (TREE_CODE (ptr) != ADDR_EXPR)
   return false;


Ack, I'll update and send v2.

I think overall the idea here is solid, just the walk back I am
questioning if needed.

Thanks, I was looking for assurance that I'm heading in the right direction. Thanks to your questions, I realized I should maybe try experimenting with strncpy as well; I have a feeling this will trip builtins too, not just general functions with the access attribute. I'll incorporate that into v2.

Thanks,
Sid

Reply via email to