Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make clang thread safety analysis configurable. #26422

Merged
merged 2 commits into from
May 9, 2023
Merged
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
10 changes: 10 additions & 0 deletions src/system/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import("//build_overrides/chip.gni")
import("//build_overrides/nlassert.gni")
import("//build_overrides/nlfaultinjection.gni")

import("${build_root}/config/compiler/compiler.gni")
import("${chip_root}/build/chip/buildconfig_header.gni")
import("${chip_root}/build/chip/tests.gni")
import("${chip_root}/src/platform/device.gni")
Expand All @@ -32,6 +33,12 @@ declare_args() {

# Extra include dirs for project configs.
chip_project_config_include_dirs = []

# enable clang thread safety analysis in SystemMutex.h,
# specifically attributes such as capability, guarded_by, acquire, ...
#
# see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
chip_enable_thread_safety_checks = is_clang
}

if (chip_project_config_include_dirs == [] &&
Expand Down Expand Up @@ -117,6 +124,9 @@ buildconfig_header("system_buildconfig") {
"SYSTEM_PLATFORM_CONFIG_INCLUDE=${chip_system_platform_config_include}",
]
}
if (chip_enable_thread_safety_checks) {
defines += [ "SYSTEM_ENABLE_CLANG_THREAD_SAFETY_ANALYSIS=1" ]
}

if (chip_system_layer_impl_config_file != "") {
defines += [ "CHIP_SYSTEM_LAYER_IMPL_CONFIG_FILE=${chip_system_layer_impl_config_file}" ]
Expand Down
2 changes: 1 addition & 1 deletion src/system/SystemMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace chip {
namespace System {

// Enable thread safety attributes only with clang.
#if defined(__clang__) && (!defined(SWIG))
#if defined(SYSTEM_ENABLE_CLANG_THREAD_SAFETY_ANALYSIS) && (!defined(SWIG))
#define CHIP_TSA_ATTRIBUTE__(x) __attribute__((x))
#else
#define CHIP_TSA_ATTRIBUTE__(x)
Expand Down