Skip to content

Conversation

@fmayer
Copy link
Contributor

@fmayer fmayer commented Feb 21, 2025

we want the stack safety analysis to be able to skip array accesses that
are already checked by array-bounds.

Created using spr 1.3.4
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Feb 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 21, 2025

@llvm/pr-subscribers-clang

Author: Florian Mayer (fmayer)

Changes

we want the stack safety analysis to be able to skip array accesses that
are already checked by array-bounds.


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

1 Files Affected:

  • (added) clang/test/CodeGen/hwasan-stack-safety-analysis-with-array-bounds.c (+26)
diff --git a/clang/test/CodeGen/hwasan-stack-safety-analysis-with-array-bounds.c b/clang/test/CodeGen/hwasan-stack-safety-analysis-with-array-bounds.c
new file mode 100644
index 0000000000000..cd12879fb410d
--- /dev/null
+++ b/clang/test/CodeGen/hwasan-stack-safety-analysis-with-array-bounds.c
@@ -0,0 +1,26 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang -fsanitize-trap=undefined -fsanitize=hwaddress,array-bounds -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=true -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefixes=CHECK,SAFETY
+// RUN: %clang -fsanitize-trap=undefined -fsanitize=hwaddress,array-bounds -target aarch64-linux-gnu -S -emit-llvm -mllvm -hwasan-use-stack-safety=false -mllvm -hwasan-generate-tags-with-calls -O2 %s -o - | FileCheck %s --check-prefixes=CHECK,NOSAFETY
+
+// Make sure that HWAsan does not re-check what has been validated by array-bounds
+
+void f(char*);
+
+int foo(unsigned int idx) {
+  char buf[10];
+  f(buf);
+  return buf[idx];
+  // CHECK-LABEL: {{.*}}foo
+  // NOSAFETY: call void @llvm.hwasan.check.memaccess.shortgranules
+  // SAFETY-NOT: call void @llvm.hwasan.check.memaccess.shortgranules
+}
+
+int bar(int idx) {
+  char buf[10];
+  f(buf);
+  return buf[idx];
+  // CHECK-LABEL: {{.*}}bar
+  // NOSAFETY: call void @llvm.hwasan.check.memaccess.shortgranules
+  // SAFETY-NOT: call void @llvm.hwasan.check.memaccess.shortgranules
+}

@fmayer fmayer added the skip-precommit-approval PR for CI feedback, not intended for review label Feb 21, 2025
@fmayer fmayer merged commit 210ecfd into main Feb 21, 2025
14 checks passed
@fmayer fmayer deleted the users/fmayer/spr/nfc-test-interaction-between-array-bounds-and-hwaddress branch February 21, 2025 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category skip-precommit-approval PR for CI feedback, not intended for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants