Skip to content

Commit ca1bb04

Browse files
committed
[Verifier] Fix some debug expression input type checks
1 parent b8130f8 commit ca1bb04

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
@@ -3086,14 +3086,14 @@ template <class Derived> class DIExprConstVisitor {
30863086
}
30873087

30883088
std::optional<Type *> getType(DIOp::BitOffset Op, ArrayRef<StackEntry> Ins) {
3089-
if (!Ins[0].ResultType->isIntegerTy())
3089+
if (!Ins[1].ResultType->isIntegerTy())
30903090
return getTypeError(
30913091
"DIOpBitOffset requires first input be integer typed");
30923092
return Op.getResultType();
30933093
}
30943094

30953095
std::optional<Type *> getType(DIOp::ByteOffset Op, ArrayRef<StackEntry> Ins) {
3096-
if (!Ins[0].ResultType->isIntegerTy())
3096+
if (!Ins[1].ResultType->isIntegerTy())
30973097
return getTypeError(
30983098
"DIOpByteOffset requires first input be integer typed");
30993099
return Op.getResultType();
@@ -3116,13 +3116,13 @@ template <class Derived> class DIExprConstVisitor {
31163116
}
31173117

31183118
std::optional<Type *> getType(DIOp::Select Op, ArrayRef<StackEntry> Ins) {
3119-
if (Ins[0].ResultType != Ins[1].ResultType)
3119+
if (Ins[1].ResultType != Ins[2].ResultType)
31203120
return getTypeError(
31213121
"DIOpSelect requires first two inputs have same type");
3122-
if (!Ins[0].ResultType->isVectorTy())
3122+
if (!Ins[1].ResultType->isVectorTy())
31233123
return getTypeError(
31243124
"DIOpSelect requires first two inputs to be vector typed");
3125-
return Ins[0].ResultType;
3125+
return Ins[1].ResultType;
31263126
}
31273127

31283128
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)