Skip to content

Commit b0bd99c

Browse files
[IRGen] Add hack to handle _Atomic(_Bool) correctly.
(cherry picked from commit a6d0cca)
1 parent 611f21d commit b0bd99c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,7 +4146,10 @@ Explosion NativeConventionSchema::mapFromNative(IRGenModule &IGM,
41464146
if (explosionTy != elt->getType()) {
41474147
if (isa<llvm::IntegerType>(explosionTy) &&
41484148
isa<llvm::IntegerType>(elt->getType())) {
4149-
elt = IGF.Builder.CreateTrunc(elt, explosionTy);
4149+
// [HACK: Atomic-Bool-IRGen] In the case of _Atomic(_Bool), Clang
4150+
// treats it as i8 whereas Swift works with i1, so we need to zext
4151+
// in that case.
4152+
elt = IGF.Builder.CreateZExtOrTrunc(elt, explosionTy);
41504153
} else {
41514154
elt = IGF.coerceValue(elt, explosionTy, DataLayout);
41524155
}
@@ -4278,10 +4281,14 @@ Explosion NativeConventionSchema::mapIntoNative(IRGenModule &IGM,
42784281
auto *elt = fromNonNative.claimNext();
42794282
if (nativeTy != elt->getType()) {
42804283
if (isa<llvm::IntegerType>(nativeTy) &&
4281-
isa<llvm::IntegerType>(elt->getType()))
4282-
elt = IGF.Builder.CreateZExt(elt, nativeTy);
4283-
else
4284+
isa<llvm::IntegerType>(elt->getType())) {
4285+
// [HACK: Atomic-Bool-IRGen] In the case of _Atomic(_Bool), Clang
4286+
// treats it as i8 whereas Swift works with i1, so we need to trunc
4287+
// in that case.
4288+
elt = IGF.Builder.CreateZExtOrTrunc(elt, nativeTy);
4289+
} else {
42844290
elt = IGF.coerceValue(elt, nativeTy, DataLayout);
4291+
}
42854292
}
42864293
nativeExplosion.add(elt);
42874294
return nativeExplosion;

test/IRGen/atomic_bool.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: not --crash %target-swift-emit-ir %s -I %S/Inputs
1+
// Check that IRGen doesn't crash. rdar://72999296
2+
// RUN: %target-swift-emit-ir %s -I %S/Inputs
23

34
import AtomicBoolModule
45

0 commit comments

Comments
 (0)