This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][4.1] Fix PR26565, unaligned accesses


The final patch below has been on the mainline now for some time
without appearantly exposing new problems.  I'll propose to backport
it for 4.1.1 now.

Bootstrapped and regtested on ia64-unknown-linux-gnu, 
x86_64-unknown-linux-gnu (on ia64 with unaligned traps on).

Ok for branch?

Thanks,
Richard.

:ADDPATCH middle-end:

2006-03-13  Richard Guenther  <rguenther@suse.de>

	PR middle-end/26565
	* builtins.c (get_pointer_alignment): Handle component
	references for field alignment.

Index: builtins.c
===================================================================
*** gcc/builtins.c	2006-03-15 14:06:59.000000000 +0100
--- gcc/builtins.c	2006-03-20 10:25:27.000000000 +0100
*************** get_pointer_alignment (tree exp, unsigne
*** 275,288 ****
  	case ADDR_EXPR:
  	  /* See what we are pointing at and look at its alignment.  */
  	  exp = TREE_OPERAND (exp, 0);
  	  if (TREE_CODE (exp) == FUNCTION_DECL)
  	    align = FUNCTION_BOUNDARY;
  	  else if (DECL_P (exp))
! 	    align = DECL_ALIGN (exp);
  #ifdef CONSTANT_ALIGNMENT
  	  else if (CONSTANT_CLASS_P (exp))
! 	    align = CONSTANT_ALIGNMENT (exp, align);
  #endif
  	  return MIN (align, max_align);
  
  	default:
--- 275,302 ----
  	case ADDR_EXPR:
  	  /* See what we are pointing at and look at its alignment.  */
  	  exp = TREE_OPERAND (exp, 0);
+ 	  inner = max_align;
+ 	  while (handled_component_p (exp))
+ 	    {
+ 	      /* Fields in a structure can be packed, honour DECL_ALIGN
+ 		 of the FIELD_DECL.  For all other references the conservative 
+ 		 alignment is the element type alignment.  */
+ 	      if (TREE_CODE (exp) == COMPONENT_REF)
+ 		inner = MIN (inner, DECL_ALIGN (TREE_OPERAND (exp, 1)));
+ 	      else
+ 		inner = MIN (inner, TYPE_ALIGN (TREE_TYPE (exp)));
+ 	      exp = TREE_OPERAND (exp, 0);
+ 	    }
  	  if (TREE_CODE (exp) == FUNCTION_DECL)
  	    align = FUNCTION_BOUNDARY;
  	  else if (DECL_P (exp))
! 	    align = MIN (inner, DECL_ALIGN (exp));
  #ifdef CONSTANT_ALIGNMENT
  	  else if (CONSTANT_CLASS_P (exp))
! 	    align = MIN (inner, (unsigned)CONSTANT_ALIGNMENT (exp, align));
  #endif
+ 	  else
+ 	    align = MIN (align, inner);
  	  return MIN (align, max_align);
  
  	default:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]