MSVC 2019 Fixes (#285)

* resolvename is declared to return a bool value, but instead can return NULL. MSVC 2019 does not like that an throws a compile error. Fixed by returning false instead of NULL.

* When compiling with MSVC 2019, the UPB_ASSUME macro expands out to:

do {} if (false && (ok))

That isn't valid C code. Fixed by adding an elif for MSVC that uses __assume(0), which is similar to gcc's __builtin_unreachable according to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0627r0.pdf.
pull/13171/head
Charlie Savage 5 years ago committed by GitHub
parent a1c2caeb25
commit 93e2a40881
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      upb/def.c
  2. 2
      upb/port_def.inc

@ -1191,7 +1191,7 @@ static bool resolvename(const upb_strtable *t, const upb_fielddef *f,
const char *base, upb_strview sym,
upb_deftype_t type, upb_status *status,
const void **def) {
if(sym.size == 0) return NULL;
if(sym.size == 0) return false;
if(sym.data[0] == '.') {
/* Symbols starting with '.' are absolute, so we do a single lookup.
* Slice to omit the leading '.' */

@ -138,6 +138,8 @@ int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg);
#ifdef NDEBUG
#ifdef __GNUC__
#define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable()
#elif defined _MSC_VER
#define UPB_ASSUME(expr) if (!(expr)) __assume(0)
#else
#define UPB_ASSUME(expr) do {} if (false && (expr))
#endif

Loading…
Cancel
Save