xref: /llvm-project/clang/test/Modules/extensions.c (revision 6623e1f10f9546cfe68268ca6724a6fc187b3c1d)
1*6623e1f1SDouglas Gregor // Test creation of modules that include extension blocks.
2*6623e1f1SDouglas Gregor // RUN: rm -rf %t
3*6623e1f1SDouglas Gregor // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash -ftest-module-file-extension=clang.testA:1:5:0:user_info_for_A -ftest-module-file-extension=clang.testB:2:3:0:user_info_for_B -fmodules-cache-path=%t -I %S/Inputs %s
4*6623e1f1SDouglas Gregor 
5*6623e1f1SDouglas Gregor // Make sure the extension blocks are actually there.
6*6623e1f1SDouglas Gregor // RUN: llvm-bcanalyzer %t/ExtensionTestA.pcm | FileCheck -check-prefix=CHECK-BCANALYZER %s
7*6623e1f1SDouglas Gregor // RUN: %clang_cc1 -module-file-info %t/ExtensionTestA.pcm | FileCheck -check-prefix=CHECK-INFO %s
8*6623e1f1SDouglas Gregor 
9*6623e1f1SDouglas Gregor // Make sure that the readers are able to check the metadata.
10*6623e1f1SDouglas Gregor // RUN: rm -rf %t
11*6623e1f1SDouglas Gregor // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -ftest-module-file-extension=clang.testA:1:5:0:user_info_for_A -ftest-module-file-extension=clang.testB:2:3:0:user_info_for_B -fmodules-cache-path=%t -I %S/Inputs %s
12*6623e1f1SDouglas Gregor // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -ftest-module-file-extension=clang.testA:1:3:0:user_info_for_A -ftest-module-file-extension=clang.testB:3:2:0:user_info_for_B -fmodules-cache-path=%t -I %S/Inputs %s -verify
13*6623e1f1SDouglas Gregor 
14*6623e1f1SDouglas Gregor // Make sure that extension blocks can be part of the module hash.
15*6623e1f1SDouglas Gregor // We test this in an obscure way, by making sure we don't get conflicts when
16*6623e1f1SDouglas Gregor // using different "versions" of the extensions. Above, the "-verify" test
17*6623e1f1SDouglas Gregor // checks that such conflicts produce errors.
18*6623e1f1SDouglas Gregor // RUN: rm -rf %t
19*6623e1f1SDouglas Gregor // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -ftest-module-file-extension=clang.testA:1:5:1:user_info_for_A -ftest-module-file-extension=clang.testB:2:3:1:user_info_for_B -fmodules-cache-path=%t -I %S/Inputs %s
20*6623e1f1SDouglas Gregor // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -ftest-module-file-extension=clang.testA:1:3:1:user_info_for_A -ftest-module-file-extension=clang.testB:3:2:1:user_info_for_B -fmodules-cache-path=%t -I %S/Inputs %s
21*6623e1f1SDouglas Gregor // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -ftest-module-file-extension=clang.testA:2:5:0:user_info_for_A -ftest-module-file-extension=clang.testB:7:3:0:user_info_for_B -fmodules-cache-path=%t -I %S/Inputs %s
22*6623e1f1SDouglas Gregor 
23*6623e1f1SDouglas Gregor // Make sure we can read the message back.
24*6623e1f1SDouglas Gregor // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash -ftest-module-file-extension=clang.testA:1:5:0:user_info_for_A -ftest-module-file-extension=clang.testB:2:3:0:user_info_for_B -fmodules-cache-path=%t -I %S/Inputs %s > %t.log 2>&1
25*6623e1f1SDouglas Gregor // RUN: FileCheck -check-prefix=CHECK-MESSAGE %s < %t.log
26*6623e1f1SDouglas Gregor 
27*6623e1f1SDouglas Gregor // Make sure we diagnose duplicate module file extensions.
28*6623e1f1SDouglas Gregor // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fdisable-module-hash -ftest-module-file-extension=clang.testA:1:5:0:user_info_for_A -ftest-module-file-extension=clang.testA:1:5:0:user_info_for_A -fmodules-cache-path=%t -I %S/Inputs %s > %t.log 2>&1
29*6623e1f1SDouglas Gregor // RUN: FileCheck -check-prefix=CHECK-DUPLICATE %s < %t.log
30*6623e1f1SDouglas Gregor 
31*6623e1f1SDouglas Gregor #include "ExtensionTestA.h"
32*6623e1f1SDouglas Gregor // expected-error@-1{{test module file extension 'clang.testA' has different version (1.5) than expected (1.3)}}
33*6623e1f1SDouglas Gregor // expected-error@-2{{test module file extension 'clang.testB' has different version (2.3) than expected (3.2)}}
34*6623e1f1SDouglas Gregor 
35*6623e1f1SDouglas Gregor // CHECK-BCANALYZER: {{Block ID.*EXTENSION_BLOCK}}
36*6623e1f1SDouglas Gregor // CHECK-BCANALYZER: {{100.00.*EXTENSION_METADATA}}
37*6623e1f1SDouglas Gregor 
38*6623e1f1SDouglas Gregor // CHECK-INFO: Module file extension 'clang.testA' 1.5: user_info_for_A
39*6623e1f1SDouglas Gregor // CHECK-INFO: Module file extension 'clang.testB' 2.3: user_info_for_B
40*6623e1f1SDouglas Gregor 
41*6623e1f1SDouglas Gregor // CHECK-MESSAGE: Read extension block message: Hello from clang.testA v1.5
42*6623e1f1SDouglas Gregor // CHECK-MESSAGE: Read extension block message: Hello from clang.testB v2.3
43*6623e1f1SDouglas Gregor 
44*6623e1f1SDouglas Gregor // CHECK-DUPLICATE: warning: duplicate module file extension block name 'clang.testA'
45