Silence warnings with new GCC

David Holmes david.holmes at oracle.com
Thu Nov 26 21:21:21 UTC 2015


On 27/11/2015 3:24 AM, Andrew Haley wrote:
> I've been getting a lot of warnings such as
>
> warning: 'size' may be used uninitialized in this function [-Wmaybe-uninitialized]
>
> which error out with -Werror.  Almost all of them are bogus.  They are
> typically of the form
>
>      unsigned size;
>
>      if (i->get(26, 26)) { // float
>        switch(i->get(31, 30)) {
>        case 0b10:
>          size = 2; break;
>        case 0b01:
>          size = 1; break;
>        case 0b00:
>          size = 0; break;
>        default:
>          ShouldNotReachHere();
>        }
>      } else {
>        size = i->get(31, 31);
>      }
>
> The problem here is that GCC does not know that ShouldNotReachHere()
> should be treated as an unreachable statement.

Strictly speaking it is of course reachable, but if we do reach it we 
expect never to return. As per the thread Mario pointed to we ran into 
problems trying to mark this as not returning. But I wonder whether 
lying to the compiler about the reachability of it would be a 
workaround? Of course if the compiler used that information to elide the 
ShouldNotReachHere() then that is not acceptable.

David

> The patch here fixes it.  I'd rather do this than add pointless assignments
> all over the place.  Thoughts?  Opinions?
>
> Thanks,
>
> Andrew.
>
>
>
> diff --git a/src/share/vm/utilities/debug.hpp b/src/share/vm/utilities/debug.hpp
> --- a/src/share/vm/utilities/debug.hpp
> +++ b/src/share/vm/utilities/debug.hpp
> @@ -172,16 +172,24 @@
>     BREAKPOINT;                                                                     \
>   } while (0)
>
> +#ifdef __GNUC__
> +#  define UNREACHABLE __builtin_unreachable()
> +#else
> +#  define UNREACHABLE do { } while (0)
> +#endif
> +
>   #define ShouldNotReachHere()                                                      \
>   do {                                                                              \
>     report_should_not_reach_here(__FILE__, __LINE__);                               \
>     BREAKPOINT;                                                                     \
> +  UNREACHABLE;                                                                    \
>   } while (0)
>
>   #define Unimplemented()                                                           \
>   do {                                                                              \
>     report_unimplemented(__FILE__, __LINE__);                                       \
>     BREAKPOINT;                                                                     \
> +  UNREACHABLE;                                                                    \
>   } while (0)
>
>   #define Untested(msg)
>



More information about the build-dev mailing list