[compiler-rt] 8e30b55 - [scudo] Fix CHECK implementation
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue May 25 10:56:01 PDT 2021
Author: Vitaly Buka
Date: 2021-05-25T10:55:52-07:00
New Revision: 8e30b55c82cc245f8b59ef3b29d95c9797584b63
URL: https://github.com/llvm/llvm-project/commit/8e30b55c82cc245f8b59ef3b29d95c9797584b63
DIFF: https://github.com/llvm/llvm-project/commit/8e30b55c82cc245f8b59ef3b29d95c9797584b63.diff
LOG: [scudo] Fix CHECK implementation
Cast of signed types to u64 breaks comparison.
Also remove double () around operands.
Reviewed By: cryptoad, hctim
Differential Revision: https://reviews.llvm.org/D103060
Added:
Modified:
compiler-rt/lib/scudo/standalone/internal_defs.h
compiler-rt/lib/scudo/standalone/report.cpp
compiler-rt/lib/scudo/standalone/tests/report_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/internal_defs.h b/compiler-rt/lib/scudo/standalone/internal_defs.h
index bbf7631be189e..c9ffad136b78d 100644
--- a/compiler-rt/lib/scudo/standalone/internal_defs.h
+++ b/compiler-rt/lib/scudo/standalone/internal_defs.h
@@ -105,14 +105,11 @@ void NORETURN die();
void NORETURN reportCheckFailed(const char *File, int Line,
const char *Condition, u64 Value1, u64 Value2);
-
#define CHECK_IMPL(C1, Op, C2) \
do { \
- scudo::u64 V1 = (scudo::u64)(C1); \
- scudo::u64 V2 = (scudo::u64)(C2); \
- if (UNLIKELY(!(V1 Op V2))) { \
- scudo::reportCheckFailed(__FILE__, __LINE__, \
- "(" #C1 ") " #Op " (" #C2 ")", V1, V2); \
+ if (UNLIKELY(!(C1 Op C2))) { \
+ scudo::reportCheckFailed(__FILE__, __LINE__, #C1 " " #Op " " #C2, \
+ (scudo::u64)C1, (scudo::u64)C2); \
scudo::die(); \
} \
} while (false)
diff --git a/compiler-rt/lib/scudo/standalone/report.cpp b/compiler-rt/lib/scudo/standalone/report.cpp
index 80cc6eda2af92..292c29918d1a1 100644
--- a/compiler-rt/lib/scudo/standalone/report.cpp
+++ b/compiler-rt/lib/scudo/standalone/report.cpp
@@ -45,8 +45,8 @@ void NORETURN reportCheckFailed(const char *File, int Line,
trap();
}
ScopedErrorReport Report;
- Report.append("CHECK failed @ %s:%d %s (%llu, %llu)\n", File, Line, Condition,
- Value1, Value2);
+ Report.append("CHECK failed @ %s:%d %s ((u64)op1=%llu, (u64)op2=%llu)\n",
+ File, Line, Condition, Value1, Value2);
}
// Generic string fatal error message.
diff --git a/compiler-rt/lib/scudo/standalone/tests/report_test.cpp b/compiler-rt/lib/scudo/standalone/tests/report_test.cpp
index 09f03f1ac896d..374b6b8de3436 100644
--- a/compiler-rt/lib/scudo/standalone/tests/report_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/report_test.cpp
@@ -10,6 +10,13 @@
#include "report.h"
+TEST(ScudoReportTest, Check) {
+ CHECK_LT(-1, 1);
+ EXPECT_DEATH(CHECK_GT(-1, 1),
+ "\\(-1\\) > \\(1\\) \\(\\(u64\\)op1=18446744073709551615, "
+ "\\(u64\\)op2=1");
+}
+
TEST(ScudoReportTest, Generic) {
// Potentially unused if EXPECT_DEATH isn't defined.
UNUSED void *P = reinterpret_cast<void *>(0x42424242U);
More information about the llvm-commits
mailing list