From: Alexandre Oliva <aoliva@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches List <gcc-patches@gcc.gnu.org>,
Nathan Sidwell <nathan@acm.org>
Subject: Re: [PATCH] [PR c++/84943] allow folding of array indexing indirect_ref
Date: Sat, 31 Mar 2018 08:23:00 -0000 [thread overview]
Message-ID: <ord0zkzrs1.fsf@lxoliva.fsfla.org> (raw)
In-Reply-To: <CADzB+2=75YwaJHL0YF=F4iPwLjh=t3mG24JMG0pdQF5o3TrFfg@mail.gmail.com> (Jason Merrill's message of "Fri, 30 Mar 2018 10:41:48 -0400")
On Mar 30, 2018, Jason Merrill <jason@redhat.com> wrote:
> I don't think we need this; if arg is overloaded, we take the
> type_unknown_p early exit, so the code lower down is always dealing
> with a single function.
Aah, that's why it seemed to me that we had already resolved overloads
when we got there.
As a bonus, I added the tf_conv test before another mark_used call I'd
missed in the previous patch.
Regstrapped on i686- and x86_64-linux-gnu. Ok to install?
[PR c++/84943] mark function as used when taking its address
fn[0]() ICEd because we would fold the INDIRECT_REF used for the
array indexing while building the address for the call, after not
finding the decl hiding there at first. But the decl would be exposed
by the folding, and then lower layers would complain we had the decl,
after all, but it wasn't one of the artificial or special functions
that could be called without being marked as used.
This patch arranges for a FUNCTION_DECL to be marked as used when
taking its address, just like we already did when taking the address
of a static function to call it as a member function (i.e. using the
obj.fn() notation). However, we shouldn't mark functions as used when
just performing overload resolution, lest we might instantiate
templates we shouldn't, as in g++.dg/overload/template1.C.
for gcc/cp/ChangeLog
PR c++/84943
* typeck.c (cp_build_addr_expr_1): Mark FUNCTION_DECL as
used.
for gcc/testsuite/ChangeLog
PR c++/84943
* g++.dg/pr84943.C: New.
* g++.dg/pr84943-2.C: New.
---
gcc/cp/typeck.c | 9 ++++-
gcc/testsuite/g++.dg/pr84943-2.C | 64 ++++++++++++++++++++++++++++++++++++++
gcc/testsuite/g++.dg/pr84943.C | 8 +++++
3 files changed, 79 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/pr84943-2.C
create mode 100644 gcc/testsuite/g++.dg/pr84943.C
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index d454c6c5a295..bdb2bb30a583 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5801,7 +5801,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
and the created OFFSET_REF. */
tree base = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (arg, 0)));
tree fn = get_first_fn (TREE_OPERAND (arg, 1));
- if (!mark_used (fn, complain) && !(complain & tf_error))
+ if (!(complain & tf_conv)
+ && !mark_used (fn, complain) && !(complain & tf_error))
return error_mark_node;
if (! flag_ms_extensions)
@@ -5971,6 +5972,9 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
so we can just form an ADDR_EXPR with the correct type. */
if (processing_template_decl || TREE_CODE (arg) != COMPONENT_REF)
{
+ if (TREE_CODE (arg) == FUNCTION_DECL && !(complain & tf_conv)
+ && !mark_used (arg, complain) && !(complain & tf_error))
+ return error_mark_node;
val = build_address (arg);
if (TREE_CODE (arg) == OFFSET_REF)
PTRMEM_OK_P (val) = PTRMEM_OK_P (arg);
@@ -5983,7 +5987,8 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
function. */
gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
&& DECL_STATIC_FUNCTION_P (fn));
- if (!mark_used (fn, complain) && !(complain & tf_error))
+ if (!(complain & tf_conv)
+ && !mark_used (fn, complain) && !(complain & tf_error))
return error_mark_node;
val = build_address (fn);
if (TREE_SIDE_EFFECTS (TREE_OPERAND (arg, 0)))
diff --git a/gcc/testsuite/g++.dg/pr84943-2.C b/gcc/testsuite/g++.dg/pr84943-2.C
new file mode 100644
index 000000000000..d1ef012b9155
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr84943-2.C
@@ -0,0 +1,64 @@
+// { dg-do run }
+
+// Avoid -pedantic-error default
+// { dg-options "" }
+
+// Make sure the functions referenced by various forms of
+// address-taking are marked as used and compiled in.
+
+static void ac() {}
+void a() {
+ ac[0](); // { dg-warning "arithmetic" }
+}
+
+static void bc() {}
+void b() {
+ (&*&*&*&bc)();
+}
+
+template <typename U> U cc() {}
+void (*c())() {
+ return cc;
+}
+
+template <typename T>
+struct x {
+ void a(int);
+ template <typename U> static U a(x*) {}
+ static void a(long) {}
+ static void a(void *) {}
+ static void a() {
+ void (*p0)(void*) = x().a;
+ p0(0);
+ void (*p1)(long) = a;
+ p1(0);
+ void (*p2)() = a;
+ p2();
+ void (*p3)(x*) = a;
+ p3(0);
+ }
+};
+
+struct z {
+ void a(int);
+ template <typename U> static U a(z*) {}
+ static void a(long) {}
+ static void a(void *) {}
+ static void a() {
+ void (*p0)(void*) = z().a;
+ p0(0);
+ void (*p1)(long) = a;
+ p1(0);
+ void (*p2)() = a;
+ p2();
+ void (*p3)(z*) = a;
+ p3(0);
+ }
+};
+
+int main(int argc, char *argv[]) {
+ if (argc > 1) {
+ x<void>().a();
+ z().a();
+ }
+}
diff --git a/gcc/testsuite/g++.dg/pr84943.C b/gcc/testsuite/g++.dg/pr84943.C
new file mode 100644
index 000000000000..36f75a164119
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr84943.C
@@ -0,0 +1,8 @@
+// { dg-do compile }
+
+// Avoid -pedantic-error default
+// { dg-options "" }
+
+void a() {
+ a[0](); // { dg-warning "arithmetic" }
+}
--
Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer
next prev parent reply other threads:[~2018-03-31 6:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-22 23:03 Alexandre Oliva
2018-03-23 13:12 ` Jason Merrill
2018-03-23 16:19 ` Alexandre Oliva
2018-03-23 16:45 ` Jason Merrill
2018-03-23 20:59 ` Jason Merrill
2018-03-23 22:04 ` Jason Merrill
2018-03-28 6:31 ` Alexandre Oliva
2018-03-28 19:21 ` Jason Merrill
2018-03-30 1:07 ` Alexandre Oliva
2018-03-30 2:31 ` Alexandre Oliva
2018-03-30 7:49 ` Alexandre Oliva
2018-03-30 14:46 ` Jason Merrill
2018-03-31 8:23 ` Alexandre Oliva [this message]
2018-04-03 1:17 ` Jason Merrill
2018-04-03 7:44 ` Alexandre Oliva
2018-04-03 15:48 ` Jason Merrill
2018-04-03 15:48 ` Jason Merrill
2018-04-04 2:41 ` Alexandre Oliva
2018-03-23 20:55 ` Alexandre Oliva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ord0zkzrs1.fsf@lxoliva.fsfla.org \
--to=aoliva@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=nathan@acm.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).