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