public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* missing warning about parameter set bug no longer used
@ 2012-01-06 11:02 Alexandre Duret-Lutz
  2012-01-07  2:56 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Duret-Lutz @ 2012-01-06 11:02 UTC (permalink / raw)
  To: gcc-help

Hi,

The following file foo.c is a simplified version of a subtler bug I
found in my code.
int b;void bar(int a);void foo(int a){  bar(a);  a = 42;}

The line a = 42 is in fact a typo in my code: I meant b = 42. I do
*not* expect the compiler to detect that I made a typo, but I would
like the get a warning that I am assigning to a local variable (or a
function parameter) that is not going to be used anymore. If I compile
this file with
% gcc-4.6 -Wall -Wextra -pedantic -O3 -c foo.c
I get absolutely no warning. Inspecting the generated code shows that
the assignment a = 42 is not performed, so gcc is perfectly well aware
that this instruction is useless (hence potentially bogus). Commenting
the call to bar(a); does produce a "warning: parameter ‘a’ set but not
used [-Wunused-but-set-parameter]", so it seems like gcc will not warn
as long as variable a is used somewhere in the function, even if it is
before the assignment.
My questions:
1. Is there a way to tell gcc to produce a warning for such case?2. Is
there a reason for the actual behavior? I.e, some cases were it is
actually desirable to assign to local variables that will be thrown
away by the optimizer?
Thanks
-- 
Alexandre Duret-Lutz

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

* Re: missing warning about parameter set bug no longer used
  2012-01-06 11:02 missing warning about parameter set bug no longer used Alexandre Duret-Lutz
@ 2012-01-07  2:56 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2012-01-07  2:56 UTC (permalink / raw)
  To: Alexandre Duret-Lutz; +Cc: gcc-help

Alexandre Duret-Lutz <adl@lrde.epita.fr> writes:

> The following file foo.c is a simplified version of a subtler bug I
> found in my code.
> int b;void bar(int a);void foo(int a){  bar(a);  a = 42;}
>
> The line a = 42 is in fact a typo in my code: I meant b = 42. I do
> *not* expect the compiler to detect that I made a typo, but I would
> like the get a warning that I am assigning to a local variable (or a
> function parameter) that is not going to be used anymore. If I compile
> this file with
> % gcc-4.6 -Wall -Wextra -pedantic -O3 -c foo.c
> I get absolutely no warning. Inspecting the generated code shows that
> the assignment a = 42 is not performed, so gcc is perfectly well aware
> that this instruction is useless (hence potentially bogus). Commenting
> the call to bar(a); does produce a "warning: parameter ‘a’ set but not
> used [-Wunused-but-set-parameter]", so it seems like gcc will not warn
> as long as variable a is used somewhere in the function, even if it is
> before the assignment.
> My questions:
> 1. Is there a way to tell gcc to produce a warning for such case?2. Is
> there a reason for the actual behavior? I.e, some cases were it is
> actually desirable to assign to local variables that will be thrown
> away by the optimizer?

As far as I know way there is no way to get a warning for this case at
present.

GCC does not currently have a framework for tracking sets and uses which
is independent of the optimizers.  And warnings that are dependent on
the optimizers are troublesome for many reasons.  GCC does have some
warnings like that today, and there are perennial sources of compliant.
So there is unlikely to be an easy way to implement this warning.

Ian

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

end of thread, other threads:[~2012-01-06 14:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-06 11:02 missing warning about parameter set bug no longer used Alexandre Duret-Lutz
2012-01-07  2:56 ` 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).