Skip to content

Enable extra warnings for mpy-cross and unix port #6510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extmod/extmod.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ SRC_MOD += $(addprefix $(LITTLEFS_DIR)/,\
lfs2.c \
lfs2_util.c \
)

$(BUILD)/$(LITTLEFS_DIR)/lfs2.o: CFLAGS += -Wno-missing-field-initializers
endif

################################################################################
Expand Down
4 changes: 2 additions & 2 deletions extmod/machine_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ STATIC void mp_machine_soft_i2c_print(const mp_print_t *print, mp_obj_t self_in,
STATIC void machine_i2c_obj_init_helper(machine_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_scl, ARG_sda, ARG_freq, ARG_timeout };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_sda, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_sda, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are required args they don't need a default value. But I can see why the compiler complains, and it won't hurt to have defaults here (shouldn't add anything to code size). So this is OK!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I think this pretty much reflects what is in the commit message. 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed! I didn't read the commit message...

{ MP_QSTR_freq, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 400000} },
{ MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} },
};
Expand Down
3 changes: 2 additions & 1 deletion extmod/moductypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
return mp_obj_new_bytearray_by_ref(uctypes_struct_agg_size(sub, self->flags, &dummy), self->addr + offset);
}
// Fall thru to return uctypes struct object
MP_FALLTHROUGH
}
case PTR: {
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
Expand Down Expand Up @@ -627,7 +628,7 @@ STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
return mp_obj_new_int((mp_int_t)(uintptr_t)p);
}
}
/* fallthru */
MP_FALLTHROUGH

default:
return MP_OBJ_NULL; // op not supported
Expand Down
1 change: 1 addition & 0 deletions extmod/re1.5/compilecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
prog->len++;
break;
}
MP_FALLTHROUGH
default:
term = PC;
EMIT(PC++, Char);
Expand Down
1 change: 1 addition & 0 deletions extmod/re1.5/recursiveloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ recursiveloop(char *pc, const char *sp, Subject *input, const char **subp, int n
case Char:
if(*sp != *pc++)
return 0;
MP_FALLTHROUGH
case Any:
sp++;
continue;
Expand Down
2 changes: 1 addition & 1 deletion extmod/vfs_lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
enum { LFS_MAKE_ARG_bdev, LFS_MAKE_ARG_readsize, LFS_MAKE_ARG_progsize, LFS_MAKE_ARG_lookahead, LFS_MAKE_ARG_mtime };

static const mp_arg_t lfs_make_allowed_args[] = {
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} },
{ MP_QSTR_readsize, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 32} },
{ MP_QSTR_progsize, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 32} },
{ MP_QSTR_lookahead, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 32} },
Expand Down
2 changes: 1 addition & 1 deletion mpy-cross/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ INC += -I$(TOP)

# compiler settings
CWARN = -Wall -Werror
CWARN += -Wpointer-arith -Wuninitialized
CWARN += -Wextra -Wno-unused-parameter -Wpointer-arith
CFLAGS = $(INC) $(CWARN) -std=gnu99 $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA)
CFLAGS += -fdata-sections -ffunction-sections -fno-asynchronous-unwind-tables

Expand Down
2 changes: 1 addition & 1 deletion ports/unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ INC += -I$(BUILD)

# compiler settings
CWARN = -Wall -Werror
CWARN += -Wpointer-arith -Wuninitialized -Wdouble-promotion -Wsign-compare -Wfloat-conversion
CWARN += -Wextra -Wno-unused-parameter -Wpointer-arith -Wdouble-promotion -Wfloat-conversion
CFLAGS += $(INC) $(CWARN) -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EXTRA)

# Debugging/Optimization
Expand Down
2 changes: 1 addition & 1 deletion py/emitinlinethumb.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ STATIC mp_uint_t emit_inline_thumb_count_params(emit_inline_asm_t *emit, mp_uint
return 0;
}
const char *p = qstr_str(MP_PARSE_NODE_LEAF_ARG(pn_params[i]));
if (!(strlen(p) == 2 && p[0] == 'r' && p[1] == '0' + i)) {
if (!(strlen(p) == 2 && p[0] == 'r' && (mp_uint_t)p[1] == '0' + i)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question: C99 guarantees that '0' + i will be of type mp_uint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as far as I understand when you have signed + unsigned then the signed value is promoted to unsigned, and then they're widened to the widest integer, which in this case is mp_uint_t (which should be wider than char).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, it's more complicated than that. First both sides are promoted to int if they're narrower or unsigned int if int can't represent all the values. Then if the widest operand is a signed type T and T is able to hold all values of the other type, the other type is promoted to T. Otherwise both sides are promoted to the unsigned type as wide as the widest of the two operands.

So here '0' is automatically converted to 'int', and then (assuming mp_uint_t is `unsigned int') both sides are promoted to 'unsigned int'. So the explanation is more complicated, but the result is the same ;)

emit_inline_thumb_error_msg(emit, MP_ERROR_TEXT("parameters must be registers in sequence r0 to r3"));
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion py/emitinlinextensa.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ STATIC mp_uint_t emit_inline_xtensa_count_params(emit_inline_asm_t *emit, mp_uin
return 0;
}
const char *p = qstr_str(MP_PARSE_NODE_LEAF_ARG(pn_params[i]));
if (!(strlen(p) == 2 && p[0] == 'a' && p[1] == '2' + i)) {
if (!(strlen(p) == 2 && p[0] == 'a' && (mp_uint_t)p[1] == '2' + i)) {
emit_inline_xtensa_error_msg(emit, MP_ERROR_TEXT("parameters must be registers in sequence a2 to a5"));
return 0;
}
Expand Down
3 changes: 2 additions & 1 deletion py/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ STATIC void gc_sweep(void) {
#if MICROPY_PY_GC_COLLECT_RETVAL
MP_STATE_MEM(gc_collected)++;
#endif
// fall through to free the head
// fall through to free the head
MP_FALLTHROUGH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice bonus: uncrustify now indents the comment to the correct level because it sees MP_FALLTHROUGH as a statement within this case.


case AT_TAIL:
if (free_tail) {
Expand Down
3 changes: 2 additions & 1 deletion py/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
vstr_add_char(&lex->vstr, '\\');
break;
}
// Otherwise fall through.
// Otherwise fall through.
MP_FALLTHROUGH
case 'x': {
mp_uint_t num = 0;
if (!get_hex(lex, (c == 'x' ? 2 : c == 'u' ? 4 : 8), &num)) {
Expand Down
4 changes: 2 additions & 2 deletions py/modmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ MATH_FUN_1(lgamma, lgamma)
STATIC mp_obj_t mp_math_isclose(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_a, ARG_b, ARG_rel_tol, ARG_abs_tol };
static const mp_arg_t allowed_args[] = {
{MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ},
{MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ},
{MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL}},
{MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL}},
{MP_QSTR_rel_tol, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL}},
{MP_QSTR_abs_tol, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(0)}},
};
Expand Down
7 changes: 7 additions & 0 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,13 @@ typedef double mp_float_t;
#endif
#endif

// Explicitly annotate switch case fall throughs
#if defined(__GNUC__) && __GNUC__ >= 7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about enabling -Wimplicit-fallthrough for clang as well? See http://clang.llvm.org/docs/AttributeReference.html#fallthrough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried that in the first three attempts, but it turns out clang only does -Wimplicit-fallthrough for C++

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha ok, wasn't clear to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, me neither

#define MP_FALLTHROUGH __attribute__((fallthrough));
#else
#define MP_FALLTHROUGH
#endif

#ifndef MP_HTOBE16
#if MP_ENDIANNESS_LITTLE
#define MP_HTOBE16(x) ((uint16_t)((((x) & 0xff) << 8) | (((x) >> 8) & 0xff)))
Expand Down
8 changes: 4 additions & 4 deletions py/objexcept.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, siz
// reserved room (after the traceback data) for a tuple with 1 element.
// Otherwise we are free to use the whole buffer after the traceback data.
if (o_tuple == NULL && mp_emergency_exception_buf_size >=
EMG_BUF_TUPLE_OFFSET + EMG_BUF_TUPLE_SIZE(n_args)) {
(mp_int_t)(EMG_BUF_TUPLE_OFFSET + EMG_BUF_TUPLE_SIZE(n_args))) {
o_tuple = (mp_obj_tuple_t *)
((uint8_t *)MP_STATE_VM(mp_emergency_exception_buf) + EMG_BUF_TUPLE_OFFSET);
}
Expand Down Expand Up @@ -383,7 +383,7 @@ mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, mp_rom_error_te
// that buffer to store the string object, reserving room at the start for the
// traceback and 1-tuple.
if (o_str == NULL
&& mp_emergency_exception_buf_size >= EMG_BUF_STR_OFFSET + sizeof(mp_obj_str_t)) {
&& mp_emergency_exception_buf_size >= (mp_int_t)(EMG_BUF_STR_OFFSET + sizeof(mp_obj_str_t))) {
o_str = (mp_obj_str_t *)((uint8_t *)MP_STATE_VM(mp_emergency_exception_buf)
+ EMG_BUF_STR_OFFSET);
}
Expand Down Expand Up @@ -465,7 +465,7 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_er
// that buffer to store the string object and its data (at least 16 bytes for
// the string data), reserving room at the start for the traceback and 1-tuple.
if ((o_str == NULL || o_str_buf == NULL)
&& mp_emergency_exception_buf_size >= EMG_BUF_STR_OFFSET + sizeof(mp_obj_str_t) + 16) {
&& mp_emergency_exception_buf_size >= (mp_int_t)(EMG_BUF_STR_OFFSET + sizeof(mp_obj_str_t) + 16)) {
used_emg_buf = true;
o_str = (mp_obj_str_t *)((uint8_t *)MP_STATE_VM(mp_emergency_exception_buf) + EMG_BUF_STR_OFFSET);
o_str_buf = (byte *)((uint8_t *)MP_STATE_VM(mp_emergency_exception_buf) + EMG_BUF_STR_BUF_OFFSET);
Expand Down Expand Up @@ -573,7 +573,7 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qs
self->traceback_data = m_new_maybe(size_t, TRACEBACK_ENTRY_LEN);
if (self->traceback_data == NULL) {
#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
if (mp_emergency_exception_buf_size >= EMG_BUF_TRACEBACK_OFFSET + EMG_BUF_TRACEBACK_SIZE) {
if (mp_emergency_exception_buf_size >= (mp_int_t)(EMG_BUF_TRACEBACK_OFFSET + EMG_BUF_TRACEBACK_SIZE)) {
// There is room in the emergency buffer for traceback data
size_t *tb = (size_t *)((uint8_t *)MP_STATE_VM(mp_emergency_exception_buf)
+ EMG_BUF_TRACEBACK_OFFSET);
Expand Down
1 change: 1 addition & 0 deletions py/objset.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
}
return MP_OBJ_NEW_SMALL_INT(hash);
}
MP_FALLTHROUGH
#endif
default:
return MP_OBJ_NULL; // op not supported
Expand Down
2 changes: 1 addition & 1 deletion py/scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void scope_free(scope_t *scope) {
m_del(scope_t, scope, 1);
}

id_info_t *scope_find_or_add_id(scope_t *scope, qstr qst, scope_kind_t kind) {
id_info_t *scope_find_or_add_id(scope_t *scope, qstr qst, id_info_kind_t kind) {
id_info_t *id_info = scope_find(scope, qst);
if (id_info != NULL) {
return id_info;
Expand Down
6 changes: 3 additions & 3 deletions py/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
#include "py/parse.h"
#include "py/emitglue.h"

enum {
typedef enum {
ID_INFO_KIND_UNDECIDED,
ID_INFO_KIND_GLOBAL_IMPLICIT,
ID_INFO_KIND_GLOBAL_EXPLICIT,
ID_INFO_KIND_LOCAL, // in a function f, written and only referenced by f
ID_INFO_KIND_CELL, // in a function f, read/written by children of f
ID_INFO_KIND_FREE, // in a function f, belongs to the parent of f
};
} id_info_kind_t;

enum {
ID_FLAG_IS_PARAM = 0x01,
Expand Down Expand Up @@ -92,7 +92,7 @@ typedef struct _scope_t {

scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, mp_uint_t emit_options);
void scope_free(scope_t *scope);
id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, scope_kind_t kind);
id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, id_info_kind_t kind);
id_info_t *scope_find(scope_t *scope, qstr qstr);
id_info_t *scope_find_global(scope_t *scope, qstr qstr);
void scope_check_to_close_over(scope_t *scope, id_info_t *id);
Expand Down
7 changes: 7 additions & 0 deletions py/vmentrytable.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winitializer-overrides"
#endif // __clang__
#if __GNUC__ >= 5
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverride-init"
#endif // __GNUC__ >= 5

static const void *const entry_table[256] = {
[0 ... 255] = &&entry_default,
Expand Down Expand Up @@ -119,3 +123,6 @@ static const void *const entry_table[256] = {
#if __clang__
#pragma clang diagnostic pop
#endif // __clang__
#if __GNUC__ >= 5
#pragma GCC diagnostic pop
#endif // __GNUC__ >= 5
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy