-
Notifications
You must be signed in to change notification settings - Fork 246
Open
Description
On architecture IA32, ./ccomp -interp on the following program printfs ERROR: Initial state undefined
(just tested on commit ce0f6ca).
typedef struct {
char is_float;
union {
long long i;
double f;
} u;
} number;
number x={.is_float=0, .u={.i=42}};
number y;
int main(){
y.u = x.u;
return y.u.i;
}I guess that there is no such UB in this program. For example, on x86_64, ./ccomp -interp prints Time 22: program terminated (exit code = 42).
I understand that this issue is related to Csem.assign_loc_copy for assignment y.u = x.u. Formal semantics requires offset to be aligned on Ctypes.alignof_blockcopy. But the trusted frontend (i.e. C2C) aligns global variables on Ctypes.alignof.
And on IA32 architecture (only), alignof_blockcopy may not divide Ctypes.alignof, even on naturally_aligned types, in particular for Tlong and for Tfloat F64.
Thus, a simple fix, would be to define
Fixpoint alignof_blockcopy (env: composite_env) (t: type) : Z :=
match t with
| Tlong _ _ => Archi.align_int64
| Tfloat F64 _ => Archi.align_float64
| ... => (* same as before *)
end.Metadata
Metadata
Assignees
Labels
No labels