瀏覽代碼

fix: few CI errors caused by recently enabled compilation flags (#4620)

- add missing warning for incompatible pointer types in CMake configuration
- fix a shadow warning
liang.he 4 月之前
父節點
當前提交
ad21524573
共有 2 個文件被更改,包括 17 次插入2 次删除
  1. 16 1
      build-scripts/warnings.cmake
  2. 1 1
      core/iwasm/interpreter/wasm_loader.c

+ 16 - 1
build-scripts/warnings.cmake

@@ -16,13 +16,28 @@ else ()
   #
   #
   # -fpermissive causes warnings like "-fpermissive is valid for C++/ObjC++ but not for C"
   # -fpermissive causes warnings like "-fpermissive is valid for C++/ObjC++ but not for C"
   #
   #
+  # Reference:
+  #   - gcc-4.8 https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Warning-Options.html
+  #   - gcc-11.5 https://gcc.gnu.org/onlinedocs/gcc-11.5.0/gcc/Warning-Options.html
   add_compile_options (
   add_compile_options (
-    $<$<COMPILE_LANGUAGE:C>:-Wincompatible-pointer-types>
     $<$<COMPILE_LANGUAGE:C>:-Wimplicit-function-declaration>
     $<$<COMPILE_LANGUAGE:C>:-Wimplicit-function-declaration>
   )
   )
+
+  # https://gcc.gnu.org/gcc-5/changes.html introduces incompatible-pointer-types
+  # https://releases.llvm.org/7.0.0/tools/clang/docs/DiagnosticsReference.html#wincompatible-pointer-types
+  #   is the earliest version that supports this option I can found.
+  # Assume AppClang versioning is compatible with Clang.
+  if ((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "5.1")
+      OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0.0")
+      OR (CMAKE_C_COMPILER_ID STREQUAL "AppClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "7.0.0"))
+    add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wincompatible-pointer-types>)
+  endif()
+
+  # options benefit embedded system.
   add_compile_options (
   add_compile_options (
     -Wdouble-promotion
     -Wdouble-promotion
   )
   )
+
   # waivers
   # waivers
   add_compile_options (
   add_compile_options (
     -Wno-unused
     -Wno-unused

+ 1 - 1
core/iwasm/interpreter/wasm_loader.c

@@ -7495,7 +7495,7 @@ wasm_loader_unload(WASMModule *module)
 #endif
 #endif
 #endif
 #endif
 #if WASM_ENABLE_BRANCH_HINTS != 0
 #if WASM_ENABLE_BRANCH_HINTS != 0
-    for (size_t i = 0; i < module->function_count; i++) {
+    for (i = 0; i < module->function_count; i++) {
         // be carefull when adding more hints. This only works as long as
         // be carefull when adding more hints. This only works as long as
         // the hint structs have been allocated all at once as an array.
         // the hint structs have been allocated all at once as an array.
         // With only branch-hints at the moment, this is the case.
         // With only branch-hints at the moment, this is the case.