Silence warnings with new GCC

Andrew Haley aph at redhat.com
Thu Nov 26 17:24:14 UTC 2015


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.

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