public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dmalcolm at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/66220] -Wmisleading-indentation false/inconsistent warning
Date: Wed, 20 May 2015 16:00:00 -0000	[thread overview]
Message-ID: <bug-66220-4-8HC0bJUxs0@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-66220-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66220

--- Comment #2 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Thanks.

I ran into a variant of this whilst testing -Wmisleading-indentation on the
linux kernel, where a preprocessor macro conditionalizes the "if/else"; here's
the test case I reduced it to:

/* This variant of K&R-style formatting (in the presence of conditional
   compilation) shouldn't lead to a warning.

   Based on false positive seen with r223098 when compiling
   linux-4.0.3:arch/x86/crypto/aesni-intel_glue.c:aesni_init.  */

void
fn_36 (void)
{
#if 1 /* e.g. some configuration variable.  */
        if (flagA) {
                foo(0);
                foo(1);
                foo(2);
        } else
#endif
        {
                foo(3);
                foo(4);
                foo(5);
        }
        foo(6); /* We shouldn't warn here.  */
}

I have a fix for this, by requiring that the visual column of the guard
("else") be <= that of the stmts, which works for all of the testcases
(including the new ones I posted as
https://gcc.gnu.org/ml/gcc-patches/2015-05/msg01846.html ), apart from fn_15:

#define FOR_EACH(VAR, START, STOP) for ((VAR) = (START); (VAR) < (STOP);
(VAR++)) /* { dg-message "36: ...this 'for' clause, but it is not" } */
void fn_15 (void)
{
  int i;
  FOR_EACH (i, 0, 10) /* { dg-message "3: in expansion of macro" } */
    foo (i);
    bar (i, i); /* { dg-warning "statement is indented as if it were guarded
by..." } */
}
#undef FOR_EACH

which then fails to report the warning due to it using the location of the
"for" in the defn of macro FOR_EACH.

Fixing that will require some reworking on how we handle macro expansions.


  parent reply	other threads:[~2015-05-20 16:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-20 13:19 [Bug c/66220] New: " sirl at gcc dot gnu.org
2015-05-20 13:21 ` [Bug c/66220] " mpolacek at gcc dot gnu.org
2015-05-20 16:00 ` dmalcolm at gcc dot gnu.org [this message]
2015-05-20 16:52 ` dmalcolm at gcc dot gnu.org
2015-05-21 10:39 ` sirl at gcc dot gnu.org
2015-06-02 18:46 ` dmalcolm at gcc dot gnu.org
2015-06-02 18:51 ` dmalcolm at gcc dot gnu.org

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=bug-66220-4-8HC0bJUxs0@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).