Skip to content

Commit 276d88c

Browse files
vonosmasmahesh-attarde
authored andcommitted
[libc] Don't rely on LIBC_HAS_SANITIZER when enabling null checks. (llvm#150341)
LIBC_HAS_SANITIZER (which is defined if ASan, MSan, or UBSan is enabled) is currently used to implicitly disable null checks, normally enabled via LIBC_ADD_NULL_CHECKS config value. Remove this condition, and rely purely on the config value instead: * LIBC_HAS_SANITIZER will be true even for UBSan modes which doesn't rely on null checks at all (e.g. -fsanitize=alignment) * null checks today (implemented via __builtin_trap) should function normally today even when sanitizer is enabled - trap is still a trap * tests have been migrated to WITH_SIGNAL(-1) which doesn't prescript a particular signal / exit-code, and thus should pass even if sanitizers override the default ones.
1 parent 72d5f5a commit 276d88c

31 files changed

+53
-76
lines changed

libc/src/__support/macros/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ add_header_library(
3535
DEPENDS
3636
.config
3737
.optimization
38-
.sanitizer
3938
)

libc/src/__support/macros/null_check.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111

1212
#include "src/__support/macros/config.h"
1313
#include "src/__support/macros/optimization.h"
14-
#include "src/__support/macros/sanitizer.h"
1514

16-
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
15+
#if defined(LIBC_ADD_NULL_CHECKS)
1716
#define LIBC_CRASH_ON_NULLPTR(ptr) \
1817
do { \
1918
if (LIBC_UNLIKELY((ptr) == nullptr)) \

libc/src/__support/macros/sanitizer.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
#define LIBC_HAS_MEMORY_SANITIZER
2424
#endif
2525

26-
#if LIBC_HAS_FEATURE(undefined_behavior_sanitizer)
27-
#define LIBC_HAS_UNDEFINED_BEHAVIOR_SANITIZER
28-
#endif
29-
30-
#if defined(LIBC_HAS_ADDRESS_SANITIZER) || \
31-
defined(LIBC_HAS_MEMORY_SANITIZER) || \
32-
defined(LIBC_HAS_UNDEFINED_BEHAVIOR_SANITIZER)
33-
#define LIBC_HAS_SANITIZER
34-
#endif
35-
3626
#ifdef LIBC_HAS_MEMORY_SANITIZER
3727
// Only perform MSAN unpoison in non-constexpr context.
3828
#include <sanitizer/msan_interface.h>

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3169,7 +3169,6 @@ add_fp_unittest(
31693169
libc.hdr.signal_macros
31703170
libc.src.math.nanf
31713171
libc.src.__support.FPUtil.fp_bits
3172-
libc.src.__support.macros.sanitizer
31733172
# FIXME: The nan tests currently have death tests, which aren't supported for
31743173
# hermetic tests.
31753174
UNIT_TEST_ONLY
@@ -3185,7 +3184,6 @@ add_fp_unittest(
31853184
libc.hdr.signal_macros
31863185
libc.src.math.nan
31873186
libc.src.__support.FPUtil.fp_bits
3188-
libc.src.__support.macros.sanitizer
31893187
# FIXME: The nan tests currently have death tests, which aren't supported for
31903188
# hermetic tests.
31913189
UNIT_TEST_ONLY
@@ -3201,7 +3199,6 @@ add_fp_unittest(
32013199
libc.hdr.signal_macros
32023200
libc.src.math.nanl
32033201
libc.src.__support.FPUtil.fp_bits
3204-
libc.src.__support.macros.sanitizer
32053202
# FIXME: The nan tests currently have death tests, which aren't supported for
32063203
# hermetic tests.
32073204
UNIT_TEST_ONLY
@@ -3217,7 +3214,6 @@ add_fp_unittest(
32173214
libc.hdr.signal_macros
32183215
libc.src.math.nanf16
32193216
libc.src.__support.FPUtil.fp_bits
3220-
libc.src.__support.macros.sanitizer
32213217
# FIXME: The nan tests currently have death tests, which aren't supported for
32223218
# hermetic tests.
32233219
UNIT_TEST_ONLY
@@ -3233,7 +3229,6 @@ add_fp_unittest(
32333229
libc.hdr.signal_macros
32343230
libc.src.math.nanf128
32353231
libc.src.__support.FPUtil.fp_bits
3236-
libc.src.__support.macros.sanitizer
32373232
# FIXME: The nan tests currently have death tests, which aren't supported for
32383233
# hermetic tests.
32393234
UNIT_TEST_ONLY

libc/test/src/math/smoke/nan_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "hdr/signal_macros.h"
1010
#include "src/__support/FPUtil/FPBits.h"
11-
#include "src/__support/macros/sanitizer.h"
1211
#include "src/math/nan.h"
1312
#include "test/UnitTest/FEnvSafeTest.h"
1413
#include "test/UnitTest/FPMatcher.h"
@@ -44,8 +43,8 @@ TEST_F(LlvmLibcNanTest, RandomString) {
4443
run_test("123 ", 0x7ff8000000000000);
4544
}
4645

47-
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
46+
#if defined(LIBC_ADD_NULL_CHECKS)
4847
TEST_F(LlvmLibcNanTest, InvalidInput) {
4948
EXPECT_DEATH([] { LIBC_NAMESPACE::nan(nullptr); }, WITH_SIGNAL(-1));
5049
}
51-
#endif // LIBC_HAS_ADDRESS_SANITIZER
50+
#endif // LIBC_ADD_NULL_CHECKS

libc/test/src/math/smoke/nanf128_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "hdr/signal_macros.h"
1010
#include "src/__support/FPUtil/FPBits.h"
11-
#include "src/__support/macros/sanitizer.h"
1211
#include "src/__support/uint128.h"
1312
#include "src/math/nanf128.h"
1413
#include "test/UnitTest/FEnvSafeTest.h"
@@ -55,8 +54,8 @@ TEST_F(LlvmLibcNanf128Test, RandomString) {
5554
QUIET_NAN);
5655
}
5756

58-
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
57+
#if defined(LIBC_ADD_NULL_CHECKS)
5958
TEST_F(LlvmLibcNanf128Test, InvalidInput) {
6059
EXPECT_DEATH([] { LIBC_NAMESPACE::nanf128(nullptr); }, WITH_SIGNAL(-1));
6160
}
62-
#endif // LIBC_HAS_ADDRESS_SANITIZER
61+
#endif // LIBC_ADD_NULL_CHECKS

libc/test/src/math/smoke/nanf16_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "hdr/signal_macros.h"
1010
#include "src/__support/FPUtil/FPBits.h"
11-
#include "src/__support/macros/sanitizer.h"
1211
#include "src/math/nanf16.h"
1312
#include "test/UnitTest/FEnvSafeTest.h"
1413
#include "test/UnitTest/FPMatcher.h"
@@ -43,8 +42,8 @@ TEST_F(LlvmLibcNanf16Test, RandomString) {
4342
run_test("123 ", 0x7e00);
4443
}
4544

46-
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
45+
#if defined(LIBC_ADD_NULL_CHECKS)
4746
TEST_F(LlvmLibcNanf16Test, InvalidInput) {
4847
EXPECT_DEATH([] { LIBC_NAMESPACE::nanf16(nullptr); }, WITH_SIGNAL(-1));
4948
}
50-
#endif // LIBC_HAS_ADDRESS_SANITIZER
49+
#endif // LIBC_ADD_NULL_CHECKS

libc/test/src/math/smoke/nanf_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "hdr/signal_macros.h"
1010
#include "src/__support/FPUtil/FPBits.h"
11-
#include "src/__support/macros/sanitizer.h"
1211
#include "src/math/nanf.h"
1312
#include "test/UnitTest/FEnvSafeTest.h"
1413
#include "test/UnitTest/FPMatcher.h"
@@ -43,8 +42,8 @@ TEST_F(LlvmLibcNanfTest, RandomString) {
4342
run_test("123 ", 0x7fc00000);
4443
}
4544

46-
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
45+
#if defined(LIBC_ADD_NULL_CHECKS)
4746
TEST_F(LlvmLibcNanfTest, InvalidInput) {
4847
EXPECT_DEATH([] { LIBC_NAMESPACE::nanf(nullptr); }, WITH_SIGNAL(-1));
4948
}
50-
#endif // LIBC_HAS_ADDRESS_SANITIZER
49+
#endif // LIBC_ADD_NULL_CHECKS

libc/test/src/math/smoke/nanl_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "hdr/signal_macros.h"
1010
#include "src/__support/FPUtil/FPBits.h"
11-
#include "src/__support/macros/sanitizer.h"
1211
#include "src/math/nanl.h"
1312
#include "test/UnitTest/FEnvSafeTest.h"
1413
#include "test/UnitTest/FPMatcher.h"
@@ -71,8 +70,8 @@ TEST_F(LlvmLibcNanlTest, RandomString) {
7170
run_test("123 ", expected);
7271
}
7372

74-
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
73+
#if defined(LIBC_ADD_NULL_CHECKS)
7574
TEST_F(LlvmLibcNanlTest, InvalidInput) {
7675
EXPECT_DEATH([] { LIBC_NAMESPACE::nanl(nullptr); }, WITH_SIGNAL(-1));
7776
}
78-
#endif // LIBC_HAS_ADDRESS_SANITIZER
77+
#endif // LIBC_ADD_NULL_CHECKS

libc/test/src/stdfix/IdivTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class IdivTest : public LIBC_NAMESPACE::testing::Test {
7171
}
7272
};
7373

74-
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER)
74+
#if defined(LIBC_ADD_NULL_CHECKS)
7575
#define LIST_IDIV_TESTS(Name, T, XType, func) \
7676
using LlvmLibcIdiv##Name##Test = IdivTest<T, XType>; \
7777
TEST_F(LlvmLibcIdiv##Name##Test, InvalidNumbers) { \
@@ -88,4 +88,4 @@ class IdivTest : public LIBC_NAMESPACE::testing::Test {
8888
testSpecialNumbers(&func); \
8989
} \
9090
static_assert(true, "Require semicolon.")
91-
#endif // LIBC_HAS_ADDRESS_SANITIZER
91+
#endif // LIBC_ADD_NULL_CHECKS

0 commit comments

Comments
 (0)