Skip to content

[ClangImporter] Fix IUO ordering bug #70106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2024
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
14 changes: 14 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,20 @@ IsImplicitlyUnwrappedOptionalRequest::evaluate(Evaluator &evaluator,
}

case DeclKind::Var:
if (decl->hasClangNode()) {
// ClangImporter does not use this request to compute whether imported
// declarations are IUOs; instead, it explicitly sets the bit itself when
// it imports the declaration's type. For most declarations this is done
// greedily, but for VarDecls, it is deferred until `getInterfaceType()`
// is called for the first time. (See apple/swift#61026.)
//
// Force the interface type, then see if a result for this request is now
// cached.
// FIXME: This is a little gross.
(void)decl->getInterfaceType();
if (auto cachedResult = this->getCachedResult())
return *cachedResult;
}
TyR = cast<VarDecl>(decl)->getTypeReprOrParentPatternTypeRepr();
break;

Expand Down
1 change: 1 addition & 0 deletions test/api-digester/Inputs/ImportedIUO/imported_iuo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
void *ImportedIUOVar;
3 changes: 3 additions & 0 deletions test/api-digester/Inputs/ImportedIUO/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module ImportedIUO {
header "imported_iuo.h"
}
11 changes: 11 additions & 0 deletions test/api-digester/imported_iuo.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RUN: %empty-directory(%t)
RUN: %api-digester -dump-sdk -module ImportedIUO -o %t/digest.json -module-cache-path %t/module-cache %clang-importer-sdk-nosource -I %S/Inputs/ImportedIUO -avoid-location
RUN: %FileCheck --input-file %t/digest.json %s

CHECK: "name": "ImportedIUOVar",
CHECK-NEXT: "printedName": "ImportedIUOVar",
CHECK-NEXT: "children": [
CHECK-NEXT: {
CHECK-NEXT: "kind": "TypeNominal",
CHECK-NEXT: "name": "ImplicitlyUnwrappedOptional",
CHECK-NEXT: "printedName": "Swift.UnsafeMutableRawPointer!",