Skip to content

Commit 08b5ecc

Browse files
Fixed address sanitizer flags when using clang on windows (#142)
1 parent a7bcbd4 commit 08b5ecc

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ if(ENABLE_SANITIZERS)
9292
set(SANITIZERS "address,undefined")
9393
# Check for Clang since vptr and fdsan are Clang-specific
9494
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
95-
list(APPEND SANITIZERS "vptr")
95+
# vptr is not supported on Windows.
96+
if(NOT WIN32)
97+
list(APPEND SANITIZERS "vptr")
98+
endif()
9699
# FDSan only works on Android builds with Clang
97100
if (ANDROID)
98101
list(APPEND SANITIZERS "fdsan")

Tests/UnitTests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ endif()
4646
add_executable(UnitTests ${SOURCES} ${SCRIPTS} ${TYPE_SCRIPTS} ${ASSETS})
4747
target_compile_definitions(UnitTests PRIVATE JSRUNTIMEHOST_PLATFORM="${JSRUNTIMEHOST_PLATFORM}")
4848

49+
if(ENABLE_SANITIZERS)
50+
target_compile_definitions(UnitTests PRIVATE JSRUNTIMEHOST_SANITIZERS_ENABLED=1)
51+
endif()
52+
4953
target_link_libraries(UnitTests
5054
PRIVATE AppRuntime
5155
PRIVATE Console

Tests/UnitTests/Scripts/tests.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Mocha.reporter('spec');
77

88
declare const hostPlatform: string;
99
declare const setExitCode: (code: number) => void;
10+
declare const sanitizersEnabled: boolean;
1011

1112

1213
describe("AbortController", function () {
@@ -1234,11 +1235,11 @@ describe("Performance", function () {
12341235
it("should measure elapsed time accurately", function (done) {
12351236
const start = performance.now();
12361237
const delay = 50;
1238+
const tolerance = sanitizersEnabled ? 500 : 100;
12371239
setTimeout(() => {
12381240
const elapsed = performance.now() - start;
1239-
// Allow some tolerance (elapsed should be at least the delay, but could be slightly more)
12401241
expect(elapsed).to.be.at.least(delay - 5);
1241-
expect(elapsed).to.be.lessThan(delay + 100); // generous upper bound
1242+
expect(elapsed).to.be.lessThan(delay + tolerance);
12421243
done();
12431244
}, delay);
12441245
});

Tests/UnitTests/Shared/Shared.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ TEST(JavaScript, All)
8080
env.Global().Set("setExitCode", setExitCodeCallback);
8181

8282
env.Global().Set("hostPlatform", Napi::Value::From(env, JSRUNTIMEHOST_PLATFORM));
83+
84+
#ifdef JSRUNTIMEHOST_SANITIZERS_ENABLED
85+
env.Global().Set("sanitizersEnabled", Napi::Value::From(env, true));
86+
#else
87+
env.Global().Set("sanitizersEnabled", Napi::Value::From(env, false));
88+
#endif
8389
});
8490

8591
Babylon::ScriptLoader loader{runtime};

0 commit comments

Comments
 (0)