Skip to content
Open
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: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# using [clang-formt-12 options](https://releases.llvm.org/12.0.0/tools/clang/docs/ClangFormatStyleOptions.html)
# using [clang-format-21 options](https://releases.llvm.org/21.1.0/tools/clang/docs/ClangFormatStyleOptions.html)
RawStringFormats:
- Language: Cpp
Delimiters:
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/coding_guidelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,29 @@ permissions:

jobs:
compliance_job:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: checkout
uses: actions/checkout@v7.0.0
with:
fetch-depth: 0

- name: install clang-format-21
run: |
# clang-format 21 matches the LLVM shipped in Xcode 26/27, so
# contributors who build or auto-format on macOS/Xcode get the same
# result as CI and other LLVM-built platforms - no formatting
# surprises. It is a small (~50 MB) apt package from apt.llvm.org,
# not a full LLVM toolchain download.
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key \
| sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc >/dev/null
. /etc/os-release
echo "deb http://apt.llvm.org/${VERSION_CODENAME}/ llvm-toolchain-${VERSION_CODENAME}-21 main" \
| sudo tee /etc/apt/sources.list.d/llvm.list >/dev/null
sudo apt-get update -qq
sudo apt-get install -y -qq clang-format-21
clang-format-21 --version

# github.event.pull_request.base.label = ${{github.repository}}/${{github.base_ref}}
- name: Run Coding Guidelines Checks
run: /usr/bin/env python3 ./ci/coding_guidelines_check.py --commits ${{ github.event.pull_request.base.sha }}..HEAD
18 changes: 9 additions & 9 deletions ci/coding_guidelines_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import sys
import unittest

CLANG_FORMAT_CMD = "clang-format-14"
GIT_CLANG_FORMAT_CMD = "git-clang-format-14"
CLANG_FORMAT_CMD = "clang-format-21"
GIT_CLANG_FORMAT_CMD = "git-clang-format-21"

# glob style patterns
EXCLUDE_PATHS = [
Expand Down Expand Up @@ -92,29 +92,29 @@ def run_clang_format(file_path: Path, root: Path) -> bool:

def run_clang_format_diff(root: Path, commits: str) -> bool:
"""
Use `clang-format-14` or `git-clang-format-14` to check code format of
Use `clang-format-21` or `git-clang-format-21` to check code format of
the PR, with a commit range specified. It is required to format the
code before committing the PR, or it might fail to pass the CI check:

1. Install clang-format-14.0.0
1. Install clang-format-21

You can download the package from
https://github.com/llvm/llvm-project/releases
and install it.

For Debian/Ubuntu, we can probably use
`sudo apt-get install clang-format-14`.
`sudo apt-get install clang-format-21`.

Homebrew has it as a part of llvm@14.
Homebrew has it as a part of llvm@21.
```shell
brew install llvm@14
/usr/local/opt/llvm@14/bin/clang-format
brew install llvm@21
/usr/local/opt/llvm@21/bin/clang-format
```

2. Format the C/C++ source file
``` shell
cd path/to/wamr/root
clang-format-14 --style file -i path/to/file
clang-format-21 --style file -i path/to/file
```

The code wrapped by `/* clang-format off */` and `/* clang-format on */`
Expand Down
6 changes: 3 additions & 3 deletions ci/pre_commit_hook_sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# This is a sample of pre-commit hook that can be used to make your code fit the WAMR CI code style requirements.
# You need to have clang-format-12 installed to use this hook.
# You need to have clang-format-21 installed to use this hook.
# To add this pre-commit hook, copy it to <path_to_wamr>/.git/hooks/pre-commit
# (you don't need any extensions here)

Expand All @@ -22,10 +22,10 @@ is_c_or_cpp_file() {
# Loop through staged files and apply command "abc" to C and C++ files
for staged_file in $(git diff --cached --name-only); do
if is_c_or_cpp_file "$staged_file"; then
clang-format-12 -Werror --style file --dry-run "$staged_file" 2>/dev/null
clang-format-21 -Werror --style file --dry-run "$staged_file" 2>/dev/null
if [ $? -ne 0 ]; then
echo "Issues are found in $staged_file. Applying the fix"
clang-format-12 --style file -i "$staged_file"
clang-format-21 --style file -i "$staged_file"
fi
git add "$staged_file" # Add the modified file back to staging
fi
Expand Down
3 changes: 2 additions & 1 deletion core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -5553,7 +5553,8 @@ aot_const_str_set_insert(const uint8 *str, int32 len, AOTModule *module,
#if WASM_ENABLE_DYNAMIC_AOT_DEBUG != 0
AOTModule *g_dynamic_aot_module = NULL;

void __attribute__((noinline)) __enable_dynamic_aot_debug(void)
void __attribute__((noinline))
__enable_dynamic_aot_debug(void)
{
/* empty implementation. */
}
Expand Down
5 changes: 1 addition & 4 deletions core/iwasm/aot/arch/aot_reloc_riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,7 @@ typedef struct RelocTypeStrMap {
char *reloc_str;
} RelocTypeStrMap;

#define RELOC_TYPE_MAP(reloc_type) \
{ \
reloc_type, #reloc_type \
}
#define RELOC_TYPE_MAP(reloc_type) { reloc_type, #reloc_type }

static RelocTypeStrMap reloc_type_str_maps[] = {
RELOC_TYPE_MAP(R_RISCV_32), RELOC_TYPE_MAP(R_RISCV_64),
Expand Down
21 changes: 14 additions & 7 deletions core/iwasm/aot/arch/aot_reloc_x86_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,42 @@ void __umoddi3();
#pragma function(floor)
#pragma function(ceil)

static int64 __stdcall __divdi3(int64 a, int64 b)
static int64 __stdcall
__divdi3(int64 a, int64 b)
{
return a / b;
}

static uint64 __stdcall __udivdi3(uint64 a, uint64 b)
static uint64 __stdcall
__udivdi3(uint64 a, uint64 b)
{
return a / b;
}

static int64 __stdcall __moddi3(int64 a, int64 b)
static int64 __stdcall
__moddi3(int64 a, int64 b)
{
return a % b;
}

static uint64 __stdcall __umoddi3(uint64 a, uint64 b)
static uint64 __stdcall
__umoddi3(uint64 a, uint64 b)
{
return a % b;
}

static uint64 __stdcall __aulldiv(uint64 a, uint64 b)
static uint64 __stdcall
__aulldiv(uint64 a, uint64 b)
{
return a / b;
}
static int64 __stdcall __alldiv(int64 a, int64 b)
static int64 __stdcall
__alldiv(int64 a, int64 b)
{
return a / b;
}
static int64 __stdcall __allrem(int64 a, int64 b)
static int64 __stdcall
__allrem(int64 a, int64 b)
{
return a % b;
}
Expand Down
8 changes: 4 additions & 4 deletions core/iwasm/aot/arch/aot_reloc_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
{
intptr_t target_addr = (intptr_t) /* S + A - P */
intptr_t target_addr = (intptr_t)/* S + A - P */
((uintptr_t)symbol_addr + reloc_addend
- (uintptr_t)(target_section_addr + reloc_offset));

Expand All @@ -176,7 +176,7 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
}
case R_X86_64_PC64:
{
intptr_t target_addr = (intptr_t) /* S + A - P */
intptr_t target_addr = (intptr_t)/* S + A - P */
((uintptr_t)symbol_addr + reloc_addend
- (uintptr_t)(target_section_addr + reloc_offset));

Expand Down Expand Up @@ -226,12 +226,12 @@ apply_relocation(AOTModule *module, uint8 *target_section_addr,
plt = (uint8 *)module->code + module->code_size
- get_plt_table_size()
+ get_plt_item_size() * symbol_index;
target_addr = (intptr_t) /* L + A - P */
target_addr = (intptr_t)/* L + A - P */
((uintptr_t)plt + reloc_addend
- (uintptr_t)(target_section_addr + reloc_offset));
}
else {
target_addr = (intptr_t) /* S + A - P */
target_addr = (intptr_t)/* S + A - P */
((uintptr_t)symbol_addr + reloc_addend
- (uintptr_t)(target_section_addr + reloc_offset));
}
Expand Down
5 changes: 1 addition & 4 deletions core/iwasm/aot/debug/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@
/* EI_NIDENT is defined in "Included Files" section */

#define EI_MAGIC_SIZE 4
#define EI_MAGIC \
{ \
0x7f, 'E', 'L', 'F' \
}
#define EI_MAGIC { 0x7f, 'E', 'L', 'F' }

#define ELFMAG0 0x7f /* EI_MAG */
#define ELFMAG1 'E'
Expand Down
8 changes: 4 additions & 4 deletions core/iwasm/aot/debug/elf32.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
****************************************************************************/

#define ELF32_ST_BIND(i) ((i) >> 4)
#define ELF32_ST_TYPE(i) ((i)&0xf)
#define ELF32_ST_INFO(b, t) (((b) << 4) | ((t)&0xf))
#define ELF32_ST_TYPE(i) ((i) & 0xf)
#define ELF32_ST_INFO(b, t) (((b) << 4) | ((t) & 0xf))

/* Definitions for Elf32_Rel*::r_info */

#define ELF32_R_SYM(i) ((i) >> 8)
#define ELF32_R_TYPE(i) ((i)&0xff)
#define ELF32_R_INFO(s, t) (((s) << 8) | ((t)&0xff))
#define ELF32_R_TYPE(i) ((i) & 0xff)
#define ELF32_R_INFO(s, t) (((s) << 8) | ((t) & 0xff))

#if 0
#define ELF_R_SYM(i) ELF32_R_SYM(i)
Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/aot/debug/elf64.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
/* Definitions for Elf64_Rel*::r_info */

#define ELF64_R_SYM(i) ((i) >> 32)
#define ELF64_R_TYPE(i) ((i)&0xffffffffL)
#define ELF64_R_INFO(s, t) (((s) << 32) + ((t)&0xffffffffL))
#define ELF64_R_TYPE(i) ((i) & 0xffffffffL)
#define ELF64_R_INFO(s, t) (((s) << 32) + ((t) & 0xffffffffL))

#if 0
#define ELF_R_SYM(i) ELF64_R_SYM(i)
Expand Down
6 changes: 4 additions & 2 deletions core/iwasm/common/gc/stringref/stringref_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
/******************* gc finalizer *****************/
void
wasm_string_destroy(WASMString str_obj)
{}
{
}

/******************* opcode functions *****************/

Expand Down Expand Up @@ -133,4 +134,5 @@ wasm_string_rewind(WASMString str_obj, uint32 pos, uint32 count,

void
wasm_string_dump(WASMString str_obj)
{}
{
}
3 changes: 2 additions & 1 deletion core/iwasm/common/wasm_blocking_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ wasm_runtime_begin_blocking_op(wasm_exec_env_t env)

void
wasm_runtime_end_blocking_op(wasm_exec_env_t env)
{}
{
}

#endif /* WASM_ENABLE_THREAD_MGR && OS_ENABLE_WAKEUP_BLOCKING_OP */
11 changes: 6 additions & 5 deletions core/iwasm/common/wasm_c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3248,11 +3248,12 @@ wasm_func_copy(const wasm_func_t *func)
return NULL;
}

if (!(cloned = func->with_env ? wasm_func_new_with_env_basic(
func->store, func->type, func->u.cb_env.cb,
func->u.cb_env.env, func->u.cb_env.finalizer)
: wasm_func_new_basic(func->store, func->type,
func->u.cb))) {
if (!(cloned =
func->with_env
? wasm_func_new_with_env_basic(
func->store, func->type, func->u.cb_env.cb,
func->u.cb_env.env, func->u.cb_env.finalizer)
: wasm_func_new_basic(func->store, func->type, func->u.cb))) {
goto failed;
}

Expand Down
6 changes: 3 additions & 3 deletions core/iwasm/compilation/aot_emit_aot_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

#define CHECK_SIZE(size) \
do { \
if (size == (uint32)-1) { \
if (size == (uint32) - 1) { \
aot_set_last_error("get symbol size failed."); \
return (uint32)-1; \
return (uint32) - 1; \
} \
} while (0)

Expand Down Expand Up @@ -3674,7 +3674,7 @@ aot_resolve_stack_sizes(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
unsigned int stack_consumption_to_call_wrapped_func =
musttail ? 0
: aot_estimate_stack_usage_for_function_call(
comp_ctx, func_ctx->aot_func->func_type);
comp_ctx, func_ctx->aot_func->func_type);

/*
* LLVM seems to eliminate calls to an empty function
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/compilation/aot_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,7 @@ jit_stack_size_callback(void *user_data, const char *name, size_t namelen,
stack_consumption_to_call_wrapped_func =
musttail ? 0
: aot_estimate_stack_usage_for_function_call(
comp_ctx, func_ctx->aot_func->func_type);
comp_ctx, func_ctx->aot_func->func_type);
LOG_VERBOSE("func %.*s stack %u + %zu + %u", (int)namelen, name,
stack_consumption_to_call_wrapped_func, stack_size, call_size);

Expand Down
6 changes: 4 additions & 2 deletions core/iwasm/compilation/aot_orc_extra2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ MyCompiler::MyCompiler(llvm::orc::JITTargetMachineBuilder JTMB, cb_t cb,
, JTMB(std::move(JTMB))
, cb(cb)
, cb_data(cb_data)
{}
{
}

class PrintStackSizes : public llvm::MachineFunctionPass
{
Expand All @@ -59,7 +60,8 @@ PrintStackSizes::PrintStackSizes(cb_t cb, void *cb_data)
: MachineFunctionPass(ID)
, cb(cb)
, cb_data(cb_data)
{}
{
}

char PrintStackSizes::ID = 0;

Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/compilation/debug/dwarf_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern "C" {

typedef unsigned int LLDBLangType;
#define LLDB_TO_LLVM_LANG_TYPE(lldb_lang_type) \
(LLVMDWARFSourceLanguage)(((lldb_lang_type) > 0 ? (lldb_lang_type)-1 : 1))
(LLVMDWARFSourceLanguage)(((lldb_lang_type) > 0 ? (lldb_lang_type) - 1 : 1))

struct AOTCompData;
typedef struct AOTCompData *aot_comp_data_t;
Expand Down
3 changes: 2 additions & 1 deletion core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ class JitErrorHandler : public ErrorHandler

JitErrorHandler()
: err(kErrorOk)
{}
{
}

void handleError(Error e, const char *msg, BaseEmitter *base) override
{
Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/fast-jit/jit_ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -1866,14 +1866,14 @@ jit_cc_update_cfg(JitCompContext *cc);
*/
#define JIT_FOREACH_BLOCK_REVERSE(CC, I, B) \
for ((I) = (CC)->_ann._label_num; (I) > 2; (I)--) \
if (((B) = (CC)->_ann._label_basic_block[(I)-1]))
if (((B) = (CC)->_ann._label_basic_block[(I) - 1]))

/**
* The version that includes entry and exit block.
*/
#define JIT_FOREACH_BLOCK_REVERSE_ENTRY_EXIT(CC, I, B) \
for ((I) = (CC)->_ann._label_num; (I) > 0; (I)--) \
if (((B) = (CC)->_ann._label_basic_block[(I)-1]))
if (((B) = (CC)->_ann._label_basic_block[(I) - 1]))

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
else
cur_func_type = cur_func->u.func->func_type;

/* clang-format off */
/* clang-format off */
#if WASM_ENABLE_GC == 0
if (cur_type != cur_func_type) {
wasm_set_exception(module, "indirect call type mismatch");
Expand Down
Loading
Loading