Skip to content

Commit 2ebae40

Browse files
authored
Merge pull request #72270 from Snowy1803/fix-empty-tuple-fragments-crash
[DebugInfo] Fix crash on empty tuple fragments
2 parents f9a42ec + ffb8ece commit 2ebae40

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,8 +2954,8 @@ bool IRGenDebugInfoImpl::handleFragmentDIExpr(
29542954
if (!FieldTypeInfo)
29552955
return false;
29562956
llvm::Type *FieldTy = FieldTypeInfo->getStorageType();
2957-
// Doesn't support non-fixed type right now
2958-
if (!Offset || !FieldTy)
2957+
// Doesn't support non-fixed or empty types right now.
2958+
if (!Offset || !FieldTy || !FieldTy->isSized())
29592959
return false;
29602960

29612961
uint64_t SizeOfByte = CI.getTargetInfo().getCharWidth();
@@ -2989,8 +2989,8 @@ bool IRGenDebugInfoImpl::handleTupleFragmentDIExpr(
29892989
auto Offset = getFixedTupleElementOffset(IGM, ParentSILType, *Idx);
29902990
auto ElementType = TT->getElement(*Idx).getType()->getCanonicalType();
29912991
llvm::Type *FieldTy = IGM.getStorageTypeForLowered(ElementType);
2992-
// Doesn't support non-fixed type right now
2993-
if (!Offset || !FieldTy)
2992+
// Doesn't support non-fixed or empty types right now.
2993+
if (!Offset || !FieldTy || !FieldTy->isSized())
29942994
return false;
29952995

29962996
uint64_t SizeInBits = IGM.DataLayout.getTypeSizeInBits(FieldTy);

test/DebugInfo/irgen_void_tuple.sil

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %target-swiftc_driver -Xfrontend -disable-debugger-shadow-copies -g -emit-ir %s | %FileCheck %s
2+
sil_stage canonical
3+
4+
import Builtin
5+
import Swift
6+
7+
// CHECK-LABEL: define {{.*}} @couple_of_voids
8+
sil hidden @couple_of_voids : $@convention(thin) () -> () {
9+
bb0:
10+
%3 = tuple ()
11+
// CHECK-NOT: call void @llvm.dbg.value
12+
debug_value %3 : $(), let, (name "success", loc "void.swift":3:1), type $*((), ()), expr op_tuple_fragment:$((), ()):0
13+
return %3 : $()
14+
} // end sil function 'couple_of_voids'
15+
16+
// CHECK-LABEL: define {{.*}} @one_existing
17+
sil hidden @one_existing : $@convention(thin) () -> Builtin.Int64 {
18+
bb0:
19+
%1 = integer_literal $Builtin.Int64, 0
20+
// CHECK: call void @llvm.dbg.value
21+
// CHECK-SAME: metadata ![[RESULT_VAR:[0-9]+]]
22+
debug_value %1 : $Builtin.Int64, let, (name "result", loc "void.swift":3:1), type $*(Builtin.Int64, ()), expr op_tuple_fragment:$(Builtin.Int64, ()):0
23+
return %1 : $Builtin.Int64
24+
} // end sil function 'one_existing'
25+
26+
// CHECK-LABEL: define {{.*}} @one_empty
27+
sil hidden @one_empty : $@convention(thin) () -> () {
28+
bb0:
29+
%3 = tuple ()
30+
// CHECK-NOT: call void @llvm.dbg.value
31+
debug_value %3 : $(), let, (name "failure", loc "void.swift":3:1), type $*(Builtin.Int64, ()), expr op_tuple_fragment:$(Builtin.Int64, ()):1
32+
return %3 : $()
33+
} // end sil function 'one_empty'
34+
35+
// CHECK: ![[RESULT_VAR]] = !DILocalVariable
36+
// CHECK-SAME: name: "result"

0 commit comments

Comments
 (0)