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-9794] __transparent_union__ sized uint8_t causes Swift compiler to crash #52219

Open
swift-ci opened this issue Jan 29, 2019 · 2 comments
Open
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 IRGen LLVM IR generation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9794
Radar None
Original Reporter mozeryansky (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, ClangImporter, CompilerCrash, IRGen
Assignee None
Priority Medium

md5: dc47a667820c193191e92869066fce25

Issue Description:

I have narrowed down my compiler issue to the use of the attribute transparent_union with uint8_t, when passing a value of that union type into a c function. Simply removing the attribute or changing the union's size solves the issue.

In c, I have a function called `myFunction`:

void myFunction(const MyUnion_t inValue) {
// body is irrelevant, can be empty or not
}

In Swift I call this function like so:

public static func test(value: MyUnion_t)  {
    myFunction(value)
}

Note: The real compiler error happens only when I use myFunction. And only when the size of the union is uint8_t.

And here is my union type:

Crashes:

typedef union
{
    uint8_t value; 
} MyUnion_t __attribute__ ( (  __transparent_union__ ) );

Compiles:

typedef union
{
    uint16_t value; // <== Anything other than uint8_t works
} MyUnion_t __attribute__ ( (  __transparent_union__ ) );

or

typedef union
{
    uint8_t value;
} MyUnion_t;

Here's the crash log:

Wrong types for attribute: byval inalloca nest noalias nocapture nonnull readnone readonly signext sret zeroext dereferenceable(1) dereferenceable_or_null(1)
call void @x(%union.MyUnion_t zeroext %5), 76
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Broken function found, compilation aborted!
0 swift 0x000000011190d59a PrintStackTraceSignalHandler(void*) + 42
1 swift 0x000000011190cd4e SignalHandler(int) + 302
2 libsystem_platform.dylib 0x00007fff7ba54b3d _sigtramp + 29
3 libsystem_platform.dylib 0x00000001153a9bc6 _sigtramp + 2576699558
4 libsystem_c.dylib 0x00007fff7b9131c9 abort + 127
5 swift 0x000000010db92a67 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)::$1::invoke(void*, std::1::basic_string<char, std::1::char_traits<char>, std::_1::allocator<char> > const&, bool) + 519
6 swift 0x00000001118c11c8 llvm::report_fatal_error(llvm::Twine const&, bool) + 280
7 swift 0x00000001118c10ab llvm::report_fatal_error(char const*, bool) + 43
8 swift 0x0000000111888736 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) + 54
9 swift 0x000000011182ef9e llvm::FPPassManager::runOnFunction(llvm::Function&) + 446
10 swift 0x00000001118372b3 llvm::legacy::FunctionPassManagerImpl::run(llvm::Function&) + 115
11 swift 0x00000001118371a8 llvm::legacy::FunctionPassManager::run(llvm::Function&) + 392
12 swift 0x000000010dd59198 swift::performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine*, llvm::sys::SmartMutex<false>, llvm::GlobalVariable, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef, swift::UnifiedStatsReporter*) + 4504
13 swift 0x000000010db9f242 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 49170
14 swift 0x000000010db8fd35 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7717
15 swift 0x000000010db35965 main + 1349
16 libdyld.dylib 0x00007fff7b86b08d start + 1
17 libdyld.dylib 0x000000000000005d start + 2222542801

@belkadan
Copy link
Contributor

aschwaighofer@apple.com (JIRA User), @rjmccall, any idea what's going wrong?

@rjmccall
Copy link
Member

Looks like we're mishandling this corner case of Clang argument handling; we need to be passing an i8 in IR, but we're passing an aggregate type.

@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
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 IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

4 participants