Debian Codegraph @

gcc/testsuite/c-c++-common/hwasan/hwasan-thread-basic-failure.c

raw
1 /* { dg-do run } */
2 /* { dg-require-effective-target hwaddress_exec } */
3 /* { dg-shouldfail "hwasan" } */
4 /* { dg-additional-options "-lpthread" } */
5
6 /* Ensure the failure mode for hwasan under pthreads looks sane.
7 (Looks sane means that the same error message is printed out rather than an
8 opaque message due to mishandling). */
9
10 #include <pthread.h>
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 extern int printf (char const *, ...);
16 #ifdef __cplusplus
17 }
18 #endif
19 typedef __UINTPTR_TYPE__ uintptr_t;
20 typedef __UINT64_TYPE__ uint64_t;
21
22 void *
23 failing_from_stack (void * argument)
24 {
25 int internal_array[16] = {0};
26 printf ("(now should fail):");
27 printf (" problem number is %d\n", internal_array[17]);
28 return (void *)1;
29 }
30
31 int
32 main (int argc, char **argv)
33 {
34 int argument[100] = {0};
35 argument[1] = 10;
36 pthread_t thread_index;
37 pthread_create (&thread_index, NULL, failing_from_stack, (void*)argument);
38
39 void *retval;
40 pthread_join (thread_index, &retval);
41
42 return (uintptr_t)retval;
43 }
44
45 /* { dg-output "HWAddressSanitizer: tag-mismatch on address 0x\[0-9a-f\]*.*" } */
46 /* { dg-output "READ of size 4 at 0x\[0-9a-f\]* tags: \[\[:xdigit:\]\]\[\[:xdigit:\]\]/00 \\(ptr/mem\\) in thread T1.*" } */
47 /* { dg-output "Address 0x\[0-9a-f\]* is located in stack of thread T1.*" } */
48 /* { dg-output "SUMMARY: HWAddressSanitizer: tag-mismatch \[^\n\]*.*" } */