* [PATCH] c++: ICE with -Wlogical-op [PR107755]
@ 2023-01-31 20:41 Marek Polacek
2023-01-31 22:48 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2023-01-31 20:41 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
Here we crash in the middle end because warn_logical_operator calls
build_range_check which calls various fold_* functions and those
don't work too well when we're still processing template trees. For
instance here we crash because we're converting a RECORD_TYPE to bool.
At this point VIEW_CONVERT_EXPR<struct Foo>(b) hasn't yet been converted
to Foo::operator bool (&b).
I was excited to fix this with instantiation_dependent_expression_p
which can now be called from c-family/ as well, but the problem isn't
that the expression is dependent. So, p_t_d it is.
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
PR c++/107755
gcc/cp/ChangeLog:
* call.cc (build_new_op): Don't call warn_logical_operator when
processing a template.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wlogical-op-4.C: New test.
---
gcc/cp/call.cc | 2 +-
gcc/testsuite/g++.dg/warn/Wlogical-op-4.C | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
index 5715a7cd1de..f7c5d9da94b 100644
--- a/gcc/cp/call.cc
+++ b/gcc/cp/call.cc
@@ -7335,7 +7335,7 @@ build_new_op (const op_location_t &loc, enum tree_code code, int flags,
case TRUTH_ORIF_EXPR:
case TRUTH_AND_EXPR:
case TRUTH_OR_EXPR:
- if (complain & tf_warning)
+ if ((complain & tf_warning) && !processing_template_decl)
warn_logical_operator (loc, code, boolean_type_node,
code_orig_arg1, arg1,
code_orig_arg2, arg2);
diff --git a/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
new file mode 100644
index 00000000000..745c9117a3d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
@@ -0,0 +1,23 @@
+// PR c++/107755
+// { dg-do compile }
+// { dg-options "-Wlogical-op" }
+
+struct Foo
+{
+ operator bool() const { return false; }
+};
+
+bool a;
+Foo b;
+
+template <typename ignored>
+static bool Bar()
+{
+ return (true && (false ? a : b));
+ return (false || (false ? a : b));
+}
+
+bool Baz()
+{
+ return Bar<void>();
+}
base-commit: b2ec2504af77b35e748067eeb846821d12a6b6b4
--
2.39.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: ICE with -Wlogical-op [PR107755]
2023-01-31 20:41 [PATCH] c++: ICE with -Wlogical-op [PR107755] Marek Polacek
@ 2023-01-31 22:48 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-01-31 22:48 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 1/31/23 15:41, Marek Polacek wrote:
> Here we crash in the middle end because warn_logical_operator calls
> build_range_check which calls various fold_* functions and those
> don't work too well when we're still processing template trees. For
> instance here we crash because we're converting a RECORD_TYPE to bool.
> At this point VIEW_CONVERT_EXPR<struct Foo>(b) hasn't yet been converted
> to Foo::operator bool (&b).
>
> I was excited to fix this with instantiation_dependent_expression_p
> which can now be called from c-family/ as well, but the problem isn't
> that the expression is dependent. So, p_t_d it is.
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
OK.
> PR c++/107755
>
> gcc/cp/ChangeLog:
>
> * call.cc (build_new_op): Don't call warn_logical_operator when
> processing a template.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/warn/Wlogical-op-4.C: New test.
> ---
> gcc/cp/call.cc | 2 +-
> gcc/testsuite/g++.dg/warn/Wlogical-op-4.C | 23 +++++++++++++++++++++++
> 2 files changed, 24 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
>
> diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc
> index 5715a7cd1de..f7c5d9da94b 100644
> --- a/gcc/cp/call.cc
> +++ b/gcc/cp/call.cc
> @@ -7335,7 +7335,7 @@ build_new_op (const op_location_t &loc, enum tree_code code, int flags,
> case TRUTH_ORIF_EXPR:
> case TRUTH_AND_EXPR:
> case TRUTH_OR_EXPR:
> - if (complain & tf_warning)
> + if ((complain & tf_warning) && !processing_template_decl)
> warn_logical_operator (loc, code, boolean_type_node,
> code_orig_arg1, arg1,
> code_orig_arg2, arg2);
> diff --git a/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
> new file mode 100644
> index 00000000000..745c9117a3d
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/warn/Wlogical-op-4.C
> @@ -0,0 +1,23 @@
> +// PR c++/107755
> +// { dg-do compile }
> +// { dg-options "-Wlogical-op" }
> +
> +struct Foo
> +{
> + operator bool() const { return false; }
> +};
> +
> +bool a;
> +Foo b;
> +
> +template <typename ignored>
> +static bool Bar()
> +{
> + return (true && (false ? a : b));
> + return (false || (false ? a : b));
> +}
> +
> +bool Baz()
> +{
> + return Bar<void>();
> +}
>
> base-commit: b2ec2504af77b35e748067eeb846821d12a6b6b4
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-31 22:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 20:41 [PATCH] c++: ICE with -Wlogical-op [PR107755] Marek Polacek
2023-01-31 22:48 ` 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).