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]

[Ada] Fix unaligned access problem in record with packed components


2001-12-04  Ed Schonberg <schonber@gnat.com>

	* exp_util.adb (Must_Be_Aligned): Return false for a component of a 
	record that has other packed components.

*** exp_util.adb	2001/10/05 15:43:39	1.332
--- exp_util.adb	2001/10/09 12:41:22	1.333
***************
*** 2497,2502 ****
--- 2497,2526 ----
     function Must_Be_Aligned (Obj : Node_Id) return Boolean is
        Typ : constant Entity_Id := Etype (Obj);
  
+       function In_Partially_Packed_Record (Comp : Entity_Id) return Boolean;
+       --  If the component is in a record that contains previous packed
+       --  components, consider it unaligned because the back-end might
+       --  choose to pack the rest of the record. Lead to less efficient code,
+       --  but safer vis-a-vis of back-end choices.
+ 
+       function In_Partially_Packed_Record (Comp : Entity_Id) return Boolean is
+          Rec_Type : constant Entity_Id := Scope (Comp);
+          Prev_Comp : Entity_Id;
+       begin
+          Prev_Comp := First_Entity (Rec_Type);
+          while Present (Prev_Comp) loop
+             if Is_Packed (Etype (Prev_Comp)) then
+                return True;
+ 
+             elsif Prev_Comp = Comp then
+                return False;
+             end if;
+ 
+             Next_Entity (Prev_Comp);
+          end loop;
+ 
+          return False;
+       end  In_Partially_Packed_Record;
     begin
        --  If object is strictly aligned, we can quit now
  
***************
*** 2535,2540 ****
--- 2559,2567 ----
           --  backend is doing alignment computations).
  
           elsif Present (Component_Clause (Entity (Selector_Name (Obj)))) then
+             return False;
+ 
+          elsif In_Partially_Packed_Record (Entity (Selector_Name (Obj))) then
              return False;
  
           --  In all other cases, go look at prefix


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