Skip to content

Commit e7e6490

Browse files
committed
IRGen: swift_taskAlloc wants its size input to be multiple of MaximumAlignment
1 parent b1c94a6 commit e7e6490

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/IRGen/GenOpaque.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ StackAddress IRGenFunction::emitDynamicAlloca(llvm::Type *eltTy,
545545
} else {
546546
byteCount = Builder.CreateMul(arraySize, IGM.getSize(Size(eltSize)));
547547
}
548+
// The task allocator wants size increments in the mulitple of
549+
// MaximumAlignment.
550+
byteCount = alignUpToMaximumAlignment(IGM.SizeTy, byteCount);
548551
auto address = emitTaskAlloc(byteCount, align);
549552
return {address, address.getAddress()};
550553
// In coroutines, call llvm.coro.alloca.alloc.

lib/IRGen/IRGenFunction.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// performs IR generation for function bodies.
1515
//
1616
//===----------------------------------------------------------------------===//
17-
17+
#include "swift/ABI/MetadataValues.h"
1818
#include "swift/AST/IRGenOptions.h"
1919
#include "swift/Basic/SourceLoc.h"
2020
#include "swift/IRGen/Linking.h"
@@ -507,3 +507,9 @@ void IRGenFunction::emitTaskDealloc(Address address) {
507507
call->setDoesNotThrow();
508508
call->setCallingConv(IGM.SwiftCC);
509509
}
510+
511+
llvm::Value *IRGenFunction::alignUpToMaximumAlignment(llvm::Type *sizeTy, llvm::Value *val) {
512+
auto *alignMask = llvm::ConstantInt::get(sizeTy, MaximumAlignment - 1);
513+
auto *invertedMask = Builder.CreateNot(alignMask);
514+
return Builder.CreateAnd(Builder.CreateAdd(val, alignMask), invertedMask);
515+
}

lib/IRGen/IRGenFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ class IRGenFunction {
460460
Alignment alignment);
461461
void emitTaskDealloc(Address address);
462462

463+
llvm::Value *alignUpToMaximumAlignment(llvm::Type *sizeTy, llvm::Value *val);
464+
463465
//--- Expression emission
464466
//------------------------------------------------------
465467
public:

0 commit comments

Comments
 (0)