[llvm-commits] [127801] When an LLVM type has struct padding that overlaps with important fields of
Duncan Sands
baldrick at free.fr
Fri Jun 1 04:58:03 PDT 2007
> > Hi Chris, this breaks the Ada build since the TYPE_SIZE may not be
> > a constant:
> >
> >> + if (TYPE_SIZE(type) == 0 ||
> >> + PadStartBits >= int(TREE_INT_CST_LOW(TYPE_SIZE(type))) ||
> >
> > I've attached a fix, which includes some other tweaks for arrays
> > (not very important) plus whitespace cleanup.
>
> Does this actually cause a problem? This function is only called if
> the outer struct has constant size. TreeToLLVM::EmitAggregateCopy
> checks that TREE_CODE(TYPE_SIZE(type)) == INTEGER_CST is true before
> calling into this code.
Yes, it crashes the compiler. Remember that the function is recursive.
The problem is that a type of fixed size can have a field of variable size.
For example, a record field which is a variable sized array, where the length
is given by another field L in the record. In this case the size of the record
type may be a constant equal to the maximum size obtained over all possible
values of L.
In the case in question, a record R contains a field F, which is also
a record type. The fields present in F depend on the value of field E
(of an enumeration type) in R. Yes this is possible! The size of F
is thus an expression: it is calculated in terms of the value of E.
The size of R is a constant: the maximum possible size, the maximum
being taken over all values of E.
Ciao,
Duncan.
More information about the llvm-commits
mailing list