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
4 changes: 4 additions & 0 deletions include/swift/AST/DiagnosticsClangImporter.def
Original file line number Diff line number Diff line change
Expand Up @@ -377,5 +377,9 @@ NOTE(ptr_to_nonescapable,none,
"pointer to non-escapable type %0 cannot be imported",
(const clang::Type*))

NOTE(nonescapable_field_of_escapable, none,
"escapable record %0 cannot have non-escapable field '%1'",
(const clang::NamedDecl *, StringRef))

#define UNDEFINE_DIAGNOSTIC_MACROS
#include "DefineDiagnosticMacros.h"
18 changes: 17 additions & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,23 @@ namespace {
continue;
}

members.push_back(cast<VarDecl>(member));
auto *vd = cast<VarDecl>(member);
if (!isNonEscapable) {
if (const auto *fd = dyn_cast<clang::FieldDecl>(nd))
if (evaluateOrDefault(
Impl.SwiftContext.evaluator,
ClangTypeEscapability({fd->getType().getTypePtr(), &Impl}),
CxxEscapability::Unknown) ==
CxxEscapability::NonEscapable) {
Impl.addImportDiagnostic(
decl,
Diagnostic(diag::nonescapable_field_of_escapable, decl,
nd->getName()),
decl->getLocation());
return nullptr;
}
}
members.push_back(vd);
}

bool hasReferenceableFields = !members.empty();
Expand Down
11 changes: 10 additions & 1 deletion test/Interop/Cxx/class/nonescapable-errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,21 @@ const View* usedToCrash(const View* p) {
return p;
}

struct SWIFT_ESCAPABLE Invalid {
View v;
};

//--- test.swift
import Test
import CxxStdlib

// CHECK: error: cannot find type 'Invalid' in scope
// CHECK: note: escapable record 'Invalid' cannot have non-escapable field 'v'
public func importInvalid(_ x: Invalid) {
}

// CHECK: error: a function with a ~Escapable result needs a parameter to depend on
// CHECK-NO-LIFETIMES: test.swift:6:32: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
// CHECK-NO-LIFETIMES: test.swift:11:32: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
public func noAnnotations() -> View {
// CHECK: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies
// CHECK-NO-LIFETIMES: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies
Expand Down