* [PATCH] c++: Crash when deducing template arguments [PR98659]
@ 2021-01-13 18:38 Marek Polacek
2021-01-19 20:41 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2021-01-13 18:38 UTC (permalink / raw)
To: GCC Patches, Jason Merrill
maybe_instantiate_noexcept doesn't expect to see error_mark_node, so
the new callsite I introduced in r11-6476 needs to be properly guarded.
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
gcc/cp/ChangeLog:
PR c++/98659
* pt.c (resolve_overloaded_unification): Don't call
maybe_instantiate_noexcept with error_mark_node.
gcc/testsuite/ChangeLog:
PR c++/98659
* g++.dg/template/deduce8.C: New test.
---
gcc/cp/pt.c | 2 +-
gcc/testsuite/g++.dg/template/deduce8.C | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/template/deduce8.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 100c35f053c..83ecb0a2c3a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -22382,7 +22382,7 @@ resolve_overloaded_unification (tree tparms,
--function_depth;
}
- if (flag_noexcept_type)
+ if (flag_noexcept_type && fn != error_mark_node)
maybe_instantiate_noexcept (fn, tf_none);
elem = TREE_TYPE (fn);
diff --git a/gcc/testsuite/g++.dg/template/deduce8.C b/gcc/testsuite/g++.dg/template/deduce8.C
new file mode 100644
index 00000000000..430be426689
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/deduce8.C
@@ -0,0 +1,21 @@
+// PR c++/98659
+// { dg-do compile }
+
+template <bool> struct enable_if;
+struct function {
+ template <typename _F> void operator=(_F);
+};
+struct map {
+ function operator[](int);
+};
+enum { E };
+template <typename> void foo ();
+template <typename T>
+typename enable_if<T::value>::type foo ();
+
+void
+bar ()
+{
+ map m;
+ m[E] = foo<int>;
+}
base-commit: 7d7ef413ef1b696dec2710ae0acc058bdc832686
--
2.29.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++: Crash when deducing template arguments [PR98659]
2021-01-13 18:38 [PATCH] c++: Crash when deducing template arguments [PR98659] Marek Polacek
@ 2021-01-19 20:41 ` Jason Merrill
2021-01-19 21:09 ` [PATCH v2] " Marek Polacek
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2021-01-19 20:41 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 1/13/21 1:38 PM, Marek Polacek wrote:
> maybe_instantiate_noexcept doesn't expect to see error_mark_node, so
> the new callsite I introduced in r11-6476 needs to be properly guarded.
I'd rather fix maybe_instantiate_noexcept to deal with error_mark_node.
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> gcc/cp/ChangeLog:
>
> PR c++/98659
> * pt.c (resolve_overloaded_unification): Don't call
> maybe_instantiate_noexcept with error_mark_node.
>
> gcc/testsuite/ChangeLog:
>
> PR c++/98659
> * g++.dg/template/deduce8.C: New test.
> ---
> gcc/cp/pt.c | 2 +-
> gcc/testsuite/g++.dg/template/deduce8.C | 21 +++++++++++++++++++++
> 2 files changed, 22 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/template/deduce8.C
>
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 100c35f053c..83ecb0a2c3a 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -22382,7 +22382,7 @@ resolve_overloaded_unification (tree tparms,
> --function_depth;
> }
>
> - if (flag_noexcept_type)
> + if (flag_noexcept_type && fn != error_mark_node)
> maybe_instantiate_noexcept (fn, tf_none);
>
> elem = TREE_TYPE (fn);
> diff --git a/gcc/testsuite/g++.dg/template/deduce8.C b/gcc/testsuite/g++.dg/template/deduce8.C
> new file mode 100644
> index 00000000000..430be426689
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/deduce8.C
> @@ -0,0 +1,21 @@
> +// PR c++/98659
> +// { dg-do compile }
> +
> +template <bool> struct enable_if;
> +struct function {
> + template <typename _F> void operator=(_F);
> +};
> +struct map {
> + function operator[](int);
> +};
> +enum { E };
> +template <typename> void foo ();
> +template <typename T>
> +typename enable_if<T::value>::type foo ();
> +
> +void
> +bar ()
> +{
> + map m;
> + m[E] = foo<int>;
> +}
>
> base-commit: 7d7ef413ef1b696dec2710ae0acc058bdc832686
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] c++: Crash when deducing template arguments [PR98659]
2021-01-19 20:41 ` Jason Merrill
@ 2021-01-19 21:09 ` Marek Polacek
2021-01-19 21:12 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2021-01-19 21:09 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
On Tue, Jan 19, 2021 at 03:41:57PM -0500, Jason Merrill wrote:
> On 1/13/21 1:38 PM, Marek Polacek wrote:
> > maybe_instantiate_noexcept doesn't expect to see error_mark_node, so
> > the new callsite I introduced in r11-6476 needs to be properly guarded.
>
> I'd rather fix maybe_instantiate_noexcept to deal with error_mark_node.
Ok, here's v2. I've checked all maybe_instantiate_noexcept calls to see
if they don't need to be guarded by != error_mark_node anymore but found
none.
Ok for trunk if the usual testing passes?
-- >8 --
maybe_instantiate_noexcept doesn't expect to see error_mark_node, but
the new callsite I introduced in r11-6476 can pass error_mark_node to
it. So cope.
gcc/cp/ChangeLog:
PR c++/98659
* pt.c (maybe_instantiate_noexcept): Return false if FN is
error_mark_node.
gcc/testsuite/ChangeLog:
PR c++/98659
* g++.dg/template/deduce8.C: New test.
---
gcc/cp/pt.c | 9 +++++----
gcc/testsuite/g++.dg/template/deduce8.C | 21 +++++++++++++++++++++
2 files changed, 26 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/template/deduce8.C
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 957140115e4..aa7a155815a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -25456,7 +25456,8 @@ always_instantiate_p (tree decl)
bool
maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain)
{
- tree fntype, spec, noex;
+ if (fn == error_mark_node)
+ return false;
/* Don't instantiate a noexcept-specification from template context. */
if (processing_template_decl
@@ -25475,13 +25476,13 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain)
return !DECL_MAYBE_DELETED (fn);
}
- fntype = TREE_TYPE (fn);
- spec = TYPE_RAISES_EXCEPTIONS (fntype);
+ tree fntype = TREE_TYPE (fn);
+ tree spec = TYPE_RAISES_EXCEPTIONS (fntype);
if (!spec || !TREE_PURPOSE (spec))
return true;
- noex = TREE_PURPOSE (spec);
+ tree noex = TREE_PURPOSE (spec);
if (TREE_CODE (noex) != DEFERRED_NOEXCEPT
&& TREE_CODE (noex) != DEFERRED_PARSE)
return true;
diff --git a/gcc/testsuite/g++.dg/template/deduce8.C b/gcc/testsuite/g++.dg/template/deduce8.C
new file mode 100644
index 00000000000..430be426689
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/deduce8.C
@@ -0,0 +1,21 @@
+// PR c++/98659
+// { dg-do compile }
+
+template <bool> struct enable_if;
+struct function {
+ template <typename _F> void operator=(_F);
+};
+struct map {
+ function operator[](int);
+};
+enum { E };
+template <typename> void foo ();
+template <typename T>
+typename enable_if<T::value>::type foo ();
+
+void
+bar ()
+{
+ map m;
+ m[E] = foo<int>;
+}
base-commit: c37f1d4081f5a19e39192d13e2a3acea13662e5a
--
2.29.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] c++: Crash when deducing template arguments [PR98659]
2021-01-19 21:09 ` [PATCH v2] " Marek Polacek
@ 2021-01-19 21:12 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2021-01-19 21:12 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On 1/19/21 4:09 PM, Marek Polacek wrote:
> On Tue, Jan 19, 2021 at 03:41:57PM -0500, Jason Merrill wrote:
>> On 1/13/21 1:38 PM, Marek Polacek wrote:
>>> maybe_instantiate_noexcept doesn't expect to see error_mark_node, so
>>> the new callsite I introduced in r11-6476 needs to be properly guarded.
>>
>> I'd rather fix maybe_instantiate_noexcept to deal with error_mark_node.
>
> Ok, here's v2. I've checked all maybe_instantiate_noexcept calls to see
> if they don't need to be guarded by != error_mark_node anymore but found
> none.
>
> Ok for trunk if the usual testing passes?
OK.
> -- >8 --
> maybe_instantiate_noexcept doesn't expect to see error_mark_node, but
> the new callsite I introduced in r11-6476 can pass error_mark_node to
> it. So cope.
>
> gcc/cp/ChangeLog:
>
> PR c++/98659
> * pt.c (maybe_instantiate_noexcept): Return false if FN is
> error_mark_node.
>
> gcc/testsuite/ChangeLog:
>
> PR c++/98659
> * g++.dg/template/deduce8.C: New test.
> ---
> gcc/cp/pt.c | 9 +++++----
> gcc/testsuite/g++.dg/template/deduce8.C | 21 +++++++++++++++++++++
> 2 files changed, 26 insertions(+), 4 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/template/deduce8.C
>
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index 957140115e4..aa7a155815a 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -25456,7 +25456,8 @@ always_instantiate_p (tree decl)
> bool
> maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain)
> {
> - tree fntype, spec, noex;
> + if (fn == error_mark_node)
> + return false;
>
> /* Don't instantiate a noexcept-specification from template context. */
> if (processing_template_decl
> @@ -25475,13 +25476,13 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain)
> return !DECL_MAYBE_DELETED (fn);
> }
>
> - fntype = TREE_TYPE (fn);
> - spec = TYPE_RAISES_EXCEPTIONS (fntype);
> + tree fntype = TREE_TYPE (fn);
> + tree spec = TYPE_RAISES_EXCEPTIONS (fntype);
>
> if (!spec || !TREE_PURPOSE (spec))
> return true;
>
> - noex = TREE_PURPOSE (spec);
> + tree noex = TREE_PURPOSE (spec);
> if (TREE_CODE (noex) != DEFERRED_NOEXCEPT
> && TREE_CODE (noex) != DEFERRED_PARSE)
> return true;
> diff --git a/gcc/testsuite/g++.dg/template/deduce8.C b/gcc/testsuite/g++.dg/template/deduce8.C
> new file mode 100644
> index 00000000000..430be426689
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/deduce8.C
> @@ -0,0 +1,21 @@
> +// PR c++/98659
> +// { dg-do compile }
> +
> +template <bool> struct enable_if;
> +struct function {
> + template <typename _F> void operator=(_F);
> +};
> +struct map {
> + function operator[](int);
> +};
> +enum { E };
> +template <typename> void foo ();
> +template <typename T>
> +typename enable_if<T::value>::type foo ();
> +
> +void
> +bar ()
> +{
> + map m;
> + m[E] = foo<int>;
> +}
>
> base-commit: c37f1d4081f5a19e39192d13e2a3acea13662e5a
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-01-19 21:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 18:38 [PATCH] c++: Crash when deducing template arguments [PR98659] Marek Polacek
2021-01-19 20:41 ` Jason Merrill
2021-01-19 21:09 ` [PATCH v2] " Marek Polacek
2021-01-19 21:12 ` Jason Merrill
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).