<< Back to previous view

[PCC-371] add -Wno-error=... option Created: 11/Jul/11  Updated: 10/Aug/12

Status: Resolved
Project: pcc
Component/s: C frontend, Common code, pcc backend
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Trivial
Reporter: TAKAHASHI Tamotsu Assignee: Iain Hibbert
Resolution: Fixed Votes: 0

File Attachments: File werror.diff    

 Description   
gcc has the "-Werror=..." and "-Wno-error=..." specifier.
I think this is really useful because pcc builds itself with -Werror unless -Wtruncate is used.
So it may be reasonable to implement and use "-Werror -Wno-error=truncate".
(The attached diff is just a PoC. The current pcc can't build it because of -Werror
without -Wno-error=truncate. Also, I'm not a so experienced programmer.)


 Comments   
Comment by Iain Hibbert [ 14/Nov/11 01:07 PM ]
I added "error=" handling to cc and ccom, not quite as you had it as cleaned up some associated Wflag
code at the same time

cannot add "-Werror -Wno-error=truncate" to the configure script at this time though, because we still have some
-Wtruncate warnings and as you note previous pcc cannot handle -Wno-error=truncate. These warnings could be fixed,
though the problem is that they can appear bogus and I experienced some such warnings in system header files

for instance,

   int i;
   char c = i & 0x0f;

will trigger such a warning, though clearly this construct is valid and no unintended truncation is going to happen
Comment by Gregory McGarry [ 14/Nov/11 11:01 PM ]
Feel free to remove -Wtruncate from the build. I added it since I really like this feature of the Microsoft compiler. It doesn't have an equivalent in gcc.
Comment by Iain Hibbert [ 15/Nov/11 11:29 AM ]
I am in two minds about it, since -Wtruncate is potentially useful (does the above example
trigger the Microsoft compiler btw?)

I had a thought about this, to change the DESIRED_FLAGS to an ordered list, ending with

   ... -Werror -Wno-error=truncate -Wtruncate"

and when the first non-supported flag is found, to break from the loop.. this means that
-Wtruncate is only added when -Wno-error=truncate is permitted.

patch below, does that look good?

Index: configure.ac
===================================================================
RCS file: /cvsroot/pcc/configure.ac,v
retrieving revision 1.107
diff -u -p -r1.107 configure.ac
--- configure.ac 1 Nov 2011 18:33:44 -0000 1.107
+++ configure.ac 15 Nov 2011 10:19:44 -0000
@@ -387,20 +387,21 @@ AC_DEFINE_UNQUOTED(WCHAR_SIZE, $wchar_si
 
 # check for additional compiler flags
 AC_PROG_CC
-DESIRED_FLAGS="-Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wsign-compare -Wtruncate"
+AC_LANG_CONFTEST([int main() { return 0; }])
+DESIRED_FLAGS="-Werror -Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow -Wsign-compare -Wno-error=truncate -Wtruncate"
 for flag in $DESIRED_FLAGS
 do
  AC_MSG_CHECKING([whether $CC accepts $flag])
- AC_LANG_CONFTEST([int main() { return 0; }])
  $CC $CFLAGS $flag -c conftest.c > /dev/null 2> /dev/null
  if test $? = 0 ; then
  ADD_CFLAGS="$ADD_CFLAGS $flag"
  AC_MSG_RESULT([yes]);
  else
  AC_MSG_RESULT([no]);
+ break # bail out at first failure
  fi
- rm -f conftest.o
 done
+rm -f conftest.o
 
 # setup for cross-compiling mkext
 AC_MSG_CHECKING([for a C compiler for mkext])
Comment by Anders Magnusson [ 31/Jul/12 08:44 AM ]
Please go ahead with this. I think -Wtruncate is a very useful flag and should be used whenever possible.
Comment by Iain Hibbert [ 10/Aug/12 09:03 AM ]
have added -Werror to the default flags now
Generated at Sat Dec 27 22:26:15 CET 2014 using JIRA Enterprise Edition, Version: 3.13.1-#333.