From cef29d7e83fee182f2115c5d79e383329345539c Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 25 May 2018 16:44:55 +0000 Subject: [PATCH] PR c++/80485 - inline function non-zero address. * symtab.c (nonzero_address): Check DECL_COMDAT. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260762 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 5 +++++ gcc/symtab.c | 8 ++++---- gcc/testsuite/g++.dg/expr/pmf-3.C | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/expr/pmf-3.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 04b94ff9ad6..a1ef11eecac 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-05-25 Jason Merrill + + PR c++/80485 - inline function non-zero address. + * symtab.c (nonzero_address): Check DECL_COMDAT. + 2018-05-25 Uros Bizjak PR target/83628 diff --git a/gcc/symtab.c b/gcc/symtab.c index 954920b6dff..67e14d76b11 100644 --- a/gcc/symtab.c +++ b/gcc/symtab.c @@ -1959,11 +1959,11 @@ symtab_node::nonzero_address () return true; } - /* If target is defined and not extern, we know it will be output and thus - it will bind to non-NULL. - Play safe for flag_delete_null_pointer_checks where weak definition maye + /* If target is defined and either comdat or not extern, we know it will be + output and thus it will bind to non-NULL. + Play safe for flag_delete_null_pointer_checks where weak definition may be re-defined by NULL. */ - if (definition && !DECL_EXTERNAL (decl) + if (definition && (!DECL_EXTERNAL (decl) || DECL_COMDAT (decl)) && (flag_delete_null_pointer_checks || !DECL_WEAK (decl))) { if (!DECL_WEAK (decl)) diff --git a/gcc/testsuite/g++.dg/expr/pmf-3.C b/gcc/testsuite/g++.dg/expr/pmf-3.C new file mode 100644 index 00000000000..fac42fc23a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/pmf-3.C @@ -0,0 +1,15 @@ +// PR c++/80485 +// { dg-do compile { target c++11 } } + +struct dummy { + void nonnull() {}; + void nonnull2(); +}; + +typedef void (dummy::*safe_bool)(); + +constexpr safe_bool a = &dummy::nonnull; +constexpr safe_bool b = &dummy::nonnull2; + +static_assert( static_cast( a ), "" ); +static_assert( static_cast( b ), "" ); -- 2.11.4.GIT