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