| 1 | // RUN: %clang -x c -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:" |
| 2 | // RUN: %clang -x c -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:" |
| 3 | // RUN: %clang -x c -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:" |
| 4 | // RUN: %clang -x c -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:" |
| 5 | |
| 6 | // RUN: %clangxx -x c++ -fsanitize=alignment -O0 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:" |
| 7 | // RUN: %clangxx -x c++ -fsanitize=alignment -O1 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:" |
| 8 | // RUN: %clangxx -x c++ -fsanitize=alignment -O2 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:" |
| 9 | // RUN: %clangxx -x c++ -fsanitize=alignment -O3 %s -o %t && %run %t 2>&1 | FileCheck %s --implicit-check-not=" assumption " --implicit-check-not="note:" --implicit-check-not="runtime error:" |
| 10 | |
| 11 | #include <stdlib.h> |
| 12 | |
| 13 | typedef char *__attribute__((align_value(0x8000))) aligned_char; |
| 14 | |
| 15 | struct ac_struct { |
| 16 | aligned_char a; |
| 17 | }; |
| 18 | |
| 19 | char *load_from_ac_struct(struct ac_struct *x) { |
| 20 | return x->a; |
| 21 | } |
| 22 | |
| 23 | int main(int argc, char* argv[]) { |
| 24 | char *ptr = (char *)malloc(size: 2); |
| 25 | |
| 26 | struct ac_struct x; |
| 27 | x.a = ptr + 1; // FIXME: it is weird that this does not also have an assumption. |
| 28 | load_from_ac_struct(x: &x); |
| 29 | // CHECK: {{.*}}align-assume-{{.*}}.cpp:[[@LINE-9]]:13: runtime error: assumption of 32768 byte alignment for pointer of type 'aligned_char' (aka 'char *') failed |
| 30 | // CHECK: {{.*}}align-assume-{{.*}}.cpp:[[@LINE-17]]:30: note: alignment assumption was specified here |
| 31 | // CHECK: 0x{{.*}}: note: address is {{.*}} aligned, misalignment offset is {{.*}} byte |
| 32 | |
| 33 | free(ptr: ptr); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |