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-2706] Swift compiler assertion failure: Assertion `LastArgWritten >= adjustedArg.size()' failed #45310

swift-ci opened this issue Sep 20, 2016 · 1 comment


Copy link

@swift-ci swift-ci commented Sep 20, 2016

Previous ID SR-2706
Radar None
Original Reporter ewmailing (JIRA User)
Type Bug
Status Closed
Resolution Duplicate

Attachment: Download


Raspberry Pi 2 (32-bit armv7) running Raspbian Jessie
Built Swift 3 from source. (A bunch of components failed to build, but the Swift compiler got built.)

I've tested this code on Mac, iOS, Linux x86_64, and Android. The code compiles and works for all these other platforms. So this bug seems to be arm specific. (iOS and Android use x86_64 platforms to cross-compile, whereas I am directly compiling on the arm device to generate arm binaries which is the big difference there.)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, 3.0Regression, CompilerCrash, arm, armv7
Assignee @compnerd
Priority Medium

md5: 8f2abfe8f8520f432ecc0169bea57a0a

Issue Description:

I'm trying to use Swift 3 on a Raspberry Pi 2 (armv7). On code that used to compile in Swift 2.3, and code that currently compiles correctly on Swift 3 for Mac/Xcode 8, Linux x86_64, and for Android, I'm getting a compiler assertion failure and stack dump.


swift: /home/pi/Source/SWIFT/swift/lib/IRGen/GenCall.cpp:1886: void swift::irgen::CallEmission::setArgs(swift::irgen::Explosion &, swift::irgen::WitnessMetadata *): Assertion `LastArgWritten >= adjustedArg.size()' failed.
Stack dump:
0.  Program arguments: /home/pi/swift3/usr/bin/swift -frontend -c -DBLURRR_PLATFORM_LINUX -DBLURRR_PLATFORM_LINUX=1 -DBLURRR_PLATFORM_RASPBERRY_PI -DBLURRR_PLATFORM_RASPBERRY_PI=1 -DBLURRR_PLATFORM_RASPBIAN -DBLURRR_PLATFORM_RASPBIAN=1 -I/home/pi/Source/Blurrr/Release/BlurrrSDKRaspberryPi/Libraries/SDK/Raspbian/C/include/BlurrrCore -I/home/pi/Source/Blurrr/Release/BlurrrSDKRaspberryPi/Libraries/SDK/Raspbian/C/include/ALmixer -I/home/pi/Source/Blurrr/Release/BlurrrSDKRaspberryPi/Libraries/SDK/Raspbian/C/include/AL -I/home/pi/Source/Blurrr/Release/BlurrrSDKRaspberryPi/Libraries/SDK/Raspbian/C/include/chipmunk -I/home/pi/Source/Blurrr/Release/BlurrrSDKRaspberryPi/Libraries/SDK/Raspbian/C/include/SDL_ttf -I/home/pi/Source/Blurrr/Release/BlurrrSDKRaspberryPi/Libraries/SDK/Raspbian/C/include/SDL_image -I/home/pi/Source/Blurrr/Release/BlurrrSDKRaspberryPi/Libraries/SDK/Raspbian/C/include/SDL2 -I/home/pi/Source/Blurrr/Examples/flappyblurrrswift/source -target armv7-unknown-linux-gnueabihf -primary-file /home/pi/Source/Blurrr/Examples/flappyblurrrswift/source/BlurrrMain.swift /home/pi/Source/Blurrr/Examples/flappyblurrrswift/source/main.swift /home/pi/Source/Blurrr/Examples/flappyblurrrswift/source/BlurrrMain.swift -import-objc-header /home/pi/Source/Blurrr/Examples/flappyblurrrswift/source/MySwiftBridgingHeader.h -emit-module -module-name FlappyBlurrrSwift -o CMakeFiles/FlappyBlurrrSwift.dir/source/BlurrrMain.swift.o 
1.  While emitting IR SIL function @_TF17FlappyBlurrrSwift27Flappy_UpdateGroundPositionFTVs6UInt329base_timeS0_12current_timeS0__T_ for 'Flappy_UpdateGroundPosition' at /home/pi/Source/Blurrr/Examples/flappyblurrrswift/source/BlurrrMain.swift:1137:1
CMakeFiles/FlappyBlurrrSwift.dir/build.make:78: recipe for target 'CMakeFiles/FlappyBlurrrSwift.dir/source/BlurrrMain.swift.o' failed
make[2]: *** [CMakeFiles/FlappyBlurrrSwift.dir/source/BlurrrMain.swift.o] Aborted
CMakeFiles/Makefile2:102: recipe for target 'CMakeFiles/FlappyBlurrrSwift.dir/all' failed
make[1]: *** [CMakeFiles/FlappyBlurrrSwift.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2


I think Swift is having trouble with C-bindings. As far as I can tell, the compiler is breaking with stuff related to a type called cpVect defined as:

typedef struct cpVect{cpFloat x,y;} cpVect;

My code typically used a convenience function provided by the library defined as:

/// Convenience constructor for cpVect structs.
static inline cpVect cpv(const cpFloat x, const cpFloat y)
        cpVect v = {x, y};
        return v;

The simple pattern that seems to trigger this seems to come down to:

let pos_vec = cpv(0.0, 0.0);
cpBodySetPosition(body, pos_vec); // also tried explicit nil for body to try to suggest that it is the cpVect causing the problem

I'm attaching my slightly modified file trying to isolate the problem. It is line 1178 that trips up the compiler. (But if I comment this out, there are other instances of the code that trigger this.)

The full source code is in BlurrrMain.swift which can be found here.
The project has a bunch of dependencies. I'm developing a cross-platform SDK that makes this easy to build. I'm happy to give you access to the SDK if it helps you debug this.




I have new/additional information for this bug.

I have created a minimal, reproducible test case that can demonstrate this bug. It seems to be related to using a bridged C struct and function in Swift.

So in Swift, I have a simple function like which will cause the compiler to hit the assertion failure:

func BlurrrMain() -> Int32
       let body_vec: fakeVect = fakeVect(x:1.1, y:2.2);
       return 0;

In C, I have a header like so:

#ifndef MYCTYPES_H
#define MYCTYPES_H

struct fakeVect
       float x;
       float y;
typedef struct fakeVect fakeVect;

void fakeSetPosition(fakeVect vec);


I make sure to include this header in my bridging header.

Compiling this on Pi is sufficient enough to trigger the Swift compiler assertion.

I know this code builds and works for Mac, iOS, Linux x86_64, and Android. I’m only having this problem with the Pi.

As a reminder, the assertion says:

swift: /home/pi/Source/SWIFT3ARM/build-swift/swift/lib/IRGen/GenCall.cpp:1864: void swift::irgen::CallEmission::setArgs(swift::irgen::Explosion &, swift::irgen::WitnessMetadata *): Assertion `LastArgWritten >= adjustedArg.size()' failed.

In this case, LastArgWritten is 2 and adustedArg.size() is 3

I am attaching a reproducible project called SwiftArmCompileBug.tar.gz.
There is a script to help build it, but if you want to jump directly to the failing part, the command is the 3rd one which is:

swift -frontend -c  -target armv7-unknown-linux-gnueabihf     -primary-file BlurrrMain.swift main.swift BlurrrMain.swift  -import-objc-header MySwiftBridgingHeader.h  -emit-module -module-name MyBlurrrProject -o BlurrrMain.swift.o
Copy link

@compnerd compnerd commented Jan 24, 2018

I'm almost certain that I have fixed this. I have added tests for both this build target (Linux ARM HF) and others (Windows ARM).

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants