<< Back to previous view

[PCC-212] mishandled -W flags Created: 13/Jan/11  Updated: 27/Jul/11

Status: Closed
Project: pcc
Component/s: C frontend
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Piotr Sikora Assignee: Anders Magnusson
Resolution: Fixed Votes: 0
Environment: pcc 0.9.9 20110112 for x86_64-unknown-linux-gnu, p@ubuntu


 Description   
Hello,
it seems that pcc is mishandling -W flags.


According to the front-end code (cc/cc/cc.c):
- -WW enables everything defined in Wflags, that is: -Wtruncate, -Werror, -Wshadow, -Wpointer-sign, -Wsign-compare, -Wunknown-pragmas, -Wunreachable-code.
- -Wall enables: -Wpointer-sign, -Wunknown-pragmas,
- everything defined in Wflags can be passed and it will be enabled, everything else is silently discarded.


According to the compiler code (cc/ccom/main.c):
- -WW enables everything defined in flagstr, that is: -Wtruncate, -Wstrict-prototypes, -Wmissing-prototypes, -Wimplicit-int, -Wimplicit-function-declaration, -Wshadow, -Wpointer-sign, -Wsign-compare, -Wunknown-pragmas, -Wunreachable-code.
- -Wimplicit enables: -Wimplicit_int, -Wimplicit_function_declaration,
- -Werror treats warnings as errors,
- everything defined in flagstr can be passed and it will be enabled.


It seems reasonable, but -WW is expanded by pcc to all flags defined in Wflags, including -Werror(!!!), but it (-WW) isn't passed down to ccom, which results in undesired behavior:

p@ubuntu:~$ pcc -v -WW hello.c
(...)
/usr/local/libexec/ccom -Wtruncate -Werror -Wshadow -Wpointer-sign -Wsign-compare -Wunknown-pragmas -Wunreachable-code -v /tmp/ctm.Lvilh2 /tmp/ctm.br501B
ccom: pcc 0.9.9 20110112 for x86_64-unknown-linux-gnu, p@ubuntu
DEBUG: warniserr: 1 <-- pcc expands -WW to -Werror (BAD)
DEBUG: truncate: 1
DEBUG: strict-prototypes: 0
DEBUG: missing-prototypes: 0
DEBUG: implicit-int: 0
DEBUG: implicit-function-declaration: 0
DEBUG: shadow: 1
DEBUG: pointer-sign: 1
DEBUG: sign-compare: 1
DEBUG: unknown-pragmas: 1
DEBUG: unreachable-code: 1


pcc -v -Wc,-WW hello.c
(...)
/usr/local/libexec/ccom -WW -v /tmp/ctm.6Cor1G /tmp/ctm.6FAUmn
ccom: pcc 0.9.9 20110112 for x86_64-unknown-linux-gnu, p@ubuntu
DEBUG: warniserr: 0 <--- ccom doesn't expand -WW to -Werror (GOOD)
DEBUG: truncate: 1
DEBUG: strict-prototypes: 1
DEBUG: missing-prototypes: 1
DEBUG: implicit-int: 1
DEBUG: implicit-function-declaration: 1
DEBUG: shadow: 1
DEBUG: pointer-sign: 1
DEBUG: sign-compare: 1
DEBUG: unknown-pragmas: 1
DEBUG: unreachable-code: 1


pcc -v -Werror -Wc,-WW hello.c
(...)
/usr/local/libexec/ccom -Werror -WW -v /tmp/ctm.INtTht /tmp/ctm.TywgvS
ccom: pcc 0.9.9 20110112 for x86_64-unknown-linux-gnu, p@ubuntu
DEBUG: warniserr: 1
DEBUG: truncate: 1
DEBUG: strict-prototypes: 1
DEBUG: missing-prototypes: 1
DEBUG: implicit-int: 1
DEBUG: implicit-function-declaration: 1
DEBUG: shadow: 1
DEBUG: pointer-sign: 1
DEBUG: sign-compare: 1
DEBUG: unknown-pragmas: 1
DEBUG: unreachable-code: 1



Also, because unknown -W flags are ignored by pcc, -Wxxx is handled differently by pcc and ccom:

p@ubuntu:~$ /usr/local/bin/pcc -Wxxx
no input files
p@ubuntu:~$ /usr/local/libexec/ccom -Wxxx
unrecognised option 'xxx'
usage: /usr/local/libexec/ccom [option] [infile] [outfile]...



To be honest I have no idea if pre-processor, assembler or linker are using -W flags, if not then -WW probably doesn't need to be expanded by pcc and ccom could take care of it (pcc just needs to pass it).

 Comments   
Comment by Anders Magnusson [ 16/Jan/11 08:55 PM ]
Not even close to all gcc -W flags are supported by pcc. And I have made the logic quite simple; cc parses the -W flags and tries to do something useful of them, but there are nothing that says that the flags to ccom should be the same (actually, they cannot). ccom is not intended to be called directly, neither is cpp.

Actually, the flag -WW should probably be handled only by cc, not ccom, like -Wall. And as you wrote, there are -W flags that should go
to at least cpp.

-- Ragge
Comment by Piotr Sikora [ 16/Jan/11 11:28 PM ]
Yeah, I know... ccom acting differently from pcc isn't big issue, because like you've mentioned, it isn't supposed to be run directly. I just thought I would add this to the report since I've noticed it.

The major issue is (just in case I wasn't clear enough) that "pcc -WW":
- enables -Werror,
- doesn't enable -Wstrict-prototypes, -Wmissing-prototypes, -Wimplicit-int, -Wimplicit-function-declaration.
Comment by Iain Hibbert [ 27/Jul/11 07:28 PM ]
I have committed changes that fix both these issues
Generated at Fri Oct 31 00:50:31 CET 2014 using JIRA Enterprise Edition, Version: 3.13.1-#333.