Skip to content

Commit 4ecbe45

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

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/node_process_methods.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ static void Abort(const FunctionCallbackInfo<Value>& args) {
7070
ABORT();
7171
}
7272

73-
// For internal testing only, not exposed to userland.
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
7484
static void CauseSegfault(const FunctionCallbackInfo<Value>& args) {
7585
// This should crash hard all platforms.
7686
volatile void** d = static_cast<volatile void**>(nullptr);

0 commit comments

Comments
 (0)