|
| 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: | `-ElaboratedType 0x{{.*}} 'enum MyEnum1' sugar imported |
| 22 | +// CHECK-NEXT: | `-EnumType 0x{{.*}} 'enum MyEnum1' imported |
| 23 | +// CHECK-NEXT: | `-Enum 0x{{.*}} 'MyEnum1' |
| 24 | + |
| 25 | + |
| 26 | +enum MyEnum2 { MyVal_B }; |
| 27 | +// CHECK: |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> MyEnum2 |
| 28 | +// CHECK-NEXT: | |-also in ModB |
| 29 | +// CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 referenced MyVal_B 'int' |
| 30 | + |
| 31 | + |
| 32 | +typedef enum { MyVal_C } MyEnum3; |
| 33 | +// CHECK: |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> |
| 34 | +// CHECK-NEXT: | |-also in ModB |
| 35 | +// CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 referenced MyVal_C 'int' |
| 36 | +// CHECK-NEXT: |-TypedefDecl 0x{{.*}} imported in ModA.ModAFile1 hidden MyEnum3 'enum MyEnum3':'MyEnum3' |
| 37 | +// CHECK-NEXT: | `-ElaboratedType 0x{{.*}} 'enum MyEnum3' sugar imported |
| 38 | +// CHECK-NEXT: | `-EnumType 0x{{.*}} 'MyEnum3' imported |
| 39 | +// CHECK-NEXT: | `-Enum 0x{{.*}} |
| 40 | + |
| 41 | +struct MyStruct { |
| 42 | + enum MyEnum5 { MyVal_D } Field; |
| 43 | +}; |
| 44 | + |
| 45 | +// CHECK: |-RecordDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> struct MyStruct definition |
| 46 | +// CHECK-NEXT: | |-also in ModB |
| 47 | +// CHECK-NEXT: | |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> MyEnum5 |
| 48 | +// CHECK-NEXT: | | |-also in ModB |
| 49 | +// CHECK-NEXT: | | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 referenced MyVal_D 'int' |
| 50 | +// CHECK-NEXT: | `-FieldDecl 0x{{.*}} imported in ModA.ModAFile1 hidden Field 'enum MyEnum5' |
| 51 | + |
| 52 | +// In this case, no merging happens on the EnumDecl in Objective-C, and ASTWriter writes both EnumConstantDecls when building ModB. |
| 53 | +enum { MyVal_E }; |
| 54 | +// CHECK: |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 hidden <undeserialized declarations> |
| 55 | +// CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 hidden MyVal_E 'int' |
| 56 | + |
| 57 | + |
| 58 | +// Redeclarations coming from ModB. |
| 59 | +// CHECK: |-TypedefDecl 0x{{.*}} prev 0x{{.*}} imported in ModB MyEnum1 'enum MyEnum1' |
| 60 | +// CHECK-NEXT: | `-ElaboratedType 0x{{.*}} 'enum MyEnum1' sugar imported |
| 61 | +// CHECK-NEXT: | `-EnumType 0x{{.*}} 'enum MyEnum1' imported |
| 62 | +// CHECK-NEXT: | `-Enum 0x{{.*}} 'MyEnum1' |
| 63 | + |
| 64 | +// CHECK: |-EnumDecl 0x{{.*}} prev 0x{{.*}} imported in ModB <undeserialized declarations> |
| 65 | +// CHECK-NEXT: | |-also in ModB |
| 66 | +// CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModB MyVal_C 'int' |
| 67 | +// CHECK-NEXT: |-TypedefDecl 0x{{.*}} prev 0x{{.*}} imported in ModB MyEnum3 'enum MyEnum3':'MyEnum3' |
| 68 | +// CHECK-NEXT: | `-ElaboratedType 0x{{.*}} 'enum MyEnum3' sugar imported |
| 69 | +// CHECK-NEXT: | `-EnumType 0x{{.*}} 'MyEnum3' imported |
| 70 | +// CHECK-NEXT: | `-Enum 0x{{.*}} |
| 71 | + |
| 72 | +// CHECK: |-EnumDecl 0x{{.*}} imported in ModB <undeserialized declarations> |
| 73 | +// CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} first 0x{{.*}} imported in ModB referenced MyVal_E 'int' |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +//--- module.modulemap |
| 78 | +module ModA { |
| 79 | + module ModAFile1 { |
| 80 | + header "ModAFile1.h" |
| 81 | + export * |
| 82 | + } |
| 83 | + module ModAFile2 { |
| 84 | + header "ModAFile2.h" |
| 85 | + export * |
| 86 | + } |
| 87 | +} |
| 88 | +// The goal of writing ModB is to test that ASTWriter can handle the merged AST nodes correctly. |
| 89 | +// For example, a stale declaration in IdResolver can cause an assertion failure while writing the identifier table. |
| 90 | +module ModB { |
| 91 | + header "ModBFile.h" |
| 92 | + export * |
| 93 | +} |
| 94 | + |
| 95 | +//--- ModAFile1.h |
| 96 | +#include "shared.h" |
| 97 | + |
| 98 | +//--- ModAFile2.h |
| 99 | +// Including this file, triggers loading of the module ModA with nodes coming ModAFile1.h being hidden. |
| 100 | + |
| 101 | +//--- ModBFile.h |
| 102 | +// ModBFile depends on ModAFile2.h only. |
| 103 | +#include "ModAFile2.h" |
| 104 | +// Including shared.h here causes Sema to merge the AST nodes from shared.h with the hidden ones from ModA. |
| 105 | +#include "shared.h" |
| 106 | + |
| 107 | + |
| 108 | +//--- source.m |
| 109 | +#include "ModBFile.h" |
| 110 | + |
| 111 | +int main() { return MyVal_A + MyVal_B + MyVal_C + MyVal_D + MyVal_E; } |
0 commit comments