Skip to content

Commit a4f3090

Browse files
committed
test: disable optimizations for CauseSegfault
1 parent 559985c commit a4f3090

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/node_process_methods.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,19 @@ static void Abort(const FunctionCallbackInfo<Value>& args) {
7070
ABORT();
7171
}
7272

73-
// For internal testing only, not exposed to userland.
74-
static void CauseSegfault(const FunctionCallbackInfo<Value>& args) {
73+
// For internal testing only, not exposed to userland. If possible, disable
74+
// optimizations since we are technically relying on an undefined behavior that
75+
// modern compilers like to abuse.
76+
#ifdef __has_cpp_attribute
77+
#if __has_cpp_attribute(clang::optnone)
78+
[[clang::optnone]]
79+
#endif
80+
#if __has_cpp_attribute(gnu::optimize)
81+
[[gnu::optimize(0)]]
82+
#endif
83+
#endif
84+
static void
85+
CauseSegfault(const FunctionCallbackInfo<Value>& args) {
7586
// This should crash hard all platforms.
7687
volatile void** d = static_cast<volatile void**>(nullptr);
7788
*d = nullptr;

0 commit comments

Comments
 (0)