[m-rev.] diff: avoid warnings from clang in runtime and util directories

Julien Fischer jfischer at opturion.com
Thu Mar 20 16:56:51 AEDT 2014


Branches: master, 14.01

GCC should, in principle, have picked up a lot of these as well, but for
historical reasons we disable the relevant warnings with GCC.  It's 
probably worth revisiting which warnings we do disable with GCC.

--------------------------


Avoid warnings from clang in the runtime and util directories.

runtime/mercury_stack_trace.c:
 	In the function MR_dump_stack_from_layout_clique initialise the variable
 	lines_dumped_so_far.  (This appears to be an actual bug.)

runtime/mercury_prof.c:
 	Only define the static global in_profiling_code if either of call count
 	profiling or time profiling is enabled.

runtime/mercury_context.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_profiling.c:
 	Only define some local variables in grades that require them.

runtime/mercury_float.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_construct.c:
runtime/mercury_memory_zones.c:
runtime/mercury_stm.c:
runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
 	Delete unused local variables.

util/mdemangle.c:
 	Delete an unused static global variable.

 	Use fputs in place of fprintf in a couple of places in order
 	to avoid warnings about format strings that are not string literals.

 	Delete an unused function.

util/mkinit.c:
util/mkinit_erl.c:
 	Delete unused local variables.

Julien.

diff --git a/runtime/mercury_construct.c b/runtime/mercury_construct.c
index 112fbd4..befbc7f 100644
--- a/runtime/mercury_construct.c
+++ b/runtime/mercury_construct.c
@@ -298,7 +298,6 @@ int
  MR_get_num_functors(MR_TypeInfo type_info)
  {
      MR_TypeCtorInfo type_ctor_info;
-    MR_Integer      functors;

      type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);

diff --git a/runtime/mercury_context.c b/runtime/mercury_context.c
index 3ce238e..f32b1be 100644
--- a/runtime/mercury_context.c
+++ b/runtime/mercury_context.c
@@ -879,10 +879,13 @@ static void
  MR_init_context_maybe_generator(MR_Context *c, const char *id,
      MR_GeneratorPtr gen)
  {
+
+#ifndef MR_HIGHLEVEL_CODE
      const char  *detstack_name;
      const char  *nondetstack_name;
      size_t      detstack_size;
      size_t      nondetstack_size;
+#endif

      c->MR_ctxt_id = id;
      c->MR_ctxt_next = NULL;
diff --git a/runtime/mercury_deconstruct.c b/runtime/mercury_deconstruct.c
index df6898c..f1481ab 100644
--- a/runtime/mercury_deconstruct.c
+++ b/runtime/mercury_deconstruct.c
@@ -348,7 +348,9 @@ MR_expand_type_name(MR_TypeCtorInfo tci, MR_bool wrap)
  MR_Word
  MR_arg_value_uncommon(MR_Word *arg_ptr, const MR_DuArgLocn *arg_locn)
  {
+#ifdef MR_BOXED_FLOAT
      MR_Float    flt;
+#endif
      MR_Word     val;

      /*
diff --git a/runtime/mercury_deep_copy_body.h b/runtime/mercury_deep_copy_body.h
index 5bd16ad..0b4d1ca 100644
--- a/runtime/mercury_deep_copy_body.h
+++ b/runtime/mercury_deep_copy_body.h
@@ -663,7 +663,6 @@ try_again:
      case MR_TYPECTOR_REP_BITMAP:
          {
              MR_Word *data_value;
-            int     i;

              assert(MR_tag(data) == 0);
              data_value = (MR_Word *) MR_body(data, MR_mktag(0));
@@ -765,7 +764,6 @@ try_again:
          {
              MR_Word *ref;
              MR_Word *new_ref;
-            int     i;
              MR_AllocSiteInfoPtr attrib;

              assert(MR_tag(data) == 0);
diff --git a/runtime/mercury_deep_profiling.c b/runtime/mercury_deep_profiling.c
index 4cf837f..124e378 100644
--- a/runtime/mercury_deep_profiling.c
+++ b/runtime/mercury_deep_profiling.c
@@ -380,9 +380,6 @@ static  FILE        *debug_fp;
  void
  MR_write_out_profiling_tree(void)
  {
-    int                     i;
-    MR_ProfilingHashNode    *n;
-    MR_ProcId               *pid;
      int                     root_pd_id;
      FILE                    *deep_fp;
      FILE                    *procrep_fp;
@@ -391,6 +388,11 @@ MR_write_out_profiling_tree(void)
      unsigned                num_call_seqs;
      long                    table_sizes_offset;

+#ifdef MR_DEEP_PROFILING_STATISTICS
+    int                     i;
+#endif
+
+
      deep_fp = fopen(MR_MDPROF_DATA_FILENAME, "wb+");
      if (deep_fp == NULL) {
          MR_fatal_error("cannot open `%s' for writing: %s",
@@ -651,7 +653,7 @@ MR_write_out_profiling_tree(void)
              fprintf(stderr, "\t%3d: %12d\n", i, MR_method_search_lengths[i]);
          }
      }
-#endif
+#endif /* MR_DEEP_PROFILING_STATISTICS */

  #ifdef MR_DEEP_PROFILING_DEBUG
      check_fp = debug_fp;
@@ -1532,7 +1534,6 @@ MR_write_ptr(FILE *fp, MR_NodeKind kind, int node_id)
  static void
  MR_write_kind(FILE *fp, MR_CallSiteKind kind)
  {
-    int byte;

  #ifdef  MR_DEEP_PROFILING_DETAIL_DEBUG
      if (debug_fp != NULL) {
@@ -1812,7 +1813,6 @@ MR_write_out_profiling_tree_check_unwritten(FILE *check_fp)
      int                     unwritten_pd;
      int                     unwritten_ps;
      int                     any_unwritten;
-    int                     iteration;

      unwritten_ps = MR_hash_table_check_all_written_INTERNAL(check_fp,
          "ProcLayout", MR_proc_layout_table,
diff --git a/runtime/mercury_float.c b/runtime/mercury_float.c
index e6b274b..6091ff8 100644
--- a/runtime/mercury_float.c
+++ b/runtime/mercury_float.c
@@ -70,7 +70,6 @@ MR_sprintf_float(char *buf, MR_Float f)
  {
      MR_Float round_trip = 0.0;
      int      i = MR_FLT_MIN_PRECISION;
-    int      n;

      /*
      ** Print the float at increasing precisions until the float
diff --git a/runtime/mercury_memory_zones.c b/runtime/mercury_memory_zones.c
index 207aaa4..b1b8e8d 100644
--- a/runtime/mercury_memory_zones.c
+++ b/runtime/mercury_memory_zones.c
@@ -529,8 +529,6 @@ MR_MemoryZone *
  MR_create_or_reuse_zone(const char *name, size_t size, size_t offset,
      size_t redzone_size, MR_ZoneHandler *handler)
  {
-    MR_Word         *base;
-    size_t          total_size;
      MR_MemoryZone   *zone;
      MR_bool         is_new_zone;

@@ -667,7 +665,6 @@ MR_extend_zone(MR_MemoryZone *zone, size_t new_size)
      void            *old_base;
      void            *new_base;
      size_t          offset;
-    size_t          redsize;
      size_t          copy_size;
      size_t          new_total_size;
      MR_Integer      base_incr;
diff --git a/runtime/mercury_prof.c b/runtime/mercury_prof.c
index 31030dc..6fcc751 100644
--- a/runtime/mercury_prof.c
+++ b/runtime/mercury_prof.c
@@ -85,7 +85,9 @@ MR_Code * volatile      MR_prof_current_proc;
  ** Private global variables.
  */

-static volatile int     in_profiling_code = MR_FALSE;
+#if defined(MR_MPROF_PROFILE_CALLS) || defined(MR_MPROF_PROFILE_TIME)
+  static volatile int     in_profiling_code = MR_FALSE;
+#endif

  #ifdef MR_MPROF_PROFILE_CALLS
    static MR_bool        profile_calls = MR_TRUE;
diff --git a/runtime/mercury_stack_trace.c b/runtime/mercury_stack_trace.c
index 22c7114..781714f 100644
--- a/runtime/mercury_stack_trace.c
+++ b/runtime/mercury_stack_trace.c
@@ -326,7 +326,7 @@ MR_dump_stack_from_layout_clique(FILE *fp, const MR_LabelLayout *label_layout,
      int                     proc_table_next;
      MR_Unsigned             reused_frames;
      MR_FrameLimit           level;
-    MR_SpecLineLimit        lines_dumped_so_far;
+    MR_SpecLineLimit        lines_dumped_so_far = 0;
      MR_Clique               *cliques_first;
      MR_Clique               *cliques_last;
      MR_Clique               *cl;
diff --git a/runtime/mercury_stm.c b/runtime/mercury_stm.c
index 768d5e8..bd1e7ea 100644
--- a/runtime/mercury_stm.c
+++ b/runtime/mercury_stm.c
@@ -232,7 +232,6 @@ MR_STM_write_var(MR_STM_Var *var, MR_Word value, MR_STM_TransLog *tlog)
  {

      MR_STM_TransRecord  *current;
-    MR_STM_TransRecord  *local_log;
      MR_bool             has_existing_record = MR_FALSE;

      /*
diff --git a/runtime/mercury_trace_base.c b/runtime/mercury_trace_base.c
index 9cb530d..d5fbe9a 100644
--- a/runtime/mercury_trace_base.c
+++ b/runtime/mercury_trace_base.c
@@ -461,7 +461,6 @@ MR_trace_write_label_exec_counts(FILE *fp, const char *progname,
      int                         module_num;
      int                         file_num;
      unsigned                    num_written;
-    char                        *s;

      MR_trace_name_count_port_ensure_init();

@@ -1242,7 +1241,6 @@ MR_io_tabling_stats(FILE *fp)
      MR_ConstString                  proc_name;
      int                             arity;
      MR_Word                         is_func;
-    int                             hv;
      MR_TrieNode                     answer_block_trie;
      MR_Word                         *answer_block;
      MR_Hash_Table                   hash_table;
diff --git a/runtime/mercury_type_info.c b/runtime/mercury_type_info.c
index 0d53af5..a9e2c22 100644
--- a/runtime/mercury_type_info.c
+++ b/runtime/mercury_type_info.c
@@ -360,7 +360,6 @@ MR_unify_pseudo_type_info(MR_PseudoTypeInfo pti1, MR_PseudoTypeInfo pti2)
      int                 num_arg_types_1;
      int                 num_arg_types_2;
      int                 i;
-    int                 comp;

      /*
      ** Try to optimize a common case:
@@ -568,7 +567,6 @@ MR_unify_type_info(MR_TypeInfo ti1, MR_TypeInfo ti2)
      int             num_arg_types_1;
      int             num_arg_types_2;
      int             i;
-    int             comp;

      /*
      ** Try to optimize a common case:
@@ -644,7 +642,6 @@ MR_unify_type_info(MR_TypeInfo ti1, MR_TypeInfo ti2)
  int
  MR_compare_type_ctor_info(MR_TypeCtorInfo tci1, MR_TypeCtorInfo tci2)
  {
-    int             i;
      int             comp;
      MR_ConstString  modulename1;
      MR_ConstString  modulename2;
@@ -699,8 +696,6 @@ MR_compare_type_ctor_info(MR_TypeCtorInfo tci1, MR_TypeCtorInfo tci2)
  MR_bool
  MR_unify_type_ctor_info(MR_TypeCtorInfo tci1, MR_TypeCtorInfo tci2)
  {
-    int     i;
-
      /*
      ** We are relying on the fact that type_ctor_infos are always
      ** statically allocated to ensure that two type_ctor_infos are
@@ -792,7 +787,6 @@ MR_deallocate(MR_MemoryList allocated)
  MR_Word
  MR_type_params_vector_to_list(int arity, MR_TypeInfoParams type_params)
  {
-    MR_TypeInfo arg_type;
      MR_Word     type_info_list;

      MR_restore_transient_registers();
@@ -811,7 +805,6 @@ MR_Word
  MR_pseudo_type_params_vector_to_list(int arity,
      MR_PseudoTypeInfoParams type_params)
  {
-    MR_TypeInfo arg_type;
      MR_Word     type_info_list;

      MR_restore_transient_registers();
diff --git a/util/mdemangle.c b/util/mdemangle.c
index aa9ec03..183df20 100644
--- a/util/mdemangle.c
+++ b/util/mdemangle.c
@@ -43,7 +43,6 @@ static MR_bool      check_for_suffix(char *start, char *position,
  static char         *fix_mangled_ascii(char *str, char **end);
  static MR_bool      fix_mangled_special_case(char *str, char **end);
  static MR_bool      find_double_underscore(char **str, char *end);
-static MR_bool      cut_at_double_underscore(char **str, char *end);
  static MR_bool      cut_trailing_integer(char *str, char **end, int *num);
  static MR_bool      cut_trailing_underscore_integer(char *str,
                          char **end, int *num);
@@ -204,7 +203,6 @@ demangle(const char *orig_name)
                          "__base_typeclass_info_";
      static const char common[] = "common";
      static const char arity_string[] = "arity";
-    static const char underscores_arity_string[] = "__arity";

      static const char MR_grade[] = "MR_grade_";
      static const char MR_runtime_grade[] = "MR_runtime_grade";
@@ -880,11 +878,11 @@ wrong_format:
      start = name;
      end = name + strlen(name);
      start = fix_mangled_ascii(start, &end);
-    printf(name);
+    fputs(name, stdout);
      return;

  too_long:
-    printf(orig_name);
+    fputs(orig_name, stdout);
      return;
  } /* end demangle() */

@@ -1106,24 +1104,6 @@ cut_trailing_underscore_integer(char *str, char **real_end, int *num)
  }

  /*
-** Scan for `__' and cut the string at there (replace first `_' with `\0',
-** return the part of the string after the `__').
-** Returns MR_TRUE if `__' was found, MR_FALSE otherwise.
-*/
-
-static MR_bool
-cut_at_double_underscore(char **start, char *end)
-{
-    if (! find_double_underscore(start, end)) {
-        return MR_FALSE;
-    }
-
-    **start = '\0';
-    *start = *start + 2;
-    return MR_TRUE;
-}
-
-/*
  ** Scan for `__' and return a pointer to the first `_'.
  ** Returns MR_TRUE if `__' was found, MR_FALSE otherwise.
  */
diff --git a/util/mkinit.c b/util/mkinit.c
index 1dd8217..6735f98 100644
--- a/util/mkinit.c
+++ b/util/mkinit.c
@@ -836,7 +836,6 @@ static void
  parse_options(int argc, char *argv[])
  {
      int         c;
-    int         i;
      String_List *tmp_slist;
      int         seen_f_option = 0;

@@ -1255,7 +1254,6 @@ process_init_file(const char *filename)
              char    *func_name;
              int     func_name_len;
              int     j;
-            MR_bool special;

              for (j = init_strlen; MR_isalnumunder(line[j]); j++) {
                  /* VOID */
diff --git a/util/mkinit_erl.c b/util/mkinit_erl.c
index 4a97987..1d0cb83 100644
--- a/util/mkinit_erl.c
+++ b/util/mkinit_erl.c
@@ -227,7 +227,6 @@ static int
  output_init_program(void)
  {
      int filenum;
-    int num_bunches;
      int i;

      do_path_search(files, num_files);
@@ -288,8 +287,6 @@ static void
  parse_options(int argc, char *argv[])
  {
      int         c;
-    int         i;
-    String_List *tmp_slist;
      int         seen_f_option = 0;

      /*
@@ -496,8 +493,6 @@ process_init_file(const char *filename, const char *prefix_str)
          if (strncmp(line, init_str, init_strlen) == 0) {
              char    *func_name;
              int     func_name_len;
-            int     j;
-            MR_bool special;

              func_name = line + init_strlen;
              func_name_len = strlen(func_name);
@@ -509,7 +504,6 @@ process_init_file(const char *filename, const char *prefix_str)
              std_module_next++;
          } else if (strncmp(line, reqinit_str, reqinit_strlen) == 0) {
              char    *func_name;
-            int     j;

              func_name = line + reqinit_strlen;
              MR_ensure_room_for_next(req_init_module, const char *,
@@ -518,7 +512,6 @@ process_init_file(const char *filename, const char *prefix_str)
              req_init_module_next++;
          } else if (strncmp(line, reqfinal_str, reqfinal_strlen) == 0) {
              char    *func_name;
-            int     j;

              func_name = line + reqfinal_strlen;
              MR_ensure_room_for_next(req_final_module, const char *,



More information about the reviews mailing list