Skip to content

Commit 17eef27

Browse files
authored
Merge pull request #74354 from kubamracek/embedded-float-abi-hard
[embedded] Respect float arg lowering convention under -mfloat-abi=hard
2 parents c42ecb0 + e871cea commit 17eef27

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,11 +4299,12 @@ static void emitDirectForeignParameter(IRGenFunction &IGF, Explosion &in,
42994299
// The ABI IR types for the entrypoint might differ from the
43004300
// Swift IR types for the body of the function.
43014301

4302+
bool IsDirectFlattened = AI.isDirect() && AI.getCanBeFlattened();
4303+
43024304
llvm::Type *coercionTy = AI.getCoerceToType();
43034305

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

43464347
// Break down a struct expansion if necessary.
4347-
if (auto expansionTy = dyn_cast<llvm::StructType>(coercionTy)) {
4348+
if (IsDirectFlattened && isa<llvm::StructType>(coercionTy)) {
4349+
auto expansionTy = cast<llvm::StructType>(coercionTy);
43484350
auto layout = IGF.IGM.DataLayout.getStructLayout(expansionTy);
43494351
for (unsigned i = 0, e = expansionTy->getNumElements(); i != e; ++i) {
43504352
auto fieldOffset = Size(layout->getElementOffset(i));

test/embedded/float-abi-hard.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-emit-ir %t/Main.swift -import-bridging-header %t/BridgingHeader.h -parse-as-library -enable-experimental-feature Embedded -wmo \
5+
// 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
6+
7+
// REQUIRES: swift_in_compiler
8+
// REQUIRES: optimized_stdlib
9+
// REQUIRES: OS=macosx || OS=linux-gnu
10+
// REQUIRES: CODEGENERATOR=ARM
11+
12+
// BEGIN BridgingHeader.h
13+
14+
typedef struct
15+
{
16+
float x;
17+
float y;
18+
float width;
19+
float height;
20+
} Rect;
21+
22+
typedef void FunctionType(Rect, Rect);
23+
void (* _Nonnull callback)(FunctionType * _Nonnull func);
24+
void c_function(Rect, Rect);
25+
26+
// BEGIN Main.swift
27+
28+
@main
29+
struct Main {
30+
static func main() {
31+
callback({ a, b in
32+
c_function(a, b)
33+
})
34+
}
35+
}

0 commit comments

Comments
 (0)