|
| 1 | +// RUN: rm -rf %t |
| 2 | +// RUN: split-file %s %t |
| 3 | +// RUN: %clang_cc1 -fsyntax-only -I %t/include %t/test.c \ |
| 4 | +// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache |
| 5 | + |
| 6 | +// Test when a decl is present in multiple modules through an inclusion of |
| 7 | +// a non-modular header. Make sure such decl is serialized correctly and can be |
| 8 | +// used after deserialization. |
| 9 | + |
| 10 | +//--- include/non-modular.h |
| 11 | +#ifndef NON_MODULAR_H |
| 12 | +#define NON_MODULAR_H |
| 13 | + |
| 14 | +union TestUnion { |
| 15 | + int x; |
| 16 | + float y; |
| 17 | +}; |
| 18 | + |
| 19 | +struct ReferenceUnion1 { |
| 20 | + union TestUnion name; |
| 21 | + unsigned versionMajor; |
| 22 | +}; |
| 23 | +struct ReferenceUnion2 { |
| 24 | + union TestUnion name; |
| 25 | + unsigned versionMinor; |
| 26 | +}; |
| 27 | + |
| 28 | +// Test another kind of RecordDecl. |
| 29 | +struct TestStruct { |
| 30 | + int p; |
| 31 | + float q; |
| 32 | +}; |
| 33 | + |
| 34 | +struct ReferenceStruct1 { |
| 35 | + unsigned fieldA; |
| 36 | + struct TestStruct fieldB; |
| 37 | +}; |
| 38 | + |
| 39 | +struct ReferenceStruct2 { |
| 40 | + unsigned field1; |
| 41 | + struct TestStruct field2; |
| 42 | +}; |
| 43 | + |
| 44 | +#endif |
| 45 | + |
| 46 | +//--- include/piecewise1-empty.h |
| 47 | +//--- include/piecewise1-initially-hidden.h |
| 48 | +#include <non-modular.h> |
| 49 | + |
| 50 | +//--- include/piecewise2-empty.h |
| 51 | +//--- include/piecewise2-initially-hidden.h |
| 52 | +#include <non-modular.h> |
| 53 | + |
| 54 | +//--- include/with-multiple-decls.h |
| 55 | +#include <piecewise1-empty.h> |
| 56 | +// Include the non-modular header and resolve a name duplication between decl |
| 57 | +// in non-modular.h and in piecewise1-initially-hidden.h, create a |
| 58 | +// redeclaration chain. |
| 59 | +#include <non-modular.h> |
| 60 | +// Include a decl with a duplicate name again to add more to IdentifierResolver. |
| 61 | +#include <piecewise2-empty.h> |
| 62 | + |
| 63 | +//--- include/module.modulemap |
| 64 | +module Piecewise1 { |
| 65 | + module Empty { |
| 66 | + header "piecewise1-empty.h" |
| 67 | + } |
| 68 | + module InitiallyHidden { |
| 69 | + header "piecewise1-initially-hidden.h" |
| 70 | + export * |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +module Piecewise2 { |
| 75 | + module Empty { |
| 76 | + header "piecewise2-empty.h" |
| 77 | + } |
| 78 | + module InitiallyHidden { |
| 79 | + header "piecewise2-initially-hidden.h" |
| 80 | + export * |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +module WithMultipleDecls { |
| 85 | + header "with-multiple-decls.h" |
| 86 | + export * |
| 87 | +} |
| 88 | + |
| 89 | +//--- test.c |
| 90 | +#include <with-multiple-decls.h> |
| 91 | + |
| 92 | +struct Test { |
| 93 | + int x; |
| 94 | + union TestUnion name; |
| 95 | +}; |
| 96 | + |
| 97 | +struct Test2 { |
| 98 | + struct TestStruct name; |
| 99 | + float y; |
| 100 | +}; |
0 commit comments