Skip to content

Commit 9090844

Browse files
committed
Merge pull request atomvm#526 from pguyot/w17/fix-some-compiler-warnings
Enable clang warnings and fix some GCC/clang warnings Also make incompatible pointer type warnings an error for both compilers These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 14dea42 + 5ff0f45 commit 9090844

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

src/libAtomVM/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ set(SOURCE_FILES
9191
add_library(libAtomVM ${SOURCE_FILES} ${HEADER_FILES})
9292
target_include_directories(libAtomVM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
9393
target_compile_features(libAtomVM PUBLIC c_std_11)
94-
if(CMAKE_COMPILER_IS_GNUCC)
95-
target_compile_options(libAtomVM PUBLIC -Wall -pedantic -Wextra -ggdb)
94+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
95+
target_compile_options(libAtomVM PUBLIC -Wall -pedantic -Wextra -ggdb -Werror=incompatible-pointer-types)
96+
elseif (CMAKE_C_COMPILER_ID MATCHES "Clang")
97+
target_compile_options(libAtomVM PUBLIC -Wall --extra-warnings -Werror=incompatible-pointer-types)
9698
endif()
9799

98100
# AtomVM options used in libAtomVM

src/libAtomVM/bitstring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ bool bitstring_insert_any_integer(uint8_t *dst, avm_int_t offset, avm_int64_t va
6868
offset += n - (8 * sizeof(value));
6969
n = 8 * sizeof(value);
7070
}
71-
for (int i = 0; i < n; ++i) {
72-
int k = (n - 1) - i;
71+
for (size_t i = 0; i < n; ++i) {
72+
size_t k = (n - 1) - i;
7373
int bit_val = (value & (0x01LL << k)) >> k;
7474
if (bit_val) {
7575
int bit_pos = offset + i;

src/libAtomVM/nifs.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
* SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
1919
*/
2020

21+
#ifndef _GNU_SOURCE
2122
#define _GNU_SOURCE
23+
#endif
2224

2325
#include "nifs.h"
2426

@@ -51,13 +53,6 @@
5153
#define MAX_NIF_NAME_LEN 260
5254
#define FLOAT_BUF_SIZE 64
5355

54-
#define VALIDATE_VALUE(value, verify_function) \
55-
if (UNLIKELY(!verify_function((value)))) { \
56-
argv[0] = ERROR_ATOM; \
57-
argv[1] = BADARG_ATOM; \
58-
return term_invalid_term(); \
59-
}
60-
6156
#define RAISE_ERROR(error_type_atom) \
6257
ctx->x[0] = ERROR_ATOM; \
6358
ctx->x[1] = (error_type_atom); \

src/libAtomVM/opcodesswitch.h

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ typedef union
8787
} dreg_type_t;
8888

8989
#ifdef IMPL_EXECUTE_LOOP
90+
// Override nifs.h RAISE_ERROR macro
91+
#ifdef RAISE_ERROR
92+
#undef RAISE_ERROR
93+
#endif
9094
#define RAISE_ERROR(error_type_atom) \
9195
ctx->x[0] = ERROR_ATOM; \
9296
ctx->x[1] = error_type_atom; \
@@ -1301,11 +1305,14 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
13011305

13021306
#endif
13031307

1308+
#ifndef __clang__
13041309
#pragma GCC diagnostic push
13051310
#ifdef __GNUC__
1306-
#ifndef __clang__
13071311
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
13081312
#endif
1313+
#else
1314+
#pragma clang diagnostic push
1315+
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
13091316
#endif
13101317

13111318
#ifdef IMPL_CODE_LOADER
@@ -3661,9 +3668,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
36613668
int next_off = 1;
36623669
uint32_t fail;
36633670
DECODE_LABEL(fail, code, i, next_off)
3664-
#ifdef IMPL_EXECUTE_LOOP
3665-
int next_off_back = next_off;
3666-
#endif
36673671
term src;
36683672
DECODE_COMPACT_TERM(src, code, i, next_off);
36693673
term arg2;
@@ -3707,9 +3711,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
37073711
int next_off = 1;
37083712
uint32_t fail;
37093713
DECODE_LABEL(fail, code, i, next_off)
3710-
#ifdef IMPL_EXECUTE_LOOP
3711-
int next_off_back = next_off;
3712-
#endif
37133714
term src;
37143715
DECODE_COMPACT_TERM(src, code, i, next_off);
37153716
term arg2;
@@ -3815,9 +3816,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
38153816
int next_off = 1;
38163817
uint32_t fail;
38173818
DECODE_LABEL(fail, code, i, next_off)
3818-
#ifdef IMPL_EXECUTE_LOOP
3819-
int next_off_back = next_off;
3820-
#endif
38213819
term src;
38223820
DECODE_COMPACT_TERM(src, code, i, next_off);
38233821
term arg2;
@@ -3861,9 +3859,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
38613859
int next_off = 1;
38623860
uint32_t fail;
38633861
DECODE_LABEL(fail, code, i, next_off)
3864-
#ifdef IMPL_EXECUTE_LOOP
3865-
int next_off_back = next_off;
3866-
#endif
38673862
term src;
38683863
DECODE_COMPACT_TERM(src, code, i, next_off);
38693864
term arg2;
@@ -3941,9 +3936,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
39413936
int next_off = 1;
39423937
uint32_t fail;
39433938
DECODE_LABEL(fail, code, i, next_off)
3944-
#ifdef IMPL_EXECUTE_LOOP
3945-
int next_off_back = next_off;
3946-
#endif
39473939
term src;
39483940
DECODE_COMPACT_TERM(src, code, i, next_off);
39493941
term arg2;
@@ -3986,9 +3978,6 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
39863978
int next_off = 1;
39873979
uint32_t fail;
39883980
DECODE_LABEL(fail, code, i, next_off)
3989-
#ifdef IMPL_EXECUTE_LOOP
3990-
int next_off_back = next_off;
3991-
#endif
39923981
term src;
39933982
DECODE_COMPACT_TERM(src, code, i, next_off);
39943983
term arg2;
@@ -4577,7 +4566,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
45774566
AVM_ABORT();
45784567
}
45794568

4580-
TRACE("bs_save2/2, src=0x%lx pos=%li\n", src, index_val);
4569+
TRACE("bs_save2/2, src=0x%lx pos=%li\n", src, index == START_ATOM ? -1 : index_val);
45814570
#endif
45824571

45834572
NEXT_INSTRUCTION(next_off);
@@ -4608,7 +4597,7 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
46084597
AVM_ABORT();
46094598
}
46104599

4611-
TRACE("bs_restore2/2, src=0x%lx pos=%li\n", src, index_val);
4600+
TRACE("bs_restore2/2, src=0x%lx pos=%li\n", src, index == START_ATOM ? -1 : index_val);
46124601
#endif
46134602

46144603
NEXT_INSTRUCTION(next_off);
@@ -5583,7 +5572,11 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
55835572
term src;
55845573
DECODE_COMPACT_TERM(src, code, i, next_off);
55855574

5586-
TRACE("has_map_fields/3: label: %i src: 0x%lx\n", label, src);
5575+
#ifdef IMPL_EXECUTE_LOOP
5576+
TRACE("has_map_fields/3: label: %i src: 0x%lx\n", label, src);
5577+
#else
5578+
TRACE("has_map_fields/3: label: %i\n", label);
5579+
#endif
55875580

55885581
DECODE_EXTENDED_LIST_TAG(code, i, next_off);
55895582
uint32_t list_len;
@@ -5615,7 +5608,11 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
56155608
DECODE_LABEL(label, code, i, next_off)
56165609
term src;
56175610
DECODE_COMPACT_TERM(src, code, i, next_off);
5618-
TRACE("get_map_elements/3: label: %i src: 0x%lx\n", label, src);
5611+
#ifdef IMPL_EXECUTE_LOOP
5612+
TRACE("get_map_elements/3: label: %i src: 0x%lx\n", label, src);
5613+
#else
5614+
TRACE("get_map_elements/3: label: %i\n", label);
5615+
#endif
56195616

56205617
DECODE_EXTENDED_LIST_TAG(code, i, next_off);
56215618
uint32_t list_len;
@@ -6927,6 +6924,10 @@ static bool maybe_call_native(Context *ctx, AtomString module_name, AtomString f
69276924
}
69286925
}
69296926

6927+
#ifndef __clang__
69306928
#pragma GCC diagnostic pop
6929+
#else
6930+
#pragma clang diagnostic pop
6931+
#endif
69316932

69326933
#undef DECODE_COMPACT_TERM

src/libAtomVM/term.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ static inline term term_maybe_create_sub_binary(term binary, size_t offset, size
10311031
}
10321032
}
10331033

1034-
static inline void term_set_refc_binary_data(term t, const char *data)
1034+
static inline void term_set_refc_binary_data(term t, const void *data)
10351035
{
10361036
TERM_DEBUG_ASSERT(term_is_refc_binary(t));
10371037
term *boxed_value = term_to_term_ptr(t);

0 commit comments

Comments
 (0)