Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<clang::TagDecl>(decl))
if (!tagDecl->isThisDeclarationADefinition() && tagDecl->getDefinition())
return;

// Iterate into extern "C" {} type declarations.
if (auto linkageDecl = dyn_cast<clang::LinkageSpecDecl>(decl)) {
for (auto *decl : linkageDecl->noload_decls()) {
Expand Down
32 changes: 32 additions & 0 deletions test/Serialization/guid-defined-in-module.swift
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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'