1 //===-- Unittests for __stack_chk_fail ------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "hdr/signal_macros.h"
10 #include "src/__support/macros/sanitizer.h"
11 #include "src/compiler/__stack_chk_fail.h"
12 #include "src/string/memset.h"
13 #include "test/UnitTest/Test.h"
15 TEST(LlvmLibcStackChkFail
, Death
) {
16 EXPECT_DEATH([] { __stack_chk_fail(); }, WITH_SIGNAL(SIGABRT
));
19 // Disable the test when asan is enabled so that it doesn't immediately fail
20 // after the memset, but before the stack canary is re-checked.
21 #ifndef LIBC_HAS_ADDRESS_SANITIZER
22 TEST(LlvmLibcStackChkFail
, Smash
) {
26 LIBC_NAMESPACE::memset(arr
, 0xAA, 2001);
28 WITH_SIGNAL(SIGABRT
));
30 #endif // LIBC_HAS_ADDRESS_SANITIZER