[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 'noreturn' warning in libcruft
From: |
John W. Eaton |
Subject: |
Re: 'noreturn' warning in libcruft |
Date: |
Tue, 7 Aug 2012 13:16:39 -0400 |
On 7-Aug-2012, Rik wrote:
| On 08/07/2012 09:26 AM, Michael Goffioul wrote:
|
| On Tue, Aug 7, 2012 at 5:22 PM, Rik <address@hidden> wrote:
|
| 8/7/12
|
| All,
|
| When compiling libcruft/misc/f77-fcn.c I get the following warning:
|
| ../../octave-dev/libcruft/misc/f77-fcn.c: In function ‘xstopx_’:
| ../../octave-dev/libcruft/misc/f77-fcn.c:63: warning: function
declared
| ‘noreturn’ has a ‘return’ statement
|
| If I look in libcruft/misc/f77-fcn.h I find the following prototype:
|
| extern CRUFT_API F77_RET_T
| F77_FUNC (xstopx, XSTOPX) (F77_CONST_CHAR_ARG_DECL
| F77_CHAR_ARG_LEN_DECL)
| GCC_ATTR_NORETURN;
|
| The 'noreturn' attribute is being explicitly set for this function so
| that
| seems okay.
|
| The actual function is
|
| F77_RET_T
| #if defined (F77_USES_CRAY_CALLING_CONVENTION)
| F77_FUNC (xstopx, XSTOPX) (octave_cray_ftn_ch_dsc desc)
| #elif defined (F77_USES_VISUAL_FORTRAN_CALLING_CONVENTION)
| F77_FUNC (xstopx, XSTOPX) (const char *s, int slen)
| #else
| F77_FUNC (xstopx, XSTOPX) (const char *s, long slen)
| #endif
| {
| #if defined (F77_USES_CRAY_CALLING_CONVENTION)
| const char *s = desc.const_ptr = ptr_arg;
| unsigned long slen = desc.mask.len;
| #endif
|
| f77_exception_encountered = 1;
|
| /* Skip printing message if it is just a single blank character. *
| /
| if (s && slen > 0 && ! (slen == 1 && *s == ' '))
| (*current_liboctave_error_handler) ("%.*s", slen, s);
|
| octave_jump_to_enclosing_context ();
|
| F77_RETURN (0)
| }
|
| So the function is declared 'noreturn' and yet has a return statement.
| The
| function before the return, octave_jump_to_enclosing_context(), does
| indeed
| do a longjmp so it seems like the F77_RETURN(0) can just be eliminated
| from
| the code.
|
| Any objections to that deletion?
|
|
| Deleting it would assume that GCC_ATTR_NORETURN is always defined
properly.
| Would it be a problem to leave it in place?
|
| Leaving the code in place is what provokes the warning that I am trying to
| silence. Note that regardless of whether GCC_ATTR_NORETURN is declared for
| this function, the particular line of code F77_RETURN(0) will never be
| executed. The noreturn attribute is merely warning us that we're being
| redundant since there is no way to get to the return statement because the
| longjmp in octave_jum_to_enclosing_context() will always intervene.
Deleting the F77_RETURN(0) will avoid the warning if GCC_ATTR_NORETURN
is defined because octave_jump_to_enclosing_context is tagged with
GCC_ATTR_NORETURN.
But if you delete the F77_RETURN (0) line and GCC_ATTR_NORETURN is not
defined, you will likely get a warning about "control reaches end of
non-void function".
So how about using
#ifndef GCC_ATTR_NORETURN
F77_RETURN (0)
#endif
?
Note that this only matters if F77_RET_T is int. If it is void, then
F77_RETURN expands to nothing and there is no inconsistency about
return type and falling off the end of the function without a return
statement.
Thinking about this again though, maybe it is confusing to have
F77_RETURN expand to nothing (shouldn't it return?). But the point
of it was just to provide a way to define a C function that would
behave like a Fortran subroutine and to avoid GCC's "control reaches
end of non-void function" warning. Maybe we should really have a few
different types of F77_RETURN macros?
F77_RETURN (retval) ! same as we have now, except that it should
! be defined to "return;" if F77_RET_T is
! defined as "void".
F77_NORETURN (retval) ! expands to nothing if either
! GCC_ATTR_NORETURN is defined or if
! F77_RET_T is defined as "void". Otherwise,
! expand to "return retval;"
Then the xstopx function should use F77_NORETURN instead of
F77_RETURN. Does that make sense?
jwe
- Re: 'noreturn' warning in libcruft, (continued)
- Re: 'noreturn' warning in libcruft, Michael Goffioul, 2012/08/07
- Re: 'noreturn' warning in libcruft, John W. Eaton, 2012/08/07
- Re: 'noreturn' warning in libcruft, Michael Goffioul, 2012/08/07
- Re: 'noreturn' warning in libcruft, John W. Eaton, 2012/08/07
- Re: 'noreturn' warning in libcruft, Rik, 2012/08/07
- Re: 'noreturn' warning in libcruft, John W. Eaton, 2012/08/07
- Re: 'noreturn' warning in libcruft, Rik, 2012/08/07
- Re: 'noreturn' warning in libcruft, John W. Eaton, 2012/08/08
- Re: 'noreturn' warning in libcruft,
John W. Eaton <=