Skip to content

Commit b7a320c

Browse files
author
Salinas, David
authored
[Verifier] Fix some debug expression input type checks (llvm#902)
2 parents 9ca1600 + 0a2a57f commit b7a320c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,14 +3077,14 @@ template <class Derived> class DIExprConstVisitor {
30773077
}
30783078

30793079
std::optional<Type *> getType(DIOp::BitOffset Op, ArrayRef<StackEntry> Ins) {
3080-
if (!Ins[0].ResultType->isIntegerTy())
3080+
if (!Ins[1].ResultType->isIntegerTy())
30813081
return getTypeError(
30823082
"DIOpBitOffset requires first input be integer typed");
30833083
return Op.getResultType();
30843084
}
30853085

30863086
std::optional<Type *> getType(DIOp::ByteOffset Op, ArrayRef<StackEntry> Ins) {
3087-
if (!Ins[0].ResultType->isIntegerTy())
3087+
if (!Ins[1].ResultType->isIntegerTy())
30883088
return getTypeError(
30893089
"DIOpByteOffset requires first input be integer typed");
30903090
return Op.getResultType();
@@ -3107,13 +3107,13 @@ template <class Derived> class DIExprConstVisitor {
31073107
}
31083108

31093109
std::optional<Type *> getType(DIOp::Select Op, ArrayRef<StackEntry> Ins) {
3110-
if (Ins[0].ResultType != Ins[1].ResultType)
3110+
if (Ins[1].ResultType != Ins[2].ResultType)
31113111
return getTypeError(
31123112
"DIOpSelect requires first two inputs have same type");
3113-
if (!Ins[0].ResultType->isVectorTy())
3113+
if (!Ins[1].ResultType->isVectorTy())
31143114
return getTypeError(
31153115
"DIOpSelect requires first two inputs to be vector typed");
3116-
return Ins[0].ResultType;
3116+
return Ins[1].ResultType;
31173117
}
31183118

31193119
std::optional<Type *> getType(DIOp::AddrOf Op, ArrayRef<StackEntry>) {

llvm/test/DebugInfo/verify-diop-based-diexpression.ll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ entry:
2626
; CHECK: #dbg_declare(i8 poison, ![[#]], !DIExpression(DIOpArg(0, i32)), ![[#]])
2727
call void @llvm.dbg.declare(metadata i8 poison, metadata !24, metadata !DIExpression(DIOpArg(0, i32))), !dbg !22
2828

29+
; CHECK: #dbg_declare(ptr %i, ![[#]], !DIExpression(DIOpArg(0, ptr), DIOpDeref(%struct.type), DIOpConstant(i32 64), DIOpBitOffset(ptr)), ![[#]])
30+
call void @llvm.dbg.declare(metadata ptr %i, metadata !26, metadata !DIExpression(DIOpArg(0, ptr), DIOpDeref(%struct.type), DIOpConstant(i32 64), DIOpBitOffset(ptr))), !dbg !22
31+
32+
; CHECK: #dbg_declare(ptr %i, ![[#]], !DIExpression(DIOpArg(0, ptr), DIOpDeref(%struct.type), DIOpConstant(i32 8), DIOpByteOffset(ptr)), ![[#]])
33+
call void @llvm.dbg.declare(metadata ptr %i, metadata !27, metadata !DIExpression(DIOpArg(0, ptr), DIOpDeref(%struct.type), DIOpConstant(i32 8), DIOpByteOffset(ptr))), !dbg !22
34+
35+
; CHECK: #dbg_declare(i32 3, ![[#]], !DIExpression(DIOpArg(0, i32), DIOpConstant(<2 x i32> <i32 1, i32 2>), DIOpConstant(<2 x i32> <i32 3, i32 4>), DIOpSelect()), ![[#]])
36+
call void @llvm.dbg.declare(metadata i32 3, metadata !28, metadata !DIExpression(DIOpArg(0, i32), DIOpConstant(<2 x i32> <i32 1, i32 2>), DIOpConstant(<2 x i32> <i32 3, i32 4>), DIOpSelect())), !dbg !22
37+
2938
ret void
3039
}
3140

@@ -55,6 +64,10 @@ entry:
5564
!22 = !DILocation(line: 12, column: 7, scope: !17)
5665
!23 = !DILocation(line: 13, column: 1, scope: !17)
5766
!24 = !DILocalVariable(name: "j", scope: !17, file: !1, line: 12, type: !10)
67+
!25 = !DIBasicType(name: "int64", size: 64, encoding: DW_ATE_unsigned)
68+
!26 = !DILocalVariable(name: "k", scope: !17, file: !1, line: 12, type: !25)
69+
!27 = !DILocalVariable(name: "l", scope: !17, file: !1, line: 12, type: !25)
70+
!28 = !DILocalVariable(name: "m", scope: !17, file: !1, line: 12, type: !25)
5871

5972
;--- invalid.ll
6073
; RUN: opt invalid.ll -S -passes=verify 2>&1 | FileCheck invalid.ll

0 commit comments

Comments
 (0)