* misaligned actual cannot be passed by reference
@ 2011-12-06 14:14 awdorrin
2011-12-06 21:53 ` awdorrin
2011-12-07 14:47 ` Robert Matthews
0 siblings, 2 replies; 3+ messages in thread
From: awdorrin @ 2011-12-06 14:14 UTC (permalink / raw)
I have the following record definition that is used as a shared data
area:
type FP_SHARED_BUF_TYPE is
record
-- POSIX.Mutexes
LOCK_SHM_ACT_NRT : Mutex;
LOCK_SHM_ACT_RT : Mutex;
LOCK_SHM_EXIT_NRT : Mutex
LOCK_SHM_EXIT_RT : Mutex;
LOCK_SHM_RT_STATUS : Mutex;
LOCK_SHM_NRT_STATUS : Mutex;
LOCK_SHM_NRT_FILENAME : Mutex;
LOCK_SHM_REINIT_FLAG : Mutex;
LOCK_ERROR : Mutex;
FP_PIDS : FP_PID_ARRAY_TYPE := (others => 0);
CYCLE_CTR : INT32 := 0;
CMN_SHM_READY : INT8;
MSCS_PER_SEC : INT8;
CURRENT_AC_TYPE : GLOBAL_TYPES.AIRCRAFT_TYPE :=
GLOBAL_TYPES.NONE;
SIM_STATUS : INT32 := 0;
CHAN_RATES : M1553_RATE_TYPE;
DCFSHM : DCFSHM_TYPE;
ERRORS_SHM : ERRORS_SHM_TYPE;
PERFORMANCE : PERFORM_ARRAY_TYPE;
LOCK_MISSION_VARS : Mutex;
MISSION_START_TIME : INT32;
MISSION_TIME : INT32;
MISSION_FRAME_COUNT : INT32;
LOCK_BUS_DATA : Mutex;
LOCK_CHNG_SCREEN : Mutex;
LOCK_STACK_DATA : Mutex;
LOCK_START_TIME : Mutex;
LOCK_SHM_TC_UPDATE : Mutex;
LOCK_UPDATE_RATE : Mutex;
OISHM : OISHM_TYPE;
LOCK_NAV : Mutex;
LOCK_PB : Mutex;
NAV : NAV_SHM_TYPE;
NAV_SERV : NAV_SERV_REQ_TYPE;
PB : PB_SHM_TYPE;
MISSION_DESC : MISSION_DESC_TYPE;
COMPANION_ID : INT32;
CAPTURE_TIME : INT32;
end record;
Compiling with the -gnatR3 option I get the following rep spec:
for FP_SHARED_BUF_TYPE'Size use 7693248;
for FP_SHARED_BUF_TYPE'Alignment use 8;
for FP_SHARED_BUF_TYPE use record
LOCK_SHM_ACT_NRT at 0 range 0 .. 255;
LOCK_SHM_ACT_RT at 32 range 0 .. 255;
LOCK_SHM_EXIT_NRT at 64 range 0 .. 255;
LOCK_SHM_EXIT_RT at 96 range 0 .. 255;
LOCK_SHM_RT_STATUS at 128 range 0 .. 255;
LOCK_SHM_NRT_STATUS at 160 range 0 .. 255;
LOCK_SHM_NRT_FILENAME at 192 range 0 .. 255;
LOCK_SHM_REINIT_FLAG at 224 range 0 .. 255;
LOCK_ERROR at 256 range 0 .. 255;
FP_PIDS at 288 range 0 .. 511;
CYCLE_CTR at 352 range 0 .. 31;
CMN_SHM_READY at 356 range 0 .. 7;
MSCS_PER_SEC at 357 range 0 .. 7;
CURRENT_AC_TYPE at 358 range 0 .. 7;
SIM_STATUS at 360 range 0 .. 31;
CHAN_RATES at 364 range 0 .. 127;
DCFSHM at 380 range 0 .. 196255;
ERRORS_SHM at 24912 range 0 .. 219903;
PERFORMANCE at 52400 range 0 .. 20479;
LOCK_MISSION_VARS at 54960 range 0 .. 255;
MISSION_START_TIME at 54992 range 0 .. 31;
MISSION_TIME at 54996 range 0 .. 31;
MISSION_FRAME_COUNT at 55000 range 0 .. 31;
LOCK_BUS_DATA at 55008 range 0 .. 255;
LOCK_CHNG_SCREEN at 55040 range 0 .. 255;
LOCK_STACK_DATA at 55072 range 0 .. 255;
LOCK_START_TIME at 55104 range 0 .. 255;
LOCK_SHM_TC_UPDATE at 55136 range 0 .. 255;
LOCK_UPDATE_RATE at 55168 range 0 .. 255;
OISHM at 55200 range 0 .. 703;
LOCK_NAV at 55288 range 0 .. 255;
LOCK_PB at 55320 range 0 .. 255;
NAV at 55352 range 0 .. 799999;
NAV_SERV at 155352 range 0 .. 48063;
PB at 161360 range 0 .. 6401407;
MISSION_DESC at 961536 range 0 .. 895;
COMPANION_ID at 961648 range 0 .. 31;
CAPTURE_TIME at 961652 range 0 .. 31;
end record;
Since I have a struct defined in C code which must map this, I don't
want the GNAT compiler moving things around in future builds, so I cut
and pasted this rep spec into the Ada code.
The next time I compile, I get the error message mentioned in the
subject:
"misaligned actual cannot be passed by reference"
There are several locations in the code being flagged but an example
is:
POSIX.Mutexes.Lock( POSIX.Mutexes.Descriptor_Of( CMN_SHM.LOCK_MISSION_VARS ) );
Looking at the LOCK_MISSION_VARS in the rep spec, it is defined as:
LOCK_MISSION_VARS at 54960 range 0 .. 255;
54960 is an 8 byte boundary, so I am not sure why GNAT thinks this is
misaligned, especially since this error is not flagged if I do not
include the rep spec in the code.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: misaligned actual cannot be passed by reference
2011-12-06 14:14 misaligned actual cannot be passed by reference awdorrin
@ 2011-12-06 21:53 ` awdorrin
2011-12-07 14:47 ` Robert Matthews
1 sibling, 0 replies; 3+ messages in thread
From: awdorrin @ 2011-12-06 21:53 UTC (permalink / raw)
I spent a long time today stepping through the debugger and looking at
the address locations of the record elements in both Ada and the
corresponding C Structure.
It looks like the rep spec that GNAT generated was not aligning some
of the values the way it wanted to. I was able to manually adjust the
rep spec (and the C struct) - and now GNAT is happy with the results.
Not sure why GNAT didn't align the items properly to begin with...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: misaligned actual cannot be passed by reference
2011-12-06 14:14 misaligned actual cannot be passed by reference awdorrin
2011-12-06 21:53 ` awdorrin
@ 2011-12-07 14:47 ` Robert Matthews
1 sibling, 0 replies; 3+ messages in thread
From: Robert Matthews @ 2011-12-07 14:47 UTC (permalink / raw)
To share with your C code, this is normally sufficient:
pragma Convention(C, FP_SHARED_BUF_TYPE);
with no need for the representation clause.
GNAT should then give a compatable layout.
In addition, I presume: "POSIX.Mutexes.Descriptor_Of (CMN_SHM.LOCK_MISSION_VARS)"
is needing the address of the parameter - so shouldn't that component of the
record be declared as aliased?
Robert
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-12-07 14:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-06 14:14 misaligned actual cannot be passed by reference awdorrin
2011-12-06 21:53 ` awdorrin
2011-12-07 14:47 ` Robert Matthews
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox