public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Question about pointer arithmetics in GIMPLE
@ 2005-08-21 18:32 Falk Hueffner
  2005-08-22 22:50 ` Jeffrey A Law
  0 siblings, 1 reply; 3+ messages in thread
From: Falk Hueffner @ 2005-08-21 18:32 UTC (permalink / raw)
  To: gcc; +Cc: law

Hi,

I'm trying to implement a tree pass that warns about bad array
accesses as suggested for PR 8268 by Jeff Law. However, I have trouble
with the following:

char digit_vector[5];
const char *ggc_alloc_string(int length) {
    return digit_vector + ((length - 17) * 2);
}

this translates to:

ggc_alloc_string (length)
{
  const char * D.1292;
  int D.1293;
  long unsigned int D.1294;
  char * D.1295;
  char * D.1296;

  D.1293 = length * 2;
  D.1294 = (long unsigned int) D.1293;
  D.1295 = (char *) D.1294;
  D.1296 = &digit_vector + -34B;     <-----------
  D.1292 = D.1295 + D.1296;
  return D.1292;
}

that is, a pointer is formed that wouldn't be legal to form from C,
and we end up with

  return (char *) (long unsigned int) (length * 2) + &digit_vector[-000000022];

producing a warning. Is that correct GIMPLE? If so, I fear it simply
isn't possible to do this kind of warnings after gimplification, and,
if at all possible, would have to be done in the front-end after all.

-- 
	Falk

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about pointer arithmetics in GIMPLE
  2005-08-21 18:32 Question about pointer arithmetics in GIMPLE Falk Hueffner
@ 2005-08-22 22:50 ` Jeffrey A Law
  2005-08-22 23:35   ` Daniel Berlin
  0 siblings, 1 reply; 3+ messages in thread
From: Jeffrey A Law @ 2005-08-22 22:50 UTC (permalink / raw)
  To: Falk Hueffner; +Cc: gcc

On Sun, 2005-08-21 at 20:32 +0200, Falk Hueffner wrote:
> Hi,
> 
> I'm trying to implement a tree pass that warns about bad array
> accesses as suggested for PR 8268 by Jeff Law. However, I have trouble
> with the following:
> 
> char digit_vector[5];
> const char *ggc_alloc_string(int length) {
>     return digit_vector + ((length - 17) * 2);
> }
> 
> this translates to:
> 
> ggc_alloc_string (length)
> {
>   const char * D.1292;
>   int D.1293;
>   long unsigned int D.1294;
>   char * D.1295;
>   char * D.1296;
> 
>   D.1293 = length * 2;
>   D.1294 = (long unsigned int) D.1293;
>   D.1295 = (char *) D.1294;
>   D.1296 = &digit_vector + -34B;     <-----------
>   D.1292 = D.1295 + D.1296;
>   return D.1292;
> }
> 
> that is, a pointer is formed that wouldn't be legal to form from C,
> and we end up with
> 
>   return (char *) (long unsigned int) (length * 2) + &digit_vector[-000000022];
IIRC creating an invalid pointer is OK -- dereferencing the pointer is 
what's bad.  You need to focus on array accesses, pointer dereferences
and the like, not pointer generation.

Warning for pointer generation is going to be a *lot* harder and I 
suspect will always result in more false positives.


> producing a warning. Is that correct GIMPLE? If so, I fear it simply
> isn't possible to do this kind of warnings after gimplification, and,
> if at all possible, would have to be done in the front-end after all.
Putting these warnings in the front-end is IMHO wrong.  They
belong in the generic parts of the compiler.    



Jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about pointer arithmetics in GIMPLE
  2005-08-22 22:50 ` Jeffrey A Law
@ 2005-08-22 23:35   ` Daniel Berlin
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Berlin @ 2005-08-22 23:35 UTC (permalink / raw)
  To: law; +Cc: Falk Hueffner, gcc

> Warning for pointer generation is going to be a *lot* harder and I 
> suspect will always result in more false positives.

In order to increase the accuracy of the data dependence analysis, i do,
at some point, plan on tracking the sizes of malloc sites, and giving an
upper bound on them (for cases of loops, etc) when possible

on an interprocedural basis, that should allow you to generate at least
"this is obviously wrong" warnings.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-08-22 22:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-21 18:32 Question about pointer arithmetics in GIMPLE Falk Hueffner
2005-08-22 22:50 ` Jeffrey A Law
2005-08-22 23:35   ` Daniel Berlin

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).