On 03/07/2017 03:57 PM, Richard Biener wrote: > On Thu, Mar 2, 2017 at 6:06 PM, marxin <mli...@suse.cz> wrote: >> gcc/ChangeLog: >> >> 2017-03-06 Martin Liska <mli...@suse.cz> >> >> PR ipa/79761 >> * tree-chkp.c (chkp_get_bound_for_parm): Get bounds for a param. >> (chkp_find_bounds_1): Remove gcc_unreachable. >> >> gcc/testsuite/ChangeLog: >> >> 2017-03-06 Martin Liska <mli...@suse.cz> >> >> PR ipa/79761 >> * g++.dg/pr79761.C: New test. >> --- >> gcc/testsuite/g++.dg/pr79761.C | 34 ++++++++++++++++++++++++++++++++++ >> gcc/tree-chkp.c | 3 +-- >> 2 files changed, 35 insertions(+), 2 deletions(-) >> create mode 100644 gcc/testsuite/g++.dg/pr79761.C >> >> diff --git a/gcc/testsuite/g++.dg/pr79761.C b/gcc/testsuite/g++.dg/pr79761.C >> new file mode 100644 >> index 00000000000..b1f92d2b036 >> --- /dev/null >> +++ b/gcc/testsuite/g++.dg/pr79761.C >> @@ -0,0 +1,34 @@ >> +/* { dg-do compile { target { ! x32 } } } */ >> +/* { dg-options "-fcheck-pointer-bounds -mmpx -mabi=ms" } */ >> + >> +struct Foo >> +{ >> + Foo() : a(1), b(1), c('a') {} >> + int a; >> + int b; >> + char c; >> +}; >> + >> +static Foo copy_foo(Foo) __attribute__((noinline, noclone)); >> + >> +static Foo copy_foo(Foo A) >> +{ >> + return A; >> +} >> + >> +struct Bar : Foo >> +{ >> + Bar(Foo t) : Foo(copy_foo(t)) {} >> +}; >> + >> +Foo F; >> + >> +int main (void) >> +{ >> + Bar B (F); >> + >> + if (B.a != 1 || B.b != 1 || B.c != 'a') >> + __builtin_abort (); >> + >> + return 0; >> +} >> diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c >> index 3d497f51ed8..d5683b1b9cf 100644 >> --- a/gcc/tree-chkp.c >> +++ b/gcc/tree-chkp.c >> @@ -2353,7 +2353,7 @@ chkp_get_next_bounds_parm (tree parm) >> static tree >> chkp_get_bound_for_parm (tree parm) >> { >> - tree decl = SSA_NAME_VAR (parm); >> + tree decl = TREE_CODE (parm) == PARM_DECL ? parm : SSA_NAME_VAR (parm); >> tree bounds; >> >> gcc_assert (TREE_CODE (decl) == PARM_DECL); >> @@ -3602,7 +3602,6 @@ chkp_find_bounds_1 (tree ptr, tree ptr_src, >> gimple_stmt_iterator *iter) >> break; >> >> case PARM_DECL: >> - gcc_unreachable (); >> bounds = chkp_get_bound_for_parm (ptr_src); > > But this is just useless work ... just do > > case PARM_DECL: > /* Handled above but failed. */ > break;
Ok, let's return invalid bounds. Please see updated patch. Martin > > the SSA_NAME case is similarly redundantly calling chkp_get_registered_bounds. > > Richard. > >> break; >> >> -- >> 2.11.1 >> >>
>From feb00580b4f084ccd376a548d1121b1718a4806e Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Thu, 2 Mar 2017 18:06:39 +0100 Subject: [PATCH 2/5] Get bounds for a PARM_DECL (PR ipa/79761). gcc/ChangeLog: 2017-03-06 Martin Liska <mli...@suse.cz> PR ipa/79761 * tree-chkp.c (chkp_get_bound_for_parm): Get bounds for a param. (chkp_find_bounds_1): Remove gcc_unreachable. gcc/testsuite/ChangeLog: 2017-03-06 Martin Liska <mli...@suse.cz> PR ipa/79761 * g++.dg/pr79761.C: New test. --- gcc/testsuite/g++.dg/pr79761.C | 34 ++++++++++++++++++++++++++++++++++ gcc/tree-chkp.c | 4 ++-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr79761.C diff --git a/gcc/testsuite/g++.dg/pr79761.C b/gcc/testsuite/g++.dg/pr79761.C new file mode 100644 index 00000000000..a97325a1fc4 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr79761.C @@ -0,0 +1,34 @@ +/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && { ! x32 } } } } */ +/* { dg-options "-fcheck-pointer-bounds -mmpx -mabi=ms" } */ + +struct Foo +{ + Foo() : a(1), b(1), c('a') {} + int a; + int b; + char c; +}; + +static Foo copy_foo(Foo) __attribute__((noinline, noclone)); + +static Foo copy_foo(Foo A) +{ + return A; +} + +struct Bar : Foo +{ + Bar(Foo t) : Foo(copy_foo(t)) {} +}; + +Foo F; + +int main (void) +{ + Bar B (F); + + if (B.a != 1 || B.b != 1 || B.c != 'a') + __builtin_abort (); + + return 0; +} diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c index 3d497f51ed8..75d8b5829d0 100644 --- a/gcc/tree-chkp.c +++ b/gcc/tree-chkp.c @@ -3602,8 +3602,8 @@ chkp_find_bounds_1 (tree ptr, tree ptr_src, gimple_stmt_iterator *iter) break; case PARM_DECL: - gcc_unreachable (); - bounds = chkp_get_bound_for_parm (ptr_src); + /* Handled above but failed. */ + bounds = chkp_get_invalid_op_bounds (); break; case TARGET_MEM_REF: -- 2.11.1