Skip to content

Commit 68312ab

Browse files
committed
Merge pull request #1846 from pguyot/w39/use-clang-pedantic
Use -Wpendantic with Clang, fix AVMCCS-L002 issues 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 d522620 + f537e4f commit 68312ab

31 files changed

+124
-90
lines changed

C_CODING_STYLE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ void f(bool reverse) {
141141
- **Function spacing**: Separate function definitions with exactly one empty line [AVMCCS-F008]
142142

143143
```c
144-
void first_function()
144+
void first_function(void)
145145
{
146146
// implementation
147147
}
148148

149-
void second_function()
149+
void second_function(void)
150150
{
151151
// implementation
152152
}

src/libAtomVM/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ target_compile_features(libAtomVM PUBLIC c_std_11)
131131
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
132132
target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} ${MAYBE_WERROR_FLAG} -Wextra -ggdb -Werror=incompatible-pointer-types)
133133
elseif (CMAKE_C_COMPILER_ID MATCHES "Clang")
134-
target_compile_options(libAtomVM PUBLIC -Wall --extra-warnings -Werror=incompatible-pointer-types ${MAYBE_WERROR_FLAG})
134+
target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} -Wno-gnu-zero-variadic-macro-arguments --extra-warnings -Werror=incompatible-pointer-types ${MAYBE_WERROR_FLAG})
135135
endif()
136136

137137
if (ENABLE_REALLOC_GC)

src/libAtomVM/atom_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct AtomTable
8080

8181
static struct HNodeGroup *new_node_group(struct AtomTable *table, int len);
8282

83-
struct AtomTable *atom_table_new()
83+
struct AtomTable *atom_table_new(void)
8484
{
8585
struct AtomTable *htable = malloc(sizeof(struct AtomTable));
8686
if (IS_NULL_PTR(htable)) {

src/libAtomVM/atom_table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ enum AtomTableEnsureAtomResult
5555

5656
typedef const void *atom_ref_t;
5757

58-
struct AtomTable *atom_table_new();
58+
struct AtomTable *atom_table_new(void);
5959
void atom_table_destroy(struct AtomTable *table);
6060

6161
size_t atom_table_count(struct AtomTable *table);

src/libAtomVM/context.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ Context *context_new(GlobalContext *glb)
9191
ctx->native_handler = NULL;
9292

9393
ctx->saved_module = NULL;
94+
#ifndef AVM_NO_EMU
9495
ctx->saved_ip = NULL;
96+
#else
97+
ctx->saved_function_ptr = NULL;
98+
#endif
9599
ctx->restore_trap_handler = NULL;
96100

97101
ctx->leader = 0;
@@ -458,13 +462,18 @@ void context_process_monitor_down_signal(Context *ctx, struct TermSignal *signal
458462
void context_process_code_server_resume_signal(Context *ctx)
459463
{
460464
#ifndef AVM_NO_JIT
461-
uint32_t label = (uint32_t) (uintptr_t) ctx->saved_ip;
465+
// jit_trap_and_load stores the label in saved_function_ptr
466+
uint32_t label = (uint32_t) (uintptr_t) ctx->saved_function_ptr;
462467
Module *module = ctx->saved_module;
468+
#ifndef AVM_NO_EMU
463469
if (module->native_code) {
464-
ctx->saved_ip = (ModuleNativeEntryPoint) module_get_native_entry_point(module, label);
470+
ctx->saved_function_ptr = module_get_native_entry_point(module, label);
465471
} else {
466472
ctx->saved_ip = module->labels[label];
467473
}
474+
#else
475+
ctx->saved_function_ptr = module_get_native_entry_point(module, label);
476+
#endif
468477
// Fix CP to OP_INT_CALL_END
469478
if (ctx->cp == module_address(module->module_index, 0)) {
470479
ctx->cp = module_address(module->module_index, module->end_instruction_ii);

src/libAtomVM/context.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define _CONTEXT_H_
3030

3131
#include "globalcontext.h"
32+
#include "jit.h"
3233
#include "list.h"
3334
#include "mailbox.h"
3435
#include "smp.h"
@@ -114,7 +115,15 @@ struct Context
114115

115116
// saved state when scheduled out
116117
Module *saved_module;
117-
const void *saved_ip;
118+
union
119+
{
120+
#ifndef AVM_NO_EMU
121+
const void *saved_ip;
122+
#endif
123+
#ifndef AVM_NO_JIT
124+
ModuleNativeEntryPoint saved_function_ptr;
125+
#endif
126+
};
118127
// pointer to a trap or wait timeout handler
119128
void *restore_trap_handler;
120129

src/libAtomVM/ets_hashtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct HNode
4040

4141
static uint32_t hash_term(term t, GlobalContext *global);
4242

43-
struct EtsHashTable *ets_hashtable_new()
43+
struct EtsHashTable *ets_hashtable_new(void)
4444
{
4545
struct EtsHashTable *htable = malloc(sizeof(struct EtsHashTable));
4646
if (IS_NULL_PTR(htable)) {

src/libAtomVM/ets_hashtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef enum EtsHashtableStatus
4949
EtsHashtableOutOfMemory
5050
} EtsHashtableStatus;
5151

52-
struct EtsHashTable *ets_hashtable_new();
52+
struct EtsHashTable *ets_hashtable_new(void);
5353
void ets_hashtable_destroy(struct EtsHashTable *hash_table, GlobalContext *global);
5454

5555
EtsHashtableStatus ets_hashtable_insert(struct EtsHashTable *hash_table, struct HNode *new_node, EtsHashtableOptions opts, GlobalContext *global);

src/libAtomVM/globalcontext.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct RegisteredProcess
5959
term local_pid_or_port;
6060
};
6161

62-
GlobalContext *globalcontext_new()
62+
GlobalContext *globalcontext_new(void)
6363
{
6464
GlobalContext *glb = malloc(sizeof(GlobalContext));
6565
if (IS_NULL_PTR(glb)) {
@@ -238,7 +238,7 @@ COLD_FUNC void globalcontext_destroy(GlobalContext *glb)
238238
struct RefcBinary *refc = GET_LIST_ENTRY(item, struct RefcBinary, head);
239239
#ifndef NDEBUG
240240
if (refc->resource_type) {
241-
fprintf(stderr, "Warning, dangling resource of type %s, ref_count = %d, data = %p\n", refc->resource_type->name, (int) refc->ref_count, refc->data);
241+
fprintf(stderr, "Warning, dangling resource of type %s, ref_count = %d, data = %p\n", refc->resource_type->name, (int) refc->ref_count, (void *) refc->data);
242242
} else {
243243
fprintf(stderr, "Warning, dangling refc binary, ref_count = %d\n", (int) refc->ref_count);
244244
}

src/libAtomVM/globalcontext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ enum SendMessageResult
192192
* @details Allocates a new GlobalContext struct and initialize it, the newly created global context is a new AtomVM instance.
193193
* @returns A newly created GlobalContext.
194194
*/
195-
GlobalContext *globalcontext_new();
195+
GlobalContext *globalcontext_new(void);
196196

197197
/**
198198
* @brief Destoys an existing GlobalContext

0 commit comments

Comments
 (0)