public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/33086]  New: warn for read-only uninitialized variables passed as arguments
@ 2007-08-16 10:50 manu at gcc dot gnu dot org
  2007-08-16 10:59 ` [Bug middle-end/33086] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-08-16 10:50 UTC (permalink / raw)
  To: gcc-bugs

void use(const int *);

void foo(void)
{
  int i;
  use(&i);
}

At least for languages where 'const' is actually enforced, we should warn for
this. For languages where the 'const' can be cast away and 'i' can be
initialized by 'use' the situation is less clear (although personally I think
we should warn anyway). This is one part of PR10138.

"the question whether an argument is actually used or not is secondary, the
fact that we pass an uninitialized variable to which only read access is
possible 
is definitely worth a warning."
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10138#c8


-- 
           Summary: warn for read-only uninitialized variables passed as
                    arguments
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: manu at gcc dot gnu dot org
OtherBugsDependingO 10138
             nThis:


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33086


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

* [Bug middle-end/33086] warn for read-only uninitialized variables passed as arguments
  2007-08-16 10:50 [Bug middle-end/33086] New: warn for read-only uninitialized variables passed as arguments manu at gcc dot gnu dot org
  2007-08-16 10:59 ` [Bug middle-end/33086] " pinskia at gcc dot gnu dot org
@ 2007-08-16 10:59 ` pinskia at gcc dot gnu dot org
  2007-08-16 11:20 ` manu at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-16 10:59 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
           Priority|P3                          |P5


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33086


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

* [Bug middle-end/33086] warn for read-only uninitialized variables passed as arguments
  2007-08-16 10:50 [Bug middle-end/33086] New: warn for read-only uninitialized variables passed as arguments manu at gcc dot gnu dot org
@ 2007-08-16 10:59 ` pinskia at gcc dot gnu dot org
  2007-08-16 10:59 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-16 10:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-08-16 10:59 -------
> At least for languages where 'const' is actually enforced

There is none, unless you are taking about fortran "in" arguments.  So we need
to mark such argument as special.

Now if you have the full program (or at least the containts of use function),
and you can prove it never writes to the incoming pointer argument, then you
can warn but only then.

In C and C++ you can never tell without the body of use.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|24639                       |
              nThis|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33086


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

* [Bug middle-end/33086] warn for read-only uninitialized variables passed as arguments
  2007-08-16 10:50 [Bug middle-end/33086] New: warn for read-only uninitialized variables passed as arguments manu at gcc dot gnu dot org
  2007-08-16 10:59 ` [Bug middle-end/33086] " pinskia at gcc dot gnu dot org
  2007-08-16 10:59 ` pinskia at gcc dot gnu dot org
@ 2007-08-16 11:20 ` manu at gcc dot gnu dot org
  2007-08-16 14:58 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-08-16 11:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from manu at gcc dot gnu dot org  2007-08-16 11:19 -------
(In reply to comment #1)
> > At least for languages where 'const' is actually enforced
> 
> There is none, 

void use(const int *a)
{
    a[0] = 5;
}
void foo(void)
{
  int i;
  use(&i);
}

new.c:3: error: assignment of read-only location

Either I am misunderstanding you or your argument about overwriting the pointer
argument is equivalent to just don't using the value of 'i'. Of course, we
don't know whether the value is used or not within use() but the fact is that
'i' cannot be initialized within use().


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
           Priority|P5                          |P3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33086


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

* [Bug middle-end/33086] warn for read-only uninitialized variables passed as arguments
  2007-08-16 10:50 [Bug middle-end/33086] New: warn for read-only uninitialized variables passed as arguments manu at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-08-16 11:20 ` manu at gcc dot gnu dot org
@ 2007-08-16 14:58 ` pinskia at gcc dot gnu dot org
  2007-08-17 10:15 ` manu at gcc dot gnu dot org
  2007-08-20 14:47 ` manu at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-08-16 14:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2007-08-16 14:58 -------


void use(const int *a)
{
  int *b = (int*)a;
    b[0] = 5;
}
void foo(void)
{
  int i;
  use(&i);
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33086


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

* [Bug middle-end/33086] warn for read-only uninitialized variables passed as arguments
  2007-08-16 10:50 [Bug middle-end/33086] New: warn for read-only uninitialized variables passed as arguments manu at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-08-16 14:58 ` pinskia at gcc dot gnu dot org
@ 2007-08-17 10:15 ` manu at gcc dot gnu dot org
  2007-08-20 14:47 ` manu at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-08-17 10:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from manu at gcc dot gnu dot org  2007-08-17 10:15 -------
(In reply to comment #3)
> 
> void use(const int *a)
> {
>   int *b = (int*)a;

Andrew, you are right. I tend to forget how fragile is 'const', even in C++.
So, then this is invalid and thus it is PR10138.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33086


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

* [Bug middle-end/33086] warn for read-only uninitialized variables passed as arguments
  2007-08-16 10:50 [Bug middle-end/33086] New: warn for read-only uninitialized variables passed as arguments manu at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2007-08-17 10:15 ` manu at gcc dot gnu dot org
@ 2007-08-20 14:47 ` manu at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-08-20 14:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from manu at gcc dot gnu dot org  2007-08-20 14:47 -------
Andrew, what about functions marked with attribute "pure" ?

int atoi(const char *) __attribute__ ((pure));


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33086


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

end of thread, other threads:[~2007-08-20 14:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-16 10:50 [Bug middle-end/33086] New: warn for read-only uninitialized variables passed as arguments manu at gcc dot gnu dot org
2007-08-16 10:59 ` [Bug middle-end/33086] " pinskia at gcc dot gnu dot org
2007-08-16 10:59 ` pinskia at gcc dot gnu dot org
2007-08-16 11:20 ` manu at gcc dot gnu dot org
2007-08-16 14:58 ` pinskia at gcc dot gnu dot org
2007-08-17 10:15 ` manu at gcc dot gnu dot org
2007-08-20 14:47 ` manu at gcc dot gnu dot org

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