* [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node
@ 2023-10-15 1:16 Andrew Pinski
2023-10-15 1:16 ` [PATCH 2/2] [c] Fix PR 101364: ICE after error due to diagnose_arglist_conflict not checking for error Andrew Pinski
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Andrew Pinski @ 2023-10-15 1:16 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
This is a simple error recovery issue when c_safe_arg_type_equiv_p
was added in r8-5312-gc65e18d3331aa999. The issue is that after
an error, an argument type (of a function type) might turn
into an error mark node and c_safe_arg_type_equiv_p was not ready
for that. So this just adds a check for error operand for its
arguments before getting the main variant.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
PR c/101285
gcc/c/ChangeLog:
* c-typeck.cc (c_safe_arg_type_equiv_p): Return true for error
operands early.
gcc/testsuite/ChangeLog:
* gcc.dg/pr101285-1.c: New test.
---
gcc/c/c-typeck.cc | 3 +++
gcc/testsuite/gcc.dg/pr101285-1.c | 10 ++++++++++
2 files changed, 13 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/pr101285-1.c
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index e55e887da14..6e044b4afbc 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -5960,6 +5960,9 @@ handle_warn_cast_qual (location_t loc, tree type, tree otype)
static bool
c_safe_arg_type_equiv_p (tree t1, tree t2)
{
+ if (error_operand_p (t1) || error_operand_p (t2))
+ return true;
+
t1 = TYPE_MAIN_VARIANT (t1);
t2 = TYPE_MAIN_VARIANT (t2);
diff --git a/gcc/testsuite/gcc.dg/pr101285-1.c b/gcc/testsuite/gcc.dg/pr101285-1.c
new file mode 100644
index 00000000000..831e35f7662
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr101285-1.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-W -Wall" } */
+const int b;
+typedef void (*ft1)(int[b++]); /* { dg-error "read-only variable" } */
+void bar(int * z);
+void baz()
+{
+ (ft1) bar; /* { dg-warning "statement with no effect" } */
+}
+
--
2.39.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] [c] Fix PR 101364: ICE after error due to diagnose_arglist_conflict not checking for error
2023-10-15 1:16 [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node Andrew Pinski
@ 2023-10-15 1:16 ` Andrew Pinski
2023-10-16 21:38 ` Joseph Myers
2023-10-16 21:38 ` [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node Joseph Myers
2023-10-16 21:40 ` Marek Polacek
2 siblings, 1 reply; 5+ messages in thread
From: Andrew Pinski @ 2023-10-15 1:16 UTC (permalink / raw)
To: gcc-patches; +Cc: Andrew Pinski
When checking to see if we have a function declaration has a conflict due to
promotations, there is no test to see if the type was an error mark and then calls
c_type_promotes_to. c_type_promotes_to is not ready for error_mark and causes an
ICE.
This adds a check for error before the call of c_type_promotes_to.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
PR c/101364
gcc/c/ChangeLog:
* c-decl.cc (diagnose_arglist_conflict): Test for
error mark before calling of c_type_promotes_to.
gcc/testsuite/ChangeLog:
* gcc.dg/pr101364-1.c: New test.
---
gcc/c/c-decl.cc | 3 ++-
gcc/testsuite/gcc.dg/pr101364-1.c | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/pr101364-1.c
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 5822faf01b4..eb2df08c0a7 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -1899,7 +1899,8 @@ diagnose_arglist_conflict (tree newdecl, tree olddecl,
break;
}
- if (c_type_promotes_to (type) != type)
+ if (!error_operand_p (type)
+ && c_type_promotes_to (type) != type)
{
inform (input_location, "an argument type that has a default "
"promotion cannot match an empty parameter name list "
diff --git a/gcc/testsuite/gcc.dg/pr101364-1.c b/gcc/testsuite/gcc.dg/pr101364-1.c
new file mode 100644
index 00000000000..e7c94a05553
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr101364-1.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c90 "} */
+
+void fruit(); /* { dg-message "previous declaration" } */
+void fruit( /* { dg-error "conflicting types for" } */
+ int b[x], /* { dg-error "undeclared " } */
+ short c)
+{} /* { dg-message "an argument type that has a" } */
--
2.39.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node
2023-10-15 1:16 [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node Andrew Pinski
2023-10-15 1:16 ` [PATCH 2/2] [c] Fix PR 101364: ICE after error due to diagnose_arglist_conflict not checking for error Andrew Pinski
@ 2023-10-16 21:38 ` Joseph Myers
2023-10-16 21:40 ` Marek Polacek
2 siblings, 0 replies; 5+ messages in thread
From: Joseph Myers @ 2023-10-16 21:38 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches
On Sat, 14 Oct 2023, Andrew Pinski wrote:
> This is a simple error recovery issue when c_safe_arg_type_equiv_p
> was added in r8-5312-gc65e18d3331aa999. The issue is that after
> an error, an argument type (of a function type) might turn
> into an error mark node and c_safe_arg_type_equiv_p was not ready
> for that. So this just adds a check for error operand for its
> arguments before getting the main variant.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
OK.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node
2023-10-15 1:16 [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node Andrew Pinski
2023-10-15 1:16 ` [PATCH 2/2] [c] Fix PR 101364: ICE after error due to diagnose_arglist_conflict not checking for error Andrew Pinski
2023-10-16 21:38 ` [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node Joseph Myers
@ 2023-10-16 21:40 ` Marek Polacek
2 siblings, 0 replies; 5+ messages in thread
From: Marek Polacek @ 2023-10-16 21:40 UTC (permalink / raw)
To: Andrew Pinski; +Cc: gcc-patches
On Sat, Oct 14, 2023 at 06:16:47PM -0700, Andrew Pinski wrote:
> This is a simple error recovery issue when c_safe_arg_type_equiv_p
> was added in r8-5312-gc65e18d3331aa999. The issue is that after
> an error, an argument type (of a function type) might turn
> into an error mark node and c_safe_arg_type_equiv_p was not ready
> for that. So this just adds a check for error operand for its
> arguments before getting the main variant.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
Please don't include this line in the commit message.
> PR c/101285
>
> gcc/c/ChangeLog:
>
> * c-typeck.cc (c_safe_arg_type_equiv_p): Return true for error
> operands early.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/pr101285-1.c: New test.
> ---
> gcc/c/c-typeck.cc | 3 +++
> gcc/testsuite/gcc.dg/pr101285-1.c | 10 ++++++++++
> 2 files changed, 13 insertions(+)
> create mode 100644 gcc/testsuite/gcc.dg/pr101285-1.c
>
> diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
> index e55e887da14..6e044b4afbc 100644
> --- a/gcc/c/c-typeck.cc
> +++ b/gcc/c/c-typeck.cc
> @@ -5960,6 +5960,9 @@ handle_warn_cast_qual (location_t loc, tree type, tree otype)
> static bool
> c_safe_arg_type_equiv_p (tree t1, tree t2)
> {
> + if (error_operand_p (t1) || error_operand_p (t2))
> + return true;
I thought it would be more natural to return false but that would result in:
cast between incompatible function types from 'void (*)(int *)' to 'void (*)(<type-error>)'
but we don't want that so pretending the cast is safe is probably better.
> t1 = TYPE_MAIN_VARIANT (t1);
> t2 = TYPE_MAIN_VARIANT (t2);
>
> diff --git a/gcc/testsuite/gcc.dg/pr101285-1.c b/gcc/testsuite/gcc.dg/pr101285-1.c
> new file mode 100644
> index 00000000000..831e35f7662
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr101285-1.c
> @@ -0,0 +1,10 @@
Let's put
/* PR c/101285 */
here.
> +/* { dg-do compile } */
> +/* { dg-options "-W -Wall" } */
> +const int b;
> +typedef void (*ft1)(int[b++]); /* { dg-error "read-only variable" } */
> +void bar(int * z);
> +void baz()
> +{
> + (ft1) bar; /* { dg-warning "statement with no effect" } */
> +}
> +
Extra newline.
Thanks,
Marek
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-16 21:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-15 1:16 [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node Andrew Pinski
2023-10-15 1:16 ` [PATCH 2/2] [c] Fix PR 101364: ICE after error due to diagnose_arglist_conflict not checking for error Andrew Pinski
2023-10-16 21:38 ` Joseph Myers
2023-10-16 21:38 ` [PATCH 1/2] Fix ICE due to c_safe_arg_type_equiv_p not checking for error_mark node Joseph Myers
2023-10-16 21:40 ` Marek Polacek
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).