brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · fc07c46 Raw
108 lines · plain
1// RUN: rm -rf %t2// RUN: split-file %s %t3 4 5// Expect no crash6// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t/modcache -fmodule-map-file=%t/module.modulemap %t/source.m7 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 %s10 11 12//--- shared.h13// 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 16typedef enum MyEnum1 { MyVal_A } MyEnum1;17// CHECK:      |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> MyEnum118// CHECK-NEXT: | |-also in ModB19// 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' imported22// CHECK-NEXT: |   `-Enum 0x{{.*}} 'MyEnum1'23 24 25enum MyEnum2 { MyVal_B };26// CHECK:      |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> MyEnum227// CHECK-NEXT: | |-also in ModB28// CHECK-NEXT: | `-EnumConstantDecl 0x{{.*}} imported in ModA.ModAFile1 referenced MyVal_B 'int'29 30 31typedef enum { MyVal_C } MyEnum3;32// CHECK:      |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations>33// CHECK-NEXT: | |-also in ModB34// 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' imported37// CHECK-NEXT: |   `-Enum 0x{{.*}}38 39struct MyStruct {40  enum MyEnum5 { MyVal_D } Field;41};42 43// CHECK:      |-RecordDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> struct MyStruct definition44// CHECK-NEXT: | |-also in ModB45// CHECK-NEXT: | |-EnumDecl 0x{{.*}} imported in ModA.ModAFile1 <undeserialized declarations> MyEnum546// CHECK-NEXT: | | |-also in ModB47// 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.51enum { 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' imported59// CHECK-NEXT: |   `-Enum 0x{{.*}} 'MyEnum1'60 61// CHECK:      |-EnumDecl 0x{{.*}} prev 0x{{.*}} imported in ModB <undeserialized declarations>62// CHECK-NEXT: | |-also in ModB63// 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' imported66// 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.modulemap74module 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.86module ModB {87  header "ModBFile.h"88  export *89}90 91//--- ModAFile1.h92#include "shared.h"93 94//--- ModAFile2.h95// Including this file, triggers loading of the module ModA with nodes coming ModAFile1.h being hidden.96 97//--- ModBFile.h98// 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.m105#include "ModBFile.h"106 107int main() { return MyVal_A + MyVal_B + MyVal_C + MyVal_D + MyVal_E; }108