Merge pull request #253 from haberman/warnings

The compile is now clean of -Wshorten-64-to-32 warnings.
pull/13171/head
Joshua Haberman 5 years ago committed by GitHub
commit 97bcd5276c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      generated_for_cmake/upb/json/parser.c
  2. 4
      tests/pb/test_varint.c
  3. 18
      upb/def.c
  4. 3
      upb/handlers.c
  5. 4
      upb/json/parser.rl
  6. 4
      upb/json/printer.c
  7. 14
      upb/pb/compile_decoder.c
  8. 34
      upb/pb/decoder.c
  9. 2
      upb/pb/encoder.c
  10. 3
      upb/pb/varint.int.h
  11. 4
      upb/reflection.c

@ -970,7 +970,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf,
} else if (val > INT32_MAX || val < INT32_MIN) { } else if (val > INT32_MAX || val < INT32_MIN) {
return false; return false;
} else { } else {
upb_sink_putint32(p->top->sink, parser_getsel(p), val); upb_sink_putint32(p->top->sink, parser_getsel(p), (int32_t)val);
return true; return true;
} }
} }
@ -981,7 +981,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf,
} else if (val > UINT32_MAX || errno == ERANGE) { } else if (val > UINT32_MAX || errno == ERANGE) {
return false; return false;
} else { } else {
upb_sink_putuint32(p->top->sink, parser_getsel(p), val); upb_sink_putuint32(p->top->sink, parser_getsel(p), (uint32_t)val);
return true; return true;
} }
} }

@ -16,7 +16,7 @@ static void test_varint_for_num(upb_decoderet (*decoder)(const char*),
bytes = upb_vencode64(num, buf); bytes = upb_vencode64(num, buf);
if (num <= UINT32_MAX) { if (num <= UINT32_MAX) {
uint64_t encoded = upb_vencode32(num); uint64_t encoded = upb_vencode32((uint32_t)num);
char buf2[16]; char buf2[16];
upb_decoderet r; upb_decoderet r;
@ -44,7 +44,7 @@ static void test_varint_for_num(upb_decoderet (*decoder)(const char*),
r = decoder(buf2); r = decoder(buf2);
ASSERT(r.val == num); ASSERT(r.val == num);
ASSERT(r.p == buf2 + upb_value_size(encoded)); ASSERT(r.p == buf2 + upb_value_size(encoded));
ASSERT(upb_zzenc_32(upb_zzdec_32(num)) == num); ASSERT(upb_zzenc_32(upb_zzdec_32((uint32_t)num)) == num);
} }
r = decoder(buf); r = decoder(buf);

@ -353,7 +353,7 @@ int32_t upb_enumdef_default(const upb_enumdef *e) {
} }
int upb_enumdef_numvals(const upb_enumdef *e) { int upb_enumdef_numvals(const upb_enumdef *e) {
return upb_strtable_count(&e->ntoi); return (int)upb_strtable_count(&e->ntoi);
} }
void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) { void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) {
@ -525,7 +525,7 @@ int64_t upb_fielddef_defaultint64(const upb_fielddef *f) {
int32_t upb_fielddef_defaultint32(const upb_fielddef *f) { int32_t upb_fielddef_defaultint32(const upb_fielddef *f) {
chkdefaulttype(f, UPB_TYPE_INT32); chkdefaulttype(f, UPB_TYPE_INT32);
return f->defaultval.sint; return (int32_t)f->defaultval.sint;
} }
uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) {
@ -535,7 +535,7 @@ uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) {
uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f) { uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f) {
chkdefaulttype(f, UPB_TYPE_UINT32); chkdefaulttype(f, UPB_TYPE_UINT32);
return f->defaultval.uint; return (uint32_t)f->defaultval.uint;
} }
bool upb_fielddef_defaultbool(const upb_fielddef *f) { bool upb_fielddef_defaultbool(const upb_fielddef *f) {
@ -696,12 +696,12 @@ bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
int upb_msgdef_numfields(const upb_msgdef *m) { int upb_msgdef_numfields(const upb_msgdef *m) {
/* The number table contains only fields. */ /* The number table contains only fields. */
return upb_inttable_count(&m->itof); return (int)upb_inttable_count(&m->itof);
} }
int upb_msgdef_numoneofs(const upb_msgdef *m) { int upb_msgdef_numoneofs(const upb_msgdef *m) {
/* The name table includes oneofs, and the number table does not. */ /* The name table includes oneofs, and the number table does not. */
return upb_strtable_count(&m->ntof) - upb_inttable_count(&m->itof); return (int)(upb_strtable_count(&m->ntof) - upb_inttable_count(&m->itof));
} }
const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m) { const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m) {
@ -795,7 +795,7 @@ const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) {
} }
int upb_oneofdef_numfields(const upb_oneofdef *o) { int upb_oneofdef_numfields(const upb_oneofdef *o) {
return upb_strtable_count(&o->ntof); return (int)upb_strtable_count(&o->ntof);
} }
uint32_t upb_oneofdef_index(const upb_oneofdef *o) { uint32_t upb_oneofdef_index(const upb_oneofdef *o) {
@ -885,8 +885,8 @@ static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) {
} }
} }
static size_t upb_msglayout_place(upb_msglayout *l, size_t size) { static uint32_t upb_msglayout_place(upb_msglayout *l, size_t size) {
size_t ret; uint32_t ret;
l->size = align_up(l->size, size); l->size = align_up(l->size, size);
ret = l->size; ret = l->size;
@ -1940,7 +1940,7 @@ const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name)
} }
int upb_symtab_filecount(const upb_symtab *s) { int upb_symtab_filecount(const upb_symtab *s) {
return upb_strtable_count(&s->files); return (int)upb_strtable_count(&s->files);
} }
static const upb_filedef *_upb_symtab_addfile( static const upb_filedef *_upb_symtab_addfile(

@ -180,7 +180,8 @@ static upb_handlers *upb_handlers_new(const upb_msgdef *md,
int extra; int extra;
upb_handlers *h; upb_handlers *h;
extra = sizeof(upb_handlers_tabent) * (upb_msgdef_selectorcount(md) - 1); extra =
(int)(sizeof(upb_handlers_tabent) * (upb_msgdef_selectorcount(md) - 1));
h = upb_calloc(arena, sizeof(*h) + extra); h = upb_calloc(arena, sizeof(*h) + extra);
if (!h) return NULL; if (!h) return NULL;

@ -968,7 +968,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf,
} else if (val > INT32_MAX || val < INT32_MIN) { } else if (val > INT32_MAX || val < INT32_MIN) {
return false; return false;
} else { } else {
upb_sink_putint32(p->top->sink, parser_getsel(p), val); upb_sink_putint32(p->top->sink, parser_getsel(p), (int32_t)val);
return true; return true;
} }
} }
@ -979,7 +979,7 @@ static bool parse_number_from_buffer(upb_json_parser *p, const char *buf,
} else if (val > UINT32_MAX || errno == ERANGE) { } else if (val > UINT32_MAX || errno == ERANGE) {
return false; return false;
} else { } else {
upb_sink_putuint32(p->top->sink, parser_getsel(p), val); upb_sink_putuint32(p->top->sink, parser_getsel(p), (uint32_t)val);
return true; return true;
} }
} }

@ -89,7 +89,7 @@ strpc *newstrpc_str(upb_handlers *h, const char * str) {
/* ------------ JSON string printing: values, maps, arrays ------------------ */ /* ------------ JSON string printing: values, maps, arrays ------------------ */
static void print_data( static void print_data(
upb_json_printer *p, const char *buf, unsigned int len) { upb_json_printer *p, const char *buf, size_t len) {
/* TODO: Will need to change if we support pushback from the sink. */ /* TODO: Will need to change if we support pushback from the sink. */
size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL); size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL);
UPB_ASSERT(n == len); UPB_ASSERT(n == len);
@ -129,7 +129,7 @@ UPB_INLINE const char* json_nice_escape(char c) {
/* Write a properly escaped string chunk. The surrounding quotes are *not* /* Write a properly escaped string chunk. The surrounding quotes are *not*
* printed; this is so that the caller has the option of emitting the string * printed; this is so that the caller has the option of emitting the string
* content in chunks. */ * content in chunks. */
static void putstring(upb_json_printer *p, const char *buf, unsigned int len) { static void putstring(upb_json_printer *p, const char *buf, size_t len) {
const char* unescaped_run = NULL; const char* unescaped_run = NULL;
unsigned int i; unsigned int i;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {

@ -156,7 +156,9 @@ static void setofs(uint32_t *instruction, int32_t ofs) {
UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */ UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */
} }
static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; } static uint32_t pcofs(compiler *c) {
return (uint32_t)(c->pc - c->group->bytecode);
}
/* Defines a local label at the current PC location. All previous forward /* Defines a local label at the current PC location. All previous forward
* references are updated to point to this location. The location is noted * references are updated to point to this location. The location is noted
@ -170,7 +172,7 @@ static void label(compiler *c, unsigned int label) {
codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val; codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val;
while (codep) { while (codep) {
int ofs = getofs(*codep); int ofs = getofs(*codep);
setofs(codep, c->pc - codep - instruction_len(*codep)); setofs(codep, (int32_t)(c->pc - codep - instruction_len(*codep)));
codep = ofs ? codep + ofs : NULL; codep = ofs ? codep + ofs : NULL;
} }
c->fwd_labels[label] = EMPTYLABEL; c->fwd_labels[label] = EMPTYLABEL;
@ -192,7 +194,7 @@ static int32_t labelref(compiler *c, int label) {
return 0; return 0;
} else if (label < 0) { } else if (label < 0) {
/* Backward local label. Relative to the next instruction. */ /* Backward local label. Relative to the next instruction. */
uint32_t from = (c->pc + 1) - c->group->bytecode; uint32_t from = (uint32_t)((c->pc + 1) - c->group->bytecode);
return c->back_labels[-label] - from; return c->back_labels[-label] - from;
} else { } else {
/* Forward local label: prepend to (possibly-empty) linked list. */ /* Forward local label: prepend to (possibly-empty) linked list. */
@ -226,7 +228,7 @@ static void putop(compiler *c, int op, ...) {
case OP_SETDISPATCH: { case OP_SETDISPATCH: {
uintptr_t ptr = (uintptr_t)va_arg(ap, void*); uintptr_t ptr = (uintptr_t)va_arg(ap, void*);
put32(c, OP_SETDISPATCH); put32(c, OP_SETDISPATCH);
put32(c, ptr); put32(c, (uint32_t)ptr);
if (sizeof(uintptr_t) > sizeof(uint32_t)) if (sizeof(uintptr_t) > sizeof(uint32_t))
put32(c, (uint64_t)ptr >> 32); put32(c, (uint64_t)ptr >> 32);
break; break;
@ -285,7 +287,7 @@ static void putop(compiler *c, int op, ...) {
case OP_TAG2: { case OP_TAG2: {
int label = va_arg(ap, int); int label = va_arg(ap, int);
uint64_t tag = va_arg(ap, uint64_t); uint64_t tag = va_arg(ap, uint64_t);
uint32_t instruction = op | (tag << 16); uint32_t instruction = (uint32_t)(op | (tag << 16));
UPB_ASSERT(tag <= 0xffff); UPB_ASSERT(tag <= 0xffff);
setofs(&instruction, labelref(c, label)); setofs(&instruction, labelref(c, label));
put32(c, instruction); put32(c, instruction);
@ -297,7 +299,7 @@ static void putop(compiler *c, int op, ...) {
uint32_t instruction = op | (upb_value_size(tag) << 16); uint32_t instruction = op | (upb_value_size(tag) << 16);
setofs(&instruction, labelref(c, label)); setofs(&instruction, labelref(c, label));
put32(c, instruction); put32(c, instruction);
put32(c, tag); put32(c, (uint32_t)tag);
put32(c, tag >> 32); put32(c, tag >> 32);
break; break;
} }

@ -185,7 +185,7 @@ static int32_t skip(upb_pbdecoder *d, size_t bytes) {
UPB_ASSERT(d->skip == 0); UPB_ASSERT(d->skip == 0);
if (bytes > delim_remaining(d)) { if (bytes > delim_remaining(d)) {
seterr(d, "Skipped value extended beyond enclosing submessage."); seterr(d, "Skipped value extended beyond enclosing submessage.");
return upb_pbdecoder_suspend(d); return (int32_t)upb_pbdecoder_suspend(d);
} else if (bufleft(d) >= bytes) { } else if (bufleft(d) >= bytes) {
/* Skipped data is all in current buffer, and more is still available. */ /* Skipped data is all in current buffer, and more is still available. */
advance(d, bytes); advance(d, bytes);
@ -198,7 +198,7 @@ static int32_t skip(upb_pbdecoder *d, size_t bytes) {
d->bufstart_ofs += (d->end - d->buf); d->bufstart_ofs += (d->end - d->buf);
d->residual_end = d->residual; d->residual_end = d->residual;
switchtobuf(d, d->residual, d->residual_end); switchtobuf(d, d->residual, d->residual_end);
return d->size_param + d->skip; return (int32_t)(d->size_param + d->skip);
} }
} }
@ -238,7 +238,7 @@ int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
/* NULL buf is ok if its entire span is covered by the "skip" above, but /* NULL buf is ok if its entire span is covered by the "skip" above, but
* by this point we know that "skip" doesn't cover the buffer. */ * by this point we know that "skip" doesn't cover the buffer. */
seterr(d, "Passed NULL buffer over non-skippable region."); seterr(d, "Passed NULL buffer over non-skippable region.");
return upb_pbdecoder_suspend(d); return (int32_t)upb_pbdecoder_suspend(d);
} }
if (d->residual_end > d->residual) { if (d->residual_end > d->residual) {
@ -348,9 +348,9 @@ UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf,
return DECODE_OK; return DECODE_OK;
} else if (d->data_end == d->delim_end) { } else if (d->data_end == d->delim_end) {
seterr(d, "Submessage ended in the middle of a value or group"); seterr(d, "Submessage ended in the middle of a value or group");
return upb_pbdecoder_suspend(d); return (int32_t)upb_pbdecoder_suspend(d);
} else { } else {
return suspend_save(d); return (int32_t)suspend_save(d);
} }
} }
@ -406,7 +406,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d,
} }
if(bitpos == 70 && (byte & 0x80)) { if(bitpos == 70 && (byte & 0x80)) {
seterr(d, kUnterminatedVarint); seterr(d, kUnterminatedVarint);
return upb_pbdecoder_suspend(d); return (int32_t)upb_pbdecoder_suspend(d);
} }
return DECODE_OK; return DECODE_OK;
} }
@ -423,7 +423,7 @@ UPB_FORCEINLINE static int32_t decode_varint(upb_pbdecoder *d, uint64_t *u64) {
upb_decoderet r = upb_vdecode_fast(d->ptr); upb_decoderet r = upb_vdecode_fast(d->ptr);
if (r.p == NULL) { if (r.p == NULL) {
seterr(d, kUnterminatedVarint); seterr(d, kUnterminatedVarint);
return upb_pbdecoder_suspend(d); return (int32_t)upb_pbdecoder_suspend(d);
} }
advance(d, r.p - d->ptr); advance(d, r.p - d->ptr);
*u64 = r.val; *u64 = r.val;
@ -447,9 +447,9 @@ UPB_FORCEINLINE static int32_t decode_v32(upb_pbdecoder *d, uint32_t *u32) {
* Right now the size_t -> int32_t can overflow and produce negative values. * Right now the size_t -> int32_t can overflow and produce negative values.
*/ */
*u32 = 0; *u32 = 0;
return upb_pbdecoder_suspend(d); return (int32_t)upb_pbdecoder_suspend(d);
} }
*u32 = u64; *u32 = (uint32_t)u64;
return DECODE_OK; return DECODE_OK;
} }
@ -525,7 +525,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d,
UPB_ASSERT(ok < 0); UPB_ASSERT(ok < 0);
return DECODE_OK; return DECODE_OK;
} else if (read < bytes && memcmp(&data, &expected, read) == 0) { } else if (read < bytes && memcmp(&data, &expected, read) == 0) {
return suspend_save(d); return (int32_t)suspend_save(d);
} else { } else {
return DECODE_MISMATCH; return DECODE_MISMATCH;
} }
@ -545,7 +545,7 @@ int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum,
have_tag: have_tag:
if (fieldnum == 0) { if (fieldnum == 0) {
seterr(d, "Saw invalid field number (0)"); seterr(d, "Saw invalid field number (0)");
return upb_pbdecoder_suspend(d); return (int32_t)upb_pbdecoder_suspend(d);
} }
switch (wire_type) { switch (wire_type) {
@ -567,7 +567,9 @@ have_tag:
break; break;
} }
case UPB_WIRE_TYPE_START_GROUP: case UPB_WIRE_TYPE_START_GROUP:
CHECK_SUSPEND(pushtagdelim(d, -fieldnum)); if (!pushtagdelim(d, -fieldnum)) {
return (int32_t)upb_pbdecoder_suspend(d);
}
break; break;
case UPB_WIRE_TYPE_END_GROUP: case UPB_WIRE_TYPE_END_GROUP:
if (fieldnum == -d->top->groupnum) { if (fieldnum == -d->top->groupnum) {
@ -576,12 +578,12 @@ have_tag:
return DECODE_ENDGROUP; return DECODE_ENDGROUP;
} else { } else {
seterr(d, "Unmatched ENDGROUP tag."); seterr(d, "Unmatched ENDGROUP tag.");
return upb_pbdecoder_suspend(d); return (int32_t)upb_pbdecoder_suspend(d);
} }
break; break;
default: default:
seterr(d, "Invalid wire type"); seterr(d, "Invalid wire type");
return upb_pbdecoder_suspend(d); return (int32_t)upb_pbdecoder_suspend(d);
} }
if (d->top->groupnum >= 0) { if (d->top->groupnum >= 0) {
@ -753,7 +755,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group,
CHECK_SUSPEND(upb_sink_endsubmsg(d->top->sink, subsink, arg)); CHECK_SUSPEND(upb_sink_endsubmsg(d->top->sink, subsink, arg));
) )
VMCASE(OP_STARTSTR, VMCASE(OP_STARTSTR,
uint32_t len = delim_remaining(d); uint32_t len = (uint32_t)delim_remaining(d);
upb_pbdecoder_frame *outer = outer_frame(d); upb_pbdecoder_frame *outer = outer_frame(d);
CHECK_SUSPEND(upb_sink_startstr(outer->sink, arg, len, &d->top->sink)); CHECK_SUSPEND(upb_sink_startstr(outer->sink, arg, len, &d->top->sink));
if (len == 0) { if (len == 0) {
@ -761,7 +763,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group,
} }
) )
VMCASE(OP_STRING, VMCASE(OP_STRING,
uint32_t len = curbufleft(d); uint32_t len = (uint32_t)curbufleft(d);
size_t n = upb_sink_putstring(d->top->sink, arg, d->ptr, len, handle); size_t n = upb_sink_putstring(d->top->sink, arg, d->ptr, len, handle);
if (n > len) { if (n > len) {
if (n > delim_remaining(d)) { if (n > delim_remaining(d)) {

@ -248,7 +248,7 @@ static bool start_delim(upb_pb_encoder *e) {
e->runbegin = e->ptr; e->runbegin = e->ptr;
} }
*e->top = e->segptr - e->segbuf; *e->top = (int)(e->segptr - e->segbuf);
e->segptr->seglen = 0; e->segptr->seglen = 0;
e->segptr->msglen = 0; e->segptr->msglen = 0;

@ -40,7 +40,8 @@ UPB_INLINE uint64_t byteswap64(uint64_t val) {
/* Zig-zag encoding/decoding **************************************************/ /* Zig-zag encoding/decoding **************************************************/
UPB_INLINE int32_t upb_zzdec_32(uint32_t n) { UPB_INLINE int32_t upb_zzdec_32(uint64_t _n) {
uint32_t n = (uint32_t)_n;
return (n >> 1) ^ -(int32_t)(n & 1); return (n >> 1) ^ -(int32_t)(n & 1);
} }
UPB_INLINE int64_t upb_zzdec_64(uint64_t n) { UPB_INLINE int64_t upb_zzdec_64(uint64_t n) {

@ -169,10 +169,10 @@ void upb_msg_set(upb_msg *msg, const upb_fielddef *f, upb_msgval val,
bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m, bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m,
const upb_symtab *ext_pool, const upb_fielddef **out_f, const upb_symtab *ext_pool, const upb_fielddef **out_f,
upb_msgval *out_val, size_t *iter) { upb_msgval *out_val, size_t *iter) {
int i = *iter; size_t i = *iter;
const upb_msgval zero = {0}; const upb_msgval zero = {0};
const upb_fielddef *f; const upb_fielddef *f;
while ((f = _upb_msgdef_field(m, ++i)) != NULL) { while ((f = _upb_msgdef_field(m, (int)++i)) != NULL) {
upb_msgval val = _upb_msg_getraw(msg, f); upb_msgval val = _upb_msg_getraw(msg, f);
/* Skip field if unset or empty. */ /* Skip field if unset or empty. */

Loading…
Cancel
Save