public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: mark_at_yahoo <markrubn@yahoo.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: gcc-help@gcc.gnu.org
Subject: Re: __attribute__ to selectively disable -Wmaybe-uninitialized
Date: Tue, 27 Oct 2020 01:01:18 -0700	[thread overview]
Message-ID: <316cf378-9eca-2fe6-7ba7-e3525abd2d30@yahoo.com> (raw)
In-Reply-To: <20201024183217.GN2672@gate.crashing.org>

(Apologies for the delayed response. I receive gcc-help posts, including 
others from you, without problem, but this one which I'm particularly 
interested got caught in my spam filters.)

On 10/24/20 11:32 AM, Segher Boessenkool wrote:
> I have to disagree with you there.  Well-factored code is *good*.  The
> compiler can (and will) do all the obvious optimisations; you should not
> obfuscate your program by doing them manually (and hinder the compiler's
> optimisers, and introduce bugs at the same time).

FWIW, I agree.


> "Gratuitous functions" is only a problem if you have trouble naming
> them.  Which sometimes is a problem, sure, but most of the time that
> simply shows that your factoring isn't so good.

I always factor out common code, and attempt to give it informative 
function/class/method/namespace/etc names.

I tend *not* to factor out code that is only used in one place merely to 
follow coding standards that forbid lengthy functions. No spaghetti 
code, but I have no problem with:

     void func()
     {
         // part1
         // ...

         // part2
         // ...

         // part3
         // ...
     }

compared to:

     void func()
     {
         part1();
         part2();
         part3();
     }

regardless how long the "parts" are (assuming they aren't reused elsewhere).

And, yes, I understand inline functions.


> -Wmaybe-uninitialized only has false positives for non-trivial control
> flow.  Which you probably shouldn't have in your source code anyway.

Whether or not it gives false positives seems unpredictable. My code's 
control flow is:

     void func(
     bool    with_buffer)
     {
         char        *buffer;

         if (with_buffer)
             buffer = allocate();

         while (still_working()) {
             other_processing();

             if (with_buffer)
                 process_buffer(buffer);

             yet_more_processing();
         }
     }

This test demo does not give the warning. The real program, with 
identical control flow but much more intermediate code, does.

Yes, there are many ways to refactor this code (separate "with" and 
"without" functions, two different loops inside "if" and "else" branches 
of "if (with_buffer)", etc).  IMO all of them obfuscate the above simple 
control flow, not the opposite.


> If you insist on using constructs that -Wmaybe-uninitialized cannot
> handle, then do not use -Wmaybe-uninitialized?

I thought we agreed that warnings are A Good Thing.


> It should arguably not be enabled by -Wall, just by -Wextra.

FWIW, I'm using -Wextra. As per above, I like warnings.


> The only comment was a helpful suggestion.  If that is not what you are
> looking for, just ignore it, or make a comment yourself?  Complaining
> that people are "dismissive" because they have a different opinion is
> not helpful.

The comment was "Why don't just initialize the variable?". In addition 
to the unnecessary compiled instructions that produces (unless the 
optimizer is smarter than the warning generator and removes them), it 
hides the issue in a non-obvious way compared to the explicit pragmas or 
a theoretical attribute.

As you point out, that's been the only comment in 8 years until this 
discussion -- and I do consider it a discussion, not a "complaint". As 
you said before, the issue is still open. I considered the comment a 
"last word", which along with lack of further response to the original 
issue filer's further points to mean, "we feel this is not 
needed/important". Whether that's "dismissive" or not is open to 
interpretation.


> If you insist on having an attribute to disable just this warning, you
> can implement it yourself (or get someone else to do it for you).  

Of course.


> It
> does not have to become part of GCC mainline.  *That* is the nature of
> Free Software.

I'm suggesting the attribute because I want to use it in some 
open-source software I'm distributing. I also think it would be a good 
GCC extension in general. Even assuming I had the ability to implement 
it myself or contract the same, I will not be distributing a custom 
compiler for my project, so if it wouldn't make it into the mainline 
(which these emails strongly suggest), that's not an option.


> If you cannot convince people to spend their time on
> implementing your ideas, then maybe they do not think those are good
> ideas?

Obviously they/you don't. Pending any further comments regarding my 
control flow example above, I'll take it that I wasn't convincing and 
the matter is closed. I do take heart that others (like the 2012 issue 
filer and some in this short thread) seem to agree with me, or at least 
that this has been worth discussing.


  reply	other threads:[~2020-10-27  8:03 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
2020-10-24 18:32       ` Segher Boessenkool
2020-10-27  8:01         ` mark_at_yahoo [this message]
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=316cf378-9eca-2fe6-7ba7-e3525abd2d30@yahoo.com \
    --to=markrubn@yahoo.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=segher@kernel.crashing.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).