summaryrefslogtreecommitdiff
path: root/compiler-rt
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2019-01-09 00:44:13 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2019-01-09 00:44:13 +0000
commitbd8b20097f5003d7d8988a6d6314026bcce91b50 (patch)
tree11bae044cffb4bf403ea356d96a35732d6452aa4 /compiler-rt
parent628c908b2b36f0ea30eae49dbee01d0e2e8ace1e (diff)
hwasan: Ignore loads and stores of size 0.
Now that memory intrinsics are instrumented, it's more likely that CheckAddressSized will be called with size 0. (It was possible before with IR like: %val = load [0 x i8], [0 x i8]* %ptr but I don't think clang will generate IR like that and the optimizer would normally remove it by the time it got anywhere near our pass anyway). The right thing to do in both cases is to disable the addressing checks (since the underlying memory intrinsic is a no-op), so that's what we do. Differential Revision: https://reviews.llvm.org/D56465
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/hwasan/hwasan_checks.h3
-rw-r--r--compiler-rt/test/hwasan/TestCases/mem-intrinsics-zero-size.c10
2 files changed, 12 insertions, 1 deletions
diff --git a/compiler-rt/lib/hwasan/hwasan_checks.h b/compiler-rt/lib/hwasan/hwasan_checks.h
index 39321a28b00..688b5e2bed8 100644
--- a/compiler-rt/lib/hwasan/hwasan_checks.h
+++ b/compiler-rt/lib/hwasan/hwasan_checks.h
@@ -61,7 +61,8 @@ __attribute__((always_inline, nodebug)) static void CheckAddress(uptr p) {
template <ErrorAction EA, AccessType AT>
__attribute__((always_inline, nodebug)) static void CheckAddressSized(uptr p,
uptr sz) {
- CHECK_NE(0, sz);
+ if (sz == 0)
+ return;
tag_t ptr_tag = GetTagFromPointer(p);
uptr ptr_raw = p & ~kAddressTagMask;
tag_t *shadow_first = (tag_t *)MemToShadow(ptr_raw);
diff --git a/compiler-rt/test/hwasan/TestCases/mem-intrinsics-zero-size.c b/compiler-rt/test/hwasan/TestCases/mem-intrinsics-zero-size.c
new file mode 100644
index 00000000000..bcb8e0771f1
--- /dev/null
+++ b/compiler-rt/test/hwasan/TestCases/mem-intrinsics-zero-size.c
@@ -0,0 +1,10 @@
+// RUN: %clang_hwasan %s -o %t && %run %t
+
+#include <string.h>
+
+int main() {
+ char a[1];
+ memset(a, 0, 0);
+ memmove(a, a, 0);
+ memcpy(a, a, 0);
+}