On Mon, Nov 17, 2014 at 05:46:55PM +0000, Joseph Myers wrote: > On Mon, 17 Nov 2014, Jakub Jelinek wrote: > > > > If it is true that a type satisfying TYPE_USER_ALIGN will never be > > > allocated at an address less-aligned than its TYPE_ALIGN, even if that's > > > greater than BIGGEST_ALIGNMENT, then the change seems correct for C11 > > > _Alignof. > > > > I think it depends on which target and where. > > In structs (unless packed) the user aligned fields should be properly > > aligned with respect to start of struct and the struct should have user > > alignment in that case, automatic vars these days use alloca with > > realignment if not handled better by the target, so should be fine too. > > For data section vars and for common vars I think it really depends on the > > target. Perhaps for TYPE_USER_ALIGN use minimum of the TYPE_ALIGN and > > MAX_OFILE_ALIGNMENT ? > > For heap objects, it really depends on how it has been allocated, but if > > allocated through malloc, the extra alignment is never guaranteed. > > So, it really depends in malloc counts or not. > > The question, for both _Alignas and ubsan, is the alignment guaranteed *in > valid programs*. > > malloc only provides sufficient alignment for types with fundamental > alignment requirements (although there are various problems with the C11 > wording; see DR#445). So if you use malloc to allocate a type with an > extended alignment requirement (without doing extra realignment on the > result of malloc), that's not a valid program. And if an alignment is > larger than MAX_OFILE_ALIGNMENT, you get an error for declaring non-stack > variables requiring that alignment. So I don't think there's any need to > check MAX_OFILE_ALIGNMENT here.
If so, then Yuri's original patch (the one changing min_align_of_type) should be fine, right? Jakub