From dd9b01bc51a368b9903a52f276f6d7ee425d1c8d Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Tue, 7 Jan 2025 17:53:59 +0100 Subject: [PATCH 1/9] test: add test for C++ applications --- test/CMakeLists.txt | 3 +++ test/cplusplus.cpp | 25 +++++++++++++++++++++++++ test/test.c | 1 + test/test.h | 10 ++++++++++ 4 files changed, 39 insertions(+) create mode 100644 test/cplusplus.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8458987b5..dce6c0b0b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -30,6 +30,7 @@ include(sanitizer) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_CXX_STANDARD 11) if(MSVC) add_compile_options("/W3") @@ -153,6 +154,8 @@ if(USE_OPENSSL) ) endif() +list(APPEND SRCS cplusplus.cpp) + ############################################################################## # diff --git a/test/cplusplus.cpp b/test/cplusplus.cpp new file mode 100644 index 000000000..8c79a3d6f --- /dev/null +++ b/test/cplusplus.cpp @@ -0,0 +1,25 @@ +/** + * @file cplusplus.cpp Emulate C++ applications + * + * Copyright (C) 2025 Alfred E. Heggestad + */ + +#include +#include +#include +#include "test.h" + + +#define DEBUG_MODULE "cplusplus" +#define DEBUG_LEVEL 5 +#include + + +int test_cplusplus(void) +{ + std::cout << "test\n"; + + DEBUG_NOTICE("%H\n", sys_kernel_get, nullptr); + + return 0; +} diff --git a/test/test.c b/test/test.c index 9be0c7bc0..0de8cabc7 100644 --- a/test/test.c +++ b/test/test.c @@ -279,6 +279,7 @@ static const struct test tests_integration[] = { TEST(test_tmr_jiffies_usec), TEST(test_turn_thread), TEST(test_thread_cnd_timedwait), + TEST(test_cplusplus), }; diff --git a/test/test.h b/test/test.h index ef4f8626c..129922eb2 100644 --- a/test/test.h +++ b/test/test.h @@ -388,6 +388,16 @@ int test_integration(const char *name, bool verbose); int test_sipevent_network(void); int test_sip_drequestf_network(void); +#ifdef __cplusplus +extern "C" { +#endif + +int test_cplusplus(void); + +#ifdef __cplusplus +} +#endif + /* High-level API */ int test_reg(const char *name, bool verbose); int test_oom(const char *name, bool verbose); From 4940a438cbf089de28778fb77652f24c0c76ab2c Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:07:16 +0100 Subject: [PATCH 2/9] cmake: move some compile options to C only --- CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e55f145d5..04cdecb5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,7 @@ endif() check_c_compiler_flag("-Watomic-implicit-seq-cst" COMPILER_SUPPORTS_WATOMIC) if(COMPILER_SUPPORTS_WATOMIC) - add_compile_options(-Watomic-implicit-seq-cst) + add_compile_options("$<$:-Watomic-implicit-seq-cst>") endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dce6c0b0b..b1beb62df 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -53,7 +53,7 @@ else() endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wshorten-64-to-32) + add_compile_options("$<$:-Wshorten-64-to-32>") endif() include_directories( From 6622407093a869cba310b34d0aa0aea0322b58a3 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:13:25 +0100 Subject: [PATCH 3/9] cmake: move -Wshorten-64-to-32 to C-only --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04cdecb5e..6aab060b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,10 +83,10 @@ endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang") add_compile_options( - -Wshorten-64-to-32 -Wno-gnu-zero-variadic-macro-arguments -Wno-c2x-extensions ) + add_compile_options("$<$:-Wshorten-64-to-32>") endif() check_c_compiler_flag("-Watomic-implicit-seq-cst" COMPILER_SUPPORTS_WATOMIC) From ef3a7730a1605859c75431fc8ac06becae9c838e Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:29:27 +0100 Subject: [PATCH 4/9] sanitizer: add clang++ --- .github/workflows/sanitizers.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index bfd94c300..9c853aaa3 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -18,8 +18,10 @@ jobs: sanitizer: [thread, address, undefined] env: CC: clang-18 + CXX: clang++-18 CMAKE_GENERATOR: Ninja CFLAGS: "-fsanitize=${{ matrix.sanitizer }} -fno-sanitize-recover=all -fno-sanitize=function" + CXXFLAGS: "-fsanitize=${{ matrix.sanitizer }} -fno-sanitize-recover=all -fno-sanitize=function" ASAN_OPTIONS: fast_unwind_on_malloc=0 steps: From 673dca6ce21acf02e5c3cdc9954946a7c26ce000 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:30:53 +0100 Subject: [PATCH 5/9] test: move compile options to C only --- test/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b1beb62df..526d7765a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -35,7 +35,8 @@ set(CMAKE_CXX_STANDARD 11) if(MSVC) add_compile_options("/W3") else() - add_compile_options( + + set(c_flags -Wall -Wbad-function-cast -Wcast-align @@ -50,6 +51,10 @@ else() -Wuninitialized -Wvla ) + + add_compile_options( + "$<$:${c_flags}>" + ) endif() if(CMAKE_C_COMPILER_ID MATCHES "Clang") From 1c371f89b26ef2514613f4e31db55e6d7df33909 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:37:12 +0100 Subject: [PATCH 6/9] test: fix cmake lint --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 526d7765a..ae910a84e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,7 +36,7 @@ if(MSVC) add_compile_options("/W3") else() - set(c_flags + set(c_flags -Wall -Wbad-function-cast -Wcast-align From f4a493fb2e04f05ee278198e791f8f71ff3e58b0 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:44:39 +0100 Subject: [PATCH 7/9] ci: rename job --- .github/workflows/cmake_win.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake_win.yml b/.github/workflows/cmake_win.yml index 3244235d2..4058e46d5 100644 --- a/.github/workflows/cmake_win.yml +++ b/.github/workflows/cmake_win.yml @@ -1,4 +1,4 @@ -name: CMake and Windows +name: Windows on: push: From 00606c2b04e18fdf34ba256e66c3bbe2206cd60e Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:27:49 +0100 Subject: [PATCH 8/9] atomic: attempt to fix __iso_volatile_load8() compile error --- include/re_atomic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/re_atomic.h b/include/re_atomic.h index ed2808814..e18afaa13 100644 --- a/include/re_atomic.h +++ b/include/re_atomic.h @@ -599,7 +599,7 @@ static __forceinline unsigned __int64 _re_atomic_load( switch (size) { case 1u: - v = __iso_volatile_load8((const unsigned __int8*)a); + v = __iso_volatile_load8((const volatile __int8*)a); break; case 2u: v = __iso_volatile_load16((const unsigned __int16*)a); From 7b543d3ac410774050242169f90aaccdf4bb5df3 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" <114750+alfredh@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:16:02 +0100 Subject: [PATCH 9/9] atomic: change unsigned to volatile --- include/re_atomic.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/re_atomic.h b/include/re_atomic.h index e18afaa13..cbcc181d4 100644 --- a/include/re_atomic.h +++ b/include/re_atomic.h @@ -602,13 +602,13 @@ static __forceinline unsigned __int64 _re_atomic_load( v = __iso_volatile_load8((const volatile __int8*)a); break; case 2u: - v = __iso_volatile_load16((const unsigned __int16*)a); + v = __iso_volatile_load16((const volatile __int16*)a); break; case 4u: - v = __iso_volatile_load32((const unsigned __int32*)a); + v = __iso_volatile_load32((const volatile __int32*)a); break; default: - v = __iso_volatile_load64((const unsigned __int64*)a); + v = __iso_volatile_load64((const volatile __int64*)a); break; }