xref: /llvm-project/clang/test/Preprocessor/search-path-usage.m (revision 77924d60efa8b3a0278361fe77403a71576c9349)
1// RUN: rm -rf %t && mkdir %t
2
3// Check that search paths used by `#include` and `#include_next` are reported.
4//
5// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage   \
6// RUN:   -I%S/Inputs/search-path-usage/a          \
7// RUN:   -I%S/Inputs/search-path-usage/a_next     \
8// RUN:   -I%S/Inputs/search-path-usage/b          \
9// RUN:   -I%S/Inputs/search-path-usage/c          \
10// RUN:   -I%S/Inputs/search-path-usage/d          \
11// RUN:   -DINCLUDE -verify
12#ifdef INCLUDE
13#include "a.h" // \
14// expected-remark-re {{search path used: '{{.*}}/search-path-usage/a'}} \
15// expected-remark-re@#a-include-next {{search path used: '{{.*}}/search-path-usage/a_next'}}
16#include "d.h" // \
17// expected-remark-re {{search path used: '{{.*}}/search-path-usage/d'}}
18#endif
19
20// Check that framework search paths are reported.
21//
22// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage \
23// RUN:   -F%S/Inputs/search-path-usage/FwA      \
24// RUN:   -F%S/Inputs/search-path-usage/FwB      \
25// RUN:   -DFRAMEWORK -verify
26#ifdef FRAMEWORK
27#include "FrameworkA/FrameworkA.h" // \
28// expected-remark-re {{search path used: '{{.*}}/search-path-usage/FwA'}}
29#endif
30
31// Check that system search paths are reported.
32//
33// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage \
34// RUN:   -isystem %S/Inputs/search-path-usage/b \
35// RUN:   -isystem %S/Inputs/search-path-usage/d \
36// RUN:   -DSYSTEM -verify
37#ifdef SYSTEM
38#include "b.h" // \
39// expected-remark-re {{search path used: '{{.*}}/search-path-usage/b'}}
40#endif
41
42// Check that sysroot-based search paths are reported.
43//
44// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage \
45// RUN:   -isysroot %S/Inputs/search-path-usage  \
46// RUN:   -iwithsysroot /b                       \
47// RUN:   -iwithsysroot /d                       \
48// RUN:   -DSYSROOT -verify
49#ifdef SYSROOT
50#include "d.h" // \
51// expected-remark {{search path used: '/d'}}
52#endif
53
54// Check that search paths used by `__has_include()` are reported.
55//
56// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage \
57// RUN:   -I%S/Inputs/search-path-usage/b        \
58// RUN:   -I%S/Inputs/search-path-usage/d        \
59// RUN:   -DHAS_INCLUDE -verify
60#ifdef HAS_INCLUDE
61#if __has_include("b.h") // \
62// expected-remark-re {{search path used: '{{.*}}/search-path-usage/b'}}
63#endif
64#if __has_include("x.h")
65#endif
66#endif
67
68// Check that search paths used by `#import` are reported.
69//
70// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage \
71// RUN:   -I%S/Inputs/search-path-usage/b        \
72// RUN:   -I%S/Inputs/search-path-usage/d        \
73// RUN:   -DIMPORT -verify
74#ifdef IMPORT
75#import "d.h" // \
76// expected-remark-re {{search path used: '{{.*}}/search-path-usage/d'}}
77#endif
78
79// Check that used header maps are reported when the target file exists.
80//
81// RUN: sed "s|DIR|%/S/Inputs/search-path-usage|g" \
82// RUN:             %S/Inputs/search-path-usage/b.hmap.json.template > %t/b.hmap.json
83// RUN: %hmaptool write %t/b.hmap.json %t/b.hmap
84// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage \
85// RUN:   -I %t/b.hmap                           \
86// RUN:   -I b                                   \
87// RUN:   -DHMAP -verify
88#ifdef HMAP
89#include "b.h" // \
90// expected-remark-re {{search path used: '{{.*}}/b.hmap'}}
91#endif
92
93// Check that unused header map are not reported.
94//
95// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage \
96// RUN:   -I%t/b.hmap                            \
97// RUN:   -I%S/Inputs/search-path-usage/d        \
98// RUN:   -DHMAP_NO_MATCH -verify
99#ifdef HMAP_NO_MATCH
100#include "d.h" // \
101// expected-remark-re {{search path used: '{{.*}}/search-path-usage/d'}}
102#endif
103
104// Check that used header map is reported even when the target file is missing.
105//
106// RUN: sed "s|DIR|%/S/Inputs/search-path-usage/missing-subdir|g" \
107// RUN:             %S/Inputs/search-path-usage/b.hmap.json.template > %t/b-missing.hmap.json
108// RUN: %hmaptool write %t/b-missing.hmap.json %t/b-missing.hmap
109// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage \
110// RUN:   -I %t/b-missing.hmap                   \
111// RUN:   -I b                                   \
112// RUN:   -DHMAP_MATCHED_BUT_MISSING -verify
113#ifdef HMAP_MATCHED_BUT_MISSING
114#include "b.h" // \
115// expected-remark-re {{search path used: '{{.*}}/b-missing.hmap'}} \
116// expected-error {{'b.h' file not found}}
117#endif
118
119// Check that used header map is reported even when the target file is missing
120// and the lookup is initiated by __has_include.
121//
122// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage \
123// RUN:   -I %t/b-missing.hmap                   \
124// RUN:   -I b                                   \
125// RUN:   -DHMAP_MATCHED_BUT_MISSING_IN_HAS_INCLUDE -verify
126#ifdef HMAP_MATCHED_BUT_MISSING_IN_HAS_INCLUDE
127#if __has_include("b.h") // \
128// expected-remark-re {{search path used: '{{.*}}/b-missing.hmap'}}
129#endif
130#endif
131
132// Check that search paths with module maps are NOT reported.
133//
134// RUN: mkdir %t/modulemap_abs
135// RUN: sed "s|DIR|%/S/Inputs/search-path-usage|g"                            \
136// RUN:   %S/Inputs/search-path-usage/modulemap_abs/module.modulemap.template \
137// RUN:     > %t/modulemap_abs/module.modulemap
138// RUN: %clang_cc1 -Eonly %s -Rsearch-path-usage                           \
139// RUN:   -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules \
140// RUN:   -I %t/modulemap_abs                                              \
141// RUN:   -I %S/Inputs/search-path-usage/a                                 \
142// RUN:   -DMODMAP_ABS -verify
143#ifdef MODMAP_ABS
144@import b; // \
145// expected-no-diagnostics
146#endif
147