Skip to content

[ubsan] Add runtime test for -fsanitize=local-bounds #120038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

vitalybuka
Copy link
Collaborator

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Dec 16, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Vitaly Buka (vitalybuka)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/120038.diff

1 Files Affected:

  • (added) compiler-rt/test/ubsan/TestCases/Misc/local_bounds.cpp (+28)
diff --git a/compiler-rt/test/ubsan/TestCases/Misc/local_bounds.cpp b/compiler-rt/test/ubsan/TestCases/Misc/local_bounds.cpp
new file mode 100644
index 00000000000000..92e9e62dbc8698
--- /dev/null
+++ b/compiler-rt/test/ubsan/TestCases/Misc/local_bounds.cpp
@@ -0,0 +1,28 @@
+// RUN: %clangxx -fsanitize=local-bounds %s -O3 -o %t && %run %t 1
+// RUN: %clangxx -fsanitize=local-bounds %s -O3 -o %t && not --crash %run %t 3
+
+// FIXME: it's always trap for now.
+
+#include <cstdlib>
+
+struct S {
+  int k;
+  int l;
+};
+
+__attribute__((noinline)) void init(S *s) {
+  __asm__ __volatile__("" : : "r"(s) : "memory");
+}
+
+__attribute__((noinline, no_sanitize("memory"))) int test(char i) {
+  S a;
+  init(&a);
+  S b;
+  init(&b);
+  return ((int*)(&a))[i];
+}
+
+int main(int argc, char **argv) {
+  test(argv[1][0] - '0');
+  return 0;
+}

Copy link

github-actions bot commented Dec 16, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.ubsan-add-runtime-test-for-fsanitizelocal-bounds to main December 18, 2024 23:03
Created using spr 1.3.4
@vitalybuka vitalybuka merged commit 0fd7c49 into main Dec 18, 2024
5 of 6 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/ubsan-add-runtime-test-for-fsanitizelocal-bounds branch December 18, 2024 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants