xref: /aosp_15_r20/external/clang/test/PCH/headersearch.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // Test reading of PCH with changed location of original input files,
2*67e74705SXin Li // i.e. invoking header search.
3*67e74705SXin Li 
4*67e74705SXin Li // Generate the original files:
5*67e74705SXin Li // RUN: rm -rf %t_orig %t_moved
6*67e74705SXin Li // RUN: mkdir -p %t_orig/sub %t_orig/sub2
7*67e74705SXin Li // RUN: echo 'struct orig_sub{char c; int i; };' > %t_orig/sub/orig_sub.h
8*67e74705SXin Li // RUN: echo 'void orig_sub2_1();' > %t_orig/sub2/orig_sub2_1.h
9*67e74705SXin Li // RUN: echo '#include "orig_sub2_1.h"' > %t_orig/sub2/orig_sub2.h
10*67e74705SXin Li // RUN: echo 'template <typename T> void tf() { orig_sub2_1(); T::foo(); }' >> %t_orig/sub2/orig_sub2.h
11*67e74705SXin Li // RUN: echo 'void foo() {}' > %t_orig/tmp2.h
12*67e74705SXin Li // RUN: echo '#include "tmp2.h"' > %t_orig/all.h
13*67e74705SXin Li // RUN: echo '#include "sub/orig_sub.h"' >> %t_orig/all.h
14*67e74705SXin Li // RUN: echo '#include "orig_sub2.h"' >> %t_orig/all.h
15*67e74705SXin Li // RUN: echo 'int all();' >> %t_orig/all.h
16*67e74705SXin Li 
17*67e74705SXin Li // This test relies on -Wpadded, which is only implemented for Itanium record
18*67e74705SXin Li // layout.
19*67e74705SXin Li 
20*67e74705SXin Li // Generate the PCH:
21*67e74705SXin Li // RUN: cd %t_orig && %clang_cc1 -triple %itanium_abi_triple -x c++ -emit-pch -o all.h.pch -Isub2 all.h
22*67e74705SXin Li // RUN: cp -R %t_orig %t_moved
23*67e74705SXin Li 
24*67e74705SXin Li // Check diagnostic with location in original source:
25*67e74705SXin Li // RUN: %clang_cc1 -triple %itanium_abi_triple -include-pch all.h.pch -I%t_moved -I%t_moved/sub2 -Wpadded -emit-llvm-only %s 2> %t.stderr
26*67e74705SXin Li // RUN: grep 'struct orig_sub' %t.stderr
27*67e74705SXin Li 
28*67e74705SXin Li // Check diagnostic with 2nd location in original source:
29*67e74705SXin Li // RUN: not %clang_cc1 -triple %itanium_abi_triple -DREDECL -include-pch all.h.pch -I%t_moved -I%t_moved/sub2 -emit-llvm-only %s 2> %t.stderr
30*67e74705SXin Li // RUN: grep 'void foo' %t.stderr
31*67e74705SXin Li 
32*67e74705SXin Li // Check diagnostic with instantiation location in original source:
33*67e74705SXin Li // RUN: not %clang_cc1 -triple %itanium_abi_triple -DINSTANTIATION -include-pch all.h.pch -I%t_moved -I%t_moved/sub2 -emit-llvm-only %s 2> %t.stderr
34*67e74705SXin Li // RUN: grep 'orig_sub2_1' %t.stderr
35*67e74705SXin Li 
qq(orig_sub *)36*67e74705SXin Li void qq(orig_sub*) {all();}
37*67e74705SXin Li 
38*67e74705SXin Li #ifdef REDECL
foo()39*67e74705SXin Li float foo() {return 0;}
40*67e74705SXin Li #endif
41*67e74705SXin Li 
42*67e74705SXin Li #ifdef INSTANTIATION
f()43*67e74705SXin Li void f() {
44*67e74705SXin Li   tf<int>();
45*67e74705SXin Li }
46*67e74705SXin Li #endif
47