Skip to content

Commit 9ba545d

Browse files
committed
IRGen: Make sure we compare equal units in type size comparison
This is in some code to initialize variables for the debugger. From the original commit "Zero-initialize uninitialized Dictionary variables for the debugger. To avoid the debugger displaying garbage or having expressions crash when inspecting an uninitialized dictionary variable, zero-initialize the first word of the alloca at -Onone. " Unfortunately, we are comparing different quantities in that code. rdar://40043512
1 parent db423c3 commit 9ba545d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4017,7 +4017,7 @@ void IRGenSILFunction::visitAllocStackInst(swift::AllocStackInst *i) {
40174017
return;
40184018

40194019
auto &DL = IGM.DataLayout;
4020-
if (DL.getTypeSizeInBits(AI->getAllocatedType()) < DL.getPointerSize())
4020+
if (DL.getTypeSizeInBits(AI->getAllocatedType()) < DL.getPointerSizeInBits())
40214021
return;
40224022

40234023
auto *BC = Builder.CreateBitCast(AI, IGM.OpaquePtrTy->getPointerTo());

test/IRGen/alloc_stack.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -emit-ir | %FileCheck %s
2+
3+
// REQUIRES: CPU=x86_64
4+
5+
class Foobar {
6+
init() {
7+
var a : Bool = true
8+
}
9+
}
10+
11+
// Make sure we are mis-initializing the alloca.
12+
// CHECK-LABEL: define {{.*}}swiftcc %T11alloc_stack6FoobarC* @"$S11alloc_stack6FoobarCACycfc"(%T11alloc_stack6FoobarC* swiftself)
13+
// CHECK-NOT: store{{.*}}opaque
14+
// CHECK: ret {{.*}}%0
15+
// CHECK:}
16+

0 commit comments

Comments
 (0)