V9 [PATCH] C/C++: Add -Waddress-of-packed-member

Jason Merrill jason@redhat.com
Thu Dec 20 19:40:00 GMT 2018


On 12/19/18 12:35 PM, H.J. Lu wrote:
> +  while (handled_component_p (rhs))
> +    {
> +      if (TREE_CODE (rhs) == COMPONENT_REF)
> +	break;
> +      rhs = TREE_OPERAND (rhs, 0);
> +    }
> +
> +  if (TREE_CODE (rhs) != COMPONENT_REF)
> +    return NULL_TREE;
> +
> +  object = TREE_OPERAND (rhs, 0);
> +  field = TREE_OPERAND (rhs, 1);
> +
> +  tree context = check_alignment_of_packed_member (type, field);
> +  if (context)
> +    return context;

All the above looks unnecessary; it will be handled by the loop below.

> +  /* Check alignment of the object.  */
> +  while (handled_component_p (object))
> +    {
> +      if (TREE_CODE (object) == COMPONENT_REF)
> +	{
> +	  do
> +	    {
> +	      field = TREE_OPERAND (object, 1);
> +	      context = check_alignment_of_packed_member (type, field);
> +	      if (context)
> +		return context;
> +	      object = TREE_OPERAND (object, 0);
> +	    }
> +	  while (TREE_CODE (object) == COMPONENT_REF);

This inner loop also seems unnecessary.

> +	}
> +      else
> +	object = TREE_OPERAND (object, 0);
> +    }

Jason



More information about the Gcc-patches mailing list