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] |
A reference to an element of a packed array is rewritten through conversions and masks and shifts. If the prefix of the reference is a source entity we must generate a reference to it for cross-reference purposes, and to prevent spurious warnings about unused entities. Compiling gcc -c -gnatwa case_2.adb must yield: case_2.adb:10:06: warning: unit "System" is not referenced case_2.adb:37:13: warning: 1 bits of "Storage_Record_Type" unused -- -- Test case for anomalous GNAT compiler warning. -- Compile as follows: -- gnatmake -f -gnatwf case_2 -- -- This will create a warning that the formal parameter "Storage" of the -- function Test_Function is not referenced, even though it is. -- with System; with Text_IO; procedure Case_2 is -- -- 32-bit signed integer type -- type My_Long is range -(2 ** 31) .. +(2 ** 31) - 1; for My_Long'size use 32; -- -- Changing this to 64 will prevent the warning from being reported. -- Record_Size : constant := 65; -- -- Note: this type is defined as having an extra bit unused for ease of -- switching the size to 64 to see the warning go away. -- Even adding an extra field to fill in the unused bit, GNAT still -- reports the warning. -- type Storage_Record_Type is record E : My_Long; F : My_Long; end record with Size => Record_Size; type My_Storage_Array_Type is array (My_Long range <>) of Storage_Record_Type with Pack => True; -- -- GNAT gives a warning that "Storage" is not used. -- function Test_Function (Storage : in My_Storage_Array_Type; Left : in My_Long; Right : in My_Long) return Boolean is begin return Storage (Left).E < Storage (Right).F; end Test_Function; -- -- Dummy variables to support the below code. -- Test : My_Storage_Array_Type (1 .. 1); Result : Boolean; begin -- -- This small bit of code is only here to ensure that none of the above -- parts get optimized out during compilation. -- Test (1) := (E => 0, F => 0); Result := Test_Function (Test, 1, 1); Text_IO.Put_Line (Boolean'image (Result)); end Case_2; Tested on x86_64-pc-linux-gnu, committed on trunk 2014-10-23 Ed Schonberg <schonberg@adacore.com> * exp_pakd.adb (Expand_Packed_Element_Reference): If the prefix is a source entity, generate a reference to it before transformation, because rewritten node might not generate a proper reference, leading to spurious warnings.
Attachment:
difs
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |