[Bug c/32570] New: Compiling GCC 4.3.0 with CIL instead of using GCC 4.2 or 4.3 finds many warnings that GCC does not report

rob1weld at aol dot com gcc-bugzilla@gcc.gnu.org
Sun Jul 1 05:30:00 GMT 2007


Here is a partial list of warnings when building GCC the "normal" way (with
GCC):

/gcc-4_3-trunk/gcc/config/i386/i386.md:18924: warning: operand 1 missing mode?
/gcc-4_3-trunk/libiberty/argv.c:313: warning: unused variable 'ret'


I decided to try something different to see if I could find more warnings.


CIL (C Intermediate Language) is a high-level representation along with a set
of tools that permit easy analysis and source-to-source transformation of C
programs.

CIL is both lower-level than abstract-syntax trees, by clarifying ambiguous
constructs and removing redundant ones, and also higher-level than typical
intermediate languages designed for compilation, by maintaining types and a
close relationship with the source program. The main advantage of CIL is that
it compiles all valid C programs into a few core constructs with a very clean
semantics. Also CIL has a syntax-directed type system that makes it easy to
analyze and manipulate C programs. Furthermore, the CIL front-end is able to
process not only ANSI-C programs but also those using Microsoft C or GNU C
extensions. If you only want CIL get it from http://hal.cs.berkeley.edu/cil/ .

It is better to get Deputy (which uses CIL) from http://deputy.cs.berkeley.edu/
or better svn co svn://hal.cs.berkeley.edu/home/svn/projects/trunk/deputy 

Deputy finds even more errors than CIL but requires a number of mods to the
source. CIL works as-is without source code modification. CIL only breaks in
two locations when building gcc:

build/gencondmd.c:70: Error: global initializer
error in createGlobal(insn_conditions: build/gencondmd.c:70): Errormsg.Error

/root/downloads/gcc-4_3-trunk/gcc/toplev.c:558: Error: There is a definition
already for floor_log2
error in collectFunction floor_log2: Errormsg.Error
/root/downloads/gcc-4_3-trunk/gcc/toplev.c:593: Error: There is a definition
already for exact_log2
error in collectFunction exact_log2: Errormsg.Error


To bypass these two files simply cut-and-paste the command on-screen and use
"gcc" instead of "/cil/bin/cilly", the two files will be created without using
CIL. You could also alter the files (or CIL) to fix the problem but it is
quicker to bypass.


After building Deputy (or only CIL) here is all you need to do to use CIL:

export CC=/cil/bin/cilly
export CPP='gcc -E'
export CXX=/cil/bin/cilly
#cd /gcc-build-dir
./configure
make


The above use of "export" uses cilly to replace your OS's GCC for the first 
stage of the build, subsequent stages are built with xgcc. Cilly sends the
"C" code it creates to the OS's GCC. The CIL output is fully gcc compatable
and can be linked with non-CIL ".o" files. Deputy is more complicated and I
will stick with using CIL for my reports at bugzilla until Deputy and CIL
are more popular.

Here are two examples of warnings that are found by using CIL instead of GCC:


The file "gcc-4_3-trunk/gcc/builtins.c" is normally compiled with commands
similar to these (note the use of -Wall and -pedantic). Both these commands 
produce no warnings whatsoever when compiling gcc-4_3-trunk/gcc/builtins.c .


gcc -c -g -fkeep-inline-functions -DIN_GCC -W -Wall -Wwrite-strings
-Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition
-Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros
-Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -I. -I.
-I/root/downloads/gcc-4_3-trunk/gcc -I/root/downloads/gcc-4_3-trunk/gcc/.
-I/root/downloads/gcc-4_3-trunk/gcc/../include -I./../intl
-I/root/downloads/gcc-4_3-trunk/gcc/../libcpp/include
-I/root/downloads/gcc-4_3-trunk/gcc/../libdecnumber
-I/root/downloads/gcc-4_3-trunk/gcc/../libdecnumber/bid -I../libdecnumber
/root/downloads/gcc-4_3-trunk/gcc/builtins.c -o builtins.o

/opt/gcc-4_3-build-6/./prev-gcc/xgcc -B/opt/gcc-4_3-build-6/./prev-gcc/
-B/usr/test2/i686-pc-linux-gnu/bin/ -c -O2 -g -fomit-frame-pointer -DIN_GCC -W
-Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes
-Wold-style-definition -Wmissing-format-attribute -pedantic -Wno-long-long
-Wno-variadic-macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -I.
-I. -I/root/downloads/gcc-4_3-trunk/gcc -I/root/downloads/gcc-4_3-trunk/gcc/.
-I/root/downloads/gcc-4_3-trunk/gcc/../include -I./../intl
-I/root/downloads/gcc-4_3-trunk/gcc/../libcpp/include
-I/root/downloads/gcc-4_3-trunk/gcc/../libdecnumber
-I/root/downloads/gcc-4_3-trunk/gcc/../libdecnumber/bid -I../libdecnumber
/root/downloads/gcc-4_3-trunk/gcc/builtins.c -o builtins.o



Here is one file with two warnings that cilly turned up:

/gcc-4_3-trunk/gcc/builtins.c:9410: warning: ISO C forbids casting nonscalar to
the same type
/gcc-4_3-trunk/gcc/builtins.c:9416: warning: ISO C forbids casting nonscalar to
the same type


...
      const REAL_VALUE_TYPE *const value = TREE_REAL_CST_PTR (arg0);
      struct real_value trunc, frac;
...
      case rvc_zero:
        /* For +-NaN or +-0, return (*arg1 = arg0, arg0).  */
        trunc = frac = *value;                          /* Line 9410 */
        break;
      case rvc_inf:
        /* For +-Inf, return (*arg1 = arg0, +-0).  */
        frac = dconst0;
        frac.sign = value->sign;
        trunc = *value;                                 /* Line 9416 */
        break;
      case rvc_normal:
...



Here is another that GCC doesn't show:

/gcc-4_3-trunk/gcc/config/i386/i386.c:4121: warning: unused parameter 'named'
/gcc-4_3-trunk/gcc/config/i386/i386.c:4402: warning: unused parameter 'valtype'


In these functions "named" or "valtype" are only used if "TARGET_64BIT_MS_ABI"
or "TARGET_64BIT" is defined. GCC does not report this; yet it uses this for a
command line (note "-Wall"):

/opt/gcc-4_3-build-6/gcc/xgcc -B/opt/gcc-4_3-build-6/./prev-gcc/
-B/usr/test2/i686-pc-linux-gnu/bin/ -c -O2 -g -fomit-frame-pointer -DIN_GCC -W
-Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes
-Wold-style-definition -Wmissing-format-attribute -pedantic -Wno-long-long
-Wno-variadic-macros -Wno-overlength-strings -fno-common -DHAVE_CONFIG_H -I.
-I. -I/root/downloads/gcc-4_3-trunk/gcc -I/root/downloads/gcc-4_3-trunk/gcc/.
-I/root/downloads/gcc-4_3-trunk/gcc/../include -I./../intl
-I/root/downloads/gcc-4_3-trunk/gcc/../libcpp/include
-I/root/downloads/gcc-4_3-trunk/gcc/../libdecnumber
-I/root/downloads/gcc-4_3-trunk/gcc/../libdecnumber/bid -I../libdecnumber
/root/downloads/gcc-4_3-trunk/gcc/config/i386/i386.c -o i386.o


>From gcc.info:
`-Wunused'
     All the above `-Wunused' options combined.

     In order to get a warning about an unused function parameter, you
     must either specify `-Wextra -Wunused' (note that `-Wall' implies
     `-Wunused'), or separately specify `-Wunused-parameter'.

The command line does have "-Wall" but even adding "-Wunused-parameter" still
does not trigger the warning. Here are the functions:


rtx
function_arg (CUMULATIVE_ARGS *cum, enum machine_mode omode,
              tree type, int named)
{
...
  if (TARGET_64BIT_MS_ABI)
    return function_arg_ms_64 (cum, mode, omode, named);
  else if (TARGET_64BIT)
    return function_arg_64 (cum, mode, omode, type);
  else
    return function_arg_32 (cum, mode, omode, type, bytes, words);
}



static rtx
ix86_function_value_1 (tree valtype, tree fntype_or_decl,
                       enum machine_mode orig_mode, enum machine_mode mode)
{
  tree fn, fntype;

  fn = NULL_TREE;
  if (fntype_or_decl && DECL_P (fntype_or_decl))
    fn = fntype_or_decl;
  fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;

  if (TARGET_64BIT_MS_ABI)
    return function_value_ms_64 (orig_mode, mode);
  else if (TARGET_64BIT)
    return function_value_64 (orig_mode, mode, valtype);
  else
    return function_value_32 (orig_mode, mode, fntype, fn);
}


This might indicate that GCC needs some fixing in it's warning code, unless 
you think that CIL is parsing "C" incorrectly, then write the author.


Sometimes the warnings are helpful. CIL finds a few "unused parameters" and
a "defined but not used" warning. Cil finds _many_ of the "casting nonscalar" 
warnings producing over 400 warning lines whereas GCC produces only a few.


I only built the "C" language (--enable-languages=c). I suspect there would
be even more warnings. If you discount the two most common warnings produced
when using CIL as a preprocessor then there are still over a dozen:

/gcc-4_3-trunk/gcc/config/i386/i386.c:4121: warning: unused parameter 'named'
/gcc-4_3-trunk/gcc/config/i386/i386.c:4402: warning: unused parameter 'valtype'
/gcc-4_3-trunk/gcc/config/i386/i386.c:9662: warning: unused parameter 'rel'
/gcc-4_3-trunk/gcc/config/i386/i386.md:18924: warning: operand 1 missing mode?
/gcc-4_3-trunk/gcc/config/i386/predicates.md:499: warning: unused parameter
'op'
/gcc-4_3-trunk/gcc/gengtype.c:3039: warning: label '__Cont' defined but not
used
/gcc-4_3-trunk/gcc/regmove.c:159: warning: unused parameter 'inc_insn'
/gcc-4_3-trunk/gcc/regmove.c:159: warning: unused parameter 'inc_insn_set'
/gcc-4_3-trunk/gcc/regmove.c:160: warning: unused parameter 'increment'
/gcc-4_3-trunk/gcc/regmove.c:160: warning: unused parameter 'pre'
/gcc-4_3-trunk/gcc/targhooks.c:145: warning: unused parameter 'mode'
/gcc-4_3-trunk/gcc/tree-ssa-dom.c:2093: warning: label '__Cont' defined but not
used
/gcc-4_3-trunk/libiberty/argv.c:313: warning: unused variable 'ret'



Another useful fact about using CIL (or Deputy) to compile GCC is that the
resulting executables are usable. I tried CIL on GCC version 4.3.0 20070629 .

The only difference on the "gcc tests" is this failure when using CIL:
FAIL: gcc.target/i386/cleanup-1.c (test for excess errors)


See the attachment for a long list of warnings given when using CIL.

We may want to improve GCC 4.3.0 (and prior versions) warning code.


-- 
           Summary: Compiling GCC 4.3.0 with CIL instead of using GCC 4.2 or
                    4.3 finds many warnings that GCC does not report
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rob1weld at aol dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32570



More information about the Gcc-bugs mailing list