Skip to content

Assertion failure when importing C++ struct defined within an overloaded operator #83942

@egorzhdan

Description

@egorzhdan

(This issue report talks about Windows, but the bug isn't Windows-specific)

Seeing this assertion when trying to import WinRT headers into Swift with C++ interop:

Assertion failed: Name.isIdentifier() && "Name is not a simple identifier", file C:\Sources\swift\llvm-project\clang\include\clang/AST/Decl.h, line 277
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: C:\\Builds.noindex\\swift\\swift\\bin\\swift-ide-test.exe -print-module -module-to-print=WinRT -source-filename=x -target aarch64-unknown-windows-msvc -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import -cxx-interoperability-mode=upcoming-swift -resource-dir C:\\Builds.noindex\\swift\\swift\\lib\\swift -swift-version 6 -Xcc -D_SILENCE_CLANG_COROUTINE_MESSAGE
1.	C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt\WinRT\base.h:8305:12: importing 'winrt::access_token'
2.	C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt\WinRT\base.h:8373:14: importing 'winrt::access_token::operator()'
3.	While importing a clang type AutoType 0x1b6af236e30 'guard' sugar imported
`-ElaboratedType 0x1b6af236e00 'guard' sugar imported
  `-RecordType 0x1b6af236de0 'guard' imported
    `-CXXRecord 0x1b6af236cb8 'guard'
4.	While importing a clang type ElaboratedType 0x1b6af236e00 'guard' sugar imported
`-RecordType 0x1b6af236de0 'guard' imported
  `-CXXRecord 0x1b6af236cb8 'guard'
5.	While importing a clang type RecordType 0x1b6af236de0 'guard' imported
`-CXXRecord 0x1b6af236cb8 'guard'
6.	C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\cppwinrt\WinRT\base.h:8375:20: importing 'guard'
Exception Code: 0x80000003
 #0 0x00007ff754e24798 HandleAbort C:\Sources\swift\llvm-project\llvm\lib\Support\Windows\Signals.inc:429:0
 #1 0x00007ffc20eb0ef8 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa0ef8)
 #2 0x00007ffc20eb2a50 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa2a50)
 #3 0x00007ffc20eb7668 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa7668)
 #4 0x00007ffc20eb5ac8 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa5ac8)
 #5 0x00007ffc20eb7be4 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa7be4)
 #6 0x00007ff741d14a78 clang::NamedDecl::getName(void) const C:\Sources\swift\llvm-project\clang\include\clang\AST\Decl.h:277:0
 #7 0x00007ff747aa1e24 swift::ClangImporter::Implementation::importDeclContextImpl(class clang::Decl const *, class clang::DeclContext const *) C:\Sources\swift\swift\lib\ClangImporter\ImportDecl.cpp:10433:0
 #8 0x00007ff747aa2250 swift::ClangImporter::Implementation::importDeclContextOf(class clang::Decl const *, class swift::EffectiveClangContext, bool) C:\Sources\swift\swift\lib\ClangImporter\ImportDecl.cpp:10591:0
 #9 0x00007ff747a34e18 `anonymous namespace'::SwiftDeclConverter::VisitRecordDecl C:\Sources\swift\swift\lib\ClangImporter\ImportDecl.cpp:2211:0
#10 0x00007ff747a144dc `anonymous namespace'::SwiftDeclConverter::VisitCXXRecordDecl C:\Sources\swift\swift\lib\ClangImporter\ImportDecl.cpp:3154:0
...

The problematic type looks like this:

struct access_token {
  auto operator()() const {
    struct guard {}; // <-- oops
    return guard();
  }
};

Metadata

Metadata

Assignees

Labels

c++ interopFeature: Interoperability with C++compilerThe Swift compiler itself

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions