public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: J Decker <d3ck0r@gmail.com>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: __attribute__ to selectively disable -Wmaybe-uninitialized
Date: Sat, 24 Oct 2020 01:49:40 -0700	[thread overview]
Message-ID: <CAA2GJqXr4comdmJmxOOgp8q6k9FD8mi_NYAP4UP_gW=qF12k_w@mail.gmail.com> (raw)
In-Reply-To: <41334120-9251-abaa-c6a2-a647fb34f123@yahoo.com>

--- Test.c -----
#include <stdio.h>
#include <stdlib.h>

void a( void ) {
   int buf[2];
   buf[0] = 0x12345678;
   buf[1] = 0x12345678;
}

void f( void ) {
   int n;
   int m;
   for( m = 0; m < 2; m++ ) {
      switch( m & 4 ) {
         case 1:
            n = 3;
            break;
      }
   }
   printf( "%d\n", n );
}

int main( void ) {
   a();
   f();
}
----

n is definitely never set, and I can't get a warning generated...
was more looking for a false-negative example (where N is definitely always
set by the usage...

it prints whatever buf[0] was set to in a()... (added A so it didn't print
0, and I could demonstrate some control; tried just doing a printf or
something before hand but ended up with '0' anyway, which looks sort of
like it might have been initialized to '0' (it wouldn't have been, but one
might feel that it did).

This is the sort of thing that happens... a series of events happen which
MUST happen before a thing is used, otherwise a return or other condition
which is not a direct test against that variables would trigger a bypass of
usage or early return...   I have several places where that warning has
shown up, and I've considered adding a fake initialization to a value that
I know would never be used and would always be replace by a real value (yes
it's only a couple ticks to set a variable, it's still a write to memory
that's not necessarily required; and who cares about generating heat?)

On Fri, Oct 23, 2020 at 2:51 PM mark_at_yahoo via Gcc-help <
gcc-help@gcc.gnu.org> wrote:

> On 10/23/20 1:38 PM, Segher Boessenkool wrote:
> > Yes.  And you usually should make trivial changes to your program if the
> > compiler warns, even if you consider that unnecessary -- just so that
> > you will not miss other warnings!
>
> > No, but you can write your code so that it more obviously does not use
> > unitialised variables.  This is an Even Better Thing(tm).  The compiler
> > will understand it, but much more importantly, human readers will
> > understand it as well!
>
> It's often (maybe always) possible to reorder/refactor the code as you
> suggest. Sometimes (maybe often) that results in convoluted logic and
> control flow, needlessly repeated code sections, gratuitous (possibly
> inline) functions, and the like. The cure being worse than the #pragma
> disease.
>
>
> > -Wmaybe-uninitialized has a LOT of false positives if you use anything
> > but the strictest, simplest control flow.  It's the nature of the beast.
>
> That's the point. There will always be false positives. Sometimes the
> programmer *does* know more than the compiler. IMO GCC could benefit
> from a better way to selectively turn them off.
>
>
> >> 5. I now see something similar was requested in 2012 in
> >> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55288 but seems to have
> >> been dismissed with a variation of #4.
> >
> > It wasn't dismissed, that PR is still open.
>
> Sorry, I was using "dismissed" colloquially. The response was
> dismissive, and from what I've been able to find nothing has been done
> in the succeeding 8 years.
>
> But, yes, that's the nature of the open source (in general) and GCC (in
> particular) beast.
>
> --
> MARK
> markrubn@yahoo.com
>
>
>

  reply	other threads:[~2020-10-24  8:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <caf2f32f-3caf-fc89-0ca6-4c885a7b8ff1.ref@yahoo.com>
2020-10-23 20:01 ` mark_at_yahoo
2020-10-23 20:38   ` Segher Boessenkool
2020-10-23 21:51     ` mark_at_yahoo
2020-10-24  8:49       ` J Decker [this message]
2020-10-24 18:32       ` Segher Boessenkool
2020-10-27  8:01         ` mark_at_yahoo
2020-10-24 17:06   ` Florian Weimer
2020-10-24 18:02     ` Segher Boessenkool

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA2GJqXr4comdmJmxOOgp8q6k9FD8mi_NYAP4UP_gW=qF12k_w@mail.gmail.com' \
    --to=d3ck0r@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).