bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash 2.05 end-of-loop warnings with SUNpro cc


From: Paul Eggert
Subject: Bash 2.05 end-of-loop warnings with SUNpro cc
Date: Thu, 3 May 2001 13:39:16 -0700 (PDT)

Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.7
Compiler: cc -xarch=v9 -xO2
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc' 
-DCONF_OSTYPE='solaris2.7' -DCONF_MACHTYPE='sparc-sun-solaris2.7' 
-DCONF_VENDOR='sun' -DSHELL  -DHAVE_CONFIG_H   -I.  -I.. -I../include -I../lib 
-I/usr/local/include -g
uname output: SunOS sic.twinsun.com 5.7 Generic_106541-15 sun4u sparc 
SUNW,UltraSPARC-IIi-Engine
Machine Type: sparc-sun-solaris2.7

Bash Version: 2.05
Patch Level: 0
Release Status: release

Description:
        SUNWpro cc (Sun WorkShop 6 update 1 C 5.2 2000/09/11)
        issues several end-of-loop warnings when compiling Bash 2.05.

        This is not a correctness issue, just a convenience.  In most
        cases, rewriting the code to avoid the warning makes the code
        shorter.  The only exception is bind.def, where it gets a bit
        longer.

Repeat-By:
        $ ../configure
        $ make

        You'll see lots of warnings like this:

        "../../builtins/../../builtins/getopts.def", line 315: warning: 
end-of-loop code not reached

        "../../../lib/readline/bind.c", line 1456: warning: end-of-loop code 
not reached
        "../../../lib/readline/bind.c", line 1458: warning: end-of-loop code 
not reached
        "../../../lib/readline/bind.c", line 1460: warning: end-of-loop code 
not reached
        "../../../lib/readline/bind.c", line 1462: warning: end-of-loop code 
not reached

        "../../../lib/readline/histexpand.c", line 240: warning: end-of-loop 
code not reached
        "../../../lib/readline/histexpand.c", line 249: warning: end-of-loop 
code not reached
        "../../../lib/readline/histexpand.c", line 275: warning: end-of-loop 
code not reached

        etc. etc.

Fix:
The following fix assumes the patches I've sent in already.

2001-05-03  Paul Eggert  <address@hidden>

        * builtins/bind.def (build_builtin):
        Adjust code to avoid SunPRO cc end-of-loop warning.
        * builtins/getopts.def (getopts_builtin): Likewise.
        * builtins/printf.def (PRETURN, printf_builtin): Likewise.
        * builtins/wait.def (WAIT_RETURN): Likewise.
        * lib/readline/bind.c (sv_bell_style): Likewise.
        * lib/readline/histexpand.c (FAIL_SEARCH): Likewise.
        * parse.y (COND_RETURN_ERROR): Likewise.
        * subst.c: (CQ_RETURN, ASSIGN_RETURN): Likewise.
        * test.c (or, and): Likewise.

        * lib/readline/bind.c (_SET_BELL): Remove.
        * builtins/bind.def (BIND_RETURN): Remove.

===================================================================
RCS file: builtins/getopts.def,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- builtins/getopts.def        2001/02/14 22:09:23     2.5
+++ builtins/getopts.def        2001/05/03 20:13:05     2.5.0.1
@@ -304,14 +304,10 @@ getopts_builtin (list)
     }
 
   reset_internal_getopt ();
-  while ((ret = internal_getopt (list, "")) != -1)
+  if (internal_getopt (list, "") != -1)
     {
-      switch (ret)
-       {
-       default:
-         builtin_usage ();
-         return (EX_USAGE);
-       }
+      builtin_usage ();
+      return (EX_USAGE);
     }
   list = loptend;
 
===================================================================
RCS file: builtins/printf.def,v
retrieving revision 2.5.0.8
retrieving revision 2.5.0.9
diff -pu -r2.5.0.8 -r2.5.0.9
--- builtins/printf.def 2001/05/01 01:13:01     2.5.0.8
+++ builtins/printf.def 2001/05/03 20:13:05     2.5.0.9
@@ -117,7 +117,7 @@ extern int errno;
   } while (0)
 
 #define PRETURN(value) \
-  do { free (conv); fflush (stdout); return (value); } while (0)
+  return (free (conv), fflush (stdout), value)
 
 #define  SKIP1 "#'-+ 0"
 #define  SKIP2 "hjlLtz"
@@ -148,15 +148,10 @@ printf_builtin (list)
 
   retval = EXECUTION_SUCCESS;
   reset_internal_getopt ();
-  while ((ch = internal_getopt (list, "")) != -1)
+  if (internal_getopt (list, "") != -1)
     {
-      switch (ch)
-       {
-       case '?':
-       default:
-         builtin_usage();
-         return (EX_USAGE);
-       }
+      builtin_usage();
+      return (EX_USAGE);
     }
   list = loptend;
 
===================================================================
RCS file: builtins/wait.def,v
retrieving revision 2.5.0.2
retrieving revision 2.5.0.3
diff -pu -r2.5.0.2 -r2.5.0.3
--- builtins/wait.def   2001/05/01 01:13:01     2.5.0.2
+++ builtins/wait.def   2001/05/03 20:13:05     2.5.0.3
@@ -67,12 +67,7 @@ procenv_t wait_intr_buf;
    the last one waited for. */
 
 #define WAIT_RETURN(s) \
-  do \
-    { \
-      interrupt_immediately = old_interrupt_immediately;\
-      return (s);\
-    } \
-  while (0)
+  return (interrupt_immediately = old_interrupt_immediately, s)
 
 int
 wait_builtin (list)
===================================================================
RCS file: lib/readline/bind.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- lib/readline/bind.c 2001/03/05 15:10:07     2.5
+++ lib/readline/bind.c 2001/05/03 20:13:05     2.5.0.1
@@ -1446,24 +1446,22 @@ sv_keymap (value)
   return 1;
 }
 
-#define _SET_BELL(v)   do { _rl_bell_preference = v; return 0; } while (0)
-
 static int
 sv_bell_style (value)
      const char *value;
 {
   if (value == 0 || *value == '\0')
-    _SET_BELL (AUDIBLE_BELL);
+    _rl_bell_preference = AUDIBLE_BELL;
   else if (_rl_stricmp (value, "none") == 0 || _rl_stricmp (value, "off") == 0)
-    _SET_BELL (NO_BELL);
+    _rl_bell_preference = NO_BELL;
   else if (_rl_stricmp (value, "audible") == 0 || _rl_stricmp (value, "on") == 
0)
-    _SET_BELL (AUDIBLE_BELL);
+    _rl_bell_preference = AUDIBLE_BELL;
   else if (_rl_stricmp (value, "visible") == 0)
-    _SET_BELL (VISIBLE_BELL);
+    _rl_bell_preference = VISIBLE_BELL;
   else
     return 1;
+  return 0;
 }
-#undef _SET_BELL
 
 static int
 sv_isrchterm (value)
===================================================================
RCS file: lib/readline/histexpand.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- lib/readline/histexpand.c   2001/03/06 19:09:25     2.5
+++ lib/readline/histexpand.c   2001/05/03 20:13:05     2.5.0.1
@@ -223,9 +223,7 @@ get_history_event (string, caller_index,
   *caller_index = i;
 
 #define FAIL_SEARCH() \
-  do { \
-    history_offset = history_length; free (temp) ; return (char *)NULL; \
-  } while (0)
+  return (history_offset = history_length, free (temp), (char *) NULL)
 
   /* If there is no search string, try to use the previous search string,
      if one exists.  If not, fail immediately. */
===================================================================
RCS file: parse.y,v
retrieving revision 2.5.0.2
retrieving revision 2.5.0.3
diff -pu -r2.5.0.2 -r2.5.0.3
--- parse.y     2001/05/01 17:14:41     2.5.0.2
+++ parse.y     2001/05/03 20:13:05     2.5.0.3
@@ -2724,7 +2724,7 @@ cond_skip_newlines ()
 }
 
 #define COND_RETURN_ERROR() \
-  do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
+  return (cond_token = COND_ERROR, (COND_COM *) NULL)
 
 static COND_COM *
 cond_term ()
===================================================================
RCS file: subst.c,v
retrieving revision 2.5.0.8
retrieving revision 2.5.0.9
diff -pu -r2.5.0.8 -r2.5.0.9
--- subst.c     2001/05/01 17:22:02     2.5.0.8
+++ subst.c     2001/05/03 20:13:05     2.5.0.9
@@ -1029,7 +1029,7 @@ unquote_bang (string)
    single and double-quoted string parsing functions should not return an
    error if there are unclosed quotes or braces. */
 
-#define CQ_RETURN(x) do { no_longjmp_on_fatal_error = 0; return (x); } while 
(0)
+#define CQ_RETURN(x) return (no_longjmp_on_fatal_error = 0, x)
 
 int
 char_is_quoted (string, eindex)
@@ -1809,7 +1809,7 @@ do_assignment_internal (string, expand)
 #endif
     fprintf (stderr, "%s%s=%s\n", indirection_level_string (), name, value);
 
-#define ASSIGN_RETURN(r)       do { FREE (value); free (name); return (r); } 
while (0)
+#define ASSIGN_RETURN(r) return (free (value), free (name), r)
 
 #if defined (ARRAY_VARS)
   if (t = strchr (name, '['))  /*]*/
===================================================================
RCS file: test.c,v
retrieving revision 2.5.0.4
retrieving revision 2.5.0.5
diff -pu -r2.5.0.4 -r2.5.0.5
--- test.c      2001/05/01 17:22:02     2.5.0.4
+++ test.c      2001/05/03 20:13:05     2.5.0.5
@@ -278,7 +278,7 @@ or ()
   int value, v2;
 
   value = and ();
-  while (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'o' && 
!argv[pos][2])
+  if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'o' && 
!argv[pos][2])
     {
       advance (0);
       v2 = or ();
@@ -299,7 +299,7 @@ and ()
   int value, v2;
 
   value = term ();
-  while (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'a' && 
!argv[pos][2])
+  if (pos < argc && argv[pos][0] == '-' && argv[pos][1] == 'a' && 
!argv[pos][2])
     {
       advance (0);
       v2 = and ();
===================================================================
RCS file: builtins/bind.def,v
retrieving revision 2.5.0.1
retrieving revision 2.5.0.2
diff -pu -r2.5.0.1 -r2.5.0.2
--- builtins/bind.def   2001/05/03 19:02:50     2.5.0.1
+++ builtins/bind.def   2001/05/03 20:13:05     2.5.0.2
@@ -81,8 +81,6 @@ static int unbind_command ();
 
 extern int no_line_editing;
 
-#define BIND_RETURN(x)  do { return_code = x; goto bind_exit; } while (0)
-
 #define LFLAG  0x0001
 #define PFLAG  0x0002
 #define FFLAG  0x0004
@@ -173,7 +171,8 @@ bind_builtin (list)
          break;
        default:
          builtin_usage ();
-         BIND_RETURN (EX_USAGE);
+         return_code = EX_USAGE;
+         goto bind_exit;
        }
     }
 
@@ -188,7 +187,8 @@ bind_builtin (list)
       if (!kmap)
        {
          builtin_error ("`%s': invalid keymap name", map_name);
-         BIND_RETURN (EXECUTION_FAILURE);
+         return_code = EXECUTION_FAILURE;
+         goto bind_exit;
        }
     }
 
@@ -227,7 +227,8 @@ bind_builtin (list)
       if (rl_read_init_file (initfile) != 0)
        {
          builtin_error ("cannot read %s: %s", initfile, strerror (errno));
-         BIND_RETURN (EXECUTION_FAILURE);
+         return_code = EXECUTION_FAILURE;
+         goto bind_exit;
        }
     }
 
@@ -242,7 +243,8 @@ bind_builtin (list)
       if (rl_set_key (remove_seq, (Function *)NULL, rl_get_keymap ()) != 0)
        {
          builtin_error ("cannot unbind %s", remove_seq);
-         BIND_RETURN (EXECUTION_FAILURE);
+         return_code = EXECUTION_FAILURE;
+         goto bind_exit;
        }
     }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]