Skip to content

Commit 0935e15

Browse files
Return nullopt if Reg is undef. (llvm#155893)
In describeORRLoadedValue in AArch64InstrInfo.cpp, we try to check if an instruction is a copy like instruction, the isCopyLikeInstr function returns a pair of destination and source registers. If any of them are undef, we should just return a nullopt to avoid any crashes later in the code when trying to get the SubReg for one of those registers. rdar://158581204
1 parent 5fd5946 commit 0935e15

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10600,6 +10600,9 @@ describeORRLoadedValue(const MachineInstr &MI, Register DescribedReg,
1060010600
Register DestReg = DestSrc->Destination->getReg();
1060110601
Register SrcReg = DestSrc->Source->getReg();
1060210602

10603+
if (!DestReg.isValid() || !SrcReg.isValid())
10604+
return std::nullopt;
10605+
1060310606
auto Expr = DIExpression::get(MI.getMF()->getFunction().getContext(), {});
1060410607

1060510608
// If the described register is the destination, just return the source.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# This test should not crash when generating call-site information.
2+
# It was created to make sure that if isCopyLikeInstr in TargetInstrInfo.h
3+
# returns an undef Dest Reg or Src Reg, we don't try to get a SubReg for it.
4+
5+
# RUN: llc --mtriple=arm64e-apple-ios -start-before=aarch64-asm-printer %s -filetype=obj -o /dev/null --emit-call-site-info
6+
--- |
7+
%struct.rtyuio = type { i8 }
8+
define noundef i32 @aserty(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 !dbg !23 {
9+
ret i32 0
10+
}
11+
define void @asdfgh(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 !dbg !53 {
12+
%4 = alloca ptr
13+
%5 = call ptr @llvm.stackguard()
14+
%6 = alloca %struct.rtyuio
15+
%7 = icmp eq ptr %1, null
16+
br i1 %7, label %10, label %8
17+
%9 = tail call i8 @polkiokl(ptr noundef %0) #6
18+
br label %10
19+
ret void
20+
}
21+
declare i8 @polkiokl(ptr noundef) local_unnamed_addr #2
22+
!llvm.module.flags = !{!2, !8}
23+
!llvm.dbg.cu = !{!9}
24+
!2 = !{i32 2, !"Debug Info Version", i32 3}
25+
!8 = !{i32 7, !"frame-pointer", i32 1}
26+
!9 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_11, file: !10, emissionKind: FullDebug, sysroot: "/")
27+
!10 = !DIFile(filename: "a.cpp", directory: "/")
28+
!23 = distinct !DISubprogram(type: !27, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, unit: !9, retainedNodes: !46)
29+
!24 = distinct !DICompositeType(tag: DW_TAG_class_type, identifier: "yshscbshhdvcm")
30+
!27 = !DISubroutineType(types: !28)
31+
!28 = !{}
32+
!30 = !DIDerivedType(tag: DW_TAG_typedef, baseType: !33)
33+
!33 = distinct !DICompositeType(tag: DW_TAG_structure_type, identifier: "tyruwyeuiwiybabd")
34+
!36 = !DISubroutineType(types: !37)
35+
!37 = !{}
36+
!46 = !{}
37+
!47 = !DILocalVariable(scope: !23, type: !48, flags: DIFlagArtificial | DIFlagObjectPointer)
38+
!48 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !24, size: 64)
39+
!49 = !DILocalVariable(scope: !23, type: !30)
40+
!50 = !DILocation(scope: !23)
41+
!51 = !DILocation(scope: !23)
42+
!53 = distinct !DISubprogram(type: !36, unit: !9, retainedNodes: !54)
43+
!54 = !{}
44+
name: aserty
45+
stack:
46+
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
47+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
48+
- { id: 1, name: '', type: spill-slot, offset: -16, size: 8, alignment: 8,
49+
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
50+
callSites:
51+
- { bb: 0, offset: 9, fwdArgRegs:
52+
- { arg: 2, reg: '$w2' } }
53+
body: |
54+
bb.0 (%ir-block.2):
55+
DBG_VALUE $x0, $noreg, !47, !DIExpression(), debug-location !50
56+
DBG_VALUE $x1, $noreg, !49, !DIExpression(), debug-location !50
57+
frame-setup PACIBSP implicit-def $lr, implicit killed $lr, implicit $sp
58+
early-clobber $sp = frame-setup STPXpre $fp, killed $lr, $sp, -2 :: (store (s64) into %stack.1), (store (s64) into %stack.0)
59+
$fp = frame-setup ADDXri $sp, 0, 0
60+
frame-setup CFI_INSTRUCTION def_cfa $w29, 16
61+
frame-setup CFI_INSTRUCTION offset $w30, -8
62+
frame-setup CFI_INSTRUCTION offset $w29, -16
63+
$x2 = ORRXrs $xzr, undef $noreg, 0, implicit $wzr, debug-location !51
64+
BL @asdfgh, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit killed $x0, implicit killed $x1, implicit killed $w2, implicit-def $sp, debug-location !51
65+
...
66+
name: asdfgh
67+
body: |
68+
bb.2 (%ir-block.10):

0 commit comments

Comments
 (0)