* C PATCH to fix c/79758 (ICE-on-invalid with function redefinition and old style decls)
@ 2017-03-02 17:35 Marek Polacek
2017-03-02 19:48 ` Bernd Schmidt
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2017-03-02 17:35 UTC (permalink / raw)
To: GCC Patches, Joseph Myers
This patch fixes an ICE-on-invalid where we redefine a function whose prototype
parameter list contains error_mark_node, which then causes a crash in
store_parm_decls_oldstyle. Fixed by adding yet another error_mark_node check.
While at it, I fixed wrong formatting in the nearby code. Also use NULL_TREE
instead of 0 where appropriate. I really dislike those zeros-as-trees; one
day I'll just go and turn them into NULL_TREEs.
I also fixed missing TREE_VALUE (), which is what I think was intended there.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2017-03-02 Marek Polacek <polacek@redhat.com>
PR c/79758
* c-decl.c (store_parm_decls_oldstyle): Check if the element of
current_function_prototype_arg_types is error_mark_node. Fix
formatting. Add TREE_VALUE.
* gcc.dg/noncompile/pr79758.c: New test.
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 32edacc..e3bf898 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -8965,12 +8965,15 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
tree type;
for (parm = DECL_ARGUMENTS (fndecl),
type = current_function_prototype_arg_types;
- parm || (type && TREE_VALUE (type) != error_mark_node
- && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node));
+ parm || (type != NULL_TREE
+ && TREE_VALUE (type) != error_mark_node
+ && TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node);
parm = DECL_CHAIN (parm), type = TREE_CHAIN (type))
{
- if (parm == 0 || type == 0
- || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
+ if (parm == NULL_TREE
+ || type == NULL_TREE
+ || (TREE_VALUE (type) != error_mark_node
+ && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node))
{
if (current_function_prototype_built_in)
warning_at (DECL_SOURCE_LOCATION (fndecl),
@@ -8996,7 +8999,7 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
declared for the arg. ISO C says we take the unqualified
type for parameters declared with qualified type. */
if (TREE_TYPE (parm) != error_mark_node
- && TREE_TYPE (type) != error_mark_node
+ && TREE_TYPE (TREE_VALUE (type)) != error_mark_node
&& ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
!= TYPE_ATOMIC (TREE_VALUE (type)))
|| !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
@@ -9017,7 +9020,7 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
&& INTEGRAL_TYPE_P (TREE_TYPE (parm))
&& TYPE_PRECISION (TREE_TYPE (parm))
- < TYPE_PRECISION (integer_type_node))
+ < TYPE_PRECISION (integer_type_node))
DECL_ARG_TYPE (parm)
= c_type_promotes_to (TREE_TYPE (parm));
diff --git gcc/testsuite/gcc.dg/noncompile/pr79758.c gcc/testsuite/gcc.dg/noncompile/pr79758.c
index e69de29..aeaf7c7 100644
--- gcc/testsuite/gcc.dg/noncompile/pr79758.c
+++ gcc/testsuite/gcc.dg/noncompile/pr79758.c
@@ -0,0 +1,6 @@
+/* PR c/79758 */
+/* { dg-do compile } */
+
+void fn1 (int[a]) { }; /* { dg-error "undeclared here|parameter name omitted" } */
+void fn1 (b) { }; /* { dg-error "redefinition" } */
+/* { dg-warning "defaults to 'int'" "" { target *-*-* } .-1 } */
Marek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: C PATCH to fix c/79758 (ICE-on-invalid with function redefinition and old style decls)
2017-03-02 17:35 C PATCH to fix c/79758 (ICE-on-invalid with function redefinition and old style decls) Marek Polacek
@ 2017-03-02 19:48 ` Bernd Schmidt
2017-03-03 13:33 ` Marek Polacek
0 siblings, 1 reply; 4+ messages in thread
From: Bernd Schmidt @ 2017-03-02 19:48 UTC (permalink / raw)
To: Marek Polacek, GCC Patches, Joseph Myers
On 03/02/2017 06:35 PM, Marek Polacek wrote:
> While at it, I fixed wrong formatting in the nearby code. Also use NULL_TREE
> instead of 0 where appropriate. I really dislike those zeros-as-trees; one
> day I'll just go and turn them into NULL_TREEs.
I sympathize, but it makes it harder to see which parts of the patch are
actual changes. Generally it's best to separate functional and
formatting changes.
> @@ -8996,7 +8999,7 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
> declared for the arg. ISO C says we take the unqualified
> type for parameters declared with qualified type. */
> if (TREE_TYPE (parm) != error_mark_node
> - && TREE_TYPE (type) != error_mark_node
> + && TREE_TYPE (TREE_VALUE (type)) != error_mark_node
> && ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
> != TYPE_ATOMIC (TREE_VALUE (type)))
> || !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
Isn't this most likely intended to be TREE_VALUE (type) != error_mark_node?
> @@ -9017,7 +9020,7 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
> if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
> && INTEGRAL_TYPE_P (TREE_TYPE (parm))
> && TYPE_PRECISION (TREE_TYPE (parm))
> - < TYPE_PRECISION (integer_type_node))
> + < TYPE_PRECISION (integer_type_node))
Should add the necessary parens while fixing formatting.
Bernd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: C PATCH to fix c/79758 (ICE-on-invalid with function redefinition and old style decls)
2017-03-02 19:48 ` Bernd Schmidt
@ 2017-03-03 13:33 ` Marek Polacek
2017-03-03 18:57 ` Bernd Schmidt
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2017-03-03 13:33 UTC (permalink / raw)
To: Bernd Schmidt; +Cc: GCC Patches, Joseph Myers
On Thu, Mar 02, 2017 at 08:47:57PM +0100, Bernd Schmidt wrote:
> On 03/02/2017 06:35 PM, Marek Polacek wrote:
> > While at it, I fixed wrong formatting in the nearby code. Also use NULL_TREE
> > instead of 0 where appropriate. I really dislike those zeros-as-trees; one
> > day I'll just go and turn them into NULL_TREEs.
>
> I sympathize, but it makes it harder to see which parts of the patch are
> actual changes. Generally it's best to separate functional and formatting
> changes.
True, but I though I'd do it anyway while I'm changing the very same if;
formatting fixes along with actual fixes are not that rare.
> > @@ -8996,7 +8999,7 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
> > declared for the arg. ISO C says we take the unqualified
> > type for parameters declared with qualified type. */
> > if (TREE_TYPE (parm) != error_mark_node
> > - && TREE_TYPE (type) != error_mark_node
> > + && TREE_TYPE (TREE_VALUE (type)) != error_mark_node
> > && ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
> > != TYPE_ATOMIC (TREE_VALUE (type)))
> > || !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
>
> Isn't this most likely intended to be TREE_VALUE (type) != error_mark_node?
Yea, that's what I had in mind but goofed.
> > @@ -9017,7 +9020,7 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
> > if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
> > && INTEGRAL_TYPE_P (TREE_TYPE (parm))
> > && TYPE_PRECISION (TREE_TYPE (parm))
> > - < TYPE_PRECISION (integer_type_node))
> > + < TYPE_PRECISION (integer_type_node))
>
> Should add the necessary parens while fixing formatting.
Dunno if they're necessary here, but I added them.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2017-03-03 Marek Polacek <polacek@redhat.com>
PR c/79758
* c-decl.c (store_parm_decls_oldstyle): Check if the element of
current_function_prototype_arg_types is error_mark_node. Fix
formatting. Use TREE_VALUE instead of TREE_TYPE.
* gcc.dg/noncompile/pr79758.c: New test.
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 32edacc..f46ca11 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -8965,12 +8965,15 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
tree type;
for (parm = DECL_ARGUMENTS (fndecl),
type = current_function_prototype_arg_types;
- parm || (type && TREE_VALUE (type) != error_mark_node
- && (TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node));
+ parm || (type != NULL_TREE
+ && TREE_VALUE (type) != error_mark_node
+ && TYPE_MAIN_VARIANT (TREE_VALUE (type)) != void_type_node);
parm = DECL_CHAIN (parm), type = TREE_CHAIN (type))
{
- if (parm == 0 || type == 0
- || TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node)
+ if (parm == NULL_TREE
+ || type == NULL_TREE
+ || (TREE_VALUE (type) != error_mark_node
+ && TYPE_MAIN_VARIANT (TREE_VALUE (type)) == void_type_node))
{
if (current_function_prototype_built_in)
warning_at (DECL_SOURCE_LOCATION (fndecl),
@@ -8996,7 +8999,7 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
declared for the arg. ISO C says we take the unqualified
type for parameters declared with qualified type. */
if (TREE_TYPE (parm) != error_mark_node
- && TREE_TYPE (type) != error_mark_node
+ && TREE_VALUE (type) != error_mark_node
&& ((TYPE_ATOMIC (DECL_ARG_TYPE (parm))
!= TYPE_ATOMIC (TREE_VALUE (type)))
|| !comptypes (TYPE_MAIN_VARIANT (DECL_ARG_TYPE (parm)),
@@ -9016,8 +9019,8 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
if (targetm.calls.promote_prototypes (TREE_TYPE (current_function_decl))
&& INTEGRAL_TYPE_P (TREE_TYPE (parm))
- && TYPE_PRECISION (TREE_TYPE (parm))
- < TYPE_PRECISION (integer_type_node))
+ && (TYPE_PRECISION (TREE_TYPE (parm))
+ < TYPE_PRECISION (integer_type_node)))
DECL_ARG_TYPE (parm)
= c_type_promotes_to (TREE_TYPE (parm));
diff --git gcc/testsuite/gcc.dg/noncompile/pr79758.c gcc/testsuite/gcc.dg/noncompile/pr79758.c
index e69de29..aeaf7c7 100644
--- gcc/testsuite/gcc.dg/noncompile/pr79758.c
+++ gcc/testsuite/gcc.dg/noncompile/pr79758.c
@@ -0,0 +1,6 @@
+/* PR c/79758 */
+/* { dg-do compile } */
+
+void fn1 (int[a]) { }; /* { dg-error "undeclared here|parameter name omitted" } */
+void fn1 (b) { }; /* { dg-error "redefinition" } */
+/* { dg-warning "defaults to 'int'" "" { target *-*-* } .-1 } */
Marek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: C PATCH to fix c/79758 (ICE-on-invalid with function redefinition and old style decls)
2017-03-03 13:33 ` Marek Polacek
@ 2017-03-03 18:57 ` Bernd Schmidt
0 siblings, 0 replies; 4+ messages in thread
From: Bernd Schmidt @ 2017-03-03 18:57 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches, Joseph Myers
On 03/03/2017 02:33 PM, Marek Polacek wrote:
>
> 2017-03-03 Marek Polacek <polacek@redhat.com>
>
> PR c/79758
> * c-decl.c (store_parm_decls_oldstyle): Check if the element of
> current_function_prototype_arg_types is error_mark_node. Fix
> formatting. Use TREE_VALUE instead of TREE_TYPE.
>
> * gcc.dg/noncompile/pr79758.c: New test.
Ok.
Bernd
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-03 18:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-02 17:35 C PATCH to fix c/79758 (ICE-on-invalid with function redefinition and old style decls) Marek Polacek
2017-03-02 19:48 ` Bernd Schmidt
2017-03-03 13:33 ` Marek Polacek
2017-03-03 18:57 ` Bernd Schmidt
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).