Skip to content

Compiler crash during C++ interop (possibly related to anonymous C++ structs) #82361

Open
@libewa

Description

@libewa

Description

While compiling my ESP32 project, the Swift compiler crashes after giving out warnings related to an anonymous struct in the TFT_eSPI library.

Reproduction

// Main.swift
var tft = TFT_eSPI(Int16(TFT_WIDTH), Int16(TFT_HEIGHT))
func setup() {
    tft.begin()
}
@_cdecl("app_main")
func main() {
    setup()
}
#include "Arduino.h"
#include "TFT_eSPI.h"

(compile with ESP-IDF for ESP32-C3 and the arduino-esp32 and TFT_eSPI components)
I based my project on the ESP32-C3 Blink SDK example.

Stack dump

0  swift-frontend           0x0000000107134ab0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107133194 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010713510c SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000019a084624 _sigtramp + 56
4  swift-frontend           0x00000001024207b0 swift::constraints::MissingMemberFailure::diagnoseUnsafeCxxMethod(swift::SourceLoc, swift::ASTNode, swift::Type, swift::DeclName) const + 1088
5  swift-frontend           0x00000001024246d4 swift::constraints::MissingMemberFailure::diagnoseAsError()::$_22::operator()(swift::Type) const + 716
6  swift-frontend           0x0000000102423850 swift::constraints::MissingMemberFailure::diagnoseAsError() + 2532
7  swift-frontend           0x00000001023f9d60 swift::constraints::DefineMemberBasedOnUse::diagnose(swift::constraints::Solution const&, bool) const + 124
8  swift-frontend           0x000000010232f8c4 swift::constraints::ConstraintSystem::applySolutionFixes(swift::constraints::Solution const&) + 1284
9  swift-frontend           0x000000010232ff58 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SyntacticElementTarget) + 100
10 swift-frontend           0x000000010258033c swift::TypeChecker::typeCheckTarget(swift::constraints::SyntacticElementTarget&, swift::optionset::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::DiagnosticTransaction*) + 384
11 swift-frontend           0x0000000102580160 swift::TypeChecker::typeCheckExpression(swift::constraints::SyntacticElementTarget&, swift::optionset::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::DiagnosticTransaction*) + 196
12 swift-frontend           0x0000000102580028 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::constraints::ContextualTypeInfo, swift::optionset::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 96
13 swift-frontend           0x000000010265a53c (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 264
14 swift-frontend           0x000000010265dc5c swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 152
15 swift-frontend           0x000000010265c100 bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
16 swift-frontend           0x000000010265ba2c (anonymous namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 48
17 swift-frontend           0x000000010265b740 swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 1136
18 swift-frontend           0x0000000102a5c5c0 swift::TypeCheckFunctionBodyRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()>(swift::TypeCheckFunctionBodyRequest const&, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()) + 240
19 swift-frontend           0x00000001029c3590 swift::AbstractFunctionDecl::getTypecheckedBody() const + 120
20 swift-frontend           0x0000000102b11c4c swift::SourceFile::typeCheckDelayedFunctions() + 104
21 swift-frontend           0x00000001026a719c swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 244
22 swift-frontend           0x00000001026a8abc swift::TypeCheckSourceFileRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()>(swift::TypeCheckSourceFileRequest const&, swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType)::'lambda'()) + 232
23 swift-frontend           0x00000001026a7080 swift::performTypeChecking(swift::SourceFile&) + 84
24 swift-frontend           0x00000001014ba5a8 bool llvm::function_ref<bool (swift::SourceFile&)>::callback_fn<swift::CompilerInstance::performSema()::$_8>(long, swift::SourceFile&) + 16
25 swift-frontend           0x00000001014b1f30 swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<bool (swift::SourceFile&)>) + 164
26 swift-frontend           0x00000001014b1e6c swift::CompilerInstance::performSema() + 76
27 swift-frontend           0x000000010126e24c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 60
28 swift-frontend           0x0000000101263fb8 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 716
29 swift-frontend           0x00000001012637d4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2216
30 swift-frontend           0x000000010101758c swift::mainEntry(int, char const**) + 3100
31 dyld                     0x0000000199caab98 start + 6076

Expected behavior

The code should compile and later link to the C and C++ code from the libraries.

Environment

Apple Swift version 6.2-dev (LLVM fdbc1301770d574, Swift 413dcfb)
Target: arm64-apple-macosx15.0

Additional information

My Project: https://github.com/libewa/swiftflag
The pull request for the library I use (otherwise I get misleading indentation warnings inside the library, which are treated as errors): Bodmer/TFT_eSPI#3741
The compiler log: https://gist.github.com/libewa/a508ea516676e338c972adc9dd130e15/023d559e0bdd6579365a8314ffe4b671fdc9dd83#file-idf_py_stdout_output_6415-L1828

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions