Debian Codegraph @

clang/test/Modules/modules-merge-enum.m

raw
1 // RUN: rm -rf %t
2 // RUN: split-file %s %t
3
4
5 // Expect no crash
6 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/modcache -fmodule-map-file=%t/module.modulemap %t/source.m
7
8 // Add -ast-dump-all to check that the AST nodes are merged correctly.
9 // RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/modcache -fmodule-map-file=%t/module.modulemap %t/source.m -ast-dump-all 2>&1 | FileCheck %s
10
11
12 //--- shared.h
13 // This header is shared between two modules, but it's not a module itself.
14 // The enums defined here are parsed in both modules, and merged while building ModB.
15
16 typedef enum MyEnum1 { MyVal_A } MyEnum1;
17 // CHECK: |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> MyEnum1
18 // CHECK-NEXT: | |-also in ModB
19 // CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 referenced MyVal_A 'int'
20 // CHECK-NEXT: |-TypedefDecl 0x{{.*}} imported in ModA.ModAFile1 hidden MyEnum1 'enum MyEnum1'
21 // CHECK-NEXT: | `-EnumType 0x{{.*}} 'enum MyEnum1' imported
22 // CHECK-NEXT: | `-Enum 0x{{.*}} 'MyEnum1'
23
24
25 enum MyEnum2 { MyVal_B };
26 // CHECK: |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> MyEnum2
27 // CHECK-NEXT: | |-also in ModB
28 // CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 referenced MyVal_B 'int'
29
30
31 typedef enum { MyVal_C } MyEnum3;
32 // CHECK: |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations>
33 // CHECK-NEXT: | |-also in ModB
34 // CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 referenced MyVal_C 'int'
35 // CHECK-NEXT: |-TypedefDecl 0x{{.*}} imported in ModA.ModAFile1 hidden MyEnum3 'enum MyEnum3'
36 // CHECK-NEXT: | `-EnumType 0x{{.*}} 'enum MyEnum3' imported
37 // CHECK-NEXT: | `-Enum 0x{{.*}}
38
39 struct MyStruct {
40 enum MyEnum5 { MyVal_D } Field;
41 };
42
43 // CHECK: |-RecordDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> struct MyStruct definition
44 // CHECK-NEXT: | |-also in ModB
45 // CHECK-NEXT: | |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> MyEnum5
46 // CHECK-NEXT: | | |-also in ModB
47 // CHECK-NEXT: | | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 referenced MyVal_D 'int'
48 // CHECK-NEXT: | `-FieldDecl 0x{{.*}} imported in ModA.ModAFile1 hidden Field 'enum MyEnum5'
49
50 // In this case, no merging happens on the EnumDecl in Objective-C, and ASTWriter writes both EnumConstantDecls when building ModB.
51 enum { MyVal_E };
52 // CHECK: |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 hidden <undeserialized declarations>
53 // CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 hidden MyVal_E 'int'
54
55
56 // Redeclarations coming from ModB.
57 // CHECK: |-TypedefDecl 0x{{.*}} prev 0x{{.*}} imported in ModB MyEnum1 'enum MyEnum1'
58 // CHECK-NEXT: | `-EnumType 0x{{.*}} 'enum MyEnum1' imported
59 // CHECK-NEXT: | `-Enum 0x{{.*}} 'MyEnum1'
60
61 // CHECK: |-EnumDecl 0x{{.*}} prev 0x{{.*}} imported in ModB <undeserialized declarations>
62 // CHECK-NEXT: | |-also in ModB
63 // CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModB MyVal_C 'int'
64 // CHECK-NEXT: |-TypedefDecl 0x{{.*}} prev 0x{{.*}} imported in ModB MyEnum3 'enum MyEnum3'
65 // CHECK-NEXT: | `-EnumType 0x{{.*}} 'enum MyEnum3' imported
66 // CHECK-NEXT: | `-Enum 0x{{.*}}
67
68 // CHECK: |-EnumDecl 0x{{.*}} imported in ModB <undeserialized declarations>
69 // CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} first 0x{{.*}} imported in ModB referenced MyVal_E 'int'
70
71
72
73 //--- module.modulemap
74 module ModA {
75 module ModAFile1 {
76 header "ModAFile1.h"
77 export *
78 }
79 module ModAFile2 {
80 header "ModAFile2.h"
81 export *
82 }
83 }
84 // The goal of writing ModB is to test that ASTWriter can handle the merged AST nodes correctly.
85 // For example, a stale declaration in IdResolver can cause an assertion failure while writing the identifier table.
86 module ModB {
87 header "ModBFile.h"
88 export *
89 }
90
91 //--- ModAFile1.h
92 #include "shared.h"
93
94 //--- ModAFile2.h
95 // Including this file, triggers loading of the module ModA with nodes coming ModAFile1.h being hidden.
96
97 //--- ModBFile.h
98 // ModBFile depends on ModAFile2.h only.
99 #include "ModAFile2.h"
100 // Including shared.h here causes Sema to merge the AST nodes from shared.h with the hidden ones from ModA.
101 #include "shared.h"
102
103
104 //--- source.m
105 #include "ModBFile.h"
106
107 int main() { return MyVal_A + MyVal_B + MyVal_C + MyVal_D + MyVal_E; }