Bug 1315010

Summary: gcc: -ftrack-macro-expansion=0 triggers indentation warnings with -Wall
Product: [Fedora] Fedora Reporter: Lukas Slebodnik <lslebodn>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED UPSTREAM QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 24CC: arjun.is, codonell, davejohansen, dj, dmalcolm, fweimer, jakub, jwakely, law, lslebodn, mfabian, mpolacek, pfrankli, siddhesh
Target Milestone: ---Keywords: Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-07-27 08:04:32 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
C reproducer
none
Proposed fix none

Description Lukas Slebodnik 2016-03-05 16:14:22 UTC
Created attachment 1133367 [details]
C reproducer

Description of problem:
Macros htons and ntohs emit gcc warning Wmisleading-indentation.
Which is enabled with gcc argument -Wall.
It breaks my effort to compile without warning and with -Werror.


Version-Release number of selected component (if applicable):
glibc-headers-2.23.1-5.fc24.x86_64
gcc-6.0.0-0.14.fc24.x86_64
How reproducible:
Deterministic

Steps to Reproduce:
1. Compile attached file
sh$ gcc -O2 -Wall -ftrack-macro-expansion=0 -c pok.c

Actual results:
pok.c: In function ‘main’:
pok.c:13:5: warning: statement is indented as if it were guarded by... [-Wmisleading-indentation]
     SOME_MACRO(htons(16), uint16_t);
     ^~~~~~~~~~
pok.c:13:5: note: ...this ‘else’ clause, but it is not
pok.c:14:5: warning: statement is indented as if it were guarded by... [-Wmisleading-indentation]
     SOME_MACRO(ntohs(16), uint16_t);
     ^~~~~~~~~~
pok.c:14:5: note: ...this ‘else’ clause, but it is not

Expected results:
No gcc warnings.

Additional info:
Attached diff /usr/include/bits/byteswap-16.h fixed issue for me.
I can see similar pattern also in /usr/include/bits/byteswap.h
but function ntohl and htonl used different part of header with optimisation
(__bswap_32). But I can prepare patch if you want.

Comment 1 Lukas Slebodnik 2016-03-05 16:15:18 UTC
Created attachment 1133368 [details]
Proposed fix

Comment 2 Florian Weimer 2016-05-07 07:44:04 UTC
I believe this was a GCC bug.  I no longer get a -Wall warning for the following test program with gcc-6.0.0-0.20.fc24.x86_64.

#include <stdlib.h>
#include <stdio.h>
#include <arpa/inet.h>

int
main(int argc, char **argv)
{
  int x = atoi (argv[1]);
  printf ("%d\n", ntohs (x));
}

Comment 3 Lukas Slebodnik 2016-05-07 12:33:37 UTC
I'm sorry but I can still reproduce this bug.
Please try to reproduce with attached C file and try to follow steps in description of this ticket.

Comment 4 Florian Weimer 2016-05-07 13:23:50 UTC
(In reply to Lukas Slebodnik from comment #3)
> I'm sorry but I can still reproduce this bug.
> Please try to reproduce with attached C file and try to follow steps in
> description of this ticket.

Ah, the culprit is -ftrack-macro-expansion=0.  Why do you use it?

Comment 5 Lukas Slebodnik 2016-05-07 14:41:22 UTC
due to another bug in gcc BZ986923

Comment 6 Florian Weimer 2016-05-07 15:38:46 UTC
Fair enough, reassigning to gcc.  We cannot fix this on the glibc side; the macro definition is fine as-is.

I'm not sure what the right solution for this problem is.  Maybe indentation warnings in macros need to be disabled with -ftrack-macro-expansion=0.

Comment 7 Lukas Slebodnik 2016-05-07 15:54:27 UTC
Macro definition is fine but after expansion it is on single line.
and therefore there will be something like
    else __asm__ (....); __v;
and it's misleading indentation :-)

I thought that proposed change for glibc [ attachment 1133368 [details] ] is a reasonable compromise.

Comment 8 Florian Weimer 2016-05-07 16:51:27 UTC
(In reply to Lukas Slebodnik from comment #7)
> I thought that proposed change for glibc [ attachment 1133368 [details] ] is
> a reasonable compromise.

We would have to rewrite many more macros in a way which is not conforming to the GNU coding style.  I don't think this is an option.

Comment 9 Jakub Jelinek 2016-05-07 17:52:23 UTC
With -ftrack-macro-expansion=0 you really don't know if you are from a macro expansion or not, that is the whole point of the option.

Comment 10 Fedora End Of Life 2017-07-25 20:17:44 UTC
This message is a reminder that Fedora 24 is nearing its end of life.
Approximately 2 (two) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 24. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '24'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version'
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not
able to fix it before Fedora 24 is end of life. If you would still like
to see this bug fixed and are able to reproduce it against a later version
of Fedora, you are encouraged  change the 'version' to a later Fedora
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

Comment 11 Florian Weimer 2017-07-27 08:04:32 UTC
Filed as an upstream bug.