Skip to content
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

[interop] Template instantiation crash when instantiating std::map.count from Swift #61365

Open
hyp opened this issue Sep 29, 2022 · 3 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++

Comments

@hyp
Copy link
Contributor

hyp commented Sep 29, 2022

Describe the bug
The compiler crashes.

Steps To Reproduce
Test.h:

#include <map>

#define SWIFT_CXX_REF_IMMORTAL                                                                                         \
	__attribute__((swift_attr("import_as_ref")))                                                                         \
  __attribute__((swift_attr("retain:immortal")))                                                                       \
	__attribute__((swift_attr("release:immortal")))

struct SWIFT_CXX_REF_IMMORTAL CxxRecord {
    std::map<int, int> map_;
};

inline CxxRecord * _Nonnull getImmortalCxxRecord() { return new CxxRecord; }

cat module.modulemap

module Testi {
  header "test.h"
  requires cplusplus
}

cat test.swift

import Testi
import std

func test() {
    let value = getImmortalCxxRecord().map_
    value.count(2)
}

Expected behavior
This should not crash.

@hyp hyp added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ labels Sep 29, 2022
@hyp
Copy link
Contributor Author

hyp commented Sep 29, 2022

Crash here:

4  swift-frontend           0x0000000101e732b0 swift::ClangImporter::instantiateCXXFunctionTemplate(swift::ASTContext&, clang::FunctionTemplateDecl*, swift::SubstitutionMap) + 376
5  swift-frontend           0x0000000101e732b0 swift::ClangImporter::instantiateCXXFunctionTemplate(swift::ASTContext&, clang::FunctionTemplateDecl*, swift::SubstitutionMap) + 376
6  swift-frontend           0x0000000101e73728 swift::ClangImporter::getCXXFunctionTemplateSpecialization(swift::SubstitutionMap, swift::ValueDecl*) + 284
7  swift-frontend           0x000000010195e6c4 swift::constraints::Solution::resolveConcreteDeclRef(swift::ValueDecl*, swift::constraints::ConstraintLocator*) const + 284
8  swift-frontend           0x0000000101972fc8 (anonymous namespace)::ExprRewriter::buildMemberRef(swift::Expr*, swift::SourceLoc, swift::constraints::SelectedOverload, swift::DeclNameLoc, swift::constraints::ConstraintLocatorBuilder, swift::constraints::ConstraintLocatorBuilder, bool, swift::AccessSemantics) + 984
9  swift-frontend           0x000000010196eca4 swift::ASTVisitor<(anonymous namespace)::ExprRewriter, swift::Expr*, void, void, void, void, void>::visit(swift::Expr*) + 23620
10 swift-frontend           0x0000000101967074 (anonymous namespace)::ExprWalker::walkToExprPost(swift::Expr*) + 36
11 swift-frontend           0x0000000101fc90ac (anonymous namespace)::Traversal::doIt(swift::Expr*) + 160
12 swift-frontend           0x0000000101fc99c4 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Expr*) + 144
13 swift-frontend           0x0000000101fc9088 (anonymous namespace)::Traversal::doIt(swift::Expr*) + 124
14 swift-frontend           0x0000000101fc9000 swift::Expr::walk(swift::ASTWalker&) + 32

@zoecarver zoecarver self-assigned this Sep 29, 2022
@zoecarver
Copy link
Contributor

Work around:

value.count(CInt(2))

@zoecarver
Copy link
Contributor

The fix for this issue is: "dependent return types don't work, we should just disable them."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++
Projects
None yet
Development

No branches or pull requests

2 participants