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

            Bug ID: 79918
           Summary: Feature request: Warning about (may potential)
                    misaligned address-reference
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: meisenmann....@fh-salzburg.ac.at
  Target Milestone: ---
            Target: arm-none-eabi

Hi!

I'm currently working on porting code (from x86) to ARM-targets and detecting
(potential) "alignment-problems". By using the option '-Wcast-align', I'm able
determine some "problematic" implementations, but I haven't found an
warning-option to detect another issue: I.e., getting a (misaligned)
address-reference, if referencing a misaligned struct-member.

--- Begin: Test-Code ---
extern void foo(double* p);

struct __attribute__((packed)) una_t
{
        char    data[2];
        double  value;
};

void    Test1(char* p)
{
        foo((double*)p);
}

void    Test2(struct una_t* p)
{
        foo(&p->value);
}
--- End of Code ---

I think (IMHO), it should be possible to detect &p->value in Test2() as risk;
similar as the pointer-cast in Test1(), but based on referencing an unaligned
member of a struct-typ.

Perhaps, a corresponding warning-option could be introduced in a future release
...

Best regards from Salzburg,
Markus

Reply via email to