* [PATCH] Fix PR33692, gimplifier strips qualifiers from COMPONENT_REFs
@ 2007-10-09 12:47 Richard Guenther
2007-10-09 15:43 ` Ian Lance Taylor
0 siblings, 1 reply; 2+ messages in thread
From: Richard Guenther @ 2007-10-09 12:47 UTC (permalink / raw)
To: gcc-patches
The problem in this PR (ICE with type-checking enabled) is that the
gimplifier in canonicalize_component_ref effectively strips qualifiers
from the referenced structure type in canonicalizing the component type.
Now, I'd argue this function is completely unnecessary, but the safer
bet for stage3 is possibly to correctly canonicalize including the
relevant qualifiers like the following.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
Comments?
Thanks,
Richard.
2007-10-08 Richard Guenther <rguenther@suse.de>
PR middle-end/33692
* gimplify.c (canonicalize_component_ref): Honor qualifiers
of referenced structure and component.
* gcc.dg/pr33692.c: New testcase.
Index: gimplify.c
===================================================================
*** gimplify.c (revision 129162)
--- gimplify.c (working copy)
*************** canonicalize_component_ref (tree *expr_p
*** 1555,1571 ****
else
type = TREE_TYPE (TREE_OPERAND (expr, 1));
if (TREE_TYPE (expr) != type)
{
tree old_type = TREE_TYPE (expr);
/* Set the type of the COMPONENT_REF to the underlying type. */
TREE_TYPE (expr) = type;
! /* And wrap the whole thing inside a NOP_EXPR. */
! expr = build1 (NOP_EXPR, old_type, expr);
!
! *expr_p = expr;
}
}
--- 1555,1585 ----
else
type = TREE_TYPE (TREE_OPERAND (expr, 1));
+ /* One could argue that all the stuff below is not necessary for
+ the non-bitfield case and declare it a FE error if type
+ adjustment would be needed. */
if (TREE_TYPE (expr) != type)
{
+ #ifdef ENABLE_TYPES_CHECKING
tree old_type = TREE_TYPE (expr);
+ #endif
+ int type_quals;
+
+ /* We need to preserve qualifiers and propagate them from
+ operand 0. */
+ type_quals = TYPE_QUALS (type)
+ | TYPE_QUALS (TREE_TYPE (TREE_OPERAND (expr, 0)));
+ if (TYPE_QUALS (type) != type_quals)
+ type = build_qualified_type (TYPE_MAIN_VARIANT (type), type_quals);
/* Set the type of the COMPONENT_REF to the underlying type. */
TREE_TYPE (expr) = type;
! #ifdef ENABLE_TYPES_CHECKING
! /* It is now a FE error, if the conversion from the canonical
! type to the original expression type is not useless. */
! gcc_assert (useless_type_conversion_p (old_type, type));
! #endif
}
}
Index: testsuite/gcc.dg/pr33692.c
===================================================================
*** testsuite/gcc.dg/pr33692.c (revision 0)
--- testsuite/gcc.dg/pr33692.c (revision 0)
***************
*** 0 ****
--- 1,12 ----
+ /* { dg-do compile } */
+
+ /* We ICEd with type-checking enabled. */
+
+ typedef struct { int i; } snd_pcm_info_t;
+ typedef struct { snd_pcm_info_t info; } snd_pcm_shm_ctrl_t;
+ void snd_pcm_info(snd_pcm_info_t *);
+ int pcm_shm_cmd(volatile snd_pcm_shm_ctrl_t *ctrl)
+ {
+ snd_pcm_info((snd_pcm_info_t *) &ctrl->info);
+ }
+
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix PR33692, gimplifier strips qualifiers from COMPONENT_REFs
2007-10-09 12:47 [PATCH] Fix PR33692, gimplifier strips qualifiers from COMPONENT_REFs Richard Guenther
@ 2007-10-09 15:43 ` Ian Lance Taylor
0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2007-10-09 15:43 UTC (permalink / raw)
To: Richard Guenther; +Cc: gcc-patches
Richard Guenther <rguenther@suse.de> writes:
> 2007-10-08 Richard Guenther <rguenther@suse.de>
>
> PR middle-end/33692
> * gimplify.c (canonicalize_component_ref): Honor qualifiers
> of referenced structure and component.
>
> * gcc.dg/pr33692.c: New testcase.
Looks right to me for stage 3.
Ian
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-10-09 15:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-09 12:47 [PATCH] Fix PR33692, gimplifier strips qualifiers from COMPONENT_REFs Richard Guenther
2007-10-09 15:43 ` Ian Lance Taylor
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).