[m-rev.] for review: Enable some clang warnings.

Peter Wang novalazy at gmail.com
Sun Sep 9 14:28:17 AEST 2018


There are a couple of issues we may wish to work out before applying
this.

(1) hard_coded/deep_copy.m and hard_coded/deep_copy_exist.m fail because
the compiler generates:

  static const MR_DuFunctorDesc deep_copy__deep_copy__du_functor_desc_bit_vector_test_1_0 = {
    (MR_String) "tuple_a",
    (MR_Integer) 18,
    (MR_Integer) 32768,
    ...

where the third field of MR_DuFunctorDesc has type MR_int_least16_t
so clang warns that:

  deep_copy.c:867:3: error: implicit conversion from 'MR_Integer'
  (aka 'long') to 'MR_int_least16_t' (aka 'short') changes value from
  32768 to -32768 [-Werror,-Wconstant-conversion]

Many of the fields in the type info structures should be changed to
unsigned types at some stage, I suppose.

(2) Some tests in the `valid' directory use looping predicates, which
clang picks up on. It is possible to suppress the warnings with
-Wno-infinite-recursion but it would be better to modify those test
cases. Should we replace the looping predicates with external_pred,
for example? These are the tests:

    valid/higher_order5
    valid/loop_in_disj
    valid/mode_syntax
    valid/recursive_no_tag_type
    valid/same_length_2
    valid/stack_alloc

---

configure.ac:
scripts/mgnuc.in:
    Enable some warnings when compiling with clang.

    Disable a few warnings implied by -Wall so that the existing
    hand written or generated code compiles.

diff --git a/configure.ac b/configure.ac
index 155061e98..6012f65f2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4624,21 +4624,21 @@ case "$mercury_cv_cc_type" in
         ;;
 
     clang*)
 
         # We do not compile with -ansi when using clang because that (currently) puts
         # clang into C89 mode and we want to use C99's inline keyword with clang.
         CFLAGS_FOR_ANSI=
 
         # XXX we need go through the warning and optimization options for clang
         # more carefully.
-        CFLAGS_FOR_WARNINGS="-w"
+        CFLAGS_FOR_WARNINGS="-Wall -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wno-parentheses-equality -Wno-non-literal-null-conversion -Wno-unused-function -Wno-unused-variable -Wno-uninitialized"
 
         # Disable C compiler optimizations for old versions of clang.
         # (See above for details.)
         case "$C_COMPILER_TYPE" in
             clang_0_*|clang_1_*|clang_2_*)
                 CFLAGS_FOR_OPT="-O0 -fomit-frame-pointer"
             ;;
             *)
                 CFLAGS_FOR_OPT="-O2 -fomit-frame-pointer"
                 OPT_FLAGS_FOR_CLANG="-O2"
diff --git a/scripts/mgnuc.in b/scripts/mgnuc.in
index 811cfe3c9..bb6e1553e 100644
--- a/scripts/mgnuc.in
+++ b/scripts/mgnuc.in
@@ -69,21 +69,23 @@ case "$C_COMPILER_TYPE" in
               OPT_OPTS="-O2 $CFLAGS_FOR_NO_STRICT_ALIASING -fomit-frame-pointer"
               ;;
         esac
         DEBUG_OPT="-g"
         DISABLE_OPTS_OPT="-O0"
         COMPILER_HALT_AT_WARN_OPT="-Werror"
         COMPILER=gcc
         ;;
     clang*)
         ANSI_OPTS=
-        CHECK_OPTS="-w"
+        CHECK_OPTS="-Wall -Wshadow -Wstrict-prototypes -Wmissing-prototypes
+            -Wno-parentheses-equality -Wno-non-literal-null-conversion
+            -Wno-unused-function -Wno-unused-variable -Wno-uninitialized"
         OPT_OPTS="@OPT_FLAGS_FOR_CLANG@ $CFLAGS_FOR_NO_STRICT_ALIASING -fomit-frame-pointer"
         DEBUG_OPT="-g"
         DISABLE_OPTS_OPT="-O0"
         COMPILER_HALT_AT_WARN_OPT="-Werror"
         COMPILER=clang
         ;;
     msvc*)
         ANSI_OPTS=""
         CHECK_OPTS="-nologo"    # Suppress the MSVC banner message.
         OPT_OPTS=""


More information about the reviews mailing list