When address of packed member of struct or union is taken, it may result
in an unaligned pointer value.  This patch adds -Waddress-of-packed-member
to warn it:

$ cat x.i
struct pair_t
{
  char c;
  int i;
} __attribute__ ((packed));

extern struct pair_t p;
int *addr = &p.i;
$ gcc -O2 -S x.i
x.i:8:13: warning: initialization of 'int *' from address of packed member of 
'struct pair_t' may result in an unaligned pointer value 
[-Waddress-of-packed-member]
 int *addr = &p.i;
             ^
$

This warning is enabled by default.

Tested on i686 and x86-64.  OK for trunk?

H.J.
---
gcc/c/

        PR c/51628
        * doc/invoke.texi: Document -Wno-address-of-packed-member.

gcc/c-family/

        PR c/51628
        * c-common.h (warn_for_address_of_packed_member): New.
        * c-warn.c (warn_for_address_of_packed_member): New function.
        * c.opt: Add -Wno-address-of-packed-member.

gcc/c/

        PR c/51628
        * c-typeck.c (convert_for_assignment): Call
        warn_for_address_of_packed_member.  Issue an warning if address
        of packed member is taken.

gcc/cp/

        PR c/51628
        * call.c (convert_for_arg_passing): Call
        warn_for_address_of_packed_member.  Issue an warning if address
        of packed member is taken.
        * typeck.c (convert_for_assignment): Likewise.

gcc/testsuite/

        PR c/51628
        * c-c++-common/pr51628-1.c: New tests.
        * c-c++-common/pr51628-2.c: Likewise.
        * c-c++-common/pr51628-3.c: Likewise.
        * c-c++-common/pr51628-4.c: Likewise.
        * c-c++-common/pr51628-5.c: Likewise.
        * c-c++-common/pr51628-6.c: Likewise.
        * c-c++-common/ubsan/align-2.c: Add -Wno-address-of-packed-member.
        * c-c++-common/ubsan/align-4.c: Likewise.
        * c-c++-common/ubsan/align-6.c: Likewise.
        * c-c++-common/ubsan/align-7.c: Likewise.
        * c-c++-common/ubsan/align-8.c: Likewise.
        * g++.dg/ubsan/align-2.C: Likewise.
---
 gcc/c-family/c-common.h                    |  1 +
 gcc/c-family/c-warn.c                      | 38 +++++++++++++++++++++++++++
 gcc/c-family/c.opt                         |  4 +++
 gcc/c/c-typeck.c                           | 40 ++++++++++++++++++++++++++++-
 gcc/cp/call.c                              |  8 ++++++
 gcc/cp/typeck.c                            | 41 ++++++++++++++++++++++++++++++
 gcc/doc/invoke.texi                        | 11 ++++++--
 gcc/testsuite/c-c++-common/pr51628-1.c     | 29 +++++++++++++++++++++
 gcc/testsuite/c-c++-common/pr51628-2.c     | 29 +++++++++++++++++++++
 gcc/testsuite/c-c++-common/pr51628-3.c     | 35 +++++++++++++++++++++++++
 gcc/testsuite/c-c++-common/pr51628-4.c     | 35 +++++++++++++++++++++++++
 gcc/testsuite/c-c++-common/pr51628-5.c     | 35 +++++++++++++++++++++++++
 gcc/testsuite/c-c++-common/pr51628-6.c     | 35 +++++++++++++++++++++++++
 gcc/testsuite/c-c++-common/ubsan/align-2.c |  2 +-
 gcc/testsuite/c-c++-common/ubsan/align-4.c |  2 +-
 gcc/testsuite/c-c++-common/ubsan/align-6.c |  2 +-
 gcc/testsuite/c-c++-common/ubsan/align-7.c |  2 +-
 gcc/testsuite/c-c++-common/ubsan/align-8.c |  2 +-
 gcc/testsuite/g++.dg/ubsan/align-2.C       |  2 +-
 19 files changed, 344 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/pr51628-1.c
 create mode 100644 gcc/testsuite/c-c++-common/pr51628-2.c
 create mode 100644 gcc/testsuite/c-c++-common/pr51628-3.c
 create mode 100644 gcc/testsuite/c-c++-common/pr51628-4.c
 create mode 100644 gcc/testsuite/c-c++-common/pr51628-5.c
 create mode 100644 gcc/testsuite/c-c++-common/pr51628-6.c

diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index d090881e95d..ef31e4d0aa2 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -1384,6 +1384,7 @@ extern void c_do_switch_warnings (splay_tree, location_t, 
tree, tree, bool,
                                  bool);
 extern void warn_for_omitted_condop (location_t, tree);
 extern void warn_for_restrict (unsigned, tree *, unsigned);
+extern tree warn_for_address_of_packed_member (tree type, tree rhs);
 
 /* Places where an lvalue, or modifiable lvalue, may be required.
    Used to select diagnostic messages in lvalue_error and
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 7d87c455ec0..ac0a2ffcb42 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -2576,3 +2576,41 @@ warn_for_multistatement_macros (location_t body_loc, 
location_t next_loc,
     inform (guard_loc, "some parts of macro expansion are not guarded by "
            "this %qs clause", guard_tinfo_to_string (keyword));
 }
+
+/* Return struct or union type if the right hand type, RHS, is the
+   address of packed member of struct or union when assigning to TYPE.
+   Otherwise, return NULL_TREE.  */
+
+tree
+warn_for_address_of_packed_member (tree type, tree rhs)
+{
+  if (!warn_address_of_packed_member)
+    return NULL_TREE;
+
+  if (TREE_CODE (rhs) == ADDR_EXPR && POINTER_TYPE_P (type))
+    {
+      tree base = TREE_OPERAND (rhs, 0);
+      if (TREE_CODE (base) == COMPONENT_REF)
+       {
+         tree field = TREE_OPERAND (base, 1);
+         if (TREE_CODE (field) == FIELD_DECL && DECL_PACKED (field))
+           {
+             tree field_type = TREE_TYPE (field);
+             unsigned int type_align = TYPE_ALIGN (field_type);
+             tree context = DECL_CONTEXT (field);
+             unsigned int record_align = TYPE_ALIGN (context);
+             if ((record_align % type_align) != 0)
+               return context;
+             type_align /= BITS_PER_UNIT;
+             unsigned HOST_WIDE_INT field_off
+                = (tree_to_uhwi (DECL_FIELD_OFFSET (field))
+                   + (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
+                      / BITS_PER_UNIT));
+             if ((field_off % type_align) != 0)
+               return context;
+           }
+       }
+    }
+
+  return NULL_TREE;
+}
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 16a515afd55..686d52a2055 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -599,6 +599,10 @@ Wincompatible-pointer-types
 C ObjC Var(warn_incompatible_pointer_types) Init(1) Warning
 Warn when there is a conversion between pointers that have incompatible types.
 
+Waddress-of-packed-member
+C ObjC C++ ObjC++ Var(warn_address_of_packed_member) Init(1) Warning
+Warn when the address of packed member of struct or union is taken.
+
 Winit-self
 C ObjC C++ ObjC++ Var(warn_init_self) Warning LangEnabledBy(C++ ObjC++,Wall)
 Warn about variables which are initialized to themselves.
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index e22bc740bca..8e31d6cc5fd 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -6495,7 +6495,45 @@ convert_for_assignment (location_t location, location_t 
expr_loc, tree type,
     }
 
   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
-    return rhs;
+    {
+      tree context = warn_for_address_of_packed_member (type, orig_rhs);
+      if (context)
+       switch (errtype)
+         {
+         case ic_argpass:
+           warning_at (expr_loc, OPT_Waddress_of_packed_member,
+                       "passing argument %d %qT of %qE from address "
+                       "of packed member of %qT may result in an "
+                       "unaligned pointer value",
+                       parmnum, type, rname, context);
+           break;
+         case ic_assign:
+           warning_at (location, OPT_Waddress_of_packed_member,
+                       "assignment to %qT from address of packed "
+                       "member of %qT may result in an unaligned "
+                       "pointer value",
+                       type, context);
+           break;
+         case ic_init:
+           warning_at (location, OPT_Waddress_of_packed_member,
+                       "initialization of %qT from address of packed "
+                       "member of %qT may result in an unaligned "
+                       "pointer value",
+                       type, context);
+           break;
+         case ic_return:
+           warning_at (location, OPT_Waddress_of_packed_member,
+                       "returning address of packed member of %qT "
+                       "from a function with return type %qT may "
+                       "result in an unaligned pointer value",
+                       context, type);
+           break;
+         default:
+           gcc_unreachable ();
+         }
+
+      return rhs;
+    }
 
   if (coder == VOID_TYPE)
     {
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index f5542850cea..8672ab0d58c 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7416,6 +7416,14 @@ convert_for_arg_passing (tree type, tree val, 
tsubst_flags_t complain)
        }
       maybe_warn_parm_abi (type, EXPR_LOC_OR_LOC (val, input_location));
     }
+
+  tree context = warn_for_address_of_packed_member (type, val);
+  if (context)
+    warning (OPT_Waddress_of_packed_member,
+            "passing argument of type %qT from address of member of "
+            "packed %qT may result in an unaligned pointer value",
+            type, context);
+
   return val;
 }
 
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index f0dc03de111..1199c27d2f0 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8887,6 +8887,47 @@ convert_for_assignment (tree type, tree rhs,
       TREE_NO_WARNING (rhs) = 1;
     }
 
+  tree context = warn_for_address_of_packed_member (type, rhs);
+  if (context)
+    switch (errtype)
+      {
+      case ICR_ARGPASS:
+      case ICR_DEFAULT_ARGUMENT:
+       warning (OPT_Waddress_of_packed_member,
+                "passing argument %d %qT of %qD from address of "
+                "packed member of %qT may result in an unaligned "
+                "pointer value",
+                parmnum, type, fndecl, context);
+       break;
+      case ICR_CONVERTING:
+       warning (OPT_Waddress_of_packed_member,
+                "converting to %qT from address of packed member of "
+                "%qT may result in an unaligned pointer value",
+                type, context);
+       break;
+      case ICR_ASSIGN:
+       warning (OPT_Waddress_of_packed_member,
+                "assignment to %qT from address of packed member of "
+                "%qT may result in an unaligned pointer value",
+                type, context);
+       break;
+      case ICR_INIT:
+       warning (OPT_Waddress_of_packed_member,
+                "initialization of %qT from address of packed member "
+                "of %qT may result in an unaligned pointer value",
+                type, context);
+       break;
+      case ICR_RETURN:
+       warning (OPT_Waddress_of_packed_member,
+                "returning address of packed member of %qT from a "
+                "function with return type %qT may result in an "
+                "unaligned pointer value",
+                context, type);
+       break;
+      default:
+       gcc_unreachable ();
+      }
+
   return perform_implicit_conversion_flags (strip_top_quals (type), rhs,
                                            complain, flags);
 }
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 28c61a078d2..13fd0abca3a 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -259,8 +259,8 @@ Objective-C and Objective-C++ Dialects}.
 @xref{Warning Options,,Options to Request or Suppress Warnings}.
 @gccoptlist{-fsyntax-only  -fmax-errors=@var{n}  -Wpedantic @gol
 -pedantic-errors @gol
--w  -Wextra  -Wall  -Waddress  -Waggregate-return  @gol
--Walloc-zero  -Walloc-size-larger-than=@var{n}
+-w  -Wextra  -Wall  -Waddress -Waddress-of-packed-member @gol
+-Waggregate-return -Walloc-zero -Walloc-size-larger-than=@var{n} @gol
 -Walloca  -Walloca-larger-than=@var{n} @gol
 -Wno-aggressive-loop-optimizations  -Warray-bounds  -Warray-bounds=@var{n} @gol
 -Wno-attributes  -Wbool-compare  -Wbool-operation @gol
@@ -6374,6 +6374,13 @@ behavior and are not portable in C, so they usually 
indicate that the
 programmer intended to use @code{strcmp}.  This warning is enabled by
 @option{-Wall}.
 
+@item -Waddress-of-packed-member
+@opindex Waddress-of-packed-member
+@opindex Wno-address-of-packed-member
+Warn when the address of packed member of struct or union is taken,
+which usually results in an unaligned pointer value.  This is
+enabled by default.
+
 @item -Wlogical-op
 @opindex Wlogical-op
 @opindex Wno-logical-op
diff --git a/gcc/testsuite/c-c++-common/pr51628-1.c 
b/gcc/testsuite/c-c++-common/pr51628-1.c
new file mode 100644
index 00000000000..5324f9cc964
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr51628-1.c
@@ -0,0 +1,29 @@
+/* PR c/51628.  */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct pair_t
+{
+  int x;
+  int i;
+} __attribute__((packed, aligned (4)));
+
+extern struct pair_t p;
+extern int *x;
+extern void bar (int *);
+
+int *addr = &p.i;
+
+int *
+foo (void)
+{
+  struct pair_t arr[2] = { { 1, 10 }, { 2, 20 } };
+  int *p0, *p1;
+  p0 = &arr[0].i;
+  bar (p0);
+  p1 = &arr[1].i;
+  bar (p1);
+  bar (&p.i);
+  x = &p.i;
+  return &p.i;
+}
diff --git a/gcc/testsuite/c-c++-common/pr51628-2.c 
b/gcc/testsuite/c-c++-common/pr51628-2.c
new file mode 100644
index 00000000000..abfb84ddd05
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr51628-2.c
@@ -0,0 +1,29 @@
+/* PR c/51628.  */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct pair_t
+{
+  int x;
+  int i;
+} __attribute__((packed, aligned (8)));
+
+extern struct pair_t p;
+extern int *x;
+extern void bar (int *);
+
+int *addr = &p.i;
+
+int *
+foo (void)
+{
+  struct pair_t arr[2] = { { 1, 10 }, { 2, 20 } };
+  int *p0, *p1;
+  p0 = &arr[0].i;
+  bar (p0);
+  p1 = &arr[1].i;
+  bar (p1);
+  bar (&p.i);
+  x = &p.i;
+  return &p.i;
+}
diff --git a/gcc/testsuite/c-c++-common/pr51628-3.c 
b/gcc/testsuite/c-c++-common/pr51628-3.c
new file mode 100644
index 00000000000..0ea94c845a0
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr51628-3.c
@@ -0,0 +1,35 @@
+/* PR c/51628.  */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct pair_t
+{
+  int x;
+  int i;
+} __attribute__((packed, aligned (2)));
+
+extern struct pair_t p;
+extern int *x;
+extern void bar (int *);
+
+int *addr = &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+
+int *
+foo (void)
+{
+  struct pair_t arr[2] = { { 1, 10 }, { 2, 20 } };
+  int *p0, *p1;
+  p0 = &arr[0].i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  bar (p0);
+  p1 = &arr[1].i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  bar (p1);
+  bar (&p.i);
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  x = &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  return &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+}
diff --git a/gcc/testsuite/c-c++-common/pr51628-4.c 
b/gcc/testsuite/c-c++-common/pr51628-4.c
new file mode 100644
index 00000000000..c4c1fb72d6d
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr51628-4.c
@@ -0,0 +1,35 @@
+/* PR c/51628.  */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct pair_t
+{
+  int x;
+  int i;
+} __attribute__((packed));
+
+extern struct pair_t p;
+extern int *x;
+extern void bar (int *);
+
+int *addr = &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+
+int *
+foo (void)
+{
+  struct pair_t arr[2] = { { 1, 10 }, { 2, 20 } };
+  int *p0, *p1;
+  p0 = &arr[0].i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  bar (p0);
+  p1 = &arr[1].i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  bar (p1);
+  bar (&p.i);
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  x = &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  return &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+}
diff --git a/gcc/testsuite/c-c++-common/pr51628-5.c 
b/gcc/testsuite/c-c++-common/pr51628-5.c
new file mode 100644
index 00000000000..9d7c309a0ef
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr51628-5.c
@@ -0,0 +1,35 @@
+/* PR c/51628.  */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct pair_t
+{
+  char x;
+  int i;
+} __attribute__((packed));
+
+extern struct pair_t p;
+extern int *x;
+extern void bar (int *);
+
+int *addr = &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+
+int *
+foo (void)
+{
+  struct pair_t arr[2] = { { 1, 10 }, { 2, 20 } };
+  int *p0, *p1;
+  p0 = &arr[0].i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  bar (p0);
+  p1 = &arr[1].i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  bar (p1);
+  bar (&p.i);
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  x = &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  return &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+}
diff --git a/gcc/testsuite/c-c++-common/pr51628-6.c 
b/gcc/testsuite/c-c++-common/pr51628-6.c
new file mode 100644
index 00000000000..52aa07a4cf3
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr51628-6.c
@@ -0,0 +1,35 @@
+/* PR c/51628.  */
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct pair_t
+{
+  char x;
+  int i;
+} __attribute__((packed, aligned (4)));
+
+extern struct pair_t p;
+extern int *x;
+extern void bar (int *);
+
+int *addr = &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+
+int *
+foo (void)
+{
+  struct pair_t arr[2] = { { 1, 10 }, { 2, 20 } };
+  int *p0, *p1;
+  p0 = &arr[0].i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  bar (p0);
+  p1 = &arr[1].i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  bar (p1);
+  bar (&p.i);
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  x = &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+  return &p.i;
+/* { dg-warning "may result in an unaligned pointer value" "" { target *-*-* } 
.-1 } */
+}
diff --git a/gcc/testsuite/c-c++-common/ubsan/align-2.c 
b/gcc/testsuite/c-c++-common/ubsan/align-2.c
index 071de8c202a..336b1c3c907 100644
--- a/gcc/testsuite/c-c++-common/ubsan/align-2.c
+++ b/gcc/testsuite/c-c++-common/ubsan/align-2.c
@@ -1,6 +1,6 @@
 /* Limit this to known non-strict alignment targets.  */
 /* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
-/* { dg-options "-fsanitize=alignment" } */
+/* { dg-options "-fsanitize=alignment -Wno-address-of-packed-member" } */
 
 struct S { int a; char b; long long c; short d[10]; };
 struct T { char a; long long b; };
diff --git a/gcc/testsuite/c-c++-common/ubsan/align-4.c 
b/gcc/testsuite/c-c++-common/ubsan/align-4.c
index 3252595d330..d5feeee29c6 100644
--- a/gcc/testsuite/c-c++-common/ubsan/align-4.c
+++ b/gcc/testsuite/c-c++-common/ubsan/align-4.c
@@ -1,6 +1,6 @@
 /* Limit this to known non-strict alignment targets.  */
 /* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
-/* { dg-options "-fsanitize=null,alignment" } */
+/* { dg-options "-fsanitize=null,alignment -Wno-address-of-packed-member" } */
 
 #include "align-2.c"
 
diff --git a/gcc/testsuite/c-c++-common/ubsan/align-6.c 
b/gcc/testsuite/c-c++-common/ubsan/align-6.c
index 3364746fb27..0302b7b8894 100644
--- a/gcc/testsuite/c-c++-common/ubsan/align-6.c
+++ b/gcc/testsuite/c-c++-common/ubsan/align-6.c
@@ -1,6 +1,6 @@
 /* Limit this to known non-strict alignment targets.  */
 /* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
-/* { dg-options "-O -fsanitize=alignment -fsanitize-recover=alignment" } */
+/* { dg-options "-O -fsanitize=alignment -fsanitize-recover=alignment 
-Wno-address-of-packed-member" } */
 
 struct S { int a; char b; long long c; short d[10]; };
 struct T { char a; long long b; };
diff --git a/gcc/testsuite/c-c++-common/ubsan/align-7.c 
b/gcc/testsuite/c-c++-common/ubsan/align-7.c
index ec4e87f56d5..dd1e8c91cef 100644
--- a/gcc/testsuite/c-c++-common/ubsan/align-7.c
+++ b/gcc/testsuite/c-c++-common/ubsan/align-7.c
@@ -1,6 +1,6 @@
 /* Limit this to known non-strict alignment targets.  */
 /* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
-/* { dg-options "-O -fsanitize=alignment -fno-sanitize-recover=alignment 
-fdump-tree-sanopt-details" } */
+/* { dg-options "-O -fsanitize=alignment -fno-sanitize-recover=alignment 
-Wno-address-of-packed-member -fdump-tree-sanopt-details" } */
 /* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */
 /* { dg-shouldfail "ubsan" } */
 
diff --git a/gcc/testsuite/c-c++-common/ubsan/align-8.c 
b/gcc/testsuite/c-c++-common/ubsan/align-8.c
index 61c1ceb6682..5fe0e0fe931 100644
--- a/gcc/testsuite/c-c++-common/ubsan/align-8.c
+++ b/gcc/testsuite/c-c++-common/ubsan/align-8.c
@@ -1,6 +1,6 @@
 /* Limit this to known non-strict alignment targets.  */
 /* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
-/* { dg-options "-O -fsanitize=alignment -fsanitize-undefined-trap-on-error 
-fdump-tree-sanopt-details" } */
+/* { dg-options "-O -fsanitize=alignment -fsanitize-undefined-trap-on-error 
-Wno-address-of-packed-member -fdump-tree-sanopt-details" } */
 /* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */
 /* { dg-shouldfail "ubsan" } */
 
diff --git a/gcc/testsuite/g++.dg/ubsan/align-2.C 
b/gcc/testsuite/g++.dg/ubsan/align-2.C
index 3e4f5485d02..c97ede88392 100644
--- a/gcc/testsuite/g++.dg/ubsan/align-2.C
+++ b/gcc/testsuite/g++.dg/ubsan/align-2.C
@@ -1,6 +1,6 @@
 // Limit this to known non-strict alignment targets.
 // { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } }
-// { dg-options "-fsanitize=alignment -Wall -Wno-unused-variable -std=c++11" }
+// { dg-options "-fsanitize=alignment -Wall -Wno-unused-variable 
-Wno-address-of-packed-member -std=c++11" }
 
 typedef const long int L;
 struct S { long int l; char buf[1 + sizeof (int) + sizeof (L)]; } s;
-- 
2.14.3

Reply via email to