This service will be undergoing maintenance at 00:00 UTC, 2017-10-23 It is expected to last about 30 minutes
Bug 1315010 - gcc: -ftrack-macro-expansion=0 triggers indentation warnings with -Wall
gcc: -ftrack-macro-expansion=0 triggers indentation warnings with -Wall
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
24
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Jakub Jelinek
Fedora Extras Quality Assurance
: Reopened
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-03-05 11:14 EST by Lukas Slebodnik
Modified: 2017-07-27 04:04 EDT (History)
14 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2017-07-27 04:04:32 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
C reproducer (402 bytes, text/x-csrc)
2016-03-05 11:14 EST, Lukas Slebodnik
no flags Details
Proposed fix (834 bytes, patch)
2016-03-05 11:15 EST, Lukas Slebodnik
no flags Details | Diff


External Trackers
Tracker ID Priority Status Summary Last Updated
GNU Compiler Collection 81577 None None None 2017-07-27 04:04 EDT

  None (edit)
Description Lukas Slebodnik 2016-03-05 11:14:22 EST
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 11:15 EST
Created attachment 1133368 [details]
Proposed fix
Comment 2 Florian Weimer 2016-05-07 03:44:04 EDT
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 08:33:37 EDT
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 09:23:50 EDT
(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 10:41:22 EDT
due to another bug in gcc BZ986923
Comment 6 Florian Weimer 2016-05-07 11:38:46 EDT
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 11:54:27 EDT
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 12:51:27 EDT
(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 13:52:23 EDT
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 16:17:44 EDT
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 04:04:32 EDT
Filed as an upstream bug.

Note You need to log in before you can comment on or make changes to this bug.