[compiler-rt] [Sanitizer] Use % patterns in report paths (PR #141820)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Thu May 29 09:58:32 PDT 2025


================
@@ -1,27 +1,42 @@
 // Test __sanitizer_set_report_path and __sanitizer_get_report_path:
 // RUN: %clangxx -O2 %s -o %t
-// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: %env HOME=%t.homedir TMPDIR=%t.tmpdir %run %t 2>%t.err | FileCheck %s
+// RUN: FileCheck %s --input-file=%t.err --check-prefix=ERROR
 
-#include <assert.h>
 #include <sanitizer/common_interface_defs.h>
 #include <stdio.h>
 #include <string.h>
 
-volatile int *null = 0;
-
 int main(int argc, char **argv) {
-  char buff[1000];
+  char buff[4096];
   sprintf(buff, "%s.report_path/report", argv[0]);
   __sanitizer_set_report_path(buff);
-  assert(strncmp(buff, __sanitizer_get_report_path(), strlen(buff)) == 0);
+  // CHECK: {{.*}}.report_path/report.[[PID:[0-9]+]]
+  printf("%s\n", __sanitizer_get_report_path());
 
-  // Try setting again with an invalid/inaccessible directory.
-  char buff_bad[1000];
-  sprintf(buff_bad, "%s/report", argv[0]);
-  fprintf(stderr, "Expected bad report path: %s\n", buff_bad);
-  // CHECK: Expected bad report path: [[BADPATH:.*]]/report
-  __sanitizer_set_report_path(buff_bad);
-  assert(strncmp(buff, __sanitizer_get_report_path(), strlen(buff)) == 0);
-}
+  strcpy(buff, "%H/foo");
+  __sanitizer_set_report_path(buff);
+  // CHECK: [[T:.*]].homedir/foo.[[PID]]
+  printf("%s\n", __sanitizer_get_report_path());
 
-// CHECK: ERROR: Can't create directory: [[BADPATH]]
+  strcpy(buff, "%t/foo");
+  __sanitizer_set_report_path(buff);
+  // CHECK: [[T]].tmpdir/foo.[[PID]]
+  printf("%s\n", __sanitizer_get_report_path());
+
+  strcpy(buff, "%H/%p/%%foo");
+  __sanitizer_set_report_path(buff);
+  // CHECK: [[T]].homedir/[[PID]]/%foo.[[PID]]
+  printf("%s\n", __sanitizer_get_report_path());
+
+  strcpy(buff, "%%foo%%bar");
+  __sanitizer_set_report_path(buff);
+  // CHECK: %foo%bar.[[PID]]
+  printf("%s\n", __sanitizer_get_report_path());
+
+  strcpy(buff, "%%foo%ba%%r");
----------------
ellishg wrote:

If we can't parse a path, we fallback to the original path. I want to test that the other `%%` isn't parsed to `%`

https://github.com/llvm/llvm-project/pull/141820


More information about the llvm-commits mailing list