https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88085

--- Comment #15 from rguenther at suse dot de <rguenther at suse dot de> ---
On Thu, 2 Sep 2021, petro.karashchenko at gmail dot com wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88085
> 
> --- Comment #13 from Petro Karashchenko <petro.karashchenko at gmail dot com> 
> ---
> Sorry that I brought some confusion. I was reading some latest comments and
> didn't fully payed attention to a ticket description. The reason for my 
> comment
> is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94662 that was closed as a
> duplicate of this issue.
> 
> For the variable alignment vs type alignment when it is specified your
> statement seems to be correct, however I agree that it still has a lot of open
> points. For example what should be the code if we put variable into a 
> structure
> 
> typedef int __attribute__((vector_size(16))) v4si; 
> 
> struct {
>   v4si a __attribute__((aligned(4)));
> } b;
> 
> Should it still get aligned on 16 bytes or 4 bytes?
> 
> In my case I was seeking for a way to generate alignment tolerant code without
> using
> struct {
>   int a;
> } __attribute__((packed));
> 
> Obviously "int a __attribute__((packed));" does not work, so I tried to solve
> it via "__attribute__((aligned(1)))" attribute.

I don't think it makes much sense to generate alignment "tolerant" code
for declarations, so when it is about indirect accesses via pointers
then simply use a pointer to a type with appropriate alignment.  Then
the access will be "tolerant" but when the compiler sees the object
accessed is actually of bigger alignment it isn't forced to honor
your "tolerant" minimum alignment.

When you're facing the situation that you have to access data at
some symbol and that symbol can end up with alignment less than
what its type specifies then you cannot just do

extern int possibly_misaligned_data __attribute__((aligned(1)));

which seems to be the case kernel folks run into with hppa.  Instead
you have to put the "tolerance" on the type again:

typedef int tolerant_int __attribute__((aligned(1)));
extern tolerant_int possibly_misaligned_data;

Reply via email to