public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Backports to 6.x
@ 2016-09-16  9:53 Jakub Jelinek
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2016-09-16  9:53 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 124 bytes --]

Hi!

I've backported a bunch of patches to 6.x, after bootstrapping/regtesting
them on x86_64-linux and i686-linux:

	Jakub

[-- Attachment #2: r239998 --]
[-- Type: text/plain, Size: 2034 bytes --]

2016-09-16  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2016-09-05  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/77396
	* asan/asan_globals.cc: Cherry-pick upstream r280657.

	* g++.dg/asan/pr77396-2.C: New test.

	2016-09-02  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/77396
	* g++.dg/asan/pr77396.C: New test.

--- libsanitizer/asan/asan_globals.cc	(revision 239997)
+++ libsanitizer/asan/asan_globals.cc	(revision 239998)
@@ -248,10 +248,10 @@ void __asan_unregister_globals(__asan_gl
 // initializer can only touch global variables in the same TU.
 void __asan_before_dynamic_init(const char *module_name) {
   if (!flags()->check_initialization_order ||
-      !CanPoisonMemory())
+      !CanPoisonMemory() ||
+      !dynamic_init_globals)
     return;
   bool strict_init_order = flags()->strict_init_order;
-  CHECK(dynamic_init_globals);
   CHECK(module_name);
   CHECK(asan_inited);
   BlockingMutexLock lock(&mu_for_globals);
@@ -274,7 +274,8 @@ void __asan_before_dynamic_init(const ch
 // TU are poisoned.  It simply unpoisons all dynamically initialized globals.
 void __asan_after_dynamic_init() {
   if (!flags()->check_initialization_order ||
-      !CanPoisonMemory())
+      !CanPoisonMemory() ||
+      !dynamic_init_globals)
     return;
   CHECK(asan_inited);
   BlockingMutexLock lock(&mu_for_globals);
--- gcc/testsuite/g++.dg/asan/pr77396.C	(revision 0)
+++ gcc/testsuite/g++.dg/asan/pr77396.C	(revision 239961)
@@ -0,0 +1,12 @@
+// PR sanitizer/77396
+// { dg-do run }
+// { dg-set-target-env-var ASAN_OPTIONS "check_initialization_order=true" }
+
+static int a = 0; 
+static int b = a; 
+
+int
+main ()
+{
+  return 0;
+}
--- gcc/testsuite/g++.dg/asan/pr77396-2.C	(revision 0)
+++ gcc/testsuite/g++.dg/asan/pr77396-2.C	(revision 239998)
@@ -0,0 +1,12 @@
+// PR sanitizer/77396
+// { dg-do run }
+// { dg-set-target-env-var ASAN_OPTIONS "check_initialization_order=true" }
+
+struct S { S () { asm volatile ("" : : : "memory"); } };
+static S c;
+
+int
+main ()
+{
+  return 0;
+}

[-- Attachment #3: r240014 --]
[-- Type: text/plain, Size: 2978 bytes --]

2016-09-16  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2016-09-06  Jakub Jelinek  <jakub@redhat.com>

	PR target/69255
	* config/i386/i386.c (ix86_expand_builtin): For builtin with
	unsupported or unknown ISA, use expand_call.

	* gcc.target/i386/pr69255-1.c: New test.
	* gcc.target/i386/pr69255-2.c: New test.
	* gcc.target/i386/pr69255-3.c: New test.

--- gcc/config/i386/i386.c	(revision 240013)
+++ gcc/config/i386/i386.c	(revision 240014)
@@ -36107,7 +36107,7 @@ ix86_expand_builtin (tree exp, rtx targe
 	  error ("%qE needs isa option %s", fndecl, opts);
 	  free (opts);
 	}
-      return const0_rtx;
+      return expand_call (exp, target, ignore);
     }
 
   switch (fcode)
--- gcc/testsuite/gcc.target/i386/pr69255-1.c	(revision 0)
+++ gcc/testsuite/gcc.target/i386/pr69255-1.c	(revision 240014)
@@ -0,0 +1,17 @@
+/* PR target/69255 */
+/* { dg-do compile } */
+/* { dg-options "-msse4 -mno-avx" } */
+
+#pragma GCC target "avx512vl"
+#pragma GCC target "no-avx512vl"
+__attribute__ ((__vector_size__ (32))) long long a;
+__attribute__ ((__vector_size__ (16))) int b;
+
+void
+foo (const long long *p)
+{
+  a = __builtin_ia32_gather3siv4di (a, p, b, 1, 1);	/* { dg-error "needs isa option -m32 -mavx512vl" } */
+}
+
+/* { dg-warning "AVX vector return without AVX enabled changes the ABI" "" { target *-*-* } 13 } */
+/* { dg-warning "AVX vector argument without AVX enabled changes the ABI" "" { target *-*-* } 13 } */
--- gcc/testsuite/gcc.target/i386/pr69255-2.c	(revision 0)
+++ gcc/testsuite/gcc.target/i386/pr69255-2.c	(revision 240014)
@@ -0,0 +1,17 @@
+/* PR target/69255 */
+/* { dg-do compile } */
+/* { dg-options "-msse4 -mno-avx" } */
+
+#pragma GCC target "avx512vl"
+#pragma GCC target ""
+__attribute__ ((__vector_size__ (32))) long long a;
+__attribute__ ((__vector_size__ (16))) int b;
+
+void
+foo (const long long *p)
+{
+  __builtin_ia32_gather3siv4di (a, p, b, 1, 1);		/* { dg-error "needs isa option -m32 -mavx512vl" } */
+}
+
+/* { dg-warning "AVX vector return without AVX enabled changes the ABI" "" { target *-*-* } 13 } */
+/* { dg-warning "AVX vector argument without AVX enabled changes the ABI" "" { target *-*-* } 13 } */
--- gcc/testsuite/gcc.target/i386/pr69255-3.c	(revision 0)
+++ gcc/testsuite/gcc.target/i386/pr69255-3.c	(revision 240014)
@@ -0,0 +1,17 @@
+/* PR target/69255 */
+/* { dg-do compile } */
+/* { dg-options "-msse4 -mno-avx" } */
+
+#pragma GCC target "avx512vl"
+#pragma GCC target ""
+__attribute__ ((__vector_size__ (32))) long long a;
+__attribute__ ((__vector_size__ (16))) int b;
+
+void
+foo (const long long *p, __attribute__ ((__vector_size__ (32))) long long *q)
+{
+  *q = __builtin_ia32_gather3siv4di (a, p, b, 1, 1);	/* { dg-error "needs isa option -m32 -mavx512vl" } */
+}
+
+/* { dg-warning "AVX vector return without AVX enabled changes the ABI" "" { target *-*-* } 13 } */
+/* { dg-warning "AVX vector argument without AVX enabled changes the ABI" "" { target *-*-* } 13 } */

[-- Attachment #4: r240037 --]
[-- Type: text/plain, Size: 1166 bytes --]

2016-09-16  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2016-09-08  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/77516
	* omp-low.c (lower_rec_simd_input_clauses): Use max_vf for non-positive
	OMP_CLAUSE_SAFELEN_EXPR.

	* gfortran.dg/gomp/pr77516.f90: New test.

--- gcc/omp-low.c	(revision 240036)
+++ gcc/omp-low.c	(revision 240037)
@@ -4302,7 +4302,9 @@ lower_rec_simd_input_clauses (tree new_v
 	{
 	  tree c = find_omp_clause (gimple_omp_for_clauses (ctx->stmt),
 				    OMP_CLAUSE_SAFELEN);
-	  if (c && TREE_CODE (OMP_CLAUSE_SAFELEN_EXPR (c)) != INTEGER_CST)
+	  if (c
+	      && (TREE_CODE (OMP_CLAUSE_SAFELEN_EXPR (c)) != INTEGER_CST
+		  || tree_int_cst_sgn (OMP_CLAUSE_SAFELEN_EXPR (c)) != 1))
 	    max_vf = 1;
 	  else if (c && compare_tree_int (OMP_CLAUSE_SAFELEN_EXPR (c),
 					  max_vf) == -1)
--- gcc/testsuite/gfortran.dg/gomp/pr77516.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/gomp/pr77516.f90	(revision 240037)
@@ -0,0 +1,12 @@
+! PR fortran/77516
+! { dg-do compile }
+
+program pr77516
+   integer :: i, x
+   x = 0
+!$omp simd safelen(0) reduction(+:x)
+   do i = 1, 8
+      x = x + 1
+   end do
+   print *, x
+end

[-- Attachment #5: r240038 --]
[-- Type: text/plain, Size: 2517 bytes --]

2016-09-16  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2016-09-08  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/77500
	* trans-openmp.c (gfc_trans_omp_atomic): For atomic write or
	swap, don't try to look through GFC_ISYM_CONVERSION.  In other cases,
	check that value.function.isym is non-NULL before dereferencing it.

	* gfortran.dg/gomp/pr77500.f90: New test.

--- gcc/fortran/trans-openmp.c	(revision 240037)
+++ gcc/fortran/trans-openmp.c	(revision 240038)
@@ -2818,7 +2818,11 @@ gfc_trans_omp_atomic (gfc_code *code)
   gfc_start_block (&block);
 
   expr2 = code->expr2;
-  if (expr2->expr_type == EXPR_FUNCTION
+  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)
     expr2 = expr2->value.function.actual->expr;
 
@@ -2857,6 +2861,7 @@ gfc_trans_omp_atomic (gfc_code *code)
 	  var = code->expr1->symtree->n.sym;
 	  expr2 = code->expr2;
 	  if (expr2->expr_type == EXPR_FUNCTION
+	      && expr2->value.function.isym
 	      && expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
 	    expr2 = expr2->value.function.actual->expr;
 	}
@@ -2914,6 +2919,7 @@ gfc_trans_omp_atomic (gfc_code *code)
 	}
       e = expr2->value.op.op1;
       if (e->expr_type == EXPR_FUNCTION
+	  && e->value.function.isym
 	  && e->value.function.isym->id == GFC_ISYM_CONVERSION)
 	e = e->value.function.actual->expr;
       if (e->expr_type == EXPR_VARIABLE
@@ -2927,6 +2933,7 @@ gfc_trans_omp_atomic (gfc_code *code)
 	{
 	  e = expr2->value.op.op2;
 	  if (e->expr_type == EXPR_FUNCTION
+	      && e->value.function.isym
 	      && e->value.function.isym->id == GFC_ISYM_CONVERSION)
 	    e = e->value.function.actual->expr;
 	  gcc_assert (e->expr_type == EXPR_VARIABLE
@@ -3041,6 +3048,7 @@ gfc_trans_omp_atomic (gfc_code *code)
 	  code = code->next;
 	  expr2 = code->expr2;
 	  if (expr2->expr_type == EXPR_FUNCTION
+	      && expr2->value.function.isym
 	      && expr2->value.function.isym->id == GFC_ISYM_CONVERSION)
 	    expr2 = expr2->value.function.actual->expr;
 
--- gcc/testsuite/gfortran.dg/gomp/pr77500.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/gomp/pr77500.f90	(revision 240038)
@@ -0,0 +1,9 @@
+! PR fortran/77500
+! { dg-do compile }
+
+program pr77500
+   real :: x
+!$omp atomic write
+   x = f()
+!$omp end atomic
+end

[-- Attachment #6: r240119 --]
[-- Type: text/plain, Size: 6585 bytes --]

2016-09-16  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2016-09-13  Jakub Jelinek  <jakub@redhat.com>

	PR c++/77553
	* constexpr.c (cxx_fold_pointer_plus_expression): New function.
	(cxx_eval_binary_expression): Use it for POINTER_PLUS_EXPR.
	(cxx_eval_pointer_plus_expression): Remove.
	(cxx_eval_constant_expression) <case POINTER_PLUS_EXPR>: Don't
	call cxx_eval_pointer_plus_expression.

	* g++.dg/cpp1y/constexpr-77553.C: New test.

--- gcc/cp/constexpr.c	(revision 240118)
+++ gcc/cp/constexpr.c	(revision 240119)
@@ -1745,6 +1745,63 @@ cxx_eval_unary_expression (const constex
   return r;
 }
 
+/* Helper function for cxx_eval_binary_expression.  Try to optimize
+   original POINTER_PLUS_EXPR T, LHS p+ RHS, return NULL_TREE if the
+   generic folding should be used.  */
+
+static tree
+cxx_fold_pointer_plus_expression (const constexpr_ctx *ctx, tree t,
+				  tree lhs, tree rhs, bool *non_constant_p,
+				  bool *overflow_p)
+{
+  STRIP_NOPS (lhs);
+  if (TREE_CODE (lhs) != ADDR_EXPR)
+    return NULL_TREE;
+
+  lhs = TREE_OPERAND (lhs, 0);
+
+  /* &A[i] p+ j => &A[i + j] */
+  if (TREE_CODE (lhs) == ARRAY_REF
+      && TREE_CODE (TREE_OPERAND (lhs, 1)) == INTEGER_CST
+      && TREE_CODE (rhs) == INTEGER_CST
+      && TYPE_SIZE_UNIT (TREE_TYPE (lhs))
+      && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST)
+    {
+      tree orig_type = TREE_TYPE (t);
+      location_t loc = EXPR_LOCATION (t);
+      tree type = TREE_TYPE (lhs);
+
+      t = fold_convert_loc (loc, ssizetype, TREE_OPERAND (lhs, 1));
+      tree nelts = array_type_nelts_top (TREE_TYPE (TREE_OPERAND (lhs, 0)));
+      nelts = cxx_eval_constant_expression (ctx, nelts, false, non_constant_p,
+					    overflow_p);
+      if (*non_constant_p)
+	return NULL_TREE;
+      /* Don't fold an out-of-bound access.  */
+      if (!tree_int_cst_le (t, nelts))
+	return NULL_TREE;
+      rhs = cp_fold_convert (ssizetype, rhs);
+      /* Don't fold if rhs can't be divided exactly by TYPE_SIZE_UNIT.
+	 constexpr int A[1]; ... (char *)&A[0] + 1 */
+      if (!integer_zerop (fold_build2_loc (loc, TRUNC_MOD_EXPR, sizetype,
+					   rhs, TYPE_SIZE_UNIT (type))))
+	return NULL_TREE;
+      /* Make sure to treat the second operand of POINTER_PLUS_EXPR
+	 as signed.  */
+      rhs = fold_build2_loc (loc, EXACT_DIV_EXPR, ssizetype, rhs,
+			     TYPE_SIZE_UNIT (type));
+      t = size_binop_loc (loc, PLUS_EXPR, rhs, t);
+      t = build4_loc (loc, ARRAY_REF, type, TREE_OPERAND (lhs, 0),
+		      t, NULL_TREE, NULL_TREE);
+      t = cp_build_addr_expr (t, tf_warning_or_error);
+      t = cp_fold_convert (orig_type, t);
+      return cxx_eval_constant_expression (ctx, t, /*lval*/false,
+					   non_constant_p, overflow_p);
+    }
+
+  return NULL_TREE;
+}
+
 /* Subroutine of cxx_eval_constant_expression.
    Like cxx_eval_unary_expression, except for binary expressions.  */
 
@@ -1790,6 +1847,9 @@ cxx_eval_binary_expression (const conste
       else if (TREE_CODE (rhs) == PTRMEM_CST)
 	rhs = cplus_expand_constant (rhs);
     }
+  else if (code == POINTER_PLUS_EXPR)
+    r = cxx_fold_pointer_plus_expression (ctx, t, lhs, rhs, non_constant_p,
+					  overflow_p);
 
   if (r == NULL_TREE)
     r = fold_binary_loc (loc, code, type, lhs, rhs);
@@ -3448,65 +3508,6 @@ cxx_eval_switch_expr (const constexpr_ct
   return NULL_TREE;
 }
 
-/* Subroutine of cxx_eval_constant_expression.
-   Attempt to reduce a POINTER_PLUS_EXPR expression T.  */
-
-static tree
-cxx_eval_pointer_plus_expression (const constexpr_ctx *ctx, tree t,
-				  bool lval, bool *non_constant_p,
-				  bool *overflow_p)
-{
-  tree orig_type = TREE_TYPE (t);
-  tree op00 = TREE_OPERAND (t, 0);
-  tree op01 = TREE_OPERAND (t, 1);
-  location_t loc = EXPR_LOCATION (t);
-
-  op00 = cxx_eval_constant_expression (ctx, op00, lval,
-				       non_constant_p, overflow_p);
-
-  STRIP_NOPS (op00);
-  if (TREE_CODE (op00) != ADDR_EXPR)
-    return NULL_TREE;
-
-  op01 = cxx_eval_constant_expression (ctx, op01, lval,
-				       non_constant_p, overflow_p);
-  op00 = TREE_OPERAND (op00, 0);
-
-  /* &A[i] p+ j => &A[i + j] */
-  if (TREE_CODE (op00) == ARRAY_REF
-      && TREE_CODE (TREE_OPERAND (op00, 1)) == INTEGER_CST
-      && TREE_CODE (op01) == INTEGER_CST
-      && TYPE_SIZE_UNIT (TREE_TYPE (op00))
-      && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (op00))) == INTEGER_CST)
-    {
-      tree type = TREE_TYPE (op00);
-      t = fold_convert_loc (loc, ssizetype, TREE_OPERAND (op00, 1));
-      tree nelts = array_type_nelts_top (TREE_TYPE (TREE_OPERAND (op00, 0)));
-      /* Don't fold an out-of-bound access.  */
-      if (!tree_int_cst_le (t, nelts))
-	return NULL_TREE;
-      op01 = cp_fold_convert (ssizetype, op01);
-      /* Don't fold if op01 can't be divided exactly by TYPE_SIZE_UNIT.
-	 constexpr int A[1]; ... (char *)&A[0] + 1 */
-      if (!integer_zerop (fold_build2_loc (loc, TRUNC_MOD_EXPR, sizetype,
-					   op01, TYPE_SIZE_UNIT (type))))
-	return NULL_TREE;
-      /* Make sure to treat the second operand of POINTER_PLUS_EXPR
-	 as signed.  */
-      op01 = fold_build2_loc (loc, EXACT_DIV_EXPR, ssizetype, op01,
-			      TYPE_SIZE_UNIT (type));
-      t = size_binop_loc (loc, PLUS_EXPR, op01, t);
-      t = build4_loc (loc, ARRAY_REF, type, TREE_OPERAND (op00, 0),
-		      t, NULL_TREE, NULL_TREE);
-      t = cp_build_addr_expr (t, tf_warning_or_error);
-      t = cp_fold_convert (orig_type, t);
-      return cxx_eval_constant_expression (ctx, t, lval, non_constant_p,
-					   overflow_p);
-    }
-
-  return NULL_TREE;
-}
-
 /* Attempt to reduce the expression T to a constant value.
    On failure, issue diagnostic and return error_mark_node.  */
 /* FIXME unify with c_fully_fold */
@@ -3824,12 +3825,6 @@ cxx_eval_constant_expression (const cons
       break;
 
     case POINTER_PLUS_EXPR:
-      r = cxx_eval_pointer_plus_expression (ctx, t, lval, non_constant_p,
-					    overflow_p);
-      if (r)
-	break;
-      /* else fall through */
-
     case PLUS_EXPR:
     case MINUS_EXPR:
     case MULT_EXPR:
--- gcc/testsuite/g++.dg/cpp1y/constexpr-77553.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp1y/constexpr-77553.C	(revision 240119)
@@ -0,0 +1,29 @@
+// PR c++/77553
+// { dg-do compile { target c++14 } }
+
+constexpr void
+bar (int *x)
+{
+  int i = 0;
+  x[i++] = 1;
+  x[3] = i;
+}
+
+constexpr int
+foo ()
+{
+  int a[] = { 0, 0, 0, 0 };
+  bar (a);
+
+  return a[0] + 8 * a[1] + 64 * a[2] + 512 * a[3];
+}
+
+constexpr int b = foo ();
+
+int
+main ()
+{
+  static_assert (b == 513, "");
+  if (foo () != 513)
+    __builtin_abort ();
+}

[-- Attachment #7: r240129 --]
[-- Type: text/plain, Size: 4600 bytes --]

2016-09-16  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2016-09-14  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/68260
	* tsan.c: Include target.h.
	(enum tsan_atomic_action): Add bool_clear and bool_test_and_set.
	(BOOL_CLEAR, BOOL_TEST_AND_SET): Define.
	(tsan_atomic_table): Add BUILT_IN_ATOMIC_CLEAR and
	BUILT_IN_ATOMIC_TEST_AND_SET entries.
	(instrument_builtin_call): Handle bool_clear and bool_test_and_set.

	* c-c++-common/tsan/pr68260.c: New test.

--- gcc/tsan.c	(revision 240128)
+++ gcc/tsan.c	(revision 240129)
@@ -40,6 +40,7 @@ along with GCC; see the file COPYING3.
 #include "tsan.h"
 #include "asan.h"
 #include "builtins.h"
+#include "target.h"
 
 /* Number of instrumented memory accesses in the current function.  */
 
@@ -240,7 +241,8 @@ instrument_expr (gimple_stmt_iterator gs
 enum tsan_atomic_action
 {
   check_last, add_seq_cst, add_acquire, weak_cas, strong_cas,
-  bool_cas, val_cas, lock_release, fetch_op, fetch_op_seq_cst
+  bool_cas, val_cas, lock_release, fetch_op, fetch_op_seq_cst,
+  bool_clear, bool_test_and_set
 };
 
 /* Table how to map sync/atomic builtins to their corresponding
@@ -274,6 +276,10 @@ static const struct tsan_map_atomic
   TRANSFORM (fcode, tsan_fcode, fetch_op, code)
 #define FETCH_OPS(fcode, tsan_fcode, code) \
   TRANSFORM (fcode, tsan_fcode, fetch_op_seq_cst, code)
+#define BOOL_CLEAR(fcode, tsan_fcode) \
+  TRANSFORM (fcode, tsan_fcode, bool_clear, ERROR_MARK)
+#define BOOL_TEST_AND_SET(fcode, tsan_fcode) \
+  TRANSFORM (fcode, tsan_fcode, bool_test_and_set, ERROR_MARK)
 
   CHECK_LAST (ATOMIC_LOAD_1, TSAN_ATOMIC8_LOAD),
   CHECK_LAST (ATOMIC_LOAD_2, TSAN_ATOMIC16_LOAD),
@@ -463,7 +469,11 @@ static const struct tsan_map_atomic
   LOCK_RELEASE (SYNC_LOCK_RELEASE_2, TSAN_ATOMIC16_STORE),
   LOCK_RELEASE (SYNC_LOCK_RELEASE_4, TSAN_ATOMIC32_STORE),
   LOCK_RELEASE (SYNC_LOCK_RELEASE_8, TSAN_ATOMIC64_STORE),
-  LOCK_RELEASE (SYNC_LOCK_RELEASE_16, TSAN_ATOMIC128_STORE)
+  LOCK_RELEASE (SYNC_LOCK_RELEASE_16, TSAN_ATOMIC128_STORE),
+
+  BOOL_CLEAR (ATOMIC_CLEAR, TSAN_ATOMIC8_STORE),
+
+  BOOL_TEST_AND_SET (ATOMIC_TEST_AND_SET, TSAN_ATOMIC8_EXCHANGE)
 };
 
 /* Instrument an atomic builtin.  */
@@ -615,6 +625,57 @@ instrument_builtin_call (gimple_stmt_ite
 				build_int_cst (NULL_TREE,
 					       MEMMODEL_RELEASE));
 	    return;
+	  case bool_clear:
+	  case bool_test_and_set:
+	    if (BOOL_TYPE_SIZE != 8)
+	      {
+		decl = NULL_TREE;
+		for (j = 1; j < 5; j++)
+		  if (BOOL_TYPE_SIZE == (8 << j))
+		    {
+		      enum built_in_function tsan_fcode
+			= (enum built_in_function)
+			  (tsan_atomic_table[i].tsan_fcode + j);
+		      decl = builtin_decl_implicit (tsan_fcode);
+		      break;
+		    }
+		if (decl == NULL_TREE)
+		  return;
+	      }
+	    last_arg = gimple_call_arg (stmt, num - 1);
+	    if (!tree_fits_uhwi_p (last_arg)
+		|| memmodel_base (tree_to_uhwi (last_arg)) >= MEMMODEL_LAST)
+	      return;
+	    t = TYPE_ARG_TYPES (TREE_TYPE (decl));
+	    t = TREE_VALUE (TREE_CHAIN (t));
+	    if (tsan_atomic_table[i].action == bool_clear)
+	      {
+		update_gimple_call (gsi, decl, 3, gimple_call_arg (stmt, 0),
+				    build_int_cst (t, 0), last_arg);
+		return;
+	      }
+	    t = build_int_cst (t, targetm.atomic_test_and_set_trueval);
+	    update_gimple_call (gsi, decl, 3, gimple_call_arg (stmt, 0),
+				t, last_arg);
+	    stmt = gsi_stmt (*gsi);
+	    lhs = gimple_call_lhs (stmt);
+	    if (lhs == NULL_TREE)
+	      return;
+	    if (targetm.atomic_test_and_set_trueval != 1
+		|| !useless_type_conversion_p (TREE_TYPE (lhs),
+					       TREE_TYPE (t)))
+	      {
+		tree new_lhs = make_ssa_name (TREE_TYPE (t));
+		gimple_call_set_lhs (stmt, new_lhs);
+		if (targetm.atomic_test_and_set_trueval != 1)
+		  g = gimple_build_assign (lhs, NE_EXPR, new_lhs,
+					   build_int_cst (TREE_TYPE (t), 0));
+		else
+		  g = gimple_build_assign (lhs, NOP_EXPR, new_lhs);
+		gsi_insert_after (gsi, g, GSI_NEW_STMT);
+		update_stmt (stmt);
+	      }
+	    return;
 	  default:
 	    continue;
 	  }
--- gcc/testsuite/c-c++-common/tsan/pr68260.c	(revision 0)
+++ gcc/testsuite/c-c++-common/tsan/pr68260.c	(revision 240129)
@@ -0,0 +1,28 @@
+/* PR sanitizer/68260 */
+
+#include <pthread.h>
+#include <stdbool.h>
+
+bool lock;
+int counter;
+
+void *
+tf (void *arg)
+{
+  (void) arg;
+  while (__atomic_test_and_set (&lock, __ATOMIC_ACQUIRE))
+    ;
+  ++counter;
+  __atomic_clear (&lock, __ATOMIC_RELEASE);
+  return (void *) 0;
+}
+
+int
+main ()
+{
+  pthread_t thr;
+  pthread_create (&thr, 0, tf, 0);
+  tf ((void *) 0);
+  pthread_join (thr, 0);
+  return 0;
+}

[-- Attachment #8: r240173 --]
[-- Type: text/plain, Size: 1089 bytes --]

2016-09-16  Jakub Jelinek  <jakub@redhat.com>
	    Eric Botcazou  <ebotcazou@adacore.com>

	PR middle-end/77594
	* internal-fn.c (expand_arith_overflow) <case MINUS_EXPR>: Don't fall
	through into expand_addsub_overflow after expand_neg_overflow.

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

--- gcc/internal-fn.c	(revision 240172)
+++ gcc/internal-fn.c	(revision 240173)
@@ -1833,7 +1833,10 @@ expand_arith_overflow (enum tree_code co
 	    {
 	    case MINUS_EXPR:
 	      if (integer_zerop (arg0) && !unsr_p)
-		expand_neg_overflow (loc, lhs, arg1, false);
+		{
+		  expand_neg_overflow (loc, lhs, arg1, false);
+		  return;
+		}
 	      /* FALLTHRU */
 	    case PLUS_EXPR:
 	      expand_addsub_overflow (loc, code, lhs, arg0, arg1,
--- gcc/testsuite/gcc.target/i386/pr77594.c	(revision 0)
+++ gcc/testsuite/gcc.target/i386/pr77594.c	(revision 240173)
@@ -0,0 +1,11 @@
+/* PR middle-end/77594 */
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+int
+foo (int a, int *b)
+{
+  return __builtin_sub_overflow (0, a, b);
+}
+
+/* { dg-final { scan-assembler-times "\tjn?o\t" 1 } } */

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Backports to 6.x
@ 2017-09-15 21:45 Jakub Jelinek
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2017-09-15 21:45 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 152 bytes --]

Hi!

I've backported 13 commits of mine and one from Richard.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed
to gcc-6-branch.

	Jakub

[-- Attachment #2: r250285 --]
[-- Type: text/plain, Size: 4565 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-06-30  Jakub Jelinek  <jakub@redhat.com>

	PR target/81225
	* config/i386/sse.md (vec_extract_lo_<mode><mask_name>): For
	V8FI, V16FI and VI8F_256 iterators, use <store_mask_predicate> instead
	of nonimmediate_operand and <store_mask_constraint> instead of m for
	the input operand.  For V8FI iterator, always split if input is a MEM.
	For V16FI and V8SF_256 iterators, don't test if both operands are MEM
	if <mask_applied>.  For VI4F_256 iterator, use <store_mask_predicate>
	instead of register_operand and <store_mask_constraint> instead of v for
	the input operand.  Make sure both operands aren't MEMs for if not
	<mask_applied>.

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

--- gcc/config/i386/sse.md	(revision 250284)
+++ gcc/config/i386/sse.md	(revision 250285)
@@ -7230,12 +7230,13 @@ (define_insn "vec_extract_lo_<mode>_mask
 (define_insn "vec_extract_lo_<mode><mask_name>"
   [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=<store_mask_constraint>,v")
 	(vec_select:<ssehalfvecmode>
-	  (match_operand:V8FI 1 "nonimmediate_operand" "v,m")
+	  (match_operand:V8FI 1 "<store_mask_predicate>" "v,<store_mask_constraint>")
 	  (parallel [(const_int 0) (const_int 1)
             (const_int 2) (const_int 3)])))]
-  "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
+  "TARGET_AVX512F
+   && (<mask_applied> || !(MEM_P (operands[0]) && MEM_P (operands[1])))"
 {
-  if (<mask_applied> || !TARGET_AVX512VL)
+  if (<mask_applied> || (!TARGET_AVX512VL && !MEM_P (operands[1])))
     return "vextract<shuffletype>64x4\t{$0x0, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x0}";
   else
     return "#";
@@ -7374,14 +7375,15 @@ (define_expand "avx_vextractf128<mode>"
 (define_insn "vec_extract_lo_<mode><mask_name>"
   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=v,m")
 	(vec_select:<ssehalfvecmode>
-	  (match_operand:V16FI 1 "nonimmediate_operand" "vm,v")
+	  (match_operand:V16FI 1 "<store_mask_predicate>"
+				 "<store_mask_constraint>,v")
 	  (parallel [(const_int 0) (const_int 1)
                      (const_int 2) (const_int 3)
                      (const_int 4) (const_int 5)
                      (const_int 6) (const_int 7)])))]
   "TARGET_AVX512F
    && <mask_mode512bit_condition>
-   && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
+   && (<mask_applied> || !(MEM_P (operands[0]) && MEM_P (operands[1])))"
 {
   if (<mask_applied>)
     return "vextract<shuffletype>32x8\t{$0x0, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x0}";
@@ -7413,11 +7415,12 @@ (define_split
 (define_insn "vec_extract_lo_<mode><mask_name>"
   [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=v,m")
 	(vec_select:<ssehalfvecmode>
-	  (match_operand:VI8F_256 1 "nonimmediate_operand" "vm,v")
+	  (match_operand:VI8F_256 1 "<store_mask_predicate>"
+				    "<store_mask_constraint>,v")
 	  (parallel [(const_int 0) (const_int 1)])))]
   "TARGET_AVX
    && <mask_avx512vl_condition> && <mask_avx512dq_condition>
-   && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
+   && (<mask_applied> || !(MEM_P (operands[0]) && MEM_P (operands[1])))"
 {
   if (<mask_applied>)
     return "vextract<shuffletype>64x2\t{$0x0, %1, %0%{%3%}|%0%{%3%}, %1, 0x0}";
@@ -7493,12 +7496,16 @@ (define_split
 
 
 (define_insn "vec_extract_lo_<mode><mask_name>"
-  [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=<store_mask_constraint>")
+  [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>"
+					  "=<store_mask_constraint>,v")
 	(vec_select:<ssehalfvecmode>
-	  (match_operand:VI4F_256 1 "register_operand" "v")
+	  (match_operand:VI4F_256 1 "<store_mask_predicate>"
+				    "v,<store_mask_constraint>")
 	  (parallel [(const_int 0) (const_int 1)
 		     (const_int 2) (const_int 3)])))]
-  "TARGET_AVX && <mask_avx512vl_condition> && <mask_avx512dq_condition>"
+  "TARGET_AVX
+   && <mask_avx512vl_condition> && <mask_avx512dq_condition>
+   && (<mask_applied> || !(MEM_P (operands[0]) && MEM_P (operands[1])))"
 {
   if (<mask_applied>)
     return "vextract<shuffletype>32x4\t{$0x0, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x0}";
--- gcc/testsuite/gcc.target/i386/pr81225.c	(nonexistent)
+++ gcc/testsuite/gcc.target/i386/pr81225.c	(revision 250285)
@@ -0,0 +1,14 @@
+/* PR target/81225 */
+/* { dg-do compile } */
+/* { dg-options "-mavx512ifma -O3 -ffloat-store" } */
+
+long a[24];
+float b[4], c[24];
+int d;
+
+void
+foo ()
+{
+  for (d = 0; d < 24; d++)
+    c[d] = (float) d ? : b[a[d]];
+}

[-- Attachment #3: r250379 --]
[-- Type: text/plain, Size: 747 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	PR libquadmath/65757
	* math/roundq.c: Cherry-pick upstream glibc 2015-04-28 change.

--- libquadmath/math/roundq.c	(revision 250378)
+++ libquadmath/math/roundq.c	(revision 250379)
@@ -1,5 +1,5 @@
 /* Round __float128 to integer away from zero.
-   Copyright (C) 1997, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1997-2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997 and
 		  Jakub Jelinek <jj@ultra.linux.cz>, 1999.
@@ -32,7 +32,7 @@ roundq (__float128 x)
 
   GET_FLT128_WORDS64 (i0, i1, x);
   j0 = ((i0 >> 48) & 0x7fff) - 0x3fff;
-  if (j0 < 31)
+  if (j0 < 48)
     {
       if (j0 < 0)
 	{

[-- Attachment #4: r250815 --]
[-- Type: text/plain, Size: 2944 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-08-08  Richard Biener  <rguenther@suse.de>

	PR middle-end/81766
	* function.c (thread_prologue_and_epilogue_insns): Restore
	behavior of always calling find_many_sub_basic_blocks on
	the inserted prologue.

	* gcc.target/i386/pr81766.c: New testcase.

	2017-08-02  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/79499
	* function.c (thread_prologue_and_epilogue_insns): Determine blocks
	for find_many_sub_basic_blocks bitmap by looking up BLOCK_FOR_INSN
	of first NONDEBUG_INSN_P in each of the split_prologue_seq and
	prologue_seq sequences - if any.

	* gcc.dg/pr79499.c: New test.

--- gcc/function.c	(revision 250814)
+++ gcc/function.c	(revision 250958)
@@ -6068,13 +6068,19 @@ thread_prologue_and_epilogue_insns (void
 
   try_shrink_wrapping (&entry_edge, &bb_flags, prologue_seq);
 
+  rtx_insn *split_prologue_insn = split_prologue_seq;
   if (split_prologue_seq != NULL_RTX)
     {
+      while (split_prologue_insn && !NONDEBUG_INSN_P (split_prologue_insn))
+	split_prologue_insn = NEXT_INSN (split_prologue_insn);
       insert_insn_on_edge (split_prologue_seq, orig_entry_edge);
       inserted = true;
     }
+  rtx_insn *prologue_insn = prologue_seq;
   if (prologue_seq != NULL_RTX)
     {
+      while (prologue_insn && !NONDEBUG_INSN_P (prologue_insn))
+	prologue_insn = NEXT_INSN (prologue_insn);
       insert_insn_on_edge (prologue_seq, entry_edge);
       inserted = true;
     }
@@ -6215,8 +6221,19 @@ epilogue_done:
       commit_edge_insertions ();
 
       /* Look for basic blocks within the prologue insns.  */
+      if (split_prologue_insn
+	  && BLOCK_FOR_INSN (split_prologue_insn) == NULL)
+	split_prologue_insn = NULL;
+      if (prologue_insn
+	  && BLOCK_FOR_INSN (prologue_insn) == NULL)
+	prologue_insn = NULL;
       blocks = sbitmap_alloc (last_basic_block_for_fn (cfun));
       bitmap_clear (blocks);
+      if (split_prologue_insn)
+	bitmap_set_bit (blocks,
+			BLOCK_FOR_INSN (split_prologue_insn)->index);
+      if (prologue_insn)
+	bitmap_set_bit (blocks, BLOCK_FOR_INSN (prologue_insn)->index);
       bitmap_set_bit (blocks, entry_edge->dest->index);
       bitmap_set_bit (blocks, orig_entry_edge->dest->index);
       find_many_sub_basic_blocks (blocks);
--- gcc/testsuite/gcc.dg/pr79499.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/pr79499.c	(revision 250815)
@@ -0,0 +1,13 @@
+/* PR middle-end/79499 */
+/* { dg-do compile { target split_stack } } */
+/* { dg-options "-O2 -fsplit-stack -fno-omit-frame-pointer" } */
+
+struct S { struct S *a, *b; };
+
+void
+foo (struct S *x)
+{
+  do
+    x->b = x->a;
+  while (x = x->a);
+}
--- gcc/testsuite/gcc.target/i386/pr81766.c	(nonexistent)
+++ gcc/testsuite/gcc.target/i386/pr81766.c	(revision 250958)
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target lp64 } */
+/* { dg-options "-O2 -fPIE -mcmodel=large" } */
+
+int main() { return 0; }

[-- Attachment #5: r251848 --]
[-- Type: text/plain, Size: 2763 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-07-27  Jakub Jelinek  <jakub@redhat.com>

	PR c/45784
	* c-omp.c (c_finish_omp_for): If the condition is wrapped in
	rhs of COMPOUND_EXPR(s), skip them and readd their lhs into
	new COMPOUND_EXPRs around the rhs of the comparison.

	* testsuite/libgomp.c/pr45784.c: New test.
	* testsuite/libgomp.c++/pr45784.C: New test.

--- gcc/c-family/c-omp.c	(revision 251847)
+++ gcc/c-family/c-omp.c	(revision 251848)
@@ -531,6 +531,12 @@ c_finish_omp_for (location_t locus, enum
 	{
 	  bool cond_ok = false;
 
+	  /* E.g. C sizeof (vla) could add COMPOUND_EXPRs with
+	     evaluation of the vla VAR_DECL.  We need to readd
+	     them to the non-decl operand.  See PR45784.  */
+	  while (TREE_CODE (cond) == COMPOUND_EXPR)
+	    cond = TREE_OPERAND (cond, 1);
+
 	  if (EXPR_HAS_LOCATION (cond))
 	    elocus = EXPR_LOCATION (cond);
 
@@ -605,6 +611,21 @@ c_finish_omp_for (location_t locus, enum
 		  else if (code != CILK_SIMD && code != CILK_FOR)
 		    cond_ok = false;
 		}
+
+	      if (cond_ok && TREE_VEC_ELT (condv, i) != cond)
+		{
+		  tree ce = NULL_TREE, *pce = &ce;
+		  tree type = TREE_TYPE (TREE_OPERAND (cond, 1));
+		  for (tree c = TREE_VEC_ELT (condv, i); c != cond;
+		       c = TREE_OPERAND (c, 1))
+		    {
+		      *pce = build2 (COMPOUND_EXPR, type, TREE_OPERAND (c, 0),
+				     TREE_OPERAND (cond, 1));
+		      pce = &TREE_OPERAND (*pce, 1);
+		    }
+		  TREE_OPERAND (cond, 1) = ce;
+		  TREE_VEC_ELT (condv, i) = cond;
+		}
 	    }
 
 	  if (!cond_ok)
--- libgomp/testsuite/libgomp.c/pr45784.c	(nonexistent)
+++ libgomp/testsuite/libgomp.c/pr45784.c	(revision 251848)
@@ -0,0 +1,41 @@
+/* PR c/45784 */
+/* { dg-do run } */
+
+void
+foo (int n)
+{
+  char *p, vla[2 * n];
+  int i;
+  #pragma omp parallel for
+  for (p = vla; p < vla + (sizeof (vla) / sizeof (vla[0])); p++)
+    *p = ' ';
+  #pragma omp parallel for
+  for (i = 0; i < 2 * n; i++)
+    if (vla[i] != ' ')
+      __builtin_abort ();
+}
+
+void
+bar (int n)
+{
+  char *p, vla1[n], vla2[n * 2], vla3[n * 3], vla4[n * 4];
+  int i;
+  __builtin_memset (vla4, ' ', n * 4);
+  #pragma omp parallel for
+  for (p = vla4 + sizeof (vla1); p < vla4 + sizeof (vla3) - sizeof (vla2) + sizeof (vla1); p += sizeof (vla4) / sizeof (vla4))
+    p[0] = '!';
+  #pragma omp parallel for
+  for (i = 0; i < n * 4; i++)
+    if (vla4[i] != ((i >= n && i < 2 * n) ? '!' : ' '))
+      __builtin_abort ();
+}
+
+int
+main ()
+{
+  volatile int n;
+  n = 128;
+  foo (n);
+  bar (n);
+  return 0;
+}
--- libgomp/testsuite/libgomp.c++/pr45784.C	(nonexistent)
+++ libgomp/testsuite/libgomp.c++/pr45784.C	(revision 251848)
@@ -0,0 +1,5 @@
+// PR c/45784
+// { dg-do run }
+
+#include "../libgomp.c/pr45784.c"
+

[-- Attachment #6: r251849 --]
[-- Type: text/plain, Size: 1599 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-08-03  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/81052
	* omp-low.c (diagnose_sb_0): Handle flag_openmp_simd like flag_openmp.
	(pass_diagnose_omp_blocks::gate): Enable also for flag_openmp_simd.

	* c-c++-common/pr81052.c: New test.

--- gcc/omp-low.c	(revision 251848)
+++ gcc/omp-low.c	(revision 251849)
@@ -9089,7 +9089,7 @@ diagnose_sb_0 (gimple_stmt_iterator *gsi
     }
   if (kind == NULL)
     {
-      gcc_checking_assert (flag_openmp);
+      gcc_checking_assert (flag_openmp || flag_openmp_simd);
       kind = "OpenMP";
     }
 
@@ -9349,7 +9349,7 @@ public:
   /* opt_pass methods: */
   virtual bool gate (function *)
   {
-    return flag_cilkplus || flag_openacc || flag_openmp;
+    return flag_cilkplus || flag_openacc || flag_openmp || flag_openmp_simd;
   }
   virtual unsigned int execute (function *)
     {
--- gcc/testsuite/c-c++-common/pr81052.c	(nonexistent)
+++ gcc/testsuite/c-c++-common/pr81052.c	(revision 251849)
@@ -0,0 +1,28 @@
+/* PR middle-end/81052 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp-simd -O2" } */
+
+int
+foo (int x, int y)
+{
+  int i;
+#pragma omp simd
+  for (i = x; i < y; ++i)
+    return 0;			/* { dg-error "invalid branch to/from OpenMP structured block" } */
+  return 1;
+}
+
+#ifdef __cplusplus
+template <typename T>
+T
+bar (T x, T y)
+{
+  T i;
+#pragma omp simd
+  for (i = x; i < y; ++i)
+    return 0;			/* { dg-error "invalid branch to/from OpenMP structured block" "" { target c++ } } */
+  return 1;
+}
+
+int x = bar (1, 7);
+#endif

[-- Attachment #7: r251851 --]
[-- Type: text/plain, Size: 1233 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-08-03  Jakub Jelinek  <jakub@redhat.com>

	PR target/81621
	* bb-reorder.c (pass_partition_blocks::execute): Return TODO_df_finish
	after setting changeable df flags.

	* gcc.dg/pr81621.c: New test.

--- gcc/bb-reorder.c	(revision 251850)
+++ gcc/bb-reorder.c	(revision 251851)
@@ -2881,7 +2881,8 @@ pass_partition_blocks::execute (function
 
   crossing_edges = find_rarely_executed_basic_blocks_and_crossing_edges ();
   if (!crossing_edges.exists ())
-    return 0;
+    /* Make sure to process deferred rescans and clear changeable df flags.  */
+    return TODO_df_finish;
 
   crtl->has_bb_partition = true;
 
@@ -2947,7 +2948,8 @@ pass_partition_blocks::execute (function
       df_analyze ();
     }
 
-  return 0;
+  /* Make sure to process deferred rescans and clear changeable df flags.  */
+  return TODO_df_finish;
 }
 
 } // anon namespace
--- gcc/testsuite/gcc.dg/pr81621.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/pr81621.c	(revision 251851)
@@ -0,0 +1,5 @@
+/* PR target/81621 */
+/* { dg-do compile { target freorder } } */
+/* { dg-options "-Og -fno-split-wide-types -freorder-blocks-and-partition" } */
+
+#include "graphite/scop-10.c"

[-- Attachment #8: r251853 --]
[-- Type: text/plain, Size: 3544 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-08-09  Jakub Jelinek  <jakub@redhat.com>

	PR c/81687
	* omp-low.c (omp_copy_decl): Don't remap FORCED_LABEL or DECL_NONLOCAL
	LABEL_DECLs.
	* tree-cfg.c (move_stmt_op): Don't adjust DECL_CONTEXT of FORCED_LABEL
	or DECL_NONLOCAL labels.
	(move_stmt_r) <case GIMPLE_LABEL>: Adjust DECL_CONTEXT of FORCED_LABEL
	or DECL_NONLOCAL labels here.

	* testsuite/libgomp.c/pr81687-1.c: New test.
	* testsuite/libgomp.c/pr81687-2.c: New test.

--- gcc/omp-low.c	(revision 251852)
+++ gcc/omp-low.c	(revision 251853)
@@ -800,6 +800,8 @@ omp_copy_decl (tree var, copy_body_data
 
   if (TREE_CODE (var) == LABEL_DECL)
     {
+      if (FORCED_LABEL (var) || DECL_NONLOCAL (var))
+	return var;
       new_var = create_artificial_label (DECL_SOURCE_LOCATION (var));
       DECL_CONTEXT (new_var) = current_function_decl;
       insert_decl_map (&ctx->cb, var, new_var);
--- gcc/tree-cfg.c	(revision 251852)
+++ gcc/tree-cfg.c	(revision 251853)
@@ -6667,7 +6667,15 @@ move_stmt_op (tree *tp, int *walk_subtre
 		*tp = t = out->to;
 	    }
 
-	  DECL_CONTEXT (t) = p->to_context;
+	  /* For FORCED_LABELs we can end up with references from other
+	     functions if some SESE regions are outlined.  It is UB to
+	     jump in between them, but they could be used just for printing
+	     addresses etc.  In that case, DECL_CONTEXT on the label should
+	     be the function containing the glabel stmt with that LABEL_DECL,
+	     rather than whatever function a reference to the label was seen
+	     last time.  */
+	  if (!FORCED_LABEL (t) && !DECL_NONLOCAL (t))
+	    DECL_CONTEXT (t) = p->to_context;
 	}
       else if (p->remap_decls_p)
 	{
@@ -6785,6 +6793,21 @@ move_stmt_r (gimple_stmt_iterator *gsi_p
     case GIMPLE_OMP_RETURN:
     case GIMPLE_OMP_CONTINUE:
       break;
+
+    case GIMPLE_LABEL:
+      {
+	/* For FORCED_LABEL, move_stmt_op doesn't adjust DECL_CONTEXT,
+	   so that such labels can be referenced from other regions.
+	   Make sure to update it when seeing a GIMPLE_LABEL though,
+	   that is the owner of the label.  */
+	walk_gimple_op (stmt, move_stmt_op, wi);
+	*handled_ops_p = true;
+	tree label = gimple_label_label (as_a <glabel *> (stmt));
+	if (FORCED_LABEL (label) || DECL_NONLOCAL (label))
+	  DECL_CONTEXT (label) = p->to_context;
+      }
+      break;
+
     default:
       if (is_gimple_omp (stmt))
 	{
--- libgomp/testsuite/libgomp.c/pr81687-1.c	(nonexistent)
+++ libgomp/testsuite/libgomp.c/pr81687-1.c	(revision 251853)
@@ -0,0 +1,23 @@
+/* PR c/81687 */
+/* { dg-do link } */
+/* { dg-additional-options "-O2" } */
+
+extern int printf (const char *, ...);
+
+int
+main ()
+{
+  #pragma omp parallel
+  {
+   lab1:
+    printf ("lab1=%p\n", (void *)(&&lab1));
+  }
+ lab2:
+  #pragma omp parallel
+  {
+   lab3:
+    printf ("lab2=%p\n", (void *)(&&lab2));
+  }
+  printf ("lab3=%p\n", (void *)(&&lab3));
+  return 0;
+}
--- libgomp/testsuite/libgomp.c/pr81687-2.c	(nonexistent)
+++ libgomp/testsuite/libgomp.c/pr81687-2.c	(revision 251853)
@@ -0,0 +1,27 @@
+/* PR c/81687 */
+/* { dg-do link } */
+/* { dg-additional-options "-O2" } */
+
+int
+main ()
+{
+  __label__ lab4, lab5, lab6;
+  volatile int l = 0;
+  int m = l;
+  void foo (int x) { if (x == 1) goto lab4; }
+  void bar (int x) { if (x == 2) goto lab5; }
+  void baz (int x) { if (x == 3) goto lab6; }
+  #pragma omp parallel
+  {
+    foo (m + 1);
+   lab4:;
+  }
+  #pragma omp task
+  {
+    bar (m + 2);
+   lab5:;
+  }
+  baz (m + 3);
+ lab6:;
+  return 0;
+}

[-- Attachment #9: r251855 --]
[-- Type: text/plain, Size: 577 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-09-04  Jakub Jelinek  <jakub@redhat.com>

	* lra-remat.c (reg_overlap_for_remat_p): Fix a pasto.

--- gcc/lra-remat.c	(revision 251854)
+++ gcc/lra-remat.c	(revision 251855)
@@ -684,7 +684,7 @@ reg_overlap_for_remat_p (lra_insn_reg *r
 
 	if (regno2 >= FIRST_PSEUDO_REGISTER && reg_renumber[regno2] >= 0)
 	  regno2 = reg_renumber[regno2];
-	if (regno >= FIRST_PSEUDO_REGISTER)
+	if (regno2 >= FIRST_PSEUDO_REGISTER)
 	  nregs2 = 1;
 	else
 	  nregs2 = hard_regno_nregs[regno2][reg->biggest_mode];

[-- Attachment #10: r251856 --]
[-- Type: text/plain, Size: 2317 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-09-05  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/81768
	* omp-low.c (expand_omp_simd): Force second operands of COND_EXPR
	into gimple val before gimplification fo the COND_EXPR.

	* gcc.dg/gomp/pr81768-1.c: New test.

--- gcc/omp-low.c	(revision 251855)
+++ gcc/omp-low.c	(revision 251856)
@@ -4725,24 +4725,28 @@ expand_omp_simd (struct omp_region *regi
 	      tree itype2 = TREE_TYPE (fd->loops[i - 1].v);
 	      if (POINTER_TYPE_P (itype2))
 		itype2 = signed_type_for (itype2);
+	      t = fold_convert (itype2, fd->loops[i - 1].step);
+	      t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, true,
+					    GSI_SAME_STMT);
 	      t = build3 (COND_EXPR, itype2,
 			  build2 (fd->loops[i].cond_code, boolean_type_node,
 				  fd->loops[i].v,
 				  fold_convert (itype, fd->loops[i].n2)),
-			  build_int_cst (itype2, 0),
-			  fold_convert (itype2, fd->loops[i - 1].step));
+			  build_int_cst (itype2, 0), t);
 	      if (POINTER_TYPE_P (TREE_TYPE (fd->loops[i - 1].v)))
 		t = fold_build_pointer_plus (fd->loops[i - 1].v, t);
 	      else
 		t = fold_build2 (PLUS_EXPR, itype2, fd->loops[i - 1].v, t);
 	      expand_omp_build_assign (&gsi, fd->loops[i - 1].v, t);
 
+	      t = fold_convert (itype, fd->loops[i].n1);
+	      t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, true,
+					    GSI_SAME_STMT);
 	      t = build3 (COND_EXPR, itype,
 			  build2 (fd->loops[i].cond_code, boolean_type_node,
 				  fd->loops[i].v,
 				  fold_convert (itype, fd->loops[i].n2)),
-			  fd->loops[i].v,
-			  fold_convert (itype, fd->loops[i].n1));
+			  fd->loops[i].v, t);
 	      expand_omp_build_assign (&gsi, fd->loops[i].v, t);
 	    }
 	}
--- gcc/testsuite/gcc.dg/gomp/pr81768-1.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/gomp/pr81768-1.c	(revision 251856)
@@ -0,0 +1,15 @@
+/* PR middle-end/81768 */
+/* { dg-do compile } */
+
+float b[10][15][10];
+
+void
+foo (void)
+{
+  float *i;
+#pragma omp target parallel for simd schedule(static, 32) collapse(3)
+  for (i = &b[0][0][0]; i < &b[0][0][10]; i++)
+    for (float *j = &b[0][15][0]; j > &b[0][0][0]; j -= 10)
+      for (float *k = &b[0][0][10]; k > &b[0][0][0]; --k)
+	b[i - &b[0][0][0]][(j - &b[0][0][0]) / 10 - 1][(k - &b[0][0][0]) - 1] -= 3.5;
+}

[-- Attachment #11: r251857 --]
[-- Type: text/plain, Size: 1595 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-09-05  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/81768
	* omp-low.c (lower_omp_for): Recompute tree invariant if
	gimple_omp_for_initial/final is ADDR_EXPR.

	* gcc.dg/gomp/pr81768-2.c: New test.

--- gcc/omp-low.c	(revision 251856)
+++ gcc/omp-low.c	(revision 251857)
@@ -6927,10 +6927,14 @@ lower_omp_for (gimple_stmt_iterator *gsi
       rhs_p = gimple_omp_for_initial_ptr (stmt, i);
       if (!is_gimple_min_invariant (*rhs_p))
 	*rhs_p = get_formal_tmp_var (*rhs_p, &body);
+      else if (TREE_CODE (*rhs_p) == ADDR_EXPR)
+	recompute_tree_invariant_for_addr_expr (*rhs_p);
 
       rhs_p = gimple_omp_for_final_ptr (stmt, i);
       if (!is_gimple_min_invariant (*rhs_p))
 	*rhs_p = get_formal_tmp_var (*rhs_p, &body);
+      else if (TREE_CODE (*rhs_p) == ADDR_EXPR)
+	recompute_tree_invariant_for_addr_expr (*rhs_p);
 
       rhs_p = &TREE_OPERAND (gimple_omp_for_incr (stmt, i), 1);
       if (!is_gimple_min_invariant (*rhs_p))
--- gcc/testsuite/gcc.dg/gomp/pr81768-2.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/gomp/pr81768-2.c	(revision 251857)
@@ -0,0 +1,15 @@
+/* PR middle-end/81768 */
+/* { dg-do compile } */
+
+float b[10][15][10];
+
+void
+foo (void)
+{
+  float *i;
+#pragma omp target parallel for schedule(static, 32) collapse(3)
+  for (i = &b[0][0][0]; i < &b[0][0][10]; i++)
+    for (float *j = &b[0][15][0]; j > &b[0][0][0]; j -= 10)
+      for (float *k = &b[0][0][10]; k > &b[0][0][0]; --k)
+        b[i - &b[0][0][0]][(j - &b[0][0][0]) / 10 - 1][(k - &b[0][0][0]) - 1] -= 3.5;
+}

[-- Attachment #12: r252803 --]
[-- Type: text/plain, Size: 4241 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

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

	PR target/82112
	* c-common.c (sync_resolve_size): Instead of c_dialect_cxx ()
	assertion check that in the condition.
	(get_atomic_generic_size): Likewise.  Before testing if parameter
	has pointer type, if it has array type, call for C++
	default_conversion to perform array-to-pointer conversion.

	* c-c++-common/pr82112.c: New test.
	* gcc.dg/pr82112.c: New test.

--- gcc/c-family/c-common.c	(revision 252802)
+++ gcc/c-family/c-common.c	(revision 252803)
@@ -6576,10 +6576,9 @@ sync_resolve_size (tree function, vec<tr
     }
 
   argtype = type = TREE_TYPE ((*params)[0]);
-  if (TREE_CODE (type) == ARRAY_TYPE)
+  if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
     {
       /* Force array-to-pointer decay for C++.  */
-      gcc_assert (c_dialect_cxx());
       (*params)[0] = default_conversion ((*params)[0]);
       type = TREE_TYPE ((*params)[0]);
     }
@@ -6741,10 +6740,9 @@ get_atomic_generic_size (location_t loc,
 
   /* Get type of first parameter, and determine its size.  */
   type_0 = TREE_TYPE ((*params)[0]);
-  if (TREE_CODE (type_0) == ARRAY_TYPE)
+  if (TREE_CODE (type_0) == ARRAY_TYPE && c_dialect_cxx ())
     {
       /* Force array-to-pointer decay for C++.  */
-      gcc_assert (c_dialect_cxx());
       (*params)[0] = default_conversion ((*params)[0]);
       type_0 = TREE_TYPE ((*params)[0]);
     }
@@ -6783,6 +6781,12 @@ get_atomic_generic_size (location_t loc,
       /* __atomic_compare_exchange has a bool in the 4th position, skip it.  */
       if (n_param == 6 && x == 3)
         continue;
+      if (TREE_CODE (type) == ARRAY_TYPE && c_dialect_cxx ())
+	{
+	  /* Force array-to-pointer decay for C++.  */
+	  (*params)[x] = default_conversion ((*params)[x]);
+	  type = TREE_TYPE ((*params)[x]);
+	}
       if (!POINTER_TYPE_P (type))
 	{
 	  error_at (loc, "argument %d of %qE must be a pointer type", x + 1,
--- gcc/testsuite/gcc.dg/pr82112.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/pr82112.c	(revision 252803)
@@ -0,0 +1,21 @@
+/* PR target/82112 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu90" } */
+
+struct S { int a[10]; } bar (void);
+int b, c;
+
+void
+foo (void)
+{
+  __atomic_load (bar ().a, &b, __ATOMIC_ACQUIRE);	/* { dg-error "argument 1 of .__atomic_load. must be a non-void pointer type" } */
+  __atomic_load (&b, bar ().a, __ATOMIC_ACQUIRE);	/* { dg-error "argument 2 of .__atomic_load. must be a pointer type" } */
+  __atomic_store (bar ().a, &b, __ATOMIC_SEQ_CST);	/* { dg-error "argument 1 of .__atomic_store. must be a non-void pointer type" } */
+  __atomic_store (&b, bar ().a, __ATOMIC_SEQ_CST);	/* { dg-error "argument 2 of .__atomic_store. must be a pointer type" } */
+  __atomic_exchange (bar ().a, &b, &c, __ATOMIC_RELAXED);	/* { dg-error "argument 1 of .__atomic_exchange. must be a non-void pointer type" } */
+  __atomic_exchange (&b, bar ().a, &c, __ATOMIC_RELAXED);	/* { dg-error "argument 2 of .__atomic_exchange. must be a pointer type" } */
+  __atomic_exchange (&b, &c, bar ().a, __ATOMIC_RELAXED);	/* { dg-error "argument 3 of .__atomic_exchange. must be a pointer type" } */
+  __atomic_compare_exchange (bar ().a, &b, &c, 1, __ATOMIC_RELAXED, __ATOMIC_RELAXED);	/* { dg-error "argument 1 of .__atomic_compare_exchange. must be a non-void pointer type" } */
+  __atomic_compare_exchange (&b, bar ().a, &c, 1, __ATOMIC_RELAXED, __ATOMIC_RELAXED);	/* { dg-error "argument 2 of .__atomic_compare_exchange. must be a pointer type" } */
+  __atomic_compare_exchange (&b, &c, bar ().a, 1, __ATOMIC_RELAXED, __ATOMIC_RELAXED);	/* { dg-error "argument 3 of .__atomic_compare_exchange. must be a pointer type" } */
+}
--- gcc/testsuite/c-c++-common/pr82112.c	(nonexistent)
+++ gcc/testsuite/c-c++-common/pr82112.c	(revision 252803)
@@ -0,0 +1,13 @@
+/* PR target/82112 */
+/* { dg-do compile } */
+
+int c[10], d[10], e[10], f[10], g[10], h[10], i[10], j[10], k[10], l[10];
+
+void
+foo (void)
+{
+  __atomic_load (c, d, __ATOMIC_ACQUIRE);
+  __atomic_store (e, f, __ATOMIC_SEQ_CST);
+  __atomic_exchange (g, h, i, __ATOMIC_RELAXED);
+  __atomic_compare_exchange (j, k, l, 1, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
+}

[-- Attachment #13: r252804 --]
[-- Type: text/plain, Size: 1287 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

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

	PR target/82112
	* gcc.target/powerpc/pr82112.c: New test.
	* g++.dg/ext/altivec-18.C: New test.

--- gcc/testsuite/gcc.target/powerpc/pr82112.c	(nonexistent)
+++ gcc/testsuite/gcc.target/powerpc/pr82112.c	(revision 252804)
@@ -0,0 +1,16 @@
+/* PR target/82112 */
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_altivec_ok } */
+/* { dg-options "-maltivec -std=gnu90" } */
+
+#include <altivec.h>
+
+struct __attribute__((aligned (16))) S { unsigned char c[64]; } bar (void);
+vector unsigned char v;
+
+void
+foo (void)
+{
+  vec_ld (0, bar ().c);	/* { dg-error "invalid parameter combination for AltiVec intrinsic" } */
+  vec_st (v, 0, bar ().c);	/* { dg-error "invalid parameter combination for AltiVec intrinsic" } */
+}
--- gcc/testsuite/g++.dg/ext/altivec-18.C	(nonexistent)
+++ gcc/testsuite/g++.dg/ext/altivec-18.C	(revision 252804)
@@ -0,0 +1,14 @@
+// PR target/82112
+// { dg-do compile { target powerpc*-*-* } }
+// { dg-require-effective-target powerpc_altivec_ok }
+// { dg-options "-maltivec" }
+
+#include <altivec.h>
+
+__attribute__((aligned (16))) extern const unsigned char c[16];
+
+void
+foo (void)
+{
+  vec_ld (0, c);
+}

[-- Attachment #14: r252806 --]
[-- Type: text/plain, Size: 1646 bytes --]

2017-09-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-09-14  Jakub Jelinek  <jakub@redhat.com>

	PR c++/81314
	* cp-gimplify.c (omp_var_to_track): Look through references.
	(omp_cxx_notice_variable): Likewise.

	* testsuite/libgomp.c++/pr81314.C: New test.

--- gcc/cp/cp-gimplify.c	(revision 252805)
+++ gcc/cp/cp-gimplify.c	(revision 252806)
@@ -924,6 +924,8 @@ omp_var_to_track (tree decl)
   tree type = TREE_TYPE (decl);
   if (is_invisiref_parm (decl))
     type = TREE_TYPE (type);
+  else if (TREE_CODE (type) == REFERENCE_TYPE)
+    type = TREE_TYPE (type);
   while (TREE_CODE (type) == ARRAY_TYPE)
     type = TREE_TYPE (type);
   if (type == error_mark_node || !CLASS_TYPE_P (type))
@@ -976,6 +978,8 @@ omp_cxx_notice_variable (struct cp_gener
 	      tree type = TREE_TYPE (decl);
 	      if (is_invisiref_parm (decl))
 		type = TREE_TYPE (type);
+	      else if (TREE_CODE (type) == REFERENCE_TYPE)
+		type = TREE_TYPE (type);
 	      while (TREE_CODE (type) == ARRAY_TYPE)
 		type = TREE_TYPE (type);
 	      get_copy_ctor (type, tf_none);
--- libgomp/testsuite/libgomp.c++/pr81314.C	(nonexistent)
+++ libgomp/testsuite/libgomp.c++/pr81314.C	(revision 252806)
@@ -0,0 +1,38 @@
+// PR c++/81314
+// { dg-do link }
+
+template <int N>
+struct S {
+  S () { s = 0; }
+  S (const S &x) { s = x.s; }
+  ~S () {}
+  int s;
+};
+
+void
+foo (S<2> &x)
+{
+  #pragma omp taskloop
+  for (int i = 0; i < 100; ++i)
+    x.s++;
+}
+
+void
+bar (S<3> &x)
+{
+  #pragma omp task
+  x.s++;
+}
+
+int
+main ()
+{
+  S<2> s;
+  S<3> t;
+  #pragma omp parallel
+  #pragma omp master
+  {
+    foo (s);
+    bar (t);
+  }
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Backports to 6.x
  2017-06-21 11:17 ` Nathan Sidwell
@ 2017-06-22 10:21   ` Richard Biener
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Biener @ 2017-06-22 10:21 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: Martin Liška, GCC Patches, Jakub Jelinek, Jan Hubicka

On Wed, Jun 21, 2017 at 1:17 PM, Nathan Sidwell <nathan@acm.org> wrote:
> On 06/21/2017 04:14 AM, Martin Liška wrote:
>>
>> As release managers are planning to release next version of GCC 6. I would
>> like to
>> do backport revisions attached.
>>
>> The only complicated one is the one for PR69953 where I decided to
>> backport
>> also refactoring patches applied by Nathan (244529, 244156).
>>
>> I would appreciate another pair of eyes to look at backports.
>
>
> Looks good to me.

Yep.

Ok.

Richard.

> nathan
>
> --
> Nathan Sidwell

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Backports to 6.x
  2017-06-21  8:14 Martin Liška
@ 2017-06-21 11:17 ` Nathan Sidwell
  2017-06-22 10:21   ` Richard Biener
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Sidwell @ 2017-06-21 11:17 UTC (permalink / raw)
  To: Martin Liška, GCC Patches; +Cc: Jakub Jelinek, Richard Biener, Jan Hubicka

On 06/21/2017 04:14 AM, Martin Liška wrote:
> As release managers are planning to release next version of GCC 6. I 
> would like to
> do backport revisions attached.
> 
> The only complicated one is the one for PR69953 where I decided to backport
> also refactoring patches applied by Nathan (244529, 244156).
> 
> I would appreciate another pair of eyes to look at backports.

Looks good to me.

nathan

-- 
Nathan Sidwell

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Backports to 6.x
@ 2017-06-21  8:14 Martin Liška
  2017-06-21 11:17 ` Nathan Sidwell
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Liška @ 2017-06-21  8:14 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jakub Jelinek, Richard Biener, Nathan Sidwell, Jan Hubicka

[-- Attachment #1: Type: text/plain, Size: 332 bytes --]

As release managers are planning to release next version of GCC 6. I would like to
do backport revisions attached.

The only complicated one is the one for PR69953 where I decided to backport
also refactoring patches applied by Nathan (244529, 244156).

I would appreciate another pair of eyes to look at backports.

Thanks,
Martin

[-- Attachment #2: 0015-Backport-r248729.patch --]
[-- Type: text/x-patch, Size: 1043 bytes --]

From 3d06a155b652468dae32382aae8abc9d6da10b77 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 31 May 2017 11:40:13 +0000
Subject: [PATCH 15/15] Backport r248729

gcc/ChangeLog:

2017-05-31  Martin Liska  <mliska@suse.cz>

	PR target/79155
	* config/i386/cpuid.h: Fix typo in a comment in cpuid.h.
---
 gcc/config/i386/cpuid.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/config/i386/cpuid.h b/gcc/config/i386/cpuid.h
index d67eeae75ce..89e260c62eb 100644
--- a/gcc/config/i386/cpuid.h
+++ b/gcc/config/i386/cpuid.h
@@ -172,7 +172,7 @@
 
 
 /* Return highest supported input value for cpuid instruction.  ext can
-   be either 0x0 or 0x8000000 to return highest supported value for
+   be either 0x0 or 0x80000000 to return highest supported value for
    basic or extended cpuid information.  Function returns 0 if cpuid
    is not supported or whatever cpuid returns in eax register.  If sig
    pointer is non-null, then first four bytes of the signature
-- 
2.13.1


[-- Attachment #3: 0014-Backport-r248647.patch --]
[-- Type: text/x-patch, Size: 887 bytes --]

From b921b54246135959a6fe9d4f6534299b3cc152fc Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 30 May 2017 08:02:03 +0000
Subject: [PATCH 14/15] Backport r248647

gcc/ChangeLog:

2017-05-30  Martin Liska  <mliska@suse.cz>

	PR other/80909
	* auto-profile.c (get_function_decl_from_block): Fix
	parenthesis.
---
 gcc/auto-profile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/auto-profile.c b/gcc/auto-profile.c
index 94afe6fd2d9..2bf5e07ab25 100644
--- a/gcc/auto-profile.c
+++ b/gcc/auto-profile.c
@@ -353,7 +353,7 @@ get_function_decl_from_block (tree block)
 {
   tree decl;
 
-  if (LOCATION_LOCUS (BLOCK_SOURCE_LOCATION (block) == UNKNOWN_LOCATION))
+  if (LOCATION_LOCUS (BLOCK_SOURCE_LOCATION (block)) == UNKNOWN_LOCATION)
     return NULL_TREE;
 
   for (decl = BLOCK_ABSTRACT_ORIGIN (block);
-- 
2.13.1


[-- Attachment #4: 0013-Backport-r248489.patch --]
[-- Type: text/x-patch, Size: 2413 bytes --]

From eec428d554a565ae1d73e6c5824474a5751bc7ce Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 26 May 2017 11:05:52 +0000
Subject: [PATCH 13/15] Backport r248489

gcc/ChangeLog:

2017-05-26  Martin Liska  <mliska@suse.cz>

	PR ipa/80663
	* params.def: Bound partial-inlining-entry-probability param.

gcc/testsuite/ChangeLog:

2017-05-26  Martin Liska  <mliska@suse.cz>

	PR ipa/80663
	* g++.dg/ipa/pr80212.C: Remove the test as it does not longer
	split at the problematic spot.
	* gcc.dg/ipa/pr48195.c: Change 101 to 100 as 101 is no longer
	a valid value of the param.
---
 gcc/params.def                     |  2 +-
 gcc/testsuite/g++.dg/ipa/pr80212.C | 18 ------------------
 gcc/testsuite/gcc.dg/ipa/pr48195.c |  2 +-
 3 files changed, 2 insertions(+), 20 deletions(-)
 delete mode 100644 gcc/testsuite/g++.dg/ipa/pr80212.C

diff --git a/gcc/params.def b/gcc/params.def
index 76308cdfcdb..ce83aa71e6d 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -126,7 +126,7 @@ DEFPARAM (PARAM_COMDAT_SHARING_PROBABILITY,
 DEFPARAM (PARAM_PARTIAL_INLINING_ENTRY_PROBABILITY,
 	  "partial-inlining-entry-probability",
 	  "Maximum probability of the entry BB of split region (in percent relative to entry BB of the function) to make partial inlining happen.",
-	  70, 0, 0)
+	  70, 0, 100)
 
 /* Limit the number of expansions created by the variable expansion
    optimization to avoid register pressure.  */
diff --git a/gcc/testsuite/g++.dg/ipa/pr80212.C b/gcc/testsuite/g++.dg/ipa/pr80212.C
deleted file mode 100644
index 60d3b613035..00000000000
--- a/gcc/testsuite/g++.dg/ipa/pr80212.C
+++ /dev/null
@@ -1,18 +0,0 @@
-// PR ipa/80212
-// { dg-options "-O2 --param partial-inlining-entry-probability=403796683 -fno-early-inlining" }
-
-struct b
-{
-  virtual b *c () const;
-};
-struct d : virtual b
-{
-};
-struct e : d
-{
-  e *
-  c () const
-  {
-  }
-};
-main () { e a; }
diff --git a/gcc/testsuite/gcc.dg/ipa/pr48195.c b/gcc/testsuite/gcc.dg/ipa/pr48195.c
index 2e38452d598..25e80bab8f8 100644
--- a/gcc/testsuite/gcc.dg/ipa/pr48195.c
+++ b/gcc/testsuite/gcc.dg/ipa/pr48195.c
@@ -1,5 +1,5 @@
 /* { dg-do link } */
-/* { dg-options "-O2 -flto --param partial-inlining-entry-probability=101" } */
+/* { dg-options "-O2 -flto --param partial-inlining-entry-probability=100" } */
 /* { dg-require-effective-target lto } */
 
 extern void abort(void);
-- 
2.13.1


[-- Attachment #5: 0012-Backport-r248089.patch --]
[-- Type: text/x-patch, Size: 1474 bytes --]

From 59383db2594cfaf380ce6e91a14b4b11f977f497 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 16 May 2017 08:57:05 +0000
Subject: [PATCH 12/15] Backport r248089

gcc/ChangeLog:

2017-05-16  Martin Liska  <mliska@suse.cz>

	PR ipa/79849.
	PR ipa/79850.
	* ipa-devirt.c (warn_types_mismatch): Fix typo.
	(odr_types_equivalent_p): Likewise.
---
 gcc/ipa-devirt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index 0332b3ec616..9853c4a499c 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -1225,7 +1225,7 @@ warn_types_mismatch (tree t1, tree t2, location_t loc1, location_t loc2)
   if (types_odr_comparable (t1, t2, true)
       && types_same_for_odr (t1, t2, true))
     inform (loc_t1,
-	    "type %qT itself violate the C++ One Definition Rule", t1);
+	    "type %qT itself violates the C++ One Definition Rule", t1);
   /* Prevent pointless warnings like "struct aa" should match "struct aa".  */
   else if (TYPE_NAME (t1) == TYPE_NAME (t2)
 	   && TREE_CODE (t1) == TREE_CODE (t2) && !loc_t2_useful)
@@ -1572,7 +1572,7 @@ odr_types_equivalent_p (tree t1, tree t2, bool warn, bool *warned,
 		    if (DECL_ARTIFICIAL (f1))
 		      break;
 		    warn_odr (t1, t2, f1, f2, warn, warned,
-			      G_("fields has different layout "
+			      G_("fields have different layout "
 				 "in another translation unit"));
 		    return false;
 		  }
-- 
2.13.1


[-- Attachment #6: 0011-Backport-r248060.patch --]
[-- Type: text/x-patch, Size: 982 bytes --]

From 2dc4257323515937f9d9cc25c1a7e8f58db5899c Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 15 May 2017 12:48:35 +0000
Subject: [PATCH 11/15] Backport r248060

gcc/ChangeLog:

2017-05-15  Martin Liska  <mliska@suse.cz>

	PR driver/31468
	* gcc.c (process_command): Do not allow empty argument of -o option.
---
 gcc/gcc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/gcc.c b/gcc/gcc.c
index c6a6fe08448..3e2c0b1b597 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -4422,6 +4422,9 @@ process_command (unsigned int decoded_options_count,
 		       output_file);
     }
 
+  if (output_file != NULL && output_file[0] == '\0')
+    fatal_error (input_location, "output filename may not be empty");
+
   /* If -save-temps=obj and -o name, create the prefix to use for %b.
      Otherwise just make -save-temps=obj the same as -save-temps=cwd.  */
   if (save_temps_flag == SAVE_TEMPS_OBJ && save_temps_prefix != NULL)
-- 
2.13.1


[-- Attachment #7: 0010-Backport-r247507.patch --]
[-- Type: text/x-patch, Size: 1177 bytes --]

From ad5c855543843df18e0091fcf620731d74150bc4 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 2 May 2017 15:37:41 +0000
Subject: [PATCH 10/15] Backport r247507

gcc/ChangeLog:

2017-05-02  Martin Liska  <mliska@suse.cz>

	* doc/gcov.texi: Add missing preposition.
	* gcov.c (function_info::function_info): Properly fill up
	all member variables.
---
 gcc/doc/gcov.texi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index d38f63370c2..6d6a10bff11 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -324,7 +324,7 @@ containing no code.  Unexecuted lines are marked @samp{#####} or
 @samp{====}, depending on whether they are reachable by
 non-exceptional paths or only exceptional paths such as C++ exception
 handlers, respectively. Given @samp{-a} option, unexecuted blocks are
-marked @samp{$$$$$} or @samp{%%%%%}, depending whether a basic block
+marked @samp{$$$$$} or @samp{%%%%%}, depending on whether a basic block
 is reachable via non-exceptional or exceptional paths.
 
 Some lines of information at the start have @var{line_number} of zero.
-- 
2.13.1


[-- Attachment #8: 0009-Backport-r247485.patch --]
[-- Type: text/x-patch, Size: 1113 bytes --]

From 0666bab34399acec12c83478c3aec2d2e44b49f5 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 2 May 2017 09:38:55 +0000
Subject: [PATCH 09/15] Backport r247485

gcc/ChangeLog:

2017-05-02  Martin Liska  <mliska@suse.cz>

	PR other/80589
	* common.opt: Fix typo.
	* doc/invoke.texi: Likewise.
---
 gcc/common.opt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 67048db7c9b..a25557720b5 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2373,7 +2373,7 @@ flow and turn the statement with erroneous or undefined behavior into a trap.
 
 fisolate-erroneous-paths-attribute
 Common Report Var(flag_isolate_erroneous_paths_attribute) Optimization
-Detect paths that trigger erroneous or undefined behavior due a null value
+Detect paths that trigger erroneous or undefined behavior due to a null value
 being used in a way forbidden by a returns_nonnull or nonnull
 attribute.  Isolate those paths from the main control flow and turn the
 statement with erroneous or undefined behavior into a trap.
-- 
2.13.1


[-- Attachment #9: 0008-Backport-r247377.patch --]
[-- Type: text/x-patch, Size: 1586 bytes --]

From 5ee76c1c179d15da72b09ce7a71617208cfd5f17 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 28 Apr 2017 12:51:57 +0000
Subject: [PATCH 08/15] Backport r247377

gcc/ChangeLog:

2017-04-28  Martin Liska  <mliska@suse.cz>

	* doc/gcov.texi: Enhance documentation of gcov.
---
 gcc/doc/gcov.texi | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index 5b409e1f793..d38f63370c2 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -323,7 +323,9 @@ command line option.  The @var{execution_count} is @samp{-} for lines
 containing no code.  Unexecuted lines are marked @samp{#####} or
 @samp{====}, depending on whether they are reachable by
 non-exceptional paths or only exceptional paths such as C++ exception
-handlers, respectively.
+handlers, respectively. Given @samp{-a} option, unexecuted blocks are
+marked @samp{$$$$$} or @samp{%%%%%}, depending whether a basic block
+is reachable via non-exceptional or exceptional paths.
 
 Some lines of information at the start have @var{line_number} of zero.
 These preamble lines are of the form
@@ -668,5 +670,5 @@ it.  This can be overcome by, for example, setting the environment as
 setting will name the data file @file{/target/run/build/foo.gcda}.
 
 You must move the data files to the expected directory tree in order to
-use them for profile directed optimizations (@option{--use-profile}), or to
+use them for profile directed optimizations (@option{-fprofile-use}), or to
 use the @command{gcov} tool.
-- 
2.13.1


[-- Attachment #10: 0007-Backport-r247376.patch --]
[-- Type: text/x-patch, Size: 16976 bytes --]

From 6a0484ab7532ae3f44c163c0bfcb87bb9f808f88 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 28 Apr 2017 12:51:40 +0000
Subject: [PATCH 07/15] Backport r247376

gcc/ChangeLog:

2017-04-28  Martin Liska  <mliska@suse.cz>

	* doc/gcov.texi: Sort options in alphabetic order.
	* doc/gcov-dump.texi: Likewise.
	* doc/gcov-tool.texi: Likewise.
	* gcov.c (print_usage): Likewise.
	* gcov-dump.c (print_usage): Likewise.
	* gcov-tool.c (print_merge_usage_message): Likewise.
	(print_rewrite_usage_message): Likewise.
	(print_overlap_usage_message): Likewise.
---
 gcc/doc/gcov-dump.texi |  10 ++--
 gcc/doc/gcov-tool.texi |  50 ++++++++---------
 gcc/doc/gcov.texi      | 147 +++++++++++++++++++++++++++----------------------
 gcc/gcov-dump.c        |   2 +-
 gcc/gcov-tool.c        |   9 +--
 gcc/gcov.c             |   2 +-
 6 files changed, 118 insertions(+), 102 deletions(-)

diff --git a/gcc/doc/gcov-dump.texi b/gcc/doc/gcov-dump.texi
index d7931fd3a19..26653d28def 100644
--- a/gcc/doc/gcov-dump.texi
+++ b/gcc/doc/gcov-dump.texi
@@ -72,11 +72,6 @@ gcov-dump [@option{-v}|@option{--version}]
 Display help about using @command{gcov-dump} (on the standard output), and
 exit without doing any further processing.
 
-@item -v
-@itemx --version
-Display the @command{gcov-dump} version number (on the standard output),
-and exit without doing any further processing.
-
 @item -l
 @itemx --long
 Dump content of records.
@@ -85,6 +80,11 @@ Dump content of records.
 @itemx --positions
 Dump positions of records.
 
+@item -v
+@itemx --version
+Display the @command{gcov-dump} version number (on the standard output),
+and exit without doing any further processing.
+
 @item -w
 @itemx --working-sets
 Dump working set computed from summary.
diff --git a/gcc/doc/gcov-tool.texi b/gcc/doc/gcov-tool.texi
index 845f14b1041..395628e4d36 100644
--- a/gcc/doc/gcov-tool.texi
+++ b/gcc/doc/gcov-tool.texi
@@ -113,23 +113,23 @@ gcov-tool @r{[}@var{global-options}@r{]} SUB_COMMAND @r{[}@var{sub_command-optio
 gcov-tool [@option{-v}|@option{--version}] [@option{-h}|@option{--help}]
 
 gcov-tool merge [merge-options] @var{directory1} @var{directory2}
+     [@option{-o}|@option{--output} @var{directory}]
      [@option{-v}|@option{--verbose}]
-     [@option{-o}|@option{ --output} @var{directory}]
      [@option{-w}|@option{--weight} @var{w1,w2}]
 
 gcov-tool rewrite [rewrite-options] @var{directory}
-     [@option{-v}|@option{--verbose}]
+     [@option{-n}|@option{--normalize} @var{long_long_value}]
      [@option{-o}|@option{--output} @var{directory}]
      [@option{-s}|@option{--scale} @var{float_or_simple-frac_value}]
-     [@option{-n}|@option{--normalize} @var{long_long_value}]
+     [@option{-v}|@option{--verbose}]
 
 gcov-tool overlap [overlap-options] @var{directory1} @var{directory2}
-     [@option{-v}|@option{--verbose}]
-     [@option{-h}|@option{--hotonly}]
      [@option{-f}|@option{--function}]
      [@option{-F}|@option{--fullname}]
+     [@option{-h}|@option{--hotonly}]
      [@option{-o}|@option{--object}]
      [@option{-t}|@option{--hot_threshold}] @var{float}
+     [@option{-v}|@option{--verbose}]
 
 @c man end
 @c man begin SEEALSO
@@ -152,17 +152,17 @@ and exit without doing any further processing.
 
 @item merge
 Merge two profile directories.
-
 @table @gcctabopt
-@item -v
-@itemx --verbose
-Set the verbose mode.
 
 @item -o @var{directory}
 @itemx --output @var{directory}
 Set the output profile directory. Default output directory name is
 @var{merged_profile}.
 
+@item -v
+@itemx --verbose
+Set the verbose mode.
+
 @item -w @var{w1},@var{w2}
 @itemx --weight @var{w1},@var{w2}
 Set the merge weights of the @var{directory1} and @var{directory2},
@@ -171,11 +171,12 @@ respectively. The default weights are 1 for both.
 
 @item rewrite
 Read the specified profile directory and rewrite to a new directory.
-
 @table @gcctabopt
-@item -v
-@itemx --verbose
-Set the verbose mode.
+
+@item -n @var{long_long_value}
+@itemx --normalize <long_long_value>
+Normalize the profile. The specified value is the max counter value
+in the new profile.
 
 @item -o @var{directory}
 @itemx --output @var{directory}
@@ -186,10 +187,9 @@ Set the output profile directory. Default output name is @var{rewrite_profile}.
 Scale the profile counters. The specified value can be in floating point value,
 or simple fraction value form, such 1, 2, 2/3, and 5/3.
 
-@item -n @var{long_long_value}
-@itemx --normalize <long_long_value>
-Normalize the profile. The specified value is the max counter value
-in the new profile.
+@item -v
+@itemx --verbose
+Set the verbose mode.
 @end table
 
 @item overlap
@@ -201,14 +201,6 @@ matched counters and p1_sum_all and p2_sum_all are the sum of counter
 values in profile 1 and profile 2, respectively.
 
 @table @gcctabopt
-@item -v
-@itemx --verbose
-Set the verbose mode.
-
-@item -h
-@itemx --hotonly
-Only print info for hot objects/functions.
-
 @item -f
 @itemx --function
 Print function level overlap score.
@@ -217,6 +209,10 @@ Print function level overlap score.
 @itemx --fullname
 Print full gcda filename.
 
+@item -h
+@itemx --hotonly
+Only print info for hot objects/functions.
+
 @item -o
 @itemx --object
 Print object level overlap score.
@@ -224,6 +220,10 @@ Print object level overlap score.
 @item -t @var{float}
 @itemx --hot_threshold <float>
 Set the threshold for hot counter value.
+
+@item -v
+@itemx --verbose
+Set the verbose mode.
 @end table
 
 @end table
diff --git a/gcc/doc/gcov.texi b/gcc/doc/gcov.texi
index 89d80499f0e..5b409e1f793 100644
--- a/gcc/doc/gcov.texi
+++ b/gcc/doc/gcov.texi
@@ -142,15 +142,6 @@ gpl(7), gfdl(7), fsf-funding(7), gcc(1) and the Info entry for @file{gcc}.
 
 @c man begin OPTIONS
 @table @gcctabopt
-@item -h
-@itemx --help
-Display help about using @command{gcov} (on the standard output), and
-exit without doing any further processing.
-
-@item -v
-@itemx --version
-Display the @command{gcov} version number (on the standard output),
-and exit without doing any further processing.
 
 @item -a
 @itemx --all-blocks
@@ -171,68 +162,18 @@ be shown, unless the @option{-u} option is given.
 Write branch frequencies as the number of branches taken, rather than
 the percentage of branches taken.
 
-@item -n
-@itemx --no-output
-Do not create the @command{gcov} output file.
-
-@item -l
-@itemx --long-file-names
-Create long file names for included source files.  For example, if the
-header file @file{x.h} contains code, and was included in the file
-@file{a.c}, then running @command{gcov} on the file @file{a.c} will
-produce an output file called @file{a.c##x.h.gcov} instead of
-@file{x.h.gcov}.  This can be useful if @file{x.h} is included in
-multiple source files and you want to see the individual
-contributions.  If you use the @samp{-p} option, both the including
-and included file names will be complete path names.
-
-@item -p
-@itemx --preserve-paths
-Preserve complete path information in the names of generated
-@file{.gcov} files.  Without this option, just the filename component is
-used.  With this option, all directories are used, with @samp{/} characters
-translated to @samp{#} characters, @file{.} directory components
-removed and unremoveable @file{..}
-components renamed to @samp{^}.  This is useful if sourcefiles are in several
-different directories.
-
-@item -r
-@itemx --relative-only
-Only output information about source files with a relative pathname
-(after source prefix elision).  Absolute paths are usually system
-header files and coverage of any inline functions therein is normally
-uninteresting.
+@item -d
+@itemx --display-progress
+Display the progress on the standard output.
 
 @item -f
 @itemx --function-summaries
 Output summaries for each function in addition to the file level summary.
 
-@item -o @var{directory|file}
-@itemx --object-directory @var{directory}
-@itemx --object-file @var{file}
-Specify either the directory containing the gcov data files, or the
-object path name.  The @file{.gcno}, and
-@file{.gcda} data files are searched for using this option.  If a directory
-is specified, the data files are in that directory and named after the
-input file name, without its extension.  If a file is specified here,
-the data files are named after that file, without its extension.
-
-@item -s @var{directory}
-@itemx --source-prefix @var{directory}
-A prefix for source file names to remove when generating the output
-coverage files.  This option is useful when building in a separate
-directory, and the pathname to the source directory is not wanted when
-determining the output file names.  Note that this prefix detection is
-applied before determining whether the source file is absolute.
-
-@item -u
-@itemx --unconditional-branches
-When branch probabilities are given, include those of unconditional branches.
-Unconditional branches are normally not interesting.
-
-@item -d
-@itemx --display-progress
-Display the progress on the standard output.
+@item -h
+@itemx --help
+Display help about using @command{gcov} (on the standard output), and
+exit without doing any further processing.
 
 @item -i
 @itemx --intermediate-format
@@ -273,11 +214,85 @@ lcount:26,1
 branch:28,nottaken
 @end smallexample
 
+@item -l
+@itemx --long-file-names
+Create long file names for included source files.  For example, if the
+header file @file{x.h} contains code, and was included in the file
+@file{a.c}, then running @command{gcov} on the file @file{a.c} will
+produce an output file called @file{a.c##x.h.gcov} instead of
+@file{x.h.gcov}.  This can be useful if @file{x.h} is included in
+multiple source files and you want to see the individual
+contributions.  If you use the @samp{-p} option, both the including
+and included file names will be complete path names.
+
 @item -m
 @itemx --demangled-names
 Display demangled function names in output. The default is to show
 mangled function names.
 
+@item -n
+@itemx --no-output
+Do not create the @command{gcov} output file.
+
+@item -o @var{directory|file}
+@itemx --object-directory @var{directory}
+@itemx --object-file @var{file}
+Specify either the directory containing the gcov data files, or the
+object path name.  The @file{.gcno}, and
+@file{.gcda} data files are searched for using this option.  If a directory
+is specified, the data files are in that directory and named after the
+input file name, without its extension.  If a file is specified here,
+the data files are named after that file, without its extension.
+
+@item -p
+@itemx --preserve-paths
+Preserve complete path information in the names of generated
+@file{.gcov} files.  Without this option, just the filename component is
+used.  With this option, all directories are used, with @samp{/} characters
+translated to @samp{#} characters, @file{.} directory components
+removed and unremoveable @file{..}
+components renamed to @samp{^}.  This is useful if sourcefiles are in several
+different directories.
+
+@item -r
+@itemx --relative-only
+Only output information about source files with a relative pathname
+(after source prefix elision).  Absolute paths are usually system
+header files and coverage of any inline functions therein is normally
+uninteresting.
+
+@item -s @var{directory}
+@itemx --source-prefix @var{directory}
+A prefix for source file names to remove when generating the output
+coverage files.  This option is useful when building in a separate
+directory, and the pathname to the source directory is not wanted when
+determining the output file names.  Note that this prefix detection is
+applied before determining whether the source file is absolute.
+
+@item -u
+@itemx --unconditional-branches
+When branch probabilities are given, include those of unconditional branches.
+Unconditional branches are normally not interesting.
+
+@item -v
+@itemx --version
+Display the @command{gcov} version number (on the standard output),
+and exit without doing any further processing.
+
+@item -w
+@itemx --verbose
+Print verbose informations related to basic blocks and arcs.
+
+@item -x
+@itemx --hash-filenames
+By default, gcov uses the full pathname of the source files to to create
+an output filename.  This can lead to long filenames that can overflow
+filesystem limits.  This option creates names of the form
+@file{@var{source-file}##@var{md5}.gcov},
+where the @var{source-file} component is the final filename part and
+the @var{md5} component is calculated from the full mangled name that
+would have been used otherwise.
+
 @end table
 
 @command{gcov} should be run with the current directory the same as that
diff --git a/gcc/gcov-dump.c b/gcc/gcov-dump.c
index e16fd9d6a3a..7b04b6ae2ea 100644
--- a/gcc/gcov-dump.c
+++ b/gcc/gcov-dump.c
@@ -132,9 +132,9 @@ print_usage (void)
   printf ("Usage: gcov-dump [OPTION] ... gcovfiles\n");
   printf ("Print coverage file contents\n");
   printf ("  -h, --help           Print this help\n");
-  printf ("  -v, --version        Print version number\n");
   printf ("  -l, --long           Dump record contents too\n");
   printf ("  -p, --positions      Dump record positions\n");
+  printf ("  -v, --version        Print version number\n");
   printf ("  -w, --working-sets   Dump working set computed from summary\n");
   printf ("\nFor bug reporting instructions, please see:\n%s.\n",
 	   bug_report_url);
diff --git a/gcc/gcov-tool.c b/gcc/gcov-tool.c
index 911d9249321..043966a5d07 100644
--- a/gcc/gcov-tool.c
+++ b/gcc/gcov-tool.c
@@ -173,8 +173,8 @@ print_merge_usage_message (int error_p)
   FILE *file = error_p ? stderr : stdout;
 
   fnotice (file, "  merge [options] <dir1> <dir2>         Merge coverage file contents\n");
-  fnotice (file, "    -v, --verbose                       Verbose mode\n");
   fnotice (file, "    -o, --output <dir>                  Output directory\n");
+  fnotice (file, "    -v, --verbose                       Verbose mode\n");
   fnotice (file, "    -w, --weight <w1,w2>                Set weights (float point values)\n");
 }
 
@@ -267,10 +267,11 @@ print_rewrite_usage_message (int error_p)
   FILE *file = error_p ? stderr : stdout;
 
   fnotice (file, "  rewrite [options] <dir>               Rewrite coverage file contents\n");
-  fnotice (file, "    -v, --verbose                       Verbose mode\n");
+  fnotice (file, "    -n, --normalize <int64_t>           Normalize the profile\n");
   fnotice (file, "    -o, --output <dir>                  Output directory\n");
   fnotice (file, "    -s, --scale <float or simple-frac>  Scale the profile counters\n");
   fnotice (file, "    -n, --normalize <long long>         Normalize the profile\n");
+  fnotice (file, "    -v, --verbose                       Verbose mode\n");
 }
 
 static const struct option rewrite_options[] =
@@ -423,12 +424,12 @@ print_overlap_usage_message (int error_p)
   FILE *file = error_p ? stderr : stdout;
 
   fnotice (file, "  overlap [options] <dir1> <dir2>       Compute the overlap of two profiles\n");
-  fnotice (file, "    -v, --verbose                       Verbose mode\n");
-  fnotice (file, "    -h, --hotonly                       Only print info for hot objects/functions\n");
   fnotice (file, "    -f, --function                      Print function level info\n");
   fnotice (file, "    -F, --fullname                      Print full filename\n");
+  fnotice (file, "    -h, --hotonly                       Only print info for hot objects/functions\n");
   fnotice (file, "    -o, --object                        Print object level info\n");
   fnotice (file, "    -t <float>, --hot_threshold <float> Set the threshold for hotness\n");
+  fnotice (file, "    -v, --verbose                       Verbose mode\n");
 
 }
 
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 9c27149f84d..3a63e844225 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -471,13 +471,13 @@ print_usage (int error_p)
 
   fnotice (file, "Usage: gcov [OPTION...] SOURCE|OBJ...\n\n");
   fnotice (file, "Print code coverage information.\n\n");
-  fnotice (file, "  -h, --help                      Print this help, then exit\n");
   fnotice (file, "  -a, --all-blocks                Show information for every basic block\n");
   fnotice (file, "  -b, --branch-probabilities      Include branch probabilities in output\n");
   fnotice (file, "  -c, --branch-counts             Output counts of branches taken\n\
                                     rather than percentages\n");
   fnotice (file, "  -d, --display-progress          Display progress information\n");
   fnotice (file, "  -f, --function-summaries        Output summaries for each function\n");
+  fnotice (file, "  -h, --help                      Print this help, then exit\n");
   fnotice (file, "  -i, --intermediate-format       Output .gcov file in intermediate text format\n");
   fnotice (file, "  -l, --long-file-names           Use long output file names for included\n\
                                     source files\n");
-- 
2.13.1


[-- Attachment #11: 0006-Backport-r247375.patch --]
[-- Type: text/x-patch, Size: 913 bytes --]

From 121e6c3b5b9d4e7d917d0563b4b4a6081eb3986b Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 28 Apr 2017 12:51:22 +0000
Subject: [PATCH 06/15] Backport r247375

gcc/ChangeLog:

2017-04-28  Martin Liska  <mliska@suse.cz>

	PR gcov-profile/53915
	* gcov.c (format_gcov): Print 'NAN %' when top > bottom.
---
 gcc/gcov.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index e60392210bf..9c27149f84d 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1768,6 +1768,13 @@ format_gcov (gcov_type top, gcov_type bottom, int dp)
 {
   static char buffer[20];
 
+  /* Handle invalid values that would result in a misleading value.  */
+  if (bottom != 0 && top > bottom && dp >= 0)
+    {
+      sprintf (buffer, "NAN %%");
+      return buffer;
+    }
+
   if (dp >= 0)
     {
       float ratio = bottom ? (float)top / bottom : 0;
-- 
2.13.1


[-- Attachment #12: 0005-Backport-r247371.patch --]
[-- Type: text/x-patch, Size: 1869 bytes --]

From 153d8781eaea461aa0988ae20a5305cf6ae3589c Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 28 Apr 2017 12:50:08 +0000
Subject: [PATCH 05/15] Backport r247371

gcc/ChangeLog:

2017-04-28  Martin Liska  <mliska@suse.cz>

	PR driver/56469
	* coverage.c (coverage_remove_note_file): New function.
	* coverage.h: Declare the function.
	* toplev.c (finalize): Clean if an error has been seen.
---
 gcc/coverage.c | 12 ++++++++++++
 gcc/coverage.h |  1 +
 gcc/toplev.c   |  3 +++
 3 files changed, 16 insertions(+)

diff --git a/gcc/coverage.c b/gcc/coverage.c
index b1fce7d0e7a..7ee37aa2955 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -725,6 +725,18 @@ coverage_end_function (unsigned lineno_checksum, unsigned cfg_checksum)
     }
 }
 
+/* Remove coverage file if opened.  */
+
+void
+coverage_remove_note_file (void)
+{
+  if (bbg_file_name)
+    {
+      gcov_close ();
+      unlink (bbg_file_name);
+    }
+}
+
 /* Build a coverage variable of TYPE for function FN_DECL.  If COUNTER
    >= 0 it is a counter array, otherwise it is the function structure.  */
 
diff --git a/gcc/coverage.h b/gcc/coverage.h
index 39e48ce38f5..e0ff0fb08c3 100644
--- a/gcc/coverage.h
+++ b/gcc/coverage.h
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 
 extern void coverage_init (const char *);
 extern void coverage_finish (void);
+extern void coverage_remove_note_file (void);
 
 /* Start outputting coverage information for the current
    function.  */
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 59604e56195..3d4137b7c7b 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1926,6 +1926,9 @@ finalize (bool no_backend)
   if (stack_usage_file)
     fclose (stack_usage_file);
 
+  if (seen_error ())
+    coverage_remove_note_file ();
+
   if (!no_backend)
     {
       statistics_fini ();
-- 
2.13.1


[-- Attachment #13: 0004-Backport-r246899.patch --]
[-- Type: text/x-patch, Size: 3315 bytes --]

From 2715e072869a0bdc566a62819e2129eabc33091b Mon Sep 17 00:00:00 2001
From: hubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 13 Apr 2017 08:04:52 +0000
Subject: [PATCH 04/15] Backport r246899

gcc/ChangeLog:

2017-04-12  Jan Hubicka  <hubicka@ucw.cz>

	PR lto/69953
	* ipa-visibility.c (non_local_p): Fix typos.
	(localize_node): When localizing symbol in same comdat group,
	dissolve the group only when we know external symbols are going
	to be privatized.
	(function_and_variable_visibility): Do not localize DECL_EXTERNAL.
---
 gcc/ipa-visibility.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c
index 25ef2623a0e..adc4426e6be 100644
--- a/gcc/ipa-visibility.c
+++ b/gcc/ipa-visibility.c
@@ -90,7 +90,7 @@ static bool
 non_local_p (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED)
 {
   return !(node->only_called_directly_or_aliased_p ()
-	   /* i386 would need update to output thunk with locak calling
+	   /* i386 would need update to output thunk with local calling
 	      ocnvetions.  */
 	   && !node->thunk.thunk_p
 	   && node->definition
@@ -153,7 +153,7 @@ comdat_can_be_unshared_p_1 (symtab_node *node)
 /* COMDAT functions must be shared only if they have address taken,
    otherwise we can produce our own private implementation with
    -fwhole-program.  
-   Return true when turning COMDAT functoin static can not lead to wrong
+   Return true when turning COMDAT function static can not lead to wrong
    code when the resulting object links with a library defining same COMDAT.
 
    Virtual functions do have their addresses taken from the vtables,
@@ -538,6 +538,35 @@ localize_node (bool whole_program, symtab_node *node)
 {
   gcc_assert (whole_program || in_lto_p || !TREE_PUBLIC (node->decl));
 
+  /* It is possible that one comdat group contains both hidden and non-hidden
+     symbols.  In this case we can privatize all hidden symbol but we need
+     to keep non-hidden exported.  */
+  if (node->same_comdat_group
+      && node->resolution == LDPR_PREVAILING_DEF_IRONLY)
+    {
+      symtab_node *next;
+      for (next = node->same_comdat_group;
+	   next != node; next = next->same_comdat_group)
+	if (next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
+	    || next->resolution == LDPR_PREVAILING_DEF)
+	  break;
+      if (node != next)
+	{
+	  if (!node->transparent_alias)
+	    {
+	      node->resolution = LDPR_PREVAILING_DEF_IRONLY;
+	      node->make_decl_local ();
+	      if (!flag_incremental_link)
+	        node->unique_name |= true;
+	      return;
+	    }
+	}
+    }
+  /* For similar reason do not privatize whole comdat when seeing comdat
+     local.  Wait for non-comdat symbol to be privatized first.  */
+  if (node->comdat_local_p ())
+    return;
+
   if (node->same_comdat_group && TREE_PUBLIC (node->decl))
     {
       for (symtab_node *next = node->same_comdat_group;
@@ -766,7 +795,8 @@ function_and_variable_visibility (bool whole_program)
 	vnode->no_reorder = 1;
 
       if (!vnode->externally_visible
-	  && !vnode->transparent_alias)
+	  && !vnode->transparent_alias
+	  && !DECL_EXTERNAL (vnode->decl))
 	localize_node (whole_program, vnode);
 
       update_visibility_by_resolution_info (vnode);
-- 
2.13.1


[-- Attachment #14: 0003-Backport-r244529.patch --]
[-- Type: text/x-patch, Size: 5970 bytes --]

From 720cf7739622449878ed844f0de00e68945ac6b4 Mon Sep 17 00:00:00 2001
From: nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Tue, 17 Jan 2017 15:04:50 +0000
Subject: [PATCH 03/15] Backport r244529

gcc/ChangeLog:

2017-01-17  Nathan Sidwell  <nathan@acm.org>

	* ipa-visibility.c (localize_node): New function, broken out of ...
	(function_and_variable_visibility): ... here. Call it.
---
 gcc/ipa-visibility.c | 132 +++++++++++++++++++--------------------------------
 1 file changed, 50 insertions(+), 82 deletions(-)

diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c
index cd10ad01055..25ef2623a0e 100644
--- a/gcc/ipa-visibility.c
+++ b/gcc/ipa-visibility.c
@@ -530,6 +530,53 @@ optimize_weakref (symtab_node *node)
   gcc_assert (node->alias);
 }
 
+/* NODE is an externally visible definition, which we've discovered is
+   not needed externally.  Make it local to this compilation.  */
+
+static void
+localize_node (bool whole_program, symtab_node *node)
+{
+  gcc_assert (whole_program || in_lto_p || !TREE_PUBLIC (node->decl));
+
+  if (node->same_comdat_group && TREE_PUBLIC (node->decl))
+    {
+      for (symtab_node *next = node->same_comdat_group;
+	   next != node; next = next->same_comdat_group)
+	{
+	  next->set_comdat_group (NULL);
+	  if (!next->alias)
+	    next->set_section (NULL);
+	  if (!next->transparent_alias)
+	    next->make_decl_local ();
+	  next->unique_name
+	    |= ((next->resolution == LDPR_PREVAILING_DEF_IRONLY
+		 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
+		&& TREE_PUBLIC (next->decl)
+		&& !flag_incremental_link);
+	}
+
+      /* Now everything's localized, the grouping has no meaning, and
+	 will cause crashes if we keep it around.  */
+      node->dissolve_same_comdat_group_list ();
+    }
+
+  node->unique_name
+    |= ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
+	 || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
+	&& TREE_PUBLIC (node->decl)
+	&& !flag_incremental_link);
+
+  if (TREE_PUBLIC (node->decl))
+    node->set_comdat_group (NULL);
+  if (DECL_COMDAT (node->decl) && !node->alias)
+    node->set_section (NULL);
+  if (!node->transparent_alias)
+    {
+      node->resolution = LDPR_PREVAILING_DEF_IRONLY;
+      node->make_decl_local ();
+    }
+}
+
 /* Decide on visibility of all symbols.  */
 
 static unsigned int
@@ -607,48 +654,7 @@ function_and_variable_visibility (bool whole_program)
       if (!node->externally_visible
 	  && node->definition && !node->weakref
 	  && !DECL_EXTERNAL (node->decl))
-	{
-	  gcc_assert (whole_program || in_lto_p
-		      || !TREE_PUBLIC (node->decl));
-	  node->unique_name
-	    |= ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
-		 || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
-		&& TREE_PUBLIC (node->decl)
-		&& !flag_incremental_link);
-	  node->resolution = LDPR_PREVAILING_DEF_IRONLY;
-	  if (node->same_comdat_group && TREE_PUBLIC (node->decl))
-	    {
-	      symtab_node *next = node;
-
-	      /* Set all members of comdat group local.  */
-	      for (next = node->same_comdat_group;
-		   next != node;
-		   next = next->same_comdat_group)
-		{
-		  next->set_comdat_group (NULL);
-		  if (!next->alias)
-		    next->set_section (NULL);
-		  if (!next->transparent_alias)
-		    next->make_decl_local ();
-		  next->unique_name
-		    |= ((next->resolution == LDPR_PREVAILING_DEF_IRONLY
-			 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
-			&& TREE_PUBLIC (next->decl)
-			&& !flag_incremental_link);
-		}
-	      /* cgraph_externally_visible_p has already checked all
-	         other nodes in the group and they will all be made
-	         local.  We need to dissolve the group at once so that
-	         the predicate does not segfault though. */
-	      node->dissolve_same_comdat_group_list ();
-	    }
-	  if (TREE_PUBLIC (node->decl))
-	    node->set_comdat_group (NULL);
-	  if (DECL_COMDAT (node->decl) && !node->alias)
-	    node->set_section (NULL);
-	  if (!node->transparent_alias)
-	    node->make_decl_local ();
-	}
+	localize_node (whole_program, node);
 
       if (node->thunk.thunk_p
 	  && !node->thunk.add_pointer_bounds_args
@@ -758,49 +764,11 @@ function_and_variable_visibility (bool whole_program)
       if (lookup_attribute ("no_reorder",
 			    DECL_ATTRIBUTES (vnode->decl)))
 	vnode->no_reorder = 1;
+
       if (!vnode->externally_visible
 	  && !vnode->transparent_alias)
-	{
-	  gcc_assert (in_lto_p || whole_program || !TREE_PUBLIC (vnode->decl));
-	  vnode->unique_name |= ((vnode->resolution == LDPR_PREVAILING_DEF_IRONLY
-			          || vnode->resolution
-				      == LDPR_PREVAILING_DEF_IRONLY_EXP)
-			         && TREE_PUBLIC (vnode->decl)
-				 && !flag_incremental_link);
-	  if (vnode->same_comdat_group && TREE_PUBLIC (vnode->decl))
-	    {
-	      symtab_node *next = vnode;
+	localize_node (whole_program, vnode);
 
-	      /* Set all members of comdat group local.  */
-	      if (vnode->same_comdat_group)
-		for (next = vnode->same_comdat_group;
-		     next != vnode;
-		     next = next->same_comdat_group)
-		{
-		  next->set_comdat_group (NULL);
-		  if (!next->alias)
-		    next->set_section (NULL);
-		  if (!next->transparent_alias)
-		    {
-		      next->make_decl_local ();
-		      next->unique_name |= ((next->resolution == LDPR_PREVAILING_DEF_IRONLY
-					     || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
-					    && TREE_PUBLIC (next->decl)
-					    && !flag_incremental_link);
-		    }
-		}
-	      vnode->dissolve_same_comdat_group_list ();
-	    }
-	  if (TREE_PUBLIC (vnode->decl))
-	    vnode->set_comdat_group (NULL);
-	  if (DECL_COMDAT (vnode->decl) && !vnode->alias)
-	    vnode->set_section (NULL);
-	  if (!vnode->transparent_alias)
-	    {
-	      vnode->make_decl_local ();
-	      vnode->resolution = LDPR_PREVAILING_DEF_IRONLY;
-	    }
-	}
       update_visibility_by_resolution_info (vnode);
 
       /* Update virtual tables to point to local aliases where possible.  */
-- 
2.13.1


[-- Attachment #15: 0002-Backport-r244156.patch --]
[-- Type: text/x-patch, Size: 7394 bytes --]

From 35ca724ea43463bc44abb6025cd4a79bccad582a Mon Sep 17 00:00:00 2001
From: nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 6 Jan 2017 14:04:05 +0000
Subject: [PATCH 02/15] Backport r244156

gcc/ChangeLog:

2017-01-06  Nathan Sidwell  <nathan@acm.org>

	* ipa-visibility.c (function_and_variable_visibility): Reformat
	comments and long lines.  Remove extrneous if.
	* symtab.c (symtab_node::make_decl_local): Fix code format.
	(symtab_node::set_section_for_node): Fix comment typo.

gcc/lto/ChangeLog:

2017-01-06  Nathan Sidwell  <nathan@acm.org>

	* lto-partition.c (lto_balanced_map): Reformat/respell comment.
	(may_need_named_section_p): Likewise.
	(rename_statics): Likewise.
	(lto_promote_cross_file_statics): Likewise.
---
 gcc/ipa-visibility.c    | 39 ++++++++++++++++++++-------------------
 gcc/lto/lto-partition.c | 23 +++++++++++++----------
 gcc/symtab.c            |  5 +++--
 3 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c
index e4c3f7c5110..cd10ad01055 100644
--- a/gcc/ipa-visibility.c
+++ b/gcc/ipa-visibility.c
@@ -554,9 +554,9 @@ function_and_variable_visibility (bool whole_program)
 	  DECL_STATIC_DESTRUCTOR (node->decl) = 0;
 	}
 
-      /* Frontends and alias code marks nodes as needed before parsing is finished.
-	 We may end up marking as node external nodes where this flag is meaningless
-	 strip it.  */
+      /* Frontends and alias code marks nodes as needed before parsing
+	 is finished.  We may end up marking as node external nodes
+	 where this flag is meaningless strip it.  */
       if (DECL_EXTERNAL (node->decl) || !node->definition)
 	{
 	  node->force_output = 0;
@@ -610,35 +610,36 @@ function_and_variable_visibility (bool whole_program)
 	{
 	  gcc_assert (whole_program || in_lto_p
 		      || !TREE_PUBLIC (node->decl));
-	  node->unique_name |= ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
-				 || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
-				&& TREE_PUBLIC (node->decl)
-				&& !flag_incremental_link);
+	  node->unique_name
+	    |= ((node->resolution == LDPR_PREVAILING_DEF_IRONLY
+		 || node->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
+		&& TREE_PUBLIC (node->decl)
+		&& !flag_incremental_link);
 	  node->resolution = LDPR_PREVAILING_DEF_IRONLY;
 	  if (node->same_comdat_group && TREE_PUBLIC (node->decl))
 	    {
 	      symtab_node *next = node;
 
 	      /* Set all members of comdat group local.  */
-	      if (node->same_comdat_group)
-		for (next = node->same_comdat_group;
-		     next != node;
-		     next = next->same_comdat_group)
+	      for (next = node->same_comdat_group;
+		   next != node;
+		   next = next->same_comdat_group)
 		{
 		  next->set_comdat_group (NULL);
 		  if (!next->alias)
 		    next->set_section (NULL);
 		  if (!next->transparent_alias)
 		    next->make_decl_local ();
-		  next->unique_name |= ((next->resolution == LDPR_PREVAILING_DEF_IRONLY
-					 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
-				        && TREE_PUBLIC (next->decl)
-					&& !flag_incremental_link);
+		  next->unique_name
+		    |= ((next->resolution == LDPR_PREVAILING_DEF_IRONLY
+			 || next->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP)
+			&& TREE_PUBLIC (next->decl)
+			&& !flag_incremental_link);
 		}
-	      /* cgraph_externally_visible_p has already checked all other nodes
-	         in the group and they will all be made local.  We need to
-	         dissolve the group at once so that the predicate does not
-	         segfault though. */
+	      /* cgraph_externally_visible_p has already checked all
+	         other nodes in the group and they will all be made
+	         local.  We need to dissolve the group at once so that
+	         the predicate does not segfault though. */
 	      node->dissolve_same_comdat_group_list ();
 	    }
 	  if (TREE_PUBLIC (node->decl))
diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c
index 9eb63c27f33..051b98771fc 100644
--- a/gcc/lto/lto-partition.c
+++ b/gcc/lto/lto-partition.c
@@ -664,8 +664,9 @@ lto_balanced_map (int n_lto_partitions)
 
 		vnode = dyn_cast <varpool_node *> (ref->referring);
 		gcc_assert (vnode->definition);
-		/* It is better to couple variables with their users, because it allows them
-		   to be removed.  Coupling with objects they refer to only helps to reduce
+		/* It is better to couple variables with their users,
+		   because it allows them to be removed.  Coupling
+		   with objects they refer to only helps to reduce
 		   number of symbols promoted to hidden.  */
 		if (!symbol_partitioned_p (vnode) && flag_toplevel_reorder
 		    && !vnode->no_reorder
@@ -1003,10 +1004,11 @@ promote_symbol (symtab_node *node)
 	    "Promoting as hidden: %s\n", node->name ());
 }
 
-/* Return true if NODE needs named section even if it won't land in the partition
-   symbol table.
-   FIXME: we should really not use named sections for inline clones and master
-   clones.  */
+/* Return true if NODE needs named section even if it won't land in
+   the partition symbol table.
+
+   FIXME: we should really not use named sections for inline clones
+   and master clones.  */
 
 static bool
 may_need_named_section_p (lto_symtab_encoder_t encoder, symtab_node *node)
@@ -1084,7 +1086,8 @@ rename_statics (lto_symtab_encoder_t encoder, symtab_node *node)
 	    || lto_symtab_encoder_lookup (encoder, s) != LCC_NOT_FOUND))
       {
         if (privatize_symbol_name (s))
-	  /* Re-start from beginning since we do not know how many symbols changed a name.  */
+	  /* Re-start from beginning since we do not know how many
+	     symbols changed a name.  */
 	  s = symtab_node::get_for_asmname (name);
         else s = s->next_sharing_asm_name;
       }
@@ -1125,8 +1128,8 @@ lto_promote_cross_file_statics (void)
         {
           symtab_node *node = lsei_node (lsei);
 
-	  /* If symbol is static, rename it if its assembler name clash with
-	     anything else in this unit.  */
+	  /* If symbol is static, rename it if its assembler name
+	     clashes with anything else in this unit.  */
 	  rename_statics (encoder, node);
 
 	  /* No need to promote if symbol already is externally visible ... */
@@ -1134,7 +1137,7 @@ lto_promote_cross_file_statics (void)
  	      /* ... or if it is part of current partition ... */
 	      || lto_symtab_encoder_in_partition_p (encoder, node)
 	      /* ... or if we do not partition it. This mean that it will
-		 appear in every partition refernecing it.  */
+		 appear in every partition referencing it.  */
 	      || node->get_partitioning_class () != SYMBOL_PARTITION)
 	    {
 	      validize_symbol_for_target (node);
diff --git a/gcc/symtab.c b/gcc/symtab.c
index 3d3cc4f738c..ef2524ba642 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -1261,7 +1261,8 @@ symtab_node::make_decl_local (void)
       TREE_ADDRESSABLE (decl) = 1;
       TREE_STATIC (decl) = 1;
     }
-  else gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
+  else
+    gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
 
   DECL_COMDAT (decl) = 0;
   DECL_WEAK (decl) = 0;
@@ -1440,7 +1441,7 @@ symtab_node::fixup_same_cpp_alias_visibility (symtab_node *target)
 }
 
 /* Set section, do not recurse into aliases.
-   When one wants to change section of symbol and its aliases,
+   When one wants to change section of a symbol and its aliases,
    use set_section.  */
 
 void
-- 
2.13.1


[-- Attachment #16: 0001-Backport-r241380.patch --]
[-- Type: text/x-patch, Size: 2589 bytes --]

From cefd664dd178f0f04eeb4242d9d2c941846c2f96 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 20 Oct 2016 15:30:17 +0000
Subject: [PATCH 01/15] Backport r241380

gcc/ChangeLog:

2016-10-20  Martin Liska  <mliska@suse.cz>

	PR lto/78049
	* lto-streamer-in.c (fixup_call_stmt_edges_1): Replace value
	comparison with STMT_UID_NOT_IN_RANGE.
	(fixup_call_stmt_edges): Do not fixup edges of a thunk in
	LTRANS.
---
 gcc/lto-streamer-in.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c
index dd48777effa..9d110dd330e 100644
--- a/gcc/lto-streamer-in.c
+++ b/gcc/lto-streamer-in.c
@@ -898,13 +898,16 @@ static void
 fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple **stmts,
 			 struct function *fn)
 {
+#define STMT_UID_NOT_IN_RANGE(uid) \
+  (gimple_stmt_max_uid (fn) < uid || uid == 0)
+
   struct cgraph_edge *cedge;
   struct ipa_ref *ref = NULL;
   unsigned int i;
 
   for (cedge = node->callees; cedge; cedge = cedge->next_callee)
     {
-      if (gimple_stmt_max_uid (fn) < cedge->lto_stmt_uid)
+      if (STMT_UID_NOT_IN_RANGE (cedge->lto_stmt_uid))
         fatal_error (input_location,
 		     "Cgraph edge statement index out of range");
       cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
@@ -914,7 +917,7 @@ fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple **stmts,
     }
   for (cedge = node->indirect_calls; cedge; cedge = cedge->next_callee)
     {
-      if (gimple_stmt_max_uid (fn) < cedge->lto_stmt_uid)
+      if (STMT_UID_NOT_IN_RANGE (cedge->lto_stmt_uid))
         fatal_error (input_location,
 		     "Cgraph edge statement index out of range");
       cedge->call_stmt = as_a <gcall *> (stmts[cedge->lto_stmt_uid - 1]);
@@ -924,7 +927,7 @@ fixup_call_stmt_edges_1 (struct cgraph_node *node, gimple **stmts,
   for (i = 0; node->iterate_reference (i, ref); i++)
     if (ref->lto_stmt_uid)
       {
-	if (gimple_stmt_max_uid (fn) < ref->lto_stmt_uid)
+	if (STMT_UID_NOT_IN_RANGE (ref->lto_stmt_uid))
 	  fatal_error (input_location,
 		       "Reference statement index out of range");
 	ref->stmt = stmts[ref->lto_stmt_uid - 1];
@@ -946,7 +949,8 @@ fixup_call_stmt_edges (struct cgraph_node *orig, gimple **stmts)
     orig = orig->clone_of;
   fn = DECL_STRUCT_FUNCTION (orig->decl);
 
-  fixup_call_stmt_edges_1 (orig, stmts, fn);
+  if (!orig->thunk.thunk_p)
+    fixup_call_stmt_edges_1 (orig, stmts, fn);
   if (orig->clones)
     for (node = orig->clones; node != orig;)
       {
-- 
2.13.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Backports to 6.x
@ 2017-02-15  7:42 Jakub Jelinek
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2017-02-15  7:42 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 133 bytes --]

Hi!

I've bootstrapped/regtested following patches on x86_64-linux and i686-linux
on gcc-6-branch and committed them to 6.x.

	Jakub

[-- Attachment #2: r244539 --]
[-- Type: text/plain, Size: 2923 bytes --]

2017-02-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-01-17  Kito Cheng  <kito.cheng@gmail.com>
		    Kuan-Lin Chen  <kuanlinchentw@gmail.com>

	PR target/79079
	* internal-fn.c (expand_mul_overflow): Use convert_modes instead of
	gen_lowpart.

--- gcc/internal-fn.c	(revision 244538)
+++ gcc/internal-fn.c	(revision 244539)
@@ -1483,8 +1483,8 @@ expand_mul_overflow (location_t loc, tre
 	  res = expand_expr_real_2 (&ops, NULL_RTX, wmode, EXPAND_NORMAL);
 	  rtx hipart = expand_shift (RSHIFT_EXPR, wmode, res, prec,
 				     NULL_RTX, uns);
-	  hipart = gen_lowpart (mode, hipart);
-	  res = gen_lowpart (mode, res);
+	  hipart = convert_modes (mode, wmode, hipart, uns);
+	  res = convert_modes (mode, wmode, res, uns);
 	  if (uns)
 	    /* For the unsigned multiplication, there was overflow if
 	       HIPART is non-zero.  */
@@ -1517,16 +1517,16 @@ expand_mul_overflow (location_t loc, tre
 	  unsigned int hprec = GET_MODE_PRECISION (hmode);
 	  rtx hipart0 = expand_shift (RSHIFT_EXPR, mode, op0, hprec,
 				      NULL_RTX, uns);
-	  hipart0 = gen_lowpart (hmode, hipart0);
-	  rtx lopart0 = gen_lowpart (hmode, op0);
+	  hipart0 = convert_modes (hmode, mode, hipart0, uns);
+	  rtx lopart0 = convert_modes (hmode, mode, op0, uns);
 	  rtx signbit0 = const0_rtx;
 	  if (!uns)
 	    signbit0 = expand_shift (RSHIFT_EXPR, hmode, lopart0, hprec - 1,
 				     NULL_RTX, 0);
 	  rtx hipart1 = expand_shift (RSHIFT_EXPR, mode, op1, hprec,
 				      NULL_RTX, uns);
-	  hipart1 = gen_lowpart (hmode, hipart1);
-	  rtx lopart1 = gen_lowpart (hmode, op1);
+	  hipart1 = convert_modes (hmode, mode, hipart1, uns);
+	  rtx lopart1 = convert_modes (hmode, mode, op1, uns);
 	  rtx signbit1 = const0_rtx;
 	  if (!uns)
 	    signbit1 = expand_shift (RSHIFT_EXPR, hmode, lopart1, hprec - 1,
@@ -1717,11 +1717,12 @@ expand_mul_overflow (location_t loc, tre
 	     if (loxhi >> (bitsize / 2) == 0		 (if uns).  */
 	  rtx hipartloxhi = expand_shift (RSHIFT_EXPR, mode, loxhi, hprec,
 					  NULL_RTX, 0);
-	  hipartloxhi = gen_lowpart (hmode, hipartloxhi);
+	  hipartloxhi = convert_modes (hmode, mode, hipartloxhi, 0);
 	  rtx signbitloxhi = const0_rtx;
 	  if (!uns)
 	    signbitloxhi = expand_shift (RSHIFT_EXPR, hmode,
-					 gen_lowpart (hmode, loxhi),
+					 convert_modes (hmode, mode,
+							loxhi, 0),
 					 hprec - 1, NULL_RTX, 0);
 
 	  do_compare_rtx_and_jump (signbitloxhi, hipartloxhi, NE, true, hmode,
@@ -1731,7 +1732,8 @@ expand_mul_overflow (location_t loc, tre
 	  /* res = (loxhi << (bitsize / 2)) | (hmode) lo0xlo1;  */
 	  rtx loxhishifted = expand_shift (LSHIFT_EXPR, mode, loxhi, hprec,
 					   NULL_RTX, 1);
-	  tem = convert_modes (mode, hmode, gen_lowpart (hmode, lo0xlo1), 1);
+	  tem = convert_modes (mode, hmode,
+			       convert_modes (hmode, mode, lo0xlo1, 1), 1);
 
 	  tem = expand_simple_binop (mode, IOR, loxhishifted, tem, res,
 				     1, OPTAB_DIRECT);

[-- Attachment #3: r245053 --]
[-- Type: text/plain, Size: 2347 bytes --]

2017-02-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-01-31  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/79267
	* value-prof.c (gimple_ic): Only drop lhs for noreturn calls
	if should_remove_lhs_p is true.

	* g++.dg/opt/pr79267.C: New test.

--- gcc/value-prof.c	(revision 245052)
+++ gcc/value-prof.c	(revision 245053)
@@ -1376,7 +1376,13 @@ gimple_ic (gcall *icall_stmt, struct cgr
   gimple_call_set_fndecl (dcall_stmt, direct_call->decl);
   dflags = flags_from_decl_or_type (direct_call->decl);
   if ((dflags & ECF_NORETURN) != 0)
-    gimple_call_set_lhs (dcall_stmt, NULL_TREE);
+    {
+      tree lhs = gimple_call_lhs (dcall_stmt);
+      if (lhs
+          && TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (lhs))) == INTEGER_CST
+          && !TREE_ADDRESSABLE (TREE_TYPE (lhs)))
+	gimple_call_set_lhs (dcall_stmt, NULL_TREE);
+    }
   gsi_insert_before (&gsi, dcall_stmt, GSI_SAME_STMT);
 
   /* Fix CFG. */
--- gcc/testsuite/g++.dg/opt/pr79267.C	(nonexistent)
+++ gcc/testsuite/g++.dg/opt/pr79267.C	(revision 245053)
@@ -0,0 +1,69 @@
+// PR tree-optimization/79267
+// { dg-do compile }
+// { dg-options "-O3" }
+
+struct A { A (int); };
+struct B
+{
+  virtual void av () = 0;
+  void aw ();
+  void h () { av (); aw (); }
+};
+template <class T> struct G : B
+{
+  T ba;
+  G (int, T) : ba (0) {}
+  void av () { ba (0); }
+};
+struct I
+{
+  B *bc;
+  template <class j, class T> I (j, T) try { G<T> (0, 0); } catch (...) {}
+  ~I () { bc->h (); }
+};
+template <class M> struct C { typedef M *i; };
+template <class M> struct J
+{
+  J ();
+  template <class O, class T> J (O, T p2) : be (0, p2) {}
+  typename C<M>::i operator-> ();
+  I be;
+};
+struct H : A { H () : A (0) {} };
+struct D { J<int> d; void q (); };
+template <typename = int> class bs;
+int z;
+
+void
+foo (int p1, int *, int)
+{
+  if (p1 == 0)
+    throw H ();
+}
+
+D bar ();
+template <typename T> struct L
+{
+  struct K { K (int); void operator() (int *) { bar ().q (); } };
+  static J<T> bp () { bq (0); }
+  template <typename br> static void bq (br) { J<T> (0, K (0)); }
+};
+struct F
+{
+  virtual J<int> x (int) { foo (0, 0, 0); J<bs<> > (L<bs<> >::bp ()); }
+};
+
+void
+baz ()
+{
+  if (z)
+    {
+      J<F> d, e;
+      d->x (0);
+      e->x (0);
+    }
+  J<F> v, i, j;
+  v->x (0);
+  i->x (0);
+  j->x (0);
+}

[-- Attachment #4: r245120 --]
[-- Type: text/plain, Size: 1922 bytes --]

2017-02-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-02-02  Jakub Jelinek  <jakub@redhat.com>

	PR target/79197
	* config/rs6000/rs6000.md (*fixuns_trunc<mode>di2_fctiduz): Rename to ...
	(fixuns_trunc<mode>di2): ... this, remove previous expander.  Put all
	conditions on a single line.

	* gcc.target/powerpc/pr79197.c: New test.
	* gcc.c-torture/compile/pr79197.c: New test.

--- gcc/config/rs6000/rs6000.md	(revision 245119)
+++ gcc/config/rs6000/rs6000.md	(revision 245120)
@@ -5429,17 +5429,10 @@ (define_insn_and_split "fixuns_trunc<mod
   [(set_attr "length" "12")
    (set_attr "type" "fp")])
 
-(define_expand "fixuns_trunc<mode>di2"
-  [(set (match_operand:DI 0 "register_operand" "")
-	(unsigned_fix:DI (match_operand:SFDF 1 "register_operand" "")))]
-  "TARGET_HARD_FLOAT && (TARGET_FCTIDUZ || VECTOR_UNIT_VSX_P (<MODE>mode))"
-  "")
-
-(define_insn "*fixuns_trunc<mode>di2_fctiduz"
+(define_insn "fixuns_trunc<mode>di2"
   [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wi")
 	(unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "<Ff>,<Fa>")))]
-  "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS
-    && TARGET_FCTIDUZ"
+  "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FPRS && TARGET_FCTIDUZ"
   "@
    fctiduz %0,%1
    xscvdpuxds %x0,%x1"
--- gcc/testsuite/gcc.target/powerpc/pr79197.c	(nonexistent)
+++ gcc/testsuite/gcc.target/powerpc/pr79197.c	(revision 245120)
@@ -0,0 +1,11 @@
+/* PR target/79197 */
+/* { dg-do compile } */
+/* { dg-options "-O0 -mno-popcntd" } */
+
+unsigned a;
+
+void
+foo (void)
+{
+  a = *(double *) (__UINTPTR_TYPE__) 0x400000;
+}
--- gcc/testsuite/gcc.c-torture/compile/pr79197.c	(nonexistent)
+++ gcc/testsuite/gcc.c-torture/compile/pr79197.c	(revision 245120)
@@ -0,0 +1,10 @@
+/* PR target/79197 */
+
+unsigned long b;
+
+unsigned long
+foo (float *a, float *x)
+{
+  __builtin_memcpy (a, x, sizeof (float));
+  return *a;
+}

[-- Attachment #5: r245183 --]
[-- Type: text/plain, Size: 3185 bytes --]

2017-02-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-02-04  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/79338
	* tree-parloops.c (gather_scalar_reductions): Don't call
	vect_analyze_loop_form for loop->inner before destroying loop's
	loop_vinfo.

--- gcc/tree-parloops.c	(revision 245182)
+++ gcc/tree-parloops.c	(revision 245183)
@@ -2513,8 +2513,8 @@ gather_scalar_reductions (loop_p loop, r
 {
   gphi_iterator gsi;
   loop_vec_info simple_loop_info;
-  loop_vec_info simple_inner_loop_info = NULL;
-  bool allow_double_reduc = true;
+  auto_vec<gphi *, 4> double_reduc_phis;
+  auto_vec<gimple *, 4> double_reduc_stmts;
 
   if (!stmt_vec_info_vec.exists ())
     init_stmt_vec_info_vec ();
@@ -2544,43 +2544,55 @@ gather_scalar_reductions (loop_p loop, r
 
       if (double_reduc)
 	{
-	  if (!allow_double_reduc
-	      || loop->inner->inner != NULL)
+	  if (loop->inner->inner != NULL)
 	    continue;
 
-	  if (!simple_inner_loop_info)
-	    {
-	      simple_inner_loop_info = vect_analyze_loop_form (loop->inner);
-	      if (!simple_inner_loop_info)
-		{
-		  allow_double_reduc = false;
-		  continue;
-		}
-	    }
-
-	  use_operand_p use_p;
-	  gimple *inner_stmt;
-	  bool single_use_p = single_imm_use (res, &use_p, &inner_stmt);
-	  gcc_assert (single_use_p);
-	  if (gimple_code (inner_stmt) != GIMPLE_PHI)
-	    continue;
-	  gphi *inner_phi = as_a <gphi *> (inner_stmt);
-	  if (simple_iv (loop->inner, loop->inner, PHI_RESULT (inner_phi),
-			 &iv, true))
-	    continue;
-
-	  gimple *inner_reduc_stmt
-	    = vect_force_simple_reduction (simple_inner_loop_info, inner_phi,
-					   true, &double_reduc, true);
-	  gcc_assert (!double_reduc);
-	  if (inner_reduc_stmt == NULL)
-	    continue;
+	  double_reduc_phis.safe_push (phi);
+	  double_reduc_stmts.safe_push (reduc_stmt);
+	  continue;
 	}
 
       build_new_reduction (reduction_list, reduc_stmt, phi);
     }
   destroy_loop_vec_info (simple_loop_info, true);
-  destroy_loop_vec_info (simple_inner_loop_info, true);
+
+  if (!double_reduc_phis.is_empty ())
+    {
+      simple_loop_info = vect_analyze_loop_form (loop->inner);
+      if (simple_loop_info)
+	{
+	  gphi *phi;
+	  unsigned int i;
+
+	  FOR_EACH_VEC_ELT (double_reduc_phis, i, phi)
+	    {
+	      affine_iv iv;
+	      tree res = PHI_RESULT (phi);
+	      bool double_reduc;
+
+	      use_operand_p use_p;
+	      gimple *inner_stmt;
+	      bool single_use_p = single_imm_use (res, &use_p, &inner_stmt);
+	      gcc_assert (single_use_p);
+	      if (gimple_code (inner_stmt) != GIMPLE_PHI)
+		continue;
+	      gphi *inner_phi = as_a <gphi *> (inner_stmt);
+	      if (simple_iv (loop->inner, loop->inner, PHI_RESULT (inner_phi),
+			     &iv, true))
+		continue;
+
+	      gimple *inner_reduc_stmt
+		= vect_force_simple_reduction (simple_loop_info, inner_phi,
+					       true, &double_reduc, true);
+	      gcc_assert (!double_reduc);
+	      if (inner_reduc_stmt == NULL)
+		continue;
+
+	      build_new_reduction (reduction_list, double_reduc_stmts[i], phi);
+	    }
+	  destroy_loop_vec_info (simple_loop_info, true);
+	}
+    }
 
  gather_done:
   /* Release the claim on gimple_uid.  */

[-- Attachment #6: r245219 --]
[-- Type: text/plain, Size: 1719 bytes --]

2017-02-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-02-06  Jakub Jelinek  <jakub@redhat.com>

	PR c++/79377
	* tree.c (build_min_non_dep_op_overload): For POST{INC,DEC}REMENT_EXPR
	allow one fewer than expected arguments if flag_permissive.

	* g++.dg/lookup/pr79377.C: New test.

--- gcc/cp/tree.c	(revision 245218)
+++ gcc/cp/tree.c	(revision 245219)
@@ -2938,8 +2938,10 @@ build_min_non_dep_op_overload (enum tree
   nargs = call_expr_nargs (non_dep);
 
   expected_nargs = cp_tree_code_length (op);
-  if (op == POSTINCREMENT_EXPR
-      || op == POSTDECREMENT_EXPR)
+  if ((op == POSTINCREMENT_EXPR
+       || op == POSTDECREMENT_EXPR)
+      /* With -fpermissive non_dep could be operator++().  */
+      && (!flag_permissive || nargs != expected_nargs))
     expected_nargs += 1;
   gcc_assert (nargs == expected_nargs);
 
--- gcc/testsuite/g++.dg/lookup/pr79377.C	(nonexistent)
+++ gcc/testsuite/g++.dg/lookup/pr79377.C	(revision 245219)
@@ -0,0 +1,36 @@
+// PR c++/79377
+// { dg-do run }
+// { dg-options "-fpermissive" }
+
+struct A
+{
+  A () : a (0) {}
+  A& operator++ () { ++a; ++c; return *this; }
+  int a;
+  static int c;
+};
+
+int A::c = 0;
+
+template <typename>
+void
+foo (A& a)
+{
+  a++;		// { dg-warning "trying prefix operator instead" }
+  if (A::c != 3 || a.a != 3) __builtin_abort ();
+  ++a;
+  if (A::c != 4 || a.a != 4) __builtin_abort ();
+}
+
+int
+main ()
+{
+  A a;
+  if (A::c != 0 || a.a != 0) __builtin_abort ();
+  ++a;
+  if (A::c != 1 || a.a != 1) __builtin_abort ();
+  a++;		// { dg-warning "trying prefix operator instead" }
+  if (A::c != 2 || a.a != 2) __builtin_abort ();
+  foo<int> (a);
+  if (A::c != 4 || a.a != 4) __builtin_abort ();
+}

[-- Attachment #7: r245256 --]
[-- Type: text/plain, Size: 1118 bytes --]

2017-02-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-02-07  Jakub Jelinek  <jakub@redhat.com>
		    Richard Biener  <rguenther@suse.de>

	PR middle-end/79399
	* ira-int.h (struct target_ira_int): Change x_max_struct_costs_size
	type from int to size_t.
	* ira-costs.c (struct_costs_size): Change type from int to size_t.

--- gcc/ira-int.h	(revision 245255)
+++ gcc/ira-int.h	(revision 245256)
@@ -782,7 +782,7 @@ struct target_ira_int {
 
   /* Initialized once.  It is a maximal possible size of the allocated
      struct costs.  */
-  int x_max_struct_costs_size;
+  size_t x_max_struct_costs_size;
 
   /* Allocated and initialized once, and used to initialize cost values
      for each insn.  */
--- gcc/ira-costs.c	(revision 245255)
+++ gcc/ira-costs.c	(revision 245256)
@@ -74,7 +74,7 @@ static struct costs *costs;
 static struct costs *total_allocno_costs;
 
 /* It is the current size of struct costs.  */
-static int struct_costs_size;
+static size_t struct_costs_size;
 
 /* Return pointer to structure containing costs of allocno or pseudo
    with given NUM in array ARR.  */

[-- Attachment #8: r245302 --]
[-- Type: text/plain, Size: 3122 bytes --]

2017-02-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-02-09  Jakub Jelinek  <jakub@redhat.com>

	PR c/79431
	* gimplify.c (gimplify_adjust_omp_clauses): Ignore
	"omp declare target link" attribute unless is_global_var.
	* omp-low.c (find_link_var_op): Likewise.

	* c-parser.c (c_parser_omp_declare_target): Don't invoke
	symtab_node::get on automatic variables.

	* parser.c (cp_parser_oacc_declare): Formatting fix.
	(cp_parser_omp_declare_target): Don't invoke symtab_node::get on
	automatic variables.

	* c-c++-common/gomp/pr79431.c: New test.

--- gcc/gimplify.c	(revision 245301)
+++ gcc/gimplify.c	(revision 245302)
@@ -8938,8 +8938,9 @@ gimplify_adjust_omp_clauses (gimple_seq
 	  if ((ctx->region_type & ORT_TARGET) != 0
 	      && !(n->value & GOVD_SEEN)
 	      && GOMP_MAP_ALWAYS_P (OMP_CLAUSE_MAP_KIND (c)) == 0
-	      && !lookup_attribute ("omp declare target link",
-				    DECL_ATTRIBUTES (decl)))
+	      && (!is_global_var (decl)
+		  || !lookup_attribute ("omp declare target link",
+					DECL_ATTRIBUTES (decl))))
 	    {
 	      remove = true;
 	      /* For struct element mapping, if struct is never referenced
--- gcc/omp-low.c	(revision 245301)
+++ gcc/omp-low.c	(revision 245302)
@@ -19890,7 +19890,9 @@ find_link_var_op (tree *tp, int *walk_su
 {
   tree t = *tp;
 
-  if (TREE_CODE (t) == VAR_DECL && DECL_HAS_VALUE_EXPR_P (t)
+  if (TREE_CODE (t) == VAR_DECL
+      && DECL_HAS_VALUE_EXPR_P (t)
+      && is_global_var (t)
       && lookup_attribute ("omp declare target link", DECL_ATTRIBUTES (t)))
     {
       *walk_subtrees = 0;
--- gcc/c/c-parser.c	(revision 245301)
+++ gcc/c/c-parser.c	(revision 245302)
@@ -16849,8 +16849,11 @@ c_parser_omp_declare_target (c_parser *p
 	}
       if (!at1)
 	{
-	  symtab_node *node = symtab_node::get (t);
 	  DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
+	  if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t))
+	    continue;
+
+	  symtab_node *node = symtab_node::get (t);
 	  if (node != NULL)
 	    {
 	      node->offloadable = 1;
--- gcc/cp/parser.c	(revision 245301)
+++ gcc/cp/parser.c	(revision 245302)
@@ -36230,7 +36230,7 @@ cp_parser_oacc_declare (cp_parser *parse
 	    id = get_identifier ("omp declare target");
 
 	  DECL_ATTRIBUTES (decl)
-			   = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl));
+	    = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl));
 	  if (global_bindings_p ())
 	    {
 	      symtab_node *node = symtab_node::get (decl);
@@ -36770,8 +36770,11 @@ cp_parser_omp_declare_target (cp_parser
 	}
       if (!at1)
 	{
-	  symtab_node *node = symtab_node::get (t);
 	  DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t));
+	  if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t))
+	    continue;
+
+	  symtab_node *node = symtab_node::get (t);
 	  if (node != NULL)
 	    {
 	      node->offloadable = 1;
--- gcc/testsuite/c-c++-common/gomp/pr79431.c	(nonexistent)
+++ gcc/testsuite/c-c++-common/gomp/pr79431.c	(revision 245302)
@@ -0,0 +1,8 @@
+/* PR c/79431 */
+
+void
+foo (void)
+{
+  int a;
+  #pragma omp declare target (a)
+}

[-- Attachment #9: r245303 --]
[-- Type: text/plain, Size: 2630 bytes --]

2017-02-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-02-09  Jakub Jelinek  <jakub@redhat.com>

	PR c++/79429
	* parser.c (cp_parser_omp_ordered): Don't check for non-pragma_stmt
	non-pragma_compound context here.
	(cp_parser_omp_target): Likewise.
	(cp_parser_pragma): Don't call push_omp_privatization_clauses and
	parsing for ordered and target omp pragmas in non-pragma_stmt
	non-pragma_compound contexts.

	* c-c++-common/gomp/pr79429.c: New test.
	* g++.dg/gomp/pr79429.C: New test.

--- gcc/cp/parser.c	(revision 245302)
+++ gcc/cp/parser.c	(revision 245303)
@@ -34934,13 +34934,6 @@ cp_parser_omp_ordered (cp_parser *parser
 {
   location_t loc = pragma_tok->location;
 
-  if (context != pragma_stmt && context != pragma_compound)
-    {
-      cp_parser_error (parser, "expected declaration specifiers");
-      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return false;
-    }
-
   if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
     {
       tree id = cp_lexer_peek_token (parser->lexer)->u.value;
@@ -35846,13 +35839,6 @@ cp_parser_omp_target (cp_parser *parser,
 {
   tree *pc = NULL, stmt;
 
-  if (context != pragma_stmt && context != pragma_compound)
-    {
-      cp_parser_error (parser, "expected declaration specifiers");
-      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
-      return false;
-    }
-
   if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
     {
       tree id = cp_lexer_peek_token (parser->lexer)->u.value;
@@ -38283,12 +38269,16 @@ cp_parser_pragma (cp_parser *parser, enu
       return true;
 
     case PRAGMA_OMP_ORDERED:
+      if (context != pragma_stmt && context != pragma_compound)
+	goto bad_stmt;
       stmt = push_omp_privatization_clauses (false);
       ret = cp_parser_omp_ordered (parser, pragma_tok, context, if_p);
       pop_omp_privatization_clauses (stmt);
       return ret;
 
     case PRAGMA_OMP_TARGET:
+      if (context != pragma_stmt && context != pragma_compound)
+	goto bad_stmt;
       stmt = push_omp_privatization_clauses (false);
       ret = cp_parser_omp_target (parser, pragma_tok, context, if_p);
       pop_omp_privatization_clauses (stmt);
--- gcc/testsuite/g++.dg/gomp/pr79429.C	(nonexistent)
+++ gcc/testsuite/g++.dg/gomp/pr79429.C	(revision 245303)
@@ -0,0 +1,3 @@
+// PR c++/79429
+
+#pragma omp ordered // { dg-error "expected declaration specifiers" }
--- gcc/testsuite/c-c++-common/gomp/pr79429.c	(nonexistent)
+++ gcc/testsuite/c-c++-common/gomp/pr79429.c	(revision 245303)
@@ -0,0 +1,3 @@
+/* PR c++/79429 */
+
+#pragma omp target /* { dg-error "expected declaration specifiers" } */

[-- Attachment #10: r245324 --]
[-- Type: text/plain, Size: 2128 bytes --]

2017-02-15  Jakub Jelinek  <jakub@redhat.com>

	Backported from mainline
	2017-02-10  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/79411
	* tree-ssa-reassoc.c (is_reassociable_op): Return false if
	stmt operands are SSA_NAMEs used in abnormal phis.
	(can_reassociate_p): Return false if op is SSA_NAME used in abnormal
	phis.

	* gcc.c-torture/compile/pr79411.c: New test.

--- gcc/tree-ssa-reassoc.c	(revision 245323)
+++ gcc/tree-ssa-reassoc.c	(revision 245324)
@@ -605,7 +605,18 @@ is_reassociable_op (gimple *stmt, enum t
   if (is_gimple_assign (stmt)
       && gimple_assign_rhs_code (stmt) == code
       && has_single_use (gimple_assign_lhs (stmt)))
-    return true;
+    {
+      tree rhs1 = gimple_assign_rhs1 (stmt);
+      tree rhs2 = gimple_assign_rhs1 (stmt);
+      if (TREE_CODE (rhs1) == SSA_NAME
+	  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))
+	return false;
+      if (rhs2
+	  && TREE_CODE (rhs2) == SSA_NAME
+	  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2))
+	return false;
+      return true;
+    }
 
   return false;
 }
@@ -4989,6 +5000,8 @@ static bool
 can_reassociate_p (tree op)
 {
   tree type = TREE_TYPE (op);
+  if (TREE_CODE (op) == SSA_NAME && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (op))
+    return false;
   if ((ANY_INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type))
       || NON_SAT_FIXED_POINT_TYPE_P (type)
       || (flag_associative_math && FLOAT_TYPE_P (type)))
--- gcc/testsuite/gcc.c-torture/compile/pr79411.c	(nonexistent)
+++ gcc/testsuite/gcc.c-torture/compile/pr79411.c	(revision 245324)
@@ -0,0 +1,22 @@
+/* PR tree-optimization/79411 */
+
+typedef struct __jmp_buf_tag { char buf[1024]; } jmp_buf[1];
+extern int setjmp (jmp_buf);
+extern int bar (unsigned int *);
+extern jmp_buf *baz (void);
+struct C { int c1; unsigned int c2, c3, c4; };
+
+void
+foo (struct C *x, const int *y, unsigned int *z, unsigned int e, unsigned int g)
+{
+  unsigned int d = 0;
+  unsigned long f;
+  setjmp (*baz ());
+  f = 1 + d;
+  if ((x->c1 || x->c2) && g && (!e || d >= 8))
+    d = 16;
+  else
+    d = 8;
+  if ((!x->c3 && !x->c4 || *y == 0) && !e && bar (z))
+    *z = 1 + f;
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Backports to 6.x
@ 2017-01-17 20:48 Jakub Jelinek
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2017-01-17 20:48 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 133 bytes --]

Hi!

I've backported a couple of patches to gcc-6-branch after
bootstrapping/regtesting them on x86_64-linux and i686-linux.

	Jakub

[-- Attachment #2: r243860 --]
[-- Type: text/plain, Size: 3949 bytes --]

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

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

	PR fortran/78866
	* openmp.c (resolve_omp_clauses): Diagnose assumed size arrays in
	OpenMP map, to and from clauses.
	* trans-openmp.c: Include diagnostic-core.h, temporarily redefining
	GCC_DIAG_STYLE to __gcc_tdiag__.
	(gfc_omp_finish_clause): Diagnose implicitly mapped assumed size
	arrays.

	* gfortran.dg/gomp/map-1.f90: Add expected error.
	* gfortran.dg/gomp/pr78866-1.f90: New test.
	* gfortran.dg/gomp/pr78866-2.f90: New test.

--- gcc/fortran/openmp.c	(revision 243859)
+++ gcc/fortran/openmp.c	(revision 243860)
@@ -3530,6 +3530,11 @@ resolve_omp_clauses (gfc_code *code, gfc
 		    else
 		      resolve_oacc_data_clauses (n->sym, n->where, name);
 		  }
+		else if (list != OMP_CLAUSE_DEPEND
+			 && n->sym->as
+			 && n->sym->as->type == AS_ASSUMED_SIZE)
+		  gfc_error ("Assumed size array %qs in %s clause at %L",
+			     n->sym->name, name, &n->where);
 	      }
 
 	    if (list != OMP_LIST_DEPEND)
--- gcc/fortran/trans-openmp.c	(revision 243859)
+++ gcc/fortran/trans-openmp.c	(revision 243860)
@@ -37,6 +37,11 @@ along with GCC; see the file COPYING3.
 #include "arith.h"
 #include "omp-low.h"
 #include "gomp-constants.h"
+#undef GCC_DIAG_STYLE
+#define GCC_DIAG_STYLE __gcc_tdiag__
+#include "diagnostic-core.h"
+#undef GCC_DIAG_STYLE
+#define GCC_DIAG_STYLE __gcc_gfc__
 
 int ompws_flags;
 
@@ -1028,6 +1033,21 @@ gfc_omp_finish_clause (tree c, gimple_se
     return;
 
   tree decl = OMP_CLAUSE_DECL (c);
+
+  /* Assumed-size arrays can't be mapped implicitly, they have to be
+     mapped explicitly using array sections.  */
+  if (TREE_CODE (decl) == PARM_DECL
+      && GFC_ARRAY_TYPE_P (TREE_TYPE (decl))
+      && GFC_TYPE_ARRAY_AKIND (TREE_TYPE (decl)) == GFC_ARRAY_UNKNOWN
+      && GFC_TYPE_ARRAY_UBOUND (TREE_TYPE (decl),
+				GFC_TYPE_ARRAY_RANK (TREE_TYPE (decl)) - 1)
+	 == NULL)
+    {
+      error_at (OMP_CLAUSE_LOCATION (c),
+		"implicit mapping of assumed size array %qD", decl);
+      return;
+    }
+
   tree c2 = NULL_TREE, c3 = NULL_TREE, c4 = NULL_TREE;
   if (POINTER_TYPE_P (TREE_TYPE (decl)))
     {
--- gcc/testsuite/gfortran.dg/gomp/pr78866-1.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/gomp/pr78866-1.f90	(revision 243860)
@@ -0,0 +1,19 @@
+! PR fortran/78866
+! { dg-do compile }
+
+subroutine pr78866(x)
+  integer :: x(*)
+!$omp target map(x)			! { dg-error "Assumed size array" }
+  x(1) = 1
+!$omp end target
+!$omp target data map(tofrom: x)	! { dg-error "Assumed size array" }
+!$omp target update to(x)		! { dg-error "Assumed size array" }
+!$omp target update from(x)		! { dg-error "Assumed size array" }
+!$omp end target data
+!$omp target map(x(:23))		! { dg-bogus "Assumed size array" }
+  x(1) = 1
+!$omp end target
+!$omp target map(x(:))			! { dg-error "upper bound of assumed size array section" }
+  x(1) = 1				! { dg-error "not a proper array section" "" { target *-*-* } .-1 }
+!$omp end target
+end
--- gcc/testsuite/gfortran.dg/gomp/pr78866-2.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/gomp/pr78866-2.f90	(revision 243860)
@@ -0,0 +1,9 @@
+! PR fortran/78866
+! { dg-do compile }
+
+subroutine pr78866(x)
+  integer :: x(*)
+!$omp target		! { dg-error "implicit mapping of assumed size array" }
+  x(1) = 1
+!$omp end target
+end
--- gcc/testsuite/gfortran.dg/gomp/map-1.f90	(revision 243859)
+++ gcc/testsuite/gfortran.dg/gomp/map-1.f90	(revision 243860)
@@ -70,7 +70,7 @@ subroutine test(aas)
   ! { dg-error "Rightmost upper bound of assumed size array section not specified" "" { target *-*-* } 68 }
   ! { dg-error "'aas' in MAP clause at \\\(1\\\) is not a proper array section" "" { target *-*-* } 68 }
 
-  !$omp target map(aas) ! { dg-error "The upper bound in the last dimension must appear" "" { xfail *-*-* } }
+  !$omp target map(aas) ! { dg-error "Assumed size array" }
   !$omp end target
 
   !$omp target map(aas(5:7))

[-- Attachment #3: r244070 --]
[-- Type: text/plain, Size: 962 bytes --]

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

	Backported from mainline
	2017-01-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/71182
	* parser.c (cp_lexer_previous_token): Use vec_safe_address in the
	assertion, as lexer->buffer may be NULL.

	* g++.dg/cpp0x/pr71182.C: New test.

--- gcc/cp/parser.c	(revision 244069)
+++ gcc/cp/parser.c	(revision 244070)
@@ -766,7 +766,7 @@ cp_lexer_previous_token (cp_lexer *lexer
   /* Skip past purged tokens.  */
   while (tp->purged_p)
     {
-      gcc_assert (tp != lexer->buffer->address ());
+      gcc_assert (tp != vec_safe_address (lexer->buffer));
       tp--;
     }
 
--- gcc/testsuite/g++.dg/cpp0x/pr71182.C	(nonexistent)
+++ gcc/testsuite/g++.dg/cpp0x/pr71182.C	(revision 244070)
@@ -0,0 +1,12 @@
+// PR c++/71182
+// { dg-do compile { target c++11 } }
+
+class A {
+  template <typename> void As();
+};
+template <typename T> class B : A {
+  void f() {
+    A *g ;
+    g ? g->As<T>() : nullptr;
+  }
+};

[-- Attachment #4: r244074 --]
[-- Type: text/plain, Size: 1410 bytes --]

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

	Backported from mainline
	2017-01-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/78693
	* parser.c (cp_parser_simple_declaration): Only complain about
	inconsistent auto deduction if auto_result doesn't use auto.

	* g++.dg/cpp0x/pr78693.C: New test.

--- gcc/cp/parser.c	(revision 244073)
+++ gcc/cp/parser.c	(revision 244074)
@@ -12799,9 +12799,11 @@ cp_parser_simple_declaration (cp_parser*
 	    }
 	}
 
-      if (auto_result)
+      if (auto_result
+	  && (!processing_template_decl || !type_uses_auto (auto_result)))
 	{
-	  if (last_type && last_type != error_mark_node
+	  if (last_type
+	      && last_type != error_mark_node
 	      && !same_type_p (auto_result, last_type))
 	    {
 	      /* If the list of declarators contains more than one declarator,
--- gcc/testsuite/g++.dg/cpp0x/pr78693.C	(nonexistent)
+++ gcc/testsuite/g++.dg/cpp0x/pr78693.C	(revision 244074)
@@ -0,0 +1,31 @@
+// PR c++/78693
+// { dg-do compile { target c++11 } }
+
+template <class T>
+void
+foo (T t)
+{
+  auto i = t, j = 1;		// { dg-bogus "inconsistent deduction" }
+}
+
+template <class T>
+void
+bar (T t)
+{
+  auto i = 1, j = t, k = 2;	// { dg-bogus "inconsistent deduction" }
+}
+
+template <class T, class U>
+void
+foo (T t, U u)
+{
+  auto i = t, j = u;		// { dg-bogus "inconsistent deduction" }
+}
+
+void
+foo ()
+{
+  foo (0);
+  bar (0);
+  foo (1, 2);
+}

[-- Attachment #5: r244075 --]
[-- Type: text/plain, Size: 1111 bytes --]

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

	Backported from mainline
	2017-01-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/78949
	* typeck.c (cp_build_unary_op): Call mark_rvalue_use on arg if it has
	vector type.

	* c-c++-common/Wunused-var-16.c: New test.

--- gcc/cp/typeck.c	(revision 244074)
+++ gcc/cp/typeck.c	(revision 244075)
@@ -5848,6 +5848,8 @@ cp_build_unary_op (enum tree_code code,
 	errstring = _("wrong type argument to bit-complement");
       else if (!noconvert && CP_INTEGRAL_TYPE_P (TREE_TYPE (arg)))
 	arg = cp_perform_integral_promotions (arg, complain);
+      else if (!noconvert && VECTOR_TYPE_P (TREE_TYPE (arg)))
+	arg = mark_rvalue_use (arg);
       break;
 
     case ABS_EXPR:
--- gcc/testsuite/c-c++-common/Wunused-var-16.c	(nonexistent)
+++ gcc/testsuite/c-c++-common/Wunused-var-16.c	(revision 244075)
@@ -0,0 +1,15 @@
+/* PR c++/78949 */
+/* { dg-do compile } */
+/* { dg-options "-Wunused" } */
+
+typedef unsigned char V __attribute__((vector_size(16)));
+V v;
+
+void
+foo ()
+{
+  V y = {};
+  V x = {};	// { dg-bogus "set but not used" }
+  y &= ~x;
+  v = y;
+}

[-- Attachment #6: r244304 --]
[-- Type: text/plain, Size: 1251 bytes --]

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

	Backported from mainline
	2017-01-11  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/50199
	* lto-lang.c (lto_post_options): Force flag_merge_constants = 1
	if it was 0.

	* gcc.dg/lto/pr50199_0.c: New test.

--- gcc/lto/lto-lang.c	(revision 244303)
+++ gcc/lto/lto-lang.c	(revision 244304)
@@ -857,6 +857,12 @@ lto_post_options (const char **pfilename
      support.  */
   flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
 
+  /* When partitioning, we can tear appart STRING_CSTs uses from the same
+     TU into multiple partitions.  Without constant merging the constants
+     might not be equal at runtime.  See PR50199.  */
+  if (!flag_merge_constants)
+    flag_merge_constants = 1;
+
   /* Initialize the compiler back end.  */
   return false;
 }
--- gcc/testsuite/gcc.dg/lto/pr50199_0.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/lto/pr50199_0.c	(revision 244304)
@@ -0,0 +1,17 @@
+/* PR middle-end/50199 */
+/* { dg-lto-options {{-O2 -flto -fno-merge-constants --param=lto-min-partition=1}} } */
+
+__attribute__ ((noinline)) const char *
+foo (const char *x)
+{
+  return x;
+}
+
+int
+main ()
+{
+  const char *a = "ab";
+  if (a != foo (a))
+    __builtin_abort ();
+  return 0;
+}

[-- Attachment #7: r244329 --]
[-- Type: text/plain, Size: 1037 bytes --]

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

	Backported from mainline
	2017-01-11  Jakub Jelinek  <jakub@redhat.com>

	PR c++/78341
	* parser.c (cp_parser_std_attribute_spec): Remove over-eager
	assertion.  Formatting fix.

	* g++.dg/cpp0x/pr78341.C: New test.

--- gcc/cp/parser.c	(revision 244328)
+++ gcc/cp/parser.c	(revision 244329)
@@ -24925,11 +24925,7 @@ cp_parser_std_attribute_spec (cp_parser
 
       if (!cp_parser_parse_definitely (parser))
 	{
-	  gcc_assert (alignas_expr == error_mark_node
-		      || alignas_expr == NULL_TREE);
-
-	  alignas_expr =
-	    cp_parser_assignment_expression (parser);
+	  alignas_expr = cp_parser_assignment_expression (parser);
 	  if (alignas_expr == error_mark_node)
 	    cp_parser_skip_to_end_of_statement (parser);
 	  if (alignas_expr == NULL_TREE
--- gcc/testsuite/g++.dg/cpp0x/pr78341.C	(nonexistent)
+++ gcc/testsuite/g++.dg/cpp0x/pr78341.C	(revision 244329)
@@ -0,0 +1,4 @@
+// PR c++/78341
+// { dg-do compile { target c++11 } }
+
+alignas (alignas double // { dg-error "" }

[-- Attachment #8: r244545 --]
[-- Type: text/plain, Size: 4009 bytes --]

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

	PR debug/78839
	* dwarf2out.c (field_byte_offset): Restore the
	PCC_BITFIELD_TYPE_MATTERS behavior for INTEGER_CST DECL_FIELD_OFFSET
	and DECL_FIELD_BIT_OFFSET.  Use fold_build2 instead of build2 + fold.
	(analyze_variants_discr, gen_variant_part): Use fold_build2 instead
	of build2 + fold.

--- gcc/dwarf2out.c	(revision 244544)
+++ gcc/dwarf2out.c	(revision 244545)
@@ -17980,10 +17980,6 @@ static dw_loc_descr_ref
 field_byte_offset (const_tree decl, struct vlr_context *ctx,
 		   HOST_WIDE_INT *cst_offset)
 {
-  offset_int object_offset_in_bits;
-  offset_int object_offset_in_bytes;
-  offset_int bitpos_int;
-  bool is_byte_offset_cst, is_bit_offset_cst;
   tree tree_result;
   dw_loc_list_ref loc_result;
 
@@ -17994,20 +17990,21 @@ field_byte_offset (const_tree decl, stru
   else
     gcc_assert (TREE_CODE (decl) == FIELD_DECL);
 
-  is_bit_offset_cst = TREE_CODE (DECL_FIELD_BIT_OFFSET (decl)) != INTEGER_CST;
-  is_byte_offset_cst = TREE_CODE (DECL_FIELD_OFFSET (decl)) != INTEGER_CST;
-
   /* We cannot handle variable bit offsets at the moment, so abort if it's the
      case.  */
-  if (is_bit_offset_cst)
+  if (TREE_CODE (DECL_FIELD_BIT_OFFSET (decl)) != INTEGER_CST)
     return NULL;
 
 #ifdef PCC_BITFIELD_TYPE_MATTERS
   /* We used to handle only constant offsets in all cases.  Now, we handle
      properly dynamic byte offsets only when PCC bitfield type doesn't
      matter.  */
-  if (PCC_BITFIELD_TYPE_MATTERS && is_byte_offset_cst && is_bit_offset_cst)
+  if (PCC_BITFIELD_TYPE_MATTERS
+      && TREE_CODE (DECL_FIELD_OFFSET (decl)) == INTEGER_CST)
     {
+      offset_int object_offset_in_bits;
+      offset_int object_offset_in_bytes;
+      offset_int bitpos_int;
       tree type;
       tree field_size_tree;
       offset_int deepest_bitpos;
@@ -18102,13 +18099,23 @@ field_byte_offset (const_tree decl, stru
 	  object_offset_in_bits
 	    = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
 	}
+
+      object_offset_in_bytes
+	= wi::lrshift (object_offset_in_bits, LOG2_BITS_PER_UNIT);
+      if (ctx->variant_part_offset == NULL_TREE)
+	{
+	  *cst_offset = object_offset_in_bytes.to_shwi ();
+	  return NULL;
+	}
+      tree_result = wide_int_to_tree (sizetype, object_offset_in_bytes);
     }
+  else
 #endif /* PCC_BITFIELD_TYPE_MATTERS */
+    tree_result = byte_position (decl);
 
-  tree_result = byte_position (decl);
   if (ctx->variant_part_offset != NULL_TREE)
-    tree_result = fold (build2 (PLUS_EXPR, TREE_TYPE (tree_result),
-				ctx->variant_part_offset, tree_result));
+    tree_result = fold_build2 (PLUS_EXPR, TREE_TYPE (tree_result),
+			       ctx->variant_part_offset, tree_result);
 
   /* If the byte offset is a constant, it's simplier to handle a native
      constant rather than a DWARF expression.  */
@@ -23744,14 +23751,12 @@ analyze_variants_discr (tree variant_par
 
 	      if (!lower_cst_included)
 		lower_cst
-		  = fold (build2 (PLUS_EXPR, TREE_TYPE (lower_cst),
-				  lower_cst,
-				  build_int_cst (TREE_TYPE (lower_cst), 1)));
+		  = fold_build2 (PLUS_EXPR, TREE_TYPE (lower_cst), lower_cst,
+				 build_int_cst (TREE_TYPE (lower_cst), 1));
 	      if (!upper_cst_included)
 		upper_cst
-		  = fold (build2 (MINUS_EXPR, TREE_TYPE (upper_cst),
-				  upper_cst,
-				  build_int_cst (TREE_TYPE (upper_cst), 1)));
+		  = fold_build2 (MINUS_EXPR, TREE_TYPE (upper_cst), upper_cst,
+				 build_int_cst (TREE_TYPE (upper_cst), 1));
 
 	      if (!get_discr_value (lower_cst,
 				    &new_node->dw_discr_lower_bound)
@@ -23922,8 +23927,8 @@ gen_variant_part (tree variant_part_decl
 		 we recurse.  */
 
 	      vlr_sub_ctx.variant_part_offset
-	        = fold (build2 (PLUS_EXPR, TREE_TYPE (variant_part_offset),
-				variant_part_offset, byte_position (member)));
+		= fold_build2 (PLUS_EXPR, TREE_TYPE (variant_part_offset),
+			       variant_part_offset, byte_position (member));
 	      gen_variant_part (member, &vlr_sub_ctx, variant_die);
 	    }
 	  else

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-09-15 21:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-16  9:53 Backports to 6.x Jakub Jelinek
2017-01-17 20:48 Jakub Jelinek
2017-02-15  7:42 Jakub Jelinek
2017-06-21  8:14 Martin Liška
2017-06-21 11:17 ` Nathan Sidwell
2017-06-22 10:21   ` Richard Biener
2017-09-15 21:45 Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).