ajxs
ajxs

Reputation: 3618

Ada: Incompatible alignment warning issued when specifying an address clause

Is there an ideal way to avoid compile-time warnings about incompatible alignment raised when using the import clause on architectures with strict alignment requirements?

This behavior is described in the GCC manual here. I'm compiling with riscv64-elf-gnat. All warnings are enabled, and warnings treated as errors. I understand that I can suppress this particular warning. Is there an ideal way to handle this scenario in code?

This warning seems rather arbitrary. It doesn't seem to be possible to handle this scenario within the exception handling block of the function itself. Any help here would be appreciated.

For example, the code below:

   ----------------------------------------------------------------------------
   --  Read_Unsigned_8
   ----------------------------------------------------------------------------
   function Read_Unsigned_8 (
     Addr : System.Address
   ) return Unsigned_8 is
      Data : Unsigned_8
      with Import,
        Address => Addr;
   begin
      return Data;
   end Read_Unsigned_8;

Raises this warning:

mmio.adb:23:09: warning: pragma Restrictions (No_Exception_Propagation) in effect
mmio.adb:23:09: warning: "Program_Error" may call Last_Chance_Handler
mmio.adb:23:09: warning: address value may be incompatible with alignment of object

Upvotes: 2

Views: 226

Answers (1)

Simon Wright
Simon Wright

Reputation: 25491

With arm-eabi, you can make this over-enthusiastic (not to say wrong) warning go away by specifying the alignment:

   Data : Unsigned_8
     with
       Import,
       Address   => Addr,
       Alignment => 1;

Upvotes: 4

Related Questions