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

[SR-8317] crash when using C struct #50845

Closed
swift-ci opened this issue Jul 19, 2018 · 8 comments
Closed

[SR-8317] crash when using C struct #50845

swift-ci opened this issue Jul 19, 2018 · 8 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8317
Radar rdar://problem/42386542
Original Reporter sunlubo (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

OS: 10.13.5 (17F77)
Swift: Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: 94066004643974004a66e6039ec9f8f6

duplicates:

  • SR-2511 Compiler crash with incorrect checksum for freed object

Issue Description:

Use attachments can produce.

Stack Trace:

0 swift 0x0000000103ff4fea PrintStackTraceSignalHandler(void*) + 42
1 swift 0x0000000103ff43a6 SignalHandler(int) + 966
2 libsystem_platform.dylib 0x00007fff72d9df5a _sigtramp + 26
3 libsystem_platform.dylib 0x0000000000000070 _sigtramp + 2368086320
4 swift 0x00000001007cada8 swift::irgen::TypeConverter::convertStructType(swift::TypeBase*, swift::CanType, swift::StructDecl*) + 1752
5 swift 0x00000001007e8271 swift::irgen::TypeConverter::convertAnyNominalType(swift::CanType, swift::NominalTypeDecl*) + 465
6 swift 0x00000001007e7664 swift::irgen::TypeConverter::getTypeEntry(swift::CanType) + 1060
7 swift 0x00000001007ec0b5 addValueWitnessesForAbstractType(swift::irgen::IRGenModule&, swift::irgen::ConstantArrayBuilder&, swift::CanType, bool&) + 293
8 swift 0x00000001007ebc9a swift::irgen::emitValueWitnessTable(swift::irgen::IRGenModule&, swift::CanType) + 234
9 swift 0x0000000100784cab swift::irgen::IRGenModule::getAddrOfForeignTypeMetadataCandidate(swift::CanType) + 1771
10 swift 0x00000001007843a8 emitForeignTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType) + 24
11 swift 0x0000000100783f3f llvm::Value* llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>::callback_fn<getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t)::$_3>(long, swift::irgen::IRGenFunction&, llvm::Constant*) + 479
12 swift 0x0000000100780e85 swift::irgen::emitLazyCacheAccessFunction(swift::irgen::IRGenModule&, llvm::Function*, llvm::GlobalVariable*, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&)> const&) + 1989
13 swift 0x000000010078432a getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>&&) + 922
14 swift 0x0000000100783b75 emitCallToTypeMetadataAccessFunction(swift::irgen::IRGenFunction&, swift::CanType, swift::ForDefinition_t) + 117
15 swift 0x00000001007814f5 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 533
16 swift 0x000000010078c490 void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<(anonymous namespace)::GenericArguments::collect(swift::irgen::IRGenFunction&, swift::CanType)::'lambda'(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) + 80
17 swift 0x00000001007c14be swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap const&, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) + 366
18 swift 0x000000010078b56f emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) + 479
19 swift 0x000000010078161e emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType) + 238
20 swift 0x0000000100783f4c llvm::Value* llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>::callback_fn<getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t)::$_3>(long, swift::irgen::IRGenFunction&, llvm::Constant*) + 492
21 swift 0x0000000100780e85 swift::irgen::emitLazyCacheAccessFunction(swift::irgen::IRGenModule&, llvm::Function*, llvm::GlobalVariable*, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&)> const&) + 1989
22 swift 0x000000010078432a getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>&&) + 922
23 swift 0x0000000100783b75 emitCallToTypeMetadataAccessFunction(swift::irgen::IRGenFunction&, swift::CanType, swift::ForDefinition_t) + 117
24 swift 0x00000001007814f5 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 533
25 swift 0x000000010078c490 void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<(anonymous namespace)::GenericArguments::collect(swift::irgen::IRGenFunction&, swift::CanType)::'lambda'(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) + 80
26 swift 0x00000001007c14be swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap const&, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) + 366
27 swift 0x000000010078b56f emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) + 479
28 swift 0x000000010078161e emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType) + 238
29 swift 0x0000000100783f4c llvm::Value* llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>::callback_fn<getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t)::$_3>(long, swift::irgen::IRGenFunction&, llvm::Constant*) + 492
30 swift 0x0000000100780e85 swift::irgen::emitLazyCacheAccessFunction(swift::irgen::IRGenModule&, llvm::Function*, llvm::GlobalVariable*, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&)> const&) + 1989
31 swift 0x000000010078432a getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>&&) + 922
32 swift 0x0000000100783b75 emitCallToTypeMetadataAccessFunction(swift::irgen::IRGenFunction&, swift::CanType, swift::ForDefinition_t) + 117
33 swift 0x00000001007814f5 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 533
34 swift 0x000000010078c490 void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<(anonymous namespace)::GenericArguments::collect(swift::irgen::IRGenFunction&, swift::CanType)::'lambda'(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) + 80
35 swift 0x00000001007c14be swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap const&, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) + 366
36 swift 0x000000010078b56f emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) + 479
37 swift 0x000000010078161e emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType) + 238
38 swift 0x0000000100783f4c llvm::Value* llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>::callback_fn<getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t)::$_3>(long, swift::irgen::IRGenFunction&, llvm::Constant*) + 492
39 swift 0x0000000100780e85 swift::irgen::emitLazyCacheAccessFunction(swift::irgen::IRGenModule&, llvm::Function*, llvm::GlobalVariable*, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&)> const&) + 1989
40 swift 0x000000010078432a getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>&&) + 922
41 swift 0x0000000100783b75 emitCallToTypeMetadataAccessFunction(swift::irgen::IRGenFunction&, swift::CanType, swift::ForDefinition_t) + 117
42 swift 0x00000001007814f5 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 533
43 swift 0x000000010078c490 void llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>::callback_fn<(anonymous namespace)::GenericArguments::collect(swift::irgen::IRGenFunction&, swift::CanType)::'lambda'(unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>(long, unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>) + 80
44 swift 0x00000001007c14be swift::irgen::GenericTypeRequirements::enumerateFulfillments(swift::irgen::IRGenModule&, swift::SubstitutionMap const&, llvm::function_ref<void (unsigned int, swift::CanType, llvm::Optional<swift::ProtocolConformanceRef>)>) + 366
45 swift 0x000000010078b56f emitNominalMetadataRef(swift::irgen::IRGenFunction&, swift::NominalTypeDecl*, swift::CanType) + 479
46 swift 0x000000010078161e emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType) + 238
47 swift 0x0000000100783f4c llvm::Value* llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>::callback_fn<getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t)::$_3>(long, swift::irgen::IRGenFunction&, llvm::Constant*) + 492
48 swift 0x0000000100780e85 swift::irgen::emitLazyCacheAccessFunction(swift::irgen::IRGenModule&, llvm::Function*, llvm::GlobalVariable*, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&)> const&) + 1989
49 swift 0x000000010078432a getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>&&) + 922
50 swift 0x0000000100783b75 emitCallToTypeMetadataAccessFunction(swift::irgen::IRGenFunction&, swift::CanType, swift::ForDefinition_t) + 117
51 swift 0x00000001007814f5 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 533
52 swift 0x000000010070ef36 swift::irgen::IRGenerator::emitLazyDefinitions() + 3542
53 swift 0x00000001007f9ac3 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::_1::unique_ptr<swift::SILModule, std::_1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1555
54 swift 0x000000010065526e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 38110
55 swift 0x000000010064a304 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
56 swift 0x00000001005fece5 main + 18917
57 libdyld.dylib 0x00007fff72a8f015 start + 1

@belkadan
Copy link
Contributor

Here's the definition of the AVFilter struct that's not working: https://www.ffmpeg.org/doxygen/3.3/avfilter_8h_source.html#l00144.

I don't see anything obviously suspicious there, but maybe some of those fields are forward-declared structs, and that messes things up?

@swift-ci create

@belkadan
Copy link
Contributor

I wasn't able to reproduce this with Swift 4.1 and ffmpeg 4.0.2's headers. What version were you using?

@swift-ci
Copy link
Collaborator Author

Comment by sunlubo (JIRA)

sun$ swift --version
Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0

sun$ ffmpeg -version
ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 9.1.0 (clang-902.0.39.2)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-ffplay --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
libavutil 56. 14.100 / 56. 14.100
libavcodec 58. 18.100 / 58. 18.100
libavformat 58. 12.100 / 58. 12.100
libavdevice 58. 3.100 / 58. 3.100
libavfilter 7. 16.100 / 7. 16.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 1.100 / 5. 1.100
libswresample 3. 1.100 / 3. 1.100
libpostproc 55. 1.100 / 55. 1.100

@swift-ci
Copy link
Collaborator Author

Comment by sunlubo (JIRA)

When I use the toolchain downloaded from swift.org, I get this info:

Assertion failed: (offset >= NextOffset && "adding fields out of order"), function addField, file /Users/buildnode/jenkins/workspace/oss-swift-4.1-package-osx/swift/lib/IRGen/GenStruct.cpp, line 751.

...

Stack dump:
...

1. While converting type 'AVFilterLink'

@belkadan
Copy link
Contributor

That certainly sounds like the forward declaration thing. Thanks.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 1, 2018

Comment by sunlubo (JIRA)

minimal example can reproduce:

#ifndef filter_h
#define filter_h

#include <stdio.h>

typedef struct AVFilterContext AVFilterContext;
typedef struct AVFilterLink    AVFilterLink;

struct AVFilterContext {
    AVFilterLink **inputs;
};

struct AVFilterLink {
    AVFilterContext *src;
    
    // comment out this declaration, everything is okay.
    enum {
        AVLINK_UNINIT = 0,
        AVLINK_STARTINIT,
        AVLINK_INIT
    } init_state;
    
    int age_index;
};

#endif /* filter_h */
public final class FilterContext {
    internal let ctxPtr: UnsafeMutablePointer<AVFilterContext>
    internal init(ctxPtr: UnsafeMutablePointer<AVFilterContext>) {
        self.ctxPtr = ctxPtr
    }
}

@belkadan
Copy link
Contributor

belkadan commented Aug 1, 2018

Thank you! Hadn't gotten around to doing that myself yet.

@belkadan
Copy link
Contributor

belkadan commented Aug 1, 2018

Aha, looks like this is the same underlying issue as SR-2511. Actually, it's literally the same issue as SR-2511. Oops.

…anyway, it's fixed in Swift 4.2!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
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. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants