1 // RUN: rm -rf %t
2 // RUN: mkdir %t
3 // RUN: echo 'module tmp { header "tmp.h" }' > %t/map
4 // RUN: touch %t/tmp.h
5 // RUN: %clang_cc1 -fmodules -DFOO=1 -x c++ -fmodule-name=tmp %t/map -emit-module -o %t/tmp.pcm
6 
7 // Can use the module.
8 // RUN: %clang_cc1 -fmodules -DFOO=1 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
9 
10 // Can use the module if an input file is newer. (This happens on
11 // remote file systems.)
12 // RUN: sleep 1
13 // RUN: touch %t/tmp.h
14 // RUN: %clang_cc1 -fmodules -DFOO=1 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
15 
16 // Can use the module if -D flags change.
17 // RUN: %clang_cc1 -fmodules -DFOO=2 -DBAR=1 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
18 // RUN: %clang_cc1 -fmodules -DBAR=2 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
19 
20 // Can use the module if -W flags change.
21 // RUN: %clang_cc1 -fmodules -DBAR=2 -Wextra -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
22 
23 // Can use the module if -I flags change.
24 // RUN: %clang_cc1 -fmodules -DBAR=2 -I. -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
25 
26 // Can use the module if -O flags change.
27 // RUN: %clang_cc1 -fmodules -DBAR=2 -Os -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp.pcm -verify -I%t %s
28 //
29 // RUN: %clang_cc1 -fmodules -DFOO=1 -O2 -x c++ -fmodule-name=tmp %t/map -emit-module -o %t/tmp-O2.pcm
30 // RUN: %clang_cc1 -fmodules -DBAR=2 -O0 -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp-O2.pcm -verify -I%t %s
31 // RUN: %clang_cc1 -fmodules -DBAR=2 -Os -x c++ -fmodule-map-file=%t/map -fmodule-file=%t/tmp-O2.pcm -verify -I%t %s
32 
33 #include "tmp.h" // expected-no-diagnostics
34 
35 #ifndef BAR
36 #if FOO != 1
37 #error bad FOO from command line and module
38 #endif
39 #elif BAR == 1
40 #if FOO != 2
41 #error bad FOO from command line overriding module
42 #endif
43 #elif BAR == 2
44 #ifdef FOO
45 #error FOO leaked from module
46 #endif
47 #else
48 #error bad BAR
49 #endif
50