diff --git a/.github/workflows/clang.yaml b/.github/workflows/clang.yaml new file mode 100644 index 0000000000000..57b833f822047 --- /dev/null +++ b/.github/workflows/clang.yaml @@ -0,0 +1,89 @@ +name: Build with Clang/LLVM + +on: pull_request + +jobs: + clang-build-cancel: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + clang-build: + runs-on: ubuntu-latest + needs: clang-build-cancel + container: + image: zephyrprojectrtos/ci:v0.17.0-alpha2 + options: '--entrypoint /bin/bash' + strategy: + fail-fast: false + matrix: + subset: [1] + env: + ZEPHYR_SDK_INSTALL_DIR: /opt/toolchains/zephyr-sdk-0.12.4 + CLANG_ROOT_DIR: /usr/lib/llvm-12 + MATRIX_SIZE: 1 + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.6.0 + with: + access_token: ${{ github.token }} + - name: Update PATH for west + run: | + echo "$HOME/.local/bin" >> $GITHUB_PATH + + - name: checkout + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + + - name: west setup + run: | + west init -l . || true + west update + + - name: Check Environment + run: | + cmake --version + ${CLANG_ROOT_DIR}/bin/clang --version + gcc --version + ls -la + + - name: Run Tests with Twister + run: | + #source zephyr-env.sh + export ZEPHYR_BASE=${PWD} + export ZEPHYR_TOOLCHAIN_VARIANT=llvm + ./scripts/twister --inline-logs -N -v --integration -p native_posix -T tests/kernel/common --subset ${{matrix.subset}}/${MATRIX_SIZE} --retry-failed 3 + + - name: Upload Unit Test Results + if: always() + uses: actions/upload-artifact@v2 + with: + name: Unit Test Results (Subset ${{ matrix.subset }}) + path: twister-out/twister.xml + + publish-test-results: + name: "Publish Unit Tests Results" + needs: clang-build + runs-on: ubuntu-20.04 + # the build-and-test job might be skipped, we don't need to run this job then + if: success() || failure() + + steps: + - name: Download Artifacts + uses: actions/download-artifact@v2 + with: + path: artifacts + + - name: Display structure of downloaded files + run: ls -R + + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v1.6 + with: + check_name: Unit Test Results + github_token: ${{ secrets.GITHUB_TOKEN }} + files: "**/twister.xml" diff --git a/cmake/toolchain/llvm/generic.cmake b/cmake/toolchain/llvm/generic.cmake index 741a2b4557236..b25e8cee284b1 100644 --- a/cmake/toolchain/llvm/generic.cmake +++ b/cmake/toolchain/llvm/generic.cmake @@ -27,8 +27,6 @@ set(CMAKE_C_COMPILER_TARGET ${triple}) set(CMAKE_ASM_COMPILER_TARGET ${triple}) set(CMAKE_CXX_COMPILER_TARGET ${triple}) -if("${ARCH}" STREQUAL "posix") - set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib") -endif() +set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib") message(STATUS "Found toolchain: host (clang/ld)") diff --git a/include/sys/cbprintf_internal.h b/include/sys/cbprintf_internal.h index ffb483b241ad3..752991b92375e 100644 --- a/include/sys/cbprintf_internal.h +++ b/include/sys/cbprintf_internal.h @@ -259,6 +259,18 @@ union z_cbprintf_hdr { void *raw; }; +/* When using clang additional warning needs to be suppressed since each + * argument of fmt string is used for sizeof() which results in the warning + * if argument is a stirng literal. Suppression is added here instead of + * the macro which generates the warning to not slow down the compiler. + */ +#if __clang__ == 1 +#define Z_CBPRINTF_SUPPRESS_SIZEOF_ARRAY_DECAY \ + _Pragma("GCC diagnostic ignored \"-Wsizeof-array-decay\"") +#else +#define Z_CBPRINTF_SUPPRESS_SIZEOF_ARRAY_DECAY +#endif + /** @brief Statically package a formatted string with arguments. * * @param buf buffer. If null then only length is calculated. @@ -277,6 +289,7 @@ union z_cbprintf_hdr { do { \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"") \ + Z_CBPRINTF_SUPPRESS_SIZEOF_ARRAY_DECAY \ BUILD_ASSERT(!IS_ENABLED(CONFIG_XTENSA) || \ (IS_ENABLED(CONFIG_XTENSA) && \ !(_align_offset % CBPRINTF_PACKAGE_ALIGNMENT)), \ diff --git a/include/toolchain.h b/include/toolchain.h index ea905a083b3ec..88639a83c42d2 100644 --- a/include/toolchain.h +++ b/include/toolchain.h @@ -37,6 +37,8 @@ #include #elif defined(__CCAC__) #include +#elif defined(__llvm__) +#include #elif defined(__GNUC__) || (defined(_LINKER) && defined(__GCC_LINKER_CMD__)) #include #else diff --git a/include/toolchain/llvm.h b/include/toolchain/llvm.h new file mode 100644 index 0000000000000..afcac9c279ec6 --- /dev/null +++ b/include/toolchain/llvm.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021 Intel Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ +#define ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ + + +#define __no_optimization __attribute__((optnone)) +#include + + +#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_LLVM_H_ */ diff --git a/tests/kernel/common/src/timeout_order.c b/tests/kernel/common/src/timeout_order.c index cf4c06a9a0548..6d76e461e1455 100644 --- a/tests/kernel/common/src/timeout_order.c +++ b/tests/kernel/common/src/timeout_order.c @@ -23,8 +23,7 @@ static void thread(void *p1, void *p2, void *p3) uintptr_t id = (uintptr_t)p1; k_timer_status_sync(&timer[id]); - printk("%s %" PRIxPTR " synced on timer %" PRIxPTR "\n", - __func__, id, id); + printk("%s %lu synced on timer %lu\n", __func__, POINTER_TO_UINT(id), POINTER_TO_UINT(id)); /* no need to protect cur, all threads have the same prio */ results[cur++] = id; diff --git a/tests/lib/cmsis_dsp/filtering/testcase.yaml b/tests/lib/cmsis_dsp/filtering/testcase.yaml index f94207d892e1d..e9b2b6b0add86 100644 --- a/tests/lib/cmsis_dsp/filtering/testcase.yaml +++ b/tests/lib/cmsis_dsp/filtering/testcase.yaml @@ -6,6 +6,7 @@ common: - mps2_an521 - native_posix tags: cmsis_dsp + toolchain_exclude: llvm tests: libraries.cmsis_dsp.filtering: diff --git a/tests/subsys/fs/multi-fs/src/test_common_dir.c b/tests/subsys/fs/multi-fs/src/test_common_dir.c index 067b9a24c03b9..8bb9a7165f165 100644 --- a/tests/subsys/fs/multi-fs/src/test_common_dir.c +++ b/tests/subsys/fs/multi-fs/src/test_common_dir.c @@ -11,6 +11,10 @@ #include #include "test_common.h" +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + int test_rmdir(const char *dir_path); int test_mkdir(const char *dir_path, const char *file)