Backports to 8.4

Message ID 20200214171509.GR17695@tucnak
State New
Headers show
Series
  • Backports to 8.4
Related show

Commit Message

Jakub Jelinek Feb. 14, 2020, 5:15 p.m.
Hi!

I've backported following 42 commits from 9 branch (the last one from
trunk), bootstrapped/regtested on x86_64-linux and i686-linux and committed
to 8.4.

	Jakub
From 54d87ffe4b34052f159ac5b72b250129ce813b2a Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:33:27 +0100
Subject: [PATCH] backport: re PR sanitizer/92154 (new glibc breaks arm
 bootstrap due to libsanitizer)

	Backported from mainline
	2019-10-22  Tamar Christina  <tamar.christina@arm.com>

	PR sanitizer/92154
	* sanitizer_common/sanitizer_platform_limits_posix.cc:
	Cherry-pick compiler-rt revision r375220.
---
 libsanitizer/ChangeLog                                   | 9 +++++++++
 .../sanitizer_common/sanitizer_platform_limits_posix.cc  | 6 +++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

-- 
2.20.1
From 56728b264c1b0d9f193aa5e8b1702a1cd7a08868 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:34:46 +0100
Subject: [PATCH] backport: re PR c++/90842 (ICE in poplevel, at cp/decl.c:585)

	Backported from mainline
	2019-11-21  Jakub Jelinek  <jakub@redhat.com>
		    Jason Merrill  <jason@redhat.com>

	PR c++/90842
	* parser.c (cp_parser_decl_specifier_seq): For concept or typedef
	break early if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR.
	For type specifiers, set CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
	if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR is set.

	* g++.dg/cpp1y/lambda-generic-90842.C: New test.
---
 gcc/cp/ChangeLog                                  | 12 ++++++++++++
 gcc/cp/parser.c                                   | 11 +++++++++++
 gcc/testsuite/ChangeLog                           |  8 ++++++++
 gcc/testsuite/g++.dg/cpp1y/lambda-generic-90842.C |  7 +++++++
 4 files changed, 38 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/lambda-generic-90842.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f9b02d0309b..b1cc9db5383 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,15 @@
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2019-11-21  Jakub Jelinek  <jakub@redhat.com>
+		    Jason Merrill  <jason@redhat.com>
+
+	PR c++/90842
+	* parser.c (cp_parser_decl_specifier_seq): For concept or typedef
+	break early if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR.
+	For type specifiers, set CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
+	if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR is set.
+
 2020-01-27  Nathan Sidwell  <nathan@acm.org>
 
 	PR c++/91826
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index d17a212a18f..f523c87a9ae 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -13552,6 +13552,10 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
         case RID_CONCEPT:
           ds = ds_concept;
           cp_lexer_consume_token (parser->lexer);
+
+	  if (flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR)
+	    break;
+
 	  /* In C++20 a concept definition is just 'concept name = expr;'
 	     Support that syntax by pretending we've seen 'bool'.  */
 	  if (cp_lexer_next_token_is (parser->lexer, CPP_NAME)
@@ -13579,6 +13583,10 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
 	  ds = ds_typedef;
 	  /* Consume the token.  */
 	  cp_lexer_consume_token (parser->lexer);
+
+	  if (flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR)
+	    break;
+
 	  /* A constructor declarator cannot appear in a typedef.  */
 	  constructor_possible_p = false;
 	  /* The "typedef" keyword can only occur in a declaration; we
@@ -13673,6 +13681,9 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
 	  bool is_cv_qualifier;
 	  tree type_spec;
 
+	  if (flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR)
+	    flags |= CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS;
+
 	  type_spec
 	    = cp_parser_type_specifier (parser, flags,
 					decl_specs,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index edc91bf9f2a..534b907d8b6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2019-11-21  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/90842
+	* g++.dg/cpp1y/lambda-generic-90842.C: New test.
+
 2020-01-20  Richard Biener  <rguenther@suse.de>
 
 	Backport from mainline
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-90842.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-90842.C
new file mode 100644
index 00000000000..433c9c2030e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-90842.C
@@ -0,0 +1,7 @@
+// PR c++/90842
+// { dg-do compile { target c++14 } }
+
+auto a = [](auto x) struct C { void foo (); } {};	// { dg-error "expected" }
+							// { dg-error "type-specifier invalid in lambda" "" { xfail *-*-* } .-1 }
+auto b = [](auto x) mutable typedef {};			// { dg-error "'typedef' invalid in lambda" }
+auto d = [](auto x) mutable friend {};			// { dg-error "'friend' invalid in lambda" }
-- 
2.20.1
From ef7d101ee0eb663c078cfc018db164387e97cc02 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:37:40 +0100
Subject: [PATCH] backport: re PR inline-asm/92615 (ICE in extract_insn)

	Backported from mainline
	2019-11-23  Jakub Jelinek  <jakub@redhat.com>

	PR target/92615
	* config/i386/i386.c (ix86_md_asm_adjust): If dest_mode is
	GET_MODE (dest), is not QImode, using ZERO_EXTEND and dest is not
	register_operand, force x into register before storing it into dest.
	Formatting fix.

	* gcc.target/i386/pr92615.c: New test.
---
 gcc/ChangeLog                           | 11 ++++++
 gcc/config/i386/i386.c                  | 10 ++++--
 gcc/testsuite/ChangeLog                 |  5 +++
 gcc/testsuite/gcc.target/i386/pr92615.c | 45 +++++++++++++++++++++++++
 4 files changed, 68 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr92615.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 808f78037b4..77b372010a4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2019-11-23  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/92615
+	* config/i386/i386.c (ix86_md_asm_adjust): If dest_mode is
+	GET_MODE (dest), is not QImode, using ZERO_EXTEND and dest is not
+	register_operand, force x into register before storing it into dest.
+	Formatting fix.
+
 2020-02-14  Richard Biener  <rguenther@suse.de>
 
 	Backport from mainline
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index f156f7e66a4..29c558489b8 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -44774,11 +44774,15 @@ ix86_md_asm_adjust (vec<rtx> &outputs, vec<rtx> &/*inputs*/,
 	    {
 	      x = force_reg (dest_mode, const0_rtx);
 
-	      emit_insn (gen_movstrictqi
-			 (gen_lowpart (QImode, x), destqi));
+	      emit_insn (gen_movstrictqi (gen_lowpart (QImode, x), destqi));
 	    }
 	  else
-	    x = gen_rtx_ZERO_EXTEND (dest_mode, destqi);
+	    {
+	      x = gen_rtx_ZERO_EXTEND (dest_mode, destqi);
+	      if (dest_mode == GET_MODE (dest)
+		  && !register_operand (dest, GET_MODE (dest)))
+		x = force_reg (dest_mode, x);
+	    }
 	}
 
       if (dest_mode != GET_MODE (dest))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 534b907d8b6..2b13ab518b7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-11-23  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/92615
+	* gcc.target/i386/pr92615.c: New test.
+
 	2019-11-21  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/90842
diff --git a/gcc/testsuite/gcc.target/i386/pr92615.c b/gcc/testsuite/gcc.target/i386/pr92615.c
new file mode 100644
index 00000000000..b84bfcdabbe
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr92615.c
@@ -0,0 +1,45 @@
+/* PR target/92615 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void *a;
+long long b;
+char c;
+
+void
+foo (void)
+{
+  void *p;
+  long long q;
+  char r;
+  __asm__ ("" : : "r" (&p), "r" (&q), "r" (&r));
+  __asm__ ("" : "=@cca" (p));
+  a = p;
+  __asm__ ("" : "=@cca" (q));
+  b = q;
+  __asm__ ("" : "=@cca" (r));
+  c = r;
+  __asm__ ("" : : "r" (&p), "r" (&q), "r" (&r));
+}
+
+void
+bar (void)
+{
+  void *p;
+  long long q;
+  char r;
+  __asm__ ("" : "=@cca" (p));
+  a = p;
+  __asm__ ("" : "=@cca" (q));
+  b = q;
+  __asm__ ("" : "=@cca" (r));
+  c = r;
+  __asm__ ("" : : "r" (p), "A" (q), "q" (r));
+}
+
+void
+baz (void)
+{
+  void *p = (void *) &p;
+  __asm__ __volatile__ ("" : "=@ccng" (p) : "r" (1));
+}
-- 
2.20.1
From dbdf86838aaaef76620c00c53096cfe157d5af6e Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:38:30 +0100
Subject: [PATCH] backport: re PR sanitizer/92154 (new glibc breaks arm
 bootstrap due to libsanitizer)

	Backported from mainline
	2019-11-26  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/92154
	* sanitizer_common/sanitizer_platform_limits_posix.h: Cherry-pick
	llvm-project revision 947f9692440836dcb8d88b74b69dd379d85974ce.
	* sanitizer_common/sanitizer_platform_limits_posix.cc: Likewise.
---
 libsanitizer/ChangeLog                            |  7 +++++++
 .../sanitizer_platform_limits_posix.cc            |  9 +++------
 .../sanitizer_platform_limits_posix.h             | 15 +--------------
 3 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/libsanitizer/ChangeLog b/libsanitizer/ChangeLog
index 70056ab8aec..df0c9449136 100644
--- a/libsanitizer/ChangeLog
+++ b/libsanitizer/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR sanitizer/92154
+	* sanitizer_common/sanitizer_platform_limits_posix.h: Cherry-pick
+	llvm-project revision 947f9692440836dcb8d88b74b69dd379d85974ce.
+	* sanitizer_common/sanitizer_platform_limits_posix.cc: Likewise.
+
 	2019-10-22  Tamar Christina  <tamar.christina@arm.com>
 
 	PR sanitizer/92154
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
index e85aaf51928..5c720b2e700 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -1147,12 +1147,9 @@ CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
-#if (!defined(__aarch64__) || !SANITIZER_LINUX || __GLIBC_PREREQ (2, 21)) && \
-    !defined(__arm__)
-/* On aarch64 glibc 2.20 and earlier provided incorrect mode field.  */
-/* On Arm glibc 2.31 and later provide a different mode field, this field is
-   never used by libsanitizer so we can simply ignore this assert for all glibc
-   versions.  */
+#if !SANITIZER_LINUX || __GLIBC_PREREQ (2, 31)
+/* glibc 2.30 and earlier provided 16-bit mode field instead of 32-bit
+   on many architectures.  */
 CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
 #endif
 
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
index 4d11d071776..9c1429623ab 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -210,26 +210,13 @@ namespace __sanitizer {
     u64 __unused1;
     u64 __unused2;
 #elif defined(__sparc__)
-#if defined(__arch64__)
     unsigned mode;
-    unsigned short __pad1;
-#else
-    unsigned short __pad1;
-    unsigned short mode;
     unsigned short __pad2;
-#endif
     unsigned short __seq;
     unsigned long long __unused1;
     unsigned long long __unused2;
-#elif defined(__mips__) || defined(__aarch64__) || defined(__s390x__)
-    unsigned int mode;
-    unsigned short __seq;
-    unsigned short __pad1;
-    unsigned long __unused1;
-    unsigned long __unused2;
 #else
-    unsigned short mode;
-    unsigned short __pad1;
+    unsigned int mode;
     unsigned short __seq;
     unsigned short __pad2;
 #if defined(__x86_64__) && !defined(_LP64)
-- 
2.20.1
From 22a7fa8517063c76b069d2b08dca5a9d270798f8 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:45:30 +0100
Subject: [PATCH] backport: re PR c++/61414 (enum class bitfield size-checking
 needs a separate warning flag controlling it)

	Backported from mainline
	2019-11-26  Jakub Jelinek  <jakub@redhat.com>

	PR c++/61414
	* c-attribs.c (handle_mode_attribute): Add mode attribute to
	ENUMERAL_TYPEs.

	* class.c (enum_to_min_precision): New hash_map.
	(enum_min_precision): New function.
	(check_bitfield_decl): Use it.

	* g++.dg/cpp0x/enum23.C: Remove xfail.
	* g++.dg/cpp0x/enum28.C: New test.
---
 gcc/c-family/ChangeLog              |  9 +++++
 gcc/c-family/c-attribs.c            |  1 +
 gcc/cp/ChangeLog                    |  7 ++++
 gcc/cp/class.c                      | 56 ++++++++++++++++++++++++++++-
 gcc/testsuite/ChangeLog             |  6 ++++
 gcc/testsuite/g++.dg/cpp0x/enum23.C |  2 +-
 gcc/testsuite/g++.dg/cpp0x/enum38.C | 25 +++++++++++++
 7 files changed, 104 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/enum38.C

diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 7db9a94f23d..d3eeb51fcbd 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,12 @@
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/61414
+	* c-attribs.c (handle_mode_attribute): Add mode attribute to
+	ENUMERAL_TYPEs.
+
 2019-09-03  Iain Sandoe  <iain@sandoe.co.uk>
 
 	Backport from mainline
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 8f9f4702378..61249cf9477 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -1650,6 +1650,7 @@ handle_mode_attribute (tree *node, tree name, tree args,
 		typefm = make_signed_type (TYPE_PRECISION (typefm));
 	      TREE_TYPE (typefm) = type;
 	    }
+	  *no_add_attrs = false;
 	}
       else if (VECTOR_MODE_P (mode)
 	       ? TREE_CODE (type) != TREE_CODE (TREE_TYPE (typefm))
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b1cc9db5383..dc658330588 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/61414
+	* class.c (enum_to_min_precision): New hash_map.
+	(enum_min_precision): New function.
+	(check_bitfield_decl): Use it.
+
 	2019-11-21  Jakub Jelinek  <jakub@redhat.com>
 		    Jason Merrill  <jason@redhat.com>
 
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 0b789b17337..38137f9723e 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -3195,6 +3195,60 @@ add_implicitly_declared_members (tree t, tree* access_decls,
     }
 }
 
+/* Cache of enum_min_precision values.  */
+static GTY((deletable)) hash_map<tree, int> *enum_to_min_precision;
+
+/* Return the minimum precision of a bit-field needed to store all
+   enumerators of ENUMERAL_TYPE TYPE.  */
+
+static int
+enum_min_precision (tree type)
+{
+  type = TYPE_MAIN_VARIANT (type);
+  /* For unscoped enums without fixed underlying type and without mode
+     attribute we can just use precision of the underlying type.  */
+  if (UNSCOPED_ENUM_P (type)
+      && !ENUM_FIXED_UNDERLYING_TYPE_P (type)
+      && !lookup_attribute ("mode", TYPE_ATTRIBUTES (type)))
+    return TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type));
+
+  if (enum_to_min_precision == NULL)
+    enum_to_min_precision = hash_map<tree, int>::create_ggc (37);
+
+  bool existed;
+  int prec = enum_to_min_precision->get_or_insert (type, &existed);
+  if (existed)
+    return prec;
+
+  tree minnode, maxnode;
+  if (TYPE_VALUES (type))
+    {
+      minnode = maxnode = NULL_TREE;
+      for (tree values = TYPE_VALUES (type);
+	   values; values = TREE_CHAIN (values))
+	{
+	  tree decl = TREE_VALUE (values);
+	  tree value = DECL_INITIAL (decl);
+	  if (value == error_mark_node)
+	    value = integer_zero_node;
+	  if (!minnode)
+	    minnode = maxnode = value;
+	  else if (tree_int_cst_lt (maxnode, value))
+	    maxnode = value;
+	  else if (tree_int_cst_lt (value, minnode))
+	    minnode = value;
+	}
+    }
+  else
+    minnode = maxnode = integer_zero_node;
+
+  signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
+  int lowprec = tree_int_cst_min_precision (minnode, sgn);
+  int highprec = tree_int_cst_min_precision (maxnode, sgn);
+  prec = MAX (lowprec, highprec);
+  return prec;
+}
+
 /* FIELD is a bit-field.  We are finishing the processing for its
    enclosing type.  Issue any appropriate messages and set appropriate
    flags.  Returns false if an error has been diagnosed.  */
@@ -3255,7 +3309,7 @@ check_bitfield_decl (tree field)
 		    "width of %qD exceeds its type", field);
       else if (TREE_CODE (type) == ENUMERAL_TYPE)
 	{
-	  int prec = TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type));
+	  int prec = enum_min_precision (type);
 	  if (compare_tree_int (w, prec) < 0)
 	    warning_at (DECL_SOURCE_LOCATION (field), 0,
 			"%qD is too small to hold all values of %q#T",
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2b13ab518b7..d1a79819833 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/61414
+	* g++.dg/cpp0x/enum23.C: Remove xfail.
+	* g++.dg/cpp0x/enum28.C: New test.
+
 	2019-11-23  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/92615
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum23.C b/gcc/testsuite/g++.dg/cpp0x/enum23.C
index b2378e1b366..53ad990bf93 100644
--- a/gcc/testsuite/g++.dg/cpp0x/enum23.C
+++ b/gcc/testsuite/g++.dg/cpp0x/enum23.C
@@ -5,5 +5,5 @@ enum class MyEnum { A = 1 };
 
 struct MyClass
 {
-  MyEnum Field1 : 3; // { dg-bogus "warning: 'MyClass::Field1' is too small" "" { xfail *-*-* } }
+  MyEnum Field1 : 3; // { dg-bogus "warning: 'MyClass::Field1' is too small" }
 };
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum38.C b/gcc/testsuite/g++.dg/cpp0x/enum38.C
new file mode 100644
index 00000000000..f0dd8a1fc6b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/enum38.C
@@ -0,0 +1,25 @@
+// PR c++/61414
+// { dg-do compile { target c++11 } }
+
+enum C { C0 = -4, C1 = 3 };
+enum D { D0 = 0, D1 = 15 };
+enum class E { E0 = -4, E1 = 3 };
+enum F : unsigned { F0 = 0, F1 = 15 };
+enum __attribute__((__mode__ (__QI__))) G { G0 = -4, G1 = 3 };
+enum __attribute__((__mode__ (__HI__))) H { H0 = 0, H1 = 15 };
+
+struct S
+{
+  C a : 2;	// { dg-warning "'S::a' is too small to hold all values of 'enum C'" }
+  C b : 3;	// { dg-bogus "'S::b' is too small to hold all values of 'enum C'" }
+  D c : 3;	// { dg-warning "'S::c' is too small to hold all values of 'enum D'" }
+  D d : 4;	// { dg-bogus "'S::d' is too small to hold all values of 'enum D'" }
+  E e : 2;	// { dg-warning "'S::e' is too small to hold all values of 'enum class E'" }
+  E f : 3;	// { dg-bogus "'S::f' is too small to hold all values of 'enum class E'" }
+  F g : 3;	// { dg-warning "'S::g' is too small to hold all values of 'enum F'" }
+  F h : 4;	// { dg-bogus "'S::h' is too small to hold all values of 'enum F'" }
+  G i : 2;	// { dg-warning "'S::i' is too small to hold all values of 'enum G'" }
+  G j : 3;	// { dg-bogus "'S::j' is too small to hold all values of 'enum G'" }
+  H k : 3;	// { dg-warning "'S::k' is too small to hold all values of 'enum H'" }
+  H l : 4;	// { dg-bogus "'S::l' is too small to hold all values of 'enum H'" }
+};
-- 
2.20.1
From 37c0297f864394ddceba143ad410a6eb44a3119e Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:48:05 +0100
Subject: [PATCH] backport: re PR c++/92648 (Handling of unknown attributes)

	Backported from mainline
	2019-11-26  Jakub Jelinek  <jakub@redhat.com>

	PR c++/92648
	* parser.c (cp_parser_std_attribute): For unknown attributes,
	skip balanced token seq instead of trying to parse
	attribute-argument-clause as expression list.

	* g++.dg/cpp0x/gen-attrs-71.C: New test.
---
 gcc/cp/ChangeLog                          |  5 +++++
 gcc/cp/parser.c                           | 12 ++++++++++++
 gcc/testsuite/ChangeLog                   |  3 +++
 gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C |  7 +++++++
 4 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index dc658330588..b7f28bb8191 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -3,6 +3,11 @@
 	Backported from mainline
 	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
 
+	PR c++/92648
+	* parser.c (cp_parser_std_attribute): For unknown attributes,
+	skip balanced token seq instead of trying to parse
+	attribute-argument-clause as expression list.
+
 	PR c++/61414
 	* class.c (enum_to_min_precision): New hash_map.
 	(enum_min_precision): New function.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f523c87a9ae..cd71e149f81 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2646,6 +2646,7 @@ static bool cp_parser_init_statement_p
   (cp_parser *);
 static bool cp_parser_skip_to_closing_square_bracket
   (cp_parser *);
+static size_t cp_parser_skip_balanced_tokens (cp_parser *, size_t);
 
 /* Concept-related syntactic transformations */
 
@@ -25400,6 +25401,17 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns)
       /* A GNU attribute that takes an identifier in parameter.  */
       attr_flag = id_attr;
 
+    const attribute_spec *as
+      = lookup_attribute_spec (TREE_PURPOSE (attribute));
+    if (as == NULL)
+      {
+	/* For unknown attributes, just skip balanced tokens instead of
+	   trying to parse the arguments.  */
+	for (size_t n = cp_parser_skip_balanced_tokens (parser, 1) - 1; n; --n)
+	  cp_lexer_consume_token (parser->lexer);
+	return attribute;
+      }
+
     vec = cp_parser_parenthesized_expression_list
       (parser, attr_flag, /*cast_p=*/false,
        /*allow_expansion_p=*/true,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d1a79819833..6964dcad785 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,9 @@
 	Backported from mainline
 	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
 
+	PR c++/92648
+	* g++.dg/cpp0x/gen-attrs-71.C: New test.
+
 	PR c++/61414
 	* g++.dg/cpp0x/enum23.C: Remove xfail.
 	* g++.dg/cpp0x/enum28.C: New test.
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C
new file mode 100644
index 00000000000..7876a2fba30
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C
@@ -0,0 +1,7 @@
+// PR c++/92648
+// { dg-do compile { target c++11 } }
+
+int a [[gnu::no_such_attribute(![!(!)!]!,;;)]];	// { dg-warning "ignored" }
+int b [[no_such_namespace::nonexisting_attribute(linear(c, d : 2), reduction(*:e), linear(uval (f)))]];	// { dg-warning "ignored" }
+int c [[gnu::nonexisting_attribute()]];	// { dg-warning "ignored" }
+int d [[gnu::another_nonexistent_attr(1,"abcd",g+6)]];	// { dg-warning "ignored" }
-- 
2.20.1
From 5c265f5f1977f7c935b8b54cfdb23c862f686f20 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:49:07 +0100
Subject: [PATCH] backport: re PR debug/92664 (Wrong .debug_line section
 information when compiling stdin input with -g3)

	Backported from mainline
	2019-11-27  Jakub Jelinek  <jakub@redhat.com>

	PR debug/92664
	* dwarf2out.c (lookup_filename): Use "<stdin>" instead of "".
---
 gcc/ChangeLog   | 5 +++++
 gcc/dwarf2out.c | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 77b372010a4..58de7f953b9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+	PR debug/92664
+	* dwarf2out.c (lookup_filename): Use "<stdin>" instead of "".
+
 	2019-11-23  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/92615
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 0d67d303eb7..ab01f7dbcae 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -26999,6 +26999,9 @@ lookup_filename (const char *file_name)
   if (!file_name)
     return NULL;
 
+  if (!file_name[0])
+    file_name = "<stdin>";
+
   dwarf_file_data **slot
     = file_table->find_slot_with_hash (file_name, htab_hash_string (file_name),
 				       INSERT);
-- 
2.20.1
From 929d901ead4f859c8e385d91547482445a85066c Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:51:28 +0100
Subject: [PATCH] backport: re PR c++/92524 (ICE in short program with
 constexpr and std::array)

	Backported from mainline
	2019-11-27  Jakub Jelinek  <jakub@redhat.com>

	PR c++/92524
	* tree.c (replace_placeholders_r): Don't walk constructor elts with
	RANGE_EXPR indexes.

	* g++.dg/cpp0x/pr92524.C: New test.
---
 gcc/cp/ChangeLog                     |  6 ++++++
 gcc/cp/tree.c                        |  5 +++++
 gcc/testsuite/ChangeLog              |  5 +++++
 gcc/testsuite/g++.dg/cpp0x/pr92524.C | 12 ++++++++++++
 4 files changed, 28 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr92524.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b7f28bb8191..43c164b4c36 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92524
+	* tree.c (replace_placeholders_r): Don't walk constructor elts with
+	RANGE_EXPR indexes.
+
 	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/92648
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 76b20ce659e..9cf3ad42533 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -3192,6 +3192,11 @@ replace_placeholders_r (tree* t, int* walk_subtrees, void* data_)
 	    tree type = TREE_TYPE (*valp);
 	    tree subob = obj;
 
+	    /* Elements with RANGE_EXPR index shouldn't have any
+	       placeholders in them.  */
+	    if (ce->index && TREE_CODE (ce->index) == RANGE_EXPR)
+	      continue;
+
 	    if (TREE_CODE (*valp) == CONSTRUCTOR
 		&& AGGREGATE_TYPE_P (type))
 	      {
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6964dcad785..bde5512af39 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92524
+	* g++.dg/cpp0x/pr92524.C: New test.
+
 	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/92648
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr92524.C b/gcc/testsuite/g++.dg/cpp0x/pr92524.C
new file mode 100644
index 00000000000..ffbcd8f9f3a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr92524.C
@@ -0,0 +1,12 @@
+// PR c++/92524
+// { dg-do compile { target c++11 } }
+
+struct A { char a = '*'; };
+struct B { A b[64]; };
+
+void
+foo ()
+{
+  A a;
+  B{a};
+}
-- 
2.20.1
From bf5e3130c0ed518311a79c5a0099e0e39f33a889 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:53:12 +0100
Subject: [PATCH] backport: re PR fortran/91944 (ICE in
 gfc_conv_array_initializer, at fortran/trans-array.c:6156)

	Backported from mainline
	2019-11-27  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/91944
	* simplify.c (gfc_simplify_spread): Check gfc_init_expr_flag instead
	of gfc_current_ns->sym_root->n.sym->attr.flavor == FL_PARAMETER.

	* gfortran.dg/spread_size_limit_2.f90: New test.
---
 gcc/fortran/ChangeLog                             |  9 +++++++++
 gcc/fortran/simplify.c                            |  2 +-
 gcc/testsuite/ChangeLog                           |  3 +++
 gcc/testsuite/gfortran.dg/spread_size_limit_2.f90 | 11 +++++++++++
 4 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/spread_size_limit_2.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index aa4dc8c65bd..1c203449ce6 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,12 @@
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/91944
+	* simplify.c (gfc_simplify_spread): Check gfc_init_expr_flag instead
+	of gfc_current_ns->sym_root->n.sym->attr.flavor == FL_PARAMETER.
+
 2020-02-03  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backported from mainline
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index e043c90a4ec..c2679012359 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -7170,7 +7170,7 @@ gfc_simplify_spread (gfc_expr *source, gfc_expr *dim_expr, gfc_expr *ncopies_exp
   nelem = mpz_get_si (size) * ncopies;
   if (nelem > flag_max_array_constructor)
     {
-      if (gfc_current_ns->sym_root->n.sym->attr.flavor == FL_PARAMETER)
+      if (gfc_init_expr_flag)
 	{
 	  gfc_error ("The number of elements (%d) in the array constructor "
 		     "at %L requires an increase of the allowed %d upper "
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bde5512af39..f1c3971bc92 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,9 @@
 	Backported from mainline
 	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
 
+	PR fortran/91944
+	* gfortran.dg/spread_size_limit_2.f90: New test.
+
 	PR c++/92524
 	* g++.dg/cpp0x/pr92524.C: New test.
 
diff --git a/gcc/testsuite/gfortran.dg/spread_size_limit_2.f90 b/gcc/testsuite/gfortran.dg/spread_size_limit_2.f90
new file mode 100644
index 00000000000..3ea064e267f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/spread_size_limit_2.f90
@@ -0,0 +1,11 @@
+! PR fortran/91944
+! { dg-do compile }
+! { dg-options "-fmax-array-constructor=65535" }
+
+program pr91944
+  integer, parameter :: n = 10
+  integer, parameter :: m = 65536
+  integer :: i
+  integer :: x(n,m) = spread([(i,i=1,n)], dim=2, ncopies=m)	! { dg-error "requires an increase of the allowed 65535 upper limit" }
+  print *, x(n,m)
+end
-- 
2.20.1
From 1aafdd7c93226cb092b560462028394a82f404a2 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:56:42 +0100
Subject: [PATCH] backport: re PR c++/60228 (ICE using lambda in #pragma omp
 declare reduction)

	Backported from mainline
	2019-11-29  Jakub Jelinek  <jakub@redhat.com>

	PR c++/60228
	* parser.c (cp_parser_omp_declare_reduction_exprs): If
	processing_template_decl, wrap the combiner or initializer
	into EXPR_STMT.
	* decl.c (start_preparsed_function): Don't start a lambda scope
	for DECL_OMP_DECLARE_REDUCTION_P functions.
	(finish_function): Don't finish a lambda scope for
	DECL_OMP_DECLARE_REDUCTION_P functions, nor cp_fold_function
	them nor cp_genericize them.
	* mangle.c (decl_mangling_context): Look through
	DECL_OMP_DECLARE_REDUCTION_P functions.
	* semantics.c (expand_or_defer_fn_1): For DECL_OMP_DECLARE_REDUCTION_P
	functions, use tentative linkage, don't keep their bodies with
	-fkeep-inline-functions and return false at the end.

	* g++.dg/gomp/openmp-simd-2.C: Don't expect bodies for
	DECL_OMP_DECLARE_REDUCTION_P functions.

	* testsuite/libgomp.c++/udr-20.C: New test.
	* testsuite/libgomp.c++/udr-21.C: New test.
---
 gcc/cp/ChangeLog                          | 17 +++++++
 gcc/cp/decl.c                             | 11 +++--
 gcc/cp/mangle.c                           | 11 ++++-
 gcc/cp/parser.c                           |  4 ++
 gcc/cp/semantics.c                        |  6 ++-
 gcc/testsuite/ChangeLog                   |  6 +++
 gcc/testsuite/g++.dg/gomp/openmp-simd-2.C |  2 -
 libgomp/ChangeLog                         |  9 ++++
 libgomp/testsuite/libgomp.c++/udr-20.C    | 54 +++++++++++++++++++++++
 libgomp/testsuite/libgomp.c++/udr-21.C    | 54 +++++++++++++++++++++++
 10 files changed, 166 insertions(+), 8 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.c++/udr-20.C
 create mode 100644 libgomp/testsuite/libgomp.c++/udr-21.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 43c164b4c36..296a7f644a6 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,6 +1,23 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/60228
+	* parser.c (cp_parser_omp_declare_reduction_exprs): If
+	processing_template_decl, wrap the combiner or initializer
+	into EXPR_STMT.
+	* decl.c (start_preparsed_function): Don't start a lambda scope
+	for DECL_OMP_DECLARE_REDUCTION_P functions.
+	(finish_function): Don't finish a lambda scope for
+	DECL_OMP_DECLARE_REDUCTION_P functions, nor cp_fold_function
+	them nor cp_genericize them.
+	* mangle.c (decl_mangling_context): Look through
+	DECL_OMP_DECLARE_REDUCTION_P functions.
+	* semantics.c (expand_or_defer_fn_1): For DECL_OMP_DECLARE_REDUCTION_P
+	functions, use tentative linkage, don't keep their bodies with
+	-fkeep-inline-functions and return false at the end.
+
 	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/92524
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 1d363d8a0be..c55cdbed170 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -15367,7 +15367,8 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
       && !implicit_default_ctor_p (decl1))
     cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
 
-  start_lambda_scope (decl1);
+  if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
+    start_lambda_scope (decl1);
 
   return true;
 }
@@ -15760,7 +15761,8 @@ finish_function (bool inline_p)
   if (fndecl == NULL_TREE)
     return error_mark_node;
 
-  finish_lambda_scope ();
+  if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
+    finish_lambda_scope ();
 
   if (c_dialect_objc ())
     objc_finish_function ();
@@ -15877,7 +15879,7 @@ finish_function (bool inline_p)
     invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
 
   /* Perform delayed folding before NRV transformation.  */
-  if (!processing_template_decl)
+  if (!processing_template_decl && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
     cp_fold_function (fndecl);
 
   /* Set up the named return value optimization, if we can.  Candidate
@@ -15986,7 +15988,8 @@ finish_function (bool inline_p)
   if (!processing_template_decl)
     {
       struct language_function *f = DECL_SAVED_FUNCTION_DATA (fndecl);
-      cp_genericize (fndecl);
+      if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
+	cp_genericize (fndecl);
       /* Clear out the bits we don't need.  */
       f->x_current_class_ptr = NULL;
       f->x_current_class_ref = NULL;
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 5146162404f..ac90e47fc94 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -875,7 +875,16 @@ decl_mangling_context (tree decl)
   else if (template_type_parameter_p (decl))
      /* template type parms have no mangling context.  */
       return NULL_TREE;
-  return CP_DECL_CONTEXT (decl);
+
+  tcontext = CP_DECL_CONTEXT (decl);
+
+  /* Ignore the artificial declare reduction functions.  */
+  if (tcontext
+      && TREE_CODE (tcontext) == FUNCTION_DECL
+      && DECL_OMP_DECLARE_REDUCTION_P (tcontext))
+    return decl_mangling_context (tcontext);
+
+  return tcontext;
 }
 
 /* <name> ::= <unscoped-name>
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index cd71e149f81..f7ecfcdc9a5 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -37615,6 +37615,8 @@ cp_parser_omp_declare_reduction_exprs (tree fndecl, cp_parser *parser)
   combiner = cp_parser_expression (parser);
   finish_expr_stmt (combiner);
   block = finish_omp_structured_block (block);
+  if (processing_template_decl)
+    block = build_stmt (input_location, EXPR_STMT, block);
   add_stmt (block);
 
   if (!cp_parser_require (parser, CPP_CLOSE_PAREN, RT_CLOSE_PAREN))
@@ -37717,6 +37719,8 @@ cp_parser_omp_declare_reduction_exprs (tree fndecl, cp_parser *parser)
 
       block = finish_omp_structured_block (block);
       cp_walk_tree (&block, cp_remove_omp_priv_cleanup_stmt, omp_priv, NULL);
+      if (processing_template_decl)
+	block = build_stmt (input_location, EXPR_STMT, block);
       add_stmt (block);
 
       if (ctor)
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 797fb309902..96849e76171 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -4234,7 +4234,7 @@ expand_or_defer_fn_1 (tree fn)
       if (DECL_INTERFACE_KNOWN (fn))
 	/* We've already made a decision as to how this function will
 	   be handled.  */;
-      else if (!at_eof)
+      else if (!at_eof || DECL_OMP_DECLARE_REDUCTION_P (fn))
 	tentative_decl_linkage (fn);
       else
 	import_export_decl (fn);
@@ -4245,6 +4245,7 @@ expand_or_defer_fn_1 (tree fn)
 	 be emitted; there may be callers in other DLLs.  */
       if (DECL_DECLARED_INLINE_P (fn)
 	  && !DECL_REALLY_EXTERN (fn)
+	  && !DECL_OMP_DECLARE_REDUCTION_P (fn)
 	  && (flag_keep_inline_functions
 	      || (flag_keep_inline_dllexport
 		  && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
@@ -4277,6 +4278,9 @@ expand_or_defer_fn_1 (tree fn)
       return false;
     }
 
+  if (DECL_OMP_DECLARE_REDUCTION_P (fn))
+    return false;
+
   return true;
 }
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f1c3971bc92..1ae45cca30e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/60228
+	* g++.dg/gomp/openmp-simd-2.C: Don't expect bodies for
+	DECL_OMP_DECLARE_REDUCTION_P functions.
+
 	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/91944
diff --git a/gcc/testsuite/g++.dg/gomp/openmp-simd-2.C b/gcc/testsuite/g++.dg/gomp/openmp-simd-2.C
index e31c1ebecf9..e66806845b7 100644
--- a/gcc/testsuite/g++.dg/gomp/openmp-simd-2.C
+++ b/gcc/testsuite/g++.dg/gomp/openmp-simd-2.C
@@ -36,8 +36,6 @@ void bar(int n, float *a, float *b)
     a[i] = b[i];
 }
 
-/* { dg-final { scan-tree-dump-times "Function void omp declare reduction operator\\+" 1 "original" } } */
-/* { dg-final { scan-tree-dump-times "Function void omp declare reduction foo" 2 "original" } } */
 /* { dg-final { scan-tree-dump-times "pragma omp simd reduction\\(u\\) reduction\\(t\\) reduction\\(\\+:s\\) aligned\\(a:32\\)" 1 "original" } } */
 /* { dg-final { scan-tree-dump-times "pragma omp simd safelen\\(64\\)" 1 "original" } } */
 /* { dg-final { scan-tree-dump-not "omp parallel" "original" } } */
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 9f2d8a1df25..48e8e082adc 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,3 +1,12 @@
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/60228
+	* testsuite/libgomp.c++/udr-20.C: New test.
+	* testsuite/libgomp.c++/udr-21.C: New test.
+
 2019-12-11  Tobias Burnus  <tobias@codesourcery.com>
 
 	Backported from mainline
diff --git a/libgomp/testsuite/libgomp.c++/udr-20.C b/libgomp/testsuite/libgomp.c++/udr-20.C
new file mode 100644
index 00000000000..83388758edd
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/udr-20.C
@@ -0,0 +1,54 @@
+// PR c++/60228
+// { dg-additional-options "-std=c++11" }
+
+extern "C" void abort ();
+
+struct A
+{
+  typedef int T;
+  #pragma omp declare reduction (x : T : omp_out += omp_in + [](){ return 0; }()) initializer (omp_priv = [](){ return 0; }())
+  static void foo ();
+};
+
+template <typename T>
+struct B
+{
+  #pragma omp declare reduction (x : T : omp_out += omp_in + [](){ return T (0); }()) initializer (omp_priv = [](){ return T (0); }())
+  static void foo ();
+};
+
+void
+A::foo ()
+{
+  int r = 0, s = 0;
+  #pragma omp parallel for reduction (x : r, s)
+  for (int i = 0; i < 64; i++)
+    {
+      r++;
+      s += i;
+    }
+  if (r != 64 || s != (64 * 63) / 2)
+    abort ();
+}
+
+template <typename T>
+void
+B<T>::foo ()
+{
+  T r = 0, s = 0;
+  #pragma omp parallel for reduction (x : r, s)
+  for (int i = 0; i < 64; i++)
+    {
+      r++;
+      s += i;
+    }
+  if (r != 64 || s != (64 * 63) / 2)
+    abort ();
+}
+
+int
+main ()
+{
+  A::foo ();
+  B<long>::foo ();
+}
diff --git a/libgomp/testsuite/libgomp.c++/udr-21.C b/libgomp/testsuite/libgomp.c++/udr-21.C
new file mode 100644
index 00000000000..9ec655718fd
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c++/udr-21.C
@@ -0,0 +1,54 @@
+// PR c++/60228
+// { dg-additional-options "-std=c++11" }
+
+extern "C" void abort ();
+
+struct A
+{
+  typedef int T;
+  #pragma omp declare reduction (y : T : [&omp_out, &omp_in]() { omp_out += omp_in; return 0; }()) initializer (omp_priv = [omp_orig]() { return omp_orig; }())
+  static void foo ();
+};
+
+template <typename T>
+struct B
+{
+  #pragma omp declare reduction (y : T : [&omp_out, &omp_in]() { omp_out += omp_in; return 0; }()) initializer (omp_priv = [omp_orig]() { return omp_orig; }())
+  static void foo ();
+};
+
+void
+A::foo ()
+{
+  int r = 0, s = 0;
+  #pragma omp parallel for reduction (y : r, s)
+  for (int i = 0; i < 64; i++)
+    {
+      r++;
+      s += i;
+    }
+  if (r != 64 || s != (64 * 63) / 2)
+    abort ();
+}
+
+template <typename T>
+void
+B<T>::foo ()
+{
+  T r = 0, s = 0;
+  #pragma omp parallel for reduction (y : r, s)
+  for (int i = 0; i < 64; i++)
+    {
+      r++;
+      s += i;
+    }
+  if (r != 64 || s != (64 * 63) / 2)
+    abort ();
+}
+
+int
+main ()
+{
+  A::foo ();
+  B<short>::foo ();
+}
-- 
2.20.1
From 41e5eec55cb64b54c717d9625bcee1aac1def569 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:58:46 +0100
Subject: [PATCH] backport: re PR c++/92732 (Bit-field of scoped enumeration
 type cannot be initialized)

	Backported from mainline
	2019-12-03  Jakub Jelinek  <jakub@redhat.com>

	PR c++/92732
	* typeck2.c (digest_nsdmi_init): For bitfields, use
	DECL_BIT_FIELD_TYPE instead of TREE_TYPE.

	* g++.dg/cpp2a/bitfield3.C: Don't expect narrowing conversion
	warnings.
	* g++.dg/cpp2a/bitfield4.C: New test.
---
 gcc/cp/ChangeLog                       |  6 ++++++
 gcc/cp/typeck2.c                       |  2 ++
 gcc/testsuite/ChangeLog                |  7 +++++++
 gcc/testsuite/g++.dg/cpp2a/bitfield3.C |  4 ----
 gcc/testsuite/g++.dg/cpp2a/bitfield4.C | 12 ++++++++++++
 5 files changed, 27 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/bitfield4.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 296a7f644a6..a114b92fe2e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-03  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92732
+	* typeck2.c (digest_nsdmi_init): For bitfields, use
+	DECL_BIT_FIELD_TYPE instead of TREE_TYPE.
+
 	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/60228
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index b28044c11dc..a0646afa405 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1224,6 +1224,8 @@ digest_nsdmi_init (tree decl, tree init, tsubst_flags_t complain)
   gcc_assert (TREE_CODE (decl) == FIELD_DECL);
 
   tree type = TREE_TYPE (decl);
+  if (DECL_BIT_FIELD_TYPE (decl))
+    type = DECL_BIT_FIELD_TYPE (decl);
   int flags = LOOKUP_IMPLICIT;
   if (DIRECT_LIST_INIT_P (init))
     flags = LOOKUP_NORMAL;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1ae45cca30e..2a0eeb5bd3e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-03  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92732
+	* g++.dg/cpp2a/bitfield3.C: Don't expect narrowing conversion
+	warnings.
+	* g++.dg/cpp2a/bitfield4.C: New test.
+
 	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/60228
diff --git a/gcc/testsuite/g++.dg/cpp2a/bitfield3.C b/gcc/testsuite/g++.dg/cpp2a/bitfield3.C
index 511c8894703..5482da490e2 100644
--- a/gcc/testsuite/g++.dg/cpp2a/bitfield3.C
+++ b/gcc/testsuite/g++.dg/cpp2a/bitfield3.C
@@ -15,11 +15,9 @@ const int b = 0;
 struct S {
   int c : 5 = 2 * a;			// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
   int d : 6 { c + a };			// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
-					// { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 }
   int e : true ? 7 : a = 3;
   int f : (true ? 8 : b) = d + a;	// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
   int g : (true ? 9 : b) { f + a };	// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
-					// { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 }
   int h : 1 || new int { 0 };
   int i = g + a;
 };
@@ -28,11 +26,9 @@ template <bool V, int W>
 struct U {
   int j : W = 3 * a;			// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
   int k : W { j + a };			// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
-					// { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 }
   int l : V ? 7 : a = 3;
   int m : (V ? W : b) = k + a;		// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
   int n : (V ? W : b) { m + a };	// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
-					// { dg-warning "narrowing conversion of" "" { target *-*-* } .-1 }
   int o : 1 || new int { 0 };
   int p = n + a;
 };
diff --git a/gcc/testsuite/g++.dg/cpp2a/bitfield4.C b/gcc/testsuite/g++.dg/cpp2a/bitfield4.C
new file mode 100644
index 00000000000..bbfa86cbb9e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/bitfield4.C
@@ -0,0 +1,12 @@
+// PR c++/92732
+// { dg-do compile { target c++17 } }
+// { dg-options "" }
+
+enum class byte : unsigned char { };
+using uint8_t = unsigned char;
+
+struct T
+{
+  byte a : 2 = byte{0};	// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
+  uint8_t b : 2 = 0;	// { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
+} t;
-- 
2.20.1
From 37e948410c67d1e4a0bb5bd3721b9fbf4d77f889 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 12:59:53 +0100
Subject: [PATCH] backport: re PR fortran/92781 (ICE in
 convert_nonlocal_reference_op, at tree-nested.c:1065)

	Backported from mainline
	2019-12-05  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/92781
	* trans-decl.c (gfc_get_symbol_decl): If sym->backend_decl is
	current_function_decl, add length to current rather than parent
	function and expect DECL_CONTEXT (length) to be current_function_decl.

	* gfortran.dg/pr92781.f90: New test.
---
 gcc/fortran/ChangeLog                 |  7 +++++++
 gcc/fortran/trans-decl.c              | 11 +++++++----
 gcc/testsuite/ChangeLog               |  5 +++++
 gcc/testsuite/gfortran.dg/pr92781.f90 | 11 +++++++++++
 4 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr92781.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 1c203449ce6..74b42d38e2d 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-05  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/92781
+	* trans-decl.c (gfc_get_symbol_decl): If sym->backend_decl is
+	current_function_decl, add length to current rather than parent
+	function and expect DECL_CONTEXT (length) to be current_function_decl.
+
 	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/91944
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 1e46b627f8f..2dc350fbb5a 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1626,15 +1626,18 @@ gfc_get_symbol_decl (gfc_symbol * sym)
 	      /* Add the string length to the same context as the symbol.  */
 	      if (DECL_CONTEXT (length) == NULL_TREE)
 		{
-		  if (DECL_CONTEXT (sym->backend_decl)
-		      == current_function_decl)
+		  if (sym->backend_decl == current_function_decl
+		      || (DECL_CONTEXT (sym->backend_decl)
+			  == current_function_decl))
 		    gfc_add_decl_to_function (length);
 		  else
 		    gfc_add_decl_to_parent_function (length);
 		}
 
-	      gcc_assert (DECL_CONTEXT (sym->backend_decl)
-			  == DECL_CONTEXT (length));
+	      gcc_assert (sym->backend_decl == current_function_decl
+			  ? DECL_CONTEXT (length) == current_function_decl
+			  : (DECL_CONTEXT (sym->backend_decl)
+			     == DECL_CONTEXT (length)));
 
 	      gfc_defer_symbol_init (sym);
 	    }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2a0eeb5bd3e..da812563d6a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-05  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/92781
+	* gfortran.dg/pr92781.f90: New test.
+
 	2019-12-03  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/92732
diff --git a/gcc/testsuite/gfortran.dg/pr92781.f90 b/gcc/testsuite/gfortran.dg/pr92781.f90
new file mode 100644
index 00000000000..67a1961205a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr92781.f90
@@ -0,0 +1,11 @@
+! PR fortran/92781
+! { dg-do compile }
+
+function foo ()
+  character(:), allocatable :: foo
+  call bar ()
+  foo = 'abc'
+contains
+  subroutine bar
+  end
+end
-- 
2.20.1
From c58bec27145c9a049d6642ca011b7f0fbe9c5f33 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 13:08:33 +0100
Subject: [PATCH] backport: re PR target/92723 (ICE in expand_shift_1, at
 expmed.c:2635)

	Backported from mainline
	2019-12-11  Jakub Jelinek  <jakub@redhat.com>

	PR target/92723
	* tree-vect-patterns.c (vect_recog_rotate_pattern): If dt is not
	vect_internal_def, use oprnd1 as is, without trying to cast it.
	Formatting fix.

	* gcc.dg/vect/pr92723.c: New test.
---
 gcc/ChangeLog                       |  7 +++++++
 gcc/testsuite/gcc.dg/vect/pr92723.c |  9 +++++++++
 gcc/tree-vect-patterns.c            | 12 ++----------
 3 files changed, 18 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/pr92723.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 58de7f953b9..94879f8d34a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-20  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/92723
+	* tree-vect-patterns.c (vect_recog_rotate_pattern): If dt is not
+	vect_internal_def, use oprnd1 as is, without trying to cast it.
+	Formatting fix.
+
 	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
 
 	PR debug/92664
diff --git a/gcc/testsuite/gcc.dg/vect/pr92723.c b/gcc/testsuite/gcc.dg/vect/pr92723.c
new file mode 100644
index 00000000000..0d60883cadd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr92723.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+
+void
+foo (unsigned long long *x, unsigned long long *y, int z)
+{
+  int i;
+  for (i = 0; i < 1024; i++)
+    x[i] = (y[i] >> z) | (y[i] << (-z & (__SIZEOF_LONG_LONG__ * __CHAR_BIT__ - 1)));
+}
diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 621ed07758f..30c3daaa32f 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -1965,8 +1965,7 @@ vect_recog_rotate_pattern (vec<gimple *> *stmts, tree *type_in, tree *type_out)
 
   def = NULL_TREE;
   scalar_int_mode mode = SCALAR_INT_TYPE_MODE (type);
-  if (TREE_CODE (oprnd1) == INTEGER_CST
-      || TYPE_MODE (TREE_TYPE (oprnd1)) == mode)
+  if (dt != vect_internal_def || TYPE_MODE (TREE_TYPE (oprnd1)) == mode)
     def = oprnd1;
   else if (def_stmt && gimple_assign_cast_p (def_stmt))
     {
@@ -1982,14 +1981,7 @@ vect_recog_rotate_pattern (vec<gimple *> *stmts, tree *type_in, tree *type_out)
     {
       def = vect_recog_temp_ssa_var (type, NULL);
       def_stmt = gimple_build_assign (def, NOP_EXPR, oprnd1);
-      if (ext_def)
-	{
-	  basic_block new_bb
-	    = gsi_insert_on_edge_immediate (ext_def, def_stmt);
-	  gcc_assert (!new_bb);
-	}
-      else
-	append_pattern_def_seq (stmt_vinfo, def_stmt);
+      append_pattern_def_seq (stmt_vinfo, def_stmt);
     }
   stype = TREE_TYPE (def);
   scalar_int_mode smode = SCALAR_INT_TYPE_MODE (stype);
-- 
2.20.1
From f9a0c0800994d5e0b68c0a8eed47454bce841f97 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:23:34 +0100
Subject: [PATCH] backport: re PR fortran/92899 ([OpenMP] ICE in
 gfc_trans_omp_atomic, at fortran/trans-openmp.c:3769)

	Backported from mainline
	2019-12-11  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/92899
	* trans-openmp.c (gfc_trans_omp_atomic): For GFC_OMP_ATOMIC_SWAP,
	do look through conversion on expr2 if any.

	* testsuite/libgomp.fortran/atomic1.f90: New test.
---
 gcc/fortran/ChangeLog                         |  6 +++
 gcc/fortran/trans-openmp.c                    |  1 -
 libgomp/ChangeLog                             |  5 ++
 libgomp/testsuite/libgomp.fortran/atomic1.f90 | 46 +++++++++++++++++++
 4 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 libgomp/testsuite/libgomp.fortran/atomic1.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 74b42d38e2d..b7f8ababc37 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-11  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/92899
+	* trans-openmp.c (gfc_trans_omp_atomic): For GFC_OMP_ATOMIC_SWAP,
+	do look through conversion on expr2 if any.
+
 	2019-12-05  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/92781
diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index 1eaad896503..85d6eab0123 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -3182,7 +3182,6 @@ gfc_trans_omp_atomic (gfc_code *code)
   expr2 = code->expr2;
   if (((atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_MASK)
        != GFC_OMP_ATOMIC_WRITE)
-      && (atomic_code->ext.omp_atomic & GFC_OMP_ATOMIC_SWAP) == 0
       && expr2->expr_type == EXPR_FUNCTION
       && expr2->value.function.isym
       && expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 48e8e082adc..889315705a8 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-11  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/92899
+	* testsuite/libgomp.fortran/atomic1.f90: New test.
+
 	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/60228
diff --git a/libgomp/testsuite/libgomp.fortran/atomic1.f90 b/libgomp/testsuite/libgomp.fortran/atomic1.f90
new file mode 100644
index 00000000000..e0c13536f94
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/atomic1.f90
@@ -0,0 +1,46 @@
+! PR fortran/92899
+
+program pr92899
+  real :: x = 1.0
+  double precision :: y
+  integer(kind=4) :: z = 4
+  integer(kind=8) :: w
+  !$omp atomic capture
+  y = x
+  x = 2.0
+  !$omp end atomic
+  if (y /= 1.0 .or. x /= 2.0) stop 1
+  !$omp atomic capture
+  x = y
+  y = 3.0
+  !$omp end atomic
+  if (x /= 1.0 .or. y /= 3.0) stop 2
+  !$omp atomic capture
+  w = z
+  z = 5
+  !$omp end atomic
+  if (w /= 4 .or. z /= 5) stop 3
+  !$omp atomic capture
+  z = w
+  w = 6
+  !$omp end atomic
+  if (z /= 4 .or. w /= 6) stop 4
+  !$omp atomic write
+  x = y
+  !$omp end atomic
+  if (x /= 3.0 .or. y /= 3.0) stop 5
+  x = 7.0
+  !$omp atomic write
+  y = x
+  !$omp end atomic
+  if (x /= 7.0 .or. y /= 7.0) stop 6
+  !$omp atomic write
+  z = w
+  !$omp end atomic
+  if (z /= 6 .or. w /= 6) stop 7
+  z = 8
+  !$omp atomic write
+  w = z
+  !$omp end atomic
+  if (z /= 8 .or. w /= 8) stop 8
+end
-- 
2.20.1
From ffb5cc9a5599b1936c5ebea153ca52a0aa2c785d Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:24:48 +0100
Subject: [PATCH] backport: re PR target/92904 (varargs for __int128 is placed
 at an unaligned location and uses movdqa for the load)

	Backported from mainline
	2019-12-12  Jakub Jelinek  <jakub@redhat.com>

	PR target/92904
	* config/i386/i386.c (ix86_gimplify_va_arg): If need_intregs and
	not need_temp, decrease alignment of the read because the GPR save
	area only guarantees 8-byte alignment.

	* gcc.c-torture/execute/pr92904.c: New test.
---
 gcc/ChangeLog                                 |   9 +-
 gcc/config/i386/i386.c                        |   6 +
 gcc/testsuite/ChangeLog                       |   5 +
 gcc/testsuite/gcc.c-torture/execute/pr92904.c | 395 ++++++++++++++++++
 4 files changed, 414 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr92904.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 94879f8d34a..234649d2d29 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,7 +1,14 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
-	2019-12-20  Jakub Jelinek  <jakub@redhat.com>
+	2019-12-12  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/92904
+	* config/i386/i386.c (ix86_gimplify_va_arg): If need_intregs and
+	not need_temp, decrease alignment of the read because the GPR save
+	area only guarantees 8-byte alignment.
+
+	2019-12-11  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/92723
 	* tree-vect-patterns.c (vect_recog_rotate_pattern): If dt is not
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 29c558489b8..1cce2a8cd73 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -10005,6 +10005,7 @@ ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
   tree ptrtype;
   machine_mode nat_mode;
   unsigned int arg_boundary;
+  unsigned int type_align;
 
   /* Only 64bit target needs something special.  */
   if (is_va_list_char_pointer (TREE_TYPE (valist)))
@@ -10062,6 +10063,7 @@ ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
   /* Pull the value out of the saved registers.  */
 
   addr = create_tmp_var (ptr_type_node, "addr");
+  type_align = TYPE_ALIGN (type);
 
   if (container)
     {
@@ -10232,6 +10234,9 @@ ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
 	  t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
 		      build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
 	  gimplify_assign (gpr, t, pre_p);
+	  /* The GPR save area guarantees only 8-byte alignment.  */
+	  if (!need_temp)
+	    type_align = MIN (type_align, 64);
 	}
 
       if (needed_sseregs)
@@ -10276,6 +10281,7 @@ ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
   if (container)
     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
 
+  type = build_aligned_type (type, type_align);
   ptrtype = build_pointer_type_for_mode (type, ptr_mode, true);
   addr = fold_convert (ptrtype, addr);
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index da812563d6a..60c7b17c88e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-12  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/92904
+	* gcc.c-torture/execute/pr92904.c: New test.
+
 	2019-12-05  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/92781
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr92904.c b/gcc/testsuite/gcc.c-torture/execute/pr92904.c
new file mode 100644
index 00000000000..25cb0b8c595
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr92904.c
@@ -0,0 +1,395 @@
+/* PR target/92904 */
+
+#include <stdarg.h>
+
+struct S { long long a, b; };
+struct __attribute__((aligned (16))) T { long long a, b; };
+struct U { double a, b, c, d; };
+struct __attribute__((aligned (32))) V { double a, b, c, d; };
+struct W { double a; long long b; };
+struct __attribute__((aligned (16))) X { double a; long long b; };
+#if __SIZEOF_INT128__ == 2 * __SIZEOF_LONG_LONG__
+__int128 b;
+#endif
+struct S c;
+struct T d;
+struct U e;
+struct V f;
+struct W g;
+struct X h;
+
+#if __SIZEOF_INT128__ == 2 * __SIZEOF_LONG_LONG__
+__attribute__((noipa)) __int128
+f1 (int x, ...)
+{
+  __int128 r;
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, int);
+  r = va_arg (ap, __int128);
+  va_end (ap);
+  return r;
+}
+#endif
+
+__attribute__((noipa)) struct S
+f2 (int x, ...)
+{
+  struct S r;
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, int);
+  r = va_arg (ap, struct S);
+  va_end (ap);
+  return r;
+}
+
+__attribute__((noipa)) struct T
+f3 (int x, ...)
+{
+  struct T r;
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, int);
+  r = va_arg (ap, struct T);
+  va_end (ap);
+  return r;
+}
+
+#if __SIZEOF_INT128__ == 2 * __SIZEOF_LONG_LONG__
+__attribute__((noipa)) void
+f4 (int x, ...)
+{
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, int);
+  b = va_arg (ap, __int128);
+  va_end (ap);
+}
+#endif
+
+__attribute__((noipa)) void
+f5 (int x, ...)
+{
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, int);
+  c = va_arg (ap, struct S);
+  va_end (ap);
+}
+
+__attribute__((noipa)) void
+f6 (int x, ...)
+{
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, int);
+  d = va_arg (ap, struct T);
+  va_end (ap);
+}
+
+__attribute__((noipa)) struct U
+f7 (int x, ...)
+{
+  struct U r;
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, double);
+  r = va_arg (ap, struct U);
+  va_end (ap);
+  return r;
+}
+
+__attribute__((noipa)) struct V
+f8 (int x, ...)
+{
+  struct V r;
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, double);
+  r = va_arg (ap, struct V);
+  va_end (ap);
+  return r;
+}
+
+__attribute__((noipa)) void
+f9 (int x, ...)
+{
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, double);
+  e = va_arg (ap, struct U);
+  va_end (ap);
+}
+
+__attribute__((noipa)) void
+f10 (int x, ...)
+{
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    va_arg (ap, double);
+  f = va_arg (ap, struct V);
+  va_end (ap);
+}
+
+__attribute__((noipa)) struct W
+f11 (int x, ...)
+{
+  struct W r;
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    {
+      va_arg (ap, int);
+      va_arg (ap, double);
+    }
+  r = va_arg (ap, struct W);
+  va_end (ap);
+  return r;
+}
+
+__attribute__((noipa)) struct X
+f12 (int x, ...)
+{
+  struct X r;
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    {
+      va_arg (ap, int);
+      va_arg (ap, double);
+    }
+  r = va_arg (ap, struct X);
+  va_end (ap);
+  return r;
+}
+
+__attribute__((noipa)) void
+f13 (int x, ...)
+{
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    {
+      va_arg (ap, int);
+      va_arg (ap, double);
+    }
+  g = va_arg (ap, struct W);
+  va_end (ap);
+}
+
+__attribute__((noipa)) void
+f14 (int x, ...)
+{
+  va_list ap;
+  va_start (ap, x);
+  while (x--)
+    {
+      va_arg (ap, int);
+      va_arg (ap, double);
+    }
+  h = va_arg (ap, struct X);
+  va_end (ap);
+}
+
+int
+main ()
+{
+  union Y {
+#if __SIZEOF_INT128__ == 2 * __SIZEOF_LONG_LONG__
+    __int128 b;
+#endif
+    struct S c;
+    struct T d;
+    struct U e;
+    struct V f;
+    struct W g;
+    struct X h;
+  } u, v;
+  u.c.a = 0x5555555555555555ULL;
+  u.c.b = 0xaaaaaaaaaaaaaaaaULL;
+#define C(x) \
+  do {								\
+    if (u.c.a != x.c.a || u.c.b != x.c.b) __builtin_abort ();	\
+    u.c.a++;							\
+    u.c.b--;							\
+  } while (0)
+#if __SIZEOF_INT128__ == 2 * __SIZEOF_LONG_LONG__
+  v.b = f1 (0, u.b); C (v);
+  v.b = f1 (1, 0, u.b); C (v);
+  v.b = f1 (2, 0, 0, u.b); C (v);
+  v.b = f1 (3, 0, 0, 0, u.b); C (v);
+  v.b = f1 (4, 0, 0, 0, 0, u.b); C (v);
+  v.b = f1 (5, 0, 0, 0, 0, 0, u.b); C (v);
+  v.b = f1 (6, 0, 0, 0, 0, 0, 0, u.b); C (v);
+  v.b = f1 (7, 0, 0, 0, 0, 0, 0, 0, u.b); C (v);
+  v.b = f1 (8, 0, 0, 0, 0, 0, 0, 0, 0, u.b); C (v);
+  v.b = f1 (9, 0, 0, 0, 0, 0, 0, 0, 0, 0, u.b); C (v);
+#endif
+  v.c = f2 (0, u.c); C (v);
+  v.c = f2 (1, 0, u.c); C (v);
+  v.c = f2 (2, 0, 0, u.c); C (v);
+  v.c = f2 (3, 0, 0, 0, u.c); C (v);
+  v.c = f2 (4, 0, 0, 0, 0, u.c); C (v);
+  v.c = f2 (5, 0, 0, 0, 0, 0, u.c); C (v);
+  v.c = f2 (6, 0, 0, 0, 0, 0, 0, u.c); C (v);
+  v.c = f2 (7, 0, 0, 0, 0, 0, 0, 0, u.c); C (v);
+  v.c = f2 (8, 0, 0, 0, 0, 0, 0, 0, 0, u.c); C (v);
+  v.c = f2 (9, 0, 0, 0, 0, 0, 0, 0, 0, 0, u.c); C (v);
+  v.d = f3 (0, u.d); C (v);
+  v.d = f3 (1, 0, u.d); C (v);
+  v.d = f3 (2, 0, 0, u.d); C (v);
+  v.d = f3 (3, 0, 0, 0, u.d); C (v);
+  v.d = f3 (4, 0, 0, 0, 0, u.d); C (v);
+  v.d = f3 (5, 0, 0, 0, 0, 0, u.d); C (v);
+  v.d = f3 (6, 0, 0, 0, 0, 0, 0, u.d); C (v);
+  v.d = f3 (7, 0, 0, 0, 0, 0, 0, 0, u.d); C (v);
+  v.d = f3 (8, 0, 0, 0, 0, 0, 0, 0, 0, u.d); C (v);
+  v.d = f3 (9, 0, 0, 0, 0, 0, 0, 0, 0, 0, u.d); C (v);
+#if __SIZEOF_INT128__ == 2 * __SIZEOF_LONG_LONG__
+  f4 (0, u.b); v.b = b; C (v);
+  f4 (1, 0, u.b); v.b = b; C (v);
+  f4 (2, 0, 0, u.b); v.b = b; C (v);
+  f4 (3, 0, 0, 0, u.b); v.b = b; C (v);
+  f4 (4, 0, 0, 0, 0, u.b); v.b = b; C (v);
+  f4 (5, 0, 0, 0, 0, 0, u.b); v.b = b; C (v);
+  f4 (6, 0, 0, 0, 0, 0, 0, u.b); v.b = b; C (v);
+  f4 (7, 0, 0, 0, 0, 0, 0, 0, u.b); v.b = b; C (v);
+  f4 (8, 0, 0, 0, 0, 0, 0, 0, 0, u.b); v.b = b; C (v);
+  f4 (9, 0, 0, 0, 0, 0, 0, 0, 0, 0, u.b); v.b = b; C (v);
+#endif
+  f5 (0, u.c); v.c = c; C (v);
+  f5 (1, 0, u.c); v.c = c; C (v);
+  f5 (2, 0, 0, u.c); v.c = c; C (v);
+  f5 (3, 0, 0, 0, u.c); v.c = c; C (v);
+  f5 (4, 0, 0, 0, 0, u.c); v.c = c; C (v);
+  f5 (5, 0, 0, 0, 0, 0, u.c); v.c = c; C (v);
+  f5 (6, 0, 0, 0, 0, 0, 0, u.c); v.c = c; C (v);
+  f5 (7, 0, 0, 0, 0, 0, 0, 0, u.c); v.c = c; C (v);
+  f5 (8, 0, 0, 0, 0, 0, 0, 0, 0, u.c); v.c = c; C (v);
+  f5 (9, 0, 0, 0, 0, 0, 0, 0, 0, 0, u.c); v.c = c; C (v);
+  f6 (0, u.d); v.d = d; C (v);
+  f6 (1, 0, u.d); v.d = d; C (v);
+  f6 (2, 0, 0, u.d); v.d = d; C (v);
+  f6 (3, 0, 0, 0, u.d); v.d = d; C (v);
+  f6 (4, 0, 0, 0, 0, u.d); v.d = d; C (v);
+  f6 (5, 0, 0, 0, 0, 0, u.d); v.d = d; C (v);
+  f6 (6, 0, 0, 0, 0, 0, 0, u.d); v.d = d; C (v);
+  f6 (7, 0, 0, 0, 0, 0, 0, 0, u.d); v.d = d; C (v);
+  f6 (8, 0, 0, 0, 0, 0, 0, 0, 0, u.d); v.d = d; C (v);
+  f6 (9, 0, 0, 0, 0, 0, 0, 0, 0, 0, u.d); v.d = d; C (v);
+  u.e.a = 1.25;
+  u.e.b = 2.75;
+  u.e.c = -3.5;
+  u.e.d = -2.0;
+#undef C
+#define C(x) \
+  do {								\
+    if (u.e.a != x.e.a || u.e.b != x.e.b			\
+	|| u.e.c != x.e.c || u.e.d != x.e.d) __builtin_abort ();\
+    u.e.a++;							\
+    u.e.b--;							\
+    u.e.c++;							\
+    u.e.d--;							\
+  } while (0)
+  v.e = f7 (0, u.e); C (v);
+  v.e = f7 (1, 0.0, u.e); C (v);
+  v.e = f7 (2, 0.0, 0.0, u.e); C (v);
+  v.e = f7 (3, 0.0, 0.0, 0.0, u.e); C (v);
+  v.e = f7 (4, 0.0, 0.0, 0.0, 0.0, u.e); C (v);
+  v.e = f7 (5, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); C (v);
+  v.e = f7 (6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); C (v);
+  v.e = f7 (7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); C (v);
+  v.e = f7 (8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); C (v);
+  v.e = f7 (9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); C (v);
+  v.f = f8 (0, u.f); C (v);
+  v.f = f8 (1, 0.0, u.f); C (v);
+  v.f = f8 (2, 0.0, 0.0, u.f); C (v);
+  v.f = f8 (3, 0.0, 0.0, 0.0, u.f); C (v);
+  v.f = f8 (4, 0.0, 0.0, 0.0, 0.0, u.f); C (v);
+  v.f = f8 (5, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); C (v);
+  v.f = f8 (6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); C (v);
+  v.f = f8 (7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); C (v);
+  v.f = f8 (8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); C (v);
+  v.f = f8 (9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); C (v);
+  f9 (0, u.e); v.e = e; C (v);
+  f9 (1, 0.0, u.e); v.e = e; C (v);
+  f9 (2, 0.0, 0.0, u.e); v.e = e; C (v);
+  f9 (3, 0.0, 0.0, 0.0, u.e); v.e = e; C (v);
+  f9 (4, 0.0, 0.0, 0.0, 0.0, u.e); v.e = e; C (v);
+  f9 (5, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); v.e = e; C (v);
+  f9 (6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); v.e = e; C (v);
+  f9 (7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); v.e = e; C (v);
+  f9 (8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); v.e = e; C (v);
+  f9 (9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.e); v.e = e; C (v);
+  f10 (0, u.f); v.f = f; C (v);
+  f10 (1, 0.0, u.f); v.f = f; C (v);
+  f10 (2, 0.0, 0.0, u.f); v.f = f; C (v);
+  f10 (3, 0.0, 0.0, 0.0, u.f); v.f = f; C (v);
+  f10 (4, 0.0, 0.0, 0.0, 0.0, u.f); v.f = f; C (v);
+  f10 (5, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); v.f = f; C (v);
+  f10 (6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); v.f = f; C (v);
+  f10 (7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); v.f = f; C (v);
+  f10 (8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); v.f = f; C (v);
+  f10 (9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, u.f); v.f = f; C (v);
+  u.g.a = 9.5;
+  u.g.b = 0x5555555555555555ULL;
+#undef C
+#define C(x) \
+  do {								\
+    if (u.e.a != x.e.a || u.e.b != x.e.b) __builtin_abort ();	\
+    u.e.a++;							\
+    u.e.b--;							\
+  } while (0)
+  v.g = f11 (0, u.g); C (v);
+  v.g = f11 (1, 0, 0.0, u.g); C (v);
+  v.g = f11 (2, 0, 0.0, 0, 0.0, u.g); C (v);
+  v.g = f11 (3, 0, 0.0, 0, 0.0, 0, 0.0, u.g); C (v);
+  v.g = f11 (4, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); C (v);
+  v.g = f11 (5, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); C (v);
+  v.g = f11 (6, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); C (v);
+  v.g = f11 (7, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); C (v);
+  v.g = f11 (8, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); C (v);
+  v.g = f11 (9, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); C (v);
+  v.h = f12 (0, u.h); C (v);
+  v.h = f12 (1, 0, 0.0, u.h); C (v);
+  v.h = f12 (2, 0, 0.0, 0, 0.0, u.h); C (v);
+  v.h = f12 (3, 0, 0.0, 0, 0.0, 0, 0.0, u.h); C (v);
+  v.h = f12 (4, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); C (v);
+  v.h = f12 (5, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); C (v);
+  v.h = f12 (6, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); C (v);
+  v.h = f12 (7, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); C (v);
+  v.h = f12 (8, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); C (v);
+  v.h = f12 (9, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); C (v);
+  f13 (0, u.g); v.g = g; C (v);
+  f13 (1, 0, 0.0, u.g); v.g = g; C (v);
+  f13 (2, 0, 0.0, 0, 0.0, u.g); v.g = g; C (v);
+  f13 (3, 0, 0.0, 0, 0.0, 0, 0.0, u.g); v.g = g; C (v);
+  f13 (4, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); v.g = g; C (v);
+  f13 (5, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); v.g = g; C (v);
+  f13 (6, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); v.g = g; C (v);
+  f13 (7, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); v.g = g; C (v);
+  f13 (8, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); v.g = g; C (v);
+  f13 (9, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.g); v.g = g; C (v);
+  f14 (0, u.h); v.h = h; C (v);
+  f14 (1, 0, 0.0, u.h); v.h = h; C (v);
+  f14 (2, 0, 0.0, 0, 0.0, u.h); v.h = h; C (v);
+  f14 (3, 0, 0.0, 0, 0.0, 0, 0.0, u.h); v.h = h; C (v);
+  f14 (4, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); v.h = h; C (v);
+  f14 (5, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); v.h = h; C (v);
+  f14 (6, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); v.h = h; C (v);
+  f14 (7, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); v.h = h; C (v);
+  f14 (8, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); v.h = h; C (v);
+  f14 (9, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, u.h); v.h = h; C (v);
+  return 0;
+}
-- 
2.20.1
From 4982521a900158e5d6d93138e0aafb5f59f75093 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:25:45 +0100
Subject: [PATCH] backport: re PR tree-optimization/92930 (GCC incorrectly
 optimizes away __builtin_apply() calls)

	Backported from mainline
	2019-12-14  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/92930
	* ipa-pure-const.c (special_builtin_state): Don't handle
	BUILT_IN_APPLY.

	* gcc.dg/tree-ssa/pr92930.c: New test.
---
 gcc/ChangeLog                           |  6 ++++++
 gcc/ipa-pure-const.c                    |  1 -
 gcc/testsuite/ChangeLog                 |  5 +++++
 gcc/testsuite/gcc.dg/tree-ssa/pr92930.c | 19 +++++++++++++++++++
 4 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr92930.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 234649d2d29..24983f352a4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-14  Jakub Jelinek  <jakub@redhat.com>
+
+	PR tree-optimization/92930
+	* ipa-pure-const.c (special_builtin_state): Don't handle
+	BUILT_IN_APPLY.
+
 	2019-12-12  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/92904
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index d36d1ba9b73..1017252d91a 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -565,7 +565,6 @@ special_builtin_state (enum pure_const_state_e *state, bool *looping,
 	case BUILT_IN_CXA_END_CLEANUP:
 	case BUILT_IN_EH_COPY_VALUES:
 	case BUILT_IN_FRAME_ADDRESS:
-	case BUILT_IN_APPLY:
 	case BUILT_IN_APPLY_ARGS:
 	case BUILT_IN_ASAN_BEFORE_DYNAMIC_INIT:
 	case BUILT_IN_ASAN_AFTER_DYNAMIC_INIT:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 60c7b17c88e..2fbb648aa09 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-14  Jakub Jelinek  <jakub@redhat.com>
+
+	PR tree-optimization/92930
+	* gcc.dg/tree-ssa/pr92930.c: New test.
+
 	2019-12-12  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/92904
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr92930.c b/gcc/testsuite/gcc.dg/tree-ssa/pr92930.c
new file mode 100644
index 00000000000..67e604b6c50
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr92930.c
@@ -0,0 +1,19 @@
+/* PR tree-optimization/92930 */
+/* { dg-do compile { target untyped_assembly } } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump "__builtin_apply " "optimized" } } */
+/* { dg-final { scan-tree-dump "__builtin_apply_args" "optimized" } } */
+
+void foo (int a, int b, int c, int d, int e, int f, int g);
+
+static void bar (int a, ...)
+{
+  __builtin_apply (foo, __builtin_apply_args (), 20);
+}
+
+int
+main ()
+{
+  bar (1024, 1025, 1026, 1027, 1028, 1029, 1030);
+  return 0;
+}
-- 
2.20.1
From 4ece9571bcb003148a4c7c8e909da2c1adf60292 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 13:45:52 +0100
Subject: [PATCH] backport: re PR ipa/92357 (ICE in IPA pass fnsummary in
 openmp offload)

	Backported from mainline
	2019-12-14  Jakub Jelinek  <jakub@redhat.com>

	PR ipa/92357
	* ipa-fnsummary.c (ipa_fn_summary_write): Use
	lto_symtab_encoder_iterator with lsei_start_function_in_partition and
	lsei_next_function_in_partition instead of walking all cgraph nodes
	in encoder.
---
 gcc/ChangeLog       |  6 ++++++
 gcc/ipa-fnsummary.c | 18 +++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 24983f352a4..b487b289224 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -3,6 +3,12 @@
 	Backported from mainline
 	2019-12-14  Jakub Jelinek  <jakub@redhat.com>
 
+	PR ipa/92357
+	* ipa-fnsummary.c (ipa_fn_summary_write): Use
+	lto_symtab_encoder_iterator with lsei_start_function_in_partition and
+	lsei_next_function_in_partition instead of walking all cgraph nodes
+	in encoder.
+
 	PR tree-optimization/92930
 	* ipa-pure-const.c (special_builtin_state): Don't handle
 	BUILT_IN_APPLY.
diff --git a/gcc/ipa-fnsummary.c b/gcc/ipa-fnsummary.c
index bdf9ba1c921..3b58a5441ab 100644
--- a/gcc/ipa-fnsummary.c
+++ b/gcc/ipa-fnsummary.c
@@ -3413,24 +3413,24 @@ static void
 ipa_fn_summary_write (void)
 {
   struct output_block *ob = create_output_block (LTO_section_ipa_fn_summary);
+  lto_symtab_encoder_iterator lsei;
   lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder;
   unsigned int count = 0;
-  int i;
 
-  for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
+  for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
+       lsei_next_function_in_partition (&lsei))
     {
-      symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
-      cgraph_node *cnode = dyn_cast <cgraph_node *> (snode);
-      if (cnode && cnode->definition && !cnode->alias)
+      cgraph_node *cnode = lsei_cgraph_node (lsei);
+      if (cnode->definition && !cnode->alias)
 	count++;
     }
   streamer_write_uhwi (ob, count);
 
-  for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
+  for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei);
+       lsei_next_function_in_partition (&lsei))
     {
-      symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
-      cgraph_node *cnode = dyn_cast <cgraph_node *> (snode);
-      if (cnode && cnode->definition && !cnode->alias)
+      cgraph_node *cnode = lsei_cgraph_node (lsei);
+      if (cnode->definition && !cnode->alias)
 	{
 	  struct ipa_fn_summary *info = ipa_fn_summaries->get (cnode);
 	  struct bitpack_d bp;
-- 
2.20.1
From b69684fdac2ac4bd128150631de6391c786e2184 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:26:52 +0100
Subject: [PATCH] backport: re PR fortran/92977 (ICE in gfc_trans_omp_atomic,
 at fortran/trans-openmp.c:3526)

	Backported from mainline
	2019-12-19  Jakub Jelinek  <jakub@redhat.com>

 	PR fortran/92977
	* frontend-passes.c (call_external_blas): Use || instead of |.

	PR fortran/92977
	* frontend-passes.c (in_omp_atomic): New variable.
	(cfe_expr_0, matmul_to_var_expr, matmul_temp_args,
	inline_matmul_assign, call_external_blas): Don't optimize in
	EXEC_OMP_ATOMIC.
	(optimize_namespace): Clear in_omp_atomic.
	(gfc_code_walker): Set in_omp_atomic for EXEC_OMP_ATOMIC, save/restore
	it around.

	* gfortran.dg/gomp/pr92977.f90: New test.
---
 gcc/fortran/ChangeLog                      | 10 ++++++++++
 gcc/fortran/frontend-passes.c              | 22 +++++++++++++++++-----
 gcc/testsuite/ChangeLog                    |  5 +++++
 gcc/testsuite/gfortran.dg/gomp/pr92977.f90 | 15 +++++++++++++++
 4 files changed, 47 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/pr92977.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index b7f8ababc37..e922c1ee652 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,6 +1,16 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-19  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/92977
+	* frontend-passes.c (in_omp_atomic): New variable.
+	(cfe_expr_0, matmul_to_var_expr, matmul_temp_args,
+	inline_matmul_assign): Don't optimize in EXEC_OMP_ATOMIC.
+	(optimize_namespace): Clear in_omp_atomic.
+	(gfc_code_walker): Set in_omp_atomic for EXEC_OMP_ATOMIC, save/restore
+	it around.
+
 	2019-12-11  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/92899
diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 2c1aafebb5f..be0fd0f7e6c 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -93,6 +93,10 @@ static int forall_level;
 
 static bool in_omp_workshare;
 
+/* Keep track of whether we are within an OMP atomic.  */
+
+static bool in_omp_atomic;
+
 /* Keep track of whether we are within a WHERE statement.  */
 
 static bool in_where;
@@ -864,9 +868,9 @@ cfe_expr_0 (gfc_expr **e, int *walk_subtrees,
   gfc_expr *newvar;
   gfc_expr **ei, **ej;
 
-  /* Don't do this optimization within OMP workshare or ASSOC lists.  */
+  /* Don't do this optimization within OMP workshare/atomic or ASSOC lists.  */
 
-  if (in_omp_workshare || in_assoc_list)
+  if (in_omp_workshare || in_omp_atomic || in_assoc_list)
     {
       *walk_subtrees = 0;
       return 0;
@@ -1415,6 +1419,7 @@ optimize_namespace (gfc_namespace *ns)
   iterator_level = 0;
   in_assoc_list = false;
   in_omp_workshare = false;
+  in_omp_atomic = false;
 
   if (flag_frontend_optimize)
     {
@@ -2751,7 +2756,7 @@ matmul_to_var_expr (gfc_expr **ep, int *walk_subtrees ATTRIBUTE_UNUSED,
     return 0;
 
   if (forall_level > 0 || iterator_level > 0 || in_omp_workshare
-      || in_where || in_assoc_list)
+      || in_omp_atomic || in_where || in_assoc_list)
     return 0;
 
   /* Check if this is already in the form c = matmul(a,b).  */
@@ -2813,7 +2818,7 @@ matmul_temp_args (gfc_code **c, int *walk_subtrees ATTRIBUTE_UNUSED,
     return 0;
 
   if (forall_level > 0 || iterator_level > 0 || in_omp_workshare
-      || in_where)
+      || in_omp_atomic || in_where)
     return 0;
 
   /* This has some duplication with inline_matmul_assign.  This
@@ -3743,7 +3748,7 @@ inline_matmul_assign (gfc_code **c, int *walk_subtrees,
   /* For now don't do anything in OpenMP workshare, it confuses
      its translation, which expects only the allowed statements in there.
      We should figure out how to parallelize this eventually.  */
-  if (in_omp_workshare)
+  if (in_omp_workshare || in_omp_atomic)
     return 0;
 
   expr1 = co->expr1;
@@ -4555,6 +4560,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 	  gfc_code *co;
 	  gfc_association_list *alist;
 	  bool saved_in_omp_workshare;
+	  bool saved_in_omp_atomic;
 	  bool saved_in_where;
 
 	  /* There might be statement insertions before the current code,
@@ -4562,6 +4568,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 
 	  co = *c;
 	  saved_in_omp_workshare = in_omp_workshare;
+	  saved_in_omp_atomic = in_omp_atomic;
 	  saved_in_where = in_where;
 
 	  switch (co->op)
@@ -4759,6 +4766,10 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 	      WALK_SUBEXPR (co->ext.dt->extra_comma);
 	      break;
 
+	    case EXEC_OMP_ATOMIC:
+	      in_omp_atomic = true;
+	      break;
+
 	    case EXEC_OMP_PARALLEL:
 	    case EXEC_OMP_PARALLEL_DO:
 	    case EXEC_OMP_PARALLEL_DO_SIMD:
@@ -4876,6 +4887,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 	    select_level --;
   
 	  in_omp_workshare = saved_in_omp_workshare;
+	  in_omp_atomic = saved_in_omp_atomic;
 	  in_where = saved_in_where;
 	}
     }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2fbb648aa09..358c82ec4d3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-19  Jakub Jelinek  <jakub@redhat.com>
+
+ 	PR fortran/92977
+	* gfortran.dg/gomp/pr92977.f90: New test.
+
 	2019-12-14  Jakub Jelinek  <jakub@redhat.com>
 
 	PR tree-optimization/92930
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr92977.f90 b/gcc/testsuite/gfortran.dg/gomp/pr92977.f90
new file mode 100644
index 00000000000..0c31f470a94
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/pr92977.f90
@@ -0,0 +1,15 @@
+! PR fortran/92977
+! { dg-do compile }
+! { dg-additional-options "-O2" }
+
+program pr92977
+  integer :: n = 1
+  integer :: a
+!$omp atomic write
+  a = f(n) - f(n)
+contains
+  integer function f(x)
+    integer, intent(in) :: x
+    f = x
+  end
+end
-- 
2.20.1
From 7d35cad11152895d239f103f1fffbd6f0cb58c8b Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:27:21 +0100
Subject: [PATCH] re PR c++/92992 (Side-effects dropped when decltype(nullptr)
 typed expression is passed to ellipsis)

	PR c++/92992
	* call.c (convert_arg_to_ellipsis): For decltype(nullptr) arguments
	that have side-effects use cp_build_compound_expr.

	* g++.dg/cpp0x/nullptr45.C: New test.
---
 gcc/cp/ChangeLog                       | 145 +++++++++++++++++++++++++
 gcc/cp/call.c                          |   7 +-
 gcc/testsuite/ChangeLog                |   5 +
 gcc/testsuite/g++.dg/cpp0x/nullptr45.C |  24 ++++
 4 files changed, 180 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/nullptr45.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a114b92fe2e..373fa734f40 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,148 @@
+<<<<<<<
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2019-12-06  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92831 - CWG 1299, not extending temporary lifetime for ?:
+	* cp-tree.h (extend_ref_init_temps): Add a new argument with NULL
+	default arg.
+	* call.c (set_up_extended_ref_temp): Add COND_GUARD argument, pass it
+	down to extend_ref_init_temps.  Before pushing cleanup, if COND_GUARD
+	is non-NULL, create a bool temporary if needed, initialize to false
+	and guard the cleanup with the temporary being true.
+	(extend_ref_init_temps_1): Add COND_GUARD argument, pass it down
+	to recursive calls and set_up_extended_ref_temp.  Handle COND_EXPR.
+	(extend_ref_init_temps): Add COND_GUARD argument, pass it down to
+	recursive calls and to extend_ref_init_temps_1.
+
+	2019-12-03  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92732
+	* typeck2.c (digest_nsdmi_init): For bitfields, use
+	DECL_BIT_FIELD_TYPE instead of TREE_TYPE.
+
+	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/60228
+	* parser.c (cp_parser_omp_declare_reduction_exprs): If
+	processing_template_decl, wrap the combiner or initializer
+	into EXPR_STMT.
+	* decl.c (start_preparsed_function): Don't start a lambda scope
+	for DECL_OMP_DECLARE_REDUCTION_P functions.
+	(finish_function): Don't finish a lambda scope for
+	DECL_OMP_DECLARE_REDUCTION_P functions, nor cp_fold_function
+	them nor cp_genericize them.
+	* mangle.c (decl_mangling_context): Look through
+	DECL_OMP_DECLARE_REDUCTION_P functions.
+	* semantics.c (expand_or_defer_fn_1): For DECL_OMP_DECLARE_REDUCTION_P
+	functions, use tentative linkage, don't keep their bodies with
+	-fkeep-inline-functions and return false at the end.
+
+	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92524
+	* tree.c (replace_placeholders_r): Don't walk constructor elts with
+	RANGE_EXPR indexes.
+
+	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92648
+	* parser.c (cp_parser_std_attribute): For unknown attributes,
+	skip balanced token seq instead of trying to parse
+	attribute-argument-clause as expression list.
+
+	PR c++/61414
+	* class.c (enum_to_min_precision): New hash_map.
+	(enum_min_precision): New function.
+	(check_bitfield_decl): Use it.
+
+	2019-11-21  Jakub Jelinek  <jakub@redhat.com>
+		    Jason Merrill  <jason@redhat.com>
+
+	PR c++/90842
+	* parser.c (cp_parser_decl_specifier_seq): For concept or typedef
+	break early if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR.
+	For type specifiers, set CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
+	if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR is set.
+
+=======
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	2019-12-06  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92831 - CWG 1299, not extending temporary lifetime for ?:
+	* cp-tree.h (extend_ref_init_temps): Add a new argument with NULL
+	default arg.
+	* call.c (set_up_extended_ref_temp): Add COND_GUARD argument, pass it
+	down to extend_ref_init_temps.  Before pushing cleanup, if COND_GUARD
+	is non-NULL, create a bool temporary if needed, initialize to false
+	and guard the cleanup with the temporary being true.
+	(extend_ref_init_temps_1): Add COND_GUARD argument, pass it down
+	to recursive calls and set_up_extended_ref_temp.  Handle COND_EXPR.
+	(extend_ref_init_temps): Add COND_GUARD argument, pass it down to
+	recursive calls and to extend_ref_init_temps_1.
+
+	2019-12-03  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92732
+	* typeck2.c (digest_nsdmi_init): For bitfields, use
+	DECL_BIT_FIELD_TYPE instead of TREE_TYPE.
+
+	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/60228
+	* parser.c (cp_parser_omp_declare_reduction_exprs): If
+	processing_template_decl, wrap the combiner or initializer
+	into EXPR_STMT.
+	* decl.c (start_preparsed_function): Don't start a lambda scope
+	for DECL_OMP_DECLARE_REDUCTION_P functions.
+	(finish_function): Don't finish a lambda scope for
+	DECL_OMP_DECLARE_REDUCTION_P functions, nor cp_fold_function
+	them nor cp_genericize them.
+	* mangle.c (decl_mangling_context): Look through
+	DECL_OMP_DECLARE_REDUCTION_P functions.
+	* semantics.c (expand_or_defer_fn_1): For DECL_OMP_DECLARE_REDUCTION_P
+	functions, use tentative linkage, don't keep their bodies with
+	-fkeep-inline-functions and return false at the end.
+
+	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92524
+	* tree.c (replace_placeholders_r): Don't walk constructor elts with
+	RANGE_EXPR indexes.
+
+	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92648
+	* parser.c (cp_parser_std_attribute): For unknown attributes,
+	skip balanced token seq instead of trying to parse
+	attribute-argument-clause as expression list.
+
+	PR c++/61414
+	* class.c (enum_to_min_precision): New hash_map.
+	(enum_min_precision): New function.
+	(check_bitfield_decl): Use it.
+
+	2019-11-21  Jakub Jelinek  <jakub@redhat.com>
+		    Jason Merrill  <jason@redhat.com>
+
+	PR c++/90842
+	* parser.c (cp_parser_decl_specifier_seq): For concept or typedef
+	break early if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR.
+	For type specifiers, set CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
+	if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR is set.
+
+>>>>>>>
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2019-12-20  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92992
+	* call.c (convert_arg_to_ellipsis): For decltype(nullptr) arguments
+	that have side-effects use cp_build_compound_expr.
+
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 11bd5420fe7..0b04eb9629c 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7180,7 +7180,12 @@ convert_arg_to_ellipsis (tree arg, tsubst_flags_t complain)
       arg = convert_to_real_nofold (double_type_node, arg);
     }
   else if (NULLPTR_TYPE_P (arg_type))
-    arg = null_pointer_node;
+    {
+      if (TREE_SIDE_EFFECTS (arg))
+	arg = cp_build_compound_expr (arg, null_pointer_node, complain);
+      else
+	arg = null_pointer_node;
+    }
   else if (INTEGRAL_OR_ENUMERATION_TYPE_P (arg_type))
     {
       if (SCOPED_ENUM_P (arg_type))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 358c82ec4d3..1d4cb65b82d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-20  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92992
+	* g++.dg/cpp0x/nullptr45.C: New test.
+
 	2019-12-19  Jakub Jelinek  <jakub@redhat.com>
 
  	PR fortran/92977
diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr45.C b/gcc/testsuite/g++.dg/cpp0x/nullptr45.C
new file mode 100644
index 00000000000..3ff226803df
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/nullptr45.C
@@ -0,0 +1,24 @@
+// PR c++/92992
+// { dg-do run { target c++11 } }
+
+int a;
+
+void
+bar (int, ...)
+{
+}
+
+decltype (nullptr)
+baz ()
+{
+  a++;
+  return nullptr;
+}
+
+int
+main ()
+{
+  bar (0, baz ());
+  if (a != 1)
+    __builtin_abort ();
+}
-- 
2.20.1
From becbae00641077f7104d16b4565c1d64df5fafc6 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:32:20 +0100
Subject: [PATCH] re PR c++/92438 (Function declaration parsed incorrectly with
 `-std=c++1z`)

	PR c++/92438
	* parser.c (cp_parser_constructor_declarator_p): If open paren
	is followed by RID_ATTRIBUTE, skip over the attribute tokens and
	try to parse type specifier.

	* g++.dg/ext/attrib61.C: New test.
---
 gcc/cp/ChangeLog                    | 139 ----------------------------
 gcc/cp/parser.c                     |  17 +++-
 gcc/testsuite/ChangeLog             |   5 +
 gcc/testsuite/g++.dg/ext/attrib61.C |  26 ++++++
 4 files changed, 47 insertions(+), 140 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/attrib61.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 373fa734f40..805007da211 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,139 +1,3 @@
-<<<<<<<
-2020-02-14  Jakub Jelinek  <jakub@redhat.com>
-
-	Backported from mainline
-	2019-12-06  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/92831 - CWG 1299, not extending temporary lifetime for ?:
-	* cp-tree.h (extend_ref_init_temps): Add a new argument with NULL
-	default arg.
-	* call.c (set_up_extended_ref_temp): Add COND_GUARD argument, pass it
-	down to extend_ref_init_temps.  Before pushing cleanup, if COND_GUARD
-	is non-NULL, create a bool temporary if needed, initialize to false
-	and guard the cleanup with the temporary being true.
-	(extend_ref_init_temps_1): Add COND_GUARD argument, pass it down
-	to recursive calls and set_up_extended_ref_temp.  Handle COND_EXPR.
-	(extend_ref_init_temps): Add COND_GUARD argument, pass it down to
-	recursive calls and to extend_ref_init_temps_1.
-
-	2019-12-03  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/92732
-	* typeck2.c (digest_nsdmi_init): For bitfields, use
-	DECL_BIT_FIELD_TYPE instead of TREE_TYPE.
-
-	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/60228
-	* parser.c (cp_parser_omp_declare_reduction_exprs): If
-	processing_template_decl, wrap the combiner or initializer
-	into EXPR_STMT.
-	* decl.c (start_preparsed_function): Don't start a lambda scope
-	for DECL_OMP_DECLARE_REDUCTION_P functions.
-	(finish_function): Don't finish a lambda scope for
-	DECL_OMP_DECLARE_REDUCTION_P functions, nor cp_fold_function
-	them nor cp_genericize them.
-	* mangle.c (decl_mangling_context): Look through
-	DECL_OMP_DECLARE_REDUCTION_P functions.
-	* semantics.c (expand_or_defer_fn_1): For DECL_OMP_DECLARE_REDUCTION_P
-	functions, use tentative linkage, don't keep their bodies with
-	-fkeep-inline-functions and return false at the end.
-
-	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/92524
-	* tree.c (replace_placeholders_r): Don't walk constructor elts with
-	RANGE_EXPR indexes.
-
-	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/92648
-	* parser.c (cp_parser_std_attribute): For unknown attributes,
-	skip balanced token seq instead of trying to parse
-	attribute-argument-clause as expression list.
-
-	PR c++/61414
-	* class.c (enum_to_min_precision): New hash_map.
-	(enum_min_precision): New function.
-	(check_bitfield_decl): Use it.
-
-	2019-11-21  Jakub Jelinek  <jakub@redhat.com>
-		    Jason Merrill  <jason@redhat.com>
-
-	PR c++/90842
-	* parser.c (cp_parser_decl_specifier_seq): For concept or typedef
-	break early if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR.
-	For type specifiers, set CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
-	if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR is set.
-
-=======
-2020-02-14  Jakub Jelinek  <jakub@redhat.com>
-
-	2019-12-06  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/92831 - CWG 1299, not extending temporary lifetime for ?:
-	* cp-tree.h (extend_ref_init_temps): Add a new argument with NULL
-	default arg.
-	* call.c (set_up_extended_ref_temp): Add COND_GUARD argument, pass it
-	down to extend_ref_init_temps.  Before pushing cleanup, if COND_GUARD
-	is non-NULL, create a bool temporary if needed, initialize to false
-	and guard the cleanup with the temporary being true.
-	(extend_ref_init_temps_1): Add COND_GUARD argument, pass it down
-	to recursive calls and set_up_extended_ref_temp.  Handle COND_EXPR.
-	(extend_ref_init_temps): Add COND_GUARD argument, pass it down to
-	recursive calls and to extend_ref_init_temps_1.
-
-	2019-12-03  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/92732
-	* typeck2.c (digest_nsdmi_init): For bitfields, use
-	DECL_BIT_FIELD_TYPE instead of TREE_TYPE.
-
-	2019-11-29  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/60228
-	* parser.c (cp_parser_omp_declare_reduction_exprs): If
-	processing_template_decl, wrap the combiner or initializer
-	into EXPR_STMT.
-	* decl.c (start_preparsed_function): Don't start a lambda scope
-	for DECL_OMP_DECLARE_REDUCTION_P functions.
-	(finish_function): Don't finish a lambda scope for
-	DECL_OMP_DECLARE_REDUCTION_P functions, nor cp_fold_function
-	them nor cp_genericize them.
-	* mangle.c (decl_mangling_context): Look through
-	DECL_OMP_DECLARE_REDUCTION_P functions.
-	* semantics.c (expand_or_defer_fn_1): For DECL_OMP_DECLARE_REDUCTION_P
-	functions, use tentative linkage, don't keep their bodies with
-	-fkeep-inline-functions and return false at the end.
-
-	2019-11-27  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/92524
-	* tree.c (replace_placeholders_r): Don't walk constructor elts with
-	RANGE_EXPR indexes.
-
-	2019-11-26  Jakub Jelinek  <jakub@redhat.com>
-
-	PR c++/92648
-	* parser.c (cp_parser_std_attribute): For unknown attributes,
-	skip balanced token seq instead of trying to parse
-	attribute-argument-clause as expression list.
-
-	PR c++/61414
-	* class.c (enum_to_min_precision): New hash_map.
-	(enum_min_precision): New function.
-	(check_bitfield_decl): Use it.
-
-	2019-11-21  Jakub Jelinek  <jakub@redhat.com>
-		    Jason Merrill  <jason@redhat.com>
-
-	PR c++/90842
-	* parser.c (cp_parser_decl_specifier_seq): For concept or typedef
-	break early if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR.
-	For type specifiers, set CP_PARSER_FLAGS_NO_TYPE_DEFINITIONS
-	if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR is set.
-
->>>>>>>
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
@@ -143,9 +7,6 @@
 	* call.c (convert_arg_to_ellipsis): For decltype(nullptr) arguments
 	that have side-effects use cp_build_compound_expr.
 
-2020-02-14  Jakub Jelinek  <jakub@redhat.com>
-
-	Backported from mainline
 	2019-12-03  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/92732
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f7ecfcdc9a5..8c5b653c055 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -26811,12 +26811,27 @@ cp_parser_constructor_declarator_p (cp_parser *parser, bool friend_p)
 	  /* A parameter declaration begins with a decl-specifier,
 	     which is either the "attribute" keyword, a storage class
 	     specifier, or (usually) a type-specifier.  */
-	  && !cp_lexer_next_token_is_decl_specifier_keyword (parser->lexer))
+	  && (!cp_lexer_next_token_is_decl_specifier_keyword (parser->lexer)
+	      /* GNU attributes can actually appear both at the start of
+		 a parameter and parenthesized declarator.
+		 S (__attribute__((unused)) int);
+		 is a constructor, but
+		 S (__attribute__((unused)) foo) (int);
+		 is a function declaration.  */
+	      || (cp_parser_allow_gnu_extensions_p (parser)
+		  && cp_next_tokens_can_be_gnu_attribute_p (parser))))
 	{
 	  tree type;
 	  tree pushed_scope = NULL_TREE;
 	  unsigned saved_num_template_parameter_lists;
 
+	  if (cp_next_tokens_can_be_gnu_attribute_p (parser))
+	    {
+	      unsigned int n = cp_parser_skip_gnu_attributes_opt (parser, 1);
+	      while (--n)
+		cp_lexer_consume_token (parser->lexer);
+	    }
+
 	  /* Names appearing in the type-specifier should be looked up
 	     in the scope of the class.  */
 	  if (current_class_type)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1d4cb65b82d..81a4ec4100e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92438
+	* g++.dg/ext/attrib61.C: New test.
+
 	2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/92992
diff --git a/gcc/testsuite/g++.dg/ext/attrib61.C b/gcc/testsuite/g++.dg/ext/attrib61.C
new file mode 100644
index 00000000000..231830616ea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/attrib61.C
@@ -0,0 +1,26 @@
+// PR c++/92438
+// { dg-do compile }
+
+typedef struct S { int x; } T;
+T (foo) (T x);
+T __attribute__((unused)) bar (T x);
+struct S (__attribute__((unused)) baz) (T x);
+T (__attribute__((unused)) qux) (T x);
+
+struct U
+{
+  U (__attribute__((unused)) int);
+  U (__attribute__((unused)) corge) (int);
+};
+
+void
+test ()
+{
+  T a, b;
+  a = foo (b);
+  b = bar (a);
+  a = baz (b);
+  b = qux (a);
+  U u (5);
+  U v = u.corge (3);
+}
-- 
2.20.1
From c343d4aab243cb477c65c6d0c37b1a6cdd2f858e Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 13:57:45 +0100
Subject: [PATCH] re PR libgomp/93065 (libgomp: destructor missing to delete
 goacc_cleanup_key)

	PR libgomp/93065
	* oacc-init.c (goacc_runtime_deinitialize): New function.
---
 libgomp/ChangeLog   | 5 +++++
 libgomp/oacc-init.c | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 889315705a8..33827bd1ac5 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2019-12-31  Ayush Mittal  <ayush.m@samsung.com>
+
+	PR libgomp/93065
+	* oacc-init.c (goacc_runtime_deinitialize): New function.
+
 	2019-12-11  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/92899
diff --git a/libgomp/oacc-init.c b/libgomp/oacc-init.c
index 8db24b17d29..093a9993847 100644
--- a/libgomp/oacc-init.c
+++ b/libgomp/oacc-init.c
@@ -657,6 +657,15 @@ goacc_runtime_initialize (void)
   goacc_host_init ();
 }
 
+static void __attribute__((destructor))
+goacc_runtime_deinitialize (void)
+{
+#if !(defined HAVE_TLS || defined USE_EMUTLS)
+  pthread_key_delete (goacc_tls_key);
+#endif
+  pthread_key_delete (goacc_cleanup_key);
+}
+
 /* Compiler helper functions */
 
 attribute_hidden void
-- 
2.20.1
From f01dfd67820e6a8254e6bf9ea242bf86134486ff Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:33:44 +0100
Subject: [PATCH] re PR ipa/93087 (Bogus `-Wsuggest-attribute=cold` on function
 already marked as `__attribute__((cold))`)

	PR ipa/93087
	* predict.c (compute_function_frequency): Don't call
	warn_function_cold on functions that already have cold attribute.

	* c-c++-common/cold-1.c: New test.
---
 gcc/ChangeLog                       |  6 ++++++
 gcc/predict.c                       | 12 +++++++-----
 gcc/testsuite/ChangeLog             |  5 +++++
 gcc/testsuite/c-c++-common/cold-1.c | 22 ++++++++++++++++++++++
 4 files changed, 40 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/cold-1.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b487b289224..b038bc9179e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-02  Jakub Jelinek  <jakub@redhat.com>
+
+	PR ipa/93087
+	* predict.c (compute_function_frequency): Don't call
+	warn_function_cold on functions that already have cold attribute.
+
 	2019-12-14  Jakub Jelinek  <jakub@redhat.com>
 
 	PR ipa/92357
diff --git a/gcc/predict.c b/gcc/predict.c
index 019ff9e44cf..e996dbf46cd 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -3740,12 +3740,14 @@ compute_function_frequency (void)
   if (profile_status_for_fn (cfun) != PROFILE_READ)
     {
       int flags = flags_from_decl_or_type (current_function_decl);
-      if ((ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa_p ()
-	   && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa() == profile_count::zero ())
-	  || lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl))
-	     != NULL)
+      if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl))
+	  != NULL)
+	node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
+      else if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa_p ()
+	       && (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa ()
+		   == profile_count::zero ()))
 	{
-          node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
+	  node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
 	  warn_function_cold (current_function_decl);
 	}
       else if (lookup_attribute ("hot", DECL_ATTRIBUTES (current_function_decl))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 81a4ec4100e..4d6c8c5e0f8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-02  Jakub Jelinek  <jakub@redhat.com>
+
+	PR ipa/93087
+	* c-c++-common/cold-1.c: New test.
+
 	2019-12-26  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/92438
diff --git a/gcc/testsuite/c-c++-common/cold-1.c b/gcc/testsuite/c-c++-common/cold-1.c
new file mode 100644
index 00000000000..3493623e1eb
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/cold-1.c
@@ -0,0 +1,22 @@
+/* PR ipa/93087 */
+/* { dg-do compile { target nonpic } } */
+/* { dg-options "-O1 -Wsuggest-attribute=cold" } */
+
+extern void *getdata (void);
+extern int set_error (char const *message) __attribute__((cold));
+
+__attribute__((cold)) int
+set_nomem (void)	/* { dg-bogus "function might be candidate for attribute 'cold'" } */
+{
+  return set_error ("Allocation failed");
+}
+
+void *
+getdata_or_set_error (void)
+{
+  void *result;
+  result = getdata ();
+  if (!result)
+    set_nomem ();
+  return result;
+}
-- 
2.20.1
From 1ccdfea80e8ead4936c35b5eb736dc407a07fb32 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:34:43 +0100
Subject: [PATCH] re PR rtl-optimization/93088 (Compile time hog on
 gcc/testsuite/gcc.target/i386/pr56348.c w/ -O3 -funroll-loops
 -fno-tree-dominator-opts -fno-tree-vrp)

	PR rtl-optimization/93088
	* loop-iv.c (find_single_def_src): Punt after looking through
	128 reg copies for regs with single definitions.  Move definitions
	to first uses.

	* gcc.target/i386/pr93088.c: New test.
---
 gcc/ChangeLog                           |  7 +++++++
 gcc/loop-iv.c                           | 15 +++++++--------
 gcc/testsuite/ChangeLog                 |  5 +++++
 gcc/testsuite/gcc.target/i386/pr93088.c |  5 +++++
 4 files changed, 24 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr93088.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b038bc9179e..d9dbcf17e0a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-03  Jakub Jelinek  <jakub@redhat.com>
+
+	PR rtl-optimization/93088
+	* loop-iv.c (find_single_def_src): Punt after looking through
+	128 reg copies for regs with single definitions.  Move definitions
+	to first uses.
+
 	2020-01-02  Jakub Jelinek  <jakub@redhat.com>
 
 	PR ipa/93087
diff --git a/gcc/loop-iv.c b/gcc/loop-iv.c
index 8f476819728..fb09e0f6e54 100644
--- a/gcc/loop-iv.c
+++ b/gcc/loop-iv.c
@@ -1380,24 +1380,23 @@ simple_rhs_p (rtx rhs)
 static rtx
 find_single_def_src (unsigned int regno)
 {
-  df_ref adef;
-  rtx set, src;
+  rtx src = NULL_RTX;
 
-  for (;;)
+  /* Don't look through unbounded number of single definition REG copies,
+     there might be loops for sources with uninitialized variables.  */
+  for (int cnt = 0; cnt < 128; cnt++)
     {
-      rtx note;
-      adef = DF_REG_DEF_CHAIN (regno);
+      df_ref adef = DF_REG_DEF_CHAIN (regno);
       if (adef == NULL || DF_REF_NEXT_REG (adef) != NULL
 	  || DF_REF_IS_ARTIFICIAL (adef))
 	return NULL_RTX;
 
-      set = single_set (DF_REF_INSN (adef));
+      rtx set = single_set (DF_REF_INSN (adef));
       if (set == NULL || !REG_P (SET_DEST (set))
 	  || REGNO (SET_DEST (set)) != regno)
 	return NULL_RTX;
 
-      note = find_reg_equal_equiv_note (DF_REF_INSN (adef));
-
+      rtx note = find_reg_equal_equiv_note (DF_REF_INSN (adef));
       if (note && function_invariant_p (XEXP (note, 0)))
 	{
 	  src = XEXP (note, 0);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4d6c8c5e0f8..b7a660c1bb2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-03  Jakub Jelinek  <jakub@redhat.com>
+
+	PR rtl-optimization/93088
+	* gcc.target/i386/pr93088.c: New test.
+
 	2020-01-02  Jakub Jelinek  <jakub@redhat.com>
 
 	PR ipa/93087
diff --git a/gcc/testsuite/gcc.target/i386/pr93088.c b/gcc/testsuite/gcc.target/i386/pr93088.c
new file mode 100644
index 00000000000..dc986cfaa80
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr93088.c
@@ -0,0 +1,5 @@
+/* PR rtl-optimization/93088 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -funroll-loops -fno-tree-dominator-opts -fno-tree-vrp -w" } */
+
+#include "pr56348.c"
-- 
2.20.1
From 04e48115ac4f4eab20525280653e8ff985f1a3d8 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:35:59 +0100
Subject: [PATCH] re PR inline-asm/93202 ([RISCV] ICE when using inline asm 'h'
 operand modifier)

	PR inline-asm/93202
	* config/riscv/riscv.c (riscv_print_operand_reloc): Use
	output_operand_lossage instead of gcc_unreachable.
	* doc/md.texi (riscv f constraint): Fix typo.

	* gcc.target/riscv/pr93202.c: New test.
---
 gcc/ChangeLog                            |  7 +++++++
 gcc/config/riscv/riscv.c                 |  3 ++-
 gcc/doc/md.texi                          |  2 +-
 gcc/testsuite/ChangeLog                  |  5 +++++
 gcc/testsuite/gcc.target/riscv/pr93202.c | 10 ++++++++++
 5 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/pr93202.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d9dbcf17e0a..e17c88b2166 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-09  Jakub Jelinek  <jakub@redhat.com>
+
+	PR inline-asm/93202
+	* config/riscv/riscv.c (riscv_print_operand_reloc): Use
+	output_operand_lossage instead of gcc_unreachable.
+	* doc/md.texi (riscv f constraint): Fix typo.
+
 	2020-01-03  Jakub Jelinek  <jakub@redhat.com>
 
 	PR rtl-optimization/93088
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 606d9aa7441..4739e8d8800 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -2932,7 +2932,8 @@ riscv_print_operand_reloc (FILE *file, rtx op, bool hi_reloc)
 	break;
 
       default:
-	gcc_unreachable ();
+	output_operand_lossage ("invalid use of '%%%c'", hi_reloc ? 'h' : 'R');
+	return;
     }
 
   fprintf (file, "%s(", reloc);
diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index 30f1e09a310..48a76ac736d 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -3392,7 +3392,7 @@ The @code{X} register.
 @table @code
 
 @item f
-A floating-point register (if availiable).
+A floating-point register (if available).
 
 @item I
 An I-type 12-bit signed immediate.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b7a660c1bb2..7c44c5eeff1 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-09  Jakub Jelinek  <jakub@redhat.com>
+
+	PR inline-asm/93202
+	* gcc.target/riscv/pr93202.c: New test.
+
 	2020-01-03  Jakub Jelinek  <jakub@redhat.com>
 
 	PR rtl-optimization/93088
diff --git a/gcc/testsuite/gcc.target/riscv/pr93202.c b/gcc/testsuite/gcc.target/riscv/pr93202.c
new file mode 100644
index 00000000000..d8091b93179
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr93202.c
@@ -0,0 +1,10 @@
+/* PR inline-asm/93202 */
+/* { dg-do compile { target fpic } } */
+/* { dg-options "-fpic" } */
+
+void
+foo (void)
+{
+  asm volatile ("%h0" :: "i" (&foo));	/* { dg-error "invalid use of '%h'" } */
+  asm volatile ("%R0" :: "i" (&foo));	/* { dg-error "invalid use of '%R'" } */
+}
-- 
2.20.1
From ef2e6135591f2a197d4fb8a7dbb8425a9d2df85e Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:39:57 +0100
Subject: [PATCH] c++: Fix deprecated attribute handling on templates (PR
 c++/93228)

As the following testcase shows, when deprecated attribute is on a template,
we'd never print the message if any, because the attribute is not
present on the TEMPLATE_DECL with which warn_deprecated_use is called,
but on its DECL_TEMPLATE_RESULT or its type.

2020-01-17  Jakub Jelinek  <jakub@redhat.com>

	PR c++/93228
	* parser.c (cp_parser_template_name): Look up deprecated attribute
	in DECL_TEMPLATE_RESULT or its type's attributes.

	* g++.dg/cpp1y/attr-deprecated-3.C: New test.
---
 gcc/cp/ChangeLog                               |  6 ++++++
 gcc/cp/parser.c                                | 12 +++++++++++-
 gcc/testsuite/ChangeLog                        |  5 +++++
 gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C | 13 +++++++++++++
 4 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 805007da211..99fc3abc1eb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-17  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/93228
+	* parser.c (cp_parser_template_name): Look up deprecated attribute
+	in DECL_TEMPLATE_RESULT or its type's attributes.
+
 	2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/92992
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 8c5b653c055..f2983b6102d 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -16166,7 +16166,17 @@ cp_parser_template_name (cp_parser* parser,
     {
       if (TREE_DEPRECATED (decl)
 	  && deprecated_state != DEPRECATED_SUPPRESS)
-	warn_deprecated_use (decl, NULL_TREE);
+	{
+	  tree d = DECL_TEMPLATE_RESULT (decl);
+	  tree attr;
+	  if (TREE_CODE (d) == TYPE_DECL)
+	    attr = lookup_attribute ("deprecated",
+				     TYPE_ATTRIBUTES (TREE_TYPE (d)));
+	  else
+	    attr = lookup_attribute ("deprecated",
+				     DECL_ATTRIBUTES (d));
+	  warn_deprecated_use (decl, attr);
+	}
     }
   else
     {
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7c44c5eeff1..dd021d1980c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-17  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/93228
+	* g++.dg/cpp1y/attr-deprecated-3.C: New test.
+
 	2020-01-09  Jakub Jelinek  <jakub@redhat.com>
 
 	PR inline-asm/93202
diff --git a/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C b/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C
new file mode 100644
index 00000000000..16e5018f9cf
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-3.C
@@ -0,0 +1,13 @@
+// PR c++/93228
+// { dg-do compile { target c++14 } }
+
+template <typename T>
+struct [[deprecated("foo")]] bar {};	// { dg-message "declared here" }
+struct [[deprecated("baz")]] qux {}; 	// { dg-message "declared here" }
+
+void
+quux ()
+{
+  bar<int> b;	// { dg-warning "is deprecated: foo" }
+  qux c;	// { dg-warning "is deprecated: baz" }
+}
-- 
2.20.1
From f0776f088dce384106609fc868061defd472bc10 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:40:34 +0100
Subject: [PATCH] powerpc: Fix ICE with fp conditional move (PR target/93073)

The following testcase ICEs, because for TFmode the particular subtraction
pattern (*subtf3) is not enabled with the given options.  Using
expand_simple_binop instead of emitting the subtraction by hand just moves
the ICE one insn later, NEG of ABS is not then recognized, etc., but
ultimately the problem is that when rs6000_emit_cmove is called for floating
point operand mode (and earlier condition ensures that in that case
compare_mode is also floating point), the expander makes sure the
operand mode is SFDF, but for the comparison mode nothing checks it, yet
there is just one *fsel* pattern with 2 separate SFDF iterators.

The following patch fixes it by giving up if compare_mode is not SFmode or
DFmode.

2020-01-21  Jakub Jelinek  <jakub@redhat.com>

	PR target/93073
	* config/rs6000/rs6000.c (rs6000_emit_cmove): If using fsel, punt for
	compare_mode other than SFmode or DFmode.

	* gcc.target/powerpc/pr93073.c: New test.
---
 gcc/ChangeLog                              |  6 ++++++
 gcc/config/rs6000/rs6000.c                 |  5 +++++
 gcc/testsuite/ChangeLog                    |  5 +++++
 gcc/testsuite/gcc.target/powerpc/pr93073.c | 16 ++++++++++++++++
 4 files changed, 32 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/powerpc/pr93073.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e17c88b2166..9437e2eb2fc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-21  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/93073
+	* config/rs6000/rs6000.c (rs6000_emit_cmove): If using fsel, punt for
+	compare_mode other than SFmode or DFmode.
+
 	2020-01-09  Jakub Jelinek  <jakub@redhat.com>
 
 	PR inline-asm/93202
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index ea43713ce01..8cf6bd54b2f 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -23551,6 +23551,11 @@ rs6000_emit_cmove (rtx dest, rtx op, rtx true_cond, rtx false_cond)
 
   /* At this point we know we can use fsel.  */
 
+  /* Don't allow compare_mode other than SFmode or DFmode, for others there
+     is no fsel instruction.  */
+  if (compare_mode != SFmode && compare_mode != DFmode)
+    return 0;
+
   /* Reduce the comparison to a comparison against zero.  */
   if (! is_against_zero)
     {
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index dd021d1980c..381ce4f4583 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-21  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/93073
+	* gcc.target/powerpc/pr93073.c: New test.
+
 	2020-01-17  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/93228
diff --git a/gcc/testsuite/gcc.target/powerpc/pr93073.c b/gcc/testsuite/gcc.target/powerpc/pr93073.c
new file mode 100644
index 00000000000..6a0a4731148
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr93073.c
@@ -0,0 +1,16 @@
+/* PR target/93073 */
+/* { dg-do compile { target powerpc_vsx_ok } } */
+/* { dg-options "-mvsx -O1 -ffinite-math-only -fno-trapping-math" } */
+
+void bar (void);
+
+void
+foo (long double x, double y, double z)
+{
+  for (;;)
+    {
+      double a = x > 0.0 ? y : z;
+      if (a == 0.0)
+	bar ();
+    }
+}
-- 
2.20.1
From 0b00f43cf381f03aeaced375f8f0ef1e731c9f43 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:41:22 +0100
Subject: [PATCH] riscv: Fix up riscv_rtx_costs for RTL checking (PR
 target/93333)

As mentioned in the PR, during combine rtx_costs can be called sometimes
even on RTL that has not been validated yet and so can contain even operands
that aren't valid in any instruction.

2020-01-21  Jakub Jelinek  <jakub@redhat.com>

	PR target/93333
	* config/riscv/riscv.c (riscv_rtx_costs) <case ZERO_EXTRACT>: Verify
	the last two operands are CONST_INT_P before using them as such.

	* gcc.c-torture/compile/pr93333.c: New test.
---
 gcc/ChangeLog                                 |  4 ++++
 gcc/config/riscv/riscv.c                      |  5 ++++-
 gcc/testsuite/ChangeLog                       |  3 +++
 gcc/testsuite/gcc.c-torture/compile/pr93333.c | 10 ++++++++++
 4 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr93333.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9437e2eb2fc..1d2fd319117 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -3,6 +3,10 @@
 	Backported from mainline
 	2020-01-21  Jakub Jelinek  <jakub@redhat.com>
 
+	PR target/93333
+	* config/riscv/riscv.c (riscv_rtx_costs) <case ZERO_EXTRACT>: Verify
+	the last two operands are CONST_INT_P before using them as such.
+
 	PR target/93073
 	* config/rs6000/rs6000.c (rs6000_emit_cmove): If using fsel, punt for
 	compare_mode other than SFmode or DFmode.
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 4739e8d8800..b8f7ebfc7cd 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -1515,7 +1515,10 @@ riscv_rtx_costs (rtx x, machine_mode mode, int outer_code, int opno ATTRIBUTE_UN
 
     case ZERO_EXTRACT:
       /* This is an SImode shift.  */
-      if (outer_code == SET && (INTVAL (XEXP (x, 2)) > 0)
+      if (outer_code == SET
+	  && CONST_INT_P (XEXP (x, 1))
+	  && CONST_INT_P (XEXP (x, 2))
+	  && (INTVAL (XEXP (x, 2)) > 0)
 	  && (INTVAL (XEXP (x, 1)) + INTVAL (XEXP (x, 2)) == 32))
 	{
 	  *total = COSTS_N_INSNS (SINGLE_SHIFT_COST);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 381ce4f4583..a1b74a22397 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,9 @@
 	Backported from mainline
 	2020-01-21  Jakub Jelinek  <jakub@redhat.com>
 
+	PR target/93333
+	* gcc.c-torture/compile/pr93333.c: New test.
+
 	PR target/93073
 	* gcc.target/powerpc/pr93073.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr93333.c b/gcc/testsuite/gcc.c-torture/compile/pr93333.c
new file mode 100644
index 00000000000..801959bea75
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr93333.c
@@ -0,0 +1,10 @@
+/* PR target/93333 */
+
+unsigned
+foo (int b, int c, int d, unsigned long e, int x, int y, int g, int h,
+     unsigned i)
+{
+  e >>= b;
+  i >>= e & 31;
+  return i & 1;
+}
-- 
2.20.1
From ba6ebaafc62924a05c961146cb0ec114ae8b04cf Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:41:59 +0100
Subject: [PATCH] openmp: Teach omp_code_to_statement about rest of OpenMP
 statements

The omp_code_to_statement function added with the initial OpenACC support
only handled small subset of the OpenMP statements, leading to ICE if
any other OpenMP directive appeared inside of OpenACC directive.

2020-01-22  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/93329
	* openmp.c (omp_code_to_statement): Handle remaining EXEC_OMP_*
	cases.

	* gfortran.dg/goacc/pr93329.f90: New test.
---
 gcc/fortran/ChangeLog                       |   6 +
 gcc/fortran/openmp.c                        |  75 +++++++
 gcc/testsuite/ChangeLog                     |   5 +
 gcc/testsuite/gfortran.dg/goacc/pr93329.f90 | 223 ++++++++++++++++++++
 4 files changed, 309 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/pr93329.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index e922c1ee652..1f17116065a 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-22  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/93329
+	* openmp.c (omp_code_to_statement): Handle remaining EXEC_OMP_*
+	cases.
+
 	2019-12-19  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/92977
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 707c43cee62..5c319805c2c 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -5689,6 +5689,81 @@ omp_code_to_statement (gfc_code *code)
       return ST_OMP_PARALLEL_WORKSHARE;
     case EXEC_OMP_DO:
       return ST_OMP_DO;
+    case EXEC_OMP_ATOMIC:
+      return ST_OMP_ATOMIC;
+    case EXEC_OMP_BARRIER:
+      return ST_OMP_BARRIER;
+    case EXEC_OMP_CANCEL:
+      return ST_OMP_CANCEL;
+    case EXEC_OMP_CANCELLATION_POINT:
+      return ST_OMP_CANCELLATION_POINT;
+    case EXEC_OMP_FLUSH:
+      return ST_OMP_FLUSH;
+    case EXEC_OMP_DISTRIBUTE:
+      return ST_OMP_DISTRIBUTE;
+    case EXEC_OMP_DISTRIBUTE_PARALLEL_DO:
+      return ST_OMP_DISTRIBUTE_PARALLEL_DO;
+    case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD:
+      return ST_OMP_DISTRIBUTE_PARALLEL_DO_SIMD;
+    case EXEC_OMP_DISTRIBUTE_SIMD:
+      return ST_OMP_DISTRIBUTE_SIMD;
+    case EXEC_OMP_DO_SIMD:
+      return ST_OMP_DO_SIMD;
+    case EXEC_OMP_SIMD:
+      return ST_OMP_SIMD;
+    case EXEC_OMP_TARGET:
+      return ST_OMP_TARGET;
+    case EXEC_OMP_TARGET_DATA:
+      return ST_OMP_TARGET_DATA;
+    case EXEC_OMP_TARGET_ENTER_DATA:
+      return ST_OMP_TARGET_ENTER_DATA;
+    case EXEC_OMP_TARGET_EXIT_DATA:
+      return ST_OMP_TARGET_EXIT_DATA;
+    case EXEC_OMP_TARGET_PARALLEL:
+      return ST_OMP_TARGET_PARALLEL;
+    case EXEC_OMP_TARGET_PARALLEL_DO:
+      return ST_OMP_TARGET_PARALLEL_DO;
+    case EXEC_OMP_TARGET_PARALLEL_DO_SIMD:
+      return ST_OMP_TARGET_PARALLEL_DO_SIMD;
+    case EXEC_OMP_TARGET_SIMD:
+      return ST_OMP_TARGET_SIMD;
+    case EXEC_OMP_TARGET_TEAMS:
+      return ST_OMP_TARGET_TEAMS;
+    case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE:
+      return ST_OMP_TARGET_TEAMS_DISTRIBUTE;
+    case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO:
+      return ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO;
+    case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
+      return ST_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD;
+    case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD:
+      return ST_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD;
+    case EXEC_OMP_TARGET_UPDATE:
+      return ST_OMP_TARGET_UPDATE;
+    case EXEC_OMP_TASKGROUP:
+      return ST_OMP_TASKGROUP;
+    case EXEC_OMP_TASKLOOP:
+      return ST_OMP_TASKLOOP;
+    case EXEC_OMP_TASKLOOP_SIMD:
+      return ST_OMP_TASKLOOP_SIMD;
+    case EXEC_OMP_TASKWAIT:
+      return ST_OMP_TASKWAIT;
+    case EXEC_OMP_TASKYIELD:
+      return ST_OMP_TASKYIELD;
+    case EXEC_OMP_TEAMS:
+      return ST_OMP_TEAMS;
+    case EXEC_OMP_TEAMS_DISTRIBUTE:
+      return ST_OMP_TEAMS_DISTRIBUTE;
+    case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO:
+      return ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO;
+    case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD:
+      return ST_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD;
+    case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD:
+      return ST_OMP_TEAMS_DISTRIBUTE_SIMD;
+    case EXEC_OMP_PARALLEL_DO:
+      return ST_OMP_PARALLEL_DO;
+    case EXEC_OMP_PARALLEL_DO_SIMD:
+      return ST_OMP_PARALLEL_DO_SIMD;
+
     default:
       gcc_unreachable ();
     }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a1b74a22397..af45060acb4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-22  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/93329
+	* gfortran.dg/goacc/pr93329.f90: New test.
+
 	2020-01-21  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/93333
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr93329.f90 b/gcc/testsuite/gfortran.dg/goacc/pr93329.f90
new file mode 100644
index 00000000000..e1feafd2ba2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/pr93329.f90
@@ -0,0 +1,223 @@
+! PR fortran/93329
+! { dg-do compile { target fopenmp } }
+! { dg-additional-options "-fopenmp" }
+
+  integer :: x, y, z
+  integer :: a(32)
+!$acc kernels copyout(x)
+!$omp target map(from:x)	! { dg-error "OMP TARGET directive cannot be specified within" }
+  x = 5
+!$omp end target
+!$acc end kernels
+  print *, x
+!$acc kernels
+!$omp atomic			! { dg-error "OMP ATOMIC directive cannot be specified within" }
+  x = x + 1
+!$omp end atomic
+!$acc end kernels
+!$acc kernels
+!$omp barrier			! { dg-error "OMP BARRIER directive cannot be specified within" }
+!$acc end kernels
+!$acc kernels
+!$omp cancel parallel		! { dg-error "OMP CANCEL directive cannot be specified within" }
+!$acc end kernels
+!$acc kernels
+!$omp cancellation point parallel	! { dg-error "OMP CANCELLATION POINT directive cannot be specified within" }
+!$acc end kernels
+!$acc kernels
+!$omp flush			! { dg-error "OMP FLUSH directive cannot be specified within" }
+!$acc end kernels
+!$acc kernels
+!$omp distribute		! { dg-error "OMP DISTRIBUTE directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp distribute parallel do	! { dg-error "OMP DISTRIBUTE PARALLEL DO directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp distribute parallel do simd	! { dg-error "OMP DISTRIBUTE PARALLEL DO SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp distribute simd		! { dg-error "OMP DISTRIBUTE SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp do simd			! { dg-error "OMP DO SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp simd			! { dg-error "OMP SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp target data map(from: x)	! { dg-error "OMP TARGET DATA directive cannot be specified within" }
+!$omp end target data
+!$acc end kernels
+!$acc kernels
+!$omp target enter data map(to: x)	! { dg-error "OMP TARGET ENTER DATA directive cannot be specified within" }
+!$acc end kernels
+!$acc kernels
+!$omp target exit data map(from: x)	! { dg-error "OMP TARGET EXIT DATA directive cannot be specified within" }
+!$acc end kernels
+!$acc kernels
+!!$omp target parallel
+!!$omp end target parallel
+!$acc end kernels
+!$acc kernels
+!$omp target parallel do	! { dg-error "OMP TARGET PARALLEL DO directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp target parallel do simd	! { dg-error "OMP TARGET PARALLEL DO SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!!$omp target simd
+!  do x = 0, 2
+!  end do
+!$acc end kernels
+!$acc kernels
+!$omp target teams		! { dg-error "OMP TARGET TEAMS directive cannot be specified within" }
+!$omp end target teams
+!$acc end kernels
+!$acc kernels
+!$omp target teams distribute	! { dg-error "OMP TARGET TEAMS DISTRIBUTE directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp target teams distribute parallel do	! { dg-error "OMP TARGET TEAMS DISTRIBUTE PARALLEL DO directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp target teams distribute parallel do simd	! { dg-error "OMP TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp target teams distribute simd	! { dg-error "OMP TARGET TEAMS DISTRIBUTE SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp target update to(x)	! { dg-error "OMP TARGET UPDATE directive cannot be specified within" }
+!$acc end kernels
+!$acc kernels
+!$omp taskgroup			! { dg-error "OMP TASKGROUP directive cannot be specified within" }
+!$omp end taskgroup
+!$acc end kernels
+!$acc kernels
+!$omp taskloop			! { dg-error "OMP TASKLOOP directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp taskloop simd		! { dg-error "OMP TASKLOOP SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp taskwait			! { dg-error "OMP TASKWAIT directive cannot be specified within" }
+!$acc end kernels
+!$acc kernels
+!$omp taskyield			! { dg-error "OMP TASKYIELD directive cannot be specified within" }
+!$acc end kernels
+!$acc kernels
+!$omp teams			! { dg-error "OMP TEAMS directive cannot be specified within" }
+!$omp end teams
+!$acc end kernels
+!$acc kernels
+!$omp teams distribute		! { dg-error "OMP TEAMS DISTRIBUTE directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp teams distribute parallel do	! { dg-error "OMP TEAMS DISTRIBUTE PARALLEL DO directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp teams distribute parallel do simd	! { dg-error "OMP TEAMS DISTRIBUTE PARALLEL DO SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp teams distribute simd	! { dg-error "OMP TEAMS DISTRIBUTE SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp parallel do		! { dg-error "OMP PARALLEL DO directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp parallel do simd		! { dg-error "OMP PARALLEL DO SIMD directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+!$acc kernels
+!$omp parallel			! { dg-error "OMP PARALLEL directive cannot be specified within" }
+!$omp end parallel
+!$acc end kernels
+!$acc kernels
+!$omp parallel sections		! { dg-error "OMP PARALLEL SECTIONS directive cannot be specified within" }
+  y = 1
+!$omp section
+  z = 2
+!$omp end parallel sections
+!$acc end kernels
+!$acc kernels
+!$omp sections			! { dg-error "OMP SECTIONS directive cannot be specified within" }
+  y = 1
+!$omp section
+  z = 2
+!$omp end sections
+!$acc end kernels
+!$acc kernels
+!$omp ordered			! { dg-error "OMP ORDERED directive cannot be specified within" }
+!$omp end ordered
+!$acc end kernels
+!$acc kernels
+!$omp critical			! { dg-error "OMP CRITICAL directive cannot be specified within" }
+!$omp end critical
+!$acc end kernels
+!$acc kernels
+!$omp master			! { dg-error "OMP MASTER directive cannot be specified within" }
+!$omp end master
+!$acc end kernels
+!$acc kernels
+!$omp single			! { dg-error "OMP SINGLE directive cannot be specified within" }
+!$omp end single
+!$acc end kernels
+!$acc kernels
+!$omp task			! { dg-error "OMP TASK directive cannot be specified within" }
+!$omp end task
+!$acc end kernels
+!$acc kernels
+!$omp workshare			! { dg-error "OMP WORKSHARE directive cannot be specified within" }
+  a(:) = 1
+!$omp end workshare
+!$acc end kernels
+!$acc kernels
+!$omp parallel workshare	! { dg-error "OMP PARALLEL WORKSHARE directive cannot be specified within" }
+  a(:) = 1
+!$omp end parallel workshare
+!$acc end kernels
+!$acc kernels
+!$omp do			! { dg-error "OMP DO directive cannot be specified within" }
+  do x = 0, 2
+  end do
+!$acc end kernels
+end
-- 
2.20.1
From a7324c0216fcb95157a1f9f980e1351d17228b35 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:42:58 +0100
Subject: [PATCH] openmp: Fix up !$omp target parallel handling

The PR93329 fix revealed we ICE on !$omp target parallel, this change fixes
that.

2020-01-22  Jakub Jelinek  <jakub@redhat.com>

	* parse.c (parse_omp_structured_block): Handle ST_OMP_TARGET_PARALLEL.
	* trans-openmp.c (gfc_trans_omp_target)
	<case EXEC_OMP_TARGET_PARALLEL>: Call pushlevel first.

	* gfortran.dg/gomp/target-parallel1.f90: New test.
	* gfortran.dg/goacc/pr93329.f90: Enable commented out target parallel
	test.
---
 gcc/fortran/ChangeLog                               | 4 ++++
 gcc/fortran/parse.c                                 | 3 +++
 gcc/fortran/trans-openmp.c                          | 1 +
 gcc/testsuite/ChangeLog                             | 4 ++++
 gcc/testsuite/gfortran.dg/goacc/pr93329.f90         | 4 ++--
 gcc/testsuite/gfortran.dg/gomp/target-parallel1.f90 | 4 ++++
 6 files changed, 18 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/target-parallel1.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 1f17116065a..d8454dd2047 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -3,6 +3,10 @@
 	Backported from mainline
 	2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
+	* parse.c (parse_omp_structured_block): Handle ST_OMP_TARGET_PARALLEL.
+	* trans-openmp.c (gfc_trans_omp_target)
+	<case EXEC_OMP_TARGET_PARALLEL>: Call pushlevel first.
+
 	PR fortran/93329
 	* openmp.c (omp_code_to_statement): Handle remaining EXEC_OMP_*
 	cases.
diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c
index e920c71d569..70ef10df9c4 100644
--- a/gcc/fortran/parse.c
+++ b/gcc/fortran/parse.c
@@ -5073,6 +5073,9 @@ parse_omp_structured_block (gfc_statement omp_st, bool workshare_stmts_only)
     case ST_OMP_TARGET_DATA:
       omp_end_st = ST_OMP_END_TARGET_DATA;
       break;
+    case ST_OMP_TARGET_PARALLEL:
+      omp_end_st = ST_OMP_END_TARGET_PARALLEL;
+      break;
     case ST_OMP_TARGET_TEAMS:
       omp_end_st = ST_OMP_END_TARGET_TEAMS;
       break;
diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index 85d6eab0123..6f82239a4b3 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -4745,6 +4745,7 @@ gfc_trans_omp_target (gfc_code *code)
       {
 	stmtblock_t iblock;
 
+	pushlevel ();
 	gfc_start_block (&iblock);
 	tree inner_clauses
 	  = gfc_trans_omp_clauses (&block, &clausesa[GFC_OMP_SPLIT_PARALLEL],
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index af45060acb4..8bfb97d2e19 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,10 @@
 	Backported from mainline
 	2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
+	* gfortran.dg/gomp/target-parallel1.f90: New test.
+	* gfortran.dg/goacc/pr93329.f90: Enable commented out target parallel
+	test.
+
 	PR fortran/93329
 	* gfortran.dg/goacc/pr93329.f90: New test.
 
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr93329.f90 b/gcc/testsuite/gfortran.dg/goacc/pr93329.f90
index e1feafd2ba2..b277bb1243c 100644
--- a/gcc/testsuite/gfortran.dg/goacc/pr93329.f90
+++ b/gcc/testsuite/gfortran.dg/goacc/pr93329.f90
@@ -68,8 +68,8 @@
 !$omp target exit data map(from: x)	! { dg-error "OMP TARGET EXIT DATA directive cannot be specified within" }
 !$acc end kernels
 !$acc kernels
-!!$omp target parallel
-!!$omp end target parallel
+!$omp target parallel		! { dg-error "OMP TARGET PARALLEL directive cannot be specified within" }
+!$omp end target parallel
 !$acc end kernels
 !$acc kernels
 !$omp target parallel do	! { dg-error "OMP TARGET PARALLEL DO directive cannot be specified within" }
diff --git a/gcc/testsuite/gfortran.dg/gomp/target-parallel1.f90 b/gcc/testsuite/gfortran.dg/gomp/target-parallel1.f90
new file mode 100644
index 00000000000..bb8561f1c73
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/target-parallel1.f90
@@ -0,0 +1,4 @@
+!$omp target parallel
+  print *, 'Hello, world'
+!$omp end target parallel
+end
-- 
2.20.1
From 93266871ac794243e9785d92a0cec09b2fa5648b Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:43:47 +0100
Subject: [PATCH] i386: Fix up -fdollars-in-identifiers with identifiers
 starting with $ in -masm=att [PR91298]

In AT&T syntax leading $ is special, so if we have identifiers that start
with dollar, we usually fail to assemble it (or assemble incorrectly).
As mentioned in the PR, what works is wrapping the identifiers inside of
parens, like:
	movl	$($a), %eax
	leaq	($a)(,%rdi,4), %rax
	movl	($a)(%rip), %eax
	movl	($a)+16(%rip), %eax
	.globl	$a
	.type	$a, @object
	.size	$a, 72
$a:
	.string	"$a"
	.quad	($a)
(this is x86_64 -fno-pic -O2).  In some places ($a) is not accepted,
like as .globl operand, in .type, .size, so the patch overrides
ASM_OUTPUT_SYMBOL_REF rather than e.g. ASM_OUTPUT_LABELREF.
I didn't want to duplicate what assemble_name is doing (following
transparent aliases), so split assemble_name into two parts; just
mere looking at the first character of a name before calling assemble_name
wouldn't be good enough, a transparent alias could lead from a name
not starting with $ to one starting with it and vice versa.

2020-01-22  Jakub Jelinek  <jakub@redhat.com>

	PR target/91298
	* output.h (assemble_name_resolve): Declare.
	* varasm.c (assemble_name_resolve): New function.
	(assemble_name): Use it.
	* config/i386/i386.h (ASM_OUTPUT_SYMBOL_REF): Define.

	* gcc.target/i386/pr91298-1.c: New test.
	* gcc.target/i386/pr91298-2.c: New test.
---
 gcc/ChangeLog                             |  8 ++++++
 gcc/config/i386/i386.h                    | 25 +++++++++++++++++
 gcc/output.h                              |  6 +++++
 gcc/testsuite/ChangeLog                   |  4 +++
 gcc/testsuite/gcc.target/i386/pr91298-1.c | 14 ++++++++++
 gcc/testsuite/gcc.target/i386/pr91298-2.c |  5 ++++
 gcc/varasm.c                              | 33 ++++++++++++++---------
 7 files changed, 82 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr91298-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr91298-2.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 1d2fd319117..c14e785cfc9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,14 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-22  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/91298
+	* output.h (assemble_name_resolve): Declare.
+	* varasm.c (assemble_name_resolve): New function.
+	(assemble_name): Use it.
+	* config/i386/i386.h (ASM_OUTPUT_SYMBOL_REF): Define.
+
 	2020-01-21  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/93333
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 59357e07a07..d594d4a417c 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2227,6 +2227,31 @@ extern int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER];
 #define ASM_OUTPUT_FUNCTION_LABEL(FILE, NAME, DECL) \
   ix86_asm_output_function_label ((FILE), (NAME), (DECL))
 
+/* A C statement (sans semicolon) to output a reference to SYMBOL_REF SYM.
+   If not defined, assemble_name will be used to output the name of the
+   symbol.  This macro may be used to modify the way a symbol is referenced
+   depending on information encoded by TARGET_ENCODE_SECTION_INFO.  */
+
+#ifndef ASM_OUTPUT_SYMBOL_REF
+#define ASM_OUTPUT_SYMBOL_REF(FILE, SYM) \
+  do {							\
+    const char *name					\
+      = assemble_name_resolve (XSTR (x, 0));		\
+    /* In -masm=att wrap identifiers that start with $	\
+       into parens.  */					\
+    if (ASSEMBLER_DIALECT == ASM_ATT			\
+	&& name[0] == '$'				\
+	&& user_label_prefix[0] == '\0')		\
+      {							\
+	fputc ('(', (FILE));				\
+	assemble_name_raw ((FILE), name);		\
+	fputc (')', (FILE));				\
+      }							\
+    else						\
+      assemble_name_raw ((FILE), name);			\
+  } while (0)
+#endif
+
 /* Under some conditions we need jump tables in the text section,
    because the assembler cannot handle label differences between
    sections.  This is the case for x86_64 on Mach-O for example.  */
diff --git a/gcc/output.h b/gcc/output.h
index f708cc75fa7..67fc5e94cc5 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -240,6 +240,12 @@ extern void assemble_label (FILE *, const char *);
    addition of an underscore).  */
 extern void assemble_name_raw (FILE *, const char *);
 
+/* Return NAME that should actually be emitted, looking through
+   transparent aliases.  If NAME refers to an entity that is also
+   represented as a tree (like a function or variable), mark the entity
+   as referenced.  */
+extern const char *assemble_name_resolve (const char *);
+
 /* Like assemble_name_raw, but should be used when NAME might refer to
    an entity that is also represented as a tree (like a function or
    variable).  If NAME does refer to such an entity, that entity will
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8bfb97d2e19..6bf50002f69 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,10 @@
 	Backported from mainline
 	2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
+	PR target/91298
+	* gcc.target/i386/pr91298-1.c: New test.
+	* gcc.target/i386/pr91298-2.c: New test.
+
 	* gfortran.dg/gomp/target-parallel1.f90: New test.
 	* gfortran.dg/goacc/pr93329.f90: Enable commented out target parallel
 	test.
diff --git a/gcc/testsuite/gcc.target/i386/pr91298-1.c b/gcc/testsuite/gcc.target/i386/pr91298-1.c
new file mode 100644
index 00000000000..45ef553fcf1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr91298-1.c
@@ -0,0 +1,14 @@
+/* PR target/91298 */
+/* { dg-do assemble } */
+/* { dg-options "-O2 -g -fdollars-in-identifiers" } */
+
+int $a[18];
+int *foo (void) { return &$a[0]; }
+int *bar (int x) { return &$a[x]; }
+int baz (void) { return $a[0]; }
+int qux (void) { return $a[4]; }
+int $quux (void) { return 1; }
+int corge (void) { return $quux (); }
+int grault (void) { return $quux () + 1; }
+typedef int (*fn) (void);
+fn foobar (void) { return $quux; }
diff --git a/gcc/testsuite/gcc.target/i386/pr91298-2.c b/gcc/testsuite/gcc.target/i386/pr91298-2.c
new file mode 100644
index 00000000000..20e47ab6c83
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr91298-2.c
@@ -0,0 +1,5 @@
+/* PR target/91298 */
+/* { dg-do assemble { target fpic } } */
+/* { dg-options "-O2 -g -fdollars-in-identifiers -fpic" } */
+
+#include "pr91298-1.c"
diff --git a/gcc/varasm.c b/gcc/varasm.c
index dfe20dd415a..adf279152b4 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -2575,20 +2575,16 @@ assemble_name_raw (FILE *file, const char *name)
     ASM_OUTPUT_LABELREF (file, name);
 }
 
-/* Like assemble_name_raw, but should be used when NAME might refer to
-   an entity that is also represented as a tree (like a function or
-   variable).  If NAME does refer to such an entity, that entity will
-   be marked as referenced.  */
-
-void
-assemble_name (FILE *file, const char *name)
+/* Return NAME that should actually be emitted, looking through
+   transparent aliases.  If NAME refers to an entity that is also
+   represented as a tree (like a function or variable), mark the entity
+   as referenced.  */
+const char *
+assemble_name_resolve (const char *name)
 {
-  const char *real_name;
-  tree id;
+  const char *real_name = targetm.strip_name_encoding (name);
+  tree id = maybe_get_identifier (real_name);
 
-  real_name = targetm.strip_name_encoding (name);
-
-  id = maybe_get_identifier (real_name);
   if (id)
     {
       tree id_orig = id;
@@ -2600,7 +2596,18 @@ assemble_name (FILE *file, const char *name)
       gcc_assert (! TREE_CHAIN (id));
     }
 
-  assemble_name_raw (file, name);
+  return name;
+}
+
+/* Like assemble_name_raw, but should be used when NAME might refer to
+   an entity that is also represented as a tree (like a function or
+   variable).  If NAME does refer to such an entity, that entity will
+   be marked as referenced.  */
+
+void
+assemble_name (FILE *file, const char *name)
+{
+  assemble_name_raw (file, assemble_name_resolve (name));
 }
 
 /* Allocate SIZE bytes writable static space with a gensym name
-- 
2.20.1
From 83799a013b4a7f555b1a168fcb5f8df25edede99 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:44:23 +0100
Subject: [PATCH] postreload: Fix up postreload combine [PR93402]

The following testcase is miscompiled, because the postreload pass changes:
-(insn 14 13 23 2 (parallel [
-            (set (reg:DI 1 dx [94])
-                (plus:DI (reg:DI 1 dx [95])
-                    (reg:DI 5 di [92])))
-            (clobber (reg:CC 17 flags))
-        ]) "pr93402.c":8:30 186 {*adddi_1}
-     (expr_list:REG_EQUAL (plus:DI (reg:DI 5 di [92])
-            (const_int 111111111111 [0x19debd01c7]))
-        (nil)))
-(insn 23 14 25 2 (set (reg:SI 0 ax)
+(insn 23 13 25 2 (set (reg:SI 0 ax)
         (const_int 0 [0])) "pr93402.c":10:1 67 {*movsi_internal}
      (nil))
 (insn 25 23 26 2 (use (reg:SI 0 ax)) "pr93402.c":10:1 -1
      (nil))
-(insn 26 25 35 2 (use (reg:DI 1 dx)) "pr93402.c":10:1 -1
+(insn 26 25 35 2 (use (plus:DI (reg:DI 1 dx [95])
+            (reg:DI 5 di [92]))) "pr93402.c":10:1 -1
      (nil))
A USE insn is not a normal insn and verify_changes called from
apply_change_group is happy about any changes into it.
The following patch avoids this optimization if we were to change
the USE operand (this routine only changes a reg into (plus reg reg2)).

2020-01-23  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/93402
	* postreload.c (reload_combine_recognize_pattern): Don't try to adjust
	USE insns.

	* gcc.c-torture/execute/pr93402.c: New test.
---
 gcc/ChangeLog                                 |  6 ++++++
 gcc/postreload.c                              |  4 ++++
 gcc/testsuite/ChangeLog                       |  5 +++++
 gcc/testsuite/gcc.c-torture/execute/pr93402.c | 21 +++++++++++++++++++
 4 files changed, 36 insertions(+)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr93402.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c14e785cfc9..3d4e31332f4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-23  Jakub Jelinek  <jakub@redhat.com>
+
+	PR rtl-optimization/93402
+	* postreload.c (reload_combine_recognize_pattern): Don't try to adjust
+	USE insns.
+
 	2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/91298
diff --git a/gcc/postreload.c b/gcc/postreload.c
index 0638709639b..184b158bb05 100644
--- a/gcc/postreload.c
+++ b/gcc/postreload.c
@@ -1076,6 +1076,10 @@ reload_combine_recognize_pattern (rtx_insn *insn)
       struct reg_use *use = reg_state[regno].reg_use + i;
       if (GET_MODE (*use->usep) != mode)
 	return false;
+      /* Don't try to adjust (use (REGX)).  */
+      if (GET_CODE (PATTERN (use->insn)) == USE
+	  && &XEXP (PATTERN (use->insn), 0) == use->usep)
+	return false;
     }
 
   /* Look for (set (REGX) (CONST_INT))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6bf50002f69..24602deb8c4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-23  Jakub Jelinek  <jakub@redhat.com>
+
+	PR rtl-optimization/93402
+	* gcc.c-torture/execute/pr93402.c: New test.
+
 	2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/91298
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr93402.c b/gcc/testsuite/gcc.c-torture/execute/pr93402.c
new file mode 100644
index 00000000000..6487797d0aa
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr93402.c
@@ -0,0 +1,21 @@
+/* PR rtl-optimization/93402 */
+
+struct S { unsigned int a; unsigned long long b; };
+
+__attribute__((noipa)) struct S
+foo (unsigned long long x)
+{
+  struct S ret;
+  ret.a = 0;
+  ret.b = x * 11111111111ULL + 111111111111ULL;
+  return ret;
+}
+
+int
+main ()
+{
+  struct S a = foo (1);
+  if (a.a != 0 || a.b != 122222222222ULL)
+    __builtin_abort ();
+  return 0;
+}
-- 
2.20.1
From e0cbedff53ead3bbb6e7af959c727a04ec8445c7 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:45:07 +0100
Subject: [PATCH] openmp: Handle rest of EXEC_OACC_* in oacc_code_to_statement
 [PR93463]

As the testcase shows, some EXEC_OACC_* codes weren't handled in
oacc_code_to_statement.  Fixed thusly.

2020-01-29  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/93463
	* openmp.c (oacc_code_to_statement): Handle
	EXEC_OACC_{ROUTINE,UPDATE,WAIT,CACHE,{ENTER,EXIT}_DATA,DECLARE}.

	* gfortran.dg/goacc/pr93463.f90: New test.
---
 gcc/fortran/ChangeLog                       |  6 ++++++
 gcc/fortran/openmp.c                        | 14 ++++++++++++++
 gcc/testsuite/ChangeLog                     |  5 +++++
 gcc/testsuite/gfortran.dg/goacc/pr93463.f90 | 15 +++++++++++++++
 4 files changed, 40 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/goacc/pr93463.f90

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index d8454dd2047..998679365aa 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-29  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/93463
+	* openmp.c (oacc_code_to_statement): Handle
+	EXEC_OACC_{ROUTINE,UPDATE,WAIT,CACHE,{ENTER,EXIT}_DATA,DECLARE}.
+
 	2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
 	* parse.c (parse_omp_structured_block): Handle ST_OMP_TARGET_PARALLEL.
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 5c319805c2c..a47870fd60e 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -5790,6 +5790,20 @@ oacc_code_to_statement (gfc_code *code)
       return ST_OACC_LOOP;
     case EXEC_OACC_ATOMIC:
       return ST_OACC_ATOMIC;
+    case EXEC_OACC_ROUTINE:
+      return ST_OACC_ROUTINE;
+    case EXEC_OACC_UPDATE:
+      return ST_OACC_UPDATE;
+    case EXEC_OACC_WAIT:
+      return ST_OACC_WAIT;
+    case EXEC_OACC_CACHE:
+      return ST_OACC_CACHE;
+    case EXEC_OACC_ENTER_DATA:
+      return ST_OACC_ENTER_DATA;
+    case EXEC_OACC_EXIT_DATA:
+      return ST_OACC_EXIT_DATA;
+    case EXEC_OACC_DECLARE:
+      return ST_OACC_DECLARE;
     default:
       gcc_unreachable ();
     }
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 24602deb8c4..a025b370570 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-29  Jakub Jelinek  <jakub@redhat.com>
+
+	PR fortran/93463
+	* gfortran.dg/goacc/pr93463.f90: New test.
+
 	2020-01-23  Jakub Jelinek  <jakub@redhat.com>
 
 	PR rtl-optimization/93402
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr93463.f90 b/gcc/testsuite/gfortran.dg/goacc/pr93463.f90
new file mode 100644
index 00000000000..920892fdcda
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/pr93463.f90
@@ -0,0 +1,15 @@
+! PR fortran/93463
+! { dg-do compile { target fopenmp } }
+! { dg-additional-options "-fopenmp" }
+
+program pr93463
+   integer :: i, x, y, z
+   !$omp parallel do
+   do i = 1, 4
+      !$acc enter data create(x)	! { dg-error "ACC ENTER DATA directive cannot be specified within" }
+      !$acc exit data copyout(x)	! { dg-error "ACC EXIT DATA directive cannot be specified within" }
+      !$acc cache(y)			! { dg-error "ACC CACHE directive cannot be specified within" }
+      !$acc wait(1)			! { dg-error "ACC WAIT directive cannot be specified within" }
+      !$acc update self(z)		! { dg-error "ACC UPDATE directive cannot be specified within" }
+   end do
+end
-- 
2.20.1
From a73ee641c3d2ca729bdf55225afd881f57bf4d96 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:46:13 +0100
Subject: [PATCH] combine: Punt on out of range rotate counts [PR93505]

What happens on this testcase is with the out of bounds rotate we get:
Trying 13 -> 16:
   13: r129:SI=r132:DI#0<-<0x20
      REG_DEAD r132:DI
   16: r123:DI=r129:SI<0
      REG_DEAD r129:SI
Successfully matched this instruction:
(set (reg/v:DI 123 [ <retval> ])
    (const_int 0 [0]))
during combine.  So, perhaps we could also change simplify-rtx.c to punt
if it is out of bounds rather than trying to optimize anything.
Or, but probably GCC11 material, if we decide that ROTATE/ROTATERT doesn't
have out of bounds counts or introduce targetm.rotate_truncation_mask,
we should truncate the argument instead of punting.
Punting is better for backports though.

2020-01-30  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/93505
	* combine.c (simplify_comparison) <case ROTATE>: Punt on out of range
	rotate counts.

	* gcc.c-torture/compile/pr93505.c: New test.
---
 gcc/ChangeLog                                 |  6 ++++++
 gcc/combine.c                                 |  3 ++-
 gcc/testsuite/ChangeLog                       |  5 +++++
 gcc/testsuite/gcc.c-torture/compile/pr93505.c | 15 +++++++++++++++
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr93505.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3d4e31332f4..88b197210de 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-30  Jakub Jelinek  <jakub@redhat.com>
+
+	PR middle-end/93505
+	* combine.c (simplify_comparison) <case ROTATE>: Punt on out of range
+	rotate counts.
+
 	2020-01-23  Jakub Jelinek  <jakub@redhat.com>
 
 	PR rtl-optimization/93402
diff --git a/gcc/combine.c b/gcc/combine.c
index 899b6f1649d..6a9638d982c 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -12318,7 +12318,8 @@ simplify_comparison (enum rtx_code code, rtx *pop0, rtx *pop1)
 	     bit.  This will be converted into a ZERO_EXTRACT.  */
 	  if (const_op == 0 && sign_bit_comparison_p
 	      && CONST_INT_P (XEXP (op0, 1))
-	      && mode_width <= HOST_BITS_PER_WIDE_INT)
+	      && mode_width <= HOST_BITS_PER_WIDE_INT
+	      && UINTVAL (XEXP (op0, 1)) < mode_width)
 	    {
 	      op0 = simplify_and_const_int (NULL_RTX, mode, XEXP (op0, 0),
 					    (HOST_WIDE_INT_1U
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a025b370570..d1c1eb6307f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-01-30  Jakub Jelinek  <jakub@redhat.com>
+
+	PR middle-end/93505
+	* gcc.c-torture/compile/pr93505.c: New test.
+
 	2020-01-29  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/93463
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr93505.c b/gcc/testsuite/gcc.c-torture/compile/pr93505.c
new file mode 100644
index 00000000000..0627962eae5
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr93505.c
@@ -0,0 +1,15 @@
+/* PR middle-end/93505 */
+
+unsigned a;
+
+unsigned
+foo (unsigned x)
+{
+  unsigned int y = 32 - __builtin_bswap64 (-a);
+  /* This would be UB (x << 32) at runtime.  Ensure we don't
+     invoke UB in the compiler because of that (visible with
+     bootstrap-ubsan).  */
+  x = x << y | x >> (-y & 31);
+  x >>= 31;
+  return x;
+}
-- 
2.20.1
From 5781600c42f3ed9860a804dbbf892392bea3e39d Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:46:51 +0100
Subject: [PATCH] openmp: Avoid ICEs with declare simd; declare simd inbranch
 [PR93555]

The testcases ICE because when processing the declare simd inbranch,
we don't create the i == 0 clone as it already exists, which means
clone_info->nargs is not adjusted, but we then rely on it being adjusted
when trying other clones.

2020-02-05  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/93555
	* omp-simd-clone.c (expand_simd_clones): If simd_clone_mangle or
	simd_clone_create failed when i == 0, adjust clone->nargs by
	clone->inbranch.

	* c-c++-common/gomp/pr93555-1.c: New test.
	* c-c++-common/gomp/pr93555-2.c: New test.
	* gfortran.dg/gomp/pr93555.f90: New test.
---
 gcc/ChangeLog                               |  7 +++++++
 gcc/omp-simd-clone.c                        | 12 ++++++++++--
 gcc/testsuite/ChangeLog                     |  7 +++++++
 gcc/testsuite/c-c++-common/gomp/pr93555-1.c | 18 ++++++++++++++++++
 gcc/testsuite/c-c++-common/gomp/pr93555-2.c | 16 ++++++++++++++++
 gcc/testsuite/gfortran.dg/gomp/pr93555.f90  | 11 +++++++++++
 6 files changed, 69 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/pr93555-1.c
 create mode 100644 gcc/testsuite/c-c++-common/gomp/pr93555-2.c
 create mode 100644 gcc/testsuite/gfortran.dg/gomp/pr93555.f90

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 88b197210de..9e7235edcd6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-05  Jakub Jelinek  <jakub@redhat.com>
+
+	PR middle-end/93555
+	* omp-simd-clone.c (expand_simd_clones): If simd_clone_mangle or
+	simd_clone_create failed when i == 0, adjust clone->nargs by
+	clone->inbranch.
+
 	2020-01-30  Jakub Jelinek  <jakub@redhat.com>
 
 	PR middle-end/93505
diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c
index c408f349b81..03d6b58d8b2 100644
--- a/gcc/omp-simd-clone.c
+++ b/gcc/omp-simd-clone.c
@@ -1709,14 +1709,22 @@ expand_simd_clones (struct cgraph_node *node)
 	     already.  */
 	  tree id = simd_clone_mangle (node, clone);
 	  if (id == NULL_TREE)
-	    continue;
+	    {
+	      if (i == 0)
+		clone->nargs += clone->inbranch;
+	      continue;
+	    }
 
 	  /* Only when we are sure we want to create the clone actually
 	     clone the function (or definitions) or create another
 	     extern FUNCTION_DECL (for prototypes without definitions).  */
 	  struct cgraph_node *n = simd_clone_create (node);
 	  if (n == NULL)
-	    continue;
+	    {
+	      if (i == 0)
+		clone->nargs += clone->inbranch;
+	      continue;
+	    }
 
 	  n->simdclone = clone;
 	  clone->origin = node;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d1c1eb6307f..46dd81b222c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-05  Jakub Jelinek  <jakub@redhat.com>
+
+	PR middle-end/93555
+	* c-c++-common/gomp/pr93555-1.c: New test.
+	* c-c++-common/gomp/pr93555-2.c: New test.
+	* gfortran.dg/gomp/pr93555.f90: New test.
+
 	2020-01-30  Jakub Jelinek  <jakub@redhat.com>
 
 	PR middle-end/93505
diff --git a/gcc/testsuite/c-c++-common/gomp/pr93555-1.c b/gcc/testsuite/c-c++-common/gomp/pr93555-1.c
new file mode 100644
index 00000000000..2eb76a2d9de
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr93555-1.c
@@ -0,0 +1,18 @@
+/* PR middle-end/93555 */
+/* { dg-do compile } */
+
+#pragma omp declare simd
+#pragma omp declare simd inbranch
+int
+foo (int x)
+{
+  return x;
+}
+
+#pragma omp declare simd inbranch
+#pragma omp declare simd
+int
+bar (int x)
+{
+  return x;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/pr93555-2.c b/gcc/testsuite/c-c++-common/gomp/pr93555-2.c
new file mode 100644
index 00000000000..091f5bd5ff1
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr93555-2.c
@@ -0,0 +1,16 @@
+/* PR middle-end/93555 */
+/* { dg-do compile } */
+
+#pragma omp declare simd
+#pragma omp declare simd inbranch
+void
+foo (void)
+{
+}
+
+#pragma omp declare simd inbranch
+#pragma omp declare simd
+void
+bar (void)
+{
+}
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr93555.f90 b/gcc/testsuite/gfortran.dg/gomp/pr93555.f90
new file mode 100644
index 00000000000..4a97fee07a7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/pr93555.f90
@@ -0,0 +1,11 @@
+! PR middle-end/93555
+! { dg-do compile }
+
+subroutine foo
+  !$omp declare simd(foo)
+  !$omp declare simd(foo) inbranch
+end
+subroutine bar
+  !$omp declare simd(bar) inbranch
+  !$omp declare simd(bar)
+end
-- 
2.20.1
From fdaf101b1dd46d6673a318139e9620c068f45a12 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 14:18:10 +0100
Subject: [PATCH] openmp: Fix handling of non-addressable shared scalars in
 parallel nested inside of target [PR93515]

As the following testcase shows, we need to consider even target to be a construct
that forces not to use copy in/out for shared on parallel inside of the target.
E.g. for parallel nested inside another parallel or host teams, we already avoid
copy in/out and we need to treat target the same.

2020-02-06  Jakub Jelinek  <jakub@redhat.com>

	PR libgomp/93515
	* omp-low.c (use_pointer_for_field): For nested constructs, also
	look for map clauses on target construct.
	(scan_omp_1_stmt) <case GIMPLE_OMP_TARGET>: Bump temporarily
	taskreg_nesting_level.

	* testsuite/libgomp.c-c++-common/pr93515.c: New test.
---
 gcc/ChangeLog                                 |  8 +++++
 gcc/omp-low.c                                 | 33 +++++++++++++----
 libgomp/ChangeLog                             |  5 +++
 .../testsuite/libgomp.c-c++-common/pr93515.c  | 36 +++++++++++++++++++
 4 files changed, 75 insertions(+), 7 deletions(-)
 create mode 100644 libgomp/testsuite/libgomp.c-c++-common/pr93515.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9e7235edcd6..dcff4acac4f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,14 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-06  Jakub Jelinek  <jakub@redhat.com>
+
+	PR libgomp/93515
+	* omp-low.c (use_pointer_for_field): For nested constructs, also
+	look for map clauses on target construct.
+	(scan_omp_1_stmt) <case GIMPLE_OMP_TARGET>: Bump temporarily
+	taskreg_nesting_level.
+
 	2020-02-05  Jakub Jelinek  <jakub@redhat.com>
 
 	PR middle-end/93555
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 102a998146d..32afc272a4e 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -404,18 +404,30 @@ use_pointer_for_field (tree decl, omp_context *shared_ctx)
 	  omp_context *up;
 
 	  for (up = shared_ctx->outer; up; up = up->outer)
-	    if (is_taskreg_ctx (up) && maybe_lookup_decl (decl, up))
+	    if ((is_taskreg_ctx (up)
+		 || (gimple_code (up->stmt) == GIMPLE_OMP_TARGET
+		     && is_gimple_omp_offloaded (up->stmt)))
+		&& maybe_lookup_decl (decl, up))
 	      break;
 
 	  if (up)
 	    {
 	      tree c;
 
-	      for (c = gimple_omp_taskreg_clauses (up->stmt);
-		   c; c = OMP_CLAUSE_CHAIN (c))
-		if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
-		    && OMP_CLAUSE_DECL (c) == decl)
-		  break;
+	      if (gimple_code (up->stmt) == GIMPLE_OMP_TARGET)
+		{
+		  for (c = gimple_omp_target_clauses (up->stmt);
+		       c; c = OMP_CLAUSE_CHAIN (c))
+		    if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
+			&& OMP_CLAUSE_DECL (c) == decl)
+		      break;
+		}
+	      else
+		for (c = gimple_omp_taskreg_clauses (up->stmt);
+		     c; c = OMP_CLAUSE_CHAIN (c))
+		  if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SHARED
+		      && OMP_CLAUSE_DECL (c) == decl)
+		    break;
 
 	      if (c)
 		goto maybe_mark_addressable_and_ret;
@@ -3174,7 +3186,14 @@ scan_omp_1_stmt (gimple_stmt_iterator *gsi, bool *handled_ops_p,
       break;
 
     case GIMPLE_OMP_TARGET:
-      scan_omp_target (as_a <gomp_target *> (stmt), ctx);
+      if (is_gimple_omp_offloaded (stmt))
+	{
+	  taskreg_nesting_level++;
+	  scan_omp_target (as_a <gomp_target *> (stmt), ctx);
+	  taskreg_nesting_level--;
+	}
+      else
+	scan_omp_target (as_a <gomp_target *> (stmt), ctx);
       break;
 
     case GIMPLE_OMP_TEAMS:
diff --git a/libgomp/ChangeLog b/libgomp/ChangeLog
index 33827bd1ac5..5edb4f2ba77 100644
--- a/libgomp/ChangeLog
+++ b/libgomp/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-06  Jakub Jelinek  <jakub@redhat.com>
+
+	PR libgomp/93515
+	* testsuite/libgomp.c-c++-common/pr93515.c: New test.
+
 	2019-12-31  Ayush Mittal  <ayush.m@samsung.com>
 
 	PR libgomp/93065
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr93515.c b/libgomp/testsuite/libgomp.c-c++-common/pr93515.c
new file mode 100644
index 00000000000..8a69088ccec
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/pr93515.c
@@ -0,0 +1,36 @@
+/* PR libgomp/93515 */
+
+#include <omp.h>
+#include <stdlib.h>
+
+int
+main ()
+{
+  int i;
+  int a = 42;
+#pragma omp target teams distribute parallel for defaultmap(tofrom: scalar)
+  for (i = 0; i < 64; ++i)
+    if (omp_get_team_num () == 0)
+      if (omp_get_thread_num () == 0)
+	a = 142;
+  if (a != 142)
+    __builtin_abort ();
+  a = 42;
+#pragma omp target parallel for defaultmap(tofrom: scalar)
+  for (i = 0; i < 64; ++i)
+    if (omp_get_thread_num () == 0)
+      a = 143;
+  if (a != 143)
+    __builtin_abort ();
+  a = 42;
+#pragma omp target firstprivate(a)
+  {
+    #pragma omp parallel for
+    for (i = 0; i < 64; ++i)
+      if (omp_get_thread_num () == 0)
+	a = 144;
+    if (a != 144)
+      abort ();
+  }
+  return 0;
+}
-- 
2.20.1
From baef3efdc4992e4dcb7f4de62ff5bcb13bf05f60 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:47:55 +0100
Subject: [PATCH] i386: Make xmm16-xmm31 call used even in ms ABI [PR65782]
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

On Tue, Feb 04, 2020 at 11:16:06AM +0100, Uros Bizjak wrote:
> I guess that Comment #9 patch form the PR should be trivially correct,

> but althouhg it looks obvious, I don't want to propose the patch since

> I have no means of testing it.


I don't have means of testing it either.
https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019
is quite explicit that [xyz]mm16-31 are call clobbered and only xmm6-15 (low
128-bits only) are call preserved.

We are talking e.g. about
/* { dg-options "-O2 -mabi=ms -mavx512vl" } */

typedef double V __attribute__((vector_size (16)));
void foo (void);
V bar (void);
void baz (V);
void
qux (void)
{
  V c;
  {
    register V a __asm ("xmm18");
    V b = bar ();
    asm ("" : "=x" (a) : "0" (b));
    c = a;
  }
  foo ();
  {
    register V d __asm ("xmm18");
    V e;
    d = c;
    asm ("" : "=x" (e) : "0" (d));
    baz (e);
  }
}
where according to the MSDN doc gcc incorrectly holds the c value
in xmm18 register across the foo call; if foo is compiled by some Microsoft
compiler (or LLVM), then it could clobber %xmm18.
If all xmm18 occurrences are changed to say xmm15, then it is valid to hold
the 128-bit value across the foo call (though, surprisingly, LLVM saves it
into stack anyway).

The other parts are I guess mainly about SEH.  Consider e.g.
void
foo (void)
{
  register double x __asm ("xmm14");
  register double y __asm ("xmm18");
  asm ("" : "=x" (x));
  asm ("" : "=v" (y));
  x += y;
  y += x;
  asm ("" : : "x" (x));
  asm ("" : : "v" (y));
}
looking at cross-compiler output, with -O2 -mavx512f this emits
	.file	"abcdeq.c"
	.text
	.align 16
	.globl	foo
	.def	foo;	.scl	2;	.type	32;	.endef
	.seh_proc	foo
foo:
	subq	$40, %rsp
	.seh_stackalloc	40
	vmovaps %xmm14,	(%rsp)
	.seh_savexmm	%xmm14, 0
	vmovaps %xmm18,	16(%rsp)
	.seh_savexmm	%xmm18, 16
	.seh_endprologue
	vaddsd	%xmm18, %xmm14, %xmm14
	vaddsd	%xmm18, %xmm14, %xmm18
	vmovaps	(%rsp), %xmm14
	vmovaps	16(%rsp), %xmm18
	addq	$40, %rsp
	ret
	.seh_endproc
	.ident	"GCC: (GNU) 10.0.1 20200207 (experimental)"
Does whatever assembler mingw64 uses even assemble this (I mean the
.seh_savexmm %xmm16, 16 could be problematic)?
I can find e.g.
https://stackoverflow.com/questions/43152633/invalid-register-for-seh-savexmm-in-cygwin/43210527
which then links to
https://gcc.gnu.org/PR65782

2020-02-08  Uroš Bizjak  <ubizjak@gmail.com>
	    Jakub Jelinek  <jakub@redhat.com>

	PR target/65782
	* config/i386/i386.h (CALL_USED_REGISTERS): Make
	xmm16-xmm31 call-used even in 64-bit ms-abi.

	* gcc.target/i386/pr65782.c: New test.

Co-authored-by: Uroš Bizjak <ubizjak@gmail.com>
---
 gcc/ChangeLog                           |  7 +++++++
 gcc/config/i386/i386.h                  |  4 ++--
 gcc/testsuite/ChangeLog                 |  6 ++++++
 gcc/testsuite/gcc.target/i386/pr65782.c | 16 ++++++++++++++++
 4 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr65782.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index dcff4acac4f..78522151f43 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-08  Uroš Bizjak  <ubizjak@gmail.com>
+		    Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/65782
+	* config/i386/i386.h (CALL_USED_REGISTERS): Make
+	xmm16-xmm31 call-used even in 64-bit ms-abi.
+
 	2020-02-06  Jakub Jelinek  <jakub@redhat.com>
 
 	PR libgomp/93515
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index d594d4a417c..aba63fb7a80 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -1062,9 +1062,9 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
 /*xmm8,xmm9,xmm10,xmm11,xmm12,xmm13,xmm14,xmm15*/		\
      6,   6,    6,    6,    6,    6,    6,    6,		\
 /*xmm16,xmm17,xmm18,xmm19,xmm20,xmm21,xmm22,xmm23*/		\
-     6,    6,     6,    6,    6,    6,    6,    6,		\
+     1,    1,     1,    1,    1,    1,    1,    1,		\
 /*xmm24,xmm25,xmm26,xmm27,xmm28,xmm29,xmm30,xmm31*/		\
-     6,    6,     6,    6,    6,    6,    6,    6,		\
+     1,    1,     1,    1,    1,    1,    1,    1,		\
  /* k0,  k1,  k2,  k3,  k4,  k5,  k6,  k7*/			\
      1,   1,   1,   1,   1,   1,   1,   1,			\
 /*   b0, b1, b2, b3*/						\
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 46dd81b222c..174defda1b3 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,12 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-08  Uroš Bizjak  <ubizjak@gmail.com>
+		    Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/65782
+	* gcc.target/i386/pr65782.c: New test.
+
 	2020-02-05  Jakub Jelinek  <jakub@redhat.com>
 
 	PR middle-end/93555
diff --git a/gcc/testsuite/gcc.target/i386/pr65782.c b/gcc/testsuite/gcc.target/i386/pr65782.c
new file mode 100644
index 00000000000..298dca1be97
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr65782.c
@@ -0,0 +1,16 @@
+/* PR target/65782 */
+/* { dg-do assemble { target { avx512vl && { ! ia32 } } } } */
+/* { dg-options "-O2 -mavx512vl" } */
+
+void
+foo (void)
+{
+  register double x __asm ("xmm14");
+  register double y __asm ("xmm18");
+  asm ("" : "=x" (x));
+  asm ("" : "=v" (y));
+  x += y;
+  y += x;
+  asm ("" : : "x" (x));
+  asm ("" : : "v" (y));
+}
-- 
2.20.1
From 231b10fe9f870a8a8a162e95416a6bc6df023839 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:48:42 +0100
Subject: [PATCH] i386: Fix -mavx -mno-mavx2 ICE with VEC_COND_EXPR [PR93637]

As mentioned in the PR, for -mavx -mno-avx2 the backend does support
vcondv4div4df and vcondv8siv8sf optabs (while generally 32-byte vectors
aren't much supported in that case, it is performed using
vandps/vandnps/vorps).  The problem is that after the last generic vector
lowering (where the VEC_COND_EXPR still compares two V4DF vectors and
has two V4DI last operands and V4DI result and so is considered ok) fre4
folds the condition into constant, at which point the middle-end during
expansion will try vcond_mask_optab and fall back to trying to expand it
as the constant vector < 0 vcondv4div4di, but neither of them is supported
for -mavx -mno-avx2 and thus we ICE.

So, the options I see is either what the following patch does, also support
vcond_mask_v4div4di and vcond_mask_v4siv4si already for TARGET_AVX, or
require for vcondv4div4df and vcondv8siv8sf TARGET_AVX2 rather than current
TARGET_AVX.

2020-02-10  Jakub Jelinek  <jakub@redhat.com>

	PR target/93637
	* config/i386/sse.md (VI_256_AVX2): New mode iterator.
	(vcond_mask_<mode><sseintvecmodelower>): Use it instead of VI_256.
	Change condition from TARGET_AVX2 to TARGET_AVX.

	* gcc.target/i386/avx-pr93637.c: New test.
---
 gcc/ChangeLog                               |  7 +++++++
 gcc/config/i386/sse.md                      | 16 +++++++++++-----
 gcc/testsuite/ChangeLog                     |  5 +++++
 gcc/testsuite/gcc.target/i386/avx-pr93637.c | 17 +++++++++++++++++
 4 files changed, 40 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/avx-pr93637.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 78522151f43..e5c2585cc1e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-10  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/93637
+	* config/i386/sse.md (VI_256_AVX2): New mode iterator.
+	(vcond_mask_<mode><sseintvecmodelower>): Use it instead of VI_256.
+	Change condition from TARGET_AVX2 to TARGET_AVX.
+
 	2020-02-08  Uroš Bizjak  <ubizjak@gmail.com>
 		    Jakub Jelinek  <jakub@redhat.com>
 
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 5c6d2948d65..e0923c40663 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -3075,13 +3075,19 @@
 	  (match_operand:<avx512fmaskmode> 3 "register_operand")))]
   "TARGET_AVX512BW")
 
+;; As vcondv4div4df and vcondv8siv8sf are enabled already with TARGET_AVX,
+;; and their condition can be folded late into a constant, we need to
+;; support vcond_mask_v4div4di and vcond_mask_v8siv8si for TARGET_AVX.
+(define_mode_iterator VI_256_AVX2 [(V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
+				   V8SI V4DI])
+
 (define_expand "vcond_mask_<mode><sseintvecmodelower>"
-  [(set (match_operand:VI_256 0 "register_operand")
-	(vec_merge:VI_256
-	  (match_operand:VI_256 1 "nonimmediate_operand")
-	  (match_operand:VI_256 2 "vector_move_operand")
+  [(set (match_operand:VI_256_AVX2 0 "register_operand")
+	(vec_merge:VI_256_AVX2
+	  (match_operand:VI_256_AVX2 1 "nonimmediate_operand")
+	  (match_operand:VI_256_AVX2 2 "vector_move_operand")
 	  (match_operand:<sseintvecmode> 3 "register_operand")))]
-  "TARGET_AVX2"
+  "TARGET_AVX"
 {
   ix86_expand_sse_movcc (operands[0], operands[3],
 			 operands[1], operands[2]);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 174defda1b3..16a7ec10756 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-10  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/93637
+	* gcc.target/i386/avx-pr93637.c: New test.
+
 	2020-02-08  Uroš Bizjak  <ubizjak@gmail.com>
 		    Jakub Jelinek  <jakub@redhat.com>
 
diff --git a/gcc/testsuite/gcc.target/i386/avx-pr93637.c b/gcc/testsuite/gcc.target/i386/avx-pr93637.c
new file mode 100644
index 00000000000..9e7a0a7c9c1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx-pr93637.c
@@ -0,0 +1,17 @@
+/* PR target/93637 */
+/* { dg-do compile } */
+/* { dg-options "-mavx -mno-avx2 -O3 --param sccvn-max-alias-queries-per-access=3" } */
+
+double
+foo (void)
+{
+  int i;
+  double r = 7.0;
+  double a[] = { 0.0, 0.0, -0.0, 0.0, 0.0, -0.0, 1.0, 0.0, 0.0, -0.0, 1.0, 0.0, 1.0, 1.0 };
+
+  for (i = 0; i < sizeof (a) / sizeof (a[0]); ++i)
+    if (a[i] == 0.0)
+      r = a[i];
+
+  return r;
+}
-- 
2.20.1
From 5538456480ad9c1a411b76479c798984bcae2c5c Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:49:11 +0100
Subject: [PATCH] i386: Fix up vec_extract_lo* patterns [PR93670]

The VEXTRACT* insns have way too many different CPUID feature flags (ATT
syntax)
vextractf128 $imm, %ymm, %xmm/mem		AVX
vextracti128 $imm, %ymm, %xmm/mem		AVX2
vextract{f,i}32x4 $imm, %ymm, %xmm/mem {k}{z}	AVX512VL+AVX512F
vextract{f,i}32x4 $imm, %zmm, %xmm/mem {k}{z}	AVX512F
vextract{f,i}64x2 $imm, %ymm, %xmm/mem {k}{z}	AVX512VL+AVX512DQ
vextract{f,i}64x2 $imm, %zmm, %xmm/mem {k}{z}	AVX512DQ
vextract{f,i}32x8 $imm, %zmm, %ymm/mem {k}{z}	AVX512DQ
vextract{f,i}64x4 $imm, %zmm, %ymm/mem {k}{z}	AVX512F

As the testcase shows and the patch too, we didn't get it right in all
cases.

The first hunk is about avx512vl_vextractf128v8s[if] incorrectly
requiring TARGET_AVX512DQ.  The corresponding insn is the first
vextract{f,i}32x4 above, so it requires VL+F, and the builtins have it
correct (TARGET_AVX512VL implies TARGET_AVX512F):
BDESC (OPTION_MASK_ISA_AVX512VL, 0, CODE_FOR_avx512vl_vextractf128v8sf, "__builtin_ia32_extractf32x4_256_mask", IX86_BUILTIN_EXTRACTF32X4_256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT_V4SF_UQI)
BDESC (OPTION_MASK_ISA_AVX512VL, 0, CODE_FOR_avx512vl_vextractf128v8si, "__builtin_ia32_extracti32x4_256_mask", IX86_BUILTIN_EXTRACTI32X4_256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT_V4SI_UQI)
We only need TARGET_AVX512DQ for avx512vl_vextractf128v4d[if].

The second hunk is about vec_extract_lo_v16s[if]{,_mask}.  These are using
the vextract{f,i}32x8 insns (AVX512DQ above), but we weren't requiring that,
but instead incorrectly && 1 for non-masked and && (64 == 64 && TARGET_AVX512VL)
for masked insns.  This is extraction from ZMM, so it doesn't need VL for
anything.  The hunk actually only requires TARGET_AVX512DQ when the insn
is masked, if it is not masked, when TARGET_AVX512DQ isn't available we can
use vextract{f,i}64x4 instead which is available already in TARGET_AVX512F
and does the same thing, extracts the low 256 bits from 512 bits vector
(often we split it into just nothing, but there are some special cases like
when using xmm16+ when we can't without AVX512VL).

The last hunk is about vec_extract_lo_v8s[if]{,_mask}.  The non-_mask
suffixed ones are ok already and just split into nothing (lowpart subreg).
The masked ones were incorrectly requiring TARGET_AVX512VL and
TARGET_AVX512DQ, when we only need TARGET_AVX512VL.

2020-02-12  Jakub Jelinek  <jakub@redhat.com>

	PR target/93670
	* config/i386/sse.md (VI48F_256_DQ): New mode iterator.
	(avx512vl_vextractf128<mode>): Use it instead of VI48F_256.  Remove
	TARGET_AVX512DQ from condition.
	(vec_extract_lo_<mode><mask_name>): Use <mask_avx512dq_condition>
	instead of <mask_mode512bit_condition> in condition.  If
	TARGET_AVX512DQ is false, emit vextract*64x4 instead of
	vextract*32x8.
	(vec_extract_lo_<mode><mask_name>): Drop <mask_avx512dq_condition>
	from condition.

	* gcc.target/i386/avx512vl-pr93670.c: New test.
---
 gcc/ChangeLog                                 | 13 ++++
 gcc/config/i386/sse.md                        | 18 +++--
 gcc/testsuite/ChangeLog                       |  5 ++
 .../gcc.target/i386/avx512vl-pr93670.c        | 77 +++++++++++++++++++
 4 files changed, 108 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/avx512vl-pr93670.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e5c2585cc1e..8301e344cf9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,19 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-12  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/93670
+	* config/i386/sse.md (VI48F_256_DQ): New mode iterator.
+	(avx512vl_vextractf128<mode>): Use it instead of VI48F_256.  Remove
+	TARGET_AVX512DQ from condition.
+	(vec_extract_lo_<mode><mask_name>): Use <mask_avx512dq_condition>
+	instead of <mask_mode512bit_condition> in condition.  If
+	TARGET_AVX512DQ is false, emit vextract*64x4 instead of
+	vextract*32x8.
+	(vec_extract_lo_<mode><mask_name>): Drop <mask_avx512dq_condition>
+	from condition.
+
 	2020-02-10  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/93637
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index e0923c40663..332fe3a8051 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -7605,13 +7605,16 @@
    (set_attr "prefix" "evex")
    (set_attr "mode" "<sseinsnmode>")])
 
+(define_mode_iterator VI48F_256_DQ
+  [V8SI V8SF (V4DI "TARGET_AVX512DQ") (V4DF "TARGET_AVX512DQ")])
+
 (define_expand "avx512vl_vextractf128<mode>"
   [(match_operand:<ssehalfvecmode> 0 "nonimmediate_operand")
-   (match_operand:VI48F_256 1 "register_operand")
+   (match_operand:VI48F_256_DQ 1 "register_operand")
    (match_operand:SI 2 "const_0_to_1_operand")
    (match_operand:<ssehalfvecmode> 3 "vector_move_operand")
    (match_operand:QI 4 "register_operand")]
-  "TARGET_AVX512DQ && TARGET_AVX512VL"
+  "TARGET_AVX512VL"
 {
   rtx (*insn)(rtx, rtx, rtx, rtx);
   rtx dest = operands[0];
@@ -7679,14 +7682,19 @@
                      (const_int 4) (const_int 5)
                      (const_int 6) (const_int 7)])))]
   "TARGET_AVX512F
-   && <mask_mode512bit_condition>
+   && <mask_avx512dq_condition>
    && (<mask_applied> || !(MEM_P (operands[0]) && MEM_P (operands[1])))"
 {
   if (<mask_applied>
       || (!TARGET_AVX512VL
 	  && !REG_P (operands[0])
 	  && EXT_REX_SSE_REG_P (operands[1])))
-    return "vextract<shuffletype>32x8\t{$0x0, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x0}";
+    {
+      if (TARGET_AVX512DQ)
+	return "vextract<shuffletype>32x8\t{$0x0, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x0}";
+      else
+	return "vextract<shuffletype>64x4\t{$0x0, %1, %0|%0, %1, 0x0}";
+    }
   else
     return "#";
 }
@@ -7796,7 +7804,7 @@
 	  (parallel [(const_int 0) (const_int 1)
 		     (const_int 2) (const_int 3)])))]
   "TARGET_AVX
-   && <mask_avx512vl_condition> && <mask_avx512dq_condition>
+   && <mask_avx512vl_condition>
    && (<mask_applied> || !(MEM_P (operands[0]) && MEM_P (operands[1])))"
 {
   if (<mask_applied>)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 16a7ec10756..1900240aca8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-12  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/93670
+	* gcc.target/i386/avx512vl-pr93670.c: New test.
+
 	2020-02-10  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/93637
diff --git a/gcc/testsuite/gcc.target/i386/avx512vl-pr93670.c b/gcc/testsuite/gcc.target/i386/avx512vl-pr93670.c
new file mode 100644
index 00000000000..3f232a96901
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512vl-pr93670.c
@@ -0,0 +1,77 @@
+/* PR target/93670 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512vl -mno-avx512dq" } */
+
+#include <x86intrin.h>
+
+__m128i
+f1 (__m256i x)
+{
+  return _mm256_extracti32x4_epi32 (x, 0);
+}
+
+__m128i
+f2 (__m256i x, __m128i w, __mmask8 m)
+{
+  return _mm256_mask_extracti32x4_epi32 (w, m, x, 0);
+}
+
+__m128i
+f3 (__m256i x, __mmask8 m)
+{
+  return _mm256_maskz_extracti32x4_epi32 (m, x, 0);
+}
+
+__m128
+f4 (__m256 x)
+{
+  return _mm256_extractf32x4_ps (x, 0);
+}
+
+__m128
+f5 (__m256 x, __m128 w, __mmask8 m)
+{
+  return _mm256_mask_extractf32x4_ps (w, m, x, 0);
+}
+
+__m128
+f6 (__m256 x, __mmask8 m)
+{
+  return _mm256_maskz_extractf32x4_ps (m, x, 0);
+}
+
+__m128i
+f7 (__m256i x)
+{
+  return _mm256_extracti32x4_epi32 (x, 1);
+}
+
+__m128i
+f8 (__m256i x, __m128i w, __mmask8 m)
+{
+  return _mm256_mask_extracti32x4_epi32 (w, m, x, 1);
+}
+
+__m128i
+f9 (__m256i x, __mmask8 m)
+{
+  return _mm256_maskz_extracti32x4_epi32 (m, x, 1);
+}
+
+__m128
+f10 (__m256 x)
+{
+  return _mm256_extractf32x4_ps (x, 1);
+}
+
+__m128
+f11 (__m256 x, __m128 w, __mmask8 m)
+{
+  return _mm256_mask_extractf32x4_ps (w, m, x, 1);
+}
+
+__m128
+f12 (__m256 x, __mmask8 m)
+{
+  return _mm256_maskz_extractf32x4_ps (m, x, 1);
+}
-- 
2.20.1
From fbb4d21086a20cd996049309d6c24d7fb3099123 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:49:32 +0100
Subject: [PATCH] i386: Fix k*shift* intrinsics [PR93673]

As mentioned in the PR, the intrinsics allow counts from 0 to 255, but
we actually reject values from 128 to 255.  That is because QImode
CONST_INTs can be only -128 to 127.  Fixed by using const_0_to_255_operand
and dropping the modes for the operands with those predicates
(the IL actually contains the CONST_INT which has VOIDmode).

2020-02-13  Jakub Jelinek  <jakub@redhat.com>

	PR target/93673
	* config/i386/sse.md (k<code><mode>): Drop mode from last operand and
	use const_0_to_255_operand predicate instead of immediate_operand.
	(avx512dq_fpclass<mode><mask_scalar_merge_name>,
	avx512dq_vmfpclass<mode><mask_scalar_merge_name>,
	vgf2p8affineinvqb_<mode><mask_name>,
	vgf2p8affineqb_<mode><mask_name>): Drop mode from
	const_0_to_255_operand predicated operands.

	* gcc.target/i386/avx512f-pr93673.c: New test.
	* gcc.target/i386/avx512dq-pr93673.c: New test.
	* gcc.target/i386/avx512bw-pr93673.c: New test.
---
 gcc/ChangeLog                                 | 11 +++++++
 gcc/config/i386/sse.md                        | 10 +++----
 gcc/testsuite/ChangeLog                       |  7 +++++
 .../gcc.target/i386/avx512bw-pr93673.c        | 30 +++++++++++++++++++
 .../gcc.target/i386/avx512dq-pr93673.c        | 20 +++++++++++++
 .../gcc.target/i386/avx512f-pr93673.c         | 20 +++++++++++++
 6 files changed, 93 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/avx512bw-pr93673.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx512dq-pr93673.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx512f-pr93673.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8301e344cf9..496845b3724 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,17 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-13  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/93673
+	* config/i386/sse.md (k<code><mode>): Drop mode from last operand and
+	use const_0_to_255_operand predicate instead of immediate_operand.
+	(avx512dq_fpclass<mode><mask_scalar_merge_name>,
+	avx512dq_vmfpclass<mode><mask_scalar_merge_name>,
+	vgf2p8affineinvqb_<mode><mask_name>,
+	vgf2p8affineqb_<mode><mask_name>): Drop mode from
+	const_0_to_255_operand predicated operands.
+
 	2020-02-12  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/93670
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 332fe3a8051..05a060d996d 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -1537,7 +1537,7 @@
   [(set (match_operand:SWI1248_AVX512BWDQ 0 "register_operand" "=k")
 	(any_lshift:SWI1248_AVX512BWDQ
 	  (match_operand:SWI1248_AVX512BWDQ 1 "register_operand" "k")
-	  (match_operand:QI 2 "immediate_operand" "n")))
+	  (match_operand 2 "const_0_to_255_operand" "n")))
    (unspec [(const_int 0)] UNSPEC_MASKOP)]
   "TARGET_AVX512F"
   "k<mshift><mskmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
@@ -19650,7 +19650,7 @@
   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
           (unspec:<avx512fmaskmode>
             [(match_operand:VF_AVX512VL 1 "register_operand" "v")
-             (match_operand:QI 2 "const_0_to_255_operand" "n")]
+             (match_operand 2 "const_0_to_255_operand" "n")]
              UNSPEC_FPCLASS))]
    "TARGET_AVX512DQ"
    "vfpclass<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}";
@@ -19664,7 +19664,7 @@
 	(and:<avx512fmaskmode>
 	  (unspec:<avx512fmaskmode>
 	    [(match_operand:VF_128 1 "register_operand" "v")
-             (match_operand:QI 2 "const_0_to_255_operand" "n")]
+             (match_operand 2 "const_0_to_255_operand" "n")]
 	    UNSPEC_FPCLASS)
 	  (const_int 1)))]
    "TARGET_AVX512DQ"
@@ -20269,7 +20269,7 @@
 	(unspec:VI1_AVX512F
 	  [(match_operand:VI1_AVX512F 1 "register_operand" "%0,x,v")
 	   (match_operand:VI1_AVX512F 2 "nonimmediate_operand" "xBm,xm,vm")
-	   (match_operand:QI 3 "const_0_to_255_operand" "n,n,n")]
+	   (match_operand 3 "const_0_to_255_operand" "n,n,n")]
 	  UNSPEC_GF2P8AFFINEINV))]
   "TARGET_GFNI"
   "@
@@ -20287,7 +20287,7 @@
 	(unspec:VI1_AVX512F
 	  [(match_operand:VI1_AVX512F 1 "register_operand" "%0,x,v")
 	   (match_operand:VI1_AVX512F 2 "nonimmediate_operand" "xBm,xm,vm")
-	   (match_operand:QI 3 "const_0_to_255_operand" "n,n,n")]
+	   (match_operand 3 "const_0_to_255_operand" "n,n,n")]
 	  UNSPEC_GF2P8AFFINE))]
   "TARGET_GFNI"
   "@
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1900240aca8..0b5a2592b36 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,13 @@
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
+	2020-02-13  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/93673
+	* gcc.target/i386/avx512f-pr93673.c: New test.
+	* gcc.target/i386/avx512dq-pr93673.c: New test.
+	* gcc.target/i386/avx512bw-pr93673.c: New test.
+
 	2020-02-12  Jakub Jelinek  <jakub@redhat.com>
 
 	PR target/93670
diff --git a/gcc/testsuite/gcc.target/i386/avx512bw-pr93673.c b/gcc/testsuite/gcc.target/i386/avx512bw-pr93673.c
new file mode 100644
index 00000000000..dc87ed20d1d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512bw-pr93673.c
@@ -0,0 +1,30 @@
+/* PR target/93673 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512bw" } */
+
+#include <x86intrin.h>
+
+void
+foo (__mmask32 *c, __mmask64 *d)
+{
+  c[0] = _kshiftli_mask32 (c[0], 0);
+  c[1] = _kshiftri_mask32 (c[1], 0);
+  c[2] = _kshiftli_mask32 (c[2], 1);
+  c[3] = _kshiftri_mask32 (c[3], 1);
+  c[4] = _kshiftli_mask32 (c[4], 31);
+  c[5] = _kshiftri_mask32 (c[5], 31);
+  c[6] = _kshiftli_mask32 (c[6], 0x7f);
+  c[7] = _kshiftri_mask32 (c[7], 0x7f);
+  c[8] = _kshiftli_mask32 (c[8], 0xff);
+  c[9] = _kshiftri_mask32 (c[9], 0xff);
+  d[0] = _kshiftli_mask64 (d[0], 0);
+  d[1] = _kshiftri_mask64 (d[1], 0);
+  d[2] = _kshiftli_mask64 (d[2], 1);
+  d[3] = _kshiftri_mask64 (d[3], 1);
+  d[4] = _kshiftli_mask64 (d[4], 63);
+  d[5] = _kshiftri_mask64 (d[5], 63);
+  d[6] = _kshiftli_mask64 (d[6], 0x7f);
+  d[7] = _kshiftri_mask64 (d[7], 0x7f);
+  d[8] = _kshiftli_mask64 (d[8], 0xff);
+  d[9] = _kshiftri_mask64 (d[9], 0xff);
+}
diff --git a/gcc/testsuite/gcc.target/i386/avx512dq-pr93673.c b/gcc/testsuite/gcc.target/i386/avx512dq-pr93673.c
new file mode 100644
index 00000000000..3ae1674e4a4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512dq-pr93673.c
@@ -0,0 +1,20 @@
+/* PR target/93673 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512dq" } */
+
+#include <x86intrin.h>
+
+void
+foo (__mmask8 *a)
+{
+  a[0] = _kshiftli_mask8 (a[0], 0);
+  a[1] = _kshiftri_mask8 (a[1], 0);
+  a[2] = _kshiftli_mask8 (a[2], 1);
+  a[3] = _kshiftri_mask8 (a[3], 1);
+  a[4] = _kshiftli_mask8 (a[4], 7);
+  a[5] = _kshiftri_mask8 (a[5], 7);
+  a[6] = _kshiftli_mask8 (a[6], 0x7f);
+  a[7] = _kshiftri_mask8 (a[7], 0x7f);
+  a[8] = _kshiftli_mask8 (a[8], 0xff);
+  a[9] = _kshiftri_mask8 (a[9], 0xff);
+}
diff --git a/gcc/testsuite/gcc.target/i386/avx512f-pr93673.c b/gcc/testsuite/gcc.target/i386/avx512f-pr93673.c
new file mode 100644
index 00000000000..963823c8a78
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512f-pr93673.c
@@ -0,0 +1,20 @@
+/* PR target/93673 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512f" } */
+
+#include <x86intrin.h>
+
+void
+foo (__mmask16 *b)
+{
+  b[0] = _kshiftli_mask16 (b[0], 0);
+  b[1] = _kshiftri_mask16 (b[1], 0);
+  b[2] = _kshiftli_mask16 (b[2], 1);
+  b[3] = _kshiftri_mask16 (b[3], 1);
+  b[4] = _kshiftli_mask16 (b[4], 15);
+  b[5] = _kshiftri_mask16 (b[5], 15);
+  b[6] = _kshiftli_mask16 (b[6], 0x7f);
+  b[7] = _kshiftri_mask16 (b[7], 0x7f);
+  b[8] = _kshiftli_mask16 (b[8], 0xff);
+  b[9] = _kshiftri_mask16 (b[9], 0xff);
+}
-- 
2.20.1
From db4bfbae142906291ee319d768f4fa56d2a7682c Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:50:10 +0100
Subject: [PATCH] i386: Fix up _mm*_mask_popcnt_epi* [PR93696]

As mentioned in the PR and as
https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mask_popcnt_epi
also documents, _mm*_popcnt_epi* intrinsics are consistent with all other
unary AVX512* intrinsics regarding arguments, i.e. the
_mm*_whatever has just single argument (called a in the docs, and __A in the
GCC headers),
_mm*_mask_whatever has 3 arguments (called src, k, a in the docs and
_W, __U, __A in GCC headers) and
_mm*_maskz_whatever 2 arguments (called k, a in the docs and __U, __A in GCC
headers).  Unfortunately, whomever implemented the _mm*_popcnt_epi*
intrinsics got it wrong for the _mm*_mask_popcnt_epi* ones, calling the
args __A, __U, __B and not passing them in the canonical order to the
builtins, making it API incompatible with ICC as well as clang (tested on
godbolts clang 7/8/9/trunk and ICC 19.0.{0,1}, older clang/ICC don't
understand those, so it isn't that it used to be broken even in other
compilers and got changed afterwards).

2020-02-13  Jakub Jelinek  <jakub@redhat.com>

	PR target/93696
	* config/i386/avx512bitalgintrin.h (_mm512_mask_popcnt_epi8,
	_mm512_mask_popcnt_epi16, _mm256_mask_popcnt_epi8,
	_mm256_mask_popcnt_epi16, _mm_mask_popcnt_epi8,
	_mm_mask_popcnt_epi16): Rename __B argument to __A and __A to __W,
	pass __A to the builtin followed by __W instead of __A followed by
	__B.
	* config/i386/avx512vpopcntdqintrin.h (_mm512_mask_popcnt_epi32,
	_mm512_mask_popcnt_epi64): Likewise.
	* config/i386/avx512vpopcntdqvlintrin.h (_mm_mask_popcnt_epi32,
	_mm256_mask_popcnt_epi32, _mm_mask_popcnt_epi64,
	_mm256_mask_popcnt_epi64): Likewise.

	* gcc.target/i386/pr93696-1.c: New test.
	* gcc.target/i386/pr93696-2.c: New test.
	* gcc.target/i386/avx512bitalg-vpopcntw-1.c (TEST): Fix argument order
	of _mm*_mask_popcnt_*.
	* gcc.target/i386/avx512vpopcntdq-vpopcntq-1.c (TEST): Likewise.
	* gcc.target/i386/avx512vpopcntdq-vpopcntd-1.c (TEST): Likewise.
	* gcc.target/i386/avx512bitalg-vpopcntb-1.c (TEST): Likewise.
	* gcc.target/i386/avx512bitalg-vpopcntb.c (foo): Likewise.
	* gcc.target/i386/avx512bitalg-vpopcntbvl.c (foo): Likewise.
	* gcc.target/i386/avx512vpopcntdq-vpopcntd.c (foo): Likewise.
	* gcc.target/i386/avx512bitalg-vpopcntwvl.c (foo): Likewise.
	* gcc.target/i386/avx512bitalg-vpopcntw.c (foo): Likewise.
	* gcc.target/i386/avx512vpopcntdq-vpopcntq.c (foo): Likewise.
---
 gcc/ChangeLog                                 | 13 +++
 gcc/config/i386/avx512bitalgintrin.h          | 24 +++---
 gcc/config/i386/avx512vpopcntdqintrin.h       |  8 +-
 gcc/config/i386/avx512vpopcntdqvlintrin.h     | 17 ++--
 gcc/testsuite/ChangeLog                       | 15 ++++
 .../gcc.target/i386/avx512bitalg-vpopcntb-1.c |  2 +-
 .../gcc.target/i386/avx512bitalg-vpopcntb.c   |  2 +-
 .../gcc.target/i386/avx512bitalg-vpopcntbvl.c |  4 +-
 .../gcc.target/i386/avx512bitalg-vpopcntw-1.c |  2 +-
 .../gcc.target/i386/avx512bitalg-vpopcntw.c   |  2 +-
 .../gcc.target/i386/avx512bitalg-vpopcntwvl.c |  4 +-
 .../i386/avx512vpopcntdq-vpopcntd-1.c         |  2 +-
 .../i386/avx512vpopcntdq-vpopcntd.c           |  6 +-
 .../i386/avx512vpopcntdq-vpopcntq-1.c         |  2 +-
 .../i386/avx512vpopcntdq-vpopcntq.c           |  6 +-
 gcc/testsuite/gcc.target/i386/pr93696-1.c     | 79 +++++++++++++++++++
 gcc/testsuite/gcc.target/i386/pr93696-2.c     | 79 +++++++++++++++++++
 17 files changed, 226 insertions(+), 41 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr93696-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr93696-2.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 496845b3724..eb0f65f2a6d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -3,6 +3,19 @@
 	Backported from mainline
 	2020-02-13  Jakub Jelinek  <jakub@redhat.com>
 
+	PR target/93696
+	* config/i386/avx512bitalgintrin.h (_mm512_mask_popcnt_epi8,
+	_mm512_mask_popcnt_epi16, _mm256_mask_popcnt_epi8,
+	_mm256_mask_popcnt_epi16, _mm_mask_popcnt_epi8,
+	_mm_mask_popcnt_epi16): Rename __B argument to __A and __A to __W,
+	pass __A to the builtin followed by __W instead of __A followed by
+	__B.
+	* config/i386/avx512vpopcntdqintrin.h (_mm512_mask_popcnt_epi32,
+	_mm512_mask_popcnt_epi64): Likewise.
+	* config/i386/avx512vpopcntdqvlintrin.h (_mm_mask_popcnt_epi32,
+	_mm256_mask_popcnt_epi32, _mm_mask_popcnt_epi64,
+	_mm256_mask_popcnt_epi64): Likewise.
+
 	PR target/93673
 	* config/i386/sse.md (k<code><mode>): Drop mode from last operand and
 	use const_0_to_255_operand predicate instead of immediate_operand.
diff --git a/gcc/config/i386/avx512bitalgintrin.h b/gcc/config/i386/avx512bitalgintrin.h
index 3a7414adb69..5c5c99f1552 100644
--- a/gcc/config/i386/avx512bitalgintrin.h
+++ b/gcc/config/i386/avx512bitalgintrin.h
@@ -61,10 +61,10 @@ _mm512_popcnt_epi16 (__m512i __A)
 
 extern __inline __m512i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm512_mask_popcnt_epi8 (__m512i __A, __mmask64 __U, __m512i __B)
+_mm512_mask_popcnt_epi8 (__m512i __W, __mmask64 __U, __m512i __A)
 {
   return (__m512i) __builtin_ia32_vpopcountb_v64qi_mask ((__v64qi) __A,
-							 (__v64qi) __B,
+							 (__v64qi) __W,
 							 (__mmask64) __U);
 }
 
@@ -79,10 +79,10 @@ _mm512_maskz_popcnt_epi8 (__mmask64 __U, __m512i __A)
 }
 extern __inline __m512i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm512_mask_popcnt_epi16 (__m512i __A, __mmask32 __U, __m512i __B)
+_mm512_mask_popcnt_epi16 (__m512i __W, __mmask32 __U, __m512i __A)
 {
   return (__m512i) __builtin_ia32_vpopcountw_v32hi_mask ((__v32hi) __A,
-							(__v32hi) __B,
+							(__v32hi) __W,
 							(__mmask32) __U);
 }
 
@@ -127,10 +127,10 @@ _mm512_mask_bitshuffle_epi64_mask (__mmask64 __M, __m512i __A, __m512i __B)
 
 extern __inline __m256i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm256_mask_popcnt_epi8 (__m256i __A, __mmask32 __U, __m256i __B)
+_mm256_mask_popcnt_epi8 (__m256i __W, __mmask32 __U, __m256i __A)
 {
   return (__m256i) __builtin_ia32_vpopcountb_v32qi_mask ((__v32qi) __A,
-							 (__v32qi) __B,
+							 (__v32qi) __W,
 							 (__mmask32) __U);
 }
 
@@ -222,10 +222,10 @@ _mm_popcnt_epi16 (__m128i __A)
 
 extern __inline __m256i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm256_mask_popcnt_epi16 (__m256i __A, __mmask16 __U, __m256i __B)
+_mm256_mask_popcnt_epi16 (__m256i __W, __mmask16 __U, __m256i __A)
 {
   return (__m256i) __builtin_ia32_vpopcountw_v16hi_mask ((__v16hi) __A,
-							(__v16hi) __B,
+							(__v16hi) __W,
 							(__mmask16) __U);
 }
 
@@ -241,10 +241,10 @@ _mm256_maskz_popcnt_epi16 (__mmask16 __U, __m256i __A)
 
 extern __inline __m128i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm_mask_popcnt_epi8 (__m128i __A, __mmask16 __U, __m128i __B)
+_mm_mask_popcnt_epi8 (__m128i __W, __mmask16 __U, __m128i __A)
 {
   return (__m128i) __builtin_ia32_vpopcountb_v16qi_mask ((__v16qi) __A,
-							 (__v16qi) __B,
+							 (__v16qi) __W,
 							 (__mmask16) __U);
 }
 
@@ -259,10 +259,10 @@ _mm_maskz_popcnt_epi8 (__mmask16 __U, __m128i __A)
 }
 extern __inline __m128i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm_mask_popcnt_epi16 (__m128i __A, __mmask8 __U, __m128i __B)
+_mm_mask_popcnt_epi16 (__m128i __W, __mmask8 __U, __m128i __A)
 {
   return (__m128i) __builtin_ia32_vpopcountw_v8hi_mask ((__v8hi) __A,
-							(__v8hi) __B,
+							(__v8hi) __W,
 							(__mmask8) __U);
 }
 
diff --git a/gcc/config/i386/avx512vpopcntdqintrin.h b/gcc/config/i386/avx512vpopcntdqintrin.h
index 722f6f841a7..cdf164971dd 100644
--- a/gcc/config/i386/avx512vpopcntdqintrin.h
+++ b/gcc/config/i386/avx512vpopcntdqintrin.h
@@ -43,10 +43,10 @@ _mm512_popcnt_epi32 (__m512i __A)
 
 extern __inline __m512i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm512_mask_popcnt_epi32 (__m512i __A, __mmask16 __U, __m512i __B)
+_mm512_mask_popcnt_epi32 (__m512i __W, __mmask16 __U, __m512i __A)
 {
   return (__m512i) __builtin_ia32_vpopcountd_v16si_mask ((__v16si) __A,
-							 (__v16si) __B,
+							 (__v16si) __W,
 							 (__mmask16) __U);
 }
 
@@ -69,10 +69,10 @@ _mm512_popcnt_epi64 (__m512i __A)
 
 extern __inline __m512i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm512_mask_popcnt_epi64 (__m512i __A, __mmask8 __U, __m512i __B)
+_mm512_mask_popcnt_epi64 (__m512i __W, __mmask8 __U, __m512i __A)
 {
   return (__m512i) __builtin_ia32_vpopcountq_v8di_mask ((__v8di) __A,
-							(__v8di) __B,
+							(__v8di) __W,
 							(__mmask8) __U);
 }
 
diff --git a/gcc/config/i386/avx512vpopcntdqvlintrin.h b/gcc/config/i386/avx512vpopcntdqvlintrin.h
index 85fc6ea6fa7..6c5da05a8bf 100644
--- a/gcc/config/i386/avx512vpopcntdqvlintrin.h
+++ b/gcc/config/i386/avx512vpopcntdqvlintrin.h
@@ -43,10 +43,10 @@ _mm_popcnt_epi32 (__m128i __A)
 
 extern __inline __m128i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm_mask_popcnt_epi32 (__m128i __A, __mmask16 __U, __m128i __B)
+_mm_mask_popcnt_epi32 (__m128i __W, __mmask16 __U, __m128i __A)
 {
   return (__m128i) __builtin_ia32_vpopcountd_v4si_mask ((__v4si) __A,
-							 (__v4si) __B,
+							 (__v4si) __W,
 							 (__mmask16) __U);
 }
 
@@ -69,10 +69,10 @@ _mm256_popcnt_epi32 (__m256i __A)
 
 extern __inline __m256i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm256_mask_popcnt_epi32 (__m256i __A, __mmask16 __U, __m256i __B)
+_mm256_mask_popcnt_epi32 (__m256i __W, __mmask16 __U, __m256i __A)
 {
   return (__m256i) __builtin_ia32_vpopcountd_v8si_mask ((__v8si) __A,
-							 (__v8si) __B,
+							 (__v8si) __W,
 							 (__mmask16) __U);
 }
 
@@ -95,10 +95,10 @@ _mm_popcnt_epi64 (__m128i __A)
 
 extern __inline __m128i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm_mask_popcnt_epi64 (__m128i __A, __mmask8 __U, __m128i __B)
+_mm_mask_popcnt_epi64 (__m128i __W, __mmask8 __U, __m128i __A)
 {
   return (__m128i) __builtin_ia32_vpopcountq_v2di_mask ((__v2di) __A,
-							(__v2di) __B,
+							(__v2di) __W,
 							(__mmask8) __U);
 }
 
@@ -121,10 +121,10 @@ _mm256_popcnt_epi64 (__m256i __A)
 
 extern __inline __m256i
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
-_mm256_mask_popcnt_epi64 (__m256i __A, __mmask8 __U, __m256i __B)
+_mm256_mask_popcnt_epi64 (__m256i __W, __mmask8 __U, __m256i __A)
 {
   return (__m256i) __builtin_ia32_vpopcountq_v4di_mask ((__v4di) __A,
-							(__v4di) __B,
+							(__v4di) __W,
 							(__mmask8) __U);
 }
 
@@ -144,4 +144,3 @@ _mm256_maskz_popcnt_epi64 (__mmask8 __U, __m256i __A)
 #endif /* __DISABLE_AVX512VPOPCNTDQVL__ */
 
 #endif /* _AVX512VPOPCNTDQVLINTRIN_H_INCLUDED */
-
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0b5a2592b36..e0cadc31f3a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,21 @@
 	Backported from mainline
 	2020-02-13  Jakub Jelinek  <jakub@redhat.com>
 
+	PR target/93696
+	* gcc.target/i386/pr93696-1.c: New test.
+	* gcc.target/i386/pr93696-2.c: New test.
+	* gcc.target/i386/avx512bitalg-vpopcntw-1.c (TEST): Fix argument order
+	of _mm*_mask_popcnt_*.
+	* gcc.target/i386/avx512vpopcntdq-vpopcntq-1.c (TEST): Likewise.
+	* gcc.target/i386/avx512vpopcntdq-vpopcntd-1.c (TEST): Likewise.
+	* gcc.target/i386/avx512bitalg-vpopcntb-1.c (TEST): Likewise.
+	* gcc.target/i386/avx512bitalg-vpopcntb.c (foo): Likewise.
+	* gcc.target/i386/avx512bitalg-vpopcntbvl.c (foo): Likewise.
+	* gcc.target/i386/avx512vpopcntdq-vpopcntd.c (foo): Likewise.
+	* gcc.target/i386/avx512bitalg-vpopcntwvl.c (foo): Likewise.
+	* gcc.target/i386/avx512bitalg-vpopcntw.c (foo): Likewise.
+	* gcc.target/i386/avx512vpopcntdq-vpopcntq.c (foo): Likewise.
+
 	PR target/93673
 	* gcc.target/i386/avx512f-pr93673.c: New test.
 	* gcc.target/i386/avx512dq-pr93673.c: New test.
diff --git a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntb-1.c b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntb-1.c
index 3dcd48f7e2a..697757b8b73 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntb-1.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntb-1.c
@@ -41,7 +41,7 @@ TEST (void)
   }
 
   res1.x = INTRINSIC (_popcnt_epi8)       (src.x);
-  res2.x = INTRINSIC (_mask_popcnt_epi8)  (src.x, mask, src0.x);
+  res2.x = INTRINSIC (_mask_popcnt_epi8)  (src0.x, mask, src.x);
   res3.x = INTRINSIC (_maskz_popcnt_epi8) (mask, src.x);
 
   if (UNION_CHECK (AVX512F_LEN, i_b) (res1, res_ref))
diff --git a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntb.c b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntb.c
index b23da58dbaf..246f925eede 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntb.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntb.c
@@ -13,7 +13,7 @@ int foo ()
   __mmask16 msk;
   __m512i c = _mm512_popcnt_epi8 (z);
   asm volatile ("" : "+v" (c));
-  c = _mm512_mask_popcnt_epi8 (z, msk, z1);
+  c = _mm512_mask_popcnt_epi8 (z1, msk, z);
   asm volatile ("" : "+v" (c));
   c = _mm512_maskz_popcnt_epi8 (msk, z);
   asm volatile ("" : "+v" (c));
diff --git a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntbvl.c b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntbvl.c
index e6d60f7596c..8c7f45fc5f7 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntbvl.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntbvl.c
@@ -18,13 +18,13 @@ int foo ()
   __mmask16 msk16;
   __m256i c256 = _mm256_popcnt_epi8 (y);
   asm volatile ("" : "+v" (c256));
-  c256 = _mm256_mask_popcnt_epi8 (y, msk32, y_1);
+  c256 = _mm256_mask_popcnt_epi8 (y_1, msk32, y);
   asm volatile ("" : "+v" (c256));
   c256 = _mm256_maskz_popcnt_epi8 (msk32, y);
   asm volatile ("" : "+v" (c256));
   __m128i c128 = _mm_popcnt_epi8 (x);
   asm volatile ("" : "+v" (c128));
-  c128 = _mm_mask_popcnt_epi8 (x, msk16, x_1);
+  c128 = _mm_mask_popcnt_epi8 (x_1, msk16, x);
   asm volatile ("" : "+v" (c128));
   c128 = _mm_maskz_popcnt_epi8 (msk16, x);
   asm volatile ("" : "+v" (c128));
diff --git a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntw-1.c b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntw-1.c
index 4f866db2f7a..0a725fe012a 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntw-1.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntw-1.c
@@ -41,7 +41,7 @@ TEST (void)
   }
 
   res1.x = INTRINSIC (_popcnt_epi16)       (src.x);
-  res2.x = INTRINSIC (_mask_popcnt_epi16)  (src.x, mask, src0.x);
+  res2.x = INTRINSIC (_mask_popcnt_epi16)  (src0.x, mask, src.x);
   res3.x = INTRINSIC (_maskz_popcnt_epi16) (mask, src.x);
 
   if (UNION_CHECK (AVX512F_LEN, i_w) (res1, res_ref))
diff --git a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntw.c b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntw.c
index 2c49583b597..90663f480fc 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntw.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntw.c
@@ -13,7 +13,7 @@ int foo ()
   __mmask16 msk;
   __m512i c = _mm512_popcnt_epi16 (z);
   asm volatile ("" : "+v" (c));
-  c = _mm512_mask_popcnt_epi16 (z, msk, z1);
+  c = _mm512_mask_popcnt_epi16 (z1, msk, z);
   asm volatile ("" : "+v" (c));
   c = _mm512_maskz_popcnt_epi16 (msk, z);
   asm volatile ("" : "+v" (c));
diff --git a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntwvl.c b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntwvl.c
index b55adc6023a..3a646b57282 100644
--- a/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntwvl.c
+++ b/gcc/testsuite/gcc.target/i386/avx512bitalg-vpopcntwvl.c
@@ -18,13 +18,13 @@ int foo ()
   __mmask8 msk8;
   __m256i c256 = _mm256_popcnt_epi16 (y);
   asm volatile ("" : "+v" (c256));
-  c256 = _mm256_mask_popcnt_epi16 (y, msk16, y_1);
+  c256 = _mm256_mask_popcnt_epi16 (y_1, msk16, y);
   asm volatile ("" : "+v" (c256));
   c256 = _mm256_maskz_popcnt_epi16 (msk16, y);
   asm volatile ("" : "+v" (c256));
   __m128i c128 = _mm_popcnt_epi16 (x);
   asm volatile ("" : "+v" (c128));
-  c128 = _mm_mask_popcnt_epi16 (x, msk8, x_1);
+  c128 = _mm_mask_popcnt_epi16 (x_1, msk8, x);
   asm volatile ("" : "+v" (c128));
   c128 = _mm_maskz_popcnt_epi16 (msk8, x);
   asm volatile ("" : "+v" (c128));
diff --git a/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntd-1.c b/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntd-1.c
index 245dcd4d534..e7d6bb4dd53 100644
--- a/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntd-1.c
+++ b/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntd-1.c
@@ -40,7 +40,7 @@ TEST (void)
   }
 
   res1.x = INTRINSIC (_popcnt_epi32)       (src.x);
-  res2.x = INTRINSIC (_mask_popcnt_epi32)  (src.x, mask, src0.x);
+  res2.x = INTRINSIC (_mask_popcnt_epi32)  (src0.x, mask, src.x);
   res3.x = INTRINSIC (_maskz_popcnt_epi32) (mask, src.x);
 
   if (UNION_CHECK (AVX512F_LEN, i_d) (res1, res_ref))
diff --git a/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntd.c b/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntd.c
index c70f226824e..b4d82f97032 100644
--- a/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntd.c
+++ b/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntd.c
@@ -22,19 +22,19 @@ int foo ()
   __mmask8 msk8;
   __m128i a = _mm_popcnt_epi32 (x);
   asm volatile ("" : "+v" (a));
-  a = _mm_mask_popcnt_epi32 (x, msk8, x_1);
+  a = _mm_mask_popcnt_epi32 (x_1, msk8, x);
   asm volatile ("" : "+v" (a));
   a = _mm_maskz_popcnt_epi32 (msk8, x);
   asm volatile ("" : "+v" (a));
   __m256i b = _mm256_popcnt_epi32 (y);
   asm volatile ("" : "+v" (b));
-  b = _mm256_mask_popcnt_epi32 (y, msk8, y_1);
+  b = _mm256_mask_popcnt_epi32 (y_1, msk8, y);
   asm volatile ("" : "+v" (b));
   b = _mm256_maskz_popcnt_epi32 (msk8, y);
   asm volatile ("" : "+v" (b));
   __m512i c = _mm512_popcnt_epi32 (z);
   asm volatile ("" : "+v" (c));
-  c = _mm512_mask_popcnt_epi32 (z, msk, z_1);
+  c = _mm512_mask_popcnt_epi32 (z_1, msk, z);
   asm volatile ("" : "+v" (c));
   c = _mm512_maskz_popcnt_epi32 (msk, z);
   asm volatile ("" : "+v" (c));
diff --git a/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntq-1.c b/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntq-1.c
index 27555c496d6..2144cf32c0d 100644
--- a/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntq-1.c
+++ b/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntq-1.c
@@ -40,7 +40,7 @@ TEST (void)
   }
 
   res1.x = INTRINSIC (_popcnt_epi64)       (src.x);
-  res2.x = INTRINSIC (_mask_popcnt_epi64)  (src.x, mask, src0.x);
+  res2.x = INTRINSIC (_mask_popcnt_epi64)  (src0.x, mask, src.x);
   res3.x = INTRINSIC (_maskz_popcnt_epi64) (mask, src.x);
 
   if (UNION_CHECK (AVX512F_LEN, i_q) (res1, res_ref))
diff --git a/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntq.c b/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntq.c
index 9f400c005f3..e87d6c999b6 100644
--- a/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntq.c
+++ b/gcc/testsuite/gcc.target/i386/avx512vpopcntdq-vpopcntq.c
@@ -21,19 +21,19 @@ int foo ()
   __mmask8 msk; 
   __m128i a = _mm_popcnt_epi64 (x);
   asm volatile ("" : "+v" (a));
-  a = _mm_mask_popcnt_epi64 (x, msk, x_1);
+  a = _mm_mask_popcnt_epi64 (x_1, msk, x);
   asm volatile ("" : "+v" (a));
   a = _mm_maskz_popcnt_epi64 (msk, x);
   asm volatile ("" : "+v" (a));
   __m256i b = _mm256_popcnt_epi64 (y);
   asm volatile ("" : "+v" (b));
-  b = _mm256_mask_popcnt_epi64 (y, msk, y_1);
+  b = _mm256_mask_popcnt_epi64 (y_1, msk, y);
   asm volatile ("" : "+v" (b));
   b = _mm256_maskz_popcnt_epi64 (msk, y);
   asm volatile ("" : "+v" (b));
   __m512i c = _mm512_popcnt_epi64 (z);
   asm volatile ("" : "+v" (c));
-  c = _mm512_mask_popcnt_epi64 (z, msk, z_1);
+  c = _mm512_mask_popcnt_epi64 (z_1, msk, z);
   asm volatile ("" : "+v" (c));
   c = _mm512_maskz_popcnt_epi64 (msk, z); 
   asm volatile ("" : "+v" (c));
diff --git a/gcc/testsuite/gcc.target/i386/pr93696-1.c b/gcc/testsuite/gcc.target/i386/pr93696-1.c
new file mode 100644
index 00000000000..128bb98c066
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr93696-1.c
@@ -0,0 +1,79 @@
+/* PR target/93696 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512bitalg -mavx512vpopcntdq -mavx512vl -mavx512bw -masm=att" } */
+/* { dg-final { scan-assembler-times "vpopcnt\[bwdq]\t%\[xyz]mm1, %\[xyz]mm0\{%k\[0-7]\}\[^\{]" 12 } } */
+/* { dg-final { scan-assembler-not "vmovdq\[au]\[0-9]" } } */
+
+#include <x86intrin.h>
+
+__m128i
+f1 (__m128i x, __mmask8 m, __m128i y)
+{
+  return _mm_mask_popcnt_epi64 (x, m, y);
+}
+
+__m128i
+f2 (__m128i x, __mmask8 m, __m128i y)
+{
+  return _mm_mask_popcnt_epi32 (x, m, y);
+}
+
+__m128i
+f3 (__m128i x, __mmask8 m, __m128i y)
+{
+  return _mm_mask_popcnt_epi16 (x, m, y);
+}
+
+__m128i
+f4 (__m128i x, __mmask16 m, __m128i y)
+{
+  return _mm_mask_popcnt_epi8 (x, m, y);
+}
+
+__m256i
+f5 (__m256i x, __mmask8 m, __m256i y)
+{
+  return _mm256_mask_popcnt_epi64 (x, m, y);
+}
+
+__m256i
+f6 (__m256i x, __mmask8 m, __m256i y)
+{
+  return _mm256_mask_popcnt_epi32 (x, m, y);
+}
+
+__m256i
+f7 (__m256i x, __mmask16 m, __m256i y)
+{
+  return _mm256_mask_popcnt_epi16 (x, m, y);
+}
+
+__m256i
+f8 (__m256i x, __mmask32 m, __m256i y)
+{
+  return _mm256_mask_popcnt_epi8 (x, m, y);
+}
+
+__m512i
+f9 (__m512i x, __mmask8 m, __m512i y)
+{
+  return _mm512_mask_popcnt_epi64 (x, m, y);
+}
+
+__m512i
+f10 (__m512i x, __mmask16 m, __m512i y)
+{
+  return _mm512_mask_popcnt_epi32 (x, m, y);
+}
+
+__m512i
+f11 (__m512i x, __mmask32 m, __m512i y)
+{
+  return _mm512_mask_popcnt_epi16 (x, m, y);
+}
+
+__m512i
+f12 (__m512i x, __mmask64 m, __m512i y)
+{
+  return _mm512_mask_popcnt_epi8 (x, m, y);
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr93696-2.c b/gcc/testsuite/gcc.target/i386/pr93696-2.c
new file mode 100644
index 00000000000..25a298aea18
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr93696-2.c
@@ -0,0 +1,79 @@
+/* PR target/93696 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512bitalg -mavx512vpopcntdq -mavx512vl -mavx512bw -masm=att" } */
+/* { dg-final { scan-assembler-times "vpopcnt\[bwdq]\t%\[xyz]mm1, %\[xyz]mm0\{%k\[0-7]\}\{z\}" 12 } } */
+/* { dg-final { scan-assembler-not "vmovdq\[au]\[0-9]" } } */
+
+#include <x86intrin.h>
+
+__m128i
+f1 (__m128i x, __mmask8 m, __m128i y)
+{
+  return _mm_maskz_popcnt_epi64 (m, y);
+}
+
+__m128i
+f2 (__m128i x, __mmask8 m, __m128i y)
+{
+  return _mm_maskz_popcnt_epi32 (m, y);
+}
+
+__m128i
+f3 (__m128i x, __mmask8 m, __m128i y)
+{
+  return _mm_maskz_popcnt_epi16 (m, y);
+}
+
+__m128i
+f4 (__m128i x, __mmask16 m, __m128i y)
+{
+  return _mm_maskz_popcnt_epi8 (m, y);
+}
+
+__m256i
+f5 (__m256i x, __mmask8 m, __m256i y)
+{
+  return _mm256_maskz_popcnt_epi64 (m, y);
+}
+
+__m256i
+f6 (__m256i x, __mmask8 m, __m256i y)
+{
+  return _mm256_maskz_popcnt_epi32 (m, y);
+}
+
+__m256i
+f7 (__m256i x, __mmask16 m, __m256i y)
+{
+  return _mm256_maskz_popcnt_epi16 (m, y);
+}
+
+__m256i
+f8 (__m256i x, __mmask32 m, __m256i y)
+{
+  return _mm256_maskz_popcnt_epi8 (m, y);
+}
+
+__m512i
+f9 (__m512i x, __mmask8 m, __m512i y)
+{
+  return _mm512_maskz_popcnt_epi64 (m, y);
+}
+
+__m512i
+f10 (__m512i x, __mmask16 m, __m512i y)
+{
+  return _mm512_maskz_popcnt_epi32 (m, y);
+}
+
+__m512i
+f11 (__m512i x, __mmask32 m, __m512i y)
+{
+  return _mm512_maskz_popcnt_epi16 (m, y);
+}
+
+__m512i
+f12 (__m512i x, __mmask64 m, __m512i y)
+{
+  return _mm512_maskz_popcnt_epi8 (m, y);
+}
-- 
2.20.1
From cd73697811f4d638a26be9aeada6eb20b645b739 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 15:50:57 +0100
Subject: [PATCH] c: Fix ICE with cast to VLA [93576]

The following testcase ICEs, because the PR84305 changes try to evaluate
the size earlier.  If size has side-effects, that is desirable, and the
side-effects will actually be wrapped in a SAVE_EXPR.  The problem on this
testcase is that there are no side-effects, and c_fully_fold doesn't fold
those COMPOUND_EXPRs to constant, and while before gimplification we unshare
trees found in the expressions, the unsharing doesn't involve TYPE_SIZE etc.
of used types.  Gimplification is destructive though, so when we gimplify
the two nested COMPOUND_EXPRs and then try to gimplify it the second time
for the TYPE_SIZEs, we ICE.
Now, we could use unshare_expr in what we push to *expr, SAVE_EXPRs and
their operands in there aren't unshared, but I really don't see a point of
evaluating expressions that don't have side-effects before, so instead
this just pushes there expressions that do have side-effects.

2020-02-13  Jakub Jelinek  <jakub@redhat.com>

	PR c/93576
	* c-decl.c (grokdeclarator): If this_size_varies, only push size into
	*expr if it has side effects.

	* gcc.dg/pr93576.c: New test.
---
 gcc/c/ChangeLog                |  9 +++++++++
 gcc/c/c-decl.c                 | 13 ++++++++-----
 gcc/cp/ChangeLog               |  7 +++++++
 gcc/testsuite/ChangeLog        |  8 ++++++++
 gcc/testsuite/gcc.dg/pr93576.c | 10 ++++++++++
 5 files changed, 42 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr93576.c

diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 50fb412634d..b85760bfc85 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,12 @@
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2020-02-13  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c/93576
+	* c-decl.c (grokdeclarator): If this_size_varies, only push size into
+	*expr if it has side effects.
+
 2020-01-22  Joseph Myers  <joseph@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 12c8dc19807..c566f765899 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -6227,11 +6227,14 @@ grokdeclarator (const struct c_declarator *declarator,
 		  }
 		if (this_size_varies)
 		  {
-		    if (*expr)
-		      *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
-				      *expr, size);
-		    else
-		      *expr = size;
+		    if (TREE_SIDE_EFFECTS (size))
+		      {
+			if (*expr)
+			  *expr = build2 (COMPOUND_EXPR, TREE_TYPE (size),
+					  *expr, size);
+			else
+			  *expr = size;
+		      }
 		    *expr_const_operands &= size_maybe_const;
 		  }
 	      }
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 99fc3abc1eb..85d29d3eb0c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -7,6 +7,13 @@
 	* parser.c (cp_parser_template_name): Look up deprecated attribute
 	in DECL_TEMPLATE_RESULT or its type's attributes.
 
+	2019-12-26  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/92438
+	* parser.c (cp_parser_constructor_declarator_p): If open paren
+	is followed by RID_ATTRIBUTE, skip over the attribute tokens and
+	try to parse type specifier.
+
 	2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
 	PR c++/92992
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e0cadc31f3a..0b321a8d041 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,9 @@
 	Backported from mainline
 	2020-02-13  Jakub Jelinek  <jakub@redhat.com>
 
+	PR c/93576
+	* gcc.dg/pr93576.c: New test.
+
 	PR target/93696
 	* gcc.target/i386/pr93696-1.c: New test.
 	* gcc.target/i386/pr93696-2.c: New test.
@@ -127,6 +130,11 @@
 	PR target/92904
 	* gcc.c-torture/execute/pr92904.c: New test.
 
+	2019-12-11  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/92723
+	* gcc.dg/vect/pr92723.c: New test.
+
 	2019-12-05  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/92781
diff --git a/gcc/testsuite/gcc.dg/pr93576.c b/gcc/testsuite/gcc.dg/pr93576.c
new file mode 100644
index 00000000000..13c34f3771f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr93576.c
@@ -0,0 +1,10 @@
+/* PR c/93576 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+foo (void)
+{
+  int b[] = { 0 };
+  (char (*)[(1, 7, 2)]) 0;
+}
-- 
2.20.1
From 53073523bca574251d45bded65b2b0c183b01e5d Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>

Date: Fri, 14 Feb 2020 17:36:00 +0100
Subject: [PATCH] c++: Fix thinko in enum_min_precision [PR61414]

When backporting the PR61414 fix to 8.4, I've noticed that the caching
of prec is actually broken, as it would fail to actually store the computed
precision into the hash_map's value and so next time we'd think the enum needs
0 bits.

2020-02-14  Jakub Jelinek  <jakub@redhat.com>

	PR c++/61414
	* class.c (enum_min_precision): Change prec type from int to int &.

	* g++.dg/cpp0x/enum39.C: New test.
---
 gcc/cp/ChangeLog                    |  5 +++++
 gcc/cp/class.c                      |  2 +-
 gcc/testsuite/ChangeLog             |  5 +++++
 gcc/testsuite/g++.dg/cpp0x/enum39.C | 15 +++++++++++++++
 4 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/enum39.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 85d29d3eb0c..4df333c91d3 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/61414
+	* class.c (enum_min_precision): Change prec type from int to int &.
+
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 38137f9723e..07ce48917f6 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -3216,7 +3216,7 @@ enum_min_precision (tree type)
     enum_to_min_precision = hash_map<tree, int>::create_ggc (37);
 
   bool existed;
-  int prec = enum_to_min_precision->get_or_insert (type, &existed);
+  int &prec = enum_to_min_precision->get_or_insert (type, &existed);
   if (existed)
     return prec;
 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0b321a8d041..3c785be5353 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	PR c++/61414
+	* g++.dg/cpp0x/enum39.C: New test.
+
 2020-02-14  Jakub Jelinek  <jakub@redhat.com>
 
 	Backported from mainline
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum39.C b/gcc/testsuite/g++.dg/cpp0x/enum39.C
new file mode 100644
index 00000000000..676cf8463de
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/enum39.C
@@ -0,0 +1,15 @@
+// PR c++/61414
+// { dg-do compile { target c++11 } }
+
+enum class E { E0 = -4, E1 = 3 };
+enum F : unsigned { F0 = 0, F1 = 15 };
+
+struct S
+{
+  E a : 2;	// { dg-warning "'S::a' is too small to hold all values of 'enum class E'" }
+  E b : 2;	// { dg-warning "'S::b' is too small to hold all values of 'enum class E'" }
+  E c : 3;	// { dg-bogus "'S::c' is too small to hold all values of 'enum class E'" }
+  F d : 3;	// { dg-warning "'S::d' is too small to hold all values of 'enum F'" }
+  F e : 3;	// { dg-warning "'S::e' is too small to hold all values of 'enum F'" }
+  F f : 4;	// { dg-bogus "'S::f' is too small to hold all values of 'enum F'" }
+};
-- 
2.20.1

Patch

diff --git a/libsanitizer/ChangeLog b/libsanitizer/ChangeLog
index e9e4fc51828..70056ab8aec 100644
--- a/libsanitizer/ChangeLog
+++ b/libsanitizer/ChangeLog
@@ -1,3 +1,12 @@ 
+2020-02-14  Jakub Jelinek  <jakub@redhat.com>
+
+	Backported from mainline
+	2019-10-22  Tamar Christina  <tamar.christina@arm.com>
+
+	PR sanitizer/92154
+	* sanitizer_common/sanitizer_platform_limits_posix.cc:
+	Cherry-pick compiler-rt revision r375220.
+
 2019-02-22  Release Manager
 
 	* GCC 8.3.0 released.
diff --git a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
index a915d37cdfe..e85aaf51928 100644
--- a/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
@@ -1147,8 +1147,12 @@  CHECK_SIZE_AND_OFFSET(ipc_perm, uid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, gid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, cuid);
 CHECK_SIZE_AND_OFFSET(ipc_perm, cgid);
-#if !defined(__aarch64__) || !SANITIZER_LINUX || __GLIBC_PREREQ (2, 21)
+#if (!defined(__aarch64__) || !SANITIZER_LINUX || __GLIBC_PREREQ (2, 21)) && \
+    !defined(__arm__)
 /* On aarch64 glibc 2.20 and earlier provided incorrect mode field.  */
+/* On Arm glibc 2.31 and later provide a different mode field, this field is
+   never used by libsanitizer so we can simply ignore this assert for all glibc
+   versions.  */
 CHECK_SIZE_AND_OFFSET(ipc_perm, mode);
 #endif