commit 32e6acb39983541ac76e95d44883f05aa9d1c350
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Jul 28 09:07:20 2021 +0200

    Update BASE-VER to 11.2.1
    
    This updates BASE-VER to 11.2.1 after the 11.2 release.
    
    2021-07-28  Richard Biener  <rguenther@suse.de>
    
            * BASE-VER: Set to 11.2.1

diff --git a/gcc/BASE-VER b/gcc/BASE-VER
index b85c6c7b035..dc170a12af1 100644
--- a/gcc/BASE-VER
+++ b/gcc/BASE-VER
@@ -1 +1 @@
-11.2.0
+11.2.1

commit 6d9619f05bed26551ede7a1c781f7921af4aaff8
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jul 23 19:55:16 2021 +0200

    expmed: Fix store_integral_bit_field [PR101562]
    
    Our documentation says that paradoxical subregs shouldn't appear
    in strict_low_part:
    '(strict_low_part (subreg:M (reg:N R) 0))'
         This expression code is used in only one context: as the
         destination operand of a 'set' expression.  In addition, the
         operand of this expression must be a non-paradoxical 'subreg'
         expression.
    but on the testcase below that triggers UB at runtime
    store_integral_bit_field emits exactly that.
    
    The following patch fixes it by ensuring the requirement is satisfied.
    
    2021-07-23  Jakub Jelinek  <jakub@redhat.com>
    
            PR rtl-optimization/101562
            * expmed.c (store_integral_bit_field): Only use movstrict_optab
            if the operand isn't paradoxical.
    
            * gcc.c-torture/compile/pr101562.c: New test.
    
    (cherry picked from commit 8408d34570c9fe9f3d22a25a76df2a4c64f08477)

diff --git a/gcc/expmed.c b/gcc/expmed.c
index 1fb63170be9..3143f38e057 100644
--- a/gcc/expmed.c
+++ b/gcc/expmed.c
@@ -921,7 +921,10 @@ store_integral_bit_field (rtx op0, opt_scalar_int_mode op0_mode,
 	}
 
       subreg_off = bitnum / BITS_PER_UNIT;
-      if (validate_subreg (fieldmode, GET_MODE (arg0), arg0, subreg_off))
+      if (validate_subreg (fieldmode, GET_MODE (arg0), arg0, subreg_off)
+	  /* STRICT_LOW_PART must have a non-paradoxical subreg as
+	     operand.  */
+	  && !paradoxical_subreg_p (fieldmode, GET_MODE (arg0)))
 	{
 	  arg0 = gen_rtx_SUBREG (fieldmode, arg0, subreg_off);
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr101562.c b/gcc/testsuite/gcc.c-torture/compile/pr101562.c
new file mode 100644
index 00000000000..ea4a5f7103a
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr101562.c
@@ -0,0 +1,21 @@
+/* PR rtl-optimization/101562 */
+
+struct S { char c; };
+void baz (struct S a, struct S b);
+
+void
+foo (void)
+{
+  struct S x[1];
+  *(short *)&x[0] = 256;
+  baz (x[0], x[1]);
+}
+
+void
+bar (void)
+{
+  struct S x[1];
+  x[0].c = 0;
+  x[1].c = 1;
+  baz (x[0], x[1]);
+}

commit 117a880acb67e06caf06d83469d64a698927e719
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jul 27 09:59:37 2021 +0200

    gimple-fold: Fix up __builtin_clear_padding on classes with virtual inheritence [PR101586]
    
    For the following testcase, B is 16-byte type, containing 8-byte
    virtual pointer and 1-byte A member, and C contains two FIELD_DECLs,
    one with B type and size of just 8-byte and then a field with type
    A and 1-byte size.
    The __builtin_clear_padding code was upset about the B typed FIELD_DECL
    containing FIELD_DECLs beyond the field size and triggered
    assertion failure.
    This patch makes it ignore all FIELD_DECLs that are (fully) beyond the sz
    passed from the caller (except for the flexible array member
    diagnostics that is kept).
    
    2021-07-27  Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/101586
            * gimple-fold.c (clear_padding_type): Ignore FIELD_DECLs with byte
            positions above or equal to sz except for diagnostics of flexible
            array members.
    
            * g++.dg/torture/builtin-clear-padding-4.C: New test.
    
    (cherry picked from commit a21bd3cebd6f54af70a37c18b8fbeae933fb6515)

diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 6079f88163f..0581338ea5f 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -4502,6 +4502,8 @@ clear_padding_type (clear_padding_struct *buf, tree type, HOST_WIDE_INT sz)
 		if (fldsz == 0)
 		  continue;
 		HOST_WIDE_INT pos = int_byte_position (field);
+		if (pos >= sz)
+		  continue;
 		HOST_WIDE_INT bpos
 		  = tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field));
 		bpos %= BITS_PER_UNIT;
@@ -4577,6 +4579,8 @@ clear_padding_type (clear_padding_struct *buf, tree type, HOST_WIDE_INT sz)
 	    else
 	      {
 		HOST_WIDE_INT pos = int_byte_position (field);
+		if (pos >= sz)
+		  continue;
 		HOST_WIDE_INT fldsz = tree_to_shwi (DECL_SIZE_UNIT (field));
 		gcc_assert (pos >= 0 && fldsz >= 0 && pos >= cur_pos);
 		clear_padding_add_padding (buf, pos - cur_pos);
diff --git a/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C
new file mode 100644
index 00000000000..5936cdf876b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/builtin-clear-padding-4.C
@@ -0,0 +1,44 @@
+// PR middle-end/101586
+
+struct A { char a; };
+struct B : virtual A {};
+struct C : B {};
+struct D : virtual A, C {};
+
+__attribute__((noipa)) A *
+baz (C *p, D *q)
+{
+  if (p)
+    return dynamic_cast <A *> (p);
+  else
+    return dynamic_cast <A *> (q);
+}
+
+void
+foo ()
+{ 
+  C c;
+  c.a = 42;
+  __builtin_clear_padding (&c);
+  A *p = baz (&c, 0);
+  if (c.a != 42 || p->a != 42)
+    __builtin_abort ();
+}
+
+void
+bar ()
+{
+  D d;
+  d.a = 42;
+  __builtin_clear_padding (&d);
+  A *p = baz (0, &d);
+  if (d.a != 42 || p->a != 42)
+    __builtin_abort ();
+}
+
+int
+main ()
+{
+  foo ();
+  bar ();
+}
