Skip to content

[embedded] Respect float arg lowering convention under -mfloat-abi=hard #74354

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

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/IRGen/GenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4299,11 +4299,12 @@ static void emitDirectForeignParameter(IRGenFunction &IGF, Explosion &in,
// The ABI IR types for the entrypoint might differ from the
// Swift IR types for the body of the function.

bool IsDirectFlattened = AI.isDirect() && AI.getCanBeFlattened();

llvm::Type *coercionTy = AI.getCoerceToType();

ArrayRef<llvm::Type*> expandedTys;
if (AI.isDirect() && AI.getCanBeFlattened() &&
isa<llvm::StructType>(coercionTy)) {
if (IsDirectFlattened && isa<llvm::StructType>(coercionTy)) {
const auto *ST = cast<llvm::StructType>(coercionTy);
expandedTys = llvm::ArrayRef(ST->element_begin(), ST->getNumElements());
} else if (coercionTy == paramTI.getStorageType()) {
Expand Down Expand Up @@ -4344,7 +4345,8 @@ static void emitDirectForeignParameter(IRGenFunction &IGF, Explosion &in,
Address coercedAddr = IGF.Builder.CreateElementBitCast(temporary, coercionTy);

// Break down a struct expansion if necessary.
if (auto expansionTy = dyn_cast<llvm::StructType>(coercionTy)) {
if (IsDirectFlattened && isa<llvm::StructType>(coercionTy)) {
auto expansionTy = cast<llvm::StructType>(coercionTy);
auto layout = IGF.IGM.DataLayout.getStructLayout(expansionTy);
for (unsigned i = 0, e = expansionTy->getNumElements(); i != e; ++i) {
auto fieldOffset = Size(layout->getElementOffset(i));
Expand Down
35 changes: 35 additions & 0 deletions test/embedded/float-abi-hard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s

// RUN: %target-swift-emit-ir %t/Main.swift -import-bridging-header %t/BridgingHeader.h -parse-as-library -enable-experimental-feature Embedded -wmo \
// RUN: -target armv7em-none-none-eabi -Xcc -mthumb -Xcc -mcpu=cortex-m7 -Xcc -mfloat-abi=hard -Xcc -mfpu=fpv5-sp-d16 -Xcc -D__FPU_USED=1 -Xcc -falign-functions=16

// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: OS=macosx || OS=linux-gnu
// REQUIRES: CODEGENERATOR=ARM

// BEGIN BridgingHeader.h

typedef struct
{
float x;
float y;
float width;
float height;
} Rect;

typedef void FunctionType(Rect, Rect);
void (* _Nonnull callback)(FunctionType * _Nonnull func);
void c_function(Rect, Rect);

// BEGIN Main.swift

@main
struct Main {
static func main() {
callback({ a, b in
c_function(a, b)
})
}
}