GCC 8 backports

2019-05-06 Thread Martin Liška
Hi.

I'm sending following backport that I've just tested.

Martin
>From ad56099403b078303477e3f501ef09b2e2b6e450 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 6 May 2019 07:35:59 +
Subject: [PATCH] Backport r270899

gcc/ChangeLog:

2019-05-06  Martin Liska  

	PR sanitizer/90312
	* config/i386/i386-options.c (ix86_option_override_internal): Error only
	when -mabi is selected to a non-default version.

gcc/testsuite/ChangeLog:

2019-05-06  Martin Liska  

	PR sanitizer/90312
	* gcc.dg/asan/pr87930.c: Run the test only on *linux or *gnu
	systems.
	* gcc.dg/tsan/pr88017.c: Likewise.
---
 gcc/config/i386/i386.c  | 17 +++--
 gcc/testsuite/gcc.dg/asan/pr87930.c |  2 +-
 gcc/testsuite/gcc.dg/tsan/pr88017.c |  2 +-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 8a1ffd3769f..5b946e1a32f 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -3705,12 +3705,17 @@ ix86_option_override_internal (bool main_args_p,
 error ("%<-mabi=ms%> not supported with X32 ABI");
   gcc_assert (opts->x_ix86_abi == SYSV_ABI || opts->x_ix86_abi == MS_ABI);
 
-  if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS) && opts->x_ix86_abi == MS_ABI)
-error ("%<-mabi=ms%> not supported with %<-fsanitize=address%>");
-  if ((opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS) && opts->x_ix86_abi == MS_ABI)
-error ("%<-mabi=ms%> not supported with %<-fsanitize=kernel-address%>");
-  if ((opts->x_flag_sanitize & SANITIZE_THREAD) && opts->x_ix86_abi == MS_ABI)
-error ("%<-mabi=ms%> not supported with %<-fsanitize=thread%>");
+  const char *abi_name = opts->x_ix86_abi == MS_ABI ? "ms" : "sysv";
+  if ((opts->x_flag_sanitize & SANITIZE_USER_ADDRESS)
+  && opts->x_ix86_abi != DEFAULT_ABI)
+error ("%<-mabi=%s%> not supported with %<-fsanitize=address%>", abi_name);
+  if ((opts->x_flag_sanitize & SANITIZE_KERNEL_ADDRESS)
+  && opts->x_ix86_abi != DEFAULT_ABI)
+error ("%<-mabi=%s%> not supported with %<-fsanitize=kernel-address%>",
+	   abi_name);
+  if ((opts->x_flag_sanitize & SANITIZE_THREAD)
+  && opts->x_ix86_abi != DEFAULT_ABI)
+error ("%<-mabi=%s%> not supported with %<-fsanitize=thread%>", abi_name);
 
   /* For targets using ms ABI enable ms-extensions, if not
  explicit turned off.  For non-ms ABI we turn off this
diff --git a/gcc/testsuite/gcc.dg/asan/pr87930.c b/gcc/testsuite/gcc.dg/asan/pr87930.c
index 4f8e6999fde..5a65d3fb030 100644
--- a/gcc/testsuite/gcc.dg/asan/pr87930.c
+++ b/gcc/testsuite/gcc.dg/asan/pr87930.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && lp64 } } } */
+/* { dg-do compile { target { { i?86-*-linux* i?86-*-gnu* x86_64-*-linux* } && lp64 } } } */
 /* { dg-options "-fsanitize=address -mabi=ms" } */
 
 int i;
diff --git a/gcc/testsuite/gcc.dg/tsan/pr88017.c b/gcc/testsuite/gcc.dg/tsan/pr88017.c
index 82693a67e87..10df2818b0d 100644
--- a/gcc/testsuite/gcc.dg/tsan/pr88017.c
+++ b/gcc/testsuite/gcc.dg/tsan/pr88017.c
@@ -1,4 +1,4 @@
-/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && lp64 } } } */
+/* { dg-do compile { target { { i?86-*-linux* i?86-*-gnu* x86_64-*-linux* } && lp64 } } } */
 /* { dg-options "-fsanitize=thread -mabi=ms" } */
 
 int i;
-- 
2.21.0



GCC 8 backports

2019-05-07 Thread Marek Polacek
I'm backporting these 5 patches to gcc-8.

Marek
2019-02-27  Marek Polacek  

PR c++/88857 - ICE with value-initialization of argument in template.
* call.c (convert_like_real): Don't call build_value_init in template.

--- gcc/cp/call.c
+++ gcc/cp/call.c
@@ -7005,7 +7005,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, 
int argnum,
/* If we're initializing from {}, it's value-initialization.  */
if (BRACE_ENCLOSED_INITIALIZER_P (expr)
&& CONSTRUCTOR_NELTS (expr) == 0
-   && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype))
+   && TYPE_HAS_DEFAULT_CONSTRUCTOR (totype)
+   && !processing_template_decl)
  {
bool direct = CONSTRUCTOR_IS_DIRECT_INIT (expr);
if (abstract_virtuals_error_sfinae (NULL_TREE, totype, complain))
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp0x/initlist-value4.C
@@ -0,0 +1,12 @@
+// PR c++/88857
+// { dg-do compile { target c++11 } }
+
+class S { int a; };
+void foo (const S &, int);
+
+template 
+void
+bar ()
+{
+  foo ({}); // { dg-error "too few arguments to function" }
+}
2019-03-25  Marek Polacek  
 
PR c++/89214 - ICE when initializing aggregates with bases.
* typeck2.c (digest_init_r): Warn about object slicing instead of
crashing.

--- gcc/cp/typeck2.c
+++ gcc/cp/typeck2.c
@@ -1209,8 +1209,29 @@ digest_init_r (tree type, tree init, int nested, int 
flags,
 {
   tree elt = CONSTRUCTOR_ELT (stripped_init, 0)->value;
   if (reference_related_p (type, TREE_TYPE (elt)))
-   /* We should have fixed this in reshape_init.  */
-   gcc_unreachable ();
+   {
+ /* In C++17, aggregates can have bases, thus participate in
+aggregate initialization.  In the following case:
+
+  struct B { int c; };
+  struct D : B { };
+  D d{{D{{42;
+
+   there's an extra set of braces, so the D temporary initializes
+   the first element of d, which is the B base subobject.  The base
+   of type B is copy-initialized from the D temporary, causing
+   object slicing.  */
+ tree field = next_initializable_field (TYPE_FIELDS (type));
+ if (field && DECL_FIELD_IS_BASE (field))
+   {
+ if (warning_at (loc, 0, "initializing a base class of type %qT "
+ "results in object slicing", TREE_TYPE (field)))
+   inform (loc, "remove %<{ }%> around initializer");
+   }
+ else
+   /* We should have fixed this in reshape_init.  */
+   gcc_unreachable ();
+   }
 }
 
   if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init)
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp1z/aggr-base8.C
@@ -0,0 +1,48 @@
+// PR c++/89214
+// { dg-do compile { target c++17 } }
+
+struct A
+{
+  A (int);
+};
+
+struct BB
+{
+  A a;
+};
+
+struct B : BB
+{
+};
+
+void
+foo ()
+{
+  B b1 = {42};
+  B b2 = {{42}};
+  B b3 = {{{42}}};
+
+  B b4 = B{42};
+  B b5 = B{{42}};
+  B b6 = B{{{42}}};
+
+  B b7 = {B{42}};
+  B b8 = {B{{42}}};
+  B b9 = {B{{{42;
+
+  B b10 = {{B{42}}}; // { dg-warning "initializing a base class of type .BB. 
results in object slicing" }
+  B b11 = {{B{{42; // { dg-warning "initializing a base class of type .BB. 
results in object slicing" }
+  B b12 = {{B{{{42}; // { dg-warning "initializing a base class of type 
.BB. results in object slicing" }
+
+  B bb1{42};
+  B bb2{{42}};
+  B bb3{{{42}}};
+
+  B bb7{B{42}};
+  B bb8{B{{42}}};
+  B bb9{B{{{42;
+
+  B bb10{{B{42}}}; // { dg-warning "initializing a base class of type .BB. 
results in object slicing" }
+  B bb11{{B{{42; // { dg-warning "initializing a base class of type .BB. 
results in object slicing" }
+  B bb12{{B{{{42}; // { dg-warning "initializing a base class of type .BB. 
results in object slicing" }
+}
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp1z/aggr-base9.C
@@ -0,0 +1,33 @@
+// PR c++/89214
+// { dg-do compile { target c++17 } }
+
+struct B {
+  int c;
+};
+
+struct D : B { };
+
+void
+foo ()
+{
+  D d1 = {42};
+  D d2 = {{42}};
+  
+  D d4 = D{42};
+  D d5 = D{{42}};
+ 
+  D d7 = {D{42}};
+  D d8 = {D{{42}}};
+
+  D d10 = {{D{42}}}; // { dg-warning "initializing a base class of type .B. 
results in object slicing" }
+  D d11 = {{D{{42; // { dg-warning "initializing a base class of type .B. 
results in object slicing" }
+
+  D dd1{42};
+  D dd2{{42}};
+  
+  D dd7{D{42}};
+  D dd8{D{{42}}};
+
+  D dd10{{D{42}}}; // { dg-warning "initializing a base class of type .B. 
results in object slicing" }
+  D dd11{{D{{42; // { dg-warning "initializing a base class of type .B. 
results in object slicing" }
+}
2019-02-27  Marek Polacek  

PR c++/89511 - ICE with using-declaration and unscoped enumerator.
* parser.c (cp_parser_using_declaration): For an unscoped enum
only use its context if it's not a function declaration.

--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -19412,7 +19412

GCC 8 backports

2018-05-23 Thread Martin Liška
Hi.

I'm going to backport following 2 revisions.
Patches can bootstrap on x86_64-linux-gnu and survive regression tests.

Martin
>From 3308817aa11be9d43cd564d249dae1c28bf41015 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Fri, 11 May 2018 07:37:35 +
Subject: Backport r260154

gcc/ChangeLog:

2018-05-11  Martin Liska  

PR sanitizer/85556
	* doc/extend.texi: Document LLVM style format for no_sanitize
	attribute.

gcc/c-family/ChangeLog:

2018-05-11  Martin Liska  

PR sanitizer/85556
	* c-attribs.c (handle_no_sanitize_attribute): Iterate all
	TREE_LIST values.

gcc/testsuite/ChangeLog:

2018-05-11  Martin Liska  

PR sanitizer/85556
	* c-c++-common/ubsan/attrib-6.c: New test.

---
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 9bddc1aad4f..d302b4f22c7 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -403,7 +403,7 @@ const struct attribute_spec c_common_attribute_table[] =
 			  0, 0, true, false, false, false,
 			  handle_no_address_safety_analysis_attribute,
 			  NULL },
-  { "no_sanitize",	  1, 1, true, false, false, false,
+  { "no_sanitize",	  1, -1, true, false, false, false,
 			  handle_no_sanitize_attribute, NULL },
   { "no_sanitize_address",0, 0, true, false, false, false,
 			  handle_no_sanitize_address_attribute, NULL },
@@ -683,22 +683,26 @@ static tree
 handle_no_sanitize_attribute (tree *node, tree name, tree args, int,
 			  bool *no_add_attrs)
 {
+  unsigned int flags = 0;
   *no_add_attrs = true;
-  tree id = TREE_VALUE (args);
   if (TREE_CODE (*node) != FUNCTION_DECL)
 {
   warning (OPT_Wattributes, "%qE attribute ignored", name);
   return NULL_TREE;
 }

-  if (TREE_CODE (id) != STRING_CST)
+  for (; args; args = TREE_CHAIN (args))
 {
-  error ("no_sanitize argument not a string");
-  return NULL_TREE;
-}
+  tree id = TREE_VALUE (args);
+  if (TREE_CODE (id) != STRING_CST)
+	{
+	  error ("no_sanitize argument not a string");
+	  return NULL_TREE;
+	}

-  char *string = ASTRDUP (TREE_STRING_POINTER (id));
-  unsigned int flags = parse_no_sanitize_attribute (string);
+  char *string = ASTRDUP (TREE_STRING_POINTER (id));
+  flags |= parse_no_sanitize_attribute (string);
+}

   add_no_sanitize_value (*node, flags);

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 9d085844cfd..a4664cad819 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2977,6 +2977,8 @@ mentioned in @var{sanitize_option}.  A list of values acceptable by
 @smallexample
 void __attribute__ ((no_sanitize ("alignment", "object-size")))
 f () @{ /* @r{Do something.} */; @}
+void __attribute__ ((no_sanitize ("alignment,object-size")))
+g () @{ /* @r{Do something.} */; @}
 @end smallexample

 @item no_sanitize_address
diff --git a/gcc/testsuite/c-c++-common/ubsan/attrib-6.c b/gcc/testsuite/c-c++-common/ubsan/attrib-6.c
new file mode 100644
index 000..2af70c8c2cf
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/attrib-6.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined" } */
+
+static void __attribute__((no_sanitize("foobar")))
+foo (void) { /* { dg-warning "attribute directive ignored" } */
+}
+
+static void __attribute__((no_sanitize("address,undefined")))
+foo2 (void) {
+}
+
+static void __attribute__((no_sanitize("address", "undefined")))
+foo3 (void) {
+}
+
+static void __attribute__((no_sanitize("address", "address", "")))
+foo4 (void) {
+}
+
+static void __attribute__((no_sanitize("address", "address", "address,address")))
+foo5 (void) {
+}
+
+static void __attribute__((no_sanitize("address", "address,kernel-address,thread,leak,undefined,vptr,shift,integer-divide-by-zero,unreachable,vla-bound,null,return,signed-integer-overflow,bounds,bounds-strict,alignment,object-size,float-divide-by-zero,float-cast-overflow,nonnull-attribute,returns-nonnull-attribute,bool,enum")))
+foo6 (void) {
+}
--
2.16.3
>From 8203f7efd03cc82717ab0416a151e96d3a7b8f4b Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 23 May 2018 07:40:43 +
Subject: Backport r260566

gcc/ChangeLog:

2018-05-23  Yury Gribov  

	PR tree-optimization/85822
	* tree-vrp.c (is_masked_range_test): Fix handling of negative
	constants.

gcc/testsuite/ChangeLog:

2018-05-23  Yury Gribov  

	PR tree-optimization/85822
	* c-c++-common/pr85822.c: New test.

---
diff --git a/gcc/testsuite/c-c++-common/pr85822.c b/gcc/testsuite/c-c++-common/pr85822.c
new file mode 100644
index 000..3b09188ab47
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr85822.c
@@ -0,0 +1,27 @@
+/* { dg-options "-O2" } */
+/* { dg-do run } */
+
+static const long long int TagTypeNumber = 0xll;
+
+long long int x;
+
+void foo(void)
+{
+  x = TagTypeNumber + 1;
+}
+
+int main(int argc, char **argv)
+{
+  if (argc > 0)
+foo ();
+
+  if ((x & TagTypeNumber) == TagTypeNumber)
+  {
+unsigned y = (unsigned)x;
+__builtin_printf ("v: %u\n", y);
+   

Re: GCC 8 backports

2018-08-16 Thread Martin Liška
Hi.

Another 2 patches that I tested.

Martin
>From 733fad0936b46794f9e1ba6742471bd9f351a4c9 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 2 Aug 2018 10:17:34 +
Subject: Backport r263248

gcc/ChangeLog:

2018-08-02  Martin Liska  

PR gcov-profile/86817
	* gcov.c (process_all_functions): New function.
	(main): Call it.
	(process_file): Move functions processing to
process_all_functions.

---
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 78a3e0e19e9..43dfc9a4b2c 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -543,6 +543,7 @@ static int process_args (int, char **);
 static void print_usage (int) ATTRIBUTE_NORETURN;
 static void print_version (void) ATTRIBUTE_NORETURN;
 static void process_file (const char *);
+static void process_all_functions (void);
 static void generate_results (const char *);
 static void create_file_names (const char *);
 static char *canonicalize_name (const char *);
@@ -798,6 +799,7 @@ main (int argc, char **argv)

   if (flag_intermediate_format || argno == argc - 1)
 	{
+	  process_all_functions ();
 	  generate_results (argv[argno]);
 	  release_structures ();
 	}
@@ -1145,11 +1147,14 @@ process_file (const char *file_name)
 {
   create_file_names (file_name);
   read_graph_file ();
-  if (functions.empty ())
-return;
-
   read_count_file ();
+}

+/* Process all functions in all files.  */
+
+static void
+process_all_functions (void)
+{
   hash_map fn_map;

   /* Identify group functions.  */
@@ -1226,7 +1231,6 @@ process_file (const char *file_name)
 	  if (fn->is_group)
 	fn->lines.resize (fn->end_line - fn->start_line + 1);

-
 	  solve_flow_graph (fn);
 	  if (fn->has_catch)
 	find_exception_blocks (fn);
--
2.18.0
>From 1a1934d31636a8bd72a6d93143dbe216ff6e6ad4 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 2 Aug 2018 09:32:58 +
Subject: Backport r263246

libsanitizer/ChangeLog:

2018-08-02  Martin Liska  

PR sanitizer/86022
	* sanitizer_common/sanitizer_linux_libcdep.cc (ThreadDescriptorSize):
Cherry-pick compiler-rt revision 338606.

---
diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
index d27a8435802..3b1a2174c46 100644
--- a/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -235,7 +235,7 @@ uptr ThreadDescriptorSize() {
 val = FIRST_32_SECOND_64(1168, 1776);
   else if (minor == 11 || (minor == 12 && patch == 1))
 val = FIRST_32_SECOND_64(1168, 2288);
-  else if (minor <= 13)
+  else if (minor <= 14)
 val = FIRST_32_SECOND_64(1168, 2304);
   else
 val = FIRST_32_SECOND_64(1216, 2304);
--
2.18.0


Re: GCC 8 backports

2019-05-24 Thread Martin Liška
Hi.

I'm sending one more patch that I've tested.

Martin
>From 3a0412967ede61515ce59230580558f5531e63f6 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 23 May 2019 10:12:01 +
Subject: [PATCH] Backport r271548

gcc/ChangeLog:

2019-05-23  Martin Liska  

	PR sanitizer/90570
	* gimplify.c (gimplify_target_expr): Skip TREE_STATIC target
	expression similarly to gimplify_decl_expr.

gcc/testsuite/ChangeLog:

2019-05-23  Martin Liska  

	PR sanitizer/90570
	* g++.dg/asan/pr90570.C: New test.
---
 gcc/gimplify.c  |  1 +
 gcc/testsuite/g++.dg/asan/pr90570.C | 18 ++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/asan/pr90570.C

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index bdb15a8fd14..2971293a720 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -6653,6 +6653,7 @@ gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
 	}
 	  if (asan_poisoned_variables
 	  && DECL_ALIGN (temp) <= MAX_SUPPORTED_STACK_ALIGNMENT
+	  && !TREE_STATIC (temp)
 	  && dbg_cnt (asan_use_after_scope)
 	  && !gimplify_omp_ctxp)
 	{
diff --git a/gcc/testsuite/g++.dg/asan/pr90570.C b/gcc/testsuite/g++.dg/asan/pr90570.C
new file mode 100644
index 000..c2366905516
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/pr90570.C
@@ -0,0 +1,18 @@
+/* PR sanitizer/90570 */
+/* { dg-do run } */
+
+#include 
+
+struct stru
+{
+  std::vector v{1,2,3,4};
+  int i{5};
+};
+
+int main()
+{
+  stru s1;
+  stru s2;
+
+  return 0;
+}
-- 
2.21.0



Re: GCC 8 backports

2019-02-14 Thread Martin Liška
On 11/20/18 11:58 AM, Martin Liška wrote:
> On 10/3/18 11:23 AM, Martin Liška wrote:
>> On 9/25/18 8:48 AM, Martin Liška wrote:
>>> Hi.
>>>
>>> One more tested patch.
>>>
>>> Martin
>>>
>>
>> One more tested patch.
>>
>> Martin
>>
> 
> Hi.
> 
> One another tested patch that I'm going to install.
> 
> Martin
> 

Hi.

Another 2 patches that I've just tested and will install.

Martin
>From 65c43b0a4fb210485ad01d5f55573bfc0f17441d Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 11 Feb 2019 08:13:03 +
Subject: [PATCH 1/2] Backport r268762

gcc/ChangeLog:

2019-02-11  Martin Liska  

	PR ipa/89009
	* ipa-cp.c (build_toporder_info): Remove usage of a param.
	* ipa-inline.c (inline_small_functions): Likewise.
	* ipa-pure-const.c (propagate_pure_const): Likewise.
	(propagate_nothrow): Likewise.
	* ipa-reference.c (propagate): Likewise.
	* ipa-utils.c (struct searchc_env): Remove unused field.
	(searchc): Always search across AVAIL_INTERPOSABLE.
	(ipa_reduced_postorder): Always allow AVAIL_INTERPOSABLE as
	the only called IPA pure const can properly not propagate
	across interposable boundary.
	* ipa-utils.h (ipa_reduced_postorder): Remove param.

gcc/testsuite/ChangeLog:

2019-02-11  Martin Liska  

	PR ipa/89009
	* g++.dg/ipa/pr89009.C: New test.
---
 gcc/ipa-cp.c   |  2 +-
 gcc/ipa-inline.c   |  2 +-
 gcc/ipa-pure-const.c   |  4 ++--
 gcc/ipa-reference.c|  2 +-
 gcc/ipa-utils.c|  9 +++--
 gcc/ipa-utils.h|  2 +-
 gcc/testsuite/g++.dg/ipa/pr89009.C | 12 
 7 files changed, 21 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/ipa/pr89009.C

diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index e868b9c2623..5bd4df0ecb7 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -820,7 +820,7 @@ build_toporder_info (struct ipa_topo_info *topo)
   topo->stack = XCNEWVEC (struct cgraph_node *, symtab->cgraph_count);
 
   gcc_checking_assert (topo->stack_top == 0);
-  topo->nnodes = ipa_reduced_postorder (topo->order, true, true, NULL);
+  topo->nnodes = ipa_reduced_postorder (topo->order, true, NULL);
 }
 
 /* Free information about strongly connected components and the arrays in
diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c
index 996b04cb81d..bde7ecfd0d5 100644
--- a/gcc/ipa-inline.c
+++ b/gcc/ipa-inline.c
@@ -1759,7 +1759,7 @@ inline_small_functions (void)
  metrics.  */
 
   max_count = profile_count::uninitialized ();
-  ipa_reduced_postorder (order, true, true, NULL);
+  ipa_reduced_postorder (order, true, NULL);
   free (order);
 
   FOR_EACH_DEFINED_FUNCTION (node)
diff --git a/gcc/ipa-pure-const.c b/gcc/ipa-pure-const.c
index a80b6845633..d36d1ba9b73 100644
--- a/gcc/ipa-pure-const.c
+++ b/gcc/ipa-pure-const.c
@@ -1443,7 +1443,7 @@ propagate_pure_const (void)
   bool remove_p = false;
   bool has_cdtor;
 
-  order_pos = ipa_reduced_postorder (order, true, false,
+  order_pos = ipa_reduced_postorder (order, true,
  ignore_edge_for_pure_const);
   if (dump_file)
 {
@@ -1773,7 +1773,7 @@ propagate_nothrow (void)
   int i;
   struct ipa_dfs_info * w_info;
 
-  order_pos = ipa_reduced_postorder (order, true, false,
+  order_pos = ipa_reduced_postorder (order, true,
  ignore_edge_for_nothrow);
   if (dump_file)
 {
diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c
index 6490c03f8d0..b9db61697d1 100644
--- a/gcc/ipa-reference.c
+++ b/gcc/ipa-reference.c
@@ -728,7 +728,7 @@ propagate (void)
  the global information.  All the nodes within a cycle will have
  the same info so we collapse cycles first.  Then we can do the
  propagation in one pass from the leaves to the roots.  */
-  order_pos = ipa_reduced_postorder (order, true, true, ignore_edge_p);
+  order_pos = ipa_reduced_postorder (order, true, ignore_edge_p);
   if (dump_file)
 ipa_print_order (dump_file, "reduced", order, order_pos);
 
diff --git a/gcc/ipa-utils.c b/gcc/ipa-utils.c
index a271bb822cb..106d3079391 100644
--- a/gcc/ipa-utils.c
+++ b/gcc/ipa-utils.c
@@ -63,7 +63,6 @@ struct searchc_env {
   int order_pos;
   splay_tree nodes_marked_new;
   bool reduce;
-  bool allow_overwritable;
   int count;
 };
 
@@ -105,7 +104,7 @@ searchc (struct searchc_env* env, struct cgraph_node *v,
 
   if (w->aux
 	  && (avail > AVAIL_INTERPOSABLE
-	  || (env->allow_overwritable && avail == AVAIL_INTERPOSABLE)))
+	  || avail == AVAIL_INTERPOSABLE))
 	{
 	  w_info = (struct ipa_dfs_info *) w->aux;
 	  if (w_info->new_node)
@@ -162,7 +161,7 @@ searchc (struct searchc_env* env, struct cgraph_node *v,
 
 int
 ipa_reduced_postorder (struct cgraph_node **order,
-		   bool reduce, bool allow_overwritable,
+		   bool reduce,
 		   bool (*ignore_edge) (struct cgraph_edge *))
 {
   struct cgraph_node *node;
@@ -175,15 +174,13 @@ ipa_reduced_postorder (struct cgraph_node **order,
   env.nodes_marked_new = splay_tree_new (splay_tree_compare_ints, 0, 0);
   env.count = 1;
   env.reduce 

Re: GCC 8 backports

2019-02-14 Thread Martin Liška
On 2/14/19 12:23 PM, Martin Liška wrote:
> On 11/20/18 11:58 AM, Martin Liška wrote:
>> On 10/3/18 11:23 AM, Martin Liška wrote:
>>> On 9/25/18 8:48 AM, Martin Liška wrote:
 Hi.

 One more tested patch.

 Martin

>>>
>>> One more tested patch.
>>>
>>> Martin
>>>
>>
>> Hi.
>>
>> One another tested patch that I'm going to install.
>>
>> Martin
>>
> 
> Hi.
> 
> Another 2 patches that I've just tested and will install.
> 
> Martin
> 

One more patch.

Martin
>From a434c00b2d9a540152ea149244fa8df97f64def4 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 14 Feb 2019 14:25:48 +0100
Subject: [PATCH] Backport r268873

gcc/ChangeLog:

2019-02-14  Martin Liska  

	PR rtl-optimization/89242
	* dce.c (delete_unmarked_insns): Call free_dominance_info we
	process a transformation.

gcc/testsuite/ChangeLog:

2019-02-14  Martin Liska  

	PR rtl-optimization/89242
	* g++.dg/pr89242.C: New test.
---
 gcc/dce.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/dce.c b/gcc/dce.c
index 2ef4dd7bd3b..ce2edc43efb 100644
--- a/gcc/dce.c
+++ b/gcc/dce.c
@@ -642,7 +642,10 @@ delete_unmarked_insns (void)
 
   /* Deleted a pure or const call.  */
   if (must_clean)
-delete_unreachable_blocks ();
+{
+  delete_unreachable_blocks ();
+  free_dominance_info (CDI_DOMINATORS);
+}
 }
 
 
-- 
2.20.1



Re: GCC 8 backports

2019-03-11 Thread Martin Liška
Hi.

I'm sending another patches that I've just tested.

Martin
>From 915af267eb22e5059737f4dbb6e9d48601bb0779 Mon Sep 17 00:00:00 2001
From: "ro@138bc75d-0d04-0410-961f-82ee72b054a4"
 
Date: Sun, 10 Mar 2019 16:43:48 +
Subject: [PATCH 4/4] Backport r269558

gcc/testsuite/ChangeLog:

2019-03-10  Rainer Orth  

	* gcc.target/i386/indirect-thunk-extern-7.c: Add -fjump-tables to
	dg-options.
---
 gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c
index b7339745116..95c5cc176ae 100644
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-extern-7.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk-extern -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk-extern -fno-pic -fjump-tables" } */
 
 void func0 (void);
 void func1 (void);
-- 
2.21.0

>From 5a433aca1d83cfc8a270b02d89be5b3ed75a503c Mon Sep 17 00:00:00 2001
From: marxin 
Date: Fri, 8 Mar 2019 12:55:40 +
Subject: [PATCH 3/4] Backport r269492

gcc/ChangeLog:

2019-03-08  Martin Liska  

	PR target/86952
	* config/i386/i386.c (ix86_option_override_internal): Disable
	jump tables when retpolines are used.

gcc/testsuite/ChangeLog:

2019-03-08  Martin Liska  

	PR target/86952
	* gcc.target/i386/indirect-thunk-7.c: Use jump tables to match
	scanned pattern.
	* gcc.target/i386/indirect-thunk-inline-7.c: Likewise.
---
 gcc/config/i386/i386.c  | 6 ++
 gcc/testsuite/gcc.target/i386/indirect-thunk-7.c| 2 +-
 gcc/testsuite/gcc.target/i386/indirect-thunk-inline-7.c | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index a88a29b51e6..f1de97f73df 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -4958,6 +4958,12 @@ ix86_option_override_internal (bool main_args_p,
 			   opts->x_param_values,
 			   opts_set->x_param_values);
 
+  /* PR86952: jump table usage with retpolines is slow.
+ The PR provides some numbers about the slowness.  */
+  if (ix86_indirect_branch != indirect_branch_keep
+  && !opts_set->x_flag_jump_tables)
+opts->x_flag_jump_tables = 0;
+
   return true;
 }
 
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-7.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-7.c
index 3c72036dbaf..53868f46558 100644
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-7.c
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-7.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk -fno-pic -fjump-tables" } */
 
 void func0 (void);
 void func1 (void);
diff --git a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-7.c b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-7.c
index ea009245a58..e6f064959a1 100644
--- a/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-7.c
+++ b/gcc/testsuite/gcc.target/i386/indirect-thunk-inline-7.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk-inline -fno-pic" } */
+/* { dg-options "-O2 -mno-indirect-branch-register -mfunction-return=keep -mindirect-branch=thunk-inline -fno-pic -fjump-tables" } */
 
 void func0 (void);
 void func1 (void);
-- 
2.21.0

>From 4a20f76e3887229751ebd8352cc3c77a4e7c2b10 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 18 Feb 2019 09:46:19 +
Subject: [PATCH 2/4] Backport r268981

libcpp/ChangeLog:

2019-02-18  Martin Liska  

	PR c++/89383
	* line-map.c (linemap_line_start): Use 1UL in order
	to not overflow.
---
 libcpp/line-map.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 42aecd6993f..72fe2c0dcec 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -758,7 +758,8 @@ linemap_line_start (struct line_maps *set, linenum_type to_line,
 	  || ( /* We can't reuse the map if the line offset is sufficiently
 		  large to cause overflow when computing location_t values.  */
 	  (to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
-	  >= (1U << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
+	  >= (((uint64_t) 1)
+		  << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
 	  || range_bits < map->m_range_bits)
 	map = linemap_check_ordinary
 	(const_cast 
-- 
2.21.0

>From fe9fa030d7ae1a4b4da4751b39bddc68395b1728 Mon Sep 17 00:00:00 2001
From: dmalcolm 
Date: Tue, 12 Feb 2019 01:09:31 +
Subject: [PATCH 1/4] Backport r268789

gcc/ChangeLog:

2019-02-11  David Malcolm  

	PR lto/88

Re: GCC 8 backports

2019-03-15 Thread Martin Liška
Hi.

One more documentation patch.

Martin
>From 12a1a2bf98075d79d60189d3d3b4d6c3de79a877 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 14 Mar 2019 14:19:33 +
Subject: Backport r269684

gcc/ChangeLog:

2019-03-14  Martin Liska  

	PR other/89712
	* doc/invoke.texi: Remove -fdump-class-hierarchy option.

---
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index df0883f2fc9..0a941519dbc 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -583,7 +583,6 @@ Objective-C and Objective-C++ Dialects}.
 -fdisable-tree-@var{pass-name}=@var{range-list} @gol
 -fdump-debug  -fdump-earlydebug @gol
 -fdump-noaddr  -fdump-unnumbered  -fdump-unnumbered-links @gol
--fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol
 -fdump-final-insns@r{[}=@var{file}@r{]} @gol
 -fdump-ipa-all  -fdump-ipa-cgraph  -fdump-ipa-inline @gol
 -fdump-lang-all @gol
--
2.21.0


Re: GCC 8 backports

2019-03-28 Thread Martin Liška
Hi.

I'm backporting a documentation fix.

Martin
>From 1055e2c2787be337c33787608473a7a4bcbe82b8 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Thu, 28 Mar 2019 09:47:27 +0100
Subject: [PATCH] Backport r265786

gcc/ChangeLog:

2018-11-05  Martin Liska  

	PR web/87829
	* doc/invoke.texi: Remove options that are
	not disabled with -Os.
---
 gcc/doc/invoke.texi | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 4ee24c3ab78..de86d7a1e01 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -7680,8 +7680,7 @@ do not typically increase code size.
 
 @option{-Os} disables the following optimization flags:
 @gccoptlist{-falign-functions  -falign-jumps  -falign-loops @gol
--falign-labels  -freorder-blocks  -freorder-blocks-algorithm=stc @gol
--freorder-blocks-and-partition  -fprefetch-loop-arrays}
+-falign-labels  -fprefetch-loop-arrays}
 
 It also enables @option{-finline-functions}, causes the compiler to tune for
 code size rather than execution speed, and performs further optimizations
-- 
2.21.0



Re: GCC 8 backports

2019-07-04 Thread Martin Liška
I'm sending one more patch that I've tested.

Martin
>From 44e3202c0416fcaa5a145c32118f0d08ff8ea0a2 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 3 Jul 2019 08:31:35 +
Subject: [PATCH] Backport r272992

gcc/ChangeLog:

2019-07-03  Martin Liska  

	PR middle-end/90899
	* multiple_target.c (create_dispatcher_calls): Add to comdat
	group only if set for ifunc.

gcc/testsuite/ChangeLog:

2019-07-03  Martin Liska  

	PR middle-end/90899
	* gcc.target/i386/pr90899.c: New test.
---
 gcc/multiple_target.c   | 3 ++-
 gcc/testsuite/gcc.target/i386/pr90899.c | 6 ++
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr90899.c

diff --git a/gcc/multiple_target.c b/gcc/multiple_target.c
index 87000dba214..97d2268663f 100644
--- a/gcc/multiple_target.c
+++ b/gcc/multiple_target.c
@@ -158,7 +158,8 @@ create_dispatcher_calls (struct cgraph_node *node)
 	{
 	  symtab_node *source = ref->referring;
 	  source->create_reference (inode, IPA_REF_ALIAS);
-	  source->add_to_same_comdat_group (inode);
+	  if (inode->get_comdat_group ())
+		source->add_to_same_comdat_group (inode);
 	}
 	  else
 	gcc_unreachable ();
diff --git a/gcc/testsuite/gcc.target/i386/pr90899.c b/gcc/testsuite/gcc.target/i386/pr90899.c
new file mode 100644
index 000..e0e2d5ac6bb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr90899.c
@@ -0,0 +1,6 @@
+/* PR middle-end/90899 */
+/* { dg-do compile } */
+/* { dg-require-ifunc "" } */
+
+__attribute__ ((target_clones ("default", "arch=slm"))) static int f () { return 0; }
+__attribute__ ((alias ("f"))) __typeof (f) g;
-- 
2.22.0



Re: GCC 8 backports

2019-07-22 Thread Martin Liška
Hi.

One more patch I've just tested.

Martin
>From eb62ef9ec1edc109aa69137ed077620cafad5253 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Mon, 22 Jul 2019 10:00:07 +0200
Subject: [PATCH] Backport r273660

gcc/ChangeLog:

2019-07-22  Martin Liska  

	PR driver/91172
	* opts-common.c (decode_cmdline_option): Decode
	argument of -Werror and check it for a wrong language.
	* opts-global.c (complain_wrong_lang): Remove such case.

gcc/testsuite/ChangeLog:

2019-07-22  Martin Liska  

	PR driver/91172
	* gcc.dg/pr91172.c: New test.
---
 gcc/opts-common.c | 20 +++-
 gcc/opts-global.c |  6 +-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index 3c2553368ac..9b0d76d1148 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -438,7 +438,8 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask,
 
   extra_args = 0;
 
-  opt_index = find_opt (argv[0] + 1, lang_mask);
+  const char *opt_value = argv[0] + 1;
+  opt_index = find_opt (opt_value, lang_mask);
   i = 0;
   while (opt_index == OPT_SPECIAL_unknown
 	 && i < ARRAY_SIZE (option_map))
@@ -641,6 +642,23 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask,
   /* Check if this is a switch for a different front end.  */
   if (!option_ok_for_language (option, lang_mask))
 errors |= CL_ERR_WRONG_LANG;
+  else if (strcmp (option->opt_text, "-Werror=") == 0
+	   && strchr (opt_value, ',') == NULL)
+{
+  /* Verify that -Werror argument is a valid warning
+	 for a language.  */
+  char *werror_arg = xstrdup (opt_value + 6);
+  werror_arg[0] = 'W';
+
+  size_t warning_index = find_opt (werror_arg, lang_mask);
+  if (warning_index != OPT_SPECIAL_unknown)
+	{
+	  const struct cl_option *warning_option
+	= &cl_options[warning_index];
+	  if (!option_ok_for_language (warning_option, lang_mask))
+	errors |= CL_ERR_WRONG_LANG;
+	}
+}
 
   /* Convert the argument to lowercase if appropriate.  */
   if (arg && option->cl_tolower)
diff --git a/gcc/opts-global.c b/gcc/opts-global.c
index bfa2afb1987..b45d18996a3 100644
--- a/gcc/opts-global.c
+++ b/gcc/opts-global.c
@@ -100,10 +100,14 @@ complain_wrong_lang (const struct cl_decoded_option *decoded,
 	   text, bad_lang);
   else if (lang_mask == CL_DRIVER)
 gcc_unreachable ();
-  else
+  else if (ok_langs[0] != '\0')
 /* Eventually this should become a hard error IMO.  */
 warning (0, "command line option %qs is valid for %s but not for %s",
 	 text, ok_langs, bad_lang);
+  else
+/* Happens for -Werror=warning_name.  */
+warning (0, "%<-Werror=%> argument %qs is not valid for %s",
+	 text, bad_lang);
 
   free (ok_langs);
   free (bad_lang);
-- 
2.22.0



Re: GCC 8 backports

2018-11-20 Thread Martin Liška
On 10/3/18 11:23 AM, Martin Liška wrote:
> On 9/25/18 8:48 AM, Martin Liška wrote:
>> Hi.
>>
>> One more tested patch.
>>
>> Martin
>>
> 
> One more tested patch.
> 
> Martin
> 

Hi.

One another tested patch that I'm going to install.

Martin
>From 94cd1e55e5baec63b7a80c59fdd8b5c52595c9e9 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 19 Nov 2018 15:00:41 +
Subject: [PATCH] Backport r266277

gcc/lto/ChangeLog:

2018-11-19  Martin Liska  

	PR lto/88077
	* lto-symtab.c (lto_symtab_merge): Transform the
	condition before r256989.

gcc/testsuite/ChangeLog:

2018-11-19  Martin Liska  

	PR lto/88077
	* gcc.dg/lto/pr88077_0.c: New test.
	* gcc.dg/lto/pr88077_1.c: New test.
---
 gcc/lto/lto-symtab.c | 5 +++--
 gcc/testsuite/gcc.dg/lto/pr88077_0.c | 3 +++
 gcc/testsuite/gcc.dg/lto/pr88077_1.c | 6 ++
 3 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/lto/pr88077_0.c
 create mode 100644 gcc/testsuite/gcc.dg/lto/pr88077_1.c

diff --git a/gcc/lto/lto-symtab.c b/gcc/lto/lto-symtab.c
index 3663ab7a9b2..cec74894c02 100644
--- a/gcc/lto/lto-symtab.c
+++ b/gcc/lto/lto-symtab.c
@@ -388,8 +388,9 @@ lto_symtab_merge (symtab_node *prevailing, symtab_node *entry)
 	 int a[]={1,2,3};
 	 here the first declaration is COMMON
 	 and sizeof(a) == sizeof (int).  */
-	else if (TREE_CODE (type) == ARRAY_TYPE)
-	  return (TYPE_SIZE (decl) == TYPE_SIZE (TREE_TYPE (type)));
+	else if (TREE_CODE (type) != ARRAY_TYPE
+		 || (TYPE_SIZE (type) != TYPE_SIZE (TREE_TYPE (type
+	  return false;
   }
 
   return true;
diff --git a/gcc/testsuite/gcc.dg/lto/pr88077_0.c b/gcc/testsuite/gcc.dg/lto/pr88077_0.c
new file mode 100644
index 000..9e464b6ad4a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr88077_0.c
@@ -0,0 +1,3 @@
+/* { dg-lto-do link } */
+
+int HeaderStr;
diff --git a/gcc/testsuite/gcc.dg/lto/pr88077_1.c b/gcc/testsuite/gcc.dg/lto/pr88077_1.c
new file mode 100644
index 000..fd3de3e77a6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr88077_1.c
@@ -0,0 +1,6 @@
+char HeaderStr[1];
+
+int main()
+{
+  return 0;
+}
-- 
2.19.1



Re: GCC 8 backports

2019-05-14 Thread Martin Liška
On 5/6/19 4:00 PM, Martin Liška wrote:
> Hi.
> 
> I'm sending following backport that I've just tested.
> 
> Martin
> 

Hi.

There are 2 more patches that I've tested.

Martin
>From af452cc71498c097d09bc8ecd848d28555a00bb2 Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 13 May 2019 07:04:58 +
Subject: [PATCH 1/2] Backport r271116

gcc/ChangeLog:

2019-05-13  Martin Liska  

	PR gcov-profile/90380
	* gcov.c (enum loop_type): Remove the enum and
	the operator.
	(handle_cycle): Assert that we should not reach
	a negative count.
	(circuit): Use loop_found instead of a tri-state loop_type.
	(get_cycles_count): Do not handle NEGATIVE_LOOP as it can't
	happen.
---
 gcc/gcov.c | 53 ++---
 1 file changed, 18 insertions(+), 35 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index c7c52ce3629..47c784a9388 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -604,27 +604,11 @@ bool function_info::group_line_p (unsigned n, unsigned src_idx)
 typedef vector arc_vector_t;
 typedef vector block_vector_t;
 
-/* Enum with types of loop in CFG.  */
-
-enum loop_type
-{
-  NO_LOOP = 0,
-  LOOP = 1,
-  NEGATIVE_LOOP = 3
-};
-
-/* Loop_type operator that merges two values: A and B.  */
-
-inline loop_type& operator |= (loop_type& a, loop_type b)
-{
-return a = static_cast (a | b);
-}
-
 /* Handle cycle identified by EDGES, where the function finds minimum cs_count
and subtract the value from all counts.  The subtracted value is added
to COUNT.  Returns type of loop.  */
 
-static loop_type
+static void
 handle_cycle (const arc_vector_t &edges, int64_t &count)
 {
   /* Find the minimum edge of the cycle, and reduce all nodes in the cycle by
@@ -640,7 +624,7 @@ handle_cycle (const arc_vector_t &edges, int64_t &count)
   for (unsigned i = 0; i < edges.size (); i++)
 edges[i]->cs_count -= cycle_count;
 
-  return cycle_count < 0 ? NEGATIVE_LOOP : LOOP;
+  gcc_assert (cycle_count >= 0);
 }
 
 /* Unblock a block U from BLOCKED.  Apart from that, iterate all blocks
@@ -671,12 +655,12 @@ unblock (const block_info *u, block_vector_t &blocked,
blocked by a block.  COUNT is accumulated count of the current LINE.
Returns what type of loop it contains.  */
 
-static loop_type
+static bool
 circuit (block_info *v, arc_vector_t &path, block_info *start,
 	 block_vector_t &blocked, vector &block_lists,
 	 line_info &linfo, int64_t &count)
 {
-  loop_type result = NO_LOOP;
+  bool loop_found = false;
 
   /* Add v to the block list.  */
   gcc_assert (find (blocked.begin (), blocked.end (), v) == blocked.end ());
@@ -691,15 +675,19 @@ circuit (block_info *v, arc_vector_t &path, block_info *start,
 
   path.push_back (arc);
   if (w == start)
-	/* Cycle has been found.  */
-	result |= handle_cycle (path, count);
+	{
+	  /* Cycle has been found.  */
+	  handle_cycle (path, count);
+	  loop_found = true;
+	}
   else if (find (blocked.begin (), blocked.end (), w) == blocked.end ())
-	result |= circuit (w, path, start, blocked, block_lists, linfo, count);
+	loop_found |= circuit (w, path, start, blocked, block_lists, linfo,
+			   count);
 
   path.pop_back ();
 }
 
-  if (result != NO_LOOP)
+  if (loop_found)
 unblock (v, blocked, block_lists);
   else
 for (arc_info *arc = v->succ; arc; arc = arc->succ_next)
@@ -716,14 +704,13 @@ circuit (block_info *v, arc_vector_t &path, block_info *start,
 	  list.push_back (v);
   }
 
-  return result;
+  return loop_found;
 }
 
-/* Find cycles for a LINFO.  If HANDLE_NEGATIVE_CYCLES is set and the line
-   contains a negative loop, then perform the same function once again.  */
+/* Find cycles for a LINFO.  */
 
 static gcov_type
-get_cycles_count (line_info &linfo, bool handle_negative_cycles = true)
+get_cycles_count (line_info &linfo)
 {
   /* Note that this algorithm works even if blocks aren't in sorted order.
  Each iteration of the circuit detection is completely independent
@@ -731,7 +718,7 @@ get_cycles_count (line_info &linfo, bool handle_negative_cycles = true)
  Therefore, operating on a permuted order (i.e., non-sorted) only
  has the effect of permuting the output cycles.  */
 
-  loop_type result = NO_LOOP;
+  bool loop_found = false;
   gcov_type count = 0;
   for (vector::iterator it = linfo.blocks.begin ();
it != linfo.blocks.end (); it++)
@@ -739,14 +726,10 @@ get_cycles_count (line_info &linfo, bool handle_negative_cycles = true)
   arc_vector_t path;
   block_vector_t blocked;
   vector block_lists;
-  result |= circuit (*it, path, *it, blocked, block_lists, linfo,
-			 count);
+  loop_found |= circuit (*it, path, *it, blocked, block_lists, linfo,
+			 count);
 }
 
-  /* If we have a negative cycle, repeat the find_cycles routine.  */
-  if (result == NEGATIVE_LOOP && handle_negative_cycles)
-count += get_cycles_count (linfo, false);
-
   return count;
 }
 
-- 
2.21.0

>From 33a14c2ebe20dc58e986503fb00814e10dec9b1a Mon Sep 17 00:00

Re: GCC 8 backports

2018-12-27 Thread Martin Liška
On 11/20/18 11:58 AM, Martin Liška wrote:
> On 10/3/18 11:23 AM, Martin Liška wrote:
>> On 9/25/18 8:48 AM, Martin Liška wrote:
>>> Hi.
>>>
>>> One more tested patch.
>>>
>>> Martin
>>>
>>
>> One more tested patch.
>>
>> Martin
>>
> 
> Hi.
> 
> One another tested patch that I'm going to install.
> 
> Martin
> 

Hi.

One another tested patch that I'm going to install.

Thanks,
Martin
>From 97052eab40506300510336bf668d4adc2a60a7cf Mon Sep 17 00:00:00 2001
From: hubicka 
Date: Fri, 21 Dec 2018 19:13:06 +
Subject: [PATCH] Backport r267338

gcc/ChangeLog:

2018-12-15  Jan Hubicka  

	PR ipa/88561
	* ipa-polymorphic-call.c
	(ipa_polymorphic_call_context::ipa_polymorphic_call_context): Handle
	arguments of thunks correctly.
	(ipa_polymorphic_call_context::get_dynamic_context): Be ready for
	NULL instance pinter.
	* lto-cgraph.c (lto_output_node): Always stream thunk info.

gcc/testsuite/ChangeLog:

2018-12-15  Jan Hubicka  

	PR ipa/88561
	* g++.dg/tree-prof/devirt.C: New testcase.
---
 gcc/ipa-polymorphic-call.c  |  32 +-
 gcc/lto-cgraph.c|   8 +-
 gcc/testsuite/g++.dg/tree-prof/devirt.C | 123 
 3 files changed, 159 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/tree-prof/devirt.C

diff --git a/gcc/ipa-polymorphic-call.c b/gcc/ipa-polymorphic-call.c
index 13aca94dd00..d5e4a6a6f97 100644
--- a/gcc/ipa-polymorphic-call.c
+++ b/gcc/ipa-polymorphic-call.c
@@ -995,9 +995,22 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl,
 	{
 	  outer_type
 	 = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (base_pointer)));
+	  cgraph_node *node = cgraph_node::get (current_function_decl);
 	  gcc_assert (TREE_CODE (outer_type) == RECORD_TYPE
 		  || TREE_CODE (outer_type) == UNION_TYPE);
 
+	  /* Handle the case we inlined into a thunk.  In this case
+	 thunk has THIS pointer of type bar, but it really receives
+	 address to its base type foo which sits in bar at
+	 0-thunk.fixed_offset.  It starts with code that adds
+	 think.fixed_offset to the pointer to compensate for this.
+
+	 Because we walked all the way to the begining of thunk, we now
+	 see pointer &bar-thunk.fixed_offset and need to compensate
+	 for it.  */
+	  if (node->thunk.fixed_offset)
+	offset -= node->thunk.fixed_offset * BITS_PER_UNIT;
+
 	  /* Dynamic casting has possibly upcasted the type
 	 in the hiearchy.  In this case outer type is less
 	 informative than inner type and we should forget
@@ -1005,7 +1018,11 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl,
 	  if ((otr_type
 	   && !contains_type_p (outer_type, offset,
 otr_type))
-	  || !contains_polymorphic_type_p (outer_type))
+	  || !contains_polymorphic_type_p (outer_type)
+	  /* If we compile thunk with virtual offset, the THIS pointer
+		 is adjusted by unknown value.  We can't thus use outer info
+		 at all.  */
+	  || node->thunk.virtual_offset_p)
 	{
 	  outer_type = NULL;
 	  if (instance)
@@ -1030,7 +1047,15 @@ ipa_polymorphic_call_context::ipa_polymorphic_call_context (tree fndecl,
 	  maybe_in_construction = false;
 	}
 	  if (instance)
-	*instance = base_pointer;
+	{
+	  /* If method is expanded thunk, we need to apply thunk offset
+		 to instance pointer.  */
+	  if (node->thunk.virtual_offset_p
+		  || node->thunk.fixed_offset)
+		*instance = NULL;
+	  else
+	*instance = base_pointer;
+	}
 	  return;
 	}
   /* Non-PODs passed by value are really passed by invisible
@@ -1547,6 +1572,9 @@ ipa_polymorphic_call_context::get_dynamic_type (tree instance,
   HOST_WIDE_INT instance_offset = offset;
   tree instance_outer_type = outer_type;
 
+  if (!instance)
+return false;
+
   if (otr_type)
 otr_type = TYPE_MAIN_VARIANT (otr_type);
 
diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index 40baf858ca5..305f22bd7e9 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -546,7 +546,11 @@ lto_output_node (struct lto_simple_output_block *ob, struct cgraph_node *node,
   streamer_write_bitpack (&bp);
   streamer_write_data_stream (ob->main_stream, section, strlen (section) + 1);
 
-  if (node->thunk.thunk_p)
+  /* Stream thunk info always because we use it in
+ ipa_polymorphic_call_context::ipa_polymorphic_call_context
+ to properly interpret THIS pointers for thunks that has been converted
+ to Gimple.  */
+  if (node->definition)
 {
   streamer_write_uhwi_stream
 	 (ob->main_stream,
@@ -1317,7 +1321,7 @@ input_node (struct lto_file_decl_data *file_data,
   if (section)
 node->set_section_for_node (section);
 
-  if (node->thunk.thunk_p)
+  if (node->definition)
 {
   int type = streamer_read_uhwi (ib);
   HOST_WIDE_INT fixed_offset = streamer_read_uhwi (ib);
diff --git a/gcc/testsuite/g++.dg/tree-prof/devirt.C b/gcc/testsuite/g++.dg/tree-prof/devirt.C
new file mode 100644
index 000.

Re: GCC 8 backports

2018-12-28 Thread Sudakshina Das
Hi Martin

On 27/12/18 12:32 PM, Martin Liška wrote:
> On 11/20/18 11:58 AM, Martin Liška wrote:
>> On 10/3/18 11:23 AM, Martin Liška wrote:
>>> On 9/25/18 8:48 AM, Martin Liška wrote:
 Hi.

 One more tested patch.

 Martin

>>> One more tested patch.
>>>
>>> Martin
>>>
>> Hi.
>>
>> One another tested patch that I'm going to install.
>>
>> Martin
>>
> Hi.
>
> One another tested patch that I'm going to install.
>
> Thanks,
> Martin

The last backport of r267338 causes the following failures on 
arm-none-linux-gnueabihf and aarch64-none-linux-gnu

UNRESOLVED: g++.dg/tree-prof/devirt.C scan-ipa-dump-times dom3 "3" 
folding virtual function call to virtual unsigned int 
mozPersonalDictionary::AddRef
UNRESOLVED: g++.dg/tree-prof/devirt.C scan-ipa-dump-times dom3 "3" 
folding virtual function call to virtual unsigned int 
mozPersonalDictionary::_ZThn16

with

g++.dg/tree-prof/devirt.C: dump file does not exist

Thanks

Sudi



Re: GCC 8 backports

2019-01-02 Thread Martin Liška
On 12/28/18 12:24 PM, Sudakshina Das wrote:
> Hi Martin
> 
> On 27/12/18 12:32 PM, Martin Liška wrote:
>> On 11/20/18 11:58 AM, Martin Liška wrote:
>>> On 10/3/18 11:23 AM, Martin Liška wrote:
 On 9/25/18 8:48 AM, Martin Liška wrote:
> Hi.
>
> One more tested patch.
>
> Martin
>
 One more tested patch.

 Martin

>>> Hi.
>>>
>>> One another tested patch that I'm going to install.
>>>
>>> Martin
>>>
>> Hi.
>>
>> One another tested patch that I'm going to install.
>>
>> Thanks,
>> Martin
> 
> The last backport of r267338 causes the following failures on 
> arm-none-linux-gnueabihf and aarch64-none-linux-gnu
> 
> UNRESOLVED: g++.dg/tree-prof/devirt.C scan-ipa-dump-times dom3 "3" 
> folding virtual function call to virtual unsigned int 
> mozPersonalDictionary::AddRef
> UNRESOLVED: g++.dg/tree-prof/devirt.C scan-ipa-dump-times dom3 "3" 
> folding virtual function call to virtual unsigned int 
> mozPersonalDictionary::_ZThn16
> 
> with
> 
> g++.dg/tree-prof/devirt.C: dump file does not exist
> 
> Thanks
> 
> Sudi
> 

Honza, in order to make the test working I would need to backport
r267495. Is it a good idea?

Thanks,
Martin


Re: GCC 8 backports

2019-01-02 Thread Jan Hubicka
> 
> Honza, in order to make the test working I would need to backport
> r267495. Is it a good idea?

Yes, my apologies for the mistake! I should stop looking for failures
via grep and use test_summary consistently since I tend to miss
unresolved tests.  Old habits are hard to change.

Honza
> 
> Thanks,
> Martin


Re: GCC 8 backports

2019-01-03 Thread Martin Liška
On 1/2/19 12:50 PM, Jan Hubicka wrote:
>>
>> Honza, in order to make the test working I would need to backport
>> r267495. Is it a good idea?
> 
> Yes, my apologies for the mistake! I should stop looking for failures
> via grep and use test_summary consistently since I tend to miss
> unresolved tests.  Old habits are hard to change.
> 
> Honza
>>
>> Thanks,
>> Martin

Hi.

So there's a backport of 3 patches that fix the test-case.
Tested and bootstrapped on x86_64-linux-gnu, I'm going
to install the patches.

Martin
>From 5fd0285a53b7caee98625472adc44cb101bd4873 Mon Sep 17 00:00:00 2001
From: jakub 
Date: Wed, 2 Jan 2019 09:25:59 +
Subject: [PATCH 3/3] Backport r267507

gcc/testsuite/ChangeLog:

2019-01-02  Jakub Jelinek  

	PR ipa/88561
	* g++.dg/tree-prof/devirt.C: Expect _ZThn16 only for lp64 and llp64
	targets and expect _ZThn8 for ilp32 targets.
---
 gcc/testsuite/g++.dg/tree-prof/devirt.C | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/tree-prof/devirt.C b/gcc/testsuite/g++.dg/tree-prof/devirt.C
index 7d6797dd226..3de5dbcf688 100644
--- a/gcc/testsuite/g++.dg/tree-prof/devirt.C
+++ b/gcc/testsuite/g++.dg/tree-prof/devirt.C
@@ -1,4 +1,6 @@
+/* PR ipa/88561 */
 /* { dg-options "-O3 -fdump-tree-dom3-details" } */
+
 struct nsISupports
 {
   virtual int QueryInterface (const int &aIID, void **aInstancePtr) = 0;
@@ -119,5 +121,6 @@ main ()
 __builtin_abort ();
 }
 
-/* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::_ZThn16" 1 "dom3" } } */
+/* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::_ZThn16" 1 "dom3" { target { lp64 || llp64 } } } } */
+/* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::_ZThn8" 1 "dom3" { target ilp32 } } } */
 /* { dg-final-use-not-autofdo { scan-tree-dump-times "folding virtual function call to virtual unsigned int mozPersonalDictionary::AddRef" 1 "dom3" } } */
-- 
2.20.1

>From f3a455cffaee5ac5af2ac188e08c51f3a662491a Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 2 Jan 2019 12:54:23 +0100
Subject: [PATCH 2/3] Backport r267495

gcc/ChangeLog:

2019-01-01  Jan Hubicka  

	* coverage.c (get_coverage_counts): Use current_function_decl.
	* profile.c (read_thunk_profile): New function.
	(branch_prob): Add THUNK parameter.
	* tree-profile.c (tree_profiling): Handle thunks.
	* value-prof.c (init_node_map): Handle thunks.
	* value-prof.h (branch_prob): Upate prototype.
	(read_thunk_profile): Declare.

gcc/testsuite/ChangeLog:

2019-01-01  Jan Hubicka  

	* g++.dg/tree-prof/devirt.C: Update testcase.
---
 gcc/coverage.c  |   2 +-
 gcc/profile.c   | 250 ++--
 gcc/testsuite/g++.dg/tree-prof/devirt.C |   4 +-
 gcc/tree-profile.c  |  28 ++-
 gcc/value-prof.c|   2 +-
 gcc/value-prof.h|   3 +-
 6 files changed, 177 insertions(+), 112 deletions(-)

diff --git a/gcc/coverage.c b/gcc/coverage.c
index 75628b1748f..592d3dcef84 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -368,7 +368,7 @@ get_coverage_counts (unsigned counter, unsigned expected,
   else
 {
   gcc_assert (coverage_node_map_initialized_p ());
-  elt.ident = cgraph_node::get (cfun->decl)->profile_id;
+  elt.ident = cgraph_node::get (current_function_decl)->profile_id;
 }
   elt.ctr = counter;
   entry = counts_hash->find (&elt);
diff --git a/gcc/profile.c b/gcc/profile.c
index 6fde0fd29d1..eb9f7d52668 100644
--- a/gcc/profile.c
+++ b/gcc/profile.c
@@ -977,6 +977,25 @@ compare_freqs (const void *p1, const void *p2)
   return e2->dest->index - e1->dest->index;
 }
 
+/* Only read execution count for thunks.  */
+
+void
+read_thunk_profile (struct cgraph_node *node)
+{
+  tree old = current_function_decl;
+  current_function_decl = node->decl;
+  gcov_type *counts = get_coverage_counts (GCOV_COUNTER_ARCS, 1, 0, 0, NULL);
+  if (counts)
+{
+  node->callees->count = node->count
+	 = profile_count::from_gcov_type (counts[0]);
+  free (counts);
+}
+  current_function_decl = old;
+  return;
+}
+
+
 /* Instrument and/or analyze program behavior based on program the CFG.
 
This function creates a representation of the control flow graph (of
@@ -997,7 +1016,7 @@ compare_freqs (const void *p1, const void *p2)
Main entry point of this file.  */
 
 void
-branch_prob (void)
+branch_prob (bool thunk)
 {
   basic_block bb;
   unsigned i;
@@ -1012,118 +1031,121 @@ branch_prob (void)
   flow_call_edges_add (NULL);
   add_noreturn_fake_exit_edges ();
 
-  /* We can't handle cyclic regions constructed using abnormal edges.
- To avoid these we replace every source of abnormal edge by a fake
- edge from entry node and every destination by fake edge to exit.
- This keeps g

Re: GCC 8 backports

2020-03-02 Thread Martin Liška

Hi.

There's one patch that was approved by Jakub before
another RC of GCC 8.4.0.

Martin
>From 5da6f38276fac87c89d86e0d447aefb7058d1880 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Fri, 28 Feb 2020 17:52:57 +0100
Subject: [PATCH] Backport 08bf7bde9f2987b1c623d272cc71fc14a1622442

gcc/ChangeLog:

2020-02-28  Martin Liska  

	PR other/93965
	* configure.ac: Improve detection of ld_date by requiring
	either two dashes or none.
	* configure: Regenerate.
---
 gcc/configure| 2 +-
 gcc/configure.ac | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/configure b/gcc/configure
index 7313088fc2c..97ba7d7d69c 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -22785,7 +22785,7 @@ if test $in_tree_ld != yes ; then
   ld_vers=`echo $ld_ver | sed -n \
 	  -e 's,^.*[	 ]\([0-9][0-9]*\.[0-9][0-9]*.*\)$,\1,p'`
 fi
-ld_date=`echo $ld_ver | sed -n 's,^.*\([2-9][0-9][0-9][0-9]\)[-]*\([01][0-9]\)[-]*\([0-3][0-9]\).*$,\1\2\3,p'`
+ld_date=`echo $ld_ver | sed -n 's,^.*\([2-9][0-9][0-9][0-9]\)\(-*\)\([01][0-9]\)\2\([0-3][0-9]\).*$,\1\3\4,p'`
 ld_vers_major=`expr "$ld_vers" : '\([0-9]*\)'`
 ld_vers_minor=`expr "$ld_vers" : '[0-9]*\.\([0-9]*\)'`
 ld_vers_patch=`expr "$ld_vers" : '[0-9]*\.[0-9]*\.\([0-9]*\)'`
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 9bed32ad43f..d6f2d5b2ed0 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -2580,7 +2580,7 @@ if test $in_tree_ld != yes ; then
   ld_vers=`echo $ld_ver | sed -n \
 	  -e 's,^.*[	 ]\([0-9][0-9]*\.[0-9][0-9]*.*\)$,\1,p'`
 fi
-ld_date=`echo $ld_ver | sed -n 's,^.*\([2-9][0-9][0-9][0-9]\)[-]*\([01][0-9]\)[-]*\([0-3][0-9]\).*$,\1\2\3,p'`
+ld_date=`echo $ld_ver | sed -n 's,^.*\([2-9][0-9][0-9][0-9]\)\(-*\)\([01][0-9]\)\2\([0-3][0-9]\).*$,\1\3\4,p'`
 ld_vers_major=`expr "$ld_vers" : '\([0-9]*\)'`
 ld_vers_minor=`expr "$ld_vers" : '[0-9]*\.\([0-9]*\)'`
 ld_vers_patch=`expr "$ld_vers" : '[0-9]*\.[0-9]*\.\([0-9]*\)'`
-- 
2.25.1



Re: GCC 8 backports

2020-01-15 Thread Martin Liška

Hi.

There's one more backport commit I've just tested and installed.

Martin
>From 67c0ee2c48a5e154bf00fa8326536881a92e287c Mon Sep 17 00:00:00 2001
From: Jan Hubicka 
Date: Sun, 14 Apr 2019 22:56:45 +0200
Subject: [PATCH] Backport d2a0371d2641e85c5e6ca396029be32204d976df

gcc/ChangeLog:

2019-04-14  Jan Hubicka  

	PR lto/89358
	* ipa-devirt.c (skip_in_fields_list_p): New.
	(odr_types_equivalent_p): Use it.

gcc/testsuite/ChangeLog:

2019-04-14  Jan Hubicka  

	PR lto/89358
	* g++.dg/lto/pr89358_0.C: New testcase.
	* g++.dg/lto/pr89358_1.C: New testcase.
---
 gcc/ipa-devirt.c | 22 --
 gcc/testsuite/g++.dg/lto/pr89358_0.C | 11 +++
 gcc/testsuite/g++.dg/lto/pr89358_1.C |  7 +++
 3 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/lto/pr89358_0.C
 create mode 100644 gcc/testsuite/g++.dg/lto/pr89358_1.C

diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index 5b6b130fa3a..380102020f9 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -1241,6 +1241,24 @@ warn_types_mismatch (tree t1, tree t2, location_t loc1, location_t loc2)
 inform (loc_t2, "the incompatible type is defined here");
 }
 
+/* Return true if T should be ignored in TYPE_FIELDS for ODR comparsion.  */
+
+static bool
+skip_in_fields_list_p (tree t)
+{
+  if (TREE_CODE (t) != FIELD_DECL)
+return true;
+  /* C++ FE introduces zero sized fields depending on -std setting, see
+ PR89358.  */
+  if (DECL_SIZE (t)
+  && integer_zerop (DECL_SIZE (t))
+  && DECL_ARTIFICIAL (t)
+  && DECL_IGNORED_P (t)
+  && !DECL_NAME (t))
+return true;
+  return false;
+}
+
 /* Compare T1 and T2, report ODR violations if WARN is true and set
WARNED to true if anything is reported.  Return true if types match.
If true is returned, the types are also compatible in the sense of
@@ -1525,9 +1543,9 @@ odr_types_equivalent_p (tree t1, tree t2, bool warn, bool *warned,
 		 f1 = TREE_CHAIN (f1), f2 = TREE_CHAIN (f2))
 	  {
 		/* Skip non-fields.  */
-		while (f1 && TREE_CODE (f1) != FIELD_DECL)
+		while (f1 && skip_in_fields_list_p (f1))
 		  f1 = TREE_CHAIN (f1);
-		while (f2 && TREE_CODE (f2) != FIELD_DECL)
+		while (f2 && skip_in_fields_list_p (f2))
 		  f2 = TREE_CHAIN (f2);
 		if (!f1 || !f2)
 		  break;
diff --git a/gcc/testsuite/g++.dg/lto/pr89358_0.C b/gcc/testsuite/g++.dg/lto/pr89358_0.C
new file mode 100644
index 000..aebd2127c0c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr89358_0.C
@@ -0,0 +1,11 @@
+/* { dg-do link } */
+/* { dg-options "-std=c++17"  } */
+#include 
+
+extern void test();
+
+int main()
+{
+std::map m;
+test();
+}
diff --git a/gcc/testsuite/g++.dg/lto/pr89358_1.C b/gcc/testsuite/g++.dg/lto/pr89358_1.C
new file mode 100644
index 000..68b80a37662
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr89358_1.C
@@ -0,0 +1,7 @@
+/* { dg-options "-std=c++14"  } */
+#include 
+
+void test()
+{
+std::map m;
+}
-- 
2.24.1



Re: GCC 8 backports

2020-03-29 Thread Martin Liška

Hi.

There's one more patch that I've just tested.

Martin
>From 0e8def2b6dac1e7e46e6310ded21283914e05748 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Mon, 2 Sep 2019 09:06:54 +0200
Subject: [PATCH] Backport 9297e013293e4d332fc7c40859ea4dd9616e0d88

gcc/ChangeLog:

2019-09-02  Martin Liska  

	PR gcov-profile/91601
	* gcov.c (path_contains_zero_cycle_arc): Rename to ...
	(path_contains_zero_or_negative_cycle_arc): ... this and handle
	also negative edges.
	(circuit): Handle also negative edges as they can happen
	in some situations.
---
 gcc/gcov.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index a99802079dc..565530d4f73 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -653,10 +653,10 @@ unblock (const block_info *u, block_vector_t &blocked,
 /* Return true when PATH contains a zero cycle arc count.  */
 
 static bool
-path_contains_zero_cycle_arc (arc_vector_t &path)
+path_contains_zero_or_negative_cycle_arc (arc_vector_t &path)
 {
   for (unsigned i = 0; i < path.size (); i++)
-if (path[i]->cs_count == 0)
+if (path[i]->cs_count <= 0)
   return true;
   return false;
 }
@@ -682,7 +682,7 @@ circuit (block_info *v, arc_vector_t &path, block_info *start,
 {
   block_info *w = arc->dst;
   if (w < start
-	  || arc->cs_count == 0
+	  || arc->cs_count <= 0
 	  || !linfo.has_block (w))
 	continue;
 
@@ -693,7 +693,7 @@ circuit (block_info *v, arc_vector_t &path, block_info *start,
 	  handle_cycle (path, count);
 	  loop_found = true;
 	}
-  else if (!path_contains_zero_cycle_arc (path)
+  else if (!path_contains_zero_or_negative_cycle_arc (path)
 	   &&  find (blocked.begin (), blocked.end (), w) == blocked.end ())
 	loop_found |= circuit (w, path, start, blocked, block_lists, linfo,
 			   count);
@@ -708,7 +708,7 @@ circuit (block_info *v, arc_vector_t &path, block_info *start,
   {
 	block_info *w = arc->dst;
 	if (w < start
-	|| arc->cs_count == 0
+	|| arc->cs_count <= 0
 	|| !linfo.has_block (w))
 	  continue;
 
-- 
2.26.0



Re: GCC 8 backports

2020-04-03 Thread Martin Liška

Hi.

There's one more I've tested.

Martin
>From 3b64f64f036c03e74fc4b55327cc07dc1dc21116 Mon Sep 17 00:00:00 2001
From: Martin Liska 
Date: Fri, 3 Apr 2020 09:39:10 +0200
Subject: [PATCH] Backport 55a7380213a5c16120d5c674fb42b38a3d796b57

gcc/ChangeLog:

2020-04-03  Martin Liska  

	PR ipa/94445
	* ipa-icf-gimple.c (func_checker::compare_gimple_call):
	  Compare type attributes for gimple_call_fntypes.
---
 gcc/ipa-icf-gimple.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/ipa-icf-gimple.c b/gcc/ipa-icf-gimple.c
index 25284936bc3..38e0ac12f7e 100644
--- a/gcc/ipa-icf-gimple.c
+++ b/gcc/ipa-icf-gimple.c
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "ipa-utils.h"
 #include "tree-eh.h"
 #include "builtins.h"
+#include "attribs.h"
 
 #include "ipa-icf-gimple.h"
 
@@ -768,6 +769,9 @@ func_checker::compare_gimple_call (gcall *s1, gcall *s2)
   || (fntype1 && !types_compatible_p (fntype1, fntype2)))
 return return_false_with_msg ("call function types are not compatible");
 
+  if (fntype1 && fntype2 && comp_type_attributes (fntype1, fntype2) != 1)
+return return_false_with_msg ("different fntype attributes");
+
   tree chain1 = gimple_call_chain (s1);
   tree chain2 = gimple_call_chain (s2);
   if ((chain1 && !chain2)
-- 
2.26.0



Re: GCC 8 backports

2018-10-03 Thread Martin Liška
On 9/25/18 8:48 AM, Martin Liška wrote:
> Hi.
> 
> One more tested patch.
> 
> Martin
> 

One more tested patch.

Martin
>From d5ac07522f558372f13e95ea05593adae36e5dfa Mon Sep 17 00:00:00 2001
From: marxin 
Date: Wed, 3 Oct 2018 10:39:16 +0200
Subject: [PATCH] Backport r264806

gcc/ChangeLog:

2018-10-03  Martin Liska  

	PR gcov-profile/86109
	* coverage.c (coverage_begin_function): Do not
	mark lambdas as artificial.
	* tree-core.h (struct GTY): Remove tm_clone_flag
	and introduce new lambda_function.
	* tree.h (DECL_LAMBDA_FUNCTION): New macro.

gcc/cp/ChangeLog:

2018-10-03  Martin Liska  

	PR gcov-profile/86109
	* parser.c (cp_parser_lambda_declarator_opt):
	Set DECL_LAMBDA_FUNCTION for lambdas.

gcc/testsuite/ChangeLog:

2018-10-03  Martin Liska  

	PR gcov-profile/86109
	* g++.dg/gcov/pr86109.C: New test.
---
 gcc/coverage.c  |  3 ++-
 gcc/cp/parser.c |  1 +
 gcc/testsuite/g++.dg/gcov/pr86109.C | 16 
 gcc/tree-core.h |  2 +-
 gcc/tree.h  |  4 
 5 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/gcov/pr86109.C

diff --git a/gcc/coverage.c b/gcc/coverage.c
index 32ef298a11f..bae3d507638 100644
--- a/gcc/coverage.c
+++ b/gcc/coverage.c
@@ -663,7 +663,8 @@ coverage_begin_function (unsigned lineno_checksum, unsigned cfg_checksum)
   gcov_write_unsigned (cfg_checksum);
   gcov_write_string (IDENTIFIER_POINTER
 		 (DECL_ASSEMBLER_NAME (current_function_decl)));
-  gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl));
+  gcov_write_unsigned (DECL_ARTIFICIAL (current_function_decl)
+		   && !DECL_LAMBDA_FUNCTION (current_function_decl));
   gcov_write_filename (xloc.file);
   gcov_write_unsigned (xloc.line);
   gcov_write_unsigned (xloc.column);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index bbf1a71d415..b40bee6d33b 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -10620,6 +10620,7 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
 	DECL_ARTIFICIAL (fco) = 1;
 	/* Give the object parameter a different name.  */
 	DECL_NAME (DECL_ARGUMENTS (fco)) = get_identifier ("__closure");
+	DECL_LAMBDA_FUNCTION (fco) = 1;
 	if (return_type)
 	  TYPE_HAS_LATE_RETURN_TYPE (TREE_TYPE (fco)) = 1;
   }
diff --git a/gcc/testsuite/g++.dg/gcov/pr86109.C b/gcc/testsuite/g++.dg/gcov/pr86109.C
new file mode 100644
index 000..9052d2e5a04
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gcov/pr86109.C
@@ -0,0 +1,16 @@
+
+/* { dg-options "-fprofile-arcs -ftest-coverage -std=c++11" } */
+/* { dg-do run { target native } } */
+
+int main()
+{
+auto partially_uncovered_lambda = [](int i) { /* count(1) */
+if (i > 10) /* count(1) */
+return 0; /* count(1) */
+return 1; /* count(#) */
+};
+
+return partially_uncovered_lambda(20); /* count(1) */
+}
+
+/* { dg-final { run-gcov pr86109.C } } */
diff --git a/gcc/tree-core.h b/gcc/tree-core.h
index 478c631998c..356330a5b0e 100644
--- a/gcc/tree-core.h
+++ b/gcc/tree-core.h
@@ -1796,8 +1796,8 @@ struct GTY(()) tree_function_decl {
   unsigned pure_flag : 1;
   unsigned looping_const_or_pure_flag : 1;
   unsigned has_debug_args_flag : 1;
-  unsigned tm_clone_flag : 1;
   unsigned versioned_function : 1;
+  unsigned lambda_function: 1;
   /* No bits left.  */
 };
 
diff --git a/gcc/tree.h b/gcc/tree.h
index 1e14d9f5866..8e703140811 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -3061,6 +3061,10 @@ extern vec **decl_debug_args_insert (tree);
 #define DECL_CXX_DESTRUCTOR_P(NODE)\
(FUNCTION_DECL_CHECK (NODE)->decl_with_vis.cxx_destructor)
 
+/* In FUNCTION_DECL, this is set if this function is a lambda function.  */
+#define DECL_LAMBDA_FUNCTION(NODE) \
+  (FUNCTION_DECL_CHECK (NODE)->function_decl.lambda_function)
+
 /* In FUNCTION_DECL that represent an virtual method this is set when
the method is final.  */
 #define DECL_FINAL_P(NODE)\
-- 
2.19.0



Re: GCC 8 backports

2018-09-18 Thread Martin Liška
Hi.

One more tested patch.

Martin
>From ee960f3dcad03652cd133b8598131aed488c11cb Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 17 Sep 2018 10:19:02 +
Subject: [PATCH] Backport r264363

gcc/ChangeLog:

2018-09-17  Martin Liska  

	PR gcov-profile/85871
	* gcov.c (output_intermediate_file): Fix out of bounds
	access.
---
 gcc/gcov.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/gcov.c b/gcc/gcov.c
index 7f06cf66d0c..c7c52ce3629 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -1068,7 +1068,8 @@ output_intermediate_file (FILE *gcov_file, source_info *src)
 	}
 
   /* Follow with lines associated with the source file.  */
-  output_intermediate_line (gcov_file, &src->lines[line_num], line_num);
+  if (line_num < src->lines.size ())
+	output_intermediate_line (gcov_file, &src->lines[line_num], line_num);
 }
 }
 
-- 
2.18.0



Re: GCC 8 backports

2018-09-24 Thread Martin Liška
Hi.

One more tested patch.

Martin
>From 62538e940432b55cf38e96e1a2cd72ed1f5f569f Mon Sep 17 00:00:00 2001
From: marxin 
Date: Mon, 24 Sep 2018 11:22:38 +
Subject: [PATCH] Backport r264528

gcc/ChangeLog:

2018-09-24  Martin Liska  

	PR sanitizer/85774
	* asan.c: Make asan_handled_variables extern.
	* asan.h: Likewise.
	* cfgexpand.c (expand_stack_vars): Make sure
	a representative is unpoison if another
	variable in the partition is handled by
	use-after-scope sanitization.

gcc/testsuite/ChangeLog:

2018-09-24  Martin Liska  

	PR sanitizer/85774
	* g++.dg/asan/pr85774.C: New test.
---
 gcc/asan.c  |  2 +-
 gcc/asan.h  |  2 ++
 gcc/cfgexpand.c | 14 
 gcc/testsuite/g++.dg/asan/pr85774.C | 51 +
 4 files changed, 68 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/asan/pr85774.C

diff --git a/gcc/asan.c b/gcc/asan.c
index e71ab2cc710..235e219479d 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -253,7 +253,7 @@ static tree last_alloca_addr;
 /* Set of variable declarations that are going to be guarded by
use-after-scope sanitizer.  */
 
-static hash_set *asan_handled_variables = NULL;
+hash_set *asan_handled_variables = NULL;
 
 hash_set  *asan_used_labels = NULL;
 
diff --git a/gcc/asan.h b/gcc/asan.h
index 412af220597..2f431b4f938 100644
--- a/gcc/asan.h
+++ b/gcc/asan.h
@@ -110,6 +110,8 @@ extern bool asan_sanitize_stack_p (void);
 
 extern bool asan_sanitize_allocas_p (void);
 
+extern hash_set *asan_handled_variables;
+
 /* Return TRUE if builtin with given FCODE will be intercepted by
libasan.  */
 
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index eca38d5ab6c..13984749985 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -1157,6 +1157,20 @@ expand_stack_vars (bool (*pred) (size_t), struct stack_vars_data *data)
 	  if (repr_decl == NULL_TREE)
 		repr_decl = stack_vars[i].decl;
 	  data->asan_decl_vec.safe_push (repr_decl);
+
+	  /* Make sure a representative is unpoison if another
+		 variable in the partition is handled by
+		 use-after-scope sanitization.  */
+	  if (asan_handled_variables != NULL
+		  && !asan_handled_variables->contains (repr_decl))
+		{
+		  for (j = i; j != EOC; j = stack_vars[j].next)
+		if (asan_handled_variables->contains (stack_vars[j].decl))
+		  break;
+		  if (j != EOC)
+		asan_handled_variables->add (repr_decl);
+		}
+
 	  data->asan_alignb = MAX (data->asan_alignb, alignb);
 	  if (data->asan_base == NULL)
 		data->asan_base = gen_reg_rtx (Pmode);
diff --git a/gcc/testsuite/g++.dg/asan/pr85774.C b/gcc/testsuite/g++.dg/asan/pr85774.C
new file mode 100644
index 000..c033abfd69b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/pr85774.C
@@ -0,0 +1,51 @@
+/* PR sanitizer/85774 */
+/* { dg-do run } */
+
+#include 
+
+void
+DoSomething ()
+{
+}
+
+void
+DoFunc (const std::function &func)
+{
+  func ();
+}
+
+void
+Setup ()
+{
+  switch (1)
+{
+case 1:
+  {
+	DoFunc ([]() {});
+	break;
+  }
+case 2:
+  {
+	DoFunc ([]() {});
+	break;
+  }
+default:
+  break;
+}
+
+  DoSomething ();
+}
+
+void
+DemostrateBadPoisoning ()
+{
+  DoFunc ([]() {});
+}
+
+int
+main ()
+{
+  Setup ();
+  DemostrateBadPoisoning ();
+  return 0;
+}
-- 
2.19.0



[PATCH] GCC 8 Backports for AIX

2019-05-14 Thread David Edelsohn
I would like to backport two AIX-specific patches to GCC 8.  These
both fix bugs that generate wrong code on AIX.

1) XCOFF private read only data section

2) Follow AIX ABI to not pass FP structures in FPRs.

These patches have been on trunk / GCC 9 for months.

Bootstrapped gcc-8-branch on powerpc-ibm-aix7.2.0.0.

Is this okay?

Thanks, David

* xcoffout.h (xcoff_private_rodata_section_name): Declare.
* xcoffout.c (xcoff_private_rodata_section_name): Define.
* config/rs6000/rs6000.c (rs6000_xcoff_asm_init_sections): Create
read_only_private_data_section using xcoff_private_rodata_section_name.
(rs6000_xcoff_file_start): Generate xcoff_private_rodata_section_name.

PR target/61976
* config/rs6000/rs6000.c (rs6000_function_arg): Don't pass aggregates
in FPRs on AIX. Ensure type is non-NULL.
(rs6000_arg_partial_bytes): Same.

Index: xcoffout.c
===
--- xcoffout.c  (revision 271131)
+++ xcoffout.c  (working copy)
@@ -64,6 +64,7 @@

 char *xcoff_bss_section_name;
 char *xcoff_private_data_section_name;
+char *xcoff_private_rodata_section_name;
 char *xcoff_tls_data_section_name;
 char *xcoff_tbss_section_name;
 char *xcoff_read_only_section_name;
Index: xcoffout.h
===
--- xcoffout.h  (revision 271131)
+++ xcoffout.h  (working copy)
@@ -127,6 +127,7 @@

 extern char *xcoff_bss_section_name;
 extern char *xcoff_private_data_section_name;
+extern char *xcoff_private_rodata_section_name;
 extern char *xcoff_tls_data_section_name;
 extern char *xcoff_tbss_section_name;
 extern char *xcoff_read_only_section_name;
Index: config/rs6000/rs6000.c
===
--- config/rs6000/rs6000.c  (revision 271131)
+++ config/rs6000/rs6000.c  (working copy)
@@ -12615,7 +12615,9 @@ rs6000_function_arg (cumulative_args_t cum_v, mach
   if (elt_mode == TDmode && (cum->fregno % 2) == 1)
cum->fregno++;

-  if (USE_FP_FOR_ARG_P (cum, elt_mode))
+  if (USE_FP_FOR_ARG_P (cum, elt_mode)
+ && !(TARGET_AIX && !TARGET_ELF
+  && type != NULL && AGGREGATE_TYPE_P (type)))
{
  rtx rvec[GP_ARG_NUM_REG + AGGR_ARG_NUM_REG + 1];
  rtx r, off;
@@ -12751,7 +12753,9 @@ rs6000_arg_partial_bytes (cumulative_args_t cum_v,

   align_words = rs6000_parm_start (mode, type, cum->words);

-  if (USE_FP_FOR_ARG_P (cum, elt_mode))
+  if (USE_FP_FOR_ARG_P (cum, elt_mode)
+  && !(TARGET_AIX && !TARGET_ELF
+  && type != NULL && AGGREGATE_TYPE_P (type)))
 {
   unsigned long n_fpreg = (GET_MODE_SIZE (elt_mode) + 7) >> 3;

@@ -34218,6 +34222,10 @@ rs6000_xcoff_asm_init_sections (void)
   rs6000_xcoff_output_readwrite_section_asm_op,
   &xcoff_private_data_section_name);

+  read_only_private_data_section
+= get_unnamed_section (0, rs6000_xcoff_output_readonly_section_asm_op,
+  &xcoff_private_rodata_section_name);
+
   tls_data_section
 = get_unnamed_section (SECTION_TLS,
   rs6000_xcoff_output_tls_section_asm_op,
@@ -34228,10 +34236,6 @@ rs6000_xcoff_asm_init_sections (void)
   rs6000_xcoff_output_tls_section_asm_op,
   &xcoff_private_data_section_name);

-  read_only_private_data_section
-= get_unnamed_section (0, rs6000_xcoff_output_readonly_section_asm_op,
-  &xcoff_private_data_section_name);
-
   toc_section
 = get_unnamed_section (0, rs6000_xcoff_output_toc_section_asm_op, NULL);

@@ -34412,6 +34416,8 @@ rs6000_xcoff_file_start (void)
   main_input_filename, ".bss_");
   rs6000_gen_section_name (&xcoff_private_data_section_name,
   main_input_filename, ".rw_");
+  rs6000_gen_section_name (&xcoff_private_rodata_section_name,
+  main_input_filename, ".rop_");
   rs6000_gen_section_name (&xcoff_read_only_section_name,
   main_input_filename, ".ro_");
   rs6000_gen_section_name (&xcoff_tls_data_section_name,


Re: [PATCH] GCC 8 Backports for AIX

2019-05-14 Thread Segher Boessenkool
On Tue, May 14, 2019 at 09:42:58AM -0400, David Edelsohn wrote:
> I would like to backport two AIX-specific patches to GCC 8.  These
> both fix bugs that generate wrong code on AIX.
> 
> 1) XCOFF private read only data section
> 
> 2) Follow AIX ABI to not pass FP structures in FPRs.
> 
> These patches have been on trunk / GCC 9 for months.
> 
> Bootstrapped gcc-8-branch on powerpc-ibm-aix7.2.0.0.
> 
> Is this okay?

Sure!  For GCC 7 too, if you want?


Segher


> * xcoffout.h (xcoff_private_rodata_section_name): Declare.
> * xcoffout.c (xcoff_private_rodata_section_name): Define.
> * config/rs6000/rs6000.c (rs6000_xcoff_asm_init_sections): Create
> read_only_private_data_section using 
> xcoff_private_rodata_section_name.
> (rs6000_xcoff_file_start): Generate xcoff_private_rodata_section_name.
> 
> PR target/61976
> * config/rs6000/rs6000.c (rs6000_function_arg): Don't pass aggregates
> in FPRs on AIX. Ensure type is non-NULL.
> (rs6000_arg_partial_bytes): Same.