Skip to content

Commit 73488ea

Browse files
authored
Merge pull request #35488 from varungandhi-apple/vg-no-atomic-explosion
2 parents e3db926 + a6d0cca commit 73488ea

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4158,7 +4158,10 @@ Explosion NativeConventionSchema::mapFromNative(IRGenModule &IGM,
41584158
if (explosionTy != elt->getType()) {
41594159
if (isa<llvm::IntegerType>(explosionTy) &&
41604160
isa<llvm::IntegerType>(elt->getType())) {
4161-
elt = IGF.Builder.CreateTrunc(elt, explosionTy);
4161+
// [HACK: Atomic-Bool-IRGen] In the case of _Atomic(_Bool), Clang
4162+
// treats it as i8 whereas Swift works with i1, so we need to zext
4163+
// in that case.
4164+
elt = IGF.Builder.CreateZExtOrTrunc(elt, explosionTy);
41624165
} else {
41634166
elt = IGF.coerceValue(elt, explosionTy, DataLayout);
41644167
}
@@ -4290,10 +4293,14 @@ Explosion NativeConventionSchema::mapIntoNative(IRGenModule &IGM,
42904293
auto *elt = fromNonNative.claimNext();
42914294
if (nativeTy != elt->getType()) {
42924295
if (isa<llvm::IntegerType>(nativeTy) &&
4293-
isa<llvm::IntegerType>(elt->getType()))
4294-
elt = IGF.Builder.CreateZExt(elt, nativeTy);
4295-
else
4296+
isa<llvm::IntegerType>(elt->getType())) {
4297+
// [HACK: Atomic-Bool-IRGen] In the case of _Atomic(_Bool), Clang
4298+
// treats it as i8 whereas Swift works with i1, so we need to trunc
4299+
// in that case.
4300+
elt = IGF.Builder.CreateZExtOrTrunc(elt, nativeTy);
4301+
} else {
42964302
elt = IGF.coerceValue(elt, nativeTy, DataLayout);
4303+
}
42974304
}
42984305
nativeExplosion.add(elt);
42994306
return nativeExplosion;

test/IRGen/Inputs/atomic_bool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
typedef struct { _Atomic(_Bool) value; } MyAtomicBool;

test/IRGen/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ module AutolinkElfCPragmaTransitive {
2121
module AutolinkModuleMapLink {
2222
link "autolink-module-map-link"
2323
}
24+
25+
module AtomicBoolModule {
26+
header "atomic_bool.h"
27+
export *
28+
}

test/IRGen/atomic_bool.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Check that IRGen doesn't crash. rdar://72999296
2+
// RUN: %target-swift-emit-ir %s -I %S/Inputs
3+
4+
import AtomicBoolModule
5+
6+
public func f() -> MyAtomicBool {
7+
return MyAtomicBool()
8+
}
9+
10+
public func g(_ b: MyAtomicBool) {
11+
let _ = b
12+
}

0 commit comments

Comments
 (0)