* The C++ FE drops qualifiers on pointer dereference
@ 2009-07-17 13:26 Richard Guenther
2009-07-17 13:54 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Richard Guenther @ 2009-07-17 13:26 UTC (permalink / raw)
To: gcc
The C++ frontend drops qualifiers when performing pointer dereference:
void foo(int * __restrict p, int * __restrict__ q, int i)
{
*q = p[i];
}
;; Function void foo(int*, int*, int) (null)
;; enabled by -tree-original
<<cleanup_point <<< Unknown tree: expr_stmt
(void) (*(int *) q = *((int *) p + (long unsigned int) ((long unsigned
int) i * 4))) >>>
>>;
while this isn't a big issue for the plain *q (the cast is stripped
as useless during gimplification), the second cast results in the
gimplifier generating an unqualified temporary to do the dereference:
void foo(int*, int*, int) (int * restrict p, int * restrict q, int i)
{
long unsigned int D.2088;
long unsigned int D.2089;
int * D.2090;
int D.2091;
D.2088 = (long unsigned int) i;
D.2089 = D.2088 * 4;
D.2090 = p + D.2089;
D.2091 = *D.2090;
*q = D.2091;
}
The C frontend seems to get away without doing this conversion, the
C++ frontend does it here:
typeck.c:decay_conversion
/* [basic.lval]
Non-class rvalues always have cv-unqualified types. */
type = TREE_TYPE (exp);
if (!CLASS_TYPE_P (type) && cp_type_quals (type))
exp = build_nop (TYPE_MAIN_VARIANT (type), exp);
called from
#1 0x0000000000657c35 in cp_build_indirect_ref (ptr=0x7ffff7edcf30,
errorstring=0x120f491 "unary *", complain=3)
at /space/rguenther/src/svn/trunk/gcc/cp/typeck.c:2493
2490 if (ptr == current_class_ptr)
2491 return current_class_ref;
2492
2493 pointer = (TREE_CODE (TREE_TYPE (ptr)) == REFERENCE_TYPE
2494 ? ptr : decay_conversion (ptr));
2495 type = TREE_TYPE (pointer);
The C++ frontend in this way currently pessimizes code by emitting
dereferences of non-restrict qualified pointers where the user
used a restrict qualified pointer.
Where can this be fixed? I currently have a hack to not strip
restrict qualifiers in decay_conversion, but that feels a little
too hackish. What's the important piece of decay_conversion
that is necessary for indirect refs?
Thanks,
Richard.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: The C++ FE drops qualifiers on pointer dereference
2009-07-17 13:26 The C++ FE drops qualifiers on pointer dereference Richard Guenther
@ 2009-07-17 13:54 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2009-07-17 13:54 UTC (permalink / raw)
To: Richard Guenther; +Cc: gcc
On 07/17/2009 03:26 PM, Richard Guenther wrote:
> Where can this be fixed? I currently have a hack to not strip
> restrict qualifiers in decay_conversion, but that feels a little
> too hackish. What's the important piece of decay_conversion
> that is necessary for indirect refs?
Well, I'd start by making a function called something like
"cv_unqualified" that strips only cv-quals from the type, and look at
replacing a lot of uses of TYPE_MAIN_VARIANT with that.
I imagine that removing the cv-quals is important for overload
resolution, but feel free to try removing that and see what breaks. :)
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-07-17 13:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-17 13:26 The C++ FE drops qualifiers on pointer dereference Richard Guenther
2009-07-17 13:54 ` 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).