]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/asan/TestCases/Linux/odr_c_test.c
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / asan / TestCases / Linux / odr_c_test.c
1 // Test that we can properly report an ODR violation
2 // between an instrumented global and a non-instrumented global.
3
4 // RUN: %clang_asan %s -fPIC -shared -o %dynamiclib1  -DFILE1
5 // RUN: %clang_asan %s -fPIC -shared -o %dynamiclib2  -DFILE2
6 // RUN: %clang_asan %s -fPIE %ld_flags_rpath_exe1 %ld_flags_rpath_exe2 -o %t
7 // RUN: not %run %t 2>&1 | FileCheck %s
8 //
9 // CHECK: The following global variable is not properly aligned.
10 // CHECK: ERROR: AddressSanitizer: odr-violation
11 #if defined(FILE1)
12 __attribute__((aligned(8))) int x;
13 __attribute__((aligned(1))) char y;
14 // The gold linker puts ZZZ at the start of bss (where it is aligned)
15 // unless we have a large alternative like Displace:
16 __attribute__((aligned(1))) char Displace[105];
17 __attribute__((aligned(1))) char ZZZ[100];
18 #elif defined(FILE2)
19 int ZZZ = 1;
20 #else
21 extern int ZZZ;
22 int main() {
23   return ZZZ;
24 }
25 #endif
26