diff --git a/lib/ClangImporter/SwiftLookupTable.cpp b/lib/ClangImporter/SwiftLookupTable.cpp index 235e9531d7af0..6f1b0546fde0c 100644 --- a/lib/ClangImporter/SwiftLookupTable.cpp +++ b/lib/ClangImporter/SwiftLookupTable.cpp @@ -2180,6 +2180,17 @@ void SwiftLookupTableWriter::populateTableWithDecl(SwiftLookupTable &table, if (decl->isFromASTFile()) return; + // Exclude a predefined declaration that's not a definition if its + // definition exists in the same module so that the definition will + // be associated with the base name, noting predefined declarations + // won't be serialized into the pcm and its state including its + // definition pointer won't be reconstructed after deserialization, + // which would cause a type not found error. + if (Writer.isDeclPredefined(decl)) + if (auto tagDecl = dyn_cast(decl)) + if (!tagDecl->isThisDeclarationADefinition() && tagDecl->getDefinition()) + return; + // Iterate into extern "C" {} type declarations. if (auto linkageDecl = dyn_cast(decl)) { for (auto *decl : linkageDecl->noload_decls()) { diff --git a/test/Serialization/guid-defined-in-module.swift b/test/Serialization/guid-defined-in-module.swift new file mode 100644 index 0000000000000..100fdebe0481f --- /dev/null +++ b/test/Serialization/guid-defined-in-module.swift @@ -0,0 +1,32 @@ +// REQUIRES: OS=windows-msvc + +// Test that a struct named _GUID is found and usable in C++ when it is +// defined, not just forward declared, within the same Clang module where +// _GUID is specially-handled as a predefined (forward) declaration on +// Windows. + +// RUN: %empty-directory(%t) +// RUN: split-file %s %t +// RUN: %target-swift-frontend -c -primary-file %t/Test.swift -cxx-interoperability-mode=default -I %t -Xcc -fmodule-map-file=%t/module.modulemap -Xcc -I -Xcc %t -module-name Test -o %t/Test.swift.o -module-cache-path %t/module-cache + +//--- Test.swift +import TestMod + +extension TestMod._GUID { + public func m() -> Int { 42 } +} + +//--- test.h +#ifndef TEST_H +#define TEST_H + +typedef struct _GUID { + int Data; +} GUID; + +#endif // TEST_H + +//--- module.modulemap +module TestMod { + header "test.h" +} diff --git a/test/Serialization/wrapped-modularization-error-remarks.swift b/test/Serialization/wrapped-modularization-error-remarks.swift index b2d4000d0b544..9fde9a224aff1 100644 --- a/test/Serialization/wrapped-modularization-error-remarks.swift +++ b/test/Serialization/wrapped-modularization-error-remarks.swift @@ -1,10 +1,4 @@ // RUN: %empty-directory(%t) // RUN: %target-swift-frontend -emit-module %S/Inputs/wrapped-modularization-error-remarks/A/A.swift -cxx-interoperability-mode=default -Xcc -fmodule-map-file=%S/Inputs/wrapped-modularization-error-remarks/CxxLib/include/module.modulemap -Xcc -I -Xcc %S/Inputs/wrapped-modularization-error-remarks/CxxLib/include -module-name A -o %t/A.swiftmodule -// RUN: not %target-swift-frontend -c -primary-file %S/Inputs/wrapped-modularization-error-remarks/B/B.swift -cxx-interoperability-mode=default -I %t -Xcc -fmodule-map-file=%S/Inputs/wrapped-modularization-error-remarks/CxxLib/include/module.modulemap -Xcc -I -Xcc %S/Inputs/wrapped-modularization-error-remarks/CxxLib/include -module-name B -o %t/B.swift.o -Rmodule-recovery 2>&1 | %FileCheck %s +// RUN: %target-swift-frontend -c -primary-file %S/Inputs/wrapped-modularization-error-remarks/B/B.swift -cxx-interoperability-mode=default -I %t -Xcc -fmodule-map-file=%S/Inputs/wrapped-modularization-error-remarks/CxxLib/include/module.modulemap -Xcc -I -Xcc %S/Inputs/wrapped-modularization-error-remarks/CxxLib/include -module-name B -o %t/B.swift.o -Rmodule-recovery // REQUIRES: OS=windows-msvc - -// Check that the diagnostics/remark from the wrapped ModularizationError is emitted. -// CHECK: remark: reference to type '_GUID' broken by a context change; '_GUID' is not found, it was expected to be in 'CxxLib' -// CHECK: note: could not deserialize type for 'queryInterface' -// CHECK: error: cannot inherit from class 'Window' because it has overridable members that could not be loaded -// CHECK: note: could not deserialize 'queryInterface'